Skip to content

Latest commit

 

History

History
147 lines (116 loc) · 5.7 KB

gitlab_access_protocol.md

File metadata and controls

147 lines (116 loc) · 5.7 KB

GitLab Access Protocol

This document is the single source of truth for how executor and reviewer read GitLab merge requests and discussions in orchestrator runs.

1. Scope and authority

  • Applies to all providers (claude, opencode, codex) and both roles (executor/reviewer).
  • Trigger: user prompt mentions GitLab/MR/merge request/review comments/discussions.
  • Tooling source: glab CLI for GitLab reads.
  • Agents must not reinterpret read-only constraints.

2. Read-only policy

  • Allowed: read-only GitLab operations (mr view, mr diff, mr view --comments, glab api GET for MR notes/discussions, pipelines read).
  • Forbidden: any mutating GitLab actions in orchestrator rounds, including:
    • creating/updating/closing/reopening MR;
    • posting/editing/deleting notes/comments;
    • approving/unapproving, assigning/reassigning, labeling;
    • pushing commits, rebasing, merging from CLI.
  • If user explicitly asks for a mutating GitLab action, it must be handled as a separate explicit task, not as part of read-only investigate/plan/review flow.

3. Canonical command set (read-only)

3.1 Merge request context

# Current branch MR
glab mr view

# Explicit MR id/iid/url
glab mr view <mr>

# Diff
glab mr diff <mr>

# Quick comments/activity view in CLI output
glab mr view <mr> --comments

3.2 Notes/discussions via API (version-compatible, read-only)

glab 1.53.0 does not provide glab mr note list <mr> read command. Use read-only API endpoints instead:

# Option A: from inside the target repository (uses current repo placeholders)
glab api "projects/:fullpath/merge_requests/<iid>/notes?per_page=100"
glab api "projects/:fullpath/merge_requests/<iid>/discussions?per_page=100"

# Option B: explicit GitLab host and URL-encoded project path
glab api --hostname <gitlab-host> "projects/<urlencoded_group%2Fproject>/merge_requests/<iid>/notes?per_page=100"
glab api --hostname <gitlab-host> "projects/<urlencoded_group%2Fproject>/merge_requests/<iid>/discussions?per_page=100"

Practical way to get <iid> and <group/project>:

glab mr view <mr> --output json

3.3 Pipeline status (read-only)

glab pipeline list
glab pipeline status

3.4 Optional Notion cross-reference

If MR description contains TASK-<id> or a Notion URL, read task context:

notion task view <id>

4. Deterministic read algorithm

When GitLab MR review/study is requested:

  1. Verify CLI availability:
    • glab --help
    • glab auth status
  2. Apply bounded retries to every required GitLab read command:
    • retry policy is mandatory and deterministic:
      • max attempts: 5
      • per-attempt timeout: 60s
      • pause between attempts: 5s
    • within each attempt:
      • run the canonical read-only glab command for the current step;
      • use a 60s per-attempt timeout (timeout 60s glab ... or an equivalent tool timeout);
      • record whether the command result was ok or failed.
    • success condition: the command exits successfully and returns usable data for the current step.
    • if a step has a documented fallback, apply the same retry policy to each fallback command.
  3. Resolve target MR:
    • if argument provided, use it;
    • otherwise use MR for current branch (glab mr view).
  4. Read MR metadata:
    • glab mr view <mr>
  5. Read diff:
    • glab mr diff <mr>
  6. Read notes/discussions:
    • first try glab mr view <mr> --comments for quick context;
    • then fetch full notes/discussions via API:
      • from inside the target repository:
        • glab api "projects/:fullpath/merge_requests/<iid>/notes?per_page=100"
        • glab api "projects/:fullpath/merge_requests/<iid>/discussions?per_page=100"
      • or with explicit host/project:
        • glab api --hostname <gitlab-host> "projects/<urlencoded_group%2Fproject>/merge_requests/<iid>/notes?per_page=100"
        • glab api --hostname <gitlab-host> "projects/<urlencoded_group%2Fproject>/merge_requests/<iid>/discussions?per_page=100"
  7. Parse and report:
    • title, author, target branch, CI/pipeline status;
    • changed files;
    • comments/notes, including open vs resolved concerns where detectable;
    • key reviewer concerns already raised (avoid duplicating already-addressed points).
  8. For each changed file, read full file in repo (not only diff hunks) before final conclusions.

5. Executor obligations

  • In outbox, explicitly list:
    • exact GitLab commands run;
    • attempt counters (attempt X/5) for each GitLab read command;
    • command result per attempt: ok / failed;
    • short stderr/stdout tail for failures;
    • MR identity used (current branch or explicit <mr>);
    • what was read from notes/discussions;
    • what could not be verified (if any).
  • Do not perform or suggest hidden mutating actions under read-only workflow.

6. Reviewer obligations

  • Independently verify executor claims using the same canonical read-only commands where possible.
  • Validate that:
    • conclusions are based on MR metadata + diff + notes, not only self-report;
    • open concerns in notes/discussions are accounted for in conclusions;
    • required GitLab read commands used the mandatory 5-attempt / 60s-timeout retry policy;
    • no mutating GitLab action was performed.

7. Failure and limitation handling

  • If MR cannot be resolved/read after the bounded retry policy (glab auth/network/not found), report exact failing command, attempt count, timeout/failure status, and error.
  • Under investigation/planning flows, continue only if task remains meaningful without MR data; otherwise mark as blocked with concrete unblock requirements.
  • Typical unblock actions:
    1. Fix GitLab auth for glab.
    2. Provide explicit MR id/url.
    3. Confirm repository/remote visibility for current environment.