@mycompbox/compbox-cli 1.21.18 → 1.21.20

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 (91) hide show
  1. package/.tsbuildinfo +1 -1
  2. package/agents/internal/feature-worker.md +311 -0
  3. package/agents/orchestrator.md +1203 -0
  4. package/agents/planner.md +694 -0
  5. package/agents/request-formulator.md +450 -0
  6. package/commands/run.d.ts +4 -1
  7. package/commands/run.d.ts.map +1 -1
  8. package/commands/run.js +116 -15
  9. package/commands/run.js.map +1 -1
  10. package/commands/workspace.d.ts +41 -2
  11. package/commands/workspace.d.ts.map +1 -1
  12. package/commands/workspace.js +148 -7
  13. package/commands/workspace.js.map +1 -1
  14. package/index.js +3193 -453
  15. package/package.json +1 -1
  16. package/utils/agent-invoker.d.ts +157 -13
  17. package/utils/agent-invoker.d.ts.map +1 -1
  18. package/utils/agent-invoker.js +587 -87
  19. package/utils/agent-invoker.js.map +1 -1
  20. package/utils/agent-permissions.d.ts +44 -0
  21. package/utils/agent-permissions.d.ts.map +1 -0
  22. package/utils/agent-permissions.js +229 -0
  23. package/utils/agent-permissions.js.map +1 -0
  24. package/utils/agent-store.d.ts +141 -0
  25. package/utils/agent-store.d.ts.map +1 -0
  26. package/utils/agent-store.js +493 -0
  27. package/utils/agent-store.js.map +1 -0
  28. package/utils/agent-trial.d.ts +34 -0
  29. package/utils/agent-trial.d.ts.map +1 -0
  30. package/utils/agent-trial.js +180 -0
  31. package/utils/agent-trial.js.map +1 -0
  32. package/utils/api-client.d.ts +11 -0
  33. package/utils/api-client.d.ts.map +1 -1
  34. package/utils/api-client.js +31 -0
  35. package/utils/api-client.js.map +1 -1
  36. package/utils/belt-engine.d.ts +72 -0
  37. package/utils/belt-engine.d.ts.map +1 -0
  38. package/utils/belt-engine.js +136 -0
  39. package/utils/belt-engine.js.map +1 -0
  40. package/utils/bundled-agents.d.ts +29 -0
  41. package/utils/bundled-agents.d.ts.map +1 -0
  42. package/utils/bundled-agents.js +73 -0
  43. package/utils/bundled-agents.js.map +1 -0
  44. package/utils/cloud-preflight.d.ts +26 -4
  45. package/utils/cloud-preflight.d.ts.map +1 -1
  46. package/utils/cloud-preflight.js +90 -7
  47. package/utils/cloud-preflight.js.map +1 -1
  48. package/utils/custom-agent-contract.d.ts +44 -0
  49. package/utils/custom-agent-contract.d.ts.map +1 -0
  50. package/utils/custom-agent-contract.js +122 -0
  51. package/utils/custom-agent-contract.js.map +1 -0
  52. package/utils/custom-agent-permissions.d.ts +48 -0
  53. package/utils/custom-agent-permissions.d.ts.map +1 -0
  54. package/utils/custom-agent-permissions.js +109 -0
  55. package/utils/custom-agent-permissions.js.map +1 -0
  56. package/utils/custom-agent-runner.d.ts +99 -0
  57. package/utils/custom-agent-runner.d.ts.map +1 -0
  58. package/utils/custom-agent-runner.js +227 -0
  59. package/utils/custom-agent-runner.js.map +1 -0
  60. package/utils/custom-agent-sync.d.ts +59 -0
  61. package/utils/custom-agent-sync.d.ts.map +1 -0
  62. package/utils/custom-agent-sync.js +197 -0
  63. package/utils/custom-agent-sync.js.map +1 -0
  64. package/utils/key-run.d.ts +9 -0
  65. package/utils/key-run.d.ts.map +1 -1
  66. package/utils/key-run.js +18 -0
  67. package/utils/key-run.js.map +1 -1
  68. package/utils/mailbox-client.d.ts +115 -2
  69. package/utils/mailbox-client.d.ts.map +1 -1
  70. package/utils/mailbox-client.js +114 -6
  71. package/utils/mailbox-client.js.map +1 -1
  72. package/utils/merge-guard.d.ts +48 -7
  73. package/utils/merge-guard.d.ts.map +1 -1
  74. package/utils/merge-guard.js +152 -17
  75. package/utils/merge-guard.js.map +1 -1
  76. package/utils/pxpipe-savings.d.ts +12 -0
  77. package/utils/pxpipe-savings.d.ts.map +1 -0
  78. package/utils/pxpipe-savings.js +68 -0
  79. package/utils/pxpipe-savings.js.map +1 -0
  80. package/utils/run-timings.d.ts +3 -0
  81. package/utils/run-timings.d.ts.map +1 -1
  82. package/utils/run-timings.js +2 -0
  83. package/utils/run-timings.js.map +1 -1
  84. package/utils/run-workspace.d.ts +18 -0
  85. package/utils/run-workspace.d.ts.map +1 -1
  86. package/utils/run-workspace.js +46 -5
  87. package/utils/run-workspace.js.map +1 -1
  88. package/utils/wrap-up.d.ts +8 -0
  89. package/utils/wrap-up.d.ts.map +1 -1
  90. package/utils/wrap-up.js +24 -2
  91. package/utils/wrap-up.js.map +1 -1
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Custom agent permissions → enforced tool limits (ENG-569).
3
+ *
4
+ * A custom agent's stored permissions (see `customAgentPermissionsSchema` in
5
+ * @mycompbox/shared) become Claude Code `--allowedTools` / `--disallowedTools`
6
+ * lists plus the `gh` shim's deny list. The run uses `dontAsk`, so any tool not
7
+ * on the allow list is refused, never asked about.
8
+ *
9
+ * - Missing or malformed permissions fall back to read-only (read code only).
10
+ * - Unknown keys are ignored and never widen access; this is the lenient
11
+ * runner side of the strict shared schema.
12
+ * - Shell commands are only allowed when explicitly granted, and merge and
13
+ * deploy commands stay refused even then (see merge-guard.ts).
14
+ */
15
+ import { DEFAULT_CUSTOM_AGENT_PERMISSIONS } from "@mycompbox/shared";
16
+ import { CUSTOM_AGENT_GH_DENY, customAgentDisallowedTools, } from "./merge-guard.js";
17
+ const PERMISSION_KEYS = [
18
+ "readCode",
19
+ "writeCode",
20
+ "runCommands",
21
+ "accessNetwork",
22
+ "commentOnPullRequests",
23
+ ];
24
+ /** Tools for reading the repository. */
25
+ export const READ_TOOLS = Object.freeze(["Read", "Grep", "Glob", "LS"]);
26
+ /** Tools for changing files in the working copy. */
27
+ export const WRITE_TOOLS = Object.freeze(["Edit", "MultiEdit", "Write", "NotebookEdit"]);
28
+ /** Tools for running shell commands. */
29
+ export const COMMAND_TOOLS = Object.freeze(["Bash"]);
30
+ /** Tools that reach the network beyond the CompBox API. */
31
+ export const NETWORK_TOOLS = Object.freeze(["WebFetch", "WebSearch"]);
32
+ /** Narrow `gh` commands for commenting on (and reading) the reviewed pull request. */
33
+ export const PR_COMMENT_TOOLS = Object.freeze([
34
+ "Bash(gh pr view:*)",
35
+ "Bash(gh pr diff:*)",
36
+ "Bash(gh pr comment:*)",
37
+ "Bash(gh pr review:*)",
38
+ ]);
39
+ /**
40
+ * Read stored permissions leniently: a JSON string or an object; unknown keys
41
+ * and non-boolean values are ignored; anything unreadable is read-only.
42
+ */
43
+ export function resolveCustomAgentPermissions(input) {
44
+ let value = input;
45
+ if (typeof value === "string") {
46
+ try {
47
+ value = JSON.parse(value);
48
+ }
49
+ catch {
50
+ value = null;
51
+ }
52
+ }
53
+ const resolved = { ...DEFAULT_CUSTOM_AGENT_PERMISSIONS };
54
+ if (!value || typeof value !== "object" || Array.isArray(value))
55
+ return resolved;
56
+ const record = value;
57
+ for (const key of PERMISSION_KEYS) {
58
+ const v = record[key];
59
+ if (typeof v === "boolean")
60
+ resolved[key] = v;
61
+ }
62
+ return resolved;
63
+ }
64
+ /**
65
+ * Map stored permissions (any shape) to the tool limits the runner enforces.
66
+ * The merge/deploy denylist is always applied and can't be removed.
67
+ */
68
+ export function toAllowedTools(input, baseBranch) {
69
+ const permissions = resolveCustomAgentPermissions(input);
70
+ const allowed = [];
71
+ const disallowed = [];
72
+ if (permissions.readCode)
73
+ allowed.push(...READ_TOOLS);
74
+ else
75
+ disallowed.push(...READ_TOOLS);
76
+ if (permissions.writeCode)
77
+ allowed.push(...WRITE_TOOLS);
78
+ else
79
+ disallowed.push(...WRITE_TOOLS);
80
+ if (permissions.runCommands)
81
+ allowed.push(...COMMAND_TOOLS);
82
+ else if (!permissions.commentOnPullRequests)
83
+ disallowed.push(...COMMAND_TOOLS);
84
+ // With comments but no commands, Bash stays off the allow list (dontAsk
85
+ // refuses it) while the narrow gh patterns below are allowed.
86
+ if (permissions.accessNetwork)
87
+ allowed.push(...NETWORK_TOOLS);
88
+ else
89
+ disallowed.push(...NETWORK_TOOLS);
90
+ if (permissions.commentOnPullRequests)
91
+ allowed.push(...PR_COMMENT_TOOLS);
92
+ disallowed.push(...customAgentDisallowedTools(baseBranch));
93
+ return {
94
+ permissions,
95
+ allowedTools: [...new Set(allowed)],
96
+ disallowedTools: [...new Set(disallowed)],
97
+ ghDeny: [...CUSTOM_AGENT_GH_DENY],
98
+ };
99
+ }
100
+ /** Claude Code args enforcing the limits (`dontAsk` so unlisted tools are refused). */
101
+ export function customAgentToolArgs(limits) {
102
+ const args = ["--permission-mode", "dontAsk"];
103
+ if (limits.allowedTools.length > 0)
104
+ args.push("--allowedTools", ...limits.allowedTools);
105
+ if (limits.disallowedTools.length > 0)
106
+ args.push("--disallowedTools", ...limits.disallowedTools);
107
+ return args;
108
+ }
109
+ //# sourceMappingURL=custom-agent-permissions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"custom-agent-permissions.js","sourceRoot":"","sources":["../../src/utils/custom-agent-permissions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,gCAAgC,EAA+B,MAAM,mBAAmB,CAAC;AAClG,OAAO,EACL,oBAAoB,EACpB,0BAA0B,GAC3B,MAAM,kBAAkB,CAAC;AAE1B,MAAM,eAAe,GAAG;IACtB,UAAU;IACV,WAAW;IACX,aAAa;IACb,eAAe;IACf,uBAAuB;CACqC,CAAC;AAE/D,wCAAwC;AACxC,MAAM,CAAC,MAAM,UAAU,GAAsB,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;AAC3F,oDAAoD;AACpD,MAAM,CAAC,MAAM,WAAW,GAAsB,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC;AAC5G,wCAAwC;AACxC,MAAM,CAAC,MAAM,aAAa,GAAsB,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AACxE,2DAA2D;AAC3D,MAAM,CAAC,MAAM,aAAa,GAAsB,MAAM,CAAC,MA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AM,GAAG,CAAC;QAAE,IAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;IACjG,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,99 @@
1
+ import type { CustomAgentResult } from "@mycompbox/shared";
2
+ import { type ParseResultOutcome, type ResolvedSkill } from "./custom-agent-contract.js";
3
+ import { type CustomAgentToolLimits } from "./custom-agent-permissions.js";
4
+ import { type GitRunner } from "./merge-guard.js";
5
+ /** Everything needed to start one custom agent run. */
6
+ export interface CustomAgentRunSpec {
7
+ /** The agent version's instructions (untrusted). */
8
+ instructions: string;
9
+ /** Skills already resolved to text (untrusted). */
10
+ skills?: readonly ResolvedSkill[];
11
+ /** Stored permissions, any shape (unknown/malformed falls back to read-only). */
12
+ permissions: unknown;
13
+ /** Base branch of the run copy (always protected from pushes and merges). */
14
+ baseBranch?: string | null;
15
+ }
16
+ /** The argv, env and limits for one custom agent run. */
17
+ export interface CustomAgentInvocation {
18
+ args: string[];
19
+ env: NodeJS.ProcessEnv;
20
+ limits: CustomAgentToolLimits;
21
+ }
22
+ /**
23
+ * Build the `claude` argv and env for a custom agent run. Pure apart from
24
+ * writing the gh shim into `mergeGuardDir`.
25
+ */
26
+ export declare function buildCustomAgentInvocation(spec: CustomAgentRunSpec, baseEnv: NodeJS.ProcessEnv, mergeGuardDir: string | null, platform?: NodeJS.Platform): CustomAgentInvocation;
27
+ /** One action the guards refused during a run. */
28
+ export interface BlockedAction {
29
+ /** `permission` = refused by Claude Code's tool limits; `guard` = refused by the gh shim or pre-push hook. */
30
+ kind: "permission" | "guard";
31
+ tool: string;
32
+ detail: string;
33
+ }
34
+ /** What a stream-json run produced: the final text and every refused action. */
35
+ export interface CustomAgentStreamSummary {
36
+ finalText: string;
37
+ blocked: BlockedAction[];
38
+ /** Token / cost usage from the final `result` event (ENG-570); null when absent. */
39
+ usage: CustomAgentUsage | null;
40
+ }
41
+ /** What one run spent, as Claude Code reported it (ENG-570). */
42
+ export interface CustomAgentUsage {
43
+ inputTokens: number;
44
+ outputTokens: number;
45
+ cacheReadTokens: number;
46
+ cacheCreationTokens: number;
47
+ costUsd: number | null;
48
+ durationMs: number | null;
49
+ }
50
+ /**
51
+ * Read Claude Code's stream-json output: the final `result` text, tool calls
52
+ * refused by the permission layer (`permission_denials`) and tool results
53
+ * carrying a guard refusal (gh shim / pre-push hook).
54
+ */
55
+ export declare function summarizeCustomAgentStream(output: string): CustomAgentStreamSummary;
56
+ /** One line for the run log describing a refused action. */
57
+ export declare function formatBlockedAction(action: BlockedAction): string;
58
+ /** Runs a process to completion; injectable for tests. */
59
+ export type CustomAgentProcessRunner = (command: string, args: string[], opts: {
60
+ cwd: string;
61
+ env: NodeJS.ProcessEnv;
62
+ signal?: AbortSignal;
63
+ }) => Promise<{
64
+ code: number | null;
65
+ stdout: string;
66
+ stderr: string;
67
+ }>;
68
+ export interface RunCustomAgentOptions {
69
+ /** Run copy (git worktree) the agent works in. */
70
+ cwd: string;
71
+ /** `claude` binary. */
72
+ command?: string;
73
+ env?: NodeJS.ProcessEnv;
74
+ /** Folder for the gh shim; null disables the shim layer. */
75
+ mergeGuardDir: string | null;
76
+ /** Installs the pre-push guard in `cwd` when given. */
77
+ git?: GitRunner;
78
+ /** The run's log. */
79
+ log: (line: string) => void;
80
+ run?: CustomAgentProcessRunner;
81
+ signal?: AbortSignal;
82
+ platform?: NodeJS.Platform;
83
+ }
84
+ export interface CustomAgentRunOutcome {
85
+ /** Parsed result (a failure result when the output had no valid block). */
86
+ outcome: ParseResultOutcome;
87
+ result: CustomAgentResult;
88
+ blocked: BlockedAction[];
89
+ exitCode: number | null;
90
+ /** What the run spent (ENG-570); null when Claude Code didn't report it. */
91
+ usage: CustomAgentUsage | null;
92
+ }
93
+ /**
94
+ * Run one custom agent: install the guards, spawn `claude` with the enforced
95
+ * tool limits, log every refused action and parse the result block. Never
96
+ * throws; a failed run yields a failure result.
97
+ */
98
+ export declare function runCustomAgent(spec: CustomAgentRunSpec, opts: RunCustomAgentOptions): Promise<CustomAgentRunOutcome>;
99
+ //# sourceMappingURL=custom-agent-runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"custom-agent-runner.d.ts","sourceRoot":"","sources":["../../src/utils/custom-agent-runner.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAA+B,KAAK,kBAAkB,EAAE,KAAK,aAAa,EAAE,MAAM,4BAA4B,CAAC;AACtH,OAAO,EAAuC,KAAK,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAChH,OAAO,EASL,KAAK,SAAS,EACf,MAAM,kBAAkB,CAAC;AAE1B,uDAAuD;AACvD,MAAM,WAAW,kBAAkB;IACjC,oDAAoD;IACpD,YAAY,EAAE,MAAM,CAAC;IACrB,mDAAmD;IACnD,MAAM,CAAC,EAAE,SAAS,aAAa,EAAE,CAAC;IAClC,iFAAiF;IACjF,WAAW,EAAE,OAAO,CAAC;IACrB,6EAA6E;IAC7E,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,yDAAyD;AACzD,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;IACvB,MAAM,EAAE,qBAAqB,CAAC;CAC/B;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,kBAAkB,EACxB,OAAO,EAAE,MAAM,CAAC,UAAU,EAC1B,aAAa,EAAE,MAAM,GAAG,IAAI,EAC5B,QAAQ,GAAE,MAAM,CAAC,QAA2B,GAC3C,qBAAqB,CAiBvB;AAED,kDAAkD;AAClD,MAAM,WAAW,aAAa;IAC5B,8GAA8G;IAC9G,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB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AE,SAAS,CAAC;IAChB,qBAAqB;IACrB,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5B,GAAG,CAAC,EAAE,wBAAwB,CAAC;IAC/B,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC;CAC5B;AAED,MAAM,WAAW,qBAAqB;IACpC,2EAA2E;IAC3E,OAAO,EAAE,kBAAkB,CAAC;IAC5B,MAAM,EAAE,iBAAiB,CAAC;IAC1B,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,4EAA4E;IAC5E,KAAK,EAAE,gBAAgB,GAAG,IAAI,CAAC;CAChC;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAClC,IAAI,EAAE,kBAAkB,EACxB,IAAI,EAAE,qBAAqB,GAC1B,OAAO,CAAC,qBAAqB,CAAC,CA+BhC"}
@@ -0,0 +1,227 @@
1
+ /**
2
+ * Custom agent runner (ENG-569): puts the result contract, permission mapping
3
+ * and merge/deploy guard together for one custom agent run.
4
+ *
5
+ * Enforcement is at the tool layer, not in the prompt:
6
+ * - `--permission-mode dontAsk` + `--allowedTools` from the stored permissions,
7
+ * so tools the agent wasn't granted are refused;
8
+ * - `--disallowedTools` always carries the merge guard and deploy denylist;
9
+ * - a `gh` shim first on the agent's PATH refuses `pr merge` and deploy
10
+ * subcommands (`workflow run`, `release create`);
11
+ * - the pre-push hook in the run copy refuses pushes to the default branch;
12
+ * git config inherited through the environment (GIT_CONFIG_*) is dropped
13
+ * and `core.hooksPath` is pinned to the guard's folder, so an inherited
14
+ * hooks override can't replace it (ENG-573).
15
+ * Every refusal the run hits is collected and logged in the run's log.
16
+ */
17
+ import { spawn } from "node:child_process";
18
+ import { buildAgentText, parseResult } from "./custom-agent-contract.js";
19
+ import { customAgentToolArgs, toAllowedTools } from "./custom-agent-permissions.js";
20
+ import { CUSTOM_AGENT_REFUSED_MESSAGE, DECLARED_GH_REFUSED_MESSAGE, MERGE_REFUSED_MESSAGE, PUSH_REFUSED_MESSAGE, installPrePushGuardDir, withHooksDisabled, withMergeGuardPath, withoutInheritedGitConfig, } from "./merge-guard.js";
21
+ /**
22
+ * Build the `claude` argv and env for a custom agent run. Pure apart from
23
+ * writing the gh shim into `mergeGuardDir`.
24
+ */
25
+ export function buildCustomAgentInvocation(spec, baseEnv, mergeGuardDir, platform = process.platform) {
26
+ const limits = toAllowedTools(spec.permissions, spec.baseBranch);
27
+ const args = [
28
+ "-p",
29
+ buildAgentText(spec.instructions, spec.skills ?? []),
30
+ "--output-format",
31
+ "stream-json",
32
+ "--verbose",
33
+ ...customAgentToolArgs(limits),
34
+ ];
35
+ const env = {
36
+ ...withoutInheritedGitConfig(baseEnv),
37
+ COMPBOX_NONINTERACTIVE: "1",
38
+ CLAUDE_CODE_DISABLE_BACKGROUND_TASKS: "1",
39
+ PATH: withMergeGuardPath(baseEnv.PATH, mergeGuardDir, platform, limits.ghDeny),
40
+ };
41
+ return { args, env, limits };
42
+ }
43
+ const GUARD_MESSAGES = [
44
+ CUSTOM_AGENT_REFUSED_MESSAGE,
45
+ DECLARED_GH_REFUSED_MESSAGE,
46
+ MERGE_REFUSED_MESSAGE,
47
+ PUSH_REFUSED_MESSAGE,
48
+ ];
49
+ function asRecord(value) {
50
+ return typeof value === "object" && value !== null && !Array.isArray(value)
51
+ ? value
52
+ : null;
53
+ }
54
+ function textOf(content) {
55
+ if (typeof content === "string")
56
+ return content;
57
+ if (Array.isArray(content))
58
+ return content.map(textOf).join("\n");
59
+ const rec = asRecord(content);
60
+ if (rec && typeof rec.text === "string")
61
+ return rec.text;
62
+ return "";
63
+ }
64
+ function describeInput(input) {
65
+ const rec = asRecord(input);
66
+ if (rec && typeof rec.command === "string")
67
+ return rec.command;
68
+ if (input === undefined)
69
+ return "";
70
+ try {
71
+ return JSON.stringify(input);
72
+ }
73
+ catch {
74
+ return "";
75
+ }
76
+ }
77
+ function count(value) {
78
+ return typeof value === "number" && Number.isFinite(value) && value >= 0 ? Math.floor(value) : 0;
79
+ }
80
+ function optionalNumber(value) {
81
+ return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : null;
82
+ }
83
+ /** Usage from a stream-json `result` event. */
84
+ function usageOf(event) {
85
+ const u = asRecord(event.usage) ?? {};
86
+ return {
87
+ inputTokens: count(u.input_tokens),
88
+ outputTokens: count(u.output_tokens),
89
+ cacheReadTokens: count(u.cache_read_input_tokens),
90
+ cacheCreationTokens: count(u.cache_creation_input_tokens),
91
+ costUsd: optionalNumber(event.total_cost_usd),
92
+ durationMs: optionalNumber(event.duration_ms),
93
+ };
94
+ }
95
+ /**
96
+ * Read Claude Code's stream-json output: the final `result` text, tool calls
97
+ * refused by the permission layer (`permission_denials`) and tool results
98
+ * carrying a guard refusal (gh shim / pre-push hook).
99
+ */
100
+ export function summarizeCustomAgentStream(output) {
101
+ const blocked = [];
102
+ const toolNames = new Map();
103
+ let finalText = "";
104
+ let usage = null;
105
+ let sawJson = false;
106
+ for (const line of output.split("\n")) {
107
+ const trimmed = line.trim();
108
+ if (!trimmed.startsWith("{"))
109
+ continue;
110
+ let event;
111
+ try {
112
+ event = asRecord(JSON.parse(trimmed));
113
+ }
114
+ catch {
115
+ continue;
116
+ }
117
+ if (!event)
118
+ continue;
119
+ sawJson = true;
120
+ const message = asRecord(event.message);
121
+ const content = Array.isArray(message?.content) ? message.content : [];
122
+ if (event.type === "assistant") {
123
+ for (const block of content) {
124
+ const b = asRecord(block);
125
+ if (b?.type === "tool_use" && typeof b.id === "string" && typeof b.name === "string") {
126
+ toolNames.set(b.id, { name: b.name, input: b.input });
127
+ }
128
+ }
129
+ }
130
+ else if (event.type === "user") {
131
+ for (const block of content) {
132
+ const b = asRecord(block);
133
+ if (b?.type !== "tool_result")
134
+ continue;
135
+ const text = textOf(b.content);
136
+ const hit = GUARD_MESSAGES.find((m) => text.includes(m));
137
+ if (!hit)
138
+ continue;
139
+ const use = typeof b.tool_use_id === "string" ? toolNames.get(b.tool_use_id) : undefined;
140
+ blocked.push({
141
+ kind: "guard",
142
+ tool: use?.name ?? "Bash",
143
+ detail: use ? `${describeInput(use.input)} — ${hit}` : hit,
144
+ });
145
+ }
146
+ }
147
+ else if (event.type === "result") {
148
+ if (typeof event.result === "string")
149
+ finalText = event.result;
150
+ usage = usageOf(event);
151
+ const denials = Array.isArray(event.permission_denials) ? event.permission_denials : [];
152
+ for (const d of denials) {
153
+ const rec = asRecord(d);
154
+ if (!rec)
155
+ continue;
156
+ blocked.push({
157
+ kind: "permission",
158
+ tool: typeof rec.tool_name === "string" ? rec.tool_name : "unknown",
159
+ detail: describeInput(rec.tool_input),
160
+ });
161
+ }
162
+ }
163
+ }
164
+ // Not stream-json (e.g. plain text): the whole output is the final text.
165
+ if (!sawJson)
166
+ finalText = output;
167
+ return { finalText, blocked, usage };
168
+ }
169
+ /** One line for the run log describing a refused action. */
170
+ export function formatBlockedAction(action) {
171
+ const by = action.kind === "permission" ? "tool limits" : "merge/deploy guard";
172
+ const detail = action.detail.replace(/[\r\n]+/g, " ").slice(0, 300);
173
+ return `[custom-agent] blocked by ${by}: ${action.tool}${detail ? ` (${detail})` : ""}`;
174
+ }
175
+ const defaultProcessRunner = (command, args, opts) => new Promise((resolve) => {
176
+ const child = spawn(command, args, {
177
+ cwd: opts.cwd,
178
+ env: opts.env,
179
+ stdio: ["ignore", "pipe", "pipe"],
180
+ signal: opts.signal,
181
+ });
182
+ let stdout = "";
183
+ let stderr = "";
184
+ child.stdout.on("data", (c) => (stdout += c.toString("utf-8")));
185
+ child.stderr.on("data", (c) => (stderr += c.toString("utf-8")));
186
+ child.on("error", (error) => {
187
+ resolve({ code: null, stdout, stderr: stderr + error.message });
188
+ });
189
+ child.on("close", (code) => {
190
+ resolve({ code, stdout, stderr });
191
+ });
192
+ });
193
+ /**
194
+ * Run one custom agent: install the guards, spawn `claude` with the enforced
195
+ * tool limits, log every refused action and parse the result block. Never
196
+ * throws; a failed run yields a failure result.
197
+ */
198
+ export async function runCustomAgent(spec, opts) {
199
+ const invocation = buildCustomAgentInvocation(spec, opts.env ?? process.env, opts.mergeGuardDir, opts.platform);
200
+ let env = invocation.env;
201
+ if (opts.git) {
202
+ const guardHooks = await installPrePushGuardDir(opts.cwd, spec.baseBranch ?? null, opts.git);
203
+ if (guardHooks)
204
+ env = withHooksDisabled(env, guardHooks);
205
+ else
206
+ opts.log("[custom-agent] pre-push guard not installed; tool limits and gh shim still apply");
207
+ }
208
+ const run = opts.run ?? defaultProcessRunner;
209
+ const { code, stdout, stderr } = await run(opts.command ?? "claude", invocation.args, {
210
+ cwd: opts.cwd,
211
+ env,
212
+ ...(opts.signal ? { signal: opts.signal } : {}),
213
+ });
214
+ const summary = summarizeCustomAgentStream(stdout);
215
+ for (const action of summary.blocked)
216
+ opts.log(formatBlockedAction(action));
217
+ let outcome = parseResult(summary.finalText);
218
+ if (!outcome.ok && code !== 0) {
219
+ const last = stderr.trim().split("\n").pop() ?? "";
220
+ const reason = `claude exited with code ${String(code)}${last ? `: ${last}` : ""}`;
221
+ outcome = { ...outcome, reason, result: { ...outcome.result, summary: reason } };
222
+ }
223
+ if (!outcome.ok)
224
+ opts.log(`[custom-agent] result failed: ${outcome.reason}`);
225
+ return { outcome, result: outcome.result, blocked: summary.blocked, exitCode: code, usage: summary.usage };
226
+ }
227
+ //# sourceMappingURL=custom-agent-runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"custom-agent-runner.js","sourceRoot":"","sources":["../../src/utils/custom-agent-runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EAAE,cAAc,EAAE,WAAW,EAA+C,MAAM,4BAA4B,CAAC;AACtH,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAA8B,MAAM,+BAA+B,CAAC;AAChH,OAAO,EACL,4BAA4B,EAC5B,2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D,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,0BAA0B,CAAC,MAAM,CAAC,CAAC;IACnD,KAAK,MAAM,MAAM,IAAI,OAAO,CAAC,OAAO;QAAE,IAAI,CAAC,GAAG,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC;IAE5E,IAAI,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAC7C,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC;QACnD,MAAM,MAAM,GAAG,2BAA2B,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;QACnF,OAAO,GAAG,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC;IACnF,CAAC;IACD,IAAI,CAAC,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,GAAG,CAAC,iCAAiC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAC7E,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC;AAC7G,CAAC"}
@@ -0,0 +1,59 @@
1
+ import { type ResolvedSkill } from './custom-agent-contract.js';
2
+ /** One installed custom agent, as `GET /api/v1/machines/custom-agents` returns it. */
3
+ export interface InstalledCustomAgent {
4
+ installId: string;
5
+ agentId: string;
6
+ name: string;
7
+ summary: string | null;
8
+ /** The pinned version this machine should run. */
9
+ version: number;
10
+ instructions: string;
11
+ skills: ResolvedSkill[];
12
+ permissions: unknown;
13
+ canBlockBelt: boolean;
14
+ }
15
+ export interface CustomAgentInstallReport {
16
+ installId: string;
17
+ version: number;
18
+ status: 'installed' | 'failed';
19
+ }
20
+ export interface CustomAgentSyncResult {
21
+ /** Agent file names (without `.md`) written to the agents directory. */
22
+ written: string[];
23
+ /** What was reported back (or would have been, when reporting failed). */
24
+ reports: CustomAgentInstallReport[];
25
+ }
26
+ /** The custom agents installed on the machine `token` belongs to. Throws when CompBox can't say. */
27
+ export declare function fetchInstalledCustomAgents(apiUrl: string, token: string, fetchFn?: typeof fetch): Promise<InstalledCustomAgent[]>;
28
+ /** Tells CompBox which installs landed. Throws when it can't. */
29
+ export declare function reportCustomAgentInstalls(apiUrl: string, token: string, reports: readonly CustomAgentInstallReport[], fetchFn?: typeof fetch): Promise<void>;
30
+ /**
31
+ * The file name (and `@name`) an agent gets: lowercase letters, digits and
32
+ * single dashes. Empty when the name has none of those.
33
+ */
34
+ export declare function customAgentSlug(name: string): string;
35
+ /** The agent file: front matter (name, description, tool allowlist) then its text with the result contract. */
36
+ export declare function customAgentFile(agent: InstalledCustomAgent): string;
37
+ /**
38
+ * Writes each agent to `agentsDir/<slug>.md`. An agent whose name would
39
+ * overwrite a file already there (a CompBox agent, or another custom agent
40
+ * with the same slug) is not written and is reported as failed.
41
+ */
42
+ export declare function writeInstalledCustomAgents(agentsDir: string, agents: readonly InstalledCustomAgent[], log?: (message: string) => void): CustomAgentSyncResult;
43
+ /**
44
+ * Fetches, writes and reports this machine's custom agents. Never throws: on
45
+ * any failure the run keeps whatever agents it already has.
46
+ */
47
+ export declare function syncCustomAgents(opts: {
48
+ apiUrl: string;
49
+ token: string;
50
+ /**
51
+ * The run's agents directory. Called only once there is something to write,
52
+ * so the caller can make a per-run copy first; if it throws, every install
53
+ * is reported as failed.
54
+ */
55
+ agentsDir: string | (() => string);
56
+ fetchFn?: typeof fetch;
57
+ log?: (message: string) => void;
58
+ }): Promise<CustomAgentSyncResult>;
59
+ //# sourceMappingURL=custom-agent-sync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"custom-agent-sync.d.ts","sourceRoot":"","sources":["../../src/utils/custom-agent-sync.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAkB,KAAK,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAIhF,sFAAsF;AACtF,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,kDAAkD;IAClD,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,aAAa,EAAE,CAAC;IACxB,WAAW,EAAE,OAAO,CAAC;IACrB,YAAY,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,wBAAwB;IACvC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,WAAW,GAAG,QAAQ,CAAC;CAChC;AAED,MAAM,WAAW,qBAAqB;IACpC,wEAAwE;IACxE,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,0EAA0E;IAC1E,OAAO,EAAE,wBAAwB,EAAE,CAAC;CACrC;AAoCD,oGAAoG;AACpG,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,OAAO,KAAa,GAC5B,OAAO,CAAC,oBAAoB,EAAE,CAAC,CAUjC;AAED,iEAAiE;AACjE,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,SAAS,wBAAwB,EAAE,EAC5C,OAAO,GAAE,OAAO,KAAa,GAC5B,OAAO,CAAC,IAAI,CAAC,CAUf;AAED;;;GAGG;AACH,wBAAgB,e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