@catladder/cli 0.0.0-main-b67a4ad4 → 0.0.0-main-db6ec1ef

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6060,15 +6060,18 @@ exports.createJobsForAgentContext = createJobsForAgentContext;
6060
6060
 
6061
6061
  "use strict";
6062
6062
 
6063
- // prompts.ts — MCP-only, DRY, review-first-then-push, CI diagnosis (no retries), self-mention guard,
6064
- // conversations-aware: always read the thread first (issues & MRs), reply inline, avoid duplicates.
6065
- // Prevents double-runs: event-triggered work cancels any running "agent-review" job on the MR's own pipeline.
6063
+ // prompts.ts — MCP-only, DRY, review-first-then-push, CI diagnosis (no retries),
6064
+ // self-mention guard, conversations-aware (issues & MRs), inline replies, de-duplication.
6065
+ // Review-on-demand: resolves MR pipeline and triggers manual "agent-review" when present.
6066
+ // Single-runner guard: cancels running "agent-review" on the MR pipeline before acting.
6067
+ // Stdout summaries included for both event and MR flows.
6066
6068
  Object.defineProperty(exports, "__esModule", ({ value: true }));
6067
6069
  exports.getMergeRequestPrompt = exports.getEventPrompt = void 0;
6068
6070
  /* ---------- Shared blocks ---------- */
6069
6071
  const header = () => `
6070
6072
  Project ID: $CI_PROJECT_ID
6071
6073
  GitLab Host: $CI_SERVER_URL
6074
+ Default Branch: $CI_DEFAULT_BRANCH
6072
6075
  `;
6073
6076
  const identity = ({ agentUserName }) => `
6074
6077
  ## Identity
@@ -6085,87 +6088,64 @@ const goldenRules = ({ agentUserName }) => `
6085
6088
  - Keep actions minimal and idempotent. Avoid duplicate comments or duplicate MRs.
6086
6089
  - Use ONE stable \`source_branch\` per run; do not regenerate its name later.
6087
6090
  `;
6088
- /* ---------- NEW: conversation intake + threading rules ---------- */
6091
+ /* ---------- Conversations + threading ---------- */
6089
6092
  const conversationsIntake = ({ agentUserName }) => `
6090
6093
  ## Conversations Intake & Threading (MANDATORY before acting)
6091
6094
  Always load and reason about the current conversation to avoid duplicates and to respond in the right place.
6092
6095
 
6093
- ### What to fetch
6094
- - **MRs**: Use \`mr_discussions({ projectId: $CI_PROJECT_ID, mergeRequestIid })\` to load all threads and notes.
6095
- - **Issues**: If an issue-discussions/listing tool exists, use it. If not available in \`gitlab-mcp\`, rely on the **event payload** and **your last note ids** if present; otherwise post a single concise note acknowledging the limitation and proceed.
6096
-
6097
- ### How to use it
6098
- 1) **Detect review/answer context**:
6099
- - Identify the **latest human note** in the thread (exclude notes authored by "${agentUserName}").
6100
- - If the latest human note **replies to you** (mentions you or is in a discussion you started), reply **in the same discussion**.
6101
- 2) **De-duplication**:
6102
- - If your most recent message is the **last message overall** and **no one else replied** since, prefer **updating your last note** instead of posting a new one:
6103
- - Use \`update_merge_request_note\` or \`update_issue_note\` accordingly.
6104
- 3) **Reply placement**:
6105
- - For MR code discussions: reply **inline in the same discussion** (preserve thread context).
6106
- - For general/MR overview threads: add a single consolidated reply (avoid multiple scattered notes).
6107
- 4) **Sanitize before write**:
6108
- - Apply the Self-mention Guard, then post.
6109
- 5) **If conversations list is unavailable**:
6110
- - Post one short note: that you cannot fetch the full conversation due to missing MCP capability, then proceed minimally (no spam).
6096
+ - **MRs**: Use \`mr_discussions({ projectId: $CI_PROJECT_ID, mergeRequestIid })\`.
6097
+ - **Issues**: Use issue discussions if available; if not, rely on event payload and note IDs.
6098
+
6099
+ Rules:
6100
+ 1) Detect latest human note (exclude "${agentUserName}"). If it replies to you or is in a discussion you started, reply **in the same thread**.
6101
+ 2) If your last message is still the latest and no one else replied, prefer **update_note** instead of creating a new one.
6102
+ 3) For MR code discussions: reply inline in the same discussion.
6103
+ 4) Always sanitize (see Self-mention Guard) before writing.
6111
6104
  `;
