@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.
@@ -9291,15 +9291,18 @@ exports.createJobsForAgentContext = createJobsForAgentContext;
9291
9291
 
9292
9292
  "use strict";
9293
9293
 
9294
- // prompts.ts — MCP-only, DRY, review-first-then-push, CI diagnosis (no retries), self-mention guard,
9295
- // conversations-aware: always read the thread first (issues & MRs), reply inline, avoid duplicates.
9296
- // Prevents double-runs: event-triggered work cancels any running "agent-review" job on the MR's own pipeline.
9294
+ // prompts.ts — MCP-only, DRY, review-first-then-push, CI diagnosis (no retries),
9295
+ // self-mention guard, conversations-aware (issues & MRs), inline replies, de-duplication.
9296
+ // Review-on-demand: resolves MR pipeline and triggers manual "agent-review" when present.
9297
+ // Single-runner guard: cancels running "agent-review" on the MR pipeline before acting.
9298
+ // Stdout summaries included for both event and MR flows.
9297
9299
  Object.defineProperty(exports, "__esModule", ({ value: true }));
9298
9300
  exports.getMergeRequestPrompt = exports.getEventPrompt = void 0;
9299
9301
  /* ---------- Shared blocks ---------- */
9300
9302
  const header = () => `
9301
9303
  Project ID: $CI_PROJECT_ID
9302
9304
  GitLab Host: $CI_SERVER_URL
9305
+ Default Branch: $CI_DEFAULT_BRANCH
9303
9306
  `;
9304
9307
  const identity = ({ agentUserName }) => `
9305
9308
  ## Identity
@@ -9316,87 +9319,64 @@ const goldenRules = ({ agentUserName }) => `
9316
9319
  - Keep actions minimal and idempotent. Avoid duplicate comments or duplicate MRs.
9317
9320
  - Use ONE stable \`source_branch\` per run; do not regenerate its name later.
9318
9321
  `;
9319
- /* ---------- NEW: conversation intake + threading rules ---------- */
9322
+ /* ---------- Conversations + threading ---------- */
9320
9323
  const conversationsIntake = ({ agentUserName }) => `
9321
9324
  ## Conversations Intake & Threading (MANDATORY before acting)
9322
9325
  Always load and reason about the current conversation to avoid duplicates and to respond in the right place.
9323
9326
 
9324
- ### What to fetch
9325
- - **MRs**: Use \`mr_discussions({ projectId: $CI_PROJECT_ID, mergeRequestIid })\` to load all threads and notes.
9326
- - **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.
9327
-
9328
- ### How to use it
9329
- 1) **Detect review/answer context**:
9330
- - Identify the **latest human note** in the thread (exclude notes authored by "${agentUserName}").
9331
- - If the latest human note **replies to you** (mentions you or is in a discussion you started), reply **in the same discussion**.
9332
- 2) **De-duplication**:
9333
- - 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:
9334
- - Use \`update_merge_request_note\` or \`update_issue_note\` accordingly.
9335
- 3) **Reply placement**:
9336
- - For MR code discussions: reply **inline in the same discussion** (preserve thread context).
9337
- - For general/MR overview threads: add a single consolidated reply (avoid multiple scattered notes).
9338
- 4) **Sanitize before write**:
9339
- - Apply the Self-mention Guard, then post.
9340
- 5) **If conversations list is unavailable**:
9341
- - Post one short note: that you cannot fetch the full conversation due to missing MCP capability, then proceed minimally (no spam).
9327
+ - **MRs**: Use \`mr_discussions({ projectId: $CI_PROJECT_ID, mergeRequestIid })\`.
9328
+ - **Issues**: Use issue discussions if available; if not, rely on event payload and note IDs.
9329
+
9330
+ Rules:
9331
+ 1) Detect latest human note (exclude "${agentUserName}"). If it replies to you or is in a discussion you started, reply **in the same thread**.
9332
+ 2) If your last message is still the latest and no one else replied, prefer **update_note** instead of creating a new one.
9333
+ 3) For MR code discussions: reply inline in the same discussion.
9334
+ 4) Always sanitize (see Self-mention Guard) before writing.
9342
9335
  `;
