@catladder/cli 0.0.0-main-ee4d2a94 → 0.0.0-main-aafb3c3b

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.
@@ -6061,7 +6061,7 @@ exports.createJobsForAgentContext = createJobsForAgentContext;
6061
6061
  "use strict";
6062
6062
 
6063
6063
  // prompts.ts — MCP-only, DRY, review-first-then-push, CI diagnosis (no retries), self-mention guard,
6064
- // event prompt supports review-on-demand via manual "agent-review" job or fallback MR review.
6064
+ // conversations-aware: always read the thread first (issues & MRs), reply inline, avoid duplicates.
6065
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;
@@ -6085,6 +6085,30 @@ const goldenRules = ({ agentUserName }) => `
6085
6085
  - Keep actions minimal and idempotent. Avoid duplicate comments or duplicate MRs.
6086
6086
  - Use ONE stable \`source_branch\` per run; do not regenerate its name later.
6087
6087
  `;
6088
+ /* ---------- NEW: conversation intake + threading rules ---------- */
6089
+ const conversationsIntake = ({ agentUserName }) => `
6090
+ ## Conversations Intake & Threading (MANDATORY before acting)
6091
+ Always load and reason about the current conversation to avoid duplicates and to respond in the right place.
6092
+
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).
6111
+ `;
6088
6112
  const selfMentionGuard = ({ agentUserName }) => `
6089
6113
  ## Self-mention Guard (mandatory preflight for ALL writes)
6090
6114
  Before ANY call that writes text (comment/create/update MR/issue/commit message), sanitize the text:
@@ -6125,11 +6149,11 @@ const mcpOnly = () => `
6125
6149
  - list_issues({ projectId, state?: "opened"|"closed", scope?: "all"|... })
6126
6150
 
6127
6151
  - **Branch & Files**
6128
- - create_branch({ projectId, branchName, ref }) // ref = default branch or SHA
6152
+ - create_branch({ projectId, branchName, ref })
6129
6153
  - push_files({ projectId, branch, commitMessage, files: [{ filePath, content }] })
6130
6154
  - create_or_update_file({ projectId, branch, filePath, content, commitMessage })
6131
6155
  - get_file_contents({ projectId, ref, path })
6132
- - get_branch_diffs({ projectId, from, to }) // compare refs
6156
+ - get_branch_diffs({ projectId, from, to })
6133
6157
 
6134
6158
  - **Merge Requests**
6135
6159
  - create_merge_request({ projectId, sourceBranch, targetBranch, title, description, assigneeUsernames?: string[] })
@@ -6164,8 +6188,7 @@ From \`event_json\`, extract:
6164
6188
  - note_id if present (\`#note_<id>\`)
6165
6189
  - description/body text, state, author \`user_username\`, timestamps
6166
6190
  - project id/path; detect default branch via \`get_merge_request\`/context as needed
6167
-
6168
- If any key is missing, choose the safest minimal action or briefly explain via a comment.
6191
+ - If available: the discussion id / thread context of the note to enable inline replies.
6169
6192
  `;
6170
6193
  /* Helper used by Single-Runner Guard and Review-on-Demand to find the MR’s own pipeline */
6171
6194
  const resolveMrPipeline = () => `
@@ -6181,7 +6204,6 @@ Given \`mr_iid\`:
6181
6204
  4) The chosen pipeline becomes \`mr_pipeline_id\`. Use it for all job queries/plays/cancels related to this MR.
6182
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.
6183
6206
  `;
6184
- // Updated: operate on the MR’s pipeline, not the event pipeline
6185
6207
  const singleRunnerGuard = () => `
6186
6208
  ## Single-Runner Guard (event-triggered work on an existing MR)
6187
6209
  Before entering MR Review Mode from an event:
@@ -6223,6 +6245,7 @@ If the issue/note text **asks for a review** (case-insensitive tokens like: "rev
6223
6245
  - \`list_pipeline_jobs({ projectId: $CI_PROJECT_ID, pipelineId: mr_pipeline_id })\`.
6224
6246
  - If any job has \`status = "manual"\` **and** its \`name\` ends with "agent-review":
6225
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).
6226
6249
  - Post a short comment confirming you triggered the review job (sanitize).
6227
6250
  - **Stop** further review actions.
6228
6251
 
@@ -6236,22 +6259,25 @@ const eventWorkflow = ({ agentUserName }) => `
6236
6259
  ## High-Reliability Workflow (sequence + postconditions)
6237
6260
  Follow this order for any change work:
