@myrialabs/clopen 0.4.39 → 0.4.41
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/.env.example +1 -1
- package/backend/artifacts/detect.ts +15 -3
- package/backend/artifacts/generate.ts +2 -2
- package/backend/artifacts/index.ts +12 -4
- package/backend/artifacts/markers.ts +24 -1
- package/backend/artifacts/matrix.ts +47 -3
- package/backend/artifacts/sync.test.ts +3 -3
- package/backend/artifacts/sync.ts +8 -20
- package/backend/artifacts/types.ts +9 -3
- package/backend/auth/permissions.ts +29 -11
- package/backend/auth/session-cleanup.ts +10 -1
- package/backend/auth/tokens.ts +9 -1
- package/backend/chat/stream-manager.ts +42 -0
- package/backend/database/crypto/secret-columns.ts +5 -1
- package/backend/database/migrations/078_create_worktree_branch_tables.ts +158 -0
- package/backend/database/migrations/079_merge_commands_into_skills.ts +222 -0
- package/backend/database/migrations/080_create_file_shares.ts +111 -0
- package/backend/database/migrations/081_create_push_subscriptions.ts +32 -0
- package/backend/database/migrations/index.ts +28 -0
- package/backend/database/queries/file-share-queries.ts +163 -0
- package/backend/database/queries/index.ts +12 -4
- package/backend/database/queries/profile-queries.ts +5 -3
- package/backend/database/queries/push-subscription-queries.test.ts +90 -0
- package/backend/database/queries/push-subscription-queries.ts +99 -0
- package/backend/database/queries/skill-queries.ts +96 -18
- package/backend/database/queries/worktree-branch-queries.ts +331 -0
- package/backend/db-client/cloning.test.ts +161 -0
- package/backend/db-client/cloning.ts +672 -0
- package/backend/db-client/connection-url.test.ts +117 -0
- package/backend/db-client/connection-url.ts +126 -0
- package/backend/db-client/drivers/mongodb.ts +2 -14
- package/backend/db-client/drivers/mysql.ts +2 -8
- package/backend/db-client/drivers/postgres.ts +10 -13
- package/backend/db-client/drivers/redis.ts +2 -6
- package/backend/db-client/env/detect.ts +438 -0
- package/backend/db-client/env/diff.ts +94 -0
- package/backend/db-client/env/env.test.ts +574 -0
- package/backend/db-client/env/index.ts +15 -0
- package/backend/db-client/env/naming.ts +202 -0
- package/backend/db-client/env/service.ts +487 -0
- package/backend/db-client/integrations/index.ts +7 -0
- package/backend/db-client/integrations/links.ts +41 -10
- package/backend/db-client/providers/neon/adapter.ts +522 -0
- package/backend/db-client/providers/neon/api-types.ts +182 -0
- package/backend/db-client/providers/neon/client.ts +298 -0
- package/backend/db-client/providers/neon/endpoints.test.ts +201 -0
- package/backend/db-client/providers/neon/endpoints.ts +314 -0
- package/backend/db-client/providers/neon/list.test.ts +181 -0
- package/backend/db-client/providers/supabase/adapter.ts +25 -2
- package/backend/db-client/providers/types.ts +57 -0
- package/backend/engine/adapters/claude/stream.ts +2 -1
- package/backend/engine/adapters/cline/stream.ts +3 -3
- package/backend/engine/adapters/codex/stream.ts +3 -3
- package/backend/engine/adapters/copilot/stream.ts +3 -3
- package/backend/engine/adapters/cursor/stream.ts +25 -3
- package/backend/engine/adapters/opencode/stream.ts +4 -6
- package/backend/engine/adapters/pi/stream.ts +2 -2
- package/backend/engine/adapters/qwen/stream.ts +2 -2
- package/backend/engine/artifact-sync.ts +26 -20
- package/backend/engine/docs/artifacts.md +81 -22
- package/backend/engine/docs/quick-reference.md +2 -1
- package/backend/engine/resolve-model.test.ts +108 -0
- package/backend/engine/resolve-model.ts +53 -10
- package/backend/engine/structured-helpers.ts +22 -0
- package/backend/env-files/discovery.ts +48 -0
- package/backend/env-files/edit.ts +213 -0
- package/backend/env-files/env-files.test.ts +515 -0
- package/backend/env-files/git.ts +27 -0
- package/backend/env-files/index.ts +44 -0
- package/backend/env-files/keys.ts +69 -0
- package/backend/env-files/parse.ts +157 -0
- package/backend/env-files/write.ts +229 -0
- package/backend/files/file-shares.ts +369 -0
- package/backend/files/path-browsing.ts +27 -21
- package/backend/http/files-shared.test.ts +505 -0
- package/backend/http/files-shared.ts +351 -0
- package/backend/http/push.ts +150 -0
- package/backend/index.ts +8 -0
- package/backend/instructions/index.ts +1 -1
- package/backend/instructions/sync.ts +30 -6
- package/backend/integrations/health.ts +18 -4
- package/backend/integrations/projections/types.ts +9 -2
- package/backend/integrations/registry/index.ts +3 -0
- package/backend/integrations/registry/providers/context7.ts +1 -0
- package/backend/integrations/registry/providers/firecrawl.ts +1 -0
- package/backend/integrations/registry/providers/github.ts +1 -0
- package/backend/integrations/registry/providers/neon.ts +55 -0
- package/backend/integrations/registry/providers/supabase.ts +1 -0
- package/backend/integrations/registry/providers/vercel.ts +1 -0
- package/backend/integrations/registry/types.ts +2 -0
- package/backend/memory/compose.ts +2 -2
- package/backend/memory/consolidate.ts +2 -2
- package/backend/memory/extract/episodic.ts +2 -2
- package/backend/memory/judge.ts +2 -2
- package/backend/profiles/service.ts +7 -6
- package/backend/push/sender.ts +172 -0
- package/backend/push/tags.ts +25 -0
- package/backend/push/vapid-keys.ts +77 -0
- package/backend/push/webpush-crypto.test.ts +200 -0
- package/backend/push/webpush-crypto.ts +231 -0
- package/backend/skills/detect.ts +28 -0
- package/backend/skills/index.ts +22 -4
- package/backend/skills/invoke.test.ts +114 -0
- package/backend/skills/invoke.ts +222 -0
- package/backend/skills/service.ts +194 -44
- package/backend/skills/spec.ts +35 -0
- package/backend/skills/sync.ts +85 -55
- package/backend/subagents/detect.ts +2 -3
- package/backend/subagents/sync.ts +15 -8
- package/backend/work/pull-requests.ts +2 -2
- package/backend/work/start-work.ts +4 -0
- package/backend/worktrees/branching/engine.ts +557 -0
- package/backend/worktrees/branching/index.ts +56 -0
- package/backend/worktrees/branching/naming.test.ts +118 -0
- package/backend/worktrees/branching/naming.ts +97 -0
- package/backend/worktrees/branching/projector.test.ts +229 -0
- package/backend/worktrees/branching/projector.ts +139 -0
- package/backend/worktrees/branching/providers/neon.ts +220 -0
- package/backend/worktrees/branching/registry.ts +27 -0
- package/backend/worktrees/branching/service.ts +620 -0
- package/backend/worktrees/branching/suggest.test.ts +154 -0
- package/backend/worktrees/branching/suggest.ts +202 -0
- package/backend/worktrees/branching/types.ts +88 -0
- package/backend/worktrees/index.ts +7 -0
- package/backend/worktrees/service.ts +48 -1
- package/backend/ws/chat/stream.ts +100 -8
- package/backend/ws/db-client/env.ts +142 -0
- package/backend/ws/db-client/index.ts +2 -0
- package/backend/ws/files/index.ts +4 -0
- package/backend/ws/files/share.ts +95 -0
- package/backend/ws/git/branch-name.ts +2 -2
- package/backend/ws/git/commit-message.ts +2 -2
- package/backend/ws/index.ts +3 -4
- package/backend/ws/profiles/crud.ts +2 -3
- package/backend/ws/projects/index.ts +6 -1
- package/backend/ws/projects/info.ts +70 -6
- package/backend/ws/projects/overview.test.ts +108 -0
- package/backend/ws/projects/overview.ts +300 -0
- package/backend/ws/skills/catalog.ts +5 -1
- package/backend/ws/skills/crud.ts +128 -22
- package/backend/ws/skills/index.ts +4 -1
- package/backend/ws/system/device-info.ts +307 -76
- package/backend/ws/user/crud.ts +12 -3
- package/backend/ws/worktrees/branching.ts +212 -0
- package/backend/ws/worktrees/crud.ts +33 -7
- package/backend/ws/worktrees/index.ts +14 -0
- package/dist/assets/{index-C8Gi-b6U.js → index-CeNKKSDR.js} +1 -1
- package/dist/assets/{index-BrF6nqld.js → index-DW89566K.js} +1 -1
- package/dist/assets/main-Cy5DXWPT.js +1207 -0
- package/dist/assets/main-DJKj_4By.css +1 -0
- package/dist/index.html +7 -2
- package/dist/sw.js +112 -0
- package/package.json +1 -1
- package/shared/constants/engine-tools.ts +31 -6
- package/shared/constants/notification-messages.ts +142 -0
- package/shared/constants/tool-icons.ts +6 -2
- package/shared/types/db-client/env.ts +192 -0
- package/shared/types/db-client/index.ts +1 -0
- package/shared/types/db-client/integrations.ts +30 -0
- package/shared/types/integrations.ts +9 -0
- package/shared/types/unified/stream.ts +7 -0
- package/shared/types/worktree-branching.ts +315 -0
- package/shared/utils/logger.ts +1 -0
- package/backend/commands/detect.ts +0 -25
- package/backend/commands/index.ts +0 -9
- package/backend/commands/service.ts +0 -178
- package/backend/commands/store.ts +0 -45
- package/backend/commands/sync.ts +0 -94
- package/backend/database/queries/command-queries.ts +0 -82
- package/backend/ws/commands/crud.ts +0 -157
- package/backend/ws/commands/index.ts +0 -8
- package/dist/assets/main-Bd3gb79F.css +0 -1
- package/dist/assets/main-Bo1hD7mt.js +0 -1191
|
@@ -19,7 +19,7 @@ import type {
|
|
|
19
19
|
import { loadEngineSdk } from '$backend/engine/sdk-loader';
|
|
20
20
|
import type { EngineOutput, EngineModel } from '$shared/types/unified';
|
|
21
21
|
import type { AIEngine, EngineQueryOptions, StructuredGenerationOptions } from '../../types';
|
|
22
|
-
import { buildJsonPrompt, extractJson } from '../../structured-helpers';
|
|
22
|
+
import { buildJsonPrompt, extractJson, emptyGenerationError } from '../../structured-helpers';
|
|
23
23
|
import { engineQueries } from '$backend/database/queries/engine-queries';
|
|
24
24
|
import { resolveOsPath, getEngineUserConfigDir } from '$backend/utils/paths';
|
|
25
25
|
import { debug } from '$shared/utils/logger';
|
|
@@ -279,7 +279,7 @@ export class CopilotEngine implements AIEngine {
|
|
|
279
279
|
// the authoritative per-session signal (synthetic commands/subagents are
|
|
280
280
|
// stripped from the global file; the native skill mirror still loads the
|
|
281
281
|
// filtered folders).
|
|
282
|
-
const artifactsContext = buildArtifactsPromptContext(profileId);
|
|
282
|
+
const artifactsContext = buildArtifactsPromptContext('copilot', profileId);
|
|
283
283
|
|
|
284
284
|
// Resolve the permission policy once per stream; onPermissionRequest below
|
|
285
285
|
// enforces it (Copilot otherwise approves every tool via approveAll).
|
|
@@ -741,7 +741,7 @@ export class CopilotEngine implements AIEngine {
|
|
|
741
741
|
try {
|
|
742
742
|
const final = await session.sendAndWait({ prompt: jsonPrompt });
|
|
743
743
|
if (!final?.data?.content) {
|
|
744
|
-
throw
|
|
744
|
+
throw emptyGenerationError('GitHub Copilot', 'no assistant message content');
|
|
745
745
|
}
|
|
746
746
|
return extractJson<T>(final.data.content);
|
|
747
747
|
} finally {
|
|
@@ -31,10 +31,11 @@ import { engineQueries } from '$backend/database/queries/engine-queries';
|
|
|
31
31
|
import { syncSkills } from '$backend/skills';
|
|
32
32
|
import { syncEngineArtifacts, buildArtifactsPromptContext } from '$backend/engine/artifact-sync';
|
|
33
33
|
import { artifactFilter } from '$backend/profiles';
|
|
34
|
+
import { resolvePermissionsFromDb, excludedBuiltinTools } from '$backend/permissions';
|
|
34
35
|
import { getCursorMcpConfig } from '../../../mcp';
|
|
35
36
|
import { subagentQueries } from '$backend/database/queries';
|
|
36
37
|
import { readSubagentMd } from '$backend/subagents/store';
|
|
37
|
-
import { buildJsonPrompt, extractJson } from '../../structured-helpers';
|
|
38
|
+
import { buildJsonPrompt, extractJson, emptyGenerationError } from '../../structured-helpers';
|
|
38
39
|
import { EngineRuns } from '../run-registry';
|
|
39
40
|
import { getActiveCursorAccount, resolveCursorApiKey } from './credential';
|
|
40
41
|
import { getCursorStore } from './environment';
|
|
@@ -177,6 +178,20 @@ export class CursorEngine implements AIEngine {
|
|
|
177
178
|
await syncSkills('cursor', profileId);
|
|
178
179
|
await syncEngineArtifacts('cursor', profileId);
|
|
179
180
|
|
|
181
|
+
// ── Permissions → disallowedTools ──
|
|
182
|
+
// Cursor exposes no per-call permission hook, but `AgentOptions` takes a
|
|
183
|
+
// `disallowedTools` list that is applied before the toolset is offered to
|
|
184
|
+
// the model — strictly stronger than a hook, since a blocked tool is never
|
|
185
|
+
// even visible. Names must come from the SDK's own vocabulary (see
|
|
186
|
+
// ENGINE_BUILTIN_TOOLS.cursor); an unknown one throws at Agent.create.
|
|
187
|
+
// Not persisted on the agent, so it is passed to BOTH create and resume.
|
|
188
|
+
const permissions = resolvePermissionsFromDb('cursor', options.mcpContext?.projectId, profileId);
|
|
189
|
+
const disallowedTools = excludedBuiltinTools(permissions, 'cursor');
|
|
190
|
+
if (disallowedTools.length > 0) {
|
|
191
|
+
debug.log('engine', `Cursor permissions: withholding ${disallowedTools.length} tool(s) — ${disallowedTools.join(', ')}`);
|
|
192
|
+
}
|
|
193
|
+
const toolPolicy = disallowedTools.length > 0 ? { disallowedTools } : {};
|
|
194
|
+
|
|
180
195
|
// ── Output queue merging the pull stream with the ask tool's push emissions ──
|
|
181
196
|
const queue = new EventQueue<EngineOutput>();
|
|
182
197
|
const converterHolder: { current: ReturnType<typeof createCursorMessageConverter> | null } = { current: null };
|
|
@@ -224,6 +239,7 @@ export class CursorEngine implements AIEngine {
|
|
|
224
239
|
apiKey,
|
|
225
240
|
model: { id: modelId },
|
|
226
241
|
local: localOptions,
|
|
242
|
+
...toolPolicy,
|
|
227
243
|
...(Object.keys(mcpServers).length ? { mcpServers } : {}),
|
|
228
244
|
...(agents ? { agents } : {}),
|
|
229
245
|
})
|
|
@@ -231,6 +247,7 @@ export class CursorEngine implements AIEngine {
|
|
|
231
247
|
apiKey,
|
|
232
248
|
model: { id: modelId },
|
|
233
249
|
local: localOptions,
|
|
250
|
+
...toolPolicy,
|
|
234
251
|
...(Object.keys(mcpServers).length ? { mcpServers } : {}),
|
|
235
252
|
...(agents ? { agents } : {}),
|
|
236
253
|
});
|
|
@@ -246,8 +263,13 @@ export class CursorEngine implements AIEngine {
|
|
|
246
263
|
converterHolder.current = converter;
|
|
247
264
|
|
|
248
265
|
// Build the user turn (text + image attachments).
|
|
266
|
+
//
|
|
267
|
+
// The artifact context rides the user message because `@cursor/sdk` has no
|
|
268
|
+
// system-prompt option — `AgentOptions` exposes model/tools/mcpServers/agents
|
|
269
|
+
// and nothing else. It is rebuilt per turn on purpose: the active Profile can
|
|
270
|
+
// change mid-session, and a stale advertisement is worse than a repeated one.
|
|
249
271
|
const promptText = prompt.content.filter(b => b.type === 'text').map(b => (b.type === 'text' ? b.text : '')).join('\n');
|
|
250
|
-
const artifacts = buildArtifactsPromptContext(profileId);
|
|
272
|
+
const artifacts = buildArtifactsPromptContext('cursor', profileId);
|
|
251
273
|
const text = artifacts ? `${artifacts}\n\n${promptText}` : promptText;
|
|
252
274
|
const images: SDKImage[] = [];
|
|
253
275
|
for (const b of prompt.content) {
|
|
@@ -394,7 +416,7 @@ export class CursorEngine implements AIEngine {
|
|
|
394
416
|
try {
|
|
395
417
|
const run = await agent.send(buildJsonPrompt(prompt, schema));
|
|
396
418
|
const result = await run.wait();
|
|
397
|
-
if (!result.result?.trim()) throw
|
|
419
|
+
if (!result.result?.trim()) throw emptyGenerationError('Cursor');
|
|
398
420
|
return extractJson<T>(result.result);
|
|
399
421
|
} finally {
|
|
400
422
|
try { agent.close(); } catch { /* ignore */ }
|
|
@@ -50,7 +50,7 @@ import { buildOpenCodeInlineAgents } from '$backend/subagents';
|
|
|
50
50
|
import { getOpenCodeProfileDisabledToolIds } from '$backend/mcp';
|
|
51
51
|
import { resolvePermissionsFromDb, matchesAny, type ResolvedPermissions } from '$backend/permissions';
|
|
52
52
|
import { formatSessionError, handleStreamError } from './error-handler';
|
|
53
|
-
import { buildJsonPrompt, extractJson } from '../../structured-helpers';
|
|
53
|
+
import { buildJsonPrompt, extractJson, emptyGenerationError } from '../../structured-helpers';
|
|
54
54
|
import { EngineRuns } from '../run-registry';
|
|
55
55
|
import { debug } from '$shared/utils/logger';
|
|
56
56
|
|
|
@@ -250,7 +250,7 @@ export class OpenCodeEngine implements AIEngine {
|
|
|
250
250
|
// so advertise the profile-scoped set PER-SESSION by prepending it as a
|
|
251
251
|
// leading context part each turn (authoritative for synthetic skills;
|
|
252
252
|
// advisory on top of the native command/agent dirs).
|
|
253
|
-
const artifactsContext = buildArtifactsPromptContext(profileId);
|
|
253
|
+
const artifactsContext = buildArtifactsPromptContext('opencode', profileId);
|
|
254
254
|
if (artifactsContext) {
|
|
255
255
|
promptParts.unshift({ type: 'text', text: artifactsContext });
|
|
256
256
|
}
|
|
@@ -1147,7 +1147,7 @@ export class OpenCodeEngine implements AIEngine {
|
|
|
1147
1147
|
|
|
1148
1148
|
const data = response.data;
|
|
1149
1149
|
if (!data) {
|
|
1150
|
-
throw
|
|
1150
|
+
throw emptyGenerationError('OpenCode', 'no response body');
|
|
1151
1151
|
}
|
|
1152
1152
|
|
|
1153
1153
|
const parts = data.parts || [];
|
|
@@ -1166,9 +1166,7 @@ export class OpenCodeEngine implements AIEngine {
|
|
|
1166
1166
|
const source = textContent || collectText('reasoning');
|
|
1167
1167
|
|
|
1168
1168
|
if (!source) {
|
|
1169
|
-
throw
|
|
1170
|
-
`OpenCode returned no parseable content (received parts: ${parts.map((p: any) => p.type).join(', ') || 'none'})`
|
|
1171
|
-
);
|
|
1169
|
+
throw emptyGenerationError('OpenCode', `received parts: ${parts.map((p: any) => p.type).join(', ') || 'none'}`);
|
|
1172
1170
|
}
|
|
1173
1171
|
|
|
1174
1172
|
debug.log('engine', `[OC structured] Raw text: ${source.slice(0, 200)}`);
|
|
@@ -38,7 +38,7 @@ import { syncSkills } from '$backend/skills';
|
|
|
38
38
|
import { syncEngineArtifacts } from '$backend/engine/artifact-sync';
|
|
39
39
|
import { artifactFilter } from '$backend/profiles';
|
|
40
40
|
import { resolvePermissionsFromDb, isToolAllowed } from '$backend/permissions';
|
|
41
|
-
import { buildJsonPrompt, extractJson } from '../../structured-helpers';
|
|
41
|
+
import { buildJsonPrompt, extractJson, emptyGenerationError } from '../../structured-helpers';
|
|
42
42
|
import { EngineRuns } from '../run-registry';
|
|
43
43
|
import { DbCredentialStore, getPiAccountForProvider, parsePiCredential } from './credential';
|
|
44
44
|
import { createPiRuntime } from './presets';
|
|
@@ -467,7 +467,7 @@ export class PiEngine implements AIEngine {
|
|
|
467
467
|
try { session.dispose(); } catch { /* ignore */ }
|
|
468
468
|
}
|
|
469
469
|
|
|
470
|
-
if (!resultText.trim()) throw
|
|
470
|
+
if (!resultText.trim()) throw emptyGenerationError('Pi');
|
|
471
471
|
return extractJson<T>(resultText);
|
|
472
472
|
}
|
|
473
473
|
}
|
|
@@ -39,7 +39,7 @@ import type {
|
|
|
39
39
|
import { loadEngineSdk } from '$backend/engine/sdk-loader';
|
|
40
40
|
import type { EngineOutput, EngineModel } from '$shared/types/unified';
|
|
41
41
|
import type { AIEngine, EngineQueryOptions, StructuredGenerationOptions } from '../../types';
|
|
42
|
-
import { buildJsonPrompt, extractJson } from '../../structured-helpers';
|
|
42
|
+
import { buildJsonPrompt, extractJson, emptyGenerationError } from '../../structured-helpers';
|
|
43
43
|
import { resolveOsPath } from '$backend/utils/paths';
|
|
44
44
|
import { debug } from '$shared/utils/logger';
|
|
45
45
|
import { getEngineEnv } from './environment';
|
|
@@ -474,7 +474,7 @@ export class QwenEngine implements AIEngine {
|
|
|
474
474
|
}
|
|
475
475
|
|
|
476
476
|
if (!resultText) {
|
|
477
|
-
throw
|
|
477
|
+
throw emptyGenerationError('Qwen Code', errorMessage || undefined);
|
|
478
478
|
}
|
|
479
479
|
|
|
480
480
|
return extractJson<T>(resultText);
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Per-stream materialization of the artifact-framework features that sit
|
|
3
|
-
* alongside Skills —
|
|
3
|
+
* alongside Skills — Subagents and (global) Instructions — plus the cleanup of
|
|
4
|
+
* artifacts earlier versions wrote for the now-merged Commands feature.
|
|
4
5
|
*
|
|
5
6
|
* Called at stream start by every engine adapter, right after `syncSkills`, so
|
|
6
|
-
* the
|
|
7
|
-
*
|
|
7
|
+
* the features share the exact same trigger point without each adapter growing
|
|
8
|
+
* separate calls.
|
|
8
9
|
*
|
|
9
10
|
* GLOBAL scope only: writing project-scoped instructions into a repo's
|
|
10
11
|
* `CLAUDE.md` / `AGENTS.md` touches the working tree, which the project's rules
|
|
@@ -12,40 +13,45 @@
|
|
|
12
13
|
* Each underlying sync swallows its own errors, so this never throws.
|
|
13
14
|
*/
|
|
14
15
|
|
|
15
|
-
import { syncCommands, buildCommandsPromptContext } from '$backend/commands';
|
|
16
16
|
import { syncSubagents, buildSubagentsPromptContext } from '$backend/subagents';
|
|
17
|
-
import { syncInstructions } from '$backend/instructions';
|
|
18
|
-
import { buildSkillsPromptContext } from '$backend/skills';
|
|
19
|
-
import type
|
|
17
|
+
import { syncInstructions, buildInstructionsPromptContext } from '$backend/instructions';
|
|
18
|
+
import { buildSkillsPromptContext, stripLegacyCommandArtifacts } from '$backend/skills';
|
|
19
|
+
import { readsGlobalMemoryFile, type ArtifactEngine } from '$backend/artifacts';
|
|
20
20
|
|
|
21
21
|
export async function syncEngineArtifacts(engine: ArtifactEngine, profileId?: number): Promise<void> {
|
|
22
|
-
// Sequential, NOT Promise.all: on synthetic engines (Codex/OpenCode)
|
|
22
|
+
// Sequential, NOT Promise.all: on synthetic engines (Codex/OpenCode) these
|
|
23
23
|
// write their own managed block into the SAME memory file (AGENTS.md). Running
|
|
24
24
|
// them concurrently would race the read-modify-write and drop blocks. Each call
|
|
25
25
|
// swallows its own errors, so a failure in one doesn't stop the others.
|
|
26
26
|
//
|
|
27
|
-
// `profileId` scopes
|
|
27
|
+
// `profileId` scopes Subagents to the active Profile's bundle (see
|
|
28
28
|
// `backend/profiles`). Instructions are NOT profile-bundled — they always sync
|
|
29
29
|
// their full global set.
|
|
30
|
-
await
|
|
30
|
+
await stripLegacyCommandArtifacts(engine);
|
|
31
31
|
await syncSubagents(engine, profileId);
|
|
32
32
|
await syncInstructions(engine);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
* The combined, profile-scoped
|
|
37
|
-
*
|
|
36
|
+
* The combined, profile-scoped artifact preamble that prompt-scoped engines
|
|
37
|
+
* inject into each turn's prompt.
|
|
38
38
|
*
|
|
39
|
-
* Their runtimes read
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
39
|
+
* Their runtimes read artifacts through a channel that is SHARED across sessions
|
|
40
|
+
* and not reliably re-read per turn (a persistent server/client and/or a global
|
|
41
|
+
* memory file), so the on-disk/global-file filter can't express a per-session
|
|
42
|
+
* Profile. Injecting the scoped set into the prompt is the one channel that is
|
|
43
|
+
* genuinely per-session. Returns '' when nothing applies.
|
|
44
|
+
*
|
|
45
|
+
* `engine` decides whether Instructions ride along. Codex/Copilot/OpenCode read
|
|
46
|
+
* the memory file `syncInstructions` writes, so adding them here would say the
|
|
47
|
+
* same thing twice. Cline and Cursor read no such file — for them the prompt is
|
|
48
|
+
* the ONLY channel, and before this parameter existed their Instructions were
|
|
49
|
+
* written to a file nothing opened and silently never applied.
|
|
44
50
|
*/
|
|
45
|
-
export function buildArtifactsPromptContext(profileId?: number): string {
|
|
51
|
+
export function buildArtifactsPromptContext(engine: ArtifactEngine, profileId?: number): string {
|
|
46
52
|
return [
|
|
53
|
+
readsGlobalMemoryFile(engine) ? '' : buildInstructionsPromptContext(),
|
|
47
54
|
buildSkillsPromptContext(profileId),
|
|
48
|
-
|
|
49
|
-
buildSubagentsPromptContext(profileId)
|
|
55
|
+
buildSubagentsPromptContext(engine, profileId)
|
|
50
56
|
].filter(Boolean).join('\n\n');
|
|
51
57
|
}
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
The adapters stream chat; **artifacts** are the reusable "extensions" the user
|
|
6
6
|
manages in **Settings → Artifacts & Access** that shape what each engine sees and
|
|
7
|
-
may do during that stream — Skills,
|
|
8
|
-
|
|
7
|
+
may do during that stream — Skills, Subagents, Instructions, Permissions,
|
|
8
|
+
Profiles, and Integrations (MCP).
|
|
9
9
|
|
|
10
10
|
They are a **separate subsystem** (`backend/artifacts/` + one module per feature)
|
|
11
11
|
that meets the adapter layer at exactly one seam: `backend/engine/artifact-sync.ts`,
|
|
@@ -15,26 +15,28 @@ point** — the per-feature source of truth is the doc-comment atop each module
|
|
|
15
15
|
|
|
16
16
|
### 8.1 What lives under "Artifacts & Access"
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
Six menus, each a canonical source (DB metadata + on-disk store, or a repo file)
|
|
19
|
+
that is **materialized** per engine. Coverage differs by engine because each
|
|
20
|
+
exposes a different native surface.
|
|
21
21
|
|
|
22
22
|
| Menu (UI) | Backend module | WS router | Materialized as |
|
|
23
23
|
|------------------|-------------------------|----------------------------|-----------------|
|
|
24
24
|
| Integrations | `backend/mcp/` + `backend/integrations/` | `backend/ws/mcp/` + `backend/ws/integrations/` | 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
|
-
|
|
|
27
|
-
|
|
|
28
|
-
| Instructions | `backend/instructions/` | `backend/ws/instructions/` | `preamble-region` inside the engine memory file |
|
|
25
|
+
| Skills | `backend/skills/` | `backend/ws/skills/` | `folder-md` in a native dir, or synthetic preamble; `/slash` skills are expanded by Clopen (§8.6) |
|
|
26
|
+
| Subagents | `backend/subagents/` | `backend/ws/subagents/` | `single-md` in a native dir, or synthetic preamble — only for engines that can delegate |
|
|
27
|
+
| Instructions | `backend/instructions/` | `backend/ws/instructions/` | `preamble-region` inside the engine memory file, or the prompt for engines that read no such file |
|
|
29
28
|
| Permissions | `backend/permissions/` | `backend/ws/permissions/` | runtime hook (+ optional Claude `settings.json`) |
|
|
30
29
|
| Profiles | `backend/profiles/` | `backend/ws/profiles/` | not materialized — a **bundle** that narrows the others |
|
|
31
30
|
|
|
32
31
|
`ArtifactType` (`backend/artifacts/types.ts`) is
|
|
33
|
-
`skill | command | subagent | instruction | mcp | permission`.
|
|
32
|
+
`skill | command | subagent | instruction | mcp | permission`. Three deliberate
|
|
34
33
|
mismatches with the menu list:
|
|
35
34
|
|
|
36
35
|
- **`mcp` is a reserved slot with no adapter** — MCP servers are config objects,
|
|
37
36
|
not files, so they keep their own path (§8.5).
|
|
37
|
+
- **`command` is a legacy slot** — Commands merged into Skills (migration 079,
|
|
38
|
+
§8.6). Nothing is materialized for it any more; the type survives so
|
|
39
|
+
`stripLegacyCommandArtifacts` can clean out what older versions wrote.
|
|
38
40
|
- **Profiles is not an artifact type** — it is a bundling/scoping concept layered
|
|
39
41
|
on top of the others (§8.4).
|
|
40
42
|
|
|
@@ -48,9 +50,9 @@ resolves **where** an artifact is materialized and **in what shape**
|
|
|
48
50
|
Two strategies recur, mirroring the two engine families:
|
|
49
51
|
|
|
50
52
|
- **NATIVE** (Claude, Qwen, Copilot) — the engine reads a real artifact
|
|
51
|
-
directory (Claude `<config>/{skills,
|
|
52
|
-
`<config>/opencode/
|
|
53
|
-
|
|
53
|
+
directory (Claude `<config>/{skills,agents}`, OpenCode
|
|
54
|
+
`<config>/opencode/agent`, Pi `<agentDir>/skills`). Clopen mirrors only the
|
|
55
|
+
slugs it owns into that dir (`ownership: 'whole-file'`).
|
|
54
56
|
- **SYNTHETIC** (Codex, OpenCode) — no native concept for a type, so Clopen
|
|
55
57
|
injects a marker-delimited block (`preamble-region`) into the engine's global
|
|
56
58
|
memory file (`AGENTS.md`).
|
|
@@ -77,29 +79,35 @@ growing separate calls (see the file taxonomy in §2.6).
|
|
|
77
79
|
|
|
78
80
|
| Export | Role |
|
|
79
81
|
|--------|------|
|
|
80
|
-
| `syncEngineArtifacts(engine, profileId?)` |
|
|
81
|
-
| `buildArtifactsPromptContext(profileId?)` | Returns the combined, profile-scoped
|
|
82
|
+
| `syncEngineArtifacts(engine, profileId?)` | Strips legacy Command artifacts, then materializes 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. |
|
|
83
|
+
| `buildArtifactsPromptContext(engine, profileId?)` | Returns the combined, profile-scoped preamble that **prompt-scoped engines** (OpenCode / Codex / Copilot / Cline / Cursor) inject into each turn's prompt. |
|
|
82
84
|
|
|
83
|
-
> **Sequential, not `Promise.all`.** On synthetic engines
|
|
84
|
-
>
|
|
85
|
+
> **Sequential, not `Promise.all`.** On synthetic engines these calls write into
|
|
86
|
+
> the same `AGENTS.md`; running them concurrently would race the
|
|
85
87
|
> read-modify-write and drop blocks. Each call swallows its own errors, so one
|
|
86
88
|
> failure never stops the others and the function never throws.
|
|
87
89
|
|
|
88
|
-
`profileId` scopes
|
|
90
|
+
`profileId` scopes Skills/Subagents to the active Profile's bundle (§8.4);
|
|
89
91
|
Instructions are never profile-bundled. Prompt-scoped engines need the preamble
|
|
90
92
|
because they read artifacts through a channel shared across sessions and not
|
|
91
93
|
reliably re-read per turn — the prompt is the one genuinely per-session channel.
|
|
92
94
|
|
|
95
|
+
`engine` decides whether **Instructions** ride along in that preamble.
|
|
96
|
+
`readsGlobalMemoryFile()` is false for Cline and Cursor: both are in-process SDKs
|
|
97
|
+
that build their own system prompt and resolve ambient rules from the workspace,
|
|
98
|
+
so an `AGENTS.md` written into their isolated config dir is a file nothing opens.
|
|
99
|
+
For them the prompt is the only channel — before this, Instructions silently
|
|
100
|
+
never applied there at all.
|
|
101
|
+
|
|
93
102
|
### 8.4 Per-artifact map
|
|
94
103
|
|
|
95
104
|
| Artifact | Canonical source | Scope | Sync behaviour |
|
|
96
105
|
|----------|------------------|-------|----------------|
|
|
97
|
-
| **Skills** (`backend/skills/`) | DB metadata + on-disk store; marketplace-installable | global, project | mirrored folder (`folder-md`) on native engines, synthetic preamble otherwise.
|
|
98
|
-
| **
|
|
99
|
-
| **Subagents** (`backend/subagents/`) | specialized delegated agents | global, project | one `.md` per subagent, or synthetic preamble. Profile-bundled |
|
|
106
|
+
| **Skills** (`backend/skills/`) | DB metadata + on-disk store; marketplace-installable | global, project | mirrored folder (`folder-md`) on native engines, synthetic preamble otherwise. Only `auto`-triggered skills are advertised; `slash` ones are expanded by Clopen (§8.6). Profile-bundled |
|
|
107
|
+
| **Subagents** (`backend/subagents/`) | specialized delegated agents | global, project | one `.md` per subagent, or synthetic preamble — and **nothing at all** for engines `canDelegateSubagents()` rejects (Codex, Copilot, Qwen), which have no surface to register one with. Profile-bundled |
|
|
100
108
|
| **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
109
|
| **Permissions** (`backend/permissions/`) | per-engine tool allow/deny | global, project | **enforcement is a runtime check** (`resolvePermissionsFromDb` + `isToolAllowed`) each adapter runs at whichever surface fires for every tool call — for Claude a `PreToolUse` hook, since `bypassPermissions` auto-approves before `canUseTool` is consulted. The matrix only describes the optional on-disk file, which today only Claude reads (a managed `permissions` key merged into its isolated `settings.json`); its `deny` rules do bite even under `bypassPermissions`, an allowlist has no on-disk equivalent |
|
|
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
|
|
110
|
+
| **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 Subagents-only profile never disables every Skill |
|
|
103
111
|
|
|
104
112
|
### 8.5 Integrations (MCP + connected accounts)
|
|
105
113
|
|
|
@@ -128,6 +136,57 @@ the remote HTTP bridge, per-engine config, and tool overrides — see
|
|
|
128
136
|
[`backend/mcp/README.md`](../../mcp/README.md). The engine-side MCP reuse rules
|
|
129
137
|
live in §10.12 (internal bridge) and §10.18 (external servers).
|
|
130
138
|
|
|
139
|
+
### 8.6 Skills cover both triggers (the Commands merge)
|
|
140
|
+
|
|
141
|
+
Skills and Commands used to be two menus over one mechanic: the same
|
|
142
|
+
frontmatter + Markdown document, the same `materializeArtifacts` call, the same
|
|
143
|
+
profile bundling. They differed only in **who pulls the trigger**. Migration 079
|
|
144
|
+
folded them into one artifact with two independent switches:
|
|
145
|
+
|
|
146
|
+
| `triggers` | Invoked by | Delivery |
|
|
147
|
+
|------------|-----------|----------|
|
|
148
|
+
| `auto` | the model, from the skill's `description` | advertised in the skills preamble / native skills dir |
|
|
149
|
+
| `slash` | the user, by typing `/<slug>` | expanded by Clopen before the prompt reaches the engine |
|
|
150
|
+
|
|
151
|
+
A skill can carry both. Two frontmatter keys come with the merge:
|
|
152
|
+
`argument-hint` (shown in the chat "/" picker) and `uses` — a list of sibling
|
|
153
|
+
slugs force-loaded whenever the skill runs, which is how one invocation pulls in
|
|
154
|
+
several skills **deterministically** instead of hoping the model notices them.
|
|
155
|
+
The spec tells runtimes to ignore frontmatter keys they don't model, so a Clopen
|
|
156
|
+
skill is still a portable SKILL.md.
|
|
157
|
+
|
|
158
|
+
**Clopen is the invoker, not the engine.** `backend/skills/invoke.ts` resolves
|
|
159
|
+
`/<slug>`, substitutes `$ARGUMENTS` / `$1`…`$9`, prepends the `uses` load block
|
|
160
|
+
(absolute SKILL.md paths, so bundled `scripts/` and `references/` stay reachable),
|
|
161
|
+
and `backend/chat/stream-manager.ts` swaps the result into the ENGINE prompt
|
|
162
|
+
only — the saved user message keeps the `/slug` the user typed, exactly like the
|
|
163
|
+
handoff and memory blocks beside it.
|
|
164
|
+
|
|
165
|
+
This is the point of the merge. Only four of the eight engines have a native
|
|
166
|
+
command directory (Claude, Codex, OpenCode, Pi); the other four were handed a
|
|
167
|
+
list of command *names* with no bodies and no argument substitution, so `/review-pr
|
|
168
|
+
123` produced an invented procedure. Expanding once, centrally, makes a slash
|
|
169
|
+
skill behave identically everywhere.
|
|
170
|
+
|
|
171
|
+
The old per-command **model override did not survive the merge**. A skill runs on
|
|
172
|
+
the session's model whichever trigger fires; pinning a model on the `slash` half
|
|
173
|
+
only would have made two halves of one artifact behave differently for a reason
|
|
174
|
+
no one could see in the UI.
|
|
175
|
+
|
|
176
|
+
Nothing is written to the native command directories any more.
|
|
177
|
+
`stripLegacyCommandArtifacts()` (called from `syncEngineArtifacts`) clears them
|
|
178
|
+
and any `CLOPEN:COMMANDS` block, so a renamed or deleted command stops being
|
|
179
|
+
offered by an engine's own picker.
|
|
180
|
+
|
|
181
|
+
**The migration copies, it does not move.** Each `{clopenDir}/commands/<slug>.md`
|
|
182
|
+
is read into `{clopenDir}/skills/<slug>/SKILL.md` and then left where it is, and
|
|
183
|
+
an existing SKILL.md is never overwritten with an empty body. A command document
|
|
184
|
+
is prose the user wrote and Clopen holds the only copy of; a migration that
|
|
185
|
+
deletes the source gets exactly one attempt, and against a database whose files
|
|
186
|
+
aren't beside it — restored from another machine, a data dir assembled by hand —
|
|
187
|
+
it would replace every prompt with nothing, irreversibly. A stale `commands/`
|
|
188
|
+
folder is the cheap half of that trade.
|
|
189
|
+
|
|
131
190
|
---
|
|
132
191
|
|
|
133
192
|
See also: [`backend/artifacts/`](../../artifacts/) (matrix, generic sync/detect,
|
|
@@ -29,7 +29,8 @@
|
|
|
29
29
|
| AskUserQuestion event + HTTP fallback | `opencode/stream.ts::resolveUserAnswer`, `claude/stream.ts::canUseTool` |
|
|
30
30
|
| MCP servers exposed over HTTP (single source) | `backend/mcp/internal/remote-server.ts`, `backend/mcp/internal/config.ts::getOpenCodeMcpConfig` (and future `getXxxMcpConfig`) |
|
|
31
31
|
| Materialize an artifact per engine (matrix) | `backend/artifacts/matrix.ts::resolveArtifact`, generic writer `backend/artifacts/sync.ts`, scanner `backend/artifacts/detect.ts` (see §8.2) |
|
|
32
|
-
| Per-stream artifact sync (
|
|
32
|
+
| Per-stream artifact sync (Subagents/Instructions + legacy Command cleanup) | `backend/engine/artifact-sync.ts::syncEngineArtifacts` + `buildArtifactsPromptContext` — called from each `stream.ts` after `syncSkills` (see §8.3) |
|
|
33
|
+
| `/slash` skill expansion (all engines) | `backend/skills/invoke.ts::expandSlashInvocation`, applied in `backend/chat/stream-manager.ts` (see §8.6) |
|
|
33
34
|
| Profile scoping (narrow active artifacts) | `backend/profiles/service.ts::resolveActiveProfileId` + `artifactFilter` (see §8.4) |
|
|
34
35
|
| Permission enforcement (runtime check) | `backend/permissions/service.ts::resolvePermissionsFromDb` + `isToolAllowed` (see §8.4); Claude wires it into a `PreToolUse` hook in `claude/stream.ts` |
|
|
35
36
|
| Auth-blob swap into shared CLI dotfile | Pattern only (no implementation yet); see §3.3 callout + §10.13 |
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `resolveGenerationTarget` is the last place a misconfigured one-shot
|
|
3
|
+
* generation can be caught before it becomes an opaque adapter failure.
|
|
4
|
+
*
|
|
5
|
+
* Handed a blank or stale model id, engines don't refuse — they run with no
|
|
6
|
+
* model and return nothing, which surfaced as "OpenCode returned empty
|
|
7
|
+
* response". That sentence names the symptom and nothing else: not the cause,
|
|
8
|
+
* not the fix, and a different wording per engine for the same situation. These
|
|
9
|
+
* tests pin that each of those cases now throws *here*, naming the settings page
|
|
10
|
+
* that owns the choice.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { describe, expect, test } from 'bun:test';
|
|
14
|
+
import { registerModels } from '$shared/constants/engines';
|
|
15
|
+
import type { EngineModel, EngineType } from '$shared/types/unified';
|
|
16
|
+
import { resolveGenerationTarget, GENERATION_SETTINGS } from './resolve-model';
|
|
17
|
+
import type { AIEngine } from './types';
|
|
18
|
+
|
|
19
|
+
/** The parts of an EngineModel this resolution actually reads. */
|
|
20
|
+
function model(engineType: EngineType, provider: string, id: string, accountId = 0): EngineModel {
|
|
21
|
+
return {
|
|
22
|
+
engine: {
|
|
23
|
+
type: engineType,
|
|
24
|
+
provider,
|
|
25
|
+
model: { id, name: id },
|
|
26
|
+
account: { id: accountId, name: 'test' }
|
|
27
|
+
}
|
|
28
|
+
} as EngineModel;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** A stand-in engine whose catalog the test controls. */
|
|
32
|
+
function fakeEngine(engineType: EngineType, catalog: EngineModel[] | Error): AIEngine {
|
|
33
|
+
return {
|
|
34
|
+
name: engineType,
|
|
35
|
+
getAvailableModels: async () => {
|
|
36
|
+
if (catalog instanceof Error) throw catalog;
|
|
37
|
+
return catalog;
|
|
38
|
+
}
|
|
39
|
+
} as unknown as AIEngine;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
describe('resolveGenerationTarget', () => {
|
|
43
|
+
test('resolves the provider and account from the catalog, ignoring a stale hint', async () => {
|
|
44
|
+
registerModels('opencode', [model('opencode', 'anthropic', 'claude-sonnet-5', 7)]);
|
|
45
|
+
const target = await resolveGenerationTarget(
|
|
46
|
+
fakeEngine('opencode', []),
|
|
47
|
+
'claude-sonnet-5',
|
|
48
|
+
'openai' // drifted: the catalog is the source of truth
|
|
49
|
+
);
|
|
50
|
+
expect(target).toEqual({ providerSlug: 'anthropic', modelId: 'claude-sonnet-5', accountId: 7 });
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('a blank model id is rejected, naming the settings page that owns it', async () => {
|
|
54
|
+
registerModels('opencode', []);
|
|
55
|
+
const promise = resolveGenerationTarget(
|
|
56
|
+
fakeEngine('opencode', [model('opencode', 'anthropic', 'claude-sonnet-5')]),
|
|
57
|
+
'',
|
|
58
|
+
'anthropic',
|
|
59
|
+
GENERATION_SETTINGS.artifact
|
|
60
|
+
);
|
|
61
|
+
await expect(promise).rejects.toThrow(/No model is selected.*Settings → Models → Artifacts/);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('whitespace is not a model id either', async () => {
|
|
65
|
+
registerModels('opencode', []);
|
|
66
|
+
await expect(
|
|
67
|
+
resolveGenerationTarget(fakeEngine('opencode', []), ' ', undefined, GENERATION_SETTINGS.commit)
|
|
68
|
+
).rejects.toThrow(/Settings → Models → Commit message/);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('an engine with no models at all says so, and points at Engines', async () => {
|
|
72
|
+
registerModels('opencode', []);
|
|
73
|
+
const promise = resolveGenerationTarget(
|
|
74
|
+
fakeEngine('opencode', []),
|
|
75
|
+
'some-model',
|
|
76
|
+
undefined,
|
|
77
|
+
GENERATION_SETTINGS.artifact
|
|
78
|
+
);
|
|
79
|
+
// "Pick a model again" would be useless advice when there is nothing to pick.
|
|
80
|
+
await expect(promise).rejects.toThrow(/no models available.*Settings → Engines/s);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('a model the catalog no longer offers is rejected, not passed through', async () => {
|
|
84
|
+
// This is the OpenCode case exactly: the catalog is fetched live, the saved
|
|
85
|
+
// id disappeared, and the provider hint still looks plausible. Trusting the
|
|
86
|
+
// hint here is what sent an unknown model id to the engine.
|
|
87
|
+
registerModels('opencode', []);
|
|
88
|
+
const promise = resolveGenerationTarget(
|
|
89
|
+
fakeEngine('opencode', [model('opencode', 'anthropic', 'claude-sonnet-5')]),
|
|
90
|
+
'gone-model',
|
|
91
|
+
'anthropic',
|
|
92
|
+
GENERATION_SETTINGS.artifact
|
|
93
|
+
);
|
|
94
|
+
await expect(promise).rejects.toThrow(/"gone-model" is no longer offered.*Settings → Models → Artifacts/);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('an unreachable catalog falls back to the hint instead of blocking', async () => {
|
|
98
|
+
// Offline or a crashed engine process: we cannot verify, so we also cannot
|
|
99
|
+
// claim the model is wrong. Let the adapter try and report what it finds.
|
|
100
|
+
registerModels('opencode', []);
|
|
101
|
+
const target = await resolveGenerationTarget(
|
|
102
|
+
fakeEngine('opencode', new Error('server unreachable')),
|
|
103
|
+
'claude-sonnet-5',
|
|
104
|
+
'anthropic'
|
|
105
|
+
);
|
|
106
|
+
expect(target).toEqual({ providerSlug: 'anthropic', modelId: 'claude-sonnet-5' });
|
|
107
|
+
});
|
|
108
|
+
});
|