@myrialabs/clopen 0.4.20 → 0.4.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/README.md +2 -1
  2. package/backend/artifacts/generate.ts +11 -5
  3. package/backend/auth/permissions.ts +8 -8
  4. package/backend/bootstrap.ts +39 -0
  5. package/backend/chat/stream-manager.ts +15 -0
  6. package/backend/database/migrations/065_add_session_reasoning_effort.ts +28 -0
  7. package/backend/database/migrations/index.ts +7 -0
  8. package/backend/database/queries/session-queries.ts +10 -0
  9. package/backend/engine/README.md +11 -8
  10. package/backend/engine/adapters/claude/models.ts +46 -23
  11. package/backend/engine/adapters/claude/stream.ts +18 -4
  12. package/backend/engine/adapters/codex/error-handler.ts +1 -1
  13. package/backend/engine/adapters/codex/models.ts +19 -2
  14. package/backend/engine/adapters/codex/stream.ts +10 -3
  15. package/backend/engine/adapters/copilot/models.ts +20 -1
  16. package/backend/engine/adapters/copilot/stream.ts +11 -1
  17. package/backend/engine/adapters/cursor/models.ts +27 -3
  18. package/backend/engine/adapters/cursor/stream.ts +23 -3
  19. package/backend/engine/adapters/pi/models.ts +20 -2
  20. package/backend/engine/adapters/pi/stream.ts +6 -3
  21. package/backend/engine/adapters/qwen/error-handler.ts +1 -1
  22. package/backend/engine/bootstrap-default-engine.ts +18 -5
  23. package/backend/engine/docs/adapter-contract.md +66 -2
  24. package/backend/engine/docs/adding-an-engine.md +46 -7
  25. package/backend/engine/docs/frontend-and-chat.md +80 -17
  26. package/backend/engine/docs/lessons-learned.md +126 -7
  27. package/backend/engine/docs/quick-reference.md +12 -3
  28. package/backend/engine/docs/{system-tools.md → stack.md} +35 -6
  29. package/backend/engine/docs/websocket-routes.md +54 -15
  30. package/backend/engine/install-runner.ts +4 -4
  31. package/backend/engine/resolve-model.ts +87 -0
  32. package/backend/engine/structured-helpers.test.ts +64 -0
  33. package/backend/engine/structured-helpers.ts +105 -13
  34. package/backend/engine/types.ts +6 -0
  35. package/backend/index.ts +6 -9
  36. package/backend/mcp/README.md +32 -11
  37. package/backend/mcp/internal/config.ts +3 -20
  38. package/backend/mcp/internal/servers/browser-automation/actions/console.ts +65 -0
  39. package/backend/mcp/internal/servers/browser-automation/actions/dom-analyze.ts +202 -0
  40. package/backend/mcp/internal/servers/browser-automation/actions/index.ts +31 -0
  41. package/backend/mcp/internal/servers/browser-automation/actions/input.ts +332 -0
  42. package/backend/mcp/internal/servers/browser-automation/actions/inspect.ts +158 -0
  43. package/backend/mcp/internal/servers/browser-automation/actions/navigation.ts +157 -0
  44. package/backend/mcp/internal/servers/browser-automation/actions/shared.ts +60 -0
  45. package/backend/mcp/internal/servers/browser-automation/actions/tabs.ts +146 -0
  46. package/backend/mcp/internal/servers/browser-automation/actions/types.ts +63 -0
  47. package/backend/mcp/internal/servers/browser-automation/context.ts +82 -0
  48. package/backend/mcp/internal/servers/browser-automation/description.ts +59 -0
  49. package/backend/mcp/internal/servers/browser-automation/format.ts +56 -0
  50. package/backend/mcp/internal/servers/browser-automation/index.ts +36 -784
  51. package/backend/mcp/internal/servers/browser-automation/paths.ts +71 -0
  52. package/backend/mcp/internal/servers/browser-automation/runner.ts +260 -0
  53. package/backend/mcp/internal/servers/browser-automation/schema.ts +26 -0
  54. package/backend/preview/browser/browser-console-manager.ts +310 -156
  55. package/backend/preview/browser/browser-dialog-handler.ts +45 -16
  56. package/backend/preview/browser/browser-host-bridge.ts +471 -0
  57. package/backend/preview/browser/browser-interaction-handler.ts +868 -297
  58. package/backend/preview/browser/browser-mcp-control.ts +7 -2
  59. package/backend/preview/browser/browser-native-ui-handler.ts +455 -81
  60. package/backend/preview/browser/browser-navigation-tracker.ts +56 -0
  61. package/backend/preview/browser/browser-pool.ts +83 -9
  62. package/backend/preview/browser/browser-preview-service.ts +432 -53
  63. package/backend/preview/browser/browser-tab-manager.ts +16 -16
  64. package/backend/preview/browser/browser-video-capture.ts +1334 -386
  65. package/backend/preview/browser/capture-profile.ts +213 -0
  66. package/backend/preview/browser/element-locator.ts +357 -0
  67. package/backend/preview/browser/frame-targeting.ts +92 -0
  68. package/backend/preview/browser/scripts/audio-stream.ts +258 -78
  69. package/backend/preview/browser/scripts/host-bridge.ts +1277 -0
  70. package/backend/preview/browser/scripts/video-stream.ts +803 -177
  71. package/backend/preview/browser/types.ts +397 -37
  72. package/backend/utils/cli.ts +1 -1
  73. package/backend/utils/path-enrich.ts +2 -2
  74. package/backend/ws/README.md +1 -1
  75. package/backend/ws/artifacts/generate.ts +2 -1
  76. package/backend/ws/chat/stream.ts +38 -2
  77. package/backend/ws/engine/codex/accounts.ts +1 -1
  78. package/backend/ws/engine/codex/status.ts +1 -1
  79. package/backend/ws/git/branch-name.ts +11 -5
  80. package/backend/ws/git/commit-message.ts +11 -5
  81. package/backend/ws/index.ts +3 -3
  82. package/backend/ws/preview/browser/host.ts +95 -0
  83. package/backend/ws/preview/browser/interact.ts +204 -10
  84. package/backend/ws/preview/browser/native-ui.ts +31 -1
  85. package/backend/ws/preview/browser/tab-info.ts +10 -1
  86. package/backend/ws/preview/browser/tab.ts +43 -0
  87. package/backend/ws/preview/browser/webcodecs.ts +180 -53
  88. package/backend/ws/preview/index.ts +58 -1
  89. package/backend/ws/{system-tools → stack}/access.ts +1 -1
  90. package/backend/ws/stack/index.ts +16 -0
  91. package/backend/ws/{system-tools → stack}/install.ts +7 -7
  92. package/backend/ws/{system-tools → stack}/status.ts +7 -7
  93. package/backend/ws/system/device-info.ts +290 -0
  94. package/backend/ws/system/index.ts +2 -0
  95. package/backend/ws/system/operations.ts +7 -0
  96. package/backend/ws/user/crud.ts +6 -3
  97. package/dist/assets/{index-BqBxKeAv.js → index-DH_GO0Lf.js} +1 -1
  98. package/dist/assets/{index-DdrcY5TE.js → index-igSQ3JaM.js} +1 -1
  99. package/dist/assets/main-BD3-qPfT.css +1 -0
  100. package/dist/assets/main-D-d8SFfW.js +616 -0
  101. package/dist/assets/preview-video.worker-DcpDhCWL.js +1 -0
  102. package/dist/index.html +2 -2
  103. package/package.json +2 -1
  104. package/shared/constants/engines.ts +23 -0
  105. package/shared/types/database/schema.ts +1 -0
  106. package/shared/types/stores/settings.ts +12 -0
  107. package/shared/types/unified/engine.ts +33 -0
  108. package/shared/types/unified/index.ts +2 -0
  109. package/shared/types/unified/message.ts +6 -0
  110. package/shared/types/unified/stream.ts +6 -0
  111. package/backend/mcp/internal/servers/browser-automation/actions.ts +0 -159
  112. package/backend/mcp/internal/servers/browser-automation/browser.ts +0 -375
  113. package/backend/mcp/internal/servers/browser-automation/inspection.ts +0 -495
  114. package/backend/ws/system-tools/index.ts +0 -16
  115. package/dist/assets/main-BBxAj17T.js +0 -582
  116. package/dist/assets/main-Cry3pLcl.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 Claude Code, OpenCode, Codex, Copilot, and Qwen Code, and sign in to the engines you'll use. Pi, Cline, and Cursor need no install and are ready to sign in to directly
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
- providerSlug: string;
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
- debug.log('artifacts', `✨ Generating ${type} draft via ${model.engine}/${model.modelId}`);
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: model.providerSlug,
100
- modelId: model.modelId,
105
+ providerSlug: target.providerSlug,
106
+ modelId: target.modelId,
101
107
  schema: SCHEMAS[type],