9343
9336
  const selfMentionGuard = ({ agentUserName }) => `
9344
- ## Self-mention Guard (mandatory preflight for ALL writes)
9345
- Before ANY call that writes text (comment/create/update MR/issue/commit message), sanitize the text:
9346
-
9347
- - Remove all occurrences of your own handle:
9348
- - Match case-insensitively: \`/@?${agentUserName}\\b/gi\`
9349
- - Also strip variants inside parentheses or brackets if present.
9350
- - Do NOT replace with another token; simply remove the self @-mention.
9351
- - If after sanitization the body becomes empty/meaningless, skip the write.
9352
-
9353
- Additionally:
9354
- - If the last actor/author of the target item is you ("${agentUserName}"), **do not** post an acknowledgement comment (avoid loops on your own events).
9355
- - To assign yourself, use the MCP assignee field(s). Do **not** mention yourself in the body to indicate assignment.
9337
+ ## Self-mention Guard
9338
+ Before ANY write (comment/MR/issue/commit message):
9339
+ - Remove all occurrences of "@${agentUserName}" (case-insensitive).
9340
+ - If the text becomes empty, skip the write.
9341
+ - If the last actor is you, skip acknowledgement comments.
9342
+ - To assign yourself, use assignee fields, not mentions.
9356
9343
  `;
9357
9344
  const commentGuidelines = () => `
9358
- ## Comment Guidelines (flexible, not verbatim)
9345
+ ## Comment Guidelines
9359
9346
  - Professional, friendly, concise.
9360
9347
  - Always @-mention the human author when replying; never mention yourself.
9361
- - Acknowledgements: confirm you saw the request and you’ll handle it.
9362
- - MR updates: acknowledge feedback and say you’ll apply/have applied the change.
9363
- - Q&A: answer directly first; add context/links only if useful.
9364
- - Avoid repeating identical boilerplate across comments.
9348
+ - Acknowledge requests, answer questions directly, confirm fixes or updates.
9349
+ - Avoid repeating boilerplate.
9365
9350
  `;
9366
- /* Exact tool names from @zereight/mcp-gitlab (lean, indicative signatures) */
9351
+ /* ---------- gitlab-mcp tool usage ---------- */
9367
9352
  const mcpOnly = () => `
9368
- ## gitlab-mcp Operations (exact tool names; indicative params)
9353
+ ## gitlab-mcp Operations
9369
9354
 
9370
9355
  - **Comments / Notes**
9371
- - create_note({ projectId, targetType: "issue"|"merge_request", iid, body })
9372
9356
  - create_issue_note({ projectId, issueIid, body })
9373
- - create_merge_request_note({ projectId, mergeRequestIid, body })
9374
9357
  - update_issue_note({ projectId, issueIid, noteId, body })
9358
+ - create_merge_request_note({ projectId, mergeRequestIid, body })
9375
9359
  - update_merge_request_note({ projectId, mergeRequestIid, noteId, body })
9376
9360
  - mr_discussions({ projectId, mergeRequestIid })
9377
9361
 
9378
9362
  - **Issues**
9379
9363
  - create_issue({ projectId, title, description, assigneeUsernames?: string[] })
9380
- - list_issues({ projectId, state?: "opened"|"closed", scope?: "all"|... })
9381
9364
 
9382
9365
  - **Branch & Files**
9383
9366
  - create_branch({ projectId, branchName, ref })
9384
9367
  - push_files({ projectId, branch, commitMessage, files: [{ filePath, content }] })
9385
9368
  - create_or_update_file({ projectId, branch, filePath, content, commitMessage })
9386
- - get_file_contents({ projectId, ref, path })
9387
9369
  - get_branch_diffs({ projectId, from, to })
9388
9370
 
9389
9371
  - **Merge Requests**
9390
9372
  - create_merge_request({ projectId, sourceBranch, targetBranch, title, description, assigneeUsernames?: string[] })
9391
- - get_merge_request({ projectId, mergeRequestIid? , branchName? })
9392
- - get_merge_request_diffs({ projectId, mergeRequestIid? , branchName? })
9393
- - list_merge_request_diffs({ projectId, mergeRequestIid? , branchName?, page?, perPage? })
9394
- - update_merge_request({ projectId, mergeRequestIid? , branchName?, title?, description?, draft?, assigneeUsernames? })
9395
- - merge_merge_request(...) // **Do NOT use** (never merge)
9373
+ - get_merge_request({ projectId, mergeRequestIid })
9374
+ - get_merge_request_diffs({ projectId, mergeRequestIid })
9375
+ - list_merge_request_diffs({ projectId, mergeRequestIid, page?, perPage? })
9376
+ - update_merge_request({ projectId, mergeRequestIid, title?, description?, draft?, assigneeUsernames? })
9396
9377
 
9397
- - **Pipelines / Jobs** (requires env USE_PIPELINE=true)
9378
+ - **Pipelines / Jobs**
9398
9379
  - list_pipelines({ projectId, ref?, sha?, status?, orderBy?, sort? })
9399
- - get_pipeline({ projectId, pipelineId })
9400
9380
  - list_pipeline_jobs({ projectId, pipelineId })
9401
9381
  - get_pipeline_job_output({ projectId, pipelineId, jobId })
9402
9382
  - play_pipeline_job({ projectId, jobId })
@@ -9408,166 +9388,124 @@ const outputDiscipline = ({ agentUserName }) => `
9408
9388
  - Keep comments concise and professional.
