@catladder/cli 0.0.0-main-bbb9c8e8 → 0.0.0-main-ee4d2a94
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,9 +6060,9 @@ exports.createJobsForAgentContext = createJobsForAgentContext;
|
|
|
6060
6060
|
|
|
6061
6061
|
"use strict";
|
|
6062
6062
|
|
|
6063
|
-
// prompts.ts — MCP-only, DRY, review-first-then-push, CI
|
|
6063
|
+
// prompts.ts — MCP-only, DRY, review-first-then-push, CI diagnosis (no retries), self-mention guard,
|
|
6064
6064
|
// event prompt supports review-on-demand via manual "agent-review" job or fallback MR review.
|
|
6065
|
-
// Prevents double-runs: event-triggered work cancels any running "agent-review" job on the
|
|
6065
|
+
// Prevents double-runs: event-triggered work cancels any running "agent-review" job on the MR's own pipeline.
|
|
6066
6066
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
6067
6067
|
exports.getMergeRequestPrompt = exports.getEventPrompt = void 0;
|
|
6068
6068
|
/* ---------- Shared blocks ---------- */
|
|
@@ -6140,10 +6140,10 @@ const mcpOnly = () => `
|
|
|
6140
6140
|
- merge_merge_request(...) // **Do NOT use** (never merge)
|
|
6141
6141
|
|
|
6142
6142
|
- **Pipelines / Jobs** (requires env USE_PIPELINE=true)
|
|
6143
|
+
- list_pipelines({ projectId, ref?, sha?, status?, orderBy?, sort? })
|
|
6144
|
+
- get_pipeline({ projectId, pipelineId })
|
|
6143
6145
|
- list_pipeline_jobs({ projectId, pipelineId })
|
|
6144
6146
|
- get_pipeline_job_output({ projectId, pipelineId, jobId })
|
|
6145
|
-
- retry_pipeline({ projectId, pipelineId })
|
|
6146
|
-
- retry_pipeline_job({ projectId, jobId })
|
|
6147
6147
|
- play_pipeline_job({ projectId, jobId })
|
|
6148
6148
|
- cancel_pipeline_job({ projectId, jobId })
|
|
6149
6149
|
`;
|
|
@@ -6167,40 +6167,47 @@ From \`event_json\`, extract:
|
|
|
6167
6167
|
|
|
6168
6168
|
If any key is missing, choose the safest minimal action or briefly explain via a comment.
|
|
6169
6169
|
`;
|
|
6170
|
-
|
|
6170
|
+
/* Helper used by Single-Runner Guard and Review-on-Demand to find the MR’s own pipeline */
|
|
6171
|
+
const resolveMrPipeline = () => `
|
|
6172
|
+
## Resolve MR Pipeline (for MR IID resolved from the event)
|
|
6173
|
+
Given \`mr_iid\`:
|
|
6174
|
+
1) Call \`get_merge_request({ projectId: $CI_PROJECT_ID, mergeRequestIid: mr_iid })\` to obtain:
|
|
6175
|
+
- \`sourceBranch\` (required)
|
|
6176
|
+
- \`sha\` or head SHA (if available)
|
|
6177
|
+
2) Prefer **SHA-based** lookup:
|
|
6178
|
+
- \`list_pipelines({ projectId: $CI_PROJECT_ID, sha })\` ordered by most recent; pick the newest.
|
|
6179
|
+
3) Fallback to **ref-based** lookup if SHA not available:
|
|
6180
|
+
- \`list_pipelines({ projectId: $CI_PROJECT_ID, ref: sourceBranch, orderBy: "updated_at", sort: "desc" })\`; pick the newest.
|
|
6181
|
+
4) The chosen pipeline becomes \`mr_pipeline_id\`. Use it for all job queries/plays/cancels related to this MR.
|
|
6182
|
+
- 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.
|
|
6183
|
+
`;
|
|
6184
|
+
// Updated: operate on the MR’s pipeline, not the event pipeline
|
|
6171
6185
|
const singleRunnerGuard = () => `
|
|
6172
6186
|
## Single-Runner Guard (event-triggered work on an existing MR)
|
|
6173
6187
|
Before entering MR Review Mode from an event:
|
|
6174
6188
|
|
|
6175
|
-
- **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.
|
|
6176
|
-
|
|
6177
|
-
**
|
|
6178
|
-
1)
|
|
6179
|
-
|
|
6180
|
-
-
|
|
6181
|
-
- For
|
|
6182
|
-
|
|
6183
|
-
|
|
6184
|
-
|
|
6185
|
-
- Post a short MR note stating you are proceeding but **cannot verify/cancel** a running \`agent-review\` job due to missing
|
|
6189
|
+
- **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.
|
|
6190
|
+
|
|
6191
|
+
**Procedure (MCP-only):**
|
|
6192
|
+
1) Resolve the MR IID from the event (target URL or text) and run **Resolve MR Pipeline** to get \`mr_pipeline_id\`.
|
|
6193
|
+
2) If \`mr_pipeline_id\` is available:
|
|
6194
|
+
- \`list_pipeline_jobs({ projectId: $CI_PROJECT_ID, pipelineId: mr_pipeline_id })\`.
|
|
6195
|
+
- For any job with \`status\` in \`["running","pending"]\` and \`name\` ending with \`"agent-review"\`, call:
|
|
6196
|
+
- \`cancel_pipeline_job({ projectId: $CI_PROJECT_ID, jobId })\`.
|
|
6197
|
+
- Proceed immediately after issuing cancellations (do not wait).
|
|
6198
|
+
3) If the pipeline cannot be resolved:
|
|
6199
|
+
- Post a short MR note stating you are proceeding but **cannot verify/cancel** a running \`agent-review\` job due to missing pipeline context.
|
|
6186
6200
|
- Proceed with review.
|
|
6187
6201
|
|
|
6188
6202
|
**Notes:**
|
|
6189
6203
|
- Keep this guard **idempotent** (safe to run multiple times).
|
|
6190
|
-
-
|
|
6204
|
+
- Only applies to **event-triggered** flows that act on an **existing MR**.
|
|
6191
6205
|
`;
|
|
6192
6206
|
const reviewOnDemandFromEvents = () => `
|
|
6193
6207
|
## Review-on-Demand (from events)
|
|
6194
6208
|
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:
|
|
6195
6209
|
|
|
6196
|
-
1) **
|
|
6197
|
-
- List jobs for the current pipeline \`$CI_PIPELINE_ID\` via \`list_pipeline_jobs\`.
|
|
6198
|
-
- If any job has \`status = "manual"\` **and** its \`name\` ends with "agent-review":
|
|
6199
|
-
- Trigger it via \`play_pipeline_job({ projectId: $CI_PROJECT_ID, jobId })\`.
|
|
6200
|
-
- Post a short comment confirming you triggered the review job (sanitize).
|
|
6201
|
-
- **Stop** further review actions.
|
|
6202
|
-
|
|
6203
|
-
2) **If no such job exists, resolve which MR to review**:
|
|
6210
|
+
1) **Resolve which MR to review**:
|
|
6204
6211
|
- If the event target is an MR → use its \`iid\`.
|
|
6205
6212
|
- Else, parse the text for MR references in order:
|
|
6206
6213
|
- \`!<iid>\` (e.g., \`!123\`)
|
|
@@ -6208,10 +6215,21 @@ If the issue/note text **asks for a review** (case-insensitive tokens like: "rev
|
|
|
6208
6215
|
- full GitLab MR URL
|
|
6209
6216
|
- If no MR can be resolved, reply with a brief comment asking the user to reference an MR (sanitize) and **stop**.
|
|
6210
6217
|
|
|
6211
|
-
|
|
6212
|
-
- Execute
|
|
6218
|
+
2) **Find the MR's pipeline** (do **not** use \`$CI_PIPELINE_ID\` from the event):
|
|
6219
|
+
- Execute **Resolve MR Pipeline** to obtain \`mr_pipeline_id\`.
|
|
6220
|
+
|
|
6221
|
+
3) **If a manual "agent-review" job exists on the MR pipeline, trigger it**
|
|
6222
|
+
- If \`mr_pipeline_id\` is available:
|
|
6223
|
+
- \`list_pipeline_jobs({ projectId: $CI_PROJECT_ID, pipelineId: mr_pipeline_id })\`.
|
|
6224
|
+
- If any job has \`status = "manual"\` **and** its \`name\` ends with "agent-review":
|
|
6225
|
+
- Trigger via \`play_pipeline_job({ projectId: $CI_PROJECT_ID, jobId })\`.
|
|
6226
|
+
- Post a short comment confirming you triggered the review job (sanitize).
|
|
6227
|
+
- **Stop** further review actions.
|
|
6228
|
+
|
|
6229
|
+
4) **Single-Runner Guard**
|
|
6230
|
+
- 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.
|
|
6213
6231
|
|
|
6214
|
-
|
|
6232
|
+
5) **Enter MR Review Mode**: execute the **MR Review Bundle** below with the resolved \`mr_iid\`.
|
|
6215
6233
|
`;
|
|
6216
6234
|
/** Regular event workflow for non-review work */
|
|
6217
6235
|
const eventWorkflow = ({ agentUserName }) => `
|
|
@@ -6267,30 +6285,21 @@ Follow this sequence with verification at each step:
|
|
|
6267
6285
|
- Post a follow-up MR note summarizing what changed and why (sanitize).
|
|
6268
6286
|
`;
|
|
6269
6287
|
const ciInspection = () => `
|
|
6270
|
-
4) **CI jobs (
|
|
6271
|
-
-
|
|
6272
|
-
-
|
|
6273
|
-
|
|
6274
|
-
|
|
6275
|
-
|
|
6276
|
-
|
|
6277
|
-
|
|
6278
|
-
|
|
6279
|
-
|
|
6280
|
-
|
|
6281
|
-
|
|
6282
|
-
-
|
|
6283
|
-
|
|
6284
|
-
|
|
6285
|
-
Post a note stating you retried and why (sanitize).
|
|
6286
|
-
- If code-related ⇒ do not retry; post a note with diagnosis and suggested fix (sanitize).
|
|
6287
|
-
- Retry-once policy: at most **one** retry per job in this run.
|
|
6288
|
-
|
|
6289
|
-
5) **Assign human reviewer if ready**
|
|
6290
|
-
- 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.
|
|
6291
|
-
|
|
6292
|
-
6) **Stdout summary**
|
|
6293
|
-
- 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.
|
|
6288
|
+
4) **CI jobs (diagnose only; no job retries)**
|
|
6289
|
+
- To analyze CI context during review triggered from events, prefer the **MR pipeline** (not the event pipeline).
|
|
6290
|
+
- If you are in MR Review Mode and have \`mr_pipeline_id\` (from **Resolve MR Pipeline**):
|
|
6291
|
+
- \`list_pipeline_jobs({ projectId: $CI_PROJECT_ID, pipelineId: mr_pipeline_id })\`.
|
|
6292
|
+
- Consider **only** jobs with \`status = "failed"\` and \`allow_failure = false\`.
|
|
6293
|
+
- For each such job:
|
|
6294
|
+
1. Retrieve details (id, name, stage, status, allow_failure, web_url).
|
|
6295
|
+
2. Fetch job output via \`get_pipeline_job_output({ projectId: $CI_PROJECT_ID, pipelineId: mr_pipeline_id, jobId })\`.
|
|
6296
|
+
3. **Classify the failure**:
|
|
6297
|
+
- **Code-related:** compiler/type/lint/test/build script errors. Provide minimal fix in your review/changes. Do **not** retry.
|
|
6298
|
+
- **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.
|
|
6299
|
+
4. **Decision**:
|
|
6300
|
+
- If \`will_push_changes = true\`: do **not** retry; note that the new pipeline from your push will validate fixes.
|
|
6301
|
+
- If \`will_push_changes = false\`: do **not** retry; post diagnosis and next steps (or request human input for infra issues).
|
|
6302
|
+
- If \`mr_pipeline_id\` is not available, you may skip CI analysis or post a short note explaining the missing pipeline context.
|
|
6294
6303
|
`;
|
|
6295
6304
|
const outputDisciplineMR = ({ agentUserName }) => `
|
|
6296
6305
|
## Output Discipline (MR)
|
|
@@ -6320,9 +6329,10 @@ ${identity(ctx)}
|
|
|
6320
6329
|
${goldenRules(ctx)}
|
|
6321
6330
|
${selfMentionGuard(ctx)}
|
|
6322
6331
|
${eventSelfParse()}
|
|
6323
|
-
${
|
|
6332
|
+
${resolveMrPipeline()} <!-- new helper used by review/cancel paths -->
|
|
6333
|
+
${singleRunnerGuard()} <!-- operates on MR pipeline, not event pipeline -->
|
|
6324
6334
|
${reviewOnDemandFromEvents()}
|
|
6325
|
-
${mrReviewBundle(ctx)}
|
|
6335
|
+
${mrReviewBundle(ctx)} <!-- included so the agent can execute it when review intent is true -->
|
|
6326
6336
|
${eventWorkflow(ctx)}
|
|
6327
6337
|
${commentGuidelines()}
|
|
6328
6338
|
${mcpOnly()}
|
|
@@ -9242,9 +9242,9 @@ exports.createJobsForAgentContext = createJobsForAgentContext;
|
|
|
9242
9242
|
|
|
9243
9243
|
"use strict";
|
|
9244
9244
|
|
|
9245
|
-
// prompts.ts — MCP-only, DRY, review-first-then-push, CI
|
|
9245
|
+
// prompts.ts — MCP-only, DRY, review-first-then-push, CI diagnosis (no retries), self-mention guard,
|
|
9246
9246
|
// event prompt supports review-on-demand via manual "agent-review" job or fallback MR review.
|
|
9247
|
-
// Prevents double-runs: event-triggered work cancels any running "agent-review" job on the
|
|
9247
|
+
// Prevents double-runs: event-triggered work cancels any running "agent-review" job on the MR's own pipeline.
|
|
9248
9248
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
9249
9249
|
exports.getMergeRequestPrompt = exports.getEventPrompt = void 0;
|
|
9250
9250
|
/* ---------- Shared blocks ---------- */
|
|
@@ -9322,10 +9322,10 @@ const mcpOnly = () => `
|
|
|
9322
9322
|
- merge_merge_request(...) // **Do NOT use** (never merge)
|
|
9323
9323
|
|
|
9324
9324
|
- **Pipelines / Jobs** (requires env USE_PIPELINE=true)
|
|
9325
|
+
- list_pipelines({ projectId, ref?, sha?, status?, orderBy?, sort? })
|
|
9326
|
+
- get_pipeline({ projectId, pipelineId })
|
|
9325
9327
|
- list_pipeline_jobs({ projectId, pipelineId })
|
|
9326
9328
|
- get_pipeline_job_output({ projectId, pipelineId, jobId })
|
|
9327
|
-
- retry_pipeline({ projectId, pipelineId })
|
|
9328
|
-
- retry_pipeline_job({ projectId, jobId })
|
|
9329
9329
|
- play_pipeline_job({ projectId, jobId })
|
|
9330
9330
|
- cancel_pipeline_job({ projectId, jobId })
|
|
9331
9331
|
`;
|
|
@@ -9349,40 +9349,47 @@ From \`event_json\`, extract:
|
|
|
9349
9349
|
|
|
9350
9350
|
If any key is missing, choose the safest minimal action or briefly explain via a comment.
|
|
9351
9351
|
`;
|
|
9352
|
-
|
|
9352
|
+
/* Helper used by Single-Runner Guard and Review-on-Demand to find the MR’s own pipeline */
|
|
9353
|
+
const resolveMrPipeline = () => `
|
|
9354
|
+
## Resolve MR Pipeline (for MR IID resolved from the event)
|
|
9355
|
+
Given \`mr_iid\`:
|
|
9356
|
+
1) Call \`get_merge_request({ projectId: $CI_PROJECT_ID, mergeRequestIid: mr_iid })\` to obtain:
|
|
9357
|
+
- \`sourceBranch\` (required)
|
|
9358
|
+
- \`sha\` or head SHA (if available)
|
|
9359
|
+
2) Prefer **SHA-based** lookup:
|
|
9360
|
+
- \`list_pipelines({ projectId: $CI_PROJECT_ID, sha })\` ordered by most recent; pick the newest.
|
|
9361
|
+
3) Fallback to **ref-based** lookup if SHA not available:
|
|
9362
|
+
- \`list_pipelines({ projectId: $CI_PROJECT_ID, ref: sourceBranch, orderBy: "updated_at", sort: "desc" })\`; pick the newest.
|
|
9363
|
+
4) The chosen pipeline becomes \`mr_pipeline_id\`. Use it for all job queries/plays/cancels related to this MR.
|
|
9364
|
+
- 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.
|
|
9365
|
+
`;
|
|
9366
|
+
// Updated: operate on the MR’s pipeline, not the event pipeline
|
|
9353
9367
|
const singleRunnerGuard = () => `
|
|
9354
9368
|
## Single-Runner Guard (event-triggered work on an existing MR)
|
|
9355
9369
|
Before entering MR Review Mode from an event:
|
|
9356
9370
|
|
|
9357
|
-
- **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.
|
|
9358
|
-
|
|
9359
|
-
**
|
|
9360
|
-
1)
|
|
9361
|
-
|
|
9362
|
-
-
|
|
9363
|
-
- For
|
|
9364
|
-
|
|
9365
|
-
|
|
9366
|
-
|
|
9367
|
-
- Post a short MR note stating you are proceeding but **cannot verify/cancel** a running \`agent-review\` job due to missing
|
|
9371
|
+
- **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.
|
|
9372
|
+
|
|
9373
|
+
**Procedure (MCP-only):**
|
|
9374
|
+
1) Resolve the MR IID from the event (target URL or text) and run **Resolve MR Pipeline** to get \`mr_pipeline_id\`.
|
|
9375
|
+
2) If \`mr_pipeline_id\` is available:
|
|
9376
|
+
- \`list_pipeline_jobs({ projectId: $CI_PROJECT_ID, pipelineId: mr_pipeline_id })\`.
|
|
9377
|
+
- For any job with \`status\` in \`["running","pending"]\` and \`name\` ending with \`"agent-review"\`, call:
|
|
9378
|
+
- \`cancel_pipeline_job({ projectId: $CI_PROJECT_ID, jobId })\`.
|
|
9379
|
+
- Proceed immediately after issuing cancellations (do not wait).
|
|
9380
|
+
3) If the pipeline cannot be resolved:
|
|
9381
|
+
- Post a short MR note stating you are proceeding but **cannot verify/cancel** a running \`agent-review\` job due to missing pipeline context.
|
|
9368
9382
|
- Proceed with review.
|
|
9369
9383
|
|
|
9370
9384
|
**Notes:**
|
|
9371
9385
|
- Keep this guard **idempotent** (safe to run multiple times).
|
|
9372
|
-
-
|
|
9386
|
+
- Only applies to **event-triggered** flows that act on an **existing MR**.
|
|
9373
9387
|
`;
|
|
9374
9388
|
const reviewOnDemandFromEvents = () => `
|
|
9375
9389
|
## Review-on-Demand (from events)
|
|
9376
9390
|
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:
|
|
9377
9391
|
|
|
9378
|
-
1) **
|
|
9379
|
-
- List jobs for the current pipeline \`$CI_PIPELINE_ID\` via \`list_pipeline_jobs\`.
|
|
9380
|
-
- If any job has \`status = "manual"\` **and** its \`name\` ends with "agent-review":
|
|
9381
|
-
- Trigger it via \`play_pipeline_job({ projectId: $CI_PROJECT_ID, jobId })\`.
|
|
9382
|
-
- Post a short comment confirming you triggered the review job (sanitize).
|
|
9383
|
-
- **Stop** further review actions.
|
|
9384
|
-
|
|
9385
|
-
2) **If no such job exists, resolve which MR to review**:
|
|
9392
|
+
1) **Resolve which MR to review**:
|
|
9386
9393
|
- If the event target is an MR → use its \`iid\`.
|
|
9387
9394
|
- Else, parse the text for MR references in order:
|
|
9388
9395
|
- \`!<iid>\` (e.g., \`!123\`)
|
|
@@ -9390,10 +9397,21 @@ If the issue/note text **asks for a review** (case-insensitive tokens like: "rev
|
|
|
9390
9397
|
- full GitLab MR URL
|
|
9391
9398
|
- If no MR can be resolved, reply with a brief comment asking the user to reference an MR (sanitize) and **stop**.
|
|
9392
9399
|
|
|
9393
|
-
|
|
9394
|
-
- Execute
|
|
9400
|
+
2) **Find the MR's pipeline** (do **not** use \`$CI_PIPELINE_ID\` from the event):
|
|
9401
|
+
- Execute **Resolve MR Pipeline** to obtain \`mr_pipeline_id\`.
|
|
9402
|
+
|
|
9403
|
+
3) **If a manual "agent-review" job exists on the MR pipeline, trigger it**
|
|
9404
|
+
- If \`mr_pipeline_id\` is available:
|
|
9405
|
+
- \`list_pipeline_jobs({ projectId: $CI_PROJECT_ID, pipelineId: mr_pipeline_id })\`.
|
|
9406
|
+
- If any job has \`status = "manual"\` **and** its \`name\` ends with "agent-review":
|
|
9407
|
+
- Trigger via \`play_pipeline_job({ projectId: $CI_PROJECT_ID, jobId })\`.
|
|
9408
|
+
- Post a short comment confirming you triggered the review job (sanitize).
|
|
9409
|
+
- **Stop** further review actions.
|
|
9410
|
+
|
|
9411
|
+
4) **Single-Runner Guard**
|
|
9412
|
+
- 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.
|
|
9395
9413
|
|
|
9396
|
-
|
|
9414
|
+
5) **Enter MR Review Mode**: execute the **MR Review Bundle** below with the resolved \`mr_iid\`.
|
|
9397
9415
|
`;
|
|
9398
9416
|
/** Regular event workflow for non-review work */
|
|
9399
9417
|
const eventWorkflow = ({ agentUserName }) => `
|
|
@@ -9449,30 +9467,21 @@ Follow this sequence with verification at each step:
|
|
|
9449
9467
|
- Post a follow-up MR note summarizing what changed and why (sanitize).
|
|
9450
9468
|
`;
|
|
9451
9469
|
const ciInspection = () => `
|
|
9452
|
-
4) **CI jobs (
|
|
9453
|
-
-
|
|
9454
|
-
-
|
|
9455
|
-
|
|
9456
|
-
|
|
9457
|
-
|
|
9458
|
-
|
|
9459
|
-
|
|
9460
|
-
|
|
9461
|
-
|
|
9462
|
-
|
|
9463
|
-
|
|
9464
|
-
-
|
|
9465
|
-
|
|
9466
|
-
|
|
9467
|
-
Post a note stating you retried and why (sanitize).
|
|
9468
|
-
- If code-related ⇒ do not retry; post a note with diagnosis and suggested fix (sanitize).
|
|
9469
|
-
- Retry-once policy: at most **one** retry per job in this run.
|
|
9470
|
-
|
|
9471
|
-
5) **Assign human reviewer if ready**
|
|
9472
|
-
- 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.
|
|
9473
|
-
|
|
9474
|
-
6) **Stdout summary**
|
|
9475
|
-
- 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.
|
|
9470
|
+
4) **CI jobs (diagnose only; no job retries)**
|
|
9471
|
+
- To analyze CI context during review triggered from events, prefer the **MR pipeline** (not the event pipeline).
|
|
9472
|
+
- If you are in MR Review Mode and have \`mr_pipeline_id\` (from **Resolve MR Pipeline**):
|
|
9473
|
+
- \`list_pipeline_jobs({ projectId: $CI_PROJECT_ID, pipelineId: mr_pipeline_id })\`.
|
|
9474
|
+
- Consider **only** jobs with \`status = "failed"\` and \`allow_failure = false\`.
|
|
9475
|
+
- For each such job:
|
|
9476
|
+
1. Retrieve details (id, name, stage, status, allow_failure, web_url).
|
|
9477
|
+
2. Fetch job output via \`get_pipeline_job_output({ projectId: $CI_PROJECT_ID, pipelineId: mr_pipeline_id, jobId })\`.
|
|
9478
|
+
3. **Classify the failure**:
|
|
9479
|
+
- **Code-related:** compiler/type/lint/test/build script errors. Provide minimal fix in your review/changes. Do **not** retry.
|
|
9480
|
+
- **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.
|
|
9481
|
+
4. **Decision**:
|
|
9482
|
+
- If \`will_push_changes = true\`: do **not** retry; note that the new pipeline from your push will validate fixes.
|
|
9483
|
+
- If \`will_push_changes = false\`: do **not** retry; post diagnosis and next steps (or request human input for infra issues).
|
|
9484
|
+
- If \`mr_pipeline_id\` is not available, you may skip CI analysis or post a short note explaining the missing pipeline context.
|
|
9476
9485
|
`;
|
|
9477
9486
|
const outputDisciplineMR = ({ agentUserName }) => `
|
|
9478
9487
|
## Output Discipline (MR)
|
|
@@ -9502,9 +9511,10 @@ ${identity(ctx)}
|
|
|
9502
9511
|
${goldenRules(ctx)}
|
|
9503
9512
|
${selfMentionGuard(ctx)}
|
|
9504
9513
|
${eventSelfParse()}
|
|
9505
|
-
${
|
|
9514
|
+
${resolveMrPipeline()} <!-- new helper used by review/cancel paths -->
|
|
9515
|
+
${singleRunnerGuard()} <!-- operates on MR pipeline, not event pipeline -->
|
|
9506
9516
|
${reviewOnDemandFromEvents()}
|
|
9507
|
-
${mrReviewBundle(ctx)}
|
|
9517
|
+
${mrReviewBundle(ctx)} <!-- included so the agent can execute it when review intent is true -->
|
|
9508
9518
|
${eventWorkflow(ctx)}
|
|
9509
9519
|
${commentGuidelines()}
|
|
9510
9520
|
${mcpOnly()}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// prompts.ts — MCP-only, DRY, review-first-then-push, CI
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
124
|
-
|
|
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
|
-
-
|
|
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) **
|
|
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
|
-
|
|
151
|
-
- Execute
|
|
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) **
|
|
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 (
|
|
210
|
-
-
|
|
211
|
-
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
-
|
|
222
|
-
|
|
223
|
-
|
|
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
|
-
${
|
|
271
|
+
${resolveMrPipeline()} <!-- new helper used by review/cancel paths -->
|
|
272
|
+
${singleRunnerGuard()} <!-- operates on MR pipeline, not event pipeline -->
|
|
263
273
|
${reviewOnDemandFromEvents()}
|
|
264
|
-
${mrReviewBundle(ctx)}
|
|
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,
|
|
1
|
+
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../../../../../pipeline/src/pipeline/agent/prompts.ts"],"names":[],"mappings":"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"}
|