@andorra-labs/code 0.1.10 → 0.1.11

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 (155) hide show
  1. package/README.md +28 -208
  2. package/THIRD_PARTY_NOTICES.md +15 -0
  3. package/dist/src/agent-execution.js +36 -0
  4. package/dist/src/app-server/protocol.d.ts +1 -0
  5. package/dist/src/app-server.d.ts +34 -1
  6. package/dist/src/app-server.js +264 -54
  7. package/dist/src/automation-service.js +1 -1
  8. package/dist/src/browser-session.d.ts +8 -0
  9. package/dist/src/browser-session.js +27 -1
  10. package/dist/src/browser-ui/app.js +237 -15
  11. package/dist/src/browser-ui/index.html +5 -5
  12. package/dist/src/browser-ui/style.css +110 -65
  13. package/dist/src/browser-ui/tokens.css +27 -26
  14. package/dist/src/coding-tools.d.ts +24 -0
  15. package/dist/src/coding-tools.js +71 -8
  16. package/dist/src/command-screens.js +1 -1
  17. package/dist/src/commands.js +1 -1
  18. package/dist/src/completion-gates.d.ts +42 -7
  19. package/dist/src/completion-gates.js +55 -9
  20. package/dist/src/completion.d.ts +8 -0
  21. package/dist/src/completion.js +19 -1
  22. package/dist/src/dashboard-view.js +2 -2
  23. package/dist/src/deadline.js +4 -0
  24. package/dist/src/graph-manager-chat.js +13 -13
  25. package/dist/src/graph-runner.js +39 -2
  26. package/dist/src/graph-server.js +9 -9
  27. package/dist/src/graph-sync.d.ts +8 -0
  28. package/dist/src/graph-sync.js +54 -3
  29. package/dist/src/graph-tool.js +1 -1
  30. package/dist/src/graph-ui/app.js +262 -93
  31. package/dist/src/graph-ui/controls.css +43 -22
  32. package/dist/src/graph-ui/controls.js +31 -1
  33. package/dist/src/graph-ui/embed.js +62 -13
  34. package/dist/src/graph-ui/icons.js +4 -0
  35. package/dist/src/graph-ui/index.html +3 -3
  36. package/dist/src/graph-ui/manager-state.js +2 -2
  37. package/dist/src/graph-ui/manager.css +19 -18
  38. package/dist/src/graph-ui/manager.js +11 -11
  39. package/dist/src/graph-ui/skill-picker.js +1 -1
  40. package/dist/src/graph-ui/studio-canvas.js +8 -8
  41. package/dist/src/graph-ui/studio.css +18 -15
  42. package/dist/src/graph-ui/studio.js +92 -35
  43. package/dist/src/graph-ui/style.css +122 -79
  44. package/dist/src/graph-ui/theme.js +2 -2
  45. package/dist/src/graph-ui/tokens.css +33 -29
  46. package/dist/src/graphs.d.ts +3 -2
  47. package/dist/src/graphs.js +3 -2
  48. package/dist/src/membership-errors.d.ts +7 -1
  49. package/dist/src/membership-errors.js +9 -3
  50. package/dist/src/pull-requests.d.ts +42 -6
  51. package/dist/src/pull-requests.js +11 -3
  52. package/dist/src/react-runtime.js +121 -14
  53. package/dist/src/read-document-doc.d.ts +20 -0
  54. package/dist/src/read-document-doc.js +524 -0
  55. package/dist/src/read-document-docx.d.ts +21 -0
  56. package/dist/src/read-document-docx.js +584 -0
  57. package/dist/src/read-document-text.d.ts +29 -0
  58. package/dist/src/read-document-text.js +67 -0
  59. package/dist/src/read-document-tool.d.ts +48 -0
  60. package/dist/src/read-document-tool.js +162 -0
  61. package/dist/src/read-document.d.ts +78 -0
  62. package/dist/src/read-document.js +353 -0
  63. package/dist/src/read-image.d.ts +29 -2
  64. package/dist/src/read-image.js +42 -17
  65. package/dist/src/runtime.d.ts +19 -0
  66. package/dist/src/runtime.js +10 -1
  67. package/dist/src/session-changes.d.ts +6 -1
  68. package/dist/src/session-changes.js +13 -5
  69. package/dist/src/side-panel.d.ts +6 -1
  70. package/dist/src/side-panel.js +12 -10
  71. package/dist/src/skills/bundled/create-skill/SKILL.md +1 -1
  72. package/dist/src/skills/bundled/diagram/SKILL.md +1 -1
  73. package/dist/src/skills/bundled/graph-manager/SKILL.md +37 -3
  74. package/dist/src/skills/bundled/graph-manager/patterns.md +27 -0
  75. package/dist/src/skills/bundled/provenance.json +4 -4
  76. package/dist/src/skills/runtime-skills.js +3 -3
  77. package/dist/src/stall-recovery.d.ts +6 -2
  78. package/dist/src/stall-recovery.js +7 -2
  79. package/dist/src/terminal-ui.js +2 -2
  80. package/dist/src/time-limit.d.ts +53 -0
  81. package/dist/src/time-limit.js +79 -0
  82. package/dist/src/tools.js +92 -7
  83. package/dist/src/transcript.js +1 -1
  84. package/dist/src/types.d.ts +6 -0
  85. package/dist/src/usage-analytics.d.ts +3 -1
  86. package/dist/src/usage-analytics.js +16 -2
  87. package/package.json +6 -26
  88. package/docs/README.md +0 -36
  89. package/docs/agents/README.md +0 -62
  90. package/docs/agents/install-for-agents.md +0 -56
  91. package/docs/agents/mcp-server.md +0 -212
  92. package/docs/agents/subagent-mode.md +0 -149
  93. package/docs/concepts/README.md +0 -47
  94. package/docs/concepts/jev-actionable-routing.md +0 -113
  95. package/docs/concepts/jev-decision-thresholds.md +0 -412
  96. package/docs/concepts/jev-efficiency.md +0 -217
  97. package/docs/concepts/jev-eval-2026-11-01.md +0 -78
  98. package/docs/concepts/limits.md +0 -52
  99. package/docs/concepts/memory.md +0 -10
  100. package/docs/concepts/security.md +0 -50
  101. package/docs/concepts/workspace-instructions.md +0 -29
  102. package/docs/getting-started/README.md +0 -82
  103. package/docs/getting-started/accounts.md +0 -78
  104. package/docs/getting-started/configure-providers.md +0 -132
  105. package/docs/guides/README.md +0 -13
  106. package/docs/guides/browser.md +0 -39
  107. package/docs/guides/desktop-app.md +0 -414
  108. package/docs/guides/extensions.md +0 -102
  109. package/docs/guides/graph-builder.md +0 -116
  110. package/docs/guides/headless.md +0 -46
  111. package/docs/guides/tui.md +0 -75
  112. package/docs/guides/update.md +0 -70
  113. package/docs/guides/web-search.md +0 -51
  114. package/docs/guides/windows-code-signing.md +0 -319
  115. package/docs/llms.txt +0 -45
  116. package/docs/reference/README.md +0 -7
  117. package/docs/reference/cli.md +0 -76
  118. package/docs/reference/config.md +0 -91
  119. package/docs/reference/slash-commands.md +0 -59
  120. package/docs/superpowers/plans/2026-11-01-claude-console-sign-in.md +0 -111
  121. package/docs/superpowers/plans/2026-11-01-jev-node-opt-in.md +0 -910
  122. package/docs/superpowers/plans/2026-11-02-workflow-pane.md +0 -398
  123. package/docs/superpowers/plans/2026-11-06-graph-soft-delete.md +0 -125
  124. package/docs/superpowers/plans/2026-11-09-orchestrator-delegation.md +0 -295
  125. package/docs/superpowers/plans/2026-11-13-graph-manager-chat.md +0 -203
  126. package/docs/superpowers/plans/2026-11-14-jev-fair-use-pricing.md +0 -79
  127. package/docs/superpowers/specs/2026-10-31-work-line-summary-design.md +0 -50
  128. package/docs/superpowers/specs/2026-11-01-claude-console-sign-in-design.md +0 -176
  129. package/docs/superpowers/specs/2026-11-01-jev-node-opt-in-design.md +0 -164
  130. package/docs/superpowers/specs/2026-11-01-pr-section-design.md +0 -111
  131. package/docs/superpowers/specs/2026-11-02-workflow-pane-design.md +0 -130
  132. package/docs/superpowers/specs/2026-11-06-bundled-skills-design.md +0 -206
  133. package/docs/superpowers/specs/2026-11-09-orchestrator-delegation-design.md +0 -291
  134. package/docs/superpowers/specs/2026-11-13-graph-manager-chat-design.md +0 -182
  135. package/docs/superpowers/specs/2026-11-14-jev-fair-use-pricing-design.md +0 -156
  136. package/scripts/jev-efficiency-eval.mjs +0 -187
  137. package/scripts/jev-efficiency-live.mjs +0 -193
  138. package/scripts/zcode-engine-replay.mjs +0 -223
  139. package/tests/agent-centric-mcp-test-plan.md +0 -208
  140. package/tests/analytics-settings-test-plan.md +0 -165
  141. package/tests/browser-cli-smoke.mjs +0 -276
  142. package/tests/browser-test-plan.md +0 -280
  143. package/tests/chat-side-panel-test-plan.md +0 -309
  144. package/tests/decision-engine-test-plan.md +0 -163
  145. package/tests/default-active-jev-test-plan.md +0 -85
  146. package/tests/harness-extensions-test-plan.md +0 -113
  147. package/tests/jev-all-decisions-test-plan.md +0 -156
  148. package/tests/jev-efficiency/criteria.json +0 -158
  149. package/tests/jev-efficiency/workloads.mjs +0 -242
  150. package/tests/jev-efficiency-test-plan.md +0 -198
  151. package/tests/permissions-sandbox-probe.mjs +0 -74
  152. package/tests/permissions-test-plan.md +0 -191
  153. package/tests/product-telemetry-test-plan.md +0 -536
  154. package/tests/thinking-stream-preview-test-plan.md +0 -136
  155. package/tests/zcode-react-engine-test-plan.md +0 -396
