@scopebond/agent 0.4.6 → 0.5.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.
Files changed (69) hide show
  1. package/README.md +35 -6
  2. package/dist/agent.d.ts +2 -0
  3. package/dist/agent.d.ts.map +1 -1
  4. package/dist/agent.js +4 -4
  5. package/dist/agent.js.map +1 -1
  6. package/dist/allowance-sender.d.ts +8 -0
  7. package/dist/allowance-sender.d.ts.map +1 -0
  8. package/dist/allowance-sender.js +80 -0
  9. package/dist/allowance-sender.js.map +1 -0
  10. package/dist/autostart.d.ts +13 -0
  11. package/dist/autostart.d.ts.map +1 -1
  12. package/dist/autostart.js +60 -10
  13. package/dist/autostart.js.map +1 -1
  14. package/dist/cli-main.d.ts +3 -0
  15. package/dist/cli-main.d.ts.map +1 -0
  16. package/dist/cli-main.js +218 -0
  17. package/dist/cli-main.js.map +1 -0
  18. package/dist/cli.js +4 -185
  19. package/dist/cli.js.map +1 -1
  20. package/dist/index.d.ts +7 -3
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +5 -3
  23. package/dist/index.js.map +1 -1
  24. package/dist/ipc.d.ts +7 -1
  25. package/dist/ipc.d.ts.map +1 -1
  26. package/dist/ipc.js +64 -12
  27. package/dist/ipc.js.map +1 -1
  28. package/dist/log-file.d.ts +6 -0
  29. package/dist/log-file.d.ts.map +1 -0
  30. package/dist/log-file.js +40 -0
  31. package/dist/log-file.js.map +1 -0
  32. package/dist/native-update.d.ts +51 -0
  33. package/dist/native-update.d.ts.map +1 -0
  34. package/dist/native-update.js +120 -0
  35. package/dist/native-update.js.map +1 -0
  36. package/dist/prompt.d.ts +11 -1
  37. package/dist/prompt.d.ts.map +1 -1
  38. package/dist/prompt.js +57 -23
  39. package/dist/prompt.js.map +1 -1
  40. package/dist/reconnect.d.ts +19 -0
  41. package/dist/reconnect.d.ts.map +1 -0
  42. package/dist/reconnect.js +60 -0
  43. package/dist/reconnect.js.map +1 -0
  44. package/dist/self.d.ts +5 -0
  45. package/dist/self.d.ts.map +1 -0
  46. package/dist/self.js +15 -0
  47. package/dist/self.js.map +1 -0
  48. package/dist/service.d.ts +50 -4
  49. package/dist/service.d.ts.map +1 -1
  50. package/dist/service.js +292 -18
  51. package/dist/service.js.map +1 -1
  52. package/dist/setup.d.ts.map +1 -1
  53. package/dist/setup.js +4 -9
  54. package/dist/setup.js.map +1 -1
  55. package/dist/summary.d.ts +16 -0
  56. package/dist/summary.d.ts.map +1 -0
  57. package/dist/summary.js +47 -0
  58. package/dist/summary.js.map +1 -0
  59. package/dist/tray-model.d.ts +91 -0
  60. package/dist/tray-model.d.ts.map +1 -0
  61. package/dist/tray-model.js +159 -0
  62. package/dist/tray-model.js.map +1 -0
  63. package/dist/tray.d.ts.map +1 -1
  64. package/dist/tray.js +103 -29
  65. package/dist/tray.js.map +1 -1
  66. package/dist/update.d.ts.map +1 -1
  67. package/dist/update.js +7 -4
  68. package/dist/update.js.map +1 -1
  69. package/package.json +4 -4