9409
9389
  - Never include "@${agentUserName}" in any body.
9410
9390
  `;
9411
- /* ---------- Event (webhook) specific ---------- */
9391
+ /* ---------- Event-specific helpers ---------- */
9412
9392
  const eventSelfParse = () => `
9413
- ## Self-Parse the Raw Payload (no preprocessing available)
9393
+ ## Self-Parse Raw Payload
9414
9394
  From \`event_json\`, extract:
9415
9395
  - kind: "issue" | "merge_request" | "note"
9416
- - target + iid from URL:
9417
- - \`/-/issues/<n>\` → target="issue", iid=<n>
9418
- - \`/-/merge_requests/<n>\` → target="mr", iid=<n>
9419
- - note_id if present (\`#note_<id>\`)
9420
- - description/body text, state, author \`user_username\`, timestamps
9421
- - project id/path; detect default branch via \`get_merge_request\`/context as needed
9422
- - If available: the discussion id / thread context of the note to enable inline replies.
9396
+ - iid from URL (/issues/<n>, /merge_requests/<n>)
9397
+ - note_id if present (#note_<id>)
9398
+ - description/body, state, author, timestamps
9399
+ - project id/path
9400
+ - discussion id if available for inline replies
9423
9401
  `;
9424
- /* Helper used by Single-Runner Guard and Review-on-Demand to find the MR’s own pipeline */
9402
+ /* Resolve MR pipeline from MR IID */
9425
9403
  const resolveMrPipeline = () => `
9426
- ## Resolve MR Pipeline (for MR IID resolved from the event)
9427
- Given \`mr_iid\`:
9428
- 1) Call \`get_merge_request({ projectId: $CI_PROJECT_ID, mergeRequestIid: mr_iid })\` to obtain:
9429
- - \`sourceBranch\` (required)
9430
- - \`sha\` or head SHA (if available)
9431
- 2) Prefer **SHA-based** lookup:
9432
- - \`list_pipelines({ projectId: $CI_PROJECT_ID, sha })\` ordered by most recent; pick the newest.
9433
- 3) Fallback to **ref-based** lookup if SHA not available:
9434
- - \`list_pipelines({ projectId: $CI_PROJECT_ID, ref: sourceBranch, orderBy: "updated_at", sort: "desc" })\`; pick the newest.
9435
- 4) The chosen pipeline becomes \`mr_pipeline_id\`. Use it for all job queries/plays/cancels related to this MR.
9436
- - 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.
9404
+ ## Resolve MR Pipeline
9405
+ 1) get_merge_request({ projectId, mergeRequestIid }) → sourceBranch, sha
9406
+ 2) Prefer: list_pipelines({ projectId, sha })
9407
+ 3) Else: list_pipelines({ projectId, ref: sourceBranch, orderBy: "updated_at", sort: "desc" })
9408
+ 4) Pick newest → mr_pipeline_id
9437
9409
  `;
