@myrialabs/clopen 0.4.45 → 0.4.46
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/sources.ts +2 -2
- package/backend/engine/adapters/claude/models.test.ts +49 -0
- package/backend/engine/adapters/claude/models.ts +81 -562
- package/backend/engine/adapters/claude/stream.ts +5 -4
- package/backend/engine/adapters/cline/credential.ts +42 -18
- package/backend/engine/adapters/cline/message-converter.ts +31 -1
- package/backend/engine/adapters/cline/models.test.ts +77 -0
- package/backend/engine/adapters/cline/models.ts +89 -3
- package/backend/engine/adapters/cline/presets.ts +5 -0
- package/backend/engine/adapters/cline/stream.ts +9 -2
- package/backend/engine/adapters/codex/message-converter.ts +1 -1
- package/backend/engine/adapters/codex/models.ts +54 -31
- package/backend/engine/adapters/codex/patch-rollout.test.ts +36 -1
- package/backend/engine/adapters/codex/patch-rollout.ts +60 -29
- package/backend/engine/adapters/codex/session-fork.ts +5 -0
- package/backend/engine/adapters/codex/stream.ts +8 -7
- package/backend/engine/adapters/copilot/models.test.ts +40 -0
- package/backend/engine/adapters/copilot/models.ts +51 -24
- package/backend/engine/adapters/copilot/permissions.test.ts +47 -0
- package/backend/engine/adapters/copilot/permissions.ts +72 -0
- package/backend/engine/adapters/copilot/stream.ts +77 -67
- package/backend/engine/adapters/cursor/stream.ts +8 -4
- package/backend/engine/adapters/pi/credential.test.ts +83 -0
- package/backend/engine/adapters/pi/credential.ts +68 -12
- package/backend/engine/adapters/pi/environment.ts +9 -5
- package/backend/engine/adapters/pi/mcp.test.ts +194 -0
- package/backend/engine/adapters/pi/mcp.ts +88 -0
- package/backend/engine/adapters/pi/message-converter.ts +6 -4
- package/backend/engine/adapters/pi/presets.ts +10 -5
- package/backend/engine/adapters/pi/stream.ts +42 -38
- package/backend/engine/adapters/qwen/environment.ts +39 -2
- package/backend/engine/adapters/qwen/message-converter.test.ts +64 -0
- package/backend/engine/adapters/qwen/message-converter.ts +40 -23
- package/backend/engine/adapters/qwen/models.test.ts +25 -0
- package/backend/engine/adapters/qwen/models.ts +42 -5
- package/backend/engine/adapters/qwen/session-store.test.ts +39 -0
- package/backend/engine/adapters/qwen/session-store.ts +66 -0
- package/backend/engine/adapters/qwen/stream.ts +110 -87
- package/backend/engine/docs/adapter-contract.md +7 -4
- package/backend/engine/docs/lessons-learned.md +405 -62
- package/backend/engine/docs/quick-reference.md +2 -2
- package/backend/engine/docs/stack.md +17 -4
- package/backend/engine/docs/websocket-routes.md +5 -5
- package/backend/engine/install-recipes.test.ts +105 -5
- package/backend/engine/install-recipes.ts +102 -42
- package/backend/engine/install-runner.ts +56 -2
- package/backend/engine/stack-project.ts +71 -1
- package/backend/index.ts +5 -0
- package/backend/mcp/README.md +2 -2
- package/backend/mcp/external/config.ts +18 -0
- package/backend/mcp/external/proxy.ts +2 -2
- package/backend/mcp/index.ts +8 -0
- package/backend/mcp/internal/config.ts +42 -3
- package/backend/memory/embedding/install.ts +29 -1
- package/backend/utils/keyed-lock.test.ts +33 -0
- package/backend/utils/keyed-lock.ts +17 -0
- package/backend/utils/port-utils.test.ts +29 -0
- package/backend/utils/port-utils.ts +19 -0
- package/backend/ws/engine/cline/accounts.ts +26 -6
- package/backend/ws/engine/codex/accounts.test.ts +49 -0
- package/backend/ws/engine/codex/accounts.ts +17 -13
- package/backend/ws/engine/pi/accounts.ts +61 -6
- package/dist/assets/{index-D-Ad1N96.js → index-BTcR1byF.js} +1 -1
- package/dist/assets/{index-Am-rJRxA.js → index-CwuKQelV.js} +1 -1
- package/dist/assets/{main--PLCDxSy.css → main-BiDNMWb3.css} +1 -1
- package/dist/assets/{main-DelPm2Xt.js → main-BlhKWz2B.js} +595 -593
- package/dist/index.html +2 -2
- package/package.json +19 -15
- package/backend/engine/adapters/pi/mcp-tools.ts +0 -153
- package/backend/engine/adapters/qwen/session-fork.ts +0 -109
package/dist/index.html
CHANGED
|
@@ -63,8 +63,8 @@
|
|
|
63
63
|
}
|
|
64
64
|
})();
|
|
65
65
|
</script>
|
|
66
|
-
<script type="module" crossorigin src="/assets/main-
|
|
67
|
-
<link rel="stylesheet" crossorigin href="/assets/main
|
|
66
|
+
<script type="module" crossorigin src="/assets/main-BlhKWz2B.js"></script>
|
|
67
|
+
<link rel="stylesheet" crossorigin href="/assets/main-BiDNMWb3.css">
|
|
68
68
|
</head>
|
|
69
69
|
<body
|
|
70
70
|
class="min-h-dvh bg-white text-slate-900 dark:bg-slate-950 dark:text-slate-100 transition-colors duration-200"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@myrialabs/clopen",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.46",
|
|
4
4
|
"description": "All-in-one web workspace for AI coding agents — Claude Code, OpenCode, Codex, Copilot, Qwen Code, Pi, Cline, and Cursor — with chat, terminal, git, browser preview, database client, checkpoints, and real-time collaboration",
|
|
5
5
|
"author": "Myria Labs",
|
|
6
6
|
"license": "MIT",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"dev:frontend": "bunx vite dev",
|
|
70
70
|
"build": "vite build",
|
|
71
71
|
"start": "bun scripts/start.ts",
|
|
72
|
-
"check": "svelte-check --tsconfig ./tsconfig.json",
|
|
72
|
+
"check": "NODE_OPTIONS=--max-old-space-size=4096 svelte-check --tsconfig ./tsconfig.json",
|
|
73
73
|
"lint": "eslint .",
|
|
74
74
|
"lint:fix": "eslint . --fix",
|
|
75
75
|
"test": "bun test --isolate",
|
|
@@ -77,20 +77,24 @@
|
|
|
77
77
|
"prepublishOnly": "bun run build"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
|
-
"@anthropic-ai/claude-agent-sdk": "0.3.
|
|
81
|
-
"@anthropic-ai/sdk": "0.
|
|
82
|
-
"@cline/agents": "0.0.
|
|
83
|
-
"@cline/sdk": "0.0.
|
|
84
|
-
"@cursor/sdk": "1.0.
|
|
85
|
-
"@earendil-works/
|
|
86
|
-
"@earendil-works/pi-
|
|
87
|
-
"@earendil-works/pi-
|
|
80
|
+
"@anthropic-ai/claude-agent-sdk": "0.3.296",
|
|
81
|
+
"@anthropic-ai/sdk": "0.133.0",
|
|
82
|
+
"@cline/agents": "0.0.92",
|
|
83
|
+
"@cline/sdk": "0.0.92",
|
|
84
|
+
"@cursor/sdk": "1.0.37",
|
|
85
|
+
"@earendil-works/chord": "1.1.0",
|
|
86
|
+
"@earendil-works/pi-agent-core": "1.1.0",
|
|
87
|
+
"@earendil-works/pi-ai": "1.1.0",
|
|
88
|
+
"@earendil-works/pi-codemode": "1.1.0",
|
|
89
|
+
"@earendil-works/pi-coding-agent": "1.1.0",
|
|
90
|
+
"@earendil-works/pi-mcp": "1.1.0",
|
|
91
|
+
"@earendil-works/pi-telemetry": "1.1.0",
|
|
92
|
+
"@earendil-works/pi-tui": "1.1.0",
|
|
88
93
|
"@eslint/js": "^9.31.0",
|
|
89
|
-
"@github/copilot": "1.0.
|
|
90
|
-
"@
|
|
91
|
-
"@
|
|
92
|
-
"@
|
|
93
|
-
"@qwen-code/sdk": "0.1.8",
|
|
94
|
+
"@github/copilot-sdk": "1.0.16",
|
|
95
|
+
"@openai/codex-sdk": "0.159.3",
|
|
96
|
+
"@opencode-ai/sdk": "1.18.34",
|
|
97
|
+
"@qwen-code/sdk": "0.1.17",
|
|
94
98
|
"@sveltejs/vite-plugin-svelte": "^6.0.0",
|
|
95
99
|
"@tailwindcss/vite": "^4.1.11",
|
|
96
100
|
"@types/bun": "^1.2.18",
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MCP → Pi custom-tool bridge.
|
|
3
|
-
*
|
|
4
|
-
* Pi has NO native MCP support (by design — see the pi README). Because Pi runs
|
|
5
|
-
* IN-PROCESS, we don't need the `/mcp` HTTP bridge the other engines use: we
|
|
6
|
-
* expose each enabled Clopen MCP tool directly as a Pi custom tool
|
|
7
|
-
* (`ToolDefinition`) whose `execute` calls the tool handler in-process.
|
|
8
|
-
*
|
|
9
|
-
* - INTERNAL servers (`defineServer()` — e.g. browser-automation): the handler
|
|
10
|
-
* runs bound to the stream's project context (AsyncLocalStorage) with an
|
|
11
|
-
* abort short-circuit, exactly like Claude's in-process path.
|
|
12
|
-
* - EXTERNAL servers (user-installed, `mcp_servers` table): proxied to the
|
|
13
|
-
* upstream server via `callExternalServerTool`.
|
|
14
|
-
*
|
|
15
|
-
* Tool names use the canonical `mcp__<namespace>__<tool>` form so the unified UI
|
|
16
|
-
* + `toCanonicalToolName()` render them identically to the other engines.
|
|
17
|
-
*
|
|
18
|
-
* Note: MCP tool JSON schemas are surfaced to the model through the tool
|
|
19
|
-
* DESCRIPTION (Pi tool `parameters` stays a permissive object) — the handler
|
|
20
|
-
* validates the arguments, so this is lossless for execution.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
import { Type } from 'typebox';
|
|
24
|
-
import type { ToolDefinition } from '@earendil-works/pi-coding-agent';
|
|
25
|
-
import type { TextContent, ImageContent } from '@earendil-works/pi-ai';
|
|
26
|
-
import type { McpExecutionContext } from '../../types';
|
|
27
|
-
import {
|
|
28
|
-
getEnabledServerNames,
|
|
29
|
-
isToolEnabled,
|
|
30
|
-
getEnabledExternalServers,
|
|
31
|
-
listExternalServerTools,
|
|
32
|
-
callExternalServerTool,
|
|
33
|
-
getTrustedProjectServers,
|
|
34
|
-
listProjectServerTools,
|
|
35
|
-
callProjectServerTool,
|
|
36
|
-
projectContextService,
|
|
37
|
-
serverMetadata,
|
|
38
|
-
} from '../../../mcp';
|
|
39
|
-
import { debug } from '$shared/utils/logger';
|
|
40
|
-
|
|
41
|
-
type McpContentItem = { type: string; text?: string; data?: string; mimeType?: string };
|
|
42
|
-
|
|
43
|
-
/** Permissive object schema — arguments are validated by the tool handler. */
|
|
44
|
-
const OPEN_PARAMS = Type.Object({}, { additionalProperties: true });
|
|
45
|
-
|
|
46
|
-
/** Map an MCP content array into Pi's `(TextContent | ImageContent)[]`. */
|
|
47
|
-
function toPiContent(raw: unknown): (TextContent | ImageContent)[] {
|
|
48
|
-
const items = Array.isArray(raw) ? (raw as McpContentItem[]) : [];
|
|
49
|
-
const out: (TextContent | ImageContent)[] = [];
|
|
50
|
-
for (const item of items) {
|
|
51
|
-
if (item?.type === 'image' && typeof item.data === 'string') {
|
|
52
|
-
out.push({ type: 'image', data: item.data, mimeType: item.mimeType || 'image/png' });
|
|
53
|
-
} else if (typeof item?.text === 'string') {
|
|
54
|
-
out.push({ type: 'text', text: item.text });
|
|
55
|
-
} else if (item != null) {
|
|
56
|
-
out.push({ type: 'text', text: JSON.stringify(item) });
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
if (out.length === 0) out.push({ type: 'text', text: '' });
|
|
60
|
-
return out;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Build the set of Pi custom tools mirroring every enabled internal + external
|
|
65
|
-
* MCP tool. Scoped to the active Profile via `profileFilter` (server ids).
|
|
66
|
-
*/
|
|
67
|
-
export async function buildPiMcpTools(
|
|
68
|
-
context: McpExecutionContext | undefined,
|
|
69
|
-
profileFilter: Set<string> | undefined,
|
|
70
|
-
): Promise<ToolDefinition[]> {
|
|
71
|
-
const tools: ToolDefinition[] = [];
|
|
72
|
-
|
|
73
|
-
// ── Internal servers (in-process handlers) ──
|
|
74
|
-
for (const serverName of getEnabledServerNames()) {
|
|
75
|
-
if (profileFilter && !profileFilter.has(serverName)) continue;
|
|
76
|
-
const meta = (serverMetadata as Record<string, { tools: readonly string[]; toolDefs: Record<string, { description: string; schema: Record<string, unknown>; handler: (args: unknown) => Promise<{ content: McpContentItem[]; isError?: boolean }> }> }>)[serverName];
|
|
77
|
-
if (!meta) continue;
|
|
78
|
-
|
|
79
|
-
// meta.tools holds RAW tool names (the toolDefs keys). getEnabledToolsForServer()
|
|
80
|
-
// returns the `mcp__<server>__<tool>` form, which would never match toolDefs.
|
|
81
|
-
for (const toolName of meta.tools) {
|
|
82
|
-
if (!isToolEnabled(serverName, toolName)) continue;
|
|
83
|
-
const def = meta.toolDefs[toolName];
|
|
84
|
-
if (!def) continue;
|
|
85
|
-
const fullName = `mcp__${serverName}__${toolName}`;
|
|
86
|
-
const argKeys = Object.keys(def.schema ?? {});
|
|
87
|
-
tools.push({
|
|
88
|
-
name: fullName,
|
|
89
|
-
label: toolName,
|
|
90
|
-
description: `${def.description}${argKeys.length ? `\n\nArguments: ${argKeys.join(', ')}` : ''}`,
|
|
91
|
-
parameters: OPEN_PARAMS,
|
|
92
|
-
execute: async (_toolCallId: string, params: unknown) => {
|
|
93
|
-
const run = async () => {
|
|
94
|
-
const signal = projectContextService.getCurrentSignal();
|
|
95
|
-
if (signal?.aborted) {
|
|
96
|
-
return { content: [{ type: 'text' as const, text: `Tool ${fullName} was cancelled.` }], details: {} };
|
|
97
|
-
}
|
|
98
|
-
const result = await def.handler(params ?? {});
|
|
99
|
-
return { content: toPiContent(result?.content), details: {} };
|
|
100
|
-
};
|
|
101
|
-
return context ? projectContextService.runWithContextAsync(context, run) : run();
|
|
102
|
-
},
|
|
103
|
-
} as ToolDefinition);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// ── External servers (proxied upstream) ──
|
|
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) {
|
|
128
|
-
let externalTools;
|
|
129
|
-
try {
|
|
130
|
-
externalTools = await server.list();
|
|
131
|
-
} catch (error) {
|
|
132
|
-
debug.warn('mcp', `Pi MCP bridge: could not list tools for "${server.label}" (skipping):`, error);
|
|
133
|
-
continue;
|
|
134
|
-
}
|
|
135
|
-
for (const tool of externalTools) {
|
|
136
|
-
const fullName = `mcp__${server.namespace}__${tool.name}`;
|
|
137
|
-
const schemaText = tool.inputSchema ? `\n\nInput JSON schema:\n${JSON.stringify(tool.inputSchema)}` : '';
|
|
138
|
-
tools.push({
|
|
139
|
-
name: fullName,
|
|
140
|
-
label: tool.name,
|
|
141
|
-
description: `${tool.description ?? tool.name}${schemaText}`,
|
|
142
|
-
parameters: OPEN_PARAMS,
|
|
143
|
-
execute: async (_toolCallId: string, params: unknown) => {
|
|
144
|
-
const result = (await server.call(tool.name, params ?? {})) as { content?: unknown } | undefined;
|
|
145
|
-
return { content: toPiContent(result?.content), details: {} };
|
|
146
|
-
},
|
|
147
|
-
} as ToolDefinition);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
debug.log('mcp', `Pi MCP bridge: ${tools.length} tool(s) exposed`);
|
|
152
|
-
return tools;
|
|
153
|
-
}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Qwen Code Session Fork (workaround)
|
|
3
|
-
*
|
|
4
|
-
* The Qwen Code SDK / CLI does not yet expose a native fork primitive. To
|
|
5
|
-
* support Clopen's multi-branch checkpoints feature — which lets the user
|
|
6
|
-
* replay an earlier point in the conversation as a sibling branch — we
|
|
7
|
-
* copy the on-disk chat file to a fresh session id and patch the embedded
|
|
8
|
-
* id references.
|
|
9
|
-
*
|
|
10
|
-
* On-disk layout (`~/.qwen/projects/<sanitized-cwd>/chats/<sessionId>.jsonl`):
|
|
11
|
-
*
|
|
12
|
-
* - `<sanitized-cwd>` is `cwd.replace(/[^a-zA-Z0-9]/g, '-')` (with a
|
|
13
|
-
* `toLowerCase()` first on win32). Mirror of the SDK's `sanitizeCwd()`
|
|
14
|
-
* in `node_modules/@qwen-code/sdk/dist/cli/cli.js` so we resolve to the
|
|
15
|
-
* same directory the bundled CLI writes to.
|
|
16
|
-
* - Each chat is a SINGLE JSONL file. Every record carries a
|
|
17
|
-
* `sessionId` field equal to the file's basename (without `.jsonl`).
|
|
18
|
-
* Per-record `uuid` / `parentUuid` reference the previous record's
|
|
19
|
-
* `uuid` and are unrelated to the session id, so a blanket replace
|
|
20
|
-
* of the source session id is safe.
|
|
21
|
-
*
|
|
22
|
-
* After copy + patch, `query({ ..., resume: <forkId> })` makes the bundled
|
|
23
|
-
* CLI pick the new file up as a resumed session whose id is `forkId`. The
|
|
24
|
-
* source file is left untouched so the original branch's history stays
|
|
25
|
-
* replayable.
|
|
26
|
-
*
|
|
27
|
-
* TODO: when @qwen-code/sdk gains a native `forkSession()` (or an
|
|
28
|
-
* equivalent flag the CLI honours, e.g. `--resume <id> --fork`), delete
|
|
29
|
-
* this helper and switch `QwenEngine.streamQuery` to use the SDK API
|
|
30
|
-
* directly. The migration is one line — same shape as Claude
|
|
31
|
-
* (`forkSession: true`) and OpenCode (`client.session.fork()`).
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
import fs from 'node:fs';
|
|
35
|
-
import path from 'node:path';
|
|
36
|
-
import os from 'node:os';
|
|
37
|
-
import { getEngineUserConfigDir } from '$backend/utils/paths';
|
|
38
|
-
import { debug } from '$shared/utils/logger';
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Qwen's runtime output base, forwarded to the CLI via `QWEN_RUNTIME_DIR`
|
|
42
|
-
* (see ./environment.ts). The bundled CLI writes chats under
|
|
43
|
-
* `<runtimeBase>/projects/<sanitized-cwd>/chats/` (Storage.getProjectDir →
|
|
44
|
-
* getRuntimeBaseDir), so this helper must resolve to the SAME base the env
|
|
45
|
-
* var sets or the fork would land in a directory the CLI never reads.
|
|
46
|
-
*/
|
|
47
|
-
export function getQwenRuntimeDir(): string {
|
|
48
|
-
return getEngineUserConfigDir('qwen');
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const QWEN_PROJECTS_DIR = path.join(getQwenRuntimeDir(), 'projects');
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Mirror of `sanitizeCwd` in @qwen-code/sdk's bundled CLI
|
|
55
|
-
* (cli.js::sanitizeCwd). Lower-case on Windows then collapse every
|
|
56
|
-
* non-alphanumeric character to `-`. Drift from this would point to a
|
|
57
|
-
* different project directory and the fork would land in a directory the
|
|
58
|
-
* CLI never reads.
|
|
59
|
-
*/
|
|
60
|
-
function sanitizeCwd(cwd: string): string {
|
|
61
|
-
const normalized = os.platform() === 'win32' ? cwd.toLowerCase() : cwd;
|
|
62
|
-
return normalized.replace(/[^a-zA-Z0-9]/g, '-');
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function getChatsDir(projectPath: string): string {
|
|
66
|
-
return path.join(QWEN_PROJECTS_DIR, sanitizeCwd(projectPath), 'chats');
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export function getSessionStatePath(projectPath: string, sessionId: string): string {
|
|
70
|
-
return path.join(getChatsDir(projectPath), `${sessionId}.jsonl`);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export function sessionStateExists(projectPath: string, sessionId: string): boolean {
|
|
74
|
-
return fs.existsSync(getSessionStatePath(projectPath, sessionId));
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Copy `sourceSessionId`'s chat file to a new file keyed by
|
|
79
|
-
* `forkSessionId` (in the same project's `chats/` directory) and patch
|
|
80
|
-
* the embedded session ids. Returns true on success, false if the source
|
|
81
|
-
* file is missing (caller falls back to a fresh chat).
|
|
82
|
-
*
|
|
83
|
-
* The destination is removed first if it already exists so a re-fork
|
|
84
|
-
* from the same source produces a clean copy.
|
|
85
|
-
*/
|
|
86
|
-
export function forkQwenSessionState(
|
|
87
|
-
projectPath: string,
|
|
88
|
-
sourceSessionId: string,
|
|
89
|
-
forkSessionId: string,
|
|
90
|
-
): boolean {
|
|
91
|
-
const srcPath = getSessionStatePath(projectPath, sourceSessionId);
|
|
92
|
-
if (!fs.existsSync(srcPath)) {
|
|
93
|
-
debug.warn('engine', `Qwen fork: source chat ${sourceSessionId} not found at ${srcPath}`);
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const dstPath = getSessionStatePath(projectPath, forkSessionId);
|
|
98
|
-
fs.mkdirSync(path.dirname(dstPath), { recursive: true });
|
|
99
|
-
if (fs.existsSync(dstPath)) {
|
|
100
|
-
fs.rmSync(dstPath, { force: true });
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const content = fs.readFileSync(srcPath, 'utf-8');
|
|
104
|
-
const patched = content.split(sourceSessionId).join(forkSessionId);
|
|
105
|
-
fs.writeFileSync(dstPath, patched);
|
|
106
|
-
|
|
107
|
-
debug.log('engine', `Qwen fork: ${sourceSessionId} → ${forkSessionId}`);
|
|
108
|
-
return true;
|
|
109
|
-
}
|