@andorra-labs/code 0.1.8 → 0.1.9

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 (129) hide show
  1. package/THIRD_PARTY_NOTICES.md +2 -1
  2. package/dist/src/account-presentation.d.ts +11 -0
  3. package/dist/src/account-presentation.js +29 -2
  4. package/dist/src/agent-execution.js +37 -4
  5. package/dist/src/agent-mcp.d.ts +12 -0
  6. package/dist/src/agent-mcp.js +81 -2
  7. package/dist/src/app-server/protocol.d.ts +12 -0
  8. package/dist/src/app-server/reasoning.d.ts +0 -8
  9. package/dist/src/app-server/reasoning.js +15 -28
  10. package/dist/src/app-server.d.ts +7 -0
  11. package/dist/src/app-server.js +59 -11
  12. package/dist/src/auth/AuthManager.d.ts +15 -0
  13. package/dist/src/auth/AuthManager.js +66 -7
  14. package/dist/src/browser-runner.js +1 -2
  15. package/dist/src/browser-server.js +10 -2
  16. package/dist/src/browser-session.js +6 -2
  17. package/dist/src/browser-stealth.d.ts +29 -0
  18. package/dist/src/browser-stealth.js +166 -0
  19. package/dist/src/browser-ui/app.js +108 -13
  20. package/dist/src/browser-ui/icons/chevron-right.svg +8 -0
  21. package/dist/src/browser-ui/index.html +8 -8
  22. package/dist/src/browser-ui/style.css +199 -171
  23. package/dist/src/browser-ui/tokens.css +198 -0
  24. package/dist/src/browser-view.d.ts +57 -9
  25. package/dist/src/browser-view.js +187 -36
  26. package/dist/src/cli.js +21 -4
  27. package/dist/src/coding-tools.js +9 -5
  28. package/dist/src/command-screens.js +4 -4
  29. package/dist/src/commands.d.ts +1 -1
  30. package/dist/src/commands.js +2 -1
  31. package/dist/src/completion-gates.d.ts +35 -0
  32. package/dist/src/completion-gates.js +25 -0
  33. package/dist/src/completion.d.ts +6 -0
  34. package/dist/src/completion.js +36 -3
  35. package/dist/src/config.d.ts +1 -1
  36. package/dist/src/config.js +2 -2
  37. package/dist/src/context-budget.d.ts +11 -0
  38. package/dist/src/context-budget.js +13 -0
  39. package/dist/src/decision/DecisionEngine.d.ts +5 -1
  40. package/dist/src/decision/DecisionManager.d.ts +1 -0
  41. package/dist/src/decision/DecisionManager.js +14 -3
  42. package/dist/src/decision/FactContinuations.d.ts +6 -0
  43. package/dist/src/decision/FactContinuations.js +9 -1
  44. package/dist/src/decision/FactServiceGate.js +1 -1
  45. package/dist/src/decision/hostedSkills.d.ts +37 -0
  46. package/dist/src/decision/hostedSkills.js +64 -0
  47. package/dist/src/decision/providers/AndorraDecisionProvider.d.ts +10 -2
  48. package/dist/src/decision/providers/AndorraDecisionProvider.js +121 -10
  49. package/dist/src/default-graph.d.ts +11 -0
  50. package/dist/src/default-graph.js +20 -0
  51. package/dist/src/duration.d.ts +13 -2
  52. package/dist/src/duration.js +27 -3
  53. package/dist/src/graph-manager-chat.d.ts +302 -0
  54. package/dist/src/graph-manager-chat.js +940 -0
  55. package/dist/src/graph-runner.js +6 -0
  56. package/dist/src/graph-server.d.ts +9 -0
  57. package/dist/src/graph-server.js +167 -16
  58. package/dist/src/graph-studio-features.js +2 -2
  59. package/dist/src/graph-sync.js +5 -2
  60. package/dist/src/graph-ui/app.js +252 -71
  61. package/dist/src/graph-ui/controls.css +55 -32
  62. package/dist/src/graph-ui/controls.js +85 -9
  63. package/dist/src/graph-ui/edge-router.js +114 -13
  64. package/dist/src/graph-ui/embed.js +23 -8
  65. package/dist/src/graph-ui/index.html +3 -3
  66. package/dist/src/graph-ui/library.css +4 -10
  67. package/dist/src/graph-ui/manager-markdown.js +155 -0
  68. package/dist/src/graph-ui/manager-state.js +191 -0
  69. package/dist/src/graph-ui/manager.css +161 -0
  70. package/dist/src/graph-ui/manager.js +700 -0
  71. package/dist/src/graph-ui/studio-canvas.js +2 -0
  72. package/dist/src/graph-ui/studio.css +24 -23
  73. package/dist/src/graph-ui/studio.js +29 -8
  74. package/dist/src/graph-ui/style.css +125 -92
  75. package/dist/src/graph-ui/tokens.css +217 -151
  76. package/dist/src/graphs.d.ts +69 -1
  77. package/dist/src/graphs.js +160 -7
  78. package/dist/src/hardened-runtime.js +8 -2
  79. package/dist/src/membership-errors.d.ts +14 -0
  80. package/dist/src/membership-errors.js +24 -1
  81. package/dist/src/membership.d.ts +20 -0
  82. package/dist/src/membership.js +45 -16
  83. package/dist/src/palette.d.ts +25 -8
  84. package/dist/src/palette.js +26 -8
  85. package/dist/src/provider-engine.d.ts +4 -4
  86. package/dist/src/provider-engine.js +39 -22
  87. package/dist/src/providers.d.ts +24 -0
  88. package/dist/src/providers.js +47 -2
  89. package/dist/src/qa/guidance.d.ts +26 -0
  90. package/dist/src/qa/guidance.js +59 -0
  91. package/dist/src/qa/index.d.ts +1 -6
  92. package/dist/src/qa/index.js +1 -14
  93. package/dist/src/qa/runtime/ProcessManager.d.ts +20 -2
  94. package/dist/src/qa/runtime/ProcessManager.js +69 -13
  95. package/dist/src/react-runtime.d.ts +11 -0
  96. package/dist/src/react-runtime.js +190 -51
  97. package/dist/src/remote/engine-pool.js +4 -1
  98. package/dist/src/run-progress.d.ts +6 -0
  99. package/dist/src/run-progress.js +7 -0
  100. package/dist/src/runtime.d.ts +8 -0
  101. package/dist/src/session-skills.d.ts +75 -0
  102. package/dist/src/session-skills.js +151 -0
  103. package/dist/src/side-panel.d.ts +1 -1
  104. package/dist/src/side-panel.js +6 -12
  105. package/dist/src/skill-commands.js +1 -1
  106. package/dist/src/skills/bundled/control-browser/SKILL.md +9 -1
  107. package/dist/src/skills/bundled/graph-manager/SKILL.md +8 -0
  108. package/dist/src/skills/bundled/provenance.json +3 -3
  109. package/dist/src/skills/bundled/web-gui-tester/SKILL.md +1 -1
  110. package/dist/src/stall-recovery.d.ts +22 -0
  111. package/dist/src/stall-recovery.js +71 -0
  112. package/dist/src/subagent-run.js +1 -2
  113. package/dist/src/terminal-ui.d.ts +2 -2
  114. package/dist/src/terminal-ui.js +18 -13
  115. package/dist/src/transcript.js +9 -1
  116. package/dist/src/types.d.ts +18 -4
  117. package/dist/src/usage-analytics.d.ts +7 -0
  118. package/dist/src/usage-analytics.js +55 -15
  119. package/docs/concepts/README.md +1 -1
  120. package/docs/concepts/limits.md +9 -0
  121. package/docs/guides/desktop-app.md +1 -1
  122. package/docs/guides/graph-builder.md +16 -1
  123. package/docs/reference/slash-commands.md +2 -1
  124. package/docs/superpowers/plans/2026-11-13-graph-manager-chat.md +203 -0
  125. package/docs/superpowers/plans/2026-11-14-jev-fair-use-pricing.md +79 -0
  126. package/docs/superpowers/specs/2026-11-13-graph-manager-chat-design.md +182 -0
  127. package/docs/superpowers/specs/2026-11-14-jev-fair-use-pricing-design.md +156 -0
  128. package/package.json +1 -1
  129. package/tests/chat-side-panel-test-plan.md +1 -1
