@catladder/cli 0.0.0-main-bbb9c8e8 → 0.0.0-main-4fc3c2ec

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.
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
- // prompts.ts — MCP-only, DRY, review-first-then-push, CI logic, self-mention guard,
2
+ // prompts.ts — MCP-only, DRY, review-first-then-push, CI diagnosis (no retries), self-mention guard,
3
3
  // event prompt supports review-on-demand via manual "agent-review" job or fallback MR review.
4
- // Prevents double-runs: event-triggered work cancels any running "agent-review" job on the same MR.
4
+ // Prevents double-runs: event-triggered work cancels any running "agent-review" job on the MR's own pipeline.
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getMergeRequestPrompt = exports.getEventPrompt = void 0;
7
7
  /* ---------- Shared blocks ---------- */
@@ -79,10 +79,10 @@ const mcpOnly = () => `
79
79
  - merge_merge_request(...) // **Do NOT use** (never merge)
80
80
 
81
81
  - **Pipelines / Jobs** (requires env USE_PIPELINE=true)
82
+ - list_pipelines({ projectId, ref?, sha?, status?, orderBy?, sort? })
83
+ - get_pipeline({ projectId, pipelineId })
82
84
  - list_pipeline_jobs({ projectId, pipelineId })
83
85
  - get_pipeline_job_output({ projectId, pipelineId, jobId })
84
- - retry_pipeline({ projectId, pipelineId })
85
- - retry_pipeline_job({ projectId, jobId })
86
86
  - play_pipeline_job({ projectId, jobId })
87
87
  - cancel_pipeline_job({ projectId, jobId })
88
88
  `;
@@ -106,40 +106,47 @@ From \`event_json\`, extract:
106
106
 
107
107
  If any key is missing, choose the safest minimal action or briefly explain via a comment.
108
108
  `;
109
- // NEW: Single-runner guard (event-triggered → existing MR)
109
+ /* Helper used by Single-Runner Guard and Review-on-Demand to find the MR’s own pipeline */
110
+ const resolveMrPipeline = () => `
111
+ ## Resolve MR Pipeline (for MR IID resolved from the event)
112
+ Given \`mr_iid\`:
113
+ 1) Call \`get_merge_request({ projectId: $CI_PROJECT_ID, mergeRequestIid: mr_iid })\` to obtain:
114
+ - \`sourceBranch\` (required)
115
+ - \`sha\` or head SHA (if available)
116
+ 2) Prefer **SHA-based** lookup:
117
+ - \`list_pipelines({ projectId: $CI_PROJECT_ID, sha })\` ordered by most recent; pick the newest.
118
+ 3) Fallback to **ref-based** lookup if SHA not available:
119
+ - \`list_pipelines({ projectId: $CI_PROJECT_ID, ref: sourceBranch, orderBy: "updated_at", sort: "desc" })\`; pick the newest.
120
+ 4) The chosen pipeline becomes \`mr_pipeline_id\`. Use it for all job queries/plays/cancels related to this MR.
121
+ - 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.
122
+ `;
123
+ // Updated: operate on the MR’s pipeline, not the event pipeline
110
124
  const singleRunnerGuard = () => `
111
125
  ## Single-Runner Guard (event-triggered work on an existing MR)
112
126
  Before entering MR Review Mode from an event:
113
127
 
114
- - **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, **cancel** it first.
115
-
116
- **Best-effort procedure (MCP-only):**
117
- 1) If \`$CI_PIPELINE_ID\` is available (this event is executing inside a CI context for the same MR):
118
- - Call \`list_pipeline_jobs({ projectId: $CI_PROJECT_ID, pipelineId: $CI_PIPELINE_ID })\`.
119
- - Identify any job where \`status\` is \`"running"\` or \`"pending"\` **and** \`name\` **endsWith** \`"agent-review"\`.
120
- - For each match, call \`cancel_pipeline_job({ projectId: $CI_PROJECT_ID, jobId })\`.
121
- - Proceed with review immediately after issuing cancellations (do not wait).
128
+ - **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.
122
129
 
123
- 2) If \`$CI_PIPELINE_ID\` is **not** available, or jobs for this MR cannot be listed with available MCP calls:
124
- - Post a short MR note stating you are proceeding but **cannot verify/cancel** a running \`agent-review\` job due to missing capabilities.
130
+ **Procedure (MCP-only):**
131
+ 1) Resolve the MR IID from the event (target URL or text) and run **Resolve MR Pipeline** to get \`mr_pipeline_id\`.
132
+ 2) If \`mr_pipeline_id\` is available:
133
+ - \`list_pipeline_jobs({ projectId: $CI_PROJECT_ID, pipelineId: mr_pipeline_id })\`.
134
+ - For any job with \`status\` in \`["running","pending"]\` and \`name\` ending with \`"agent-review"\`, call:
135
+ - \`cancel_pipeline_job({ projectId: $CI_PROJECT_ID, jobId })\`.
136
+ - Proceed immediately after issuing cancellations (do not wait).
137
+ 3) If the pipeline cannot be resolved:
138
+ - Post a short MR note stating you are proceeding but **cannot verify/cancel** a running \`agent-review\` job due to missing pipeline context.
125
139
  - Proceed with review.
126
140
 
127
141
  **Notes:**
128
142
  - Keep this guard **idempotent** (safe to run multiple times).
129
- - This guard only applies to **event-triggered** flows that decide to act on an **existing MR**.
143
+ - Only applies to **event-triggered** flows that act on an **existing MR**.
130
144
  `;