102
108
  projectPath: model.projectPath || getClopenDir(),
103
- accountId: model.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
- // System Tools — binary installation is an admin-only operation.
47
- 'system-tools:status',
48
- 'system-tools:status-all',
49
- 'system-tools:install-start',
50
- 'system-tools:install-cancel',
51
- 'system-tools:install-session',
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 System Tools and Engines.
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 System Tools.
142
+ // admin-only, mirroring MCP and Stack.
143
143
  'skills:list',
144
144
  'skills:get',
145
145
  'skills:create',
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Post-database-init bootstrap
3
+ *
4
+ * Re-establishes code-defined built-ins that live OUTSIDE the migration/seeder
5
+ * pipeline — internal MCP servers (e.g. Browser Automation) synced from code,
6
+ * and the default engine install. These are normally set up once at server
7
+ * startup, right after `initializeDatabase()`.
8
+ *
9
+ * "Clear All Data" wipes the whole ~/.clopen directory and re-runs only
10
+ * migrations + seeders on the SAME live process, so anything established here
11
+ * would silently vanish until the next restart. Sharing this function between
12
+ * startup and the clear-data handler keeps built-ins alive across a data reset
13
+ * without a restart — and means any future startup-synced built-in is covered
14
+ * automatically.
15
+ */
16
+
17
+ import { syncInternalServers } from './mcp';
18
+ import { ensureDefaultEngineInstalled } from './engine/bootstrap-default-engine';
19
+ import { debug } from '$shared/utils/logger';
20
+
21
+ /**
22
+ * Rebuild DB-derived built-ins after the database is (re)initialized.
23
+ *
24
+ * Idempotent and safe to call on an already-running process. Intentionally does
25
+ * NOT start long-lived schedulers — those are launched once from `startServer()`
26
+ * and would double-run if invoked again on the live process during clear-data.
27
+ */
28
+ export function bootstrapAfterDbInit(): void {
29
+ // Mirror code-defined internal MCP servers into the mcp_servers table and
30
+ // refresh the enabled cache. Without this, a post-startup DB wipe leaves
31
+ // Settings → MCP empty until the next restart.
32
+ syncInternalServers();
33
+
34
+ // Fresh/emptied install: (re)install a usable engine in the background.
35
+ // No-ops once any engine is already present. Fire-and-forget.
36
+ void ensureDefaultEngineInstalled();
37
+
38
+ debug.log('server', '✅ Post-DB bootstrap complete');
39
+ }
@@ -55,6 +55,8 @@ export interface StreamState {
55
55
  processId: string;
56
56
  engine: EngineType;
57
57
  accountId?: number;
58
+ /** Reasoning/thinking level token for this run (native per engine; undefined = engine default). */
59
+ reasoningEffort?: string;
58
60
  status: 'active' | 'completed' | 'error' | 'cancelled';
59
61
  startedAt: Date;
60
62
  completedAt?: Date;
@@ -124,6 +126,8 @@ interface RequestEngineContext {
124
126
  accountId: number;
125
127
  accountName: string;
126
128
  modelName: string;
129
+ /** Reasoning/thinking level for this turn (native per engine; undefined = no knob). */
130
+ reasoningEffort?: string;
127
131
  }
128
132
 
129
133
  /**
@@ -148,6 +152,9 @@ function enrichMessageEngine(
148
152
  id: ctx.accountId || message.engine.account.id,
149
153
  name: ctx.accountName || message.engine.account.name,
150
154
  },
155
+ // Surface the turn's reasoning level (when the engine exposes one) so it's
156
+ // visible in the Raw Message view. Omitted when there's no knob.
157
+ ...(ctx.reasoningEffort !== undefined && { reasoningEffort: ctx.reasoningEffort }),
151
158
  },
152
159
  };
153
160
  }
@@ -298,6 +305,7 @@ class StreamManager extends EventEmitter {
298
305
  processId,
299
306
  engine: request.engine.type,
300
307
  accountId: request.engine.account?.id || undefined,
308
+ reasoningEffort: request.reasoningEffort ?? undefined,
301
309
  status: 'active',
302
310
  startedAt: new Date(),
303
311
  messages: [],
@@ -327,6 +335,11 @@ class StreamManager extends EventEmitter {
327
335
  if (request.profileId !== undefined) {
328
336
  sessionQueries.updateProfile(request.chatSessionId, request.profileId);
329
337
  }
338
+ // Persist the reasoning/thinking level (string or null). `undefined`
339
+ // (client didn't send one) leaves the stored value untouched.
340
+ if (request.reasoningEffort !== undefined) {
341
+ sessionQueries.updateReasoning(request.chatSessionId, request.reasoningEffort);
342
+ }
330
343
  } catch (error) {
331
344
  debug.error('chat', 'Failed to save engine/model to session:', error);
332
345
  }
@@ -456,6 +469,7 @@ class StreamManager extends EventEmitter {
456
469
  accountId: requestEngine.account.id,
457
470
  accountName: requestEngine.account.name,
458
471
  modelName: requestEngine.model.name,
472
+ reasoningEffort: streamState.reasoningEffort,
459
473
  };
460
474
 
461
475
  const projectPathExists = projectPath ? await this.existsSync(projectPath) : false;
@@ -642,6 +656,7 @@ class StreamManager extends EventEmitter {
642
656
  resume: resumeSessionId,
643
657
  providerSlug: requestEngine.provider,
644
658
  modelId: requestEngine.model.id,
659
+ ...(streamState.reasoningEffort && { reasoningEffort: streamState.reasoningEffort }),
645
660
  includePartialMessages: true,
646
661
  abortController: streamState.abortController,
647
662
  ...(requestEngine.account.id !== 0 && { accountId: requestEngine.account.id }),
@@ -0,0 +1,28 @@
1
+ import type { DatabaseConnection } from '$shared/types/database/connection';
2
+ import { debug } from '$shared/utils/logger';
3
+
4
+ export const description = 'Add reasoning_effort column to chat_sessions for per-session reasoning/thinking level';
5
+
6
+ /**
7
+ * Persists the reasoning/thinking level chosen per chat session (native per
8
+ * engine — e.g. Codex `high`, Copilot `medium`, Pi `low`). Nullable: a NULL
9
+ * value means "use the engine's own default", which is the behaviour for every
10
+ * pre-existing session and any engine/model that exposes no reasoning knob.
11
+ */
12
+ export const up = (db: DatabaseConnection): void => {
13
+ debug.log('migration', 'Adding reasoning_effort column to chat_sessions...');
14
+ db.exec(`ALTER TABLE chat_sessions ADD COLUMN reasoning_effort TEXT`);
15
+ debug.log('migration', 'chat_sessions reasoning_effort column added');
16
+ };
17
+
18
+ export const down = (db: DatabaseConnection): void => {
19
+ debug.log('migration', 'Removing reasoning_effort column from chat_sessions...');
20
+ // SQLite pre-3.35 can't DROP COLUMN reliably in all builds; use the guarded
21
+ // form so the down migration is a no-op where DROP COLUMN is unsupported.
22
+ try {
23
+ db.exec(`ALTER TABLE chat_sessions DROP COLUMN reasoning_effort`);
24
+ } catch {
25
+ debug.warn('migration', 'DROP COLUMN reasoning_effort unsupported on this SQLite build — leaving column in place');
26
+ }
27
+ debug.log('migration', 'chat_sessions reasoning_effort column removed');
28
+ };
@@ -63,6 +63,7 @@ import * as migration061 from './061_add_session_device_metadata';
63
63
  import * as migration062 from './062_add_session_source';
64
64
  import * as migration063 from './063_add_invite_project_ids';
65
65
  import * as migration064 from './064_create_messages_fts';
66
+ import * as migration065 from './065_add_session_reasoning_effort';
66
67
 
67
68
  // Export all migrations in order
68
69
  export const migrations = [
@@ -449,6 +450,12 @@ export const migrations = [
449
450
  description: migration064.description,
450
451
  up: migration064.up,
451
452
  down: migration064.down
453
+ },
454
+ {
455
+ id: '065',
456
+ description: migration065.description,
457
+ up: migration065.up,
458
+ down: migration065.down
452
459
  }
453
460
  ];
454
461
 
@@ -93,6 +93,16 @@ export const sessionQueries = {
93
93
  `).run(engine, provider, modelId, modelName, id);
94
94
  },
95
95
 
96
+ /** Persist the reasoning/thinking level for a session (NULL clears → engine default). */
97
+ updateReasoning(id: string, reasoningEffort: string | null): void {
98
+ const db = getDatabase();
99
+ db.prepare(`
100
+ UPDATE chat_sessions
101
+ SET reasoning_effort = ?
102
+ WHERE id = ?
103
+ `).run(reasoningEffort, id);
104
+ },
105
+
96
106
  /** Persist the active profile for a session (NULL clears it). */
97
107
  updateProfile(id: string, profileId: number | null): void {
98
108
  const db = getDatabase();
@@ -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/qwen-code`), **`pi`**
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:*`, `system-tools:*`, `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/attachments/AskUserQuestion.
59
- 6. [Stack](./docs/system-tools.md) — registering a host tool or on-demand engine SDK in `install-recipes.ts` + the install runner.
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/ SystemToolsSettings… EngineModel… │
74
+ │ AIEnginesSettings+panels/ StackSettings… EngineModel… │
75
75
  │ │ │ │ │
76
76
  │ ├─ claudeAccountsStore └─ ws.http( ├─ model │
77
- │ ├─ copilotAccountsStore 'system-tools:…') │ Store │
77
+ │ ├─ copilotAccountsStore 'stack:…') │ Store │
78
78
  │ ├─ opencodeProvidersStore └─ chat │