@@ -1,295 +0,0 @@
1
- # Orchestrator Delegation Implementation Plan
2
-
3
- > **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
4
-
5
- **Goal:** Let an Orchestrator node delegate implementation to writing subagents, each in its own Git worktree with a shell, review their diffs and test reports, land accepted changes into the working folder, and finish on a new `delivered` outcome, without the Orchestrator itself ever writing code.
6
-
7
- **Architecture:** Graph validation learns a "delegating Orchestrator" (spawning on and at least one writing role) with two capability ceilings and a `delivered` output port. A new `src/delegation-changes.ts` module owns every Git operation: snapshot the working folder, create a worktree from the snapshot, collect a child's change, three-way land it with `git merge-tree`, and clean up. `executeAgentNode` wires those into `spawn_subagent`, adds `accept_change` / `discard_change`, and guards the `delivered` completion. The graph builder and desktop view gain the matching port, copy and change states.
8
-
9
- **Tech Stack:** TypeScript (Node ESM), `node:test` via `scripts/run-tests.mjs` for engine tests, Vitest for `desktop/`, Git CLI ≥ 2.40.
10
-
11
- **Spec:** `docs/superpowers/specs/2026-11-09-orchestrator-delegation-design.md`
12
-
13
- ## Global Constraints
14
-
15
- - Existing graphs, including `DEFAULT_HARNESS`, `DEFAULT_HARNESS_REVISION_1..5` and every saved graph, load, validate and run exactly as before.
16
- - `createOrchestratorNode()` must return exactly what it returns today (revision 5 and the default harness are built from it at load time).
17
- - With delegation inactive (no writing role, spawning off, or no `delivered` edge in `options.graph`), `executeAgentNode` behaves byte-for-byte as today, including the existing refusal "Subagent capabilities exceed its parent".
18
- - The Orchestrator's own capabilities stay `intakeCapabilities(node)` in every mode. It never gets `Write`, `Edit`, a shell, or a Git write tool.
19
- - Only writing roles of a delegating Orchestrator, running in `workspace: 'worktree'`, may get command tools. Every other child keeps `canRunCommands === false`.
20
- - Accepted changes land as uncommitted working-folder edits. The user's index, refs, stash and branches are never modified.
21
- - Every Git invocation uses `-c core.hooksPath= -c core.fsmonitor=false`, `windowsHide: true`, a timeout, and the run's abort signal, as the existing worktree code does.
22
- - Delegated writing requires Git ≥ 2.40 (`git merge-tree --write-tree --merge-base`). Older Git fails the first writing spawn with: `Delegated writing needs Git 2.40 or newer.`
23
- - The Orchestrator remains Premium (`src/graph-quota.ts` unchanged).
24
- - Build with `npm run build`. Run engine tests one file at a time with `node scripts/run-tests.mjs dist/test/<name>.test.js`; never bare `node --test`, and do not run the whole suite (AGENTS.md).
25
- - Ships with `tests/orchestrator-delegation-test-plan.md` (AGENTS.md QA plan rules).
26
-
27
- ## Review Focus
28
-
29
- 1. **Ignored dependency folders are missing in a worktree** (for example `node_modules`). A child that runs `npm test` must not fail confusingly. Designer's call: nothing is linked into the worktree, because a link would let a child mutate the user's dependencies. Instead, the child's task text carries a notice. Pinned in Task 3.
30
- 2. **The user edits the working folder while subagents run.** `accept_change` merges three ways against the folder as it is now. A conflict writes nothing. Pinned in Task 2.
31
- 3. **Deletes, renames, binary files and paths with spaces in a change** must land exactly. Pinned in Task 2.
32
- 4. **Cancel or wall-time while children are running.** Every worktree is removed, nothing partial lands, and changes already accepted stay. Pinned in Task 4.
33
- 5. **The workspace is not a Git repository, or has no commit yet.** The first writing spawn fails with a clear message, and no directory or worktree is created. Pinned in Task 2 (message) and Task 3 (no side effects).
34
-
35
- ---
36
-
37
- ## File Structure
38
-
39
- | File | Change | Responsibility |
40
- |---|---|---|
41
- | `src/graphs.ts` | modify | `isWritingRole`, `delegatesWriting`, `DELIVERED_OUTCOME`, `CommandScope`; ceilings, outcomes and validation |
42
- | `src/capabilities.ts` | modify | `capabilityTools` accepts `CommandScope` |
43
- | `src/delegation-changes.ts` | create | All Git work: snapshot, worktree, collect, land, remove |
44
- | `src/agent-execution.ts` | modify | Activation, writing spawns, change registry, `accept_change` / `discard_change`, `delivered` guard, cleanup |
45
- | `src/tools.ts`, `src/types.ts` | modify | `ToolContext.delegationRoots` trusted for reads |
46
- | `src/graph-ui/app.js` | modify | `delivered` port, help copy, worktree requirement |
47
- | `desktop/src/engine/rows.ts`, `desktop/src/engine/workflow.ts`, `desktop/src/components/WorkflowView.tsx` | modify | Change state on subagent entries |
48
- | `test/orchestrator-delegation-graph.test.ts` | create | Validation and outcomes |
49
- | `test/delegation-changes.test.ts` | create | Git module against real temp repos |
50
- | `test/orchestrator-delegation-runtime.test.ts` | create | Runtime against a real temp repo with stub adapters |
51
- | `test/orchestrator-role-ceiling.test.ts` | modify | Expectations that change for writing roles |
52
- | `tests/orchestrator-delegation-test-plan.md` | create | QA plan |
53
-
54
- ---
55
-
56
- ### Task 1: Graph model — delegating Orchestrator, ceilings, `delivered` port, child command scope
57
-
58
- **Files:**
59
- - Modify: `src/graphs.ts` (`canRunCommands` / `permitsBuiltInTool` ~233-249, `nodeOutcomes` ~257, subagent validation ~575-610, required-route check ~673, Orchestrator checks ~704-720)
60
- - Modify: `src/capabilities.ts:12` (`capabilityTools`)
61
- - Create: `test/orchestrator-delegation-graph.test.ts`
62
- - Modify: `test/orchestrator-role-ceiling.test.ts`
63
-
64
- **Interfaces:**
65
- - Produces (in `src/graphs.ts`):
66
- - `export const DELIVERED_OUTCOME = 'delivered'`
67
- - `export type CommandScope = boolean | 'delegated-worktree'` (`false` = primary agent, `true` = ordinary child, `'delegated-worktree'` = writing child of a delegating Orchestrator)
68
- - `export function isWritingRole(role: SubagentRole): boolean`: `role.capabilities?.filesystem === 'read-write' || role.capabilities?.git === 'write'`
69
- - `export function delegatesWriting(node: GraphNode): boolean`: `node.type === 'agent' && node.agentRole === 'orchestrator' && node.subagents?.enabled === true && node.maxSubagents !== 0 && (node.subagents.roles ?? []).some(isWritingRole)`
70
- - `permitsBuiltInTool(node, name, child: CommandScope = false)`. Command and QA tools are allowed when `child !== true` and the existing policy test holds.
71
- - `nodeOutcomes(node)` returns `[node.completion?.outcome ?? 'completed', DELIVERED_OUTCOME]` when `delegatesWriting(node)`
72
- - Produces (in `src/capabilities.ts`): `capabilityTools(node: GraphNode, tools: Tool[], child: CommandScope = false)`. The external-MCP exclusion applies to any truthy `child`.
73
-
74
- - [ ] **Step 1: Write the failing tests** in `test/orchestrator-delegation-graph.test.ts`. Build fixtures from `structuredClone(DEFAULT_HARNESS)` with `orchestrator.capabilities = { filesystem: 'read-write', shell: 'allowed', git: 'write', github: 'none', browser: 'disabled', deployment: 'none' }`, `subagents = { enabled: true, workspace: 'worktree', maxConcurrent: 2, maxTotal: 6, roles: [{ id: 'coder', name: 'Coder', instruction: 'Implement', capabilities: { ...thatPolicy } }] }`.
75
- - `delegating Orchestrator validates and exposes completed and delivered ports`: `validateGraph` does not throw, and `nodeOutcomes(orchestrator)` deep-equals `['completed', 'delivered']`.
76
- - `delivered needs no route`: the fixture has no `delivered` edge and validates.
77
- - `an edge may route delivered`: add `{ id: 'o-done', source: 'orchestrator', target: 'done', outcome: 'delivered' }`, and it validates.
78
- - `writing roles require separate worktrees`: `workspace: 'shared-write', maxConcurrent: 1` throws `/writing roles on an Orchestrator require separate worktrees/`.
79
- - `delegation requires single completion`: `completion = { mode: 'outcomes', outcomes: ['a', 'b'] }` throws `/delegation needs a single completion outcome/`.
80
- - `writing role is checked against the node ceiling, not intake`: role `{ ...policy }` passes. A role with `deployment: 'allowed'` throws `/capability exceeds parent/`.
81
- - `read-only roles on a delegating Orchestrator keep the intake ceiling`: a role `{ filesystem: 'read', shell: 'allowed', git: 'read', ... }` throws `/intake read-only ceiling/`.
82
- - `spawning off keeps today's behavior`: `subagents.enabled = false` with a writing role means `delegatesWriting` is false, `nodeOutcomes` is `['completed']`, and it validates as today.
83
- - `command tools only for delegated worktree children`: for `{ capabilities: policy }`, `permitsBuiltInTool(n, 'Bash', true) === false`, `permitsBuiltInTool(n, 'Bash', 'delegated-worktree') === true`, `permitsBuiltInTool(n, 'qa.test', 'delegated-worktree') === true`, and `permitsBuiltInTool({ capabilities: { ...policy, git: 'read' } }, 'Bash', 'delegated-worktree') === false`.
84
- - `frozen and default graphs are unchanged`: for `DEFAULT_HARNESS` and each `DEFAULT_HARNESS_REVISION_*` that has an Orchestrator, `delegatesWriting(orchestrator) === false`, `nodeOutcomes(orchestrator)` deep-equals `['completed']`, and `createOrchestratorNode()` deep-equals the JSON snapshot `test/fixtures/orchestrator-preset.json`. Write that snapshot in Step 1 from the unmodified `createOrchestratorNode()`, before touching `src/graphs.ts`.
85
- - `minimum tool calls ignore an unrouted delivered port`: `minimumGraphToolCalls(fixture)` equals `minimumGraphToolCalls` of the same graph with spawning disabled.
86
-
87
- - [ ] **Step 2: Update `test/orchestrator-role-ceiling.test.ts`.** In the first test, the `{ filesystem: 'read-write' }` and `{ git: 'write' }` cases now make the node delegating with `workspace: 'shared-write'`, so they assert `/writing roles on an Orchestrator require separate worktrees/`. The `shell`, `github` and `deployment` cases keep `/intake read-only ceiling/`.
88
-
89
- - [ ] **Step 3: Build and run, expect failures.** Run: `npm run build && node scripts/run-tests.mjs dist/test/orchestrator-delegation-graph.test.js dist/test/orchestrator-role-ceiling.test.js`. Expected: FAIL (`delegatesWriting` is not exported).
90
-
91
- - [ ] **Step 4: Implement** the Interfaces above.
92
- - Validation, inside the subagent block: when `delegatesWriting(node)`, validate writing roles against `effectiveCapabilities(node)` and other roles against `intakeCapabilities(node)`. Require `(s.workspace ?? 'shared-read-only') === 'worktree'` (message: `${label}: writing roles on an Orchestrator require separate worktrees; select Separate Git worktree`). Require `node.completion?.mode !== 'outcomes'` (message: `${label}: Orchestrator delegation needs a single completion outcome; remove declared outcomes or the writing roles`).
93
- - Validate writing-role `tools` with `permitsBuiltInTool({capabilities: child}, t, 'delegated-worktree')`.
94
- - Exclude `DELIVERED_OUTCOME` of a delegating node from the required-route check, and from `guaranteedGraphInvocations` alternatives when it has no route.
95
- - Update the "custom Orchestrator delegation … rejects explicit writer roles" runtime test only if it breaks. It should not, because its node is validated nowhere and has no graph.
96
-
97
- - [ ] **Step 5: Run tests and the neighbors.** Run: `npm run build && node scripts/run-tests.mjs dist/test/orchestrator-delegation-graph.test.js dist/test/orchestrator-role-ceiling.test.js dist/test/graphs.test.js dist/test/graph-policy-validation.test.js dist/test/orchestrator-schema.test.js dist/test/graph-quota.test.js`. Expected: PASS, apart from failures already listed in memory as baseline.
98
-
99
- - [ ] **Step 6: Commit** `feat(graphs): delegating Orchestrator ceilings and delivered outcome`.
100
-
101
- ---
102
-
103
- ### Task 2: Git change module
104
-
105
- **Files:**
106
- - Create: `src/delegation-changes.ts`
107
- - Create: `test/delegation-changes.test.ts`
108
-
109
- **Interfaces:**
110
- - Produces:
111
- - `export const DELEGATION_DIFF_LIMIT = 20_000` (characters of diff inlined into an observation)
112
- - `export async function assertDelegationGit(workspace: string, signal: AbortSignal): Promise<void>`. Throws `Delegated writing needs Git 2.40 or newer.`, `Delegated writing needs the workspace to be a Git repository.`, or `Delegated writing needs a Git repository with at least one commit.`
113
- - `export async function snapshotWorkspace(workspace: string, signal: AbortSignal): Promise<string>` returns a commit id. Its tree is the working folder's tracked plus untracked non-ignored files, and its parent is `HEAD`. It uses a temporary `GIT_INDEX_FILE` and `git add -A`, `git write-tree`, `git commit-tree`. It never touches the real index, refs or stash.
114
- - `export async function addChangeWorktree(workspace: string, commit: string, signal: AbortSignal): Promise<string>` returns the worktree path, created with `mkdtemp(join(tmpdir(), 'andorra-subagent-'))` + `/worktree` and `git worktree add --detach <path> <commit>`.
115
- - `export interface CollectedChange { tree: string; files: { path: string; status: 'A' | 'M' | 'D' | 'R' }[]; diff: string }`
116
- - `export async function collectChange(worktree: string, base: string, signal: AbortSignal): Promise<CollectedChange>`. Snapshots the worktree's final files with a temporary index (commits made inside the worktree don't matter). `diff` is `git diff --binary -M <base>^{tree} <tree>`. `files` comes from `--name-status -M`.
117
- - `export type LandResult = { landed: true; files: string[] } | { landed: false; conflicts: string[]; detail: string }`
118
- - `export async function landChange(workspace: string, base: string, tree: string, signal: AbortSignal): Promise<LandResult>`. `ours = snapshotWorkspace(workspace)^{tree}`, then `git merge-tree --write-tree --merge-base <base> <ours> <tree>`. On a clean merge, apply `git diff --binary <ours> <merged>` to the working tree with `git apply` (no `--index`). On a conflict, write nothing and return the conflicted paths.
119
- - `export async function removeChangeWorktree(workspace: string, worktree: string): Promise<void>`. Best effort and never throws: `git worktree remove --force`, then `rm -rf` of the `mkdtemp` parent, then `git worktree prune`.
120
-
121
- - [ ] **Step 1: Write the failing tests** in `test/delegation-changes.test.ts`. Each test creates a real temp repo with `mkdtemp`, `git init`, a committed `README.md` and `src/a.txt`, and `t.after` removal. Set `git config user.email/name` locally in the repo.
122
- - `snapshot includes uncommitted and untracked files and leaves index and refs alone`: modify `src/a.txt`, add untracked `new file.txt`, and add `ignored.log` with `.gitignore` containing `*.log`. After `snapshotWorkspace`, `git ls-tree -r --name-only <commit>` contains `new file.txt` and not `ignored.log`. `git status --porcelain`, `git rev-parse HEAD` and `git stash list` are byte-identical before and after.
123
- - `worktree starts from the snapshot`: `addChangeWorktree(ws, commit)` contains the modified `src/a.txt` content and `new file.txt`.
124
- - `collect reports adds, edits, deletes, renames and binary`: in the worktree, edit `src/a.txt`, delete `README.md`, rename `src/b.txt` (committed in setup) to `src/c.txt`, add `img.bin` with bytes `[0, 255, 1]`, then `git commit -am x` inside the worktree. `files` maps to statuses M, D, R (`src/c.txt`) and A, and `diff` contains `GIT binary patch`.
125
- - `land applies a clean change as uncommitted edits`: after `landChange`, the working folder has the worktree's file contents (byte-equal for `img.bin`), `git diff --cached --quiet` exits 0, and `HEAD` is unchanged.
126
- - `land merges with edits the user made meanwhile`: the user edits line 1 of `src/a.txt` in the workspace after spawn, and the child edits line 3. The result is `landed: true` and both edits are present.
127
- - `land conflict writes nothing`: the user and the child both edit line 2 differently. The result is `{ landed: false }` with `conflicts` containing `src/a.txt`, and the workspace bytes are identical to before the call.
128
- - `paths with spaces land`: the child adds `docs/my notes.md`, and it lands.
129
- - `remove cleans the worktree and the temp directory`: after `removeChangeWorktree`, the path does not exist and `git worktree list` no longer lists it. A second call does not throw.
130
- - `refuses non-repositories and unborn repositories`: an empty dir rejects with `/must be a Git repository|needs the workspace to be a Git repository/`. `git init` without a commit rejects with `/at least one commit/`.
131
-
132
- - [ ] **Step 2: Run, expect failure.** Run: `npm run build && node scripts/run-tests.mjs dist/test/delegation-changes.test.js`. Expected: FAIL (module not found).
133
-
134
- - [ ] **Step 3: Implement `src/delegation-changes.ts`** per the Interfaces. Run Git through `promisify(execFile)` with the hardened `-c` flags from the Global Constraints. Pass `GIT_INDEX_FILE` via `env: { ...process.env, GIT_INDEX_FILE }`, pointing at a file inside a `mkdtemp` directory that is removed in `finally`. For `assertDelegationGit`, parse `git --version` and compare major.minor ≥ 2.40.
135
-
136
- - [ ] **Step 4: Run tests.** Same command. Expected: PASS.
137
-
138
- - [ ] **Step 5: Commit** `feat: Git snapshot, worktree and three-way landing for delegated changes`.
139
-
140
- ---
141
-
142
- ### Task 3: Runtime — activation, writing spawns, review record, child shell
143
-
144
- **Files:**
145
- - Modify: `src/agent-execution.ts` (instructions ~54, tool filter ~298, `spawn_subagent` ~357-470, approvals ~440-462)
146
- - Modify: `src/types.ts:125` (add `delegationRoots?: readonly string[]` next to `attachmentRoots`), `src/tools.ts:40` (`trustedAttachment` also consults `delegationRoots`, which is cleared wherever `attachmentRoots` is cleared for mutations)
147
- - Create: `test/orchestrator-delegation-runtime.test.ts`
148
-
149
- **Interfaces:**
150
- - Consumes: Task 1 (`delegatesWriting`, `isWritingRole`, `DELIVERED_OUTCOME`, `CommandScope`, `capabilityTools`), Task 2 (all exports).
151
- - Produces (module-internal to `executeAgentNode`, used by Task 4):
152
- - `const delegationActive: boolean` = `orchestrator && delegatesWriting(node) && !!options.graph?.edges.some(e => e.source === node.id && e.outcome === DELIVERED_OUTCOME)`
153
- - `interface ChangeRecord { id: string; subagentId: string; role: string; worktree: string; base: string; tree?: string; files: CollectedChange['files']; state: 'pending' | 'landed' | 'discarded' | 'conflict'; diffArtifact?: ArtifactRef }`
154
- - `const changes = new Map<string, ChangeRecord>()`, scoped to the node visit, next to `active` / `total`
155
- - Event `subagent.change` with data `{ subagentId, changeId, state, files?: string[] }`
156
- - The writing spawn's observation JSON adds `change: { id, files, diff, truncated: boolean, diffArtifact }` and `tests: string[]` (from `result.completion?.tests ?? []`)
157
-
158
- - [ ] **Step 1: Write the failing tests** in `test/orchestrator-delegation-runtime.test.ts`. Reuse the harness style of `test/orchestrator-runtime.test.ts` (`tool()`, `plan()`, `read()`, `ask()`, `createTools()`), plus a real temp Git repo fixture from Task 2. The graph is `DEFAULT_HARNESS` with the Task 1 delegating Orchestrator and an edge `orchestrator → done` on `delivered`. Call `executeAgentNode(node, { ...opts, graph })` with `context.permissions = 'full-access'` unless stated.
159
- - `inactive without a delivered route`: same node, `graph` without the edge. Spawning `coder` returns an observation matching `/capabilities exceed its parent/` and no worktree is created (`git worktree list` has one entry).
160
- - `writing child gets a shell and works in its worktree`: the stub child adapter's first request has a tool whose `canonicalToolName` is `Bash` or `PowerShell`, and `Write`/`Edit` tools. Replace the shell tool with a stub that records `ctx.workspace`; the recorded workspace is not the repo root and starts with `join(tmpdir(), 'andorra-subagent-')`.
161
- - `child task notes missing ignored files`: the child's first user message contains `Files ignored by Git (for example node_modules) are not in this worktree`.
162
- - `review record reaches the Orchestrator`: the child writes `src/a.txt` and completes with `tests: ['npm test: 3 passed']`. The parent's next request has a tool observation whose JSON has `change.files` `[{ path: 'src/a.txt', status: 'M' }]`, `change.diff` containing the edit, `truncated: false`, and `tests` `['npm test: 3 passed']`. The repo's working folder is unchanged at that point.
163
- - `large diffs are truncated with an artifact`: the child writes 30,000 characters, so `change.diff.length <= 20_000`, `truncated === true`, and `diffArtifact.ref` is readable with `read_artifact` and contains the full diff.
164
- - `Orchestrator can read inside a child's worktree without prompts`: in `ask-for-approval` with `approve` counting calls, the parent calls `read_file` with the absolute worktree path of the changed file. It returns the new content with zero `approve` calls for that read.
165
- - `worktree approval is asked once per visit`: in `ask-for-approval` with `approve` returning `true`, two writing spawns produce exactly one `approve` call named `spawn_subagent.worktree`.
166
- - `failed child yields no change`: a child completing with a failure status means the observation has no `change`, and the worktree path no longer exists.
167
- - `not a repository fails before side effects`: the workspace is a plain temp dir. The spawn observation matches `/needs the workspace to be a Git repository/`, and `fs.readdir(tmpdir())` shows no new `andorra-subagent-*` entry created by this test (compare before and after).
168
- - `the Orchestrator still has no write or shell tools`: in every parent request, no tool's canonical name is `Write`, `Edit`, `Bash` or `PowerShell`.
169
- - `writing spawn waits for clarification`: a writing spawn after `update_todos` but before a successful `ask_user` returns an observation matching `/Ask the user to confirm the design before starting writing subagents/`, and no worktree is created. Read-only research spawns keep today's rule (plan only).
170
-
171
- - [ ] **Step 2: Run, expect failure.** Run: `npm run build && node scripts/run-tests.mjs dist/test/orchestrator-delegation-runtime.test.js`. Expected: FAIL.
172
-
173
- - [ ] **Step 3: Implement.**
174
- - Compute `delegationActive`. When it is false, change nothing.
175
- - In `spawn_subagent`, for a writing role when `delegationActive`:
176
- - Refuse with the clarification message from the test while `clarified` is false.
177
- - Take `parentCapabilities` from `effectiveCapabilities(node)` (the configured ceiling), not the intake-clamped `configured`.
178
- - Build `available` from `capabilityTools({ ...node, capabilities: parentCapabilities, tools: undefined }, options.tools, 'delegated-worktree')` minus `browser.panel`.
179
- - Default `childToolNames` for a writing role with no `tools` is all of `available`.
180
- - Run `assertDelegationGit` before any approval or mkdtemp.
181
- - Replace the clean-tree `git status` check and `HEAD` base with `snapshotWorkspace` + `addChangeWorktree`.
182
- - Hoist the worktree approval state (`audited`, `explicitlyApproved`) to the node-visit scope so one grant covers the visit, while keeping its live-mode recheck.
183
- - Pass a new `commandScope: CommandScope` argument through `run` → `runWithinDeadline` and into `capabilityTools`/`permitsBuiltInTool` (default `depth > 0`). Writing delegated children get `'delegated-worktree'`.
184
- - Append the ignored-files notice (exact text from the test, followed by: `Install what you need inside this worktree if a build or test requires it.`) to the child task.
185
- - After the child returns `succeeded`, call `collectChange`. When `files` is empty, remove the worktree and add no change. Otherwise register a `pending` `ChangeRecord`, put the full diff in the `ArtifactStore` as type `delegation-diff`, emit `subagent.change`, and add `worktree` to the parent context's `delegationRoots`.
186
- - When the child does not succeed, remove the worktree.
187
- - Append `DELEGATION_INSTRUCTIONS` to the Orchestrator's instructions only when `delegationActive`. It covers: the two paths (`completed` handoff or `delivered`); clarify first; spawn writing roles in parallel; review each `change` and `tests` report; `accept_change` / `discard_change`; spawn fixes with findings; complete `delivered` only when every change is decided; never write code.
188
-
189
- - [ ] **Step 4: Run tests** plus `dist/test/subagent-worktree-permissions.test.js` and `dist/test/orchestrator-runtime.test.js`. Expected: PASS, apart from known baseline failures.
190
-
191
- - [ ] **Step 5: Commit** `feat(runtime): writing subagents for a delegating Orchestrator`.
192
-
193
- ---
194
-
195
- ### Task 4: Landing tools, `delivered` completion, cleanup, end-to-end routing
196
-
197
- **Files:**
198
- - Modify: `src/agent-execution.ts` (tool registration next to `spawn_subagent`, `completionGuard` ~1074, `completionPolicy` ~1079, node `finish`/`finally`)
199
- - Modify: `test/orchestrator-delegation-runtime.test.ts`
200
-
201
- **Interfaces:**
202
- - Consumes: Task 3 `changes`, `ChangeRecord`, `delegationActive`. Task 2 `landChange`, `removeChangeWorktree`.
203
- - Produces:
204
- - Tool `accept_change` with `{ id: string }`, returning `{"state":"landed","files":[...]}` or `{"state":"conflict","conflicts":[...],"detail":"..."}`. Allowed from `pending` or `conflict`.
205
- - Tool `discard_change` with `{ id: string }`, returning `{"state":"discarded"}`. Allowed from `pending` or `conflict`.
206
- - Both refuse unknown ids (`Unknown change`) and finished changes (`Change already landed` / `Change already discarded`), and both are `executionMode: 'sequential'`.
207
- - Completion policy when `delegationActive`: `{ mode: 'outcomes', outcomes: [configured completion outcome ?? 'completed', 'delivered'] }`.
208
-
209
- - [ ] **Step 1: Write the failing tests** (append to the runtime test file):
210
- - `accept lands and discard removes`: two writing children. `accept_change(c1)` → the working folder has c1's edit, the state is `landed`, and the `subagent.change` event has `state: 'landed'`. `discard_change(c2)` → c2's worktree path is gone and the folder lacks c2's edit.
211
- - `accept conflict writes nothing and can be retried or discarded`: the user edit conflicts, so the result is `state: 'conflict'` and the folder bytes are unchanged. After the test reverts the user edit, `accept_change` again → `landed`.
212
- - `landing does not prompt where a workspace edit would not`: in `ask-for-approval` and `approve-for-me`, `accept_change` makes zero `approve` calls. In `read-only`, one `approve` call named `accept_change`, and the change lands only when it returns `true`.
213
- - `delivered requires every change decided`: completing `delivered` with a `pending` change gets a repair message matching `/Accept or discard every change before completing as delivered/`. With nothing landed, `/Land at least one accepted change before completing as delivered/`. After a decision, it succeeds.
214
- - `delivered uses the handoff schema`: `delivered` without `taskInstruction` gets the existing handoff repair message.
215
- - `delivered output references the delivery record`: `result.completion.artifacts` contains one ref of type `delegation-record` whose content lists each change's `role`, `files` and `state`.
216
- - `runGraph routes delivered`: graph `orchestrator →(completed) engineer`, `orchestrator →(delivered) done`. A delivered run finishes without the engineer adapter being called, and `result.nodeResults.orchestrator.outcome === 'delivered'`.
217
- - `cancel removes every worktree and keeps accepted changes`: accept c1, then abort `context` while c2's child adapter is awaiting. The run is `cancelled`, the folder has c1's edit and not c2's, and `git worktree list` shows only the main worktree.
218
- - `undecided changes are discarded at node end`: after a `completed` (handoff) completion with a `pending` change, its worktree is removed and a `subagent.change` `discarded` event fires.
219
- - `cannot pass content through landing tools`: `accept_change` with an extra `patch` argument is refused by schema validation (`additionalProperties: false`).
220
-
221
- - [ ] **Step 2: Run, expect failure.** Run: `npm run build && node scripts/run-tests.mjs dist/test/orchestrator-delegation-runtime.test.js`.
222
-
223
- - [ ] **Step 3: Implement.**
224
- - Register both tools only when `delegationActive`.
225
- - Landing approval: call `assertPlanMutationAllowed`. Skip approval when `permissionMode(ctx)` is `full-access`, `ask-for-approval` or `approve-for-me`. Otherwise call `approveOperation(ctx, 'accept_change', { id, files })`.
226
- - Extend `completionGuard`: when `completion.outcome === 'delivered'`, after the existing handoff checks, require `active === 0`, at least one `landed`, and no `pending`/`conflict` change, using the exact messages from the tests. Then `put` a `delegation-record` artifact and add its ref to the completion's artifacts.
227
- - In the node's `finally`, for each change not `landed`/`discarded`: run `removeChangeWorktree`, set `discarded`, and emit the event. Also remove worktrees of landed or discarded changes not yet removed.
228
-
229
- - [ ] **Step 4: Run tests** plus `dist/test/orchestrator-runtime.test.js`, `dist/test/orchestrator-outcome-routing.test.js` and `dist/test/graph-runner.test.js`. Expected: PASS, apart from known baseline failures.
230
-
231
- - [ ] **Step 5: Commit** `feat(runtime): land, discard and deliver delegated changes`.
232
-
233
- ---
234
-
235
- ### Task 5: Graph builder
236
-
237
- **Files:**
238
- - Modify: `src/graph-ui/app.js` (`outcomes` ~168, `renderSubagents` ~1126-1160)
239
- - Modify: `test/graph-ui.test.ts` (or a new `test/graph-ui-delegation.test.ts` using the same vm fixture as `test/graph-ui-orchestrator-reuse.test.ts`)
240
-
241
- **Interfaces:**
242
- - Produces in `app.js`: `function delegatesWriting(node)`, mirroring Task 1 exactly. `outcomes(node)` appends `'delivered'` when it is true.
243
-
244
- - [ ] **Step 1: Write the failing tests:**
245
- - `outcomes(node)` for the Task 1 fixture deep-equals `['completed', 'delivered']`, and for `DEFAULT_HARNESS.nodes.orchestrator` deep-equals `['completed']`.
246
- - With the delegating fixture rendered, the subagent help text contains `Writing roles of an Orchestrator run in their own Git worktree with a shell` and does not contain `Subagents never receive the unsandboxed host shell, including in worktrees`.
247
- - Adding a writing role to an Orchestrator whose workspace is `shared-read-only` sets `policy.workspace` to `worktree`.
248
-
249
- - [ ] **Step 2: Run, expect failure.** Run: `npm run build && node scripts/run-tests.mjs dist/test/graph-ui-delegation.test.js`.
250
-
251
- - [ ] **Step 3: Implement.** Help text for a delegating Orchestrator, exactly: `Writing roles of an Orchestrator run in their own Git worktree with a shell. The shell is not sandboxed and follows your permission mode. The Orchestrator reviews each change and lands the ones it accepts into your working folder; it never writes code itself.` Other nodes get today's copy with the "never receive the unsandboxed host shell" sentence changed to `Subagents of ordinary agents never receive the unsandboxed host shell.`
252
-
253
- - [ ] **Step 4: Run tests** plus `dist/test/graph-ui.test.js` and `dist/test/graph-ui-orchestrator-reuse.test.js`. Expected: PASS.
254
-
255
- - [ ] **Step 5: Commit** `feat(graph-ui): delivered port and delegation settings`.
256
-
257
- ---
258
-
259
- ### Task 6: Desktop change states
260
-
261
- **Files:**
262
- - Modify: `desktop/src/engine/rows.ts` (`SubagentItem` ~145, fold `case 'subagent.change'` next to ~2158)
263
- - Modify: `desktop/src/engine/workflow.ts` (`subagentStatusLabel` ~62)
264
- - Modify: `desktop/src/components/WorkflowView.tsx` (~183)
265
- - Test: `desktop/src/engine/rows.test.ts`, `desktop/src/engine/workflow.test.ts`
266
-
267
- **Interfaces:**
268
- - Produces: `SubagentItem.change?: 'pending' | 'landed' | 'discarded' | 'conflict'`. `export function subagentChangeLabel(item: SubagentItem): string | undefined` returns `Awaiting review`, `Landed`, `Discarded` or `Conflict`, or `undefined` when there is no change.
269
-
270
- - [ ] **Step 1: Write failing tests:**
271
- - `rows.test.ts`: folding `subagent.started` then `subagent.change { subagentId, state: 'pending' }` then `{ state: 'landed' }` leaves `state.subagents[0].change === 'landed'`. A `subagent.change` for an unknown id is ignored.
272
- - `workflow.test.ts`: `subagentChangeLabel` maps all four states, and `undefined` for an item without `change`.
273
-
274
- - [ ] **Step 2: Run, expect failure.** Run: `npm test --prefix desktop -- rows workflow`.
275
-
276
- - [ ] **Step 3: Implement.** The fold replaces the item immutably, like the existing cases. `WorkflowView` renders the label after the status in a `workflow-agent-change` span.
277
-
278
- - [ ] **Step 4: Run tests and typecheck.** Run: `npm test --prefix desktop -- rows workflow WorkflowView && npm run check --prefix desktop`. Expected: PASS.
279
-
280
- - [ ] **Step 5: Commit** `feat(desktop): show delegated change state on subagents`.
281
-
282
- ---
283
-
284
- ### Task 7: QA plan, run verification, pull request
285
-
286
- **Files:**
287
- - Create: `tests/orchestrator-delegation-test-plan.md`
288
-
289
- - [ ] **Step 1: Write the QA plan** to the AGENTS.md outline. Cover: scope and prerequisites (Premium account, Git ≥ 2.40, two providers), how to configure the graph in the builder, and cases for each spec goal, the five Review Focus items, each permission mode, Windows paths with spaces, and the no-`delivered`-route fallback. Include gaps and limitations, and validation evidence (only what was actually run).
290
-
291
- - [ ] **Step 2: Run verification with the built CLI.** `npm run build`. Then, in a throwaway home (`home=$(mktemp -d) || exit 1; export ANDORRACODE_HOME="$home"`, removed in the same invocation), drive `node dist/src/cli.js app-server --stdio` against a temp Git repo and a local stub provider (see memory "Verify desktop renderer headless"). Run a delegating graph through: clarify, two writing spawns, accept one, discard one, deliver. Observe: the folder has the accepted change only, `git worktree list` is clean, `git diff --cached` is empty, and the run ends on `delivered`. Record the commands and output for the PR.
292
-
293
- - [ ] **Step 3: Confirm nothing is left behind.** `git status --short` shows only intended changes, and no `andorra-subagent-*` directory from the run remains in `tmpdir()`.
294
-
295
- - [ ] **Step 4: Commit, push and open the PR** to `main` using `.github/PULL_REQUEST_TEMPLATE.md`. List the exact tests run and the verification above in Validation, linking the QA plan. Then follow the Codex review loop in AGENTS.md.
@@ -1,203 +0,0 @@
1
- # Graph Manager Chat Implementation Plan
2
-
3
- > **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
4
-
5
- **Goal:** A Graph Manager button, first-graph tip and side chat in Graph Studio that runs the `andorra:graph-manager` skill on a dedicated engine, with the open graph's canvas as context.
6
-
7
- **Architecture:** The graph server (`src/graph-server.ts`) lazily owns a `GraphManagerChat` (`src/graph-manager-chat.ts`) that spawns `andorra app-server --stdio` (pattern: `src/automation-runner.ts`) and relays one session over new `/api/manager/*` routes and a server-sent-events stream. Graph Studio (`src/graph-ui/`) gets a pure logic module (`manager-state.js`, testable in `node:vm`) and a DOM module (`manager.js` + `manager.css`). The run uses a hidden built-in single-agent graph so the agent holds the `graphs` tool and no Orchestrator intake runs.
8
-
9
- **Tech Stack:** TypeScript (Node, ESM), plain browser JS without a bundler, `node:test`.
10
-
11
- **Spec:** `docs/superpowers/specs/2026-11-13-graph-manager-chat-design.md`
12
-
13
- ## Global Constraints
14
-
15
- - Works identically in the desktop iframe and a browser tab; no desktop (`desktop/`) code changes.
16
- - Run permissions are fixed: `runPermissions: "ask-for-approval"`.
17
- - Chat workspace: `<config directory>/graph-manager/workspace`, created on first use.
18
- - Session name: `Graph Manager: <graph name>`, pinned (create with `sessions.create { name }`, which the engine records; then keep it with `sessions.rename` so `renamed: true` blocks automatic titling).
19
- - Idle engine stop: 10 minutes (`600_000` ms) with no stream client, and only while no run is working and nothing is pending.
20
- - Tip storage key: `andorra.graphManager.tipDismissed` (`localStorage`); last model key: `andorra.graphManager.model`.
21
- - Tip copy: "Let Graph Manager build this graph with you."
22
- - Load bar copy: "Graph Manager saved revision N. Load it?"
23
- - Graph-switch copy: "Start a new chat about <name>?"
24
- - All `/api/manager/*` routes sit behind the existing bearer-token and session checks; the stream also accepts `?token=` like `/api/activity/stream`.
25
- - Bind only ephemeral ports in tests (`listen(0)`); every spawned child and timer is stopped by `close()`.
26
- - Repository rules (AGENTS.md): QA plan at `tests/graph-manager-chat-test-plan.md`; do not run whole suites; run the targeted test files below via `node scripts/run-tests.mjs dist/test/<file>.test.js` after `npm run build`.
27
-
28
- ## Review Focus
29
-
30
- 1. **Engine exits mid-chat (crash, killed, update):** the panel shows an error state and the next message starts a fresh engine and session instead of hanging. → Task 2 test `restarts the engine after it exits`.
31
- 2. **The graph server closes while a run or approval is pending:** the child is cancelled and killed; no orphan process. → Task 3 test `close stops the chat engine`.
32
- 3. **The user keeps editing while the agent works:** the agent's revision never replaces those edits without the Load click. → Task 4 test `offers instead of loading when the canvas changed`.
33
- 4. **A canvas larger than the request body limit:** refused with a readable message, never truncated. → Task 3 test `refuses an oversized canvas`.
34
- 5. **Two panels (desktop + browser) on one server:** both receive the same events; the second connection gets a `snapshot` first. → Task 3 test `a second stream client receives the snapshot`.
35
-
36
- ---
37
-
38
- ### Task 1: Hidden built-in Graph Manager graph
39
-
40
- **Files:**
41
- - Modify: `src/graphs.ts` (next to `DEFAULT_HARNESS`, `loadGraph` at ~876, `listGraphs` ~891, `saveGraph` ~903, `deleteGraph`)
42
- - Test: `test/graph-manager-harness.test.ts`
43
-
44
- **Interfaces:**
45
- - Produces: `export const GRAPH_MANAGER_GRAPH_ID = 'andorra-graph-manager'`; `export const GRAPH_MANAGER_HARNESS: Graph` (schemaVersion 3, one agent node `manager` named "Graph Manager", `executor: 'react-basic'`, edge `completed` → end node `done`); `loadGraph(GRAPH_MANAGER_GRAPH_ID)` returns a clone of it.
46
- - The `manager` node's `instruction`: "You are Graph Manager inside Graph Studio. Before acting, load the bundled skill andorra:graph-manager with read_skill_resource and follow it. Work only through the graphs tool; never write graph files. Reply to the user in the conversation and ask with ask_user when a choice is theirs." Its tool and permission fields copy the default harness's engineer node so `graphs`, `read_skill_resource` and `ask_user` are available.
47
-
48
- - [ ] **Step 1: Write the failing tests** — `loads the hidden graph manager graph` (`loadGraph(GRAPH_MANAGER_GRAPH_ID, undefined, tmp)` has `entry === 'manager'` and `nodes.manager.type === 'agent'`); `does not list it` (`listGraphs(tmp)` ids exclude it, both with and without a `graphs/` folder); `refuses to save or delete over it` (`saveGraph({...GRAPH_MANAGER_HARNESS}, null, tmp)` and `deleteGraph(GRAPH_MANAGER_GRAPH_ID, …)` reject with a message containing "reserved").
49
- - [ ] **Step 2:** `npm run build && node scripts/run-tests.mjs dist/test/graph-manager-harness.test.js` → FAIL (export missing).
50
- - [ ] **Step 3: Implement** the constant, the `loadGraph` branch (before the filesystem read, like `'default'`), the `listGraphs` filter, and the reserved-id refusals.
51
- - [ ] **Step 4:** Re-run → PASS. Also run `dist/test/graph-tool.test.js` and `dist/test/graph-selection.test.js` → same results as on `main`.
52
- - [ ] **Step 5: Commit** `feat(graphs): hidden built-in Graph Manager graph`.
53
-
54
- ### Task 2: Engine-backed chat (`GraphManagerChat`)
55
-
56
- **Files:**
57
- - Create: `src/graph-manager-chat.ts`
58
- - Test: `test/graph-manager-chat.test.ts`
59
-
60
- **Interfaces:**
61
- - Consumes: `GRAPH_MANAGER_GRAPH_ID` (Task 1); `describeTool(name, args)` from `src/transcript.ts`; `stopAutomationWorker(child, closed)` from `src/automation-worker-shutdown.js` for shutdown.
62
- - Produces:
63
- ```ts
64
- export interface ManagerGraphContext { graph: Record<string, unknown>; saved: boolean; revision?: number }
65
- export interface ManagerTurn extends ManagerGraphContext { provider: string; model: string; text: string }
66
- export type ManagerEvent =
67
- | { type: 'snapshot'; events: ManagerEvent[]; state: ManagerState }
68
- | { type: 'user'; text: string }
69
- | { type: 'assistant'; text: string }
70
- | { type: 'tool'; text: string; failed?: boolean }
71
- | { type: 'approval'; id: string; text: string }
72
- | { type: 'question'; id: string; question: string; choices?: string[] }
73
- | { type: 'resolved'; id: string }
74
- | { type: 'state'; state: ManagerState }
75
- | { type: 'error'; message: string }
76
- | { type: 'graph.saved'; graphId: string; revision: number };
77
- export type ManagerState = 'idle' | 'starting' | 'working' | 'awaiting';
78
- export interface EngineChild { stdin: Writable; stdout: Readable; stderr: Readable; once(event: 'close', fn: (code: number | null) => void): unknown; on(event: 'error', fn: (e: Error) => void): unknown; kill(): boolean }
79
- export interface GraphManagerChatOptions {
80
- directory: string; // config directory (ANDORRACODE_HOME)
81
- spawnEngine?: (cwd: string) => EngineChild; // default: spawn(process.execPath, [cli, 'app-server', '--stdio'], { cwd, env: { ...process.env, ANDORRACODE_HOME: directory }, windowsHide: true })
82
- readRevision: (graphId: string) => Promise<number | undefined>;
83
- idleMs?: number; // default 600_000
84
- }
85
- export function managerTask(turn: ManagerTurn): string;
86
- export class GraphManagerChat {
87
- constructor(options: GraphManagerChatOptions);
88
- subscribe(listener: (event: ManagerEvent) => void): () => void; // first call delivers a snapshot
89
- send(turn: ManagerTurn): Promise<void>; // start, continue, or steer
90
- approve(id: string, approved: boolean): Promise<void>;
91
- answer(id: string, value: string): Promise<void>;
92
- cancel(): Promise<void>;
93
- reset(): Promise<void>; // forget sessionId and transcript; engine stays
94
- close(): Promise<void>; // cancel run, stop child, clear timers
95
- }
96
- ```
97
- - `managerTask` text, exactly:
98
- ```
99
- You are helping in Graph Studio. Open graph: "<name>", id <id> (saved revision <N> | not saved yet).
100
- The canvas below is what the user sees now, including edits not yet saved. Work from it, and save your changes under this same graph id (mode "create" when it is not saved yet, "edit" otherwise).
101
- Selected model: <provider>/<model>. Use it for new agent nodes unless the user asks otherwise.
102
-
103
- Canvas:
104
- ```json
105
- <JSON.stringify(graph, null, 2)>
106
- ```
107
-
108
- User message:
109
- <text>
110
- ```
111
- - Protocol (same framing as `automation-runner.ts`: one JSON object per line, `{ id, method, params }` out; `{ id, result | error }` and `{ event, data }` in). On `ready`: require capability `run.start.runPermissions`, else emit `error` "Update Andorra to use Graph Manager." First `send`: `sessions.create { workspace, name }` then `sessions.rename { id, name }`, then `run.start { workspace, sessionId, task, provider, model, graph: GRAPH_MANAGER_GRAPH_ID, runPermissions: 'ask-for-approval' }`. Later `send` while idle: `run.start` with the same `sessionId` and `continueSession: true`; while working: `run.steer { sessionId, text: managerTask(turn) }`.
112
- - Event mapping: `run.event` with `agent.message` → `assistant`; `node.tool.started` → `tool` (`describeTool`); `node.tool.failed` → `tool` with `failed: true`; `node.tool.completed` with `name === 'graphs'` → `readRevision(current graph id)` and emit `graph.saved` when it is higher than the last known revision; `run.approval` → `approval` (`describeTool(name, arguments)`); `run.question` → `question`; `run.state` `awaiting-*` → `awaiting`; `run.completed`/`run.failed` → `state idle` (+ `error` with the failure message).
113
- - The transcript kept for snapshots holds every non-snapshot event, cleared by `reset()`.
114
-
115
- - [ ] **Step 1: Write the failing tests** with a fake `EngineChild` (two `PassThrough` streams; the test reads lines the chat writes and writes engine lines back):
116
- - `managerTask includes name, id, revision state, model, canvas and message` (saved and unsaved variants).
117
- - `first send creates a named session and starts the hidden graph` — asserts methods in order `sessions.create`, `sessions.rename`, `run.start` and the `run.start` params above.
118
- - `a send while working steers; a send while idle continues the session`.
119
- - `maps engine events to panel events` — feeds `agent.message`, `node.tool.started`, `run.approval`, `run.question`, `run.completed`; asserts the emitted `ManagerEvent`s.
120
- - `emits graph.saved only when the revision rises` (`readRevision` stub returns 1, then 2).
121
- - `restarts the engine after it exits` — fake child closes; the next `send` spawns a second child and creates a new session; the panel got `error` and `state idle`.
122
- - `stops the idle engine only when nothing is pending` — `idleMs: 20`; with a pending approval the child is not killed; after `run.completed` and no subscribers it is.
123
- - `close cancels and stops the child`.
124
- - [ ] **Step 2:** Build, run `dist/test/graph-manager-chat.test.js` → FAIL.
125
- - [ ] **Step 3: Implement** `src/graph-manager-chat.ts` to the interface above. The workspace folder is created with `mkdir(join(directory, 'graph-manager', 'workspace'), { recursive: true })` before the first spawn.
126
- - [ ] **Step 4:** Re-run → PASS.
127
- - [ ] **Step 5: Commit** `feat(graph-manager): engine-backed chat session`.
128
-
129
- ### Task 3: Graph server routes
130
-
131
- **Files:**
132
- - Modify: `src/graph-server.ts` (`startGraphServer` options, `/api/` router, stream token check ~line 150, `close()` ~line 375, asset map)
133
- - Test: `test/graph-manager-routes.test.ts` (setup copied from `test/graph-server.test.ts`: temp home, `startGraphServer(dir, async () => {}, { … })`, `t.after` close)
134
-
135
- **Interfaces:**
136
- - Consumes: `GraphManagerChat`, `ManagerTurn`, `ManagerEvent` (Task 2).
137
- - Produces: `startGraphServer(..., options: { …existing, managerChat?: (directory: string) => Pick<GraphManagerChat, 'subscribe'|'send'|'approve'|'answer'|'cancel'|'reset'|'close'> })`; default factory builds `GraphManagerChat` with `readRevision: id => loadGraph(id, undefined, graphDirectory).then(g => g.revision, () => undefined)`. Created lazily on the first `/api/manager/*` request.
138
- - Routes (JSON bodies; replies `{ ok: true }` unless noted):
139
- - `POST /api/manager/message` `{ provider, model, text, graph, saved, revision? }` → `send`. Validation: non-empty strings for provider, model, text; `graph` an object with string `id` and `name`. 400 on failure.
140
- - `POST /api/manager/approve` `{ id, approved }`, `POST /api/manager/answer` `{ id, value }`, `POST /api/manager/cancel`, `POST /api/manager/reset`.
141
- - `GET /api/manager/stream` → `text/event-stream`; each `ManagerEvent` as `data: <json>\n\n`; `: ping` every 15 s; unsubscribes on close.
142
- - Requests to the manager routes count as their own body-size budget: reuse the server's existing body reader and limit; a body over it gets 413 `{ error: 'This graph is too large to send to Graph Manager.' }`.
143
-
144
- - [ ] **Step 1: Write the failing tests** using a fake `managerChat` that records calls and lets the test push events:
145
- - `forwards a message with the canvas`; `rejects a message without a graph` (400).
146
- - `stream requires the token` (401 without, 200 with `?token=`).
147
- - `a second stream client receives the snapshot` (fake `subscribe` delivers a snapshot first; both clients then get a pushed event).
148
- - `refuses an oversized canvas` (413 and the copy above).
149
- - `close stops the chat engine` (fake `close` called once by server `close()`).
150
- - `serves manager.js, manager-state.js and manager.css`.
151
- - [ ] **Step 2:** Build, run `dist/test/graph-manager-routes.test.js` → FAIL.
152
- - [ ] **Step 3: Implement** the option, routes, stream, `close()` hook and the three asset entries.
153
- - [ ] **Step 4:** Re-run → PASS; also run `dist/test/graph-server.test.js` and `dist/test/graph-studio-editor-api.test.js` → same as `main`.
154
- - [ ] **Step 5: Commit** `feat(graph-server): Graph Manager chat routes`.
155
-
156
- ### Task 4: Editor logic (`manager-state.js`)
157
-
158
- **Files:**
159
- - Create: `src/graph-ui/manager-state.js` (assigns `globalThis.AndorraManagerState`; no DOM access)
160
- - Test: `test/graph-ui-manager-state.test.ts` (loads the file with `node:vm` like `test/graph-ui-sidebar.test.ts`)
161
-
162
- **Interfaces:**
163
- - Produces on `globalThis.AndorraManagerState`:
164
- - `shouldShowTip(storage, reason) → boolean` — `reason` is `'new' | 'duplicate' | 'import' | 'open'`; true only for `'new'` when the storage key is unset; storage read errors count as unset.
165
- - `dismissTip(storage) → void` (swallows storage errors).
166
- - `initialModel(storage, graph, providers) → { provider, model } | undefined` — saved choice if that provider/model is still listed, else the graph's first agent node's `provider`/`model`, else the first provider's default model.
167
- - `applyDecision({ sentCanvas, currentCanvas, untouched }) → 'load' | 'offer'` — `'load'` when `currentCanvas === sentCanvas` or `currentCanvas === untouched` (all JSON strings), else `'offer'`.
168
- - `reduce(transcript, event) → transcript` — appends events; `snapshot` replaces; `resolved` marks the matching approval/question answered.
169
-
170
- - [ ] **Step 1: Write the failing tests** — `shows the tip only after New graph, once`; `tip survives blocked storage`; `initial model prefers the saved choice, then the graph, then the provider default`; `loads when the canvas is unchanged or untouched`; `offers instead of loading when the canvas changed`; `snapshot replaces the transcript and resolved closes a card`.
171
- - [ ] **Step 2:** Build, run `dist/test/graph-ui-manager-state.test.js` → FAIL.
172
- - [ ] **Step 3: Implement** `manager-state.js`.
173
- - [ ] **Step 4:** Re-run → PASS.
174
- - [ ] **Step 5: Commit** `feat(graph-ui): Graph Manager panel logic`.
175
-
176
- ### Task 5: Editor UI (button, tip, panel)
177
-
178
- **Files:**
179
- - Create: `src/graph-ui/manager.js`, `src/graph-ui/manager.css`
180
- - Modify: `src/graph-ui/index.html` (button in `#chrome-actions` before `#save`; `<aside id="manager-panel" hidden>` after `#inspector` inside `.workspace`; stylesheet and `defer` scripts `manager-state.js` then `manager.js` after `app.js`), `src/graph-ui/app.js` (`newGraph` and `openGraph` call `globalThis.AndorraManager?.graphOpened(reason)`; expose `globalThis.AndorraStudio = { currentGraph: () => state.graph, isSaved, revision, untouched: () => state.untouched, reopen: id => openGraph(id) }` if no equivalent exists), `scripts/ci-local-groups.mjs` (add the four new test files to the groups that list graph-ui and graph-server tests)
181
- - Test: `test/graph-ui-manager.test.ts` (static checks on `index.html` and `manager.js` like `test/graph-studio-editor-api.test.ts`)
182
-
183
- **Interfaces:**
184
- - Consumes: Task 3 routes; Task 4 functions; `api(path, body)`, `status(message, error)` from `app.js`; `ProviderModelPicker`-equivalent data from `/api/provider-models` already loaded into `state.providers`.
185
- - Behaviour: button `#graph-manager` (label "Graph Manager", hidden when `state.graph` is null); tip popover anchored to it with a close button (`aria-label="Dismiss"`); panel header with provider and model `<select>`s and New chat; transcript (assistant text through the existing Markdown-safe renderer, tool lines, approval cards with Approve/Deny, question cards with choices or a text box); footer textarea with Send (Enter) and Stop. Opening the panel or closing the tip calls `dismissTip`. One `EventSource('/api/manager/stream?token=…')` while the panel is open, reconnecting with the snapshot. Each send posts the current canvas (`JSON.stringify(state.graph)`) and stores it as `sentCanvas`. On `graph.saved` for the open graph id, `applyDecision` → `reopen(id)` or the Load bar. Switching graphs with a non-empty transcript shows the graph-switch prompt; agreeing calls `/api/manager/reset`. Styling uses `studio.css` tokens; the panel narrows the canvas (it is a flex sibling, like `#inspector`).
186
-
187
- - [ ] **Step 1: Write the failing tests** — `index.html has the Graph Manager button and panel and loads both scripts in order`; `manager.js posts the canvas with each message`; `manager.js never assigns innerHTML from engine text` (assert the file has no `innerHTML =` on transcript paths, using the same check style other graph-ui tests use).
188
- - [ ] **Step 2:** Build, run `dist/test/graph-ui-manager.test.js` → FAIL.
189
- - [ ] **Step 3: Implement** the files and hooks above.
190
- - [ ] **Step 4:** Re-run → PASS; also run `dist/test/graph-ui.test.js`, `dist/test/graph-ui-modern.test.js` and `node --test scripts/ci-local.test.mjs` → same as `main`.
191
- - [ ] **Step 5: Commit** `feat(graph-ui): Graph Manager button, tip and chat panel`.
192
-
193
- ### Task 6: Run verification, QA plan, docs, PR
194
-
195
- **Files:**
196
- - Create: `tests/graph-manager-chat-test-plan.md`
197
- - Modify: `docs/guides/graph-builder.md` (a "Graph Manager" section: button, tip, what the agent sees, approvals)
198
-
199
- - [ ] **Step 1: Run it in a browser.** `npm run build`, then `node dist/src/cli.js graph` (real signed-in home, per the user's live-testing practice) and open the printed URL in the built-in browser. Check: New graph shows the tip once; Graph Manager opens the panel; choose a cheap model; ask "Add a review step after the agent that loops back on fail"; approve the publish card; the canvas loads the new revision. Edit the canvas during a second request and confirm the Load bar appears instead.
200
- - [ ] **Step 2: Run it in the desktop path** by starting the graph server through `node dist/src/cli.js app-server --stdio` (the engine's editor command) and opening its URL in the built-in browser, or the dev desktop if available; confirm the same panel loads inside the iframe CSP.
201
- - [ ] **Step 3: Leave no state.** Close the editor; `tasklist`/`ps` shows no leftover `app-server --stdio` child from the graph server; `git status --short` shows only intended changes.
202
- - [ ] **Step 4: Write the QA plan** covering the cases above, the Review Focus items, and gaps (desktop iframe verified only as described in Step 2).
203
- - [ ] **Step 5: Commit, push (`GH_TOKEN=$(gh auth token -u mchang-andorra)`), open a ready PR to `main`** with `.github/PULL_REQUEST_TEMPLATE.md`, Validation listing exactly what ran.
@@ -1,79 +0,0 @@
1
- # Jev fair-use pricing Implementation Plan
2
-
3
- > **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
4
-
5
- **Goal:** Free = 100 Jev calls per rolling 30 days; Legacy/Paid = unlimited under fair use (250/UTC day, 2,500/rolling 30 days); surfaces show it, plus an odometer and a tokens-saved estimate on the website.
6
-
7
- **Architecture:** The proxy keeps daily counters 32 days and sums the last 30 with one `BatchGetItem` before the existing reservation transaction. `/v1/me` adds window fields; clients render them and fall back to today's daily display when absent.
8
-
9
- **Tech Stack:** Python Lambda + DynamoDB (infra/andorra-auth), TypeScript CLI/app-server (src), React desktop (desktop/src), React website (Andorra-Code-Website).
10
-
11
- **Spec:** `docs/superpowers/specs/2026-11-14-jev-fair-use-pricing-design.md`
12
-
13
- ## Global Constraints
14
-
15
- - Template defaults: `FREE_WINDOW_LIMIT=100`, `PAID_DAILY_LIMIT=250`, `PAID_WINDOW_LIMIT=2500`, `GLOBAL_DAILY_LIMIT=10000`; `FREE_DAILY_LIMIT` removed.
16
- - Window = the 30 UTC days ending today (today + 29 before). Daily keys TTL = day + 32 days.
17
- - 429 keeps `error: "daily_limit_reached"`; `limitScope` ∈ `user | window | global`.
18
- - `/v1/me` keeps `dailyDecisionLimit` (paid/legacy 250; free = window limit 100).
19
- - `TOKENS_SAVED_PER_JEV_CALL` = (258,941,871 − 158,606,273) / 323, rounded = 310,637.
20
- - No fabricated figures: unreported values render "—"/"Unavailable".
21
- - Don't touch promotion config; don't deploy.
22
-
23
- ## Review Focus
24
-
25
- - Window read fails or returns `UnprocessedKeys` → reservation fails closed (503), `/v1/me` omits only the window fields.
26
- - Old server (no window fields) → every client renders exactly today's daily view.
27
- - Free account at exactly 100 in the window → 429 `window` with the return date; 99 → allowed.
28
- - Window with usage only today → `windowDecisionResetsAt` = today + 30 days 00:00Z.
29
- - Premium at 80% of either cap → meter shows the closer cap; below → no meter.
30
-
31
- ---
32
-
33
- ### Task 1: Proxy rolling window + template
34
-
35
- **Files:** Modify `infra/andorra-auth/proxy.py` (`membership`, `reserve_quota`, `quota_usage`, handler 429 + `/v1/me`), `infra/andorra-auth/template.json` (env + `dynamodb:BatchGetItem` on the proxy role), `infra/andorra-auth/README.md` (limits paragraph). Test: `infra/andorra-auth/test_proxy.py`.
36
-
37
- **Produces:** `membership()` → `{'paid','tier','dailyDecisionLimit','windowDecisionLimit','fairUse'}`; `window_usage(client, sub, day) -> (used:int, resets_at:datetime|None)`; `/v1/me` adds `fairUse`, `windowDays`, `windowDecisionLimit`, `windowDecisionUsed`, `windowDecisionResetsAt?`; 429 adds `windowDecisionLimit`.
38
-
39
- - [ ] Tests (update fakes: `batch_get_item.return_value = {'Responses': {'quota': []}}`; env without `FREE_DAILY_LIMIT`):
40
- - `test_window_cap_refuses_at_limit_without_spending` (free, window sum 100 → 429 `limitScope:'window'`, `resetsAt` = oldest used day + 30, no transact; sum 99 → 200).
41
- - `test_paid_window_and_daily_caps` (paid: daily condition `:limit` 250, window sum 2500 → 429 window).
42
- - `test_window_read_failure_fails_closed` (batch raises / leaves `UnprocessedKeys` → 503, upstream not called).
43
- - `test_me_reports_window_and_fair_use` (free and paid bodies; window outage omits only window fields).
44
- - `test_daily_keys_live_32_days`; update `test_default_allowances…` to the new defaults.
45
- - [ ] Implement; run `python -m unittest test_proxy -v` in `infra/andorra-auth` → all pass (2 known baseline failures in memory are in `test_proxy` infra cases — compare against main).
46
- - [ ] Commit.
47
-
48
- ### Task 2: CLI / app-server plumbing and wording
49
-
50
- **Files:** `src/membership.ts`, `src/account-presentation.ts`, `src/app-server.ts`, `src/app-server/protocol.ts`, `src/decision/providers/AndorraDecisionProvider.ts`, `src/decision/FactServiceGate.ts`, `src/decision/DecisionManager.ts` (safe reasons), `src/transcript.ts`. Tests: `test/membership.test.ts`, `test/account-presentation.test.ts`, `test/andorra-decision-provider.test.ts`.
51
-
52
- **Produces:** `Membership`/`AppServerAccount` gain `fairUse?: boolean; windowDays?: number; windowDecisionLimit?: number; windowDecisionUsed?: number; windowDecisionResetsAt?: string`. Reason `decision_window_limit_reached` (label "30-day Jev limit reached").
53
-
54
- - [ ] Tests: membership parses/drops invalid window fields; presentation → premium `Jev 12 today · fair use`, free `Jev 37/100 · 30d`, old server unchanged `Jev 3/1,000 UTC`; provider maps 429 `limitScope:'window'` to the new reason.
55
- - [ ] Implement; run those three files via `node scripts/run-tests.mjs` (targeted) → pass. Commit.
56
-
57
- ### Task 3: Desktop Settings / Portal
58
-
59
- **Files:** `desktop/src/engine/protocol.ts`, `desktop/src/engine/settingsDisplay.ts` (+test), `desktop/src/components/SettingsView.tsx`, `desktop/src/components/PortalView.tsx` (+tests), `SettingsPolish.test.ts`.
60
-
61
- **Produces:** `jevUsage(account) -> { kind: 'fair-use'; today?: number; meter?: DecisionUsage; note: string } | { kind: 'window'; meter: DecisionUsage; returnsAt?: string } | { kind: 'daily'; meter: DecisionUsage } | undefined`.
62
-
63
- - [ ] Tests in `settingsDisplay.test.ts`: fair-use below 80% → no meter, note "Unlimited · fair use"; 212/250 today → meter `212 / 250 today`; 2,100/2,500 window with 30 today → meter `2,100 / 2,500 · 30 days`; free → `37 / 100 · 30 days`; no window fields → existing daily behaviour.
64
- - [ ] Wire Quota + UsageRows; rename "Since rollout" → "All-time Jev calls". Run `npx vitest run` on touched files in `desktop/` → pass. Commit.
65
-
66
- ### Task 4: Website (separate repo/worktree `Andorra-Code-Website-jev-fair-use`, branch `feat/jev-fair-use`)
67
-
68
- **Files:** `src/auth.ts` (+test), `src/performance.ts` (+test), `src/AccountCenter.tsx` (+test), `src/styles.css`.
69
-
70
- **Produces:** `JEV_QUESTIONS = { tb: 112, swe: 211 }`, `TOKENS_SAVED_PER_JEV_CALL` (derived, = 310,637), `estimatedTokensSaved(calls)`; `Odometer({ value })`.
71
-
72
- - [ ] Tests: derivation pinned to 310,637; plan copy per tier; free usage pane (30-day figures, "More return …"); premium (today, 30 days, caps listed, no bar below 80%); odometer renders digits + accessible label; tokens-saved tile = calls × constant, links `/performance`; old server → current daily pane.
73
- - [ ] Implement; `npx vitest run` + `npm run build` → pass. Commit.
74
-
75
- ### Task 5: QA plan, verification, PRs
76
-
77
- - [ ] `tests/jev-fair-use-pricing-test-plan.md` (this repo).
78
- - [ ] Run verification: proxy unit tests; `npm run build` + CLI against a stub `/v1/me` (node preload) showing footer text; desktop renderer headless with stub account; website dev server via the built-in browser on the account page with a mocked membership.
79
- - [ ] Push both branches, open ready PRs, Codex loop.