@andorra-labs/code 0.1.10 → 0.1.12

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 (238) hide show
  1. package/README.md +31 -205
  2. package/THIRD_PARTY_NOTICES.md +30 -0
  3. package/dist/src/agent-execution.js +50 -2
  4. package/dist/src/agent-mcp.js +5 -0
  5. package/dist/src/app-server/protocol.d.ts +9 -1
  6. package/dist/src/app-server/protocol.js +1 -1
  7. package/dist/src/app-server.d.ts +49 -1
  8. package/dist/src/app-server.js +353 -64
  9. package/dist/src/automation-service.js +1 -1
  10. package/dist/src/browser-panel-tool.d.ts +24 -3
  11. package/dist/src/browser-panel-tool.js +80 -6
  12. package/dist/src/browser-runner.js +3 -1
  13. package/dist/src/browser-session.d.ts +8 -0
  14. package/dist/src/browser-session.js +27 -1
  15. package/dist/src/browser-ui/app.js +237 -15
  16. package/dist/src/browser-ui/index.html +5 -5
  17. package/dist/src/browser-ui/style.css +110 -65
  18. package/dist/src/browser-ui/tokens.css +27 -26
  19. package/dist/src/browser-view.d.ts +16 -0
  20. package/dist/src/browser-view.js +38 -2
  21. package/dist/src/claude-provider.js +15 -2
  22. package/dist/src/cli.d.ts +2 -1
  23. package/dist/src/cli.js +175 -43
  24. package/dist/src/code-intelligence/CodeIntelligenceManager.js +1 -1
  25. package/dist/src/codex-provider.js +6 -3
  26. package/dist/src/coding-tools.d.ts +26 -1
  27. package/dist/src/coding-tools.js +104 -33
  28. package/dist/src/command-screens.js +1 -1
  29. package/dist/src/commands.js +1 -1
  30. package/dist/src/completion-gates.d.ts +42 -7
  31. package/dist/src/completion-gates.js +55 -9
  32. package/dist/src/completion.d.ts +51 -1
  33. package/dist/src/completion.js +164 -5
  34. package/dist/src/config.d.ts +1 -0
  35. package/dist/src/config.js +2 -0
  36. package/dist/src/dashboard-view.js +2 -2
  37. package/dist/src/deadline.js +4 -0
  38. package/dist/src/decision/PreparedSteps.js +1 -1
  39. package/dist/src/delegation-changes.js +19 -2
  40. package/dist/src/diff-preview.d.ts +1 -0
  41. package/dist/src/diff-preview.js +12 -3
  42. package/dist/src/engine-streams.d.ts +22 -0
  43. package/dist/src/engine-streams.js +16 -0
  44. package/dist/src/extensions.js +17 -6
  45. package/dist/src/file-read-key.d.ts +8 -0
  46. package/dist/src/file-read-key.js +12 -0
  47. package/dist/src/graph-editor-session.js +2 -1
  48. package/dist/src/graph-health.d.ts +21 -0
  49. package/dist/src/graph-health.js +46 -0
  50. package/dist/src/graph-manager-chat.d.ts +52 -3
  51. package/dist/src/graph-manager-chat.js +62 -17
  52. package/dist/src/graph-runner.js +62 -5
  53. package/dist/src/graph-server.d.ts +1 -1
  54. package/dist/src/graph-server.js +48 -27
  55. package/dist/src/graph-sync.d.ts +8 -0
  56. package/dist/src/graph-sync.js +54 -3
  57. package/dist/src/graph-tool.js +1 -1
  58. package/dist/src/graph-ui/app.js +362 -123
  59. package/dist/src/graph-ui/controls.css +95 -22
  60. package/dist/src/graph-ui/controls.js +31 -1
  61. package/dist/src/graph-ui/embed.js +62 -13
  62. package/dist/src/graph-ui/icons.js +7 -0
  63. package/dist/src/graph-ui/index.html +4 -4
  64. package/dist/src/graph-ui/manager-state.js +143 -5
  65. package/dist/src/graph-ui/manager.css +21 -20
  66. package/dist/src/graph-ui/manager.js +337 -75
  67. package/dist/src/graph-ui/model-picker.js +279 -0
  68. package/dist/src/graph-ui/provider-glyphs/alibaba-cloud.png +0 -0
  69. package/dist/src/graph-ui/provider-glyphs/anthropic.png +0 -0
  70. package/dist/src/graph-ui/provider-glyphs/aws-bedrock.png +0 -0
  71. package/dist/src/graph-ui/provider-glyphs/claude.png +0 -0
  72. package/dist/src/graph-ui/provider-glyphs/deepseek.png +0 -0
  73. package/dist/src/graph-ui/provider-glyphs/fireworks.png +0 -0
  74. package/dist/src/graph-ui/provider-glyphs/kimi.png +0 -0
  75. package/dist/src/graph-ui/provider-glyphs/minimax.png +0 -0
  76. package/dist/src/graph-ui/provider-glyphs/openai.png +0 -0
  77. package/dist/src/graph-ui/provider-glyphs/opencode.png +0 -0
  78. package/dist/src/graph-ui/provider-glyphs/openrouter.png +0 -0
  79. package/dist/src/graph-ui/provider-glyphs/xai.png +0 -0
  80. package/dist/src/graph-ui/provider-glyphs/xiaomi-mimo.png +0 -0
  81. package/dist/src/graph-ui/provider-glyphs/zai.png +0 -0
  82. package/dist/src/graph-ui/skill-picker.js +1 -1
  83. package/dist/src/graph-ui/studio-canvas.js +8 -8
  84. package/dist/src/graph-ui/studio.css +18 -15
  85. package/dist/src/graph-ui/studio.js +92 -35
  86. package/dist/src/graph-ui/style.css +122 -79
  87. package/dist/src/graph-ui/theme.js +2 -2
  88. package/dist/src/graph-ui/tokens.css +33 -29
  89. package/dist/src/graphs.d.ts +5 -2
  90. package/dist/src/graphs.js +10 -9
  91. package/dist/src/mcp.d.ts +52 -14
  92. package/dist/src/mcp.js +285 -128
  93. package/dist/src/membership-errors.d.ts +7 -1
  94. package/dist/src/membership-errors.js +9 -3
  95. package/dist/src/memory/ProjectMemory.d.ts +77 -0
  96. package/dist/src/memory/ProjectMemory.js +310 -0
  97. package/dist/src/memory/index.d.ts +1 -0
  98. package/dist/src/memory/index.js +1 -0
  99. package/dist/src/opencode-provider.js +5 -6
  100. package/dist/src/package-name.d.ts +3 -0
  101. package/dist/src/package-name.js +3 -0
  102. package/dist/src/provider-engine.js +2 -2
  103. package/dist/src/pull-requests.d.ts +42 -6
  104. package/dist/src/pull-requests.js +11 -3
  105. package/dist/src/qa/runtime/PtyManager.js +2 -1
  106. package/dist/src/react-runtime.js +137 -22
  107. package/dist/src/read-document-doc.d.ts +20 -0
  108. package/dist/src/read-document-doc.js +524 -0
  109. package/dist/src/read-document-docx.d.ts +21 -0
  110. package/dist/src/read-document-docx.js +584 -0
  111. package/dist/src/read-document-text.d.ts +29 -0
  112. package/dist/src/read-document-text.js +67 -0
  113. package/dist/src/read-document-tool.d.ts +48 -0
  114. package/dist/src/read-document-tool.js +162 -0
  115. package/dist/src/read-document.d.ts +78 -0
  116. package/dist/src/read-document.js +353 -0
  117. package/dist/src/read-image.d.ts +29 -2
  118. package/dist/src/read-image.js +42 -17
  119. package/dist/src/remote/cert.d.ts +1 -1
  120. package/dist/src/remote/cert.js +2 -7
  121. package/dist/src/remote/client.js +1 -1
  122. package/dist/src/remote/pem.d.ts +6 -0
  123. package/dist/src/remote/pem.js +11 -0
  124. package/dist/src/run-records.js +49 -10
  125. package/dist/src/runtime.d.ts +21 -0
  126. package/dist/src/runtime.js +10 -1
  127. package/dist/src/session-changes.d.ts +6 -1
  128. package/dist/src/session-changes.js +13 -5
  129. package/dist/src/sessions.d.ts +3 -1
  130. package/dist/src/sessions.js +5 -3
  131. package/dist/src/side-panel.d.ts +6 -1
  132. package/dist/src/side-panel.js +12 -10
  133. package/dist/src/sign-in-detection.d.ts +82 -0
  134. package/dist/src/sign-in-detection.js +197 -0
  135. package/dist/src/sign-in-offer.d.ts +35 -0
  136. package/dist/src/sign-in-offer.js +116 -0
  137. package/dist/src/skills/bundled/create-skill/SKILL.md +1 -1
  138. package/dist/src/skills/bundled/diagram/SKILL.md +1 -1
  139. package/dist/src/skills/bundled/graph-manager/SKILL.md +59 -7
  140. package/dist/src/skills/bundled/graph-manager/patterns.md +27 -0
  141. package/dist/src/skills/bundled/provenance.json +4 -4
  142. package/dist/src/skills/runtime-skills.d.ts +6 -0
  143. package/dist/src/skills/runtime-skills.js +16 -3
  144. package/dist/src/stall-recovery.d.ts +6 -2
  145. package/dist/src/stall-recovery.js +7 -2
  146. package/dist/src/stray-files.d.ts +14 -0
  147. package/dist/src/stray-files.js +81 -0
  148. package/dist/src/subagent-run.js +6 -1
  149. package/dist/src/terminal-ui.d.ts +1 -1
  150. package/dist/src/terminal-ui.js +11 -5
  151. package/dist/src/time-limit.d.ts +53 -0
  152. package/dist/src/time-limit.js +79 -0
  153. package/dist/src/tool-activity.js +1 -1
  154. package/dist/src/tool-schema-compatibility.d.ts +7 -2
  155. package/dist/src/tool-schema-compatibility.js +8 -4
  156. package/dist/src/tools.js +92 -7
  157. package/dist/src/transcript.d.ts +5 -0
  158. package/dist/src/transcript.js +12 -4
  159. package/dist/src/types.d.ts +8 -0
  160. package/dist/src/untracked-file-removal.d.ts +3 -0
  161. package/dist/src/untracked-file-removal.js +125 -0
  162. package/dist/src/update-check.js +1 -1
  163. package/dist/src/update.d.ts +11 -1
  164. package/dist/src/update.js +27 -5
  165. package/dist/src/usage-analytics.d.ts +3 -1
  166. package/dist/src/usage-analytics.js +16 -2
  167. package/dist/src/workspace-git-metadata.d.ts +15 -0
  168. package/dist/src/workspace-git-metadata.js +50 -1
  169. package/dist/src/workspace-instructions.js +1 -1
  170. package/package.json +6 -26
  171. package/docs/README.md +0 -36
  172. package/docs/agents/README.md +0 -62
  173. package/docs/agents/install-for-agents.md +0 -56
  174. package/docs/agents/mcp-server.md +0 -212
  175. package/docs/agents/subagent-mode.md +0 -149
  176. package/docs/concepts/README.md +0 -47
  177. package/docs/concepts/jev-actionable-routing.md +0 -113
  178. package/docs/concepts/jev-decision-thresholds.md +0 -412
  179. package/docs/concepts/jev-efficiency.md +0 -217
  180. package/docs/concepts/jev-eval-2026-11-01.md +0 -78
  181. package/docs/concepts/limits.md +0 -52
  182. package/docs/concepts/memory.md +0 -10
  183. package/docs/concepts/security.md +0 -50
  184. package/docs/concepts/workspace-instructions.md +0 -29
  185. package/docs/getting-started/README.md +0 -82
  186. package/docs/getting-started/accounts.md +0 -78
  187. package/docs/getting-started/configure-providers.md +0 -132
  188. package/docs/guides/README.md +0 -13
  189. package/docs/guides/browser.md +0 -39
  190. package/docs/guides/desktop-app.md +0 -414
  191. package/docs/guides/extensions.md +0 -102
  192. package/docs/guides/graph-builder.md +0 -116
  193. package/docs/guides/headless.md +0 -46
  194. package/docs/guides/tui.md +0 -75
  195. package/docs/guides/update.md +0 -70
  196. package/docs/guides/web-search.md +0 -51
  197. package/docs/guides/windows-code-signing.md +0 -319
  198. package/docs/llms.txt +0 -45
  199. package/docs/reference/README.md +0 -7
  200. package/docs/reference/cli.md +0 -76
  201. package/docs/reference/config.md +0 -91
  202. package/docs/reference/slash-commands.md +0 -59
  203. package/docs/superpowers/plans/2026-11-01-claude-console-sign-in.md +0 -111
  204. package/docs/superpowers/plans/2026-11-01-jev-node-opt-in.md +0 -910
  205. package/docs/superpowers/plans/2026-11-02-workflow-pane.md +0 -398
  206. package/docs/superpowers/plans/2026-11-06-graph-soft-delete.md +0 -125
  207. package/docs/superpowers/plans/2026-11-09-orchestrator-delegation.md +0 -295
  208. package/docs/superpowers/plans/2026-11-13-graph-manager-chat.md +0 -203
  209. package/docs/superpowers/plans/2026-11-14-jev-fair-use-pricing.md +0 -79
  210. package/docs/superpowers/specs/2026-10-31-work-line-summary-design.md +0 -50
  211. package/docs/superpowers/specs/2026-11-01-claude-console-sign-in-design.md +0 -176
  212. package/docs/superpowers/specs/2026-11-01-jev-node-opt-in-design.md +0 -164
  213. package/docs/superpowers/specs/2026-11-01-pr-section-design.md +0 -111
  214. package/docs/superpowers/specs/2026-11-02-workflow-pane-design.md +0 -130
  215. package/docs/superpowers/specs/2026-11-06-bundled-skills-design.md +0 -206
  216. package/docs/superpowers/specs/2026-11-09-orchestrator-delegation-design.md +0 -291
  217. package/docs/superpowers/specs/2026-11-13-graph-manager-chat-design.md +0 -182
  218. package/docs/superpowers/specs/2026-11-14-jev-fair-use-pricing-design.md +0 -156
  219. package/scripts/jev-efficiency-eval.mjs +0 -187
  220. package/scripts/jev-efficiency-live.mjs +0 -193
  221. package/scripts/zcode-engine-replay.mjs +0 -223
  222. package/tests/agent-centric-mcp-test-plan.md +0 -208
  223. package/tests/analytics-settings-test-plan.md +0 -165
  224. package/tests/browser-cli-smoke.mjs +0 -276
  225. package/tests/browser-test-plan.md +0 -280
  226. package/tests/chat-side-panel-test-plan.md +0 -309
  227. package/tests/decision-engine-test-plan.md +0 -163
  228. package/tests/default-active-jev-test-plan.md +0 -85
  229. package/tests/harness-extensions-test-plan.md +0 -113
  230. package/tests/jev-all-decisions-test-plan.md +0 -156
  231. package/tests/jev-efficiency/criteria.json +0 -158
  232. package/tests/jev-efficiency/workloads.mjs +0 -242
  233. package/tests/jev-efficiency-test-plan.md +0 -198
  234. package/tests/permissions-sandbox-probe.mjs +0 -74
  235. package/tests/permissions-test-plan.md +0 -191
  236. package/tests/product-telemetry-test-plan.md +0 -536
  237. package/tests/thinking-stream-preview-test-plan.md +0 -136
  238. package/tests/zcode-react-engine-test-plan.md +0 -396