6112
6105
  const selfMentionGuard = ({ agentUserName }) => `
6113
- ## Self-mention Guard (mandatory preflight for ALL writes)
6114
- Before ANY call that writes text (comment/create/update MR/issue/commit message), sanitize the text:
6115
-
6116
- - Remove all occurrences of your own handle:
6117
- - Match case-insensitively: \`/@?${agentUserName}\\b/gi\`
6118
- - Also strip variants inside parentheses or brackets if present.
6119
- - Do NOT replace with another token; simply remove the self @-mention.
6120
- - If after sanitization the body becomes empty/meaningless, skip the write.
6121
-
6122
- Additionally:
6123
- - If the last actor/author of the target item is you ("${agentUserName}"), **do not** post an acknowledgement comment (avoid loops on your own events).
6124
- - To assign yourself, use the MCP assignee field(s). Do **not** mention yourself in the body to indicate assignment.
6106
+ ## Self-mention Guard
6107
+ Before ANY write (comment/MR/issue/commit message):
6108
+ - Remove all occurrences of "@${agentUserName}" (case-insensitive).
6109
+ - If the text becomes empty, skip the write.
6110
+ - If the last actor is you, skip acknowledgement comments.
6111
+ - To assign yourself, use assignee fields, not mentions.
6125
6112
  `;
6126
6113
  const commentGuidelines = () => `
6127
- ## Comment Guidelines (flexible, not verbatim)
6114
+ ## Comment Guidelines
6128
6115
  - Professional, friendly, concise.
6129
6116
  - Always @-mention the human author when replying; never mention yourself.
6130
- - Acknowledgements: confirm you saw the request and you’ll handle it.
6131
- - MR updates: acknowledge feedback and say you’ll apply/have applied the change.
6132
- - Q&A: answer directly first; add context/links only if useful.
6133
- - Avoid repeating identical boilerplate across comments.
6117
+ - Acknowledge requests, answer questions directly, confirm fixes or updates.
6118
+ - Avoid repeating boilerplate.
6134
6119
  `;
6135
- /* Exact tool names from @zereight/mcp-gitlab (lean, indicative signatures) */
6120
+ /* ---------- gitlab-mcp tool usage ---------- */
6136
6121
  const mcpOnly = () => `
6137
- ## gitlab-mcp Operations (exact tool names; indicative params)
6122
+ ## gitlab-mcp Operations
6138
6123
 
6139
6124
  - **Comments / Notes**
6140
- - create_note({ projectId, targetType: "issue"|"merge_request", iid, body })
6141
6125
  - create_issue_note({ projectId, issueIid, body })
6142
- - create_merge_request_note({ projectId, mergeRequestIid, body })
6143
6126
  - update_issue_note({ projectId, issueIid, noteId, body })
6127
+ - create_merge_request_note({ projectId, mergeRequestIid, body })
6144
6128
  - update_merge_request_note({ projectId, mergeRequestIid, noteId, body })
6145
6129
  - mr_discussions({ projectId, mergeRequestIid })
6146
6130
 
6147
6131
  - **Issues**
6148
6132
  - create_issue({ projectId, title, description, assigneeUsernames?: string[] })
6149
- - list_issues({ projectId, state?: "opened"|"closed", scope?: "all"|... })
6150
6133
 
6151
6134
  - **Branch & Files**
6152
6135
  - create_branch({ projectId, branchName, ref })
6153
6136
  - push_files({ projectId, branch, commitMessage, files: [{ filePath, content }] })
6154
6137
  - create_or_update_file({ projectId, branch, filePath, content, commitMessage })
6155
- - get_file_contents({ projectId, ref, path })
6156
6138
  - get_branch_diffs({ projectId, from, to })
6157
6139
 
6158
6140
  - **Merge Requests**
6159
6141
  - create_merge_request({ projectId, sourceBranch, targetBranch, title, description, assigneeUsernames?: string[] })
6160
- - get_merge_request({ projectId, mergeRequestIid? , branchName? })
6161
- - get_merge_request_diffs({ projectId, mergeRequestIid? , branchName? })
6162
- - list_merge_request_diffs({ projectId, mergeRequestIid? , branchName?, page?, perPage? })
6163
- - update_merge_request({ projectId, mergeRequestIid? , branchName?, title?, description?, draft?, assigneeUsernames? })
6164
- - merge_merge_request(...) // **Do NOT use** (never merge)
6142
+ - get_merge_request({ projectId, mergeRequestIid })
6143
+ - get_merge_request_diffs({ projectId, mergeRequestIid })
6144
+ - list_merge_request_diffs({ projectId, mergeRequestIid, page?, perPage? })
6145
+ - update_merge_request({ projectId, mergeRequestIid, title?, description?, draft?, assigneeUsernames? })
6165
6146
 
6166
- - **Pipelines / Jobs** (requires env USE_PIPELINE=true)
6147
+ - **Pipelines / Jobs**
6167
6148
  - list_pipelines({ projectId, ref?, sha?, status?, orderBy?, sort? })
6168
- - get_pipeline({ projectId, pipelineId })
6169
6149
  - list_pipeline_jobs({ projectId, pipelineId })
6170
6150
  - get_pipeline_job_output({ projectId, pipelineId, jobId })
6171
6151
  - play_pipeline_job({ projectId, jobId })
@@ -6177,166 +6157,124 @@ const outputDiscipline = ({ agentUserName }) => `
6177
6157
  - Keep comments concise and professional.