@@ -0,0 +1,218 @@
1
+ // scopebond-agent: run, look at and control the Scopebond Agent for this user.
2
+ //
3
+ // scopebond-agent setup <workspace-url> [--claude|--cursor|--codex] [--relogin]
4
+ // one command to start: sign in, install, autostart, status
5
+ // scopebond-agent run run in the foreground (what autostart starts)
6
+ // scopebond-agent status [--json] what the running agent reports, or why it is not running
7
+ // scopebond-agent flush deliver now
8
+ // scopebond-agent repair put the Scopebond hook back where agent settings lost it
9
+ // scopebond-agent check update check, hook upkeep and the end-to-end self-check, now
10
+ // scopebond-agent autostart on|off start with this user's sign-in, or stop doing so (off also stops it now)
11
+ // scopebond-agent stop stop the running agent (autostart still starts it at the next sign-in)
12
+ // scopebond-agent uninstall [--purge] autostart off, stop, the hook's uninstall (tells the workspace); what the installer runs
13
+ import { spawnSync } from "node:child_process";
14
+ import { homedir } from "node:os";
15
+ import { hookSelfCommand, isEphemeralPath, userHome } from "@scopebond/hook";
16
+ import { computerStatus } from "./agent.js";
17
+ import { AGENT_LOG_ENV, autostartHealth, disableAutostart, enableAutostart, startNow } from "./autostart.js";
18
+ import { callAgent } from "./ipc.js";
19
+ import { agentCliPath } from "./self.js";
20
+ import { runSetup } from "./setup.js";
21
+ import { agentVersion } from "./update.js";
22
+ import { writeOutputTo } from "./log-file.js";
23
+ import { AGENT_VERSION, startService, takeOver } from "./service.js";
24
+ let cmd = "help";
25
+ let rest = [];
26
+ // What a person types here: on Windows, PowerShell blocks the plain name's script shim.
27
+ const me = process.platform === "win32" ? "scopebond-agent.cmd" : "scopebond-agent";
28
+ const dir = process.env.SCOPEBOND_HOME ?? userHome();
29
+ function help() {
30
+ const c = (sub) => `${me} ${sub}`.padEnd(me.length + 36);
31
+ console.log(`Scopebond Agent — keeps this computer delivering to its Scopebond workspace.
32
+
33
+ ${c("setup <workspace-url>")}sign in, install for this user, start with sign-in, show status
34
+ ${c("run")}run in the foreground (what autostart starts)
35
+ ${c("status [--json]")}what the agent reports about this computer
36
+ ${c("flush")}deliver waiting records now
37
+ ${c("repair")}put the Scopebond hook back where agent settings lost it
38
+ ${c("check")}check for updates and run the end-to-end self-check now
39
+ ${c("autostart on|off")}start with your sign-in, or stop doing so (off also stops it now)
40
+ ${c("stop")}stop the running agent until the next sign-in
41
+ ${c("uninstall [--purge]")}stop it, stop starting it, take the hook out and tell the workspace
42
+
43
+ The hook keeps deciding every action on its own; the agent only keeps delivery, rules and the
44
+ connection current. Home: ${dir}`);
45
+ }
46
+ /** Run one command (`argv` as after the program name). cli.ts, the npm program, calls this; so does the single executable. */
47
+ export async function main(argv = process.argv.slice(2)) {
48
+ [cmd = "help", ...rest] = argv;
49
+ switch (cmd) {
50
+ case "run": {
51
+ // A launcher or a handover names the log; the agent writes it itself (see log-file.ts).
52
+ const log = process.env[AGENT_LOG_ENV];
53
+ if (log)
54
+ writeOutputTo(log);
55
+ // Started by an agent that just updated itself: let it exit first.
56
+ await takeOver(dir, agentCliPath());
57
+ const service = await startService({ dir, onStopped: () => process.exit(0) });
58
+ const stop = () => { void service.stop().finally(() => process.exit(0)); };
59
+ process.on("SIGINT", stop);
60
+ process.on("SIGTERM", stop);
61
+ return;
62
+ }
63
+ case "status": {
64
+ const live = await callAgent(dir, "GET", "/status");
65
+ const status = { ...(live ?? { ...computerStatus(dir), agent: null }), autostart: autostartHealth(dir) };
66
+ if (rest.includes("--json")) {
67
+ console.log(JSON.stringify(status, null, 2));
68
+ return;
69
+ }
70
+ const d = status.delivery;
71
+ console.log(`Scopebond Agent: ${live ? "running" : "not running"}`);
72
+ console.log(` state ${live ? status.state : "not running: records wait on this computer until it runs"}`);
73
+ console.log(` connected ${d.connected ? "yes" : "no"}`);
74
+ console.log(` waiting to send ${d.pending} record(s)${d.oldest_pending_age_s !== null ? `, oldest ${Math.round(d.oldest_pending_age_s / 60)} min` : ""}`);
75
+ if (d.last_error)
76
+ console.log(` last problem ${d.last_error}`);
77
+ console.log(` version ${status.agent?.version ?? AGENT_VERSION}`);
78
+ console.log(` autostart ${status.autostart.detail}`);
79
+ const check = status.agent?.last_maintenance?.selfCheck;
80
+ if (check)
81
+ console.log(` self-check ${check.ok ? "passed" : `failed: ${check.failed.join(", ")}`}`);
82
+ if (!live)
83
+ console.log(`\nStart it with: ${me} autostart on`);
84
+ return;
85
+ }
86
+ case "flush":
87
+ case "repair":
88
+ case "check": {
89
+ const answer = await callAgent(dir, "POST", `/${cmd === "check" ? "maintain" : cmd}`, {}, 6 * 60_000);
90
+ if (!answer) {
91
+ console.error(`The Scopebond Agent is not running. Start it with: ${me} autostart on`);
92
+ process.exitCode = 1;
93
+ return;
94
+ }
95
+ console.log(JSON.stringify(answer, null, 2));
96
+ const updatedTo = answer.updatedTo;
97
+ if (cmd === "check" && typeof updatedTo === "string")
98
+ console.log(await afterUpdate(updatedTo));
99
+ return;
100
+ }
101
+ case "setup": {
102
+ const target = rest.find((a) => !a.startsWith("--"));
103
+ let origin = null;
104
+ try {
105
+ const url = new URL(target ?? "");
106
+ const local = ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
107
+ if (url.protocol === "https:" || (local && url.protocol === "http:"))
108
+ origin = url.origin;
109
+ }
110
+ catch {
111
+ origin = null;
112
+ }
113
+ if (!origin) {
114
+ console.error(`usage: ${process.platform === "win32" ? "npx.cmd" : "npx"} -y @scopebond/agent@${agentVersion()} setup <workspace-url> [--claude|--cursor|--codex]`);
115
+ console.error("The workspace URL is the address of your Scopebond workspace, for example https://cloud.scopebond.com.");
116
+ process.exitCode = 1;
117
+ return;
118
+ }
119
+ const harness = rest.includes("--cursor") ? "cursor" : rest.includes("--codex") ? "codex" : "claude";
120
+ process.exitCode = await runSetup({ dir, origin, harness, relogin: rest.includes("--relogin"), version: agentVersion(), me });
121
+ return;
122
+ }
123
+ case "stop": {
124
+ console.log(await stopRunning() ? "Stopped the Scopebond Agent." : "The Scopebond Agent was not running.");
125
+ return;
126
+ }
127
+ case "uninstall": {
128
+ // What the Windows installer runs when Scopebond is removed (and anyone may run): stop and unregister the agent,
129
+ // then the hook's own uninstall, which tells the workspace and takes the hook out of the coding agents' settings.
130
+ // The Scopebond folder (keys, receipts) stays unless --purge.
131
+ console.log(disableAutostart(dir));
132
+ if (await stopRunning())
133
+ console.log("Stopped the running Scopebond Agent.");
134
+ const [program, args] = hookSelfCommand(["uninstall", "--yes", ...(rest.includes("--purge") ? ["--purge"] : [])]);
135
+ const removal = spawnSync(program, args, { stdio: "inherit", cwd: homedir(), env: { ...process.env, SCOPEBOND_HOME: dir } });
136
+ process.exitCode = removal.status ?? 1;
137
+ return;
138
+ }
139
+ case "autostart": {
140
+ const on = rest[0] === "on";
141
+ if (rest[0] !== "on" && rest[0] !== "off") {
142
+ console.error(`usage: ${me} autostart on|off`);
143
+ process.exitCode = 1;
144
+ return;
145
+ }
146
+ if (on && isEphemeralPath(agentCliPath())) {
147
+ // npx runs from a cache npm clears; an autostart entry pointing there would stop working.
148
+ console.error(`Install the agent first so autostart has a stable path: ${process.platform === "win32" ? "npm.cmd" : "npm"} install -g @scopebond/agent`);
149
+ process.exitCode = 1;
150
+ return;
151
+ }
152
+ console.log(on ? enableAutostart(dir, agentCliPath()) : disableAutostart(dir));
153
+ if (!on) {
154
+ // Off means off: an agent left running would keep going until sign-out, even after an uninstall.
155
+ if (await stopRunning())
156
+ console.log("Stopped the running Scopebond Agent.");
157
+ return;
158
+ }
159
+ // Turning autostart on also starts the agent now, so nobody has to sign out and in again.
160
+ if (await callAgent(dir, "GET", "/status", undefined, 2_000)) {
161
+ console.log("The Scopebond Agent is running.");
162
+ return;
163
+ }
164
+ if (await startAndWait()) {
165
+ console.log(`The Scopebond Agent is running${process.platform === "win32" ? "; its icon is in the taskbar tray (it may be under the ^ arrow)" : ""}.`);
166
+ return;
167
+ }
168
+ console.log(`It starts at your next sign-in. To start it now: ${me} run`);
169
+ return;
170
+ }
171
+ default:
172
+ help();
173
+ if (cmd !== "help" && cmd !== "--help")
174
+ process.exitCode = 1;
175
+ }
176
+ }
177
+ /** Start the agent through its autostart launcher and wait until it answers. Each way of starting it gets a few seconds;
178
+ * a headless console that never starts falls back to a hidden cmd.exe. Whether it answers. */
179
+ async function startAndWait() {
180
+ for (let attempt = 0; attempt < 2; attempt++) {
181
+ if (!startNow(dir, process.platform, attempt) && attempt > 0)
182
+ break;
183
+ for (let i = 0; i < (attempt === 0 ? 12 : 18); i++) {
184
+ await new Promise((r) => setTimeout(r, 500));
185
+ if (await callAgent(dir, "GET", "/status", undefined, 1_000))
186
+ return true;
187
+ }
188
+ }
189
+ return false;
190
+ }
191
+ /** After `check` updated the agent: wait for the updated one to answer, start it if nothing does, and say which version runs. */
192
+ async function afterUpdate(version) {
193
+ const running = async () => (await callAgent(dir, "GET", "/status", undefined, 1_000))?.agent?.version ?? null;
194
+ let seen = null;
195
+ for (let i = 0; i < 60; i++) {
196
+ await new Promise((r) => setTimeout(r, 1_000));
197
+ seen = await running();
198
+ if (seen === `agent/${version}`)
199
+ return `The Scopebond Agent ${version} is running.`;
200
+ }
201
+ if (seen)
202
+ return `The Scopebond Agent running now is ${seen.replace(/^agent\//, "")}, not ${version}. Restart it with: ${me} stop, then ${me} autostart on`;
203
+ if (autostartHealth(dir).on && await startAndWait())
204
+ return "The updated agent had not started; it is running now.";
205
+ return `The updated agent is not running. Start it with: ${me} autostart on`;
206
+ }
207
+ /** Ask the running agent to stop and wait until its control channel is gone. Whether one was running. */
208
+ async function stopRunning() {
209
+ if (!await callAgent(dir, "POST", "/stop", {}, 3_000))
210
+ return false;
211
+ for (let i = 0; i < 40; i++) {
212
+ await new Promise((r) => setTimeout(r, 250));
213
+ if (!await callAgent(dir, "GET", "/status", undefined, 1_000))
214
+ return true;
215
+ }
216
+ return true;
217
+ }
218
+ //# sourceMappingURL=cli-main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli-main.js","sourceRoot":"","sources":["../src/cli-main.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,EAAE;AACF,kFAAkF;AAClF,kGAAkG;AAClG,sFAAsF;AACtF,iGAAiG;AACjG,oDAAoD;AACpD,iGAAiG;AACjG,qGAAqG;AACrG,iHAAiH;AACjH,+GAA+G;AAC/G,iIAAiI;AAEjI,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,gBAAgB,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC7G,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3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AAe,CAAC;AAC/E,CAAC;AAED,yGAAyG;AACzG,KAAK,UAAU,WAAW;IACxB,IAAI,CAAC,MAAM,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACpE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5B,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;QAC7C,IAAI,CAAC,MAAM,SAAS,CAAC,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;IAC7E,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["// scopebond-agent: run, look at and control the Scopebond Agent for this user.\n//\n// scopebond-agent setup <workspace-url> [--claude|--cursor|--codex] [--relogin]\n// one command to start: sign in, install, autostart, status\n// scopebond-agent run run in the foreground (what autostart starts)\n// scopebond-agent status [--json] what the running agent reports, or why it is not running\n// scopebond-agent flush deliver now\n// scopebond-agent repair put the Scopebond hook back where agent settings lost it\n// scopebond-agent check update check, hook upkeep and the end-to-end self-check, now\n// scopebond-agent autostart on|off start with this user's sign-in, or stop doing so (off also stops it now)\n// scopebond-agent stop stop the running agent (autostart still starts it at the next sign-in)\n// scopebond-agent uninstall [--purge] autostart off, stop, the hook's uninstall (tells the workspace); what the installer runs\n\nimport { spawnSync } from \"node:child_process\";\nimport { homedir } from \"node:os\";\nimport { hookSelfCommand, isEphemeralPath, userHome } from \"@scopebond/hook\";\nimport { computerStatus } from \"./agent.js\";\nimport { AGENT_LOG_ENV, autostartHealth, disableAutostart, enableAutostart, startNow } from \"./autostart.js\";\nimport { callAgent } from \"./ipc.js\";\nimport { agentCliPath } from \"./self.js\";\nimport { runSetup } from \"./setup.js\";\nimport { agentVersion } from \"./update.js\";\nimport { writeOutputTo } from \"./log-file.js\";\nimport { AGENT_VERSION, startService, takeOver } from \"./service.js\";\n\nlet cmd = \"help\";\nlet rest: string[] = [];\n// What a person types here: on Windows, PowerShell blocks the plain name's script shim.\nconst me = process.platform === \"win32\" ? \"scopebond-agent.cmd\" : \"scopebond-agent\";\nconst dir = process.env.SCOPEBOND_HOME ?? userHome();\n\nfunction help(): void {\n const c = (sub: string) => `${me} ${sub}`.padEnd(me.length + 36);\n console.log(`Scopebond Agent — keeps this computer delivering to its Scopebond workspace.\n\n ${c(\"setup <workspace-url>\")}sign in, install for this user, start with sign-in, show status\n ${c(\"run\")}run in the foreground (what autostart starts)\n ${c(\"status [--json]\")}what the agent reports about this computer\n ${c(\"flush\")}deliver waiting records now\n ${c(\"repair\")}put the Scopebond hook back where agent settings lost it\n ${c(\"check\")}check for updates and run the end-to-end self-check now\n ${c(\"autostart on|off\")}start with your sign-in, or stop doing so (off also stops it now)\n ${c(\"stop\")}stop the running agent until the next sign-in\n ${c(\"uninstall [--purge]\")}stop it, stop starting it, take the hook out and tell the workspace\n\nThe hook keeps deciding every action on its own; the agent only keeps delivery, rules and the\nconnection current. Home: ${dir}`);\n}\n\n/** Run one command (`argv` as after the program name). cli.ts, the npm program, calls this; so does the single executable. */\nexport async function main(argv: string[] = process.argv.slice(2)): Promise<void> {\n [cmd = \"help\", ...rest] = argv;\n switch (cmd) {\n case \"run\": {\n // A launcher or a handover names the log; the agent writes it itself (see log-file.ts).\n const log = process.env[AGENT_LOG_ENV];\n if (log) writeOutputTo(log);\n // Started by an agent that just updated itself: let it exit first.\n await takeOver(dir, agentCliPath());\n const service = await startService({ dir, onStopped: () => process.exit(0) });\n const stop = () => { void service.stop().finally(() => process.exit(0)); };\n process.on(\"SIGINT\", stop);\n process.on(\"SIGTERM\", stop);\n return;\n }\n case \"status\": {\n const live = await callAgent(dir, \"GET\", \"/status\") as (ReturnType<typeof computerStatus> & { agent?: AgentReport | null }) | null;\n const status = { ...(live ?? { ...computerStatus(dir), agent: null }), autostart: autostartHealth(dir) };\n if (rest.includes(\"--json\")) { console.log(JSON.stringify(status, null, 2)); return; }\n const d = status.delivery;\n console.log(`Scopebond Agent: ${live ? \"running\" : \"not running\"}`);\n console.log(` state ${live ? status.state : \"not running: records wait on this computer until it runs\"}`);\n console.log(` connected ${d.connected ? \"yes\" : \"no\"}`);\n console.log(` waiting to send ${d.pending} record(s)${d.oldest_pending_age_s !== null ? `, oldest ${Math.round(d.oldest_pending_age_s / 60)} min` : \"\"}`);\n if (d.last_error) console.log(` last problem ${d.last_error}`);\n console.log(` version ${status.agent?.version ?? AGENT_VERSION}`);\n console.log(` autostart ${status.autostart.detail}`);\n const check = status.agent?.last_maintenance?.selfCheck;\n if (check) console.log(` self-check ${check.ok ? \"passed\" : `failed: ${check.failed.join(\", \")}`}`);\n if (!live) console.log(`\\nStart it with: ${me} autostart on`);\n return;\n }\n case \"flush\":\n case \"repair\":\n case \"check\": {\n const answer = await callAgent(dir, \"POST\", `/${cmd === \"check\" ? \"maintain\" : cmd}`, {}, 6 * 60_000);\n if (!answer) { console.error(`The Scopebond Agent is not running. Start it with: ${me} autostart on`); process.exitCode = 1; return; }\n console.log(JSON.stringify(answer, null, 2));\n const updatedTo = (answer as { updatedTo?: unknown }).updatedTo;\n if (cmd === \"check\" && typeof updatedTo === \"string\") console.log(await afterUpdate(updatedTo));\n return;\n }\n case \"setup\": {\n const target = rest.find((a) => !a.startsWith(\"--\"));\n let origin: string | null = null;\n try {\n const url = new URL(target ?? \"\");\n const local = [\"localhost\", \"127.0.0.1\", \"[::1]\"].includes(url.hostname);\n if (url.protocol === \"https:\" || (local && url.protocol === \"http:\")) origin = url.origin;\n } catch { origin = null; }\n if (!origin) {\n console.error(`usage: ${process.platform === \"win32\" ? \"npx.cmd\" : \"npx\"} -y @scopebond/agent@${agentVersion()} setup <workspace-url> [--claude|--cursor|--codex]`);\n console.error(\"The workspace URL is the address of your Scopebond workspace, for example https://cloud.scopebond.com.\");\n process.exitCode = 1;\n return;\n }\n const harness = rest.includes(\"--cursor\") ? \"cursor\" : rest.includes(\"--codex\") ? \"codex\" : \"claude\";\n process.exitCode = await runSetup({ dir, origin, harness, relogin: rest.includes(\"--relogin\"), version: agentVersion(), me });\n return;\n }\n case \"stop\": {\n console.log(await stopRunning() ? \"Stopped the Scopebond Agent.\" : \"The Scopebond Agent was not running.\");\n return;\n }\n case \"uninstall\": {\n // What the Windows installer runs when Scopebond is removed (and anyone may run): stop and unregister the agent,\n // then the hook's own uninstall, which tells the workspace and takes the hook out of the coding agents' settings.\n // The Scopebond folder (keys, receipts) stays unless --purge.\n console.log(disableAutostart(dir));\n if (await stopRunning()) console.log(\"Stopped the running Scopebond Agent.\");\n const [program, args] = hookSelfCommand([\"uninstall\", \"--yes\", ...(rest.includes(\"--purge\") ? [\"--purge\"] : [])]);\n const removal = spawnSync(program, args, { stdio: \"inherit\", cwd: homedir(), env: { ...process.env, SCOPEBOND_HOME: dir } });\n process.exitCode = removal.status ?? 1;\n return;\n }\n case \"autostart\": {\n const on = rest[0] === \"on\";\n if (rest[0] !== \"on\" && rest[0] !== \"off\") { console.error(`usage: ${me} autostart on|off`); process.exitCode = 1; return; }\n if (on && isEphemeralPath(agentCliPath())) {\n // npx runs from a cache npm clears; an autostart entry pointing there would stop working.\n console.error(`Install the agent first so autostart has a stable path: ${process.platform === \"win32\" ? \"npm.cmd\" : \"npm\"} install -g @scopebond/agent`);\n process.exitCode = 1;\n return;\n }\n console.log(on ? enableAutostart(dir, agentCliPath()) : disableAutostart(dir));\n if (!on) {\n // Off means off: an agent left running would keep going until sign-out, even after an uninstall.\n if (await stopRunning()) console.log(\"Stopped the running Scopebond Agent.\");\n return;\n }\n // Turning autostart on also starts the agent now, so nobody has to sign out and in again.\n if (await callAgent(dir, \"GET\", \"/status\", undefined, 2_000)) { console.log(\"The Scopebond Agent is running.\"); return; }\n if (await startAndWait()) {\n console.log(`The Scopebond Agent is running${process.platform === \"win32\" ? \"; its icon is in the taskbar tray (it may be under the ^ arrow)\" : \"\"}.`);\n return;\n }\n console.log(`It starts at your next sign-in. To start it now: ${me} run`);\n return;\n }\n default:\n help();\n if (cmd !== \"help\" && cmd !== \"--help\") process.exitCode = 1;\n }\n}\n\n/** Start the agent through its autostart launcher and wait until it answers. Each way of starting it gets a few seconds;\n * a headless console that never starts falls back to a hidden cmd.exe. Whether it answers. */\nasync function startAndWait(): Promise<boolean> {\n for (let attempt = 0; attempt < 2; attempt++) {\n if (!startNow(dir, process.platform, attempt) && attempt > 0) break;\n for (let i = 0; i < (attempt === 0 ? 12 : 18); i++) {\n await new Promise((r) => setTimeout(r, 500));\n if (await callAgent(dir, \"GET\", \"/status\", undefined, 1_000)) return true;\n }\n }\n return false;\n}\n\n/** After `check` updated the agent: wait for the updated one to answer, start it if nothing does, and say which version runs. */\nasync function afterUpdate(version: string): Promise<string> {\n const running = async () => ((await callAgent(dir, \"GET\", \"/status\", undefined, 1_000)) as { agent?: AgentReport | null } | null)?.agent?.version ?? null;\n let seen: string | null = null;\n for (let i = 0; i < 60; i++) {\n await new Promise((r) => setTimeout(r, 1_000));\n seen = await running();\n if (seen === `agent/${version}`) return `The Scopebond Agent ${version} is running.`;\n }\n if (seen) return `The Scopebond Agent running now is ${seen.replace(/^agent\\//, \"\")}, not ${version}. Restart it with: ${me} stop, then ${me} autostart on`;\n if (autostartHealth(dir).on && await startAndWait()) return \"The updated agent had not started; it is running now.\";\n return `The updated agent is not running. Start it with: ${me} autostart on`;\n}\n\n/** Ask the running agent to stop and wait until its control channel is gone. Whether one was running. */\nasync function stopRunning(): Promise<boolean> {\n if (!await callAgent(dir, \"POST\", \"/stop\", {}, 3_000)) return false;\n for (let i = 0; i < 40; i++) {\n await new Promise((r) => setTimeout(r, 250));\n if (!await callAgent(dir, \"GET\", \"/status\", undefined, 1_000)) return true;\n }\n return true;\n}\n\ninterface AgentReport { version?: string; last_maintenance?: { selfCheck?: { ok: boolean; failed: string[] } | null } | null }\n\n"]}
package/dist/cli.js CHANGED
@@ -1,187 +1,6 @@
1
1
  #!/usr/bin/env node
