@chibitek/chibi 0.1.201 → 0.1.203

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/dist/assets/{TerminalPanel-CF3ynjQ5.js → TerminalPanel-BElP4AKU.js} +1 -1
  2. package/dist/assets/{abnfDiagram-O67JEVCF-DsLr5Rkp.js → abnfDiagram-O67JEVCF-DIuUOwmd.js} +1 -1
  3. package/dist/assets/{arc-BP9MW1JT.js → arc-Dds_KTq7.js} +1 -1
  4. package/dist/assets/{architectureDiagram-NJMV4G6O-DqqmVruY.js → architectureDiagram-NJMV4G6O-eLk2tjr6.js} +1 -1
  5. package/dist/assets/{blockDiagram-BEXU5L5S-DCZycPW_.js → blockDiagram-BEXU5L5S-_le6ltg_.js} +1 -1
  6. package/dist/assets/{c4Diagram-YGBWAQC7-DAt7A5JI.js → c4Diagram-YGBWAQC7-DrU02MIb.js} +1 -1
  7. package/dist/assets/channel-BpbK6yrb.js +1 -0
  8. package/dist/assets/{chunk-2Q5K7J3B-D4XUKzBr.js → chunk-2Q5K7J3B-rcI6MSvp.js} +1 -1
  9. package/dist/assets/{chunk-3FUC2YCW-BvKRlW0a.js → chunk-3FUC2YCW-39HTD7JO.js} +2 -2
  10. package/dist/assets/{chunk-5VM5RSS4-CpaqfcXB.js → chunk-5VM5RSS4-CrSmXsvZ.js} +1 -1
  11. package/dist/assets/{chunk-GTNCS2PH-bFX_YBLa.js → chunk-GTNCS2PH-CyO-M-l3.js} +1 -1
  12. package/dist/assets/{chunk-GWA4HPMP-D4ceVX3-.js → chunk-GWA4HPMP-CTkpzXCy.js} +1 -1
  13. package/dist/assets/{chunk-JWPE2WC7-BrM5oyHo.js → chunk-JWPE2WC7-DmoIZQg3.js} +1 -1
  14. package/dist/assets/{chunk-NETBCI7D-DJCITo_6.js → chunk-NETBCI7D-Ctm1X9cr.js} +1 -1
  15. package/dist/assets/{chunk-WEXAMYUT-DE5Rbq8q.js → chunk-WEXAMYUT-LZxb50vI.js} +1 -1
  16. package/dist/assets/{chunk-XXDRQBXY-C6QndzP7.js → chunk-XXDRQBXY-DnrD0iub.js} +1 -1
  17. package/dist/assets/{classDiagram-v2-NBCMYWYE-DupxtheF.js → classDiagram-v2-NBCMYWYE-heTSNDkY.js} +1 -1
  18. package/dist/assets/{cose-bilkent-JH36ORCC-K2_JJ1Os.js → cose-bilkent-JH36ORCC-DZjSYkXZ.js} +1 -1
  19. package/dist/assets/{cynefin-OW5HDTMX-D1iCt_1r.js → cynefin-OW5HDTMX-wQcMt3uT.js} +1 -1
  20. package/dist/assets/{cynefinDiagram-VND7K2PF-BxIP-LPT.js → cynefinDiagram-VND7K2PF-5E35iM5-.js} +1 -1
  21. package/dist/assets/{dagre-6A5THRUB-C9f6kI0w.js → dagre-6A5THRUB-DiPoKIW2.js} +1 -1
  22. package/dist/assets/{diagram-22UHCM2B-DX1Js_iQ.js → diagram-22UHCM2B-BwpuuQcs.js} +1 -1
  23. package/dist/assets/{diagram-3UASUU5V-Dok5oHqH.js → diagram-3UASUU5V-D5Rl9ZRb.js} +1 -1
  24. package/dist/assets/{diagram-ATOU4E4O-CZjPw12I.js → diagram-ATOU4E4O-CZLQxysq.js} +1 -1
  25. package/dist/assets/{diagram-CDSNMT55-CcdGyWm0.js → diagram-CDSNMT55-DZVHIPfz.js} +1 -1
  26. package/dist/assets/{diagram-MLGK6HIB-BuyhR8Yt.js → diagram-MLGK6HIB-C1Pi9_am.js} +1 -1
  27. package/dist/assets/{diagram-MPIPVDR6-DyfzZWWJ.js → diagram-MPIPVDR6-DDj2I4vu.js} +1 -1
  28. package/dist/assets/{ebnfDiagram-ZINNZB2B-DbX8lcW9.js → ebnfDiagram-ZINNZB2B-lbaLM_av.js} +1 -1
  29. package/dist/assets/{elk-276RUBZZ-B_1y08rH.js → elk-276RUBZZ-wXqylexg.js} +1 -1
  30. package/dist/assets/{erDiagram-OPXOYQCR-CMNLleGm.js → erDiagram-OPXOYQCR-CpLdyMbT.js} +1 -1
  31. package/dist/assets/{flowDiagram-KWPJA3E3-BWNxAxrN.js → flowDiagram-KWPJA3E3-CzDrX1gh.js} +1 -1
  32. package/dist/assets/{ganttDiagram-FUAMR5RP-DIbuHGn_.js → ganttDiagram-FUAMR5RP-DKW5crQd.js} +1 -1
  33. package/dist/assets/{gitGraphDiagram-X574FWY7-DOQ7lEBd.js → gitGraphDiagram-X574FWY7-DqAcp3D0.js} +1 -1
  34. package/dist/assets/index-C36j3Mf7.css +1 -0
  35. package/dist/assets/{index-AVvV2BDP.js → index-gpLNKyYq.js} +166 -166
  36. package/dist/assets/{index-DwCyxkQ-.js → index-rupwTDyf.js} +1 -1
  37. package/dist/assets/{infoDiagram-VRGFBTTK-B6jXr3vk.js → infoDiagram-VRGFBTTK-LYkest4n.js} +1 -1
  38. package/dist/assets/{ishikawaDiagram-OU5B5YK6-BMzUYIuP.js → ishikawaDiagram-OU5B5YK6-xRPEtSHz.js} +1 -1
  39. package/dist/assets/{journeyDiagram-ZHPQQLJL-BSna9Sw4.js → journeyDiagram-ZHPQQLJL-PBy6VPoF.js} +1 -1
  40. package/dist/assets/{kanban-definition-PNTS6WVX-nGY_xsmB.js → kanban-definition-PNTS6WVX-CCzY9zIb.js} +1 -1
  41. package/dist/assets/{linear-ClawroOG.js → linear-CQVIekKt.js} +1 -1
  42. package/dist/assets/{mermaid.core-QWILSY7q.js → mermaid.core-COJbmdxu.js} +5 -5
  43. package/dist/assets/{mindmap-definition-NLK3R4M7-BHBjOj_N.js → mindmap-definition-NLK3R4M7-BqBK52Gh.js} +1 -1
  44. package/dist/assets/{pegDiagram-GJSIUBJH-BEhI0umY.js → pegDiagram-GJSIUBJH-DclCDmF-.js} +1 -1
  45. package/dist/assets/{pieDiagram-5QR66LMP-BNrNnFcF.js → pieDiagram-5QR66LMP-Cnc_7KQD.js} +1 -1
  46. package/dist/assets/{quadrantDiagram-O4NWA36T-DU8ZKo3R.js → quadrantDiagram-O4NWA36T-CsnEf2Rz.js} +1 -1
  47. package/dist/assets/{railroadDiagram-XR7U4H2S-CXpikGSY.js → railroadDiagram-XR7U4H2S-CpkTQd_u.js} +1 -1
  48. package/dist/assets/{requirementDiagram-PLB6GJNP-T2kWY6dy.js → requirementDiagram-PLB6GJNP-BRMB6afU.js} +1 -1
  49. package/dist/assets/{sankeyDiagram-IPEJSGJF-DUVsoHCX.js → sankeyDiagram-IPEJSGJF-DnelOAiT.js} +1 -1
  50. package/dist/assets/{sequenceDiagram-PO4LG4MO-BqI-CnQQ.js → sequenceDiagram-PO4LG4MO-CdYdcgja.js} +1 -1
  51. package/dist/assets/{sizeCapture-INFHLROL-CHRKcWjb.js → sizeCapture-INFHLROL-BBOLLhDe.js} +1 -1
  52. package/dist/assets/{stateDiagram-v2-GCMORJYK-Drb1kh-m.js → stateDiagram-v2-GCMORJYK-DyBxB96X.js} +1 -1
  53. package/dist/assets/{swimlanes-2SLR337P-D6bNO7iC.js → swimlanes-2SLR337P-BsBjZgxg.js} +1 -1
  54. package/dist/assets/swimlanesDiagram-TC7HE7FX-B2yzMjDy.js +8 -0
  55. package/dist/assets/{timeline-definition-EJHVYXUP-30UJPQln.js → timeline-definition-EJHVYXUP-Dfri51mC.js} +1 -1
  56. package/dist/assets/{usecaseDiagram-POWQR4AR-CsfAqILe.js → usecaseDiagram-POWQR4AR-fTzUxcQM.js} +1 -1
  57. package/dist/assets/{vennDiagram-UO4OBE2U-D63qiwyq.js → vennDiagram-UO4OBE2U--_Z-CWw0.js} +1 -1
  58. package/dist/assets/{wardleyDiagram-VNRHLVJA-CwMexqnm.js → wardleyDiagram-VNRHLVJA-Ce926wEL.js} +1 -1
  59. package/dist/assets/{xychartDiagram-PMCCYNJV-DFkAUNxr.js → xychartDiagram-PMCCYNJV-DJRGcYGv.js} +1 -1
  60. package/dist/index.html +2 -2
  61. package/dist-server/companion/src/routes.js +5 -0
  62. package/dist-server/index.js +1625 -1425
  63. package/dist-server/openmausbot.js +5 -0
  64. package/dist-server/pair-cli.js +5 -0
  65. package/dist-server/server/index.js +6 -4
  66. package/dist-server/server/nexus-memory/import-offer-copy.js +9 -0
  67. package/dist-server/server/nexus-memory/import-offer.js +147 -0
  68. package/dist-server/server/ready-sweep.js +60 -0
  69. package/dist-server/server/routes/nexus-memory.js +15 -0
  70. package/dist-server/server/store.js +1 -1
  71. package/dist-server/shared/badge-count.js +10 -0
  72. package/dist-server/shared/ready-queue.js +70 -0
  73. package/package.json +1 -1
  74. package/dist/assets/channel-CfAu_VOE.js +0 -1
  75. package/dist/assets/index-DBOyvapT.css +0 -1
  76. package/dist/assets/swimlanesDiagram-TC7HE7FX-BBg0kB8F.js +0 -8
