@catladder/cli 0.0.0-main-5bdbbbe0 → 0.0.0-main-f29db9e2

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.
Files changed (65) hide show
  1. package/dist/bundles/catenv/index.js +492 -18
  2. package/dist/bundles/cli/index.js +656 -18
  3. package/dist/cli/src/apps/cli/commands/project/setup/index.js +2 -0
  4. package/dist/cli/src/apps/cli/commands/project/setup/index.js.map +1 -1
  5. package/dist/cli/src/apps/cli/commands/project/setup/setupAgents.d.ts +2 -0
  6. package/dist/cli/src/apps/cli/commands/project/setup/setupAgents.js +155 -0
  7. package/dist/cli/src/apps/cli/commands/project/setup/setupAgents.js.map +1 -0
  8. package/dist/cli/src/config/getProjectConfig.js +4 -1
  9. package/dist/cli/src/config/getProjectConfig.js.map +1 -1
  10. package/dist/pipeline/src/bash/bashEscape.d.ts +2 -0
  11. package/dist/pipeline/src/bash/bashEscape.js +5 -1
  12. package/dist/pipeline/src/bash/bashEscape.js.map +1 -1
  13. package/dist/pipeline/src/pipeline/agent/createAgentContext.d.ts +6 -0
  14. package/dist/pipeline/src/pipeline/agent/createAgentContext.js +19 -0
  15. package/dist/pipeline/src/pipeline/agent/createAgentContext.js.map +1 -0
  16. package/dist/pipeline/src/pipeline/agent/createAgentEventJob.d.ts +2 -0
  17. package/dist/pipeline/src/pipeline/agent/createAgentEventJob.js +37 -0
  18. package/dist/pipeline/src/pipeline/agent/createAgentEventJob.js.map +1 -0
  19. package/dist/pipeline/src/pipeline/agent/createAgentReviewJob.d.ts +2 -0
  20. package/dist/pipeline/src/pipeline/agent/createAgentReviewJob.js +34 -0
  21. package/dist/pipeline/src/pipeline/agent/createAgentReviewJob.js.map +1 -0
  22. package/dist/pipeline/src/pipeline/agent/createJobsForAgentContext.d.ts +2 -0
  23. package/dist/pipeline/src/pipeline/agent/createJobsForAgentContext.js +10 -0
  24. package/dist/pipeline/src/pipeline/agent/createJobsForAgentContext.js.map +1 -0
  25. package/dist/pipeline/src/pipeline/agent/prompts.d.ts +6 -0
  26. package/dist/pipeline/src/pipeline/agent/prompts.js +221 -0
  27. package/dist/pipeline/src/pipeline/agent/prompts.js.map +1 -0
  28. package/dist/pipeline/src/pipeline/agent/shared.d.ts +6 -0
  29. package/dist/pipeline/src/pipeline/agent/shared.js +30 -0
  30. package/dist/pipeline/src/pipeline/agent/shared.js.map +1 -0
  31. package/dist/pipeline/src/pipeline/agent/utils.d.ts +3 -0
  32. package/dist/pipeline/src/pipeline/agent/utils.js +14 -0
  33. package/dist/pipeline/src/pipeline/agent/utils.js.map +1 -0
  34. package/dist/pipeline/src/pipeline/createAllJobs.d.ts +5 -1
  35. package/dist/pipeline/src/pipeline/createAllJobs.js +10 -1
  36. package/dist/pipeline/src/pipeline/createAllJobs.js.map +1 -1
  37. package/dist/pipeline/src/pipeline/createJobsForComponent.js.map +1 -1
  38. package/dist/pipeline/src/pipeline/createMainPipeline.js +13 -4
  39. package/dist/pipeline/src/pipeline/createMainPipeline.js.map +1 -1
  40. package/dist/pipeline/src/pipeline/gitlab/createGitlabJobs.d.ts +3 -3
  41. package/dist/pipeline/src/pipeline/gitlab/createGitlabJobs.js +18 -9
  42. package/dist/pipeline/src/pipeline/gitlab/createGitlabJobs.js.map +1 -1
  43. package/dist/pipeline/src/pipeline/gitlab/createGitlabPipeline.js +8 -1
  44. package/dist/pipeline/src/pipeline/gitlab/createGitlabPipeline.js.map +1 -1
  45. package/dist/pipeline/src/rules/index.d.ts +1 -0
  46. package/dist/pipeline/src/rules/index.js +8 -1
  47. package/dist/pipeline/src/rules/index.js.map +1 -1
  48. package/dist/pipeline/src/types/agent.d.ts +7 -0
  49. package/dist/pipeline/src/types/agent.js +3 -0
  50. package/dist/pipeline/src/types/agent.js.map +1 -0
  51. package/dist/pipeline/src/types/config.d.ts +2 -0
  52. package/dist/pipeline/src/types/config.js.map +1 -1
  53. package/dist/pipeline/src/types/context.d.ts +7 -0
  54. package/dist/pipeline/src/types/context.js.map +1 -1
  55. package/dist/pipeline/src/types/index.d.ts +1 -0
  56. package/dist/pipeline/src/types/index.js +1 -0
  57. package/dist/pipeline/src/types/index.js.map +1 -1
  58. package/dist/pipeline/src/types/jobs.d.ts +5 -1
  59. package/dist/pipeline/src/types/jobs.js +1 -0
  60. package/dist/pipeline/src/types/jobs.js.map +1 -1
  61. package/dist/tsconfig.tsbuildinfo +1 -1
  62. package/package.json +1 -1
  63. package/src/apps/cli/commands/project/setup/index.ts +2 -0
  64. package/src/apps/cli/commands/project/setup/setupAgents.ts +319 -0
  65. package/src/config/getProjectConfig.ts +8 -3