6238
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
+
6239
6266
  1) **Acknowledge** with a short comment on the issue/MR thread (\`create_note\`), **unless the last actor is you**.
6240
6267
  2) **Discover default branch** (e.g., "main") — infer from repo/MR context if needed.
6241
6268
  3) **Create a working branch** from default (stable name, e.g., \`fix/issue-<iid>-<slug>\` or \`feat/issue-<iid>-<slug>\`) via \`create_branch\`.
6242
6269
  4) **Write changes → commit → push to remote branch** via \`push_files\` (or \`create_or_update_file\`).
6243
6270
  5) **Verify push landed**:
6244
- - Fetch latest state (optional: \`get_file_contents\`/log) and capture a short SHA from the branch head if exposed by the host.
6245
- - Compare default vs \`source_branch\` via \`get_branch_diffs({ from: "<default>", to: "<source>" })\` and ensure there are diffs.
6271
+ - Fetch latest state and ensure diffs via \`get_branch_diffs({ from: "<default>", to: "<source>" })\`.
6246
6272
  6) **Create or update MR** ONLY if there is a non-empty diff via \`create_merge_request\`.
6247
6273
  - Include \`Closes #<issue_iid>\` in MR description when applicable.
6248
6274
  - **Assign the MR to yourself**: \`assigneeUsernames: ["${agentUserName}"]\`.
6249
- 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**.
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).
6250
6276
  8) **If verification fails**:
6251
6277
  - Do NOT create the MR.
6252
6278
  - Comment the exact failure and retry once with a fresh branch name. If still failing, comment and stop.
6253
6279
 
6254
- For Q&A-only (no code changes), just post a concise, helpful answer on the same issue/MR (sanitize first).
6280
+ For Q&A-only (no code changes), run **Conversations Intake** first, then post a single concise, helpful answer **in the correct thread** (sanitize).
6255
6281
  `;
6256
6282
  /* ---------- MR-review specific (shared with both prompts) ---------- */
6257
6283
  const mrScope = ({ agentUserName }) => `
@@ -6268,7 +6294,7 @@ Follow this sequence with verification at each step:
6268
6294
  1) **Collect context**
6269
6295
  - Get MR metadata via \`get_merge_request({ projectId: $CI_PROJECT_ID, mergeRequestIid })\`.
6270
6296
  - Fetch the full changeset/diffs via \`get_merge_request_diffs\` (or \`list_merge_request_diffs\`) and open discussions via \`mr_discussions\`.
6271
- - Read existing notes to avoid duplication.
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.
6272
6298
 
6273
6299
  2) **Code review**
6274
6300
  - Identify required changes (bugs, tests, style, security, perf, docs).
@@ -6282,12 +6308,12 @@ Follow this sequence with verification at each step:
6282
6308
  - Apply minimal, safe changes; keep commits small and clear.
6283
6309
  - **Push** to the MR's **source branch** via \`push_files\` (or \`create_or_update_file\`).
6284
6310
  - **Verify push landed** using \`get_branch_diffs({ from: "<target_branch>", to: "<source_branch>" })\` and ensure there are diffs.
6285
- - Post a follow-up MR note summarizing what changed and why (sanitize).
6311
+ - Post a follow-up MR note summarizing what changed and why, **in the appropriate thread** (sanitize).
6286
6312
  `;
6287
6313
  const ciInspection = () => `
6288
6314
  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**):
6315
+ - Prefer the **MR pipeline** (not the event pipeline).
6316
+ - If you have \`mr_pipeline_id\` (from **Resolve MR Pipeline**):
6291
6317
  - \`list_pipeline_jobs({ projectId: $CI_PROJECT_ID, pipelineId: mr_pipeline_id })\`.
6292
6318
  - Consider **only** jobs with \`status = "failed"\` and \`allow_failure = false\`.
6293
6319
  - For each such job:
@@ -6328,11 +6354,12 @@ $(cat $TRIGGER_PAYLOAD)
6328
6354
  ${identity(ctx)}
6329
6355
  ${goldenRules(ctx)}
6330
6356
  ${selfMentionGuard(ctx)}
6357
+ ${conversationsIntake(ctx)} <!-- NEW: mandatory before acting -->
6331
6358
  ${eventSelfParse()}
6332
- ${resolveMrPipeline()} <!-- new helper used by review/cancel paths -->
6333
- ${singleRunnerGuard()} <!-- operates on MR pipeline, not event pipeline -->
6359
+ ${resolveMrPipeline()} <!-- used by review/cancel paths -->
6360
+ ${singleRunnerGuard()} <!-- operates on MR pipeline, not event pipeline -->
6334
6361
  ${reviewOnDemandFromEvents()}
6335
- ${mrReviewBundle(ctx)} <!-- included so the agent can execute it when review intent is true -->
6362
+ ${mrReviewBundle(ctx)} <!-- agent can execute when review intent is true -->
6336
6363
  ${eventWorkflow(ctx)}
6337
6364
  ${commentGuidelines()}
6338
6365
  ${mcpOnly()}
@@ -6352,6 +6379,7 @@ description: $CI_MERGE_REQUEST_DESCRIPTION
6352
6379
  ${mrScope(ctx)}
6353
6380
  ${goldenRules(ctx)}
6354
6381
  ${selfMentionGuard(ctx)}
6382
+ ${conversationsIntake(ctx)} <!-- NEW: always read MR discussions -->
6355
6383
  ${mrWorkflow()}
6356
6384
  ${ciInspection()}
6357
6385
  ${commentGuidelines()}
@@ -2071,6 +2071,7 @@ exports.setupAgents = void 0;
2071
2071
  const gitlab_1 = __nccwpck_require__(12927);
2072
2072
  const getProjectConfig_1 = __nccwpck_require__(12145);
2073
2073
  const gitProjectInformation_1 = __nccwpck_require__(78329);
2074
+ const git_1 = __nccwpck_require__(85096);
2074
2075
  const listTriggerTokens = async (instance, projectId) => {
2075
2076
  return await (0, gitlab_1.doGitlabRequest)(instance, `projects/${projectId}/triggers`);
2076
2077
  };
@@ -2092,7 +2093,8 @@ const updateWebhook = async (instance, projectId, hookId, webhookData) => {
2092
2093
  const setupAgentWebhook = async (instance, projectId, agentName, triggerToken) => {
2093
2094
  const webhookName = `cl_agent_${agentName}_webhook`;
2094
2095
  const { gitRemoteHost } = await (0, gitProjectInformation_1.getGitRemoteHostAndPath)();
2095
- const webhookUrl = `https://${gitRemoteHost}/api/v4/projects/${projectId}/ref/main/trigger/pipeline?token=${triggerToken}`;
2096
+ const mainBranch = await (0, git_1.getMainBranch)();
2097
+ const webhookUrl = `https://${gitRemoteHost}/api/v4/projects/${projectId}/ref/${mainBranch}/trigger/pipeline?token=${triggerToken}`;
2096
2098
  instance.log(`Setting up webhook for agent: ${agentName}`);
2097
2099
  // List existing webhooks
2098
2100
  const existingWebhooks = await listWebhooks(instance, projectId);
@@ -3157,6 +3159,23 @@ const hash = (str, length) => {
3157
3159
 
3158
3160
  /***/ }),