2
- // scopebond-agent: run, look at and control the Scopebond Agent for this user.
3
- //
4
- // scopebond-agent setup <workspace-url> [--claude|--cursor|--codex] [--relogin]
5
- // one command to start: sign in, install, autostart, status
6
- // scopebond-agent run run in the foreground (what autostart starts)
7
- // scopebond-agent status [--json] what the running agent reports, or why it is not running
8
- // scopebond-agent flush deliver now
9
- // scopebond-agent repair put the Scopebond hook back where agent settings lost it
10
- // scopebond-agent check update check, hook upkeep and the end-to-end self-check, now
11
- // scopebond-agent autostart on|off start with this user's sign-in, or stop doing so (off also stops it now)
12
- // scopebond-agent stop stop the running agent (autostart still starts it at the next sign-in)
13
- import { realpathSync } from "node:fs";
14
- import { fileURLToPath } from "node:url";
15
- import { isEphemeralPath, userHome } from "@scopebond/hook";
16
- import { computerStatus } from "./agent.js";
17
- import { autostartHealth, disableAutostart, enableAutostart, startNow } from "./autostart.js";
18
- import { callAgent } from "./ipc.js";
19
- import { runSetup } from "./setup.js";
20
- import { agentVersion } from "./update.js";
21
- import { AFTER_PID_ENV, AGENT_VERSION, startService } from "./service.js";
22
- const [cmd = "help", ...rest] = process.argv.slice(2);
23
- // What a person types here: on Windows, PowerShell blocks the plain name's script shim.
24
- const me = process.platform === "win32" ? "scopebond-agent.cmd" : "scopebond-agent";
25
- const dir = process.env.SCOPEBOND_HOME ?? userHome();
26
- const cliPath = realpathSync(fileURLToPath(import.meta.url));
27
- function help() {
28
- const c = (sub) => `${me} ${sub}`.padEnd(me.length + 36);
29
- console.log(`Scopebond Agent — keeps this computer delivering to its Scopebond workspace.
30
-
31
- ${c("setup <workspace-url>")}sign in, install for this user, start with sign-in, show status
32
- ${c("run")}run in the foreground (what autostart starts)
33
- ${c("status [--json]")}what the agent reports about this computer
34
- ${c("flush")}deliver waiting records now
35
- ${c("repair")}put the Scopebond hook back where agent settings lost it
36
- ${c("check")}check for updates and run the end-to-end self-check now
37
- ${c("autostart on|off")}start with your sign-in, or stop doing so (off also stops it now)
38
- ${c("stop")}stop the running agent until the next sign-in
39
-
40
- The hook keeps deciding every action on its own; the agent only keeps delivery, rules and the
41
- connection current. Home: ${dir}`);
42
- }
43
- async function main() {
44
- switch (cmd) {
45
- case "run": {
46
- // Started by an agent that just updated itself: let it exit first.
47
- const previous = Number(process.env[AFTER_PID_ENV]);
48
- if (Number.isInteger(previous) && previous > 0)
49
- await waitForExit(previous, 30_000);
50
- const service = await startService({ dir, onStopped: () => process.exit(0) });
51
- const stop = () => { void service.stop().finally(() => process.exit(0)); };
52
- process.on("SIGINT", stop);
53
- process.on("SIGTERM", stop);
54
- return;
55
- }
56
- case "status": {
57
- const live = await callAgent(dir, "GET", "/status");
58
- const status = { ...(live ?? { ...computerStatus(dir), agent: null }), autostart: autostartHealth(dir) };
59
- if (rest.includes("--json")) {
60
- console.log(JSON.stringify(status, null, 2));
61
- return;
62
- }
63
- const d = status.delivery;
64
- console.log(`Scopebond Agent: ${live ? "running" : "not running"}`);
65
- console.log(` state ${live ? status.state : "not running: records wait on this computer until it runs"}`);
66
- console.log(` connected ${d.connected ? "yes" : "no"}`);
67
- console.log(` waiting to send ${d.pending} record(s)${d.oldest_pending_age_s !== null ? `, oldest ${Math.round(d.oldest_pending_age_s / 60)} min` : ""}`);
68
- if (d.last_error)
69
- console.log(` last problem ${d.last_error}`);
70
- console.log(` version ${status.agent?.version ?? AGENT_VERSION}`);
71
- console.log(` autostart ${status.autostart.detail}`);
72
- const check = status.agent?.last_maintenance?.selfCheck;
73
- if (check)
74
- console.log(` self-check ${check.ok ? "passed" : `failed: ${check.failed.join(", ")}`}`);
75
- if (!live)
76
- console.log(`\nStart it with: ${me} autostart on`);
77
- return;
78
- }
79
- case "flush":
80
- case "repair":
81
- case "check": {
82
- const answer = await callAgent(dir, "POST", `/${cmd === "check" ? "maintain" : cmd}`, {}, 6 * 60_000);
83
- if (!answer) {
84
- console.error(`The Scopebond Agent is not running. Start it with: ${me} autostart on`);
85
- process.exitCode = 1;
86
- return;
87
- }
88
- console.log(JSON.stringify(answer, null, 2));
89
- return;
90
- }
91
- case "setup": {
92
- const target = rest.find((a) => !a.startsWith("--"));
93
- let origin = null;
94
- try {
95
- const url = new URL(target ?? "");
96
- const local = ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
97
- if (url.protocol === "https:" || (local && url.protocol === "http:"))
98
- origin = url.origin;
99
- }
100
- catch {
101
- origin = null;
102
- }
103
- if (!origin) {
104
- console.error(`usage: ${process.platform === "win32" ? "npx.cmd" : "npx"} -y @scopebond/agent@${agentVersion()} setup <workspace-url> [--claude|--cursor|--codex]`);
105
- console.error("The workspace URL is the address of your Scopebond workspace, for example https://cloud.scopebond.com.");
106
- process.exitCode = 1;
107
- return;
108
- }
109
- const harness = rest.includes("--cursor") ? "cursor" : rest.includes("--codex") ? "codex" : "claude";
110
- process.exitCode = await runSetup({ dir, origin, harness, relogin: rest.includes("--relogin"), version: agentVersion(), me });
111
- return;
112
- }
113
- case "stop": {
114
- console.log(await stopRunning() ? "Stopped the Scopebond Agent." : "The Scopebond Agent was not running.");
115
- return;
116
- }
117
- case "autostart": {
118
- const on = rest[0] === "on";
119
- if (rest[0] !== "on" && rest[0] !== "off") {
120
- console.error(`usage: ${me} autostart on|off`);
121
- process.exitCode = 1;
122
- return;
123
- }
124
- if (on && isEphemeralPath(cliPath)) {
125
- // npx runs from a cache npm clears; an autostart entry pointing there would stop working.
126
- console.error(`Install the agent first so autostart has a stable path: ${process.platform === "win32" ? "npm.cmd" : "npm"} install -g @scopebond/agent`);
127
- process.exitCode = 1;
128
- return;
129
- }
130
- console.log(on ? enableAutostart(dir, cliPath) : disableAutostart(dir));
131
- if (!on) {
132
- // Off means off: an agent left running would keep going until sign-out, even after an uninstall.
133
- if (await stopRunning())
134
- console.log("Stopped the running Scopebond Agent.");
135
- return;
136
- }
137
- // Turning autostart on also starts the agent now, so nobody has to sign out and in again.
138
- if (await callAgent(dir, "GET", "/status", undefined, 2_000)) {
139
- console.log("The Scopebond Agent is running.");
140
- return;
141
- }
142
- // Each way of starting it gets a few seconds; a headless console that never starts falls back to a hidden cmd.exe.
143
- for (let attempt = 0; attempt < 2; attempt++) {
144
- if (!startNow(dir, process.platform, attempt) && attempt > 0)
145
- break;
146
- for (let i = 0; i < (attempt === 0 ? 12 : 18); i++) {
147
- await new Promise((r) => setTimeout(r, 500));
148
- if (await callAgent(dir, "GET", "/status", undefined, 1_000)) {
149
- console.log(`The Scopebond Agent is running${process.platform === "win32" ? "; its icon is in the taskbar tray (it may be under the ^ arrow)" : ""}.`);
150
- return;
151
- }
152
- }
153
- }
154
- console.log(`It starts at your next sign-in. To start it now: ${me} run`);
155
- return;
156
- }
157
- default:
158
- help();
159
- if (cmd !== "help" && cmd !== "--help")
160
- process.exitCode = 1;
161
- }
162
- }
163
- /** Ask the running agent to stop and wait until its control channel is gone. Whether one was running. */
164
- async function stopRunning() {
165
- if (!await callAgent(dir, "POST", "/stop", {}, 3_000))
166
- return false;
167
- for (let i = 0; i < 40; i++) {
168
- await new Promise((r) => setTimeout(r, 250));
169
- if (!await callAgent(dir, "GET", "/status", undefined, 1_000))
170
- return true;
171
- }
172
- return true;
173
- }
174
- async function waitForExit(pid, timeoutMs) {
175
- const until = Date.now() + timeoutMs;
176
- while (Date.now() < until) {
177
- try {
178
- process.kill(pid, 0);
179
- }
180
- catch {
181
- return;
182
- }
183
- await new Promise((r) => setTimeout(r, 250));
184
- }
185
- }
186
- void main().catch((error) => { console.error(error.message); process.exitCode = 1; });
2
+ // scopebond-agent: run, look at and control the Scopebond Agent for this user. This is the program npm installs and
3
+ // autostart starts (`cli.js run`); the commands themselves are in cli-main.ts.
4
+ import { main } from "./cli-main.js";
5
+ void main(process.argv.slice(2)).catch((error) => { console.error(error.message); process.exitCode = 1; });
187
6
  //# sourceMappingURL=cli.js.map
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts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C;IACpE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5B,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;QAC7C,IAAI,CAAC,MAAM,SAAS,CAAC,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;IAC7E,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAID,KAAK,UAAU,WAAW,CAAC,GAAW,EAAE,SAAiB;IACvD,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;IACrC,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC;QAC1B,IAAI,CAAC;YAAC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QAAC,CAAC;QAAC,MAAM,CAAC;YAAC,OAAO;QAAC,CAAC;QAC/C,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IAC/C,CAAC;AACH,CAAC;AAED,KAAK,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAE,KAAe,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\n// scopebond-agent: run, look at and control the Scopebond Agent for this user.\n//\n// scopebond-agent setup <workspace-url> [--claude|--cursor|--codex] [--relogin]\n// one command to start: sign in, install, autostart, status\n// scopebond-agent run run in the foreground (what autostart starts)\n// scopebond-agent status [--json] what the running agent reports, or why it is not running\n// scopebond-agent flush deliver now\n// scopebond-agent repair put the Scopebond hook back where agent settings lost it\n// scopebond-agent check update check, hook upkeep and the end-to-end self-check, now\n// scopebond-agent autostart on|off start with this user's sign-in, or stop doing so (off also stops it now)\n// scopebond-agent stop stop the running agent (autostart still starts it at the next sign-in)\n\nimport { realpathSync } from \"node:fs\";\nimport { fileURLToPath } from \"node:url\";\nimport { isEphemeralPath, userHome } from \"@scopebond/hook\";\nimport { computerStatus } from \"./agent.js\";\nimport { autostartHealth, disableAutostart, enableAutostart, startNow } from \"./autostart.js\";\nimport { callAgent } from \"./ipc.js\";\nimport { runSetup } from \"./setup.js\";\nimport { agentVersion } from \"./update.js\";\nimport { AFTER_PID_ENV, AGENT_VERSION, startService } from \"./service.js\";\n\nconst [cmd = \"help\", ...rest] = process.argv.slice(2);\n// What a person types here: on Windows, PowerShell blocks the plain name's script shim.\nconst me = process.platform === \"win32\" ? \"scopebond-agent.cmd\" : \"scopebond-agent\";\nconst dir = process.env.SCOPEBOND_HOME ?? userHome();\nconst cliPath = realpathSync(fileURLToPath(import.meta.url));\n\nfunction help(): void {\n const c = (sub: string) => `${me} ${sub}`.padEnd(me.length + 36);\n console.log(`Scopebond Agent — keeps this computer delivering to its Scopebond workspace.\n\n ${c(\"setup <workspace-url>\")}sign in, install for this user, start with sign-in, show status\n ${c(\"run\")}run in the foreground (what autostart starts)\n ${c(\"status [--json]\")}what the agent reports about this computer\n ${c(\"flush\")}deliver waiting records now\n ${c(\"repair\")}put the Scopebond hook back where agent settings lost it\n ${c(\"check\")}check for updates and run the end-to-end self-check now\n ${c(\"autostart on|off\")}start with your sign-in, or stop doing so (off also stops it now)\n ${c(\"stop\")}stop the running agent until the next sign-in\n\nThe hook keeps deciding every action on its own; the agent only keeps delivery, rules and the\nconnection current. Home: ${dir}`);\n}\n\nasync function main(): Promise<void> {\n switch (cmd) {\n case \"run\": {\n // Started by an agent that just updated itself: let it exit first.\n const previous = Number(process.env[AFTER_PID_ENV]);\n if (Number.isInteger(previous) && previous > 0) await waitForExit(previous, 30_000);\n const service = await startService({ dir, onStopped: () => process.exit(0) });\n const stop = () => { void service.stop().finally(() => process.exit(0)); };\n process.on(\"SIGINT\", stop);\n process.on(\"SIGTERM\", stop);\n return;\n }\n case \"status\": {\n const live = await callAgent(dir, \"GET\", \"/status\") as (ReturnType<typeof computerStatus> & { agent?: AgentReport | null }) | null;\n const status = { ...(live ?? { ...computerStatus(dir), agent: null }), autostart: autostartHealth(dir) };\n if (rest.includes(\"--json\")) { console.log(JSON.stringify(status, null, 2)); return; }\n const d = status.delivery;\n console.log(`Scopebond Agent: ${live ? \"running\" : \"not running\"}`);\n console.log(` state ${live ? status.state : \"not running: records wait on this computer until it runs\"}`);\n console.log(` connected ${d.connected ? \"yes\" : \"no\"}`);\n console.log(` waiting to send ${d.pending} record(s)${d.oldest_pending_age_s !== null ? `, oldest ${Math.round(d.oldest_pending_age_s / 60)} min` : \"\"}`);\n if (d.last_error) console.log(` last problem ${d.last_error}`);\n console.log(` version ${status.agent?.version ?? AGENT_VERSION}`);\n console.log(` autostart ${status.autostart.detail}`);\n const check = status.agent?.last_maintenance?.selfCheck;\n if (check) console.log(` self-check ${check.ok ? \"passed\" : `failed: ${check.failed.join(\", \")}`}`);\n if (!live) console.log(`\\nStart it with: ${me} autostart on`);\n return;\n }\n case \"flush\":\n case \"repair\":\n case \"check\": {\n const answer = await callAgent(dir, \"POST\", `/${cmd === \"check\" ? \"maintain\" : cmd}`, {}, 6 * 60_000);\n if (!answer) { console.error(`The Scopebond Agent is not running. Start it with: ${me} autostart on`); process.exitCode = 1; return; }\n console.log(JSON.stringify(answer, null, 2));\n return;\n }\n case \"setup\": {\n const target = rest.find((a) => !a.startsWith(\"--\"));\n let origin: string | null = null;\n try {\n const url = new URL(target ?? \"\");\n const local = [\"localhost\", \"127.0.0.1\", \"[::1]\"].includes(url.hostname);\n if (url.protocol === \"https:\" || (local && url.protocol === \"http:\")) origin = url.origin;\n } catch { origin = null; }\n if (!origin) {\n console.error(`usage: ${process.platform === \"win32\" ? \"npx.cmd\" : \"npx\"} -y @scopebond/agent@${agentVersion()} setup <workspace-url> [--claude|--cursor|--codex]`);\n console.error(\"The workspace URL is the address of your Scopebond workspace, for example https://cloud.scopebond.com.\");\n process.exitCode = 1;\n return;\n }\n const harness = rest.includes(\"--cursor\") ? \"cursor\" : rest.includes(\"--codex\") ? \"codex\" : \"claude\";\n process.exitCode = await runSetup({ dir, origin, harness, relogin: rest.includes(\"--relogin\"), version: agentVersion(), me });\n return;\n }\n case \"stop\": {\n console.log(await stopRunning() ? \"Stopped the Scopebond Agent.\" : \"The Scopebond Agent was not running.\");\n return;\n }\n case \"autostart\": {\n const on = rest[0] === \"on\";\n if (rest[0] !== \"on\" && rest[0] !== \"off\") { console.error(`usage: ${me} autostart on|off`); process.exitCode = 1; return; }\n if (on && isEphemeralPath(cliPath)) {\n // npx runs from a cache npm clears; an autostart entry pointing there would stop working.\n console.error(`Install the agent first so autostart has a stable path: ${process.platform === \"win32\" ? \"npm.cmd\" : \"npm\"} install -g @scopebond/agent`);\n process.exitCode = 1;\n return;\n }\n console.log(on ? enableAutostart(dir, cliPath) : disableAutostart(dir));\n if (!on) {\n // Off means off: an agent left running would keep going until sign-out, even after an uninstall.\n if (await stopRunning()) console.log(\"Stopped the running Scopebond Agent.\");\n return;\n }\n // Turning autostart on also starts the agent now, so nobody has to sign out and in again.\n if (await callAgent(dir, \"GET\", \"/status\", undefined, 2_000)) { console.log(\"The Scopebond Agent is running.\"); return; }\n // Each way of starting it gets a few seconds; a headless console that never starts falls back to a hidden cmd.exe.\n for (let attempt = 0; attempt < 2; attempt++) {\n if (!startNow(dir, process.platform, attempt) && attempt > 0) break;\n for (let i = 0; i < (attempt === 0 ? 12 : 18); i++) {\n await new Promise((r) => setTimeout(r, 500));\n if (await callAgent(dir, \"GET\", \"/status\", undefined, 1_000)) {\n console.log(`The Scopebond Agent is running${process.platform === \"win32\" ? \"; its icon is in the taskbar tray (it may be under the ^ arrow)\" : \"\"}.`);\n return;\n }\n }\n }\n console.log(`It starts at your next sign-in. To start it now: ${me} run`);\n return;\n }\n default:\n help();\n if (cmd !== \"help\" && cmd !== \"--help\") process.exitCode = 1;\n }\n}\n\n/** Ask the running agent to stop and wait until its control channel is gone. Whether one was running. */\nasync function stopRunning(): Promise<boolean> {\n if (!await callAgent(dir, \"POST\", \"/stop\", {}, 3_000)) return false;\n for (let i = 0; i < 40; i++) {\n await new Promise((r) => setTimeout(r, 250));\n if (!await callAgent(dir, \"GET\", \"/status\", undefined, 1_000)) return true;\n }\n return true;\n}\n\ninterface AgentReport { version?: string; last_maintenance?: { selfCheck?: { ok: boolean; failed: string[] } | null } | null }\n\nasync function waitForExit(pid: number, timeoutMs: number): Promise<void> {\n const until = Date.now() + timeoutMs;\n while (Date.now() < until) {\n try { process.kill(pid, 0); } catch { return; }\n await new Promise((r) => setTimeout(r, 250));\n }\n}\n\nvoid main().catch((error) => { console.error((error as Error).message); process.exitCode = 1; });\n"]}
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,oHAAoH;AACpH,+EAA+E;AAC/E,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAErC,KAAK,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAE,KAAe,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\n// scopebond-agent: run, look at and control the Scopebond Agent for this user. This is the program npm installs and\n// autostart starts (`cli.js run`); the commands themselves are in cli-main.ts.\nimport { main } from \"./cli-main.js\";\n\nvoid main(process.argv.slice(2)).catch((error) => { console.error((error as Error).message); process.exitCode = 1; });\n"]}
package/dist/index.d.ts CHANGED
@@ -1,10 +1,12 @@
1
1
  export { runCycle, computerStatus, expectedHarnesses, missingHookEntries } from "./agent.js";