@@ -316,7 +316,7 @@ const getAllComponentsWithAllEnvsFlat = async () => {
316
316
  if (!config) {
317
317
  return [];
318
318
  }
319
- return Object.keys(config.components).flatMap((componentName) => (0, pipeline_1.getAllEnvs)(config, componentName).map((env) => ({ env, componentName })));
319
+ return getAllComponentsWithAllEnvsFlatFromConfig(config);
320
320
  };
321
321
  exports.getAllComponentsWithAllEnvsFlat = getAllComponentsWithAllEnvsFlat;
322
322
  const getAllComponentsWithAllEnvsHierarchical = async () => {
@@ -393,6 +393,9 @@ const getJobOnlyEnvVarsResolved = async (vorpal, env, componentName) => {
393
393
  ]);
394
394
  };
395
395
  exports.getJobOnlyEnvVarsResolved = getJobOnlyEnvVarsResolved;
396
+ function getAllComponentsWithAllEnvsFlatFromConfig(config) {
397
+ return Object.keys(config.components).flatMap((componentName) => (0, pipeline_1.getAllEnvs)(config, componentName).map((env) => ({ env, componentName })));
398
+ }
396
399
  //# sourceMappingURL=getProjectConfig.js.map
397
400
 
398
401
  /***/ }),
@@ -914,7 +917,7 @@ exports.joinBashExpressions = joinBashExpressions;
914
917
  "use strict";
915
918
 
916
919
  Object.defineProperty(exports, "__esModule", ({ value: true }));
917
- exports.escapeForDotEnv = exports.escapeSingleQuotes = exports.escapeDoubleQuotes = exports.escapeBashExpression = exports.escapeString = exports.bashEscape = void 0;
920
+ exports.escapeForDotEnv = exports.escapeNewlines = exports.escapeBackTicks = exports.escapeSingleQuotes = exports.escapeDoubleQuotes = exports.escapeBashExpression = exports.escapeString = exports.bashEscape = void 0;
918
921
  const globalScriptFunctions_1 = __nccwpck_require__(2912);
919
922
  const VariableValueContainingReferences_1 = __nccwpck_require__(1592);
920
923
  const BashExpression_1 = __nccwpck_require__(2376);
@@ -955,6 +958,10 @@ const escapeDoubleQuotes = (value) => value === null || value === void 0 ? void
955
958
  exports.escapeDoubleQuotes = escapeDoubleQuotes;
956
959
  const escapeSingleQuotes = (value) => value === null || value === void 0 ? void 0 : value.toString().replace(/'/g, "\\'");
957
960
  exports.escapeSingleQuotes = escapeSingleQuotes;
961
+ const escapeBackTicks = (value) => value === null || value === void 0 ? void 0 : value.toString().replace(/`/g, "\\`");
962
+ exports.escapeBackTicks = escapeBackTicks;
963
+ const escapeNewlines = (value) => value === null || value === void 0 ? void 0 : value.toString().replace(/\n/g, "\\n");
964
+ exports.escapeNewlines = escapeNewlines;
958
965
  /**
959
966
  *
960
967
  * escape env vars for .env files.
@@ -5879,6 +5886,420 @@ __exportStar(__nccwpck_require__(2990), exports);
5879
5886
 
5880
5887
  /***/ }),
5881
5888
 