3159
3161
 
3162
+ /***/ 60906:
3163
+ /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
3164
+
3165
+ "use strict";
3166
+
3167
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
3168
+ exports.getMainBranch = void 0;
3169
+ const child_process_promise_1 = __nccwpck_require__(75763);
3170
+ const getMainBranch = async () => {
3171
+ const { stdout } = await (0, child_process_promise_1.exec)("git rev-parse --abbrev-ref HEAD");
3172
+ return stdout.trim();
3173
+ };
3174
+ exports.getMainBranch = getMainBranch;
3175
+ //# sourceMappingURL=getGetMainBranch.js.map
3176
+
3177
+ /***/ }),
3178
+
3160
3179
  /***/ 72745:
3161
3180
  /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
3162
3181
 
@@ -3225,6 +3244,33 @@ exports.gitProjectInformation = gitProjectInformation;
3225
3244
 
3226
3245
  /***/ }),
3227
3246
 
3247
+ /***/ 85096:
3248
+ /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
3249
+
3250
+ "use strict";
3251
+
3252
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3253
+ if (k2 === undefined) k2 = k;
3254
+ var desc = Object.getOwnPropertyDescriptor(m, k);
3255
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
3256
+ desc = { enumerable: true, get: function() { return m[k]; } };
3257
+ }
3258
+ Object.defineProperty(o, k2, desc);
3259
+ }) : (function(o, m, k, k2) {
3260
+ if (k2 === undefined) k2 = k;
3261
+ o[k2] = m[k];
3262
+ }));
3263
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
3264
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
3265
+ };
3266
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
3267
+ __exportStar(__nccwpck_require__(72745), exports);
3268
+ __exportStar(__nccwpck_require__(78329), exports);
3269
+ __exportStar(__nccwpck_require__(60906), exports);
3270
+ //# sourceMappingURL=index.js.map
3271
+
3272
+ /***/ }),
3273
+
3228
3274
  /***/ 79672:
3229
3275
  /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
3230
3276
 
@@ -9243,7 +9289,7 @@ exports.createJobsForAgentContext = createJobsForAgentContext;
9243
9289
  "use strict";
9244
9290
 
9245
9291
  // prompts.ts — MCP-only, DRY, review-first-then-push, CI diagnosis (no retries), self-mention guard,
9246
- // event prompt supports review-on-demand via manual "agent-review" job or fallback MR review.
9292
+ // conversations-aware: always read the thread first (issues & MRs), reply inline, avoid duplicates.
9247
9293
  // Prevents double-runs: event-triggered work cancels any running "agent-review" job on the MR's own pipeline.
9248
9294
  Object.defineProperty(exports, "__esModule", ({ value: true }));
9249
9295
  exports.getMergeRequestPrompt = exports.getEventPrompt = void 0;
@@ -9267,6 +9313,30 @@ const goldenRules = ({ agentUserName }) => `
9267
9313
  - Keep actions minimal and idempotent. Avoid duplicate comments or duplicate MRs.
9268
9314
  - Use ONE stable \`source_branch\` per run; do not regenerate its name later.
9269
9315
  `;
9316
+ /* ---------- NEW: conversation intake + threading rules ---------- */
9317
+ const conversationsIntake = ({ agentUserName }) => `
9318
+ ## Conversations Intake & Threading (MANDATORY before acting)
9319
+ Always load and reason about the current conversation to avoid duplicates and to respond in the right place.
9320
+
9321
+ ### What to fetch
9322
+ - **MRs**: Use \`mr_discussions({ projectId: $CI_PROJECT_ID, mergeRequestIid })\` to load all threads and notes.
9323
+ - **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.
9324
+
9325
+ ### How to use it
9326
+ 1) **Detect review/answer context**:
9327
+ - Identify the **latest human note** in the thread (exclude notes authored by "${agentUserName}").
9328
+ - If the latest human note **replies to you** (mentions you or is in a discussion you started), reply **in the same discussion**.
9329
+ 2) **De-duplication**:
9330
+ - 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:
9331
+ - Use \`update_merge_request_note\` or \`update_issue_note\` accordingly.
9332
+ 3) **Reply placement**:
9333
+ - For MR code discussions: reply **inline in the same discussion** (preserve thread context).
9334
+ - For general/MR overview threads: add a single consolidated reply (avoid multiple scattered notes).
9335
+ 4) **Sanitize before write**:
9336
+ - Apply the Self-mention Guard, then post.
9337
+ 5) **If conversations list is unavailable**:
9338
+ - Post one short note: that you cannot fetch the full conversation due to missing MCP capability, then proceed minimally (no spam).
9339
+ `;
9270
9340
  const selfMentionGuard = ({ agentUserName }) => `
9271
9341
  ## Self-mention Guard (mandatory preflight for ALL writes)
9272
9342
  Before ANY call that writes text (comment/create/update MR/issue/commit message), sanitize the text:
@@ -9307,11 +9377,11 @@ const mcpOnly = () => `
9307
9377
  - list_issues({ projectId, state?: "opened"|"closed", scope?: "all"|... })