9410
+ /* Guard against double agent-review jobs */
9438
9411
  const singleRunnerGuard = () => `
9439
- ## Single-Runner Guard (event-triggered work on an existing MR)
9440
- Before entering MR Review Mode from an event:
9441
-
9442
- - **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.
9443
-
9444
- **Procedure (MCP-only):**
9445
- 1) Resolve the MR IID from the event (target URL or text) and run **Resolve MR Pipeline** to get \`mr_pipeline_id\`.
9446
- 2) If \`mr_pipeline_id\` is available:
9447
- - \`list_pipeline_jobs({ projectId: $CI_PROJECT_ID, pipelineId: mr_pipeline_id })\`.
9448
- - For any job with \`status\` in \`["running","pending"]\` and \`name\` ending with \`"agent-review"\`, call:
9449
- - \`cancel_pipeline_job({ projectId: $CI_PROJECT_ID, jobId })\`.
9450
- - Proceed immediately after issuing cancellations (do not wait).
9451
- 3) If the pipeline cannot be resolved:
9452
- - Post a short MR note stating you are proceeding but **cannot verify/cancel** a running \`agent-review\` job due to missing pipeline context.
9453
- - Proceed with review.
9454
-
9455
- **Notes:**
9456
- - Keep this guard **idempotent** (safe to run multiple times).
9457
- - Only applies to **event-triggered** flows that act on an **existing MR**.
9412
+ ## Single-Runner Guard
9413
+ - If mr_pipeline_id available:
9414
+ - list_pipeline_jobs({ projectId, pipelineId: mr_pipeline_id })
9415
+ - cancel_pipeline_job on any running/pending job ending with "agent-review"
9416
+ - If not available, note limitation and proceed
9458
9417
  `;
9418
+ /* If user asks for review from an event, try manual agent-review job first on the MR's pipeline */
9459
9419
  const reviewOnDemandFromEvents = () => `
9460
- ## Review-on-Demand (from events)
9461
- 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:
9462
-
9463
- 1) **Resolve which MR to review**:
9464
- - If the event target is an MR → use its \`iid\`.
9465
- - Else, parse the text for MR references in order:
9466
- - \`!<iid>\` (e.g., \`!123\`)
9467
- - \`/-/merge_requests/<iid>\` in a path or URL
9468
- - full GitLab MR URL
9469
- - If no MR can be resolved, reply with a brief comment asking the user to reference an MR (sanitize) and **stop**.
9470
-
9471
- 2) **Find the MR's pipeline** (do **not** use \`$CI_PIPELINE_ID\` from the event):
9472
- - Execute **Resolve MR Pipeline** to obtain \`mr_pipeline_id\`.
9473
-
9474
- 3) **If a manual "agent-review" job exists on the MR pipeline, trigger it**
9475
- - If \`mr_pipeline_id\` is available:
9476
- - \`list_pipeline_jobs({ projectId: $CI_PROJECT_ID, pipelineId: mr_pipeline_id })\`.
9477
- - If any job has \`status = "manual"\` **and** its \`name\` ends with "agent-review":
9478
- - Trigger via \`play_pipeline_job({ projectId: $CI_PROJECT_ID, jobId })\`.
9479
- - **Conversations Intake**: run the section above to determine **where** to post the confirmation (prefer replying in the same thread that requested review).
9480
- - Post a short comment confirming you triggered the review job (sanitize).
9481
- - **Stop** further review actions.
9482
-
9483
- 4) **Single-Runner Guard**
9484
- - 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.
9485
-
9486
- 5) **Enter MR Review Mode**: execute the **MR Review Bundle** below with the resolved \`mr_iid\`.
9420
+ ## Review-on-Demand
9421
+ If the text asks for a review ("review", "please review", "PTAL", "needs review", "can you look at", "LGTM?"):
9422
+ 1) Resolve MR IID (from target or text).
9423
+ 2) Resolve MR pipeline (do NOT use the event pipeline).
9424
+ 3) If a manual "agent-review" job exists, play it → confirm in-thread → STOP.
9425
+ 4) Else run Single-Runner Guard, then enter MR Review Mode.
9487
9426
  `;