package/dist/src/mcp.js CHANGED
@@ -8,8 +8,13 @@ import { authorize } from './tools.js';
8
8
  import { permissionMode, PLAN_MODE_MUTATION_ERROR } from './permissions.js';
9
9
  import { validateMcpServer } from './config.js';
10
10
  import { clipText } from './text.js';
11
+ /** The bytes of tool metadata a task lists one by one, across servers. A server past what is left is offered on demand. */
11
12
  const MCP_CATALOG_MAX_BYTES = 16_000;
12
13
  const MCP_CATALOG_MAX_TOOLS = 500;
14
+ /** The most tools one server may report. */
15
+ const MCP_SERVER_MAX_TOOLS = 1000;
16
+ /** The bytes the index of on-demand tools takes in the lookup tool's description. */
17
+ const MCP_INDEX_MAX_BYTES = 6_000;
13
18
  const MCP_STARTUP_MAX_SERVERS = 8;
14
19
  const MCP_RESPONSE_MAX_BYTES = 1024 * 1024;
15
20
  /** A remembered catalog larger than this was not written by this module, and is not read back. */
@@ -48,8 +53,9 @@ export function mcpCatalogStore(directory) {
48
53
  const parsed = JSON.parse(raw);
49
54
  if (!parsed || parsed.version !== 1)
50
55
  return undefined;
56
+ // An earlier version recorded only that a catalog did not fit; such a server is asked again.
51
57
  if (parsed.overBudget === true)
52
- return { overBudget: true };
58
+ return undefined;
53
59
  return Array.isArray(parsed.tools) ? { tools: parsed.tools } : undefined;
54
60
  }
