@ai-codebot/daemon 0.1.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/LICENSE +21 -0
- package/README.md +61 -0
- package/dist/broker/handoff.d.ts +57 -0
- package/dist/broker/handoff.js +87 -0
- package/dist/broker/handoff.js.map +1 -0
- package/dist/broker/server.d.ts +34 -0
- package/dist/broker/server.js +204 -0
- package/dist/broker/server.js.map +1 -0
- package/dist/broker/token.d.ts +36 -0
- package/dist/broker/token.js +48 -0
- package/dist/broker/token.js.map +1 -0
- package/dist/cli.d.ts +15 -0
- package/dist/cli.js +120 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +33 -0
- package/dist/config.js +132 -0
- package/dist/config.js.map +1 -0
- package/dist/frames.d.ts +311 -0
- package/dist/frames.js +137 -0
- package/dist/frames.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/launch.d.ts +40 -0
- package/dist/launch.js +163 -0
- package/dist/launch.js.map +1 -0
- package/dist/logging.d.ts +27 -0
- package/dist/logging.js +91 -0
- package/dist/logging.js.map +1 -0
- package/dist/spawn/cli-runner.d.ts +91 -0
- package/dist/spawn/cli-runner.js +180 -0
- package/dist/spawn/cli-runner.js.map +1 -0
- package/dist/spawn/detect.d.ts +18 -0
- package/dist/spawn/detect.js +46 -0
- package/dist/spawn/detect.js.map +1 -0
- package/dist/spawn/disallowed-tools.d.ts +15 -0
- package/dist/spawn/disallowed-tools.js +30 -0
- package/dist/spawn/disallowed-tools.js.map +1 -0
- package/dist/spawn/git.d.ts +19 -0
- package/dist/spawn/git.js +56 -0
- package/dist/spawn/git.js.map +1 -0
- package/dist/spawn/llm-client.d.ts +52 -0
- package/dist/spawn/llm-client.js +61 -0
- package/dist/spawn/llm-client.js.map +1 -0
- package/dist/spawn/n2-runner.d.ts +33 -0
- package/dist/spawn/n2-runner.js +176 -0
- package/dist/spawn/n2-runner.js.map +1 -0
- package/dist/spawn/n2-tools.d.ts +44 -0
- package/dist/spawn/n2-tools.js +374 -0
- package/dist/spawn/n2-tools.js.map +1 -0
- package/dist/spawn/result-map.d.ts +40 -0
- package/dist/spawn/result-map.js +68 -0
- package/dist/spawn/result-map.js.map +1 -0
- package/dist/tunnel.d.ts +61 -0
- package/dist/tunnel.js +205 -0
- package/dist/tunnel.js.map +1 -0
- package/package.json +60 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `codebot-daemon connect …` command wiring (design §3/§4).
|
|
3
|
+
*
|
|
4
|
+
* Parses + validates flags, wires the tunnel to the launch manager, and translates
|
|
5
|
+
* the terminal tunnel exit into a process exit code:
|
|
6
|
+
* - 4401 unauth → exit 1 (dead key — don't hammer).
|
|
7
|
+
* - 4409 superseded / `--once` done → exit 0 (clean).
|
|
8
|
+
*
|
|
9
|
+
* NEVER logs the api key. SIGINT/SIGTERM tears down all live launches first.
|
|
10
|
+
*/
|
|
11
|
+
import { ConfigError, parseConnectArgs } from "./config.js";
|
|
12
|
+
import { LaunchManager } from "./launch.js";
|
|
13
|
+
import { log } from "./logging.js";
|
|
14
|
+
import { DISALLOWED_TOOLS } from "./spawn/disallowed-tools.js";
|
|
15
|
+
import { makeProgress } from "./frames.js";
|
|
16
|
+
import { runTunnel } from "./tunnel.js";
|
|
17
|
+
export const DAEMON_VERSION = "0.1.0";
|
|
18
|
+
// Advertised tools = the N2 toolset minus the blacklist (already excluded). This is
|
|
19
|
+
// the scope-attestation seed the server stores; the broker is the real boundary.
|
|
20
|
+
const ADVERTISED_TOOLS = [
|
|
21
|
+
"list_dir",
|
|
22
|
+
"read_file",
|
|
23
|
+
"write_file",
|
|
24
|
+
"replace_in_file",
|
|
25
|
+
"run_tests",
|
|
26
|
+
];
|
|
27
|
+
const USAGE = `codebot-daemon connect --server-url <wss://…/daemon/connect> --api-key <ck_machine_…>
|
|
28
|
+
[--repo <path>] [--model-url <url>] [--cli claude|codex|auto] [--once] [--insecure]
|
|
29
|
+
|
|
30
|
+
Dials the cloud relay, runs local coding-agent launches through a 127.0.0.1
|
|
31
|
+
capability broker, and reports results. The machine key may also be supplied via
|
|
32
|
+
CODEBOT_MACHINE_KEY. The real model key is never handed to the agent.
|
|
33
|
+
Disallowed tools (always stripped before spawn): ${DISALLOWED_TOOLS.join(", ")}.`;
|
|
34
|
+
/** Entry for the `connect` subcommand. Returns the process exit code. */
|
|
35
|
+
export async function runConnect(argv) {
|
|
36
|
+
let cfg;
|
|
37
|
+
try {
|
|
38
|
+
cfg = parseConnectArgs(argv);
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
if (err instanceof ConfigError) {
|
|
42
|
+
process.stderr.write(`error: ${err.message}\n\n${USAGE}\n`);
|
|
43
|
+
return 2;
|
|
44
|
+
}
|
|
45
|
+
throw err;
|
|
46
|
+
}
|
|
47
|
+
const manager = new LaunchManager({
|
|
48
|
+
cliMode: cfg.cli,
|
|
49
|
+
modelUrlFallback: cfg.modelUrl,
|
|
50
|
+
});
|
|
51
|
+
// Tear down all live launches on signal (no orphan children / 0600 files).
|
|
52
|
+
const onSignal = (sig) => {
|
|
53
|
+
log.warn("daemon.signal", { signal: sig });
|
|
54
|
+
void manager.shutdownAll().finally(() => process.exit(0));
|
|
55
|
+
};
|
|
56
|
+
process.once("SIGINT", () => onSignal("SIGINT"));
|
|
57
|
+
process.once("SIGTERM", () => onSignal("SIGTERM"));
|
|
58
|
+
log.info("daemon.connect.start", {
|
|
59
|
+
server_url: cfg.serverUrl,
|
|
60
|
+
repo: cfg.repo,
|
|
61
|
+
cli: cfg.cli,
|
|
62
|
+
once: cfg.once,
|
|
63
|
+
});
|
|
64
|
+
const exit = await runTunnel({
|
|
65
|
+
serverUrl: cfg.serverUrl,
|
|
66
|
+
apiKey: cfg.apiKey,
|
|
67
|
+
daemonVersion: DAEMON_VERSION,
|
|
68
|
+
advertisedTools: ADVERTISED_TOOLS,
|
|
69
|
+
once: cfg.once,
|
|
70
|
+
onLaunch: async (launch, send) => {
|
|
71
|
+
log.info("daemon.launch.received", {
|
|
72
|
+
launch_id: launch.launch_id,
|
|
73
|
+
agent_id: launch.agent_id,
|
|
74
|
+
});
|
|
75
|
+
let result;
|
|
76
|
+
try {
|
|
77
|
+
result = await manager.run(launch, (stage) => {
|
|
78
|
+
send(makeProgress(launch.launch_id, stage));
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
// Defensive: manager.run already maps failures, but never let a throw escape
|
|
83
|
+
// without a terminal Result (零静默).
|
|
84
|
+
result = {
|
|
85
|
+
type: "result",
|
|
86
|
+
launch_id: launch.launch_id,
|
|
87
|
+
status: "failed",
|
|
88
|
+
error: `daemon error: ${err.message}`,
|
|
89
|
+
cost_usd: null,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
const frame = result;
|
|
93
|
+
send(frame);
|
|
94
|
+
log.info("daemon.launch.result", {
|
|
95
|
+
launch_id: launch.launch_id,
|
|
96
|
+
status: result.status,
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
if (exit.kind === "unauth") {
|
|
101
|
+
log.error("daemon.exit.unauthorized", {});
|
|
102
|
+
return 1;
|
|
103
|
+
}
|
|
104
|
+
log.info("daemon.exit", { reason: exit.kind });
|
|
105
|
+
return 0;
|
|
106
|
+
}
|
|
107
|
+
/** Top-level CLI dispatch. */
|
|
108
|
+
export async function main(argv) {
|
|
109
|
+
const [sub, ...rest] = argv;
|
|
110
|
+
if (sub === "connect") {
|
|
111
|
+
return runConnect(rest);
|
|
112
|
+
}
|
|
113
|
+
if (sub === "--help" || sub === "-h" || sub === "help" || sub === undefined) {
|
|
114
|
+
process.stdout.write(`${USAGE}\n`);
|
|
115
|
+
return sub === undefined ? 2 : 0;
|
|
116
|
+
}
|
|
117
|
+
process.stderr.write(`error: unknown command '${sub}'\n\n${USAGE}\n`);
|
|
118
|
+
return 2;
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAsB,MAAM,aAAa,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAmC,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,CAAC,MAAM,cAAc,GAAG,OAAO,CAAC;AAEtC,oFAAoF;AACpF,iFAAiF;AACjF,MAAM,gBAAgB,GAAG;IACvB,UAAU;IACV,WAAW;IACX,YAAY;IACZ,iBAAiB;IACjB,WAAW;CACZ,CAAC;AAEF,MAAM,KAAK,GAAG;;;;;;mDAMqC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;AAElF,yEAAyE;AACzE,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,IAAuB;IACtD,IAAI,GAAkB,CAAC;IACvB,IAAI,CAAC;QACH,GAAG,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,GAAG,YAAY,WAAW,EAAE,CAAC;YAC/B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,GAAG,CAAC,OAAO,OAAO,KAAK,IAAI,CAAC,CAAC;YAC5D,OAAO,CAAC,CAAC;QACX,CAAC;QACD,MAAM,GAAG,CAAC;IACZ,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,aAAa,CAAC;QAChC,OAA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I,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,MAAM,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QAC5E,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,KAAK,IAAI,CAAC,CAAC;QACnC,OAAO,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACnC,CAAC;IACD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,2BAA2B,GAAG,QAAQ,KAAK,IAAI,CAAC,CAAC;IACtE,OAAO,CAAC,CAAC;AACX,CAAC"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI argument parsing + fail-fast validation for the `connect` subcommand
|
|
3
|
+
* (design §3). NEVER logs `apiKey`.
|
|
4
|
+
*
|
|
5
|
+
* codebot-daemon connect \
|
|
6
|
+
* --server-url <wss://…/daemon/connect> \
|
|
7
|
+
* --api-key <ck_machine_…> \
|
|
8
|
+
* [--repo <path>] [--model-url <url>] [--cli claude|codex|auto] \
|
|
9
|
+
* [--once] [--insecure]
|
|
10
|
+
*
|
|
11
|
+
* The api key may also come from `CODEBOT_MACHINE_KEY` (so it never has to appear
|
|
12
|
+
* in a shell history / process list).
|
|
13
|
+
*/
|
|
14
|
+
export declare const MACHINE_KEY_PREFIX = "ck_machine_";
|
|
15
|
+
export declare const MACHINE_KEY_ENV = "CODEBOT_MACHINE_KEY";
|
|
16
|
+
export type CliKind = "claude" | "codex" | "auto";
|
|
17
|
+
export interface ConnectConfig {
|
|
18
|
+
readonly serverUrl: string;
|
|
19
|
+
readonly apiKey: string;
|
|
20
|
+
readonly repo: string;
|
|
21
|
+
readonly modelUrl: string | null;
|
|
22
|
+
readonly cli: CliKind;
|
|
23
|
+
readonly once: boolean;
|
|
24
|
+
readonly insecure: boolean;
|
|
25
|
+
}
|
|
26
|
+
export declare class ConfigError extends Error {
|
|
27
|
+
constructor(message: string);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Parse + validate the `connect` flags. Fails fast (throws `ConfigError`) on any
|
|
31
|
+
* invalid input. The api key is read from `--api-key` or `CODEBOT_MACHINE_KEY`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function parseConnectArgs(argv: readonly string[], env?: NodeJS.ProcessEnv): ConnectConfig;
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI argument parsing + fail-fast validation for the `connect` subcommand
|
|
3
|
+
* (design §3). NEVER logs `apiKey`.
|
|
4
|
+
*
|
|
5
|
+
* codebot-daemon connect \
|
|
6
|
+
* --server-url <wss://…/daemon/connect> \
|
|
7
|
+
* --api-key <ck_machine_…> \
|
|
8
|
+
* [--repo <path>] [--model-url <url>] [--cli claude|codex|auto] \
|
|
9
|
+
* [--once] [--insecure]
|
|
10
|
+
*
|
|
11
|
+
* The api key may also come from `CODEBOT_MACHINE_KEY` (so it never has to appear
|
|
12
|
+
* in a shell history / process list).
|
|
13
|
+
*/
|
|
14
|
+
import { resolve } from "node:path";
|
|
15
|
+
export const MACHINE_KEY_PREFIX = "ck_machine_";
|
|
16
|
+
export const MACHINE_KEY_ENV = "CODEBOT_MACHINE_KEY";
|
|
17
|
+
export class ConfigError extends Error {
|
|
18
|
+
constructor(message) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.name = "ConfigError";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const CLI_KINDS = ["claude", "codex", "auto"];
|
|
24
|
+
/** Parse `--flag value` / `--bool` tokens. Unknown flags are a fail-fast error. */
|
|
25
|
+
function parseRawArgs(argv, booleanFlags) {
|
|
26
|
+
const out = {};
|
|
27
|
+
let i = 0;
|
|
28
|
+
while (i < argv.length) {
|
|
29
|
+
const tok = argv[i];
|
|
30
|
+
if (!tok.startsWith("--")) {
|
|
31
|
+
throw new ConfigError(`unexpected argument '${tok}' (flags must start with --)`);
|
|
32
|
+
}
|
|
33
|
+
const flag = tok.slice(2);
|
|
34
|
+
if (booleanFlags.has(flag)) {
|
|
35
|
+
out[flag] = true;
|
|
36
|
+
i += 1;
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const value = argv[i + 1];
|
|
40
|
+
if (value === undefined || value.startsWith("--")) {
|
|
41
|
+
throw new ConfigError(`flag '--${flag}' requires a value`);
|
|
42
|
+
}
|
|
43
|
+
out[flag] = value;
|
|
44
|
+
i += 2;
|
|
45
|
+
}
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
48
|
+
const KNOWN_FLAGS = new Set([
|
|
49
|
+
"server-url",
|
|
50
|
+
"api-key",
|
|
51
|
+
"repo",
|
|
52
|
+
"model-url",
|
|
53
|
+
"cli",
|
|
54
|
+
"once",
|
|
55
|
+
"insecure",
|
|
56
|
+
]);
|
|
57
|
+
const BOOLEAN_FLAGS = new Set(["once", "insecure"]);
|
|
58
|
+
/**
|
|
59
|
+
* Parse + validate the `connect` flags. Fails fast (throws `ConfigError`) on any
|
|
60
|
+
* invalid input. The api key is read from `--api-key` or `CODEBOT_MACHINE_KEY`.
|
|
61
|
+
*/
|
|
62
|
+
export function parseConnectArgs(argv, env = process.env) {
|
|
63
|
+
const raw = parseRawArgs(argv, BOOLEAN_FLAGS);
|
|
64
|
+
for (const flag of Object.keys(raw)) {
|
|
65
|
+
if (!KNOWN_FLAGS.has(flag)) {
|
|
66
|
+
throw new ConfigError(`unknown flag '--${flag}'`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const serverUrl = typeof raw["server-url"] === "string" ? raw["server-url"] : "";
|
|
70
|
+
if (!serverUrl) {
|
|
71
|
+
throw new ConfigError("--server-url is required");
|
|
72
|
+
}
|
|
73
|
+
const insecure = raw["insecure"] === true;
|
|
74
|
+
if (!isValidServerUrl(serverUrl, insecure)) {
|
|
75
|
+
throw new ConfigError(insecure
|
|
76
|
+
? "--server-url must be a ws:// or wss:// URL"
|
|
77
|
+
: "--server-url must be a wss:// URL (use --insecure for a localhost ws:// dev relay)");
|
|
78
|
+
}
|
|
79
|
+
const apiKey = (typeof raw["api-key"] === "string" ? raw["api-key"] : "") ||
|
|
80
|
+
env[MACHINE_KEY_ENV] ||
|
|
81
|
+
"";
|
|
82
|
+
if (!apiKey) {
|
|
83
|
+
throw new ConfigError(`--api-key is required (or set ${MACHINE_KEY_ENV})`);
|
|
84
|
+
}
|
|
85
|
+
if (!apiKey.startsWith(MACHINE_KEY_PREFIX)) {
|
|
86
|
+
// Note: we validate the PREFIX, never the value, and never echo the key.
|
|
87
|
+
throw new ConfigError(`--api-key must start with '${MACHINE_KEY_PREFIX}'`);
|
|
88
|
+
}
|
|
89
|
+
const repoRaw = typeof raw["repo"] === "string" ? raw["repo"] : process.cwd();
|
|
90
|
+
const repo = resolve(repoRaw);
|
|
91
|
+
const modelUrl = typeof raw["model-url"] === "string" ? raw["model-url"] : null;
|
|
92
|
+
if (modelUrl !== null && !isValidHttpUrl(modelUrl)) {
|
|
93
|
+
throw new ConfigError("--model-url must be an http(s):// URL");
|
|
94
|
+
}
|
|
95
|
+
const cliRaw = typeof raw["cli"] === "string" ? raw["cli"] : "auto";
|
|
96
|
+
if (!CLI_KINDS.includes(cliRaw)) {
|
|
97
|
+
throw new ConfigError(`--cli must be one of ${CLI_KINDS.join("|")}`);
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
serverUrl,
|
|
101
|
+
apiKey,
|
|
102
|
+
repo,
|
|
103
|
+
modelUrl,
|
|
104
|
+
cli: cliRaw,
|
|
105
|
+
once: raw["once"] === true,
|
|
106
|
+
insecure,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function isValidServerUrl(value, insecure) {
|
|
110
|
+
let url;
|
|
111
|
+
try {
|
|
112
|
+
url = new URL(value);
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
if (url.protocol === "wss:")
|
|
118
|
+
return true;
|
|
119
|
+
if (insecure && url.protocol === "ws:")
|
|
120
|
+
return true;
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
function isValidHttpUrl(value) {
|
|
124
|
+
try {
|
|
125
|
+
const url = new URL(value);
|
|
126
|
+
return url.protocol === "http:" || url.protocol === "https:";
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa,CAAC;AAChD,MAAM,CAAC,MAAM,eAAe,GAAG,qBAAqB,CAAC;AAcrD,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF;AAED,MAAM,SAAS,GAAuB,CAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;AAMlE,mFAAmF;AACnF,SAAS,YAAY,CACnB,IAAuB,EACvB,YAAiC;IAEjC,MAAM,GAAG,GAAY,EAAE,CAAC;IACxB,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QACvB,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YAC1B,MAAM,IAAI,WAAW,CACnB,wBAAwB,GAAG,8BAA8B,CAC1D,CAAC;QACJ,CAAC;QACD,MAAM,IAAI,GAAG,GAAG,C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ACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
package/dist/frames.d.ts
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire frame protocol for `/daemon/connect` — TS mirror of the server's
|
|
3
|
+
* `daemon_frames.py` (PR2). Field-for-field, snake_case keys.
|
|
4
|
+
*
|
|
5
|
+
* Directionality (matches the Python contract):
|
|
6
|
+
* - Server -> daemon (INBOUND, zod-validated at the boundary):
|
|
7
|
+
* HelloAck, Launch, Ping, ServerError
|
|
8
|
+
* - Daemon -> server (OUTBOUND, constructed by us, trusted):
|
|
9
|
+
* Hello, Progress, Result, Pong
|
|
10
|
+
*
|
|
11
|
+
* The server validates the daemon->server direction; we validate the
|
|
12
|
+
* server->daemon direction. `parseInbound` is the boundary validator: an unknown
|
|
13
|
+
* `type` or a malformed field throws a `ZodError` the receive loop catches and
|
|
14
|
+
* ignores (never crashes the loop) — mirroring `parse_inbound`.
|
|
15
|
+
*
|
|
16
|
+
* Secrets: `ModelOverride.api_key` is a custom-provider credential — NEVER logged.
|
|
17
|
+
*/
|
|
18
|
+
import { z } from "zod";
|
|
19
|
+
/**
|
|
20
|
+
* Largest frame we accept (design §8.7 / `daemon_frames.MAX_FRAME_BYTES`): 256 KiB.
|
|
21
|
+
* Used as the `ws` `maxPayload`. Must equal the server's ceiling field-for-field.
|
|
22
|
+
*/
|
|
23
|
+
export declare const MAX_FRAME_BYTES: number;
|
|
24
|
+
/** Terminal launch outcomes a daemon may report (`Result.status`). */
|
|
25
|
+
export declare const RESULT_STATUSES: readonly ["succeeded", "failed", "timed_out"];
|
|
26
|
+
export type ResultStatus = (typeof RESULT_STATUSES)[number];
|
|
27
|
+
/** Custom-provider model override carried on a Launch (C4/C8). `apiKey` is secret. */
|
|
28
|
+
export declare const ModelOverrideSchema: z.ZodObject<{
|
|
29
|
+
kind: z.ZodDefault<z.ZodLiteral<"custom">>;
|
|
30
|
+
api_url: z.ZodString;
|
|
31
|
+
api_key: z.ZodString;
|
|
32
|
+
}, "strip", z.ZodTypeAny, {
|
|
33
|
+
api_key: string;
|
|
34
|
+
kind: "custom";
|
|
35
|
+
api_url: string;
|
|
36
|
+
}, {
|
|
37
|
+
api_key: string;
|
|
38
|
+
api_url: string;
|
|
39
|
+
kind?: "custom" | undefined;
|
|
40
|
+
}>;
|
|
41
|
+
export type ModelOverride = z.infer<typeof ModelOverrideSchema>;
|
|
42
|
+
export declare const HelloAckSchema: z.ZodObject<{
|
|
43
|
+
type: z.ZodLiteral<"hello_ack">;
|
|
44
|
+
machine_id: z.ZodString;
|
|
45
|
+
server_time: z.ZodString;
|
|
46
|
+
heartbeat_interval_s: z.ZodNumber;
|
|
47
|
+
}, "strip", z.ZodTypeAny, {
|
|
48
|
+
type: "hello_ack";
|
|
49
|
+
machine_id: string;
|
|
50
|
+
server_time: string;
|
|
51
|
+
heartbeat_interval_s: number;
|
|
52
|
+
}, {
|
|
53
|
+
type: "hello_ack";
|
|
54
|
+
machine_id: string;
|
|
55
|
+
server_time: string;
|
|
56
|
+
heartbeat_interval_s: number;
|
|
57
|
+
}>;
|
|
58
|
+
export type HelloAck = z.infer<typeof HelloAckSchema>;
|
|
59
|
+
export declare const LaunchSchema: z.ZodObject<{
|
|
60
|
+
type: z.ZodLiteral<"launch">;
|
|
61
|
+
launch_id: z.ZodString;
|
|
62
|
+
agent_id: z.ZodString;
|
|
63
|
+
prompt: z.ZodString;
|
|
64
|
+
repo: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
65
|
+
model_override: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
66
|
+
kind: z.ZodDefault<z.ZodLiteral<"custom">>;
|
|
67
|
+
api_url: z.ZodString;
|
|
68
|
+
api_key: z.ZodString;
|
|
69
|
+
}, "strip", z.ZodTypeAny, {
|
|
70
|
+
api_key: string;
|
|
71
|
+
kind: "custom";
|
|
72
|
+
api_url: string;
|
|
73
|
+
}, {
|
|
74
|
+
api_key: string;
|
|
75
|
+
api_url: string;
|
|
76
|
+
kind?: "custom" | undefined;
|
|
77
|
+
}>>>;
|
|
78
|
+
capabilities: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
79
|
+
deadline_s: z.ZodNumber;
|
|
80
|
+
}, "strip", z.ZodTypeAny, {
|
|
81
|
+
type: "launch";
|
|
82
|
+
launch_id: string;
|
|
83
|
+
agent_id: string;
|
|
84
|
+
prompt: string;
|
|
85
|
+
capabilities: string[];
|
|
86
|
+
deadline_s: number;
|
|
87
|
+
repo?: string | null | undefined;
|
|
88
|
+
model_override?: {
|
|
89
|
+
api_key: string;
|
|
90
|
+
kind: "custom";
|
|
91
|
+
api_url: string;
|
|
92
|
+
} | null | undefined;
|
|
93
|
+
}, {
|
|
94
|
+
type: "launch";
|
|
95
|
+
launch_id: string;
|
|
96
|
+
agent_id: string;
|
|
97
|
+
prompt: string;
|
|
98
|
+
deadline_s: number;
|
|
99
|
+
repo?: string | null | undefined;
|
|
100
|
+
model_override?: {
|
|
101
|
+
api_key: string;
|
|
102
|
+
api_url: string;
|
|
103
|
+
kind?: "custom" | undefined;
|
|
104
|
+
} | null | undefined;
|
|
105
|
+
capabilities?: string[] | undefined;
|
|
106
|
+
}>;
|
|
107
|
+
export type Launch = z.infer<typeof LaunchSchema>;
|
|
108
|
+
export declare const PingSchema: z.ZodObject<{
|
|
109
|
+
type: z.ZodLiteral<"ping">;
|
|
110
|
+
nonce: z.ZodString;
|
|
111
|
+
}, "strip", z.ZodTypeAny, {
|
|
112
|
+
type: "ping";
|
|
113
|
+
nonce: string;
|
|
114
|
+
}, {
|
|
115
|
+
type: "ping";
|
|
116
|
+
nonce: string;
|
|
117
|
+
}>;
|
|
118
|
+
export type Ping = z.infer<typeof PingSchema>;
|
|
119
|
+
export declare const ServerErrorSchema: z.ZodObject<{
|
|
120
|
+
type: z.ZodLiteral<"error">;
|
|
121
|
+
code: z.ZodString;
|
|
122
|
+
detail: z.ZodString;
|
|
123
|
+
launch_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
124
|
+
}, "strip", z.ZodTypeAny, {
|
|
125
|
+
code: string;
|
|
126
|
+
type: "error";
|
|
127
|
+
detail: string;
|
|
128
|
+
launch_id?: string | null | undefined;
|
|
129
|
+
}, {
|
|
130
|
+
code: string;
|
|
131
|
+
type: "error";
|
|
132
|
+
detail: string;
|
|
133
|
+
launch_id?: string | null | undefined;
|
|
134
|
+
}>;
|
|
135
|
+
export type ServerError = z.infer<typeof ServerErrorSchema>;
|
|
136
|
+
/** Discriminated union of every frame the SERVER may send us (inbound). */
|
|
137
|
+
export declare const InboundFrameSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
138
|
+
type: z.ZodLiteral<"hello_ack">;
|
|
139
|
+
machine_id: z.ZodString;
|
|
140
|
+
server_time: z.ZodString;
|
|
141
|
+
heartbeat_interval_s: z.ZodNumber;
|
|
142
|
+
}, "strip", z.ZodTypeAny, {
|
|
143
|
+
type: "hello_ack";
|
|
144
|
+
machine_id: string;
|
|
145
|
+
server_time: string;
|
|
146
|
+
heartbeat_interval_s: number;
|
|
147
|
+
}, {
|
|
148
|
+
type: "hello_ack";
|
|
149
|
+
machine_id: string;
|
|
150
|
+
server_time: string;
|
|
151
|
+
heartbeat_interval_s: number;
|
|
152
|
+
}>, z.ZodObject<{
|
|
153
|
+
type: z.ZodLiteral<"launch">;
|
|
154
|
+
launch_id: z.ZodString;
|
|
155
|
+
agent_id: z.ZodString;
|
|
156
|
+
prompt: z.ZodString;
|
|
157
|
+
repo: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
158
|
+
model_override: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
159
|
+
kind: z.ZodDefault<z.ZodLiteral<"custom">>;
|
|
160
|
+
api_url: z.ZodString;
|
|
161
|
+
api_key: z.ZodString;
|
|
162
|
+
}, "strip", z.ZodTypeAny, {
|
|
163
|
+
api_key: string;
|
|
164
|
+
kind: "custom";
|
|
165
|
+
api_url: string;
|
|
166
|
+
}, {
|
|
167
|
+
api_key: string;
|
|
168
|
+
api_url: string;
|
|
169
|
+
kind?: "custom" | undefined;
|
|
170
|
+
}>>>;
|
|
171
|
+
capabilities: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
172
|
+
deadline_s: z.ZodNumber;
|
|
173
|
+
}, "strip", z.ZodTypeAny, {
|
|
174
|
+
type: "launch";
|
|
175
|
+
launch_id: string;
|
|
176
|
+
agent_id: string;
|
|
177
|
+
prompt: string;
|
|
178
|
+
capabilities: string[];
|
|
179
|
+
deadline_s: number;
|
|
180
|
+
repo?: string | null | undefined;
|
|
181
|
+
model_override?: {
|
|
182
|
+
api_key: string;
|
|
183
|
+
kind: "custom";
|
|
184
|
+
api_url: string;
|
|
185
|
+
} | null | undefined;
|
|
186
|
+
}, {
|
|
187
|
+
type: "launch";
|
|
188
|
+
launch_id: string;
|
|
189
|
+
agent_id: string;
|
|
190
|
+
prompt: string;
|
|
191
|
+
deadline_s: number;
|
|
192
|
+
repo?: string | null | undefined;
|
|
193
|
+
model_override?: {
|
|
194
|
+
api_key: string;
|
|
195
|
+
api_url: string;
|
|
196
|
+
kind?: "custom" | undefined;
|
|
197
|
+
} | null | undefined;
|
|
198
|
+
capabilities?: string[] | undefined;
|
|
199
|
+
}>, z.ZodObject<{
|
|
200
|
+
type: z.ZodLiteral<"ping">;
|
|
201
|
+
nonce: z.ZodString;
|
|
202
|
+
}, "strip", z.ZodTypeAny, {
|
|
203
|
+
type: "ping";
|
|
204
|
+
nonce: string;
|
|
205
|
+
}, {
|
|
206
|
+
type: "ping";
|
|
207
|
+
nonce: string;
|
|
208
|
+
}>, z.ZodObject<{
|
|
209
|
+
type: z.ZodLiteral<"error">;
|
|
210
|
+
code: z.ZodString;
|
|
211
|
+
detail: z.ZodString;
|
|
212
|
+
launch_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
213
|
+
}, "strip", z.ZodTypeAny, {
|
|
214
|
+
code: string;
|
|
215
|
+
type: "error";
|
|
216
|
+
detail: string;
|
|
217
|
+
launch_id?: string | null | undefined;
|
|
218
|
+
}, {
|
|
219
|
+
code: string;
|
|
220
|
+
type: "error";
|
|
221
|
+
detail: string;
|
|
222
|
+
launch_id?: string | null | undefined;
|
|
223
|
+
}>]>;
|
|
224
|
+
export type InboundFrame = z.infer<typeof InboundFrameSchema>;
|
|
225
|
+
export declare const HELLO_MAX_TOOL_LEN = 200;
|
|
226
|
+
export declare const HELLO_MAX_TOOLS = 100;
|
|
227
|
+
export declare const HELLO_MAX_VERSION_LEN = 200;
|
|
228
|
+
export declare const HelloSchema: z.ZodObject<{
|
|
229
|
+
type: z.ZodLiteral<"hello">;
|
|
230
|
+
daemon_version: z.ZodString;
|
|
231
|
+
advertised_tools: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
232
|
+
}, "strip", z.ZodTypeAny, {
|
|
233
|
+
type: "hello";
|
|
234
|
+
daemon_version: string;
|
|
235
|
+
advertised_tools: string[];
|
|
236
|
+
}, {
|
|
237
|
+
type: "hello";
|
|
238
|
+
daemon_version: string;
|
|
239
|
+
advertised_tools?: string[] | undefined;
|
|
240
|
+
}>;
|
|
241
|
+
export type Hello = z.infer<typeof HelloSchema>;
|
|
242
|
+
export declare const ProgressSchema: z.ZodObject<{
|
|
243
|
+
type: z.ZodLiteral<"progress">;
|
|
244
|
+
launch_id: z.ZodString;
|
|
245
|
+
stage: z.ZodString;
|
|
246
|
+
message: z.ZodDefault<z.ZodString>;
|
|
247
|
+
}, "strip", z.ZodTypeAny, {
|
|
248
|
+
message: string;
|
|
249
|
+
type: "progress";
|
|
250
|
+
launch_id: string;
|
|
251
|
+
stage: string;
|
|
252
|
+
}, {
|
|
253
|
+
type: "progress";
|
|
254
|
+
launch_id: string;
|
|
255
|
+
stage: string;
|
|
256
|
+
message?: string | undefined;
|
|
257
|
+
}>;
|
|
258
|
+
export type Progress = z.infer<typeof ProgressSchema>;
|
|
259
|
+
export declare const ResultSchema: z.ZodObject<{
|
|
260
|
+
type: z.ZodLiteral<"result">;
|
|
261
|
+
launch_id: z.ZodString;
|
|
262
|
+
status: z.ZodEnum<["succeeded", "failed", "timed_out"]>;
|
|
263
|
+
text: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
264
|
+
diff: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
265
|
+
files: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
|
|
266
|
+
cost_usd: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
267
|
+
tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
268
|
+
error: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
269
|
+
}, "strip", z.ZodTypeAny, {
|
|
270
|
+
type: "result";
|
|
271
|
+
status: "succeeded" | "failed" | "timed_out";
|
|
272
|
+
launch_id: string;
|
|
273
|
+
error?: string | null | undefined;
|
|
274
|
+
diff?: string | null | undefined;
|
|
275
|
+
files?: string[] | null | undefined;
|
|
276
|
+
text?: string | null | undefined;
|
|
277
|
+
cost_usd?: number | null | undefined;
|
|
278
|
+
tokens?: number | null | undefined;
|
|
279
|
+
}, {
|
|
280
|
+
type: "result";
|
|
281
|
+
status: "succeeded" | "failed" | "timed_out";
|
|
282
|
+
launch_id: string;
|
|
283
|
+
error?: string | null | undefined;
|
|
284
|
+
diff?: string | null | undefined;
|
|
285
|
+
files?: string[] | null | undefined;
|
|
286
|
+
text?: string | null | undefined;
|
|
287
|
+
cost_usd?: number | null | undefined;
|
|
288
|
+
tokens?: number | null | undefined;
|
|
289
|
+
}>;
|
|
290
|
+
export type Result = z.infer<typeof ResultSchema>;
|
|
291
|
+
export declare const PongSchema: z.ZodObject<{
|
|
292
|
+
type: z.ZodLiteral<"pong">;
|
|
293
|
+
nonce: z.ZodString;
|
|
294
|
+
}, "strip", z.ZodTypeAny, {
|
|
295
|
+
type: "pong";
|
|
296
|
+
nonce: string;
|
|
297
|
+
}, {
|
|
298
|
+
type: "pong";
|
|
299
|
+
nonce: string;
|
|
300
|
+
}>;
|
|
301
|
+
export type Pong = z.infer<typeof PongSchema>;
|
|
302
|
+
export type OutboundFrame = Hello | Progress | Result | Pong;
|
|
303
|
+
/**
|
|
304
|
+
* Validate one decoded server->daemon message at the boundary (mirrors
|
|
305
|
+
* `parse_inbound`). Throws `ZodError` on an unknown `type` or any malformed
|
|
306
|
+
* field; the receive loop catches it, logs, and ignores the frame.
|
|
307
|
+
*/
|
|
308
|
+
export declare function parseInbound(raw: unknown): InboundFrame;
|
|
309
|
+
export declare function makeHello(daemonVersion: string, advertisedTools?: string[]): Hello;
|
|
310
|
+
export declare function makePong(nonce: string): Pong;
|
|
311
|
+
export declare function makeProgress(launchId: string, stage: string, message?: string): Progress;
|