9488
- /** Regular event workflow for non-review work */
9427
+ /* ---------- Event workflow ---------- */
9489
9428
  const eventWorkflow = ({ agentUserName }) => `
9490
- ## High-Reliability Workflow (sequence + postconditions)
9491
- Follow this order for any change work:
9492
-
9493
- 0) **Conversations Intake (MANDATORY)**:
9494
- - For MR targets: call \`mr_discussions\` and apply the rules in **Conversations Intake & Threading**.
9495
- - For issue targets: attempt to load notes if supported; otherwise rely on event context and post one concise note acknowledging the limitation.
9496
-
9497
- 1) **Acknowledge** with a short comment on the issue/MR thread (\`create_note\`), **unless the last actor is you**.
9498
- 2) **Discover default branch** (e.g., "main") — infer from repo/MR context if needed.
9499
- 3) **Create a working branch** from default (stable name, e.g., \`fix/issue-<iid>-<slug>\` or \`feat/issue-<iid>-<slug>\`) via \`create_branch\`.
9500
- 4) **Write changes → commit → push to remote branch** via \`push_files\` (or \`create_or_update_file\`).
9501
- 5) **Verify push landed**:
9502
- - Fetch latest state and ensure diffs via \`get_branch_diffs({ from: "<default>", to: "<source>" })\`.
9503
- 6) **Create or update MR** ONLY if there is a non-empty diff via \`create_merge_request\`.
9504
- - Include \`Closes #<issue_iid>\` in MR description when applicable.
9505
- - **Assign the MR to yourself**: \`assigneeUsernames: ["${agentUserName}"]\`.
9506
- 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).
9507
- 8) **If verification fails**:
9508
- - Do NOT create the MR.
9509
- - Comment the exact failure and retry once with a fresh branch name. If still failing, comment and stop.
9510
-
9511
- For Q&A-only (no code changes), run **Conversations Intake** first, then post a single concise, helpful answer **in the correct thread** (sanitize).
9429
+ ## Event Workflow
9430
+ 0) Conversations Intake first
9431
+ 1) Acknowledge with note (unless last actor is you)
9432
+ 2) Default branch: use \`$CI_DEFAULT_BRANCH\`
9433
+ 3) Create branch from \`$CI_DEFAULT_BRANCH\`:
9434
+ create_branch({ projectId: $CI_PROJECT_ID, branchName: "<source_branch>", ref: $CI_DEFAULT_BRANCH })
9435
+ 4) Write changes → commit → push:
9436
+ push_files({ projectId: $CI_PROJECT_ID, branch: "<source_branch>", commitMessage, files })
9437
+ 5) Verify:
9438
+ get_branch_diffs({ projectId: $CI_PROJECT_ID, from: $CI_DEFAULT_BRANCH, to: "<source_branch>" })
9439
+ - Require non-empty diffs
9440
+ 6) Create MR (if diffs exist):
9441
+ create_merge_request({
9442
+ projectId: $CI_PROJECT_ID,
9443
+ sourceBranch: "<source_branch>",
9444
+ targetBranch: $CI_DEFAULT_BRANCH,
9445
+ title,
9446
+ description, // include "Closes #<issue_iid>" when applicable
9447
+ assigneeUsernames: ["${agentUserName}"]
9448
+ })
9449
+ 7) Follow-up note (in correct thread) with branch, short SHA if available, files-changed count, and MR link (unless last actor is you)
9450
+ 8) If verification fails: comment error and STOP
9451
+
9452
+ ## Stdout Summary (Event)
9453
+ Print a plain-text summary with:
9454
+ - action: "event"
9455
+ - source_branch
9456
+ - target_branch: $CI_DEFAULT_BRANCH
9457
+ - diff_count (from get_branch_diffs)
9458
+ - mr_iid and/or mr_url if created
9459
+ - any note ids created/updated
9460
+ - any limitations encountered (e.g., missing discussions tool)
9512
9461
  `;
9513
- /* ---------- MR-review specific (shared with both prompts) ---------- */
9462
+ /* ---------- MR-specific ---------- */
9514
9463
  const mrScope = ({ agentUserName }) => `
9515
- ## Identity & Scope
9516
- - Your GitLab username is "${agentUserName}".
9517
- - This prompt runs in the context of ONE MR.
9518
- - You may review, comment, and push updates **to the MR's source branch**.
9519
- - You must **never merge** the MR yourself.
9464
+ ## MR Scope
9465
+ - You are reviewing a single MR
9466
+ - Never merge the MR yourself
9467
+ - Work only on the MR's source branch
9520
9468
  `;