2
2
  export type { CycleOptions, CycleResult } from "./agent.js";
3
- export { startService, repairHookEntries, spawnReplacement, acquireAgentLock, releaseAgentLock, AGENT_LOCK, AGENT_VERSION, AFTER_PID_ENV } from "./service.js";
3
+ export { startService, repairHookEntries, spawnReplacement, handoverPlan, takeOver, acquireAgentLock, releaseAgentLock, AGENT_LOCK, AGENT_VERSION, AFTER_PID_ENV, REFRESH_LAUNCHER_ENV, RESTART_EXIT_CODE } from "./service.js";
4
+ export type { Handover } from "./service.js";
5
+ export { writeOutputTo, FALLBACK_LOG } from "./log-file.js";
4
6
  export type { Service, ServiceOptions, MaintenanceResult } from "./service.js";
5
- export { startControl, callAgent, readEndpoint, AGENT_FILE, TOKEN_HEADER } from "./ipc.js";
7
+ export { startControl, callAgent, readEndpoint, localSocketPath, AGENT_FILE, TOKEN_HEADER } from "./ipc.js";
6
8
  export type { AgentEndpoint } from "./ipc.js";
7
- export { launcherPath, windowsLauncher, posixLauncher, windowsRunCommand, macLaunchAgent, linuxUserUnit, enableAutostart, disableAutostart, autostartHealth, autostartPaths, startCommands, startNow, LABEL, } from "./autostart.js";
9
+ export { launcherPath, windowsLauncher, posixLauncher, windowsRunCommand, macLaunchAgent, linuxUserUnit, enableAutostart, disableAutostart, autostartHealth, autostartPaths, startCommands, startNow, LABEL, AGENT_LOG_ENV, LAUNCHER_MARK, launcherIsCurrent, refreshLauncher, } from "./autostart.js";
8
10
  export { agentVersion, fetchClientVersion, compareVersions, commandHookVersion, maintainedHookCommand, maintainHookEntries, installAgent, ownNpm, } from "./update.js";
