@chibitek/chibi 0.1.190 → 0.1.191
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-D8Eovq0F.js +10 -0
- package/dist/assets/TerminalPanel-DFuMZ0ql.css +1 -0
- package/dist/assets/{abnfDiagram-O67JEVCF-Bz3wlNsQ.js → abnfDiagram-O67JEVCF-CPvuUneJ.js} +1 -1
- package/dist/assets/{arc-CX0dJSa0.js → arc-aMP_0t5b.js} +1 -1
- package/dist/assets/{architectureDiagram-NJMV4G6O-APIM9yGf.js → architectureDiagram-NJMV4G6O-yyXrFi66.js} +1 -1
- package/dist/assets/{blockDiagram-BEXU5L5S-DNmNNaVY.js → blockDiagram-BEXU5L5S-BQN3ZvRc.js} +1 -1
- package/dist/assets/{c4Diagram-YGBWAQC7-CAPPUeMU.js → c4Diagram-YGBWAQC7-BieilTo4.js} +1 -1
- package/dist/assets/channel-Bw54wjTR.js +1 -0
- package/dist/assets/{chunk-2Q5K7J3B-DfCDsQgU.js → chunk-2Q5K7J3B-Df4lxXIM.js} +1 -1
- package/dist/assets/{chunk-3FUC2YCW-vdffwGmy.js → chunk-3FUC2YCW-su_KXf5y.js} +2 -2
- package/dist/assets/{chunk-5VM5RSS4-BazIL_2e.js → chunk-5VM5RSS4-DL3rM5tY.js} +1 -1
- package/dist/assets/{chunk-GTNCS2PH-GpKjNZ-V.js → chunk-GTNCS2PH-53Ovfw1t.js} +1 -1
- package/dist/assets/{chunk-GWA4HPMP-BuRq21LZ.js → chunk-GWA4HPMP-BkeiDfwS.js} +1 -1
- package/dist/assets/{chunk-JWPE2WC7-CqNGOyHV.js → chunk-JWPE2WC7-CvsdGjCO.js} +1 -1
- package/dist/assets/{chunk-NETBCI7D-B1DpzVCP.js → chunk-NETBCI7D-BngSjMee.js} +1 -1
- package/dist/assets/{chunk-WEXAMYUT-DcH1Euc6.js → chunk-WEXAMYUT-DitKn6fq.js} +1 -1
- package/dist/assets/{chunk-XXDRQBXY-M1JLd_cm.js → chunk-XXDRQBXY-Czjvl52d.js} +1 -1
- package/dist/assets/{classDiagram-v2-NBCMYWYE-C8mBZ7i2.js → classDiagram-v2-NBCMYWYE-COr4Qzpk.js} +1 -1
- package/dist/assets/{cose-bilkent-JH36ORCC-Cr3TqHDz.js → cose-bilkent-JH36ORCC-Eg0tlzqp.js} +1 -1
- package/dist/assets/{cynefin-OW5HDTMX-BKPr6l0I.js → cynefin-OW5HDTMX-BjtG84WL.js} +1 -1
- package/dist/assets/{cynefinDiagram-VND7K2PF-Cbg5mrIM.js → cynefinDiagram-VND7K2PF-BzZtwDD4.js} +1 -1
- package/dist/assets/{dagre-6A5THRUB-9I9X1J3r.js → dagre-6A5THRUB-TrLQ507j.js} +1 -1
- package/dist/assets/{diagram-22UHCM2B-B43b8pqQ.js → diagram-22UHCM2B-BDQDC-33.js} +1 -1
- package/dist/assets/{diagram-3UASUU5V-CIehgEkZ.js → diagram-3UASUU5V-Cm_mzSfE.js} +1 -1
- package/dist/assets/{diagram-ATOU4E4O-gx8nkXLZ.js → diagram-ATOU4E4O-CAI_i4oy.js} +1 -1
- package/dist/assets/{diagram-CDSNMT55-BZzWgYHa.js → diagram-CDSNMT55-9GjNyQXn.js} +1 -1
- package/dist/assets/{diagram-MLGK6HIB-BqoCqkZD.js → diagram-MLGK6HIB-ETDg4UN-.js} +1 -1
- package/dist/assets/{diagram-MPIPVDR6-Bsc7x0UT.js → diagram-MPIPVDR6-8_8dZKgW.js} +1 -1
- package/dist/assets/{ebnfDiagram-ZINNZB2B-8HjdD_s8.js → ebnfDiagram-ZINNZB2B-BiYh2ZYM.js} +1 -1
- package/dist/assets/{elk-276RUBZZ-bmxiEFtT.js → elk-276RUBZZ-5u6sMYIg.js} +1 -1
- package/dist/assets/{erDiagram-OPXOYQCR-BU-sRLe3.js → erDiagram-OPXOYQCR-Dm6semJ3.js} +1 -1
- package/dist/assets/{flowDiagram-KWPJA3E3-D45vn40U.js → flowDiagram-KWPJA3E3-DbQ12CeV.js} +1 -1
- package/dist/assets/{ganttDiagram-FUAMR5RP-CArB98Hu.js → ganttDiagram-FUAMR5RP-C12s51S6.js} +1 -1
- package/dist/assets/{gitGraphDiagram-X574FWY7-fPB1k-W7.js → gitGraphDiagram-X574FWY7-BhkwBL2T.js} +1 -1
- package/dist/assets/{index-u1wvoacp.js → index-D4BfC2Zf.js} +1 -1
- package/dist/assets/index-DBOyvapT.css +1 -0
- package/dist/assets/{index-QsXeEMxJ.js → index-WT8Xwc4G.js} +172 -171
- package/dist/assets/{infoDiagram-VRGFBTTK-ZRVWXAr4.js → infoDiagram-VRGFBTTK-IvWqyiSM.js} +1 -1
- package/dist/assets/{ishikawaDiagram-OU5B5YK6-DOaurRbX.js → ishikawaDiagram-OU5B5YK6-N2ZxLyoE.js} +1 -1
- package/dist/assets/{journeyDiagram-ZHPQQLJL-Ca9B-09w.js → journeyDiagram-ZHPQQLJL-UWy3ala_.js} +1 -1
- package/dist/assets/{kanban-definition-PNTS6WVX-CA2XswEJ.js → kanban-definition-PNTS6WVX-Cutk-kDA.js} +1 -1
- package/dist/assets/{linear-B-F7icip.js → linear-dPnV_-aA.js} +1 -1
- package/dist/assets/{mermaid.core-ymtCpbZ5.js → mermaid.core-QdldWb2L.js} +5 -5
- package/dist/assets/{mindmap-definition-NLK3R4M7-02vIazCi.js → mindmap-definition-NLK3R4M7-pkXW8CYn.js} +1 -1
- package/dist/assets/{pegDiagram-GJSIUBJH-DRb7Pn72.js → pegDiagram-GJSIUBJH-DhKkEQzV.js} +1 -1
- package/dist/assets/{pieDiagram-5QR66LMP-B2YwP3S_.js → pieDiagram-5QR66LMP-DMehGrxw.js} +1 -1
- package/dist/assets/{quadrantDiagram-O4NWA36T-CbR573mu.js → quadrantDiagram-O4NWA36T-oNzYf4fg.js} +1 -1
- package/dist/assets/{railroadDiagram-XR7U4H2S-CqHuDCnM.js → railroadDiagram-XR7U4H2S-pkMOwYja.js} +1 -1
- package/dist/assets/{requirementDiagram-PLB6GJNP-BSeC-H1j.js → requirementDiagram-PLB6GJNP-J29GrlJj.js} +1 -1
- package/dist/assets/{sankeyDiagram-IPEJSGJF-BMFuhoh1.js → sankeyDiagram-IPEJSGJF-YuyCeGY6.js} +1 -1
- package/dist/assets/{sequenceDiagram-PO4LG4MO-DRT_EI9u.js → sequenceDiagram-PO4LG4MO-BjxLu0JW.js} +1 -1
- package/dist/assets/{sizeCapture-INFHLROL-BLFT4fV7.js → sizeCapture-INFHLROL-BESOD3ec.js} +1 -1
- package/dist/assets/{stateDiagram-v2-GCMORJYK-C8vB_69H.js → stateDiagram-v2-GCMORJYK-DF2yvbZA.js} +1 -1
- package/dist/assets/{swimlanes-2SLR337P-T6BBolT8.js → swimlanes-2SLR337P-Bzp4ze7n.js} +1 -1
- package/dist/assets/swimlanesDiagram-TC7HE7FX-B6y4ZZ5q.js +8 -0
- package/dist/assets/{timeline-definition-EJHVYXUP-DjdjBRQV.js → timeline-definition-EJHVYXUP-CnLbXs4R.js} +1 -1
- package/dist/assets/{usecaseDiagram-POWQR4AR-CDGccZMN.js → usecaseDiagram-POWQR4AR-nuJhbhCv.js} +1 -1
- package/dist/assets/{vennDiagram-UO4OBE2U-CgYSihtW.js → vennDiagram-UO4OBE2U-D_hzVg9h.js} +1 -1
- package/dist/assets/{wardleyDiagram-VNRHLVJA-Bub5ScM8.js → wardleyDiagram-VNRHLVJA-hgmpI4iu.js} +1 -1
- package/dist/assets/{xychartDiagram-PMCCYNJV-DK5iMX67.js → xychartDiagram-PMCCYNJV-DwnJWdDn.js} +1 -1
- package/dist/index.html +2 -2
- package/dist-server/container-mcp.js +3 -0
- package/dist-server/index.js +1552 -1075
- package/dist-server/openmausbot.js +6 -3
- package/dist-server/pair-cli.js +6 -3
- 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 +27 -0
- package/dist-server/server/nexus-memory/index.js +12 -16
- 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/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/vps-container-mcp.js +3 -0
- 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/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
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// One shared wait after Nexus fails: 1, 5, 15, then 30 minutes while the
|
|
2
|
+
// outage lasts (unreachable, or signed out, which makes the bridge open a
|
|
3
|
+
// sign-in page). A failure more than an hour after the previous one is a
|
|
4
|
+
// new blip and starts over at one minute, so a night of Wi-Fi drops does
|
|
5
|
+
// not leave every later call blocked for half an hour.
|
|
6
|
+
const WAITS_MS = [60_000, 300_000, 900_000, 1_800_000];
|
|
7
|
+
const SAME_OUTAGE_MS = 2 * WAITS_MS[WAITS_MS.length - 1];
|
|
8
|
+
export class UnavailableBackoff {
|
|
9
|
+
until = 0;
|
|
10
|
+
failures = 0;
|
|
11
|
+
lastAt = 0;
|
|
12
|
+
/** How much longer to wait; 0 when calls may go through. */
|
|
13
|
+
remainingMs(now) {
|
|
14
|
+
return Math.max(0, this.until - now);
|
|
15
|
+
}
|
|
16
|
+
failed(now) {
|
|
17
|
+
if (now - this.lastAt > SAME_OUTAGE_MS)
|
|
18
|
+
this.failures = 0;
|
|
19
|
+
this.lastAt = now;
|
|
20
|
+
this.failures += 1;
|
|
21
|
+
this.until = now + WAITS_MS[Math.min(this.failures - 1, WAITS_MS.length - 1)];
|
|
22
|
+
}
|
|
23
|
+
succeeded() {
|
|
24
|
+
this.failures = 0;
|
|
25
|
+
this.until = 0;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -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 { 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;
|
|
@@ -181,29 +180,26 @@ export class NexusMemory {
|
|
|
181
180
|
}
|
|
182
181
|
return this.client;
|
|
183
182
|
}
|
|
184
|
-
/** The client behind one shared back-off: once Nexus
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
* minutes. Writes keep queuing on disk meanwhile. */
|
|
183
|
+
/** The client behind one shared back-off (see backoff.ts): once Nexus
|
|
184
|
+
* fails, nothing calls it again until the wait is over. Writes keep
|
|
185
|
+
* queuing on disk meanwhile. */
|
|
188
186
|
getClient() {
|
|
189
187
|
const client = this.rawClient();
|
|
190
188
|
if (!client)
|
|
191
189
|
return null;
|
|
192
190
|
return {
|
|
193
191
|
call: async (tool, args, timeoutMs) => {
|
|
194
|
-
|
|
195
|
-
|
|
192
|
+
const remaining = this.backoff.remainingMs(this.now());
|
|
193
|
+
if (remaining > 0)
|
|
194
|
+
throw new NexusUnavailableError(`waiting before trying Nexus again (next try in ${Math.ceil(remaining / 60_000)} min)`);
|
|
196
195
|
try {
|
|
197
196
|
const result = await client.call(tool, args, timeoutMs);
|
|
198
|
-
this.
|
|
199
|
-
this.unavailableUntil = 0;
|
|
197
|
+
this.backoff.succeeded();
|
|
200
198
|
return result;
|
|
201
199
|
}
|
|
202
200
|
catch (error) {
|
|
203
|
-
if (error instanceof NexusUnavailableError)
|
|
204
|
-
this.
|
|
205
|
-
this.unavailableUntil = this.now() + UNAVAILABLE_BACKOFF_MS[Math.min(this.unavailableFailures - 1, UNAVAILABLE_BACKOFF_MS.length - 1)];
|
|
206
|
-
}
|
|
201
|
+
if (error instanceof NexusUnavailableError)
|
|
202
|
+
this.backoff.failed(this.now());
|
|
207
203
|
throw error;
|
|
208
204
|
}
|
|
209
205
|
},
|
|
@@ -530,7 +526,7 @@ export class NexusMemory {
|
|
|
530
526
|
const due = outboxDue === null ? notesDue : notesDue === null ? outboxDue : Math.min(outboxDue, notesDue);
|
|
531
527
|
if (due === null)
|
|
532
528
|
return;
|
|
533
|
-
const wait = Math.max(delayMs ?? Math.max(0, due - this.now()), this.
|
|
529
|
+
const wait = Math.max(delayMs ?? Math.max(0, due - this.now()), this.backoff.remainingMs(this.now()), 0);
|
|
534
530
|
this.timer = setTimeout(() => {
|
|
535
531
|
void this.flush().finally(() => this.kick());
|
|
536
532
|
}, 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
|
+
}
|