9308
9378
 
9309
9379
  - **Branch & Files**
9310
- - create_branch({ projectId, branchName, ref }) // ref = default branch or SHA
9380
+ - create_branch({ projectId, branchName, ref })
9311
9381
  - push_files({ projectId, branch, commitMessage, files: [{ filePath, content }] })
9312
9382
  - create_or_update_file({ projectId, branch, filePath, content, commitMessage })
9313
9383
  - get_file_contents({ projectId, ref, path })
9314
- - get_branch_diffs({ projectId, from, to }) // compare refs
9384
+ - get_branch_diffs({ projectId, from, to })
9315
9385
 
9316
9386
  - **Merge Requests**
9317
9387
  - create_merge_request({ projectId, sourceBranch, targetBranch, title, description, assigneeUsernames?: string[] })
@@ -9346,8 +9416,7 @@ From \`event_json\`, extract:
9346
9416
  - note_id if present (\`#note_<id>\`)
9347
9417
  - description/body text, state, author \`user_username\`, timestamps
9348
9418
  - project id/path; detect default branch via \`get_merge_request\`/context as needed
9349
-
9350
- If any key is missing, choose the safest minimal action or briefly explain via a comment.
9419
+ - If available: the discussion id / thread context of the note to enable inline replies.
9351
9420
  `;
9352
9421
  /* Helper used by Single-Runner Guard and Review-on-Demand to find the MR’s own pipeline */
9353
9422
  const resolveMrPipeline = () => `
@@ -9363,7 +9432,6 @@ Given \`mr_iid\`:
9363
9432
  4) The chosen pipeline becomes \`mr_pipeline_id\`. Use it for all job queries/plays/cancels related to this MR.
9364
9433
  - 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
9434
  `;
9366
- // Updated: operate on the MR’s pipeline, not the event pipeline
9367
9435
  const singleRunnerGuard = () => `
9368
9436
  ## Single-Runner Guard (event-triggered work on an existing MR)
9369
9437
  Before entering MR Review Mode from an event:
@@ -9405,6 +9473,7 @@ If the issue/note text **asks for a review** (case-insensitive tokens like: "rev
9405
9473
  - \`list_pipeline_jobs({ projectId: $CI_PROJECT_ID, pipelineId: mr_pipeline_id })\`.
9406
9474
  - If any job has \`status = "manual"\` **and** its \`name\` ends with "agent-review":
9407
9475
  - Trigger via \`play_pipeline_job({ projectId: $CI_PROJECT_ID, jobId })\`.
9476
+ - **Conversations Intake**: run the section above to determine **where** to post the confirmation (prefer replying in the same thread that requested review).
9408
9477
  - Post a short comment confirming you triggered the review job (sanitize).
9409
9478
  - **Stop** further review actions.
9410
9479
 
@@ -9418,22 +9487,25 @@ const eventWorkflow = ({ agentUserName }) => `
9418
9487
  ## High-Reliability Workflow (sequence + postconditions)
9419
9488
  Follow this order for any change work:
9420
9489
 
9490
+ 0) **Conversations Intake (MANDATORY)**:
9491
+ - For MR targets: call \`mr_discussions\` and apply the rules in **Conversations Intake & Threading**.
9492
+ - For issue targets: attempt to load notes if supported; otherwise rely on event context and post one concise note acknowledging the limitation.
9493
+
9421
9494
  1) **Acknowledge** with a short comment on the issue/MR thread (\`create_note\`), **unless the last actor is you**.
9422
9495
  2) **Discover default branch** (e.g., "main") — infer from repo/MR context if needed.
9423
9496
  3) **Create a working branch** from default (stable name, e.g., \`fix/issue-<iid>-<slug>\` or \`feat/issue-<iid>-<slug>\`) via \`create_branch\`.
9424
9497
  4) **Write changes → commit → push to remote branch** via \`push_files\` (or \`create_or_update_file\`).
9425
9498
  5) **Verify push landed**:
9426
- - Fetch latest state (optional: \`get_file_contents\`/log) and capture a short SHA from the branch head if exposed by the host.
9427
- - Compare default vs \`source_branch\` via \`get_branch_diffs({ from: "<default>", to: "<source>" })\` and ensure there are diffs.
9499
+ - Fetch latest state and ensure diffs via \`get_branch_diffs({ from: "<default>", to: "<source>" })\`.
9428
9500
  6) **Create or update MR** ONLY if there is a non-empty diff via \`create_merge_request\`.
9429
9501
  - Include \`Closes #<issue_iid>\` in MR description when applicable.
9430
9502
  - **Assign the MR to yourself**: \`assigneeUsernames: ["${agentUserName}"]\`.
9431
- 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**.
9503
+ 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).
9432
9504
  8) **If verification fails**:
9433
9505
  - Do NOT create the MR.
9434
9506
  - Comment the exact failure and retry once with a fresh branch name. If still failing, comment and stop.
9435
9507
 
9436
- For Q&A-only (no code changes), just post a concise, helpful answer on the same issue/MR (sanitize first).
9508
+ For Q&A-only (no code changes), run **Conversations Intake** first, then post a single concise, helpful answer **in the correct thread** (sanitize).
9437
9509
  `;
