@chibitek/chibi 0.1.195 → 0.1.196

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 (74) hide show
  1. package/dist/assets/{TerminalPanel-ColKaJYW.js → TerminalPanel-CB-6ECq_.js} +1 -1
  2. package/dist/assets/{abnfDiagram-O67JEVCF-3Ob4zw74.js → abnfDiagram-O67JEVCF-C79ttPKo.js} +1 -1
  3. package/dist/assets/{arc-HPFapNIH.js → arc-BUuqriRQ.js} +1 -1
  4. package/dist/assets/{architectureDiagram-NJMV4G6O-DkCwaZOT.js → architectureDiagram-NJMV4G6O-CxWfPil9.js} +1 -1
  5. package/dist/assets/{blockDiagram-BEXU5L5S-BimJc2cp.js → blockDiagram-BEXU5L5S-BSLYuBHS.js} +1 -1
  6. package/dist/assets/{c4Diagram-YGBWAQC7-RwjFYoqV.js → c4Diagram-YGBWAQC7-B-xzP35S.js} +1 -1
  7. package/dist/assets/channel-AilCgHWM.js +1 -0
  8. package/dist/assets/{chunk-2Q5K7J3B-KYH4VNAA.js → chunk-2Q5K7J3B-B11khEvC.js} +1 -1
  9. package/dist/assets/{chunk-3FUC2YCW-CoGh3EJb.js → chunk-3FUC2YCW-DsPETNim.js} +2 -2
  10. package/dist/assets/{chunk-5VM5RSS4-BWgviAjX.js → chunk-5VM5RSS4-D6WoBPUT.js} +1 -1
  11. package/dist/assets/{chunk-GTNCS2PH-Ddlqcpyc.js → chunk-GTNCS2PH-CN_1S4k_.js} +1 -1
  12. package/dist/assets/{chunk-GWA4HPMP-RV94Cbaa.js → chunk-GWA4HPMP-NlXta6PY.js} +1 -1
  13. package/dist/assets/{chunk-JWPE2WC7-B0BTZ6sh.js → chunk-JWPE2WC7-CLIqUdNW.js} +1 -1
  14. package/dist/assets/{chunk-NETBCI7D-CfcSF9jy.js → chunk-NETBCI7D-DnuYREKE.js} +1 -1
  15. package/dist/assets/{chunk-WEXAMYUT-srnz312I.js → chunk-WEXAMYUT-DJKFEs93.js} +1 -1
  16. package/dist/assets/{chunk-XXDRQBXY-C4vdFU17.js → chunk-XXDRQBXY-CRWsxQ_5.js} +1 -1
  17. package/dist/assets/{classDiagram-v2-NBCMYWYE-DNy2vFs-.js → classDiagram-v2-NBCMYWYE-Cyp63Eux.js} +1 -1
  18. package/dist/assets/{cose-bilkent-JH36ORCC-D0i9E7vP.js → cose-bilkent-JH36ORCC-BLjNsWhq.js} +1 -1
  19. package/dist/assets/{cynefin-OW5HDTMX-gkAOk-jI.js → cynefin-OW5HDTMX-BnV2cLbs.js} +1 -1
  20. package/dist/assets/{cynefinDiagram-VND7K2PF-Q4524mSo.js → cynefinDiagram-VND7K2PF-ClWXZ7xW.js} +1 -1
  21. package/dist/assets/{dagre-6A5THRUB-Bzq01xjc.js → dagre-6A5THRUB-Dk58FIJ2.js} +1 -1
  22. package/dist/assets/{diagram-22UHCM2B-Cm5DPMsm.js → diagram-22UHCM2B-BjlV2Pv3.js} +1 -1
  23. package/dist/assets/{diagram-3UASUU5V-6tnEN2tD.js → diagram-3UASUU5V-BOqom62X.js} +1 -1
  24. package/dist/assets/{diagram-ATOU4E4O-Ce8MaZqL.js → diagram-ATOU4E4O-CVw9PK2o.js} +1 -1
  25. package/dist/assets/{diagram-CDSNMT55-DmxP3ZT3.js → diagram-CDSNMT55-LTIvpF3x.js} +1 -1
  26. package/dist/assets/{diagram-MLGK6HIB-BG4kwPCS.js → diagram-MLGK6HIB-DZKwFRor.js} +1 -1
  27. package/dist/assets/{diagram-MPIPVDR6-BnLYiwBc.js → diagram-MPIPVDR6-CY_QtFYz.js} +1 -1
  28. package/dist/assets/{ebnfDiagram-ZINNZB2B-Dd19Rw8P.js → ebnfDiagram-ZINNZB2B-Kb2bwfRU.js} +1 -1
  29. package/dist/assets/{elk-276RUBZZ-B2-jAuba.js → elk-276RUBZZ-D05nrUAY.js} +1 -1
  30. package/dist/assets/{erDiagram-OPXOYQCR-CVXqmXQ8.js → erDiagram-OPXOYQCR-cBbx_M93.js} +1 -1
  31. package/dist/assets/{flowDiagram-KWPJA3E3-RrANAUuT.js → flowDiagram-KWPJA3E3-CzlBDlR8.js} +1 -1
  32. package/dist/assets/{ganttDiagram-FUAMR5RP-C5vGW4y-.js → ganttDiagram-FUAMR5RP-DkkjIANc.js} +1 -1
  33. package/dist/assets/{gitGraphDiagram-X574FWY7-BHvq9YfO.js → gitGraphDiagram-X574FWY7-DXlMkWfc.js} +1 -1
  34. package/dist/assets/{index-1PLvu0_F.js → index-B2U0UUX-.js} +1 -1
  35. package/dist/assets/{index-DQQGKX5x.js → index-DzInGWYS.js} +137 -137
  36. package/dist/assets/{infoDiagram-VRGFBTTK-DvuzWS54.js → infoDiagram-VRGFBTTK-B4MLOatD.js} +1 -1
  37. package/dist/assets/{ishikawaDiagram-OU5B5YK6-cCkUTtkg.js → ishikawaDiagram-OU5B5YK6-ccVErf8N.js} +1 -1
  38. package/dist/assets/{journeyDiagram-ZHPQQLJL-B0RmSvGs.js → journeyDiagram-ZHPQQLJL-B8-kD51p.js} +1 -1
  39. package/dist/assets/{kanban-definition-PNTS6WVX-xbVsCFqa.js → kanban-definition-PNTS6WVX-Kegk_QSG.js} +1 -1
  40. package/dist/assets/{linear-ChjewIA3.js → linear-CA_cRwMp.js} +1 -1
  41. package/dist/assets/{mermaid.core-s9HcmFG6.js → mermaid.core-DuwzJ1O8.js} +5 -5
  42. package/dist/assets/{mindmap-definition-NLK3R4M7-DyOdKH03.js → mindmap-definition-NLK3R4M7-DngsWKWx.js} +1 -1
  43. package/dist/assets/{pegDiagram-GJSIUBJH-CIvAV7Do.js → pegDiagram-GJSIUBJH-BhVSGE6P.js} +1 -1
  44. package/dist/assets/{pieDiagram-5QR66LMP-wPi-yl9z.js → pieDiagram-5QR66LMP-C-NQpcBB.js} +1 -1
  45. package/dist/assets/{quadrantDiagram-O4NWA36T-SBFfoKYC.js → quadrantDiagram-O4NWA36T-urAENfOl.js} +1 -1
  46. package/dist/assets/{railroadDiagram-XR7U4H2S-Otwi150n.js → railroadDiagram-XR7U4H2S-BPyCQBVM.js} +1 -1
  47. package/dist/assets/{requirementDiagram-PLB6GJNP-D8He2y9Y.js → requirementDiagram-PLB6GJNP-CZDPK8ow.js} +1 -1
  48. package/dist/assets/{sankeyDiagram-IPEJSGJF-Z39wdwHB.js → sankeyDiagram-IPEJSGJF-BLkmCnNY.js} +1 -1
  49. package/dist/assets/{sequenceDiagram-PO4LG4MO-ELX5hqvT.js → sequenceDiagram-PO4LG4MO-DOnJsutQ.js} +1 -1
  50. package/dist/assets/{sizeCapture-INFHLROL-BDeFl-HY.js → sizeCapture-INFHLROL-BTzltmsq.js} +1 -1
  51. package/dist/assets/{stateDiagram-v2-GCMORJYK-DUbETp8f.js → stateDiagram-v2-GCMORJYK-dMgLAXwt.js} +1 -1
  52. package/dist/assets/{swimlanes-2SLR337P-D3WtSrRL.js → swimlanes-2SLR337P-d_KFeNnI.js} +1 -1
  53. package/dist/assets/swimlanesDiagram-TC7HE7FX-DUtZuLFb.js +8 -0
  54. package/dist/assets/{timeline-definition-EJHVYXUP-C4s78-PG.js → timeline-definition-EJHVYXUP-quo7Si9R.js} +1 -1
  55. package/dist/assets/{usecaseDiagram-POWQR4AR-D6Gf3aB1.js → usecaseDiagram-POWQR4AR-BPt91Frf.js} +1 -1
  56. package/dist/assets/{vennDiagram-UO4OBE2U-RMzQilxk.js → vennDiagram-UO4OBE2U-U_iYVkHo.js} +1 -1
  57. package/dist/assets/{wardleyDiagram-VNRHLVJA-B9YM9a43.js → wardleyDiagram-VNRHLVJA-Se__ees9.js} +1 -1
  58. package/dist/assets/{xychartDiagram-PMCCYNJV-D7GxLZwD.js → xychartDiagram-PMCCYNJV-D4CVeuAX.js} +1 -1
  59. package/dist/index.html +1 -1
  60. package/dist-server/companion/src/routes.js +29 -0
  61. package/dist-server/index.js +38 -5
  62. package/dist-server/openmausbot.js +42258 -42001
  63. package/dist-server/pair-cli.js +42258 -42001
  64. package/dist-server/server/cli-browser.js +42 -0
  65. package/dist-server/server/cli-help.js +4 -0
  66. package/dist-server/server/cli-terminal.js +87 -0
  67. package/dist-server/server/cli.js +12 -45
  68. package/dist-server/server/request-auth.js +2 -1
  69. package/dist-server/server/routes/terminal.js +13 -2
  70. package/dist-server/server/terminal-places.js +3 -2
  71. package/dist-server/server/terminal.js +28 -2
  72. package/package.json +1 -1
  73. package/dist/assets/channel-CCkmsk9Z.js +0 -1
  74. package/dist/assets/swimlanesDiagram-TC7HE7FX-cEw5_whO.js +0 -8