5889
+ /***/ 2636:
5890
+ /***/ ((__unused_webpack_module, exports) => {
5891
+
5892
+ "use strict";
5893
+
5894
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
5895
+ exports.createAgentContext = void 0;
5896
+ const createAgentContext = async (ctx) => {
5897
+ var _a;
5898
+ const agentConfig = (_a = ctx.config.agents) === null || _a === void 0 ? void 0 : _a[ctx.agentName];
5899
+ if (!agentConfig) {
5900
+ throw new Error(`Agent ${ctx.agentName} not found in config`);
5901
+ }
5902
+ return {
5903
+ type: "agent",
5904
+ name: ctx.agentName,
5905
+ //env: ctx.env,
5906
+ fullConfig: ctx.config,
5907
+ agentConfig: agentConfig,
5908
+ };
5909
+ };
5910
+ exports.createAgentContext = createAgentContext;
5911
+ //# sourceMappingURL=createAgentContext.js.map
5912
+
5913
+ /***/ }),
5914
+
5915
+ /***/ 9404:
5916
+ /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
5917
+
5918
+ "use strict";
5919
+
5920
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
5921
+ exports.createAgentEventJob = void 0;
5922
+ const prompts_1 = __nccwpck_require__(8698);
5923
+ const shared_1 = __nccwpck_require__(732);
5924
+ const utils_1 = __nccwpck_require__(9133);
5925
+ const createAgentEventJob = (context) => {
5926
+ const baseJob = (0, shared_1.createBaseAgentJob)(context);
5927
+ // unfortunatly, we need to manage both, because the "@mention"-feature only works with the username
5928
+ const agentUserId = (0, utils_1.getAgentUserId)(context);
5929
+ const agentUserName = (0, utils_1.getAgentUserName)(context);
5930
+ return {
5931
+ interruptible: false, // do not cancel this job if it is running. Otherwise a commit to main will cancel it
5932
+ ...baseJob,
5933
+ variables: {
5934
+ ...baseJob.variables,
5935
+ },
5936
+ name: context.name + "-agent-event",
5937
+ rules: [
5938
+ {
5939
+ if: `$CI_PIPELINE_SOURCE == "trigger" && ($ASSIGNEE_USER_ID == ${agentUserId} || $OBJECT_DESCRIPTION =~ /@${agentUserName}/)`,
5940
+ when: "always",
5941
+ },
5942
+ {
5943
+ when: "never",
5944
+ },
5945
+ ],
5946
+ script: [
5947
+ ...shared_1.baseSetupScript,
5948
+ ...(0, shared_1.callClaude)({
5949
+ prompt: (0, prompts_1.getEventPrompt)({ agentUserName: agentUserName }),
5950
+ }),
5951
+ ],
5952
+ };
5953
+ };
5954
+ exports.createAgentEventJob = createAgentEventJob;
5955
+ //# sourceMappingURL=createAgentEventJob.js.map
5956
+
5957
+ /***/ }),
5958
+
5959
+ /***/ 8672:
5960
+ /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
5961
+
5962
+ "use strict";
5963
+
5964
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
5965
+ exports.createAgentReviewJob = void 0;
5966
+ const rules_1 = __nccwpck_require__(7551);
5967
+ const prompts_1 = __nccwpck_require__(8698);
5968
+ const shared_1 = __nccwpck_require__(732);
5969
+ const utils_1 = __nccwpck_require__(9133);
5970
+ const createAgentReviewJob = (context) => {
5971
+ const baseJob = (0, shared_1.createBaseAgentJob)(context);
5972
+ const agentUserName = (0, utils_1.getAgentUserName)(context);
5973
+ return {
5974
+ ...baseJob,
5975
+ name: context.name + "-agent-review",
5976
+ rules: [
5977
+ {
5978
+ ...rules_1.RULE_IS_MERGE_REQUEST,
5979
+ when: "always",
5980
+ },
5981
+ {
5982
+ when: "never",
5983
+ },
5984
+ ],
5985
+ script: [
5986
+ ...shared_1.baseSetupScript,
5987
+ ...(0, shared_1.callClaude)({
5988
+ prompt: (0, prompts_1.getMergeRequestPrompt)({
5989
+ agentUserName: agentUserName,
5990
+ }),
5991
+ }),
5992
+ ],
5993
+ };
5994
+ };
5995
+ exports.createAgentReviewJob = createAgentReviewJob;
5996
+ //# sourceMappingURL=createAgentReviewJob.js.map
5997
+
5998
+ /***/ }),
5999
+
6000
+ /***/ 1455:
6001
+ /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
6002
+
6003
+ "use strict";
6004
+
6005
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
6006
+ exports.createJobsForAgentContext = void 0;
6007
+ const createAgentEventJob_1 = __nccwpck_require__(9404);
6008
+ const createAgentReviewJob_1 = __nccwpck_require__(8672);
6009
+ const createJobsForAgentContext = (context) => {
6010
+ return [(0, createAgentEventJob_1.createAgentEventJob)(context), (0, createAgentReviewJob_1.createAgentReviewJob)(context)];
6011
+ };
6012
+ exports.createJobsForAgentContext = createJobsForAgentContext;
6013
+ //# sourceMappingURL=createJobsForAgentContext.js.map
6014
+
6015
+ /***/ }),
6016
+
6017
+ /***/ 8698:
6018
+ /***/ ((__unused_webpack_module, exports) => {
6019
+
6020
+ "use strict";
6021
+
6022
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
6023
+ exports.getMergeRequestPrompt = exports.getEventPrompt = void 0;
6024
+ const header = () => `
6025
+ Project ID: $CI_PROJECT_ID
6026
+ GitLab Host: $CI_SERVER_URL
6027
+ `;
6028
+ const identity = ({ agentUserName }) => `
6029
+ ## Identity
6030
+ - Your GitLab username is "${agentUserName}".
6031
+ `;
6032
+ const goldenRules = ({ agentUserName }) => `
6033
+ ## Golden Rules
6034
+ - Use the \`gitlab-mcp\` tool for ALL GitLab actions. If a needed action is missing, use GitLab REST/GraphQL API directly as a fallback.
6035
+ - NEVER mention yourself ("@${agentUserName}").
6036
+ - NEVER push to main/default or any protected branch. Always create a new branch and open a Merge Request (MR).
6037
+ - Do not create an MR for a **closed** issue.
6038
+ - Keep actions minimal and idempotent. Avoid duplicate comments or duplicate MRs.
6039
+ - Use ONE stable \`source_branch\` per run; do not regenerate its name later.
6040
+ `;
6041
+ const commentGuidelines = () => `
6042
+ ## Comment Guidelines (flexible, not verbatim)
6043
+ - Keep tone professional, friendly, and concise.
6044
+ - Always @-mention the human author when replying; never mention yourself.
6045
+ - Acknowledgements: confirm you saw the request and you’ll handle it.
6046
+ - MR updates: acknowledge feedback and say you’ll apply/have applied the change.
6047
+ - Q&A: answer directly first; add context/links only if useful.
6048
+ - Avoid repeating identical boilerplate across comments.
6049
+ `;
6050
+ const mcpAndApi = () => `
6051
+ ## Tools & API (MCP-first, REST/GraphQL fallback)
6052
+ Use these \`gitlab-mcp\` capabilities when available (names illustrative—match the actual tool schema):
6053
+
6054
+ - **Comments**
6055
+ - \`gitlab-mcp.comment.create({ project_id: $CI_PROJECT_ID, target: "issue"|"mr", iid, body })\`
6056
+
6057
+ - **Branch**
6058
+ - \`gitlab-mcp.branch.create({ project_id: $CI_PROJECT_ID, from: "<default_branch>", name: "<source_branch>" })\`
6059
+
6060
+ - **Commits & push**
6061
+ - \`gitlab-mcp.commit.push({ project_id: $CI_PROJECT_ID, branch: "<source_branch>", message, files: [{ path, content | patch }] })\`
6062
+
6063
+ - **Merge Requests**
6064
+ - \`gitlab-mcp.merge_request.create({ project_id: $CI_PROJECT_ID, source_branch, target_branch: "<default_branch>", title, description, assign_to_self: true })\`
6065
+ - \`gitlab-mcp.merge_request.update({ project_id: $CI_PROJECT_ID, mr_iid, ... })\`
6066
+ - \`gitlab-mcp.merge_request.rebase({ project_id: $CI_PROJECT_ID, mr_iid, onto: "<default_branch>" })\`
6067
+
6068
+ - **Read/verify**
6069
+ - \`gitlab-mcp.project.get({ project_id: $CI_PROJECT_ID })\` → default branch
6070
+ - \`gitlab-mcp.repo.compare({ project_id: $CI_PROJECT_ID, from: "<default_branch>", to: "<source_branch>" })\`
6071
+ - \`gitlab-mcp.repo.branch.get({ project_id: $CI_PROJECT_ID, name: "<source_branch>" })\`
6072
+ - \`gitlab-mcp.repo.commits.list({ project_id: $CI_PROJECT_ID, ref_name: "<source_branch>", per_page: 1 })\`
6073
+
6074
+ ### Fallback: Direct GitLab API
6075
+ If MCP lacks an operation, call GitLab’s REST/GraphQL API directly.
6076
+
6077
+ - **Authentication**
6078
+ Use the environment variable \`GITLAB_PERSONAL_ACCESS_TOKEN\`.
6079
+ Send it in the HTTP header:
6080
+ \`\`\`
6081
+ Private-Token: $GITLAB_PERSONAL_ACCESS_TOKEN
6082
+ \`\`\`
6083
+
6084
+ - **Host & project variables**
6085
+ - API base URL: \`$CI_SERVER_URL/api/v4\`
6086
+ - Project ID: \`$CI_PROJECT_ID\`
6087
+
6088
+ - **Examples**
6089
+ - Get project (default branch):
6090
+ \`GET $CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID\`
6091
+ - Get/create branch:
6092
+ \`GET|POST $CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/repository/branches\`
6093
+ - Compare refs:
6094
+ \`GET $CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/repository/compare?from=<default>&to=<source>\`
6095
+ - List commits:
6096
+ \`GET $CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/repository/commits?ref_name=<branch>&per_page=1\`
6097
+ - Create comment on issue/MR:
6098
+ \`POST $CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/issues/:iid/notes\`
6099
+ \`POST $CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/merge_requests/:iid/notes\`
6100
+ - Create MR:
6101
+ \`POST $CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/merge_requests\`
6102
+ - Get MR changes:
6103
+ \`GET $CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/merge_requests/:iid/changes\`
6104
+ `;
6105
+ const outputDiscipline = ({ agentUserName }) => `
6106
+ ## Output Discipline
6107
+ - Prefer \`gitlab-mcp\` tool calls. If unavailable, output direct API requests (endpoint, method, headers, JSON body).
6108
+ - Keep comments concise and professional.
6109
+ - Never include "@${agentUserName}" in any body.
6110
+ `;
6111
+ // --- Event-specific sections ---
6112
+ const eventSelfParse = () => `
6113
+ ## Self-Parse the Raw Payload (no preprocessing available)
6114
+ From \`event_json\`, extract:
6115
+ - kind: "issue" | "merge_request" | "note"
6116
+ - target + iid from URL:
6117
+ - \`/-/issues/<n>\` → target="issue", iid=<n>
6118
+ - \`/-/merge_requests/<n>\` → target="mr", iid=<n>
6119
+ - note_id if present (\`#note_<id>\`)
6120
+ - description/body text, state, author \`user_username\`, timestamps
6121
+ - project id/path; detect default branch via tool/API when needed
6122
+
6123
+ If any key is missing, choose the safest minimal action or briefly explain via a comment.
6124
+ `;
6125
+ const eventWorkflow = () => `
6126
+ ## High-Reliability Workflow (sequence + postconditions)
6127
+ Follow this order for any change work:
6128
+
6129
+ 1) **Acknowledge** with a short comment on the issue/MR thread.
6130
+ 2) **Discover default branch** (e.g., "main") via MCP or API.
6131
+ 3) **Create a working branch** from default (stable name, e.g., \`fix/issue-<iid>-<slug>\` or \`feat/issue-<iid>-<slug>\`).
6132
+ 4) **Write changes → commit → push to remote branch.**
6133
+ 5) **Verify push landed**:
6134
+ - Fetch latest commit on \`source_branch\`; record its short SHA.
6135
+ - Compare default vs \`source_branch\` and ensure \`diffs.length > 0\`.
6136
+ 6) **Create or update MR** ONLY if there is a non-empty diff.
6137
+ - Include \`Closes #<issue_iid>\` in MR description when applicable.
6138
+ - Assign yourself to the MR.
6139
+ 7) **Follow-up comment** with branch name, commit short SHA, files changed count, and MR link.
6140
+ 8) **If verification fails**:
6141
+ - Do NOT create the MR.
6142
+ - Comment the exact failure and retry once with a fresh branch name. If still failing, comment and stop.
6143
+
6144
+ For Q&A-only (no code changes), just post a concise, helpful answer on the same issue/MR.
6145
+ `;
6146
+ // --- MR-specific sections ---
6147
+ const mrScope = ({ agentUserName }) => `
6148
+ ## Identity & Scope
6149
+ - Your GitLab username is "${agentUserName}".
6150
+ - This prompt runs in the context of ONE MR (no webhook).
6151
+ - You may review, comment, rebase, and push updates **to the MR's source branch**.
6152
+ - You must **never merge** the MR yourself.
6153
+ `;
6154
+ const mrWorkflow = () => `
6155
+ ## High-Reliability Review Workflow
6156
+ Follow this sequence with verification at each step:
6157
+
6158
+ 1) **Collect context**
6159
+ - Get MR metadata (source_branch, target_branch, state, draft/WIP).
6160
+ - Fetch the full changeset/diffs and open discussions (notes, threads, unresolved discussions).
6161
+ - Read existing reviews/comments to avoid duplication.
6162
+ - (Optional) Fetch recent CI pipeline(s) for this MR SHA/branch).
6163
+
6164
+ 2) **Code review**
6165
+ - Identify required changes (bugs, tests, style, security, perf, docs).
6166
+ - If no meaningful changes are needed:
6167
+ - Post a concise review comment summarizing findings.
6168
+ - Ask for review by a **recent active human contributor** (not you).
6169
+
6170
+ 3) **If changes are needed**
6171
+ - Post a short acknowledgment comment on the MR.
6172
+ - **Rebase** the MR onto the target/default branch (resolve trivial conflicts).
6173
+ - Implement minimal, safe changes; keep commits small and clear.
6174
+ - **Push** to the MR's **source_branch**.
6175
+ - **Verify push landed** (latest commit short SHA; compare target vs source shows diffs > 0).
6176
+ - Comment summarizing what changed and why.
6177
+
6178
+ 4) **CI pipeline**
6179
+ - Check pipeline status for the new commit on the MR branch.
6180
+ - Retry/re-run if allowed on flaky failures; fix minimal issues; push again if needed.
6181
+ - If still failing, comment with failure summary and next steps.
6182
+
6183
+ 5) **Assign human reviewer if ready**
6184
+ - If discussions are resolved and CI is passing (or running), request review from a recent active human contributor (not you).
6185
+
6186
+ 6) **Stdout summary**
6187
+ - Print concise summary: commits pushed (short SHAs), files changed count, discussions resolved/left, CI status, and requested reviewers.
6188
+ `;
6189
+ const fallbackApiAuth = () => `
6190
+ ## Fallback API Auth (if MCP lacks a method)
6191
+ - Base URL: \`$CI_SERVER_URL/api/v4\`
6192
+ - Project: \`$CI_PROJECT_ID\`
6193
+ - Header: \`Private-Token: $GITLAB_PERSONAL_ACCESS_TOKEN\`
6194
+ `;
6195
+ // ---------- Public builders ----------
6196
+ const getEventPrompt = ({ agentUserName }) => `
6197
+ You are a GitLab assistant bot. You receive ONE raw GitLab webhook JSON payload.
6198
+
6199
+ ${header()}
6200
+ ---
6201
+ event_json:
6202
+ $(cat $TRIGGER_PAYLOAD)
6203
+ ---
6204
+
6205
+ ${identity({ agentUserName })}
6206
+ ${goldenRules({ agentUserName })}
6207
+ ${eventSelfParse()}
6208
+ ${eventWorkflow()}
6209
+ ${commentGuidelines()}
6210
+ ${mcpAndApi()}
6211
+ ${outputDiscipline({ agentUserName })}
6212
+ `;
6213
+ exports.getEventPrompt = getEventPrompt;
6214
+ const getMergeRequestPrompt = ({ agentUserName }) => `
6215
+ You are a GitLab assistant bot reviewing and updating a single Merge Request (MR).
6216
+
6217
+ ${header()}
6218
+ ---
6219
+ merge_request_iid: $CI_MERGE_REQUEST_IID
6220
+ title: $CI_MERGE_REQUEST_TITLE
6221
+ description: $CI_MERGE_REQUEST_DESCRIPTION
6222
+ ---
6223
+
6224
+ ${mrScope({ agentUserName })}
6225
+ ${goldenRules({ agentUserName })}
6226
+ ${mrWorkflow()}
6227
+ ${commentGuidelines()}
6228
+ ${mcpAndApi()}
6229
+ ${fallbackApiAuth()}
6230
+ ## Output Discipline (MR)
6231
+ - Prefer \`gitlab-mcp\` tool calls; if unavailable, provide explicit REST calls (method, url, headers, body).
6232
+ - At the end, print a **plain-text** summary to STDOUT including:
6233
+ - \`source_branch\` and \`target_branch\`
6234
+ - commits pushed (short SHAs)
6235
+ - number of files changed
6236
+ - CI status/result
6237
+ - reviewers requested (if any)
6238
+ - Do **not** merge the MR yourself under any circumstance.
6239
+ `;
6240
+ exports.getMergeRequestPrompt = getMergeRequestPrompt;
6241
+ //# sourceMappingURL=prompts.js.map
6242
+
6243
+ /***/ }),
6244
+
6245
+ /***/ 732:
6246
+ /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
6247
+
6248
+ "use strict";
6249
+
6250
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
6251
+ exports.callClaude = exports.baseSetupScript = exports.createBaseAgentJob = void 0;
6252
+ const bashEscape_1 = __nccwpck_require__(2463);
6253
+ const createBaseAgentJob = (context) => ({
6254
+ stage: "agents",
6255
+ envMode: "none",
6256
+ image: "node:24-alpine3.21",
6257
+ variables: {
6258
+ MAX_MCP_OUTPUT_TOKENS: "75000",
6259
+ GITLAB_PERSONAL_ACCESS_TOKEN: "$AGENT_GITLAB_PERSONAL_ACCESS_TOKEN", // TODO: we don't have global secret keys to configure yet
6260
+ GITLAB_API_URL: "$CI_API_V4_URL",
6261
+ },
6262
+ });
6263
+ exports.createBaseAgentJob = createBaseAgentJob;
6264
+ exports.baseSetupScript = [
6265
+ "apk update",
6266
+ "apk add --no-cache git curl bash",
6267
+ "npm install -g @anthropic-ai/claude-code",
6268
+ "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",
6269
+ ];
6270
+ const callClaude = ({ prompt }) => {
6271
+ return [
6272
+ `export PROMPT="${(0, bashEscape_1.escapeNewlines)((0, bashEscape_1.escapeDoubleQuotes)((0, bashEscape_1.escapeBackTicks)(prompt)))}"`,
6273
+ //'echo "$PROMPT"',
6274
+ `claude -p "$PROMPT" --permission-mode acceptEdits --allowedTools "Bash(*) Read(*) Edit(*) Write(*) mcp__gitlab" --verbose --debug`,
6275
+ ];
6276
+ };
6277
+ exports.callClaude = callClaude;
6278
+ //# sourceMappingURL=shared.js.map
6279
+
6280
+ /***/ }),
6281
+
6282
+ /***/ 9133:
6283
+ /***/ ((__unused_webpack_module, exports) => {
6284
+
6285
+ "use strict";
6286
+
6287
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
6288
+ exports.getAgentUserId = exports.getAgentUserName = void 0;
6289
+ const getAgentUserName = (context) => {
6290
+ var _a, _b;
6291
+ return (_b = (_a = context.agentConfig.agentUser) === null || _a === void 0 ? void 0 : _a.username) !== null && _b !== void 0 ? _b : "agent.claude";
6292
+ };
6293
+ exports.getAgentUserName = getAgentUserName;
6294
+ const getAgentUserId = (context) => {
6295
+ var _a, _b;
6296
+ return (_b = (_a = context.agentConfig.agentUser) === null || _a === void 0 ? void 0 : _a.userId) !== null && _b !== void 0 ? _b : "$DEFAULT_AGENT_USER_ID";
6297
+ };
6298
+ exports.getAgentUserId = getAgentUserId;
6299
+ //# sourceMappingURL=utils.js.map
6300
+
6301
+ /***/ }),
6302
+
5882
6303
  /***/ 3579:
5883
6304
  /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
5884
6305
 
@@ -5891,8 +6312,10 @@ const createWorkspaceContext_1 = __nccwpck_require__(6558);
5891
6312
  const types_1 = __nccwpck_require__(1853);
5892
6313
  const createJobsForComponent_1 = __nccwpck_require__(2321);
5893
6314
  const createJobsForWorkspace_1 = __nccwpck_require__(803);
6315
+ const createJobsForAgentContext_1 = __nccwpck_require__(1455);
6316
+ const createAgentContext_1 = __nccwpck_require__(2636);
5894
6317
  const createAllJobs = async ({ config, trigger, pipelineType, }) => {
5895
- var _a;
6318
+ var _a, _b;
5896
6319
  const allComponentsContext = await (0, createAllComponentsContext_1.createAllComponentsContext)({
5897
6320
  config,
5898
6321
  trigger,
@@ -5924,6 +6347,13 @@ const createAllJobs = async ({ config, trigger, pipelineType, }) => {
5924
6347
  jobs: (0, createJobsForComponent_1.createJobsForComponentContext)(context),
5925
6348
  };
5926
6349
  }),
6350
+ agents: await Promise.all(Object.keys((_b = config.agents) !== null && _b !== void 0 ? _b : {}).map(async (agentName) => {
6351
+ const context = await (0, createAgentContext_1.createAgentContext)({ agentName, config });
6352
+ return {
6353
+ context,
6354
+ jobs: (0, createJobsForAgentContext_1.createJobsForAgentContext)(context),
6355
+ };
6356
+ })).then((f) => f.flat()),
5927
6357
  };