9438
9510
  /* ---------- MR-review specific (shared with both prompts) ---------- */
9439
9511
  const mrScope = ({ agentUserName }) => `
@@ -9450,7 +9522,7 @@ Follow this sequence with verification at each step:
9450
9522
  1) **Collect context**
9451
9523
  - Get MR metadata via \`get_merge_request({ projectId: $CI_PROJECT_ID, mergeRequestIid })\`.
9452
9524
  - Fetch the full changeset/diffs via \`get_merge_request_diffs\` (or \`list_merge_request_diffs\`) and open discussions via \`mr_discussions\`.
9453
- - Read existing notes to avoid duplication.
9525
+ - **Conversations Intake**: analyze discussions to find latest human notes, detect replies to the agent, and decide between inline reply vs updating your prior note.
9454
9526
 
9455
9527
  2) **Code review**
9456
9528
  - Identify required changes (bugs, tests, style, security, perf, docs).
@@ -9464,12 +9536,12 @@ Follow this sequence with verification at each step:
9464
9536
  - Apply minimal, safe changes; keep commits small and clear.
9465
9537
  - **Push** to the MR's **source branch** via \`push_files\` (or \`create_or_update_file\`).
9466
9538
  - **Verify push landed** using \`get_branch_diffs({ from: "<target_branch>", to: "<source_branch>" })\` and ensure there are diffs.
9467
- - Post a follow-up MR note summarizing what changed and why (sanitize).
9539
+ - Post a follow-up MR note summarizing what changed and why, **in the appropriate thread** (sanitize).
9468
9540
  `;
9469
9541
  const ciInspection = () => `
9470
9542
  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**):
9543
+ - Prefer the **MR pipeline** (not the event pipeline).
9544
+ - If you have \`mr_pipeline_id\` (from **Resolve MR Pipeline**):
9473
9545
  - \`list_pipeline_jobs({ projectId: $CI_PROJECT_ID, pipelineId: mr_pipeline_id })\`.
9474
9546
  - Consider **only** jobs with \`status = "failed"\` and \`allow_failure = false\`.
9475
9547
  - For each such job:
@@ -9510,11 +9582,12 @@ $(cat $TRIGGER_PAYLOAD)
9510
9582
  ${identity(ctx)}
9511
9583
  ${goldenRules(ctx)}
9512
9584
  ${selfMentionGuard(ctx)}
9585
+ ${conversationsIntake(ctx)} <!-- NEW: mandatory before acting -->
9513
9586
  ${eventSelfParse()}
9514
- ${resolveMrPipeline()} <!-- new helper used by review/cancel paths -->
9515
- ${singleRunnerGuard()} <!-- operates on MR pipeline, not event pipeline -->
9587
+ ${resolveMrPipeline()} <!-- used by review/cancel paths -->
9588
+ ${singleRunnerGuard()} <!-- operates on MR pipeline, not event pipeline -->
9516
9589
  ${reviewOnDemandFromEvents()}
9517
- ${mrReviewBundle(ctx)} <!-- included so the agent can execute it when review intent is true -->
9590
+ ${mrReviewBundle(ctx)} <!-- agent can execute when review intent is true -->
9518
9591
  ${eventWorkflow(ctx)}
9519
9592
  ${commentGuidelines()}
9520
9593
  ${mcpOnly()}
@@ -9534,6 +9607,7 @@ description: $CI_MERGE_REQUEST_DESCRIPTION
9534
9607
  ${mrScope(ctx)}
9535
9608
  ${goldenRules(ctx)}
9536
9609
  ${selfMentionGuard(ctx)}
9610
+ ${conversationsIntake(ctx)} <!-- NEW: always read MR discussions -->
9537
9611
  ${mrWorkflow()}
9538
9612
  ${ciInspection()}
9539
9613
  ${commentGuidelines()}
@@ -4,6 +4,7 @@ exports.setupAgents = void 0;
4
4
  const gitlab_1 = require("../../../../../utils/gitlab");
5
5
  const getProjectConfig_1 = require("../../../../../config/getProjectConfig");
6
6
  const gitProjectInformation_1 = require("../../../../../git/gitProjectInformation");
7
+ const git_1 = require("../../../../../git");
7
8
  const listTriggerTokens = async (instance, projectId) => {
8
9
  return await (0, gitlab_1.doGitlabRequest)(instance, `projects/${projectId}/triggers`);
9
10
  };
@@ -25,7 +26,8 @@ const updateWebhook = async (instance, projectId, hookId, webhookData) => {
25
26
  const setupAgentWebhook = async (instance, projectId, agentName, triggerToken) => {
26
27
  const webhookName = `cl_agent_${agentName}_webhook`;
27
28
  const { gitRemoteHost } = await (0, gitProjectInformation_1.getGitRemoteHostAndPath)();
28
- const webhookUrl = `https://${gitRemoteHost}/api/v4/projects/${projectId}/ref/main/trigger/pipeline?token=${triggerToken}`;
29
+ const mainBranch = await (0, git_1.getMainBranch)();
30
+ const webhookUrl = `https://${gitRemoteHost}/api/v4/projects/${projectId}/ref/${mainBranch}/trigger/pipeline?token=${triggerToken}`;
29
31
  instance.log(`Setting up webhook for agent: ${agentName}`);