9
11
  export type { ClientVersion } from "./update.js";
10
12
  export { selfCheckProof, localChecks, runSelfCheck } from "./selfcheck.js";
@@ -14,4 +16,6 @@ export { queueReason, flushReasons, pendingReasons, REASONS_FILE } from "./overr
14
16
  export type { SelfCheckItem } from "./selfcheck.js";
15
17
  export { setupPlan, globalBinDir, onPath, addToPathCommand, nodeSupported, runSetup } from "./setup.js";
16
18
  export type { SetupState, SetupStep, SetupOptions } from "./setup.js";
19
+ export { installKind, updaterPublicKey, verifyManifest, fetchVerifiedInstaller, installerName, MANIFEST_DOMAIN, PUBLISHER } from "./native-update.js";
20
+ export type { InstallKind, ReleaseManifest } from "./native-update.js";
17
21
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAC7F,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC/J,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC3F,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EACL,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,iBAAiB,EAAE,cAAc,EAAE,aAAa,EAC9F,eAAe,EAAE,gBAAgB,EAAE,eAAe,EAAE,cAAc,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,GACnG,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,YAAY,EAAE,kBAAkB,EAAE,eAAe,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,GACxI,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,YA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EAAE,MAAM,oBAAoB,CAAC"}
package/dist/index.js CHANGED
@@ -1,10 +1,12 @@
1
1
  export { runCycle, computerStatus, expectedHarnesses, missingHookEntries } from "./agent.js";