131
145
  const reviewOnDemandFromEvents = () => `
132
146
  ## Review-on-Demand (from events)
133
147
  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:
134
148
 
135
- 1) **Check for pipeline review job**
136
- - List jobs for the current pipeline \`$CI_PIPELINE_ID\` via \`list_pipeline_jobs\`.
137
- - If any job has \`status = "manual"\` **and** its \`name\` ends with "agent-review":
138
- - Trigger it via \`play_pipeline_job({ projectId: $CI_PROJECT_ID, jobId })\`.
139
- - Post a short comment confirming you triggered the review job (sanitize).
140
- - **Stop** further review actions.
141
-
142
- 2) **If no such job exists, resolve which MR to review**:
149
+ 1) **Resolve which MR to review**:
143
150
  - If the event target is an MR → use its \`iid\`.
144
151
  - Else, parse the text for MR references in order:
145
152
  - \`!<iid>\` (e.g., \`!123\`)
@@ -147,10 +154,21 @@ If the issue/note text **asks for a review** (case-insensitive tokens like: "rev
147
154
  - full GitLab MR URL
148
155
  - If no MR can be resolved, reply with a brief comment asking the user to reference an MR (sanitize) and **stop**.
149
156
 
150
- 3) **Single-Runner Guard (cancel any running "agent-review" job)** // NEW: Single-runner guard
151
- - Execute the **Single-Runner Guard** steps above **before** MR Review Mode.
157
+ 2) **Find the MR's pipeline** (do **not** use \`$CI_PIPELINE_ID\` from the event):
158
+ - Execute **Resolve MR Pipeline** to obtain \`mr_pipeline_id\`.
159
+
160
+ 3) **If a manual "agent-review" job exists on the MR pipeline, trigger it**
161
+ - If \`mr_pipeline_id\` is available:
162
+ - \`list_pipeline_jobs({ projectId: $CI_PROJECT_ID, pipelineId: mr_pipeline_id })\`.
163
+ - If any job has \`status = "manual"\` **and** its \`name\` ends with "agent-review":
164
+ - Trigger via \`play_pipeline_job({ projectId: $CI_PROJECT_ID, jobId })\`.
165
+ - Post a short comment confirming you triggered the review job (sanitize).
166
+ - **Stop** further review actions.
152
167
 
153
- 4) **Enter MR Review Mode**: execute the **MR Review Bundle** below with the resolved \`mr_iid\`.
168
+ 4) **Single-Runner Guard**
169
+ - 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.
170
+
171
+ 5) **Enter MR Review Mode**: execute the **MR Review Bundle** below with the resolved \`mr_iid\`.
154
172
  `;
155
173
  /** Regular event workflow for non-review work */
156
174
  const eventWorkflow = ({ agentUserName }) => `
@@ -206,30 +224,21 @@ Follow this sequence with verification at each step:
206
224
  - Post a follow-up MR note summarizing what changed and why (sanitize).
207
225
  `;