9521
9469
  const mrWorkflow = () => `
9522
- ## High-Reliability Review Workflow
9523
- Follow this sequence with verification at each step:
9524
-
9525
- 1) **Collect context**
9526
- - Get MR metadata via \`get_merge_request({ projectId: $CI_PROJECT_ID, mergeRequestIid })\`.
9527
- - Fetch the full changeset/diffs via \`get_merge_request_diffs\` (or \`list_merge_request_diffs\`) and open discussions via \`mr_discussions\`.
9528
- - **Conversations Intake**: analyze discussions to find latest human notes, detect replies to the agent, and decide between inline reply vs updating your prior note.
9529
-
9530
- 2) **Code review**
9531
- - Identify required changes (bugs, tests, style, security, perf, docs).
9532
- - Always **post your review comments first** using \`create_merge_request_note\` (ack + concrete notes). Sanitize before sending.
9533
- - Set an internal intent flag:
9534
- - \`will_push_changes = true\` if you will modify code/config.
9535
- - \`will_push_changes = false\` if it’s commentary-only.
9536
-
9537
- 3) **Implement changes after review is posted (only if \`will_push_changes = true\`)**
9538
- - If needed, create the working branch from the target/default (or use existing MR source branch).
9539
- - Apply minimal, safe changes; keep commits small and clear.
9540
- - **Push** to the MR's **source branch** via \`push_files\` (or \`create_or_update_file\`).
9541
- - **Verify push landed** using \`get_branch_diffs({ from: "<target_branch>", to: "<source_branch>" })\` and ensure there are diffs.
9542
- - Post a follow-up MR note summarizing what changed and why, **in the appropriate thread** (sanitize).
9470
+ ## MR Workflow
9471
+ 1) get_merge_request + get_merge_request_diffs + mr_discussions
9472
+ 2) Conversations Intake
9473
+ 3) Post review comments first via create_merge_request_note (sanitize)
9474
+ 4) If will_push_changes = true:
9475
+ - push_files to source branch
9476
+ - verify with get_branch_diffs({ from: targetBranch || $CI_DEFAULT_BRANCH, to: sourceBranch })
9477
+ - follow-up note summarizing changes in the right thread (sanitize)
9478
+
9479
+ ## Stdout Summary (MR)
9480
+ Print a plain-text summary with:
9481
+ - action: "mr"
9482
+ - mr_iid
9483
+ - source_branch and target_branch (fallback to $CI_DEFAULT_BRANCH)
9484
+ - will_push_changes: true|false
9485
+ - diff_count (post-push, if applicable)
9486
+ - discussions: number of notes added/updated
9487
+ - ci: whether mr_pipeline_id was resolved
9488
+ - blocking_failed_jobs (names+stages) if inspected
9543
9489
  `;
9490
+ /* ---------- CI Inspection (shared) ---------- */
9544
9491
  const ciInspection = () => `
9545
- 4) **CI jobs (diagnose only; no job retries)**
9546
- - Prefer the **MR pipeline** (not the event pipeline).
9547
- - If you have \`mr_pipeline_id\` (from **Resolve MR Pipeline**):
9548
- - \`list_pipeline_jobs({ projectId: $CI_PROJECT_ID, pipelineId: mr_pipeline_id })\`.
9549
- - Consider **only** jobs with \`status = "failed"\` and \`allow_failure = false\`.
9550
- - For each such job:
9551
- 1. Retrieve details (id, name, stage, status, allow_failure, web_url).
9552
- 2. Fetch job output via \`get_pipeline_job_output({ projectId: $CI_PROJECT_ID, pipelineId: mr_pipeline_id, jobId })\`.
9553
- 3. **Classify the failure**:
9554
- - **Code-related:** compiler/type/lint/test/build script errors. Provide minimal fix in your review/changes. Do **not** retry.
9555
- - **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.
9556
- 4. **Decision**:
9557
- - If \`will_push_changes = true\`: do **not** retry; note that the new pipeline from your push will validate fixes.
9558
- - If \`will_push_changes = false\`: do **not** retry; post diagnosis and next steps (or request human input for infra issues).
9559
- - If \`mr_pipeline_id\` is not available, you may skip CI analysis or post a short note explaining the missing pipeline context.
9492
+ ## CI Inspection (diagnose only)
9493
+ - Use mr_pipeline_id if available
9494
+ - list_pipeline_jobs → for each failed + allow_failure=false:
9495
+ - get_pipeline_job_output
9496
+ - classify: code vs infra
9497
+ - Do not retry; only report diagnosis in a note
9498
+ - If no mr_pipeline_id, note limitation
9560
9499
  `;