30
32
  // List existing webhooks
31
33
  const existingWebhooks = await listWebhooks(instance, projectId);
@@ -1 +1 @@
1
- {"version":3,"file":"setupAgents.js","sourceRoot":"","sources":["../../../../../../../../src/apps/cli/commands/project/setup/setupAgents.ts"],"names":[],"mappings":";;;AACA,wDAA8E;AAC9E,6EAA0E;AAC1E,oFAAmF;AAyDnF,MAAM,iBAAiB,GAAG,KAAK,EAC7B,QAAyB,EACzB,SAAiB,EACQ,EAAE;IAC3B,OAAO,MAAM,IAAA,wBAAe,EAAC,QAAQ,EAAE,YAAY,SAAS,WAAW,CAAC,CAAC;AAC3E,CA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C;IACH,CAAC;IAED,QAAQ,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;IAC7C,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACjB,QAAQ,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;IAC1C,QAAQ,CAAC,GAAG,CAAC,+DAA+D,CAAC,CAAC;IAC9E,QAAQ,CAAC,GAAG,CAAC,gDAAgD,CAAC,CAAC;IAC/D,QAAQ,CAAC,GAAG,CACV,6EAA6E,CAC9E,CAAC;IACF,QAAQ,CAAC,GAAG,CACV,oGAAoG,CACrG,CAAC;AACJ,CAAC,CAAC;AA/BW,QAAA,WAAW,eA+BtB"}
1
+ {"version":3,"file":"setupAgents.js","sourceRoot":"","sources":["../../../../../../../../src/apps/cli/commands/project/setup/setupAgents.ts"],"names":[],"mappings":";;;AACA,wDAA8E;AAC9E,6EAA0E;AAC1E,oFAAmF;AACnF,4CAAmD;AAyDnD,MAAM,iBAAiB,GAAG,KAAK,EAC7B,QAAyB,EACzB,SAAiB,EACQ,EAAE;IAC3B,OAAO,MAAM,IAAA,wBAAe,EAAC,QAAQ,EAAE,YAAY,SAAS,WAAW,CAAC,CAAC;AAC3E,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,KAAK,EAC9B,QAAyB,EACzB,SAAiB,EACjB,SAAiB,EACF,EAAE;IACjB,MAAM,IAAA,wBAAe,EACnB,QAAQ,EACR,YAAY,SAAS,aAAa,SAAS,EAAE,EAC7C,SAAS,EACT,QAAQ,CACT,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,KAAK,EAC9B,QAAyB,EACzB,SAAiB,EACjB,WAAmB,EACI,EAAE;IACzB,OAAO,MAAM,IAAA,wBAAe,EAC1B,QAAQ,EACR,YAAY,SAAS,WAAW,EAChC,EAAE,WAAW,EAAE,EACf,MAAM,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,YAAY,GAAG,KAAK,EACxB,QAAyB,EACzB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B"}
@@ -0,0 +1 @@
1
+ export declare const getMainBranch: () => Promise<string>;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getMainBranch = void 0;
4
+ const child_process_promise_1 = require("child-process-promise");
5
+ const getMainBranch = async () => {
6
+ const { stdout } = await (0, child_process_promise_1.exec)("git rev-parse --abbrev-ref HEAD");
7
+ return stdout.trim();
8
+ };
9
+ exports.getMainBranch = getMainBranch;
10
+ //# sourceMappingURL=getGetMainBranch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getGetMainBranch.js","sourceRoot":"","sources":["../../../../src/git/getGetMainBranch.ts"],"names":[],"mappings":";;;AAAA,iEAA6C;AACtC,MAAM,aAAa,GAAG,KAAK,IAAI,EAAE;IACtC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,IAAA,4BAAI,EAAC,iCAAiC,CAAC,CAAC;IACjE,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;AACvB,CAAC,CAAC;AAHW,QAAA,aAAa,iBAGxB"}
@@ -1,2 +1,3 @@
1
1
  export * from "./gitConfig";
2
2
  export * from "./gitProjectInformation";
3
+ export * from "./getGetMainBranch";
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./gitConfig"), exports);
18
18
  __exportStar(require("./gitProjectInformation"), exports);
19
+ __exportStar(require("./getGetMainBranch"), exports);
19
20
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/git/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,0DAAwC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/git/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,0DAAwC;AACxC,qDAAmC"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  // prompts.ts — MCP-only, DRY, review-first-then-push, CI diagnosis (no retries), self-mention guard,
3
- // event prompt supports review-on-demand via manual "agent-review" job or fallback MR review.
3
+ // conversations-aware: always read the thread first (issues & MRs), reply inline, avoid duplicates.
4
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;
@@ -24,6 +24,30 @@ const goldenRules = ({ agentUserName }) => `
24
24
  - Keep actions minimal and idempotent. Avoid duplicate comments or duplicate MRs.
25
25
  - Use ONE stable \`source_branch\` per run; do not regenerate its name later.
26
26
  `;