6178
6158
  - Never include "@${agentUserName}" in any body.
6179
6159
  `;
6180
- /* ---------- Event (webhook) specific ---------- */
6160
+ /* ---------- Event-specific helpers ---------- */
6181
6161
  const eventSelfParse = () => `
6182
- ## Self-Parse the Raw Payload (no preprocessing available)
6162
+ ## Self-Parse Raw Payload
6183
6163
  From \`event_json\`, extract:
6184
6164
  - kind: "issue" | "merge_request" | "note"
6185
- - target + iid from URL:
6186
- - \`/-/issues/<n>\` → target="issue", iid=<n>
6187
- - \`/-/merge_requests/<n>\` → target="mr", iid=<n>
6188
- - note_id if present (\`#note_<id>\`)
6189
- - description/body text, state, author \`user_username\`, timestamps
6190
- - project id/path; detect default branch via \`get_merge_request\`/context as needed
6191
- - If available: the discussion id / thread context of the note to enable inline replies.
6165
+ - iid from URL (/issues/<n>, /merge_requests/<n>)
6166
+ - note_id if present (#note_<id>)
6167
+ - description/body, state, author, timestamps
6168
+ - project id/path
6169
+ - discussion id if available for inline replies
6192
6170
  `;
6193
- /* Helper used by Single-Runner Guard and Review-on-Demand to find the MR’s own pipeline */
6171
+ /* Resolve MR pipeline from MR IID */
6194
6172
  const resolveMrPipeline = () => `
6195
- ## Resolve MR Pipeline (for MR IID resolved from the event)
6196
- Given \`mr_iid\`:
6197
- 1) Call \`get_merge_request({ projectId: $CI_PROJECT_ID, mergeRequestIid: mr_iid })\` to obtain:
6198
- - \`sourceBranch\` (required)
6199
- - \`sha\` or head SHA (if available)
6200
- 2) Prefer **SHA-based** lookup:
6201
- - \`list_pipelines({ projectId: $CI_PROJECT_ID, sha })\` ordered by most recent; pick the newest.
6202
- 3) Fallback to **ref-based** lookup if SHA not available:
6203
- - \`list_pipelines({ projectId: $CI_PROJECT_ID, ref: sourceBranch, orderBy: "updated_at", sort: "desc" })\`; pick the newest.
6204
- 4) The chosen pipeline becomes \`mr_pipeline_id\`. Use it for all job queries/plays/cancels related to this MR.
6205
- - If no pipeline is found, post a short MR note explaining that no pipeline was located for the current MR head and proceed with review actions without CI job control.
6173
+ ## Resolve MR Pipeline
6174
+ 1) get_merge_request({ projectId, mergeRequestIid }) → sourceBranch, sha
6175
+ 2) Prefer: list_pipelines({ projectId, sha })
6176
+ 3) Else: list_pipelines({ projectId, ref: sourceBranch, orderBy: "updated_at", sort: "desc" })
6177
+ 4) Pick newest → mr_pipeline_id
6206
6178
  `;