@@ -0,0 +1,42 @@
1
+ const message = (error) => (error instanceof Error ? error.message : String(error));
2
+ export async function runBrowser(options, io) {
3
+ const { browserEngineStatus, describeBrowserEngine, ensureChrome, installAgentBrowserBinary, resolveAgentBrowserBinary } = await import("./browser-engine.js");
4
+ const status = browserEngineStatus({ dataDir: options.dataDir });
5
+ if (options.browserAction === "status") {
6
+ io.log(describeBrowserEngine(status));
7
+ if (status.kind !== "ready" && status.installable)
8
+ io.log("install it with: chibi browser install");
9
+ return status.kind === "ready" ? 0 : 1;
10
+ }
11
+ let binary = resolveAgentBrowserBinary({ dataDir: options.dataDir });
12
+ if (binary) {
13
+ io.log(`agent-browser is already here: ${binary}`);
14
+ }
15
+ else {
16
+ if (status.kind !== "ready" && !status.installable) {
17
+ io.error(status.reason);
18
+ return 1;
19
+ }
20
+ try {
21
+ binary = await installAgentBrowserBinary({ dataDir: options.dataDir, log: io.log });
22
+ }
23
+ catch (error) {
24
+ io.error(`could not install agent-browser: ${message(error)}`);
25
+ return 1;
26
+ }
27
+ io.log(`installed ${binary}`);
28
+ }
29
+ try {
30
+ await ensureChrome(binary, { withDeps: options.withDeps === true, log: io.log });
31
+ }
32
+ catch (error) {
33
+ io.error(`Chrome is not ready: ${message(error)}`);
34
+ if (process.platform === "linux" && !options.withDeps)
35
+ io.error("on Linux, install Chrome's system libraries with `sudo chibi browser install --with-deps`, then retry `chibi browser install` as the user running serve");
36
+ return 1;
37
+ }
38
+ io.log("browser installed for this user and data directory; run serve as the same user, then enable it under Settings → Experimental and per bot");
39
+ if (process.platform === "linux" && options.withDeps)
40
+ io.log("if serve runs as another user, run `chibi browser install` from that user's login shell too");
41
+ return 0;
42
+ }
@@ -16,6 +16,7 @@ export const USAGE = `chibi — your team of AI bots, ready in a few steps
16
16
  chibi access list | add EMAIL [--chat-only] | remove EMAIL
17
17
  chibi service install [--domain HOST | --tunnel | --tailscale] [--port N] [--data-dir DIR] | uninstall
18
18
  chibi browser install [--with-deps] | status
19
+ chibi terminal --bot ID [--place local|vm|cloud] [--thread ID]
19
20
  chibi fleet init --domain HOST [--operator USER] | create NAME --admin EMAIL [--member EMAIL] [--brand FILE]
20
21
  [--anthropic-key-file FILE] [--cap USD] [--license-key KEY] [--memory 1G]
21
22
  | list | users NAME add|remove EMAIL [--chat-only] | suspend NAME | resume NAME
@@ -44,6 +45,9 @@ browser install: the bots' browser engine (agent-browser, pinned) into the
44
45
  the Linux libraries Chrome needs (run as root once). Then run
45
46
  browser install as the user running serve, from that user's home.
46
47
  status: what the current user and data directory have.
48
+ terminal a shell on a bot's computer, like the Computer panel's Terminal
49
+ tab: local (this computer, the default), vm or cloud. Keys go to
50
+ the shell as typed; Ctrl-] closes it.
47
51
  fleet many client workspaces on one Linux server, each its own account,
48
52
  service, data folder, brand, sign-in list and keys at NAME.HOST
49
53
  behind the system Caddy. Plans are printed unless run as root;
@@ -0,0 +1,87 @@
1
+ // `chibi terminal --bot ID [--place vm|cloud|local] [--thread ID]`: the
2
+ // Computer panel's Terminal tab in this terminal, through the running server
3
+ // (server/routes/terminal.ts). Loopback is the owner, so the shell is the
4
+ // desktop's; a service-trust server refuses it like any other caller.
5
+ //
6
+ // Keys go to the shell as typed (raw mode), Ctrl-C included. Ctrl-] closes
7
+ // the shell and returns, as in telnet.
8
+ const CLOSE_KEY = "\x1d";
9
+ const HEADERS = { "content-type": "application/json", "x-openmausbot-cli": "1" };
10
+ export async function runTerminal(options, io) {
11
+ const call = io.fetch ?? fetch;
12
+ const base = `http://127.0.0.1:${options.port}`;
13
+ let opened;
14
+ try {
15
+ opened = await call(`${base}/api/bots/${encodeURIComponent(options.botId)}/terminal`, {
16
+ method: "POST",
17
+ headers: HEADERS,
18
+ body: JSON.stringify({ place: options.place, threadId: options.threadId, cols: io.stdout.columns, rows: io.stdout.rows }),
19
+ });
20
+ }
21
+ catch {
22
+ io.error(`no server answered on port ${options.port}; start it with chibi start`);
23
+ return 1;
24
+ }
25
+ const body = await opened.json().catch(() => ({}));
26
+ if (!opened.ok || !body.id) {
27
+ io.error(body.error ?? `Server returned ${opened.status}`);
28
+ return 1;
29
+ }
30
+ const session = `${base}/api/terminal/${encodeURIComponent(body.id)}`;
31
+ const stream = await call(`${session}/stream`, { headers: HEADERS });
32
+ if (!stream.ok || !stream.body) {
33
+ io.error(`the terminal stream did not open (${stream.status})`);
34
+ return 1;
35
+ }
36
+ const reader = stream.body.getReader();
37
+ // Keystrokes go out one request at a time so they arrive in order.
38
+ let sending = Promise.resolve();
39
+ const onKeys = (chunk) => {
40
+ const data = chunk.toString();
41
+ if (data.includes(CLOSE_KEY)) {
42
+ void reader.cancel();
43
+ return;
44
+ }
45
+ sending = sending.then(() => call(`${session}/input`, { method: "POST", headers: HEADERS, body: JSON.stringify({ data }) }).then(() => undefined, () => undefined));
46
+ };
47
+ const raw = Boolean(io.stdin.isTTY && io.stdin.setRawMode);
48
+ if (raw)
49
+ io.stdin.setRawMode(true);
50
+ io.stdin.on("data", onKeys);
51
+ io.stdin.resume();
52
+ let code = null;
53
+ const decoder = new TextDecoder();
54
+ let pending = "";
55
+ try {
56
+ for (;;) {
57
+ const { done, value } = await reader.read();
58
+ if (done)
59
+ break;
60
+ pending += decoder.decode(value, { stream: true });
61
+ const lines = pending.split("\n");
62
+ pending = lines.pop() ?? "";
63
+ for (const line of lines) {
64
+ // Blank lines are the server's keepalive.
65
+ if (!line.trim())
66
+ continue;
67
+ const event = JSON.parse(line);
68
+ if (event.type === "output" && event.data)
69
+ io.stdout.write(event.data);
70
+ if (event.type === "exit")
71
+ code = event.code ?? 0;
72
+ }
73
+ }
74
+ }
75
+ catch {
76
+ // The stream was cut (Ctrl-], or the server went away); the shell is closed below.
77
+ }
78
+ finally {
79
+ io.stdin.off("data", onKeys);
80
+ if (raw)
81
+ io.stdin.setRawMode(false);
82
+ io.stdin.pause();
83
+ }
84
+ await sending;
85
+ await call(session, { method: "DELETE", headers: HEADERS }).catch(() => undefined);
86
+ return code ?? 0;
87
+ }
@@ -1,4 +1,6 @@
1
1
  import { USAGE } from "./cli-help.js";