27
+ /* ---------- NEW: conversation intake + threading rules ---------- */
28
+ const conversationsIntake = ({ agentUserName }) => `
29
+ ## Conversations Intake & Threading (MANDATORY before acting)
30
+ Always load and reason about the current conversation to avoid duplicates and to respond in the right place.
31
+
32
+ ### What to fetch
33
+ - **MRs**: Use \`mr_discussions({ projectId: $CI_PROJECT_ID, mergeRequestIid })\` to load all threads and notes.
34
+ - **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.
35
+
36
+ ### How to use it
37
+ 1) **Detect review/answer context**:
38
+ - Identify the **latest human note** in the thread (exclude notes authored by "${agentUserName}").
39
+ - If the latest human note **replies to you** (mentions you or is in a discussion you started), reply **in the same discussion**.
40
+ 2) **De-duplication**:
41
+ - 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:
42
+ - Use \`update_merge_request_note\` or \`update_issue_note\` accordingly.
43
+ 3) **Reply placement**:
44
+ - For MR code discussions: reply **inline in the same discussion** (preserve thread context).
45
+ - For general/MR overview threads: add a single consolidated reply (avoid multiple scattered notes).
46
+ 4) **Sanitize before write**:
47
+ - Apply the Self-mention Guard, then post.
48
+ 5) **If conversations list is unavailable**:
49
+ - Post one short note: that you cannot fetch the full conversation due to missing MCP capability, then proceed minimally (no spam).
50
+ `;
27
51
  const selfMentionGuard = ({ agentUserName }) => `
28
52
  ## Self-mention Guard (mandatory preflight for ALL writes)
29
53
  Before ANY call that writes text (comment/create/update MR/issue/commit message), sanitize the text:
@@ -64,11 +88,11 @@ const mcpOnly = () => `
64
88
  - list_issues({ projectId, state?: "opened"|"closed", scope?: "all"|... })
65
89
 
66
90
  - **Branch & Files**
67
- - create_branch({ projectId, branchName, ref }) // ref = default branch or SHA
91
+ - create_branch({ projectId, branchName, ref })
68
92
  - push_files({ projectId, branch, commitMessage, files: [{ filePath, content }] })
69
93
  - create_or_update_file({ projectId, branch, filePath, content, commitMessage })
70
94
  - get_file_contents({ projectId, ref, path })
71
- - get_branch_diffs({ projectId, from, to }) // compare refs
95
+ - get_branch_diffs({ projectId, from, to })
72
96
 
73
97
  - **Merge Requests**
74
98
  - create_merge_request({ projectId, sourceBranch, targetBranch, title, description, assigneeUsernames?: string[] })
@@ -103,8 +127,7 @@ From \`event_json\`, extract:
103
127
  - note_id if present (\`#note_<id>\`)
104
128
  - description/body text, state, author \`user_username\`, timestamps
105
129
  - project id/path; detect default branch via \`get_merge_request\`/context as needed
106
-
107
- If any key is missing, choose the safest minimal action or briefly explain via a comment.
130
+ - If available: the discussion id / thread context of the note to enable inline replies.
108
131
  `;
109
132
  /* Helper used by Single-Runner Guard and Review-on-Demand to find the MR’s own pipeline */
110
133
  const resolveMrPipeline = () => `
@@ -120,7 +143,6 @@ Given \`mr_iid\`:
120
143
  4) The chosen pipeline becomes \`mr_pipeline_id\`. Use it for all job queries/plays/cancels related to this MR.
121
144
  - 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
145
  `;
123
- // Updated: operate on the MR’s pipeline, not the event pipeline
124
146
  const singleRunnerGuard = () => `
125
147
  ## Single-Runner Guard (event-triggered work on an existing MR)
126
148
  Before entering MR Review Mode from an event:
@@ -162,6 +184,7 @@ If the issue/note text **asks for a review** (case-insensitive tokens like: "rev
162
184
  - \`list_pipeline_jobs({ projectId: $CI_PROJECT_ID, pipelineId: mr_pipeline_id })\`.
163
185
  - If any job has \`status = "manual"\` **and** its \`name\` ends with "agent-review":
164
186
  - Trigger via \`play_pipeline_job({ projectId: $CI_PROJECT_ID, jobId })\`.
187
+ - **Conversations Intake**: run the section above to determine **where** to post the confirmation (prefer replying in the same thread that requested review).
165
188
  - Post a short comment confirming you triggered the review job (sanitize).
166
189
  - **Stop** further review actions.
167
190
 
@@ -175,22 +198,25 @@ const eventWorkflow = ({ agentUserName }) => `
175
198
  ## High-Reliability Workflow (sequence + postconditions)
176
199
  Follow this order for any change work:
177
200
 
