@myrialabs/clopen 0.3.13 → 0.3.14

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.
@@ -38,6 +38,7 @@ import type {
38
38
  ErrorResultEvent,
39
39
  SystemInitEvent,
40
40
  RateLimitEvent,
41
+ NotificationEvent,
41
42
  TokenUsage,
42
43
  StopReason,
43
44
  } from '$shared/types/unified';
@@ -389,6 +390,26 @@ export function convertSystemInit(msg: SDKSystemMessage): SystemInitEvent {
389
390
  };
390
391
  }
391
392
 
393
+ /**
394
+ * Convert SDKTaskNotificationMessage (terminal background-task event) →
395
+ * NotificationEvent. Fires when a backgrounded Agent/teammate finishes
396
+ * (status completed | failed | stopped). The non-terminal task_started /
397
+ * task_progress / task_updated messages are intentionally not surfaced —
398
+ * they would spam the toast and there is no dedicated tasks panel.
399
+ */
400
+ function convertTaskNotification(
401
+ msg: { session_id: string; status: string; summary?: string; task_id: string },
402
+ ): NotificationEvent {
403
+ const completed = msg.status === 'completed';
404
+ return {
405
+ type: 'notification',
406
+ sessionId: msg.session_id,
407
+ level: completed ? 'info' : 'warning',
408
+ title: completed ? 'Background task completed' : `Background task ${msg.status}`,
409
+ message: msg.summary || `Task ${msg.task_id} ${msg.status}`,
410
+ };
411
+ }
412
+
392
413
  /** Convert SDKCompactBoundaryMessage → CompactBoundaryMessage */
