@myrialabs/clopen 0.4.21 → 0.4.23
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/README.md +2 -1
- package/backend/artifacts/generate.ts +11 -5
- package/backend/auth/permissions.ts +8 -8
- package/backend/engine/README.md +11 -8
- package/backend/engine/adapters/codex/error-handler.ts +1 -1
- package/backend/engine/adapters/qwen/error-handler.ts +1 -1
- package/backend/engine/docs/adapter-contract.md +66 -2
- package/backend/engine/docs/adding-an-engine.md +46 -7
- package/backend/engine/docs/frontend-and-chat.md +80 -17
- package/backend/engine/docs/lessons-learned.md +126 -7
- package/backend/engine/docs/quick-reference.md +12 -3
- package/backend/engine/docs/{system-tools.md → stack.md} +35 -6
- package/backend/engine/docs/websocket-routes.md +54 -15
- package/backend/engine/install-runner.ts +4 -4
- package/backend/engine/resolve-model.ts +87 -0
- package/backend/engine/structured-helpers.test.ts +64 -0
- package/backend/engine/structured-helpers.ts +105 -13
- package/backend/mcp/README.md +32 -11
- package/backend/mcp/internal/config.ts +3 -20
- package/backend/mcp/internal/servers/browser-automation/actions/console.ts +65 -0
- package/backend/mcp/internal/servers/browser-automation/actions/dom-analyze.ts +202 -0
- package/backend/mcp/internal/servers/browser-automation/actions/index.ts +31 -0
- package/backend/mcp/internal/servers/browser-automation/actions/input.ts +332 -0
- package/backend/mcp/internal/servers/browser-automation/actions/inspect.ts +158 -0
- package/backend/mcp/internal/servers/browser-automation/actions/navigation.ts +157 -0
- package/backend/mcp/internal/servers/browser-automation/actions/shared.ts +60 -0
- package/backend/mcp/internal/servers/browser-automation/actions/tabs.ts +157 -0
- package/backend/mcp/internal/servers/browser-automation/actions/types.ts +79 -0
- package/backend/mcp/internal/servers/browser-automation/context.ts +100 -0
- package/backend/mcp/internal/servers/browser-automation/description.ts +60 -0
- package/backend/mcp/internal/servers/browser-automation/format.ts +62 -0
- package/backend/mcp/internal/servers/browser-automation/index.ts +36 -784
- package/backend/mcp/internal/servers/browser-automation/paths.ts +71 -0
- package/backend/mcp/internal/servers/browser-automation/runner.ts +269 -0
- package/backend/mcp/internal/servers/browser-automation/schema.ts +26 -0
- package/backend/preview/browser/browser-console-manager.ts +310 -156
- package/backend/preview/browser/browser-dialog-handler.ts +45 -16
- package/backend/preview/browser/browser-host-bridge.ts +471 -0
- package/backend/preview/browser/browser-interaction-handler.ts +868 -297
- package/backend/preview/browser/browser-mcp-control.ts +7 -2
- package/backend/preview/browser/browser-native-ui-handler.ts +455 -81
- package/backend/preview/browser/browser-navigation-tracker.ts +56 -0
- package/backend/preview/browser/browser-pool.ts +83 -9
- package/backend/preview/browser/browser-preview-service.ts +432 -53
- package/backend/preview/browser/browser-tab-manager.ts +16 -16
- package/backend/preview/browser/browser-video-capture.ts +1334 -386
- package/backend/preview/browser/capture-profile.ts +213 -0
- package/backend/preview/browser/element-locator.ts +357 -0
- package/backend/preview/browser/frame-targeting.ts +92 -0
- package/backend/preview/browser/scripts/audio-stream.ts +258 -78
- package/backend/preview/browser/scripts/host-bridge.ts +1277 -0
- package/backend/preview/browser/scripts/video-stream.ts +803 -177
- package/backend/preview/browser/types.ts +397 -37
- package/backend/utils/cli.ts +1 -1
- package/backend/utils/path-enrich.ts +2 -2
- package/backend/ws/README.md +1 -1
- package/backend/ws/artifacts/generate.ts +2 -1
- package/backend/ws/engine/codex/accounts.ts +1 -1
- package/backend/ws/engine/codex/status.ts +1 -1
- package/backend/ws/git/branch-name.ts +11 -5
- package/backend/ws/git/commit-message.ts +11 -5
- package/backend/ws/index.ts +3 -3
- package/backend/ws/preview/browser/host.ts +95 -0
- package/backend/ws/preview/browser/interact.ts +204 -10
- package/backend/ws/preview/browser/native-ui.ts +31 -1
- package/backend/ws/preview/browser/tab-info.ts +10 -1
- package/backend/ws/preview/browser/tab.ts +43 -0
- package/backend/ws/preview/browser/webcodecs.ts +180 -53
- package/backend/ws/preview/index.ts +58 -1
- package/backend/ws/{system-tools → stack}/access.ts +1 -1
- package/backend/ws/stack/index.ts +16 -0
- package/backend/ws/{system-tools → stack}/install.ts +7 -7
- package/backend/ws/{system-tools → stack}/status.ts +7 -7
- package/dist/assets/{index-CEGW8vEt.js → index-DH_GO0Lf.js} +1 -1
- package/dist/assets/{index-B8YRz8wG.js → index-igSQ3JaM.js} +1 -1
- package/dist/assets/main-BD3-qPfT.css +1 -0
- package/dist/assets/{main-D-2ByODy.js → main-D-d8SFfW.js} +384 -358
- package/dist/assets/preview-video.worker-DcpDhCWL.js +1 -0
- package/dist/index.html +2 -2
- package/package.json +1 -1
- package/shared/types/stores/settings.ts +6 -0
- package/backend/mcp/internal/servers/browser-automation/actions.ts +0 -159
- package/backend/mcp/internal/servers/browser-automation/browser.ts +0 -375
- package/backend/mcp/internal/servers/browser-automation/inspection.ts +0 -495
- package/backend/ws/system-tools/index.ts +0 -16
- package/dist/assets/main-D8I0MfRQ.css +0 -1
package/README.md
CHANGED
|
@@ -58,6 +58,7 @@ A complete development environment designed around AI-assisted workflows, built
|
|
|
58
58
|
|
|
59
59
|
- **Multi-Engine Support** — Switch between Claude Code, OpenCode, Codex, GitHub Copilot, Qwen Code, Pi, Cline, and Cursor as your AI engine, per session
|
|
60
60
|
- **Multi-Account Per Engine** — Manage multiple accounts per engine (personal, work, or team) and switch between them instantly per chat session
|
|
61
|
+
- **Reasoning Effort Control** — Dial a model's thinking level right from the chat input, using that engine's own levels. Set a default per model in Settings, and the choice is remembered and synced with everyone in the session
|
|
61
62
|
- **Integrated Terminal** — Multi-tab xterm.js terminal with full keyboard control and complete ANSI/VT support, right inside your workspace
|
|
62
63
|
- **Full Git Management** — Stage, commit, branch, push, pull, stash, log, and resolve conflicts, all from a clean UI
|
|
63
64
|
- **Real Browser Preview** — A live browser preview streams directly into your workspace. Interact with your app manually, or let the AI drive: clicking, typing, and scrolling for autonomous visual testing
|
|
@@ -117,7 +118,7 @@ On first launch, a setup wizard guides you through:
|
|
|
117
118
|
1. **Authentication mode** — Choose between **No Login** (no authentication required, ideal for personal/local use) or **With Login** (login with Personal Access Token, supports team collaboration)
|
|
118
119
|
2. **Admin account** — If With Login mode is selected, create your admin account and save the generated PAT
|
|
119
120
|
3. **Stack** — Install Git, Chrome, Cloudflared, and any AI engine you don't have yet — straight from the wizard, no terminal needed
|
|
120
|
-
4. **AI Engines** — Check installation status for
|
|
121
|
+
4. **AI Engines** — Check installation status for every engine and sign in to the ones you'll use. An engine that isn't installed yet links straight back to the Stack step
|
|
121
122
|
5. **Preferences** — Set dark mode, font size, sound notifications, and message layout (Classic cards or Compact lines)
|
|
122
123
|
|
|
123
124
|
You can change the authentication mode anytime in **Settings → Security → Authentication**.
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import { initializeEngine } from '$backend/engine';
|
|
14
|
+
import { resolveGenerationTarget } from '$backend/engine/resolve-model';
|
|
14
15
|
import { getClopenDir } from '$backend/utils/paths';
|
|
15
16
|
import type { EngineType } from '$shared/types/unified';
|
|
16
17
|
import { debug } from '$shared/utils/logger';
|
|
@@ -69,7 +70,8 @@ const GUIDANCE: Record<GeneratableType, string> = {
|
|
|
69
70
|
|
|
70
71
|
export interface GenerateModel {
|
|
71
72
|
engine: EngineType;
|
|
72
|
-
|
|
73
|
+
/** Hint only — the provider is re-derived from the engine catalog. */
|
|
74
|
+
providerSlug?: string;
|
|
73
75
|
modelId: string;
|
|
74
76
|
/** Optional cwd for the engine process; defaults to the Clopen data dir. */
|
|
75
77
|
projectPath?: string;
|
|
@@ -92,14 +94,18 @@ ${purpose.trim()}
|
|
|
92
94
|
|
|
93
95
|
Always write the draft in English, regardless of the language of the purpose. Be specific and immediately usable.`;
|
|
94
96
|
|
|
95
|
-
|
|
97
|
+
// The caller's providerSlug/account can be stale (see resolve-model.ts).
|
|
98
|
+
const target = await resolveGenerationTarget(engine, model.modelId, model.providerSlug);
|
|
99
|
+
const accountId = model.accountId ?? target.accountId;
|
|
100
|
+
|
|
101
|
+
debug.log('artifacts', `✨ Generating ${type} draft via ${model.engine}/${target.providerSlug}/${target.modelId}`);
|
|
96
102
|
|
|
97
103
|
return engine.generateStructured<Record<string, unknown>>({
|
|
98
104
|
prompt,
|
|
99
|
-
providerSlug:
|
|
100
|
-
modelId:
|
|
105
|
+
providerSlug: target.providerSlug,
|
|
106
|
+
modelId: target.modelId,
|
|
101
107
|
schema: SCHEMAS[type],
|
|
102
108
|
projectPath: model.projectPath || getClopenDir(),
|
|
103
|
-
accountId
|
|
109
|
+
...(accountId != null && { accountId })
|
|
104
110
|
});
|
|
105
111
|
}
|
|
@@ -43,12 +43,12 @@ export const ADMIN_ONLY_ROUTES = new Set([
|
|
|
43
43
|
'settings:update-batch',
|
|
44
44
|
'system:run-update',
|
|
45
45
|
'system:clear-data',
|
|
46
|
-
//
|
|
47
|
-
'
|
|
48
|
-
'
|
|
49
|
-
'
|
|
50
|
-
'
|
|
51
|
-
'
|
|
46
|
+
// Stack — binary installation is an admin-only operation.
|
|
47
|
+
'stack:status',
|
|
48
|
+
'stack:status-all',
|
|
49
|
+
'stack:install-start',
|
|
50
|
+
'stack:install-cancel',
|
|
51
|
+
'stack:install-session',
|
|
52
52
|
// Engine — account/provider mutations are global system credentials and
|
|
53
53
|
// must only be changed by admins. Read-only routes (status, *-list) stay
|
|
54
54
|
// open so any authenticated user can see what is configured.
|
|
@@ -121,7 +121,7 @@ export const ADMIN_ONLY_ROUTES = new Set([
|
|
|
121
121
|
'tunnel:local:stop',
|
|
122
122
|
// External MCP — installing/removing servers from the official registry is a
|
|
123
123
|
// global, system-wide operation (it applies to every engine and project), so
|
|
124
|
-
// the whole surface is admin-only, mirroring
|
|
124
|
+
// the whole surface is admin-only, mirroring Stack and Engines.
|
|
125
125
|
'mcp:catalog',
|
|
126
126
|
'mcp:list',
|
|
127
127
|
'mcp:parse-config',
|
|
@@ -139,7 +139,7 @@ export const ADMIN_ONLY_ROUTES = new Set([
|
|
|
139
139
|
'mcp:call-tool',
|
|
140
140
|
// Agent Skills — creating/importing/installing skills writes to the shared
|
|
141
141
|
// canonical store and applies to every engine, so the whole surface is
|
|
142
|
-
// admin-only, mirroring MCP and
|
|
142
|
+
// admin-only, mirroring MCP and Stack.
|
|
143
143
|
'skills:list',
|
|
144
144
|
'skills:get',
|
|
145
145
|
'skills:create',
|
package/backend/engine/README.md
CHANGED
|
@@ -4,7 +4,7 @@ This folder is the **boundary** between Clopen and the AI SDKs that drive
|
|
|
4
4
|
streaming chat. The adapters today: **`claude`**
|
|
5
5
|
(`@anthropic-ai/claude-agent-sdk`), **`opencode`** (`@opencode-ai/sdk`),
|
|
6
6
|
**`copilot`** (`@github/copilot-sdk`), **`codex`** (`@openai/codex-sdk`),
|
|
7
|
-
**`qwen`** (`@qwen-code/
|
|
7
|
+
**`qwen`** (`@qwen-code/sdk`), **`pi`**
|
|
8
8
|
(`@earendil-works/pi-coding-agent`), **`cline`** (`@cline/sdk`), and
|
|
9
9
|
**`cursor`** (`@cursor/sdk`). Every
|
|
10
10
|
adapter follows the same shape so that the rest of the system outside this
|
|
@@ -54,9 +54,9 @@ map, then jump to the area you need.
|
|
|
54
54
|
1. [Architecture map](#1-architecture-map) — the layers and the two design pitfalls to read before proposing new infrastructure (below).
|
|
55
55
|
2. [Adapter contract](./docs/adapter-contract.md) — the `AIEngine` interface, `EngineOutput`, `EngineQueryOptions`, the standard adapter file taxonomy, and what an adapter must NOT do.
|
|
56
56
|
3. [Database](./docs/database.md) — `engine_providers` + `engine_accounts`, `engineQueries`, and how each adapter reads credentials.
|
|
57
|
-
4. [WebSocket routes](./docs/websocket-routes.md) — `engine:*`, `
|
|
58
|
-
5. [Frontend & chat integration](./docs/frontend-and-chat.md) — Settings → Engines / Stack, the model picker, the send path, reasoning/attachments/AskUserQuestion.
|
|
59
|
-
6. [Stack](./docs/
|
|
57
|
+
4. [WebSocket routes](./docs/websocket-routes.md) — `engine:*`, `stack:*`, `models:list`, `chat:stream`, and the Restart-Server pattern.
|
|
58
|
+
5. [Frontend & chat integration](./docs/frontend-and-chat.md) — Settings → Engines / Stack, the model picker, the send path, reasoning effort/attachments/AskUserQuestion.
|
|
59
|
+
6. [Stack](./docs/stack.md) — registering a host tool or on-demand engine SDK in `install-recipes.ts` + the install runner.
|
|
60
60
|
7. [Artifacts & Access](./docs/artifacts.md) — the extension layer (Skills, Commands, Subagents, Instructions, Permissions, Profiles, MCP), the capability matrix, and the `artifact-sync.ts` seam adapters call at stream start.
|
|
61
61
|
8. [Adding a new engine](./docs/adding-an-engine.md) — the end-to-end, stage-by-stage checklist.
|
|
62
62
|
9. [Lessons learned](./docs/lessons-learned.md) — §10 pitfalls (tool name/input canonicalisation, fork session, MCP reuse, auth-blob swap, sub-agent routing, OpenCode v1/v2, structured output, …).
|
|
@@ -71,15 +71,15 @@ map, then jump to the area you need.
|
|
|
71
71
|
│ │
|
|
72
72
|
│ Settings → Engines Settings → Stack Chat Input │
|
|
73
73
|
│ ───────────────────── ────────────────────── ────────────── │
|
|
74
|
-
│ AIEnginesSettings+panels/
|
|
74
|
+
│ AIEnginesSettings+panels/ StackSettings… EngineModel… │
|
|
75
75
|
│ │ │ │ │
|
|
76
76
|
│ ├─ claudeAccountsStore └─ ws.http( ├─ model │
|
|
77
|
-
│ ├─ copilotAccountsStore '
|
|
77
|
+
│ ├─ copilotAccountsStore 'stack:…') │ Store │
|
|
78
78
|
│ ├─ opencodeProvidersStore └─ chat │
|
|
79
79
|
│ └─ modelStore ModelState│
|
|
80
80
|
│ │ │ │ │ │ │
|
|
81
81
|
│ ▼ ▼ ▼ ▼ ▼ │
|
|
82
|
-
│ ws.http('engine:*') ws.http('
|
|
82
|
+
│ ws.http('engine:*') ws.http('stack:*') ws.emit('chat:…') │
|
|
83
83
|
└──────────────────────────────┬────────────────────────────────────────┘
|
|
84
84
|
│ WebSocket (ws-server router)
|
|
85
85
|
┌──────────────────────────────▼────────────────────────────────────────┐
|
|
@@ -89,7 +89,7 @@ map, then jump to the area you need.
|
|
|
89
89
|
│ status.ts, accounts.ts status.ts, providers.ts │
|
|
90
90
|
│ backend/ws/engine/copilot/ │
|
|
91
91
|
│ status.ts, accounts.ts │
|
|
92
|
-
│ backend/ws/
|
|
92
|
+
│ backend/ws/stack/ backend/ws/chat/stream.ts │
|
|
93
93
|
│ status.ts, install.ts backend/ws/settings/crud.ts │
|
|
94
94
|
│ │ │ │
|
|
95
95
|
│ ▼ ▼ │
|
|
@@ -101,6 +101,9 @@ map, then jump to the area you need.
|
|
|
101
101
|
│ │ sdk-loader.ts on-demand loader (~/.clopen/stack/…) │ │
|
|
102
102
|
│ │ install-recipes.ts host-tool + engine-SDK install recipes│ │
|
|
103
103
|
│ │ install-runner.ts spawns recipe, streams logs over WS │ │
|
|
104
|
+
│ │ bootstrap-default-engine fresh install → auto-install OpenCode │ │
|
|
105
|
+
│ │ resolve-model.ts catalog-verified provider/model/acct │ │
|
|
106
|
+
│ │ structured-helpers.ts prompt + tolerant JSON extraction │ │
|
|
104
107
|
│ │ adapters/<name>/ │ │
|
|
105
108
|
│ │ index.ts public surface (re-exports only) │ │
|
|
106
109
|
│ │ stream.ts class implements AIEngine │ │
|
|
@@ -24,7 +24,7 @@ export function handleStreamError(error: unknown): void {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
if (error.message.includes('ENOENT') || error.message.includes('spawn codex')) {
|
|
27
|
-
throw new Error('Codex CLI not found. Install it via Settings →
|
|
27
|
+
throw new Error('Codex CLI not found. Install it via Settings → Stack (or run `bun add -g @openai/codex`).');
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
if (error.message.includes('OPENAI_API_KEY') || error.message.includes('not authenticated')) {
|
|
@@ -30,7 +30,7 @@ export function handleStreamError(error: unknown, stderrTail?: string): void {
|
|
|
30
30
|
const tailLower = tail.toLowerCase();
|
|
31
31
|
|
|
32
32
|
if (error.message.includes('ENOENT') || error.message.includes('spawn qwen')) {
|
|
33
|
-
throw new Error('Qwen Code CLI not found. Install it via Settings →
|
|
33
|
+
throw new Error('Qwen Code CLI not found. Install it via Settings → Stack (or `bun add -g @qwen-code/qwen-code`).');
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
if (
|
|
@@ -26,7 +26,7 @@ export interface AIEngine {
|
|
|
26
26
|
}
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
Four invariants:
|
|
30
30
|
|
|
31
31
|
1. **`streamQuery` is the only streaming output path.** It is an
|
|
32
32
|
`AsyncGenerator<EngineOutput>`. The adapter translates SDK events into
|
|
@@ -40,6 +40,14 @@ Three invariants:
|
|
|
40
40
|
callers **must** share a single init promise. See:
|
|
41
41
|
- `claude/environment.ts::setupEnvironmentOnce`
|
|
42
42
|
- `opencode/server.ts::ensureClient`
|
|
43
|
+
4. **`generateStructured` callers resolve their target first.** The
|
|
44
|
+
`providerSlug` a client hands to a one-shot JSON call is a *hint*, not
|
|
45
|
+
truth — every call site pipes it through
|
|
46
|
+
`resolveGenerationTarget(engine, modelId, providerHint)`
|
|
47
|
+
(`backend/engine/resolve-model.ts`) and uses what comes back. The engine's
|
|
48
|
+
own catalog is the only source of truth for which provider (and account) a
|
|
49
|
+
model belongs to. Skipping this "works" on the five engines that ignore the
|
|
50
|
+
slug and fails on OpenCode, Pi, and Cline. See §10.16 point 3.
|
|
43
51
|
|
|
44
52
|
### 2.2 `index.ts` — registry & lifecycle
|
|
45
53
|
|
|
@@ -98,7 +106,8 @@ interface EngineQueryOptions {
|
|
|
98
106
|
forkSession?: boolean;
|
|
99
107
|
maxTurns?: number;
|
|
100
108
|
providerSlug: string; // 'anthropic', 'openai', etc — required for opencode
|
|
101
|
-
modelId: string; // 'claude-opus-
|
|
109
|
+
modelId: string; // 'claude-opus-5', 'gpt-5', etc
|
|
110
|
+
reasoningEffort?: string; // native reasoning/thinking level for this turn
|
|
102
111
|
includePartialMessages?: boolean;
|
|
103
112
|
abortController?: AbortController;
|
|
104
113
|
accountId?: number; // override credential for a single stream
|
|
@@ -110,6 +119,61 @@ interface EngineQueryOptions {
|
|
|
110
119
|
**cannot** write into project B. Always forward it: see `claude/stream.ts`
|
|
111
120
|
calling `getEnabledMcpServers(options.mcpContext)`.
|
|
112
121
|
|
|
122
|
+
`reasoningEffort` is an **opaque, native-per-engine token** — there is no
|
|
123
|
+
cross-engine normalization. The adapter that produced the level in
|
|
124
|
+
`models.ts` is the one that consumes it in `stream.ts`; every other layer
|
|
125
|
+
(stream-manager, WS, frontend) just carries the string. `undefined` means
|
|
126
|
+
"no explicit choice" → the engine's own default applies. See §2.4a.
|
|
127
|
+
|
|
128
|
+
### 2.4a Reasoning effort — `EngineModel.capabilities.reasoningControl`
|
|
129
|
+
|
|
130
|
+
A model may advertise a reasoning/thinking control from its `models.ts`:
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
interface ReasoningControl {
|
|
134
|
+
levels: { value: string; label: string }[]; // ordered low → high
|
|
135
|
+
default: string; // mirrors the engine default
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Rules:
|
|
140
|
+
|
|
141
|
+
- **Capability-driven, not hardcoded.** The picker renders a level selector
|
|
142
|
+
**only** when the selected model carries `capabilities.reasoningControl`.
|
|
143
|
+
Omit the field and the UI hides the control entirely — that is how Qwen,
|
|
144
|
+
OpenCode, and Cline stay knob-less without a single `if (engine === …)`
|
|
145
|
+
anywhere in the frontend.
|
|
146
|
+
- **Levels are the SDK's own vocabulary.** Don't invent a shared
|
|
147
|
+
`low|medium|high` scale. Use `toReasoningOptions([...])` from
|
|
148
|
+
`$shared/constants/engines` to attach labels; `reasoningLevelLabel()` maps the
|
|
149
|
+
known tokens (`off`, `auto`/`adaptive`, `minimal` … `max`) and capitalizes
|
|
150
|
+
anything it doesn't recognise.
|
|
151
|
+
- **Derive from the catalog when the SDK reports it.** Copilot reads
|
|
152
|
+
`supportedReasoningEfforts` / `defaultReasoningEffort` off `ModelInfo`, Pi
|
|
153
|
+
reads `getSupportedThinkingLevels(model)`, Cursor reads the model's
|
|
154
|
+
`ModelParameterDefinition`. Only static catalogs (Claude, Codex) hardcode
|
|
155
|
+
the list.
|
|
156
|
+
- **The adapter clamps.** `streamQuery` must treat the incoming token as
|
|
157
|
+
untrusted — an unknown/stale value falls back to the engine default rather
|
|
158
|
+
than being forwarded to the SDK.
|
|
159
|
+
|
|
160
|
+
Where each engine's knob lives:
|
|
161
|
+
|
|
162
|
+
| Engine | SDK knob | Levels |
|
|
163
|
+
|---------------|-----------------------------------------|--------------------------------------------|
|
|
164
|
+
| `claude-code` | `thinking` + `effort` on `query()` | `off, auto, low, medium, high, xhigh, max` (static; `off` → `thinking: { type: 'disabled' }`, `auto` → adaptive with no `effort`) |
|
|
165
|
+
| `codex` | `modelReasoningEffort` (thread option) | `minimal, low, medium, high, xhigh` (static; reasoning-capable models only) |
|
|
166
|
+
| `copilot` | `SessionConfig.reasoningEffort` | from `ModelInfo.supportedReasoningEfforts` (dynamic) |
|
|
167
|
+
| `pi` | agent `thinkingLevel` | from `getSupportedThinkingLevels(model)` (dynamic; `clampThinkingLevel` on apply) |
|
|
168
|
+
| `cursor` | `ModelSelection.params[]` | from the model's reasoning-ish `ModelParameterDefinition` (dynamic) |
|
|
169
|
+
| `qwen`, `opencode`, `cline` | — (none exposed) | no `reasoningControl` → selector hidden |
|
|
170
|
+
|
|
171
|
+
Cursor is the one engine whose token is **not** a bare level: it encodes the
|
|
172
|
+
model-parameter id as `"<paramId>::<value>"` so `stream.ts` can rebuild a
|
|
173
|
+
`ModelSelection.params` entry without re-fetching the catalog. If a future SDK
|
|
174
|
+
needs more than a level name, follow that shape rather than adding a new field
|
|
175
|
+
to `EngineQueryOptions`.
|
|
176
|
+
|
|
113
177
|
### 2.5 What an adapter **MUST NOT** do
|
|
114
178
|
|
|
115
179
|
- ❌ Call `ws.emit.*` — that is the stream-manager's job.
|
|
@@ -11,8 +11,12 @@ blueprint for the next engine you add.
|
|
|
11
11
|
- [ ] `shared/types/unified/common.ts`: add `'newengine'` to `EngineType`.
|
|
12
12
|
- [ ] `shared/types/unified/engine.ts`: add `'newengine'` to `EngineInfo.type`.
|
|
13
13
|
- [ ] `shared/types/unified/message.ts`: add `'newengine'` to `MessageEngine.type`.
|
|
14
|
+
- [ ] `shared/constants/tool-icons.ts`: add the brand SVG to `TOOL_ICONS`
|
|
15
|
+
(`{ light, dark }`). This is the single source of truth — Settings →
|
|
16
|
+
Engines, Settings → Stack, the wizard, and the chat picker all read it.
|
|
14
17
|
- [ ] `shared/constants/engines.ts`: add an entry in `ENGINES[]`
|
|
15
|
-
(`type, name, description, icon
|
|
18
|
+
(`type, name, description, icon: TOOL_ICONS['newengine']`). The array's
|
|
19
|
+
order is the display order everywhere.
|
|
16
20
|
- [ ] **Exhaustive `Record<EngineType, …>` maps & unions — forgetting any is a
|
|
17
21
|
compile error, so `bun run check` after this step catches them all:**
|
|
18
22
|
- `shared/constants/engine-tools.ts`: add `'newengine'` to
|
|
@@ -31,6 +35,13 @@ blueprint for the next engine you add.
|
|
|
31
35
|
engines export a fetcher (`fetchNewengineModels(...)`) consumed by
|
|
32
36
|
`getAvailableModels()`. Don't add anything to `shared/constants/engines.ts`
|
|
33
37
|
for the catalog itself — the frontend loads it via `models:list`.
|
|
38
|
+
- [ ] (Optional) **Reasoning control.** If the SDK exposes a reasoning /
|
|
39
|
+
thinking / effort knob, attach `capabilities.reasoningControl`
|
|
40
|
+
(`{ levels, default }`) to each model that supports it — build the labels
|
|
41
|
+
with `toReasoningOptions([...])` from `$shared/constants/engines`, and
|
|
42
|
+
read the level list off the SDK payload when it reports one (Copilot, Pi,
|
|
43
|
+
Cursor) rather than hardcoding. Omit the field entirely when there is no
|
|
44
|
+
knob; the picker then hides the control. See §2.4a.
|
|
34
45
|
- [ ] (Optional) `backend/engine/adapters/newengine/presets.ts` if the
|
|
35
46
|
engine needs provider/region/BYOK presets exposed to the UI.
|
|
36
47
|
Mirror `qwen/presets.ts`: keep runtime values in the adapter,
|
|
@@ -47,7 +58,10 @@ mandatory files; optional files use the canonical names from §2.6.
|
|
|
47
58
|
> runtime dependency; it lives in `package.json` `devDependencies` (pinned
|
|
48
59
|
> exact) and is installed on demand into `~/.clopen/stack/engines`. In the
|
|
49
60
|
> adapter, reference the SDK's types only via `import type` (erased at runtime)
|
|
50
|
-
>
|
|
61
|
+
> — **every** file, not just `stream.ts`; a value import left in a helper
|
|
62
|
+
> (`server.ts`, `models.ts`, `credential.ts`) resolves from the repo's own
|
|
63
|
+
> `node_modules` in dev and only breaks for end users — and resolve the real
|
|
64
|
+
> module at point of use with
|
|
51
65
|
> `loadEngineSdk<typeof import('<pkg>')>('newengine', '<pkg>')` from
|
|
52
66
|
> `backend/engine/sdk-loader.ts`. The loader throws `EngineNotReadyError`
|
|
53
67
|
> (`not-installed` / `needs-update`) when the SDK is absent or version-mismatched,
|
|
@@ -94,6 +108,10 @@ mandatory files; optional files use the canonical names from §2.6.
|
|
|
94
108
|
event after all messages (Codex, Cursor), assistant rows persist
|
|
95
109
|
`usage:null` — add the engine to `stream-manager.ts::backfillUsageForStream`'s
|
|
96
110
|
gate so the turn aggregate is written to every assistant row (see §10.20-I).
|
|
111
|
+
- [ ] **Reasoning effort (if the SDK has a knob):** read `options.reasoningEffort`
|
|
112
|
+
in `streamQuery` and map it onto the SDK's own option. Treat it as
|
|
113
|
+
untrusted — clamp/ignore an unknown token and fall back to the engine
|
|
114
|
+
default rather than forwarding it. See §2.4a for the per-engine table.
|
|
97
115
|
- [ ] **Context window:** set `EngineModel.limit.input` to the model's real max
|
|
98
116
|
when the catalog provides it; leave `0` when it doesn't — do NOT hard-code a
|
|
99
117
|
value. The UI renders `0` as "?" via `getContextUsage(...).unknown` (§10.20-J).
|
|
@@ -101,6 +119,12 @@ mandatory files; optional files use the canonical names from §2.6.
|
|
|
101
119
|
...): void` (and any helper formatters specific to the SDK's error
|
|
102
120
|
payload — see `opencode/error-handler.ts::formatSessionError` for the
|
|
103
121
|
pattern).
|
|
122
|
+
- [ ] `generateStructured` (optional but expected — it powers AI commit
|
|
123
|
+
messages, branch names, and artifact authoring). Native-schema SDKs pass
|
|
124
|
+
the schema through; the rest use `buildJsonPrompt` + `extractJson` from
|
|
125
|
+
`backend/engine/structured-helpers.ts` on a tool-less one-shot run.
|
|
126
|
+
Leave the method `undefined` if the SDK genuinely can't do it — the WS
|
|
127
|
+
handlers guard on its presence. See §10.16.
|
|
104
128
|
- [ ] `credential.ts` / `environment.ts` / `server.ts` / `config.ts` /
|
|
105
129
|
`presets.ts` / `session-fork.ts` (optional; canonical names only).
|
|
106
130
|
- [ ] Artifacts: in `streamQuery`, call `syncSkills(...)` +
|
|
@@ -177,8 +201,7 @@ mandatory files; optional files use the canonical names from §2.6.
|
|
|
177
201
|
Engine SDKs are installed **on demand** into the clopen-managed stack dir
|
|
178
202
|
(`~/.clopen/stack/engines`), not onto the machine's PATH — so you don't write a
|
|
179
203
|
per-platform recipe. You only declare the pinned package(s); `resolveEngineRecipe()`
|
|
180
|
-
handles the install.
|
|
181
|
-
`system-tools`.)
|
|
204
|
+
handles the install.
|
|
182
205
|
|
|
183
206
|
- [ ] `package.json`: add the engine's SDK package(s) to `devDependencies` at an
|
|
184
207
|
**exact** pinned version — this is the single source of truth for the
|
|
@@ -189,9 +212,9 @@ handles the install. (The panel is displayed as "Stack"; its WS route/id stays
|
|
|
189
212
|
imports and detects install-state from; any extras pin a transitive CLI the
|
|
190
213
|
SDK would otherwise float, e.g. Copilot's `@github/copilot`).
|
|
191
214
|
- No resolver needed — `resolveEngineRecipe()` picks it up.
|
|
192
|
-
- [ ] `backend/ws/
|
|
215
|
+
- [ ] `backend/ws/stack/status.ts` & `install.ts`: add
|
|
193
216
|
`'newengine'` to `TOOL_UNION`.
|
|
194
|
-
- [ ] `frontend/components/settings/
|
|
217
|
+
- [ ] `frontend/components/settings/stack/StackSettings.svelte`:
|
|
195
218
|
`<ToolInstallCard tool="newengine" title="NewEngine" description="..." />`.
|
|
196
219
|
|
|
197
220
|
### Stage 8 — Chat input
|
|
@@ -210,7 +233,15 @@ heavier — copy the OpenCode block.
|
|
|
210
233
|
|
|
211
234
|
Other auto wiring:
|
|
212
235
|
- [ ] The engine tab appears automatically in `EngineModelPicker` from
|
|
213
|
-
`ENGINES
|
|
236
|
+
`ENGINES`, and its position in the shared `ENGINES` order is the order
|
|
237
|
+
used by every grid, tab strip, and picker (Stack card list included).
|
|
238
|
+
- [ ] The reasoning-level pill appears automatically for any model whose
|
|
239
|
+
catalog entry carries `capabilities.reasoningControl` — no frontend
|
|
240
|
+
change, and no engine name in the component.
|
|
241
|
+
- [ ] The engine's brand icon comes from the single `TOOL_ICONS` registry in
|
|
242
|
+
`shared/constants/tool-icons.ts`, which both `ENGINES` and the Stack
|
|
243
|
+
cards reference. Add the SVG **there only** — never inline it a second
|
|
244
|
+
time.
|
|
214
245
|
- [ ] Verify: select engine → model list appears → send message → stream
|
|
215
246
|
runs.
|
|
216
247
|
|
|
@@ -232,6 +263,14 @@ Then the minimum UI scenarios that must pass:
|
|
|
232
263
|
replies → cancel mid-stream → idle → send again → resume works.
|
|
233
264
|
- [ ] AskUserQuestion (if the SDK supports it) → appears in UI → submit
|
|
234
265
|
answer → stream continues.
|
|
266
|
+
- [ ] Reasoning effort (if the engine has a knob) → the pill appears for
|
|
267
|
+
models that advertise one and is **absent** for models that don't →
|
|
268
|
+
pick a level → the Raw Message view shows `engine.reasoningEffort` →
|
|
269
|
+
the level survives a refresh (persisted on the session row).
|
|
270
|
+
- [ ] `generateStructured` on a **non-Claude** engine: Git → generate commit
|
|
271
|
+
message, and Artifacts → generate from a purpose. These are the two
|
|
272
|
+
paths that break on a stale `providerSlug` and on JSON with trailing
|
|
273
|
+
prose / raw newlines — Claude Code passing proves nothing (§10.16).
|
|
235
274
|
- [ ] Restart Clopen → state survives (account, provider, last-used model
|
|
236
275
|
in chat).
|
|
237
276
|
|
|
@@ -65,27 +65,30 @@ modelStore // models[], fetchModels(engine), refreshModels(engin
|
|
|
65
65
|
|
|
66
66
|
### 5.2 Settings → Stack
|
|
67
67
|
|
|
68
|
-
The panel is displayed as **Stack** (its internal section id / WS route stays
|
|
69
|
-
`system-tools`).
|
|
70
|
-
|
|
71
68
|
Files:
|
|
72
|
-
- `frontend/components/settings/
|
|
73
|
-
- `frontend/components/settings/
|
|
69
|
+
- `frontend/components/settings/stack/StackSettings.svelte`
|
|
70
|
+
- `frontend/components/settings/stack/ToolInstallCard.svelte`
|
|
74
71
|
|
|
75
|
-
`
|
|
72
|
+
`StackSettings` renders one `ToolInstallCard` per tool — host tools
|
|
76
73
|
(`git`, `chrome`, `cloudflared`) plus every engine SDK (`claude`, `opencode`,
|
|
77
74
|
`copilot`, `codex`, `qwen`, `pi`, `cline`, `cursor`). `ToolInstallCard`:
|
|
78
75
|
|
|
79
|
-
1. Calls `
|
|
76
|
+
1. Calls `stack:status` on mount.
|
|
80
77
|
2. Renders: status (installed/version/source; engines also carry
|
|
81
78
|
`requiredVersion` + `needsUpdate`), an "Install" button if
|
|
82
79
|
`recipe.autoInstallable`, otherwise a "Manual install" dialog.
|
|
83
|
-
3. While installing: `
|
|
84
|
-
`
|
|
85
|
-
exit status from `
|
|
80
|
+
3. While installing: `stack:install-start` → subscribe to
|
|
81
|
+
`stack:install-stream` (per-line) → render in xterm + show
|
|
82
|
+
exit status from `stack:install-finished`.
|
|
86
83
|
4. The session survives navigation: if `activeSession` exists on refresh,
|
|
87
84
|
re-attach to the same session id.
|
|
88
85
|
|
|
86
|
+
Cards are **collapsible** — a compact status row by default, expanding to
|
|
87
|
+
version + actions + live install output, and auto-expanding while an install
|
|
88
|
+
runs (the list stays scannable as engines are added). The header's brand icon
|
|
89
|
+
comes from `TOOL_ICONS` (`shared/constants/tool-icons.ts`), the same registry
|
|
90
|
+
`ENGINES` reads — no SVG is defined twice.
|
|
91
|
+
|
|
89
92
|
Engine cards differ from host-tool cards:
|
|
90
93
|
- The SDK installs on demand into `~/.clopen/stack/engines` (managed dir), not
|
|
91
94
|
the machine's PATH; there is no manual command to run.
|
|
@@ -97,15 +100,35 @@ Engine cards differ from host-tool cards:
|
|
|
97
100
|
To add a new **host** tool (e.g. `goose`):
|
|
98
101
|
1. Add the literal to `ToolId` (`backend/engine/install-recipes.ts`).
|
|
99
102
|
2. Add `resolveGooseRecipe()` + a case in `resolveRecipe()`.
|
|
100
|
-
3. Add the literal to `TOOL_UNION` (`backend/ws/
|
|
103
|
+
3. Add the literal to `TOOL_UNION` (`backend/ws/stack/status.ts`
|
|
101
104
|
and `install.ts`).
|
|
102
105
|
4. Add `<ToolInstallCard tool="goose" title="Goose" description="…" />`
|
|
103
|
-
in `
|
|
106
|
+
in `StackSettings.svelte`.
|
|
104
107
|
5. (Optional) expose detection in the `engine:<name>-status` handler so
|
|
105
108
|
Settings → Engines can show an "Installed" badge.
|
|
106
109
|
|
|
107
110
|
For a new **engine SDK**, you declare the pinned package instead of a resolver —
|
|
108
|
-
see [
|
|
111
|
+
see [stack](./stack.md) §7.7.
|
|
112
|
+
|
|
113
|
+
### 5.3 Settings → Models
|
|
114
|
+
|
|
115
|
+
`frontend/components/settings/model/EngineModelPicker.svelte` is the shared
|
|
116
|
+
catalog browser mounted by `AssistantSettings`, `GitSettings`, and
|
|
117
|
+
`ArtifactsSettings` (it is a different component from the chat-input picker of
|
|
118
|
+
the same name — see §6.2).
|
|
119
|
+
|
|
120
|
+
Per-model reasoning defaults are edited here: each model row that carries a
|
|
121
|
+
`reasoningControl` (§2.4a) gets a nested row of level buttons, rendered
|
|
122
|
+
**whether or not the model is selected** so it can't read as a global setting.
|
|
123
|
+
Clicking one calls `setReasoningDefault(modelId, level)` →
|
|
124
|
+
`settings.reasoningDefaults` (`null` deletes the key → back to the model's own
|
|
125
|
+
default). The chat pill writes the same map, so a level chosen in either place
|
|
126
|
+
is remembered in both.
|
|
127
|
+
|
|
128
|
+
The two generator overrides (`commitGenerator`, `artifactGenerator`) persist
|
|
129
|
+
`engine` + `provider` + `modelId` + `modelName` as separate fields. `GitSettings`
|
|
130
|
+
and `ArtifactsSettings` write them through `modelFieldsOf(...)` (§6.1) — never
|
|
131
|
+
one at a time.
|
|
109
132
|
|
|
110
133
|
---
|
|
111
134
|
|
|
@@ -118,13 +141,30 @@ see [system-tools](./system-tools.md) §7.7.
|
|
|
118
141
|
```ts
|
|
119
142
|
{ engine, provider, modelId, modelName,
|
|
120
143
|
engineModelMemory: { [engine]: { provider, id, name } },
|
|
121
|
-
accountId, accountName
|
|
144
|
+
accountId, accountName,
|
|
145
|
+
profileId, // null = use the project default
|
|
146
|
+
reasoningEffort } // native level token; null = engine/model default
|
|
122
147
|
```
|
|
123
148
|
|
|
124
149
|
This store is **local to the active session**: settings under Settings →
|
|
125
150
|
Engines only seed the initial defaults via `initChatModel(...)`. Switching
|
|
126
151
|
engine/model in chat input does **not** affect Settings.
|
|
127
152
|
|
|
153
|
+
`reasoningEffort` is the one field that is deliberately kept at its
|
|
154
|
+
**effective** value rather than "only what the user picked": an `$effect` in
|
|
155
|
+
the picker re-seeds it whenever the model changes (per-model default from
|
|
156
|
+
Settings → the model's own `reasoningControl.default`) and clears it to `null`
|
|
157
|
+
for models with no knob. That way the value sent with the turn — and stamped
|
|
158
|
+
onto the message for the Raw view — always matches what actually ran, and a
|
|
159
|
+
level left over from a different model can never leak into the next request.
|
|
160
|
+
|
|
161
|
+
> **Engine/provider/model move together.** They are three fields describing one
|
|
162
|
+
> choice; anything that writes one must write all three. Use `modelFieldsOf(...)`
|
|
163
|
+
> from `frontend/utils/model-override.ts` for the Settings-persisted
|
|
164
|
+
> generator configs (Git, Artifacts) instead of assigning them individually —
|
|
165
|
+
> a stale `provider` is invisible on five engines and fatal on three (see
|
|
166
|
+
> §10.16 point 3).
|
|
167
|
+
|
|
128
168
|
### 6.2 EngineModelPicker (in chat input)
|
|
129
169
|
|
|
130
170
|
`frontend/components/chat/input/components/EngineModelPicker.svelte`:
|
|
@@ -146,6 +186,18 @@ engine/model in chat input does **not** affect Settings.
|
|
|
146
186
|
resolves the model's provider via `ocMatchingProvider`, then writes the
|
|
147
187
|
chosen account into `chatModelState.accountId` and triggers a server
|
|
148
188
|
restart.
|
|
189
|
+
- **Reasoning-level pill** — rendered next to the model trigger **only** when
|
|
190
|
+
`currentModel.capabilities.reasoningControl` exists (§2.4a). Options come
|
|
191
|
+
straight from `reasoningControl.levels`; no engine is named anywhere in the
|
|
192
|
+
component. Picking a level does three things: sets
|
|
193
|
+
`chatModelState.reasoningEffort`, saves it as that model's default via
|
|
194
|
+
`setReasoningDefault(modelId, value)`, and broadcasts
|
|
195
|
+
`chat:reasoning-sync` to the session room.
|
|
196
|
+
- **Not-installed notice** — when `models:list` reports a readiness error for
|
|
197
|
+
the active engine (`modelStore.getError(engine)`, typically
|
|
198
|
+
`EngineNotReadyError`), the picker renders the same actionable notice as
|
|
199
|
+
Settings, with an **Open Stack** button and a Configure-engine fallback.
|
|
200
|
+
Both are admin-gated.
|
|
149
201
|
|
|
150
202
|
### 6.3 Send path → backend
|
|
151
203
|
|
|
@@ -163,13 +215,17 @@ ws.emit('chat:stream', {
|
|
|
163
215
|
model: { id: chatModelState.modelId, name: chatModelState.modelName },
|
|
164
216
|
account: { id: chatModelState.accountId ?? 0, name: chatModelState.accountName ?? '' },
|
|
165
217
|
},
|
|
166
|
-
sender: { id, name }
|
|
218
|
+
sender: { id, name },
|
|
219
|
+
profileId: chatModelState.profileId,
|
|
220
|
+
reasoningEffort: chatModelState.reasoningEffort,
|
|
167
221
|
});
|
|
168
222
|
```
|
|
169
223
|
|
|
170
224
|
Backend `chat:stream` then `streamManager.startStream(...)`, which:
|
|
171
225
|
- Resolves `getProjectEngine(projectId, engine.type)`
|
|
172
|
-
-
|
|
226
|
+
- Persists engine/model/account + `profile_id` + `reasoning_effort` onto the
|
|
227
|
+
`chat_sessions` row so a refresh or a late joiner restores the same setup
|
|
228
|
+
- Calls `engine.streamQuery({ projectPath, prompt, providerSlug: engine.provider, modelId: engine.model.id, reasoningEffort, accountId: engine.account.id !== 0 ? engine.account.id : undefined, mcpContext })`
|
|
173
229
|
- Yields `EngineOutput` → emits `chat:message` / `chat:partial` /
|
|
174
230
|
`chat:notification` to the session room.
|
|
175
231
|
|
|
@@ -180,10 +236,17 @@ Backend `chat:stream` then `streamManager.startStream(...)`, which:
|
|
|
180
236
|
|
|
181
237
|
### 6.4 Reasoning, attachments, AskUserQuestion
|
|
182
238
|
|
|
183
|
-
- **Reasoning**: an adapter must emit
|
|
239
|
+
- **Reasoning (output)**: an adapter must emit
|
|
184
240
|
`StreamLifecycleEvent { reasoning: true }` to mark start/stop of the
|
|
185
241
|
thinking block, then `TextDeltaEvent { reasoning: true }` for each delta.
|
|
186
242
|
The frontend renders these in a separate bubble.
|
|
243
|
+
- **Reasoning effort (input)**: the level the user picked rides the request as
|
|
244
|
+
`EngineQueryOptions.reasoningEffort` and is mapped to the SDK's own knob by
|
|
245
|
+
the adapter (§2.4a). Three places hold a value, in precedence order:
|
|
246
|
+
`chatModelState.reasoningEffort` (this session) → `settings.reasoningDefaults[modelId]`
|
|
247
|
+
(per-model, Settings → Models) → `reasoningControl.default` (the model's own).
|
|
248
|
+
Nothing in the frontend branches on engine type — a model without a
|
|
249
|
+
`reasoningControl` simply has no pill.
|
|
187
250
|
- **Attachments**: `UserMessage.content` carries `text | image | document`
|
|
188
251
|
blocks. The adapter maps these to the SDK's format — Claude uses native
|
|
189
252
|
content blocks, OpenCode uses `extractPromptParts()` to
|