2
+ import { runBrowser } from "./cli-browser.js";
3
+ import { runTerminal } from "./cli-terminal.js";
2
4
  export { USAGE } from "./cli-help.js";
3
5
  // `chibi` on the command line: run the server anywhere and pair devices
4
6
  // to it. One implementation for three homes — `npx @chibitek/chibi` (the npm
@@ -50,7 +52,7 @@ import { defaultSetupIo, SetupCancelled } from "./cli-prompts.js";
50
52
  import { normalizePhoneOrigin, phonePairingInstructions, runPhoneSetup } from "./cli-phone-setup.js";
51
53
  import { cleanupTunnelOrigin, createTunnelAccount, createTunnelOrigin, describeTunnelAccount, describeTunnelState, ensureCloudflared, FLEET_CREDENTIAL_ENV, fleetAccess, fleetCredential, guardianEntry, startTunnel, tunnelAccess, } from "./tunnel.js";
52
54
  const HERE = dirname(fileURLToPath(import.meta.url));
53
- export const COMMANDS = ["command", "goal", "setup", "start", "serve", "pair", "sessions", "status", "login", "logout", "access", "service", "browser", "fleet", "help", "--help", "-h"];
55
+ export const COMMANDS = ["command", "goal", "setup", "start", "serve", "pair", "sessions", "status", "login", "logout", "access", "service", "browser", "fleet", "terminal", "help", "--help", "-h"];
54
56
  export function parseArgs(argv, env = process.env) {
55
57
  const implicitStart = !argv.length || (argv[0].startsWith("--") && argv[0] !== "--help");
56
58
  const [command = "start", ...rest] = implicitStart ? ["start", ...argv] : argv;
@@ -79,11 +81,11 @@ export function parseArgs(argv, env = process.env) {
79
81
  return v;
80
82
  };
81
83
  try {
82
- if ((options.command === "command" || options.command === "goal") && arg === "--bot")
84
+ if ((options.command === "command" || options.command === "goal" || options.command === "terminal") && arg === "--bot")
83
85
  options.botId = value();
84
86
  else if ((options.command === "command" || options.command === "goal") && arg === "--group")
85
87
  options.groupId = value();
86
- else if ((options.command === "command" || options.command === "goal") && arg === "--thread")
88
+ else if ((options.command === "command" || options.command === "goal" || options.command === "terminal") && arg === "--thread")
87
89
  options.threadId = value();
88
90
  else if ((options.command === "command" || options.command === "goal") && arg === "--text")
89
91
  options.commandText = value();
@@ -143,6 +145,8 @@ export function parseArgs(argv, env = process.env) {
143
145
  options.browserAction = arg;
144
146
  else if (options.command === "browser" && arg === "--with-deps")
145
147
  options.withDeps = true;
148
+ else if (options.command === "terminal" && arg === "--place")
149
+ options.place = value();
146
150
  else if (options.command === "fleet" && !options.fleetAction && ["init", "create", "list", "users", "suspend", "resume", "delete", "upgrade", "agent"].includes(arg))
147
151
  options.fleetAction = arg;
148
152
  else if (options.command === "fleet" && options.fleetAction && !["init", "list", "upgrade", "agent"].includes(options.fleetAction) && !options.slug && !arg.startsWith("--"))
@@ -205,6 +209,8 @@ export function parseArgs(argv, env = process.env) {
205
209
  return { error: "--local cannot be combined with a remote-access option" };
206
210
  if (options.command === "browser" && !options.browserAction)
207
211
  return { error: "browser needs an action: install or status" };
212
+ if (options.command === "terminal" && (!options.botId || !["vm", "cloud", "local"].includes(options.place ?? "local")))
213
+ return { error: "terminal needs --bot ID, and --place is vm, cloud or local" };
208
214
  if (options.command === "fleet") {
209
215
  if (!options.fleetAction)
210
216
  return { error: "fleet needs one of: init --domain HOST [--operator USER], create NAME --admin EMAIL, list, users NAME add|remove EMAIL, suspend NAME, resume NAME, delete NAME --yes, upgrade, agent" };
@@ -722,47 +728,6 @@ export async function runLogout(options, io = defaultIo()) {
722
728
  io.log(`Signed out ${before.email}${before.address ? `; ${before.address} is released` : ""}.`);
723
729
  return 0;
724
730
  }
725
- export async function runBrowser(options, io = defaultIo()) {
726
- const { browserEngineStatus, describeBrowserEngine, ensureChrome, installAgentBrowserBinary, resolveAgentBrowserBinary } = await import("./browser-engine.js");
727
- const status = browserEngineStatus({ dataDir: options.dataDir });
728
- if (options.browserAction === "status") {
729
- io.log(describeBrowserEngine(status));
730
- if (status.kind !== "ready" && status.installable)
731
- io.log("install it with: chibi browser install");
732
- return status.kind === "ready" ? 0 : 1;
733
- }
734
- let binary = resolveAgentBrowserBinary({ dataDir: options.dataDir });
735
- if (binary) {
736
- io.log(`agent-browser is already here: ${binary}`);
737
- }
738
- else {
739
- if (status.kind !== "ready" && !status.installable) {
740
- io.error(status.reason);
741
- return 1;
742
- }
743
- try {
744
- binary = await installAgentBrowserBinary({ dataDir: options.dataDir, log: io.log });
745
- }
746
- catch (error) {
747
- io.error(`could not install agent-browser: ${message(error)}`);
748
- return 1;
749
- }
750
- io.log(`installed ${binary}`);
751
- }
752
- try {
753
- await ensureChrome(binary, { withDeps: options.withDeps === true, log: io.log });
754
- }
755
- catch (error) {
756
- io.error(`Chrome is not ready: ${message(error)}`);
757
- if (process.platform === "linux" && !options.withDeps)
758
- io.error("on Linux, install Chrome's system libraries with `sudo chibi browser install --with-deps`, then retry `chibi browser install` as the user running serve");
759
- return 1;
760
- }
761
- io.log("browser installed for this user and data directory; run serve as the same user, then enable it under Settings → Experimental and per bot");
762
- if (process.platform === "linux" && options.withDeps)
763
- io.log("if serve runs as another user, run `chibi browser install` from that user's login shell too");
764
- return 0;
765
- }
766
731
  /** Where the server bundle lives relative to this file: next to it in the
767
732
  * npm package and the image (dist-server/), or the TypeScript source in a
768
733
  * checkout. */
@@ -1260,7 +1225,9 @@ export async function main(argv = process.argv.slice(2)) {
1260
1225
  case "logout":
1261
1226
  return runLogout(options);
1262
1227
  case "browser":
1263
- return runBrowser(options);
1228
+ return runBrowser(options, defaultIo());
1229
+ case "terminal":
1230
+ return runTerminal({ port: options.port, botId: options.botId, place: options.place ?? "local", threadId: options.threadId }, { stdin: process.stdin, stdout: process.stdout, error: (line) => console.error(line) });
1264
1231
  default:
1265
1232
  console.log(USAGE);
1266
1233
  return 0;
@@ -471,7 +471,8 @@ export function resolveRequestAuth(req, options) {
471
471
  !/^[\w-]{1,128}$/.test(headerValue(req.headers["x-openmausbot-companion-device"]) ?? "") ||
472
472
  companionDenial({ path, method, authenticated: true }))
473
473
  return deny(403, "forbidden: invalid companion request");
474
- return { auth: { kind: "loopback", scopes: LOOPBACK_SCOPES }, status: 401, error: "" };
474
+ const device = headerValue(req.headers["x-openmausbot-companion-device"]);
475
+ return { auth: { kind: "loopback", scopes: LOOPBACK_SCOPES, device }, status: 401, error: "" };
475
476
  }
476
477
  if (options.loopbackMutationToken !== undefined &&
477
478
  mutatingPublicRoute(method, path) &&
@@ -1,12 +1,16 @@
1
1
  import { clampSize } from "../terminal.js";
2
2
  import { PASS } from "./table.js";
3
+ /** Under the 90-second idle timeout the phone's stream session uses. */
4
+ const KEEPALIVE_MS = 25_000;
3
5
  const owner = (auth) => {
4
6
  if (!auth.scopes.includes("admin"))
5
7
  return null;
6
8
  if (auth.kind === "session")
7
9
  return `session:${auth.session.id}`;
10
+ // A paired phone reaches the server through the companion as a loopback
11
+ // owner; its shells are its own, not the desktop's or another phone's.
8
12
  if (auth.kind === "loopback" && auth.trust !== "service")
9
- return "desktop";
13
+ return auth.device ? `companion:${auth.device}` : "desktop";
10
14
  return null;
11
15
  };
12
16
  export function createTerminalRoutes(deps) {
@@ -47,12 +51,19 @@ export function createTerminalRoutes(deps) {
47
51
  return json(res, 405, { error: "method not allowed" });
48
52
  res.writeHead(200, { "content-type": "application/x-ndjson", "cache-control": "no-cache", "x-accel-buffering": "no" });
49
53
  req.socket.setTimeout(0);
54
+ // A blank line every so often keeps a quiet shell's stream from looking
55
+ // dead to a phone's idle timeout; readers skip empty lines.
56
+ const keepalive = setInterval(() => res.write("\n"), KEEPALIVE_MS);
57
+ keepalive.unref?.();
50
58
  const unsubscribe = live.subscribe((event) => {
51
59
  res.write(`${JSON.stringify(event)}\n`);
52
60
  if (event.type === "exit")
53
61
  res.end();
54
62
  });
55
- res.on("close", unsubscribe);
63
+ res.on("close", () => {
64
+ clearInterval(keepalive);
65
+ unsubscribe();
66
+ });
56
67
  return;
57
68
  }
58
69
  if (action === "input") {
@@ -10,7 +10,7 @@ import { createTerminalRoutes } from "./routes/terminal.js";
10
10
  import { TerminalRegistry, sizedShell } from "./terminal.js";
11
11
  import * as vps from "./vps-computer.js";
12
12
  import { prepareVpsSsh } from "./vps-ssh.js";
13
- import { ensureTaskWorkspace, workspaceDir } from "./workspace.js";
13
+ import { ensureTaskWorkspace, ensureWorkspace } from "./workspace.js";
14
14
  /** Terminal tab (docs/computer-terminal.md): on unless Settings > Experimental turns it off. */
15
15
  export function terminalEnabled(cfg) {
16
16
  return cfg.features?.terminal !== false;
@@ -55,7 +55,8 @@ export async function terminalSpec(deps, botId, place, threadId, { cols, rows },
55
55
  }
56
56
  if (!localTerminalEnabled(cfg))
57
57
  throw refuse(403, "Turn on the shell on this computer in Settings > Experimental");
58
- const cwd = threadId ? ensureTaskWorkspace(botId, threadId) : workspaceDir(botId);
58
+ // A bot that has not run yet has no workspace folder, and a shell cannot start in one that is missing.
59
+ const cwd = threadId ? ensureTaskWorkspace(botId, threadId) : ensureWorkspace(botId);
59
60
  if (platform === "win32")
60
61
  return { command: "powershell.exe", args: ["-NoLogo"], cwd, cols, rows, label: "This computer" };
61
62
  const shell = process.env.SHELL || (platform === "darwin" ? "/bin/zsh" : "/bin/bash");
@@ -10,6 +10,11 @@ import { randomUUID } from "node:crypto";
10
10
  import { StringDecoder } from "node:string_decoder";
11
11
  const REPLAY_CAP = 64 * 1024;
12
12
  export const MAX_SESSIONS = 8;
13
+ /** A shell nobody is watching closes after this long. A phone that is put
14
+ * away, killed or loses its connection never sends the close, and without
15
+ * this its shells would hold slots until the server restarts. Reattaching
16
+ * inside the window gets the replay and the same shell back. */
17
+ export const DETACHED_CLOSE_MS = 10 * 60_000;
13
18
  /** The argv that gives `spec.command` a real terminal on this platform. On
14
19
  * Windows there is none: the shell talks over pipes (no colours, no cursor
15
20
  * keys; a line console). */
@@ -38,8 +43,10 @@ export function clampSize(value, fallback) {
38
43
  export class TerminalRegistry {
39
44
  sessions = new Map();
40
45
  platform;
41
- constructor(platform = process.platform) {
46
+ detachedCloseMs;
47
+ constructor(platform = process.platform, detachedCloseMs = DETACHED_CLOSE_MS) {
42
48
  this.platform = platform;
49
+ this.detachedCloseMs = detachedCloseMs;
43
50
  }
44
51
  get size() {
45
52
  return this.sessions.size;
@@ -60,6 +67,18 @@ export class TerminalRegistry {
60
67
  const id = randomUUID();
61
68
  const listeners = new Set();
62
69
  let replay = "";
70
+ let detached = null;
71
+ const watchDetached = () => {
72
+ if (detached || listeners.size)
73
+ return;
74
+ detached = setTimeout(() => session.close(), this.detachedCloseMs);
75
+ detached.unref?.();
76
+ };
77
+ const attached = () => {
78
+ if (detached)
79
+ clearTimeout(detached);
80
+ detached = null;
81
+ };
63
82
  const emit = (event) => {
64
83
  if (event.type === "output")
65
84
  replay = (replay + event.data).slice(-REPLAY_CAP);
@@ -97,12 +116,18 @@ export class TerminalRegistry {
97
116
  return () => { };
98
117
  }
99
118
  listeners.add(listener);
100
- return () => { listeners.delete(listener); };
119
+ attached();
120
+ return () => {
121
+ listeners.delete(listener);
122
+ if (!session.exited)
123
+ watchDetached();
124
+ };
101
125
  },
102
126
  };
103
127
  const finish = (code, signal) => {
104
128
  if (session.exited)
105
129
  return;
130
+ attached();
106
131
  session.exited = { code, signal };
107
132
  child.stdin?.end();
108
133
  emit({ type: "exit", code, signal });
@@ -115,6 +140,7 @@ export class TerminalRegistry {
115
140
  });
116
141
  child.on("exit", finish);
117
142
  this.sessions.set(id, session);
143
+ watchDetached();
118
144
  return session;
119
145
  }
120
146
  closeAll() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chibitek/chibi",
3
- "version": "0.1.195",
3
+ "version": "0.1.196",
4
4
  "description": "Atomic by Chibitek: run your AI team's server anywhere and pair your devices to it",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -1 +0,0 @@
1
- import{U as a,C as n}from"./mermaid.core-s9HcmFG6.js";const t=(r,o)=>a.lang.round(n.parse(r)[o]);export{t as c};
@@ -1,8 +0,0 @@
1
- import{c as r,s as e}from"./flowDiagram-KWPJA3E3-RrANAUuT.js";import{_ as a}from"./mermaid.core-s9HcmFG6.js";import"./chunk-5VM5RSS4-BWgviAjX.js";import"./chunk-XXDRQBXY-C4vdFU17.js";import"./chunk-WEXAMYUT-srnz312I.js";import"./chunk-GWA4HPMP-RV94Cbaa.js";import"./channel-CCkmsk9Z.js";import"./index-DQQGKX5x.js";var o=a(t=>`${e(t)}
2
- .swimlane.cluster:not([data-color-id]) rect {
3
- stroke: ${t.clusterBorder} !important;
4
- }
5
- [data-look="neo"].cluster rect {
6
- filter: none;
7
- }
8
- `,"getStyles"),s=o,u=r({styles:s});export{u as diagram};