2
- export { startService, repairHookEntries, spawnReplacement, acquireAgentLock, releaseAgentLock, AGENT_LOCK, AGENT_VERSION, AFTER_PID_ENV } from "./service.js";
3
- export { startControl, callAgent, readEndpoint, AGENT_FILE, TOKEN_HEADER } from "./ipc.js";
4
- export { launcherPath, windowsLauncher, posixLauncher, windowsRunCommand, macLaunchAgent, linuxUserUnit, enableAutostart, disableAutostart, autostartHealth, autostartPaths, startCommands, startNow, LABEL, } from "./autostart.js";
2
+ export { startService, repairHookEntries, spawnReplacement, handoverPlan, takeOver, acquireAgentLock, releaseAgentLock, AGENT_LOCK, AGENT_VERSION, AFTER_PID_ENV, REFRESH_LAUNCHER_ENV, RESTART_EXIT_CODE } from "./service.js";
3
+ export { writeOutputTo, FALLBACK_LOG } from "./log-file.js";
4
+ export { startControl, callAgent, readEndpoint, localSocketPath, AGENT_FILE, TOKEN_HEADER } from "./ipc.js";
5
+ export { launcherPath, windowsLauncher, posixLauncher, windowsRunCommand, macLaunchAgent, linuxUserUnit, enableAutostart, disableAutostart, autostartHealth, autostartPaths, startCommands, startNow, LABEL, AGENT_LOG_ENV, LAUNCHER_MARK, launcherIsCurrent, refreshLauncher, } from "./autostart.js";
5
6
  export { agentVersion, fetchClientVersion, compareVersions, commandHookVersion, maintainedHookCommand, maintainHookEntries, installAgent, ownNpm, } from "./update.js";