9561
9500
  const outputDisciplineMR = ({ agentUserName }) => `
9562
9501
  ## Output Discipline (MR)
9563
- - Output only \`gitlab-mcp\` tool calls and the final plain-text summary.
9564
- - Do **not** merge the MR yourself under any circumstance.
9565
- - Never include "@${agentUserName}" in any body.
9502
+ - Only gitlab-mcp calls + final summary
9503
+ - Never merge MR
9504
+ - Never mention "@${agentUserName}"
9566
9505
  `;
9567
- /* ---------- Shared bundle for MR review ---------- */
9506
+ /* ---------- MR Review Bundle ---------- */
9568
9507
  const mrReviewBundle = (ctx) => `
9569
- ## MR Review Mode (execute ONLY when review intent is detected and an MR IID is resolved)
9570
- Resolved MR IID: <set this to the resolved \`mr_iid\` before executing>
9508
+ ## MR Review Mode
9571
9509
  ${mrScope(ctx)}
9572
9510
  ${mrWorkflow()}
9573
9511
  ${ciInspection()}
@@ -9585,12 +9523,12 @@ $(cat $TRIGGER_PAYLOAD)
9585
9523
  ${identity(ctx)}
9586
9524
  ${goldenRules(ctx)}
9587
9525
  ${selfMentionGuard(ctx)}
9588
- ${conversationsIntake(ctx)} <!-- NEW: mandatory before acting -->
9526
+ ${conversationsIntake(ctx)}
9589
9527
  ${eventSelfParse()}
9590
- ${resolveMrPipeline()} <!-- used by review/cancel paths -->
9591
- ${singleRunnerGuard()} <!-- operates on MR pipeline, not event pipeline -->
9528
+ ${resolveMrPipeline()}
9529
+ ${singleRunnerGuard()}
9592
9530
  ${reviewOnDemandFromEvents()}
9593
- ${mrReviewBundle(ctx)} <!-- agent can execute when review intent is true -->
9531
+ ${mrReviewBundle(ctx)}
9594
9532
  ${eventWorkflow(ctx)}
9595
9533
  ${commentGuidelines()}
9596
9534
  ${mcpOnly()}
@@ -9610,7 +9548,7 @@ description: $CI_MERGE_REQUEST_DESCRIPTION
9610
9548
  ${mrScope(ctx)}
9611
9549
  ${goldenRules(ctx)}
9612
9550
  ${selfMentionGuard(ctx)}
9613
- ${conversationsIntake(ctx)} <!-- NEW: always read MR discussions -->
9551
+ ${conversationsIntake(ctx)}
9614
9552
  ${mrWorkflow()}
9615
9553
  ${ciInspection()}
9616
9554
  ${commentGuidelines()}
@@ -9654,7 +9592,7 @@ const callClaude = ({ prompt }) => {
9654
9592
  return [
9655
9593
  `export PROMPT="${(0, bashEscape_1.escapeNewlines)((0, bashEscape_1.escapeDoubleQuotes)((0, bashEscape_1.escapeBackTicks)(prompt)))}"`,
9656
9594
  //'echo "$PROMPT"',
9657
- `claude -p "$PROMPT" --permission-mode acceptEdits --allowedTools "Bash(*) Bash(git checkout:*) Read(*) Edit(*) Write(*) mcp__gitlab" --verbose --debug`,
9595
+ `claude -p "$PROMPT" --permission-mode acceptEdits --allowedTools "Bash Read(*) Edit(*) Write(*) mcp__gitlab" --verbose --debug`,
9658
9596
  ];
9659
9597
  };
9660
9598
  exports.callClaude = callClaude;