55
61
  catch {
@@ -364,23 +370,207 @@ export function probeFailureReason(error, config) {
364
370
  return 'Its answer was larger than 1 MiB.';
365
371
  return 'Could not connect or list its tools. Check its command and authentication.';
366
372
  }
367
- const OVER_BUDGET = 'MCP catalog exceeds task metadata budget';
368
373
  // Transport errors can contain server-provided strings or auth headers: report a bounded, non-secret status.
369
374
  const unavailableReason = (error) => error instanceof Error && error.message === 'Permission denied' ? 'connection permission denied'
370
- : error instanceof Error && error.message === OVER_BUDGET ? 'tool catalog exceeds the task metadata budget'
371
- : 'connection or tool discovery failed; check server configuration and authentication';
375
+ : 'connection or tool discovery failed; check server configuration and authentication';
376
+ /** The tool a model uses to read the descriptions and input schemas of tools that are offered on demand. */
377
+ export const MCP_FIND_TOOLS = 'mcp_find_tools';
378
+ /** The tool a model uses to run a tool that is offered on demand. */
379
+ export const MCP_CALL_TOOL = 'mcp_call_tool';
380
+ /** The most tools one lookup returns. */
381
+ const MCP_FIND_MAX_RESULTS = 20;
382
+ /**
383
+ * The characters one lookup's answer may take. The runtime clips every tool observation at 24,000
384
+ * characters (`src/react-runtime.ts`), so an answer past that would reach the model as broken JSON.
385
+ */
386
+ const MCP_FIND_MAX_CHARS = 20_000;
387
+ /** The characters one part of a schema too large for a single answer takes once JSON-encoded in that answer. */
388
+ const MCP_FIND_PART_CHARS = 16_000;
389
+ /**
390
+ * A large entry's JSON cut into parts that each take at most {@link MCP_FIND_PART_CHARS} once
391
+ * encoded again as a string — quotes and backslashes double, control characters grow to six —
392
+ * never splitting a surrogate pair.
393
+ */
394
+ function schemaChunks(text) {
395
+ const chunks = [];
396
+ let start = 0;
397
+ let encoded = 0;
398
+ for (let at = 0; at < text.length;) {
399
+ const code = text.charCodeAt(at);
400
+ const next = text.charCodeAt(at + 1);
401
+ const width = code >= 0xd800 && code <= 0xdbff && next >= 0xdc00 && next <= 0xdfff ? 2 : 1;
402
+ const cost = JSON.stringify(text.slice(at, at + width)).length - 2;
403
+ if (encoded + cost > MCP_FIND_PART_CHARS && at > start) {
404
+ chunks.push(text.slice(start, at));
405
+ start = at;
406
+ encoded = 0;
407
+ }
408
+ encoded += cost;
409
+ at += width;
410
+ }
411
+ chunks.push(text.slice(start));
412
+ return chunks;
413
+ }
414
+ /**
415
+ * The index of on-demand tools a model is shown: each server with its tool names, within
416
+ * {@link MCP_INDEX_MAX_BYTES}. Names past the bound are counted, and the lookup finds them by query.
417
+ */
418
+ export function deferredIndex(servers) {
419
+ const lines = [];
420
+ let bytes = 0;
421
+ for (const server of servers) {
422
+ const head = `${server.id} (${server.catalog.length} tools): `;
423
+ const names = [];
424
+ let used = Buffer.byteLength(head);
425
+ const share = Math.max(400, Math.floor((MCP_INDEX_MAX_BYTES - bytes) / Math.max(1, servers.length - lines.length)));
426
+ for (const tool of server.catalog) {
427
+ const size = Buffer.byteLength(tool.name) + 2;
428
+ if (used + size > share)
429
+ break;
430
+ names.push(tool.name);
431
+ used += size;
432
+ }
433
+ const rest = server.catalog.length - names.length;
434
+ const line = head + names.join(', ') + (rest > 0 ? `, and ${rest} more (search with a query)` : '');
435
+ lines.push(line);
436
+ bytes += Buffer.byteLength(line) + 1;
437
+ }
438
+ return lines.join('\n');
439
+ }
440
+ /**
441
+ * The tools of on-demand servers that match a lookup, best first: every named tool, or the tools
442
+ * whose name or description carries the most words of the query, or a server's whole list.
443
+ */
444
+ export function findDeferredTools(servers, request) {
445
+ const scoped = request.server === undefined ? servers : servers.filter(server => server.id === resolveDeferredServer(servers, request.server)?.id);
446
+ const named = (request.tools ?? []).filter(name => typeof name === 'string' && name);
447
+ if (named.length > 0)
448
+ return scoped.flatMap(server => server.catalog.filter(tool => named.includes(tool.name)).map(tool => ({ server: server.id, tool })));
449
+ const words = (request.query ?? '').toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(word => word.length > 1 || /\d/.test(word));
450
+ const all = scoped.flatMap(server => server.catalog.map(tool => ({ server: server.id, tool })));
451
+ if (words.length === 0)
452
+ return all;
453
+ const score = (tool) => {
454
+ const name = tool.name.toLowerCase();
455
+ const description = (tool.description ?? '').toLowerCase();
456
+ return words.reduce((total, word) => total + (name.includes(word) ? 3 : 0) + (description.includes(word) ? 1 : 0), 0);
457
+ };
458
+ return all.map(entry => ({ entry, score: score(entry.tool) })).filter(item => item.score > 0).sort((a, b) => b.score - a.score).map(item => item.entry);
459
+ }
460
+ /** The server a model named: its exact id, or the one id whose name after `configured:` or `plugin:` matches. */
461
+ function resolveDeferredServer(servers, name) {
462
+ const exact = servers.find(server => server.id === name);
463
+ if (exact)
464
+ return exact;
465
+ const short = servers.filter(server => server.id.slice(server.id.lastIndexOf(':') + 1) === name);
466
+ return short.length === 1 ? short[0] : undefined;
467
+ }
468
+ /**
469
+ * What {@link MCP_FIND_TOOLS} answers, always within {@link MCP_FIND_MAX_CHARS}.
470
+ *
471
+ * Matching tools are described with their schemas, best first, while they fit. A tool whose own
472
+ * description and schema would not fit one answer is named with how many parts it takes; asking
473
+ * for it by exact name with `part` returns that slice of its JSON, and the parts joined in order
474
+ * are the whole entry.
475
+ */
476
+ export function answerFind(servers, args) {
477
+ const server = typeof args.server === 'string' ? args.server : undefined;
478
+ if (server !== undefined && !resolveDeferredServer(servers, server))
479
+ throw new Error(`Unknown MCP server ${server}. Servers: ${servers.map(item => item.id).join(', ')}.`);
480
+ const tools = Array.isArray(args.tools) ? args.tools.filter((name) => typeof name === 'string') : undefined;
481
+ const matches = findDeferredTools(servers, { ...(server === undefined ? {} : { server }), ...(typeof args.query === 'string' ? { query: args.query } : {}), ...(tools ? { tools } : {}) });
482
+ const entryOf = ({ server: id, tool }) => ({ server: id, name: tool.name, description: tool.description ?? '', inputSchema: tool.inputSchema });
483
+ if (args.part !== undefined) {
484
+ const part = args.part;
485
+ if (typeof part !== 'number' || !Number.isInteger(part) || part < 1)
486
+ throw new Error('part must be a whole number from 1.');
487
+ if (tools?.length !== 1 || matches.length !== 1)
488
+ throw new Error('part needs exactly one tool, named in tools (and server when two servers share the name).');
489
+ const chunks = schemaChunks(JSON.stringify(entryOf(matches[0])));
490
+ const parts = chunks.length;
491
+ if (part > parts)
492
+ throw new Error(`${matches[0].tool.name} has ${parts} parts.`);
493
+ return JSON.stringify({ server: matches[0].server, name: matches[0].tool.name, part, parts, chunk: chunks[part - 1],
494
+ note: part < parts ? `Join the chunks of parts 1 to ${parts} in order; the result is the tool's JSON entry.` : 'Last part. The chunks joined in order are the tool\'s JSON entry.' });
495
+ }
496
+ if (matches.length === 0)
497
+ return JSON.stringify({ tools: [], note: 'No tool matched. Try other words, or omit query to list a server\'s tools.' });
498
+ const results = [];
499
+ let used = 200; // The enclosing object and its note.
500
+ for (const match of matches) {
501
+ if (results.length >= MCP_FIND_MAX_RESULTS)
502
+ break;
503
+ let entry = entryOf(match);
504
+ let size = JSON.stringify(entry).length + 1;
505
+ if (size > MCP_FIND_MAX_CHARS - 200) {
506
+ const parts = schemaChunks(JSON.stringify(entry)).length;
507
+ entry = { server: match.server, name: match.tool.name, description: clipText(match.tool.description ?? '', 1_000), schemaParts: parts,
508
+ note: `Too large for one answer: call ${MCP_FIND_TOOLS} with tools ["${match.tool.name}"] and part 1 to ${parts}, and join the chunks.` };
509
+ size = JSON.stringify(entry).length + 1;
510
+ }
511
+ if (used + size > MCP_FIND_MAX_CHARS)
512
+ break;
513
+ results.push(entry);
514
+ used += size;
515
+ }
516
+ const omitted = matches.length - results.length;
517
+ return JSON.stringify({ tools: results, ...(omitted > 0 ? { omitted, note: `${omitted} more matched; narrow the query or name the tools.` } : {}) });
518
+ }
519
+ /** The two tools that reach every on-demand server: one to look tools up, one to run them. */
520
+ function deferredTools(servers) {
521
+ const index = deferredIndex(servers);
522
+ const find = {
523
+ name: MCP_FIND_TOOLS, capability: 'external', executionMode: 'parallel',
524
+ description: `Look up tools of MCP servers whose tools are too many to list one by one. Returns each matching tool's description and JSON input schema; run one with ${MCP_CALL_TOOL}. Pass tools (exact names) to describe them, or query (words) to search names and descriptions; server narrows either to one server. A schema too large for one answer is fetched in parts (part, with one tool named). Servers and their tools:\n${index}`,
525
+ parameters: { type: 'object', properties: {
526
+ server: { type: 'string', description: 'Server id, as listed in this description.' },
527
+ query: { type: 'string', description: 'Words to search tool names and descriptions for.' },
528
+ tools: { type: 'array', items: { type: 'string' }, description: 'Exact tool names to describe.' },
529
+ part: { type: 'integer', minimum: 1, description: 'Part of one large schema to return, with exactly one tool named.' },
530
+ }, additionalProperties: false },
531
+ execute: async (args) => answerFind(servers, args),
532
+ };
533
+ const call = {
534
+ name: MCP_CALL_TOOL, capability: 'external', executionMode: 'sequential',
535
+ description: `Run a tool of an MCP server listed by ${MCP_FIND_TOOLS}. Look the tool up first: arguments must match its input schema.`,
536
+ parameters: { type: 'object', properties: {
537
+ server: { type: 'string', description: 'Server id.' },
538
+ tool: { type: 'string', description: 'Exact tool name.' },
539
+ arguments: { type: 'object', description: 'Arguments matching the tool\'s input schema.' },
540
+ }, required: ['server', 'tool'], additionalProperties: false },
541
+ execute: async (args, callContext) => {
542
+ if (typeof args.server !== 'string' || typeof args.tool !== 'string')
543
+ throw new Error(`${MCP_CALL_TOOL} needs server and tool.`);
544
+ const server = resolveDeferredServer(servers, args.server);
545
+ if (!server)
546
+ throw new Error(`Unknown MCP server ${args.server}. Servers: ${servers.map(item => item.id).join(', ')}.`);
547
+ if (!server.catalog.some(tool => tool.name === args.tool))
548
+ throw new Error(`MCP ${server.id} has no tool ${args.tool}. Look it up with ${MCP_FIND_TOOLS}.`);
549
+ const toolArgs = args.arguments ?? {};
550
+ if (!toolArgs || typeof toolArgs !== 'object' || Array.isArray(toolArgs))
551
+ throw new Error(`${MCP_CALL_TOOL} arguments must be an object.`);
552
+ return server.run(args.tool, toolArgs, callContext);
553
+ },
554
+ };
555
+ return [find, call];
556
+ }
372
557
  /**
373
558
  * Each task owns its clients; no server tools or spawned processes survive task exit.
374
559
  *
560
+ * A server's tools are offered one by one while their advertised metadata fits the task's budget
561
+ * ({@link MCP_CATALOG_MAX_BYTES} across servers, in order). A server whose catalog does not fit is
562
+ * not dropped: its tools are offered on demand, through {@link MCP_FIND_TOOLS} (an index of their
563
+ * names, and their schemas when looked up) and {@link MCP_CALL_TOOL}, which runs them under the
564
+ * same approval as a tool offered by itself.
565
+ *
375
566
  * With `catalogs`, a server this home has already heard from does not hold the task back while it
376
567
  * starts. Its connection is approved first, as every server's is. Then its last answer decides
377
- * what the task is told now — its tools, offered from the record, or that its catalog does not fit
378
- * the task's metadata budget — and the server itself connects behind the caller, where a call to
379
- * one of its tools waits for the connection. The record is
380
- * checked against what the server reports once it is up: a catalog that changed is used from the
381
- * next task on, and a server that could not be reached is forgotten, so the next task asks it
382
- * before offering anything, as a server seen for the first time is always asked. `settled` resolves
383
- * when every server has answered.
568
+ * what the task is told now — its tools, offered from the record, one by one or on demand — and the
569
+ * server itself connects behind the caller, where a call to one of its tools waits for the
570
+ * connection. The record is checked against what the server reports once it is up: a catalog that
571
+ * changed is used from the next task on, and a server that could not be reached is forgotten, so
572
+ * the next task asks it before offering anything, as a server seen for the first time is always
573
+ * asked. `settled` resolves when every server has answered.
384
574
  */
385
575
  export async function connectMcpServers(servers, context, notice, taskSignal = context.signal, options = {}) {
386
576
  // A server still starting behind the task is stopped by the same close that ends the established ones.
@@ -388,6 +578,7 @@ export async function connectMcpServers(servers, context, notice, taskSignal = c
388
578
  const startupSignal = AbortSignal.any([context.signal, taskSignal, closed.signal]);
389
579
  const clients = new Map();
390
580
  const tools = [];
581
+ const deferred = [];
391
582
  let catalogBytes = 2; // Include the enclosing advertised catalog array.
392
583
  /** The servers connecting behind the task, one at a time. Never rejects. */
393
584
  let background = Promise.resolve();
@@ -438,13 +629,22 @@ export async function connectMcpServers(servers, context, notice, taskSignal = c
438
629
  // Approval can finish after task cancellation has already closed clients.
439
630
  startupSignal.throwIfAborted();
440
631
  };
632
+ /** The limits one server's catalog is held to while it is listed or read back: valid, unique, and at most {@link MCP_SERVER_MAX_TOOLS} tools. */
633
+ const checked = (id) => {
634
+ const seen = new Set();
635
+ return (tool) => {
636
+ if (seen.size >= MCP_SERVER_MAX_TOOLS)
637
+ throw new Error('Invalid or oversized MCP tool catalog');
638
+ checkCatalogTool(id, tool, seen);
639
+ };
640
+ };
441
641
  /**
442
- * Start one server whose connection was approved and read its catalog. `accept` sees each tool
443
- * as it is listed and throws to refuse the whole catalog, so a failure never exposes a partially
444
- * discovered set.
642
+ * Start one server whose connection was approved and read its catalog. A tool that fails the
643
+ * limits refuses the whole catalog, so a failure never exposes a partially discovered set.
445
644
  */
446
- const connectServer = async (id, config, accept) => {
645
+ const connectServer = async (id, config) => {
447
646
  const client = new Client({ name: 'andorra-code', version: '0.1.0' }, { capabilities: {} });
647
+ const accept = checked(id);
448
648
  try {
449
649
  startupSignal.throwIfAborted();
450
650
  const transport = mcpTransport(config, context.workspace, () => { void client.close().catch(() => { }); });
@@ -478,26 +678,6 @@ export async function connectMcpServers(servers, context, notice, taskSignal = c
478
678
  throw error;
479
679
  }
480
680
  };
481
- /**
482
- * The bounds a discovery is held to, against what the servers before this one took: the tool
483
- * count and the bytes of advertised metadata across pages and all task-owned servers. A catalog
484
- * past either is refused whole.
485
- */
486
- const bounded = (id, takenTools, takenBytes) => {
487
- const seen = new Set();
488
- let bytes = 0;
489
- return {
490
- accept(tool) {
491
- if (takenTools + seen.size >= MCP_CATALOG_MAX_TOOLS)
492
- throw new Error('Invalid or oversized MCP tool catalog');
493
- checkCatalogTool(id, tool, seen);
494
- bytes += advertisedBytes(id, tool);
495
- if (takenBytes + bytes > MCP_CATALOG_MAX_BYTES)
496
- throw new Error(OVER_BUDGET);
497
- },
498
- get bytes() { return bytes; },
499
- };
500
- };
501
681
  const callTool = async (client, id, name, args, callContext) => {
502
682
  // MCP execution has no read-only enforcement: a call can change the workspace or the
503
683
  // host, so plan mode refuses it the way it refuses QA host execution, rather than
@@ -516,23 +696,67 @@ export async function connectMcpServers(servers, context, notice, taskSignal = c
516
696
  throw new Error(`MCP tool failed: ${rendered}`);
517
697
  return rendered;
518
698
  };
519
- /** What the record says this task can be told now: the tools it may offer, or that they do not fit. */
699
+ /**
700
+ * Run one tool of a server, once its connection is up. The call's own cancellation ends the wait;
701
+ * the connection carries on for the task. A tool the live server no longer lists is refused.
702
+ */
703
+ const runTool = async (connection, id, name, args, callContext) => {
704
+ if (permissionMode(callContext) === 'plan')
705
+ throw new Error(PLAN_MODE_MUTATION_ERROR);
706
+ let live;
707
+ let stop;
708
+ try {
709
+ live = await Promise.race([connection, new Promise((_, reject) => {
710
+ stop = () => reject(callContext.signal.reason instanceof Error ? callContext.signal.reason : new Error('Aborted'));
711
+ if (callContext.signal.aborted)
712
+ stop();
713
+ else
714
+ callContext.signal.addEventListener('abort', stop, { once: true });
715
+ })]);
716
+ }
717
+ catch (error) {
718
+ callContext.signal.throwIfAborted();
719
+ throw new Error(`MCP ${id} is unavailable (${unavailableReason(error)}).`);
720
+ }
721
+ finally {
722
+ if (stop)
723
+ callContext.signal.removeEventListener('abort', stop);
724
+ }
725
+ if (!live.catalog.some(item => item.name === name))
726
+ throw new Error(`MCP ${id} no longer provides ${name}: its tool catalog changed since it was last used. Start a new task to use the current catalog.`);
727
+ return callTool(live.client, id, name, args, callContext);
728
+ };
729
+ /**
730
+ * Offer a server's tools to the task: one by one when their metadata fits what is left of the
731
+ * budget, otherwise on demand. Says which, for the notice.
732
+ */
733
+ const offer = (id, catalog, connection) => {
734
+ const bytes = catalog.reduce((total, tool) => total + advertisedBytes(id, tool), 0);
735
+ if (tools.length + catalog.length <= MCP_CATALOG_MAX_TOOLS && catalogBytes + bytes <= MCP_CATALOG_MAX_BYTES) {
736
+ for (const tool of catalog) {
737
+ tools.push({ ...advertise(id, tool), capability: 'external', executionMode: 'sequential', execute: (args, callContext) => runTool(connection, id, tool.name, args, callContext) });
738
+ }
739
+ catalogBytes += bytes;
740
+ return 'listed';
741
+ }
742
+ deferred.push({ id, catalog, run: (name, args, callContext) => runTool(connection, id, name, args, callContext) });
743
+ return 'on-demand';
744
+ };
745
+ const available = (id, count, how) => how === 'listed'
746
+ ? `MCP ${id}: ${count} tools available to agents with shell permission.`
747
+ : `MCP ${id}: ${count} tools available on demand to agents with shell permission (too many to list one by one; agents look them up with ${MCP_FIND_TOOLS} and run them with ${MCP_CALL_TOOL}).`;
748
+ /** The catalog on record, when it holds tools and meets the limits a listed one must: the file is no more trusted than the server. */
520
749
  const remembered = (record, id) => {
521
- if (record === undefined)
522
- return undefined;
523
- if ('overBudget' in record)
524
- return 'over-budget';
525
- if (record.tools.length === 0)
750
+ if (record === undefined || record.tools.length === 0)
526
751
  return undefined;
527
752
  try {
528
- // A record is held to the bounds a discovery is: the file is no more trusted than the server.
529
- const limits = bounded(id, tools.length, catalogBytes);
753
+ const accept = checked(id);
530
754
  for (const tool of record.tools)
531
- limits.accept(tool);
532
- return { catalog: record.tools, bytes: limits.bytes };
755
+ accept(tool);
756
+ return record.tools;
533
757
  }
534
- catch (error) {
535
- return error instanceof Error && error.message === OVER_BUDGET ? 'over-budget' : undefined;
758
+ catch {
759
+ return undefined;
536
760
  }
537
761
  };
538
762
  // Startup may be interrupted by a pause; established clients belong to the task.
@@ -564,46 +788,17 @@ export async function connectMcpServers(servers, context, notice, taskSignal = c
564
788
  const store = options.catalogs;
565
789
  const key = store ? mcpCatalogKey(id, config, context.workspace) : undefined;
566
790
  const known = store && key !== undefined ? remembered(await store.read(key).catch(() => undefined), id) : undefined;
567
- if (store && key !== undefined && known === 'over-budget') {
568
- // The answer the server gave last time, told now; whether it still holds is found out
569
- // behind the task. Nothing of this server is offered either way, so its client is not kept.
570
- notice(`MCP ${id}: unavailable (${unavailableReason(new Error(OVER_BUDGET))}).`);
571
- const limits = bounded(id, tools.length, catalogBytes);
572
- background = background.then(async () => {
573
- startupSignal.throwIfAborted();
574
- const live = await connectServer(id, config, tool => limits.accept(tool));
575
- await drop(live.client);
576
- // A server that now lists nothing has nothing to remember, and nothing to announce.
577
- if (live.catalog.length === 0) {
578
- await store.remove(key).catch(() => { });
579
- return;
580
- }
581
- await store.write(key, { tools: live.catalog }).catch(() => { });
582
- notice(`MCP ${id}: its tool catalog now fits the task metadata budget; the next task offers its tools.`);
583
- }).catch(async (error) => {
584
- // A task that is ending says nothing about the server, and a catalog that is still too large is what the record says.
585
- if (startupSignal.aborted || (error instanceof Error && error.message === OVER_BUDGET))
586
- return;
587
- await store.remove(key).catch(() => { });
588
- });
589
- continue;
590
- }
591
- if (store && key !== undefined && known !== undefined && known !== 'over-budget') {
791
+ if (store && key !== undefined && known !== undefined) {
592
792
  // Offered from the record now; the server itself starts behind the task.
593
- const connection = background.then(() => {
594
- startupSignal.throwIfAborted();
595
- const seen = new Set();
596
- return connectServer(id, config, tool => {
597
- if (seen.size >= MCP_CATALOG_MAX_TOOLS)
598
- throw new Error('Invalid or oversized MCP tool catalog');
599
- checkCatalogTool(id, tool, seen);
600
- });
601
- });
793
+ const connection = background.then(() => { startupSignal.throwIfAborted(); return connectServer(id, config); });
794
+ // A connection that fails is reported below and by each call that waits on it.
795
+ connection.catch(() => { });
796
+ const how = offer(id, known, connection);
602
797
  background = connection.then(async (live) => {
603
798
  options.status?.(id, config, { state: 'ready', tools: live.catalog.length });
604
799
  // Key order inside a schema is the server's serializer's business, not a change of catalog.
605
- if (canonical(live.catalog) === canonical(known.catalog)) {
606
- notice(`MCP ${id}: ${known.catalog.length} tools available to agents with shell permission.`);
800
+ if (canonical(live.catalog) === canonical(known)) {
801
+ notice(available(id, known.length, how));
607
802
  return;
608
803
  }
609
804
  // The model was already told the earlier catalog, and a tool list that changed under a
@@ -612,7 +807,7 @@ export async function connectMcpServers(servers, context, notice, taskSignal = c
612
807
  await store.write(key, { tools: live.catalog }).catch(() => { });
613
808
  else
614
809
  await store.remove(key).catch(() => { });
615
- notice(`MCP ${id}: the server's tool catalog changed since it was last used. This task keeps the earlier catalog (${known.catalog.length} tools); the next task uses the current one.`);
810
+ notice(`MCP ${id}: the server's tool catalog changed since it was last used. This task keeps the earlier catalog (${known.length} tools); the next task uses the current one.`);
616
811
  }, async (error) => {
617
812
  // A task that is ending says nothing about the server: its record stands.
618
813
  if (startupSignal.aborted)
@@ -622,46 +817,12 @@ export async function connectMcpServers(servers, context, notice, taskSignal = c
622
817
  await store.remove(key).catch(() => { });
623
818
  notice(`MCP ${id}: unavailable (${unavailableReason(error)}).`);
624
819
  });
625
- for (const tool of known.catalog) {
626
- tools.push({ ...advertise(id, tool), capability: 'external', executionMode: 'sequential', execute: async (args, callContext) => {
627
- if (permissionMode(callContext) === 'plan')
628
- throw new Error(PLAN_MODE_MUTATION_ERROR);
629
- let live;
630
- let stop;
631
- try {
632
- // The call's own cancellation ends the wait; the connection carries on for the task.
633
- live = await Promise.race([connection, new Promise((_, reject) => {
634
- stop = () => reject(callContext.signal.reason instanceof Error ? callContext.signal.reason : new Error('Aborted'));
635
- if (callContext.signal.aborted)
636
- stop();
637
- else
638
- callContext.signal.addEventListener('abort', stop, { once: true });
639
- })]);
640
- }
641
- catch (error) {
642
- callContext.signal.throwIfAborted();
643
- throw new Error(`MCP ${id} is unavailable (${unavailableReason(error)}).`);
644
- }
645
- finally {
646
- if (stop)
647
- callContext.signal.removeEventListener('abort', stop);
648
- }
649
- if (!live.catalog.some(item => item.name === tool.name))
650
- throw new Error(`MCP ${id} no longer provides ${tool.name}: its tool catalog changed since it was last used. Start a new task to use the current catalog.`);
651
- return callTool(live.client, id, tool.name, args, callContext);
652
- } });
653
- }
654
- catalogBytes += known.bytes;
655
820
  continue;
656
821
  }
657
822
  try {
658
- const limits = bounded(id, tools.length, catalogBytes);
659
- const live = await connectServer(id, config, tool => limits.accept(tool));
660
- for (const tool of live.catalog) {
661
- tools.push({ ...advertise(id, tool), capability: 'external', executionMode: 'sequential', execute: (args, callContext) => callTool(live.client, id, tool.name, args, callContext) });
662
- }
663
- catalogBytes += limits.bytes;
664
- notice(`MCP ${id}: ${live.catalog.length} tools available to agents with shell permission.`);
823
+ const live = await connectServer(id, config);
824
+ const how = offer(id, live.catalog, Promise.resolve(live));
825
+ notice(available(id, live.catalog.length, how));
665
826
  options.status?.(id, config, { state: 'ready', tools: live.catalog.length });
666
827
  // Remembered for the next task. An empty catalog offers nothing to wait for and is asked again.
667
828
  if (store && key !== undefined && live.catalog.length > 0)
@@ -669,17 +830,13 @@ export async function connectMcpServers(servers, context, notice, taskSignal = c
669
830
  }
670
831
  catch (error) {
671
832
  startupSignal.throwIfAborted();
672
- // The one refusal that is the server's own answer rather than a failure to reach it: the
673
- // next task is told the same thing without waiting for the server to say it again.
674
- if (store && key !== undefined && error instanceof Error && error.message === OVER_BUDGET)
675
- await store.write(key, { overBudget: true }).catch(() => { });
676
- // A catalog refused for the task's budget came from a server that answered: that is not its status.
677
- else
678
- options.status?.(id, config, { state: 'failed', error: probeFailureReason(error, config) });
833
+ options.status?.(id, config, { state: 'failed', error: probeFailureReason(error, config) });
679
834
  notice(`MCP ${id}: unavailable (${unavailableReason(error)}).`);
680
835
  }
681
836
  }
682
837
  startupSignal.throwIfAborted();
838
+ if (deferred.length > 0)
839
+ tools.push(...deferredTools(deferred));
683
840
  return { tools, close: async () => { taskSignal.removeEventListener('abort', abort); await close(); }, settled: background };
684
841
  }
685
842
  catch (error) {
@@ -5,7 +5,13 @@ export interface MembershipVerdict {
5
5
  failureReason?: 'tls' | 'dns' | 'network';
6
6
  subject?: string;
7
7
  }
8
- /** A graph feature the account's membership does not reach. */
8
+ /**
9
+ * A graph feature the account's membership does not reach.
10
+ *
11
+ * The messages are the CLI's output, so they name `/login`; that advice is always a sentence of its
12
+ * own, which the desktop window replaces with its own way in (Settings › Account) when it shows the
13
+ * refusal (desktop/src/engine/errorWords.ts). Keep it that way when changing the wording.
14
+ */
9
15
  export declare class PaidMembershipRequiredError extends Error {
10
16
  constructor(message?: string);
11
17
  /**
@@ -1,10 +1,16 @@
1
- const FEATURES = 'the Andorra workflow, custom workflows and the Workflow Editor';
1
+ const FEATURES = 'the Andorra graph, custom graphs and the Graph Editor';
2
2
  const REASONS = {
3
3
  tls: 'a secure connection to the account service could not be verified',
4
4
  dns: 'the account service address could not be resolved',
5
5
  network: 'the account service could not be reached',
6
6
  };
7
- /** A graph feature the account's membership does not reach. */
7
+ /**
8
+ * A graph feature the account's membership does not reach.
9
+ *
10
+ * The messages are the CLI's output, so they name `/login`; that advice is always a sentence of its
11
+ * own, which the desktop window replaces with its own way in (Settings › Account) when it shows the
12
+ * refusal (desktop/src/engine/errorWords.ts). Keep it that way when changing the wording.
13
+ */
8
14
  export class PaidMembershipRequiredError extends Error {
9
15
  constructor(message = `Paid membership is required for ${FEATURES}. Use /login to sign in. If already signed in, check your membership or connection.`) { super(message); }
10
16
  /**
@@ -19,7 +25,7 @@ export class PaidMembershipRequiredError extends Error {
19
25
  return new PaidMembershipRequiredError(`Your Andorra membership could not be checked${reason}. This does not mean you were signed out; check your connection and retry.`);
20
26
  }
21
27
  if (!access.subject)
22
- return new PaidMembershipRequiredError(`You are signed out of your Andorra account. Use /login to sign in again; ${FEATURES} need a signed-in account.`);
28
+ return new PaidMembershipRequiredError(`You are signed out of your Andorra account; ${FEATURES} need a signed-in account. Use /login to sign in again.`);
23
29
  if (!access.paid)
24
30
  return new PaidMembershipRequiredError('This needs a paid membership, and your Andorra account does not have one.');
25
31
  return new PaidMembershipRequiredError();
@@ -0,0 +1,77 @@
1
+ import type { Tool } from '../types.js';
2
+ /**
3
+ * Per-project Markdown memory: small facts an agent wants a future session to know, such as how
4
+ * the team actually releases, which commands work, a user's corrections and known baseline test
5
+ * failures. One file per memory under `<home>/projects/<repositoryId>/memory/`, each with a
6
+ * `name`/`description`/`type` frontmatter, plus a `MEMORY.md` index of one line per memory.
7
+ *
8
+ * The folder is keyed by repository identity (origin remote, else the repository root), so every
9
+ * worktree and clone of a repository shares one memory. The index is recalled into each node's
10
+ * context at activation; bodies are read on demand with `memory_read`.
11
+ *
12
+ * This is separate from the provider-backed `MemoryManager` (distilled, verified facts behind a
13
+ * pluggable service) and from `LocalToolMemory` (automatic tool-failure lessons): these memories
14
+ * are written deliberately by agents and are plain files a person can read and edit.
15
+ */
16
+ export declare const PROJECT_MEMORY_TYPES: readonly ["user", "feedback", "project", "reference"];
17
+ export type ProjectMemoryType = typeof PROJECT_MEMORY_TYPES[number];
18
+ export interface ProjectMemoryEntry {
19
+ name: string;
20
+ description: string;
21
+ type: ProjectMemoryType;
22
+ body: string;
23
+ }
24
+ export declare const INDEX_FILE = "MEMORY.md";
25
+ /**
26
+ * Directory name for a repository id. Ids are already short slugs ending in a hash and are used
27
+ * as they are. One that is too long or not a plain slug keeps a readable prefix and gains a hash
28
+ * of the whole id, so bounding the name can never merge two repositories' memories.
29
+ */
30
+ export declare function folderName(repositoryId: string): string;
31
+ /** Parse a memory file. Returns undefined for anything that is not a well-formed memory. */
32
+ export declare function parseMemoryFile(text: string, fileName: string): ProjectMemoryEntry | undefined;
33
+ export declare function formatMemoryFile(entry: ProjectMemoryEntry): string;
34
+ /**
35
+ * Rewrite an index against the memories that exist: keep hand-written lines and the order of
36
+ * existing entries, refresh each entry's description, drop entries whose file is gone and append
37
+ * memories the index does not list yet. Reconciling against the files, not replaying one change,
38
+ * heals an index another process rewrote concurrently.
39
+ */
40
+ export declare function reconcileIndex(current: string, entries: ProjectMemoryEntry[]): string;
41
+ /**
42
+ * The repository a workspace's memory belongs to. A linked worktree resolves through its main
43
+ * repository, so every worktree and the main checkout share one identity: the origin remote when
44
+ * there is one, else the main checkout's root.
45
+ */
46
+ export declare function projectRepositoryId(workspace: string): Promise<string>;
47
+ export declare class ProjectMemory {
48
+ readonly directory: string;
49
+ readonly repositoryId: string;
50
+ private queue;
51
+ private constructor();
52
+ /** `home` is the Andorra home directory (`~/.andorracode`). Opening never touches the disk. */
53
+ static open(options: {
54
+ home: string;
55
+ workspace: string;
56
+ repositoryId?: string;
57
+ }): Promise<ProjectMemory>;
58
+ /** Serialize this process's writes so two nodes saving at once cannot interleave an index rewrite. */
59
+ private exclusive;
60
+ private readText;
61
+ list(): Promise<ProjectMemoryEntry[]>;
62
+ read(name: string): Promise<ProjectMemoryEntry | undefined>;
63
+ private writeAtomic;
64
+ private rewriteIndex;
65
+ /** Create or replace one memory. Throws with a model-readable reason when the entry is refused. */
66
+ write(entry: ProjectMemoryEntry): Promise<'created' | 'updated'>;
67
+ delete(name: string): Promise<boolean>;
68
+ /**
69
+ * The block recalled into a node's context: the guidance and the index, read fresh so a memory
70
+ * one node saved is visible to the next activation. The index is reconciled against the files
71
+ * rather than trusted: two processes saving at once can leave a `MEMORY.md` that misses one of
72
+ * them, or a person may delete a file by hand, and recall must still show what exists. Never
73
+ * throws; an unreadable folder recalls an empty index.
74
+ */
75
+ context(): Promise<string>;
76
+ tools(): Tool[];
77
+ }