@catladder/pipeline 3.14.0 → 3.15.0
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.
- package/dist/constants.js +1 -1
- package/dist/pipeline/agent/createAgentContext.d.ts +18 -1
- package/dist/pipeline/agent/createAgentContext.js +62 -15
- package/dist/pipeline/agent/createAgentReviewJob.js +19 -3
- package/dist/pipeline/agent/prompts.d.ts +2 -6
- package/dist/pipeline/agent/prompts.js +44 -30
- package/dist/pipeline/agent/shared.js +2 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/agent.d.ts +9 -0
- package/dist/types/context.d.ts +1 -7
- package/examples/__snapshots__/cloud-run-with-agents.test.ts.snap +15 -9
- package/package.json +1 -1
- package/src/pipeline/agent/createAgentContext.ts +42 -13
- package/src/pipeline/agent/createAgentReviewJob.ts +20 -2
- package/src/pipeline/agent/prompts.ts +198 -121
- package/src/pipeline/agent/shared.ts +2 -2
- package/src/types/agent.ts +14 -0
- package/src/types/context.ts +1 -6
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
// prompts.ts
|
|
1
|
+
// prompts.ts — MCP-only, DRY, review-first-then-push, CI logic, self-mention guard,
|
|
2
|
+
// event prompt supports review-on-demand via manual "agent-review" job or fallback MR review.
|
|
3
|
+
// Prevents double-runs: event-triggered work cancels any running "agent-review" job on the same MR.
|
|
4
|
+
|
|
2
5
|
type Ctx = { agentUserName: string };
|
|
3
6
|
|
|
7
|
+
/* ---------- Shared blocks ---------- */
|
|
8
|
+
|
|
4
9
|
const header = () => `
|
|
5
10
|
Project ID: $CI_PROJECT_ID
|
|
6
11
|
GitLab Host: $CI_SERVER_URL
|
|
@@ -13,17 +18,34 @@ const identity = ({ agentUserName }: Ctx) => `
|
|
|
13
18
|
|
|
14
19
|
const goldenRules = ({ agentUserName }: Ctx) => `
|
|
15
20
|
## Golden Rules
|
|
16
|
-
- Use the \`gitlab-mcp\` tool for ALL GitLab actions.
|
|
17
|
-
-
|
|
21
|
+
- Use the \`gitlab-mcp\` tool for ALL GitLab actions. Do not call any other APIs.
|
|
22
|
+
- If a needed \`gitlab-mcp\` capability is unavailable, post a short comment explaining the limitation and stop.
|
|
23
|
+
- NEVER mention yourself ("@${agentUserName}") anywhere (comments, descriptions, titles, commit messages).
|
|
18
24
|
- NEVER push to main/default or any protected branch. Always create a new branch and open a Merge Request (MR).
|
|
25
|
+
- Always assign yourself as the assignee of any MR you create.
|
|
19
26
|
- Do not create an MR for a **closed** issue.
|
|
20
27
|
- Keep actions minimal and idempotent. Avoid duplicate comments or duplicate MRs.
|
|
21
28
|
- Use ONE stable \`source_branch\` per run; do not regenerate its name later.
|
|
22
29
|
`;
|
|
23
30
|
|
|
31
|
+
const selfMentionGuard = ({ agentUserName }: Ctx) => `
|
|
32
|
+
## Self-mention Guard (mandatory preflight for ALL writes)
|
|
33
|
+
Before ANY call that writes text (comment/create/update MR/issue/commit message), sanitize the text:
|
|
34
|
+
|
|
35
|
+
- Remove all occurrences of your own handle:
|
|
36
|
+
- Match case-insensitively: \`/@?${agentUserName}\\b/gi\`
|
|
37
|
+
- Also strip variants inside parentheses or brackets if present.
|
|
38
|
+
- Do NOT replace with another token; simply remove the self @-mention.
|
|
39
|
+
- If after sanitization the body becomes empty/meaningless, skip the write.
|
|
40
|
+
|
|
41
|
+
Additionally:
|
|
42
|
+
- If the last actor/author of the target item is you ("${agentUserName}"), **do not** post an acknowledgement comment (avoid loops on your own events).
|
|
43
|
+
- To assign yourself, use the MCP assignee field(s). Do **not** mention yourself in the body to indicate assignment.
|
|
44
|
+
`;
|
|
45
|
+
|
|
24
46
|
const commentGuidelines = () => `
|
|
25
47
|
## Comment Guidelines (flexible, not verbatim)
|
|
26
|
-
-
|
|
48
|
+
- Professional, friendly, concise.
|
|
27
49
|
- Always @-mention the human author when replying; never mention yourself.
|
|
28
50
|
- Acknowledgements: confirm you saw the request and you’ll handle it.
|
|
29
51
|
- MR updates: acknowledge feedback and say you’ll apply/have applied the change.
|
|
@@ -31,70 +53,54 @@ const commentGuidelines = () => `
|
|
|
31
53
|
- Avoid repeating identical boilerplate across comments.
|
|
32
54
|
`;
|
|
33
55
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
- **Comments**
|
|
39
|
-
-
|
|
40
|
-
|
|
41
|
-
-
|
|
42
|
-
-
|
|
43
|
-
|
|
44
|
-
-
|
|
45
|
-
|
|
56
|
+
/* Exact tool names from @zereight/mcp-gitlab (lean, indicative signatures) */
|
|
57
|
+
const mcpOnly = () => `
|
|
58
|
+
## gitlab-mcp Operations (exact tool names; indicative params)
|
|
59
|
+
|
|
60
|
+
- **Comments / Notes**
|
|
61
|
+
- create_note({ projectId, targetType: "issue"|"merge_request", iid, body })
|
|
62
|
+
- create_issue_note({ projectId, issueIid, body })
|
|
63
|
+
- create_merge_request_note({ projectId, mergeRequestIid, body })
|
|
64
|
+
- update_issue_note({ projectId, issueIid, noteId, body })
|
|
65
|
+
- update_merge_request_note({ projectId, mergeRequestIid, noteId, body })
|
|
66
|
+
- mr_discussions({ projectId, mergeRequestIid })
|
|
67
|
+
|
|
68
|
+
- **Issues**
|
|
69
|
+
- create_issue({ projectId, title, description, assigneeUsernames?: string[] })
|
|
70
|
+
- list_issues({ projectId, state?: "opened"|"closed", scope?: "all"|... })
|
|
71
|
+
|
|
72
|
+
- **Branch & Files**
|
|
73
|
+
- create_branch({ projectId, branchName, ref }) // ref = default branch or SHA
|
|
74
|
+
- push_files({ projectId, branch, commitMessage, files: [{ filePath, content }] })
|
|
75
|
+
- create_or_update_file({ projectId, branch, filePath, content, commitMessage })
|
|
76
|
+
- get_file_contents({ projectId, ref, path })
|
|
77
|
+
- get_branch_diffs({ projectId, from, to }) // compare refs
|
|
46
78
|
|
|
47
79
|
- **Merge Requests**
|
|
48
|
-
-
|
|
49
|
-
-
|
|
50
|
-
-
|
|
51
|
-
|
|
52
|
-
-
|
|
53
|
-
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
-
|
|
62
|
-
Use the environment variable \`GITLAB_PERSONAL_ACCESS_TOKEN\`.
|
|
63
|
-
Send it in the HTTP header:
|
|
64
|
-
\`\`\`
|
|
65
|
-
Private-Token: $GITLAB_PERSONAL_ACCESS_TOKEN
|
|
66
|
-
\`\`\`
|
|
67
|
-
|
|
68
|
-
- **Host & project variables**
|
|
69
|
-
- API base URL: \`$CI_SERVER_URL/api/v4\`
|
|
70
|
-
- Project ID: \`$CI_PROJECT_ID\`
|
|
71
|
-
|
|
72
|
-
- **Examples**
|
|
73
|
-
- Get project (default branch):
|
|
74
|
-
\`GET $CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID\`
|
|
75
|
-
- Get/create branch:
|
|
76
|
-
\`GET|POST $CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/repository/branches\`
|
|
77
|
-
- Compare refs:
|
|
78
|
-
\`GET $CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/repository/compare?from=<default>&to=<source>\`
|
|
79
|
-
- List commits:
|
|
80
|
-
\`GET $CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/repository/commits?ref_name=<branch>&per_page=1\`
|
|
81
|
-
- Create comment on issue/MR:
|
|
82
|
-
\`POST $CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/issues/:iid/notes\`
|
|
83
|
-
\`POST $CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/merge_requests/:iid/notes\`
|
|
84
|
-
- Create MR:
|
|
85
|
-
\`POST $CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/merge_requests\`
|
|
86
|
-
- Get MR changes:
|
|
87
|
-
\`GET $CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/merge_requests/:iid/changes\`
|
|
80
|
+
- create_merge_request({ projectId, sourceBranch, targetBranch, title, description, assigneeUsernames?: string[] })
|
|
81
|
+
- get_merge_request({ projectId, mergeRequestIid? , branchName? })
|
|
82
|
+
- get_merge_request_diffs({ projectId, mergeRequestIid? , branchName? })
|
|
83
|
+
- list_merge_request_diffs({ projectId, mergeRequestIid? , branchName?, page?, perPage? })
|
|
84
|
+
- update_merge_request({ projectId, mergeRequestIid? , branchName?, title?, description?, draft?, assigneeUsernames? })
|
|
85
|
+
- merge_merge_request(...) // **Do NOT use** (never merge)
|
|
86
|
+
|
|
87
|
+
- **Pipelines / Jobs** (requires env USE_PIPELINE=true)
|
|
88
|
+
- list_pipeline_jobs({ projectId, pipelineId })
|
|
89
|
+
- get_pipeline_job_output({ projectId, pipelineId, jobId })
|
|
90
|
+
- retry_pipeline({ projectId, pipelineId })
|
|
91
|
+
- retry_pipeline_job({ projectId, jobId })
|
|
92
|
+
- play_pipeline_job({ projectId, jobId })
|
|
93
|
+
- cancel_pipeline_job({ projectId, jobId })
|
|
88
94
|
`;
|
|
89
95
|
|
|
90
96
|
const outputDiscipline = ({ agentUserName }: Ctx) => `
|
|
91
97
|
## Output Discipline
|
|
92
|
-
-
|
|
98
|
+
- Output only \`gitlab-mcp\` tool calls and plain-text summaries where requested.
|
|
93
99
|
- Keep comments concise and professional.
|
|
94
100
|
- Never include "@${agentUserName}" in any body.
|
|
95
101
|
`;
|
|
96
102
|
|
|
97
|
-
|
|
103
|
+
/* ---------- Event (webhook) specific ---------- */
|
|
98
104
|
|
|
99
105
|
const eventSelfParse = () => `
|
|
100
106
|
## Self-Parse the Raw Payload (no preprocessing available)
|
|
@@ -105,40 +111,89 @@ From \`event_json\`, extract:
|
|
|
105
111
|
- \`/-/merge_requests/<n>\` → target="mr", iid=<n>
|
|
106
112
|
- note_id if present (\`#note_<id>\`)
|
|
107
113
|
- description/body text, state, author \`user_username\`, timestamps
|
|
108
|
-
- project id/path; detect default branch via
|
|
114
|
+
- project id/path; detect default branch via \`get_merge_request\`/context as needed
|
|
109
115
|
|
|
110
116
|
If any key is missing, choose the safest minimal action or briefly explain via a comment.
|
|
111
117
|
`;
|
|
112
118
|
|
|
113
|
-
|
|
119
|
+
// NEW: Single-runner guard (event-triggered → existing MR)
|
|
120
|
+
const singleRunnerGuard = () => `
|
|
121
|
+
## Single-Runner Guard (event-triggered work on an existing MR)
|
|
122
|
+
Before entering MR Review Mode from an event:
|
|
123
|
+
|
|
124
|
+
- **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.
|
|
125
|
+
|
|
126
|
+
**Best-effort procedure (MCP-only):**
|
|
127
|
+
1) If \`$CI_PIPELINE_ID\` is available (this event is executing inside a CI context for the same MR):
|
|
128
|
+
- Call \`list_pipeline_jobs({ projectId: $CI_PROJECT_ID, pipelineId: $CI_PIPELINE_ID })\`.
|
|
129
|
+
- Identify any job where \`status\` is \`"running"\` or \`"pending"\` **and** \`name\` **endsWith** \`"agent-review"\`.
|
|
130
|
+
- For each match, call \`cancel_pipeline_job({ projectId: $CI_PROJECT_ID, jobId })\`.
|
|
131
|
+
- Proceed with review immediately after issuing cancellations (do not wait).
|
|
132
|
+
|
|
133
|
+
2) If \`$CI_PIPELINE_ID\` is **not** available, or jobs for this MR cannot be listed with available MCP calls:
|
|
134
|
+
- Post a short MR note stating you are proceeding but **cannot verify/cancel** a running \`agent-review\` job due to missing capabilities.
|
|
135
|
+
- Proceed with review.
|
|
136
|
+
|
|
137
|
+
**Notes:**
|
|
138
|
+
- Keep this guard **idempotent** (safe to run multiple times).
|
|
139
|
+
- This guard only applies to **event-triggered** flows that decide to act on an **existing MR**.
|
|
140
|
+
`;
|
|
141
|
+
|
|
142
|
+
const reviewOnDemandFromEvents = () => `
|
|
143
|
+
## Review-on-Demand (from events)
|
|
144
|
+
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:
|
|
145
|
+
|
|
146
|
+
1) **Check for pipeline review job**
|
|
147
|
+
- List jobs for the current pipeline \`$CI_PIPELINE_ID\` via \`list_pipeline_jobs\`.
|
|
148
|
+
- If any job has \`status = "manual"\` **and** its \`name\` ends with "agent-review":
|
|
149
|
+
- Trigger it via \`play_pipeline_job({ projectId: $CI_PROJECT_ID, jobId })\`.
|
|
150
|
+
- Post a short comment confirming you triggered the review job (sanitize).
|
|
151
|
+
- **Stop** further review actions.
|
|
152
|
+
|
|
153
|
+
2) **If no such job exists, resolve which MR to review**:
|
|
154
|
+
- If the event target is an MR → use its \`iid\`.
|
|
155
|
+
- Else, parse the text for MR references in order:
|
|
156
|
+
- \`!<iid>\` (e.g., \`!123\`)
|
|
157
|
+
- \`/-/merge_requests/<iid>\` in a path or URL
|
|
158
|
+
- full GitLab MR URL
|
|
159
|
+
- If no MR can be resolved, reply with a brief comment asking the user to reference an MR (sanitize) and **stop**.
|
|
160
|
+
|
|
161
|
+
3) **Single-Runner Guard (cancel any running "agent-review" job)** // NEW: Single-runner guard
|
|
162
|
+
- Execute the **Single-Runner Guard** steps above **before** MR Review Mode.
|
|
163
|
+
|
|
164
|
+
4) **Enter MR Review Mode**: execute the **MR Review Bundle** below with the resolved \`mr_iid\`.
|
|
165
|
+
`;
|
|
166
|
+
|
|
167
|
+
/** Regular event workflow for non-review work */
|
|
168
|
+
const eventWorkflow = ({ agentUserName }: Ctx) => `
|
|
114
169
|
## High-Reliability Workflow (sequence + postconditions)
|
|
115
170
|
Follow this order for any change work:
|
|
116
171
|
|
|
117
|
-
1) **Acknowledge** with a short comment on the issue/MR thread
|
|
118
|
-
2) **Discover default branch** (e.g., "main")
|
|
119
|
-
3) **Create a working branch** from default (stable name, e.g., \`fix/issue-<iid>-<slug>\` or \`feat/issue-<iid>-<slug>\`)
|
|
120
|
-
4) **Write changes → commit → push to remote branch
|
|
172
|
+
1) **Acknowledge** with a short comment on the issue/MR thread (\`create_note\`), **unless the last actor is you**.
|
|
173
|
+
2) **Discover default branch** (e.g., "main") — infer from repo/MR context if needed.
|
|
174
|
+
3) **Create a working branch** from default (stable name, e.g., \`fix/issue-<iid>-<slug>\` or \`feat/issue-<iid>-<slug>\`) via \`create_branch\`.
|
|
175
|
+
4) **Write changes → commit → push to remote branch** via \`push_files\` (or \`create_or_update_file\`).
|
|
121
176
|
5) **Verify push landed**:
|
|
122
|
-
- Fetch latest
|
|
123
|
-
- Compare default vs \`source_branch\` and ensure
|
|
124
|
-
6) **Create or update MR** ONLY if there is a non-empty diff
|
|
177
|
+
- Fetch latest state (optional: \`get_file_contents\`/log) and capture a short SHA from the branch head if exposed by the host.
|
|
178
|
+
- Compare default vs \`source_branch\` via \`get_branch_diffs({ from: "<default>", to: "<source>" })\` and ensure there are diffs.
|
|
179
|
+
6) **Create or update MR** ONLY if there is a non-empty diff via \`create_merge_request\`.
|
|
125
180
|
- Include \`Closes #<issue_iid>\` in MR description when applicable.
|
|
126
|
-
- Assign
|
|
127
|
-
7) **Follow-up comment** with branch name, commit short SHA, files changed count, and MR link
|
|
181
|
+
- **Assign the MR to yourself**: \`assigneeUsernames: ["${agentUserName}"]\`.
|
|
182
|
+
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**.
|
|
128
183
|
8) **If verification fails**:
|
|
129
184
|
- Do NOT create the MR.
|
|
130
185
|
- Comment the exact failure and retry once with a fresh branch name. If still failing, comment and stop.
|
|
131
186
|
|
|
132
|
-
For Q&A-only (no code changes), just post a concise, helpful answer on the same issue/MR.
|
|
187
|
+
For Q&A-only (no code changes), just post a concise, helpful answer on the same issue/MR (sanitize first).
|
|
133
188
|
`;
|
|
134
189
|
|
|
135
|
-
|
|
190
|
+
/* ---------- MR-review specific (shared with both prompts) ---------- */
|
|
136
191
|
|
|
137
192
|
const mrScope = ({ agentUserName }: Ctx) => `
|
|
138
193
|
## Identity & Scope
|
|
139
194
|
- Your GitLab username is "${agentUserName}".
|
|
140
|
-
- This prompt runs in the context of ONE MR
|
|
141
|
-
- You may review, comment,
|
|
195
|
+
- This prompt runs in the context of ONE MR.
|
|
196
|
+
- You may review, comment, and push updates **to the MR's source branch**.
|
|
142
197
|
- You must **never merge** the MR yourself.
|
|
143
198
|
`;
|
|
144
199
|
|
|
@@ -147,47 +202,72 @@ const mrWorkflow = () => `
|
|
|
147
202
|
Follow this sequence with verification at each step:
|
|
148
203
|
|
|
149
204
|
1) **Collect context**
|
|
150
|
-
- Get MR metadata (
|
|
151
|
-
- Fetch the full changeset/diffs and open discussions
|
|
152
|
-
- Read existing
|
|
153
|
-
- (Optional) Fetch recent CI pipeline(s) for this MR SHA/branch).
|
|
205
|
+
- Get MR metadata via \`get_merge_request({ projectId: $CI_PROJECT_ID, mergeRequestIid })\`.
|
|
206
|
+
- Fetch the full changeset/diffs via \`get_merge_request_diffs\` (or \`list_merge_request_diffs\`) and open discussions via \`mr_discussions\`.
|
|
207
|
+
- Read existing notes to avoid duplication.
|
|
154
208
|
|
|
155
209
|
2) **Code review**
|
|
156
210
|
- Identify required changes (bugs, tests, style, security, perf, docs).
|
|
157
|
-
-
|
|
158
|
-
|
|
159
|
-
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
-
|
|
164
|
-
-
|
|
165
|
-
- **Push** to the MR's **
|
|
166
|
-
- **Verify push landed** (
|
|
167
|
-
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
-
|
|
211
|
+
- Always **post your review comments first** using \`create_merge_request_note\` (ack + concrete notes). Sanitize before sending.
|
|
212
|
+
- Set an internal intent flag:
|
|
213
|
+
- \`will_push_changes = true\` if you will modify code/config.
|
|
214
|
+
- \`will_push_changes = false\` if it’s commentary-only.
|
|
215
|
+
|
|
216
|
+
3) **Implement changes after review is posted (only if \`will_push_changes = true\`)**
|
|
217
|
+
- If needed, create the working branch from the target/default (or use existing MR source branch).
|
|
218
|
+
- Apply minimal, safe changes; keep commits small and clear.
|
|
219
|
+
- **Push** to the MR's **source branch** via \`push_files\` (or \`create_or_update_file\`).
|
|
220
|
+
- **Verify push landed** using \`get_branch_diffs({ from: "<target_branch>", to: "<source_branch>" })\` and ensure there are diffs.
|
|
221
|
+
- Post a follow-up MR note summarizing what changed and why (sanitize).
|
|
222
|
+
`;
|
|
223
|
+
|
|
224
|
+
const ciInspection = () => `
|
|
225
|
+
4) **CI jobs (current pipeline focus: diagnose first, retry only when useful)**
|
|
226
|
+
- Inspect jobs for the **current pipeline**: \`$CI_PIPELINE_ID\` via \`list_pipeline_jobs\`.
|
|
227
|
+
- Consider **only** jobs with \`status = "failed"\` and \`allow_failure = false\`.
|
|
228
|
+
- For each such job:
|
|
229
|
+
1. Retrieve details (id, name, stage, status, allow_failure, web_url).
|
|
230
|
+
2. Fetch job output via \`get_pipeline_job_output({ projectId: $CI_PROJECT_ID, pipelineId: $CI_PIPELINE_ID, jobId })\`.
|
|
231
|
+
3. **Classify the failure**:
|
|
232
|
+
- **Code-related (do not retry):** compiler/type/lint/test/build script errors.
|
|
233
|
+
- **Likely transient (may retry):** network/timeouts/infra/cache/artifacts/5xx/429/etc.
|
|
234
|
+
4. **Decision**:
|
|
235
|
+
- If \`will_push_changes = true\`:
|
|
236
|
+
- **Do not retry** current pipeline (upcoming push will trigger a new one).
|
|
237
|
+
- Post an MR note: brief diagnosis per failed job; note a new pipeline will validate the fix (sanitize).
|
|
238
|
+
- If \`will_push_changes = false\`:
|
|
239
|
+
- If transient ⇒ \`retry_pipeline_job({ projectId: $CI_PROJECT_ID, jobId })\` (or \`retry_pipeline\` if job-level retry not available).
|
|
240
|
+
Post a note stating you retried and why (sanitize).
|
|
241
|
+
- If code-related ⇒ do not retry; post a note with diagnosis and suggested fix (sanitize).
|
|
242
|
+
- Retry-once policy: at most **one** retry per job in this run.
|
|
173
243
|
|
|
174
244
|
5) **Assign human reviewer if ready**
|
|
175
|
-
- If discussions are resolved and CI
|
|
245
|
+
- 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.
|
|
176
246
|
|
|
177
247
|
6) **Stdout summary**
|
|
178
|
-
- Print concise summary:
|
|
248
|
+
- 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.
|
|
249
|
+
`;
|
|
250
|
+
|
|
251
|
+
const outputDisciplineMR = ({ agentUserName }: Ctx) => `
|
|
252
|
+
## Output Discipline (MR)
|
|
253
|
+
- Output only \`gitlab-mcp\` tool calls and the final plain-text summary.
|
|
254
|
+
- Do **not** merge the MR yourself under any circumstance.
|
|
255
|
+
- Never include "@${agentUserName}" in any body.
|
|
179
256
|
`;
|
|
180
257
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
258
|
+
/* ---------- Shared bundle for MR review ---------- */
|
|
259
|
+
|
|
260
|
+
const mrReviewBundle = (ctx: Ctx) => `
|
|
261
|
+
## MR Review Mode (execute ONLY when review intent is detected and an MR IID is resolved)
|
|
262
|
+
Resolved MR IID: <set this to the resolved \`mr_iid\` before executing>
|
|
263
|
+
${mrScope(ctx)}
|
|
264
|
+
${mrWorkflow()}
|
|
265
|
+
${ciInspection()}
|
|
186
266
|
`;
|
|
187
267
|
|
|
188
|
-
|
|
268
|
+
/* ---------- Public builders ---------- */
|
|
189
269
|
|
|
190
|
-
export const getEventPrompt = (
|
|
270
|
+
export const getEventPrompt = (ctx: Ctx) => `
|
|
191
271
|
You are a GitLab assistant bot. You receive ONE raw GitLab webhook JSON payload.
|
|
192
272
|
|
|
193
273
|
${header()}
|
|
@@ -196,16 +276,20 @@ event_json:
|
|
|
196
276
|
$(cat $TRIGGER_PAYLOAD)
|
|
197
277
|
---
|
|
198
278
|
|
|
199
|
-
${identity(
|
|
200
|
-
${goldenRules(
|
|
279
|
+
${identity(ctx)}
|
|
280
|
+
${goldenRules(ctx)}
|
|
281
|
+
${selfMentionGuard(ctx)}
|
|
201
282
|
${eventSelfParse()}
|
|
202
|
-
${
|
|
283
|
+
${singleRunnerGuard()} <!-- NEW: included so the agent can run it when acting on an existing MR -->
|
|
284
|
+
${reviewOnDemandFromEvents()}
|
|
285
|
+
${mrReviewBundle(ctx)} <!-- Included so the agent can execute it when review intent is true -->
|
|
286
|
+
${eventWorkflow(ctx)}
|
|
203
287
|
${commentGuidelines()}
|
|
204
|
-
${
|
|
205
|
-
${outputDiscipline(
|
|
288
|
+
${mcpOnly()}
|
|
289
|
+
${outputDiscipline(ctx)}
|
|
206
290
|
`;
|
|
207
291
|
|
|
208
|
-
export const getMergeRequestPrompt = (
|
|
292
|
+
export const getMergeRequestPrompt = (ctx: Ctx) => `
|
|
209
293
|
You are a GitLab assistant bot reviewing and updating a single Merge Request (MR).
|
|
210
294
|
|
|
211
295
|
${header()}
|
|
@@ -215,19 +299,12 @@ title: $CI_MERGE_REQUEST_TITLE
|
|
|
215
299
|
description: $CI_MERGE_REQUEST_DESCRIPTION
|
|
216
300
|
---
|
|
217
301
|
|
|
218
|
-
${mrScope(
|
|
219
|
-
${goldenRules(
|
|
302
|
+
${mrScope(ctx)}
|
|
303
|
+
${goldenRules(ctx)}
|
|
304
|
+
${selfMentionGuard(ctx)}
|
|
220
305
|
${mrWorkflow()}
|
|
306
|
+
${ciInspection()}
|
|
221
307
|
${commentGuidelines()}
|
|
222
|
-
${
|
|
223
|
-
${
|
|
224
|
-
## Output Discipline (MR)
|
|
225
|
-
- Prefer \`gitlab-mcp\` tool calls; if unavailable, provide explicit REST calls (method, url, headers, body).
|
|
226
|
-
- At the end, print a **plain-text** summary to STDOUT including:
|
|
227
|
-
- \`source_branch\` and \`target_branch\`
|
|
228
|
-
- commits pushed (short SHAs)
|
|
229
|
-
- number of files changed
|
|
230
|
-
- CI status/result
|
|
231
|
-
- reviewers requested (if any)
|
|
232
|
-
- Do **not** merge the MR yourself under any circumstance.
|
|
308
|
+
${mcpOnly()}
|
|
309
|
+
${outputDisciplineMR(ctx)}
|
|
233
310
|
`;
|
|
@@ -22,7 +22,7 @@ export const baseSetupScript = [
|
|
|
22
22
|
"apk update",
|
|
23
23
|
"apk add --no-cache git curl bash",
|
|
24
24
|
"npm install -g @anthropic-ai/claude-code",
|
|
25
|
-
"claude mcp add gitlab --env GITLAB_PERSONAL_ACCESS_TOKEN=$GITLAB_PERSONAL_ACCESS_TOKEN --env GITLAB_API_URL=$GITLAB_API_URL -- npx -y @zereight/mcp-gitlab",
|
|
25
|
+
"claude mcp add gitlab --env GITLAB_PERSONAL_ACCESS_TOKEN=$GITLAB_PERSONAL_ACCESS_TOKEN --env GITLAB_API_URL=$GITLAB_API_URL --env USE_PIPELINE='true' -- npx -y @zereight/mcp-gitlab",
|
|
26
26
|
];
|
|
27
27
|
|
|
28
28
|
export const callClaude = ({ prompt }: { prompt: string }) => {
|
|
@@ -31,6 +31,6 @@ export const callClaude = ({ prompt }: { prompt: string }) => {
|
|
|
31
31
|
escapeDoubleQuotes(escapeBackTicks(prompt)),
|
|
32
32
|
)}"`,
|
|
33
33
|
//'echo "$PROMPT"',
|
|
34
|
-
`claude -p "$PROMPT" --permission-mode acceptEdits --allowedTools "Bash(*) Read(*) Edit(*) Write(*) mcp__gitlab" --verbose --debug`,
|
|
34
|
+
`claude -p "$PROMPT" --permission-mode acceptEdits --allowedTools "Bash(*) Bash(git checkout:*) Read(*) Edit(*) Write(*) mcp__gitlab" --verbose --debug`,
|
|
35
35
|
];
|
|
36
36
|
};
|
package/src/types/agent.ts
CHANGED
|
@@ -4,4 +4,18 @@ export type AgentConfig = {
|
|
|
4
4
|
username: string;
|
|
5
5
|
userId: string;
|
|
6
6
|
};
|
|
7
|
+
reviews?: {
|
|
8
|
+
/**
|
|
9
|
+
* usernames that the agent should review merge requests for.
|
|
10
|
+
* Defaults to agentUser
|
|
11
|
+
*/
|
|
12
|
+
byUser?:
|
|
13
|
+
| Record<
|
|
14
|
+
string,
|
|
15
|
+
{
|
|
16
|
+
automatic: boolean;
|
|
17
|
+
}
|
|
18
|
+
>
|
|
19
|
+
| "all-automatic";
|
|
20
|
+
};
|
|
7
21
|
};
|
package/src/types/context.ts
CHANGED
|
@@ -216,9 +216,4 @@ export type WorkspaceContext = {
|
|
|
216
216
|
env: string;
|
|
217
217
|
};
|
|
218
218
|
|
|
219
|
-
export type AgentContext
|
|
220
|
-
type: "agent";
|
|
221
|
-
name: string;
|
|
222
|
-
fullConfig: Config;
|
|
223
|
-
agentConfig: AgentConfig;
|
|
224
|
-
};
|
|
219
|
+
export type { AgentContext } from "../pipeline/agent/createAgentContext";
|