@mycompbox/compbox-cli 1.21.17 → 1.21.19

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 (83) hide show
  1. package/.tsbuildinfo +1 -1
  2. package/commands/run.d.ts +4 -1
  3. package/commands/run.d.ts.map +1 -1
  4. package/commands/run.js +103 -14
  5. package/commands/run.js.map +1 -1
  6. package/commands/workspace.d.ts +41 -2
  7. package/commands/workspace.d.ts.map +1 -1
  8. package/commands/workspace.js +147 -7
  9. package/commands/workspace.js.map +1 -1
  10. package/index.js +2902 -468
  11. package/package.json +1 -1
  12. package/utils/agent-invoker.d.ts +74 -13
  13. package/utils/agent-invoker.d.ts.map +1 -1
  14. package/utils/agent-invoker.js +341 -82
  15. package/utils/agent-invoker.js.map +1 -1
  16. package/utils/agent-permissions.d.ts +44 -0
  17. package/utils/agent-permissions.d.ts.map +1 -0
  18. package/utils/agent-permissions.js +229 -0
  19. package/utils/agent-permissions.js.map +1 -0
  20. package/utils/agent-store.d.ts +119 -0
  21. package/utils/agent-store.d.ts.map +1 -0
  22. package/utils/agent-store.js +421 -0
  23. package/utils/agent-store.js.map +1 -0
  24. package/utils/agent-trial.d.ts +34 -0
  25. package/utils/agent-trial.d.ts.map +1 -0
  26. package/utils/agent-trial.js +180 -0
  27. package/utils/agent-trial.js.map +1 -0
  28. package/utils/api-client.d.ts +11 -0
  29. package/utils/api-client.d.ts.map +1 -1
  30. package/utils/api-client.js +31 -0
  31. package/utils/api-client.js.map +1 -1
  32. package/utils/belt-engine.d.ts +72 -0
  33. package/utils/belt-engine.d.ts.map +1 -0
  34. package/utils/belt-engine.js +136 -0
  35. package/utils/belt-engine.js.map +1 -0
  36. package/utils/cloud-preflight.d.ts +26 -4
  37. package/utils/cloud-preflight.d.ts.map +1 -1
  38. package/utils/cloud-preflight.js +90 -7
  39. package/utils/cloud-preflight.js.map +1 -1
  40. package/utils/custom-agent-contract.d.ts +44 -0
  41. package/utils/custom-agent-contract.d.ts.map +1 -0
  42. package/utils/custom-agent-contract.js +122 -0
  43. package/utils/custom-agent-contract.js.map +1 -0
  44. package/utils/custom-agent-permissions.d.ts +48 -0
  45. package/utils/custom-agent-permissions.d.ts.map +1 -0
  46. package/utils/custom-agent-permissions.js +109 -0
  47. package/utils/custom-agent-permissions.js.map +1 -0
  48. package/utils/custom-agent-runner.d.ts +99 -0
  49. package/utils/custom-agent-runner.d.ts.map +1 -0
  50. package/utils/custom-agent-runner.js +227 -0
  51. package/utils/custom-agent-runner.js.map +1 -0
  52. package/utils/custom-agent-sync.d.ts +59 -0
  53. package/utils/custom-agent-sync.d.ts.map +1 -0
  54. package/utils/custom-agent-sync.js +197 -0
  55. package/utils/custom-agent-sync.js.map +1 -0
  56. package/utils/key-run.d.ts +9 -0
  57. package/utils/key-run.d.ts.map +1 -1
  58. package/utils/key-run.js +18 -0
  59. package/utils/key-run.js.map +1 -1
  60. package/utils/mailbox-client.d.ts +115 -2
  61. package/utils/mailbox-client.d.ts.map +1 -1
  62. package/utils/mailbox-client.js +114 -6
  63. package/utils/mailbox-client.js.map +1 -1
  64. package/utils/merge-guard.d.ts +48 -7
  65. package/utils/merge-guard.d.ts.map +1 -1
  66. package/utils/merge-guard.js +152 -17
  67. package/utils/merge-guard.js.map +1 -1
  68. package/utils/pxpipe-savings.d.ts +12 -0
  69. package/utils/pxpipe-savings.d.ts.map +1 -0
  70. package/utils/pxpipe-savings.js +68 -0
  71. package/utils/pxpipe-savings.js.map +1 -0
  72. package/utils/run-timings.d.ts +3 -0
  73. package/utils/run-timings.d.ts.map +1 -1
  74. package/utils/run-timings.js +2 -0
  75. package/utils/run-timings.js.map +1 -1
  76. package/utils/run-workspace.d.ts +18 -0
  77. package/utils/run-workspace.d.ts.map +1 -1
  78. package/utils/run-workspace.js +46 -5
  79. package/utils/run-workspace.js.map +1 -1
  80. package/utils/wrap-up.d.ts +8 -0
  81. package/utils/wrap-up.d.ts.map +1 -1
  82. package/utils/wrap-up.js +24 -2
  83. package/utils/wrap-up.js.map +1 -1
