@andorra-labs/code 0.1.8 → 0.1.10
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.
- package/THIRD_PARTY_NOTICES.md +2 -1
- package/dist/src/account-presentation.d.ts +11 -0
- package/dist/src/account-presentation.js +29 -2
- package/dist/src/agent-execution.js +57 -4
- package/dist/src/agent-mcp.d.ts +12 -0
- package/dist/src/agent-mcp.js +81 -2
- package/dist/src/app-server/protocol.d.ts +120 -1
- package/dist/src/app-server/protocol.js +8 -1
- package/dist/src/app-server/reasoning.d.ts +0 -8
- package/dist/src/app-server/reasoning.js +15 -28
- package/dist/src/app-server.d.ts +32 -0
- package/dist/src/app-server.js +214 -21
- package/dist/src/auth/AuthManager.d.ts +15 -0
- package/dist/src/auth/AuthManager.js +66 -7
- package/dist/src/auth/index.d.ts +1 -1
- package/dist/src/auth/index.js +1 -1
- package/dist/src/auth/store.d.ts +17 -1
- package/dist/src/auth/store.js +25 -2
- package/dist/src/browser-runner.js +1 -2
- package/dist/src/browser-server.js +10 -2
- package/dist/src/browser-session.js +6 -2
- package/dist/src/browser-stealth.d.ts +29 -0
- package/dist/src/browser-stealth.js +166 -0
- package/dist/src/browser-ui/app.js +123 -28
- package/dist/src/browser-ui/icons/chevron-right.svg +8 -0
- package/dist/src/browser-ui/index.html +8 -8
- package/dist/src/browser-ui/style.css +199 -171
- package/dist/src/browser-ui/tokens.css +198 -0
- package/dist/src/browser-view.d.ts +57 -9
- package/dist/src/browser-view.js +187 -36
- package/dist/src/cli.js +31 -9
- package/dist/src/coding-tools.js +9 -5
- package/dist/src/command-screens.js +4 -4
- package/dist/src/commands.d.ts +1 -1
- package/dist/src/commands.js +3 -2
- package/dist/src/completion-gates.d.ts +35 -0
- package/dist/src/completion-gates.js +25 -0
- package/dist/src/completion.d.ts +7 -1
- package/dist/src/completion.js +37 -4
- package/dist/src/config.d.ts +1 -1
- package/dist/src/config.js +2 -2
- package/dist/src/context-budget.d.ts +11 -0
- package/dist/src/context-budget.js +13 -0
- package/dist/src/decision/DecisionEngine.d.ts +5 -1
- package/dist/src/decision/DecisionManager.d.ts +1 -0
- package/dist/src/decision/DecisionManager.js +14 -3
- package/dist/src/decision/FactContinuations.d.ts +6 -0
- package/dist/src/decision/FactContinuations.js +9 -1
- package/dist/src/decision/FactServiceGate.js +1 -1
- package/dist/src/decision/checks.js +1 -1
- package/dist/src/decision/hostedSkills.d.ts +37 -0
- package/dist/src/decision/hostedSkills.js +64 -0
- package/dist/src/decision/providers/AndorraDecisionProvider.d.ts +10 -2
- package/dist/src/decision/providers/AndorraDecisionProvider.js +121 -10
- package/dist/src/default-graph.d.ts +11 -0
- package/dist/src/default-graph.js +20 -0
- package/dist/src/duration.d.ts +13 -2
- package/dist/src/duration.js +27 -3
- package/dist/src/file-diff.d.ts +105 -0
- package/dist/src/file-diff.js +244 -0
- package/dist/src/graph-manager-chat.d.ts +302 -0
- package/dist/src/graph-manager-chat.js +940 -0
- package/dist/src/graph-runner.js +6 -0
- package/dist/src/graph-server.d.ts +9 -0
- package/dist/src/graph-server.js +171 -20
- package/dist/src/graph-studio-features.js +2 -2
- package/dist/src/graph-sync.js +5 -2
- package/dist/src/graph-ui/app.js +369 -183
- package/dist/src/graph-ui/controls.css +55 -32
- package/dist/src/graph-ui/controls.js +85 -9
- package/dist/src/graph-ui/edge-router.js +114 -13
- package/dist/src/graph-ui/embed.js +32 -17
- package/dist/src/graph-ui/icons.js +1 -0
- package/dist/src/graph-ui/index.html +4 -4
- package/dist/src/graph-ui/library.css +4 -10
- package/dist/src/graph-ui/manager-markdown.js +155 -0
- package/dist/src/graph-ui/manager-state.js +191 -0
- package/dist/src/graph-ui/manager.css +161 -0
- package/dist/src/graph-ui/manager.js +700 -0
- package/dist/src/graph-ui/skill-picker.js +6 -6
- package/dist/src/graph-ui/studio-canvas.js +17 -15
- package/dist/src/graph-ui/studio.css +24 -23
- package/dist/src/graph-ui/studio.js +69 -48
- package/dist/src/graph-ui/style.css +128 -93
- package/dist/src/graph-ui/theme.js +2 -2
- package/dist/src/graph-ui/tokens.css +217 -151
- package/dist/src/graphs.d.ts +76 -2
- package/dist/src/graphs.js +172 -9
- package/dist/src/hardened-runtime.js +8 -2
- package/dist/src/mcp.d.ts +75 -0
- package/dist/src/mcp.js +240 -8
- package/dist/src/membership-errors.d.ts +14 -0
- package/dist/src/membership-errors.js +24 -1
- package/dist/src/membership.d.ts +20 -0
- package/dist/src/membership.js +45 -16
- package/dist/src/palette.d.ts +25 -8
- package/dist/src/palette.js +26 -8
- package/dist/src/provider-engine.d.ts +4 -4
- package/dist/src/provider-engine.js +39 -22
- package/dist/src/provider-keys.d.ts +5 -1
- package/dist/src/provider-keys.js +7 -3
- package/dist/src/provider-settings.d.ts +4 -1
- package/dist/src/provider-settings.js +46 -5
- package/dist/src/providers.d.ts +24 -0
- package/dist/src/providers.js +47 -2
- package/dist/src/qa/guidance.d.ts +26 -0
- package/dist/src/qa/guidance.js +46 -0
- package/dist/src/qa/index.d.ts +1 -8
- package/dist/src/qa/index.js +1 -16
- package/dist/src/qa/profile/QaProfile.d.ts +5 -1
- package/dist/src/qa/profile/QaProfile.js +6 -2
- package/dist/src/qa/runtime/ProcessManager.d.ts +20 -2
- package/dist/src/qa/runtime/ProcessManager.js +69 -13
- package/dist/src/qa/tools.d.ts +19 -1
- package/dist/src/qa/tools.js +20 -145
- package/dist/src/react-runtime.d.ts +11 -0
- package/dist/src/react-runtime.js +203 -53
- package/dist/src/remote/engine-pool.js +21 -6
- package/dist/src/run-progress.d.ts +6 -0
- package/dist/src/run-progress.js +7 -0
- package/dist/src/runtime.d.ts +8 -0
- package/dist/src/screen-selection.d.ts +38 -0
- package/dist/src/screen-selection.js +103 -0
- package/dist/src/session-changes.d.ts +117 -0
- package/dist/src/session-changes.js +796 -0
- package/dist/src/session-skills.d.ts +75 -0
- package/dist/src/session-skills.js +151 -0
- package/dist/src/side-panel.d.ts +1 -1
- package/dist/src/side-panel.js +6 -12
- package/dist/src/skill-commands.js +1 -1
- package/dist/src/skills/bundled/control-browser/SKILL.md +9 -1
- package/dist/src/skills/bundled/graph-manager/SKILL.md +8 -0
- package/dist/src/skills/bundled/provenance.json +3 -3
- package/dist/src/skills/bundled/web-gui-tester/SKILL.md +1 -1
- package/dist/src/stall-recovery.d.ts +33 -0
- package/dist/src/stall-recovery.js +83 -0
- package/dist/src/subagent-run.js +1 -2
- package/dist/src/telemetry/schema.d.ts +1 -1
- package/dist/src/telemetry/schema.js +1 -2
- package/dist/src/terminal-ui.d.ts +66 -22
- package/dist/src/terminal-ui.js +327 -92
- package/dist/src/tool-diff-stats.d.ts +9 -0
- package/dist/src/tool-diff-stats.js +20 -0
- package/dist/src/tool-names.d.ts +1 -1
- package/dist/src/tool-result-filter.js +1 -1
- package/dist/src/tools.js +26 -2
- package/dist/src/transcript.d.ts +11 -0
- package/dist/src/transcript.js +23 -3
- package/dist/src/types.d.ts +24 -4
- package/dist/src/usage-analytics.d.ts +7 -0
- package/dist/src/usage-analytics.js +55 -15
- package/docs/concepts/README.md +1 -1
- package/docs/concepts/limits.md +9 -0
- package/docs/guides/desktop-app.md +1 -1
- package/docs/guides/graph-builder.md +16 -1
- package/docs/guides/tui.md +9 -9
- package/docs/reference/slash-commands.md +2 -1
- package/docs/superpowers/plans/2026-11-13-graph-manager-chat.md +203 -0
- package/docs/superpowers/plans/2026-11-14-jev-fair-use-pricing.md +79 -0
- package/docs/superpowers/specs/2026-11-13-graph-manager-chat-design.md +182 -0
- package/docs/superpowers/specs/2026-11-14-jev-fair-use-pricing-design.md +156 -0
- package/package.json +1 -1
- package/tests/chat-side-panel-test-plan.md +1 -1
- package/dist/src/qa/api/http-runner.d.ts +0 -3
- package/dist/src/qa/api/http-runner.js +0 -47
- package/dist/src/qa/git/ChangeDetector.d.ts +0 -26
- package/dist/src/qa/git/ChangeDetector.js +0 -177
- package/dist/src/qa/git/DiffReviewer.d.ts +0 -28
- package/dist/src/qa/git/DiffReviewer.js +0 -115
- package/dist/src/qa/orchestrator/ChangeClassifier.d.ts +0 -14
- package/dist/src/qa/orchestrator/ChangeClassifier.js +0 -28
- package/dist/src/qa/orchestrator/MergeGate.d.ts +0 -14
- package/dist/src/qa/orchestrator/MergeGate.js +0 -40
- package/dist/src/qa/orchestrator/QaOrchestrator.d.ts +0 -79
- package/dist/src/qa/orchestrator/QaOrchestrator.js +0 -373
- package/dist/src/qa/runners/CommandRunner.d.ts +0 -22
- package/dist/src/qa/runners/CommandRunner.js +0 -96
- package/dist/src/qa/runners/TestRunner.d.ts +0 -21
- package/dist/src/qa/runners/TestRunner.js +0 -66
- package/dist/src/qa/runtime/RuntimeSmoke.d.ts +0 -11
- package/dist/src/qa/runtime/RuntimeSmoke.js +0 -78
- package/dist/src/qa/runtime-detect.d.ts +0 -10
- package/dist/src/qa/runtime-detect.js +0 -72
- package/dist/src/qa/security/DependencyScanner.d.ts +0 -19
- package/dist/src/qa/security/DependencyScanner.js +0 -167
- package/dist/src/qa/security/SecretScanner.d.ts +0 -3
- package/dist/src/qa/security/SecretScanner.js +0 -55
|
@@ -0,0 +1,203 @@
|
|
|
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.
|
|
@@ -0,0 +1,79 @@
|
|
|
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.
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
# Graph Manager chat in Graph Studio
|
|
2
|
+
|
|
3
|
+
Date: 2026-11-13. Status: approved 2026-11-13.
|
|
4
|
+
|
|
5
|
+
## Intent
|
|
6
|
+
|
|
7
|
+
Building a graph by hand in Graph Studio means knowing node types, ports, routes and limits. The bundled
|
|
8
|
+
`andorra:graph-manager` skill already knows how to design and edit graphs through the `graphs` tool, but you
|
|
9
|
+
can only reach it from a regular task, away from the graph you are looking at. This feature puts that
|
|
10
|
+
assistant next to the open graph. A **Graph Manager** button opens a side chat. You pick the provider and
|
|
11
|
+
model, and the agent starts already knowing which graph is open, so it can help you create or change that
|
|
12
|
+
graph without leaving the editor.
|
|
13
|
+
|
|
14
|
+
## Goals
|
|
15
|
+
|
|
16
|
+
- A **Graph Manager** button in Graph Studio's toolbar whenever a graph is open (saved or new).
|
|
17
|
+
- When you create a new graph, a closable tip next to the button says you can let Graph Manager build it.
|
|
18
|
+
- The button opens a side panel in the editor with a provider and model picker and a chat.
|
|
19
|
+
- Each chat runs the `andorra:graph-manager` skill. Its first message tells the agent the open graph's id and
|
|
20
|
+
name, and the provider and model you chose.
|
|
21
|
+
- It works the same in the desktop app (Graph Studio in its iframe) and in a browser (`andorra graph`).
|
|
22
|
+
- When the agent saves a revision of the open graph, the canvas shows it.
|
|
23
|
+
|
|
24
|
+
## Non-goals
|
|
25
|
+
|
|
26
|
+
- No new graph tool. The agent uses the existing `graphs` tool and the existing skill.
|
|
27
|
+
- No native desktop panel. The desktop shows the same in-editor panel through the iframe.
|
|
28
|
+
- No attachments, voice, slash-skill menu or other composer features from the main chat.
|
|
29
|
+
- No change to how regular tasks run.
|
|
30
|
+
|
|
31
|
+
## Anti-goals (a failure even if it works)
|
|
32
|
+
|
|
33
|
+
- The agent edits graph files on disk, or saves graphs without the user seeing an approval.
|
|
34
|
+
- The chat silently overwrites unsaved canvas edits with the agent's revision.
|
|
35
|
+
- Opening the panel leaves a stray engine process, listener or temp folder after the editor closes.
|
|
36
|
+
- The desktop's own task engine is blocked or busy because Graph Manager is talking.
|
|
37
|
+
|
|
38
|
+
## Constraints found in the code
|
|
39
|
+
|
|
40
|
+
- Graph Studio is `src/graph-ui/` (plain JS, no bundler), served by `startGraphServer` in
|
|
41
|
+
`src/graph-server.ts` on loopback with a bearer token. In the desktop, the engine starts that server
|
|
42
|
+
in-process (`src/app-server.ts`, `editorTask`), and `GraphEditorView.tsx` embeds it in a sandboxed iframe.
|
|
43
|
+
In a browser, `andorra graph` starts it alone (`src/graph-editor-session.ts`).
|
|
44
|
+
- An engine runs one task at a time (`engine-busy`). The desktop engine that hosts the graph server may be
|
|
45
|
+
running the user's task, so the chat cannot share it.
|
|
46
|
+
- `run.start` takes `task`, `provider`, `model`, `workspace`, `sessionId` (+ `continueSession`) and
|
|
47
|
+
`runPermissions`. A task that begins with `/graph-manager` invokes the skill (`resolveSkillInvocation`).
|
|
48
|
+
Events (`run.event`, `run.approval`, `run.question`, `run.completed`, `run.failed`) stream on stdout;
|
|
49
|
+
`run.approve`, `run.answer` and `run.cancel` answer them.
|
|
50
|
+
- The skill says the `graphs` tool needs shell permission and is never given to subagents.
|
|
51
|
+
- The graph server already lists providers and models (`GET /api/provider-models`).
|
|
52
|
+
- A new graph has no revision until it is saved; the agent's `andorra_graph_begin` with `mode: "create"`
|
|
53
|
+
creates it.
|
|
54
|
+
|
|
55
|
+
## Approaches
|
|
56
|
+
|
|
57
|
+
- **A. The graph server runs a dedicated engine session (chosen).** On first use the graph server spawns
|
|
58
|
+
`andorra app-server --stdio` as a child process and relays one session to the panel. Reuses multi-turn
|
|
59
|
+
history, streaming, approvals, questions, cancel and model selection. Costs one extra process while a chat
|
|
60
|
+
is open, which must be stopped with the editor.
|
|
61
|
+
- **B. One in-process run per message.** The graph server calls `runDefaultGraph` with earlier turns as
|
|
62
|
+
`history`. No extra process, but memory, streaming, approvals and cancel would be rebuilt by hand: a second,
|
|
63
|
+
thinner engine to maintain.
|
|
64
|
+
- **C. A native desktop panel plus a browser chat.** Twice the work, and the two would drift apart.
|
|
65
|
+
|
|
66
|
+
The user picked A because the hard parts of a chat already exist in the engine.
|
|
67
|
+
|
|
68
|
+
## Design
|
|
69
|
+
|
|
70
|
+
### Server: `src/graph-manager-chat.ts` (new) and routes in `graph-server.ts`
|
|
71
|
+
|
|
72
|
+
A `GraphManagerChat` owned by the graph server, created lazily:
|
|
73
|
+
|
|
74
|
+
- **Engine.** Spawns the running CLI's own entry (`process.execPath` + the CLI script) with
|
|
75
|
+
`app-server --stdio`, the same `ANDORRACODE_HOME` (the user's real home, so sign-in, providers and graphs
|
|
76
|
+
match). One child per graph server. It is killed when the graph server closes and on process exit. It is
|
|
77
|
+
also stopped after 10 minutes with no connected panel, but only while no run is working and no approval or
|
|
78
|
+
question is pending: the `graphs` tool keeps unpublished drafts in the engine's memory.
|
|
79
|
+
- **Workspace.** The chat's workspace (child cwd and `run.start` `workspace`) is a dedicated empty folder,
|
|
80
|
+
`<config directory>/graph-manager/workspace`, created on first use. The graph server's own `directory` is
|
|
81
|
+
the config directory, not a project, and `ask-for-approval` lets an agent edit files inside its workspace
|
|
82
|
+
without asking; an empty, dedicated folder means there is nothing on disk to edit and the chat's sessions
|
|
83
|
+
stay out of the user's project task lists.
|
|
84
|
+
- **Agent.** The run uses a single top-level agent node (shell permission, no Orchestrator intake): the skill
|
|
85
|
+
says delegated subagents never get the `graphs` tool, and the default graph's Orchestrator would interview
|
|
86
|
+
the user before every message. If `run.start` only takes saved graph ids, add an internal built-in
|
|
87
|
+
single-agent graph id for this purpose, hidden from graph lists.
|
|
88
|
+
- **Clients.** Several panels can connect to one graph server (the desktop iframe and a browser tab). They
|
|
89
|
+
share one conversation: every client receives the stream, and any client can send, approve or cancel.
|
|
90
|
+
- **Starting a chat.** `POST /api/manager/start` `{ provider, model, graph, saved, message }` creates the
|
|
91
|
+
session with `sessions.create` (name `Graph Manager: <graph name>`, pinned with `renamed` so automatic
|
|
92
|
+
titling keeps it) and calls `run.start` with:
|
|
93
|
+
- `task`: the bundled skill invoked by its full id (`andorra:graph-manager`, so an installed skill also
|
|
94
|
+
named `graph-manager` cannot shadow it; the builder confirms the exact invocation syntax
|
|
95
|
+
`resolveSkillInvocation` accepts), followed by a context block and the user's message:
|
|
96
|
+
```
|
|
97
|
+
You are helping in Graph Studio. Open graph: "<name>", id <id> (saved revision N | not saved yet).
|
|
98
|
+
The canvas below is what the user sees now, including edits not yet saved. Work from it, and save your
|
|
99
|
+
changes under this same graph id (mode "create" when it is not saved yet, "edit" otherwise).
|
|
100
|
+
Selected model: <provider>/<model>. Use it for new agent nodes unless the user asks otherwise.
|
|
101
|
+
<canvas graph JSON>
|
|
102
|
+
<user message>
|
|
103
|
+
```
|
|
104
|
+
- The canvas is the editor's current graph definition (`state.graph`, including unsaved edits), sent with
|
|
105
|
+
every message, not only the first, so the agent always works from what is on screen. A graph over the
|
|
106
|
+
server's body limit is refused with a clear message rather than truncated.
|
|
107
|
+
- `provider`, `model` as chosen; `workspace` = the graph server's cwd;
|
|
108
|
+
`runPermissions: "ask-for-approval"` so every graph write and shell use stops for approval in the panel.
|
|
109
|
+
- **Follow-ups.** `POST /api/manager/message` `{ text, graph, saved }` (canvas included again) sends `run.start` with the same `sessionId` and
|
|
110
|
+
`continueSession: true` when idle, or `run.steer` while a run is working.
|
|
111
|
+
- **Answers.** `POST /api/manager/approve` `{ id, approved }`, `POST /api/manager/answer` `{ id, value }`,
|
|
112
|
+
`POST /api/manager/cancel`, `POST /api/manager/reset` (new conversation; the old session stays in history).
|
|
113
|
+
- **Events.** `GET /api/manager/stream?token=` is a server-sent-events stream (like `/api/activity/stream`)
|
|
114
|
+
carrying a reduced event shape: `assistant.delta`, `assistant.message`, `tool` (name + one-line summary),
|
|
115
|
+
`approval`, `question`, `state` (`idle` | `working` | `awaiting`), `error`, `graph.saved` `{ graphId }`.
|
|
116
|
+
A reconnecting client gets the conversation so far as one `snapshot` event.
|
|
117
|
+
- All routes use the existing bearer token check and require a signed-in account, like graph saves.
|
|
118
|
+
|
|
119
|
+
### Editor: `src/graph-ui/manager.js` + `manager.css` (new)
|
|
120
|
+
|
|
121
|
+
- **Button.** A **Graph Manager** button in the editor toolbar, shown whenever `state.graph` is set.
|
|
122
|
+
- **Tip.** After `newGraph()` (not after Duplicate or import), a small popover anchored to the button:
|
|
123
|
+
"Let Graph Manager build this graph with you." with a close button. Closing it, or opening the panel,
|
|
124
|
+
stores `andorra.graphManager.tipDismissed` in `localStorage`, so it shows once per browser profile. It
|
|
125
|
+
never covers the canvas's own first-run hints.
|
|
126
|
+
- **Panel.** A right-hand side panel (resizable, closable) that narrows the canvas instead of covering it.
|
|
127
|
+
Header: provider + model selects filled from `/api/provider-models`, defaulting to the last choice
|
|
128
|
+
(`localStorage`) or the graph's first agent node's model; a New chat button. Body: the transcript with
|
|
129
|
+
Markdown text, compact tool lines, approval cards (Approve / Deny) and question cards. Footer: a text box
|
|
130
|
+
with Send and Stop.
|
|
131
|
+
- **Model changes.** Changing the model before the first message just changes the start. Changing it
|
|
132
|
+
mid-chat applies from the next message (`run.setModel` when idle is not needed; the next `run.start`
|
|
133
|
+
carries the new pair).
|
|
134
|
+
- **Graph switches.** The panel follows the open graph: switching graphs offers "Start a new chat about
|
|
135
|
+
<name>?" and keeps the old conversation until the user agrees.
|
|
136
|
+
- **Applying the agent's work.** The panel records the canvas it sent with the latest message. On
|
|
137
|
+
`graph.saved` for the open graph id: if the canvas is unchanged since that message (or is still the
|
|
138
|
+
untouched starter, `state.untouched`), it opens the new revision directly; if the user edited the canvas
|
|
139
|
+
after sending, it shows a bar, "Graph Manager saved revision N. Load it?", and never discards edits
|
|
140
|
+
without that click. Because the agent saves under the open graph's id, a new graph turns into its first
|
|
141
|
+
saved revision in place.
|
|
142
|
+
|
|
143
|
+
### Desktop
|
|
144
|
+
|
|
145
|
+
No new desktop UI. The panel is inside the iframe. `GraphEditorView.tsx` only needs the iframe tall and wide
|
|
146
|
+
enough as it already is; the desktop engine is untouched because the chat has its own engine process.
|
|
147
|
+
|
|
148
|
+
## Decided by the user
|
|
149
|
+
|
|
150
|
+
- Desktop and browser both get the feature (in-editor panel).
|
|
151
|
+
- Approach A: the graph server runs a dedicated engine session.
|
|
152
|
+
- The agent receives the current canvas, including unsaved edits, with every message, and saves under the
|
|
153
|
+
open graph's id.
|
|
154
|
+
|
|
155
|
+
## Calls I made (correct any of these)
|
|
156
|
+
|
|
157
|
+
- Permissions are fixed at Ask for approval. Publishing, deleting and restoring a graph always stop for an
|
|
158
|
+
approval card (`DURABLE_ACTIONS` in `src/graph-tool.ts`); file edits are harmless because the workspace is
|
|
159
|
+
an empty dedicated folder.
|
|
160
|
+
- Chat sessions are ordinary saved sessions named `Graph Manager: <graph name>`, filed under the dedicated
|
|
161
|
+
workspace, so they never appear in a project's task list.
|
|
162
|
+
- One shared conversation per graph server, across all connected panels.
|
|
163
|
+
- The tip shows once per browser profile, not once per graph.
|
|
164
|
+
- One conversation at a time per editor; New chat starts a fresh session.
|
|
165
|
+
- The idle engine stops after 10 minutes without a connected panel.
|
|
166
|
+
|
|
167
|
+
## Left to the builder
|
|
168
|
+
|
|
169
|
+
- Event mapping from the engine's `run.event` stream to the reduced panel events.
|
|
170
|
+
- Exact layout and styling, following `studio.css` tokens in light and dark.
|
|
171
|
+
- Detecting `graph.saved` (from `graphs` tool results or the graph store's revision change).
|
|
172
|
+
- Tests in `test/` for the server routes (with a fake engine) and the tip/button logic, and the QA plan at
|
|
173
|
+
`tests/graph-manager-chat-test-plan.md`.
|
|
174
|
+
|
|
175
|
+
## Refinements made while planning
|
|
176
|
+
|
|
177
|
+
- The skill is loaded by the hidden Graph Manager graph's own node instruction (`andorra:graph-manager` by full
|
|
178
|
+
id) rather than a `/graph-manager` slash prefix: `resolveSkillInvocation` JSON-escapes everything after the
|
|
179
|
+
name into its arguments, which would mangle the canvas JSON, and the instruction cannot be shadowed by an
|
|
180
|
+
installed skill of the same name.
|
|
181
|
+
- The panel receives whole assistant messages (`agent.message`), not token deltas; the engine does not
|
|
182
|
+
stream partial text on this path.
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# Jev pricing: Free credits and Premium fair use
|
|
2
|
+
|
|
3
|
+
Date: 2026-11-14 · Status: proposed
|
|
4
|
+
|
|
5
|
+
## Intent
|
|
6
|
+
|
|
7
|
+
Change how hosted Jev decisions are allowed per plan, and make the account surfaces say so:
|
|
8
|
+
|
|
9
|
+
- **Free**: 100 Jev calls per rolling 30 days (they come back as old calls age out).
|
|
10
|
+
- **Legacy and Paid**: unlimited, subject to fair use: at most 250 per UTC day and at most 2,500
|
|
11
|
+
per rolling 30 days.
|
|
12
|
+
- The website's account center reflects the new terms, shows an "odometer" of every Jev call the
|
|
13
|
+
account has made, and an estimate of tokens Jev saved.
|
|
14
|
+
- The app (desktop Settings → Account, Portal, and the CLI/TUI footer) stops showing "/ 1,000".
|
|
15
|
+
|
|
16
|
+
## Goals
|
|
17
|
+
|
|
18
|
+
- One enforcement mechanism for both plans: an optional per-UTC-day cap plus a rolling 30-day cap.
|
|
19
|
+
- Old clients (0.1.8 and earlier, already installed) keep working without a crash or a wrong lockout.
|
|
20
|
+
- The tokens-saved figure is labeled an estimate and traceable to the Performance page's data.
|
|
21
|
+
|
|
22
|
+
## Non-goals
|
|
23
|
+
|
|
24
|
+
- Purchasable credits, top-ups, Stripe billing changes.
|
|
25
|
+
- Deploying the infra stack or releasing the website (stop at merged PRs; the owner deploys).
|
|
26
|
+
- Changing who is on which plan (`premium_policy.membership_tier` is unchanged). Production runs
|
|
27
|
+
`PremiumPromotionEnabled=true` with no dates, so every account is Legacy today and the Free
|
|
28
|
+
path has no live users until the owner ends or dates the promotion at deploy time (owner's
|
|
29
|
+
choice; the template is not touched).
|
|
30
|
+
- Changing the shared `GLOBAL_DAILY_LIMIT` (10,000/day across all accounts) — unchanged.
|
|
31
|
+
|
|
32
|
+
## Anti-goals
|
|
33
|
+
|
|
34
|
+
- Presenting the Premium caps as an allowance ("12 / 250") in normal use: Premium reads as
|
|
35
|
+
unlimited with a fair-use note.
|
|
36
|
+
- Fabricating figures: usage the service did not report stays "—"/"Unavailable", as today.
|
|
37
|
+
|
|
38
|
+
## Approaches considered (rolling 30-day cap)
|
|
39
|
+
|
|
40
|
+
- **A. Rolling window over daily counters — chosen.** Keep per-user daily counters for 31+ days
|
|
41
|
+
(TTL raised from 2 days). Before reserving, read the last 30 daily counters (one
|
|
42
|
+
`BatchGetItem`, consistent reads) and refuse if `sum >= windowLimit`; then the existing
|
|
43
|
+
transaction reserves today's counter (conditioned on the daily cap) and bumps the lifetime
|
|
44
|
+
counter. True rolling as asked; ~30 extra reads per call (≈$7.50 per million calls on demand);
|
|
45
|
+
bursts can overshoot the 30-day cap by the number of concurrent in-flight calls, acceptable for
|
|
46
|
+
fair use.
|
|
47
|
+
- B. Fixed 30-day periods anchored at signup: exact and cheap, "Refills <date>", but not rolling —
|
|
48
|
+
a heavy user can use 2× the cap across a boundary. Rejected.
|
|
49
|
+
|
|
50
|
+
## Design
|
|
51
|
+
|
|
52
|
+
### Server (`infra/andorra-auth/proxy.py`, `template.json`)
|
|
53
|
+
|
|
54
|
+
Limits per plan, from environment (template defaults shown):
|
|
55
|
+
|
|
56
|
+
| Plan | Daily cap (UTC day) | 30-day cap |
|
|
57
|
+
| --- | --- | --- |
|
|
58
|
+
| free | none | `FREE_WINDOW_LIMIT=100` |
|
|
59
|
+
| legacy, paid | `PAID_DAILY_LIMIT=250` | `PAID_WINDOW_LIMIT=2500` |
|
|
60
|
+
|
|
61
|
+
`FREE_DAILY_LIMIT` is removed. Free has no separate daily cap (the window cap bounds it).
|
|
62
|
+
|
|
63
|
+
Reservation (`POST /v1/decisions`):
|
|
64
|
+
1. Read the user's daily counters for the 30 UTC days ending today (today and the 29 before).
|
|
65
|
+
2. If `sum >= windowLimit` → 429.
|
|
66
|
+
3. Transaction as today: today's counter `+1` conditioned on the daily cap (Free: no condition
|
|
67
|
+
besides the window check), global counter conditioned on `GLOBAL_DAILY_LIMIT`, lifetime `+1`.
|
|
68
|
+
Daily keys get a TTL of 32 days after their day.
|
|
69
|
+
4. 429 body keeps `error: "daily_limit_reached"` (old clients recognise it and back off) and adds
|
|
70
|
+
`limitScope: "user" | "window" | "global"` and `resetsAt`: for `user`/`global` the next UTC
|
|
71
|
+
midnight; for `window` the moment the oldest counted day leaves the window (the first day in
|
|
72
|
+
the window with a non-zero count, plus 30 days).
|
|
73
|
+
|
|
74
|
+
Display (`GET /v1/me`) adds, without removing existing fields:
|
|
75
|
+
- `fairUse: true` for legacy/paid, `false` for free.
|
|
76
|
+
- `windowDecisionLimit`, `windowDecisionUsed`, `windowDays: 30`, `windowDecisionResetsAt` (when
|
|
77
|
+
the next call returns; only when the window has usage).
|
|
78
|
+
- `dailyDecisionLimit` stays for compatibility: 250 for legacy/paid, and for free the window
|
|
79
|
+
limit (100), so an old client still sees a sane bound. `dailyDecisionUsed`,
|
|
80
|
+
`dailyDecisionResetsAt`, and `decisionsSinceRollout` (the odometer) are unchanged.
|
|
81
|
+
- `estimatedTokensSavedPerDecision` is **not** sent by the server; the estimate lives with the
|
|
82
|
+
Performance data on the website (see below).
|
|
83
|
+
|
|
84
|
+
Admin metrics (`infra/admin` in the website repo) read the quota table by key prefix; the longer
|
|
85
|
+
daily TTL only means more `user#<sub>#<day>` items stay around — verify the admin rollup filters
|
|
86
|
+
by day and is unaffected.
|
|
87
|
+
|
|
88
|
+
### App (this repo)
|
|
89
|
+
|
|
90
|
+
- `src/membership.ts`: parse and validate the new fields (non-negative safe integers, ISO dates);
|
|
91
|
+
an invalid field is dropped, not fatal.
|
|
92
|
+
- `src/account-presentation.ts` (footer + notice):
|
|
93
|
+
- Premium: `Jev 12 today · fair use` (no denominator). Notice text: "Unlimited Jev calls,
|
|
94
|
+
fair use: 250 per UTC day, 2,500 per 30 days."
|
|
95
|
+
- Free: `Jev 37/100 · 30d`. Notice: "100 Jev calls per 30 days."
|
|
96
|
+
- `src/decision/providers/AndorraDecisionProvider.ts` + `src/transcript.ts`: read `limitScope`;
|
|
97
|
+
`window` maps to a new reason `decision_window_limit_reached` shown as "30-day Jev limit
|
|
98
|
+
reached" (Free: "Free Jev calls used up for now"), with the return date when given. The fact
|
|
99
|
+
service gate treats it like the daily limit (stop asking until `resetsAt`).
|
|
100
|
+
- Desktop `settingsDisplay.decisionUsage` / `SettingsView` Quota / `PortalView` UsageRows:
|
|
101
|
+
- Premium: row "Jev calls today: 12" with sub-note "Unlimited · fair use". A meter appears only
|
|
102
|
+
when today's count ≥ 80% of the daily cap or the 30-day count ≥ 80% of the 30-day cap, and
|
|
103
|
+
then shows whichever is closer (e.g. "212 / 250 today").
|
|
104
|
+
- Free: meter "37 / 100 · last 30 days" with "more return <date>".
|
|
105
|
+
- "Since rollout" row renamed "All-time Jev calls" (the odometer figure).
|
|
106
|
+
- The app-server protocol (`src/app-server/protocol.ts`, `desktop/src/engine/protocol.ts`) and
|
|
107
|
+
`src/app-server.ts` pass the new fields through.
|
|
108
|
+
|
|
109
|
+
### Website (`Andorra-Code-Website`)
|
|
110
|
+
|
|
111
|
+
- `src/auth.ts` `Membership`: parse the new fields.
|
|
112
|
+
- `src/AccountCenter.tsx`:
|
|
113
|
+
- Plan descriptions: Free "100 JEV calls every 30 days"; Legacy/Paid "Unlimited JEV calls, fair
|
|
114
|
+
use: up to 250 a day and 2,500 per 30 days."
|
|
115
|
+
- Usage pane: an **odometer** — the all-time count rendered as rolling digit wheels (CSS
|
|
116
|
+
transform per digit, animates once on load; `prefers-reduced-motion` shows static digits),
|
|
117
|
+
labeled "JEV calls, all time".
|
|
118
|
+
- **Estimated tokens saved** tile: `all-time calls × TOKENS_SAVED_PER_JEV_CALL`, compact
|
|
119
|
+
formatted, with the note "Estimate from our benchmark runs" linking to `/performance`.
|
|
120
|
+
- Free: "Used in the last 30 days 37 of 100" + "More return <date>". Premium: "Today 12",
|
|
121
|
+
"Last 30 days 340", fair-use caps listed as rows, no allowance bar unless ≥ 80%.
|
|
122
|
+
- `src/performance.ts`: export `JEV_QUESTIONS` per benchmark for the `andorra-018-jev` row
|
|
123
|
+
(TB 2.1: 112, SWE-bench: 211 — the `jev_telemetry` "requested" totals in the 0.1.8 run
|
|
124
|
+
READMEs in `Andorra-Bench-archive-v018`) and
|
|
125
|
+
`TOKENS_SAVED_PER_JEV_CALL = (tokens(JEV off) − tokens(JEV on)) / JEV questions(JEV on)` over
|
|
126
|
+
TB 2.1 + SWE-bench, computed from the same constants the page uses (prompt + completion
|
|
127
|
+
tokens): (258,941,871 − 158,606,273) / 323 ≈ 310,637. **Owner's choice:** per question, not per
|
|
128
|
+
HTTP call. One hosted call carries one or more questions, so multiplying the odometer (hosted
|
|
129
|
+
calls) by a per-question figure underestimates — the conservative side. A unit test pins the
|
|
130
|
+
derivation.
|
|
131
|
+
- Odometer label: "JEV calls" with the small note "counted since the counter started" — the
|
|
132
|
+
lifetime counter began at rollout, so "all time" would overstate.
|
|
133
|
+
|
|
134
|
+
## Constraints
|
|
135
|
+
|
|
136
|
+
- The infra change is not live until the stack is deployed; the app and website must handle a
|
|
137
|
+
service that does not yet send the new fields (fall back to today's daily display).
|
|
138
|
+
- Work in worktrees; open ready-for-review PRs to `main` in both repos; Codex review loop per
|
|
139
|
+
`AGENTS.md`; QA test plan at `tests/jev-fair-use-pricing-test-plan.md`.
|
|
140
|
+
|
|
141
|
+
## Calls made by the designer (not decided by the owner)
|
|
142
|
+
|
|
143
|
+
- Free has no separate daily cap; the window cap covers it.
|
|
144
|
+
- 429 keeps the `daily_limit_reached` error code for old clients; scope is in `limitScope`.
|
|
145
|
+
- Premium meter appears only past 80% of a cap.
|
|
146
|
+
- Tokens-saved constant lives in the website's performance data, not the server.
|
|
147
|
+
- An old client (0.1.8) on an account locked by the 30-day cap sees a "daily quota reached" 429
|
|
148
|
+
while `/v1/me` still shows today's count under 250; accepted — it backs off correctly and the
|
|
149
|
+
new clients show the real reason. No figure is faked to make old clients read "exhausted".
|
|
150
|
+
- Existing Free accounts' last-30-days usage counts toward the 100 immediately (daily counters
|
|
151
|
+
older than 2 days have already expired, so in practice at most ~2 days of history counts).
|
|
152
|
+
|
|
153
|
+
## Left to the builder
|
|
154
|
+
|
|
155
|
+
- Exact copy and styling of the odometer and tiles, within the site's existing account styles.
|
|
156
|
+
- Test structure; reuse existing fakes in `test_proxy.py`, `membership.test.ts`, desktop tests.
|