393
414
  export function convertCompactBoundary(msg: SDKCompactBoundaryMessage): CompactBoundaryMessage {
394
415
  return {
@@ -476,14 +497,20 @@ function* dispatchSdkMessage(msg: SDKMessage, state: StreamConverterState): Gene
476
497
  break;
477
498
 
478
499
  case 'system': {
479
- const systemMsg = msg as SDKSystemMessage | SDKCompactBoundaryMessage;
480
- if ('subtype' in systemMsg) {
481
- if (systemMsg.subtype === 'init') {
482
- yield convertSystemInit(systemMsg as SDKSystemMessage);
483
- } else if (systemMsg.subtype === 'compact_boundary') {
484
- yield convertCompactBoundary(systemMsg as SDKCompactBoundaryMessage);
485
- }
500
+ // Read subtype as a plain string: the SDKMessage `system` arm covers
501
+ // more subtypes (task_*, etc.) than the SDKSystemMessage |
502
+ // SDKCompactBoundaryMessage union, so narrowing on that union would
503
+ // collapse the task branch to `never`.
504
+ const subtype = (msg as { subtype?: string }).subtype;
505
+ if (subtype === 'init') {
506
+ yield convertSystemInit(msg as SDKSystemMessage);
507
+ } else if (subtype === 'compact_boundary') {
508
+ yield convertCompactBoundary(msg as SDKCompactBoundaryMessage);
509
+ } else if (subtype === 'task_notification') {
510
+ yield convertTaskNotification(msg as unknown as Parameters<typeof convertTaskNotification>[0]);
486
511
  }
512
+ // task_started / task_progress / task_updated: background-task
513
+ // progress noise — intentionally not surfaced (no tasks panel).
487
514
  break;
488
515
  }
489
516
 
@@ -23,7 +23,7 @@ export const CLAUDE_CODE_MODELS: EngineModel[] = [
23
23
  },
24
24
  },
25
25
  limit: {
26
- input: 200_000,
26
+ input: 1_000_000,
27
27
  output: 128_000,
28
28
  },
29
29
  modalities: {
@@ -66,7 +66,7 @@ export const CLAUDE_CODE_MODELS: EngineModel[] = [
66
66
  },
67
67
  },
68
68
  limit: {
69
- input: 200_000,
69
+ input: 1_000_000,
70
70
  output: 64_000,
71
71
  },
72
72
  modalities: {
@@ -138,4 +138,176 @@ export const CLAUDE_CODE_MODELS: EngineModel[] = [
138
138
  output: 5,
139
139
  },
140
140
  },
141
+ {
142
+ engine: {
143
+ type: 'claude-code',
144
+ provider: 'anthropic',
145
+ model: {
146
+ id: 'claude-opus-4-6',
147
+ name: 'Claude Opus 4.6',
148
+ },
149
+ account: {
150
+ id: 0,
151
+ name: '',
152
+ },
153
+ },
154
+ limit: {
155
+ input: 1_000_000,
156
+ output: 128_000,
157
+ },
158
+ modalities: {
159
+ input: {
160
+ text: true,
161
+ image: true,
162
+ audio: false,
163
+ video: false,
164
+ pdf: true,
165
+ },
166
+ output: {
167
+ text: true,
168
+ image: false,
169
+ audio: false,
170
+ video: false,
171
+ pdf: false,
172
+ },
173
+ },
174
+ capabilities: {
175
+ reasoning: true,
176
+ tools: true,
177
+ structuredOutput: true,
178
+ },
179
+ cost: {
180
+ input: 5,
181
+ output: 25,
182
+ },
183
+ },
184
+ {
185
+ engine: {
186
+ type: 'claude-code',
187
+ provider: 'anthropic',
188
+ model: {
189
+ id: 'claude-sonnet-4-5',
190
+ name: 'Claude Sonnet 4.5',
191
+ },
192
+ account: {
193
+ id: 0,
194
+ name: '',
195
+ },
196
+ },
197
+ limit: {
198
+ input: 200_000,
199
+ output: 64_000,
200
+ },
201
+ modalities: {
202
+ input: {
203
+ text: true,
204
+ image: true,
205
+ audio: false,
206
+ video: false,
207
+ pdf: true,
208
+ },
209
+ output: {
210
+ text: true,
211
+ image: false,
212
+ audio: false,
213
+ video: false,
214
+ pdf: false,
215
+ },
216
+ },
217
+ capabilities: {
218
+ reasoning: true,
219
+ tools: true,
220
+ structuredOutput: true,
221
+ },
222
+ cost: {
223
+ input: 3,
224
+ output: 15,
225
+ },
226
+ },
227
+ {
228
+ engine: {
229
+ type: 'claude-code',
230
+ provider: 'anthropic',
231
+ model: {
232
+ id: 'claude-opus-4-5',
233
+ name: 'Claude Opus 4.5',
234
+ },
235
+ account: {
236
+ id: 0,
237
+ name: '',
238
+ },
239
+ },
240
+ limit: {
241
+ input: 200_000,
242
+ output: 64_000,
243
+ },
244
+ modalities: {
245
+ input: {
246
+ text: true,
247
+ image: true,
248
+ audio: false,
249
+ video: false,
250
+ pdf: true,
251
+ },
252
+ output: {
253
+ text: true,
254
+ image: false,
255
+ audio: false,
256
+ video: false,
257
+ pdf: false,
258
+ },
259
+ },
260
+ capabilities: {
261
+ reasoning: true,
262
+ tools: true,
263
+ structuredOutput: true,
264
+ },
265
+ cost: {
266
+ input: 5,
267
+ output: 25,
268
+ },
269
+ },
270
+ {
271
+ engine: {
272
+ type: 'claude-code',
273
+ provider: 'anthropic',
274
+ model: {
275
+ id: 'claude-opus-4-1',
276
+ name: 'Claude Opus 4.1',
277
+ },
278
+ account: {
279
+ id: 0,
280
+ name: '',
281
+ },
282
+ },
283
+ limit: {
284
+ input: 200_000,
285
+ output: 32_000,
286
+ },
287
+ modalities: {
288
+ input: {
289
+ text: true,
290
+ image: true,
291
+ audio: false,
292
+ video: false,
293
+ pdf: true,
294
+ },
295
+ output: {
296
+ text: true,
297
+ image: false,
298
+ audio: false,
299
+ video: false,
300
+ pdf: false,
301
+ },
302
+ },
303
+ capabilities: {
304
+ reasoning: true,
305
+ tools: true,
306
+ structuredOutput: true,
307
+ },
308
+ cost: {
309
+ input: 15,
310
+ output: 75,
311
+ },
312
+ },
141
313
  ];
@@ -0,0 +1,183 @@
1
+ [← Engine adapter guide](../README.md)
2
+
3
+ ## 2. The `backend/engine/` layer — core contract
4
+
5
+ ### 2.1 `types.ts` — the `AIEngine` interface
6
+
7
+ ```ts
8
+ export interface AIEngine {
9
+ readonly name: EngineType; // 'claude-code' | 'opencode' | 'copilot'
10
+ readonly isInitialized: boolean;
11
+ readonly isActive: boolean;
12
+
13
+ initialize(accountId?: number): Promise<void>; // lazy; idempotent
14
+ dispose(): Promise<void>; // called per-project & on shutdown
15
+ cancel(): Promise<void>; // hard cancel
16
+ interrupt(): Promise<void>; // soft stop
17
+
18
+ streamQuery(options: EngineQueryOptions):
19
+ AsyncGenerator<EngineOutput, void, unknown>;
20
+
21
+ getAvailableModels(): Promise<EngineModel[]>;
22
+
23
+ // Optional
24
+ resolveUserAnswer?(toolUseId: string, answers: Record<string,string>): boolean;
25
+ generateStructured?<T>(options: StructuredGenerationOptions): Promise<T>;
26
+ }
27
+ ```
28
+
29
+ Three invariants:
30
+
31
+ 1. **`streamQuery` is the only streaming output path.** It is an
32
+ `AsyncGenerator<EngineOutput>`. The adapter translates SDK events into
33
+ `EngineOutput` — that is all.
34
+ 2. **Streaming state lives on the instance.** Because `getProjectEngine`
35
+ returns one instance per `(projectId, engineType)`, the abort controller,
36
+ active query, `pendingUserAnswers`, and session ID are automatically
37
+ isolated per-project.
38
+ 3. **Init is lazy & concurrency-safe.** The first `streamQuery` /
39
+ `getAvailableModels` call triggers `initialize()`. Multiple parallel
40
+ callers **must** share a single init promise. See:
41
+ - `claude/environment.ts::setupEnvironmentOnce`
42
+ - `opencode/server.ts::ensureClient`
43
+
44
+ ### 2.2 `index.ts` — registry & lifecycle
45
+
46
+ Two instance tiers:
47
+
48
+ | Tier | Factory | Used for |
49
+ |--------------------|-------------------------------|-------------------------------------------|
50
+ | Global singleton | `getEngine(type)` | Non-streaming ops: `models:list`, settings|
51
+ | Per-project | `getProjectEngine(projectId, type)` | Streaming chat — isolated per-project|
52
+
53
+ Cleanup:
54
+ - `disposeProjectEngines(projectId)` when a project closes.
55
+ - `disposeAllEngines()` at server shutdown — also calls
56
+ `disposeOpenCodeClient()`. Pattern: when an adapter owns a shared
57
+ subprocess, expose `disposeXxxClient()` from `adapters/<name>/index.ts`
58
+ and call it from `disposeAllProjectEngines()` in `index.ts`.
59
+
60
+ ### 2.3 `EngineOutput` — the event contract
61
+
62
+ In `shared/types/unified/stream.ts`:
63
+
64
+ ```ts
65
+ type EngineOutput =
66
+ | UserMessage // persisted to DB
67
+ | AssistantMessage // persisted to DB
68
+ | ReasoningMessage // persisted to DB
69
+ | CompactBoundaryMessage
70
+ | StreamEvent // transient: 'start' | 'stop' | 'delta'
71
+ | ResultEvent // transient: success / error_max_turns / etc.
72
+ | SystemInitEvent // transient: model + tools + mcpServers
73
+ | RateLimitEvent; // transient
74
+ ```
75
+
76
+ `stream-manager.ts` discriminates on `output.type`:
77
+
78
+ | `type` | Routing |
79
+ |----------------|---------------------------------------------------------|
80
+ | `user`/`assistant`/`reasoning`/`compact_boundary` | save DB + emit `chat:message` |
81
+ | `stream_event` | forward to frontend for live typing (`chat:partial`) |
82
+ | `result` | extract metadata + emit `chat:stream-finished` |
83
+ | `system_init` | emit MCP-failure notification if any |
84
+ | `rate_limit` | emit `chat:notification` |
85
+
86
+ > **Strict rule:** do not invent new types. If an SDK has an event that
87
+ > needs to be propagated, **extend** the union in
88
+ > `shared/types/unified/stream.ts` first, teach `stream-manager` how to
89
+ > route it, and only then emit it from the adapter.
90
+
91
+ ### 2.4 `EngineQueryOptions`
92
+
93
+ ```ts
94
+ interface EngineQueryOptions {
95
+ projectPath: string;
96
+ prompt: UserMessage;
97
+ resume?: string; // SDK session id for resume / fork
98
+ forkSession?: boolean;
99
+ maxTurns?: number;
100
+ providerSlug: string; // 'anthropic', 'openai', etc — required for opencode
101
+ modelId: string; // 'claude-opus-4-7', 'gpt-5', etc
102
+ includePartialMessages?: boolean;
103
+ abortController?: AbortController;
104
+ accountId?: number; // override credential for a single stream
105
+ mcpContext?: McpExecutionContext; // { projectId, chatSessionId, streamId }
106
+ }
107
+ ```
108
+
109
+ `mcpContext` is bound into the MCP handler so a tool call from project A
110
+ **cannot** write into project B. Always forward it: see `claude/stream.ts`
111
+ calling `getEnabledMcpServers(options.mcpContext)`.
112
+
113
+ ### 2.5 What an adapter **MUST NOT** do
114
+
115
+ - ❌ Call `ws.emit.*` — that is the stream-manager's job.
116
+ - ❌ Touch chat / message DB (`messageQueries`, `sessionQueries`) —
117
+ persistence belongs to the stream-manager. Adapters **may** read
118
+ credentials via `engineQueries`.
119
+ - ❌ Mutate `process.env` or call `process.chdir()` — pass env & cwd via
120
+ SDK options. Many projects stream concurrently.
121
+ - ❌ Define shared types inline — extend `shared/types/unified/*`.
122
+ - ❌ Use `console.*` — use `debug` from `$shared/utils/logger` with
123
+ category `'engine'`, `'chat'`, or `'mcp'`.
124
+ - ❌ **Build a new MCP HTTP server for the adapter.** Use the existing
125
+ `backend/mcp/remote-server.ts` and add a `getXxxMcpConfig()` helper in
126
+ `backend/mcp/config.ts` returning the URL in the engine's expected
127
+ shape. New MCP servers are added via `defineServer()` — never via a
128
+ parallel HTTP listener.
129
+ - ❌ **Create per-account isolated home directories** to multiplex two
130
+ accounts into the same CLI's shared dotfile. Snapshot the CLI's auth
131
+ file into `engine_accounts.credential` on login; write the chosen
132
+ account's snapshot back into the shared location on switch. See §9.13.
133
+
134
+ ### 2.6 Standard files in each adapter
135
+
136
+ Adapters follow a fixed file taxonomy. **Mandatory** files exist in every
137
+ adapter; **optional** files may be omitted, but when present they MUST use
138
+ the canonical name below — never a synonym (`auth.ts`, `provider-catalog.ts`,
139
+ etc.). This keeps `git grep` and the README's quick-reference rows usable.
140
+
141
+ ```
142
+ adapters/<name>/
143
+ ├── index.ts ← MANDATORY re-exports only, NO logic
144
+ ├── stream.ts ← MANDATORY class implements AIEngine
145
+ ├── models.ts ← MANDATORY static EngineModel[] OR dynamic fetcher
146
+ ├── message-converter.ts ← MANDATORY SDK message → EngineOutput (pure)
147
+ ├── error-handler.ts ← MANDATORY SDK error → user-facing string
148
+ ├── credential.ts? ← OPTIONAL credential parse / auth-blob swap (codex, qwen)
149
+ ├── environment.ts? ← OPTIONAL env / dotfile setup (claude, qwen)
150
+ ├── server.ts? ← OPTIONAL subprocess + client lifecycle (opencode)
151
+ ├── config.ts? ← OPTIONAL runtime config builder (opencode)
152
+ ├── presets.ts? ← OPTIONAL multi-provider/region preset catalog (qwen, opencode)
153
+ └── session-fork.ts? ← OPTIONAL on-disk session fork workaround (codex, qwen)
154
+ ```
155
+
156
+ Naming rules — strict, even when an SDK's local jargon differs:
157
+
158
+ | File | Owns |
159
+ |-------------------|-----------------------------------------------------------------------|
160
+ | `credential.ts` | Parse `engine_accounts.credential` (JSON wrapper or raw key); for shared-CLI engines, materialise the auth-blob into the dotfile and snapshot it back. **Never** name this `auth.ts` — credentials are the unified concept (see §9.13). |
161
+ | `error-handler.ts`| Export `handleStreamError(error: unknown, ...): void` that swallows abort errors and re-throws everything else as a sanitised `Error`. Required even when the body is short — `OpenCodeEngine` previously inlined ~50 lines into the catch block; that pattern is no longer accepted. |
162
+ | `presets.ts` | Multi-provider/region picker catalog (Qwen's DashScope/OpenRouter/Fireworks; OpenCode's models.dev cache). Multi-provider engines that lacked a `presets.ts` (OpenCode used to call this `config.ts`) have been migrated. |
163
+ | `config.ts` | Runtime config builder ONLY — turning DB providers + accounts into env vars / spawn options. Catalog data goes in `presets.ts`. |
164
+
165
+ Important conventions:
166
+ - `message-converter.ts` is generally pure. If you need per-stream state
167
+ (e.g. tracking "is the reasoning block already closed?"), expose a
168
+ **factory** `createSdkMessageConverter()` returning a stateful converter
169
+ — see Claude.
170
+ - Tool names **must** be canonicalised via `toCanonicalToolName(...)`
171
+ (`shared/types/unified/tool.ts`) so the frontend renders the same UI for
172
+ tools that have different names across SDKs.
173
+ - `cancel()` ordering: **abort the local controller first**, **then** RPC
174
+ to the SDK/server. RPCs can hang; the local abort cuts the `for await`
175
+ loop deterministically. See `OpenCodeEngine.cancel`,
176
+ `ClaudeCodeEngine.cancel`, `CopilotEngine.cancel`.
177
+ - Dynamic-catalog fetchers in `models.ts` MUST return `EngineModel[]` and
178
+ use `[]` as the failure sentinel (network, auth, parse error). Do **not**
179
+ return `null` — both `fetchOpenCodeModels` and `fetchQwenModels` return
180
+ `[]` on failure so the picker renders empty rather than a stale catalog.
181
+
182
+ ---
183
+
@@ -0,0 +1,150 @@
1
+ [← Engine adapter guide](../README.md)
2
+
3
+ ## 8. End-to-end checklist for adding a new engine
4
+
5
+ The steps below are the same pattern used when the **`copilot`**
6
+ (`@github/copilot-sdk`) adapter was added to the repo. Use it as a
7
+ blueprint for the next engine you add.
8
+
9
+ ### Stage 1 — Shared types
10
+
11
+ - [ ] `shared/types/unified/common.ts`: add `'newengine'` to `EngineType`.
12
+ - [ ] `shared/types/unified/engine.ts`: add `'newengine'` to `EngineInfo.type`.
13
+ - [ ] `shared/types/unified/message.ts`: add `'newengine'` to `MessageEngine.type`.
14
+ - [ ] `shared/constants/engines.ts`: add an entry in `ENGINES[]`
15
+ (`type, name, description, icon.light, icon.dark`).
16
+ - [ ] `backend/engine/adapters/newengine/models.ts`: own the catalog. Static
17
+ engines export a `NEWENGINE_MODELS: EngineModel[]` array; dynamic
18
+ engines export a fetcher (`fetchNewengineModels(...)`) consumed by
19
+ `getAvailableModels()`. Don't add anything to `shared/constants/engines.ts`
20
+ for the catalog itself — the frontend loads it via `models:list`.
21
+ - [ ] (Optional) `backend/engine/adapters/newengine/presets.ts` if the
22
+ engine needs provider/region/BYOK presets exposed to the UI.
23
+ Mirror `qwen/presets.ts`: keep runtime values in the adapter,
24
+ export wire types from `shared/types/unified/engine.ts`, and ship
25
+ a WS endpoint (see Stage 4) — never import these from frontend
26
+ via `$backend`.
27
+
28
+ ### Stage 2 — Adapter `backend/engine/`
29
+
30
+ Refer to §2.6 for the full file taxonomy. Every adapter ships these five
31
+ mandatory files; optional files use the canonical names from §2.6.
32
+
33
+ - [ ] Create `backend/engine/adapters/newengine/`
34
+ - [ ] `index.ts` (mandatory) → `export { NewEngineEngine } from './stream';`
35
+ (+ `disposeXxxClient` if there is a subprocess).
36
+ - [ ] `stream.ts` (mandatory) → class `NewEngineEngine implements AIEngine`.
37
+ Pick a template: `claude/stream.ts` (in-process SDK),
38
+ `opencode/stream.ts` (subprocess), `copilot/stream.ts` (in-process
39
+ with construction-time credential), or `qwen/stream.ts` (CLI subprocess
40
+ via SDK with auth-blob swap).
41
+ - [ ] `models.ts` (mandatory) → static `NEWENGINE_MODELS: EngineModel[]`
42
+ OR `fetchNewengineModels(...): Promise<EngineModel[]>` (dynamic;
43
+ return `[]` on failure — see §4.5).
44
+ - [ ] `message-converter.ts` (mandatory) → pure functions SDK → `EngineOutput`.
45
+ Use `toCanonicalToolName()` for tool names.
46
+ - [ ] `error-handler.ts` (mandatory) → exports `handleStreamError(error,
47
+ ...): void` (and any helper formatters specific to the SDK's error
48
+ payload — see `opencode/error-handler.ts::formatSessionError` for the
49
+ pattern).
50
+ - [ ] `credential.ts` / `environment.ts` / `server.ts` / `config.ts` /
51
+ `presets.ts` / `session-fork.ts` (optional; canonical names only).
52
+ - [ ] `backend/engine/index.ts`: import + add a case in
53
+ `createEngine(type)`. If there is a shared subprocess, call
54
+ `disposeXxxClient()` from `disposeAllProjectEngines()`.
55
+
56
+ ### Stage 3 — Database (if a default provider needs to be seeded)
57
+
58
+ - [ ] Add a new migration in `backend/database/migrations/` (e.g. seed
59
+ `('newengine', 'vendor', 'Vendor', NULL, NULL, '{}', 1)` into
60
+ `engine_providers`). **Do not change the schema** — the tables
61
+ are already generic.
62
+
63
+ ### Stage 4 — WebSocket `engine:newengine-*`
64
+
65
+ - [ ] Create `backend/ws/engine/newengine/`:
66
+ - `status.ts` — `engine:newengine-status` (`installed`, `version`, etc).
67
+ - `accounts.ts` or `providers.ts` — account/provider CRUD:
68
+ - List, add, switch, delete, rename.
69
+ - Setup flow: PTY (Claude-style) OR direct API-key/PAT input
70
+ (OpenCode/Copilot-style) depending on the SDK's auth mechanism.
71
+ - (Optional) `presets.ts` — `engine:newengine-presets-list` if the
72
+ adapter has a `presets.ts` module. See `backend/ws/engine/qwen/presets.ts`.
73
+ - `index.ts` — merge the sub-router.
74
+ - [ ] `backend/ws/engine/index.ts`: `.merge(newengineEngineRouter)`.
75
+ - [ ] `backend/ws/chat/stream.ts`: add the `'newengine'` literal to the
76
+ typebox schema for `engine.type`.
77
+ - [ ] `backend/ws/settings/crud.ts`: add the `'newengine'` literal to the
78
+ `models:list` typebox schema.
79
+
80
+ ### Stage 5 — Frontend store
81
+
82
+ - [ ] Add `frontend/stores/features/newengine-accounts.svelte.ts` (or
83
+ `newengine-providers.svelte.ts` following OpenCode's style if the
84
+ engine is multi-provider). Mirror the pattern of
85
+ `claudeAccountsStore` / `copilotAccountsStore` / `opencodeProvidersStore`.
86
+
87
+ ### Stage 6 — Settings → Engines
88
+
89
+ - [ ] Add a panel to `AIEnginesSettings.svelte`: the card appears
90
+ automatically since `ENGINES` already has the new entry. Implement
91
+ the setup flow:
92
+ - Load status via `ws.http('engine:newengine-status', {})`.
93
+ - Subscribe to server-emit events for login progress.
94
+ - After save: `newengineStore.refresh()` +
95
+ `modelStore.refreshModels('newengine')`.
96
+
97
+ ### Stage 7 — Settings → System Tools
98
+
99
+ - [ ] `backend/engine/install-recipes.ts`:
100
+ - Add `'newengine'` to `ToolId`.
101
+ - Write `resolveNewEngineRecipe()` (winget/brew/curl pipe — whatever the
102
+ SDK needs to install its CLI).
103
+ - Add a case in `resolveRecipe()`.
104
+ - [ ] `backend/ws/system-tools/status.ts` & `install.ts`: add
105
+ `'newengine'` to `TOOL_UNION`.
106
+ - [ ] `frontend/components/settings/system-tools/SystemToolsSettings.svelte`:
107
+ `<ToolInstallCard tool="newengine" title="NewEngine CLI" description="..." />`.
108
+
109
+ ### Stage 8 — Chat input
110
+
111
+ If the engine uses one-account-per-engine (Claude/Copilot style), wire it
112
+ into `EngineModelPicker.svelte`:
113
+
114
+ - [ ] Import the new store + add a branch to `accountsForEngine`,
115
+ `accountPickerLabel`, `showAccountPicker`, and the two
116
+ `$effect` blocks (auto-fetch and auto-select active account).
117
+ - [ ] No new dropdown markup is required — the existing dropdown iterates
118
+ `accountsForEngine`.
119
+
120
+ If the engine is multi-provider (OpenCode style) the picker logic is
121
+ heavier — copy the OpenCode block.
122
+
123
+ Other auto wiring:
124
+ - [ ] The engine tab appears automatically in `EngineModelPicker` from
125
+ `ENGINES`.
126
+ - [ ] Verify: select engine → model list appears → send message → stream
127
+ runs.
128
+
129
+ ### Stage 9 — Manual QA
130
+
131
+ From the project root:
132
+
133
+ ```sh
134
+ bun run check && bun run lint
135
+ ```
136
+
137
+ Then the minimum UI scenarios that must pass:
138
+
139
+ - [ ] Settings → System Tools → Install NewEngine CLI → exit 0.
140
+ - [ ] Settings → Engines → NewEngine → Add Account → status `Installed,
141
+ Active account: <name>`.
142
+ - [ ] Chat input → pick NewEngine + model → send a message → assistant
143
+ replies → cancel mid-stream → idle → send again → resume works.
144
+ - [ ] AskUserQuestion (if the SDK supports it) → appears in UI → submit
145
+ answer → stream continues.
146
+ - [ ] Restart Clopen → state survives (account, provider, last-used model
147
+ in chat).
148
+
149
+ ---
150
+