@myrialabs/clopen 0.4.14 → 0.4.16

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 (130) hide show
  1. package/backend/artifacts/matrix.ts +8 -0
  2. package/backend/artifacts/types.ts +2 -2
  3. package/backend/auth/permissions.ts +16 -0
  4. package/backend/chat/stream-manager.ts +5 -5
  5. package/backend/commands/detect.ts +1 -1
  6. package/backend/commands/sync.ts +1 -1
  7. package/backend/database/migrations/056_support_mssql_driver.ts +137 -0
  8. package/backend/database/migrations/057_seed_pi_provider.ts +25 -0
  9. package/backend/database/migrations/058_seed_cline_provider.ts +25 -0
  10. package/backend/database/migrations/059_seed_cursor_provider.ts +25 -0
  11. package/backend/database/migrations/index.ts +28 -0
  12. package/backend/database/queries/engine-queries.ts +13 -0
  13. package/backend/database/queries/message-queries.ts +43 -1
  14. package/backend/db-client/connection-manager.ts +8 -2
  15. package/backend/db-client/drivers/mssql.ts +829 -0
  16. package/backend/db-client/drivers/mysql.ts +33 -4
  17. package/backend/db-client/drivers/postgres.ts +55 -5
  18. package/backend/db-client/drivers/sql-builders.test.ts +70 -0
  19. package/backend/db-client/drivers/sql-builders.ts +9 -2
  20. package/backend/db-client/pool-config.ts +32 -0
  21. package/backend/db-client/query-executor.test.ts +42 -0
  22. package/backend/db-client/query-executor.ts +47 -3
  23. package/backend/engine/README.md +36 -13
  24. package/backend/engine/adapters/cline/agent-tool.ts +64 -0
  25. package/backend/engine/adapters/cline/ask-question-tool.ts +105 -0
  26. package/backend/engine/adapters/cline/credential.ts +166 -0
  27. package/backend/engine/adapters/cline/error-handler.ts +49 -0
  28. package/backend/engine/adapters/cline/index.ts +1 -0
  29. package/backend/engine/adapters/cline/mcp-tools.ts +119 -0
  30. package/backend/engine/adapters/cline/message-converter.ts +396 -0
  31. package/backend/engine/adapters/cline/models.ts +73 -0
  32. package/backend/engine/adapters/cline/presets.ts +128 -0
  33. package/backend/engine/adapters/cline/stream.ts +413 -0
  34. package/backend/engine/adapters/codex/credential.ts +1 -1
  35. package/backend/engine/adapters/codex/message-converter.ts +4 -4
  36. package/backend/engine/adapters/codex/session-fork.ts +1 -1
  37. package/backend/engine/adapters/codex/stream.ts +3 -3
  38. package/backend/engine/adapters/copilot/stream.ts +1 -1
  39. package/backend/engine/adapters/cursor/ask-question-tool.ts +98 -0
  40. package/backend/engine/adapters/cursor/credential.ts +68 -0
  41. package/backend/engine/adapters/cursor/environment.ts +32 -0
  42. package/backend/engine/adapters/cursor/error-handler.ts +60 -0
  43. package/backend/engine/adapters/cursor/index.ts +1 -0
  44. package/backend/engine/adapters/cursor/message-converter.ts +615 -0
  45. package/backend/engine/adapters/cursor/models.ts +68 -0
  46. package/backend/engine/adapters/cursor/session-fork.ts +68 -0
  47. package/backend/engine/adapters/cursor/stream.ts +341 -0
  48. package/backend/engine/adapters/opencode/config.ts +9 -0
  49. package/backend/engine/adapters/opencode/models.ts +10 -1
  50. package/backend/engine/adapters/opencode/server.ts +110 -2
  51. package/backend/engine/adapters/pi/agent-tool.ts +62 -0
  52. package/backend/engine/adapters/pi/ask-question-tool.ts +93 -0
  53. package/backend/engine/adapters/pi/credential.ts +137 -0
  54. package/backend/engine/adapters/pi/environment.ts +33 -0
  55. package/backend/engine/adapters/pi/error-handler.ts +46 -0
  56. package/backend/engine/adapters/pi/index.ts +1 -0
  57. package/backend/engine/adapters/pi/mcp-tools.ts +131 -0
  58. package/backend/engine/adapters/pi/message-converter.ts +446 -0
  59. package/backend/engine/adapters/pi/models.ts +53 -0
  60. package/backend/engine/adapters/pi/presets.ts +133 -0
  61. package/backend/engine/adapters/pi/session-fork.ts +46 -0
  62. package/backend/engine/adapters/pi/stream.ts +427 -0
  63. package/backend/engine/adapters/qwen/message-converter.ts +5 -5
  64. package/backend/engine/adapters/qwen/stream.ts +2 -2
  65. package/backend/engine/docs/adapter-contract.md +7 -2
  66. package/backend/engine/docs/adding-an-engine.md +70 -12
  67. package/backend/engine/docs/artifacts.md +124 -0
  68. package/backend/engine/docs/database.md +4 -4
  69. package/backend/engine/docs/frontend-and-chat.md +22 -4
  70. package/backend/engine/docs/lessons-learned.md +219 -32
  71. package/backend/engine/docs/quick-reference.md +18 -7
  72. package/backend/engine/docs/websocket-routes.md +2 -2
  73. package/backend/engine/index.ts +9 -0
  74. package/backend/index.ts +6 -0
  75. package/backend/mcp/README.md +3 -3
  76. package/backend/mcp/external/config.ts +11 -0
  77. package/backend/mcp/index.ts +8 -0
  78. package/backend/mcp/internal/config.ts +33 -1
  79. package/backend/permissions/service.ts +5 -2
  80. package/backend/preview/browser/browser-preview-service.ts +15 -6
  81. package/backend/preview/browser/browser-video-capture.ts +232 -100
  82. package/backend/preview/browser/scripts/video-stream.ts +216 -56
  83. package/backend/preview/browser/types.ts +24 -12
  84. package/backend/skills/sync.ts +1 -1
  85. package/backend/subagents/detect.ts +1 -1
  86. package/backend/subagents/sync.ts +1 -1
  87. package/backend/ws/chat/stream.ts +13 -5
  88. package/backend/ws/db-client/connections.ts +2 -1
  89. package/backend/ws/db-client/query.ts +41 -4
  90. package/backend/ws/db-client/schema.ts +45 -1
  91. package/backend/ws/engine/claude/accounts.ts +37 -13
  92. package/backend/ws/engine/cline/accounts.ts +317 -0
  93. package/backend/ws/engine/cline/index.ts +15 -0
  94. package/backend/ws/engine/cline/presets.ts +36 -0
  95. package/backend/ws/engine/cline/status.ts +49 -0
  96. package/backend/ws/engine/codex/accounts.ts +37 -5
  97. package/backend/ws/engine/copilot/accounts.ts +12 -0
  98. package/backend/ws/engine/cursor/accounts.ts +162 -0
  99. package/backend/ws/engine/cursor/index.ts +13 -0
  100. package/backend/ws/engine/cursor/status.ts +55 -0
  101. package/backend/ws/engine/index.ts +6 -0
  102. package/backend/ws/engine/opencode/providers.ts +72 -1
  103. package/backend/ws/engine/pi/accounts.ts +319 -0
  104. package/backend/ws/engine/pi/index.ts +15 -0
  105. package/backend/ws/engine/pi/presets.ts +34 -0
  106. package/backend/ws/engine/pi/status.ts +50 -0
  107. package/backend/ws/engine/qwen/accounts.ts +22 -0
  108. package/backend/ws/messages/crud.ts +13 -0
  109. package/backend/ws/preview/browser/interact.ts +10 -8
  110. package/backend/ws/preview/browser/webcodecs.ts +26 -2
  111. package/backend/ws/sessions/crud.ts +2 -2
  112. package/backend/ws/settings/crud.ts +2 -2
  113. package/dist/assets/{index-CDZf6lfv.js → index-BPvctwJ2.js} +1 -1
  114. package/dist/assets/{index-BWf-DDJN.js → index-vLKZpWQH.js} +1 -1
  115. package/dist/assets/{main-C15mQTCW.js → main-BtBZvCwv.js} +428 -386
  116. package/dist/assets/main-D7ATW8pp.css +1 -0
  117. package/dist/index.html +2 -2
  118. package/package.json +11 -1
  119. package/shared/constants/engine-tools.ts +16 -2
  120. package/shared/constants/engines.ts +27 -0
  121. package/shared/types/db-client/connection.ts +1 -1
  122. package/shared/types/db-client/query.ts +4 -1
  123. package/shared/types/unified/common.ts +1 -1
  124. package/shared/types/unified/engine.ts +82 -1
  125. package/shared/types/unified/index.ts +6 -0
  126. package/shared/types/unified/message.ts +1 -1
  127. package/shared/utils/db-client/split-sql.test.ts +13 -0
  128. package/shared/utils/db-client/split-sql.ts +38 -1
  129. package/shared/utils/subagent-wire-trim.ts +87 -0
  130. package/dist/assets/main-Ba5ZGlY4.css +0 -1