208
226
  const ciInspection = () => `
209
- 4) **CI jobs (current pipeline focus: diagnose first, retry only when useful)**
210
- - Inspect jobs for the **current pipeline**: \`$CI_PIPELINE_ID\` via \`list_pipeline_jobs\`.
211
- - Consider **only** jobs with \`status = "failed"\` and \`allow_failure = false\`.
212
- - For each such job:
213
- 1. Retrieve details (id, name, stage, status, allow_failure, web_url).
214
- 2. Fetch job output via \`get_pipeline_job_output({ projectId: $CI_PROJECT_ID, pipelineId: $CI_PIPELINE_ID, jobId })\`.
215
- 3. **Classify the failure**:
216
- - **Code-related (do not retry):** compiler/type/lint/test/build script errors.
217
- - **Likely transient (may retry):** network/timeouts/infra/cache/artifacts/5xx/429/etc.
218
- 4. **Decision**:
219
- - If \`will_push_changes = true\`:
220
- - **Do not retry** current pipeline (upcoming push will trigger a new one).
221
- - Post an MR note: brief diagnosis per failed job; note a new pipeline will validate the fix (sanitize).
222
- - If \`will_push_changes = false\`:
223
- - If transient ⇒ \`retry_pipeline_job({ projectId: $CI_PROJECT_ID, jobId })\` (or \`retry_pipeline\` if job-level retry not available).
224
- Post a note stating you retried and why (sanitize).
225
- - If code-related ⇒ do not retry; post a note with diagnosis and suggested fix (sanitize).
226
- - Retry-once policy: at most **one** retry per job in this run.
227
-
228
- 5) **Assign human reviewer if ready**
229
- - If discussions are resolved and blocking CI issues are addressed or clearly triaged, request review from a recent active human contributor (not you), if supported by your environment.
230
-
231
- 6) **Stdout summary**
232
- - Print concise summary: branch used, files changed count (approx by diffs), discussions resolved/left, **blocking failed jobs (names + stages)** with classification (code vs transient), which jobs were retried (if any), and requested reviewers.
227
+ 4) **CI jobs (diagnose only; no job retries)**
228
+ - To analyze CI context during review triggered from events, prefer the **MR pipeline** (not the event pipeline).
229
+ - If you are in MR Review Mode and have \`mr_pipeline_id\` (from **Resolve MR Pipeline**):
230
+ - \`list_pipeline_jobs({ projectId: $CI_PROJECT_ID, pipelineId: mr_pipeline_id })\`.
231
+ - Consider **only** jobs with \`status = "failed"\` and \`allow_failure = false\`.
232
+ - For each such job:
233
+ 1. Retrieve details (id, name, stage, status, allow_failure, web_url).
234
+ 2. Fetch job output via \`get_pipeline_job_output({ projectId: $CI_PROJECT_ID, pipelineId: mr_pipeline_id, jobId })\`.
235
+ 3. **Classify the failure**:
236
+ - **Code-related:** compiler/type/lint/test/build script errors. Provide minimal fix in your review/changes. Do **not** retry.
237
+ - **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.
238
+ 4. **Decision**:
239
+ - If \`will_push_changes = true\`: do **not** retry; note that the new pipeline from your push will validate fixes.
240
+ - If \`will_push_changes = false\`: do **not** retry; post diagnosis and next steps (or request human input for infra issues).
241
+ - If \`mr_pipeline_id\` is not available, you may skip CI analysis or post a short note explaining the missing pipeline context.
233
242
  `;
234
243
  const outputDisciplineMR = ({ agentUserName }) => `
235
244
  ## Output Discipline (MR)
@@ -259,9 +268,10 @@ ${identity(ctx)}
259
268
  ${goldenRules(ctx)}
260
269
  ${selfMentionGuard(ctx)}
261
270
  ${eventSelfParse()}
262
- ${singleRunnerGuard()} <!-- NEW: included so the agent can run it when acting on an existing MR -->
271
+ ${resolveMrPipeline()} <!-- new helper used by review/cancel paths -->
272
+ ${singleRunnerGuard()} <!-- operates on MR pipeline, not event pipeline -->
263
273
  ${reviewOnDemandFromEvents()}
264
- ${mrReviewBundle(ctx)} <!-- Included so the agent can execute it when review intent is true -->
274
+ ${mrReviewBundle(ctx)} <!-- included so the agent can execute it when review intent is true -->
265
275
  ${eventWorkflow(ctx)}
266
276
  ${commentGuidelines()}
267
277
  ${mcpOnly()}
@@ -1 +1 @@
1
- {"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../../../../../pipeline/src/pipeline/agent/prompts.ts"],"names":[],"mappings":";AAAA,oFAAoF;AACpF,8FAA8F;AAC9F,oGAAoG;;;AAIpG,yCAAyC;AAEzC,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC;;;CAGpB,CAAC;AAEF,MAAM,QAAQ,GAAG,CAAC,EAAE,aAAa,EAAO,EAAE,EAAE,CAAC;;6BAEhB,aAAa;CACzC,CAAC;AAEF,MAAM,WAAW,GAAG,CAAC,EAAE,aAAa,EAAO,EAAE,EAAE,CAAC;;;;8BAIlB,aAAa;;;;;;CAM1C,CAAC;AAEF,MAAM,gBAAgB,GAAG,CAAC,EAAE,aAAa,EAAO,EAAE,EAAE,CAAC;;;;;qCAKhB,aAAa;;;;;;yDAMO,aAAa;;CAErE,CAAC;AAEF,MAAM,iBAAiB,GAAG,GAAG,EAAE,CAAC;;;;;;;;CAQ/B,CAAC;AAEF,8E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