@@ -62357,6 +62357,11 @@ var ALLOWED = [
62357
62357
  // on/off only. The full server list stays on the computer, since a local
62358
62358
  // server's arguments can carry anything.
62359
62359
  { method: "GET", path: /^\/api\/mcp\/defaults$/ },
62360
+ // The Nexus memory-import offer the computer decides on (sign-in check
62361
+ // included): what to show, and the person's answer. Nothing else under
62362
+ // /api/nexus-memory is reachable from a phone.
62363
+ { method: "GET", path: /^\/api\/nexus-memory\/import-offer$/ },
62364
+ { method: "POST", path: /^\/api\/nexus-memory\/import-offer$/ },
62360
62365
  // A marketplace connect card. The harness adds only Atomic's featured,
62361
62366
  // vendor-run servers, threat-scans them and saves them switched off.
62362
62367
  { method: "POST", path: /^\/api\/mcp\/registry\/add$/ }
@@ -62357,6 +62357,11 @@ var ALLOWED = [
62357
62357
  // on/off only. The full server list stays on the computer, since a local
62358
62358
  // server's arguments can carry anything.
62359
62359
  { method: "GET", path: /^\/api\/mcp\/defaults$/ },
62360
+ // The Nexus memory-import offer the computer decides on (sign-in check
62361
+ // included): what to show, and the person's answer. Nothing else under
62362
+ // /api/nexus-memory is reachable from a phone.
62363
+ { method: "GET", path: /^\/api\/nexus-memory\/import-offer$/ },
62364
+ { method: "POST", path: /^\/api\/nexus-memory\/import-offer$/ },
62360
62365
  // A marketplace connect card. The harness adds only Atomic's featured,
62361
62366
  // vendor-run servers, threat-scans them and saves them switched off.
62362
62367
  { method: "POST", path: /^\/api\/mcp\/registry\/add$/ }
@@ -1,5 +1,6 @@
1
1
  import "../electron/socket-qos.mjs";
2
2
  import { createMessageFileRoutes } from "./routes/message-file.js";
3
+ import { markThreadLooked, startReadyBacklogSweep } from "./ready-sweep.js";
3
4
  import { SharedDeliverables, createSharedDeliverablesRoutes, sharedDeliverableAccess } from "./shared-deliverables.js";
4
5
  import { connectionCredentialServer } from "./connection-credential.js";
5
6
  import { requestCredentialCard } from "./credential-card-request.js";
@@ -321,7 +322,7 @@ import { createSubscriptionBotRoutes } from "./routes/subscription-bots.js";
321
322
  import { createTeamRoomsRoutes } from "./routes/team-rooms.js";
322
323
  import { TeamRoomsHost } from "./team-rooms/host.js";
323
324
  import { engineCanHideFiles, restrictIntegrations, roomPromptSections, roomTurnInput } from "./team-rooms/turn.js";
324
- import { createNexusMemoryRoutes } from "./routes/nexus-memory.js";
325
+ import { createNexusMemoryRoutes, NexusImportOffer } from "./routes/nexus-memory.js";
325
326
  import { createBoardRoutes } from "./routes/board.js";
326
327
  import { readBoardFromNexus } from "./board/nexus-board.js";
327
328
  import { LocalModelInventory, localModePlacement, machineMemory } from "./local-models-mode.js";
@@ -9931,7 +9932,7 @@ async function startTurn(botId, text, opts) {
9931
9932
  // never re-marks an internal turn, so clearing here would silently spend
9932
9933
  // a signal the person still owes a glance to.
9933
9934
  if (commsDepth === 0)
9934
- store.patchTask(bot.id, threadId, { unread: false });
9935
+ markThreadLooked(store, bot.id, threadId); // replying to a result is reviewing it
9935
9936
  turnUsage.delete(threadId);
9936
9937
  turnContext.delete(threadId);
9937
9938
  turnTimingMark(threadId, "admitted");
@@ -15709,7 +15710,7 @@ ROUTES.push(createNexusMemoryRoutes({
15709
15710
  flush: () => nexusMemory.flush(),
15710
15711
  items: (scope) => nexusMemory.listItems(scope),
15711
15712
  forget: (kind, id) => nexusMemory.forget(kind, id),
15712
- fromBot: (req) => authorizedInternalCapability(req.headers.authorization) !== null,
15713
+ fromBot: (req) => authorizedInternalCapability(req.headers.authorization) !== null, importOffer: new NexusImportOffer({ dataDir: DATA_DIR, enabled: () => nexusMemory.settings().connected && !nexusMemory.settings().personalConnection, session: stikiSession, client: () => nexusMemory.getClient(), botId: () => (store.personalBot() ?? store.bots[0])?.id ?? null }), // the first-connect memory-import offer (server/nexus-memory/import-offer.ts)
15713
15714
  bots: {
15714
15715
  find: (botId) => {
15715
15716
  const bot = store.bot(botId);
@@ -20869,7 +20870,7 @@ const handleRequest = async (req, res) => {
20869
20870
  const body = await readBody(req);
20870
20871
  requirePinnedClientThread(m[1], body?.threadId);
20871
20872
  const current = requestedTaskBot(m[1], body?.threadId);
20872
- store.patchTask(current.id, current.threadId, { unread: false });
20873
+ markThreadLooked(store, current.id, current.threadId); // opening it reviews its finished result, so "Ready for you" stops counting it
20873
20874
  const bot = store.bot(current.id);
20874
20875
  const visible = wireBot(bot);
20875
20876
  broadcast({ kind: "bot", bot: visible });
@@ -25307,6 +25308,7 @@ catch (error) {
25307
25308
  // A days-scale window needs no tighter cadence; unref so the timer never
25308
25309
  // holds the process open.
25309
25310
  setInterval(sweepThreadEventLogsNow, THREAD_LOG_RETENTION_SWEEP_MS).unref();
25311
+ startReadyBacklogSweep(store); // "Ready for you" backlog: opened results reviewed, 30-day archive (server/ready-sweep.ts)
25310
25312
  // A dispatch claim is deliberately committed before transcript/provider work.
25311
25313
  // If we died after that point, its outcome is unknown: recover the user's words
25312
25314
  // and a review notice, never hand them to a model for a second execution.
@@ -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
+ }
@@ -0,0 +1,60 @@
1
+ import { olderDisposition, readyStatus } from "../shared/ready-queue.js";
2
+ /** The finished-result backlog sweep behind "Ready for you" (see the 30-day
3
+ * rule in shared/ready-queue.ts). Pure: it only decides patches; the caller
4
+ * applies them. Nothing is ever deleted. */
5
+ const SEEN_GRACE_MS = 10 * 60 * 1000;
6
+ /** Two things, in this order:
7
+ *
8
+ * 1. SEEN: a finished result whose thread is no longer unread was looked at
9
+ * (unread is set when the result lands and cleared when the person opens
10
+ * the thread), so it is marked reviewed. Opening a thread used to leave
11
+ * the result "unreviewed" forever, which is how the badge piled up.
12
+ * 2. 30-DAY: a finished result still unreviewed after 30 days is archived
13
+ * (archivedAt) and marked reviewed, stamped `autoClosedAt` so it is
14
+ * closed once only. Unarchiving it restores the thread.
15
+ *
16
+ * Waiting approvals and questions are never closed here. */
17
+ export function planReadyBacklog(tasks, now) {
18
+ const out = [];
19
+ for (const task of tasks) {
20
+ if (task.routineRunId || task.archivedAt || task.autoClosedAt)
21
+ continue;
22
+ if (readyStatus(task) !== "ready" || !task.readyResult)
23
+ continue;
24
+ const resultId = task.readyResult.id;
25
+ // The grace window keeps a result that is landing right now (its unread
26
+ // flag is stamped a moment after the result) from reading as seen.
27
+ if (task.unread === false && now - task.readyResult.at > SEEN_GRACE_MS) {
28
+ out.push({ threadId: task.threadId, reason: "seen", patch: { reviewedResultId: resultId } });
29
+ }
30
+ else if (olderDisposition(task, now) === "auto-close") {
31
+ out.push({ threadId: task.threadId, reason: "30-day", patch: { reviewedResultId: resultId, archivedAt: now, autoClosedAt: now } });
32
+ }
33
+ }
34
+ return out;
35
+ }
36
+ /** The person looked at a thread (opened it, or started a turn in it): it is
37
+ * read, and a finished result in it counts as reviewed, so "Ready for you"
38
+ * stops counting it. */
39
+ export function markThreadLooked(store, botId, threadId) {
40
+ const task = store.taskByThread(botId, threadId);
41
+ const reviewed = task?.readyResult && task.reviewedResultId !== task.readyResult.id ? { reviewedResultId: task.readyResult.id } : {};
42
+ store.patchTask(botId, threadId, { unread: false, ...reviewed });
43
+ }
44
+ /** Apply planReadyBacklog to every bot now and every six hours. Nothing is
45
+ * deleted: the 30-day rule only archives, and unarchiving restores. */
46
+ export function startReadyBacklogSweep(store, log = console.warn) {
47
+ const sweep = () => {
48
+ try {
49
+ const now = Date.now();
50
+ for (const bot of store.bots)
51
+ for (const plan of planReadyBacklog(bot.tasks ?? [], now))
52
+ store.patchTask(bot.id, plan.threadId, plan.patch);
53
+ }
54
+ catch (error) {
55
+ log(`ready backlog sweep failed: ${error instanceof Error ? error.message : String(error)}`);
56
+ }
57
+ };
58
+ sweep();
59
+ setInterval(sweep, 6 * 60 * 60_000).unref();
60
+ }
@@ -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" });
@@ -49,7 +49,7 @@ export function toWireTask(task) {
49
49
  }
50
50
  const TASK_PATCH_FIELDS = [
51
51
  "readyResult", "reviewedResultId", "title", "projectId", "modelSelection", "approvalMode", "autoApprove", "alwaysAllow",
52
- "unread", "rewound", "archivedAt", "pinned", "pinnedMessageId", "resumeCursors", "lastInstanceId", "cwd",
52
+ "unread", "rewound", "archivedAt", "autoClosedAt", "pinned", "pinnedMessageId", "resumeCursors", "lastInstanceId", "cwd",
53
53
  "routineRunId", "surface", "surfaceSource", "appliedCompactionId", "contextFloor", "lastContextModel", "modelAuto", "engineClass",
54
54
  ];
55
55
  /** Pin a bot or room for the sidebar's pinned grid. The stamp is the pin
@@ -0,0 +1,10 @@
1
+ /** One cap for every count that asks for the person's attention. A number
2
+ * above this reads as a wall, so it is shown as "10+" (ADHD-friendly: the
3
+ * exact figure is never worth the anxiety). Keep in step with
4
+ * ios/Sources/CompanionCore/BadgeCount.swift. */
5
+ export const BADGE_CAP = 10;
6
+ /** "7", "10", then "10+" for anything above the cap. Never negative. */
7
+ export function badgeText(count, cap = BADGE_CAP) {
8
+ const n = Number.isFinite(count) ? Math.max(0, Math.floor(count)) : 0;
9
+ return n > cap ? `${cap}+` : String(n);
10
+ }
@@ -0,0 +1,70 @@
1
+ export function readyStatus(task) {
2
+ if (task.activity === 'waiting-on-you')
3
+ return 'waiting';
4
+ if (task.busy || task.activity === 'working')
5
+ return 'working';
6
+ if (task.readyResult && task.readyResult.id !== task.reviewedResultId)
7
+ return 'ready';
8
+ return 'other';
9
+ }
10
+ export function readyQueue(threads) {
11
+ const rank = { waiting: 0, ready: 1, working: 2, other: 3 };
12
+ // Archived threads are put away: they never belong in the queue.
13
+ return threads.filter(task => !task.routineRunId && !task.archivedAt && !/^(Team incidents|Primary Bot sweeps)$/i.test(task.title))
14
+ .slice().sort((a, b) => rank[readyStatus(a)] - rank[readyStatus(b)] ||
15
+ (b.readyResult?.at ?? b.updatedAt ?? b.createdAt) - (a.readyResult?.at ?? a.updatedAt ?? a.createdAt) || a.threadId.localeCompare(b.threadId));
16
+ }
17
+ /** THE 30-DAY RULE (mirrored in ios/Sources/CompanionCore/ReadyQueue30Day.swift)
18
+ *
19
+ * An item "needs the person" when it is `waiting` (an approval or question)
20
+ * or `ready` (a finished result nobody reviewed). Its age is the time of the
21
+ * result (or of the question's last activity), never its creation time.
22
+ * Once an item is older than OLDER_ITEM_DAYS it is checked, never counted:
23
+ *
24
+ * - `ready` → "auto-close": the result is informational, finished or
25
+ * superseded; nothing is asked of the person. It is archived
26
+ * and marked reviewed (never deleted; restorable by
27
+ * unarchiving). See server/ready-sweep.ts.
28
+ * - `waiting` → "roll-up": it may still need an action, so it stays, folded
29
+ * with its peers into ONE "Older items" entry that counts as
30
+ * one item, not N.
31
+ * - anything else (working, idle conversation) is untouched.
32
+ */
33
+ export const OLDER_ITEM_DAYS = 30;
34
+ export const OLDER_ITEM_MS = OLDER_ITEM_DAYS * 24 * 60 * 60 * 1000;
35
+ export function itemTime(task) {
36
+ return task.readyResult?.at ?? task.updatedAt ?? task.createdAt;
37
+ }
38
+ export function olderDisposition(task, now) {
39
+ if (task.routineRunId || task.archivedAt)
40
+ return 'keep';
41
+ if (now - itemTime(task) <= OLDER_ITEM_MS)
42
+ return 'keep';
43
+ const status = readyStatus(task);
44
+ if (status === 'ready')
45
+ return 'auto-close';
46
+ if (status === 'waiting')
47
+ return 'roll-up';
48
+ return 'keep';
49
+ }
50
+ /** The queue split for display: recent entries as-is, older waiting items folded. */
51
+ export function splitOlder(queue, now) {
52
+ const recent = [];
53
+ const older = [];
54
+ for (const task of queue)
55
+ (olderDisposition(task, now) === 'roll-up' ? older : recent).push(task);
56
+ return { recent, older };
57
+ }
58
+ /** What the "Ready for you" badge counts: waiting + ready only (not idle
59
+ * conversations, not working), with every older waiting item as ONE entry.
60
+ * Pass the result to badgeText() for the "10+" cap. */
61
+ export function readyBadgeCount(threads, now) {
62
+ const { recent, older } = splitOlder(readyQueue(threads), now);
63
+ const needs = recent.filter(task => {
64
+ const status = readyStatus(task);
65
+ return (status === 'waiting' || status === 'ready') && olderDisposition(task, now) !== 'auto-close';
66
+ }).length;
67
+ return needs + (older.length > 0 ? 1 : 0);
68
+ }
69
+ /** Re-exported so the web app reads the queue and its badge from one place. */
70
+ export { badgeText } from "./badge-count.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chibitek/chibi",
3
- "version": "0.1.201",
3
+ "version": "0.1.203",
4
4
  "description": "Atomic by Chibitek: run your AI team's server anywhere and pair your devices to it",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -1 +0,0 @@
1
- import{U as a,C as n}from"./mermaid.core-QWILSY7q.js";const t=(r,o)=>a.lang.round(n.parse(r)[o]);export{t as c};