6179
+ /* Guard against double agent-review jobs */
6207
6180
  const singleRunnerGuard = () => `
6208
- ## Single-Runner Guard (event-triggered work on an existing MR)
6209
- Before entering MR Review Mode from an event:
6210
-
6211
- - **Goal:** Avoid two agents working the same MR. If a **running or pending** CI job whose name **ends with "agent-review"** is active for this MR's pipeline, **cancel** it first.
6212
-
6213
- **Procedure (MCP-only):**
6214
- 1) Resolve the MR IID from the event (target URL or text) and run **Resolve MR Pipeline** to get \`mr_pipeline_id\`.
6215
- 2) If \`mr_pipeline_id\` is available:
6216
- - \`list_pipeline_jobs({ projectId: $CI_PROJECT_ID, pipelineId: mr_pipeline_id })\`.
6217
- - For any job with \`status\` in \`["running","pending"]\` and \`name\` ending with \`"agent-review"\`, call:
6218
- - \`cancel_pipeline_job({ projectId: $CI_PROJECT_ID, jobId })\`.
6219
- - Proceed immediately after issuing cancellations (do not wait).
6220
- 3) If the pipeline cannot be resolved:
6221
- - Post a short MR note stating you are proceeding but **cannot verify/cancel** a running \`agent-review\` job due to missing pipeline context.
6222
- - Proceed with review.
6223
-
6224
- **Notes:**
6225
- - Keep this guard **idempotent** (safe to run multiple times).
6226
- - Only applies to **event-triggered** flows that act on an **existing MR**.
6181
+ ## Single-Runner Guard
6182
+ - If mr_pipeline_id available:
6183
+ - list_pipeline_jobs({ projectId, pipelineId: mr_pipeline_id })
6184
+ - cancel_pipeline_job on any running/pending job ending with "agent-review"
6185
+ - If not available, note limitation and proceed
6227
6186
  `;
6187
+ /* If user asks for review from an event, try manual agent-review job first on the MR's pipeline */
6228
6188
  const reviewOnDemandFromEvents = () => `
6229
- ## Review-on-Demand (from events)
6230
- If the issue/note text **asks for a review** (case-insensitive tokens like: "review", "please review", "PTAL", "needs review", "can you look at", "LGTM?"), then:
6231
-
6232
- 1) **Resolve which MR to review**:
6233
- - If the event target is an MR → use its \`iid\`.
6234
- - Else, parse the text for MR references in order:
6235
- - \`!<iid>\` (e.g., \`!123\`)
6236
- - \`/-/merge_requests/<iid>\` in a path or URL
6237
- - full GitLab MR URL
6238
- - If no MR can be resolved, reply with a brief comment asking the user to reference an MR (sanitize) and **stop**.
6239
-
6240
- 2) **Find the MR's pipeline** (do **not** use \`$CI_PIPELINE_ID\` from the event):
6241
- - Execute **Resolve MR Pipeline** to obtain \`mr_pipeline_id\`.
6242
-
6243
- 3) **If a manual "agent-review" job exists on the MR pipeline, trigger it**
6244
- - If \`mr_pipeline_id\` is available:
6245
- - \`list_pipeline_jobs({ projectId: $CI_PROJECT_ID, pipelineId: mr_pipeline_id })\`.
6246
- - If any job has \`status = "manual"\` **and** its \`name\` ends with "agent-review":
6247
- - Trigger via \`play_pipeline_job({ projectId: $CI_PROJECT_ID, jobId })\`.
6248
- - **Conversations Intake**: run the section above to determine **where** to post the confirmation (prefer replying in the same thread that requested review).
6249
- - Post a short comment confirming you triggered the review job (sanitize).
6250
- - **Stop** further review actions.
6251
-
6252
- 4) **Single-Runner Guard**
6253
- - If no manual job was triggered, execute the **Single-Runner Guard** (it will cancel any running/pending \`agent-review\` jobs on the MR pipeline) before MR Review Mode.
6254
-
6255
- 5) **Enter MR Review Mode**: execute the **MR Review Bundle** below with the resolved \`mr_iid\`.
6189
+ ## Review-on-Demand
6190
+ If the text asks for a review ("review", "please review", "PTAL", "needs review", "can you look at", "LGTM?"):
6191
+ 1) Resolve MR IID (from target or text).
6192
+ 2) Resolve MR pipeline (do NOT use the event pipeline).
6193
+ 3) If a manual "agent-review" job exists, play it → confirm in-thread → STOP.
6194
+ 4) Else run Single-Runner Guard, then enter MR Review Mode.
6256
6195
  `;