@@ -241,6 +241,12 @@ export async function runGraph(graph, options) {
241
241
  // Skill activation is run-wide and independent of conversation reuse or provider identity.
242
242
  // Journal replay restores it before any resumed frontier node starts.
243
243
  const activeSkills = new Set(options.resumeFrom?.progress.activeSkills ?? []);
244
+ // A run-level skill the stopped attempt inherited is decided again by this caller: the user may have
245
+ // paused, removed or replaced the session's skill since the stop. Skills a node loaded stay restored.
246
+ for (const skillId of options.resumeFrom?.progress.runSkills ?? []) {
247
+ if (!(options.inheritedSkills ?? []).includes(skillId))
248
+ activeSkills.delete(skillId);
249
+ }
244
250
  const queue = [{ nodeId: pinned.entry, generation: 0, path: [], inputs: {}, predecessors: {} }];
245
251
  const visits = new Map();
246
252
  const executed = new Set();
@@ -1,11 +1,20 @@
1
1
  import { type Config } from './config.js';
2
2
  import { type Membership } from './membership.js';
3
3
  import { GraphSync } from './graph-sync.js';
4
+ import { GraphManagerChat, type ManagerGraphRevision } from './graph-manager-chat.js';
5
+ /** What the Graph Manager routes need of the chat; a test supplies a stand-in for the engine-backed one. */
6
+ /**
7
+ * What the Graph Manager chat reads after each `graphs` call: the graph's latest stored revision, and
8
+ * whether it is the one a deletion publishes. Undefined for a graph with nothing stored.
9
+ */
10
+ export declare function readManagerGraphRevision(id: string, graphDirectory: string): Promise<ManagerGraphRevision | undefined>;
11
+ export type GraphManagerChatSession = Pick<GraphManagerChat, 'subscribe' | 'send' | 'approve' | 'answer' | 'cancel' | 'reset' | 'close'>;
4
12
  export declare function createGraphSessionCheck(subject: string | undefined, status?: (signal?: AbortSignal) => Promise<import("./auth/types.js").AuthStatus>, membership?: (signal?: AbortSignal, home?: string) => Promise<Membership>): () => Promise<void>;
5
13
  export declare function requireGraphProviders(directory?: string): Promise<Config>;
6
14
  export declare function startGraphServer(directory?: string, checkMembership?: () => Promise<unknown>, options?: {
7
15
  membership?: () => Promise<Membership>;
8
16
  sync?: GraphSync;
17
+ managerChat?: (directory: string) => GraphManagerChatSession;
9
18
  }): Promise<{
10
19
  url: string;
11
20
  origin: string;
@@ -6,7 +6,7 @@ import { execFile } from 'node:child_process';
6
6
  import { changeConfigFile, configDirectory, loadConfig, validateConfig } from './config.js';
7
7
  import { stampGraphProviderProfiles } from './graph-provider-portability.js';
8
8
  import { resetDeletedGraphSelection } from './graph-selection.js';
9
- import { listGraphs, loadGraph, saveGraph, validateGraph, migrateGraphForEditor, deleteGraph, withoutDeletedGraphs } from './graphs.js';
9
+ import { listGraphs, loadGraph, saveGraph, validateGraph, migrateGraphForEditor, deleteGraph, isDeletedGraph, withoutDeletedGraphs, GRAPH_MANAGER_GRAPH_ID, reservedGraphId } from './graphs.js';
10
10
  import { createTools } from './tools.js';
11
11
  import { AutomationStore } from './automations.js';
12
12
  import { deleteAgentDefinition, exportAgentDefinition, importAgentDefinition, listAgentDefinitions, readAgentDefinition, saveAgentDefinition, validateAgentDefinition } from './agent-definitions.js';
@@ -21,6 +21,36 @@ import { graphStorageDirectory } from './graph-account.js';
21
21
  import { GraphSync } from './graph-sync.js';
22
22
  import { editorSkillCatalog } from './skills/invocable-skills.js';
23
23
  import { graphRevisionHistory, previewGraphRoutes, studioRuns, studioRunEvents } from './graph-studio-features.js';
24
+ import { GraphManagerChat } from './graph-manager-chat.js';
25
+ /** What the Graph Manager routes need of the chat; a test supplies a stand-in for the engine-backed one. */
26
+ /**
27
+ * What the Graph Manager chat reads after each `graphs` call: the graph's latest stored revision, and
28
+ * whether it is the one a deletion publishes. Undefined for a graph with nothing stored.
29
+ */
30
+ export function readManagerGraphRevision(id, graphDirectory) {
31
+ return loadGraph(id, undefined, graphDirectory).then(graph => ({ revision: graph.revision, deleted: isDeletedGraph(graph) }), () => undefined);
32
+ }
33
+ /** The largest request body the editor accepts for a graph, whether it is being saved or sent to Graph Manager. */
34
+ const GRAPH_BODY_LIMIT = 512 * 1024;
35
+ const MANAGER_TOO_LARGE = 'This graph is too large to send to Graph Manager.';
36
+ const MANAGER_PING_MS = 15_000;
37
+ /**
38
+ * Reads a request body of at most `limit` bytes; undefined when it is larger. An oversized body is
39
+ * read to its end without being kept: leaving the loop early would destroy the request, and the
40
+ * connection with it, before the refusal could be delivered.
41
+ */
42
+ async function readBody(req, limit) {
43
+ let size = 0;
44
+ let chunks = [];
45
+ for await (const chunk of req) {
46
+ size += chunk.length;
47
+ if (size > limit)
48
+ chunks = undefined;
49
+ chunks?.push(Buffer.from(chunk));
50
+ }
51
+ return chunks && Buffer.concat(chunks);
52
+ }
53
+ const filled = (value) => typeof value === 'string' && value.trim() !== '';
24
54
  const setupMessage = 'No providers configured. Run `andorra` and open `/providers` first, then retry `andorra graph`.';
25
55
  export function createGraphSessionCheck(subject, status = getAuthStatus, membership = getMembership) {
26
56
  let revoked = false;
@@ -100,6 +130,22 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
100
130
  };
101
131
  await freeTier();
102
132
  const token = randomBytes(32).toString('hex');
133
+ // The Graph Manager chat owns a child engine, so it exists only once a panel asks for it. Revisions
134
+ // are read from the folder this account's graphs are saved in, which is where the agent's saves land.
135
+ const createManagerChat = options.managerChat ?? ((home) => new GraphManagerChat({
136
+ directory: home,
137
+ readRevision: id => readManagerGraphRevision(id, graphDirectory),
138
+ }));
139
+ let manager;
140
+ let closing = false;
141
+ const managerChat = () => {
142
+ // A request that outlives close() must not start an engine nothing would stop.
143
+ if (closing)
144
+ throw new Error('The editor is closing.');
145
+ return manager ??= createManagerChat(directory);
146
+ };
147
+ /** Ends each open Graph Manager stream, so closing the server never waits on one. */
148
+ const managerStreams = new Set();
103
149
  let origin = '';
104
150
  const assets = {
105
151
  '/': ['index.html', 'text/html; charset=utf-8'],
@@ -111,6 +157,10 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
111
157
  '/embed.js': ['embed.js', 'text/javascript; charset=utf-8'],
112
158
  '/sidebar.js': ['sidebar.js', 'text/javascript; charset=utf-8'],
113
159
  '/drafts.js': ['drafts.js', 'text/javascript; charset=utf-8'],
160
+ '/manager-markdown.js': ['manager-markdown.js', 'text/javascript; charset=utf-8'],
161
+ '/manager-state.js': ['manager-state.js', 'text/javascript; charset=utf-8'],
162
+ '/manager.js': ['manager.js', 'text/javascript; charset=utf-8'],
163
+ '/manager.css': ['manager.css', 'text/css; charset=utf-8'],
114
164
  '/edge-router.js': ['edge-router.js', 'text/javascript; charset=utf-8'],
115
165
  '/icons.js': ['icons.js', 'text/javascript; charset=utf-8'],
116
166
  '/controls.js': ['controls.js', 'text/javascript; charset=utf-8'],
@@ -168,9 +218,9 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
168
218
  if (path.startsWith('/api/')) {
169
219
  const expected = Buffer.from(`Bearer ${token}`);
170
220
  const authorized = (value) => { const supplied = Buffer.from(value); return supplied.length === expected.length && timingSafeEqual(supplied, expected); };
171
- // EventSource cannot send an Authorization header, so the activity stream alone also
172
- // accepts the session token in the query string.
173
- const streamQuery = path === '/api/activity/stream' ? `Bearer ${new URL(req.url, origin).searchParams.get('token') ?? ''}` : undefined;
221
+ // EventSource cannot send an Authorization header, so the two event streams alone also
222
+ // accept the session token in the query string.
223
+ const streamQuery = path === '/api/activity/stream' || path === '/api/manager/stream' ? `Bearer ${new URL(req.url, origin).searchParams.get('token') ?? ''}` : undefined;
174
224
  if (!authorized(req.headers.authorization ?? '') && !(streamQuery !== undefined && authorized(streamQuery))) {
175
225
  reply(res, 401, { error: 'Reopen the editor using andorra graph.' });
176
226
  return;
@@ -239,6 +289,93 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
239
289
  await push();
240
290
  return;
241
291
  }
292
+ if (req.method === 'GET' && path === '/api/manager/stream') {
293
+ const chat = managerChat();
294
+ res.writeHead(200, { 'Content-Type': 'text/event-stream; charset=utf-8', 'Cache-Control': 'no-store' });
295
+ res.flushHeaders?.();
296
+ let open = true;
297
+ let unsubscribe = () => { };
298
+ const finish = () => {
299
+ if (!open)
300
+ return;
301
+ open = false;
302
+ clearInterval(timer);
303
+ managerStreams.delete(end);
304
+ unsubscribe();
305
+ };
306
+ const end = () => { finish(); try {
307
+ res.end();
308
+ }
309
+ catch { /* The socket is already gone. */ } };
310
+ const timer = setInterval(() => {
311
+ // Logout or a membership downgrade revokes an open stream like any other editor request.
312
+ void (async () => { if (sync?.accessDenied)
313
+ throw new PaidMembershipRequiredError(); await checkSession(); })()
314
+ .then(() => { if (open && !res.destroyed)
315
+ res.write(': ping\n\n'); }, end);
316
+ }, MANAGER_PING_MS);
317
+ managerStreams.add(end);
318
+ req.on('close', finish);
319
+ res.on('close', finish);
320
+ // The chat hands over the conversation so far as a snapshot before anything else.
321
+ unsubscribe = chat.subscribe(event => { if (open && !res.destroyed)
322
+ res.write(`data: ${JSON.stringify(event)}\n\n`); });
323
+ if (!open)
324
+ unsubscribe();
325
+ return;
326
+ }
327
+ if (req.method === 'POST' && path.startsWith('/api/manager/')) {
328
+ const action = path.slice('/api/manager/'.length);
329
+ // The chat reports what goes wrong on the engine's side as an `error` event on the stream,
330
+ // and a message can take as long as an engine start, so no route waits for its outcome.
331
+ const accepted = (work) => { void work.catch(() => { }); reply(res, 200, { ok: true }); };
332
+ if (action === 'cancel') {
333
+ accepted(managerChat().cancel());
334
+ return;
335
+ }
336
+ if (action === 'reset') {
337
+ accepted(managerChat().reset());
338
+ return;
339
+ }
340
+ if (action === 'message' || action === 'approve' || action === 'answer') {
341
+ if (!req.headers['content-type']?.startsWith('application/json')) {
342
+ reply(res, 415, { error: 'Expected application/json' });
343
+ return;
344
+ }
345
+ const body = await readBody(req, GRAPH_BODY_LIMIT);
346
+ if (!body) {
347
+ reply(res, 413, { error: MANAGER_TOO_LARGE });
348
+ return;
349
+ }
350
+ const parsed = JSON.parse(body.toString('utf8'));
351
+ const value = parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : {};
352
+ if (action === 'approve') {
353
+ if (!filled(value.id) || typeof value.approved !== 'boolean')
354
+ throw new Error('An approval needs its id and a decision.');
355
+ accepted(managerChat().approve(value.id, value.approved));
356
+ return;
357
+ }
358
+ if (action === 'answer') {
359
+ if (!filled(value.id) || typeof value.value !== 'string')
360
+ throw new Error('An answer needs the question id and a value.');
361
+ accepted(managerChat().answer(value.id, value.value));
362
+ return;
363
+ }
364
+ const graph = value.graph;
365
+ if (!filled(value.provider) || !filled(value.model))
366
+ throw new Error('Choose a model for Graph Manager.');
367
+ if (!filled(value.text))
368
+ throw new Error('Write a message for Graph Manager.');
369
+ if (graph === null || typeof graph !== 'object' || Array.isArray(graph) || typeof graph.id !== 'string' || typeof graph.name !== 'string')
370
+ throw new Error('A message to Graph Manager needs the open graph.');
371
+ accepted(managerChat().send({
372
+ provider: value.provider, model: value.model, text: value.text,
373
+ graph: graph, saved: value.saved === true,
374
+ ...(typeof value.revision === 'number' && Number.isInteger(value.revision) && value.revision >= 0 ? { revision: value.revision } : {}),
375
+ }));
376
+ return;
377
+ }
378
+ }
242
379
  const config = await editorConfig(directory);
243
380
  if (req.method === 'GET' && path === '/api/sync') {
244
381
  reply(res, 200, sync?.status ?? { state: 'pending', detail: 'Saved locally' });
@@ -386,6 +523,10 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
386
523
  reply(res, 400, { error: 'The bundled default graph cannot be deleted.' });
387
524
  return;
388
525
  }
526
+ if (id === GRAPH_MANAGER_GRAPH_ID) {
527
+ reply(res, 400, { error: reservedGraphId(id).message });
528
+ return;
529
+ }
389
530
  // forgetGraph schedules the post-delete sync pass itself; scheduling another here
390
531
  // would bump the pass generation and traverse the whole history twice per delete.
391
532
  await deleteGraphWithTombstone(id, graphDirectory, directory, account.subject, sync);
@@ -407,17 +548,12 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
407
548
  reply(res, 415, { error: 'Expected application/json' });
408
549
  return;
409
550
  }
410
- let size = 0;
411
- const chunks = [];
412
- for await (const chunk of req) {
413
- size += chunk.length;
414
- if (size > 512 * 1024) {
415
- reply(res, 413, { error: 'Graph exceeds 512 KiB' });
416
- return;
417
- }
418
- chunks.push(Buffer.from(chunk));
551
+ const body = await readBody(req, GRAPH_BODY_LIMIT);
552
+ if (!body) {
553
+ reply(res, 413, { error: 'Graph exceeds 512 KiB' });
554
+ return;
419
555
  }
420
- const value = JSON.parse(Buffer.concat(chunks).toString('utf8'));
556
+ const value = JSON.parse(body.toString('utf8'));
421
557
  // The deletion marker is set only through the graph MCP server's delete tool, which confirms
422
558
  // with the person and checks automations first; an ordinary save may not carry it.
423
559
  if (path === '/api/graphs' && value && typeof value === 'object' && value.metadata && typeof value.metadata === 'object' && Object.hasOwn(value.metadata, 'deletedAt')) {
@@ -468,7 +604,7 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
468
604
  }
469
605
  // Stamping can add profile entries after the streamed body already passed the limit.
470
606
  const stamped = stampGraphProviderProfiles(graph, config);
471
- if (Buffer.byteLength(JSON.stringify(stamped)) > 512 * 1024) {
607
+ if (Buffer.byteLength(JSON.stringify(stamped)) > GRAPH_BODY_LIMIT) {
472
608
  reply(res, 413, { error: 'Graph exceeds 512 KiB' });
473
609
  return;
474
610
  }
@@ -509,7 +645,19 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
509
645
  if (!address || typeof address === 'string')
510
646
  throw new Error('Unable to bind graph server');
511
647
  origin = `http://127.0.0.1:${address.port}`;
512
- return { url: `${origin}/#token=${token}`, origin, token, close: async () => { await sync?.close(); await new Promise((resolve, reject) => { server.closeAllConnections(); server.close(error => error ? reject(error) : resolve()); }); } };
648
+ return { url: `${origin}/#token=${token}`, origin, token, close: async () => {
649
+ closing = true;
650
+ for (const end of [...managerStreams])
651
+ end();
652
+ // The server goes down even when the chat's engine does not stop cleanly.
653
+ try {
654
+ await manager?.close();
655
+ }
656
+ finally {
657
+ await sync?.close();
658
+ await new Promise((resolve, reject) => { server.closeAllConnections(); server.close(error => error ? reject(error) : resolve()); });
659
+ }
660
+ } };
513
661
  }
514
662
  /**
515
663
  * Reset the configured selection only after the deletion succeeds. Otherwise a graph-lock
@@ -517,6 +665,9 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
517
665
  * between removal and reset is handled by the CLI's missing-selection fallback.
518
666
  */
519
667
  export async function deleteGraphWithTombstone(id, graphDirectory, directory, subject, sync) {
668
+ // The signed-in path never reaches deleteGraph, so the built-in graph is refused here for both.
669
+ if (id === GRAPH_MANAGER_GRAPH_ID)
670
+ throw reservedGraphId(id);
520
671
  // An automation would fail at its next run; the user decides what it runs instead. The graph
521
672
  // MCP server's delete tool applies the same check, so the editor cannot bypass it.
522
673
  const users = (await new AutomationStore(directory).list()).filter(job => job.execution?.graph === id);
@@ -1,6 +1,6 @@
1
1
  import { readdir, readFile, open, stat } from 'node:fs/promises';
2
2
  import { join } from 'node:path';
3
- import { DEFAULT_HARNESS, loadGraph } from './graphs.js';
3
+ import { DEFAULT_GRAPH, loadGraph } from './graphs.js';
4
4
  import { runRecordsDirectory, runRecordPath } from './run-records.js';
5
5
  /** A conservative connectivity walkthrough, not a substitute for a real Agent/Join/Loop run. */
6
6
  export function previewGraphRoutes(graph, choices = {}) {
@@ -120,7 +120,7 @@ export async function graphRevisionHistory(id, directory) {
120
120
  safeId(id);
121
121
  let revisions;
122
122
  if (id === 'default')
123
- revisions = Array.from({ length: DEFAULT_HARNESS.revision }, (_, index) => DEFAULT_HARNESS.revision - index);
123
+ revisions = Array.from({ length: DEFAULT_GRAPH.revision }, (_, index) => DEFAULT_GRAPH.revision - index);
124
124
  else {
125
125
  // A new/imported draft has no saved revision directory yet.
126
126
  let filenames;
@@ -4,7 +4,7 @@ import { setTimeout as delay } from 'node:timers/promises';
4
4
  import { join, relative } from 'node:path';
5
5
  import { AUTH_REFRESH_BUDGET_MS, getAccessToken, getAuthConfiguration, getAuthStatus } from './auth/index.js';
6
6
  import { decodeJwt } from 'jose';
7
- import { GraphConflictError, restoreGraphRevision, validateGraph } from './graphs.js';
7
+ import { GRAPH_MANAGER_GRAPH_ID, GraphConflictError, reservedGraphId, restoreGraphRevision, validateGraph } from './graphs.js';
8
8
  import { acquireSaveLock, removeLockedFolder, SaveLockBusyError } from './save-lock.js';
9
9
  import { readGraphQuota } from './graph-quota.js';
10
10
  const MAX_BYTES = 600 * 1024;
@@ -367,6 +367,9 @@ export class GraphSync {
367
367
  async forgetGraph(id) {
368
368
  if (!safeId(id) || id === 'default')
369
369
  throw new Error('Invalid graph id');
370
+ // Built in: there is no stored graph to remove, and a tombstone would outlive a delete that removed nothing.
371
+ if (id === GRAPH_MANAGER_GRAPH_ID)
372
+ throw reservedGraphId(id);
370
373
  await mkdir(this.folder, { recursive: true });
371
374
  const folder = join(this.directory, 'graphs', id);
372
375
  let release;
@@ -458,7 +461,7 @@ export class GraphSync {
458
461
  * the replacement's latest pointer.
459
462
  */
460
463
  async reviveGraph(id) {
461
- if (!safeId(id) || id === 'default')
464
+ if (!safeId(id) || id === 'default' || id === GRAPH_MANAGER_GRAPH_ID)
462
465
  return;
463
466
  // A slow draft prune can hold the account lock past the normal two-second budget.
464
467
  // A successful save must not return while its tombstone remains: keep retrying the