sessionpipe-core 0.9.0 → 0.11.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/dist/control.js +180 -13
- package/dist/control.js.map +2 -2
- package/dist/index.js +2133 -965
- package/dist/index.js.map +4 -4
- package/dist/schema/v1.d.ts +443 -34
- package/dist/schema/v1.d.ts.map +1 -1
- package/dist/schema.js +201 -34
- package/dist/schema.js.map +2 -2
- package/dist/service.js +155 -0
- package/dist/service.js.map +7 -0
- package/dist/src/adapters/acp-control.d.ts +87 -0
- package/dist/src/adapters/acp-control.d.ts.map +1 -0
- package/dist/src/adapters/antigravity-control.d.ts +15 -5
- package/dist/src/adapters/antigravity-control.d.ts.map +1 -1
- package/dist/src/adapters/claude-code-control.d.ts +39 -4
- package/dist/src/adapters/claude-code-control.d.ts.map +1 -1
- package/dist/src/adapters/claude-code-pool.d.ts +116 -0
- package/dist/src/adapters/claude-code-pool.d.ts.map +1 -0
- package/dist/src/adapters/claude-code.d.ts +20 -1
- package/dist/src/adapters/claude-code.d.ts.map +1 -1
- package/dist/src/adapters/claude-shaped.d.ts +3 -0
- package/dist/src/adapters/claude-shaped.d.ts.map +1 -1
- package/dist/src/adapters/codex-config.d.ts +2 -1
- package/dist/src/adapters/codex-config.d.ts.map +1 -1
- package/dist/src/adapters/codex-control.d.ts +23 -7
- package/dist/src/adapters/codex-control.d.ts.map +1 -1
- package/dist/src/adapters/codex.d.ts +9 -0
- package/dist/src/adapters/codex.d.ts.map +1 -1
- package/dist/src/adapters/gemini-cli.d.ts +3 -0
- package/dist/src/adapters/gemini-cli.d.ts.map +1 -1
- package/dist/src/adapters/headless.d.ts +4 -1
- package/dist/src/adapters/headless.d.ts.map +1 -1
- package/dist/src/adapters/index.d.ts +7 -1
- package/dist/src/adapters/index.d.ts.map +1 -1
- package/dist/src/adapters/types.d.ts +18 -1
- package/dist/src/adapters/types.d.ts.map +1 -1
- package/dist/src/config.d.ts +6 -0
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/control/verify.d.ts +99 -17
- package/dist/src/control/verify.d.ts.map +1 -1
- package/dist/src/index.d.ts +3 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/launched-by.d.ts +12 -0
- package/dist/src/launched-by.d.ts.map +1 -0
- package/dist/src/paths.d.ts +4 -0
- package/dist/src/paths.d.ts.map +1 -1
- package/dist/src/privacy/filter.d.ts.map +1 -1
- package/dist/src/service/index.d.ts +83 -0
- package/dist/src/service/index.d.ts.map +1 -0
- package/dist/src/types.d.ts +4 -0
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/version.d.ts +39 -0
- package/dist/src/version.d.ts.map +1 -0
- package/dist/version.js +75 -0
- package/dist/version.js.map +7 -0
- package/package.json +10 -2
package/dist/service.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// sessionpipe-core 0.11.0 · Apache-2.0 · https://sessionpipe.org
|
|
2
|
+
|
|
3
|
+
// src/service/index.ts
|
|
4
|
+
import { execFileSync } from "node:child_process";
|
|
5
|
+
import { existsSync, mkdirSync, unlinkSync, writeFileSync } from "node:fs";
|
|
6
|
+
import os from "node:os";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
var execQuiet = (cmd, args) => execFileSync(cmd, args, { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 15e3 });
|
|
9
|
+
var xml = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
10
|
+
var sd = (s) => `"${s.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/%/g, "%%")}"`;
|
|
11
|
+
function serviceFiles(s) {
|
|
12
|
+
const home = s.home ?? os.homedir();
|
|
13
|
+
const env = (manager) => ({ SESSIONPIPE_SERVICE: manager, ...s.env });
|
|
14
|
+
const plistEnv = Object.entries(env("launchd")).map(([k, v]) => `<key>${xml(k)}</key><string>${xml(v)}</string>`).join("");
|
|
15
|
+
const plist = `<?xml version="1.0" encoding="UTF-8"?>
|
|
16
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
17
|
+
<plist version="1.0">
|
|
18
|
+
<dict>
|
|
19
|
+
<key>Label</key><string>${xml(s.label)}</string>
|
|
20
|
+
<key>ProgramArguments</key>
|
|
21
|
+
<array>${s.argv.map((a) => `<string>${xml(a)}</string>`).join("")}</array>
|
|
22
|
+
<key>EnvironmentVariables</key><dict>${plistEnv}</dict>
|
|
23
|
+
<key>RunAtLoad</key><true/>
|
|
24
|
+
<key>KeepAlive</key><dict><key>SuccessfulExit</key><false/></dict>
|
|
25
|
+
<key>ProcessType</key><string>Background</string>
|
|
26
|
+
<key>StandardOutPath</key><string>${xml(s.logPath)}</string>
|
|
27
|
+
<key>StandardErrorPath</key><string>${xml(s.logPath)}</string>
|
|
28
|
+
</dict>
|
|
29
|
+
</plist>
|
|
30
|
+
`;
|
|
31
|
+
const unitEnv = Object.entries(env("systemd")).map(([k, v]) => `Environment=${k === "SESSIONPIPE_SERVICE" ? `${k}=${v}` : sd(`${k}=${v}`)}`).join("\n");
|
|
32
|
+
const unit = `[Unit]
|
|
33
|
+
Description=${s.description.replace(/\n/g, " ")}
|
|
34
|
+
After=network-online.target
|
|
35
|
+
|
|
36
|
+
[Service]
|
|
37
|
+
ExecStart=${s.argv.map(sd).join(" ")}
|
|
38
|
+
${unitEnv}
|
|
39
|
+
Restart=on-failure
|
|
40
|
+
RestartForceExitStatus=75
|
|
41
|
+
RestartSec=5
|
|
42
|
+
|
|
43
|
+
[Install]
|
|
44
|
+
WantedBy=default.target
|
|
45
|
+
`;
|
|
46
|
+
return {
|
|
47
|
+
plist: { path: path.join(home, "Library", "LaunchAgents", `${s.label}.plist`), text: plist },
|
|
48
|
+
unit: { path: path.join(home, ".config", "systemd", "user", s.unit), text: unit }
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function ensureLinger(user, exec = execQuiet) {
|
|
52
|
+
const lingering = () => {
|
|
53
|
+
try {
|
|
54
|
+
return /^Linger=yes/m.test(exec("loginctl", ["show-user", user, "--property=Linger"]));
|
|
55
|
+
} catch {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
if (lingering()) return { on: true, note: "it keeps running after you log out (linger was already on)" };
|
|
60
|
+
try {
|
|
61
|
+
exec("loginctl", ["enable-linger", user]);
|
|
62
|
+
} catch {
|
|
63
|
+
}
|
|
64
|
+
if (lingering()) return { on: true, note: "it keeps running after you log out (turned linger on)" };
|
|
65
|
+
return {
|
|
66
|
+
on: false,
|
|
67
|
+
note: `it stops when you log out: run \`sudo loginctl enable-linger ${user}\` once to keep it running`
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
var line = (cmd, args) => [cmd, ...args].join(" ");
|
|
71
|
+
function installService(o) {
|
|
72
|
+
const f = serviceFiles(o);
|
|
73
|
+
const platform = o.platform ?? process.platform;
|
|
74
|
+
const uid = o.uid ?? String(process.getuid?.() ?? "");
|
|
75
|
+
const commands = [];
|
|
76
|
+
const real = o.exec ?? execQuiet;
|
|
77
|
+
const run = (cmd, args) => {
|
|
78
|
+
commands.push(line(cmd, args));
|
|
79
|
+
return o.dryRun ? "" : real(cmd, args);
|
|
80
|
+
};
|
|
81
|
+
const write = (file) => {
|
|
82
|
+
if (o.dryRun) return;
|
|
83
|
+
mkdirSync(path.dirname(file.path), { recursive: true });
|
|
84
|
+
writeFileSync(file.path, file.text);
|
|
85
|
+
};
|
|
86
|
+
if (platform === "darwin") {
|
|
87
|
+
write(f.plist);
|
|
88
|
+
for (const d of ["gui", "user"])
|
|
89
|
+
try {
|
|
90
|
+
run("launchctl", ["bootout", `${d}/${uid}/${o.label}`]);
|
|
91
|
+
} catch {
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
run("launchctl", ["bootstrap", `gui/${uid}`, f.plist.path]);
|
|
95
|
+
return { files: [f.plist], commands, manager: "launchd", domain: "gui" };
|
|
96
|
+
} catch {
|
|
97
|
+
}
|
|
98
|
+
run("launchctl", ["bootstrap", `user/${uid}`, f.plist.path]);
|
|
99
|
+
return { files: [f.plist], commands, manager: "launchd", domain: "user" };
|
|
100
|
+
}
|
|
101
|
+
if (platform === "linux") {
|
|
102
|
+
write(f.unit);
|
|
103
|
+
try {
|
|
104
|
+
run("systemctl", ["--user", "daemon-reload"]);
|
|
105
|
+
run("systemctl", ["--user", "enable", "--now", o.unit]);
|
|
106
|
+
} catch {
|
|
107
|
+
return { files: [f.unit], commands, manager: null, unreachable: f.unit.path };
|
|
108
|
+
}
|
|
109
|
+
const user = o.user ?? os.userInfo().username;
|
|
110
|
+
if (o.dryRun) {
|
|
111
|
+
commands.push(line("loginctl", ["enable-linger", user]));
|
|
112
|
+
return { files: [f.unit], commands, manager: "systemd", linger: { on: false, note: "dry run" } };
|
|
113
|
+
}
|
|
114
|
+
return { files: [f.unit], commands, manager: "systemd", linger: ensureLinger(user, run) };
|
|
115
|
+
}
|
|
116
|
+
return { files: [], commands, manager: null };
|
|
117
|
+
}
|
|
118
|
+
function uninstallService(o) {
|
|
119
|
+
const f = serviceFiles({ ...o, description: "", argv: [], logPath: "" });
|
|
120
|
+
const platform = o.platform ?? process.platform;
|
|
121
|
+
const uid = o.uid ?? String(process.getuid?.() ?? "");
|
|
122
|
+
const commands = [];
|
|
123
|
+
const files = [];
|
|
124
|
+
const real = o.exec ?? execQuiet;
|
|
125
|
+
const run = (cmd, args) => {
|
|
126
|
+
commands.push(line(cmd, args));
|
|
127
|
+
if (o.dryRun) return;
|
|
128
|
+
try {
|
|
129
|
+
real(cmd, args);
|
|
130
|
+
} catch {
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
const remove = (file) => {
|
|
134
|
+
files.push(file);
|
|
135
|
+
if (!o.dryRun) unlinkSync(file);
|
|
136
|
+
};
|
|
137
|
+
if (platform === "darwin" && existsSync(f.plist.path)) {
|
|
138
|
+
run("launchctl", ["bootout", `gui/${uid}/${o.label}`]);
|
|
139
|
+
run("launchctl", ["bootout", `user/${uid}/${o.label}`]);
|
|
140
|
+
remove(f.plist.path);
|
|
141
|
+
}
|
|
142
|
+
if (platform === "linux" && existsSync(f.unit.path)) {
|
|
143
|
+
run("systemctl", ["--user", "disable", "--now", o.unit]);
|
|
144
|
+
remove(f.unit.path);
|
|
145
|
+
run("systemctl", ["--user", "daemon-reload"]);
|
|
146
|
+
}
|
|
147
|
+
return { files, commands };
|
|
148
|
+
}
|
|
149
|
+
export {
|
|
150
|
+
ensureLinger,
|
|
151
|
+
installService,
|
|
152
|
+
serviceFiles,
|
|
153
|
+
uninstallService
|
|
154
|
+
};
|
|
155
|
+
//# sourceMappingURL=service.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/service/index.ts"],
|
|
4
|
+
"sourcesContent": ["// SPDX-License-Identifier: Apache-2.0\n/** sessionpipe-core/service \u2014 a per-user background service for a sessionpipe process:\n * a launchd agent on macOS, a systemd user unit on Linux. The control daemon runs\n * under it (`org.sessionpipe.control`), and so can a receiver of the person's own (a\n * board on their machine), with the same files and the same commands. Node only: it\n * writes files and runs launchctl, systemctl and loginctl, so it is never part of the\n * root export, which stays Worker- and browser-safe.\n *\n * Both files restart the process when it exits non-zero, and when it exits\n * UPDATE_EXIT (75, sessionpipe-core/version) to come back on new code. The process is\n * told which manager that is in SESSIONPIPE_SERVICE (`launchd`, `systemd`). Nothing\n * here needs root, and a dry run touches nothing: it answers the files it would write\n * and the commands it would run. */\nimport { execFileSync } from \"node:child_process\";\nimport { existsSync, mkdirSync, unlinkSync, writeFileSync } from \"node:fs\";\nimport os from \"node:os\";\nimport path from \"node:path\";\n\n/** One service, as both managers need it. */\nexport interface ServiceSpec {\n /** The launchd label, also the plist's name: `org.sessionpipe.control`. */\n label: string;\n /** The systemd user unit's file name: `sessionpipe-control.service`. */\n unit: string;\n /** The unit's Description line. */\n description: string;\n /** The program and its arguments, each one argument (never through a shell). */\n argv: string[];\n /** More environment for the process, beside SESSIONPIPE_SERVICE. */\n env?: Record<string, string>;\n /** Where launchd writes its stdout and stderr (journald keeps a unit's). */\n logPath: string;\n /** The home the files go under; the user's own by default. */\n home?: string;\n}\n\n/** A file the service writes, and what is in it. */\nexport interface ServiceFile {\n path: string;\n text: string;\n}\n\n/** Runs one command and answers its stdout; throws when it fails. */\nexport type Exec = (cmd: string, args: string[]) => string;\n\nconst execQuiet: Exec = (cmd, args) =>\n execFileSync(cmd, args, { encoding: \"utf8\", stdio: [\"ignore\", \"pipe\", \"ignore\"], timeout: 15_000 });\n\nconst xml = (s: string) => s.replace(/&/g, \"&\").replace(/</g, \"<\").replace(/>/g, \">\");\n/** One systemd argument, quoted: backslashes and quotes escaped, `%` doubled (a specifier otherwise). */\nconst sd = (s: string) => `\"${s.replace(/\\\\/g, \"\\\\\\\\\").replace(/\"/g, '\\\\\"').replace(/%/g, \"%%\")}\"`;\n\n/** The plist and the unit for a service, and where each goes. */\nexport function serviceFiles(s: ServiceSpec): { plist: ServiceFile; unit: ServiceFile } {\n const home = s.home ?? os.homedir();\n const env = (manager: string) => ({ SESSIONPIPE_SERVICE: manager, ...s.env });\n const plistEnv = Object.entries(env(\"launchd\"))\n .map(([k, v]) => `<key>${xml(k)}</key><string>${xml(v)}</string>`)\n .join(\"\");\n const plist = `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n <key>Label</key><string>${xml(s.label)}</string>\n <key>ProgramArguments</key>\n <array>${s.argv.map((a) => `<string>${xml(a)}</string>`).join(\"\")}</array>\n <key>EnvironmentVariables</key><dict>${plistEnv}</dict>\n <key>RunAtLoad</key><true/>\n <key>KeepAlive</key><dict><key>SuccessfulExit</key><false/></dict>\n <key>ProcessType</key><string>Background</string>\n <key>StandardOutPath</key><string>${xml(s.logPath)}</string>\n <key>StandardErrorPath</key><string>${xml(s.logPath)}</string>\n</dict>\n</plist>\n`;\n const unitEnv = Object.entries(env(\"systemd\"))\n .map(([k, v]) => `Environment=${k === \"SESSIONPIPE_SERVICE\" ? `${k}=${v}` : sd(`${k}=${v}`)}`)\n .join(\"\\n\");\n const unit = `[Unit]\nDescription=${s.description.replace(/\\n/g, \" \")}\nAfter=network-online.target\n\n[Service]\nExecStart=${s.argv.map(sd).join(\" \")}\n${unitEnv}\nRestart=on-failure\nRestartForceExitStatus=75\nRestartSec=5\n\n[Install]\nWantedBy=default.target\n`;\n return {\n plist: { path: path.join(home, \"Library\", \"LaunchAgents\", `${s.label}.plist`), text: plist },\n unit: { path: path.join(home, \".config\", \"systemd\", \"user\", s.unit), text: unit },\n };\n}\n\n/** A systemd user service stops when its person's last login ends \u2014 closing the ssh\n * session to a lab workstation or a cloud machine stopped the daemon with it \u2014 unless\n * the user lingers. `loginctl enable-linger` for yourself needs no root on systemd's\n * default policy; where it does, say the one command that does it. */\nexport function ensureLinger(user: string, exec: Exec = execQuiet): { on: boolean; note: string } {\n const lingering = () => {\n try {\n return /^Linger=yes/m.test(exec(\"loginctl\", [\"show-user\", user, \"--property=Linger\"]));\n } catch {\n return false;\n }\n };\n if (lingering()) return { on: true, note: \"it keeps running after you log out (linger was already on)\" };\n try {\n exec(\"loginctl\", [\"enable-linger\", user]);\n } catch {}\n if (lingering()) return { on: true, note: \"it keeps running after you log out (turned linger on)\" };\n return {\n on: false,\n note: `it stops when you log out: run \\`sudo loginctl enable-linger ${user}\\` once to keep it running`,\n };\n}\n\n/** What an install did, or would do in a dry run. */\nexport interface ServicePlan {\n /** The files written (or that would be). */\n files: ServiceFile[];\n /** The commands run (or that would be), one string each, in order. */\n commands: string[];\n /** Which manager runs it now: null on a platform with none, or where it isn't reachable. */\n manager: \"launchd\" | \"systemd\" | null;\n /** launchd: `gui` when someone is at the screen, else `user` (it starts again at the next login there). */\n domain?: \"gui\" | \"user\";\n /** systemd: whether it outlives the login, in words. */\n linger?: { on: boolean; note: string };\n /** The file that was written for a manager that couldn't be reached. */\n unreachable?: string;\n}\n\nexport interface InstallOptions extends ServiceSpec {\n /** Answer the plan and touch nothing. */\n dryRun?: boolean;\n exec?: Exec;\n platform?: NodeJS.Platform;\n /** The user's id (launchd's domains) and name (linger); this process's by default. */\n uid?: string;\n user?: string;\n}\n\nconst line = (cmd: string, args: string[]) => [cmd, ...args].join(\" \");\n\n/** Write the service for this platform and start it now; a service already there is\n * replaced (launchd: booted out first). */\nexport function installService(o: InstallOptions): ServicePlan {\n const f = serviceFiles(o);\n const platform = o.platform ?? process.platform;\n const uid = o.uid ?? String(process.getuid?.() ?? \"\");\n const commands: string[] = [];\n const real = o.exec ?? execQuiet;\n const run: Exec = (cmd, args) => {\n commands.push(line(cmd, args));\n return o.dryRun ? \"\" : real(cmd, args);\n };\n const write = (file: ServiceFile) => {\n if (o.dryRun) return;\n mkdirSync(path.dirname(file.path), { recursive: true });\n writeFileSync(file.path, file.text);\n };\n if (platform === \"darwin\") {\n write(f.plist);\n for (const d of [\"gui\", \"user\"])\n try {\n run(\"launchctl\", [\"bootout\", `${d}/${uid}/${o.label}`]);\n } catch {}\n try {\n run(\"launchctl\", [\"bootstrap\", `gui/${uid}`, f.plist.path]);\n return { files: [f.plist], commands, manager: \"launchd\", domain: \"gui\" };\n } catch {}\n // No one logged in at the screen (an ssh session to a Mac mini): the gui domain\n // doesn't exist. The user domain runs it now; after a restart it starts again at\n // the next login at the screen.\n run(\"launchctl\", [\"bootstrap\", `user/${uid}`, f.plist.path]);\n return { files: [f.plist], commands, manager: \"launchd\", domain: \"user\" };\n }\n if (platform === \"linux\") {\n write(f.unit);\n try {\n run(\"systemctl\", [\"--user\", \"daemon-reload\"]);\n run(\"systemctl\", [\"--user\", \"enable\", \"--now\", o.unit]);\n } catch {\n return { files: [f.unit], commands, manager: null, unreachable: f.unit.path };\n }\n const user = o.user ?? os.userInfo().username;\n if (o.dryRun) {\n commands.push(line(\"loginctl\", [\"enable-linger\", user]));\n return { files: [f.unit], commands, manager: \"systemd\", linger: { on: false, note: \"dry run\" } };\n }\n return { files: [f.unit], commands, manager: \"systemd\", linger: ensureLinger(user, run) };\n }\n return { files: [], commands, manager: null };\n}\n\nexport interface UninstallOptions {\n label: string;\n unit: string;\n home?: string;\n dryRun?: boolean;\n exec?: Exec;\n platform?: NodeJS.Platform;\n uid?: string;\n}\n\n/** Stop the service and remove its file, where this platform has one; nothing where\n * there is none. A manager that says it wasn't loaded is no failure. */\nexport function uninstallService(o: UninstallOptions): { files: string[]; commands: string[] } {\n const f = serviceFiles({ ...o, description: \"\", argv: [], logPath: \"\" });\n const platform = o.platform ?? process.platform;\n const uid = o.uid ?? String(process.getuid?.() ?? \"\");\n const commands: string[] = [];\n const files: string[] = [];\n const real = o.exec ?? execQuiet;\n const run = (cmd: string, args: string[]) => {\n commands.push(line(cmd, args));\n if (o.dryRun) return;\n try {\n real(cmd, args);\n } catch {}\n };\n const remove = (file: string) => {\n files.push(file);\n if (!o.dryRun) unlinkSync(file);\n };\n if (platform === \"darwin\" && existsSync(f.plist.path)) {\n run(\"launchctl\", [\"bootout\", `gui/${uid}/${o.label}`]);\n run(\"launchctl\", [\"bootout\", `user/${uid}/${o.label}`]);\n remove(f.plist.path);\n }\n if (platform === \"linux\" && existsSync(f.unit.path)) {\n run(\"systemctl\", [\"--user\", \"disable\", \"--now\", o.unit]);\n remove(f.unit.path);\n run(\"systemctl\", [\"--user\", \"daemon-reload\"]);\n }\n return { files, commands };\n}\n"],
|
|
5
|
+
"mappings": ";;;AAaA,SAAS,oBAAoB;AAC7B,SAAS,YAAY,WAAW,YAAY,qBAAqB;AACjE,OAAO,QAAQ;AACf,OAAO,UAAU;AA6BjB,IAAM,YAAkB,CAAC,KAAK,SAC5B,aAAa,KAAK,MAAM,EAAE,UAAU,QAAQ,OAAO,CAAC,UAAU,QAAQ,QAAQ,GAAG,SAAS,KAAO,CAAC;AA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;AAC3B;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { type Mode } from "./headless.js";
|
|
2
|
+
export interface AcpAgent {
|
|
3
|
+
/** sessionpipe's harness name (ADAPTERS.md): the registry's id unless a hook adapter already named it. */
|
|
4
|
+
harness: string;
|
|
5
|
+
/** The registry's id. */
|
|
6
|
+
registry: string;
|
|
7
|
+
label: string;
|
|
8
|
+
/** The CLI's name on PATH. */
|
|
9
|
+
bin: string;
|
|
10
|
+
args: string[];
|
|
11
|
+
}
|
|
12
|
+
/** The agents the daemon can drive, with the launch line the registry publishes. */
|
|
13
|
+
export declare const ACP_AGENTS: readonly AcpAgent[];
|
|
14
|
+
export declare const ACP_HARNESSES: readonly string[];
|
|
15
|
+
export declare const acpAgent: (harness: string) => AcpAgent | undefined;
|
|
16
|
+
/** The env var that names an agent's CLI by hand: `SESSIONPIPE_ACP_GEMINI_CLI`. */
|
|
17
|
+
export declare const acpOverride: (harness: string) => string;
|
|
18
|
+
/** An agent's CLI on this machine: the override, else on PATH, else beside the node
|
|
19
|
+
* running this (an `npm install -g` there) or where the installers put it. */
|
|
20
|
+
export declare function findAcpAgent(harness: string, env?: NodeJS.ProcessEnv, home?: string, nodeDir?: string): {
|
|
21
|
+
bin: string;
|
|
22
|
+
args: string[];
|
|
23
|
+
} | null;
|
|
24
|
+
/** The ACP agents installed here, by harness name, for the daemon's hello. */
|
|
25
|
+
export declare function acpHarnesses(env?: NodeJS.ProcessEnv): string[];
|
|
26
|
+
type Json = Record<string, unknown>;
|
|
27
|
+
interface Option {
|
|
28
|
+
optionId: string;
|
|
29
|
+
kind: string;
|
|
30
|
+
}
|
|
31
|
+
/** Which permission option the machine's mode picks, or null for `cancelled`: safe
|
|
32
|
+
* refuses (once, else always), auto allows (once, else always). Inherit refuses as safe
|
|
33
|
+
* does: the agent asked because its own settings want a person, and none is there.
|
|
34
|
+
* Never the other way. */
|
|
35
|
+
export declare function permissionChoice(options: unknown, mode: Mode): Option | null;
|
|
36
|
+
/** A JSON-RPC error in words: its message, and its `data` where that says more (goose
|
|
37
|
+
* 1.55 answers session/new with "Internal error" and the reason in `data`). */
|
|
38
|
+
export declare function errorWords(err: Json): string;
|
|
39
|
+
/** A session the daemon holds (the shape of daemon.ts's SdkSession, plus the agent's own id). */
|
|
40
|
+
export interface AcpHeld {
|
|
41
|
+
/** Deliver one message; resolves with the agent's reply when the turn ends. */
|
|
42
|
+
send(text: string): Promise<{
|
|
43
|
+
reply: string;
|
|
44
|
+
error?: string;
|
|
45
|
+
}>;
|
|
46
|
+
interrupt(): Promise<void>;
|
|
47
|
+
close(): void;
|
|
48
|
+
readonly busy: boolean;
|
|
49
|
+
readonly lastUsed: number;
|
|
50
|
+
readonly mode: "api";
|
|
51
|
+
/** The id the agent gave the session. */
|
|
52
|
+
readonly session: string;
|
|
53
|
+
/** The process is gone or was closed: nothing more can be sent. */
|
|
54
|
+
readonly closed: boolean;
|
|
55
|
+
}
|
|
56
|
+
export interface AcpOptions {
|
|
57
|
+
bin: string;
|
|
58
|
+
args: string[];
|
|
59
|
+
cwd: string;
|
|
60
|
+
mode: Mode;
|
|
61
|
+
label: string;
|
|
62
|
+
env?: NodeJS.ProcessEnv;
|
|
63
|
+
/** Reopen this session of the agent's (`session/load`) instead of starting a new one. */
|
|
64
|
+
load?: string;
|
|
65
|
+
/** The reply so far, each time it grows. */
|
|
66
|
+
onText?: (text: string) => void;
|
|
67
|
+
log?: (line: string) => void;
|
|
68
|
+
now?: () => number;
|
|
69
|
+
/** A turn still running after this is cancelled, then stopped. */
|
|
70
|
+
timeoutMs?: number;
|
|
71
|
+
/** How long the agent may take to answer `initialize` and open the session. */
|
|
72
|
+
openTimeoutMs?: number;
|
|
73
|
+
/** On close, how long the agent gets to leave by itself before SIGTERM (then SIGKILL). */
|
|
74
|
+
closeGraceMs?: number;
|
|
75
|
+
}
|
|
76
|
+
export type AcpStart = {
|
|
77
|
+
held: AcpHeld;
|
|
78
|
+
} | {
|
|
79
|
+
failed: string;
|
|
80
|
+
} | {
|
|
81
|
+
unsupported: string;
|
|
82
|
+
};
|
|
83
|
+
/** Run an ACP agent and open a session in it. Resolves once the agent has answered
|
|
84
|
+
* `session/new` (or `session/load`); every later turn goes through `held.send`. */
|
|
85
|
+
export declare function startAcp(o: AcpOptions): Promise<AcpStart>;
|
|
86
|
+
export {};
|
|
87
|
+
//# sourceMappingURL=acp-control.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acp-control.d.ts","sourceRoot":"","sources":["../../../src/adapters/acp-control.ts"],"names":[],"mappings":"AAeA,OAAO,EAAkD,KAAK,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1F,MAAM,WAAW,QAAQ;IACvB,0GAA0G;IAC1G,OAAO,EAAE,MAAM,CAAC;IAChB,yBAAyB;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,8BAA8B;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAED,oFAAoF;AACpF,eAAO,MAAM,UAAU,EAAE,SAAS,QAAQ,EA0CzC,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,SAAS,MAAM,EAAqC,CAAC;AAEjF,eAAO,MAAM,QAAQ,YAAa,MAAM,KAAG,QAAQ,GAAG,SAA0D,CAAC;AAEjH,mFAAmF;AACnF,eAAO,MAAM,WAAW,YAAa,MAAM,KAAG,MAAuE,CAAC;AAEtH;+EAC+E;AAC/E,wBAAgB,YAAY,CAC1B,OAAO,EAAE,MAAM,EACf,GAAG,GAAE,MAAM,CAAC,UAAwB,EACpC,IAAI,SAAe,EACnB,OAAO,SAAiC,GACvC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,GAAG,IAAI,CAgBxC;AAED,8EAA8E;AAC9E,wBAAgB,YAAY,CAAC,GAAG,G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CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7B,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,kEAAkE;IAClE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+EAA+E;IAC/E,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,0FAA0F;IAC1F,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,MAAM,QAAQ,GAAG;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC;AAIxF;oFACoF;AACpF,wBAAgB,QAAQ,CAAC,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC,CA+QzD"}
|
|
@@ -1,14 +1,24 @@
|
|
|
1
|
+
import type { RunLevel, StartPermission } from "../control/verify.js";
|
|
1
2
|
import { type Mode, type Reading, type RunResult } from "./headless.js";
|
|
2
3
|
/** The `agy` to run: SESSIONPIPE_AGY, else on PATH, else where its installer puts it. */
|
|
3
4
|
export declare function findAgy(env?: NodeJS.ProcessEnv, home?: string): string | null;
|
|
4
|
-
/** Permission flags for
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
|
|
5
|
+
/** Permission flags for a level. Safe: none — agy denies every tool call nobody is
|
|
6
|
+
* there to approve, and says which. Edits: `--mode accept-edits`, its widest, which is
|
|
7
|
+
* also what an auto machine's mode means for it. Inherit: none either, so agy runs as
|
|
8
|
+
* it would by itself. agy has no read-only mode known, so `read` is never offered and
|
|
9
|
+
* throws rather than run at safe. Never `--dangerously-skip-permissions`: no path here
|
|
10
|
+
* writes it. */
|
|
11
|
+
export declare function agyModeFlags(level: RunLevel): string[];
|
|
12
|
+
/** The levels a start may ask agy for on a machine in `mode`: safe, and edits on an
|
|
13
|
+
* auto machine. */
|
|
14
|
+
export declare const offeredLevels: (mode: Mode) => StartPermission[];
|
|
15
|
+
/** What a start that names no level gets, said as what it is: edits on an auto machine,
|
|
16
|
+
* no flag on an inherit one. */
|
|
17
|
+
export declare const defaultLevel: (mode: Mode) => RunLevel;
|
|
8
18
|
/** One headless turn in the folder it is spawned in. A message that starts with a dash
|
|
9
19
|
* would read as a flag after `-p`; a leading space keeps it the prompt. */
|
|
10
20
|
export declare function agyArgs(o: {
|
|
11
|
-
|
|
21
|
+
permission: RunLevel;
|
|
12
22
|
prompt: string;
|
|
13
23
|
resume?: string;
|
|
14
24
|
}): string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"antigravity-control.d.ts","sourceRoot":"","sources":["../../../src/adapters/antigravity-control.ts"],"names":[],"mappings":"AAUA,OAAO,EAAkC,KAAK,IAAI,EAAE,KAAK,OAAO,EAAE,KAAK,SAAS,EAAc,MAAM,eAAe,CAAC;AAIpH,yFAAyF;AACzF,wBAAgB,OAAO,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,EAAE,IAAI,SAAe,GAAG,MAAM,GAAG,IAAI,CAOhG;AAED
|
|
1
|
+
{"version":3,"file":"antigravity-control.d.ts","sourceRoot":"","sources":["../../../src/adapters/antigravity-control.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAkC,KAAK,IAAI,EAAE,KAAK,OAAO,EAAE,KAAK,SAAS,EAAc,MAAM,eAAe,CAAC;AAIpH,yFAAyF;AACzF,wBAAgB,OAAO,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,EAAE,IAAI,SAAe,GAAG,MAAM,GAAG,IAAI,CAOhG;AAED;;;;;iBAKiB;AACjB,wBAAgB,YAAY,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM,EAAE,CAGtD;AAED;oBACoB;AACpB,eAAO,MAAM,aAAa,SAAU,IAA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CAAuB;IAEnC,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAa1B;IAED,OAAO,CAAC,GAAG,EAAE,SAAS,GAAG;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAiB9D;CACF;AAED,eAAO,MAAM,OAAO,QAAO,UAA8B,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type RunLevel, type StartPermission } from "../control/verify.js";
|
|
1
2
|
import { JOB_TIMEOUT_MS, type Login, type Mode, type RunOptions, type RunResult } from "./headless.js";
|
|
2
3
|
export { JOB_TIMEOUT_MS, type Login, type Mode, type RunResult };
|
|
3
4
|
/** Dotted versions by number, a missing part as 0: 1.9.0 < 1.10 = 1.10.0. */
|
|
@@ -15,10 +16,44 @@ export interface Caps {
|
|
|
15
16
|
stream?: boolean;
|
|
16
17
|
}
|
|
17
18
|
export declare function parseCaps(help: string): Caps;
|
|
18
|
-
/** Permission flags for
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
|
|
19
|
+
/** Permission flags for a level (a machine's mode is one: safe, auto, inherit). Read:
|
|
20
|
+
* plan mode. Safe: `dontAsk` (nothing that needs approval runs). Edits: acceptEdits.
|
|
21
|
+
* Auto: Claude Code's own auto mode. Inherit: none, so the turn starts in the mode
|
|
22
|
+
* Claude Code picks by itself here, its settings' `permissions.defaultMode` (a resume
|
|
23
|
+
* too: Claude Code never restores a session's earlier mode). A level this Claude Code
|
|
24
|
+
* has no mode for is a refusal, never another level. Never bypassPermissions — no path
|
|
25
|
+
* here writes it. */
|
|
26
|
+
export declare function modeFlags(level: RunLevel, caps: Caps): {
|
|
27
|
+
args: string[];
|
|
28
|
+
} | {
|
|
29
|
+
error: string;
|
|
30
|
+
};
|
|
31
|
+
/** The widest level a start may name on a machine in `mode`: the mode itself, and safe
|
|
32
|
+
* on an inherit machine, whose own default sessionpipe can't rank, so a message there may
|
|
33
|
+
* only narrow to a level that never runs anything needing approval. */
|
|
34
|
+
export declare const ceilingLevel: (mode: Mode) => StartPermission;
|
|
35
|
+
/** The levels a start may ask Claude Code for on a machine in `mode`: never above its
|
|
36
|
+
* ceiling, and each only where `claude --help` lists the mode it maps to (safe always). */
|
|
37
|
+
export declare function offeredLevels(mode: Mode, caps: Caps): StartPermission[];
|
|
38
|
+
/** What a start that names no level gets: what the machine's mode means for Claude Code. */
|
|
39
|
+
export declare const defaultLevel: (mode: Mode) => RunLevel;
|
|
40
|
+
/** How a headless run prints: streamed where this Claude Code can, else one JSON at the end. */
|
|
41
|
+
export declare function outputArgs(caps: {
|
|
42
|
+
stream?: boolean;
|
|
43
|
+
}): string[];
|
|
44
|
+
/** One headless `claude -p` run: a new session (`session`), or the next message of one
|
|
45
|
+
* (`resume`, optionally as a fork). The model is its own argument after `--model`, and
|
|
46
|
+
* a prompt that starts with a dash gets a leading space, so it is never read as a flag. */
|
|
47
|
+
export declare function claudeArgs(o: {
|
|
48
|
+
caps: Caps;
|
|
49
|
+
level: RunLevel;
|
|
50
|
+
prompt: string;
|
|
51
|
+
session?: string;
|
|
52
|
+
resume?: string;
|
|
53
|
+
fork?: boolean;
|
|
54
|
+
model?: string;
|
|
55
|
+
allowedTools?: string[];
|
|
56
|
+
}): {
|
|
22
57
|
args: string[];
|
|
23
58
|
} | {
|
|
24
59
|
error: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude-code-control.d.ts","sourceRoot":"","sources":["../../../src/adapters/claude-code-control.ts"],"names":[],"mappings":"AAYA,OAAO,EAEL,cAAc,EACd,KAAK,KAAK,EACV,KAAK,IAAI,EACT,KAAK,UAAU,EACf,KAAK,SAAS,EAEf,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,cAAc,EAAE,KAAK,KAAK,EAAE,KAAK,IAAI,EAAE,KAAK,SAAS,EAAE,CAAC;AAMjE,6EAA6E;AAC7E,eAAO,MAAM,UAAU,MAAO,MAAM,KAAK,MAAM,WAM9C,CAAC;AAEF;mEACmE;AACnE,wBAAgB,UAAU,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,EAAE,IAAI,SAAe,GAAG,MAAM,GAAG,IAAI,CA2BnG;AAcD,MAAM,WAAW,IAAI;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,WAAW,EAAE,OAAO,CAAC;IACrB,IAAI,EAAE,OAAO,CAAC;IACd;sFACkF;IAClF,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAU5C;AAED;;
|
|
1
|
+
{"version":3,"file":"claude-code-control.d.ts","sourceRoot":"","sources":["../../../src/adapters/claude-code-control.ts"],"names":[],"mappings":"AAYA,OAAO,EAAa,KAAK,QAAQ,EAAqB,KAAK,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACzG,OAAO,EAEL,cAAc,EACd,KAAK,KAAK,EACV,KAAK,IAAI,EACT,KAAK,UAAU,EACf,KAAK,SAAS,EAEf,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,cAAc,EAAE,KAAK,KAAK,EAAE,KAAK,IAAI,EAAE,KAAK,SAAS,EAAE,CAAC;AAMjE,6EAA6E;AAC7E,eAAO,MAAM,UAAU,MAAO,MAAM,KAAK,MAAM,WAM9C,CAAC;AAEF;mEACmE;AACnE,wBAAgB,UAAU,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,EAAE,IAAI,SAAe,GAAG,MAAM,GAAG,IAAI,CA2BnG;AAcD,MAAM,WAAW,IAAI;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,WAAW,EAAE,OAAO,CAAC;IACrB,IAAI,EAAE,OAAO,CAAC;IACd;sFACkF;IAClF,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,wBA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AW,YAAY;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,kBAAkB,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,OAAO,CAAA;KAAE,EAAE,CAAC;CAChD;AAED,8FAA8F;AAC9F,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,YAAY,GAAG,IAAI,CAqBlF;AAED,eAAO,MAAM,MAAM,MAAO,OAAO,KAAG,CAAC,IAAI,MAAkD,CAAC"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { DataOf } from "../types.js";
|
|
2
|
+
export type LimitWindow = DataOf<"limits.observed">["windows"][number];
|
|
3
|
+
/** Claude Code 2.1.312's own prod endpoints. bb signs in at claude.ai/oauth/authorize with
|
|
4
|
+
* console.anthropic.com's callback and token URL, which still answer; the paste-back code
|
|
5
|
+
* works the same at either. */
|
|
6
|
+
export declare const POOL_ENDPOINTS: {
|
|
7
|
+
readonly authorize: "https://claude.com/cai/oauth/authorize";
|
|
8
|
+
readonly token: "https://platform.claude.com/v1/oauth/token";
|
|
9
|
+
readonly callback: "https://platform.claude.com/oauth/code/callback";
|
|
10
|
+
readonly profile: "https://api.anthropic.com/api/oauth/profile";
|
|
11
|
+
readonly usage: "https://api.anthropic.com/api/oauth/usage";
|
|
12
|
+
readonly api: "https://api.anthropic.com";
|
|
13
|
+
readonly clientId: "9d1c250a-e61b-44d9-88ed-5944d1962f5e";
|
|
14
|
+
readonly scopes: readonly ["user:inference", "user:profile", "org:create_api_key", "user:sessions:claude_code", "user:mcp_servers", "user:file_upload"];
|
|
15
|
+
readonly beta: "oauth-2025-04-20";
|
|
16
|
+
};
|
|
17
|
+
export interface PoolCredential {
|
|
18
|
+
access: string;
|
|
19
|
+
refresh: string;
|
|
20
|
+
/** Epoch milliseconds. */
|
|
21
|
+
expires_at: number;
|
|
22
|
+
}
|
|
23
|
+
export type PoolStatus = "allowed" | "allowed_warning" | "rejected";
|
|
24
|
+
export interface PoolLimits {
|
|
25
|
+
windows: LimitWindow[];
|
|
26
|
+
/** The account as a whole. */
|
|
27
|
+
status?: PoolStatus;
|
|
28
|
+
/** On a refusal: the window that refused (`five_hour`, `seven_day`, …) and when it resets. */
|
|
29
|
+
claim?: string;
|
|
30
|
+
resets_at?: string;
|
|
31
|
+
observed_at: number;
|
|
32
|
+
}
|
|
33
|
+
export interface PoolProfile {
|
|
34
|
+
account_uuid: string;
|
|
35
|
+
email: string;
|
|
36
|
+
org?: string;
|
|
37
|
+
plan?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface ImportableLogin {
|
|
40
|
+
/** The Claude Code config dir the login belongs to. */
|
|
41
|
+
dir: string;
|
|
42
|
+
credential: PoolCredential;
|
|
43
|
+
/** From the dir's .claude.json; absent when that file has no login (fetchProfile fills it). */
|
|
44
|
+
account_uuid?: string;
|
|
45
|
+
email?: string;
|
|
46
|
+
source: "keychain" | "file";
|
|
47
|
+
}
|
|
48
|
+
/** The person has to sign in (again): a refused code, a dead refresh token, a 401. */
|
|
49
|
+
export declare class PoolAuthError extends Error {
|
|
50
|
+
}
|
|
51
|
+
/** Anthropic did not answer properly right now; the same call may work in a minute. */
|
|
52
|
+
export declare class PoolUpstreamError extends Error {
|
|
53
|
+
}
|
|
54
|
+
type HeaderBag = Headers | Record<string, string | string[] | undefined>;
|
|
55
|
+
/** The account's limits from a response's headers; null when the limiter did not run
|
|
56
|
+
* (no `anthropic-ratelimit-unified-*` header at all). A window needs a readable
|
|
57
|
+
* utilization; a status or a reset alone is kept on the account. */
|
|
58
|
+
export declare function readLimits(headers: HeaderBag, now: number): PoolLimits | null;
|
|
59
|
+
/** The usage endpoint's JSON: `{five_hour: {utilization, resets_at}, seven_day: {…},
|
|
60
|
+
* seven_day_<model>: {…}, …}`, utilization a percent already. Any other key shaped
|
|
61
|
+
* like a window passes through under its own id; null when none is. */
|
|
62
|
+
export declare function usageLimits(json: unknown, now: number): PoolLimits | null;
|
|
63
|
+
/** `metadata.user_id` of a request body (parsed, or the raw bytes): the session to pin
|
|
64
|
+
* on and the account the body claims. null when the body carries none. */
|
|
65
|
+
export declare function parseUserId(body: unknown): {
|
|
66
|
+
session?: string;
|
|
67
|
+
account?: string;
|
|
68
|
+
} | null;
|
|
69
|
+
/** The body with the account part of `metadata.user_id` set to `accountUuid`, the same
|
|
70
|
+
* bytes when there is nothing to rewrite. Done on the string, not a parse/stringify
|
|
71
|
+
* round trip: Claude Code's bodies are JSON.stringify output and would survive one, but
|
|
72
|
+
* a body a person built by hand (an SDK, a `CLAUDE_CODE_EXTRA_BODY`) can carry number
|
|
73
|
+
* forms and escapes a round trip rewrites, and a prompt cache is keyed on bytes. The
|
|
74
|
+
* only change is the UUID inside that one string literal. */
|
|
75
|
+
export declare function withAccount(body: Buffer, accountUuid: string): Buffer;
|
|
76
|
+
/** The request's headers as they go to Anthropic: the serving account's bearer in place
|
|
77
|
+
* of the pool's own token, the OAuth beta present, hop-by-hop and the ones the sender
|
|
78
|
+
* sets (host, content-length) gone. Our token and any x-api-key never go through. */
|
|
79
|
+
export declare function upstreamHeaders(req: Record<string, string | string[] | undefined>, access: string): Record<string, string>;
|
|
80
|
+
/** PKCE, as Claude Code builds its own sign-in URL (the same parameters in the same
|
|
81
|
+
* order; `code=true` asks for the paste-back page). 32 random bytes base64url is a
|
|
82
|
+
* 43-character verifier, inside RFC 7636's 43–128. */
|
|
83
|
+
export declare function beginLogin(random?: (n: number) => Buffer): {
|
|
84
|
+
url: string;
|
|
85
|
+
verifier: string;
|
|
86
|
+
state: string;
|
|
87
|
+
};
|
|
88
|
+
type Fetch = typeof globalThis.fetch;
|
|
89
|
+
/** Exchange the pasted code for a credential and read whose it is. */
|
|
90
|
+
export declare function completeLogin(code: string, pending: {
|
|
91
|
+
verifier: string;
|
|
92
|
+
state: string;
|
|
93
|
+
}, fetch: Fetch, now: () => number): Promise<{
|
|
94
|
+
credential: PoolCredential;
|
|
95
|
+
profile: PoolProfile;
|
|
96
|
+
}>;
|
|
97
|
+
/** A fresh access token. 400/401 means the refresh token is dead (revoked, expired,
|
|
98
|
+
* used elsewhere): the person signs in again. Anything else is Anthropic's moment. */
|
|
99
|
+
export declare function refreshCredential(cred: PoolCredential, fetch: Fetch, now: () => number): Promise<PoolCredential>;
|
|
100
|
+
/** Whose token this is: `{account: {uuid, email, …}, organization: {name, …}}`. */
|
|
101
|
+
export declare function fetchProfile(access: string, fetch: Fetch): Promise<PoolProfile>;
|
|
102
|
+
/** The account's windows from the usage endpoint; null when it reports none. */
|
|
103
|
+
export declare function fetchUsage(access: string, fetch: Fetch, now: () => number): Promise<PoolLimits | null>;
|
|
104
|
+
/** The keychain service Claude Code keeps a config dir's login under: bare for the
|
|
105
|
+
* default dir, suffixed with 8 hex of sha256(dir) when CLAUDE_CONFIG_DIR names one. */
|
|
106
|
+
export declare function keychainService(dir: string, home: string, platform?: NodeJS.Platform): string;
|
|
107
|
+
type ReadFile = (file: string) => string;
|
|
108
|
+
/** Every Claude Code login on this machine the pool could copy, one per config dir
|
|
109
|
+
* (claudeDirs): the credential from the keychain (macOS) or `.credentials.json`, and
|
|
110
|
+
* who it is from the dir's .claude.json. `exec` runs `security` and returns stdout; it
|
|
111
|
+
* is the only thing that touches the keychain, so a test hands in a fake. Returns []
|
|
112
|
+
* on any failure and never throws: an import that finds nothing is a message, not a
|
|
113
|
+
* crash, and a token never reaches a log through here. */
|
|
114
|
+
export declare function importableLogins(env: NodeJS.ProcessEnv, exec: (cmd: string, args: string[]) => string, readFile?: ReadFile, platform?: NodeJS.Platform): ImportableLogin[];
|
|
115
|
+
export {};
|
|
116
|
+
//# sourceMappingURL=claude-code-pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-code-pool.d.ts","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,QAAQ,GAAE,QAAmB,EAC7B,QAAQ,GAAE,MAAM,CAAC,QAA2B,GAC3C,eAAe,EAAE,CA+BnB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { HarnessAccount } from "../types.js";
|
|
1
|
+
import type { DataOf, HarnessAccount } from "../types.js";
|
|
2
2
|
import type { Adapter, FactsState, SessionFacts } from "./types.js";
|
|
3
3
|
export declare const CLAUDE_EVENTS: readonly ["SessionStart", "UserPromptSubmit", "PreToolUse", "PostToolUse", "PostToolUseFailure", "PermissionRequest", "Notification", "Stop", "SubagentStart", "SubagentStop", "PreCompact", "PostCompact", "SessionEnd", "StopFailure"];
|
|
4
4
|
/** Every Claude Code config dir on this machine. `home` follows the env's HOME, so a
|
|
@@ -6,6 +6,11 @@ export declare const CLAUDE_EVENTS: readonly ["SessionStart", "UserPromptSubmit"
|
|
|
6
6
|
* once rewrote a real settings.json with its fake hook paths on every run. */
|
|
7
7
|
export declare function claudeDirs(env?: NodeJS.ProcessEnv, home?: string): string[];
|
|
8
8
|
export declare const claudeCode: Adapter;
|
|
9
|
+
/** The status line's `rate_limits`: `five_hour`, `seven_day` and, behind a gateway,
|
|
10
|
+
* `spend_limit`, each with `used_percentage` and `resets_at` in epoch seconds. Only
|
|
11
|
+
* Pro and Max accounts (or a gateway) have them, and only after a session's first
|
|
12
|
+
* response; a window drops out once it resets. */
|
|
13
|
+
export declare function claudeLimits(rl: unknown): DataOf<"limits.observed"> | null;
|
|
9
14
|
/** Another harness reading this settings file, not Claude Code. Several harnesses
|
|
10
15
|
* import `~/.claude/settings.json` hooks, so our entries there can be run by a tool
|
|
11
16
|
* that has its own adapter: it would arrive under the wrong name, with ids that mean
|
|
@@ -25,6 +30,20 @@ export declare function appTitle(text: string): string;
|
|
|
25
30
|
* name or custom-title) → Claude Code's own title (registry "auto" name or
|
|
26
31
|
* ai-title) → the first ask, marked first-ask so a real title later replaces it. */
|
|
27
32
|
export declare function claudeFacts(file: string, sessionId: string, hints: Record<string, unknown>, state: FactsState): SessionFacts;
|
|
33
|
+
/** claude.ai's name for a session with a claude.ai link, unless the person named it
|
|
34
|
+
* here: `{title, title_source: "harness"}`, or nothing. */
|
|
35
|
+
export declare function claudeRemoteFacts(id: string, local: SessionFacts, transcript: string | undefined, state: FactsState, env: NodeJS.ProcessEnv, now?: number): Promise<Partial<SessionFacts>>;
|
|
36
|
+
/** The access token Claude Code signed in to `dir` with: from the macOS keychain, else
|
|
37
|
+
* from `<dir>/.credentials.json`. Never written anywhere, never logged. One that has
|
|
38
|
+
* expired is not refreshed, since that would rotate Claude Code's own login: the lookup
|
|
39
|
+
* waits for Claude Code to refresh it. */
|
|
40
|
+
export declare function claudeAiToken(dir: string, env: NodeJS.ProcessEnv, now: number): string | null;
|
|
41
|
+
/** claude.ai's name for the session `bridge` (`session_…`), from the endpoint Claude Code
|
|
42
|
+
* reads a session from: a string, null when it has none yet, undefined when it couldn't
|
|
43
|
+
* be asked or wouldn't say (offline, a 401 or 404, an answer about another session), so
|
|
44
|
+
* the last answer stands. The token goes to api.anthropic.com alone: a redirect is
|
|
45
|
+
* refused, never followed. */
|
|
46
|
+
export declare function claudeAiTitle(bridge: string, token: string): Promise<string | null | undefined>;
|
|
28
47
|
/** For tests: each hook runs in a fresh process; a test that edits the registry mid-run clears the cache. */
|
|
29
48
|
export declare const _resetClaudeCaches: () => void;
|
|
30
49
|
//# sourceMappingURL=claude-code.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude-code.d.ts","sourceRoot":"","sources":["../../../src/adapters/claude-code.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"claude-code.d.ts","sourceRoot":"","sources":["../../../src/adapters/claude-code.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAU1D,OAAO,KAAK,EACV,OAAO,EAEP,UAAU,EAMV,YAAY,EACb,MAAM,YAAY,CAAC;AAGpB,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AAU,EACjB,GAAG,EAAE,MAAM,CAAC,UAAU,EACtB,GAAG,SAAa,GACf,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAehC;AAmBD;;;2CAG2C;AAC3C,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAwC7F;AAMD;;;;+BAI+B;AAC/B,wBAAsB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAqBrG;AAED,6GAA6G;AAC7G,eAAO,MAAM,kBAAkB,QAAO,IAIrC,CAAC"}
|
|
@@ -26,6 +26,7 @@ export type JsonFile = {
|
|
|
26
26
|
indent: string;
|
|
27
27
|
eol: string;
|
|
28
28
|
finalNewline: boolean;
|
|
29
|
+
bom: boolean;
|
|
29
30
|
} | {
|
|
30
31
|
ok: true;
|
|
31
32
|
existed: false;
|
|
@@ -34,6 +35,7 @@ export type JsonFile = {
|
|
|
34
35
|
indent: " ";
|
|
35
36
|
eol: "\n";
|
|
36
37
|
finalNewline: true;
|
|
38
|
+
bom: false;
|
|
37
39
|
} | {
|
|
38
40
|
ok: false;
|
|
39
41
|
existed: true;
|
|
@@ -47,6 +49,7 @@ export declare function formatJson(value: unknown, f: {
|
|
|
47
49
|
indent: string;
|
|
48
50
|
eol: string;
|
|
49
51
|
finalNewline: boolean;
|
|
52
|
+
bom?: boolean;
|
|
50
53
|
}): string;
|
|
51
54
|
/** Back-compat helper for callers that only read. */
|
|
52
55
|
export declare function readJson(file: string): Record<string, unknown>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude-shaped.d.ts","sourceRoot":"","sources":["../../../src/adapters/claude-shaped.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM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ACvE,MAAM,CAGR;AAED,qDAAqD;AACrD,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAG9D;AAUD,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,GAAG,EAAE,WAAW,EAChB,CAAC,EAAE,mBAAmB,GACrB,aAAa,CAyCf;AAED,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,IAAI,GAAE;IAAE,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CAAO,GAC3C,aAAa,CAyBf;AAED,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,GAAG,EAAE,WAAW,EAChB,CAAC,EAAE,mBAAmB,GACrB,SAAS,GAAG,OAAO,GAAG,SAAS,CAiBjC"}
|
|
@@ -13,7 +13,8 @@ export interface Notify {
|
|
|
13
13
|
}
|
|
14
14
|
/** notify as Codex sees it; `misplaced` for a line of ours inside a table. */
|
|
15
15
|
export declare function readNotify(text: string): Notify | null;
|
|
16
|
-
/** Put `line` at the top level: before the first table, or at the end of a file that has
|
|
16
|
+
/** Put `line` at the top level: before the first table, or at the end of a file that has
|
|
17
|
+
* none. The line takes the file's own line end, so a CRLF file stays one. */
|
|
17
18
|
export declare function insertTopLevel(text: string, line: string): string;
|
|
18
19
|
/** The config with `line` as its notify, for a config whose notify is ours or absent. */
|
|
19
20
|
export declare function withNotify(text: string, line: string): string;
|