@chibitek/chibi 0.1.200 → 0.1.202
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-DUfFZmEG.js → TerminalPanel-BqQaJQrc.js} +1 -1
- package/dist/assets/{abnfDiagram-O67JEVCF-BqQSwr1u.js → abnfDiagram-O67JEVCF-BCeO-FJ-.js} +1 -1
- package/dist/assets/{arc-T05LhWW8.js → arc-DAcyEY9g.js} +1 -1
- package/dist/assets/{architectureDiagram-NJMV4G6O-D_ggH0yg.js → architectureDiagram-NJMV4G6O-Dwzl21OF.js} +1 -1
- package/dist/assets/{blockDiagram-BEXU5L5S-RE8mkopU.js → blockDiagram-BEXU5L5S-CB9lZurW.js} +1 -1
- package/dist/assets/{c4Diagram-YGBWAQC7-BXtV9POP.js → c4Diagram-YGBWAQC7-enWMxZTY.js} +1 -1
- package/dist/assets/channel-DfJpivlk.js +1 -0
- package/dist/assets/{chunk-2Q5K7J3B-7zaRJzef.js → chunk-2Q5K7J3B-CiQIhCM0.js} +1 -1
- package/dist/assets/{chunk-3FUC2YCW-BOxhuNM3.js → chunk-3FUC2YCW-LA3V3P14.js} +2 -2
- package/dist/assets/{chunk-5VM5RSS4-Clc6Y-k_.js → chunk-5VM5RSS4-C24r0tJ3.js} +1 -1
- package/dist/assets/{chunk-GTNCS2PH-D7IERUnR.js → chunk-GTNCS2PH-_BXj6Flz.js} +1 -1
- package/dist/assets/{chunk-GWA4HPMP-8QL2NNrN.js → chunk-GWA4HPMP-CcOUNIER.js} +1 -1
- package/dist/assets/{chunk-JWPE2WC7-DKVMCjGt.js → chunk-JWPE2WC7-65CF3zSi.js} +1 -1
- package/dist/assets/{chunk-NETBCI7D-SlxDfy1G.js → chunk-NETBCI7D-33XJs1ao.js} +1 -1
- package/dist/assets/{chunk-WEXAMYUT-CRtOamAr.js → chunk-WEXAMYUT-Bf108rcV.js} +1 -1
- package/dist/assets/{chunk-XXDRQBXY-Dapib2DP.js → chunk-XXDRQBXY-CPtVeZ9w.js} +1 -1
- package/dist/assets/{classDiagram-v2-NBCMYWYE-2D0I10Na.js → classDiagram-v2-NBCMYWYE-9IR2tQzs.js} +1 -1
- package/dist/assets/{cose-bilkent-JH36ORCC-DF9qnXun.js → cose-bilkent-JH36ORCC-DCqYmLmJ.js} +1 -1
- package/dist/assets/{cynefin-OW5HDTMX-DrAkyhcY.js → cynefin-OW5HDTMX-D21Oj5DP.js} +1 -1
- package/dist/assets/{cynefinDiagram-VND7K2PF-KQpEcNdf.js → cynefinDiagram-VND7K2PF-DTbN6FwN.js} +1 -1
- package/dist/assets/{dagre-6A5THRUB-BbJ2VQn6.js → dagre-6A5THRUB-CCmPZ43E.js} +1 -1
- package/dist/assets/{diagram-22UHCM2B-BNzSyGUh.js → diagram-22UHCM2B-CJyMaY9z.js} +1 -1
- package/dist/assets/{diagram-3UASUU5V-DjjLDFUp.js → diagram-3UASUU5V-LKeJRoef.js} +1 -1
- package/dist/assets/{diagram-ATOU4E4O-DC5I0Rdi.js → diagram-ATOU4E4O-jjufFAkX.js} +1 -1
- package/dist/assets/{diagram-CDSNMT55-BrXM08dx.js → diagram-CDSNMT55-Dq3h17-z.js} +1 -1
- package/dist/assets/{diagram-MLGK6HIB-C3YZl0Tw.js → diagram-MLGK6HIB-Ca97pK2N.js} +1 -1
- package/dist/assets/{diagram-MPIPVDR6-DN6TO0ne.js → diagram-MPIPVDR6-jRckT1gO.js} +1 -1
- package/dist/assets/{ebnfDiagram-ZINNZB2B-Z-Wj8D9u.js → ebnfDiagram-ZINNZB2B-BPaoE5L2.js} +1 -1
- package/dist/assets/{elk-276RUBZZ-D0oWP8_p.js → elk-276RUBZZ-C6Y5YZAN.js} +1 -1
- package/dist/assets/{erDiagram-OPXOYQCR-BzPDI-qn.js → erDiagram-OPXOYQCR-k77jMxHA.js} +1 -1
- package/dist/assets/{flowDiagram-KWPJA3E3-BYYAeWqA.js → flowDiagram-KWPJA3E3-Co1J8TdL.js} +1 -1
- package/dist/assets/{ganttDiagram-FUAMR5RP-k6obyqY7.js → ganttDiagram-FUAMR5RP-DZqEDtow.js} +1 -1
- package/dist/assets/{gitGraphDiagram-X574FWY7-DinY8xWJ.js → gitGraphDiagram-X574FWY7-B-noo13S.js} +1 -1
- package/dist/assets/{index-YyLa_0lt.js → index-BThKfVMa.js} +1 -1
- package/dist/assets/index-C36j3Mf7.css +1 -0
- package/dist/assets/{index-ChUqQMGu.js → index-D_v7jkw4.js} +137 -137
- package/dist/assets/{infoDiagram-VRGFBTTK-BW2C-iLy.js → infoDiagram-VRGFBTTK-BT5S_4rV.js} +1 -1
- package/dist/assets/{ishikawaDiagram-OU5B5YK6-DVMxtqNy.js → ishikawaDiagram-OU5B5YK6-CBIJFAO1.js} +1 -1
- package/dist/assets/{journeyDiagram-ZHPQQLJL-VBQwKC0m.js → journeyDiagram-ZHPQQLJL-DpfvTmha.js} +1 -1
- package/dist/assets/{kanban-definition-PNTS6WVX-BjkXxAFy.js → kanban-definition-PNTS6WVX-B_PzfC-4.js} +1 -1
- package/dist/assets/{linear-BvzB7a4B.js → linear-x7oeFpwu.js} +1 -1
- package/dist/assets/{mermaid.core-BINI6H7d.js → mermaid.core-CRUgO9rc.js} +5 -5
- package/dist/assets/{mindmap-definition-NLK3R4M7-b73g38FN.js → mindmap-definition-NLK3R4M7-BRyqRB1b.js} +1 -1
- package/dist/assets/{pegDiagram-GJSIUBJH-B8b2xdaw.js → pegDiagram-GJSIUBJH-B40H6nbN.js} +1 -1
- package/dist/assets/{pieDiagram-5QR66LMP-DmlfE59D.js → pieDiagram-5QR66LMP-I_zHV9hF.js} +1 -1
- package/dist/assets/{quadrantDiagram-O4NWA36T-DO8GiPy0.js → quadrantDiagram-O4NWA36T-DuoQbk_z.js} +1 -1
- package/dist/assets/{railroadDiagram-XR7U4H2S-DJkdT4GR.js → railroadDiagram-XR7U4H2S-DRgi73Cb.js} +1 -1
- package/dist/assets/{requirementDiagram-PLB6GJNP-BAx14esZ.js → requirementDiagram-PLB6GJNP-B4uiAonn.js} +1 -1
- package/dist/assets/{sankeyDiagram-IPEJSGJF-CYlEooaw.js → sankeyDiagram-IPEJSGJF-Dzirs5sT.js} +1 -1
- package/dist/assets/{sequenceDiagram-PO4LG4MO-BTK7rivc.js → sequenceDiagram-PO4LG4MO-D07Gg-lu.js} +1 -1
- package/dist/assets/{sizeCapture-INFHLROL-6V9VYNKI.js → sizeCapture-INFHLROL-D-jPw2ZR.js} +1 -1
- package/dist/assets/{stateDiagram-v2-GCMORJYK-DVRTd965.js → stateDiagram-v2-GCMORJYK-CrQbI0yG.js} +1 -1
- package/dist/assets/{swimlanes-2SLR337P-Bv1wYyTS.js → swimlanes-2SLR337P-S3fTHH2F.js} +1 -1
- package/dist/assets/swimlanesDiagram-TC7HE7FX-D4aUOLcM.js +8 -0
- package/dist/assets/{timeline-definition-EJHVYXUP-BMnrjUM5.js → timeline-definition-EJHVYXUP-BcOKypXw.js} +1 -1
- package/dist/assets/{usecaseDiagram-POWQR4AR-DQNQX-6S.js → usecaseDiagram-POWQR4AR-ekrATLwu.js} +1 -1
- package/dist/assets/{vennDiagram-UO4OBE2U-Cnv1OiVG.js → vennDiagram-UO4OBE2U-BN23smbd.js} +1 -1
- package/dist/assets/{wardleyDiagram-VNRHLVJA-Di1yp5Fs.js → wardleyDiagram-VNRHLVJA-ChulRrvn.js} +1 -1
- package/dist/assets/{xychartDiagram-PMCCYNJV-B_sh_5r0.js → xychartDiagram-PMCCYNJV-NFJS73i9.js} +1 -1
- package/dist/index.html +2 -2
- package/dist-server/companion/src/routes.js +5 -0
- package/dist-server/index.js +1947 -1487
- package/dist-server/openmausbot.js +36 -0
- package/dist-server/pair-cli.js +36 -0
- package/dist-server/server/chibitek-mcp-credentials.js +207 -0
- package/dist-server/server/chibitek-mcp-signin.js +124 -0
- package/dist-server/server/company-mcp-tenancy.js +2 -2
- package/dist-server/server/index.js +23 -15
- package/dist-server/server/mcp-tool-hints.js +15 -1
- package/dist-server/server/mcp-turn.js +2 -1
- package/dist-server/server/nexus-memory/backoff.js +40 -8
- package/dist-server/server/nexus-memory/client.js +44 -12
- package/dist-server/server/nexus-memory/import-offer-copy.js +9 -0
- package/dist-server/server/nexus-memory/import-offer.js +147 -0
- package/dist-server/server/nexus-memory/index.js +3 -3
- package/dist-server/server/repo-github.js +3 -1
- package/dist-server/server/routes/nexus-memory.js +15 -0
- package/dist-server/server/routine-mochii-sync.js +1 -1
- package/dist-server/server/stiki-desktop-session.js +18 -5
- package/dist-server/server/stiki-session.js +3 -2
- package/package.json +1 -1
- package/dist/assets/channel--GPtxJe9.js +0 -1
- package/dist/assets/index-DBOyvapT.css +0 -1
- package/dist/assets/swimlanesDiagram-TC7HE7FX-Drv2GtYA.js +0 -8
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { NexusInitializeError, NexusUnavailableError } from "./client.js";
|
|
1
|
+
import { NexusAuthError, NexusInitializeError, NexusUnavailableError } from "./client.js";
|
|
2
2
|
// One shared wait after Nexus fails: 1, 5, 15, then 30 minutes while the
|
|
3
|
-
// outage lasts (unreachable, or
|
|
4
|
-
//
|
|
3
|
+
// outage lasts (unreachable, or a refused sign-in that a refresh could not
|
|
4
|
+
// fix). A failure more than an hour after the previous one is a
|
|
5
5
|
// new blip and starts over at one minute, so a night of Wi-Fi drops does
|
|
6
6
|
// not leave every later call blocked for half an hour.
|
|
7
7
|
const WAITS_MS = [60_000, 300_000, 900_000, 1_800_000];
|
|
@@ -27,20 +27,48 @@ export class UnavailableBackoff {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
/** One failed initialize is retried and does not count. The retry failing
|
|
30
|
-
* trips the breaker.
|
|
31
|
-
|
|
30
|
+
* trips the breaker. A refused sign-in (NexusAuthError) is not an outage: it
|
|
31
|
+
* refreshes the Chibitek sign-in and retries at once on a client built with
|
|
32
|
+
* the new token; only when no new token comes back does it trip the breaker.
|
|
33
|
+
* Any other outage trips immediately.
|
|
34
|
+
*
|
|
35
|
+
* `client` may be a getter so a retry after a refresh reaches the client the
|
|
36
|
+
* new token built (nexus-memory/index.ts rebuilds it when the spec changes). */
|
|
37
|
+
export function guardNexusClient(client, backoff, now, log, signIn) {
|
|
38
|
+
const current = () => {
|
|
39
|
+
const resolved = typeof client === "function" ? client() : client;
|
|
40
|
+
if (!resolved)
|
|
41
|
+
throw new NexusUnavailableError("Nexus is not connected on this computer");
|
|
42
|
+
return resolved;
|
|
43
|
+
};
|
|
32
44
|
const finish = async (tool, args, timeoutMs) => {
|
|
33
45
|
try {
|
|
34
|
-
const result = await
|
|
46
|
+
const result = await current().call(tool, args, timeoutMs);
|
|
35
47
|
backoff.succeeded();
|
|
36
48
|
return result;
|
|
37
49
|
}
|
|
38
50
|
catch (error) {
|
|
39
|
-
if (!(error instanceof NexusInitializeError) && error instanceof NexusUnavailableError)
|
|
51
|
+
if (!(error instanceof NexusInitializeError) && !(error instanceof NexusAuthError) && error instanceof NexusUnavailableError)
|
|
40
52
|
backoff.failed(now());
|
|
41
53
|
throw error;
|
|
42
54
|
}
|
|
43
55
|
};
|
|
56
|
+
const afterSignInRefused = async (error, tool, args, timeoutMs) => {
|
|
57
|
+
if (signIn && await signIn.refresh().catch(() => false)) {
|
|
58
|
+
log("Nexus refused the sign-in; refreshed the Chibitek sign-in and retrying now");
|
|
59
|
+
try {
|
|
60
|
+
return await finish(tool, args, timeoutMs);
|
|
61
|
+
}
|
|
62
|
+
catch (again) {
|
|
63
|
+
if (again instanceof NexusAuthError || again instanceof NexusInitializeError)
|
|
64
|
+
backoff.failed(now());
|
|
65
|
+
throw again;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// Nothing new to try: wait like any outage rather than resend a refused token.
|
|
69
|
+
backoff.failed(now());
|
|
70
|
+
throw error;
|
|
71
|
+
};
|
|
44
72
|
return {
|
|
45
73
|
call: async (tool, args, timeoutMs) => {
|
|
46
74
|
const remaining = backoff.remainingMs(now());
|
|
@@ -50,6 +78,8 @@ export function guardNexusClient(client, backoff, now, log) {
|
|
|
50
78
|
return await finish(tool, args, timeoutMs);
|
|
51
79
|
}
|
|
52
80
|
catch (error) {
|
|
81
|
+
if (error instanceof NexusAuthError)
|
|
82
|
+
return afterSignInRefused(error, tool, args, timeoutMs);
|
|
53
83
|
if (!(error instanceof NexusInitializeError))
|
|
54
84
|
throw error;
|
|
55
85
|
log("Nexus initialize failed; retrying once");
|
|
@@ -57,12 +87,14 @@ export function guardNexusClient(client, backoff, now, log) {
|
|
|
57
87
|
return await finish(tool, args, timeoutMs);
|
|
58
88
|
}
|
|
59
89
|
catch (again) {
|
|
90
|
+
if (again instanceof NexusAuthError)
|
|
91
|
+
return afterSignInRefused(again, tool, args, timeoutMs);
|
|
60
92
|
if (again instanceof NexusInitializeError)
|
|
61
93
|
backoff.failed(now());
|
|
62
94
|
throw again;
|
|
63
95
|
}
|
|
64
96
|
}
|
|
65
97
|
},
|
|
66
|
-
close: () =>
|
|
98
|
+
close: () => current().close(),
|
|
67
99
|
};
|
|
68
100
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
// How the harness itself calls Nexus tools.
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
1
|
+
// How the harness itself calls Nexus tools. Bots reach Nexus through the
|
|
2
|
+
// configured `nexus` MCP server: on a Chibitek install, the bundled mcp-remote
|
|
3
|
+
// bridge carrying the person's Chibitek (Stiki) sign-in from Atomic itself
|
|
4
|
+
// (server/chibitek-mcp-credentials.ts), or its own cached browser sign-in
|
|
5
|
+
// when nobody signed in to Atomic. The harness speaks MCP to that same server, so
|
|
5
6
|
// every write lands under the signed-in person and no auth code changes.
|
|
6
7
|
// A remote `nexus` entry (url + headers) is spoken to over HTTP instead.
|
|
7
8
|
import { PROVIDER_CREDENTIAL_ENV, stripWorkspaceCredentialEnv } from "../config.js";
|
|
@@ -9,6 +10,7 @@ import { augmentedPath } from "../env-path.js";
|
|
|
9
10
|
import { createLineSplitter } from "../mcp-bridge.js";
|
|
10
11
|
import { McpHttpError, RemoteMcpClient } from "../mcp-http.js";
|
|
11
12
|
import { isRemoteMcpServer } from "../mcp-registry.js";
|
|
13
|
+
import { exitMeansSignInRequired, MCP_SIGN_IN_REQUIRED_MARKER } from "../mcp-remote-bridge.js";
|
|
12
14
|
import { killCliTree, spawnCli } from "../procs.js";
|
|
13
15
|
/** Nexus could not be reached (offline, signed out, timed out): retry later. */
|
|
14
16
|
export class NexusUnavailableError extends Error {
|
|
@@ -24,6 +26,15 @@ export class NexusInitializeError extends NexusUnavailableError {
|
|
|
24
26
|
this.name = "NexusInitializeError";
|
|
25
27
|
}
|
|
26
28
|
}
|
|
29
|
+
/** Nexus refused the sign-in (401, an expired or rejected token, or a bridge
|
|
30
|
+
* that would need a browser sign-in). Not an outage: the caller refreshes the
|
|
31
|
+
* Chibitek sign-in and retries at once (backoff.ts). */
|
|
32
|
+
export class NexusAuthError extends NexusUnavailableError {
|
|
33
|
+
constructor(message) {
|
|
34
|
+
super(message);
|
|
35
|
+
this.name = "NexusAuthError";
|
|
36
|
+
}
|
|
37
|
+
}
|
|
27
38
|
/** Nexus answered and refused this call (bad input): retrying will not help. */
|
|
28
39
|
export class NexusRejectedError extends Error {
|
|
29
40
|
constructor(message) {
|
|
@@ -35,7 +46,15 @@ const DEFAULT_TIMEOUT_MS = 20_000;
|
|
|
35
46
|
const PROTOCOL_VERSION = "2025-06-18";
|
|
36
47
|
/** Messages that mean "try again later", not "this input is wrong". */
|
|
37
48
|
const PRIVATE_SCOPE_ANSWER = /\b(?:private_scope_\w+|private_proof_invalid|personal_scope_requires_private_bot|personal_memory_cannot_be_shared)\b/;
|
|
38
|
-
|
|
49
|
+
/** Messages that mean "the sign-in was refused", checked before TRANSIENT. */
|
|
50
|
+
const AUTH_REFUSED = /unauthori[sz]ed|sign ?in|\btoken\b|\b401\b|ATOMIC_MCP_SIGN_IN_REQUIRED/i;
|
|
51
|
+
const TRANSIENT = /timed? ?out|timeout|ECONN|ENOTFOUND|EAI_AGAIN|fetch failed|network|socket|503|502|504|429|temporar|unavailable|not provisioned/i;
|
|
52
|
+
/** The error a refusal message stands for: sign-in, try-later, or final. */
|
|
53
|
+
function refusalError(message) {
|
|
54
|
+
if (AUTH_REFUSED.test(message))
|
|
55
|
+
return new NexusAuthError(message);
|
|
56
|
+
return TRANSIENT.test(message) ? new NexusUnavailableError(message) : new NexusRejectedError(message);
|
|
57
|
+
}
|
|
39
58
|
const BRIDGE_URL = /https?:\/\/[^\s"'<>]+/gi;
|
|
40
59
|
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
60
|
const BRIDGE_JWT = /\beyJ[A-Za-z0-9_-]{8,}(?:\.[A-Za-z0-9_-]{8,}){2}\b/g;
|
|
@@ -73,7 +92,7 @@ export function parseToolResult(result) {
|
|
|
73
92
|
// Nexus's private-scope answers are final, never "try later" (chibitek/nexus#151).
|
|
74
93
|
if (PRIVATE_SCOPE_ANSWER.test(message))
|
|
75
94
|
throw new NexusRejectedError(message);
|
|
76
|
-
throw
|
|
95
|
+
throw refusalError(message);
|
|
77
96
|
}
|
|
78
97
|
return parsed;
|
|
79
98
|
}
|
|
@@ -93,13 +112,15 @@ class HttpNexusClient {
|
|
|
93
112
|
}
|
|
94
113
|
catch (error) {
|
|
95
114
|
await client.close().catch(() => undefined);
|
|
115
|
+
if (error instanceof McpHttpError && error.kind === "status" && error.status === 401)
|
|
116
|
+
throw new NexusAuthError("Nexus answered HTTP 401");
|
|
96
117
|
throw new NexusInitializeError(error instanceof Error ? error.message : "Nexus initialize failed");
|
|
97
118
|
}
|
|
98
119
|
this.client = client;
|
|
99
120
|
return client;
|
|
100
121
|
})().catch((error) => {
|
|
101
122
|
this.ready = null;
|
|
102
|
-
throw error instanceof NexusInitializeError ? error : new NexusInitializeError(error instanceof Error ? error.message : "Nexus initialize failed");
|
|
123
|
+
throw error instanceof NexusInitializeError || error instanceof NexusAuthError ? error : new NexusInitializeError(error instanceof Error ? error.message : "Nexus initialize failed");
|
|
103
124
|
});
|
|
104
125
|
return this.ready;
|
|
105
126
|
}
|
|
@@ -114,6 +135,9 @@ class HttpNexusClient {
|
|
|
114
135
|
throw error;
|
|
115
136
|
// A dropped session must re-handshake next time.
|
|
116
137
|
await this.reset();
|
|
138
|
+
if (error instanceof McpHttpError && error.kind === "status" && error.status === 401) {
|
|
139
|
+
throw new NexusAuthError("Nexus answered HTTP 401");
|
|
140
|
+
}
|
|
117
141
|
if (error instanceof McpHttpError && error.kind === "status" && error.status && error.status < 500 && ![401, 403, 408, 429].includes(error.status)) {
|
|
118
142
|
throw new NexusRejectedError(`Nexus answered HTTP ${error.status}`);
|
|
119
143
|
}
|
|
@@ -217,7 +241,7 @@ class StdioNexusClient {
|
|
|
217
241
|
clearTimeout(entry.timer);
|
|
218
242
|
if (frame.error !== undefined) {
|
|
219
243
|
const message = isRecord(frame.error) && typeof frame.error.message === "string" ? frame.error.message : "Nexus error";
|
|
220
|
-
entry.reject(
|
|
244
|
+
entry.reject(refusalError(message));
|
|
221
245
|
}
|
|
222
246
|
else
|
|
223
247
|
entry.resolve(frame.result);
|
|
@@ -225,7 +249,10 @@ class StdioNexusClient {
|
|
|
225
249
|
child.stdout.on("data", (chunk) => splitter.push(chunk));
|
|
226
250
|
let logged = 0;
|
|
227
251
|
let handshook = false;
|
|
252
|
+
let signInRefused = false;
|
|
228
253
|
const errSplit = createLineSplitter((line) => {
|
|
254
|
+
if (line.includes(MCP_SIGN_IN_REQUIRED_MARKER))
|
|
255
|
+
signInRefused = true;
|
|
229
256
|
const redacted = redactBridgeLine(line);
|
|
230
257
|
// ponytail: 20 lines per child; raise if a handshake needs more of the log
|
|
231
258
|
if (!redacted || logged >= 20)
|
|
@@ -234,14 +261,19 @@ class StdioNexusClient {
|
|
|
234
261
|
this.log?.(`bridge: ${redacted}`);
|
|
235
262
|
});
|
|
236
263
|
child.stderr.on("data", (chunk) => errSplit.push(chunk));
|
|
237
|
-
const gone = (message) => {
|
|
264
|
+
const gone = (message, code) => {
|
|
238
265
|
errSplit.flush();
|
|
239
266
|
if (this.child !== child)
|
|
240
267
|
return;
|
|
241
|
-
|
|
268
|
+
// The bridge exits 77 when the server refused its sign-in and it may
|
|
269
|
+
// not open a browser (server/mcp-remote-bridge.ts).
|
|
270
|
+
if (signInRefused || exitMeansSignInRequired(code ?? null))
|
|
271
|
+
this.fail(new NexusAuthError("Nexus refused the sign-in"));
|
|
272
|
+
else
|
|
273
|
+
this.fail(handshook ? new NexusUnavailableError(message) : new NexusInitializeError(message));
|
|
242
274
|
};
|
|
243
275
|
child.once("error", () => gone("Nexus bridge failed"));
|
|
244
|
-
child.once("close", () => gone("Nexus bridge stopped"));
|
|
276
|
+
child.once("close", (code) => gone("Nexus bridge stopped", code));
|
|
245
277
|
await this.send("initialize", {
|
|
246
278
|
protocolVersion: PROTOCOL_VERSION,
|
|
247
279
|
capabilities: {},
|
|
@@ -252,7 +284,7 @@ class StdioNexusClient {
|
|
|
252
284
|
})().catch((error) => {
|
|
253
285
|
const message = error instanceof Error ? error.message : String(error);
|
|
254
286
|
this.fail(error instanceof Error ? error : new Error(message));
|
|
255
|
-
throw error instanceof NexusInitializeError ? error : new NexusInitializeError(message);
|
|
287
|
+
throw error instanceof NexusInitializeError || error instanceof NexusAuthError ? error : new NexusInitializeError(message);
|
|
256
288
|
});
|
|
257
289
|
return this.ready;
|
|
258
290
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Nexus's consent copy, verbatim. Kept free of imports so the web app's
|
|
2
|
+
// tests can read it without pulling the server into the browser tsconfig.
|
|
3
|
+
export const CONSENT_COPY = `**Nexus is now connected.**
|
|
4
|
+
|
|
5
|
+
Nexus is your second brain in the cloud. It keeps what you've built up with your AI (who you are, how you work, your projects, people, preferences and decisions) in one place, so it follows you no matter which harness you use.
|
|
6
|
+
|
|
7
|
+
Do you want to copy all your memories from this harness into Nexus? **We recommend you do.** That's the whole point of Nexus: so you don't lose what you've already established here.
|
|
8
|
+
|
|
9
|
+
**[Yes, copy my memories to Nexus]** [Not now]`;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// The Nexus memory-import offer, for Atomic itself (Erick, 2026-11-20).
|
|
2
|
+
//
|
|
3
|
+
// Every other harness gets one offer the first time Nexus is turned on:
|
|
4
|
+
// "Nexus is now connected ... copy all your memories from this harness into
|
|
5
|
+
// Nexus?" Atomic gets the same offer, once per person, with one extra step in
|
|
6
|
+
// front: check the person is signed in to Chibitek first. Signed out or an
|
|
7
|
+
// expired sign-in shows a sign-in prompt, and the offer still follows once
|
|
8
|
+
// they have signed in. It never blocks their work: Not now just closes it.
|
|
9
|
+
//
|
|
10
|
+
// This module only decides what to show. It uses the sign-in the app already
|
|
11
|
+
// has (server/stiki-session.ts: accessToken(), then refresh() once) and the
|
|
12
|
+
// existing guarded Nexus client; it does not touch tokens, refresh timing or
|
|
13
|
+
// the MCP credential files. The offer text is Nexus's (nexus_first_connect,
|
|
14
|
+
// harness "atomic"), with the pinned copy below as the fallback. It is the
|
|
15
|
+
// text in nexus-memory-import-handoff.md, word for word.
|
|
16
|
+
import { existsSync, mkdirSync, readFileSync } from "node:fs";
|
|
17
|
+
import { dirname, join } from "node:path";
|
|
18
|
+
import { writeFileAtomic } from "../atomic.js";
|
|
19
|
+
import { NexusAuthError } from "./client.js";
|
|
20
|
+
import { CONSENT_COPY } from "./import-offer-copy.js";
|
|
21
|
+
export { CONSENT_COPY };
|
|
22
|
+
export const IMPORT_HARNESS = "atomic";
|
|
23
|
+
export const HANDOFF_PROMPT = `I'm moving my memory into Nexus, my second brain in the cloud, so I keep everything I've established with you no matter which AI I use. Give me everything you have in memory about me and everything I've already shared with you. I mean everything. Don't summarize it away, don't leave anything out, and don't ask me any questions first.
|
|
24
|
+
|
|
25
|
+
Include all of it:
|
|
26
|
+
- Every saved memory, custom instruction, profile detail and preference you hold about me, word for word where you can.
|
|
27
|
+
- Who I am: name, role, company, location, time zone, family, background.
|
|
28
|
+
- How I want you to work: tone, format, rules, corrections I've given you, things I've told you to always or never do.
|
|
29
|
+
- My work: companies, products, projects, goals, plans, decisions and the reasons for them, with dates where you know them.
|
|
30
|
+
- People and organizations I've mentioned: who they are, their roles, and how they relate to me.
|
|
31
|
+
- Tools, accounts, systems and workflows I use (no passwords, keys or codes).
|
|
32
|
+
- Ongoing tasks, open questions and anything I said I'd come back to.
|
|
33
|
+
- Anything else I've shared that you would want to know if you were starting fresh tomorrow.
|
|
34
|
+
|
|
35
|
+
Format: plain Markdown, grouped under headings, one fact per bullet, with the date learned when you know it. Put it in one code block so it can be copied in full. If it's long, keep going across as many messages as it takes until everything is out, then end with the line \`END OF NEXUS MEMORY EXPORT\`.`;
|
|
36
|
+
/** What the person's bot is sent when they say Yes: the handoff, word for
|
|
37
|
+
* word, then one separate line asking for the save. */
|
|
38
|
+
export function importMessage(handoff = HANDOFF_PROMPT) {
|
|
39
|
+
return `${handoff}\n\n---\nWhen the export is complete, save all of it unchanged to Nexus with the Nexus import_memories tool (harness "${IMPORT_HARNESS}"), then tell me: "Your memories from ${IMPORT_HARNESS} are now in Nexus."`;
|
|
40
|
+
}
|
|
41
|
+
/** A Yes whose export never reached Nexus is offered again after this long. */
|
|
42
|
+
export const IMPORTING_RETRY_MS = 24 * 60 * 60_000;
|
|
43
|
+
const text = (value) => (typeof value === "string" ? value : "");
|
|
44
|
+
export class NexusImportOffer {
|
|
45
|
+
deps;
|
|
46
|
+
path;
|
|
47
|
+
now;
|
|
48
|
+
log;
|
|
49
|
+
constructor(deps) {
|
|
50
|
+
this.deps = deps;
|
|
51
|
+
this.path = join(deps.dataDir, "nexus-outbox", "import-offer.json");
|
|
52
|
+
this.now = deps.now ?? Date.now;
|
|
53
|
+
this.log = deps.log ?? ((message) => console.warn(`[nexus-import-offer] ${message}`));
|
|
54
|
+
}
|
|
55
|
+
ledger() {
|
|
56
|
+
try {
|
|
57
|
+
const raw = JSON.parse(readFileSync(this.path, "utf8"));
|
|
58
|
+
return raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return {};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
record(userId, entry) {
|
|
65
|
+
const next = { ...this.ledger(), [userId]: entry };
|
|
66
|
+
if (!existsSync(dirname(this.path)))
|
|
67
|
+
mkdirSync(dirname(this.path), { recursive: true });
|
|
68
|
+
writeFileAtomic(this.path, JSON.stringify(next));
|
|
69
|
+
}
|
|
70
|
+
answered(entry) {
|
|
71
|
+
if (!entry)
|
|
72
|
+
return false;
|
|
73
|
+
return entry.state === "declined" || this.now() - entry.at < IMPORTING_RETRY_MS;
|
|
74
|
+
}
|
|
75
|
+
/** Signed in with a usable token? Renews once; never loops. */
|
|
76
|
+
async signInState() {
|
|
77
|
+
const session = this.deps.session();
|
|
78
|
+
const identity = session.identity();
|
|
79
|
+
if (!identity)
|
|
80
|
+
return { signIn: "signed_out" };
|
|
81
|
+
let token = null;
|
|
82
|
+
try {
|
|
83
|
+
token = await session.accessToken();
|
|
84
|
+
if (!token && session.refresh)
|
|
85
|
+
token = await session.refresh();
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
token = null;
|
|
89
|
+
}
|
|
90
|
+
return token ? { userId: identity.userId } : { signIn: "expired" };
|
|
91
|
+
}
|
|
92
|
+
/** What to show now. Safe to call on launch and after a sign-in change. */
|
|
93
|
+
async check() {
|
|
94
|
+
if (!this.deps.enabled())
|
|
95
|
+
return { status: "hidden", reason: "not_connected" };
|
|
96
|
+
const signedIn = await this.signInState();
|
|
97
|
+
if ("signIn" in signedIn) {
|
|
98
|
+
// A person who already answered on this computer is not asked to sign in for it.
|
|
99
|
+
const entries = Object.values(this.ledger());
|
|
100
|
+
if (entries.length > 0 && entries.every((entry) => this.answered(entry)))
|
|
101
|
+
return { status: "hidden", reason: "answered" };
|
|
102
|
+
return { status: "signIn", reason: signedIn.signIn };
|
|
103
|
+
}
|
|
104
|
+
if (this.answered(this.ledger()[signedIn.userId]))
|
|
105
|
+
return { status: "hidden", reason: "answered" };
|
|
106
|
+
const client = this.deps.client();
|
|
107
|
+
if (!client)
|
|
108
|
+
return { status: "hidden", reason: "not_connected" };
|
|
109
|
+
let result;
|
|
110
|
+
try {
|
|
111
|
+
result = await client.call("nexus_first_connect", { harness: IMPORT_HARNESS });
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
// The guard already renewed the sign-in once. Still refused: one "Sign in again".
|
|
115
|
+
if (error instanceof NexusAuthError)
|
|
116
|
+
return { status: "signIn", reason: "expired" };
|
|
117
|
+
this.log(`first-connect check failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
118
|
+
return { status: "hidden", reason: "unavailable" };
|
|
119
|
+
}
|
|
120
|
+
if (result.offer !== true) {
|
|
121
|
+
return { status: "hidden", reason: result.reason === "already_answered" || result.reason === "declined" ? "answered" : "no_offer" };
|
|
122
|
+
}
|
|
123
|
+
const handoff = text(result.handoff_prompt).trim() ? text(result.handoff_prompt) : HANDOFF_PROMPT;
|
|
124
|
+
return {
|
|
125
|
+
status: "offer",
|
|
126
|
+
harness: IMPORT_HARNESS,
|
|
127
|
+
consentCopy: text(result.consent_copy).trim() ? text(result.consent_copy) : CONSENT_COPY,
|
|
128
|
+
message: importMessage(handoff),
|
|
129
|
+
botId: this.deps.botId(),
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
/** Yes ("import") or Not now ("decline"). Never throws over Nexus being away. */
|
|
133
|
+
async answer(answer) {
|
|
134
|
+
const identity = this.deps.session().identity();
|
|
135
|
+
const userId = identity?.userId ?? "unknown";
|
|
136
|
+
this.record(userId, { state: answer === "decline" ? "declined" : "importing", at: this.now() });
|
|
137
|
+
if (answer === "decline") {
|
|
138
|
+
try {
|
|
139
|
+
await this.deps.client()?.call("nexus_first_connect", { harness: IMPORT_HARNESS, answer: "decline" });
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
this.log(`could not tell Nexus about Not now: ${error instanceof Error ? error.message : String(error)}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return { ok: true };
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -171,8 +171,8 @@ export class NexusMemory {
|
|
|
171
171
|
this.client ??= this.deps.clientFor(cfg);
|
|
172
172
|
return this.client;
|
|
173
173
|
}
|
|
174
|
-
const spec = customMcpServers(cfg).nexus;
|
|
175
|
-
const key = JSON.stringify(spec ?? null);
|
|
174
|
+
const spec = this.deps.serverSpec ? this.deps.serverSpec(customMcpServers(cfg).nexus) : customMcpServers(cfg).nexus;
|
|
175
|
+
const key = JSON.stringify(spec ?? null); // holds a mounted token (memory only): a refreshed token builds a new client
|
|
176
176
|
if (key !== this.clientKey) {
|
|
177
177
|
void this.client?.close();
|
|
178
178
|
this.client = nexusClientFor(spec, (message) => this.log(message));
|
|
@@ -185,7 +185,7 @@ export class NexusMemory {
|
|
|
185
185
|
const client = this.rawClient();
|
|
186
186
|
if (!client)
|
|
187
187
|
return null;
|
|
188
|
-
return guardNexusClient(
|
|
188
|
+
return guardNexusClient(() => this.rawClient(), this.backoff, this.now, this.log, this.deps.signIn);
|
|
189
189
|
}
|
|
190
190
|
// ── the Private Bot's signed calls ─────────────────────────────────────
|
|
191
191
|
privateKey() {
|
|
@@ -13,10 +13,12 @@ export const GITHUB_REPO_NAME = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,38})\/[A-Za-z0-9_
|
|
|
13
13
|
const LIST_URL = "user/repos?per_page=100&sort=pushed&affiliation=owner,collaborator,organization_member";
|
|
14
14
|
const JOB_TTL_MS = 60 * 60 * 1000;
|
|
15
15
|
export class GitHubRepos {
|
|
16
|
+
jobs = new Map();
|
|
17
|
+
// Plain fields, not parameter properties: Node's type stripping (the dev
|
|
18
|
+
// and verification server) refuses those.
|
|
16
19
|
registry;
|
|
17
20
|
run;
|
|
18
21
|
folder;
|
|
19
|
-
jobs = new Map();
|
|
20
22
|
constructor(registry, run = runCommand, folder = join(homedir(), "repos")) {
|
|
21
23
|
this.registry = registry;
|
|
22
24
|
this.run = run;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { NexusImportOffer } from "../nexus-memory/import-offer.js";
|
|
1
2
|
import { PASS } from "./table.js";
|
|
2
3
|
const BOT = /^\/api\/nexus-memory\/bots\/([\w-]{1,128})(\/memories(?:\/([0-9a-fA-F-]{36}))?)?$/;
|
|
3
4
|
function errorText(error) {
|
|
@@ -58,6 +59,20 @@ export function createNexusMemoryRoutes(deps) {
|
|
|
58
59
|
deps.save(parsed.patch);
|
|
59
60
|
return json(res, 200, deps.status());
|
|
60
61
|
}
|
|
62
|
+
if (path === "/api/nexus-memory/import-offer") {
|
|
63
|
+
const offer = deps.importOffer;
|
|
64
|
+
if (!offer)
|
|
65
|
+
return json(res, 404, { error: "not found" });
|
|
66
|
+
if (method === "GET")
|
|
67
|
+
return json(res, 200, await offer.check());
|
|
68
|
+
if (method !== "POST")
|
|
69
|
+
return json(res, 405, { error: "method not allowed" });
|
|
70
|
+
const body = await readBody(req, 1_024);
|
|
71
|
+
const answer = body && typeof body === "object" && !Array.isArray(body) ? body.answer : undefined;
|
|
72
|
+
if (answer !== "import" && answer !== "decline")
|
|
73
|
+
return json(res, 400, { error: 'answer must be "import" or "decline"' });
|
|
74
|
+
return json(res, 200, await offer.answer(answer));
|
|
75
|
+
}
|
|
61
76
|
if (path === "/api/nexus-memory/flush") {
|
|
62
77
|
if (method !== "POST")
|
|
63
78
|
return json(res, 405, { error: "method not allowed" });
|
|
@@ -217,7 +217,7 @@ export class RoutineMochiiSync {
|
|
|
217
217
|
clientFor(cfg) {
|
|
218
218
|
if (this.deps.clientFor)
|
|
219
219
|
return (this.client ??= this.deps.clientFor(cfg));
|
|
220
|
-
const spec = customMcpServers(cfg).mochii;
|
|
220
|
+
const spec = this.deps.serverSpec ? this.deps.serverSpec(customMcpServers(cfg).mochii) : customMcpServers(cfg).mochii;
|
|
221
221
|
const key = JSON.stringify(spec ?? null);
|
|
222
222
|
if (key !== this.clientKey) {
|
|
223
223
|
void this.client?.close();
|
|
@@ -83,15 +83,24 @@ export class DesktopStikiSession {
|
|
|
83
83
|
const held = this.held;
|
|
84
84
|
return held && held.expiresAt - this.now() > MIN_VALID_MS ? held.token : null;
|
|
85
85
|
}
|
|
86
|
+
/** A server refused the held token: ask main to refresh it now (main
|
|
87
|
+
* rate-limits this), then hand out whatever it answered. */
|
|
88
|
+
async refresh() {
|
|
89
|
+
if (!this.held)
|
|
90
|
+
return null;
|
|
91
|
+
await this.askMain(true);
|
|
92
|
+
const held = this.held;
|
|
93
|
+
return held && held.expiresAt - this.now() > MIN_VALID_MS ? held.token : null;
|
|
94
|
+
}
|
|
86
95
|
onChange(listener) {
|
|
87
96
|
this.listeners.add(listener);
|
|
88
97
|
return () => this.listeners.delete(listener);
|
|
89
98
|
}
|
|
90
|
-
askMain() {
|
|
91
|
-
if (this.asking)
|
|
99
|
+
askMain(refresh = false) {
|
|
100
|
+
if (this.asking && !refresh)
|
|
92
101
|
return this.asking;
|
|
93
102
|
const requestId = randomUUID();
|
|
94
|
-
|
|
103
|
+
const answered = new Promise((resolve) => {
|
|
95
104
|
const timer = setTimeout(() => {
|
|
96
105
|
this.waiting.delete(requestId);
|
|
97
106
|
resolve();
|
|
@@ -101,12 +110,16 @@ export class DesktopStikiSession {
|
|
|
101
110
|
clearTimeout(timer);
|
|
102
111
|
resolve();
|
|
103
112
|
});
|
|
104
|
-
if (!this.send({ type: "openmausbot:stiki-token-request", requestId })) {
|
|
113
|
+
if (!this.send({ type: "openmausbot:stiki-token-request", requestId, ...(refresh ? { refresh: true } : {}) })) {
|
|
105
114
|
clearTimeout(timer);
|
|
106
115
|
this.waiting.delete(requestId);
|
|
107
116
|
resolve();
|
|
108
117
|
}
|
|
109
|
-
})
|
|
118
|
+
});
|
|
119
|
+
// A forced refresh runs on its own; it never replaces the shared ask.
|
|
120
|
+
if (refresh)
|
|
121
|
+
return answered;
|
|
122
|
+
this.asking = answered.finally(() => {
|
|
110
123
|
this.asking = null;
|
|
111
124
|
});
|
|
112
125
|
return this.asking;
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
// (electron/stiki-signin.mjs): PKCE public client, tokens in the OS-encrypted
|
|
5
5
|
// credential store, refreshed there, shown in Settings. The desktop server
|
|
6
6
|
// registers server/stiki-desktop-session.ts with `setStikiSessionSource`.
|
|
7
|
-
// This module is the seam: Team Rooms (server/team-rooms/)
|
|
8
|
-
//
|
|
7
|
+
// This module is the seam: Team Rooms (server/team-rooms/) and the Chibitek
|
|
8
|
+
// MCP servers (server/chibitek-mcp-credentials.ts) read the signed-in person
|
|
9
|
+
// only through `stikiSession()`. Without a source (plain
|
|
9
10
|
// Node, or nobody signed in) Atomic is signed out and Team Rooms stay off;
|
|
10
11
|
// everything else in Atomic keeps working.
|
|
11
12
|
//
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{U as a,C as n}from"./mermaid.core-BINI6H7d.js";const t=(r,o)=>a.lang.round(n.parse(r)[o]);export{t as c};
|