@chibitek/chibi 0.1.190 → 0.1.192
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/assets/TerminalPanel-DFuMZ0ql.css +1 -0
- package/dist/assets/TerminalPanel-PcPGVxjJ.js +10 -0
- package/dist/assets/{abnfDiagram-O67JEVCF-Bz3wlNsQ.js → abnfDiagram-O67JEVCF-CrdtKXgW.js} +1 -1
- package/dist/assets/{arc-CX0dJSa0.js → arc-DZp6zTLS.js} +1 -1
- package/dist/assets/{architectureDiagram-NJMV4G6O-APIM9yGf.js → architectureDiagram-NJMV4G6O-By4YaF8p.js} +1 -1
- package/dist/assets/{blockDiagram-BEXU5L5S-DNmNNaVY.js → blockDiagram-BEXU5L5S-b9XT0BEX.js} +1 -1
- package/dist/assets/{c4Diagram-YGBWAQC7-CAPPUeMU.js → c4Diagram-YGBWAQC7-ClDc6UCa.js} +1 -1
- package/dist/assets/channel-CP6zTF5h.js +1 -0
- package/dist/assets/{chunk-2Q5K7J3B-DfCDsQgU.js → chunk-2Q5K7J3B-D8FDC39i.js} +1 -1
- package/dist/assets/{chunk-3FUC2YCW-vdffwGmy.js → chunk-3FUC2YCW-_Lb0IVFX.js} +2 -2
- package/dist/assets/{chunk-5VM5RSS4-BazIL_2e.js → chunk-5VM5RSS4-f7re7-dy.js} +1 -1
- package/dist/assets/{chunk-GTNCS2PH-GpKjNZ-V.js → chunk-GTNCS2PH-Cl4oAWQ1.js} +1 -1
- package/dist/assets/{chunk-GWA4HPMP-BuRq21LZ.js → chunk-GWA4HPMP-CLO3k8zE.js} +1 -1
- package/dist/assets/{chunk-JWPE2WC7-CqNGOyHV.js → chunk-JWPE2WC7-kXWDfQP-.js} +1 -1
- package/dist/assets/{chunk-NETBCI7D-B1DpzVCP.js → chunk-NETBCI7D-DPtewwHN.js} +1 -1
- package/dist/assets/{chunk-WEXAMYUT-DcH1Euc6.js → chunk-WEXAMYUT-B17lA9FX.js} +1 -1
- package/dist/assets/{chunk-XXDRQBXY-M1JLd_cm.js → chunk-XXDRQBXY-B6RbRjkG.js} +1 -1
- package/dist/assets/{classDiagram-v2-NBCMYWYE-C8mBZ7i2.js → classDiagram-v2-NBCMYWYE-BrZPolTO.js} +1 -1
- package/dist/assets/{cose-bilkent-JH36ORCC-Cr3TqHDz.js → cose-bilkent-JH36ORCC-DAvSQrfJ.js} +1 -1
- package/dist/assets/{cynefin-OW5HDTMX-BKPr6l0I.js → cynefin-OW5HDTMX-BBEKoW-B.js} +1 -1
- package/dist/assets/{cynefinDiagram-VND7K2PF-Cbg5mrIM.js → cynefinDiagram-VND7K2PF-DTeD9b7A.js} +1 -1
- package/dist/assets/{dagre-6A5THRUB-9I9X1J3r.js → dagre-6A5THRUB-7Lem_oJB.js} +1 -1
- package/dist/assets/{diagram-22UHCM2B-B43b8pqQ.js → diagram-22UHCM2B-BBMu1DQ4.js} +1 -1
- package/dist/assets/{diagram-3UASUU5V-CIehgEkZ.js → diagram-3UASUU5V-wTBd45sT.js} +1 -1
- package/dist/assets/{diagram-ATOU4E4O-gx8nkXLZ.js → diagram-ATOU4E4O-DejXVMcb.js} +1 -1
- package/dist/assets/{diagram-CDSNMT55-BZzWgYHa.js → diagram-CDSNMT55-CqYId1m8.js} +1 -1
- package/dist/assets/{diagram-MLGK6HIB-BqoCqkZD.js → diagram-MLGK6HIB-DrOnQ-Zt.js} +1 -1
- package/dist/assets/{diagram-MPIPVDR6-Bsc7x0UT.js → diagram-MPIPVDR6-CHDvidFk.js} +1 -1
- package/dist/assets/{ebnfDiagram-ZINNZB2B-8HjdD_s8.js → ebnfDiagram-ZINNZB2B-BzwpPn5m.js} +1 -1
- package/dist/assets/{elk-276RUBZZ-bmxiEFtT.js → elk-276RUBZZ-E1HDqzYH.js} +1 -1
- package/dist/assets/{erDiagram-OPXOYQCR-BU-sRLe3.js → erDiagram-OPXOYQCR-D5E6uaT3.js} +1 -1
- package/dist/assets/{flowDiagram-KWPJA3E3-D45vn40U.js → flowDiagram-KWPJA3E3-R1exlkB4.js} +1 -1
- package/dist/assets/{ganttDiagram-FUAMR5RP-CArB98Hu.js → ganttDiagram-FUAMR5RP-B5kjMGRd.js} +1 -1
- package/dist/assets/{gitGraphDiagram-X574FWY7-fPB1k-W7.js → gitGraphDiagram-X574FWY7-BqkJtDvq.js} +1 -1
- package/dist/assets/index-DBOyvapT.css +1 -0
- package/dist/assets/{index-QsXeEMxJ.js → index-D_WPT1i-.js} +172 -171
- package/dist/assets/{index-u1wvoacp.js → index-DvEhLbPJ.js} +1 -1
- package/dist/assets/{infoDiagram-VRGFBTTK-ZRVWXAr4.js → infoDiagram-VRGFBTTK-LXwGqqoO.js} +1 -1
- package/dist/assets/{ishikawaDiagram-OU5B5YK6-DOaurRbX.js → ishikawaDiagram-OU5B5YK6-D_E17iEV.js} +1 -1
- package/dist/assets/{journeyDiagram-ZHPQQLJL-Ca9B-09w.js → journeyDiagram-ZHPQQLJL-BkKKJrLR.js} +1 -1
- package/dist/assets/{kanban-definition-PNTS6WVX-CA2XswEJ.js → kanban-definition-PNTS6WVX-y6rjCvyW.js} +1 -1
- package/dist/assets/{linear-B-F7icip.js → linear-BYdFcAFG.js} +1 -1
- package/dist/assets/{mermaid.core-ymtCpbZ5.js → mermaid.core-BZnTzEV7.js} +5 -5
- package/dist/assets/{mindmap-definition-NLK3R4M7-02vIazCi.js → mindmap-definition-NLK3R4M7-HPM-ymN0.js} +1 -1
- package/dist/assets/{pegDiagram-GJSIUBJH-DRb7Pn72.js → pegDiagram-GJSIUBJH-X2YHQQDC.js} +1 -1
- package/dist/assets/{pieDiagram-5QR66LMP-B2YwP3S_.js → pieDiagram-5QR66LMP-FQ47RvEb.js} +1 -1
- package/dist/assets/{quadrantDiagram-O4NWA36T-CbR573mu.js → quadrantDiagram-O4NWA36T-CZok45i-.js} +1 -1
- package/dist/assets/{railroadDiagram-XR7U4H2S-CqHuDCnM.js → railroadDiagram-XR7U4H2S-CkzgSbiA.js} +1 -1
- package/dist/assets/{requirementDiagram-PLB6GJNP-BSeC-H1j.js → requirementDiagram-PLB6GJNP-B96vOB2k.js} +1 -1
- package/dist/assets/{sankeyDiagram-IPEJSGJF-BMFuhoh1.js → sankeyDiagram-IPEJSGJF-C3OzzNBk.js} +1 -1
- package/dist/assets/{sequenceDiagram-PO4LG4MO-DRT_EI9u.js → sequenceDiagram-PO4LG4MO-UEjwqc9C.js} +1 -1
- package/dist/assets/{sizeCapture-INFHLROL-BLFT4fV7.js → sizeCapture-INFHLROL-CYlsATAn.js} +1 -1
- package/dist/assets/{stateDiagram-v2-GCMORJYK-C8vB_69H.js → stateDiagram-v2-GCMORJYK-i3kPrA1F.js} +1 -1
- package/dist/assets/{swimlanes-2SLR337P-T6BBolT8.js → swimlanes-2SLR337P-CwxGl-A-.js} +1 -1
- package/dist/assets/swimlanesDiagram-TC7HE7FX-BxG6JDb-.js +8 -0
- package/dist/assets/{timeline-definition-EJHVYXUP-DjdjBRQV.js → timeline-definition-EJHVYXUP-B-CIp72A.js} +1 -1
- package/dist/assets/{usecaseDiagram-POWQR4AR-CDGccZMN.js → usecaseDiagram-POWQR4AR-CvI2j7z-.js} +1 -1
- package/dist/assets/{vennDiagram-UO4OBE2U-CgYSihtW.js → vennDiagram-UO4OBE2U--l2Nr666.js} +1 -1
- package/dist/assets/{wardleyDiagram-VNRHLVJA-Bub5ScM8.js → wardleyDiagram-VNRHLVJA-C_WERxNO.js} +1 -1
- package/dist/assets/{xychartDiagram-PMCCYNJV-DK5iMX67.js → xychartDiagram-PMCCYNJV-VoRUD4V6.js} +1 -1
- package/dist/index.html +2 -2
- package/dist-server/container-mcp.js +84 -81
- package/dist-server/drivers/agents-proxy.js +81 -81
- package/dist-server/index.js +2115 -1577
- package/dist-server/openmausbot.js +611 -606
- package/dist-server/pair-cli.js +611 -606
- package/dist-server/server/config.js +1 -1
- package/dist-server/server/engine-failover.js +20 -7
- package/dist-server/server/engine-failure.js +5 -5
- package/dist-server/server/engine-tiers.js +12 -42
- package/dist-server/server/hermes-reply-failure.js +27 -0
- package/dist-server/server/index.js +26 -23
- package/dist-server/server/ladder-order.js +74 -0
- package/dist-server/server/model-levels/chibitek-rankings.js +8 -3
- package/dist-server/server/model-levels/index.js +3 -0
- package/dist-server/server/nexus-memory/backoff.js +68 -0
- package/dist-server/server/nexus-memory/client.js +55 -11
- package/dist-server/server/nexus-memory/index.js +6 -29
- package/dist-server/server/paw/nexus-sync.js +160 -0
- package/dist-server/server/paw/service.js +25 -3
- package/dist-server/server/paw/sync.js +19 -30
- package/dist-server/server/remote-desktop.js +1 -0
- package/dist-server/server/routes/terminal.js +72 -0
- package/dist-server/server/terminal-places.js +63 -0
- package/dist-server/server/terminal.js +124 -0
- package/dist-server/server/vault/store.js +8 -4
- package/dist-server/shared/approval-mode.js +12 -2
- package/dist-server/shared/engine-choices.js +14 -0
- package/dist-server/shared/engine-tiers.js +14 -8
- package/dist-server/shared/harness-weights.js +33 -0
- package/dist-server/shared/vault-api-providers.js +16 -2
- package/dist-server/shared/vault.js +3 -2
- package/dist-server/vps-container-mcp.js +84 -81
- package/package.json +1 -1
- package/skills/build-paw/SKILL.md +53 -0
- package/skills/build-paw/VENDORED.md +4 -0
- package/skills/build-paw/manifest.json +10 -2
- package/skills/build-paw/references/roles.md +134 -0
- package/skills/build-paw/references/wiring.md +77 -0
- package/dist/assets/channel-CnfDal05.js +0 -1
- package/dist/assets/index-CI0vGAif.css +0 -1
- package/dist/assets/swimlanesDiagram-TC7HE7FX-BIY4fGCv.js +0 -8
- package/dist-server/server/session-fallback.js +0 -76
- package/skills/icm-workspace-builder/SKILL.md +0 -154
- package/skills/icm-workspace-builder/VENDORED.md +0 -14
- package/skills/icm-workspace-builder/manifest.json +0 -15
- package/skills/icm-workspace-builder/references/interview.md +0 -39
- package/skills/icm-workspace-builder/references/templates.md +0 -147
- package/skills/icm-workspace-builder/references/wiring.md +0 -69
|
@@ -17,6 +17,13 @@ export class NexusUnavailableError extends Error {
|
|
|
17
17
|
this.name = "NexusUnavailableError";
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
+
/** The MCP initialize handshake failed. One of these is retried; the next trips the breaker. */
|
|
21
|
+
export class NexusInitializeError extends NexusUnavailableError {
|
|
22
|
+
constructor(message) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.name = "NexusInitializeError";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
20
27
|
/** Nexus answered and refused this call (bad input): retrying will not help. */
|
|
21
28
|
export class NexusRejectedError extends Error {
|
|
22
29
|
constructor(message) {
|
|
@@ -29,6 +36,18 @@ const PROTOCOL_VERSION = "2025-06-18";
|
|
|
29
36
|
/** Messages that mean "try again later", not "this input is wrong". */
|
|
30
37
|
const PRIVATE_SCOPE_ANSWER = /\b(?:private_scope_\w+|private_proof_invalid|personal_scope_requires_private_bot|personal_memory_cannot_be_shared)\b/;
|
|
31
38
|
const TRANSIENT = /unauthori[sz]ed|sign ?in|token|timed? ?out|timeout|ECONN|ENOTFOUND|EAI_AGAIN|fetch failed|network|socket|503|502|504|429|temporar|unavailable|not provisioned/i;
|
|
39
|
+
const BRIDGE_URL = /https?:\/\/[^\s"'<>]+/gi;
|
|
40
|
+
const BRIDGE_SECRET = /\b(bearer|token|access_token|refresh_token|id_token|authorization|client_secret|api[_-]?key|password|code)\b(\s*[:=]\s*)\S+/gi;
|
|
41
|
+
const BRIDGE_JWT = /\beyJ[A-Za-z0-9_-]{8,}(?:\.[A-Za-z0-9_-]{8,}){2}\b/g;
|
|
42
|
+
/** Bridge stderr, safe to log: no URLs, tokens, or sign-in links. */
|
|
43
|
+
function redactBridgeLine(line) {
|
|
44
|
+
return line
|
|
45
|
+
.replace(BRIDGE_URL, "[url]")
|
|
46
|
+
.replace(BRIDGE_SECRET, "$1$2[redacted]")
|
|
47
|
+
.replace(BRIDGE_JWT, "[jwt]")
|
|
48
|
+
.trim()
|
|
49
|
+
.slice(0, 240);
|
|
50
|
+
}
|
|
32
51
|
function isRecord(value) {
|
|
33
52
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
34
53
|
}
|
|
@@ -69,12 +88,18 @@ class HttpNexusClient {
|
|
|
69
88
|
connect(signal) {
|
|
70
89
|
this.ready ??= (async () => {
|
|
71
90
|
const client = new RemoteMcpClient(this.spec);
|
|
72
|
-
|
|
91
|
+
try {
|
|
92
|
+
await client.initialize("Atomic Nexus writeback", signal);
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
await client.close().catch(() => undefined);
|
|
96
|
+
throw new NexusInitializeError(error instanceof Error ? error.message : "Nexus initialize failed");
|
|
97
|
+
}
|
|
73
98
|
this.client = client;
|
|
74
99
|
return client;
|
|
75
100
|
})().catch((error) => {
|
|
76
101
|
this.ready = null;
|
|
77
|
-
throw error;
|
|
102
|
+
throw error instanceof NexusInitializeError ? error : new NexusInitializeError(error instanceof Error ? error.message : "Nexus initialize failed");
|
|
78
103
|
});
|
|
79
104
|
return this.ready;
|
|
80
105
|
}
|
|
@@ -115,8 +140,10 @@ class StdioNexusClient {
|
|
|
115
140
|
idle;
|
|
116
141
|
spec;
|
|
117
142
|
idleMs;
|
|
118
|
-
|
|
143
|
+
log;
|
|
144
|
+
constructor(spec, log, idleMs = 60_000) {
|
|
119
145
|
this.spec = spec;
|
|
146
|
+
this.log = log;
|
|
120
147
|
this.idleMs = idleMs;
|
|
121
148
|
}
|
|
122
149
|
env() {
|
|
@@ -196,19 +223,36 @@ class StdioNexusClient {
|
|
|
196
223
|
entry.resolve(frame.result);
|
|
197
224
|
});
|
|
198
225
|
child.stdout.on("data", (chunk) => splitter.push(chunk));
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
226
|
+
let logged = 0;
|
|
227
|
+
let handshook = false;
|
|
228
|
+
const errSplit = createLineSplitter((line) => {
|
|
229
|
+
const redacted = redactBridgeLine(line);
|
|
230
|
+
// ponytail: 20 lines per child; raise if a handshake needs more of the log
|
|
231
|
+
if (!redacted || logged >= 20)
|
|
232
|
+
return;
|
|
233
|
+
logged += 1;
|
|
234
|
+
this.log?.(`bridge: ${redacted}`);
|
|
235
|
+
});
|
|
236
|
+
child.stderr.on("data", (chunk) => errSplit.push(chunk));
|
|
237
|
+
const gone = (message) => {
|
|
238
|
+
errSplit.flush();
|
|
239
|
+
if (this.child !== child)
|
|
240
|
+
return;
|
|
241
|
+
this.fail(handshook ? new NexusUnavailableError(message) : new NexusInitializeError(message));
|
|
242
|
+
};
|
|
243
|
+
child.once("error", () => gone("Nexus bridge failed"));
|
|
244
|
+
child.once("close", () => gone("Nexus bridge stopped"));
|
|
203
245
|
await this.send("initialize", {
|
|
204
246
|
protocolVersion: PROTOCOL_VERSION,
|
|
205
247
|
capabilities: {},
|
|
206
248
|
clientInfo: { name: "Atomic Nexus writeback", version: "1" },
|
|
207
249
|
}, timeoutMs);
|
|
208
250
|
child.stdin.write(`${JSON.stringify({ jsonrpc: "2.0", method: "notifications/initialized" })}\n`);
|
|
251
|
+
handshook = true;
|
|
209
252
|
})().catch((error) => {
|
|
210
|
-
|
|
211
|
-
|
|
253
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
254
|
+
this.fail(error instanceof Error ? error : new Error(message));
|
|
255
|
+
throw error instanceof NexusInitializeError ? error : new NexusInitializeError(message);
|
|
212
256
|
});
|
|
213
257
|
return this.ready;
|
|
214
258
|
}
|
|
@@ -231,8 +275,8 @@ class StdioNexusClient {
|
|
|
231
275
|
}
|
|
232
276
|
}
|
|
233
277
|
/** A client for the configured `nexus` MCP server, or null when there is none. */
|
|
234
|
-
export function nexusClientFor(spec) {
|
|
278
|
+
export function nexusClientFor(spec, log) {
|
|
235
279
|
if (!spec)
|
|
236
280
|
return null;
|
|
237
|
-
return isRemoteMcpServer(spec) ? new HttpNexusClient(spec) : new StdioNexusClient(spec);
|
|
281
|
+
return isRemoteMcpServer(spec) ? new HttpNexusClient(spec) : new StdioNexusClient(spec, log);
|
|
238
282
|
}
|
|
@@ -29,6 +29,7 @@ import { existsSync, mkdirSync, readFileSync, statSync } from "node:fs";
|
|
|
29
29
|
import { basename, dirname, isAbsolute, join, resolve } from "node:path";
|
|
30
30
|
import { writeFileAtomic } from "../atomic.js";
|
|
31
31
|
import { customMcpServers } from "../config.js";
|
|
32
|
+
import { guardNexusClient, UnavailableBackoff } from "./backoff.js";
|
|
32
33
|
import { nexusClientFor, NexusRejectedError, NexusUnavailableError } from "./client.js";
|
|
33
34
|
import { buildSessionOutcome, promptText } from "./outcome.js";
|
|
34
35
|
import { NexusOutbox } from "./outbox.js";
|
|
@@ -62,7 +63,6 @@ const DOC_MAX_BYTES = 10 * MB;
|
|
|
62
63
|
const READBACK_TTL_MS = 10 * 60_000;
|
|
63
64
|
const READBACK_TIMEOUT_MS = 2_500;
|
|
64
65
|
const LOCAL_NOTE_MAX_CHARS = 24_000;
|
|
65
|
-
const UNAVAILABLE_BACKOFF_MS = [60_000, 300_000, 900_000, 1_800_000];
|
|
66
66
|
/**
|
|
67
67
|
* Whose Nexus a message belongs to. Nexus writes go to the person signed in
|
|
68
68
|
* on this computer's bridge. A message from someone else on a shared
|
|
@@ -109,8 +109,7 @@ export class NexusMemory {
|
|
|
109
109
|
readBackCache = new Map();
|
|
110
110
|
client = null;
|
|
111
111
|
clientKey = "";
|
|
112
|
-
|
|
113
|
-
unavailableFailures = 0;
|
|
112
|
+
backoff = new UnavailableBackoff();
|
|
114
113
|
timer;
|
|
115
114
|
stopped = true;
|
|
116
115
|
now;
|
|
@@ -176,39 +175,17 @@ export class NexusMemory {
|
|
|
176
175
|
const key = JSON.stringify(spec ?? null);
|
|
177
176
|
if (key !== this.clientKey) {
|
|
178
177
|
void this.client?.close();
|
|
179
|
-
this.client = nexusClientFor(spec);
|
|
178
|
+
this.client = nexusClientFor(spec, (message) => this.log(message));
|
|
180
179
|
this.clientKey = key;
|
|
181
180
|
}
|
|
182
181
|
return this.client;
|
|
183
182
|
}
|
|
184
|
-
/** The client behind one shared back-off
|
|
185
|
-
* the person is signed out, which makes the bridge open a sign-in page),
|
|
186
|
-
* nothing calls it again until the wait is over — 1, 5, 15, then 30
|
|
187
|
-
* minutes. Writes keep queuing on disk meanwhile. */
|
|
183
|
+
/** The client behind one shared back-off (see backoff.ts). */
|
|
188
184
|
getClient() {
|
|
189
185
|
const client = this.rawClient();
|
|
190
186
|
if (!client)
|
|
191
187
|
return null;
|
|
192
|
-
return
|
|
193
|
-
call: async (tool, args, timeoutMs) => {
|
|
194
|
-
if (this.now() < this.unavailableUntil)
|
|
195
|
-
throw new NexusUnavailableError("waiting before trying Nexus again");
|
|
196
|
-
try {
|
|
197
|
-
const result = await client.call(tool, args, timeoutMs);
|
|
198
|
-
this.unavailableFailures = 0;
|
|
199
|
-
this.unavailableUntil = 0;
|
|
200
|
-
return result;
|
|
201
|
-
}
|
|
202
|
-
catch (error) {
|
|
203
|
-
if (error instanceof NexusUnavailableError) {
|
|
204
|
-
this.unavailableFailures += 1;
|
|
205
|
-
this.unavailableUntil = this.now() + UNAVAILABLE_BACKOFF_MS[Math.min(this.unavailableFailures - 1, UNAVAILABLE_BACKOFF_MS.length - 1)];
|
|
206
|
-
}
|
|
207
|
-
throw error;
|
|
208
|
-
}
|
|
209
|
-
},
|
|
210
|
-
close: () => client.close(),
|
|
211
|
-
};
|
|
188
|
+
return guardNexusClient(client, this.backoff, this.now, this.log);
|
|
212
189
|
}
|
|
213
190
|
// ── the Private Bot's signed calls ─────────────────────────────────────
|
|
214
191
|
privateKey() {
|
|
@@ -530,7 +507,7 @@ export class NexusMemory {
|
|
|
530
507
|
const due = outboxDue === null ? notesDue : notesDue === null ? outboxDue : Math.min(outboxDue, notesDue);
|
|
531
508
|
if (due === null)
|
|
532
509
|
return;
|
|
533
|
-
const wait = Math.max(delayMs ?? Math.max(0, due - this.now()), this.
|
|
510
|
+
const wait = Math.max(delayMs ?? Math.max(0, due - this.now()), this.backoff.remainingMs(this.now()), 0);
|
|
534
511
|
this.timer = setTimeout(() => {
|
|
535
512
|
void this.flush().finally(() => this.kick());
|
|
536
513
|
}, wait);
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
// PAW sync with Nexus (the paw_pull and paw_push tools, chibitek/nexus
|
|
2
|
+
// src/paw). The folder on this computer stays the working copy; Nexus holds
|
|
3
|
+
// the copy every computer syncs to.
|
|
4
|
+
//
|
|
5
|
+
// Shared layers (paw.yaml, org/, departments/): pulled, read-only here.
|
|
6
|
+
// The person's layer (me/, never me/personal/): two-way. What decides each
|
|
7
|
+
// file is what changed since the last sync: only here (push), only in Nexus
|
|
8
|
+
// (take it), or both (keep this computer's text, and save Nexus's beside it
|
|
9
|
+
// as "<name>.nexus-copy.md"). A file this computer has never synced takes
|
|
10
|
+
// Nexus's text, with what was written here kept as "<name>.local-copy.md".
|
|
11
|
+
// Either way nothing is lost.
|
|
12
|
+
import { createHash } from "node:crypto";
|
|
13
|
+
import { rmSync } from "node:fs";
|
|
14
|
+
import { join } from "node:path";
|
|
15
|
+
import { looksLikeSecret } from "./change-requests.js";
|
|
16
|
+
import { PAW_MANIFEST_FILE } from "./manifest.js";
|
|
17
|
+
import { writeText } from "./workspace.js";
|
|
18
|
+
const PUSH_BATCH = 200;
|
|
19
|
+
const MAX_PULL_ROUNDS = 50;
|
|
20
|
+
const sha256 = (text) => createHash("sha256").update(text, "utf8").digest("hex");
|
|
21
|
+
function remoteFiles(value) {
|
|
22
|
+
if (!Array.isArray(value))
|
|
23
|
+
return [];
|
|
24
|
+
return value.flatMap((entry) => {
|
|
25
|
+
const file = entry;
|
|
26
|
+
if (!file || typeof file.path !== "string" || typeof file.sha256 !== "string" || typeof file.version !== "number")
|
|
27
|
+
return [];
|
|
28
|
+
return [{
|
|
29
|
+
path: file.path, layer: String(file.layer ?? ""), sha256: file.sha256, version: file.version, deleted: file.deleted === true,
|
|
30
|
+
...(typeof file.content === "string" ? { content: file.content } : {}),
|
|
31
|
+
}];
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/** A path Nexus sent that is safe to write under the workspace. */
|
|
35
|
+
function safePath(path) {
|
|
36
|
+
return !path.includes("\\") && !path.startsWith("/") && path.split("/").every((part) => part !== "" && part !== "." && part !== "..");
|
|
37
|
+
}
|
|
38
|
+
/** Every file Nexus holds for this person, with the text of those that
|
|
39
|
+
* differ from `have`. Bodies arrive in batches, so this pulls until done. */
|
|
40
|
+
async function pullAll(client, have, departments) {
|
|
41
|
+
const files = new Map();
|
|
42
|
+
const held = { ...have };
|
|
43
|
+
for (let round = 0; round < MAX_PULL_ROUNDS; round++) {
|
|
44
|
+
const answer = await client.call("paw_pull", { have: held, ...(departments ? { departments: [...departments] } : {}) });
|
|
45
|
+
if (answer.success !== true)
|
|
46
|
+
throw new Error(String(answer.error ?? "Nexus refused the PAW pull"));
|
|
47
|
+
for (const file of remoteFiles(answer.files)) {
|
|
48
|
+
if (!safePath(file.path))
|
|
49
|
+
continue;
|
|
50
|
+
const earlier = files.get(file.path);
|
|
51
|
+
files.set(file.path, file.content === undefined && earlier?.sha256 === file.sha256 ? earlier : file);
|
|
52
|
+
if (file.content !== undefined)
|
|
53
|
+
held[file.path] = file.sha256;
|
|
54
|
+
}
|
|
55
|
+
if (!(Number(answer.pending) > 0))
|
|
56
|
+
return files;
|
|
57
|
+
}
|
|
58
|
+
throw new Error("Nexus kept reporting more PAW files than it sent");
|
|
59
|
+
}
|
|
60
|
+
/** The organization and department layers as Nexus holds them, or null when
|
|
61
|
+
* Nexus has no workspace for this organization yet (no paw.yaml): an empty
|
|
62
|
+
* Nexus must never clear the copy on this computer. */
|
|
63
|
+
export async function pullSharedLayers(client, departments) {
|
|
64
|
+
const remote = await pullAll(client, {}, departments);
|
|
65
|
+
const files = {};
|
|
66
|
+
for (const file of remote.values()) {
|
|
67
|
+
if (file.layer !== "me" && !file.deleted && file.content !== undefined)
|
|
68
|
+
files[file.path] = file.content;
|
|
69
|
+
}
|
|
70
|
+
return PAW_MANIFEST_FILE in files ? { files } : null;
|
|
71
|
+
}
|
|
72
|
+
function copyPath(path, tag) {
|
|
73
|
+
const dot = path.lastIndexOf(".");
|
|
74
|
+
return dot > path.lastIndexOf("/") ? `${path.slice(0, dot)}.${tag}${path.slice(dot)}` : `${path}.${tag}`;
|
|
75
|
+
}
|
|
76
|
+
/** Two-way sync of the person's layer. `local` is me/ without me/personal/
|
|
77
|
+
* and without anything that looks like a secret (sync.ts personalBackupFiles). */
|
|
78
|
+
export async function syncPersonalLayer(input) {
|
|
79
|
+
const { root, client, local } = input;
|
|
80
|
+
const have = Object.fromEntries(Object.entries(local).map(([path, body]) => [path, sha256(body)]));
|
|
81
|
+
const remote = new Map([...(await pullAll(client, have)).entries()]
|
|
82
|
+
.filter(([path, file]) => file.layer === "me" && path.startsWith("me/") && !path.startsWith("me/personal/")));
|
|
83
|
+
const known = { ...input.known };
|
|
84
|
+
const result = { known, pushed: 0, pulled: 0, removed: 0, conflicts: [], refused: [] };
|
|
85
|
+
const pushes = [];
|
|
86
|
+
const take = (path, file) => {
|
|
87
|
+
if (file.deleted) {
|
|
88
|
+
rmSync(join(root, ...path.split("/")), { force: true });
|
|
89
|
+
result.removed++;
|
|
90
|
+
}
|
|
91
|
+
else if (file.content !== undefined && !looksLikeSecret(file.content)) {
|
|
92
|
+
writeText(root, path, file.content);
|
|
93
|
+
result.pulled++;
|
|
94
|
+
}
|
|
95
|
+
else
|
|
96
|
+
return;
|
|
97
|
+
known[path] = { version: file.version, sha256: file.deleted ? "" : file.sha256 };
|
|
98
|
+
};
|
|
99
|
+
for (const path of new Set([...Object.keys(local), ...remote.keys(), ...Object.keys(known)])) {
|
|
100
|
+
const body = local[path];
|
|
101
|
+
const mine = body === undefined ? "" : have[path];
|
|
102
|
+
const theirs = remote.get(path);
|
|
103
|
+
const last = known[path];
|
|
104
|
+
if (!theirs) {
|
|
105
|
+
if (body !== undefined)
|
|
106
|
+
pushes.push({ path, content: body, base_version: 0 });
|
|
107
|
+
else
|
|
108
|
+
delete known[path];
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (mine === (theirs.deleted ? "" : theirs.sha256)) {
|
|
112
|
+
known[path] = { version: theirs.version, sha256: mine };
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (!last && body !== undefined && !theirs.deleted) {
|
|
116
|
+
// First sync of this file on this computer: Nexus wins, and text a person wrote here is kept beside it.
|
|
117
|
+
if (!input.isPlaceholder?.(body)) {
|
|
118
|
+
writeText(root, copyPath(path, "local-copy"), body);
|
|
119
|
+
result.conflicts.push(path);
|
|
120
|
+
}
|
|
121
|
+
take(path, theirs);
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const changedHere = last ? mine !== last.sha256 : body !== undefined;
|
|
125
|
+
const changedThere = !last || theirs.version !== last.version;
|
|
126
|
+
if (!changedHere || (changedThere && body === undefined))
|
|
127
|
+
take(path, theirs);
|
|
128
|
+
else if (!changedThere || theirs.deleted) {
|
|
129
|
+
pushes.push(body === undefined ? { path, delete: true, base_version: theirs.version } : { path, content: body, base_version: theirs.version });
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
if (theirs.content !== undefined && !looksLikeSecret(theirs.content))
|
|
133
|
+
writeText(root, copyPath(path, "nexus-copy"), theirs.content);
|
|
134
|
+
pushes.push({ path, content: body, base_version: theirs.version });
|
|
135
|
+
result.conflicts.push(path);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
for (let start = 0; start < pushes.length; start += PUSH_BATCH) {
|
|
139
|
+
const answer = await client.call("paw_push", { files: pushes.slice(start, start + PUSH_BATCH) });
|
|
140
|
+
if (answer.success !== true)
|
|
141
|
+
throw new Error(String(answer.error ?? "Nexus refused the PAW push"));
|
|
142
|
+
for (const entry of Array.isArray(answer.results) ? answer.results : []) {
|
|
143
|
+
const outcome = entry;
|
|
144
|
+
if (typeof outcome.path !== "string")
|
|
145
|
+
continue;
|
|
146
|
+
const [file] = remoteFiles([outcome.file]);
|
|
147
|
+
if ((outcome.status === "saved" || outcome.status === "unchanged") && file) {
|
|
148
|
+
known[outcome.path] = { version: file.version, sha256: file.deleted ? "" : file.sha256 };
|
|
149
|
+
if (outcome.status === "saved")
|
|
150
|
+
result.pushed++;
|
|
151
|
+
}
|
|
152
|
+
else if (outcome.status === "unchanged")
|
|
153
|
+
delete known[outcome.path];
|
|
154
|
+
else if (outcome.status === "refused")
|
|
155
|
+
result.refused.push(`${outcome.path}: ${String(outcome.reason ?? "refused")}`);
|
|
156
|
+
// conflict: another computer got there first; the next sync settles it
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return result;
|
|
160
|
+
}
|
|
@@ -9,7 +9,8 @@ import { writeFileAtomic } from "../atomic.js";
|
|
|
9
9
|
import { fileQueued, scanDrift, scanProposals, ChangeRequestStore, } from "./change-requests.js";
|
|
10
10
|
import { mergeView, pawSystemPrompt } from "./loader.js";
|
|
11
11
|
import { PAW_MANIFEST_FILE, isLockedPath, safeRelative, serializeManifest, staleFiles } from "./manifest.js";
|
|
12
|
-
import {
|
|
12
|
+
import { syncPersonalLayer } from "./nexus-sync.js";
|
|
13
|
+
import { chooseSource, personalBackupFiles, pullLayers } from "./sync.js";
|
|
13
14
|
import { builtinTemplate, chooseTemplateName, emptyTemplate, parseTemplateJson } from "./templates.js";
|
|
14
15
|
import { applyBuildPawInterview, assessPawFill, isPlaceholderText, needsBuildPawInterview, planBuildPawWrites, staleOrPlaceholderFiles, } from "./fill.js";
|
|
15
16
|
import { applyInterview, applyLocks, defaultPawRoot, ensureWorkspace, listFiles, pawExists, readManifest, readText, writeAboutMe, writeText, } from "./workspace.js";
|
|
@@ -182,17 +183,38 @@ export class PawService {
|
|
|
182
183
|
}
|
|
183
184
|
async sync() {
|
|
184
185
|
const manifest = this.manifest();
|
|
185
|
-
const source = chooseSource(manifest, { localSource: this.options.localSource?.(), home: this.options.home,
|
|
186
|
+
const source = chooseSource(manifest, { localSource: this.options.localSource?.(), home: this.options.home, nexus: this.options.nexus });
|
|
186
187
|
let result;
|
|
187
188
|
if (!source) {
|
|
188
189
|
result = { ok: false, source: "", written: 0, removed: 0, skippedSecrets: [], message: "No sync source is set. Your organization's files stay as they are." };
|
|
189
190
|
}
|
|
190
191
|
else {
|
|
191
192
|
result = await pullLayers({ root: this.root, source, departments: this.state.departments, personEmail: this.options.person().email, store: this.store });
|
|
193
|
+
if (source.kind === "nexus")
|
|
194
|
+
result = { ...result, message: `${result.message} ${await this.syncPersonalWithNexus()}`.trim() };
|
|
192
195
|
}
|
|
193
196
|
this.saveState({ ...this.state, lastSync: { at: Date.now(), ok: result.ok, message: result.message, source: result.source } });
|
|
194
197
|
return result;
|
|
195
198
|
}
|
|
199
|
+
/** Two-way sync of me/ with Nexus; returns one plain sentence for the status line. */
|
|
200
|
+
async syncPersonalWithNexus() {
|
|
201
|
+
const client = this.options.nexus?.();
|
|
202
|
+
if (!client)
|
|
203
|
+
return "Your own files were not synced: Nexus is not connected.";
|
|
204
|
+
try {
|
|
205
|
+
const done = await syncPersonalLayer({ root: this.root, client, local: personalBackupFiles(this.root), known: this.state.nexusMe ?? {}, isPlaceholder: isPlaceholderText });
|
|
206
|
+
this.saveState({ ...this.state, nexusMe: done.known });
|
|
207
|
+
const parts = [`Your own files: ${done.pushed} sent, ${done.pulled} received${done.removed ? `, ${done.removed} removed` : ""}.`];
|
|
208
|
+
if (done.conflicts.length)
|
|
209
|
+
parts.push(`${done.conflicts.length} changed in two places; both versions were kept.`);
|
|
210
|
+
if (done.refused.length)
|
|
211
|
+
parts.push(`${done.refused.length} not accepted by Nexus.`);
|
|
212
|
+
return parts.join(" ");
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
return `Your own files were not synced: ${error.message}`;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
196
218
|
/** Files this person owns that need a review (Primary Bot pre-check). */
|
|
197
219
|
staleForOwner(now = Date.now()) {
|
|
198
220
|
if (!this.enabled() || !this.exists())
|
|
@@ -228,7 +250,7 @@ export class PawService {
|
|
|
228
250
|
const exists = this.exists();
|
|
229
251
|
const manifest = this.manifest();
|
|
230
252
|
const joined = new Set(this.state.departments);
|
|
231
|
-
const source = exists ? chooseSource(manifest, { localSource: this.options.localSource?.(), home: this.options.home,
|
|
253
|
+
const source = exists ? chooseSource(manifest, { localSource: this.options.localSource?.(), home: this.options.home, nexus: this.options.nexus }) : null;
|
|
232
254
|
const requests = this.store.list();
|
|
233
255
|
return {
|
|
234
256
|
enabled: this.enabled(),
|
|
@@ -5,16 +5,13 @@
|
|
|
5
5
|
// staff. Two sources:
|
|
6
6
|
// local a folder on this computer or a shared drive (paw.yaml
|
|
7
7
|
// sync.localSource, or Settings). This is what v1 uses.
|
|
8
|
-
// nexus Nexus
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
// ATOMIC_PAW_NEXUS=1 flag so nobody turns it on by accident.
|
|
8
|
+
// nexus Nexus (server/paw/nexus-sync.ts). Behind the `paw.sync.source:
|
|
9
|
+
// nexus` setting plus the ATOMIC_PAW_NEXUS=1 flag until the Nexus
|
|
10
|
+
// side is live for everyone. When Nexus cannot be reached, or holds
|
|
11
|
+
// no workspace yet, the last copy on disk keeps working.
|
|
13
12
|
//
|
|
14
|
-
//
|
|
15
|
-
// Nexus under their identity
|
|
16
|
-
// exists. Until then the backup reports "not available" and nothing leaves
|
|
17
|
-
// the computer.
|
|
13
|
+
// The person's own layer (me/, never me/personal/) syncs both ways with
|
|
14
|
+
// Nexus under their identity when the source is Nexus.
|
|
18
15
|
//
|
|
19
16
|
// No secrets: a file that looks like it holds a credential is never pulled
|
|
20
17
|
// or pushed (shared/redact.ts, the same patterns that scrub transcripts).
|
|
@@ -23,6 +20,7 @@ import { homedir } from "node:os";
|
|
|
23
20
|
import { join, resolve } from "node:path";
|
|
24
21
|
import { looksLikeSecret } from "./change-requests.js";
|
|
25
22
|
import { PAW_MANIFEST_FILE, parseManifest } from "./manifest.js";
|
|
23
|
+
import { pullSharedLayers } from "./nexus-sync.js";
|
|
26
24
|
import { applyLocks, listFiles, readText, writeText } from "./workspace.js";
|
|
27
25
|
export function expandHome(path, home = homedir()) {
|
|
28
26
|
if (path === "~")
|
|
@@ -65,25 +63,24 @@ export function nexusSyncEnabled(env = process.env) {
|
|
|
65
63
|
}
|
|
66
64
|
export class NexusSource {
|
|
67
65
|
kind = "nexus";
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
this.organization = organization;
|
|
72
|
-
this.writeBack = writeBack;
|
|
66
|
+
client;
|
|
67
|
+
constructor(client) {
|
|
68
|
+
this.client = client;
|
|
73
69
|
}
|
|
74
70
|
describe() {
|
|
75
71
|
return "Nexus";
|
|
76
72
|
}
|
|
73
|
+
/** Null when Nexus is not connected, cannot be reached, or holds no workspace yet. */
|
|
77
74
|
async pull(departments) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (!this.writeBack)
|
|
75
|
+
const client = this.client();
|
|
76
|
+
if (!client)
|
|
81
77
|
return null;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
78
|
+
try {
|
|
79
|
+
return await pullSharedLayers(client, departments);
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
85
82
|
return null;
|
|
86
|
-
|
|
83
|
+
}
|
|
87
84
|
}
|
|
88
85
|
}
|
|
89
86
|
/** Pull and apply. Files under org/ and the joined departments that the
|
|
@@ -126,7 +123,7 @@ export async function pullLayers(input) {
|
|
|
126
123
|
/** Which source this computer uses. */
|
|
127
124
|
export function chooseSource(manifest, options) {
|
|
128
125
|
if (manifest.sync.source === "nexus" && nexusSyncEnabled(options.env)) {
|
|
129
|
-
return new NexusSource(
|
|
126
|
+
return new NexusSource(options.nexus ?? (() => null));
|
|
130
127
|
}
|
|
131
128
|
const folder = options.localSource?.trim() || manifest.sync.localSource;
|
|
132
129
|
return folder ? new LocalFolderSource(expandHome(folder, options.home)) : null;
|
|
@@ -144,11 +141,3 @@ export function personalBackupFiles(root) {
|
|
|
144
141
|
}
|
|
145
142
|
return files;
|
|
146
143
|
}
|
|
147
|
-
export async function backupPersonalLayer(root, identity, writeBack) {
|
|
148
|
-
// TODO(paw-nexus): pass the nexus-writeback module once merged.
|
|
149
|
-
if (!writeBack || !identity)
|
|
150
|
-
return { ok: false, files: 0, message: "Backup to Nexus is not available yet." };
|
|
151
|
-
const files = personalBackupFiles(root);
|
|
152
|
-
await writeBack.writeFolder({ identity, layer: "me" }, files);
|
|
153
|
-
return { ok: true, files: Object.keys(files).length, message: "Backed up." };
|
|
154
|
-
}
|
|
@@ -157,6 +157,7 @@ export async function remoteFrame(call, shrink = sipsJpeg) {
|
|
|
157
157
|
frameWidth: size.width,
|
|
158
158
|
frameHeight: size.height,
|
|
159
159
|
display: layout.id,
|
|
160
|
+
platform: process.platform,
|
|
160
161
|
},
|
|
161
162
|
sent: { frameWidth: size.width, frameHeight: size.height, layout },
|
|
162
163
|
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { clampSize } from "../terminal.js";
|
|
2
|
+
import { PASS } from "./table.js";
|
|
3
|
+
const owner = (auth) => {
|
|
4
|
+
if (!auth.scopes.includes("admin"))
|
|
5
|
+
return null;
|
|
6
|
+
if (auth.kind === "session")
|
|
7
|
+
return `session:${auth.session.id}`;
|
|
8
|
+
if (auth.kind === "loopback" && auth.trust !== "service")
|
|
9
|
+
return "desktop";
|
|
10
|
+
return null;
|
|
11
|
+
};
|
|
12
|
+
export function createTerminalRoutes(deps) {
|
|
13
|
+
return async ({ req, res, path, method, auth, json, readBody }) => {
|
|
14
|
+
const open = path.match(/^\/api\/bots\/([\w-]+)\/terminal$/);
|
|
15
|
+
const session = path.match(/^\/api\/terminal\/([\w-]+)(?:\/(stream|input))?$/);
|
|
16
|
+
if (!open && !session)
|
|
17
|
+
return PASS;
|
|
18
|
+
const who = owner(auth);
|
|
19
|
+
if (!who)
|
|
20
|
+
return json(res, 403, { error: "The terminal is for the person at this computer" });
|
|
21
|
+
if (open) {
|
|
22
|
+
if (method !== "POST")
|
|
23
|
+
return json(res, 405, { error: "method not allowed" });
|
|
24
|
+
const body = await readBody(req);
|
|
25
|
+
const place = body?.place;
|
|
26
|
+
if (place !== "vm" && place !== "cloud" && place !== "local")
|
|
27
|
+
return json(res, 400, { error: "send { place: \"vm\" | \"cloud\" | \"local\" }" });
|
|
28
|
+
const threadId = typeof body?.threadId === "string" && /^[\w-]{1,128}$/.test(body.threadId) ? body.threadId : undefined;
|
|
29
|
+
const size = { cols: clampSize(body?.cols, 100), rows: clampSize(body?.rows, 30) };
|
|
30
|
+
let spec;
|
|
31
|
+
try {
|
|
32
|
+
spec = await deps.spec(open[1], place, threadId, size);
|
|
33
|
+
const opened = deps.registry.open(spec, who);
|
|
34
|
+
return json(res, 200, { id: opened.id, label: opened.label });
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
const status = error.status;
|
|
38
|
+
return json(res, typeof status === "number" ? status : 500, { error: error instanceof Error ? error.message : String(error) });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const live = deps.registry.get(session[1]);
|
|
42
|
+
if (!live || live.owner !== who)
|
|
43
|
+
return json(res, 404, { error: "no such terminal" });
|
|
44
|
+
const action = session[2];
|
|
45
|
+
if (action === "stream") {
|
|
46
|
+
if (method !== "GET")
|
|
47
|
+
return json(res, 405, { error: "method not allowed" });
|
|
48
|
+
res.writeHead(200, { "content-type": "application/x-ndjson", "cache-control": "no-cache", "x-accel-buffering": "no" });
|
|
49
|
+
req.socket.setTimeout(0);
|
|
50
|
+
const unsubscribe = live.subscribe((event) => {
|
|
51
|
+
res.write(`${JSON.stringify(event)}\n`);
|
|
52
|
+
if (event.type === "exit")
|
|
53
|
+
res.end();
|
|
54
|
+
});
|
|
55
|
+
res.on("close", unsubscribe);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (action === "input") {
|
|
59
|
+
if (method !== "POST")
|
|
60
|
+
return json(res, 405, { error: "method not allowed" });
|
|
61
|
+
const body = await readBody(req, 64 * 1024);
|
|
62
|
+
if (typeof body?.data !== "string")
|
|
63
|
+
return json(res, 400, { error: "send { data }" });
|
|
64
|
+
live.write(body.data);
|
|
65
|
+
return json(res, 200, { ok: true });
|
|
66
|
+
}
|
|
67
|
+
if (method !== "DELETE")
|
|
68
|
+
return json(res, 405, { error: "method not allowed" });
|
|
69
|
+
live.close();
|
|
70
|
+
return json(res, 200, { ok: true });
|
|
71
|
+
};
|
|
72
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// The Computer panel's Terminal tab (docs/computer-terminal.md): decides the
|
|
2
|
+
// shell command per place and wires the session registry into the HTTP routes
|
|
3
|
+
// (server/routes/terminal.ts). Which shell runs where is decided here, never
|
|
4
|
+
// by the client.
|
|
5
|
+
import { dockerEnvForColima } from "./colima-docker.js";
|
|
6
|
+
import { vpsSshAlias } from "./config.js";
|
|
7
|
+
import { containerRuntimeStatus } from "./container-computer.js";
|
|
8
|
+
import { augmentedPath, resolveCliSpawn } from "./env-path.js";
|
|
9
|
+
import { createTerminalRoutes } from "./routes/terminal.js";
|
|
10
|
+
import { TerminalRegistry, sizedShell } from "./terminal.js";
|
|
11
|
+
import * as vps from "./vps-computer.js";
|
|
12
|
+
import { prepareVpsSsh } from "./vps-ssh.js";
|
|
13
|
+
import { ensureTaskWorkspace, workspaceDir } from "./workspace.js";
|
|
14
|
+
/** Terminal tab (docs/computer-terminal.md): on unless Settings > Experimental turns it off. */
|
|
15
|
+
export function terminalEnabled(cfg) {
|
|
16
|
+
return cfg.features?.terminal !== false;
|
|
17
|
+
}
|
|
18
|
+
/** A shell on this computer from the Terminal tab; needs the tab enabled too. */
|
|
19
|
+
export function localTerminalEnabled(cfg) {
|
|
20
|
+
return terminalEnabled(cfg) && cfg.features?.localTerminal === true;
|
|
21
|
+
}
|
|
22
|
+
// ponytail: one process-wide registry; index.ts is the only caller.
|
|
23
|
+
const registry = new TerminalRegistry();
|
|
24
|
+
export const closeTerminals = () => registry.closeAll();
|
|
25
|
+
/** The two Settings > Experimental switches, as configStatus reports them. */
|
|
26
|
+
export function terminalFeatures(cfg) {
|
|
27
|
+
return { terminal: terminalEnabled(cfg), localTerminal: localTerminalEnabled(cfg) };
|
|
28
|
+
}
|
|
29
|
+
export function terminalRoutes(deps) {
|
|
30
|
+
return createTerminalRoutes({ registry, spec: (botId, place, threadId, size) => terminalSpec(deps, botId, place, threadId, size) });
|
|
31
|
+
}
|
|
32
|
+
const refuse = (status, message) => Object.assign(new Error(message), { status });
|
|
33
|
+
export async function terminalSpec(deps, botId, place, threadId, { cols, rows }, platform = process.platform) {
|
|
34
|
+
const cfg = deps.cfg();
|
|
35
|
+
if (!terminalEnabled(cfg))
|
|
36
|
+
throw refuse(403, "The Terminal tab is turned off in Settings > Experimental");
|
|
37
|
+
if (!deps.hasBot(botId))
|
|
38
|
+
throw refuse(404, "no such bot");
|
|
39
|
+
const tty = platform === "win32" ? "-i" : "-it";
|
|
40
|
+
const inContainer = (name) => ["exec", tty, "-u", "cua", "-w", "/home/cua", "-e", "TERM=xterm-256color", name, ...sizedShell(cols, rows, "bash -l")];
|
|
41
|
+
if (place === "vm") {
|
|
42
|
+
const runtime = (await containerRuntimeStatus()).runtime;
|
|
43
|
+
if (!runtime)
|
|
44
|
+
throw refuse(409, "No container runtime is running for the Local VM");
|
|
45
|
+
const plan = resolveCliSpawn(runtime, inContainer(deps.localVmContainer(botId)));
|
|
46
|
+
const env = { ...process.env, PATH: augmentedPath(), ...plan.env };
|
|
47
|
+
return { command: plan.command, args: plan.args, env: runtime === "docker" ? dockerEnvForColima(env) : env, cols, rows, label: "Local VM" };
|
|
48
|
+
}
|
|
49
|
+
if (place === "cloud") {
|
|
50
|
+
const alias = vpsSshAlias(cfg);
|
|
51
|
+
if (!alias)
|
|
52
|
+
throw refuse(409, "No VPS is set up for this workspace");
|
|
53
|
+
const plan = resolveCliSpawn("docker", vps.vpsDockerArgs(alias, inContainer(vps.vpsContainerName(botId))));
|
|
54
|
+
return { command: plan.command, args: plan.args, env: { ...process.env, PATH: prepareVpsSsh(deps.dataDir, augmentedPath()).path, ...plan.env }, cols, rows, label: "VPS" };
|
|
55
|
+
}
|
|
56
|
+
if (!localTerminalEnabled(cfg))
|
|
57
|
+
throw refuse(403, "Turn on the shell on this computer in Settings > Experimental");
|
|
58
|
+
const cwd = threadId ? ensureTaskWorkspace(botId, threadId) : workspaceDir(botId);
|
|
59
|
+
if (platform === "win32")
|
|
60
|
+
return { command: "powershell.exe", args: ["-NoLogo"], cwd, cols, rows, label: "This computer" };
|
|
61
|
+
const shell = process.env.SHELL || (platform === "darwin" ? "/bin/zsh" : "/bin/bash");
|
|
62
|
+
return { command: "sh", args: sizedShell(cols, rows, `"${shell}" -l`).slice(1), cwd, cols, rows, label: "This computer" };
|
|
63
|
+
}
|