5928
6358
  };
5929
6359
  exports.createAllJobs = createAllJobs;
@@ -6028,7 +6458,12 @@ const createMainPipeline = async (pipelineType, config) => {
6028
6458
  const bIndex = componentNames.findIndex((c) => c === b.context.name);
6029
6459
  return aIndex - bIndex;
6030
6460
  });
6031
- const allJobs = [...allWorkspaceJobs, ...allComponentJobs].reduce((acc, { gitlabJob, name, context }) => {
6461
+ const allGlobalJobs = allJobsPerTrigger.filter((j) => { var _a; return ((_a = j.context) === null || _a === void 0 ? void 0 : _a.type) === "agent"; });
6462
+ const allJobs = [
6463
+ ...allWorkspaceJobs,
6464
+ ...allComponentJobs,
6465
+ ...allGlobalJobs,
6466
+ ].reduce((acc, { gitlabJob, name, context }) => {
6032
6467
  var _a, _b;
6033
6468
  // merge jobs, if a job is already there, merge the rules
6034
6469
  // this is currently needed because of envMode: "none", which creates the same job for all triggers, so it can appear multiple times
@@ -6067,12 +6502,16 @@ function getGitlabRulesForTrigger(trigger) {
6067
6502
  // taggedRelease: on tag
6068
6503
  switch (trigger) {
6069
6504
  case "mainBranch":
6070
- return [rules_1.RULE_IS_MAIN_BRANCH_AND_NOT_RELEASE_COMMIT];
6505
+ return [
6506
+ rules_1.RULE_NEVER_ON_AGENT_TRIGGER,
6507
+ rules_1.RULE_IS_MAIN_BRANCH_AND_NOT_RELEASE_COMMIT,
6508
+ ];
6071
6509
  case "mr":
6072
- return [rules_1.RULE_IS_MERGE_REQUEST];
6510
+ return [rules_1.RULE_NEVER_ON_AGENT_TRIGGER, rules_1.RULE_IS_MERGE_REQUEST];
6073
6511
  case "taggedRelease":
6074
- return [rules_1.RULE_IS_TAGGED_RELEASE];
6512
+ return [rules_1.RULE_NEVER_ON_AGENT_TRIGGER, rules_1.RULE_IS_TAGGED_RELEASE];
6075
6513
  }
6514
+ throw new Error(`${trigger} is not supported`);
6076
6515
  }
6077
6516
  //# sourceMappingURL=createMainPipeline.js.map
6078
6517
 
@@ -6210,7 +6649,7 @@ const BashExpression_1 = __nccwpck_require__(2376);
6210
6649
  exports.GITLAB_ENVIRONMENT_URL_VARIABLE = "CL_GITLAB_ENVIRONMENT_URL";
6211
6650
  const getFullJobName = ({ type, name, baseName, allJobs, env, }) => {
6212
6651
  const shouldAddIcon = allJobs.workspaces.length > 0;
6213
- const icon = type === "component" ? "🔹" : "🔸";
6652
+ const icon = type === "component" ? "🔹" : type === "agent" ? "🤖" : "🔸";
6214
6653
  const prefix = shouldAddIcon ? icon + " " : "";
6215
6654
  if (env) {
6216
6655
  return `${prefix}${baseName} ${name} | ${env} `;
@@ -6253,13 +6692,15 @@ const getJobName = (need) => (0, lodash_1.isObject)(need) ? need.job : need;
6253
6692
  const makeGitlabJob = (context, job, allJobs, baseRules) => {
6254
6693
  var _a, _b;
6255
6694
  const { environment, envMode, needsStages, name, needs, jobTags, script, variables, runnerVariables, when, ...rest } = job;
6256
- const stage = envMode === "stagePerEnv" ? `${job.stage} ${context.env}` : job.stage;
6695
+ const stage = envMode === "stagePerEnv" && context.type !== "agent"
6696
+ ? `${job.stage} ${context.env}`
6697
+ : job.stage;
6257
6698
  const deduplicatedGitlabNeeds = getGitlabNeeds(context, job, allJobs);
6258
6699
  const fullJobName = getFullJobName({
6259
6700
  type: context.type,
6260
6701
  name,
6261
6702
  baseName: context.name,
6262
- env: envMode !== "none" ? context.env : undefined,
6703
+ env: envMode !== "none" && context.type !== "agent" ? context.env : undefined,
6263
6704
  allJobs,
6264
6705
  });
6265
6706
  // backwards compatibility, some may still use KUBERNETES_CPU_REQUEST, KUBERNETES_MEMORY_REQUEST, etc. in variables.
@@ -6292,6 +6733,8 @@ const makeGitlabJob = (context, job, allJobs, baseRules) => {
6292
6733
  : []),
6293
6734
  ];
6294
6735
  const gitlabJob = {
6736
+ retry: defaults_1.BASE_RETRY,
6737
+ interruptible: true,
6295
6738
  ...rest,
6296
6739
  rules: rules.length > 0 ? rules : undefined,
6297
6740
  variables: {
@@ -6303,8 +6746,6 @@ const makeGitlabJob = (context, job, allJobs, baseRules) => {
6303
6746
  stage,
6304
6747
  // sort in a predictable manner for snapshot tests
6305
6748
  needs: deduplicatedGitlabNeeds,
6306
- retry: defaults_1.BASE_RETRY,
6307
- interruptible: true,
6308
6749
  };
6309
6750
  const modified = addGitlabEnvironment(context, environment, gitlabJob, allJobs);
6310
6751
  return [fullJobName, (0, removeUndefined_1.removeUndefined)(modified)];
@@ -6316,7 +6757,7 @@ const addGitlabEnvironment = (context, catladderJobEnvironment, job, allJobs) =>
6316
6757
  return job;
6317
6758
  }
6318
6759
  if (context.type !== "component") {
6319
- // don't add enviornment for workspace jobs atm.
6760
+ // don't add enviornment for workspace and agent jobs atm.
6320
6761
  return job;
6321
6762
  }
6322
6763
  const { env, name, environment } = context;
@@ -6358,7 +6799,11 @@ const addGitlabEnvironment = (context, catladderJobEnvironment, job, allJobs) =>
6358
6799
  };
6359
6800
  const createGitlabJobs = async (allJobs, baseRules) => {
6360
6801
  // TODO: add workspace jobs
6361
- return [...allJobs.workspaces, ...allJobs.components].flatMap(({ context, jobs }) => {
6802
+ return [
6803
+ ...allJobs.workspaces,
6804
+ ...allJobs.components,
6805
+ ...allJobs.agents,
6806
+ ].flatMap(({ context, jobs }) => {
6362
6807
  return jobs.map((job) => {
6363
6808
  const [fullJobName, gitlabJob] = (0, exports.makeGitlabJob)(context, job, allJobs, baseRules);
6364
6809
  return {
@@ -6371,10 +6816,13 @@ const createGitlabJobs = async (allJobs, baseRules) => {
6371
6816
  };
6372
6817
  exports.createGitlabJobs = createGitlabJobs;
6373
6818
  function getGitlabNeeds(context, job, allJobs) {
6819
+ var _a;
6374
6820
  const needs = context.type === "workspace"
6375
6821
  ? getGitlabNeedsForWorkspaceJob(context, job, allJobs)
6376
- : getGitlabNeedsForComponentJob(context, job, allJobs);
6377
- return deduplicateNeeds(needs);
6822
+ : context.type === "agent"
6823
+ ? ((_a = job.needs) !== null && _a !== void 0 ? _a : null)
6824
+ : getGitlabNeedsForComponentJob(context, job, allJobs);
6825
+ return needs ? deduplicateNeeds(needs) : undefined;
6378
6826
  }
6379
6827
  function deduplicateNeeds(needs) {
6380
6828
  return needs
@@ -6496,6 +6944,13 @@ const createGitlabPipelineWithDefaults = ({ image, variables, before_script, ...
6496
6944
  workflow: {
6497
6945
  name: "$PIPELINE_ICON $PIPELINE_NAME",
6498
6946
  rules: [
6947
+ {
6948
+ if: '$CI_PIPELINE_SOURCE == "trigger"',
6949
+ variables: {
6950
+ PIPELINE_ICON: "🤖",
6951
+ PIPELINE_NAME: "Thinking...",
6952
+ },
6953
+ },
6499
6954
  {
6500
6955
  if: rules_1.RULE_IS_MERGE_REQUEST.if,
6501
6956
  variables: {
@@ -6514,7 +6969,7 @@ const createGitlabPipelineWithDefaults = ({ image, variables, before_script, ...
6514
6969
  if: rules_1.RULE_IS_MAIN_BRANCH_AND_NOT_RELEASE_COMMIT.if,
6515
6970
  variables: {
6516
6971
  PIPELINE_ICON: "🐱🔨",
6517
- PIPELINE_NAME: "Main $CI_COMMIT_REF_NAME",
6972
+ PIPELINE_NAME: "Main",
6518
6973
  },
6519
6974
  },
6520
6975
  {
@@ -6794,7 +7249,7 @@ exports.getWorkspaceDependencies = getWorkspaceDependencies;
6794
7249
  "use strict";
6795
7250
 
6796
7251
  Object.defineProperty(exports, "__esModule", ({ value: true }));
6797
- exports.RULES_MANUAL_RELEASE = exports.RULES_RELEASE = exports.RULE_CONDITION_HOTFIX_BRANCH = exports.RULE_IS_TAGGED_RELEASE = exports.RULE_IS_MERGE_REQUEST = exports.RULE_NEVER_ON_SCHEDULE = exports.RULE_NEVER_ON_RELEASE_COMMIT = exports.RULE_IS_MAIN_BRANCH_AND_NOT_RELEASE_COMMIT = exports.RULE_IS_MAIN_BRANCH = exports.RULE_CONDITION_NOT_RELEASE_COMMIT = exports.RULE_CONDITION_RELEASE_COMMIT = exports.RULE_CONDITION_MAIN_BRANCH = void 0;
7252
+ exports.RULES_MANUAL_RELEASE = exports.RULES_RELEASE = exports.RULE_CONDITION_HOTFIX_BRANCH = exports.RULE_IS_TAGGED_RELEASE = exports.RULE_IS_MERGE_REQUEST = exports.RULE_NEVER_ON_SCHEDULE = exports.RULE_NEVER_ON_AGENT_TRIGGER = exports.RULE_NEVER_ON_RELEASE_COMMIT = exports.RULE_IS_MAIN_BRANCH_AND_NOT_RELEASE_COMMIT = exports.RULE_IS_MAIN_BRANCH = exports.RULE_CONDITION_NOT_RELEASE_COMMIT = exports.RULE_CONDITION_RELEASE_COMMIT = exports.RULE_CONDITION_MAIN_BRANCH = void 0;
6798
7253
  exports.RULE_CONDITION_MAIN_BRANCH = "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH";
6799
7254
  exports.RULE_CONDITION_RELEASE_COMMIT = "$CI_COMMIT_MESSAGE =~ /^chore\\(release\\).*/";
6800
7255
  exports.RULE_CONDITION_NOT_RELEASE_COMMIT = "$CI_COMMIT_MESSAGE !~ /^chore\\(release\\).*/";
@@ -6808,6 +7263,11 @@ exports.RULE_NEVER_ON_RELEASE_COMMIT = {
6808
7263
  if: exports.RULE_CONDITION_RELEASE_COMMIT,
6809
7264
  when: "never",
6810
7265
  };
7266
+ // currently, we consider all triggered pipelines as agent triggers
7267
+ exports.RULE_NEVER_ON_AGENT_TRIGGER = {
7268
+ if: '$CI_PIPELINE_SOURCE == "trigger"',
7269
+ when: "never",
7270
+ };
6811
7271
  exports.RULE_NEVER_ON_SCHEDULE = {
6812
7272
  if: '$CI_PIPELINE_SOURCE == "schedule"',
6813
7273
  when: "never",
@@ -6821,6 +7281,7 @@ exports.RULE_IS_TAGGED_RELEASE = {
6821
7281
  exports.RULE_CONDITION_HOTFIX_BRANCH = "$CI_COMMIT_BRANCH =~ /^[0-9]+.([0-9]+|x).x$/";
6822
7282
  exports.RULES_RELEASE = [
6823
7283
  exports.RULE_NEVER_ON_RELEASE_COMMIT,
7284
+ exports.RULE_NEVER_ON_AGENT_TRIGGER,
6824
7285
  exports.RULE_NEVER_ON_SCHEDULE,
6825
7286
  {
6826
7287
  if: exports.RULE_CONDITION_MAIN_BRANCH + ' && $AUTO_RELEASE == "true"',
@@ -6837,6 +7298,7 @@ exports.RULES_RELEASE = [
6837
7298
  ];
6838
7299
  exports.RULES_MANUAL_RELEASE = [
6839
7300
  exports.RULE_NEVER_ON_RELEASE_COMMIT,
7301
+ exports.RULE_NEVER_ON_AGENT_TRIGGER,
6840
7302
  exports.RULE_NEVER_ON_SCHEDULE,
6841
7303
  {
6842
7304
  if: exports.RULE_CONDITION_MAIN_BRANCH,
@@ -6865,6 +7327,16 @@ exports.getRunnerImage = getRunnerImage;
6865
7327
 
6866
7328
  /***/ }),
6867
7329
 
7330
+ /***/ 9632:
7331
+ /***/ ((__unused_webpack_module, exports) => {
7332
+
7333
+ "use strict";
7334
+
7335
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
7336
+ //# sourceMappingURL=agent.js.map
7337
+
7338
+ /***/ }),
7339
+
6868
7340
  /***/ 7770:
6869
7341
  /***/ ((__unused_webpack_module, exports) => {
6870
7342
 
@@ -6972,6 +7444,7 @@ __exportStar(__nccwpck_require__(1724), exports);
6972
7444
  __exportStar(__nccwpck_require__(8207), exports);
6973
7445
  __exportStar(__nccwpck_require__(2074), exports);
6974
7446
  __exportStar(__nccwpck_require__(7432), exports);
7447
+ __exportStar(__nccwpck_require__(9632), exports);
6975
7448
  //# sourceMappingURL=index.js.map
6976
7449
 
6977
7450
  /***/ }),
@@ -6999,6 +7472,7 @@ exports.BASE_STAGES = [
6999
7472
  "build",
7000
7473
  "deploy",
7001
7474
  "verify",
7475
+ "agents",
7002
7476
  "rollback",
7003
7477
  "stop",
7004
7478
  ];