6257
- /** Regular event workflow for non-review work */
6196
+ /* ---------- Event workflow ---------- */
6258
6197
  const eventWorkflow = ({ agentUserName }) => `
6259
- ## High-Reliability Workflow (sequence + postconditions)
6260
- Follow this order for any change work:
6261
-
6262
- 0) **Conversations Intake (MANDATORY)**:
6263
- - For MR targets: call \`mr_discussions\` and apply the rules in **Conversations Intake & Threading**.
6264
- - For issue targets: attempt to load notes if supported; otherwise rely on event context and post one concise note acknowledging the limitation.
6265
-
6266
- 1) **Acknowledge** with a short comment on the issue/MR thread (\`create_note\`), **unless the last actor is you**.
6267
- 2) **Discover default branch** (e.g., "main") — infer from repo/MR context if needed.
6268
- 3) **Create a working branch** from default (stable name, e.g., \`fix/issue-<iid>-<slug>\` or \`feat/issue-<iid>-<slug>\`) via \`create_branch\`.
6269
- 4) **Write changes → commit → push to remote branch** via \`push_files\` (or \`create_or_update_file\`).
6270
- 5) **Verify push landed**:
6271
- - Fetch latest state and ensure diffs via \`get_branch_diffs({ from: "<default>", to: "<source>" })\`.
6272
- 6) **Create or update MR** ONLY if there is a non-empty diff via \`create_merge_request\`.
6273
- - Include \`Closes #<issue_iid>\` in MR description when applicable.
6274
- - **Assign the MR to yourself**: \`assigneeUsernames: ["${agentUserName}"]\`.
6275
- 7) **Follow-up comment** with branch name, any commit short SHA you can obtain, files changed count (approx by diffs), and MR link via \`create_note\`, **unless the last actor is you**. Place this **in the relevant conversation thread** (see Intake rules).
6276
- 8) **If verification fails**:
6277
- - Do NOT create the MR.
6278
- - Comment the exact failure and retry once with a fresh branch name. If still failing, comment and stop.
6279
-
6280
- For Q&A-only (no code changes), run **Conversations Intake** first, then post a single concise, helpful answer **in the correct thread** (sanitize).
6198
+ ## Event Workflow
6199
+ 0) Conversations Intake first
6200
+ 1) Acknowledge with note (unless last actor is you)
6201
+ 2) Default branch: use \`$CI_DEFAULT_BRANCH\`
6202
+ 3) Create branch from \`$CI_DEFAULT_BRANCH\`:
6203
+ create_branch({ projectId: $CI_PROJECT_ID, branchName: "<source_branch>", ref: $CI_DEFAULT_BRANCH })
6204
+ 4) Write changes → commit → push:
6205
+ push_files({ projectId: $CI_PROJECT_ID, branch: "<source_branch>", commitMessage, files })
6206
+ 5) Verify:
6207
+ get_branch_diffs({ projectId: $CI_PROJECT_ID, from: $CI_DEFAULT_BRANCH, to: "<source_branch>" })
6208
+ - Require non-empty diffs
6209
+ 6) Create MR (if diffs exist):
6210
+ create_merge_request({
6211
+ projectId: $CI_PROJECT_ID,
6212
+ sourceBranch: "<source_branch>",
6213
+ targetBranch: $CI_DEFAULT_BRANCH,
6214
+ title,
6215
+ description, // include "Closes #<issue_iid>" when applicable
6216
+ assigneeUsernames: ["${agentUserName}"]
6217
+ })
6218
+ 7) Follow-up note (in correct thread) with branch, short SHA if available, files-changed count, and MR link (unless last actor is you)
6219
+ 8) If verification fails: comment error and STOP
6220
+
6221
+ ## Stdout Summary (Event)
6222
+ Print a plain-text summary with:
6223
+ - action: "event"
6224
+ - source_branch
6225
+ - target_branch: $CI_DEFAULT_BRANCH
6226
+ - diff_count (from get_branch_diffs)
6227
+ - mr_iid and/or mr_url if created
6228
+ - any note ids created/updated
6229
+ - any limitations encountered (e.g., missing discussions tool)
6281
6230
  `;
