@andorra-labs/code 0.1.13 → 0.1.15

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 (168) hide show
  1. package/dist/src/account-presentation.js +4 -1
  2. package/dist/src/acp-agent.d.ts +54 -0
  3. package/dist/src/acp-agent.js +991 -0
  4. package/dist/src/agent-execution.js +304 -140
  5. package/dist/src/agent-mcp-catalog.js +2 -0
  6. package/dist/src/agent-mcp.d.ts +2 -0
  7. package/dist/src/agent-mcp.js +86 -4
  8. package/dist/src/andorra/endpoint.d.ts +7 -0
  9. package/dist/src/andorra/endpoint.js +46 -0
  10. package/dist/src/andorra/entry.d.ts +21 -0
  11. package/dist/src/andorra/entry.js +118 -0
  12. package/dist/src/andorra/errors.d.ts +2 -0
  13. package/dist/src/andorra/errors.js +39 -0
  14. package/dist/src/andorra/hosted.d.ts +55 -0
  15. package/dist/src/andorra/hosted.js +130 -0
  16. package/dist/src/andorra/monitor.d.ts +151 -0
  17. package/dist/src/andorra/monitor.js +393 -0
  18. package/dist/src/andorra/notices.d.ts +16 -0
  19. package/dist/src/andorra/notices.js +38 -0
  20. package/dist/src/andorra/opt-in.d.ts +58 -0
  21. package/dist/src/andorra/opt-in.js +112 -0
  22. package/dist/src/andorra/request-watch.d.ts +6 -0
  23. package/dist/src/andorra/request-watch.js +10 -0
  24. package/dist/src/andorra/state.d.ts +86 -0
  25. package/dist/src/andorra/state.js +238 -0
  26. package/dist/src/andorra/terminal.d.ts +70 -0
  27. package/dist/src/andorra/terminal.js +125 -0
  28. package/dist/src/andorra/usage-format.d.ts +9 -0
  29. package/dist/src/andorra/usage-format.js +19 -0
  30. package/dist/src/anthropic-credentials.js +9 -1
  31. package/dist/src/app-server/protocol.d.ts +10 -2
  32. package/dist/src/app-server/protocol.js +1 -1
  33. package/dist/src/app-server/workspace.d.ts +1 -0
  34. package/dist/src/app-server/workspace.js +141 -10
  35. package/dist/src/app-server.d.ts +35 -0
  36. package/dist/src/app-server.js +377 -124
  37. package/dist/src/auth/AuthManager.d.ts +9 -0
  38. package/dist/src/auth/AuthManager.js +164 -24
  39. package/dist/src/auth/deployment.d.ts +1 -0
  40. package/dist/src/auth/deployment.js +1 -0
  41. package/dist/src/auth/index.d.ts +1 -1
  42. package/dist/src/auth/index.js +1 -1
  43. package/dist/src/auth/store.d.ts +26 -0
  44. package/dist/src/auth/store.js +34 -1
  45. package/dist/src/browser-bridge.d.ts +1 -0
  46. package/dist/src/browser-bridge.js +5 -2
  47. package/dist/src/browser-external-app.d.ts +27 -0
  48. package/dist/src/browser-external-app.js +60 -0
  49. package/dist/src/browser-panel-tool.d.ts +6 -0
  50. package/dist/src/browser-panel-tool.js +36 -0
  51. package/dist/src/browser-runner.js +1 -1
  52. package/dist/src/browser-server.d.ts +5 -0
  53. package/dist/src/browser-server.js +27 -3
  54. package/dist/src/browser-stealth.d.ts +19 -1
  55. package/dist/src/browser-stealth.js +23 -3
  56. package/dist/src/browser-ui/tokens.css +4 -4
  57. package/dist/src/browser-view.d.ts +81 -0
  58. package/dist/src/browser-view.js +289 -18
  59. package/dist/src/bug-report.d.ts +81 -0
  60. package/dist/src/bug-report.js +235 -0
  61. package/dist/src/claude-provider.d.ts +2 -1
  62. package/dist/src/claude-provider.js +10 -8
  63. package/dist/src/cli-sign-in.d.ts +3 -1
  64. package/dist/src/cli-sign-in.js +4 -1
  65. package/dist/src/cli.js +205 -58
  66. package/dist/src/coding-tools.js +7 -7
  67. package/dist/src/command-screens.d.ts +26 -3
  68. package/dist/src/command-screens.js +323 -85
  69. package/dist/src/commands.d.ts +7 -1
  70. package/dist/src/commands.js +79 -27
  71. package/dist/src/completion-gates.d.ts +22 -0
  72. package/dist/src/completion-gates.js +11 -0
  73. package/dist/src/config.d.ts +11 -1
  74. package/dist/src/config.js +134 -3
  75. package/dist/src/dashboard-view.d.ts +2 -0
  76. package/dist/src/dashboard-view.js +11 -2
  77. package/dist/src/decision/PreparedSteps.js +1 -1
  78. package/dist/src/decision/applyToolMenu.js +1 -1
  79. package/dist/src/decision/toolFamilies.js +1 -1
  80. package/dist/src/decision/types.d.ts +1 -0
  81. package/dist/src/google-provider.d.ts +31 -0
  82. package/dist/src/google-provider.js +153 -0
  83. package/dist/src/graph-health.d.ts +11 -0
  84. package/dist/src/graph-health.js +36 -4
  85. package/dist/src/graph-manager-chat.d.ts +33 -0
  86. package/dist/src/graph-manager-chat.js +165 -6
  87. package/dist/src/graph-runner.js +27 -0
  88. package/dist/src/graph-selection.js +2 -1
  89. package/dist/src/graph-sync.d.ts +1 -0
  90. package/dist/src/graph-sync.js +93 -34
  91. package/dist/src/graph-tool.d.ts +2 -0
  92. package/dist/src/graph-tool.js +2 -2
  93. package/dist/src/graph-ui/app.js +92 -10
  94. package/dist/src/graph-ui/edge-router.js +121 -53
  95. package/dist/src/graph-ui/manager.js +40 -5
  96. package/dist/src/graph-ui/style.css +5 -2
  97. package/dist/src/graph-ui/tokens.css +4 -4
  98. package/dist/src/graph-visibility.d.ts +31 -0
  99. package/dist/src/graph-visibility.js +102 -0
  100. package/dist/src/graphs.js +1 -3
  101. package/dist/src/hardened-runtime.js +1 -1
  102. package/dist/src/live-model.d.ts +24 -0
  103. package/dist/src/live-model.js +37 -0
  104. package/dist/src/managed-sign-in.d.ts +1 -0
  105. package/dist/src/managed-sign-in.js +13 -0
  106. package/dist/src/membership-errors.d.ts +2 -0
  107. package/dist/src/membership-errors.js +6 -2
  108. package/dist/src/membership.d.ts +13 -2
  109. package/dist/src/membership.js +39 -8
  110. package/dist/src/model-context-windows.d.ts +2 -0
  111. package/dist/src/model-context-windows.js +24 -0
  112. package/dist/src/model-health-cache.js +1 -1
  113. package/dist/src/model-metadata.d.ts +1 -0
  114. package/dist/src/model-metadata.js +47 -3
  115. package/dist/src/paged-transcript.d.ts +2 -0
  116. package/dist/src/paged-transcript.js +16 -0
  117. package/dist/src/palette.d.ts +1 -0
  118. package/dist/src/palette.js +1 -1
  119. package/dist/src/permissions.js +17 -4
  120. package/dist/src/provider-connection.js +32 -0
  121. package/dist/src/provider-engine.d.ts +5 -0
  122. package/dist/src/provider-engine.js +3 -3
  123. package/dist/src/provider-import.js +3 -1
  124. package/dist/src/provider-settings.d.ts +16 -1
  125. package/dist/src/provider-settings.js +50 -22
  126. package/dist/src/providers.d.ts +29 -3
  127. package/dist/src/providers.js +100 -18
  128. package/dist/src/react-runtime.js +33 -12
  129. package/dist/src/read-document-tool.d.ts +2 -0
  130. package/dist/src/read-document-tool.js +6 -6
  131. package/dist/src/remote/engine-pool.js +31 -6
  132. package/dist/src/run-control.d.ts +2 -2
  133. package/dist/src/run-control.js +9 -6
  134. package/dist/src/runtime-environment.d.ts +1 -0
  135. package/dist/src/runtime-environment.js +13 -0
  136. package/dist/src/runtime.d.ts +2 -0
  137. package/dist/src/runtime.js +2 -1
  138. package/dist/src/save-lock.js +14 -7
  139. package/dist/src/session-title.d.ts +3 -0
  140. package/dist/src/session-title.js +5 -2
  141. package/dist/src/sessions.d.ts +1 -0
  142. package/dist/src/sessions.js +4 -2
  143. package/dist/src/sign-in-detection.d.ts +1 -1
  144. package/dist/src/sign-in-detection.js +10 -3
  145. package/dist/src/sign-in-offer.js +1 -1
  146. package/dist/src/skill-commands.js +1 -1
  147. package/dist/src/skills/bundled/bug-report/SKILL.md +80 -0
  148. package/dist/src/skills/bundled/graph-manager/SKILL.md +9 -1
  149. package/dist/src/skills/bundled/graph-manager/errors.md +2 -1
  150. package/dist/src/skills/bundled/provenance.json +743 -738
  151. package/dist/src/skills/runtime-skills.js +1 -0
  152. package/dist/src/subagent-run.d.ts +2 -0
  153. package/dist/src/subagent-run.js +14 -3
  154. package/dist/src/telemetry/schema.d.ts +1 -1
  155. package/dist/src/telemetry/schema.js +2 -2
  156. package/dist/src/telemetry/uploader.d.ts +7 -1
  157. package/dist/src/telemetry/uploader.js +11 -2
  158. package/dist/src/terminal-links.d.ts +16 -0
  159. package/dist/src/terminal-links.js +113 -0
  160. package/dist/src/terminal-ui.d.ts +29 -1
  161. package/dist/src/terminal-ui.js +113 -24
  162. package/dist/src/tool-catalog.js +1 -1
  163. package/dist/src/trajectory.js +6 -1
  164. package/dist/src/transcript.d.ts +2 -0
  165. package/dist/src/transcript.js +5 -1
  166. package/dist/src/types.d.ts +5 -0
  167. package/dist/src/workspace-instructions.js +1 -1
  168. package/package.json +13 -1