79
79
  │ └─ modelStore ModelState│
80
80
  │ │ │ │ │ │ │
81
81
  │ ▼ ▼ ▼ ▼ ▼ │
82
- │ ws.http('engine:*') ws.http('system-tools:*') ws.emit('chat:…') │
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/system-tools/ backend/ws/chat/stream.ts │
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 │ │
@@ -4,11 +4,29 @@
4
4
  * Static catalog — the Anthropic Agent SDK accepts these IDs directly via
5
5
  * the `model` option, no runtime discovery endpoint is needed. Update when
6
6
  * Anthropic ships a new generation.
7
+ *
8
+ * Only models with `Current state: Active` on
9
+ * https://platform.claude.com/docs/en/about-claude/model-deprecations are
10
+ * listed here — deprecated/retired models are dropped.
7
11
  */
8
12
 
9
- import type { EngineModel } from '$shared/types/unified';
13
+ import type { EngineModel, ReasoningControl } from '$shared/types/unified';
14
+ import { toReasoningOptions } from '$shared/constants/engines';
10
15
 
11
- export const CLAUDE_CODE_MODELS: EngineModel[] = [
16
+ /**
17
+ * Claude's reasoning knob is the Agent SDK `effort` option plus `thinking`.
18
+ * `off` disables thinking; `auto` is adaptive thinking (Claude decides — the
19
+ * historical default); the rest are the SDK's native `EffortLevel` values
20
+ * (`low | medium | high | xhigh | max`, silently downgraded on models that
21
+ * don't support the higher tiers). Uniform across the catalog; the stream
22
+ * adapter translates the chosen token.
23
+ */
24
+ const CLAUDE_REASONING_CONTROL: ReasoningControl = {
25
+ levels: toReasoningOptions(['off', 'auto', 'low', 'medium', 'high', 'xhigh', 'max']),
26
+ default: 'auto',
27
+ };
28
+
29
+ const CLAUDE_CODE_MODELS_BASE: EngineModel[] = [
12
30
  {
13
31
  engine: {
14
32
  type: 'claude-code',
@@ -57,8 +75,8 @@ export const CLAUDE_CODE_MODELS: EngineModel[] = [
57
75
  type: 'claude-code',
58
76
  provider: 'anthropic',
59
77
  model: {
60
- id: 'claude-opus-4-8',
61
- name: 'Claude Opus 4.8',
78
+ id: 'claude-opus-5',
79
+ name: 'Claude Opus 5',
62
80
  },
63
81
  account: {
64
82
  id: 0,
@@ -186,8 +204,8 @@ export const CLAUDE_CODE_MODELS: EngineModel[] = [
186
204
  type: 'claude-code',
187
205
  provider: 'anthropic',
188
206
  model: {
189
- id: 'claude-opus-4-7',
190
- name: 'Claude Opus 4.7',
207
+ id: 'claude-opus-4-8',
208
+ name: 'Claude Opus 4.8',
191
209
  },
192
210
  account: {
193
211
  id: 0,
@@ -229,8 +247,8 @@ export const CLAUDE_CODE_MODELS: EngineModel[] = [
229
247
  type: 'claude-code',
230
248
  provider: 'anthropic',
231
249
  model: {
232
- id: 'claude-sonnet-4-6',
233
- name: 'Claude Sonnet 4.6',
250
+ id: 'claude-opus-4-7',
251
+ name: 'Claude Opus 4.7',
234
252
  },
235
253
  account: {
236
254
  id: 0,
@@ -263,8 +281,8 @@ export const CLAUDE_CODE_MODELS: EngineModel[] = [
263
281
  structuredOutput: true,
264
282
  },
265
283
  cost: {
266
- input: 3,
267
- output: 15,
284
+ input: 5,
285
+ output: 25,
268
286
  },
269
287
  },
270
288
  {
@@ -315,8 +333,8 @@ export const CLAUDE_CODE_MODELS: EngineModel[] = [
315
333
  type: 'claude-code',
316
334
  provider: 'anthropic',
317
335
  model: {
318
- id: 'claude-sonnet-4-5',
319
- name: 'Claude Sonnet 4.5',
336
+ id: 'claude-sonnet-4-6',
337
+ name: 'Claude Sonnet 4.6',
320
338
  },
321
339
  account: {
322
340
  id: 0,
@@ -324,8 +342,8 @@ export const CLAUDE_CODE_MODELS: EngineModel[] = [
324
342
  },
325
343
  },
326
344
  limit: {
327
- input: 200_000,
328
- output: 64_000,
345
+ input: 1_000_000,
346
+ output: 128_000,
329
347
  },
330
348
  modalities: {
331
349
  input: {
@@ -358,8 +376,8 @@ export const CLAUDE_CODE_MODELS: EngineModel[] = [
358
376
  type: 'claude-code',
359
377
  provider: 'anthropic',
360
378
  model: {
361
- id: 'claude-opus-4-5',
362
- name: 'Claude Opus 4.5',
379
+ id: 'claude-sonnet-4-5',
380
+ name: 'Claude Sonnet 4.5',
363
381
  },
364
382
  account: {
365
383
  id: 0,
@@ -392,8 +410,8 @@ export const CLAUDE_CODE_MODELS: EngineModel[] = [
392
410
  structuredOutput: true,
393
411
  },
394
412
  cost: {
395
- input: 5,
396
- output: 25,
413
+ input: 3,
414
+ output: 15,
397
415
  },
398
416
  },
399
417
  {
@@ -401,8 +419,8 @@ export const CLAUDE_CODE_MODELS: EngineModel[] = [
401
419
  type: 'claude-code',
402
420
  provider: 'anthropic',
403
421
  model: {
404
- id: 'claude-opus-4-1',
405
- name: 'Claude Opus 4.1',
422
+ id: 'claude-opus-4-5',
423
+ name: 'Claude Opus 4.5',
406
424
  },
407
425
  account: {
408
426
  id: 0,
@@ -411,7 +429,7 @@ export const CLAUDE_CODE_MODELS: EngineModel[] = [
411
429
  },
412
430
  limit: {
413
431
  input: 200_000,
414
- output: 32_000,
432
+ output: 64_000,
415
433
  },
416
434
  modalities: {
417
435
  input: {
@@ -435,8 +453,13 @@ export const CLAUDE_CODE_MODELS: EngineModel[] = [
435
453
  structuredOutput: true,
436
454
  },
437
455
  cost: {
438
- input: 15,
439
- output: 75,
456
+ input: 5,
457
+ output: 25,
440
458
  },
441
459
  },
442
460
  ];
461
+
462
+ export const CLAUDE_CODE_MODELS: EngineModel[] = CLAUDE_CODE_MODELS_BASE.map((model) => ({
463
+ ...model,
464
+ capabilities: { ...model.capabilities, reasoningControl: CLAUDE_REASONING_CONTROL },
465
+ }));
@@ -19,6 +19,7 @@ import type {
19
19
  Query,
20
20
  PermissionMode,
21
21
  PermissionResult,
22
+ EffortLevel,
22
23
  } from '@anthropic-ai/claude-agent-sdk';
23
24
  import type { EngineOutput } from '$shared/types/unified';
24
25
  import type { StructuredGenerationOptions } from '../../types';
@@ -89,11 +90,23 @@ export class ClaudeCodeEngine implements AIEngine {
89
90
  resume,
90
91
  maxTurns = undefined,
91
92
  modelId,
93
+ reasoningEffort,
92
94
  includePartialMessages = false,
93
95
  abortController,
94
96
  accountId
95
97
  } = options;
96
98
 
99
+ // Map the chosen reasoning level to Claude's knobs: `off` disables thinking
100
+ // entirely, `auto`/unset keeps adaptive thinking (Claude decides how much),
101
+ // and an explicit effort level pairs adaptive thinking with `effort`.
102
+ const claudeEffort = new Set<string>(['low', 'medium', 'high', 'xhigh', 'max']);
103
+ const thinkingConfig: Options['thinking'] = reasoningEffort === 'off'
104
+ ? { type: 'disabled' }
105
+ : { type: 'adaptive', display: 'summarized' };
106
+ const effortOption = reasoningEffort && claudeEffort.has(reasoningEffort)
107
+ ? { effort: reasoningEffort as EffortLevel }
108
+ : {};
109
+
97
110
  debug.log('chat', "Claude Code - Stream Query");
98
111
  debug.log('chat', { prompt });
99
112
 
@@ -142,10 +155,11 @@ export class ClaudeCodeEngine implements AIEngine {
142
155
  systemPrompt: { type: "preset", preset: "claude_code" },
143
156
  settingSources: ["user", "project", "local"],
144
157
  forkSession: true,
145
- // Explicit adaptive thinking with summarized display so Opus 4.6+ emits
146
- // visible thinking_delta events; without this the SDK can default to
147
- // 'omitted' and reasoning blocks arrive empty.
148
- thinking: { type: 'adaptive', display: 'summarized' },
158
+ // Reasoning level → thinking/effort (see thinkingConfig above). Adaptive
159
+ // thinking with summarized display keeps Opus 4.6+ emitting visible
160
+ // thinking_delta events; 'off' disables it, an explicit level adds effort.
161
+ thinking: thinkingConfig,
162
+ ...effortOption,
149
163
  // Custom permission handler: blocks on AskUserQuestion until user answers,
150
164
  // auto-allows everything else. Works alongside bypassPermissions.
151
165
  canUseTool: async (_toolName, input, canUseToolOptions) => {
@@ -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 → System Tools (or run `bun add -g @openai/codex`).');
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')) {
@@ -9,9 +9,20 @@
9
9
  * generation.
10
10
  */
11
11
 
12
- import type { EngineModel } from '$shared/types/unified';
12
+ import type { EngineModel, ReasoningControl } from '$shared/types/unified';
13
+ import { toReasoningOptions } from '$shared/constants/engines';
13
14
 
14
- export const CODEX_MODELS: EngineModel[] = [
15
+ /**
16
+ * Codex's reasoning knob is the SDK `modelReasoningEffort` thread option
17
+ * (`minimal | low | medium | high | xhigh`). `medium` is the historical
18
+ * default. Attached only to reasoning-capable models below.
19
+ */
20
+ const CODEX_REASONING_CONTROL: ReasoningControl = {
21
+ levels: toReasoningOptions(['minimal', 'low', 'medium', 'high', 'xhigh']),
22
+ default: 'medium',
23
+ };
24
+
25
+ const CODEX_MODELS_BASE: EngineModel[] = [
15
26
  {
16
27
  engine: {
17
28
  type: 'codex',
@@ -103,3 +114,9 @@ export const CODEX_MODELS: EngineModel[] = [
103
114
  cost: { input: 0, output: 0 },
104
115
  },
105
116
  ];
117
+
118
+ export const CODEX_MODELS: EngineModel[] = CODEX_MODELS_BASE.map((model) =>
119
+ model.capabilities.reasoning
120
+ ? { ...model, capabilities: { ...model.capabilities, reasoningControl: CODEX_REASONING_CONTROL } }
121
+ : model,
122
+ );
@@ -19,7 +19,7 @@
19
19
  * `backend/ws/chat/stream.ts` to it — same pattern as Claude/OpenCode.
20
20
  */
21
21
 
22
- import type { Codex, Thread, ThreadOptions, Input as CodexInput } from '@openai/codex-sdk';
22
+ import type { Codex, Thread, ThreadOptions, Input as CodexInput, ModelReasoningEffort } from '@openai/codex-sdk';
23
23
  import { loadEngineSdk } from '$backend/engine/sdk-loader';
24
24
  import type { EngineOutput, EngineModel } from '$shared/types/unified';
25
25
  import type { AIEngine, EngineQueryOptions, StructuredGenerationOptions } from '../../types';
@@ -151,7 +151,14 @@ export class CodexEngine implements AIEngine {
151
151
  }
152
152
 
153
153
  async *streamQuery(options: EngineQueryOptions): AsyncGenerator<EngineOutput, void, unknown> {
154
- const { projectPath, prompt, resume, modelId, abortController, accountId } = options;
154
+ const { projectPath, prompt, resume, modelId, reasoningEffort, abortController, accountId } = options;
155
+
156
+ // Codex's reasoning knob (`minimal | low | medium | high | xhigh`); default
157
+ // medium when unset or an unsupported token slips through.
158
+ const codexEfforts = new Set<string>(['minimal', 'low', 'medium', 'high', 'xhigh']);
159
+ const modelReasoningEffort: ModelReasoningEffort = reasoningEffort && codexEfforts.has(reasoningEffort)
160
+ ? reasoningEffort as ModelReasoningEffort
161
+ : 'medium';
155
162
 
156
163
  // Active Profile for this stream — scopes the materialized artifact set AND
157
164
  // (below) the MCP connector set baked into the Codex client.
@@ -200,7 +207,7 @@ export class CodexEngine implements AIEngine {
200
207
  skipGitRepoCheck: true,
201
208
  sandboxMode: 'danger-full-access',
202
209
  approvalPolicy: 'never',
203
- modelReasoningEffort: 'medium',
210
+ modelReasoningEffort,
204
211
  webSearchMode: 'cached',
205
212
  webSearchEnabled: true,
206
213
  };
@@ -9,7 +9,8 @@
9
9
  */
10
10
 
11
11
  import type { CopilotClient, ModelInfo } from '@github/copilot-sdk';
12
- import type { EngineModel } from '$shared/types/unified';
12
+ import type { EngineModel, ReasoningControl } from '$shared/types/unified';
13
+ import { toReasoningOptions } from '$shared/constants/engines';
13
14
  import { debug } from '$shared/utils/logger';
14
15
 
15
16
  export async function fetchCopilotModels(
@@ -49,9 +50,26 @@ function summariseModelsError(error: unknown): string {
49
50
  return firstLine;
50
51
  }
51
52
 
53
+ /**
54
+ * Copilot's reasoning knob is the SDK `SessionConfig.reasoningEffort`. The
55
+ * models.list payload reports which levels each model accepts
56
+ * (`supportedReasoningEfforts`) and its default (`defaultReasoningEffort`), so
57
+ * the control is fully model-driven. Absent when the model doesn't support it.
58
+ */
59
+ function buildCopilotReasoningControl(info: ModelInfo): ReasoningControl | undefined {
60
+ if (!info.capabilities?.supports?.reasoningEffort) return undefined;
61
+ const levels = info.supportedReasoningEfforts ?? [];
62
+ if (levels.length === 0) return undefined;
63
+ return {
64
+ levels: toReasoningOptions(levels),
65
+ default: info.defaultReasoningEffort ?? levels[0],
66
+ };
67
+ }
68
+
52
69
  function mapModelInfoToEngineModel(info: ModelInfo): EngineModel {
53
70
  const limits = info.capabilities?.limits;
54
71
  const supports = info.capabilities?.supports;
72
+ const reasoningControl = buildCopilotReasoningControl(info);
55
73
  return {
56
74
  engine: {
57
75
  type: 'copilot',
@@ -83,6 +101,7 @@ function mapModelInfoToEngineModel(info: ModelInfo): EngineModel {
83
101
  reasoning: !!supports?.reasoningEffort,
84
102
  tools: true,
85
103
  structuredOutput: false,
104
+ ...(reasoningControl && { reasoningControl }),
86
105
  },
87
106
  cost: {
88
107
  input: info.billing?.multiplier ?? 0,