@zeroroot-ai/zerocool-claude 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/.mcp.json +1 -1
- package/dist/index.d.ts +1 -7
- package/dist/index.js +6 -8
- package/dist/state.d.ts +13 -10
- package/dist/state.js +4 -13
- package/package.json +4 -8
- package/dist/ambient.d.ts +0 -7
- package/dist/ambient.js +0 -18
- package/dist/build.d.ts +0 -32
- package/dist/build.js +0 -218
- package/dist/claude-run.d.ts +0 -46
- package/dist/claude-run.js +0 -118
- package/dist/cli.d.ts +0 -88
- package/dist/cli.js +0 -186
- package/dist/config.d.ts +0 -44
- package/dist/config.js +0 -53
- package/dist/mode.d.ts +0 -32
- package/dist/mode.js +0 -21
- package/dist/sandbox-run.d.ts +0 -26
- package/dist/sandbox-run.js +0 -42
- package/dist/sandbox.d.ts +0 -2
- package/dist/sandbox.js +0 -30
- package/dist/server.d.ts +0 -2
- package/dist/server.js +0 -34
- package/dist/session.d.ts +0 -34
- package/dist/session.js +0 -142
- package/dist/tls.d.ts +0 -1
- package/dist/tls.js +0 -19
- package/dist/tools/componentize.d.ts +0 -18
- package/dist/tools/componentize.js +0 -80
- package/dist/tools/delegate.d.ts +0 -4
- package/dist/tools/delegate.js +0 -108
- package/dist/tools/findings.d.ts +0 -24
- package/dist/tools/findings.js +0 -104
- package/dist/tools/gibson-tools.d.ts +0 -20
- package/dist/tools/gibson-tools.js +0 -89
- package/dist/tools/memory.d.ts +0 -14
- package/dist/tools/memory.js +0 -96
- package/dist/tools/result.d.ts +0 -5
- package/dist/tools/result.js +0 -8
- package/dist/tools/status.d.ts +0 -5
- package/dist/tools/status.js +0 -21
package/dist/cli.d.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { type ChildProcess } from "node:child_process";
|
|
2
|
-
/**
|
|
3
|
-
* The `gibson` CLI as the session's user. It holds the login session
|
|
4
|
-
* (`gibson login`, a browser device flow), so it is the one process on the
|
|
5
|
-
* host that can mint an enrollment token or create a target. The plugin
|
|
6
|
-
* drives it instead of asking a person to copy tokens between terminals.
|
|
7
|
-
*/
|
|
8
|
-
export type Spawn = (cmd: string, args: string[], opts: {
|
|
9
|
-
detached?: boolean;
|
|
10
|
-
env?: NodeJS.ProcessEnv;
|
|
11
|
-
}) => ChildProcess;
|
|
12
|
-
export interface CliOptions {
|
|
13
|
-
bin?: string;
|
|
14
|
-
env?: NodeJS.ProcessEnv;
|
|
15
|
-
spawn?: Spawn;
|
|
16
|
-
timeoutMs?: number;
|
|
17
|
-
}
|
|
18
|
-
export interface CliResult {
|
|
19
|
-
code: number;
|
|
20
|
-
stdout: string;
|
|
21
|
-
stderr: string;
|
|
22
|
-
}
|
|
23
|
-
export declare function runGibson(args: string[], opts?: CliOptions): Promise<CliResult>;
|
|
24
|
-
/** True when the CLI's failure reads as "no login session". */
|
|
25
|
-
export declare function needsLogin(r: CliResult): boolean;
|
|
26
|
-
/**
|
|
27
|
-
* `gibson agent enroll`: mint a one-time bootstrap token for a new machine
|
|
28
|
-
* identity, authenticated as the person who ran `gibson login`.
|
|
29
|
-
*/
|
|
30
|
-
/**
|
|
31
|
-
* The session capabilities an interactive coding agent needs in its
|
|
32
|
-
* credential's ceiling (ADR-0045): it starts its own live mission
|
|
33
|
-
* (gibson#1593 decision 9) and may hand sub-tasks to other agents.
|
|
34
|
-
*/
|
|
35
|
-
export declare const INTERACTIVE_AGENT_CAPABILITIES: readonly ["mission:originate", "mission:delegate"];
|
|
36
|
-
export declare function enrollIdentity(name: string, opts?: CliOptions & {
|
|
37
|
-
gibsonURL?: string;
|
|
38
|
-
tenant?: string;
|
|
39
|
-
capabilities?: readonly string[];
|
|
40
|
-
}): Promise<string>;
|
|
41
|
-
export interface Target {
|
|
42
|
-
id: string;
|
|
43
|
-
name: string;
|
|
44
|
-
type: string;
|
|
45
|
-
status: string;
|
|
46
|
-
}
|
|
47
|
-
/** `gibson target list`, a tabwriter table: UUID NAME TYPE STATUS. */
|
|
48
|
-
export declare function parseTargetList(stdout: string): Target[];
|
|
49
|
-
export declare function listTargets(opts?: CliOptions & {
|
|
50
|
-
gibsonURL?: string;
|
|
51
|
-
tenant?: string;
|
|
52
|
-
}): Promise<Target[]>;
|
|
53
|
-
/**
|
|
54
|
-
* `gibson target create`: prints the new target id. The daemon refuses a
|
|
55
|
-
* target with neither a URL nor connection parameters, so the URL is
|
|
56
|
-
* required here: for a coding workspace it names the repository.
|
|
57
|
-
*/
|
|
58
|
-
export declare function createTarget(name: string, url: string, opts?: CliOptions & {
|
|
59
|
-
gibsonURL?: string;
|
|
60
|
-
tenant?: string;
|
|
61
|
-
type?: string;
|
|
62
|
-
}): Promise<string>;
|
|
63
|
-
export interface LoginPrompt {
|
|
64
|
-
url: string;
|
|
65
|
-
code: string;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* `gibson login`: a browser device flow. The CLI prints a URL and a code, then
|
|
69
|
-
* waits for the approval. This starts it detached, returns the URL and code
|
|
70
|
-
* as soon as they appear, and leaves the CLI waiting so the session lands in
|
|
71
|
-
* `~/.gibson/auth/credentials` when the person approves.
|
|
72
|
-
*/
|
|
73
|
-
export declare function startLogin(opts?: CliOptions & {
|
|
74
|
-
gibsonURL?: string;
|
|
75
|
-
}): Promise<LoginPrompt>;
|
|
76
|
-
/**
|
|
77
|
-
* The person originates the session mission. A component may originate a
|
|
78
|
-
* mission only from inside one it was dispatched to (gibson ADR-0063), and an
|
|
79
|
-
* interactive session has no parent mission, so the definition goes through
|
|
80
|
-
* the CLI's login session: `gibson mission submit` validates it, registers it
|
|
81
|
-
* and runs it, then prints the mission id. The daemon dispatches the one AGENT
|
|
82
|
-
* node to this component, which must already be checked in.
|
|
83
|
-
*/
|
|
84
|
-
export declare function submitMission(definition: unknown, targetId: string, opts?: CliOptions & {
|
|
85
|
-
gibsonURL?: string;
|
|
86
|
-
tenant?: string;
|
|
87
|
-
dir?: string;
|
|
88
|
-
}): Promise<string>;
|
package/dist/cli.js
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import { spawn as nodeSpawn } from "node:child_process";
|
|
2
|
-
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
3
|
-
import { tmpdir } from "node:os";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
export async function runGibson(args, opts = {}) {
|
|
6
|
-
const spawn = opts.spawn ?? nodeSpawn;
|
|
7
|
-
const child = spawn(opts.bin ?? opts.env?.GIBSON_CLI ?? "gibson", args, { env: opts.env ?? process.env });
|
|
8
|
-
return await new Promise((resolve, reject) => {
|
|
9
|
-
const out = [];
|
|
10
|
-
const err = [];
|
|
11
|
-
const timer = setTimeout(() => {
|
|
12
|
-
child.kill();
|
|
13
|
-
reject(new Error(`gibson ${args[0] ?? ""} ${args[1] ?? ""} timed out after ${opts.timeoutMs ?? 60_000}ms`));
|
|
14
|
-
}, opts.timeoutMs ?? 60_000);
|
|
15
|
-
child.stdout?.on("data", (d) => out.push(d.toString()));
|
|
16
|
-
child.stderr?.on("data", (d) => err.push(d.toString()));
|
|
17
|
-
child.on("error", (e) => {
|
|
18
|
-
clearTimeout(timer);
|
|
19
|
-
reject(new Error(`cannot run the gibson CLI (${e.message}). Install it: see https://github.com/zeroroot-ai/adk`));
|
|
20
|
-
});
|
|
21
|
-
child.on("exit", (code) => {
|
|
22
|
-
clearTimeout(timer);
|
|
23
|
-
resolve({ code: code ?? -1, stdout: out.join(""), stderr: err.join("") });
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
/** True when the CLI's failure reads as "no login session". */
|
|
28
|
-
export function needsLogin(r) {
|
|
29
|
-
return /login|credentials|unauthenticated|token expired|not signed in/i.test(r.stderr + r.stdout);
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* `gibson agent enroll`: mint a one-time bootstrap token for a new machine
|
|
33
|
-
* identity, authenticated as the person who ran `gibson login`.
|
|
34
|
-
*/
|
|
35
|
-
/**
|
|
36
|
-
* The session capabilities an interactive coding agent needs in its
|
|
37
|
-
* credential's ceiling (ADR-0045): it starts its own live mission
|
|
38
|
-
* (gibson#1593 decision 9) and may hand sub-tasks to other agents.
|
|
39
|
-
*/
|
|
40
|
-
export const INTERACTIVE_AGENT_CAPABILITIES = ["mission:originate", "mission:delegate"];
|
|
41
|
-
export async function enrollIdentity(name, opts = {}) {
|
|
42
|
-
const args = ["agent", "enroll", "--name", name, "--kind", "agent"];
|
|
43
|
-
for (const c of opts.capabilities ?? INTERACTIVE_AGENT_CAPABILITIES)
|
|
44
|
-
args.push("--capability", c);
|
|
45
|
-
if (opts.gibsonURL)
|
|
46
|
-
args.push("--gibson-url", opts.gibsonURL);
|
|
47
|
-
if (opts.tenant)
|
|
48
|
-
args.push("--tenant", opts.tenant);
|
|
49
|
-
const r = await runGibson(args, opts);
|
|
50
|
-
const m = /^bootstrap_token:\s*(\S+)/m.exec(r.stdout);
|
|
51
|
-
if (r.code !== 0 || !m) {
|
|
52
|
-
const why = (r.stderr || r.stdout).trim();
|
|
53
|
-
throw new Error(needsLogin(r)
|
|
54
|
-
? `the gibson CLI has no login session (${why}). Call gibson_login first.`
|
|
55
|
-
: `gibson agent enroll failed (exit ${r.code}): ${why || "no bootstrap_token in the output"}`);
|
|
56
|
-
}
|
|
57
|
-
return m[1];
|
|
58
|
-
}
|
|
59
|
-
/** `gibson target list`, a tabwriter table: UUID NAME TYPE STATUS. */
|
|
60
|
-
export function parseTargetList(stdout) {
|
|
61
|
-
return stdout
|
|
62
|
-
.split("\n")
|
|
63
|
-
.map((l) => l.trim())
|
|
64
|
-
.filter((l) => l && !/^UUID\s+NAME/.test(l))
|
|
65
|
-
.map((l) => l.split(/\s{2,}|\t/))
|
|
66
|
-
.filter((cols) => cols.length >= 2)
|
|
67
|
-
.map(([id, name, type, status]) => ({ id: id, name: name ?? "", type: type ?? "", status: status ?? "" }));
|
|
68
|
-
}
|
|
69
|
-
export async function listTargets(opts = {}) {
|
|
70
|
-
const args = ["target", "list"];
|
|
71
|
-
if (opts.gibsonURL)
|
|
72
|
-
args.push("--gibson-url", opts.gibsonURL);
|
|
73
|
-
if (opts.tenant)
|
|
74
|
-
args.push("--tenant", opts.tenant);
|
|
75
|
-
const r = await runGibson(args, opts);
|
|
76
|
-
if (r.code !== 0) {
|
|
77
|
-
const why = (r.stderr || r.stdout).trim();
|
|
78
|
-
throw new Error(needsLogin(r) ? `the gibson CLI has no login session (${why}). Call gibson_login first.` : `gibson target list failed: ${why}`);
|
|
79
|
-
}
|
|
80
|
-
return parseTargetList(r.stdout);
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* `gibson target create`: prints the new target id. The daemon refuses a
|
|
84
|
-
* target with neither a URL nor connection parameters, so the URL is
|
|
85
|
-
* required here: for a coding workspace it names the repository.
|
|
86
|
-
*/
|
|
87
|
-
export async function createTarget(name, url, opts = {}) {
|
|
88
|
-
const args = ["target", "create", "--name", name, "--url", url, "--type", opts.type ?? "custom"];
|
|
89
|
-
if (opts.gibsonURL)
|
|
90
|
-
args.push("--gibson-url", opts.gibsonURL);
|
|
91
|
-
if (opts.tenant)
|
|
92
|
-
args.push("--tenant", opts.tenant);
|
|
93
|
-
const r = await runGibson(args, opts);
|
|
94
|
-
const id = r.stdout.trim().split("\n").pop()?.trim() ?? "";
|
|
95
|
-
if (r.code !== 0 || !id) {
|
|
96
|
-
const why = (r.stderr || r.stdout).trim();
|
|
97
|
-
throw new Error(needsLogin(r) ? `the gibson CLI has no login session (${why}). Call gibson_login first.` : `gibson target create failed: ${why}`);
|
|
98
|
-
}
|
|
99
|
-
return id;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* `gibson login`: a browser device flow. The CLI prints a URL and a code, then
|
|
103
|
-
* waits for the approval. This starts it detached, returns the URL and code
|
|
104
|
-
* as soon as they appear, and leaves the CLI waiting so the session lands in
|
|
105
|
-
* `~/.gibson/auth/credentials` when the person approves.
|
|
106
|
-
*/
|
|
107
|
-
export async function startLogin(opts = {}) {
|
|
108
|
-
const spawn = opts.spawn ?? nodeSpawn;
|
|
109
|
-
const args = ["login"];
|
|
110
|
-
if (opts.gibsonURL)
|
|
111
|
-
args.push("--gibson-url", opts.gibsonURL);
|
|
112
|
-
const child = spawn(opts.bin ?? opts.env?.GIBSON_CLI ?? "gibson", args, { detached: true, env: opts.env ?? process.env });
|
|
113
|
-
return await new Promise((resolve, reject) => {
|
|
114
|
-
let buf = "";
|
|
115
|
-
const timer = setTimeout(() => {
|
|
116
|
-
child.kill();
|
|
117
|
-
reject(new Error(`gibson login printed no device code within ${opts.timeoutMs ?? 30_000}ms: ${buf.trim()}`));
|
|
118
|
-
}, opts.timeoutMs ?? 30_000);
|
|
119
|
-
const check = () => {
|
|
120
|
-
const url = /open:\s*\n?\s*(https?:\/\/\S+)/.exec(buf);
|
|
121
|
-
const code = /confirm this code:\s*(\S+)/.exec(buf);
|
|
122
|
-
if (url && code) {
|
|
123
|
-
clearTimeout(timer);
|
|
124
|
-
child.unref();
|
|
125
|
-
resolve({ url: url[1], code: code[1] });
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
child.stdout?.on("data", (d) => {
|
|
129
|
-
buf += d.toString();
|
|
130
|
-
check();
|
|
131
|
-
});
|
|
132
|
-
child.stderr?.on("data", (d) => {
|
|
133
|
-
buf += d.toString();
|
|
134
|
-
check();
|
|
135
|
-
});
|
|
136
|
-
child.on("error", (e) => {
|
|
137
|
-
clearTimeout(timer);
|
|
138
|
-
reject(new Error(`cannot run the gibson CLI (${e.message}). Install it: see https://github.com/zeroroot-ai/adk`));
|
|
139
|
-
});
|
|
140
|
-
child.on("exit", (code) => {
|
|
141
|
-
clearTimeout(timer);
|
|
142
|
-
reject(new Error(`gibson login exited with ${code} before printing a device code: ${buf.trim()}`));
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
const UUID = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/g;
|
|
147
|
-
/**
|
|
148
|
-
* The person originates the session mission. A component may originate a
|
|
149
|
-
* mission only from inside one it was dispatched to (gibson ADR-0063), and an
|
|
150
|
-
* interactive session has no parent mission, so the definition goes through
|
|
151
|
-
* the CLI's login session: `gibson mission submit` validates it, registers it
|
|
152
|
-
* and runs it, then prints the mission id. The daemon dispatches the one AGENT
|
|
153
|
-
* node to this component, which must already be checked in.
|
|
154
|
-
*/
|
|
155
|
-
export async function submitMission(definition, targetId, opts = {}) {
|
|
156
|
-
const dir = await mkdtemp(join(opts.dir ?? tmpdir(), "zerocool-claude-mission-"));
|
|
157
|
-
const file = join(dir, "session.json");
|
|
158
|
-
try {
|
|
159
|
-
await writeFile(file, JSON.stringify(definition), { mode: 0o600 });
|
|
160
|
-
// --detach: the CLI returns once the daemon started the run and prints the
|
|
161
|
-
// mission id. Without it the CLI holds the RunMission stream until the
|
|
162
|
-
// mission ends, which never happens: this process must go on to claim the
|
|
163
|
-
// dispatch, and the CLI's own deadline fires first.
|
|
164
|
-
const args = ["mission", "submit", file, "--format", "json", "--target", targetId, "--detach"];
|
|
165
|
-
if (opts.gibsonURL)
|
|
166
|
-
args.push("--gibson-url", opts.gibsonURL);
|
|
167
|
-
if (opts.tenant)
|
|
168
|
-
args.push("--tenant", opts.tenant);
|
|
169
|
-
const r = await runGibson(args, { ...opts, timeoutMs: opts.timeoutMs ?? 120_000 });
|
|
170
|
-
if (r.code !== 0) {
|
|
171
|
-
if (needsLogin(r))
|
|
172
|
-
throw new Error("the gibson CLI has no session; run gibson_login first");
|
|
173
|
-
if (/unknown flag: --detach/.test(r.stderr))
|
|
174
|
-
throw new Error("the gibson CLI is too old for mission submit --detach; update the gibson CLI (adk >= 0.109)");
|
|
175
|
-
throw new Error(`gibson mission submit failed (exit ${r.code}): ${(r.stderr || r.stdout).trim().slice(0, 400)}`);
|
|
176
|
-
}
|
|
177
|
-
const ids = r.stdout.match(UUID) ?? [];
|
|
178
|
-
const missionId = ids[ids.length - 1];
|
|
179
|
-
if (!missionId)
|
|
180
|
-
throw new Error(`gibson mission submit printed no mission id: ${r.stdout.trim().slice(0, 400)}`);
|
|
181
|
-
return missionId;
|
|
182
|
-
}
|
|
183
|
-
finally {
|
|
184
|
-
await rm(dir, { recursive: true, force: true });
|
|
185
|
-
}
|
|
186
|
-
}
|
package/dist/config.d.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Where a session learns how to reach Gibson, in precedence order:
|
|
3
|
-
*
|
|
4
|
-
* 1. the environment (`GIBSON_*`), for people who script it,
|
|
5
|
-
* 2. the plugin config this plugin wrote after a `gibson_connect`,
|
|
6
|
-
* 3. the `gibson` CLI login session (`~/.gibson/auth/credentials`), which
|
|
7
|
-
* already knows the platform URL, the active tenant and the private CA.
|
|
8
|
-
*
|
|
9
|
-
* So a person who ran `gibson login` once needs nothing else: the plugin
|
|
10
|
-
* finds the platform through the same session the CLI uses.
|
|
11
|
-
*/
|
|
12
|
-
export interface PluginConfig {
|
|
13
|
-
platformURL?: string;
|
|
14
|
-
daemonURL?: string;
|
|
15
|
-
targetId?: string;
|
|
16
|
-
caCertPath?: string;
|
|
17
|
-
callbackInsecure?: boolean;
|
|
18
|
-
}
|
|
19
|
-
export interface CliCredentials {
|
|
20
|
-
gibsonURL?: string;
|
|
21
|
-
tenant?: string;
|
|
22
|
-
caCertPath?: string;
|
|
23
|
-
}
|
|
24
|
-
export interface Settings {
|
|
25
|
-
platformURL?: string;
|
|
26
|
-
daemonURL?: string;
|
|
27
|
-
targetId?: string;
|
|
28
|
-
caCertPath?: string;
|
|
29
|
-
callbackInsecure: boolean;
|
|
30
|
-
bootstrapToken?: string;
|
|
31
|
-
hostKeyPath: string;
|
|
32
|
-
agentName: string;
|
|
33
|
-
tenant?: string;
|
|
34
|
-
}
|
|
35
|
-
export declare const DEFAULT_AGENT_NAME = "zerocool-claude";
|
|
36
|
-
export declare function configPath(env: NodeJS.ProcessEnv): string;
|
|
37
|
-
export declare function readConfig(env: NodeJS.ProcessEnv): Promise<PluginConfig>;
|
|
38
|
-
/** Merge and persist. Only the keys given change. */
|
|
39
|
-
export declare function writeConfig(env: NodeJS.ProcessEnv, patch: PluginConfig): Promise<PluginConfig>;
|
|
40
|
-
export declare function cliCredentialsPath(env: NodeJS.ProcessEnv): string;
|
|
41
|
-
/** The `gibson` CLI login session, addressing fields only. Tokens are never read. */
|
|
42
|
-
export declare function cliCredentials(env: NodeJS.ProcessEnv): Promise<CliCredentials | undefined>;
|
|
43
|
-
export declare function resolveSettings(env: NodeJS.ProcessEnv, cfg: PluginConfig, creds: CliCredentials | undefined): Settings;
|
|
44
|
-
export declare function loadSettings(env: NodeJS.ProcessEnv): Promise<Settings>;
|
package/dist/config.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { readFile, writeFile, mkdir } from "node:fs/promises";
|
|
2
|
-
import { homedir } from "node:os";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { stateDir } from "./state.js";
|
|
5
|
-
export const DEFAULT_AGENT_NAME = "zerocool-claude";
|
|
6
|
-
export function configPath(env) {
|
|
7
|
-
return join(stateDir(env), "config.json");
|
|
8
|
-
}
|
|
9
|
-
export async function readConfig(env) {
|
|
10
|
-
try {
|
|
11
|
-
return JSON.parse(await readFile(configPath(env), "utf8"));
|
|
12
|
-
}
|
|
13
|
-
catch {
|
|
14
|
-
return {};
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
/** Merge and persist. Only the keys given change. */
|
|
18
|
-
export async function writeConfig(env, patch) {
|
|
19
|
-
const merged = { ...(await readConfig(env)), ...patch };
|
|
20
|
-
await mkdir(stateDir(env), { recursive: true, mode: 0o700 });
|
|
21
|
-
await writeFile(configPath(env), `${JSON.stringify(merged, null, 2)}\n`, { encoding: "utf8", mode: 0o600 });
|
|
22
|
-
return merged;
|
|
23
|
-
}
|
|
24
|
-
export function cliCredentialsPath(env) {
|
|
25
|
-
return env.GIBSON_CLI_CREDENTIALS ?? join(homedir(), ".gibson", "auth", "credentials");
|
|
26
|
-
}
|
|
27
|
-
/** The `gibson` CLI login session, addressing fields only. Tokens are never read. */
|
|
28
|
-
export async function cliCredentials(env) {
|
|
29
|
-
try {
|
|
30
|
-
const raw = JSON.parse(await readFile(cliCredentialsPath(env), "utf8"));
|
|
31
|
-
const str = (k) => (typeof raw[k] === "string" && raw[k] ? raw[k] : undefined);
|
|
32
|
-
return { gibsonURL: str("gibson_url"), tenant: str("active_tenant"), caCertPath: str("ca_cert_path") };
|
|
33
|
-
}
|
|
34
|
-
catch {
|
|
35
|
-
return undefined;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
export function resolveSettings(env, cfg, creds) {
|
|
39
|
-
return {
|
|
40
|
-
platformURL: env.GIBSON_PLATFORM_URL ?? cfg.platformURL ?? creds?.gibsonURL,
|
|
41
|
-
daemonURL: env.GIBSON_DAEMON_URL ?? cfg.daemonURL,
|
|
42
|
-
targetId: env.GIBSON_TARGET_ID ?? cfg.targetId,
|
|
43
|
-
caCertPath: env.GIBSON_CA_CERT ?? cfg.caCertPath ?? creds?.caCertPath,
|
|
44
|
-
callbackInsecure: env.GIBSON_CALLBACK_INSECURE === "1" || cfg.callbackInsecure === true,
|
|
45
|
-
bootstrapToken: env.GIBSON_BOOTSTRAP_TOKEN,
|
|
46
|
-
hostKeyPath: env.GIBSON_HOST_KEY_PATH ?? join(homedir(), ".zerocool", "host.key"),
|
|
47
|
-
agentName: env.ZEROCOOL_AGENT_NAME ?? DEFAULT_AGENT_NAME,
|
|
48
|
-
tenant: creds?.tenant,
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
export async function loadSettings(env) {
|
|
52
|
-
return resolveSettings(env, await readConfig(env), await cliCredentials(env));
|
|
53
|
-
}
|
package/dist/mode.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Which of three postures this process runs in. Pure: decided from what the
|
|
3
|
-
* environment says and whether the host key exists, so it is testable and the
|
|
4
|
-
* reasons are printed once at start instead of discovered per tool call.
|
|
5
|
-
*
|
|
6
|
-
* - `standalone`: no platform. Findings go to a local log, componentize works.
|
|
7
|
-
* - `component`: checked in, no live mission. Reads and findings run under the
|
|
8
|
-
* component grant. No memory writes: a memory is a World observation and
|
|
9
|
-
* the World is written under a mission (gibson ADR-0012).
|
|
10
|
-
* - `live`: checked in, and this session is a mission (gibson#1593, decision 9).
|
|
11
|
-
* - `task`: a sandboxed dispatch (gibson ADR-0016). The launch injected the
|
|
12
|
-
* per-dispatch grant and the task; there is no check-in and no live
|
|
13
|
-
* mission to create, the mission already exists and this run is one of
|
|
14
|
-
* its nodes. Reads and writes use that grant.
|
|
15
|
-
*
|
|
16
|
-
* The postures are one path with fewer tools at each step down, the same
|
|
17
|
-
* fail-open shape as the opencode plugin: a coding agent that cannot reach its
|
|
18
|
-
* platform is still a working coding agent.
|
|
19
|
-
*/
|
|
20
|
-
export type Mode = "standalone" | "component" | "live" | "task";
|
|
21
|
-
export interface ModeDecision {
|
|
22
|
-
mode: Mode;
|
|
23
|
-
/** One line a person can act on. Empty when nothing is missing. */
|
|
24
|
-
reason: string;
|
|
25
|
-
}
|
|
26
|
-
export interface ModeInputs {
|
|
27
|
-
platformURL?: string;
|
|
28
|
-
bootstrapToken?: string;
|
|
29
|
-
hostKeyExists: boolean;
|
|
30
|
-
targetId?: string;
|
|
31
|
-
}
|
|
32
|
-
export declare function decideMode(env: ModeInputs, hostKeyPath: string): ModeDecision;
|
package/dist/mode.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export function decideMode(env, hostKeyPath) {
|
|
2
|
-
if (!env.platformURL) {
|
|
3
|
-
return { mode: "standalone", reason: "GIBSON_PLATFORM_URL is not set." };
|
|
4
|
-
}
|
|
5
|
-
if (!env.hostKeyExists && !env.bootstrapToken) {
|
|
6
|
-
return {
|
|
7
|
-
mode: "standalone",
|
|
8
|
-
reason: "GIBSON_PLATFORM_URL is set but this host has not checked in. Run `gibson login` then " +
|
|
9
|
-
"`gibson agent enroll`, and start once with GIBSON_BOOTSTRAP_TOKEN=<one-time token>. " +
|
|
10
|
-
`After that the host key at ${hostKeyPath} is enough.`,
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
if (!env.targetId) {
|
|
14
|
-
return {
|
|
15
|
-
mode: "component",
|
|
16
|
-
reason: "GIBSON_TARGET_ID is not set, so this session cannot be a live mission and cannot " +
|
|
17
|
-
"write memories. Create a target once (`gibson target create`) and set GIBSON_TARGET_ID.",
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
return { mode: "live", reason: "" };
|
|
21
|
-
}
|
package/dist/sandbox-run.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { type SandboxDispatch } from "@zeroroot-ai/sdk";
|
|
2
|
-
import { runClaude, type ClaudeRunResult } from "./claude-run.js";
|
|
3
|
-
/**
|
|
4
|
-
* The sandboxed-dispatch bin (gibson ADR-0016, #1621). gibson launches this
|
|
5
|
-
* image once per mission run with the task, the per-dispatch grant and the
|
|
6
|
-
* callback endpoint in the environment, and the tenant's own Anthropic key
|
|
7
|
-
* as ANTHROPIC_API_KEY (the manifest's `credentials`). It runs Claude Code
|
|
8
|
-
* headless with the Gibson MCP server attached in its task posture, streams
|
|
9
|
-
* the NDJSON events to stdout for the live console, and exits 0 when the
|
|
10
|
-
* run completed. Findings and memories reach the World through the
|
|
11
|
-
* callbacks; there is no result blob.
|
|
12
|
-
*/
|
|
13
|
-
export interface SandboxRunOptions {
|
|
14
|
-
env: NodeJS.ProcessEnv;
|
|
15
|
-
cwd: string;
|
|
16
|
-
run?: typeof runClaude;
|
|
17
|
-
onEvent?: (line: string) => void;
|
|
18
|
-
}
|
|
19
|
-
/** Everything the child claude and its MCP server need from the launch. */
|
|
20
|
-
export declare function sandboxEnv(d: SandboxDispatch, env: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
21
|
-
/** A `.js` path runs under node; anything else is a bin on PATH. */
|
|
22
|
-
export declare function mcpServerSpec(bin: string): {
|
|
23
|
-
command: string;
|
|
24
|
-
args?: string[];
|
|
25
|
-
};
|
|
26
|
-
export declare function runSandbox(opts: SandboxRunOptions): Promise<ClaudeRunResult>;
|
package/dist/sandbox-run.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { readSandboxDispatch, SANDBOX_ENV } from "@zeroroot-ai/sdk";
|
|
2
|
-
import { runClaude } from "./claude-run.js";
|
|
3
|
-
/** Everything the child claude and its MCP server need from the launch. */
|
|
4
|
-
export function sandboxEnv(d, env) {
|
|
5
|
-
return {
|
|
6
|
-
...env,
|
|
7
|
-
[SANDBOX_ENV.grant]: d.grant,
|
|
8
|
-
[SANDBOX_ENV.callbackEndpoint]: d.callbackEndpoint,
|
|
9
|
-
[SANDBOX_ENV.missionId]: d.missionId,
|
|
10
|
-
[SANDBOX_ENV.missionRunId]: d.missionRunId,
|
|
11
|
-
[SANDBOX_ENV.agentRunId]: d.agentRunId,
|
|
12
|
-
...(d.traceId ? { [SANDBOX_ENV.traceId]: d.traceId } : {}),
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
/** A `.js` path runs under node; anything else is a bin on PATH. */
|
|
16
|
-
export function mcpServerSpec(bin) {
|
|
17
|
-
return bin.endsWith(".js") ? { command: "node", args: [bin] } : { command: bin };
|
|
18
|
-
}
|
|
19
|
-
export async function runSandbox(opts) {
|
|
20
|
-
const d = readSandboxDispatch(opts.env);
|
|
21
|
-
if (!opts.env.ANTHROPIC_API_KEY) {
|
|
22
|
-
throw new Error("ANTHROPIC_API_KEY is not set. Headless Claude Code runs on an API key only; the catalog manifest " +
|
|
23
|
-
"declares it under credentials and the launch injects the tenant's own (gibson#1621, decision 12).");
|
|
24
|
-
}
|
|
25
|
-
const env = sandboxEnv(d, opts.env);
|
|
26
|
-
const run = opts.run ?? runClaude;
|
|
27
|
-
return await run({
|
|
28
|
-
goal: d.goal,
|
|
29
|
-
cwd: opts.cwd,
|
|
30
|
-
...(opts.env.ZEROCOOL_CLAUDE_MODEL ? { model: opts.env.ZEROCOOL_CLAUDE_MODEL } : {}),
|
|
31
|
-
maxTurns: Number(opts.env.ZEROCOOL_CLAUDE_MAX_TURNS ?? 200),
|
|
32
|
-
...(opts.env.ZEROCOOL_CLAUDE_MAX_BUDGET_USD ? { maxBudgetUsd: Number(opts.env.ZEROCOOL_CLAUDE_MAX_BUDGET_USD) } : {}),
|
|
33
|
-
appendSystemPrompt: "You run inside a Gibson mission sandbox. Record every real security finding with submit_finding, " +
|
|
34
|
-
"keep facts worth carrying to later runs with remember, and read prior context with recall. " +
|
|
35
|
-
"Work until the goal is met or clearly unreachable, then state the outcome.",
|
|
36
|
-
mcpServers: { gibson: mcpServerSpec(opts.env.ZEROCOOL_CLAUDE_MCP_BIN ?? "zerocool-claude-mcp") },
|
|
37
|
-
allowedTools: ["mcp__gibson__*"],
|
|
38
|
-
timeoutMs: Number(opts.env.ZEROCOOL_CLAUDE_TIMEOUT_MS ?? 0),
|
|
39
|
-
env,
|
|
40
|
-
...(opts.onEvent ? { onEvent: opts.onEvent } : {}),
|
|
41
|
-
});
|
|
42
|
-
}
|
package/dist/sandbox.d.ts
DELETED
package/dist/sandbox.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { runSandbox } from "./sandbox-run.js";
|
|
3
|
-
/**
|
|
4
|
-
* The sandboxed-dispatch bin. Runs unconditionally: npm installs it as a
|
|
5
|
-
* symlink named zerocool-claude-dispatch. Library code lives in sandbox-run.ts.
|
|
6
|
-
*/
|
|
7
|
-
async function main() {
|
|
8
|
-
const log = (l) => process.stderr.write(`[zerocool-claude-dispatch] ${l}\n`);
|
|
9
|
-
let result;
|
|
10
|
-
try {
|
|
11
|
-
result = await runSandbox({
|
|
12
|
-
env: process.env,
|
|
13
|
-
cwd: process.env.ZEROCOOL_WORKSPACE ?? process.cwd(),
|
|
14
|
-
onEvent: (line) => process.stdout.write(`${line}\n`),
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
catch (e) {
|
|
18
|
-
log(`run failed: ${e.message}`);
|
|
19
|
-
process.exit(1);
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
if (result.mcpServerErrors.length > 0)
|
|
23
|
-
log(`MCP: ${result.mcpServerErrors.join("; ")}`);
|
|
24
|
-
log(`done turns=${result.numTurns} cost_usd=${result.costUsd.toFixed(4)} session=${result.sessionId || "-"} error=${result.isError}`);
|
|
25
|
-
process.exit(result.isError ? 1 : 0);
|
|
26
|
-
}
|
|
27
|
-
main().catch((e) => {
|
|
28
|
-
process.stderr.write(`[zerocool-claude-dispatch] fatal: ${e.message}\n`);
|
|
29
|
-
process.exit(1);
|
|
30
|
-
});
|
package/dist/server.d.ts
DELETED
package/dist/server.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
|
-
import { buildServer, log } from "./build.js";
|
|
4
|
-
import { clearLive, stateDir } from "./state.js";
|
|
5
|
-
import { describeGibson } from "./tools/status.js";
|
|
6
|
-
/**
|
|
7
|
-
* The MCP server bin. This file runs main() unconditionally: npm installs
|
|
8
|
-
* bins as symlinks named after the bin (`zerocool-claude-mcp`), so any
|
|
9
|
-
* "am I the entry point" check on argv[1] is false there and the process
|
|
10
|
-
* exits before it serves anything. Library code lives in build.ts.
|
|
11
|
-
*/
|
|
12
|
-
async function main() {
|
|
13
|
-
const cwd = process.cwd();
|
|
14
|
-
const surface = await buildServer(process.env, cwd);
|
|
15
|
-
const { server } = surface;
|
|
16
|
-
log(`[zerocool-claude] ${describeGibson(surface.current()).replaceAll("\n", "; ")}`);
|
|
17
|
-
let closing = false;
|
|
18
|
-
const close = async () => {
|
|
19
|
-
if (closing)
|
|
20
|
-
return;
|
|
21
|
-
closing = true;
|
|
22
|
-
await clearLive(stateDir(process.env), cwd).catch(() => { });
|
|
23
|
-
await surface.current().close().catch((e) => log(`[zerocool-claude] close: ${e.message}`));
|
|
24
|
-
};
|
|
25
|
-
// Claude Code ends the session by closing stdio. The mission ends with it.
|
|
26
|
-
process.stdin.on("close", () => void close().finally(() => process.exit(0)));
|
|
27
|
-
for (const sig of ["SIGINT", "SIGTERM"])
|
|
28
|
-
process.on(sig, () => void close().finally(() => process.exit(0)));
|
|
29
|
-
await server.connect(new StdioServerTransport());
|
|
30
|
-
}
|
|
31
|
-
main().catch((e) => {
|
|
32
|
-
log(`[zerocool-claude] fatal: ${e.message}`);
|
|
33
|
-
process.exit(1);
|
|
34
|
-
});
|
package/dist/session.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { connectGibson, startLiveMission, type GibsonSession, type KnowledgeSource, type LiveMission, type MissionOriginator } from "@zeroroot-ai/sdk";
|
|
2
|
-
import type { Settings } from "./config.js";
|
|
3
|
-
import { type Mode } from "./mode.js";
|
|
4
|
-
export { DEFAULT_AGENT_NAME } from "./config.js";
|
|
5
|
-
/** Everything the tools need, decided once per connect. */
|
|
6
|
-
export interface Gibson {
|
|
7
|
-
mode: Mode;
|
|
8
|
-
reason: string;
|
|
9
|
-
agentName: string;
|
|
10
|
-
hostKeyPath: string;
|
|
11
|
-
settings: Settings;
|
|
12
|
-
session?: GibsonSession;
|
|
13
|
-
live?: LiveMission;
|
|
14
|
-
knowledge?: KnowledgeSource;
|
|
15
|
-
/** Release the mission and the component registration. Idempotent. */
|
|
16
|
-
close(): Promise<void>;
|
|
17
|
-
}
|
|
18
|
-
export interface OpenGibsonOptions {
|
|
19
|
-
settings: Settings;
|
|
20
|
-
log: (line: string) => void;
|
|
21
|
-
/** The process environment, for the sandboxed-dispatch contract. */
|
|
22
|
-
env?: NodeJS.ProcessEnv;
|
|
23
|
-
/** Test seams. */
|
|
24
|
-
connect?: typeof connectGibson;
|
|
25
|
-
start?: typeof startLiveMission;
|
|
26
|
-
originate?: MissionOriginator;
|
|
27
|
-
hostKeyExists?: (path: string) => boolean;
|
|
28
|
-
trust?: (path: string) => Promise<void>;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Check in, then make the session a live mission. Fails open at every step:
|
|
32
|
-
* a platform failure lands one posture down, never in a refusal to start.
|
|
33
|
-
*/
|
|
34
|
-
export declare function openGibson(opts: OpenGibsonOptions): Promise<Gibson>;
|