@myrialabs/clopen 0.4.44 → 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/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 +20 -3
- 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/models.test.ts +49 -0
- package/backend/engine/adapters/claude/models.ts +81 -562
- package/backend/engine/adapters/claude/stream.ts +32 -5
- package/backend/engine/adapters/cline/credential.ts +42 -18
- package/backend/engine/adapters/cline/mcp-tools.ts +26 -4
- 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 +29 -8
- 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 +29 -11
- 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 +83 -70
- package/backend/engine/adapters/cursor/stream.ts +27 -12
- package/backend/engine/adapters/opencode/server.ts +14 -4
- package/backend/engine/adapters/opencode/stream.ts +18 -3
- 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 +77 -41
- 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 +118 -87
- package/backend/engine/artifact-sync.ts +12 -5
- 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/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 +16 -1
- package/backend/instructions/service.ts +5 -3
- package/backend/instructions/sync.ts +10 -27
- package/backend/mcp/README.md +2 -2
- package/backend/mcp/external/config.ts +83 -23
- package/backend/mcp/external/project.ts +124 -0
- package/backend/mcp/external/proxy.ts +65 -11
- package/backend/mcp/index.ts +22 -9
- package/backend/mcp/internal/config.ts +42 -3
- package/backend/mcp/internal/remote-server.ts +11 -1
- package/backend/memory/embedding/install.ts +29 -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/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/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/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/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-DX5OwLOc.js → index-BTcR1byF.js} +1 -1
- package/dist/assets/{index-BWyhqUi5.js → index-CwuKQelV.js} +1 -1
- package/dist/assets/main-BiDNMWb3.css +1 -0
- package/dist/assets/main-BlhKWz2B.js +1241 -0
- package/dist/index.html +2 -2
- package/package.json +19 -15
- package/shared/types/stores/settings.ts +5 -0
- package/shared/types/unified/message.ts +2 -0
- package/backend/engine/adapters/pi/mcp-tools.ts +0 -131
- package/backend/engine/adapters/qwen/session-fork.ts +0 -109
- package/dist/assets/main-DOkwqXRU.js +0 -1215
- package/dist/assets/main-DzCY0n-j.css +0 -1
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Qwen Code on-disk session store
|
|
3
|
+
*
|
|
4
|
+
* Forking is native since @qwen-code/sdk 0.1.17 (`resume` + `forkSession`,
|
|
5
|
+
* the CLI's `--fork-session`; see `QwenEngine.streamQuery`). This module
|
|
6
|
+
* only locates chats on disk so the adapter can tell whether a resume target
|
|
7
|
+
* still exists before asking the CLI to fork it — `--fork-session` on a
|
|
8
|
+
* missing source exits the CLI with code 1 instead of starting fresh.
|
|
9
|
+
*
|
|
10
|
+
* On-disk layout (`<QWEN_RUNTIME_DIR>/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 `sanitizeCwd()` in the
|
|
14
|
+
* SDK's bundled CLI (`dist/cli/chunks/`) so we resolve to the same
|
|
15
|
+
* directory the CLI writes to.
|
|
16
|
+
* - The `cwd` the CLI sanitizes is its own `process.cwd()`, which the OS
|
|
17
|
+
* reports with symlinks resolved (`/var/…` → `/private/var/…` on macOS),
|
|
18
|
+
* so the project path is realpath'd before sanitizing.
|
|
19
|
+
* - Each chat is a SINGLE JSONL file named after its session id.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import fs from 'node:fs';
|
|
23
|
+
import path from 'node:path';
|
|
24
|
+
import os from 'node:os';
|
|
25
|
+
import { getEngineUserConfigDir } from '$backend/utils/paths';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Qwen's runtime output base, forwarded to the CLI via `QWEN_RUNTIME_DIR`
|
|
29
|
+
* (see ./environment.ts). The bundled CLI writes chats under
|
|
30
|
+
* `<runtimeBase>/projects/<sanitized-cwd>/chats/` (Storage.getProjectDir →
|
|
31
|
+
* getRuntimeBaseDir), so lookups here must resolve to the SAME base the env
|
|
32
|
+
* var sets or every chat would look missing.
|
|
33
|
+
*/
|
|
34
|
+
export function getQwenRuntimeDir(): string {
|
|
35
|
+
return getEngineUserConfigDir('qwen');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const QWEN_PROJECTS_DIR = path.join(getQwenRuntimeDir(), 'projects');
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Mirror of `sanitizeCwd` in @qwen-code/sdk's bundled CLI. Lower-case on
|
|
42
|
+
* Windows then collapse every non-alphanumeric character to `-`. Drift from
|
|
43
|
+
* this would point to a different project directory than the one the CLI
|
|
44
|
+
* writes to.
|
|
45
|
+
*/
|
|
46
|
+
function sanitizeCwd(cwd: string): string {
|
|
47
|
+
const normalized = os.platform() === 'win32' ? cwd.toLowerCase() : cwd;
|
|
48
|
+
return normalized.replace(/[^a-zA-Z0-9]/g, '-');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The cwd as the spawned CLI sees it: symlinks resolved, input kept if it doesn't exist. */
|
|
52
|
+
function resolveCliCwd(projectPath: string): string {
|
|
53
|
+
try {
|
|
54
|
+
return fs.realpathSync(projectPath);
|
|
55
|
+
} catch {
|
|
56
|
+
return projectPath;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function getSessionStatePath(projectPath: string, sessionId: string): string {
|
|
61
|
+
return path.join(QWEN_PROJECTS_DIR, sanitizeCwd(resolveCliCwd(projectPath)), 'chats', `${sessionId}.jsonl`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function sessionStateExists(projectPath: string, sessionId: string): boolean {
|
|
65
|
+
return fs.existsSync(getSessionStatePath(projectPath, sessionId));
|
|
66
|
+
}
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* (README §10.12).
|
|
19
19
|
*
|
|
20
20
|
* AskUserQuestion: Qwen's `canUseTool` callback signature does NOT include
|
|
21
|
-
* the tool_use_id (
|
|
21
|
+
* the tool_use_id (`CanUseTool` in `@qwen-code/sdk`'s `dist/index.d.ts`),
|
|
22
22
|
* so we cannot key pending answers by id at the moment the SDK invokes the
|
|
23
23
|
* callback. The SDK serialises AskUserQuestion — only one can be pending at
|
|
24
24
|
* a time — so we keep a single slot and recover the real tool_use_id from
|
|
@@ -35,24 +35,63 @@ import type {
|
|
|
35
35
|
SDKUserMessage,
|
|
36
36
|
PermissionResult,
|
|
37
37
|
ToolInput,
|
|
38
|
+
EffortTier,
|
|
38
39
|
} from '@qwen-code/sdk';
|
|
39
40
|
import { loadEngineSdk } from '$backend/engine/sdk-loader';
|
|
40
|
-
import type { EngineOutput, EngineModel } from '$shared/types/unified';
|
|
41
|
+
import type { EngineOutput, EngineModel, AskUserQuestion } from '$shared/types/unified';
|
|
41
42
|
import type { AIEngine, EngineQueryOptions, StructuredGenerationOptions } from '../../types';
|
|
42
43
|
import { buildJsonPrompt, extractJson, emptyGenerationError } from '../../structured-helpers';
|
|
43
44
|
import { resolveOsPath } from '$backend/utils/paths';
|
|
44
45
|
import { debug } from '$shared/utils/logger';
|
|
45
46
|
import { getEngineEnv } from './environment';
|
|
46
47
|
import { handleStreamError } from './error-handler';
|
|
47
|
-
import { createSdkMessageConverter, toSdkUserMessage, type SdkMessageConverter } from './message-converter';
|
|
48
|
+
import { createSdkMessageConverter, toSdkUserMessage, toQwenAnswers, type SdkMessageConverter } from './message-converter';
|
|
48
49
|
import { fetchQwenModels } from './models';
|
|
49
50
|
import { getQwenMcpConfig } from '../../../mcp';
|
|
50
51
|
import { EngineRuns } from '../run-registry';
|
|
51
52
|
import { artifactFilter } from '$backend/profiles';
|
|
52
53
|
import { syncSkills } from '$backend/skills';
|
|
53
54
|
import { syncEngineArtifacts } from '$backend/engine/artifact-sync';
|
|
55
|
+
import { resolveProjectBridge, buildProjectPromptContext } from '$backend/artifacts/project';
|
|
54
56
|
import { resolvePermissionsFromDb, isToolAllowed, excludedBuiltinTools } from '$backend/permissions';
|
|
55
|
-
import {
|
|
57
|
+
import { sessionStateExists } from './session-store';
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Every tier the SDK's `effort` option accepts. Typed against the SDK union so
|
|
61
|
+
* a tier it drops is a compile error here. The picker only offers what the
|
|
62
|
+
* model advertises (see ./models.ts); this guards against a stale per-model
|
|
63
|
+
* default from another engine reaching the CLI.
|
|
64
|
+
*/
|
|
65
|
+
const QWEN_EFFORTS: ReadonlySet<string> = new Set<EffortTier>(['low', 'medium', 'high', 'xhigh', 'max']);
|
|
66
|
+
|
|
67
|
+
function toQwenEffort(reasoningEffort: string | undefined): EffortTier | undefined {
|
|
68
|
+
return reasoningEffort && QWEN_EFFORTS.has(reasoningEffort) ? reasoningEffort as EffortTier : undefined;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The CLI's `MAX_CAN_USE_TOOL_TIMEOUT_MS`; anything larger is ignored for its 60 s default. */
|
|
72
|
+
const QWEN_MAX_CAN_USE_TOOL_TIMEOUT_MS = 600_000;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The prompt for one turn, as a stream that stays OPEN until the turn ends.
|
|
76
|
+
*
|
|
77
|
+
* When the prompt iterable completes, the SDK waits for the first `result`
|
|
78
|
+
* or its `streamClose` timeout (60 s) and then closes the CLI's stdin. The
|
|
79
|
+
* CLI answers that by rejecting every pending and future control request
|
|
80
|
+
* with "Input closed" — so in any turn longer than a minute, AskUserQuestion,
|
|
81
|
+
* write-tool approvals and interrupt all failed ("The host could not present
|
|
82
|
+
* the required approval"). Holding the stream open until `end()` (called on
|
|
83
|
+
* `result`, on abort, and in `finally`) keeps stdin alive for the whole turn.
|
|
84
|
+
*/
|
|
85
|
+
function openPromptStream(message: SDKUserMessage, signal: AbortSignal): { iterable: AsyncIterable<SDKUserMessage>; end: () => void } {
|
|
86
|
+
let end!: () => void;
|
|
87
|
+
const ended = new Promise<void>((resolve) => { end = resolve; });
|
|
88
|
+
signal.addEventListener('abort', () => end(), { once: true });
|
|
89
|
+
const iterable = (async function* (): AsyncIterable<SDKUserMessage> {
|
|
90
|
+
yield message;
|
|
91
|
+
await ended;
|
|
92
|
+
})();
|
|
93
|
+
return { iterable, end };
|
|
94
|
+
}
|
|
56
95
|
|
|
57
96
|
interface PendingAskUserQuestion {
|
|
58
97
|
resolve: (result: PermissionResult) => void;
|
|
@@ -79,11 +118,8 @@ interface QwenRun {
|
|
|
79
118
|
query: Query | null;
|
|
80
119
|
/**
|
|
81
120
|
* Live converter for this run — used by `resolveUserAnswer` to push the
|
|
82
|
-
* user's answers into the converter state so the
|
|
83
|
-
*
|
|
84
|
-
* AUQ tool execution path drops `answers` on the floor; see the comment
|
|
85
|
-
* block at the top of `message-converter.ts` and the analysis in
|
|
86
|
-
* `qwen/stream.ts::canUseTool` for AskUserQuestion).
|
|
121
|
+
* user's answers into the converter state so the AUQ tool_result is shown
|
|
122
|
+
* in the same wording every engine uses (see `convertUserMessage`).
|
|
87
123
|
*/
|
|
88
124
|
converter: SdkMessageConverter | null;
|
|
89
125
|
pendingAskUserQuestion: PendingAskUserQuestion | null;
|
|
@@ -139,6 +175,7 @@ export class QwenEngine implements AIEngine {
|
|
|
139
175
|
resume,
|
|
140
176
|
maxTurns,
|
|
141
177
|
modelId,
|
|
178
|
+
reasoningEffort,
|
|
142
179
|
includePartialMessages = true,
|
|
143
180
|
abortController,
|
|
144
181
|
accountId,
|
|
@@ -165,35 +202,40 @@ export class QwenEngine implements AIEngine {
|
|
|
165
202
|
await syncSkills('qwen', profileId);
|
|
166
203
|
await syncEngineArtifacts('qwen', profileId);
|
|
167
204
|
const mcpConfig = getQwenMcpConfig(mcpProfileFilter, options.mcpContext);
|
|
205
|
+
// Repository artifacts Qwen doesn't read natively (it reads `.qwen/*`,
|
|
206
|
+
// QWEN.md and AGENTS.md itself) — appended to its preset system prompt,
|
|
207
|
+
// which is per query. Qwen has no delegation surface Clopen can register
|
|
208
|
+
// with, so project subagents are never advertised to it.
|
|
209
|
+
const projectBridge = await resolveProjectBridge('qwen', resolvedProjectPath, options.mcpContext?.projectId);
|
|
210
|
+
const projectContext = buildProjectPromptContext(projectBridge, { skills: true, instructions: true });
|
|
168
211
|
|
|
169
212
|
// Resolve the permission policy once per stream; canUseTool enforces it
|
|
170
213
|
// (Qwen otherwise auto-allows everything). Tool names arrive snake_cased.
|
|
171
214
|
const permissions = resolvePermissionsFromDb('qwen', options.mcpContext?.projectId, profileId);
|
|
172
215
|
|
|
173
|
-
//
|
|
174
|
-
// (`forkSession: true`)
|
|
175
|
-
//
|
|
176
|
-
//
|
|
177
|
-
//
|
|
178
|
-
//
|
|
179
|
-
//
|
|
180
|
-
//
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
if (forkQwenSessionState(resolvedProjectPath, resume, forkId)) {
|
|
187
|
-
resumeId = forkId;
|
|
188
|
-
debug.log('engine', `Qwen resumed session: ${forkId} (forked from ${resume})`);
|
|
189
|
-
}
|
|
216
|
+
// Native fork on EVERY resume — same semantics as Claude
|
|
217
|
+
// (`forkSession: true`) and OpenCode (`client.session.fork()`): each
|
|
218
|
+
// turn gets a brand-new session id so the original branch's history is
|
|
219
|
+
// never mutated and the multi-branch checkpoint tree stays consistent.
|
|
220
|
+
// The CLI picks the fork id itself (`--session-id` is rejected next to
|
|
221
|
+
// `--resume`), and reports it on the stream like any other session id.
|
|
222
|
+
// `--fork-session` exits the CLI when the source chat is missing, so a
|
|
223
|
+
// vanished source falls through to a plain resume (best-effort recovery).
|
|
224
|
+
const forkOnResume = !!resume && sessionStateExists(resolvedProjectPath, resume);
|
|
225
|
+
if (resume) {
|
|
226
|
+
debug.log('engine', forkOnResume
|
|
227
|
+
? `Qwen resuming session ${resume} as a fork`
|
|
228
|
+
: `Qwen resume source ${resume} not found on disk, resuming without fork`);
|
|
190
229
|
}
|
|
230
|
+
const effort = toQwenEffort(reasoningEffort);
|
|
191
231
|
|
|
192
232
|
// Capture the last few stderr lines from the bundled CLI so we can
|
|
193
233
|
// surface them when the SDK reports a generic "CLI process exited
|
|
194
234
|
// with code N" error. Otherwise the underlying cause (bad model,
|
|
195
235
|
// bad endpoint, MCP timeout, …) is invisible to the user.
|
|
196
236
|
const stderrLines: string[] = [];
|
|
237
|
+
// Closes the prompt stream; set once the query is built (see openPromptStream).
|
|
238
|
+
let endPrompt = (): void => {};
|
|
197
239
|
const STDERR_KEEP = 20;
|
|
198
240
|
|
|
199
241
|
// Optional verbose SDK logging when CLOPEN_DEBUG_QWEN is set — useful
|
|
@@ -221,54 +263,27 @@ export class QwenEngine implements AIEngine {
|
|
|
221
263
|
debug.warn('engine', 'qwen stderr:', trimmed);
|
|
222
264
|
},
|
|
223
265
|
...(verbose ? { logLevel: 'debug' as const, debug: true } : {}),
|
|
224
|
-
// Lift the SDK's defaults: AskUserQuestion
|
|
225
|
-
//
|
|
226
|
-
// behaviour). MCP requests get a longer ceiling for slow
|
|
266
|
+
// Lift the SDK's defaults: AskUserQuestion blocks while the user
|
|
267
|
+
// thinks, and MCP requests get a longer ceiling for slow
|
|
227
268
|
// browser-automation calls. Other timeouts keep the default.
|
|
228
269
|
//
|
|
229
|
-
// `canUseTool` is
|
|
230
|
-
//
|
|
231
|
-
//
|
|
232
|
-
//
|
|
233
|
-
//
|
|
234
|
-
// the practical maximum and is effectively unbounded for AUQ.
|
|
270
|
+
// `canUseTool` is ALSO forwarded to the CLI, which ignores any
|
|
271
|
+
// value above its own `MAX_CAN_USE_TOOL_TIMEOUT_MS` (10 min) and
|
|
272
|
+
// silently falls back to 60 s — so a larger "unbounded" value
|
|
273
|
+
// cancelled every question answered after a minute. 10 min is
|
|
274
|
+
// the longest wait the CLI allows.
|
|
235
275
|
timeout: {
|
|
236
|
-
canUseTool:
|
|
276
|
+
canUseTool: QWEN_MAX_CAN_USE_TOOL_TIMEOUT_MS,
|
|
237
277
|
mcpRequest: 600_000,
|
|
238
278
|
},
|
|
239
279
|
// 'default' lets `canUseTool` decide; non-write tools auto-execute.
|
|
240
280
|
permissionMode: 'default',
|
|
241
|
-
//
|
|
242
|
-
//
|
|
243
|
-
//
|
|
244
|
-
//
|
|
245
|
-
//
|
|
246
|
-
|
|
247
|
-
// `handleOutgoingPermissionRequest` (cli.js:486478-486485) calls
|
|
248
|
-
// `onConfirm(ProceedOnce)` WITHOUT forwarding the `updatedInput`
|
|
249
|
-
// payload we resolve `canUseTool` with — so the user's `answers`
|
|
250
|
-
// are dropped and the AUQ tool executes with `userAnswers: {}`,
|
|
251
|
-
// emitting `"User has provided the following answers:\n\n"` and
|
|
252
|
-
// closing the UI dialog before the user can respond. The
|
|
253
|
-
// converter has a rewrite workaround (recordUserAnswer +
|
|
254
|
-
// convertUserMessage interception) but it depends on a race
|
|
255
|
-
// between the empty tool_result and `resolveUserAnswer` landing —
|
|
256
|
-
// not reliable enough for production use.
|
|
257
|
-
//
|
|
258
|
-
// TODO(qwen-sdk): re-enable AUQ once the upstream SDK forwards
|
|
259
|
-
// `updatedInput` from `canUseTool` into the tool execution
|
|
260
|
-
// payload. Verify by checking `handleOutgoingPermissionRequest`
|
|
261
|
-
// in the bundled CLI — when it stops calling
|
|
262
|
-
// `onConfirm(ProceedOnce)` without the payload (or starts
|
|
263
|
-
// passing the resolved `updatedInput`), drop this excludeTools
|
|
264
|
-
// entry. The AUQ flow code (canUseTool handler, converter
|
|
265
|
-
// state, resolveUserAnswer, recordUserAnswer) is intentionally
|
|
266
|
-
// kept in place so reverting is a one-line change.
|
|
267
|
-
// `canUseTool` (permissionMode 'default') only fires for WRITE tools,
|
|
268
|
-
// so read-only tools can't be blocked there. `excludeTools` has the
|
|
269
|
-
// highest permission priority, so denied/non-allowlisted built-ins are
|
|
270
|
-
// hidden from the model entirely. MCP tools are filtered at the bridge.
|
|
271
|
-
excludeTools: ['ask_user_question', ...excludedBuiltinTools(permissions, 'qwen')],
|
|
281
|
+
// `canUseTool` (permissionMode 'default') only fires for WRITE tools
|
|
282
|
+
// and `ask_user_question`, so read-only tools can't be blocked there.
|
|
283
|
+
// `excludeTools` has the highest permission priority, so
|
|
284
|
+
// denied/non-allowlisted built-ins are hidden from the model
|
|
285
|
+
// entirely. MCP tools are filtered at the bridge.
|
|
286
|
+
excludeTools: excludedBuiltinTools(permissions, 'qwen'),
|
|
272
287
|
canUseTool: async (toolName, input, ctx) => {
|
|
273
288
|
// Qwen SDK passes the registered (snake_case) tool name here —
|
|
274
289
|
// `ToolNames.ASK_USER_QUESTION = "ask_user_question"` — NOT the
|
|
@@ -313,18 +328,18 @@ export class QwenEngine implements AIEngine {
|
|
|
313
328
|
// Auto-allow everything else.
|
|
314
329
|
return { behavior: 'allow' as const, updatedInput: input };
|
|
315
330
|
},
|
|
331
|
+
...(projectContext ? { systemPrompt: { type: 'preset' as const, preset: 'qwen_code' as const, append: projectContext } } : {}),
|
|
316
332
|
...(maxTurns !== undefined ? { maxSessionTurns: maxTurns } : {}),
|
|
317
|
-
...(
|
|
333
|
+
...(resume ? { resume, ...(forkOnResume ? { forkSession: true } : {}) } : {}),
|
|
334
|
+
...(effort ? { effort } : {}),
|
|
318
335
|
...(Object.keys(mcpConfig).length > 0 ? { mcpServers: mcpConfig } : {}),
|
|
319
336
|
};
|
|
320
337
|
|
|
321
|
-
const
|
|
322
|
-
|
|
323
|
-
yield sdkPrompt;
|
|
324
|
-
})();
|
|
338
|
+
const promptStream = openPromptStream(toSdkUserMessage(prompt), controller.signal);
|
|
339
|
+
endPrompt = promptStream.end;
|
|
325
340
|
|
|
326
341
|
const { query } = await loadEngineSdk<typeof import('@qwen-code/sdk')>('qwen', '@qwen-code/sdk');
|
|
327
|
-
const queryInstance = query({ prompt:
|
|
342
|
+
const queryInstance = query({ prompt: promptStream.iterable, options: sdkOptions });
|
|
328
343
|
run.query = queryInstance;
|
|
329
344
|
|
|
330
345
|
const converter = createSdkMessageConverter(modelId, {
|
|
@@ -340,12 +355,27 @@ export class QwenEngine implements AIEngine {
|
|
|
340
355
|
},
|
|
341
356
|
});
|
|
342
357
|
run.converter = converter;
|
|
358
|
+
// The CLI may decline the requested effort (thinking disabled for the
|
|
359
|
+
// model, or a higher-priority wire override); log it once so a
|
|
360
|
+
// selector that "does nothing" is explainable from the server log.
|
|
361
|
+
let effortChecked = !effort;
|
|
343
362
|
for await (const sdkMessage of queryInstance) {
|
|
363
|
+
if (!effortChecked) {
|
|
364
|
+
const status = queryInstance.getInitialEffortStatus();
|
|
365
|
+
if (status) {
|
|
366
|
+
effortChecked = true;
|
|
367
|
+
if (!status.applied) {
|
|
368
|
+
debug.warn('engine', `Qwen effort "${effort}" not applied for ${modelId}: ${status.reason ?? (status.override ? `overridden by ${status.override.source}.${status.override.field}` : 'thinking disabled')}`);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
if (sdkMessage.type === 'result') endPrompt();
|
|
344
373
|
yield* converter.convert(sdkMessage);
|
|
345
374
|
}
|
|
346
375
|
} catch (error) {
|
|
347
376
|
handleStreamError(error, stderrLines.join('\n'));
|
|
348
377
|
} finally {
|
|
378
|
+
endPrompt();
|
|
349
379
|
// Retire THIS run only — another chat session of the same project may
|
|
350
380
|
// still be streaming on this instance.
|
|
351
381
|
this.runs.remove(run);
|
|
@@ -442,25 +472,23 @@ export class QwenEngine implements AIEngine {
|
|
|
442
472
|
maxSessionTurns: 1,
|
|
443
473
|
};
|
|
444
474
|
|
|
445
|
-
const
|
|
475
|
+
const promptStream = openPromptStream({
|
|
446
476
|
type: 'user',
|
|
447
477
|
uuid: crypto.randomUUID(),
|
|
448
478
|
session_id: '',
|
|
449
479
|
parent_tool_use_id: null,
|
|
450
480
|
message: { role: 'user', content: jsonPrompt },
|
|
451
|
-
};
|
|
452
|
-
const promptIterable = (async function* (): AsyncIterable<SDKUserMessage> {
|
|
453
|
-
yield sdkPrompt;
|
|
454
|
-
})();
|
|
481
|
+
}, controller.signal);
|
|
455
482
|
|
|
456
483
|
const { query } = await loadEngineSdk<typeof import('@qwen-code/sdk')>('qwen', '@qwen-code/sdk');
|
|
457
|
-
const queryInstance = query({ prompt:
|
|
484
|
+
const queryInstance = query({ prompt: promptStream.iterable, options: sdkOptions });
|
|
458
485
|
|
|
459
486
|
let resultText = '';
|
|
460
487
|
let errorMessage = '';
|
|
461
488
|
try {
|
|
462
489
|
for await (const message of queryInstance) {
|
|
463
490
|
if (message.type === 'result') {
|
|
491
|
+
promptStream.end();
|
|
464
492
|
if (message.subtype === 'success') {
|
|
465
493
|
resultText = message.result || '';
|
|
466
494
|
} else {
|
|
@@ -473,6 +501,8 @@ export class QwenEngine implements AIEngine {
|
|
|
473
501
|
throw new Error('Generation was cancelled');
|
|
474
502
|
}
|
|
475
503
|
throw error;
|
|
504
|
+
} finally {
|
|
505
|
+
promptStream.end();
|
|
476
506
|
}
|
|
477
507
|
|
|
478
508
|
if (!resultText) {
|
|
@@ -502,18 +532,19 @@ export class QwenEngine implements AIEngine {
|
|
|
502
532
|
return false;
|
|
503
533
|
}
|
|
504
534
|
|
|
505
|
-
// Push the answers into converter state FIRST so
|
|
506
|
-
//
|
|
507
|
-
//
|
|
508
|
-
//
|
|
509
|
-
//
|
|
510
|
-
// (empty). The converter intercepts that tool_result and replaces its
|
|
511
|
-
// content with the proper formatted answers we just stored.
|
|
535
|
+
// Push the answers into converter state FIRST so they are in place by
|
|
536
|
+
// the time the AUQ tool_result arrives. The CLI forwards `answers`
|
|
537
|
+
// from `updatedInput` to the tool, so the model sees the real answers;
|
|
538
|
+
// the converter only rewrites the tool_result into the cross-engine
|
|
539
|
+
// wording for the UI.
|
|
512
540
|
run.converter?.recordUserAnswer(toolUseId, answers);
|
|
513
541
|
|
|
542
|
+
// The frontend keys answers by question text; the CLI only reads
|
|
543
|
+
// question-index keys and drops the rest (see toQwenAnswers).
|
|
544
|
+
const questions = Array.isArray(pending.input['questions']) ? pending.input['questions'] as AskUserQuestion[] : [];
|
|
514
545
|
pending.resolve({
|
|
515
546
|
behavior: 'allow',
|
|
516
|
-
updatedInput: { ...pending.input, answers },
|
|
547
|
+
updatedInput: { ...pending.input, answers: toQwenAnswers(questions, answers) },
|
|
517
548
|
});
|
|
518
549
|
run.pendingAskUserQuestion = null;
|
|
519
550
|
return true;
|
|
@@ -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
|
}
|
|
@@ -239,12 +239,14 @@ Where each engine's knob lives:
|
|
|
239
239
|
|
|
240
240
|
| Engine | SDK knob | Levels |
|
|
241
241
|
|---------------|-----------------------------------------|--------------------------------------------|
|
|
242
|
-
| `claude-code` | `thinking` + `effort` on `query()` | `off, auto, low, medium, high, xhigh, max` (
|
|
243
|
-
| `codex` | `modelReasoningEffort` (thread option) |
|
|
242
|
+
| `claude-code` | `thinking` + `effort` on `query()` | per model from the static catalog, out of `off, auto, low, medium, high, xhigh, max` — no `off` where the model rejects disabled thinking, no `xhigh` before Opus 4.7, no effort tiers on Opus 4.5 (`resolveClaudeReasoning` gates the value; `off` → `thinking: { type: 'disabled' }`, `auto` → adaptive with no `effort`) |
|
|
243
|
+
| `codex` | `modelReasoningEffort` (thread option) | per model from the static catalog: `low…xhigh`, `low…max` or `low…ultra` (`resolveCodexEffort` gates the value) |
|
|
244
244
|
| `copilot` | `SessionConfig.reasoningEffort` | from `ModelInfo.supportedReasoningEfforts` (dynamic) |
|
|
245
245
|
| `pi` | agent `thinkingLevel` | from `getSupportedThinkingLevels(model)` (dynamic; `clampThinkingLevel` on apply) |
|
|
246
246
|
| `cursor` | `ModelSelection.params[]` | from the model's reasoning-ish `ModelParameterDefinition` (dynamic) |
|
|
247
|
-
| `qwen
|
|
247
|
+
| `qwen` | `effort` on `query()` | `low…xhigh` only when the `/models` entry lists `reasoning_effort` in `supported_parameters` (OpenRouter); hidden on DashScope/Fireworks |
|
|
248
|
+
| `cline` | `thinking` + `reasoningEffort` on `Agent` | per model from the catalog's `reasoningOptions` (dynamic): `off` (toggle or `none` effort), `auto`, the advertised `minimal…max` tiers, `on` for toggle-only; budget-only models get none (`resolveClineReasoning` gates the value) |
|
|
249
|
+
| `opencode` | — (none exposed) | no `reasoningControl` → selector hidden |
|
|
248
250
|
|
|
249
251
|
Cursor is the one engine whose token is **not** a bare level: it encodes the
|
|
250
252
|
model-parameter id as `"<paramId>::<value>"` so `stream.ts` can rebuild a
|
|
@@ -292,7 +294,8 @@ adapters/<name>/
|
|
|
292
294
|
├── server.ts? ← OPTIONAL subprocess + client lifecycle (opencode)
|
|
293
295
|
├── config.ts? ← OPTIONAL runtime config builder (opencode)
|
|
294
296
|
├── presets.ts? ← OPTIONAL multi-provider/region preset catalog (qwen, opencode)
|
|
295
|
-
|
|
297
|
+
├── session-store.ts? ← OPTIONAL on-disk session lookup for a native fork (qwen)
|
|
298
|
+
└── session-fork.ts? ← OPTIONAL on-disk session fork workaround (codex)
|
|
296
299
|
```
|
|
297
300
|
|
|
298
301
|
Naming rules — strict, even when an SDK's local jargon differs:
|