@@ -397,6 +397,10 @@ export async function runGraph(graph, options) {
397
397
  }
398
398
  const liveUsage = { inputTokens: 0, outputTokens: 0, requests: 0 };
399
399
  const nodeUsageTotals = new Map();
400
+ // A node's total includes what its subagents spent, so a subagent's own figures are kept apart: usage
401
+ // arrives per model invocation, and the events that name both ids say which invocations are whose.
402
+ const invocationUsageTotals = new Map();
403
+ const subagentInvocations = new Map();
400
404
  const addUsage = (target, delta) => {
401
405
  target.inputTokens += delta.inputTokens;
402
406
  target.outputTokens += delta.outputTokens;
@@ -571,14 +575,37 @@ export async function runGraph(graph, options) {
571
575
  const total = nodeUsageTotals.get(nodeId) ?? { inputTokens: 0, outputTokens: 0, requests: 0 };
572
576
  addMeasuredUsage(total, usage);
573
577
  nodeUsageTotals.set(nodeId, total);
578
+ if (origin?.invocationId) {
579
+ const own = invocationUsageTotals.get(origin.invocationId) ?? { inputTokens: 0, outputTokens: 0, requests: 0 };
580
+ addMeasuredUsage(own, usage);
581
+ invocationUsageTotals.set(origin.invocationId, own);
582
+ }
574
583
  options.onUsage?.(usage, origin);
575
584
  },
576
585
  onEvent: async (event) => {
577
586
  event = { ...event, data: { runId: result.id, ...event.data, nodeName: node.name, nodeType: node.type } };
587
+ const { subagentId, invocationId } = event.data;
588
+ if (typeof subagentId === 'string' && subagentId && typeof invocationId === 'string' && invocationId) {
589
+ const own = subagentInvocations.get(subagentId) ?? new Set();
590
+ own.add(invocationId);
591
+ subagentInvocations.set(subagentId, own);
592
+ }
578
593
  if (event.type === 'agent.model.completed') {
579
594
  const { measuredOutputTokens: _chipsOnly, ...runUsage } = liveUsage;
580
595
  event = { ...event, data: { ...event.data, graphUsage: runUsage,
581
596
  nodeUsage: { ...(nodeUsageTotals.get(nodeId) ?? { inputTokens: 0, outputTokens: 0, requests: 0 }) } } };
597
+ if (typeof subagentId === 'string' && subagentId) {
598
+ const subagentUsage = { inputTokens: 0, outputTokens: 0, requests: 0 };
599
+ for (const id of subagentInvocations.get(subagentId) ?? []) {
600
+ const part = invocationUsageTotals.get(id);
601
+ if (part === undefined)
602
+ continue;
603
+ addUsage(subagentUsage, part);
604
+ if (part.measuredOutputTokens !== undefined)
605
+ subagentUsage.measuredOutputTokens = (subagentUsage.measuredOutputTokens ?? 0) + part.measuredOutputTokens;
606
+ }
607
+ event = { ...event, data: { ...event.data, subagentUsage } };
608
+ }
582
609
  }
583
610
  if (activation.parallelGroup && event.type === 'graph.todos.updated')
584
611
  event = { ...event, type: 'agent.modifier.todos.updated' };
@@ -1,4 +1,5 @@
1
1
  import { getAuthStatus } from './auth/index.js';
2
+ import { currentGraphSelection } from './membership.js';
2
3
  export async function currentGraphSubject() {
3
4
  const status = await getAuthStatus().catch(() => ({ signedIn: false, subject: undefined }));
4
5
  return status.signedIn && status.subject && /^[A-Za-z0-9-]{1,128}$/.test(status.subject) ? status.subject : undefined;
@@ -11,7 +12,7 @@ export function identityStillHolds(declared, current) {
11
12
  return true;
12
13
  }
13
14
  export function configuredGraphSelection(config, subject) {
14
- return subject && Object.hasOwn(config.graphSelections ?? {}, subject) ? config.graphSelections[subject] : 'default';
15
+ return subject && Object.hasOwn(config.graphSelections ?? {}, subject) ? currentGraphSelection(config.graphSelections[subject]) : 'default';
15
16
  }
16
17
  export function saveGraphSelection(config, graph, subject) {
17
18
  if (graph !== 'default' && !subject)
@@ -23,6 +23,7 @@ export declare class GraphSync {
23
23
  private generation;
24
24
  private deadline;
25
25
  private readonly lastDraft;
26
+ private readonly stored;
26
27
  private readonly folder;
27
28
  constructor(directory: string, subject: string, deps?: GraphSyncDependencies);
28
29
  start(): Promise<void>;
@@ -1,5 +1,5 @@
1
1
  import { createHash, randomUUID } from 'node:crypto';
2
- import { mkdir, readdir, readFile, rename, writeFile, link, unlink } from 'node:fs/promises';
2
+ import { mkdir, readdir, readFile, rename, stat, writeFile, link, unlink } from 'node:fs/promises';
3
3
  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';
@@ -118,6 +118,7 @@ export class GraphSync {
118
118
  generation = 0;
119
119
  deadline = 0;
120
120
  lastDraft = new Map();
121
+ stored = new Map();
121
122
  folder;
122
123
  constructor(directory, subject, deps = defaults) {
123
124
  this.directory = directory;
@@ -574,6 +575,7 @@ export class GraphSync {
574
575
  || (saved.file !== undefined && (typeof saved.file !== 'string' || !/^(?:\d+|[a-f0-9]{64})\.json$/.test(saved.file)))
575
576
  || (saved.drafts !== undefined && typeof saved.drafts !== 'boolean')
576
577
  || (saved.invalid !== undefined && (!Number.isSafeInteger(saved.invalid) || saved.invalid < 0))
578
+ || (saved.head !== undefined && !safeId(saved.head))
577
579
  || (saved.refused !== undefined && (!Array.isArray(saved.refused) || saved.refused.length > 10_000
578
580
  || saved.refused.some((file) => typeof file !== 'string' || !REFUSED_FILE.test(file)))))
579
581
  throw new Error('Invalid local checkpoint');
@@ -585,21 +587,36 @@ export class GraphSync {
585
587
  let processed = 0, localComplete = false;
586
588
  const refused = new Set(local.refused ?? []);
587
589
  let confirmKept;
590
+ // Resolves true when the file cost a request, false when it was already stored or cannot be read.
591
+ // `head` marks the newest-revision pass below, whose files the history sweep also visits and counts.
588
592
  const upload = async (path, kind, filename, options = {}) => {
589
- let raw;
593
+ let raw, mark;
590
594
  try {
595
+ // A file this process already found stored is recognized by its size and times, without opening it:
596
+ // every pass now visits every file, and reading them all again each time would cost far more than it saves.
597
+ const info = await stat(path);
598
+ mark = `${info.size}:${info.mtimeMs}:${info.ino}`;
599
+ if (!options.confirm && this.stored.get(path) === mark)
600
+ return false;
591
601
  const body = await readFile(path, 'utf8');
592
- if (!options.confirm && receipts[path] === digest(body))
602
+ if (!options.confirm && receipts[path] === digest(body)) {
603
+ this.stored.set(path, mark);
593
604
  return false;
605
+ }
594
606
  raw = kind === 'revision' ? envelope(kind, JSON.parse(body)) : body;
595
607
  parseSnapshot(raw, kind === 'draft' ? filename.slice(0, -5) : digest(raw));
596
608
  }
597
609
  catch {
598
- local.invalid = (local.invalid ?? 0) + 1;
610
+ if (!options.head)
611
+ local.invalid = (local.invalid ?? 0) + 1;
599
612
  return false;
600
613
  }
601
614
  const hash = digest(raw);
602
- if (options.confirm || !await this.cached(hash)) {
615
+ if (!options.confirm && await this.cached(hash)) {
616
+ this.stored.set(path, mark);
617
+ return false;
618
+ }
619
+ {
603
620
  if (this.status === recheck)
604
621
  this.status = { state: 'syncing', detail: 'Saving graphs to your account…' };
605
622
  try {
@@ -614,47 +631,89 @@ export class GraphSync {
614
631
  return true;
615
632
  }
616
633
  await immutable(join(this.folder, 'snapshots', `${hash}.json`), raw);
634
+ this.stored.set(path, mark);
617
635
  return true;
618
636
  }
619
- return false;
620
637
  };
621
638
  const exhausted = () => processed >= 32 || this.now() >= localDeadline || this.stopped;
622
- if (!local.drafts) {
623
- const dirs = (await entries(join(this.directory, 'graphs'))).filter(dir => dir.isDirectory() && safeId(dir.name) && !deleted.has(dir.name)).sort((a, b) => a.name < b.name ? -1 : 1);
624
- const kept = (await readGraphQuota(this.directory).catch(() => undefined))?.freeGraphId;
625
- const latest = kept && dirs.some(dir => dir.name === kept)
626
- ? (await entries(join(this.directory, 'graphs', kept))).filter(file => file.isFile() && /^\d+\.json$/.test(file.name))
627
- .sort((a, b) => Number.parseInt(b.name, 10) - Number.parseInt(a.name, 10))[0]
628
- : undefined;
629
- if (kept && latest) {
630
- let confirmed = false;
631
- confirmKept = async () => {
632
- if (confirmed)
633
- return;
634
- confirmed = true;
635
- await upload(join(this.directory, 'graphs', kept, latest.name), 'revision', latest.name, { pin: true, confirm: true });
636
- };
637
- if (!local.directory && await upload(join(this.directory, 'graphs', kept, latest.name), 'revision', latest.name, { pin: true }))
638
- processed++;
639
+ // A file that was already stored costs no request, so it does not count against the batch and its
640
+ // checkpoint is written once for the run of them: a sweep over an account's settled history takes
641
+ // one pass, not one pass per 32 files.
642
+ let unsaved = false;
643
+ const advance = async (worked) => {
644
+ if (!worked) {
645
+ unsaved = true;
646
+ return;
647
+ }
648
+ processed++;
649
+ unsaved = false;
650
+ await atomic(localPath, JSON.stringify(local));
651
+ };
652
+ const dirs = (await entries(join(this.directory, 'graphs'))).filter(dir => dir.isDirectory() && safeId(dir.name) && !deleted.has(dir.name)).sort((a, b) => a.name < b.name ? -1 : 1);
653
+ const revisions = async (id) => (await entries(join(this.directory, 'graphs', id))).filter(file => file.isFile() && /^\d+\.json$/.test(file.name));
654
+ const newest = async (id) => (await revisions(id)).sort((a, b) => Number.parseInt(b.name, 10) - Number.parseInt(a.name, 10))[0];
655
+ const kept = (await readGraphQuota(this.directory).catch(() => undefined))?.freeGraphId;
656
+ const latest = kept && dirs.some(dir => dir.name === kept) ? await newest(kept) : undefined;
657
+ if (kept && latest) {
658
+ let confirmed = false;
659
+ confirmKept = async () => {
660
+ if (confirmed)
661
+ return;
662
+ confirmed = true;
663
+ await upload(join(this.directory, 'graphs', kept, latest.name), 'revision', latest.name, { pin: true, confirm: true });
664
+ };
665
+ }
666
+ // The newest revision of every graph goes up before the sweep resumes, the kept graph first so it
667
+ // takes the free pin. A graph that was just published is therefore stored by the pass its save
668
+ // starts, wherever the sweep's checkpoint stands; the sweep still carries the older revisions.
669
+ // It shares the sweep's batch and takes at most half its local time, so neither many new graphs nor
670
+ // a collection too large to check in one slice keeps the pass from the sweep and the account index.
671
+ // A scan that is cut short records the last graph it checked and the next pass carries on after it.
672
+ const refusedBefore = refused.size, resumedAfter = local.head;
673
+ const headDeadline = Math.min(localDeadline, this.now() + 2500);
674
+ const others = dirs.filter(dir => dir.name !== kept);
675
+ const rotated = resumedAfter === undefined ? others
676
+ : [...others.filter(dir => dir.name > resumedAfter), ...others.filter(dir => dir.name <= resumedAfter)];
677
+ let headsDone = true;
678
+ for (const dir of [...dirs.filter(dir => dir.name === kept), ...rotated]) {
679
+ if (processed >= 32 || this.now() >= headDeadline || this.stopped) {
680
+ headsDone = false;
681
+ break;
639
682
  }
683
+ const head = dir.name === kept ? latest : await newest(dir.name);
684
+ if (dir.name !== kept)
685
+ local.head = dir.name;
686
+ if (!head)
687
+ continue;
688
+ const path = join(this.directory, 'graphs', dir.name, head.name);
689
+ if (refused.has(relative(this.directory, path).replace(/\\/g, '/')))
690
+ continue;
691
+ if (await upload(path, 'revision', head.name, { pin: dir.name === kept, head: true }))
692
+ processed++;
693
+ }
694
+ if (headsDone)
695
+ delete local.head;
696
+ if (refused.size > refusedBefore || local.head !== resumedAfter)
697
+ await atomic(localPath, JSON.stringify(local));
698
+ if (!local.drafts) {
640
699
  outer: for (const dir of dirs) {
641
700
  if (local.directory && dir.name < local.directory)
642
701
  continue;
643
- const files = (await entries(join(this.directory, 'graphs', dir.name))).filter(file => file.isFile() && /^\d+\.json$/.test(file.name)).sort((a, b) => a.name < b.name ? -1 : 1);
702
+ const files = (await revisions(dir.name)).sort((a, b) => a.name < b.name ? -1 : 1);
644
703
  for (const file of files) {
645
704
  if (dir.name === local.directory && local.file && file.name <= local.file)
646
705
  continue;
647
706
  if (exhausted())
648
707
  break outer;
649
- await upload(join(this.directory, 'graphs', dir.name, file.name), 'revision', file.name, { pin: dir.name === kept });
708
+ const worked = await upload(join(this.directory, 'graphs', dir.name, file.name), 'revision', file.name, { pin: dir.name === kept });
650
709
  local.directory = dir.name;
651
710
  local.file = file.name;
652
- processed++;
653
- await atomic(localPath, JSON.stringify(local));
711
+ await advance(worked);
654
712
  }
655
713
  }
656
714
  if (!exhausted()) {
657
- local = { drafts: true, invalid: local.invalid, ...(refused.size ? { refused: [...refused] } : {}) };
715
+ local = { drafts: true, invalid: local.invalid, ...(refused.size ? { refused: [...refused] } : {}), ...(local.head ? { head: local.head } : {}) };
716
+ unsaved = false;
658
717
  await atomic(localPath, JSON.stringify(local));
659
718
  }
660
719
  }
@@ -674,22 +733,22 @@ export class GraphSync {
674
733
  if (deleted.has(parseSnapshot(raw, file.name.slice(0, -5)).graphId)) {
675
734
  await unlink(join(this.directory, 'graph-drafts', file.name)).catch(() => { });
676
735
  local.file = file.name;
677
- processed++;
678
- await atomic(localPath, JSON.stringify(local));
736
+ await advance(true);
679
737
  continue;
680
738
  }
681
739
  }
682
740
  catch { }
683
741
  }
684
- await upload(join(this.directory, 'graph-drafts', file.name), 'draft', file.name);
742
+ const worked = await upload(join(this.directory, 'graph-drafts', file.name), 'draft', file.name);
685
743
  local.file = file.name;
686
- processed++;
687
- await atomic(localPath, JSON.stringify(local));
744
+ await advance(worked);
688
745
  }
689
746
  }
747
+ if (unsaved && !localComplete)
748
+ await atomic(localPath, JSON.stringify(local));
690
749
  const invalidLocalFiles = local.invalid ?? 0;
691
750
  if (localComplete)
692
- await atomic(localPath, '{}');
751
+ await atomic(localPath, JSON.stringify(local.head ? { head: local.head } : {}));
693
752
  const progressPath = join(this.folder, 'index-progress.json');
694
753
  let progress = {};
695
754
  try {
@@ -2,6 +2,7 @@ import type { Tool } from './types.js';
2
2
  export interface GraphBackend {
3
3
  call(name: string, args: unknown, options?: {
4
4
  beforeSave?: () => void;
5
+ workspace?: string;
5
6
  }): Promise<{
6
7
  ok: true;
7
8
  data: unknown;
@@ -20,6 +21,7 @@ export declare class GraphBackendPool {
20
21
  });
21
22
  call(directory: string, action: string, args: unknown, options?: {
22
23
  beforeSave?: () => void;
24
+ workspace?: string;
23
25
  }): Promise<{
24
26
  ok: true;
25
27
  data: unknown;
@@ -61,7 +61,7 @@ function actionSummary() {
61
61
  export function createGraphTool(pool = sharedPool) {
62
62
  return {
63
63
  name: 'graphs', capability: 'external', executionMode: 'sequential',
64
- description: 'Create, edit, validate, publish, delete or restore Andorra graphs (multi-agent workflows) in the signed-in account\'s graph store, the same store the Graph Builder and graph picker use. Never write graph files on disk. '
64
+ description: 'Create, edit, validate, publish, delete or restore Andorra graphs, and choose which projects list them, (multi-agent workflows) in the signed-in account\'s graph store, the same store the Graph Builder and graph picker use. Never write graph files on disk. '
65
65
  + 'Call action andorra_graph_guide first for node types, ports, limits and error codes; load the skill andorra:graph-manager to design a graph with the user. '
66
66
  + 'Put the action\'s arguments in args. Drafts are kept in this Andorra process for up to an hour; publish saves a revision and syncs it to the account. Publish, delete and restore ask the user for permission, except under Full Access, which approves them without a prompt; never tell the user a prompt is coming when the task runs in Full Access. '
67
67
  + `Actions and their args (* required): ${actionSummary()}.`,
@@ -93,7 +93,7 @@ export function createGraphTool(pool = sharedPool) {
93
93
  throw error;
94
94
  }
95
95
  };
96
- const reply = await pool.call(context.automationDirectory ?? configDirectory(), action, input, { beforeSave });
96
+ const reply = await pool.call(context.automationDirectory ?? configDirectory(), action, input, { beforeSave, workspace: context.workspace });
97
97
  if (refused !== undefined)
98
98
  throw refused;
99
99
  let text = JSON.stringify(reply);
@@ -252,7 +252,7 @@ function outcomes(node) {
252
252
  function edgeOutcome(edge) { return edge.outcome || 'completed'; }
253
253
  function pruneRoutes(node) { state.graph.edges = state.graph.edges.filter(edge => edge.source !== node.id || outcomes(node).includes(edgeOutcome(edge))); }
254
254
  function selectedNodes() { return (state.selectedIds.length ? state.selectedIds : state.selected ? [state.selected] : []).map(id => state.graph?.nodes[id]).filter(Boolean); }
255
- function selectionType(node) { return `${node.type}:${node.agentRole || 'regular'}`; }
255
+ function selectionType(node) { return node.type; }
256
256
  function clearSelection() { state.selectedIds = []; state.selected = null; state.selectedEdge = null; state.routePick = null; state.bulkOutcome = null; }
257
257
  function showInspector() { $('inspector').classList.remove('hidden'); $('toggle-inspector').setAttribute('aria-expanded','true'); }
258
258
  function selectNode(node, event = {}) {
@@ -281,10 +281,65 @@ function routeSelectionTo(targetId) {
281
281
  },true);
282
282
  status(`Routed ${sources.length} steps to ${target.name}. Existing matching connections were kept; set the inputs of new ones below.`);
283
283
  }
284
+ const MIXED = 'Mixed';
285
+ // What every selected step has for one setting, or `mixed` when they differ.
286
+ function sharedValue(nodes, read) {
287
+ const first = read(nodes[0]), key = JSON.stringify(first ?? null);
288
+ return nodes.every(node => JSON.stringify(read(node) ?? null) === key) ? { value: first, mixed: false } : { value: undefined, mixed: true };
289
+ }
290
+ function bulkChoice(parent, label, nodes, read, values, write) {
291
+ const { value, mixed } = sharedValue(nodes, read);
292
+ const options = values.map(item => typeof item === 'string' ? { value: item, label: item.replaceAll('-', ' ') } : item);
293
+ const input = field(parent, label, mixed ? '' : value, chosen => { if (chosen !== '') for (const node of nodes) write(node, chosen); }, { options: mixed ? [{ value: '', label: MIXED }, ...options] : options, refresh: true });
294
+ if (mixed) input.children[0].disabled = true;
295
+ return input;
296
+ }
297
+ function bulkCheck(parent, label, nodes, read, write) {
298
+ const { value, mixed } = sharedValue(nodes, node => !!read(node));
299
+ const input = check(parent, label, !mixed && value, checked => { for (const node of nodes) write(node, checked); });
300
+ if (mixed) { input.indeterminate = true; input.setAttribute('aria-checked', 'mixed'); }
301
+ return input;
302
+ }
303
+ function bulkNumber(parent, label, nodes, read, write, options = {}) {
304
+ const { value, mixed } = sharedValue(nodes, read);
305
+ const input = field(parent, label, mixed ? '' : value, next => { for (const node of nodes) write(node, next); }, { type: 'number', refresh: true, ...options, placeholder: mixed ? MIXED : options.placeholder });
306
+ const commit = input.onchange;
307
+ // A blank box leaves the steps as they are while they differ, and is not a number where one is required.
308
+ input.onchange = () => { if (input.value.trim() === '' && (mixed || !options.optional)) { renderInspector(); return; } commit(); };
309
+ return input;
310
+ }
311
+ function renderBulkSettings(panels, nodes) {
312
+ explain(bulkCheck(panels.general, 'Jev decisions', nodes, node => node.jevEnabled === true, (node, on) => { if (on) node.jevEnabled = true; else delete node.jevEnabled; }), 'Off unless ticked. When Jev is on, it assists each selected agent with routing decisions. A dash means some of the selected steps have it on; ticking turns it on for all of them.');
313
+ const models = sharedValue(nodes, node => [node.provider ?? null, node.model ?? null]);
314
+ modelFields(panels.model, models.mixed ? {} : { provider: nodes[0].provider, model: nodes[0].model }, value => { for (const node of nodes) { node.provider = value.provider; node.model = value.model; } }, undefined, undefined, undefined, { mixed: models.mixed });
315
+ bulkChoice(panels.model, 'Conversation', nodes, node => node.contextPolicy?.conversation ?? 'reuse', [{value:'reuse',label:'Reuse with the same provider and model'}, {value:'isolate',label:'Start an isolated conversation'}], (node, value) => { node.contextPolicy = { ...node.contextPolicy, conversation: value }; });
316
+ bulkChoice(panels.model, 'Skill inheritance', nodes, node => node.contextPolicy?.skillInheritance ?? 'inherit', [{value:'inherit',label:'Inherit active graph skills'}, {value:'none',label:'Do not inherit skills'}], (node, value) => { node.contextPolicy = { ...node.contextPolicy, skillInheritance: value }; });
317
+ const advanced = panels.advanced;
318
+ const caps = disclosure(advanced, 'Permissions');
319
+ for (const [key, values] of Object.entries(CAPABILITIES)) bulkChoice(caps, key.charAt(0).toUpperCase() + key.slice(1), nodes, node => node.capabilities?.[key] || effectiveCaps()[key], values, (node, value) => { node.capabilities = { ...effectiveCaps(), ...node.capabilities, [key]: value }; });
320
+ const context = disclosure(advanced, 'Context sharing');
321
+ bulkCheck(context, 'Include previous task summaries', nodes, node => node.contextPolicy?.history ?? false, (node, value) => { node.contextPolicy = { ...node.contextPolicy, history: value }; });
322
+ bulkChoice(context, 'Visible predecessor state', nodes, node => node.contextPolicy?.predecessors || 'none', ['none', 'direct', 'all'], (node, value) => { node.contextPolicy = { ...node.contextPolicy, predecessors: value }; });
323
+ bulkNumber(context, 'Maximum context characters', nodes, node => node.contextPolicy?.maxChars ?? 32000, (node, value) => { node.contextPolicy = { ...node.contextPolicy, maxChars: value }; }, { min: 1 });
324
+ const limits = disclosure(advanced, 'Execution limits');
325
+ for (const [key, label, defaultValue] of [['maxContextChars', 'Context characters', 120000], ['maxCompletionRepairs', 'Completion repair tries', 2]]) bulkNumber(limits, label, nodes, node => node.limits?.[key] ?? defaultValue, (node, value) => { node.limits = { ...node.limits, [key]: value }; delete node.limits.maxTokens; }, { min: key === 'maxCompletionRepairs' ? 0 : 1 });
326
+ bulkNumber(limits, 'Iterations (blank = unlimited)', nodes, node => node.limits?.maxIterations ?? node.maxIterations, (node, value) => { node.limits = { ...node.limits, maxIterations: value }; delete node.limits.maxTokens; if (value === undefined) { delete node.limits.maxIterations; delete node.maxIterations; } else node.maxIterations = value; }, { min: 0, max: 1000, optional: true, placeholder: 'Unlimited' });
327
+ bulkNumber(limits, 'Wall time, seconds (blank = unlimited)', nodes, node => msToSeconds(node.limits?.wallTimeMs), (node, value) => { node.limits = { ...node.limits, wallTimeMs: secondsToMs(value) }; delete node.limits.maxTokens; if (value === undefined) delete node.limits.wallTimeMs; }, { min: 0, step: 'any', optional: true, placeholder: 'Unlimited' });
328
+ bulkNumber(limits, 'Tool calls (blank = unlimited)', nodes, node => node.limits?.maxToolCalls, (node, value) => { node.limits = { ...node.limits, maxToolCalls: value }; if (value === undefined) delete node.limits.maxToolCalls; }, { min: 0, optional: true, placeholder: 'Unlimited' });
329
+ bulkNumber(advanced, 'Retries', nodes, node => node.retry?.maxAttempts ?? 1, (node, value) => { node.retry = { ...node.retry, maxAttempts: value }; }, { min: 1 });
330
+ const tools = disclosure(advanced, 'Tool allowlist'), all = () => state.tools.map(tool => typeof tool === 'string' ? tool : tool.name || tool.id);
331
+ for (const name of [...new Set([...all(), ...nodes.flatMap(node => node.tools || [])])]) bulkCheck(tools, name, nodes, node => node.tools === undefined || node.tools.includes(name), (node, enabled) => { node.tools = enabled ? [...new Set([...(node.tools ?? all()), name])] : (node.tools ?? all()).filter(tool => tool !== name); });
332
+ }
284
333
  function renderBulkInspector(parent, nodes) {
285
334
  $('inspector-title').textContent = `${nodes.length} steps selected`;
286
335
  parent.append(el('p',nodes.map(node=>node.name).join(', '),'help'));
287
- const group = section(parent,'Output step');
336
+ let routing = parent;
337
+ if (nodes.every(node => node.type === 'agent')) {
338
+ parent.append(el('p', `Changes here apply to all ${nodes.length} selected steps. ${MIXED} marks a setting the steps do not share yet; names, prompts and outcomes stay per step.`, 'help'));
339
+ const panels = inspectorTabs(parent, ['general', 'model', 'behavior', 'advanced']);
340
+ renderBulkSettings(panels, nodes); routing = panels.behavior;
341
+ }
342
+ const group = section(routing,'Output step');
288
343
  const shared = outcomes(nodes[0]).filter(outcome => nodes.every(node => outcomes(node).includes(outcome)));
289
344
  if (!shared.length) {group.append(el('p','These steps have no shared outcome. Give them a matching completion outcome before routing together.','help'));return;}
290
345
  if (!shared.includes(state.bulkOutcome)) state.bulkOutcome=shared[0];
@@ -848,14 +903,17 @@ function renderEdges() {
848
903
  for(const [name,value] of Object.entries({'text-anchor':'middle',fill:palette.pillInk}))text.setAttribute(name,value);
849
904
  text.textContent=outcome;group.append(rect,text);pillLayer.append(group);
850
905
  const pill={rect,text,width:Math.max(28,Math.round(outcome.length*6.6+16))};
851
- entry.pill=group;drawnEdges[index].pill=pill;drawnPills.push({pill,at});
906
+ entry.pill=group;drawnEdges[index].pill=pill;drawnPills.push({pill,at,index});
852
907
  }
853
908
  $('edges').append(pillLayer,caption);
854
- for(const {pill,at} of drawnPills){
909
+ const pillWidths=[];
910
+ for(const {pill,index} of drawnPills){
855
911
  const measured=typeof pill.text.getComputedTextLength==='function'?pill.text.getComputedTextLength():0;
856
912
  if(measured>0)pill.width=Math.max(28,Math.ceil(measured+16));
857
- pill.rect.setAttribute('width',String(pill.width));placePill(pill,at);
913
+ pill.rect.setAttribute('width',String(pill.width));pillWidths[index]=pill.width;
858
914
  }
915
+ const pillSpots=AndorraEdgeRouter.placeLabels?.(routedPoints,pillWidths,PILL_HEIGHT,rectangles);
916
+ for(const {pill,at,index} of drawnPills)placePill(pill,pillSpots?.[index]||at);
859
917
  emphasize(state.selectedEdge);
860
918
  }
861
919
  function removeNodes(ids) {
@@ -966,12 +1024,33 @@ function inspectorTabs(parent, ids) {
966
1024
  if (remembered !== undefined && !ids.includes(remembered)) state.inspectorTab = remembered;
967
1025
  return panels;
968
1026
  }
1027
+ const promptHeights = new Map();
969
1028
  function promptField(parent, label, value, onChange, options = {}) {
970
1029
  const input = field(parent, label, value, onChange, { multiline: true, maxLength: 100000, ...options });
971
1030
  const wrapper = input.parentElement; wrapper.className = 'field prompt-field';
972
1031
  const isFullscreen = () => !!wrapper.classList.contains?.('fullscreen');
973
- const grow = () => { try { if (!isFullscreen() && input.scrollHeight) { input.style.height = 'auto'; input.style.height = `${input.scrollHeight + 2}px`; } } catch { } };
1032
+ // Typing grows the field up to 60% of the window; dragging its corner sets a height that typing no
1033
+ // longer overrides, kept for this label while the editor stays open so another step opens at that size.
1034
+ const grow = () => { try {
1035
+ if (isFullscreen()) return;
1036
+ const kept = promptHeights.get(label); if (kept) { input.style.height = kept; return; }
1037
+ if (!input.scrollHeight) return;
1038
+ const cap = Math.round((globalThis.innerHeight || 0) * 0.6);
1039
+ input.style.height = 'auto'; input.style.height = `${cap ? Math.min(input.scrollHeight + 2, cap) : input.scrollHeight + 2}px`;
1040
+ } catch { } };
974
1041
  input.addEventListener?.('input', grow);
1042
+ input.addEventListener?.('pointerdown', () => {
1043
+ if (isFullscreen()) return;
1044
+ const before = input.offsetHeight;
1045
+ const settle = () => { if (input.offsetHeight && input.offsetHeight !== before) promptHeights.set(label, `${input.offsetHeight}px`); };
1046
+ document.addEventListener?.('pointerup', settle, { once: true });
1047
+ });
1048
+ input.addEventListener?.('dblclick', event => {
1049
+ // Double-clicking the resize corner returns the field to sizing itself to its text.
1050
+ if (!promptHeights.has(label) || isFullscreen()) return;
1051
+ const rect = input.getBoundingClientRect?.(); if (!rect || event.clientX < rect.right - 16 || event.clientY < rect.bottom - 16) return;
1052
+ promptHeights.delete(label); grow();
1053
+ });
975
1054
  const expand = el('button', undefined, 'icon-button btn-small prompt-expand'); expand.type = 'button';
976
1055
  let backdrop;
977
1056
  const setFullscreen = on => {
@@ -1110,6 +1189,7 @@ function modelFields(parent, target, update, parentModel, inheritedProvider, fal
1110
1189
  const pickerButton = modelPickerButton({
1111
1190
  ariaLabel: 'Model',
1112
1191
  current: () => {
1192
+ if (options.mixed) return { model: MIXED, provider: '', entry: undefined };
1113
1193
  const pinned = target.model?.trim();
1114
1194
  const entry = entryFor(effectiveProvider);
1115
1195
  if (!pinned && !target.provider && options.defaultLabel) return { model: options.defaultLabel, provider: '', entry: undefined };
@@ -1126,7 +1206,7 @@ function modelFields(parent, target, update, parentModel, inheritedProvider, fal
1126
1206
  });
1127
1207
  },
1128
1208
  selected: () => target.model?.trim() ? { provider: effectiveProvider, model: target.model.trim() } : null,
1129
- defaultRow: () => options.noDefault ? undefined : ({ label: defaultLabel, hint: defaultHint, selected: !target.provider && !target.model?.trim() }),
1209
+ defaultRow: () => options.noDefault ? undefined : ({ label: defaultLabel, hint: defaultHint, selected: !options.mixed && !target.provider && !target.model?.trim() }),
1130
1210
  pickDefault: () => mutate(() => update({ ...target, provider: undefined, model: undefined }), true),
1131
1211
  pick: ({ provider: chosenProvider, model: chosenModel }) => {
1132
1212
  if (chosenProvider === effectiveProvider && !(options.requireProvider && !target.provider)) { model.value = chosenModel; model.onchange(); return; }
@@ -1196,13 +1276,13 @@ function modelFields(parent, target, update, parentModel, inheritedProvider, fal
1196
1276
  parent.append(el('p', `This selection follows "${originalId}"'s current model, ${exact.model}.`, 'help'));
1197
1277
  }
1198
1278
  }
1199
- const info = el('p', 'Context window: detecting from model…', 'help model-context'); parent.append(info);
1279
+ const info = el('p', options.mixed ? 'The selected steps use different models. Choosing one applies it to all of them.' : 'Context window: detecting from model…', 'help model-context'); parent.append(info);
1200
1280
  const key = JSON.stringify([target.provider || '', target.model || '', provider?.model || '']);
1201
1281
  const registryGeneration = state.providerRegistryGeneration || 0;
1202
1282
  state.modelContextRequests ||= new Map();
1203
1283
  if (!state.modelContextRequests.has(key)) state.modelContextRequests.set(key, api(`/api/model-context?provider=${encodeURIComponent(target.provider || '')}&model=${encodeURIComponent(target.model || '')}`).catch(() => ({contextWindow:null})));
1204
1284
  state.modelContextRequests.get(key).then(data => {
1205
- if ((state.providerRegistryGeneration || 0) !== registryGeneration) return;
1285
+ if (options.mixed || (state.providerRegistryGeneration || 0) !== registryGeneration) return;
1206
1286
  info.textContent = data.contextWindow ? `Context window: ${data.contextWindow.toLocaleString()} tokens (automatic)` : 'Context window: not reported by this model. Runtime uses its default budget.';
1207
1287
  });
1208
1288
  const override = disclosure(parent, 'Custom model name');
@@ -1294,7 +1374,9 @@ function renderCompletion(parent, node) {
1294
1374
  graph.edges = graph.edges.filter(edge => edge.source !== node.id || outcomes(node).includes(edgeOutcome(edge)));
1295
1375
  });
1296
1376
  explain(behavior, 'Outcome names are short phrases such as DONE, PASS, FAILED TESTING or BLOCKED. Describe when the agent should choose each one; for a single outcome, describe when the work is considered achieved, for example "This is considered DONE when xyz is finished". The agent evaluates these written criteria using its evidence; they are not automatic checks. Connect outcomes to destinations under Connections.');
1297
- if (delegatesWriting(node) && node.completion?.mode !== 'outcomes') { for (const option of behavior.options) option.disabled = option.value === 'outcomes'; parent.append(el('p', 'An Orchestrator with a writing role keeps a single outcome: it completes by passing work on, or delivers landed changes through its delivered port.', 'help')); }
1377
+ if (delegatesWriting(node)) parent.append(el('p', node.completion?.mode === 'outcomes'
1378
+ ? 'An Orchestrator with a writing role picks one of these outcomes whether or not its subagents implemented the work, so name a route for each case, such as release, QA or no QA.'
1379
+ : 'An Orchestrator with a writing role completes by passing work on, or delivers landed changes through its delivered port. Choose outcomes to route delivered work yourself.', 'help'));
1298
1380
  if (node.completion?.mode === 'outcomes') {
1299
1381
  parent.append(el('p', 'Criteria are optional; blank rows use the agent prompt. Removing or renaming an outcome removes its old routes. Undo restores routes and criteria.', 'help'));
1300
1382
  if (node.modifiers?.condition || node.modifiers?.loop?.until.outcome !== undefined) parent.append(el('p', 'Modifiers control the final connections: a Condition routes to true/false; an outcome Loop exposes its exit outcome.', 'help'));