201
+ 0) **Conversations Intake (MANDATORY)**:
202
+ - For MR targets: call \`mr_discussions\` and apply the rules in **Conversations Intake & Threading**.
203
+ - For issue targets: attempt to load notes if supported; otherwise rely on event context and post one concise note acknowledging the limitation.
204
+
178
205
  1) **Acknowledge** with a short comment on the issue/MR thread (\`create_note\`), **unless the last actor is you**.
179
206
  2) **Discover default branch** (e.g., "main") — infer from repo/MR context if needed.
180
207
  3) **Create a working branch** from default (stable name, e.g., \`fix/issue-<iid>-<slug>\` or \`feat/issue-<iid>-<slug>\`) via \`create_branch\`.
181
208
  4) **Write changes → commit → push to remote branch** via \`push_files\` (or \`create_or_update_file\`).
182
209
  5) **Verify push landed**:
183
- - Fetch latest state (optional: \`get_file_contents\`/log) and capture a short SHA from the branch head if exposed by the host.
184
- - Compare default vs \`source_branch\` via \`get_branch_diffs({ from: "<default>", to: "<source>" })\` and ensure there are diffs.
210
+ - Fetch latest state and ensure diffs via \`get_branch_diffs({ from: "<default>", to: "<source>" })\`.
185
211
  6) **Create or update MR** ONLY if there is a non-empty diff via \`create_merge_request\`.
186
212
  - Include \`Closes #<issue_iid>\` in MR description when applicable.
187
213
  - **Assign the MR to yourself**: \`assigneeUsernames: ["${agentUserName}"]\`.
188
- 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**.
214
+ 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).
189
215
  8) **If verification fails**:
190
216
  - Do NOT create the MR.
191
217
  - Comment the exact failure and retry once with a fresh branch name. If still failing, comment and stop.
192
218
 
193
- For Q&A-only (no code changes), just post a concise, helpful answer on the same issue/MR (sanitize first).
219
+ For Q&A-only (no code changes), run **Conversations Intake** first, then post a single concise, helpful answer **in the correct thread** (sanitize).
194
220
  `;
195
221
  /* ---------- MR-review specific (shared with both prompts) ---------- */
196
222
  const mrScope = ({ agentUserName }) => `
@@ -207,7 +233,7 @@ Follow this sequence with verification at each step:
207
233
  1) **Collect context**
208
234
  - Get MR metadata via \`get_merge_request({ projectId: $CI_PROJECT_ID, mergeRequestIid })\`.
209
235
  - Fetch the full changeset/diffs via \`get_merge_request_diffs\` (or \`list_merge_request_diffs\`) and open discussions via \`mr_discussions\`.
210
- - Read existing notes to avoid duplication.
236
+ - **Conversations Intake**: analyze discussions to find latest human notes, detect replies to the agent, and decide between inline reply vs updating your prior note.
211
237
 
212
238
  2) **Code review**
213
239
  - Identify required changes (bugs, tests, style, security, perf, docs).
@@ -221,12 +247,12 @@ Follow this sequence with verification at each step:
221
247
  - Apply minimal, safe changes; keep commits small and clear.
222
248
  - **Push** to the MR's **source branch** via \`push_files\` (or \`create_or_update_file\`).
223
249
  - **Verify push landed** using \`get_branch_diffs({ from: "<target_branch>", to: "<source_branch>" })\` and ensure there are diffs.
224
- - Post a follow-up MR note summarizing what changed and why (sanitize).
250
+ - Post a follow-up MR note summarizing what changed and why, **in the appropriate thread** (sanitize).
225
251
  `;
226
252
  const ciInspection = () => `
227
253
  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**):
254
+ - Prefer the **MR pipeline** (not the event pipeline).
255
+ - If you have \`mr_pipeline_id\` (from **Resolve MR Pipeline**):
230
256
  - \`list_pipeline_jobs({ projectId: $CI_PROJECT_ID, pipelineId: mr_pipeline_id })\`.
231
257
  - Consider **only** jobs with \`status = "failed"\` and \`allow_failure = false\`.
232
258
  - For each such job:
@@ -267,11 +293,12 @@ $(cat $TRIGGER_PAYLOAD)
267
293
  ${identity(ctx)}
268
294
  ${goldenRules(ctx)}
269
295
  ${selfMentionGuard(ctx)}
296
+ ${conversationsIntake(ctx)} <!-- NEW: mandatory before acting -->
270
297
  ${eventSelfParse()}
271
- ${resolveMrPipeline()} <!-- new helper used by review/cancel paths -->
272
- ${singleRunnerGuard()} <!-- operates on MR pipeline, not event pipeline -->
298
+ ${resolveMrPipeline()} <!-- used by review/cancel paths -->
299
+ ${singleRunnerGuard()} <!-- operates on MR pipeline, not event pipeline -->
273
300
  ${reviewOnDemandFromEvents()}
274
- ${mrReviewBundle(ctx)} <!-- included so the agent can execute it when review intent is true -->
301
+ ${mrReviewBundle(ctx)} <!-- agent can execute when review intent is true -->
275
302
  ${eventWorkflow(ctx)}
276
303
  ${commentGuidelines()}
277
304
  ${mcpOnly()}
@@ -291,6 +318,7 @@ description: $CI_MERGE_REQUEST_DESCRIPTION
291
318
  ${mrScope(ctx)}
292
319
  ${goldenRules(ctx)}
293
320
  ${selfMentionGuard(ctx)}
321
+ ${conversationsIntake(ctx)} <!-- NEW: always read MR discussions -->
294
322
  ${mrWorkflow()}
295
323
  ${ciInspection()}
296
324
  ${commentGuidelines()}