6282
- /* ---------- MR-review specific (shared with both prompts) ---------- */
6231
+ /* ---------- MR-specific ---------- */
6283
6232
  const mrScope = ({ agentUserName }) => `
6284
- ## Identity & Scope
6285
- - Your GitLab username is "${agentUserName}".
6286
- - This prompt runs in the context of ONE MR.
6287
- - You may review, comment, and push updates **to the MR's source branch**.
6288
- - You must **never merge** the MR yourself.
6233
+ ## MR Scope
6234
+ - You are reviewing a single MR
6235
+ - Never merge the MR yourself
6236
+ - Work only on the MR's source branch
6289
6237
  `;
6290
6238
  const mrWorkflow = () => `
6291
- ## High-Reliability Review Workflow
6292
- Follow this sequence with verification at each step:
6293
-
6294
- 1) **Collect context**
6295
- - Get MR metadata via \`get_merge_request({ projectId: $CI_PROJECT_ID, mergeRequestIid })\`.
6296
- - Fetch the full changeset/diffs via \`get_merge_request_diffs\` (or \`list_merge_request_diffs\`) and open discussions via \`mr_discussions\`.
6297
- - **Conversations Intake**: analyze discussions to find latest human notes, detect replies to the agent, and decide between inline reply vs updating your prior note.
6298
-
6299
- 2) **Code review**
6300
- - Identify required changes (bugs, tests, style, security, perf, docs).
6301
- - Always **post your review comments first** using \`create_merge_request_note\` (ack + concrete notes). Sanitize before sending.
6302
- - Set an internal intent flag:
6303
- - \`will_push_changes = true\` if you will modify code/config.
6304
- - \`will_push_changes = false\` if it’s commentary-only.
6305
-
6306
- 3) **Implement changes after review is posted (only if \`will_push_changes = true\`)**
6307
- - If needed, create the working branch from the target/default (or use existing MR source branch).
6308
- - Apply minimal, safe changes; keep commits small and clear.
6309
- - **Push** to the MR's **source branch** via \`push_files\` (or \`create_or_update_file\`).
6310
- - **Verify push landed** using \`get_branch_diffs({ from: "<target_branch>", to: "<source_branch>" })\` and ensure there are diffs.
6311
- - Post a follow-up MR note summarizing what changed and why, **in the appropriate thread** (sanitize).
6239
+ ## MR Workflow
6240
+ 1) get_merge_request + get_merge_request_diffs + mr_discussions
6241
+ 2) Conversations Intake
6242
+ 3) Post review comments first via create_merge_request_note (sanitize)
6243
+ 4) If will_push_changes = true:
6244
+ - push_files to source branch
6245
+ - verify with get_branch_diffs({ from: targetBranch || $CI_DEFAULT_BRANCH, to: sourceBranch })
6246
+ - follow-up note summarizing changes in the right thread (sanitize)
6247
+
6248
+ ## Stdout Summary (MR)
6249
+ Print a plain-text summary with:
6250
+ - action: "mr"
6251
+ - mr_iid
6252
+ - source_branch and target_branch (fallback to $CI_DEFAULT_BRANCH)
6253
+ - will_push_changes: true|false
6254
+ - diff_count (post-push, if applicable)
6255
+ - discussions: number of notes added/updated
6256
+ - ci: whether mr_pipeline_id was resolved
6257
+ - blocking_failed_jobs (names+stages) if inspected
6312
6258
  `;
6259
+ /* ---------- CI Inspection (shared) ---------- */
6313
6260
  const ciInspection = () => `
6314
- 4) **CI jobs (diagnose only; no job retries)**
6315
- - Prefer the **MR pipeline** (not the event pipeline).
6316
- - If you have \`mr_pipeline_id\` (from **Resolve MR Pipeline**):
6317
- - \`list_pipeline_jobs({ projectId: $CI_PROJECT_ID, pipelineId: mr_pipeline_id })\`.
6318
- - Consider **only** jobs with \`status = "failed"\` and \`allow_failure = false\`.
6319
- - For each such job:
6320
- 1. Retrieve details (id, name, stage, status, allow_failure, web_url).
6321
- 2. Fetch job output via \`get_pipeline_job_output({ projectId: $CI_PROJECT_ID, pipelineId: mr_pipeline_id, jobId })\`.
6322
- 3. **Classify the failure**:
6323
- - **Code-related:** compiler/type/lint/test/build script errors. Provide minimal fix in your review/changes. Do **not** retry.
6324
- - **Likely transient / infra:** network/timeouts/cache/artifacts/5xx/429/runner issues. Do **not** retry here; note likely cause and suggest CI-level retry/backoff if appropriate.
6325
- 4. **Decision**:
6326
- - If \`will_push_changes = true\`: do **not** retry; note that the new pipeline from your push will validate fixes.
6327
- - If \`will_push_changes = false\`: do **not** retry; post diagnosis and next steps (or request human input for infra issues).
6328
- - If \`mr_pipeline_id\` is not available, you may skip CI analysis or post a short note explaining the missing pipeline context.
6261
+ ## CI Inspection (diagnose only)
6262
+ - Use mr_pipeline_id if available
6263
+ - list_pipeline_jobs → for each failed + allow_failure=false:
6264
+ - get_pipeline_job_output
6265
+ - classify: code vs infra
6266
+ - Do not retry; only report diagnosis in a note
6267
+ - If no mr_pipeline_id, note limitation
6329
6268
  `;