6
7
  export { selfCheckProof, localChecks, runSelfCheck } from "./selfcheck.js";
7
8
  export { parseQuestion, questionText, windowsScript, systemPrompter, serialized } from "./prompt.js";
8
9
  export { queueReason, flushReasons, pendingReasons, REASONS_FILE } from "./override-reasons.js";
9
10
  export { setupPlan, globalBinDir, onPath, addToPathCommand, nodeSupported, runSetup } from "./setup.js";
11
+ export { installKind, updaterPublicKey, verifyManifest, fetchVerifiedInstaller, installerName, MANIFEST_DOMAIN, PUBLISHER } from "./native-update.js";
10
12
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAE7F,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE/J,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE3F,OAAO,EACL,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,iBAAiB,EAAE,cAAc,EAAE,aAAa,EAC9F,eAAe,EAAE,gBAAgB,EAAE,eAAe,EAAE,cAAc,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,GACnG,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,YAAY,EAAE,kBAAkB,EAAE,eAAe,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,GACxI,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAErG,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAEhG,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,gBAAgB,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC","sourcesContent":["export { runCycle, computerStatus, expectedHarnesses, missingHookEntries } from \"./agent.js\";\nexport type { CycleOptions, CycleResult } from \"./agent.js\";\nexport { startService, repairHookEntries, spawnReplacement, acquireAgentLock, releaseAgentLock, AGENT_LOCK, AGENT_VERSION, AFTER_PID_ENV } from \"./service.js\";\nexport type { Service, ServiceOptions, MaintenanceResult } from \"./service.js\";\nexport { startControl, callAgent, readEndpoint, AGENT_FILE, TOKEN_HEADER } from \"./ipc.js\";\nexport type { AgentEndpoint } from \"./ipc.js\";\nexport {\n launcherPath, windowsLauncher, posixLauncher, windowsRunCommand, macLaunchAgent, linuxUserUnit,\n enableAutostart, disableAutostart, autostartHealth, autostartPaths, startCommands, startNow, LABEL,\n} from \"./autostart.js\";\nexport {\n agentVersion, fetchClientVersion, compareVersions, commandHookVersion, maintainedHookCommand, maintainHookEntries, installAgent, ownNpm,\n} from \"./update.js\";\nexport type { ClientVersion } from \"./update.js\";\nexport { selfCheckProof, localChecks, runSelfCheck } from \"./selfcheck.js\";\nexport { parseQuestion, questionText, windowsScript, systemPrompter, serialized } from \"./prompt.js\";\nexport type { OverrideQuestion, OverrideAnswer, Prompter } from \"./prompt.js\";\nexport { queueReason, flushReasons, pendingReasons, REASONS_FILE } from \"./override-reasons.js\";\nexport type { SelfCheckItem } from \"./selfcheck.js\";\nexport { setupPlan, globalBinDir, onPath, addToPathCommand, nodeSupported, runSetup } from \"./setup.js\";\nexport type { SetupState, SetupStep, SetupOptions } from \"./setup.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAE7F,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,YAAY,EAAE,QAAQ,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEhO,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE5D,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,eAAe,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE5G,OAAO,EACL,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,iBAAiB,EAAE,cAAc,EAAE,aAAa,EAC9F,eAAe,EAAE,gBAAgB,EAAE,eAAe,EAAE,cAAc,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAClG,aAAa,EAAE,aAAa,EAAE,iBAAiB,EAAE,eAAe,GACjE,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,YAAY,EAAE,kBAAkB,EAAE,eAAe,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,GACxI,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAErG,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAEhG,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,gBAAgB,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAExG,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,cAAc,EAAE,sBAAsB,EAAE,aAAa,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["export { runCycle, computerStatus, expectedHarnesses, missingHookEntries } from \"./agent.js\";\nexport type { CycleOptions, CycleResult } from \"./agent.js\";\nexport { startService, repairHookEntries, spawnReplacement, handoverPlan, takeOver, acquireAgentLock, releaseAgentLock, AGENT_LOCK, AGENT_VERSION, AFTER_PID_ENV, REFRESH_LAUNCHER_ENV, RESTART_EXIT_CODE } from \"./service.js\";\nexport type { Handover } from \"./service.js\";\nexport { writeOutputTo, FALLBACK_LOG } from \"./log-file.js\";\nexport type { Service, ServiceOptions, MaintenanceResult } from \"./service.js\";\nexport { startControl, callAgent, readEndpoint, localSocketPath, AGENT_FILE, TOKEN_HEADER } from \"./ipc.js\";\nexport type { AgentEndpoint } from \"./ipc.js\";\nexport {\n launcherPath, windowsLauncher, posixLauncher, windowsRunCommand, macLaunchAgent, linuxUserUnit,\n enableAutostart, disableAutostart, autostartHealth, autostartPaths, startCommands, startNow, LABEL,\n AGENT_LOG_ENV, LAUNCHER_MARK, launcherIsCurrent, refreshLauncher,\n} from \"./autostart.js\";\nexport {\n agentVersion, fetchClientVersion, compareVersions, commandHookVersion, maintainedHookCommand, maintainHookEntries, installAgent, ownNpm,\n} from \"./update.js\";\nexport type { ClientVersion } from \"./update.js\";\nexport { selfCheckProof, localChecks, runSelfCheck } from \"./selfcheck.js\";\nexport { parseQuestion, questionText, windowsScript, systemPrompter, serialized } from \"./prompt.js\";\nexport type { OverrideQuestion, OverrideAnswer, Prompter } from \"./prompt.js\";\nexport { queueReason, flushReasons, pendingReasons, REASONS_FILE } from \"./override-reasons.js\";\nexport type { SelfCheckItem } from \"./selfcheck.js\";\nexport { setupPlan, globalBinDir, onPath, addToPathCommand, nodeSupported, runSetup } from \"./setup.js\";\nexport type { SetupState, SetupStep, SetupOptions } from \"./setup.js\";\nexport { installKind, updaterPublicKey, verifyManifest, fetchVerifiedInstaller, installerName, MANIFEST_DOMAIN, PUBLISHER } from \"./native-update.js\";\nexport type { InstallKind, ReleaseManifest } from \"./native-update.js\";\n"]}
package/dist/ipc.d.ts CHANGED
@@ -1,13 +1,19 @@
1
1
  import { type Server } from "node:http";