@@ -0,0 +1,124 @@
1
+ [← Engine adapter guide](../README.md)
2
+
3
+ ## 8. Artifacts & the extension layer
4
+
5
+ The adapters stream chat; **artifacts** are the reusable "extensions" the user
6
+ manages in **Settings → Artifacts & Access** that shape what each engine sees and
7
+ may do during that stream — Skills, Commands, Subagents, Instructions,
8
+ Permissions, Profiles, and Connectors (MCP).
9
+
10
+ They are a **separate subsystem** (`backend/artifacts/` + one module per feature)
11
+ that meets the adapter layer at exactly one seam: `backend/engine/artifact-sync.ts`,
12
+ called at stream start by every adapter. This section is the **map + integration
13
+ point** — the per-feature source of truth is the doc-comment atop each module
14
+ (`backend/artifacts/types.ts`, `matrix.ts`, and each feature's `service.ts`).
15
+
16
+ ### 8.1 What lives under "Artifacts & Access"
17
+
18
+ Seven menus, each a canonical source (DB metadata + on-disk store, or a repo
19
+ file) that is **materialized** per engine. Coverage differs by engine because
20
+ each exposes a different native surface.
21
+
22
+ | Menu (UI) | Backend module | WS router | Materialized as |
23
+ |------------------|-------------------------|----------------------------|-----------------|
24
+ | Connectors (MCP) | `backend/mcp/` | `backend/ws/mcp/` | config object + `/mcp/ext/<slug>` bridge — **not** a file artifact (see §8.5) |
25
+ | Skills | `backend/skills/` | `backend/ws/skills/` | `folder-md` in a native dir, or synthetic preamble |
26
+ | Commands | `backend/commands/` | `backend/ws/commands/` | `single-md` in a native dir, or synthetic preamble |
27
+ | Subagents | `backend/subagents/` | `backend/ws/subagents/` | `single-md` in a native dir, or synthetic preamble |
28
+ | Instructions | `backend/instructions/` | `backend/ws/instructions/` | `preamble-region` inside the engine memory file |
29
+ | Permissions | `backend/permissions/` | `backend/ws/permissions/` | runtime hook (+ optional Claude `settings.json`) |
30
+ | Profiles | `backend/profiles/` | `backend/ws/profiles/` | not materialized — a **bundle** that narrows the others |
31
+
32
+ `ArtifactType` (`backend/artifacts/types.ts`) is
33
+ `skill | command | subagent | instruction | mcp | permission`. Two deliberate
34
+ mismatches with the menu list:
35
+
36
+ - **`mcp` is a reserved slot with no adapter** — MCP servers are config objects,
37
+ not files, so they keep their own path (§8.5).
38
+ - **Profiles is not an artifact type** — it is a bundling/scoping concept layered
39
+ on top of the others (§8.4).
40
+
41
+ ### 8.2 The capability matrix
42
+
43
+ `backend/artifacts/matrix.ts` is the single table the generic writer (`sync.ts`)
44
+ and scanner (`detect.ts`) consult. For every `artifactType × engine × scope` it
45
+ resolves **where** an artifact is materialized and **in what shape**
46
+ (`ArtifactResolution`). Adding a feature is a new row here — not new sync code.
47
+
48
+ Two strategies recur, mirroring the two engine families:
49
+
50
+ - **NATIVE** (Claude, Qwen, Copilot) — the engine reads a real artifact
51
+ directory (Claude `<config>/{skills,commands,agents}`, OpenCode
52
+ `<config>/opencode/{command,agent}`, Codex `$CODEX_HOME/prompts`). Clopen
53
+ mirrors only the slugs it owns into that dir (`ownership: 'whole-file'`).
54
+ - **SYNTHETIC** (Codex, OpenCode) — no native concept for a type, so Clopen
55
+ injects a marker-delimited block (`preamble-region`) into the engine's global
56
+ memory file (`AGENTS.md`).
57
+
58
+ > **Synthetic targets are best-effort.** They follow each engine's documented
59
+ > global-memory convention but are unverified, and are surfaced with a marker so
60
+ > the UI never claims they definitely take effect.
61
+
62
+ **Scope.** `global` paths live in the engine's *isolated* config dir
63
+ (`getEngineUserConfigDir`) so Clopen never mixes with the user's own CLI usage —
64
+ except Qwen/Copilot skills, which resolve from the real `$HOME`. `project` paths
65
+ live in the repo (`.claude/…`, `CLAUDE.md`, …). The isolation itself is §10.19;
66
+ the matrix only decides *which* isolated path each artifact lands in.
67
+ `matrix.ts`'s `locateReal` returns the user's *real* standard locations, scanned
68
+ by **detect & link** so existing on-disk artifacts can be adopted.
69
+
70
+ ### 8.3 Integration point — `artifact-sync.ts`
71
+
72
+ `backend/engine/artifact-sync.ts` is the **only** file where the artifact
73
+ subsystem meets the adapter layer. Every adapter (`claude`, `qwen`, `codex`,
74
+ `copilot`, `opencode`) calls into it from `stream.ts` at stream start, right
75
+ after `syncSkills`, so all features share one trigger point without each adapter
76
+ growing separate calls (see the file taxonomy in §2.6).
77
+
78
+ | Export | Role |
79
+ |--------|------|
80
+ | `syncEngineArtifacts(engine, profileId?)` | Materializes Commands, Subagents, and Instructions for the engine. **Global scope only** — writing project-scoped instructions into a repo's `CLAUDE.md` / `AGENTS.md` touches the working tree, which must be an explicit user action, never silent at stream start. |
81
+ | `buildArtifactsPromptContext(profileId?)` | Returns the combined, profile-scoped Skills + Commands + Subagents preamble that **prompt-scoped engines** (OpenCode / Codex / Copilot) inject into each turn's prompt. |
82
+
83
+ > **Sequential, not `Promise.all`.** On synthetic engines all three sync calls
84
+ > write into the same `AGENTS.md`; running them concurrently would race the
85
+ > read-modify-write and drop blocks. Each call swallows its own errors, so one
86
+ > failure never stops the others and the function never throws.
87
+
88
+ `profileId` scopes Commands/Subagents to the active Profile's bundle (§8.4);
89
+ Instructions are never profile-bundled. Prompt-scoped engines need the preamble
90
+ because they read artifacts through a channel shared across sessions and not
91
+ reliably re-read per turn — the prompt is the one genuinely per-session channel.
92
+
93
+ ### 8.4 Per-artifact map
94
+
95
+ | Artifact | Canonical source | Scope | Sync behaviour |
96
+ |----------|------------------|-------|----------------|
97
+ | **Skills** (`backend/skills/`) | DB metadata + on-disk store; marketplace-installable | global, project | mirrored folder (`folder-md`) on native engines, synthetic preamble otherwise. Keeps its own `syncSkills` call — the framework generalized this mechanic |
98
+ | **Commands** (`backend/commands/`) | custom slash commands | global, project | one `.md` per command into the engine command dir, or synthetic preamble. Profile-bundled |
99
+ | **Subagents** (`backend/subagents/`) | specialized delegated agents | global, project | one `.md` per subagent, or synthetic preamble. Profile-bundled |
100
+ | **Instructions** (`backend/instructions/`) | a shared instruction block | global, project | marker region inside the engine memory file (`CLAUDE.md` / `QWEN.md` / `AGENTS.md`). Global set always synced in full; never profile-bundled |
101
+ | **Permissions** (`backend/permissions/`) | per-engine tool allow/deny | global, project | **enforcement is a runtime hook** (`resolvePermissionsFromDb` + `isToolAllowed`) each adapter consults at its auto-approve point. The matrix only describes the optional on-disk "honesty" file, which today only Claude reads (a managed `permissions` key merged into its isolated `settings.json`) |
102
+ | **Profiles** (`backend/profiles/`) | a named bundle of slugs | per session | not materialized. Narrows which instance-global artifacts are active: effective profile = `chat_sessions.profile_id ?? projects.default_profile_id`, resolved once at stream start and threaded down as `profileId`. Only constrains the types it references (`artifactFilter` → `null` = unconstrained), so a Commands-only profile never disables every Skill |
103
+
104
+ ### 8.5 Connectors (MCP)
105
+
106
+ MCP is part of Artifacts & Access in the UI but is **not** part of this file
107
+ framework — it has its own subsystem. MCP servers are config objects composed
108
+ per engine and proxied through the `/mcp/ext/<slug>` bridge, so forcing them
109
+ through a file writer/detector would be a mis-fit; the `'mcp'` slot in
110
+ `ArtifactType` exists only for future extensibility. Profiles can still reference
111
+ MCP connectors as bundle items (§8.4).
112
+
113
+ For MCP's own architecture — internal `defineServer()` tools, the OAuth client,
114
+ the remote HTTP bridge, per-engine config, and tool overrides — see
115
+ [`backend/mcp/README.md`](../../mcp/README.md). The engine-side MCP reuse rules
116
+ live in §10.12 (internal bridge) and §10.18 (external servers).
117
+
118
+ ---
119
+
120
+ See also: [`backend/artifacts/`](../../artifacts/) (matrix, generic sync/detect,
121
+ authoritative doc-comments) and §2.6 for where `artifact-sync.ts` sits in the
122
+ adapter file taxonomy.
123
+
124
+ ---
@@ -91,12 +91,12 @@ getProvidersWithAccounts(engineType?) // join used by endpoint listing
91
91
  and constructs a fresh `CopilotClient({ gitHubToken: account.credential })`.
92
92
  The Copilot SDK takes the token at **client construction time**, so a
93
93
  per-stream account switch requires `dispose()` + `initialize(newId)` —
94
- see `streamQuery` in `copilot/stream.ts` and §9.9 below.
94
+ see `streamQuery` in `copilot/stream.ts` and §10.9 below.
95
95
 
96
96
  > **Pattern: auth-blob materialization for shared CLI dotfiles.**
97
97
  > Some CLIs (e.g. Codex's `auth.json`) read credentials from a fixed
98
98
  > filename inside their home dir. That home dir is isolated to
99
- > `{clopenDir}/engine/codex/user/` (via `CODEX_HOME` — see §9.19), but it is a
99
+ > `{clopenDir}/engine/codex/user/` (via `CODEX_HOME` — see §10.19), but it is a
100
100
  > **single** dir shared by all of the engine's Clopen accounts, so the
101
101
  > dotfile inside it still has to be swapped per account. For those engines,
102
102
  > `credential` stores the **whole file content** as a JSON wrapper
@@ -105,8 +105,8 @@ getProvidersWithAccounts(engineType?) // join used by endpoint listing
105
105
  > each stream, snapshot the (possibly-refreshed-by-the-CLI) dotfile back
106
106
  > into `engine_accounts.credential` so token refreshes survive across
107
107
  > account switches. This keeps multi-account support working **without**
108
- > per-account `XYZ_HOME` directories — see §9.13 for the rationale, and
109
- > §9.19 for the Clopen-vs-global home-dir isolation.
108
+ > per-account `XYZ_HOME` directories — see §10.13 for the rationale, and
109
+ > §10.19 for the Clopen-vs-global home-dir isolation.
110
110
 
111
111
  ### 3.4 The models.dev catalog (OpenCode-specific)
112
112
 
@@ -5,14 +5,32 @@
5
5
  ### 5.1 Settings → Engines
6
6
 
7
7
  Files:
8
- - `frontend/components/settings/engines/AIEnginesSettings.svelte`
8
+ - `frontend/components/settings/engines/AIEnginesSettings.svelte` — the shell:
9
+ renders the engine selector grid, fetches every engine's status on mount
10
+ (for the grid badges), and delegates the active engine's card to a panel.
11
+ - `frontend/components/settings/engines/panels/` — one self-contained panel
12
+ per engine (`ClaudeCodePanel`, `CopilotPanel`, `CodexPanel`, `QwenPanel`,
13
+ `PiPanel`, `OpenCodePanel`), each owning its own add/edit/delete flow state,
14
+ WS listeners, and dialogs. Shared helpers live alongside them:
15
+ `panel-types.ts` (the per-engine status shapes) and `debug-viewer.ts`
16
+ (the read-only xterm viewer used by Claude + Codex).
9
17
  - Stores: `frontend/stores/features/claude-accounts.svelte.ts`,
10
18
  `frontend/stores/features/copilot-accounts.svelte.ts`,
11
19
  `frontend/stores/features/opencode-providers.svelte.ts`
12
20
 
13
21
  Pattern:
14
- - The component renders one card **per engine** from the `ENGINES` constant
15
- in `shared/constants/engines.ts` (icon, name, description).
22
+ - The shell renders one selector tile **per engine** from the `ENGINES`
23
+ constant in `shared/constants/engines.ts` (icon, name, description) and
24
+ mounts only the active engine's panel. `status` + `isLoading` are passed
25
+ down as props; panels that mutate account state also receive an
26
+ `onRefreshStatus` callback (the shell's per-engine status refresh) so the
27
+ grid's installed/count badges stay current.
28
+ - **Re-authentication is in-place**: engines with a browser/device auth flow
29
+ (Claude, Codex, Pi) render that flow *inside the account's edit form*,
30
+ replacing the name field. A shared `{#snippet}` holds the auth-flow markup
31
+ and is rendered both at the bottom "Add Account" area (new accounts) and in
32
+ the edit form (re-auth), gated on `<engine>ReauthAccountId`. Clicking
33
+ **Cancel** in the auth flow returns to the edit form.
16
34
  - For **Claude**: calls `engine:claude-status`. The "Add Account" button
17
35
  starts `engine:claude-account-setup-start` and renders an xterm terminal
18
36
  for debug + to display the auth URL.
@@ -170,7 +188,7 @@ Backend `chat:stream` then `streamManager.startStream(...)`, which:
170
188
  **no** MCP-tool fallback: the previous engine-agnostic MCP path was
171
189
  removed (its carrying cost outweighed the benefit). Do not reintroduce
172
190
  it — wire the engine's native hook to `resolveUserAnswer` when it
173
- exists. See §9.12 point 3.
191
+ exists. See §10.12 point 3.
174
192
 
175
193
  ---
176
194