6330
6269
  const outputDisciplineMR = ({ agentUserName }) => `
6331
6270
  ## Output Discipline (MR)
6332
- - Output only \`gitlab-mcp\` tool calls and the final plain-text summary.
6333
- - Do **not** merge the MR yourself under any circumstance.
6334
- - Never include "@${agentUserName}" in any body.
6271
+ - Only gitlab-mcp calls + final summary
6272
+ - Never merge MR
6273
+ - Never mention "@${agentUserName}"
6335
6274
  `;
6336
- /* ---------- Shared bundle for MR review ---------- */
6275
+ /* ---------- MR Review Bundle ---------- */
6337
6276
  const mrReviewBundle = (ctx) => `
6338
- ## MR Review Mode (execute ONLY when review intent is detected and an MR IID is resolved)
6339
- Resolved MR IID: <set this to the resolved \`mr_iid\` before executing>
6277
+ ## MR Review Mode
6340
6278
  ${mrScope(ctx)}
6341
6279
  ${mrWorkflow()}
6342
6280
  ${ciInspection()}
@@ -6354,12 +6292,12 @@ $(cat $TRIGGER_PAYLOAD)
6354
6292
  ${identity(ctx)}
6355
6293
  ${goldenRules(ctx)}
6356
6294
  ${selfMentionGuard(ctx)}
6357
- ${conversationsIntake(ctx)} <!-- NEW: mandatory before acting -->
6295
+ ${conversationsIntake(ctx)}
6358
6296
  ${eventSelfParse()}
6359
- ${resolveMrPipeline()} <!-- used by review/cancel paths -->
6360
- ${singleRunnerGuard()} <!-- operates on MR pipeline, not event pipeline -->
6297
+ ${resolveMrPipeline()}
6298
+ ${singleRunnerGuard()}
6361
6299
  ${reviewOnDemandFromEvents()}
6362
- ${mrReviewBundle(ctx)} <!-- agent can execute when review intent is true -->
6300
+ ${mrReviewBundle(ctx)}
6363
6301
  ${eventWorkflow(ctx)}
6364
6302
  ${commentGuidelines()}
6365
6303
  ${mcpOnly()}
@@ -6379,7 +6317,7 @@ description: $CI_MERGE_REQUEST_DESCRIPTION
6379
6317
  ${mrScope(ctx)}
6380
6318
  ${goldenRules(ctx)}
6381
6319
  ${selfMentionGuard(ctx)}
6382
- ${conversationsIntake(ctx)} <!-- NEW: always read MR discussions -->
6320
+ ${conversationsIntake(ctx)}
6383
6321
  ${mrWorkflow()}
6384
6322
  ${ciInspection()}
6385
6323
  ${commentGuidelines()}
@@ -6423,7 +6361,7 @@ const callClaude = ({ prompt }) => {
6423
6361
  return [
6424
6362
  `export PROMPT="${(0, bashEscape_1.escapeNewlines)((0, bashEscape_1.escapeDoubleQuotes)((0, bashEscape_1.escapeBackTicks)(prompt)))}"`,
6425
6363
  //'echo "$PROMPT"',
6426
- `claude -p "$PROMPT" --permission-mode acceptEdits --allowedTools "Bash(*) Bash(git checkout:*) Read(*) Edit(*) Write(*) mcp__gitlab" --verbose --debug`,
6364
+ `claude -p "$PROMPT" --permission-mode acceptEdits --allowedTools "Bash Read(*) Edit(*) Write(*) mcp__gitlab" --verbose --debug`,
6427
6365
  ];
6428
6366
  };
6429
6367
  exports.callClaude = callClaude;