2
2
  export declare const AGENT_FILE = "agent.json";
3
3
  export declare const TOKEN_HEADER = "x-scopebond-agent-token";
4
+ /** `socket`: the named pipe or Unix socket (absent from agents before it); `port`: 0 when loopback is off. */
4
5
  export interface AgentEndpoint {
5
6
  port: number;
7
+ socket?: string | null;
6
8
  token: string;
7
9
  pid: number;
8
10
  started_at: number;
9
11
  version: string;
10
12
  }
13
+ /** Where this start's pipe or socket goes. Windows: a pipe whose name is random, so no other user can guess it or claim it
14
+ * first. Elsewhere: `run/agent.sock` in the Scopebond home (folder 0700), or a private folder under the temporary folder
15
+ * when that path is longer than a Unix socket path may be. */
16
+ export declare function localSocketPath(dir: string, platform?: NodeJS.Platform, random?: string): string;
11
17
  export type Handler = (body: unknown) => Promise<unknown> | unknown;
12
18
  export declare function readEndpoint(dir: string): AgentEndpoint | null;
13
19
  /** Start the control server. `routes` maps "METHOD /path" to a handler. */
@@ -16,6 +22,6 @@ export declare function startControl(dir: string, version: string, routes: Recor
16
22
  endpoint: AgentEndpoint;
17
23
  close(): Promise<void>;
18
24
  }>;
19
- /** Call a running agent. Returns null when no agent answers. */
25
+ /** Call a running agent, over its pipe or socket when it has one. Returns null when no agent answers. */
20
26
  export declare function callAgent(dir: string, method: "GET" | "POST", path: string, body?: unknown, timeoutMs?: number): Promise<unknown | null>;
21
27
  //# sourceMappingURL=ipc.d.ts.map
package/dist/ipc.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ipc.d.ts","sourceRoot":"","sources":["../src/ipc.ts"],"names":[],"mappings":"AAKA,OAAO,EAAsC,KAAK,MAAM,EAAuB,MAAM,WAAW,CAAC;AAKjG,eAAO,MAAM,UAAU,eAAe,CAAC;AACvC,eAAO,MAAM,YAAY,4BAA4B,CAAC;AAEtD,MAAM,WAAW,aAAa;IAAG,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE;AAEhH,MAAM,MAAM,OAAO,GAAG,CAAC,IAAI,EAAE,OAAO,KAAK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