@@ -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 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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,2BAA2B,EAC3B,qBAAqB,EACrB,oBAAoB,EACpB,sBAAsB,EACtB,iBAAiB,EACjB,kBAAkB,EAClB,yBAAyB,GAE1B,M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AO,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":"cust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BAAoB,GAAG,MAAM,CAmBnE;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,SAAS,oBAAoB,EAAE,EACvC,GAAG,GAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAsB,GAC/C,qBAAqB,CAiCvB;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CAAC,IAAI,EAAE;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,SAAS,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,CAAC;IACnC,OAAO,CAAC,EAAE,OAAO,KAAK,CAAC;IACvB,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACjC,GAAG,OAAO,CAAC,qBAAqB,CAAC,CA4BjC"}
@@ -0,0 +1,197 @@
1
+ /**
2
+ * ENG-571: custom agents an admin installed on this machine.
3
+ *
4
+ * Before a run, the runner asks CompBox which custom agents are installed on
5
+ * this machine (`GET /api/v1/machines/custom-agents`, the pinned version of
6
+ * each), writes each one into the run's agents directory as
7
+ * `<agent-dir>/<slug>.md` — its instructions and skills with the result
8
+ * contract appended (`buildAgentText`), and its tool allowlist in the
9
+ * front matter — then reports back which installs landed and which failed
10
+ * (`POST /api/v1/machines/custom-agents/status`).
11
+ *
12
+ * Syncing never fails a run: if CompBox can't be reached the run goes on with
13
+ * the agents it already has, and a status report that can't be sent is
14
+ * dropped (the next run reports again).
15
+ */
16
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
17
+ import { join } from 'node:path';
18
+ import { buildAgentText } from './custom-agent-contract.js';
19
+ import { toAllowedTools } from './custom-agent-permissions.js';
20
+ import { sha256Hex } from './agent-store.js';
21
+ const REQUEST_TIMEOUT_MS = 15_000;
22
+ /** The server caps one status report at 500 entries. */
23
+ const MAX_REPORTS = 500;
24
+ function isRecord(value) {
25
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
26
+ }
27
+ /** Drops entries that aren't usable rather than failing the whole list. */
28
+ function toInstalledAgent(value) {
29
+ if (!isRecord(value))
30
+ return null;
31
+ const { installId, agentId, name, summary, version, instructions, skills, permissions, canBlockBelt } = value;
32
+ if (typeof installId !== 'string' || !installId)
33
+ return null;
34
+ if (typeof agentId !== 'string' || typeof name !== 'string' || !name.trim())
35
+ return null;
36
+ if (typeof version !== 'number' || !Number.isInteger(version) || version < 1)
37
+ return null;
38
+ if (typeof instructions !== 'string')
39
+ return null;
40
+ const resolvedSkills = Array.isArray(skills)
41
+ ? skills.filter((s) => isRecord(s) && typeof s.name === 'string' && typeof s.content === 'string')
42
+ : [];
43
+ return {
44
+ installId,
45
+ agentId,
46
+ name,
47
+ summary: typeof summary === 'string' ? summary : null,
48
+ version,
49
+ instructions,
50
+ skills: resolvedSkills,
51
+ permissions,
52
+ canBlockBelt: canBlockBelt === true,
53
+ };
54
+ }
55
+ /** The custom agents installed on the machine `token` belongs to. Throws when CompBox can't say. */
56
+ export async function fetchInstalledCustomAgents(apiUrl, token, fetchFn = fetch) {
57
+ const res = await fetchFn(`${apiUrl}/api/v1/machines/custom-agents`, {
58
+ method: 'GET',
59
+ headers: { Authorization: `Bearer ${token}` },
60
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
61
+ });
62
+ if (!res.ok)
63
+ throw new Error(`CompBox returned ${String(res.status)} for the installed custom agents`);
64
+ const body = (await res.json());
65
+ if (!Array.isArray(body.data))
66
+ throw new Error("CompBox's list of installed custom agents couldn't be read");
67
+ return body.data.map(toInstalledAgent).filter((a) => a !== null);
68
+ }
69
+ /** Tells CompBox which installs landed. Throws when it can't. */
70
+ export async function reportCustomAgentInstalls(apiUrl, token, reports, fetchFn = fetch) {
71
+ for (let i = 0; i < reports.length; i += MAX_REPORTS) {
72
+ const res = await fetchFn(`${apiUrl}/api/v1/machines/custom-agents/status`, {
73
+ method: 'POST',
74
+ headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },
75
+ body: JSON.stringify({ reports: reports.slice(i, i + MAX_REPORTS) }),
76
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
77
+ });
78
+ if (!res.ok)
79
+ throw new Error(`CompBox returned ${String(res.status)} for the install status`);
80
+ }
81
+ }
82
+ /**
83
+ * The file name (and `@name`) an agent gets: lowercase letters, digits and
84
+ * single dashes. Empty when the name has none of those.
85
+ */
86
+ export function customAgentSlug(name) {
87
+ return name
88
+ .toLowerCase()
89
+ .replace(/[^a-z0-9]+/g, '-')
90
+ .replace(/^-+|-+$/g, '')
91
+ .slice(0, 64)
92
+ .replace(/-+$/, '');
93
+ }
94
+ /** A YAML double-quoted scalar on one line. */
95
+ function yamlString(value) {
96
+ return JSON.stringify(value.replace(/\s+/g, ' ').trim());
97
+ }
98
+ /** The agent file: front matter (name, description, tool allowlist) then its text with the result contract. */
99
+ export function customAgentFile(agent) {
100
+ const limits = toAllowedTools(agent.permissions);
101
+ const lines = [
102
+ '---',
103
+ `name: ${yamlString(agent.name)}`,
104
+ `description: ${yamlString(agent.summary ?? `Custom agent ${agent.name}`)}`,
105
+ 'runtime: claude-code',
106
+ `version: ${String(agent.version)}`,
107
+ `tools: ${yamlString(limits.allowedTools.join(', '))}`,
108
+ `disallowedTools: ${yamlString(limits.disallowedTools.join(', '))}`,
109
+ '---',
110
+ '',
111
+ `You may only use these tools: ${limits.allowedTools.join(', ') || '(none)'}.`,
112
+ `You must never use: ${limits.disallowedTools.join(', ')}.`,
113
+ '',
114
+ buildAgentText(agent.instructions, agent.skills),
115
+ '',
116
+ ];
117
+ return lines.join('\n');
118
+ }
119
+ /**
120
+ * Writes each agent to `agentsDir/<slug>.md`. An agent whose name would
121
+ * overwrite a file already there (a CompBox agent, or another custom agent
122
+ * with the same slug) is not written and is reported as failed.
123
+ */
124
+ export function writeInstalledCustomAgents(agentsDir, agents, log = () => undefined) {
125
+ const written = [];
126
+ const reports = [];
127
+ for (const agent of agents) {
128
+ const report = (status) => {
129
+ reports.push({ installId: agent.installId, version: agent.version, status });
130
+ };
131
+ const slug = customAgentSlug(agent.name);
132
+ if (!slug) {
133
+ log(`Custom agent "${agent.name}" has no usable file name; skipped.`);
134
+ report('failed');
135
+ continue;
136
+ }
137
+ const target = join(agentsDir, `${slug}.md`);
138
+ if (written.includes(slug) || existsSync(target)) {
139
+ log(`Custom agent "${agent.name}" would replace the agent @${slug}; skipped.`);
140
+ report('failed');
141
+ continue;
142
+ }
143
+ try {
144
+ const content = customAgentFile(agent);
145
+ mkdirSync(agentsDir, { recursive: true });
146
+ writeFileSync(target, content);
147
+ if (sha256Hex(readFileSync(target)) !== sha256Hex(content))
148
+ throw new Error('the file on disk does not match');
149
+ written.push(slug);
150
+ report('installed');
151
+ log(`Custom agent @${slug} (version ${String(agent.version)}) installed.`);
152
+ }
153
+ catch (error) {
154
+ log(`Couldn't install custom agent "${agent.name}": ${error instanceof Error ? error.message : String(error)}`);
155
+ report('failed');
156
+ }
157
+ }
158
+ return { written, reports };
159
+ }
160
+ /**
161
+ * Fetches, writes and reports this machine's custom agents. Never throws: on
162
+ * any failure the run keeps whatever agents it already has.
163
+ */
164
+ export async function syncCustomAgents(opts) {
165
+ const log = opts.log ?? (() => undefined);
166
+ const fetchFn = opts.fetchFn ?? fetch;
167
+ let agents;
168
+ try {
169
+ agents = await fetchInstalledCustomAgents(opts.apiUrl, opts.token, fetchFn);
170
+ }
171
+ catch (error) {
172
+ log(`Couldn't load the installed custom agents, so the run uses the built-in agents: ${error instanceof Error ? error.message : String(error)}`);
173
+ return { written: [], reports: [] };
174
+ }
175
+ if (agents.length === 0)
176
+ return { written: [], reports: [] };
177
+ let result;
178
+ try {
179
+ const dir = typeof opts.agentsDir === 'string' ? opts.agentsDir : opts.agentsDir();
180
+ result = writeInstalledCustomAgents(dir, agents, log);
181
+ }
182
+ catch (error) {
183
+ log(`Couldn't prepare the agents directory for custom agents: ${error instanceof Error ? error.message : String(error)}`);
184
+ result = {
185
+ written: [],
186
+ reports: agents.map((a) => ({ installId: a.installId, version: a.version, status: 'failed' })),
187
+ };
188
+ }
189
+ try {
190
+ await reportCustomAgentInstalls(opts.apiUrl, opts.token, result.reports, fetchFn);
191
+ }
192
+ catch (error) {
193
+ log(`Couldn't report the custom agent install status: ${error instanceof Error ? error.message : String(error)}`);
194
+ }
195
+ return result;
196
+ }
197
+ //# sourceMappingURL=custom-agent-sync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"custom-agent-sync.js","sourceRoot":"","sources":["../../src/utils/custom-agent-sync.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,cAAc,EAAsB,MAAM,4BAA4B,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AA6B7C,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAClC,wDAAwD;AACxD,MAAM,WAAW,GAAG,GAAG,CAAC;AAExB,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,2EAA2E;AAC3E,SAAS,gBAAgB,CAAC,KAAc;IACtC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAClC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,GAAG,KAAK,CAAC;IAC9G,IAAI,OAAO,SAAS,KAAK,QAAQ,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
@@ -17,6 +17,15 @@ export interface KeyRun {
17
17
  * Claude credential removed so the key is what gets billed.
18
18
  */
19
19
  export declare function keyRunEnv(env: NodeJS.ProcessEnv, keyRun: KeyRun): NodeJS.ProcessEnv;
20
+ /**
21
+ * A computer set up in API-key mode (`compbox configure` → "SDK / API key")
22
+ * keeps its key on this machine. Every Claude Code run the runner starts —
23
+ * plan, refine, orchestrate, follow-up — must use that key, not only the
24
+ * idea conversation. Returns the env to run the daemon with: the stored key
25
+ * set as ANTHROPIC_API_KEY unless the environment already provides one.
26
+ * Other modes, or no stored key, leave the env unchanged.
27
+ */
28
+ export declare function machineKeyEnv(env: NodeJS.ProcessEnv, aiMode: string | undefined, storedKey: string | null | undefined): NodeJS.ProcessEnv;
20
29
  /** Adds JSON output so usage can be read from the result. */
21
30
  export declare function keyRunArgs(args: string[]): string[];
22
31
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"key-run.d.ts","sourceRoot":"","sources":["../../src/utils/key-run.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD,MAAM,WAAW,MAAM;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,UAAU,CAKnF;AAED,6DAA6D;AAC7D,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAEnD;AAMD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,GACpB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,WAAW,CAAA;CAAE,GAAG,IAAI,CAwC7C"}
1
+ {"version":3,"file":"key-run.d.ts","sourceRoot":"","sources":["../../src/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