@myrialabs/clopen 0.4.43 → 0.4.45
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/backend/artifacts/project/bridge.ts +218 -0
- package/backend/artifacts/project/edit.ts +243 -0
- package/backend/artifacts/project/index.ts +38 -0
- package/backend/artifacts/project/project.test.ts +181 -0
- package/backend/artifacts/project/scan.ts +368 -0
- package/backend/artifacts/project/sources.ts +100 -0
- package/backend/artifacts/sync.ts +1 -1
- package/backend/auth/permissions.ts +15 -0
- package/backend/chat/stream-manager.ts +26 -8
- package/backend/database/migrations/083_create_project_mcp_trust.ts +32 -0
- package/backend/database/migrations/index.ts +7 -0
- package/backend/database/queries/index.ts +2 -0
- package/backend/database/queries/project-mcp-trust-queries.ts +43 -0
- package/backend/engine/adapters/claude/message-converter.ts +6 -2
- package/backend/engine/adapters/claude/stream.ts +36 -8
- package/backend/engine/adapters/cline/mcp-tools.ts +26 -4
- package/backend/engine/adapters/cline/stream.ts +20 -6
- package/backend/engine/adapters/codex/stream.ts +21 -4
- package/backend/engine/adapters/copilot/stream.ts +6 -3
- package/backend/engine/adapters/cursor/stream.ts +19 -8
- package/backend/engine/adapters/opencode/server.ts +14 -4
- package/backend/engine/adapters/opencode/stream.ts +18 -3
- package/backend/engine/adapters/pi/mcp-tools.ts +26 -4
- package/backend/engine/adapters/pi/stream.ts +35 -3
- package/backend/engine/adapters/qwen/message-converter.ts +2 -2
- package/backend/engine/adapters/qwen/stream.ts +8 -0
- package/backend/engine/artifact-sync.ts +12 -5
- package/backend/engine/docs/lessons-learned.md +118 -0
- package/backend/files/file-watcher.test.ts +77 -0
- package/backend/files/file-watcher.ts +92 -60
- package/backend/files/watch-ignore.test.ts +182 -0
- package/backend/files/watch-ignore.ts +244 -0
- package/backend/git/git-executor.ts +14 -4
- package/backend/index.ts +11 -1
- package/backend/instructions/service.ts +5 -3
- package/backend/instructions/sync.ts +10 -27
- package/backend/mcp/external/config.ts +65 -23
- package/backend/mcp/external/project.ts +124 -0
- package/backend/mcp/external/proxy.ts +65 -11
- package/backend/mcp/index.ts +14 -9
- package/backend/mcp/internal/remote-server.ts +11 -1
- package/backend/skills/marketplace.ts +1 -1
- package/backend/snapshot/blob-store.ts +9 -5
- package/backend/snapshot/git-attribution.test.ts +42 -0
- package/backend/snapshot/git-attribution.ts +306 -0
- package/backend/snapshot/gitignore.test.ts +62 -0
- package/backend/snapshot/gitignore.ts +158 -78
- package/backend/snapshot/snapshot-service.test.ts +270 -0
- package/backend/snapshot/snapshot-service.ts +412 -136
- package/backend/snapshot/turn-activity.test.ts +52 -0
- package/backend/snapshot/turn-activity.ts +83 -0
- package/backend/snapshot/turn-changes.test.ts +58 -1
- package/backend/snapshot/turn-changes.ts +66 -0
- package/backend/worktrees/tree.ts +1 -1
- package/backend/ws/chat/composer.ts +504 -0
- package/backend/ws/chat/index.ts +3 -1
- package/backend/ws/chat/stream.ts +252 -440
- package/backend/ws/index.ts +4 -0
- package/backend/ws/project-artifacts/index.ts +236 -0
- package/backend/ws/snapshot/changes.ts +66 -31
- package/dist/assets/{index-BeUKiRiY.js → index-Am-rJRxA.js} +1 -1
- package/dist/assets/{index-B6u8cait.js → index-D-Ad1N96.js} +1 -1
- package/dist/assets/main--PLCDxSy.css +1 -0
- package/dist/assets/main-DelPm2Xt.js +1239 -0
- package/dist/index.html +2 -2
- package/package.json +5 -5
- package/shared/types/stores/settings.ts +5 -0
- package/shared/types/unified/index.ts +2 -0
- package/shared/types/unified/message.ts +2 -0
- package/shared/types/unified/stream.ts +38 -1
- package/dist/assets/main-CMRXlv2f.js +0 -1215
- package/dist/assets/main-DzCY0n-j.css +0 -1
|
@@ -45,6 +45,8 @@ import {
|
|
|
45
45
|
import { ensureClient, acquireServer, releaseServer, getDefaultServer, type ServerInstance } from './server';
|
|
46
46
|
import { syncSkills } from '$backend/skills';
|
|
47
47
|
import { syncEngineArtifacts, buildArtifactsPromptContext } from '$backend/engine/artifact-sync';
|
|
48
|
+
import { resolveProjectBridge } from '$backend/artifacts/project';
|
|
49
|
+
import { resolveOsPath } from '$backend/utils/paths';
|
|
48
50
|
import { artifactFilter } from '$backend/profiles';
|
|
49
51
|
import { buildOpenCodeInlineAgents } from '$backend/subagents';
|
|
50
52
|
import { getOpenCodeProfileDisabledToolIds } from '$backend/mcp';
|
|
@@ -221,7 +223,20 @@ export class OpenCodeEngine implements AIEngine {
|
|
|
221
223
|
// server, different Profiles get isolated servers, concurrently.
|
|
222
224
|
const mcpProfileFilter = artifactFilter(profileId, 'mcp') ?? undefined;
|
|
223
225
|
const subagentFilter = artifactFilter(profileId, 'subagent') ?? undefined;
|
|
224
|
-
|
|
226
|
+
// Repository artifacts Open Code doesn't read natively (it reads
|
|
227
|
+
// `.opencode/*`, `.agents/skills`, `.claude/skills` and AGENTS.md itself).
|
|
228
|
+
// Project subagents join the inline agents (an installed one wins a slug
|
|
229
|
+
// clash); the approved `.agents/mcp.json` joins MCP via `projectId`.
|
|
230
|
+
const projectBridge = await resolveProjectBridge('opencode', resolveOsPath(projectPath), options.mcpContext?.projectId);
|
|
231
|
+
const inlineAgents = {
|
|
232
|
+
...Object.fromEntries(projectBridge.subagents.map(sub => [sub.slug, {
|
|
233
|
+
description: sub.description || sub.name,
|
|
234
|
+
mode: 'subagent' as const,
|
|
235
|
+
prompt: sub.prompt,
|
|
236
|
+
...(sub.model ? { model: sub.model } : {})
|
|
237
|
+
}])),
|
|
238
|
+
...(await buildOpenCodeInlineAgents(profileId))
|
|
239
|
+
};
|
|
225
240
|
// The pool derives the key from the config it is about to spawn with, so a
|
|
226
241
|
// changed connector set, provider, credential or subagent prompt routes this
|
|
227
242
|
// stream to a server built from it — while any server still serving another
|
|
@@ -229,7 +244,7 @@ export class OpenCodeEngine implements AIEngine {
|
|
|
229
244
|
// stream id is what makes that safe: a held server is never reaped.
|
|
230
245
|
const holderId = options.mcpContext?.streamId;
|
|
231
246
|
const server = await acquireServer(
|
|
232
|
-
{ mcpProfileFilter, subagentFilter, inlineAgents, gitIdentityEnv: options.gitIdentityEnv },
|
|
247
|
+
{ mcpProfileFilter, subagentFilter, inlineAgents, gitIdentityEnv: options.gitIdentityEnv, projectId: options.mcpContext?.projectId ?? null },
|
|
233
248
|
holderId
|
|
234
249
|
);
|
|
235
250
|
run.server = server;
|
|
@@ -253,7 +268,7 @@ export class OpenCodeEngine implements AIEngine {
|
|
|
253
268
|
// so advertise the profile-scoped set PER-SESSION by prepending it as a
|
|
254
269
|
// leading context part each turn (authoritative for synthetic skills;
|
|
255
270
|
// advisory on top of the native command/agent dirs).
|
|
256
|
-
const artifactsContext = buildArtifactsPromptContext('opencode', profileId);
|
|
271
|
+
const artifactsContext = buildArtifactsPromptContext('opencode', profileId, projectBridge);
|
|
257
272
|
if (artifactsContext) {
|
|
258
273
|
promptParts.unshift({ type: 'text', text: artifactsContext });
|
|
259
274
|
}
|
|
@@ -30,6 +30,9 @@ import {
|
|
|
30
30
|
getEnabledExternalServers,
|
|
31
31
|
listExternalServerTools,
|
|
32
32
|
callExternalServerTool,
|
|
33
|
+
getTrustedProjectServers,
|
|
34
|
+
listProjectServerTools,
|
|
35
|
+
callProjectServerTool,
|
|
33
36
|
projectContextService,
|
|
34
37
|
serverMetadata,
|
|
35
38
|
} from '../../../mcp';
|
|
@@ -102,12 +105,31 @@ export async function buildPiMcpTools(
|
|
|
102
105
|
}
|
|
103
106
|
|
|
104
107
|
// ── External servers (proxied upstream) ──
|
|
105
|
-
|
|
108
|
+
// Installed servers (profile-filtered) plus the project's approved
|
|
109
|
+
// `.agents/mcp.json` servers, which never shadow an installed namespace.
|
|
110
|
+
const upstreams: { label: string; namespace: string; list: () => ReturnType<typeof listExternalServerTools>; call: (tool: string, args: unknown) => Promise<unknown> }[] =
|
|
111
|
+
getEnabledExternalServers(profileFilter).map(s => ({
|
|
112
|
+
label: s.slug,
|
|
113
|
+
namespace: s.namespace,
|
|
114
|
+
list: () => listExternalServerTools(s.slug),
|
|
115
|
+
call: (tool: string, args: unknown) => callExternalServerTool(s.slug, tool, args)
|
|
116
|
+
}));
|
|
117
|
+
const taken = new Set(upstreams.map(u => u.namespace));
|
|
118
|
+
for (const s of getTrustedProjectServers(context?.projectId)) {
|
|
119
|
+
if (taken.has(s.namespace)) continue;
|
|
120
|
+
upstreams.push({
|
|
121
|
+
label: s.namespace,
|
|
122
|
+
namespace: s.namespace,
|
|
123
|
+
list: () => listProjectServerTools(s.projectId, s.name),
|
|
124
|
+
call: (tool: string, args: unknown) => callProjectServerTool(s.projectId, s.name, tool, args)
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
for (const server of upstreams) {
|
|
106
128
|
let externalTools;
|
|
107
129
|
try {
|
|
108
|
-
externalTools = await
|
|
130
|
+
externalTools = await server.list();
|
|
109
131
|
} catch (error) {
|
|
110
|
-
debug.warn('mcp', `Pi MCP bridge: could not list tools for "${server.
|
|
132
|
+
debug.warn('mcp', `Pi MCP bridge: could not list tools for "${server.label}" (skipping):`, error);
|
|
111
133
|
continue;
|
|
112
134
|
}
|
|
113
135
|
for (const tool of externalTools) {
|
|
@@ -119,7 +141,7 @@ export async function buildPiMcpTools(
|
|
|
119
141
|
description: `${tool.description ?? tool.name}${schemaText}`,
|
|
120
142
|
parameters: OPEN_PARAMS,
|
|
121
143
|
execute: async (_toolCallId: string, params: unknown) => {
|
|
122
|
-
const result = (await
|
|
144
|
+
const result = (await server.call(tool.name, params ?? {})) as { content?: unknown } | undefined;
|
|
123
145
|
return { content: toPiContent(result?.content), details: {} };
|
|
124
146
|
},
|
|
125
147
|
} as ToolDefinition);
|
|
@@ -36,6 +36,9 @@ import { subagentQueries } from '$backend/database/queries';
|
|
|
36
36
|
import { readSubagentMd } from '$backend/subagents/store';
|
|
37
37
|
import { syncSkills } from '$backend/skills';
|
|
38
38
|
import { syncEngineArtifacts } from '$backend/engine/artifact-sync';
|
|
39
|
+
import { resolveProjectBridge, buildProjectPromptContext } from '$backend/artifacts/project';
|
|
40
|
+
import { homedir } from 'node:os';
|
|
41
|
+
import { join, sep } from 'node:path';
|
|
39
42
|
import { artifactFilter } from '$backend/profiles';
|
|
40
43
|
import { resolvePermissionsFromDb, isToolAllowed } from '$backend/permissions';
|
|
41
44
|
import { buildJsonPrompt, extractJson, emptyGenerationError } from '../../structured-helpers';
|
|
@@ -165,6 +168,13 @@ export class PiEngine implements AIEngine {
|
|
|
165
168
|
await syncSkills('pi', profileId);
|
|
166
169
|
await syncEngineArtifacts('pi', profileId);
|
|
167
170
|
|
|
171
|
+
// Repository artifacts Pi doesn't read natively (it reads `.pi/*`,
|
|
172
|
+
// `.agents/skills` and AGENTS.md itself): skills go in as extra skill
|
|
173
|
+
// paths, instructions as an appended system prompt, subagents join the
|
|
174
|
+
// dispatch tool below.
|
|
175
|
+
const projectBridge = await resolveProjectBridge('pi', resolvedProjectPath, options.mcpContext?.projectId);
|
|
176
|
+
const projectInstructions = buildProjectPromptContext(projectBridge, { instructions: true });
|
|
177
|
+
|
|
168
178
|
// ── Permissions (enforced at the `tool_call` extension hook) ──
|
|
169
179
|
const permissions = resolvePermissionsFromDb('pi', options.mcpContext?.projectId, profileId);
|
|
170
180
|
const permissionBlocker = (pi: ExtensionAPI) => {
|
|
@@ -194,13 +204,24 @@ export class PiEngine implements AIEngine {
|
|
|
194
204
|
// Subagent dispatch — Pi has no native Agent tool, so materialising the
|
|
195
205
|
// "Available Subagents" preamble isn't enough; expose a tool that actually
|
|
196
206
|
// spawns a sub-session with the chosen subagent's system prompt.
|
|
197
|
-
|
|
207
|
+
// Project subagents Pi can't read natively (`.agents/agents`, `.claude/agents`,
|
|
208
|
+
// …) join the same dispatch tool; an installed subagent wins a slug clash.
|
|
209
|
+
const installedSubagents = subagentQueries.getEnabled();
|
|
210
|
+
const installedSlugs = new Set(installedSubagents.map((s) => s.slug));
|
|
211
|
+
const projectSubagents = new Map(projectBridge.subagents.filter((s) => !installedSlugs.has(s.slug)).map((s) => [s.slug, s]));
|
|
212
|
+
const subagents: SubagentInfo[] = [
|
|
213
|
+
...installedSubagents.map((s) => ({ slug: s.slug, name: s.name, description: s.description })),
|
|
214
|
+
...[...projectSubagents.values()].map((s) => ({ slug: s.slug, name: s.name, description: s.description })),
|
|
215
|
+
];
|
|
198
216
|
if (subagents.length > 0) {
|
|
199
217
|
const agentTool = createAgentDispatchTool({
|
|
200
218
|
subagents,
|
|
201
219
|
run: async (subagent, subPrompt, toolCallId, signal) => {
|
|
202
|
-
const
|
|
203
|
-
const
|
|
220
|
+
const projectSubagent = projectSubagents.get(subagent.slug);
|
|
221
|
+
const md = projectSubagent ? '' : ((await readSubagentMd(subagent.slug)) ?? '');
|
|
222
|
+
const instructions = projectSubagent?.prompt
|
|
223
|
+
|| stripFrontmatter(md)
|
|
224
|
+
|| `You are the ${subagent.name} subagent. ${subagent.description}`;
|
|
204
225
|
// APPEND the subagent instructions to Pi's base coding prompt —
|
|
205
226
|
// replacing it wholesale strips the tool-use scaffolding and the
|
|
206
227
|
// sub-agent then produces nothing. Keep the sub-session bounded:
|
|
@@ -264,10 +285,21 @@ export class PiEngine implements AIEngine {
|
|
|
264
285
|
}
|
|
265
286
|
|
|
266
287
|
// ── Resource loader (discovers synced skills/prompts/AGENTS.md) ──
|
|
288
|
+
// Pi also scans the REAL `~/.agents/skills` (via $HOME, with no override),
|
|
289
|
+
// which leaks the user's personal CLI skills past Clopen's per-engine
|
|
290
|
+
// isolation. Drop anything loaded from there; project `.agents/skills`
|
|
291
|
+
// and Clopen's own synced dir are unaffected.
|
|
292
|
+
const userAgentsSkillsDir = join(process.env.HOME || homedir(), '.agents', 'skills') + sep;
|
|
267
293
|
const resourceLoader = new DefaultResourceLoader({
|
|
268
294
|
cwd: resolvedProjectPath,
|
|
269
295
|
agentDir,
|
|
270
296
|
extensionFactories: [permissionBlocker],
|
|
297
|
+
...(projectBridge.skills.length > 0 && { additionalSkillPaths: projectBridge.skills.map((s) => s.skillMd) }),
|
|
298
|
+
...(projectInstructions && { appendSystemPrompt: [projectInstructions] }),
|
|
299
|
+
skillsOverride: (base) => ({
|
|
300
|
+
...base,
|
|
301
|
+
skills: base.skills.filter((skill) => !skill.filePath.startsWith(userAgentsSkillsDir)),
|
|
302
|
+
}),
|
|
271
303
|
});
|
|
272
304
|
await resourceLoader.reload();
|
|
273
305
|
|
|
@@ -50,7 +50,7 @@ import type {
|
|
|
50
50
|
StopReason,
|
|
51
51
|
AskUserQuestion,
|
|
52
52
|
} from '$shared/types/unified';
|
|
53
|
-
import { toCanonicalToolName } from '$shared/types/unified';
|
|
53
|
+
import { toCanonicalToolName, toMcpServerStatus } from '$shared/types/unified';
|
|
54
54
|
import { resolveOpenCodeToolName } from '../../../mcp';
|
|
55
55
|
|
|
56
56
|
// ============================================================
|
|
@@ -838,7 +838,7 @@ export function convertSystemInit(msg: SDKSystemMessage, state: QwenConverterSta
|
|
|
838
838
|
tools: msg.tools || [],
|
|
839
839
|
mcpServers: (msg.mcp_servers || []).map(s => ({
|
|
840
840
|
name: s.name || '',
|
|
841
|
-
status: (s.status
|
|
841
|
+
status: toMcpServerStatus(s.status),
|
|
842
842
|
})),
|
|
843
843
|
};
|
|
844
844
|
}
|
|
@@ -51,6 +51,7 @@ import { EngineRuns } from '../run-registry';
|
|
|
51
51
|
import { artifactFilter } from '$backend/profiles';
|
|
52
52
|
import { syncSkills } from '$backend/skills';
|
|
53
53
|
import { syncEngineArtifacts } from '$backend/engine/artifact-sync';
|
|
54
|
+
import { resolveProjectBridge, buildProjectPromptContext } from '$backend/artifacts/project';
|
|
54
55
|
import { resolvePermissionsFromDb, isToolAllowed, excludedBuiltinTools } from '$backend/permissions';
|
|
55
56
|
import { forkQwenSessionState, sessionStateExists } from './session-fork';
|
|
56
57
|
|
|
@@ -165,6 +166,12 @@ export class QwenEngine implements AIEngine {
|
|
|
165
166
|
await syncSkills('qwen', profileId);
|
|
166
167
|
await syncEngineArtifacts('qwen', profileId);
|
|
167
168
|
const mcpConfig = getQwenMcpConfig(mcpProfileFilter, options.mcpContext);
|
|
169
|
+
// Repository artifacts Qwen doesn't read natively (it reads `.qwen/*`,
|
|
170
|
+
// QWEN.md and AGENTS.md itself) — appended to its preset system prompt,
|
|
171
|
+
// which is per query. Qwen has no delegation surface Clopen can register
|
|
172
|
+
// with, so project subagents are never advertised to it.
|
|
173
|
+
const projectBridge = await resolveProjectBridge('qwen', resolvedProjectPath, options.mcpContext?.projectId);
|
|
174
|
+
const projectContext = buildProjectPromptContext(projectBridge, { skills: true, instructions: true });
|
|
168
175
|
|
|
169
176
|
// Resolve the permission policy once per stream; canUseTool enforces it
|
|
170
177
|
// (Qwen otherwise auto-allows everything). Tool names arrive snake_cased.
|
|
@@ -313,6 +320,7 @@ export class QwenEngine implements AIEngine {
|
|
|
313
320
|
// Auto-allow everything else.
|
|
314
321
|
return { behavior: 'allow' as const, updatedInput: input };
|
|
315
322
|
},
|
|
323
|
+
...(projectContext ? { systemPrompt: { type: 'preset' as const, preset: 'qwen_code' as const, append: projectContext } } : {}),
|
|
316
324
|
...(maxTurns !== undefined ? { maxSessionTurns: maxTurns } : {}),
|
|
317
325
|
...(resumeId ? { resume: resumeId } : {}),
|
|
318
326
|
...(Object.keys(mcpConfig).length > 0 ? { mcpServers: mcpConfig } : {}),
|
|
@@ -7,9 +7,10 @@
|
|
|
7
7
|
* the features share the exact same trigger point without each adapter growing
|
|
8
8
|
* separate calls.
|
|
9
9
|
*
|
|
10
|
-
* GLOBAL scope only:
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* GLOBAL scope only: nothing here writes into a repository. A project's own
|
|
11
|
+
* artifacts reach the engine through the per-stream project bridge
|
|
12
|
+
* (`backend/artifacts/project/bridge.ts`), and edits to repo files are explicit
|
|
13
|
+
* actions in Settings — never a side effect of starting a chat.
|
|
13
14
|
* Each underlying sync swallows its own errors, so this never throws.
|
|
14
15
|
*/
|
|
15
16
|
|
|
@@ -17,6 +18,7 @@ import { syncSubagents, buildSubagentsPromptContext } from '$backend/subagents';
|
|
|
17
18
|
import { syncInstructions, buildInstructionsPromptContext } from '$backend/instructions';
|
|
18
19
|
import { buildSkillsPromptContext, stripLegacyCommandArtifacts } from '$backend/skills';
|
|
19
20
|
import { readsGlobalMemoryFile, type ArtifactEngine } from '$backend/artifacts';
|
|
21
|
+
import { buildProjectPromptContext, type ProjectBridge } from '$backend/artifacts/project';
|
|
20
22
|
|
|
21
23
|
export async function syncEngineArtifacts(engine: ArtifactEngine, profileId?: number): Promise<void> {
|
|
22
24
|
// Sequential, NOT Promise.all: on synthetic engines (Codex/OpenCode) these
|
|
@@ -47,11 +49,16 @@ export async function syncEngineArtifacts(engine: ArtifactEngine, profileId?: nu
|
|
|
47
49
|
* same thing twice. Cline and Cursor read no such file — for them the prompt is
|
|
48
50
|
* the ONLY channel, and before this parameter existed their Instructions were
|
|
49
51
|
* written to a file nothing opened and silently never applied.
|
|
52
|
+
*
|
|
53
|
+
* `project` appends the repository's bridged artifacts (see
|
|
54
|
+
* `resolveProjectBridge`) — only what this engine can't read from the repo.
|
|
50
55
|
*/
|
|
51
|
-
export function buildArtifactsPromptContext(engine: ArtifactEngine, profileId?: number): string {
|
|
56
|
+
export function buildArtifactsPromptContext(engine: ArtifactEngine, profileId?: number, project?: ProjectBridge): string {
|
|
52
57
|
return [
|
|
53
58
|
readsGlobalMemoryFile(engine) ? '' : buildInstructionsPromptContext(),
|
|
54
59
|
buildSkillsPromptContext(profileId),
|
|
55
|
-
buildSubagentsPromptContext(engine, profileId)
|
|
60
|
+
buildSubagentsPromptContext(engine, profileId),
|
|
61
|
+
// The repository's own artifacts this engine doesn't read natively.
|
|
62
|
+
project ? buildProjectPromptContext(project) : ''
|
|
56
63
|
].filter(Boolean).join('\n\n');
|
|
57
64
|
}
|
|
@@ -1509,6 +1509,61 @@ diffs. `/tmp`-installing the old and new versions side by side and diffing the
|
|
|
1509
1509
|
`type: "…"` literals in each SDK's event declarations found every item above in
|
|
1510
1510
|
minutes.
|
|
1511
1511
|
|
|
1512
|
+
**The September 2026 Claude pass (0.3.229 → 0.3.284) added one more trap, and
|
|
1513
|
+
it is the reverse of the stale-catalog item above.** Here the catalog was
|
|
1514
|
+
*right* and the binary was behind. `models.ts` listed `claude-opus-5-5`,
|
|
1515
|
+
`claude-sonnet-5-5` and `claude-fable-5-1`, but the CLI bundled with 0.3.229 is
|
|
1516
|
+
2.1.229, whose embedded model table predates all three — so picking any of them
|
|
1517
|
+
failed inside the CLI with `Claude Code 2.1.229 does not support this model;
|
|
1518
|
+
version 2.1.280 or newer is required`. Nothing in Clopen could have caught it:
|
|
1519
|
+
the slugs are correct, the types compile, and the engine is installed and
|
|
1520
|
+
healthy. The rule that follows is bidirectional, because the SDK pin and the
|
|
1521
|
+
model catalog are one decision wearing two hats:
|
|
1522
|
+
|
|
1523
|
+
- Adding a model to `models.ts` is not done until the **pinned** SDK's bundled
|
|
1524
|
+
CLI knows the slug. `strings -a node_modules/@anthropic-ai/claude-agent-sdk-<platform>-<arch>/claude | grep -oE 'claude-(opus|sonnet|haiku|fable)-[0-9-]+' | sort -u`
|
|
1525
|
+
answers it in seconds, the same read `codex/models.ts` does for Codex.
|
|
1526
|
+
- Bumping the SDK is therefore a **model-availability change**, not only a type
|
|
1527
|
+
change, and belongs in the PR description as one. The Claude CLI ships as a
|
|
1528
|
+
platform package of the SDK (`engine-cli.ts` → `claudeCandidates`), so the two
|
|
1529
|
+
versions move together and cannot be bumped apart.
|
|
1530
|
+
|
|
1531
|
+
Two smaller findings from the same pass, both worth reusing:
|
|
1532
|
+
|
|
1533
|
+
- **An unchanged union is itself a result, but only if you diff for it.**
|
|
1534
|
+
`SDKMessage` was byte-identical across the 55 versions, which is what made the
|
|
1535
|
+
upgrade safe — not the clean compile. Diffing every type's *fields* (not just
|
|
1536
|
+
the member names) is what proved it: `Options` gained five optional entries,
|
|
1537
|
+
`Query` three methods, and the only removals anywhere were
|
|
1538
|
+
`Settings.policyHelpers` and two control requests, none referenced by Clopen.
|
|
1539
|
+
- **A cast at the SDK boundary erased the two states that decide a toast.** The
|
|
1540
|
+
`system:init` payload types `mcp_servers[].status` as a bare `string`, while
|
|
1541
|
+
the SDK *separately* exports a richer `McpServerStatus` for a different API
|
|
1542
|
+
surface — so the obvious `as 'connected' | 'disconnected' | 'error'` looked
|
|
1543
|
+
authoritative and was fiction. `pending` and `needs-auth` are not failures,
|
|
1544
|
+
and 0.3.282 made `pending` routine by connecting MCP servers in the
|
|
1545
|
+
background. Both the Claude and Qwen converters carried the same invented
|
|
1546
|
+
union; the vocabulary now lives once in `toMcpServerStatus`
|
|
1547
|
+
(`shared/types/unified/stream.ts`), for the same reason `resolveCodexEffort`
|
|
1548
|
+
does.
|
|
1549
|
+
|
|
1550
|
+
**`prewarm()` (0.3.284, `@alpha`) was evaluated and declined.** It parks a spare
|
|
1551
|
+
Claude Code process so process start, auth, tools, plugins and MCP handshakes
|
|
1552
|
+
come off the first message — but `claim()` can only set `cwd`,
|
|
1553
|
+
`additionalDirectories`, `model`, `permissionMode`, `maxThinkingTokens`, a
|
|
1554
|
+
settings overlay, `appendSystemPrompt`, `title`, `agents` and three named
|
|
1555
|
+
environment variables. Everything else is frozen at `prewarm()`, including the
|
|
1556
|
+
four things Clopen varies per stream: `mcpServers` (whose tool handlers are
|
|
1557
|
+
bound to a project via `mcpContext`), `hooks` (the PreToolUse permission hook is
|
|
1558
|
+
per project + profile), `canUseTool` (its closure captures the per-stream run),
|
|
1559
|
+
and `env` (git identity is not one of the three claimable variables). A spare is
|
|
1560
|
+
therefore only reusable inside one `(project × profile × account × identity)`
|
|
1561
|
+
and holds 230–260 MB while parked, which does not fit the low-spec/VPS target.
|
|
1562
|
+
If it is revisited: it needs a spare registry keyed on that tuple, a
|
|
1563
|
+
default-off setting, and a fallback that special-cases `option_not_applied` —
|
|
1564
|
+
that rejection means the session is **already running**, so the naive
|
|
1565
|
+
"fall back to `query()`" double-sends the prompt.
|
|
1566
|
+
|
|
1512
1567
|
---
|
|
1513
1568
|
|
|
1514
1569
|
### 10.26 One engine instance, many chats — per-stream state cannot live on it
|
|
@@ -1578,3 +1633,66 @@ What made this survive so long is that the contract doc *taught* it: invariant 2
|
|
|
1578
1633
|
used to read "Streaming state lives on the instance … automatically isolated
|
|
1579
1634
|
per-project". It was true about projects and silently wrong about chat sessions.
|
|
1580
1635
|
When an invariant is scoped, write down what it does **not** cover.
|
|
1636
|
+
|
|
1637
|
+
---
|
|
1638
|
+
|
|
1639
|
+
### 10.27 A tool id is scoped to the SDK session that minted it
|
|
1640
|
+
|
|
1641
|
+
The Task Progress panel showed a plan that could never finish. Turn 1 created
|
|
1642
|
+
three tasks and completed them; turn 2 created two more and, as the user put it,
|
|
1643
|
+
"updated 1-2 instead of continuing from 4". The count settled at half done and
|
|
1644
|
+
stayed there.
|
|
1645
|
+
|
|
1646
|
+
`TodoWrite` sent a full snapshot per call, so reading it was "take the last
|
|
1647
|
+
one". The Task tools that replaced it (`TaskCreate` / `TaskUpdate`, SDK
|
|
1648
|
+
0.3.142+) are deltas — one task per create, patched by `taskId` — so the panel
|
|
1649
|
+
replays them. The replay keyed tasks on a **single counter over the whole
|
|
1650
|
+
conversation**, on the assumption that the engine numbers tasks the same way.
|
|
1651
|
+
It does not. Clopen sends every turn with `forkSession: true`, so each turn runs
|
|
1652
|
+
under a fresh SDK session whose task store starts empty and **whose ids restart
|
|
1653
|
+
at 1**.
|
|
1654
|
+
|
|
1655
|
+
Reading it out of the database made the damage exact. In one real session turn 6
|
|
1656
|
+
created ten tasks (ids 1-10), turn 7 created seven more that the engine also
|
|
1657
|
+
numbered 1-7, and turn 9 three more numbered 1-3. The replay handed turn 7's
|
|
1658
|
+
creates the synthetic ids 11-17 while turn 7's updates still said 1-7 — so every
|
|
1659
|
+
later turn's status landed on **turn 6's rows**, and its own tasks never left
|
|
1660
|
+
`pending`. The panel read 10/20 = 50% forever, and the header named a turn-6
|
|
1661
|
+
task while the agent worked on a turn-9 one. Replaying that same session through
|
|
1662
|
+
the fix yields 3/3.
|
|
1663
|
+
|
|
1664
|
+
The engine had been saying so all along: across the whole database, every
|
|
1665
|
+
`TaskList` call answers `No tasks found`, each one issued in a turn *after*
|
|
1666
|
+
tasks were created. An empty store per fork is not an edge case, it is the
|
|
1667
|
+
normal shape.
|
|
1668
|
+
|
|
1669
|
+
So the id namespace is the SDK session, and the rules that follow are worth
|
|
1670
|
+
keeping for any future delta-keyed tool:
|
|
1671
|
+
|
|
1672
|
+
- **Key per session, not per conversation.** A create arriving under a new
|
|
1673
|
+
`message.sessionId` starts that session's list from scratch. The same
|
|
1674
|
+
reasoning as §10.23: an SDK session id is only meaningful to the engine that
|
|
1675
|
+
minted it, and so is anything numbered inside it.
|
|
1676
|
+
- **Only creates open a namespace; updates never do.** A turn that patches
|
|
1677
|
+
without creating is a continuation, and clearing on it would discard the list
|
|
1678
|
+
those patches refer to — the case if the engine ever persists its store
|
|
1679
|
+
across a fork.
|
|
1680
|
+
- **Prefer the id the engine reports over one you derive.** `TaskCreate`'s
|
|
1681
|
+
result reads `Task #4 created successfully: …`; parse it, and fall back to
|
|
1682
|
+
counting *within the namespace* only while the result is still in flight.
|
|
1683
|
+
The old counter was not wrong because counting is wrong, it was wrong because
|
|
1684
|
+
it counted across a boundary the ids do not cross.
|
|
1685
|
+
- **Do not invent a row for an id you never saw created.** The old `upsert`
|
|
1686
|
+
defaulted a missing subject to the id, so a stray patch entered the list as a
|
|
1687
|
+
task literally labelled `7` — reachable whenever the loaded message window
|
|
1688
|
+
opens partway through a turn. Skip it unless the patch names the task.
|
|
1689
|
+
|
|
1690
|
+
Two pieces of dead code hid the bug's surface. The replay read
|
|
1691
|
+
`item.result?.content` for `TaskList` snapshots, but that widget consumes the
|
|
1692
|
+
**raw** message list while `ToolUseBlock.result` is populated by the grouper
|
|
1693
|
+
that feeds the rendered list — across 2140 stored Task blocks, not one carries a
|
|
1694
|
+
`result`. And what it tried to parse (`{ tasks: [...] }`) is not a shape
|
|
1695
|
+
`TaskList` returns; its result is prose. A branch that cannot fire will not tell
|
|
1696
|
+
you its premise is wrong, so the replay lives in
|
|
1697
|
+
`frontend/utils/chat/task-progress.ts` now, behind unit tests that state each
|
|
1698
|
+
scenario, rather than inside a `$derived` where no test could reach it.
|
|
@@ -149,6 +149,83 @@ describe('FileWatcherManager', () => {
|
|
|
149
149
|
expect(paths.some((p) => p.includes('.git'))).toBe(false);
|
|
150
150
|
});
|
|
151
151
|
|
|
152
|
+
test('reports changes inside dot-directories people and agents edit', async () => {
|
|
153
|
+
// `.agents/` is written by Settings → Artifacts; ignoring every dot path
|
|
154
|
+
// left the explorer stale until a reload while root `AGENTS.md` updated live.
|
|
155
|
+
const root = await makeProject();
|
|
156
|
+
await mkdir(join(root, '.agents', 'skills', 'demo'), { recursive: true });
|
|
157
|
+
expect(await fileWatcher.startWatching('p10', root)).toBe(true);
|
|
158
|
+
// Let the mkdir's own event drain first, or the platform watcher folds the
|
|
159
|
+
// write into it and reports only `.agents`.
|
|
160
|
+
await new Promise((r) => setTimeout(r, 400));
|
|
161
|
+
|
|
162
|
+
await writeFile(join(root, '.agents', 'skills', 'demo', 'SKILL.md'), '---\nname: demo\n---\n');
|
|
163
|
+
|
|
164
|
+
await waitFor(() => changesFor('p10').some((p) => p.endsWith('SKILL.md')));
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test('never reports changes inside heavy dot-directories', async () => {
|
|
168
|
+
const root = await makeProject();
|
|
169
|
+
await mkdir(join(root, '.venv', 'lib'), { recursive: true });
|
|
170
|
+
expect(await fileWatcher.startWatching('p11', root)).toBe(true);
|
|
171
|
+
|
|
172
|
+
await writeFile(join(root, '.venv', 'lib', 'site.py'), '# noise');
|
|
173
|
+
await writeFile(join(root, '.notes.md.swp'), 'swap');
|
|
174
|
+
// Spaced out for the same reason as the ignored-directories test above.
|
|
175
|
+
await new Promise((r) => setTimeout(r, 400));
|
|
176
|
+
|
|
177
|
+
await writeFile(join(root, 'app.ts'), 'export {}');
|
|
178
|
+
await waitFor(() => changesFor('p11').some((p) => p.endsWith('app.ts')));
|
|
179
|
+
|
|
180
|
+
const paths = changesFor('p11');
|
|
181
|
+
expect(paths.some((p) => p.includes('.venv'))).toBe(false);
|
|
182
|
+
expect(paths.some((p) => p.endsWith('.swp'))).toBe(false);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
test('ignores output recognised by its manifest or its contents, not by name', async () => {
|
|
186
|
+
const root = await makeProject();
|
|
187
|
+
await writeFile(join(root, 'Cargo.toml'), '[package]');
|
|
188
|
+
await mkdir(join(root, 'target', 'debug'), { recursive: true });
|
|
189
|
+
await mkdir(join(root, 'myenv', 'lib'), { recursive: true });
|
|
190
|
+
await writeFile(join(root, 'myenv', 'pyvenv.cfg'), 'home = /usr/bin');
|
|
191
|
+
// No `.csproj` here, so `bin/` is source (as Clopen's own is).
|
|
192
|
+
await mkdir(join(root, 'bin'), { recursive: true });
|
|
193
|
+
expect(await fileWatcher.startWatching('p12', root)).toBe(true);
|
|
194
|
+
await new Promise((r) => setTimeout(r, 400));
|
|
195
|
+
|
|
196
|
+
await writeFile(join(root, 'target', 'debug', 'app'), 'binary');
|
|
197
|
+
await new Promise((r) => setTimeout(r, 400));
|
|
198
|
+
await writeFile(join(root, 'myenv', 'lib', 'site.py'), '# noise');
|
|
199
|
+
await new Promise((r) => setTimeout(r, 400));
|
|
200
|
+
|
|
201
|
+
await writeFile(join(root, 'bin', 'cli.ts'), 'export {}');
|
|
202
|
+
await waitFor(() => changesFor('p12').some((p) => p.endsWith('cli.ts')));
|
|
203
|
+
|
|
204
|
+
const paths = changesFor('p12');
|
|
205
|
+
expect(paths.some((p) => p.includes(join('target', 'debug')))).toBe(false);
|
|
206
|
+
expect(paths.some((p) => p.includes(join('myenv', 'lib')))).toBe(false);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
test('stops reporting a directory once it declares itself a cache', async () => {
|
|
210
|
+
const root = await makeProject();
|
|
211
|
+
await mkdir(join(root, 'scratch'), { recursive: true });
|
|
212
|
+
expect(await fileWatcher.startWatching('p13', root)).toBe(true);
|
|
213
|
+
await new Promise((r) => setTimeout(r, 400));
|
|
214
|
+
|
|
215
|
+
await writeFile(join(root, 'scratch', 'before.txt'), 'seen');
|
|
216
|
+
await waitFor(() => changesFor('p13').some((p) => p.endsWith('before.txt')));
|
|
217
|
+
|
|
218
|
+
await writeFile(join(root, 'scratch', 'CACHEDIR.TAG'), 'Signature: 8a477f597d28d172789f06886806bc55');
|
|
219
|
+
await new Promise((r) => setTimeout(r, 400));
|
|
220
|
+
await writeFile(join(root, 'scratch', 'after.txt'), 'noise');
|
|
221
|
+
await new Promise((r) => setTimeout(r, 400));
|
|
222
|
+
|
|
223
|
+
await writeFile(join(root, 'app.ts'), 'export {}');
|
|
224
|
+
await waitFor(() => changesFor('p13').some((p) => p.endsWith('app.ts')));
|
|
225
|
+
|
|
226
|
+
expect(changesFor('p13').some((p) => p.endsWith('after.txt'))).toBe(false);
|
|
227
|
+
});
|
|
228
|
+
|
|
152
229
|
test('does not emit an empty change list', async () => {
|
|
153
230
|
const root = await makeProject();
|
|
154
231
|
expect(await fileWatcher.startWatching('p4', root)).toBe(true);
|