pi-web-ui 0.118.0 → 0.120.0
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/CHANGELOG.md +143 -1
- package/bin/hub-upgrade.mjs +33 -15
- package/bin/lib/atomic-file.mjs +90 -0
- package/dist/server/agent-service-daemon.js +44 -10
- package/dist/server/agent-service.js +930 -166
- package/dist/server/approval-default-rules.js +4 -4
- package/dist/server/ask-user-question-tool.js +3 -40
- package/dist/server/atomic-file.js +130 -5
- package/dist/server/background-executors.js +235 -0
- package/dist/server/bash-timeout.js +47 -0
- package/dist/server/bash-tool.js +72 -5
- package/dist/server/bg-servers.js +19 -13
- package/dist/server/browser-page-tool.js +38 -29
- package/dist/server/browser-script-tool.js +119 -0
- package/dist/server/canvas/canvas-agent-tool.js +46 -35
- package/dist/server/canvas/canvas-dispatch.js +12 -1
- package/dist/server/claim-files-tool.js +6 -7
- package/dist/server/client-state.js +457 -41
- package/dist/server/communicate-tool.js +59 -77
- package/dist/server/compact-context-tool.js +4 -13
- package/dist/server/conversation-communication.js +23 -1
- package/dist/server/conversation-read-tool.js +14 -23
- package/dist/server/conversation-rows.js +17 -0
- package/dist/server/conversation-tool-names.js +2 -2
- package/dist/server/conversation-tool.js +23 -15
- package/dist/server/conversation-touches.js +1 -1
- package/dist/server/delegate-mode.js +0 -1
- package/dist/server/delegate-task.js +18 -39
- package/dist/server/device-center/approval-summary.js +0 -1
- package/dist/server/device-center/bot-execution.js +0 -1
- package/dist/server/device-center/group-router-runtime.js +2 -0
- package/dist/server/device-center/hub-upgrade.js +5 -10
- package/dist/server/device-center/task-progress.js +2 -2
- package/dist/server/dispatch-domain-handlers.js +97 -24
- package/dist/server/dispatch-plugin-handlers.js +10 -0
- package/dist/server/dsh/dsh-agent-service.js +21 -19
- package/dist/server/durable/durable-agent-service.js +1 -1
- package/dist/server/edit-tool.js +293 -0
- package/dist/server/engine-catalog.js +8 -2
- package/dist/server/engine-cli.js +29 -7
- package/dist/server/engine-probe.js +11 -6
- package/dist/server/eval-tool.js +5 -19
- package/dist/server/files-service.js +41 -19
- package/dist/server/fs-copy.js +93 -0
- package/dist/server/goal-review-gate.js +2 -3
- package/dist/server/index.js +92 -3
- package/dist/server/job-runner.js +345 -0
- package/dist/server/lsp-tool.js +10 -28
- package/dist/server/marker-service.js +42 -30
- package/dist/server/mcp-agent-tool.js +22 -47
- package/dist/server/model-session.js +16 -0
- package/dist/server/native-cli-session-hooks.js +3 -2
- package/dist/server/native-cli-session.js +27 -2
- package/dist/server/patch-tool.js +2 -8
- package/dist/server/phone-tool.js +167 -0
- package/dist/server/plan-mode.js +7 -4
- package/dist/server/plan-update-tool.js +5 -8
- package/dist/server/plugin-api-catalog.js +13 -1
- package/dist/server/plugin-bundled.js +35 -28
- package/dist/server/plugin-catalog.js +6 -0
- package/dist/server/plugin-delivery.js +358 -0
- package/dist/server/plugin-inbox.js +152 -0
- package/dist/server/plugin-installer.js +15 -0
- package/dist/server/plugin-ledger.js +183 -0
- package/dist/server/plugin-manifest-validate.js +19 -0
- package/dist/server/plugin-materialize.js +161 -0
- package/dist/server/plugin-paths.js +60 -0
- package/dist/server/plugin-removal.js +16 -3
- package/dist/server/plugin-schedule.js +8 -7
- package/dist/server/plugin-secrets.js +7 -3
- package/dist/server/plugin-updater.js +2 -4
- package/dist/server/plugins.js +205 -48
- package/dist/server/present-files-tool.js +7 -13
- package/dist/server/preset-fields.js +23 -12
- package/dist/server/preset-share.js +1 -1
- package/dist/server/process-utils.js +11 -0
- package/dist/server/project-scripts.js +38 -0
- package/dist/server/prompt-composer.js +40 -21
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/question-params.js +98 -0
- package/dist/server/quick-ask-settings.js +0 -1
- package/dist/server/quick-ask.js +3 -0
- package/dist/server/read-tool.js +10 -17
- package/dist/server/remote-ssh-service.js +40 -1
- package/dist/server/sandbox-runtime-gate.js +1 -1
- package/dist/server/sandbox-service.js +0 -1
- package/dist/server/sandbox-tool.js +25 -34
- package/dist/server/schedule-agent-tool.js +9 -19
- package/dist/server/scm-commitmsg.js +2 -1
- package/dist/server/serialize.js +8 -0
- package/dist/server/session-list-index.js +246 -0
- package/dist/server/session-list-scan.js +5 -0
- package/dist/server/session-parser.js +16 -0
- package/dist/server/settings-service.js +49 -19
- package/dist/server/skill-tool.js +4 -6
- package/dist/server/subagent-budget.js +68 -0
- package/dist/server/subagent-evidence.js +297 -0
- package/dist/server/subagent-helpers.js +12 -0
- package/dist/server/subagent-ledger.js +401 -0
- package/dist/server/subagent-notify.js +6 -2
- package/dist/server/subagent-security-gate.js +2 -3
- package/dist/server/subagent-settle.js +71 -0
- package/dist/server/subagents.js +566 -211
- package/dist/server/tabs.js +8 -1
- package/dist/server/terminals.js +34 -28
- package/dist/server/tool-approval.js +15 -1
- package/dist/server/tool-guards.js +0 -91
- package/dist/server/tool-manager.js +127 -47
- package/dist/server/tool-overrides.js +8 -1
- package/dist/server/tool-prompt-overrides.js +3 -6
- package/dist/server/tool-prompts.js +60 -17
- package/dist/server/universal/driver-base.js +2 -0
- package/dist/server/universal/drivers/claude-code.js +210 -211
- package/dist/server/universal/drivers/codex.js +29 -24
- package/dist/server/universal/engine-mcp.js +107 -0
- package/dist/server/universal/universal-attachments.js +77 -1
- package/dist/server/universal/universal-service.js +1 -1
- package/dist/server/universal/universal-session.js +106 -69
- package/dist/server/vision-bridge.js +2 -0
- package/dist/server/workspace-handle.js +119 -17
- package/dist/server/workspace-queue.js +37 -0
- package/dist/server/worktree-tool.js +13 -20
- package/docs/README.md +40 -36
- package/docs/architecture-plugins.md +64 -35
- package/docs/device-center.md +1 -1
- package/package.json +16 -4
- package/plugin-sdk/index.d.ts +102 -0
- package/plugins/catalog.json +23 -51
- package/themes/bases/flow-base.css +8 -17
- package/themes/dark-teal.css +0 -3
- package/web/dist/.build-assets.json +1 -1
- package/web/dist/assets/BgTasksModal-BdOJ19Hj.js +1 -0
- package/web/dist/assets/BgTasksModal-SAH2XCkY.js +1 -0
- package/web/dist/assets/{CanvasStudio-CAWcs9tm.js → CanvasStudio-BB_Iq7pl.js} +3 -3
- package/web/dist/assets/CanvasStudio-DU6O3N4u.js +1579 -0
- package/web/dist/assets/DeviceCenter-By1zVTSY.js +3 -0
- package/web/dist/assets/DeviceCenter-Cnm0Tjrx.js +3 -0
- package/web/dist/assets/DeviceExecutionSettings-qJzbI0Cf.js +1 -0
- package/web/dist/assets/{DeviceGroups-C_fZMNeK.js → DeviceGroups-DPrQxW6B.js} +1 -1
- package/web/dist/assets/DeviceGroups-DoucyUjI.js +1 -0
- package/web/dist/assets/{Dropdown-CTgVLUbp.js → Dropdown-kj_NIj6e.js} +1 -1
- package/web/dist/assets/FilePreview-Bub8Y9uq.js +2 -0
- package/web/dist/assets/FilePreview-CC76Z6an.js +2 -0
- package/web/dist/assets/GlobalSearchModal-01nkgw4X.js +1 -0
- package/web/dist/assets/GlobalSearchModal-CiT6wBmR.js +1 -0
- package/web/dist/assets/GroupConversation-1-lsPO1f.js +61 -0
- package/web/dist/assets/GroupConversation-HeiyW_O_.js +61 -0
- package/web/dist/assets/{GroupWorkItems-BIvZtr10.js → GroupWorkItems-BYJv2XFj.js} +1 -1
- package/web/dist/assets/{HintTip-Da6qc566.js → HintTip-DFhoclDw.js} +1 -1
- package/web/dist/assets/ModelConfigModal-D2Ro-jUZ.js +2 -0
- package/web/dist/assets/ModelConfigModal-DPc9R1pq.js +2 -0
- package/web/dist/assets/{NativeCliPanel-CU1rZmyu.js → NativeCliPanel-B108d697.js} +3 -3
- package/web/dist/assets/NativeCliPanel-DupvGwQM.js +5 -0
- package/web/dist/assets/{PiSetupModal-DZKY5Wiw.js → PiSetupModal-D0HitBfd.js} +1 -1
- package/web/dist/assets/ProviderOAuthControls-BLKUEDde.js +1 -0
- package/web/dist/assets/SCMPanel-DDbWrUHR.js +2 -0
- package/web/dist/assets/SCMPanel-DluNcd2-.js +2 -0
- package/web/dist/assets/SettingsModal-Cy5lRC97.css +1 -0
- package/web/dist/assets/SettingsModal-DQu18366.js +33 -0
- package/web/dist/assets/SettingsModal-Dm_haPme.js +33 -0
- package/web/dist/assets/{TermXterm-Bt5WKAxP.js → TermXterm-SYc-MUk2.js} +2 -2
- package/web/dist/assets/TerminalPanel-CgA_lhVT.js +1 -0
- package/web/dist/assets/TerminalPanel-vdSIOPjD.js +1 -0
- package/web/dist/assets/TuiOverlayModal-Cy1jYYIw.js +1 -0
- package/web/dist/assets/TuiOverlayModal-kXY_4hV8.js +1 -0
- package/web/dist/assets/app-globals-CBEscsYP.js +129 -0
- package/web/dist/assets/{canvas-client-WkhM55mR.js → canvas-client-Clsypfs6.js} +1 -1
- package/web/dist/assets/{desktop-B8NZ3KW-.js → desktop-C6D9a8HZ.js} +1 -1
- package/web/dist/assets/index-BD29OL9L.js +404 -0
- package/web/dist/assets/index-BlCxbqqr.js +404 -0
- package/web/dist/assets/index-DB55rbKC.css +1 -0
- package/web/dist/assets/plugin-host-VWBcq-LQ.js +1 -0
- package/web/dist/assets/remote-ssh-client-C2eab5Kw.js +1 -0
- package/web/dist/assets/theme-CpQk_Agp.js +1 -0
- package/web/dist/index.html +10 -10
- package/web/dist/sw.js +1 -1
- package/dist/server/edit-soft-tool.js +0 -297
- package/web/dist/assets/BgTasksModal-D-x7kA63.js +0 -1
- package/web/dist/assets/DeviceCenter-Dc0whRcu.js +0 -3
- package/web/dist/assets/DeviceExecutionSettings-BoX7-0h7.js +0 -1
- package/web/dist/assets/FilePreview-C6W0PvaK.js +0 -2
- package/web/dist/assets/GlobalSearchModal-HR9LSspC.js +0 -1
- package/web/dist/assets/GroupConversation-C81YjF2C.js +0 -61
- package/web/dist/assets/ModelConfigModal-DhSyuIuV.js +0 -2
- package/web/dist/assets/ProviderOAuthControls-CIL85nA7.js +0 -1
- package/web/dist/assets/SCMPanel-CuEgzAlO.js +0 -2
- package/web/dist/assets/SettingsModal-Cdu5h29p.js +0 -33
- package/web/dist/assets/TerminalPanel-BCIBV8se.js +0 -1
- package/web/dist/assets/TuiOverlayModal-3NDd9T97.js +0 -1
- package/web/dist/assets/app-globals-CZjFtI4F.js +0 -129
- package/web/dist/assets/index-CQc3VrWa.css +0 -1
- package/web/dist/assets/index-D_AGu4Zv.js +0 -404
- package/web/dist/assets/plugin-host-uqZGpvCs.js +0 -1
- package/web/dist/assets/remote-ssh-client-Cdf-cTUe.js +0 -1
- package/web/dist/assets/theme-DGL7hLUs.js +0 -1
|
@@ -12,26 +12,27 @@ import { TERMINAL_TOOL_NAMES } from "../tool-manager.js";
|
|
|
12
12
|
import { BgServerTracker } from "../bg-servers.js";
|
|
13
13
|
import { ModelAdminService } from "../model-admin.js";
|
|
14
14
|
import { WebUIContext } from "../webui-context.js";
|
|
15
|
-
import { ClaudeCodeDriver, probeClaudeCode } from "./drivers/claude-code.js";
|
|
15
|
+
import { CLAUDE_CODE_MODELS, ClaudeCodeDriver, normalizeClaudeModelId, probeClaudeCode, } from "./drivers/claude-code.js";
|
|
16
16
|
import { CodexDriver, probeCodex } from "./drivers/codex.js";
|
|
17
17
|
import { normalizeUiLayout, settingsPresetToUi } from "../client-state.js";
|
|
18
18
|
import { messageTextWithQuotes } from "../text-quote.js";
|
|
19
19
|
import { readModelsJson, getModelThinkingLevelFromSettings, saveModelThinkingLevelToSettings, } from "../model-resolver.js";
|
|
20
20
|
import { DEFAULT_UNIVERSAL_CAPABILITIES } from "../engine-capabilities.js";
|
|
21
21
|
import { unsupportedToolInfo } from "../tool-info.js";
|
|
22
|
+
import { conversationRowKind } from "../conversation-rows.js";
|
|
22
23
|
import { SandboxManager } from "../sandbox-service.js";
|
|
23
24
|
import { assertEngineWorkspaceSupported } from "../sandbox-engines.js";
|
|
24
25
|
import { getWorktreeContext, removeWorktree } from "../worktree-service.js";
|
|
25
26
|
import { MarkerService } from "../marker-service.js";
|
|
26
27
|
import { SlashCommandsService, parseSlash } from "../slash-commands.js";
|
|
27
28
|
import { discoverDiskSkills, readSkillInstruction } from "../skill-discovery.js";
|
|
28
|
-
import { scanAtMentions, createAttachmentUiMessages, formatPromptWithSkills } from "./universal-attachments.js";
|
|
29
|
+
import { scanAtMentions, createAttachmentUiMessages, formatPromptWithSkills, materializeUploads, } from "./universal-attachments.js";
|
|
29
30
|
import { scmCommitContext } from "../scm.js";
|
|
30
31
|
import { buildCommitMsgInput, sanitizeCommitMessage } from "../scm-commitmsg.js";
|
|
31
32
|
import { getAppVersion } from "../pkg-info.js";
|
|
32
33
|
import { createQueuedEntry, removeQueuedEntry, toQueuedPromptItems } from "../queue-utils.js";
|
|
33
34
|
import { SubagentTemplatesStore, DEFAULT_TEMPLATES, pickTemplatePrompt, } from "../subagent-templates.js";
|
|
34
|
-
import { subagentTitle, isSubagentTerminal, computeWaitCapMs, makeSubagentTools, } from "../subagents.js";
|
|
35
|
+
import { subagentTitle, isSubagentTerminal, computeWaitCapMs, makeSubagentTools, CONVERSATION_TOOL_NAME, } from "../subagents.js";
|
|
35
36
|
import { recordSubagentHandoff, formatSubagentHandoffMessage, } from "../subagent-handoff.js";
|
|
36
37
|
import { pick } from "../i18n.js";
|
|
37
38
|
import { fetchRemoteSkillMarket, fetchRemoteSkillContent, fetchRemoteMcpMarket } from "../market-service.js";
|
|
@@ -96,7 +97,7 @@ export class UniversalSession {
|
|
|
96
97
|
sessionDrafts = new Map();
|
|
97
98
|
followUpQueue = [];
|
|
98
99
|
engine;
|
|
99
|
-
currentModel = "
|
|
100
|
+
currentModel = "default";
|
|
100
101
|
thinkingLevel = "medium";
|
|
101
102
|
lang = "zh";
|
|
102
103
|
modelsMap = new Map();
|
|
@@ -139,7 +140,11 @@ export class UniversalSession {
|
|
|
139
140
|
return this.subagentToSnapshot(conv);
|
|
140
141
|
},
|
|
141
142
|
listSubagents: (scope) => this.listSubagents(scope),
|
|
142
|
-
steerSubagent: (convId, message) =>
|
|
143
|
+
steerSubagent: async (convId, message) => {
|
|
144
|
+
await this.steerSubagent(convId, message);
|
|
145
|
+
return { state: "queued" };
|
|
146
|
+
},
|
|
147
|
+
waitForSubagentSettle: (ids, opts) => this.waitForSubagentChange(ids, opts),
|
|
143
148
|
stopSubagent: (convId) => this.stopSubagent(convId),
|
|
144
149
|
markSubagentsConsumed: (_runIds) => { },
|
|
145
150
|
listTemplates: () => this.subagentTemplates
|
|
@@ -239,7 +244,7 @@ export class UniversalSession {
|
|
|
239
244
|
});
|
|
240
245
|
const markerStateStore = this.stateStore ??
|
|
241
246
|
{
|
|
242
|
-
getMarkerSettings: () => ({
|
|
247
|
+
getMarkerSettings: () => ({ disabledMarkers: [] }),
|
|
243
248
|
saveMarkerSettings: () => { },
|
|
244
249
|
};
|
|
245
250
|
this.markerSvc = new MarkerService({
|
|
@@ -268,7 +273,7 @@ export class UniversalSession {
|
|
|
268
273
|
lang: () => this.getLang(),
|
|
269
274
|
});
|
|
270
275
|
if (opts.driver.id === "claude-code") {
|
|
271
|
-
this.currentModel = "
|
|
276
|
+
this.currentModel = "default";
|
|
272
277
|
this.seedDefaultClaudeModels();
|
|
273
278
|
}
|
|
274
279
|
else if (opts.driver.id === "codex") {
|
|
@@ -286,8 +291,11 @@ export class UniversalSession {
|
|
|
286
291
|
const savedModel = opts.stateStore?.getProjectModel(opts.clientId, opts.cwd, this.engine) ??
|
|
287
292
|
opts.stateStore?.getDefaultModel(this.engine);
|
|
288
293
|
if (savedModel) {
|
|
289
|
-
|
|
294
|
+
// Retired Claude 3.x ids saved by older builds make every turn fail; fall back to the CLI default.
|
|
295
|
+
this.currentModel = opts.driver.id === "claude-code" ? normalizeClaudeModelId(savedModel) : savedModel;
|
|
290
296
|
}
|
|
297
|
+
// The driver must run the model the UI shows, not its own construction-time default.
|
|
298
|
+
void Promise.resolve(this.driver.setModel?.(this.currentModel)).catch(() => { });
|
|
291
299
|
const rememberedThinking = getModelThinkingLevelFromSettings(this.currentModel, this.agentDir);
|
|
292
300
|
if (rememberedThinking) {
|
|
293
301
|
this.thinkingLevel = rememberedThinking;
|
|
@@ -338,7 +346,7 @@ export class UniversalSession {
|
|
|
338
346
|
this.store.saveConversation(this.cwd, initialConv);
|
|
339
347
|
}
|
|
340
348
|
if (typeof this.stateStore?.remember === "function" && this.cwd) {
|
|
341
|
-
this.stateStore.remember(this.clientId, this.cwd);
|
|
349
|
+
this.stateStore.remember(this.clientId, this.cwd, { promote: false });
|
|
342
350
|
}
|
|
343
351
|
if (this.driver instanceof CodexDriver) {
|
|
344
352
|
void probeCodex()
|
|
@@ -357,13 +365,7 @@ export class UniversalSession {
|
|
|
357
365
|
}
|
|
358
366
|
}
|
|
359
367
|
seedDefaultClaudeModels() {
|
|
360
|
-
const
|
|
361
|
-
{ id: "claude-3-7-sonnet-20250219", name: "Claude 3.7 Sonnet" },
|
|
362
|
-
{ id: "claude-3-5-sonnet-20241022", name: "Claude 3.5 Sonnet" },
|
|
363
|
-
{ id: "claude-3-5-haiku-20241022", name: "Claude 3.5 Haiku" },
|
|
364
|
-
{ id: "claude-3-opus-20240229", name: "Claude 3 Opus" },
|
|
365
|
-
];
|
|
366
|
-
for (const d of defaults) {
|
|
368
|
+
for (const d of CLAUDE_CODE_MODELS) {
|
|
367
369
|
const canonicalId = `${this.driver.id}/${d.id}`;
|
|
368
370
|
const entry = { id: d.id, name: d.name, provider: this.driver.id, vision: true };
|
|
369
371
|
this.modelsMap.set(canonicalId, entry);
|
|
@@ -400,11 +402,7 @@ export class UniversalSession {
|
|
|
400
402
|
}
|
|
401
403
|
return {
|
|
402
404
|
id: this.currentModel,
|
|
403
|
-
name: this.currentModel === "
|
|
404
|
-
? "Claude 3.7 Sonnet"
|
|
405
|
-
: this.currentModel === "deepseek-v4-flash"
|
|
406
|
-
? "DeepSeek V4 Flash"
|
|
407
|
-
: this.currentModel,
|
|
405
|
+
name: this.currentModel === "deepseek-v4-flash" ? "DeepSeek V4 Flash" : this.currentModel,
|
|
408
406
|
provider: this.driver.id === "dsh" ? "deepseek" : this.driver.id,
|
|
409
407
|
vision: true,
|
|
410
408
|
};
|
|
@@ -628,14 +626,21 @@ export class UniversalSession {
|
|
|
628
626
|
return this.prompt(skillPrompt, attachments, _queue, targetConv, rebuiltContext);
|
|
629
627
|
}
|
|
630
628
|
}
|
|
631
|
-
|
|
632
|
-
if (
|
|
633
|
-
|
|
629
|
+
// Native CLI commands (e.g. Claude Code's /compact, /init, skills) go to the engine verbatim.
|
|
630
|
+
if (!this.driver.handlesNativeSlashCommand?.(slash.name)) {
|
|
631
|
+
const handled = await this.slash.exec(slash.name, slash.args);
|
|
632
|
+
if (handled)
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
634
635
|
}
|
|
635
636
|
if (this.switchingProject || this.disposed || this.abortPromise || generation !== this.projectGeneration)
|
|
636
637
|
return;
|
|
637
638
|
if (this.activeConv !== targetConv)
|
|
638
639
|
return;
|
|
640
|
+
// 真的发消息才算「项目最近对话」:左栏项目排序只认这个,浏览/切换不刷新
|
|
641
|
+
if (typeof this.stateStore?.remember === "function")
|
|
642
|
+
this.stateStore.remember(this.clientId, this.cwd);
|
|
643
|
+
void this.pushProjects().catch(() => { });
|
|
639
644
|
this.isStreaming = true;
|
|
640
645
|
const conv = targetConv;
|
|
641
646
|
startTurnTiming(conv);
|
|
@@ -649,7 +654,11 @@ export class UniversalSession {
|
|
|
649
654
|
if (!isCurrent())
|
|
650
655
|
return;
|
|
651
656
|
const scanResult = scanAtMentions(text, turn.cwd, availableSkills, attachments ?? []);
|
|
652
|
-
const effectiveAttachments = [...(attachments ?? []), ...scanResult.detectedAttachments]
|
|
657
|
+
const effectiveAttachments = materializeUploads([...(attachments ?? []), ...scanResult.detectedAttachments], {
|
|
658
|
+
clientId: this.clientId,
|
|
659
|
+
dataDir: this.dataDir,
|
|
660
|
+
maxInlineImageBytes: this.driver.maxInlineImageBytes,
|
|
661
|
+
});
|
|
653
662
|
const finalPrompt = formatPromptWithSkills(text, scanResult.detectedSkills);
|
|
654
663
|
const hasNoUserMessages = !conv.messages.some((m) => m.role === "user");
|
|
655
664
|
if (UniversalSession.isDefaultTitle(conv.title) && hasNoUserMessages && text.trim()) {
|
|
@@ -876,6 +885,8 @@ export class UniversalSession {
|
|
|
876
885
|
conv.driverSessionId = activeSid;
|
|
877
886
|
}
|
|
878
887
|
}
|
|
888
|
+
if (this.driver.consumeSlashCommandsChanged?.())
|
|
889
|
+
void this.pushSlashCommands();
|
|
879
890
|
finishTurnTiming(conv);
|
|
880
891
|
this.isStreaming = false;
|
|
881
892
|
this.streamingThinking = "";
|
|
@@ -1245,25 +1256,34 @@ export class UniversalSession {
|
|
|
1245
1256
|
}
|
|
1246
1257
|
}
|
|
1247
1258
|
const allList = Array.from(convMap.values()).sort((a, b) => b.updatedAt - a.updatedAt);
|
|
1259
|
+
// ConversationSummary 是单源协议;会话身份(sessionId=会话 id)必须带上,
|
|
1260
|
+
// 否则客户端无法把「运行中对话」和「历史会话」认成同一条,左栏会重复一遍。
|
|
1261
|
+
// rowKind:universal 底座的会话全部已落盘(sessions 里都有一条),所以只有需要自占一行的
|
|
1262
|
+
// (流式 / 子代理 / 固定 / 临时 / 有子代理的父节点)标 open,其余交给历史行代表。
|
|
1263
|
+
const subagentParentIds = new Set(allList.map((c) => c.subagentParentId).filter((id) => Boolean(id)));
|
|
1248
1264
|
const convs = allList.map((c) => ({
|
|
1249
1265
|
id: c.id,
|
|
1250
1266
|
title: c.title,
|
|
1251
|
-
updatedAt: c.updatedAt,
|
|
1252
|
-
createdAt: c.createdAt,
|
|
1253
|
-
pinned: Boolean(c.pinned),
|
|
1254
|
-
sessionPath: c.id,
|
|
1255
|
-
active: c.id === this.activeConvId,
|
|
1256
1267
|
cwd: this.cwd,
|
|
1257
1268
|
messageCount: c.messages.length,
|
|
1258
1269
|
isStreaming: Boolean(c.id === this.activeConvId ? this.isStreaming : c.subagentStreaming),
|
|
1259
1270
|
isSubagent: Boolean(c.isSubagent),
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1271
|
+
pinned: Boolean(c.pinned),
|
|
1272
|
+
sessionId: c.id,
|
|
1273
|
+
modified: c.updatedAt,
|
|
1274
|
+
rowKind: conversationRowKind({
|
|
1275
|
+
isStreaming: c.id === this.activeConvId ? this.isStreaming : c.subagentStreaming,
|
|
1276
|
+
isSubagent: c.isSubagent,
|
|
1277
|
+
parentId: c.subagentParentId,
|
|
1278
|
+
pinned: c.pinned,
|
|
1279
|
+
isEphemeral: c.isEphemeral,
|
|
1280
|
+
hasHistoryRow: true,
|
|
1281
|
+
forceOpen: subagentParentIds.has(c.id),
|
|
1282
|
+
}),
|
|
1283
|
+
...(c.isEphemeral ? { isEphemeral: true } : {}),
|
|
1284
|
+
...(c.subagentParentId ? { parentId: c.subagentParentId } : {}),
|
|
1285
|
+
...(c.subagentType ? { agentPreset: c.subagentType } : {}),
|
|
1286
|
+
...(c.subagentError ? { error: c.subagentError } : {}),
|
|
1267
1287
|
}));
|
|
1268
1288
|
this.send({ type: "conversations", conversations: convs, activeId: this.activeConvId });
|
|
1269
1289
|
const sessionSummaries = allList
|
|
@@ -1278,6 +1298,8 @@ export class UniversalSession {
|
|
|
1278
1298
|
return {
|
|
1279
1299
|
path: c.id,
|
|
1280
1300
|
sessionId: c.id,
|
|
1301
|
+
// Ids carry no project slug; without cwd the left panel attaches them to every project.
|
|
1302
|
+
cwd: this.cwd,
|
|
1281
1303
|
name: c.title,
|
|
1282
1304
|
displayName,
|
|
1283
1305
|
firstMessage: firstMsg,
|
|
@@ -1286,7 +1308,7 @@ export class UniversalSession {
|
|
|
1286
1308
|
pinned: Boolean(c.pinned),
|
|
1287
1309
|
};
|
|
1288
1310
|
});
|
|
1289
|
-
this.send({ type: "sessions", sessions: sessionSummaries });
|
|
1311
|
+
this.send({ type: "sessions", sessions: sessionSummaries, cwd: this.cwd });
|
|
1290
1312
|
}
|
|
1291
1313
|
resolveSessionDisplayName(conv, firstMsg) {
|
|
1292
1314
|
if (conv.title && !UniversalSession.isDefaultTitle(conv.title)) {
|
|
@@ -1383,8 +1405,8 @@ export class UniversalSession {
|
|
|
1383
1405
|
async listFiles(path) {
|
|
1384
1406
|
await this.files.listFiles(path);
|
|
1385
1407
|
}
|
|
1386
|
-
async searchFiles(query, reqId) {
|
|
1387
|
-
await this.files.searchFiles(query, reqId);
|
|
1408
|
+
async searchFiles(query, reqId, scope) {
|
|
1409
|
+
await this.files.searchFiles(query, reqId, scope);
|
|
1388
1410
|
}
|
|
1389
1411
|
async readFile(path) {
|
|
1390
1412
|
await this.files.readFile(path);
|
|
@@ -1486,6 +1508,8 @@ export class UniversalSession {
|
|
|
1486
1508
|
}
|
|
1487
1509
|
}
|
|
1488
1510
|
async setModel(modelId) {
|
|
1511
|
+
if (this.driver.id === "claude-code")
|
|
1512
|
+
modelId = normalizeClaudeModelId(modelId);
|
|
1489
1513
|
this.currentModel = modelId;
|
|
1490
1514
|
if (this.stateStore) {
|
|
1491
1515
|
this.stateStore.saveProjectModel(this.clientId, this.cwd, modelId, this.engine);
|
|
@@ -1568,7 +1592,7 @@ export class UniversalSession {
|
|
|
1568
1592
|
await this.refreshSessions();
|
|
1569
1593
|
await this.refreshWorktreeInfo();
|
|
1570
1594
|
if (typeof this.stateStore?.remember === "function") {
|
|
1571
|
-
this.stateStore.remember(this.clientId, path);
|
|
1595
|
+
this.stateStore.remember(this.clientId, path, { promote: false });
|
|
1572
1596
|
}
|
|
1573
1597
|
void this.pushProjects();
|
|
1574
1598
|
const savedModel = this.stateStore?.getProjectModel(this.clientId, path, this.engine) ??
|
|
@@ -1610,9 +1634,9 @@ export class UniversalSession {
|
|
|
1610
1634
|
return { output: text, details: res.details };
|
|
1611
1635
|
}
|
|
1612
1636
|
getToolInfo(name) {
|
|
1613
|
-
if (name ===
|
|
1637
|
+
if (name === CONVERSATION_TOOL_NAME) {
|
|
1614
1638
|
const tools = makeSubagentTools(this.subagentHost);
|
|
1615
|
-
const target = tools.find((t) => t.name ===
|
|
1639
|
+
const target = tools.find((t) => t.name === name) ?? tools[0];
|
|
1616
1640
|
if (target) {
|
|
1617
1641
|
this.send({
|
|
1618
1642
|
type: "tool_info",
|
|
@@ -1646,9 +1670,9 @@ export class UniversalSession {
|
|
|
1646
1670
|
}
|
|
1647
1671
|
getToolPrompt(name) {
|
|
1648
1672
|
let targetTool;
|
|
1649
|
-
if (name ===
|
|
1673
|
+
if (name === CONVERSATION_TOOL_NAME) {
|
|
1650
1674
|
const tools = makeSubagentTools(this.subagentHost);
|
|
1651
|
-
targetTool = tools.find((t) => t.name ===
|
|
1675
|
+
targetTool = tools.find((t) => t.name === name) ?? tools[0];
|
|
1652
1676
|
}
|
|
1653
1677
|
else if (TERMINAL_TOOL_NAMES.includes(name)) {
|
|
1654
1678
|
const tools = this.getTerminalTools();
|
|
@@ -1874,30 +1898,13 @@ export class UniversalSession {
|
|
|
1874
1898
|
return out;
|
|
1875
1899
|
}
|
|
1876
1900
|
async compactActiveConversation(instructions) {
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1901
|
+
// Compaction must happen inside the engine's own context; trimming UI messages would only hide
|
|
1902
|
+
// history while the CLI session keeps the full context.
|
|
1903
|
+
if (this.driver.handlesNativeSlashCommand?.("compact")) {
|
|
1904
|
+
await this.prompt(`/compact ${instructions ?? ""}`.trim());
|
|
1880
1905
|
return;
|
|
1881
1906
|
}
|
|
1882
|
-
|
|
1883
|
-
const recent = conv.messages.slice(-4);
|
|
1884
|
-
const summaryMsg = {
|
|
1885
|
-
id: `compaction-${Date.now()}`,
|
|
1886
|
-
role: "compactionSummary",
|
|
1887
|
-
content: [
|
|
1888
|
-
{
|
|
1889
|
-
type: "text",
|
|
1890
|
-
text: instructions ? `上下文已根据说明压缩: ${instructions}` : "历史消息已由通用底座自动压缩归纳",
|
|
1891
|
-
},
|
|
1892
|
-
],
|
|
1893
|
-
timestamp: Date.now(),
|
|
1894
|
-
};
|
|
1895
|
-
conv.messages = [...first, summaryMsg, ...recent];
|
|
1896
|
-
if (!conv.isEphemeral) {
|
|
1897
|
-
this.store.saveConversation(this.cwd, conv);
|
|
1898
|
-
}
|
|
1899
|
-
this.flushSnapshot();
|
|
1900
|
-
this.emitNotice("info", "已压缩当前会话上下文", "Current conversation context compacted");
|
|
1907
|
+
this.emitNotice("info", `${this.driver.name} 引擎不支持手动压缩,上下文由 CLI 自动管理`, `${this.driver.name} does not support manual compaction; the CLI manages its context automatically`);
|
|
1901
1908
|
}
|
|
1902
1909
|
async reloadSessionResources() {
|
|
1903
1910
|
await this.collectUniversalSkills();
|
|
@@ -1924,6 +1931,7 @@ export class UniversalSession {
|
|
|
1924
1931
|
disabledSkills: s?.disabledSkills ?? [],
|
|
1925
1932
|
disabledExtensions: s?.disabledExtensions ?? [],
|
|
1926
1933
|
disabledAgentTools: [],
|
|
1934
|
+
toolOnDemandTools: [],
|
|
1927
1935
|
disabledPluginTools: [],
|
|
1928
1936
|
nativeCliInheritModel: { ...s?.nativeCliInheritModel },
|
|
1929
1937
|
terminalToolsEnabled: s?.terminalToolsEnabled ?? true,
|
|
@@ -1936,7 +1944,6 @@ export class UniversalSession {
|
|
|
1936
1944
|
toolLazyLoading: false,
|
|
1937
1945
|
codemodeMode: "on",
|
|
1938
1946
|
codemodeInlineBudget: 3000,
|
|
1939
|
-
editSoftEnabled: false,
|
|
1940
1947
|
retryMaxAttempts: 0,
|
|
1941
1948
|
softCapTokens: 0,
|
|
1942
1949
|
softCapByModel: {},
|
|
@@ -1994,7 +2001,6 @@ export class UniversalSession {
|
|
|
1994
2001
|
reviewSkills: [],
|
|
1995
2002
|
extensions: [],
|
|
1996
2003
|
presets: (this.stateStore?.getPresets(this.clientId) ?? []).map(settingsPresetToUi),
|
|
1997
|
-
markersEnabled: this.markerSvc.current.markersEnabled,
|
|
1998
2004
|
disabledMarkers: [...this.markerSvc.current.disabledMarkers],
|
|
1999
2005
|
markers: this.markerSvc.listForUi(),
|
|
2000
2006
|
subagentTemplates: this.subagentTemplates.list(),
|
|
@@ -2720,6 +2726,37 @@ export class UniversalSession {
|
|
|
2720
2726
|
catch { }
|
|
2721
2727
|
}
|
|
2722
2728
|
}
|
|
2729
|
+
/**
|
|
2730
|
+
* 通用引擎没有逐运行的结算边沿,只能借用「子代理状态变化」监听:
|
|
2731
|
+
* 唤醒后由等待循环自己重新判定,语义与 pi 引擎一致。
|
|
2732
|
+
*/
|
|
2733
|
+
waitForSubagentChange(ids, opts) {
|
|
2734
|
+
void ids;
|
|
2735
|
+
if (opts.signal?.aborted)
|
|
2736
|
+
return Promise.resolve("aborted");
|
|
2737
|
+
if (opts.timeoutMs <= 0)
|
|
2738
|
+
return Promise.resolve("timeout");
|
|
2739
|
+
return new Promise((resolve) => {
|
|
2740
|
+
let done = false;
|
|
2741
|
+
let timer;
|
|
2742
|
+
const finish = (reason) => {
|
|
2743
|
+
if (done)
|
|
2744
|
+
return;
|
|
2745
|
+
done = true;
|
|
2746
|
+
if (timer)
|
|
2747
|
+
clearTimeout(timer);
|
|
2748
|
+
this.subagentWaitListeners.delete(onChange);
|
|
2749
|
+
opts.signal?.removeEventListener("abort", onAbort);
|
|
2750
|
+
resolve(reason);
|
|
2751
|
+
};
|
|
2752
|
+
const onChange = () => finish("changed");
|
|
2753
|
+
const onAbort = () => finish("aborted");
|
|
2754
|
+
timer = setTimeout(() => finish("timeout"), Math.max(1, Math.floor(opts.timeoutMs)));
|
|
2755
|
+
timer.unref?.();
|
|
2756
|
+
this.subagentWaitListeners.add(onChange);
|
|
2757
|
+
opts.signal?.addEventListener("abort", onAbort, { once: true });
|
|
2758
|
+
});
|
|
2759
|
+
}
|
|
2723
2760
|
listSubagents(scope = "all") {
|
|
2724
2761
|
const snaps = [];
|
|
2725
2762
|
for (const conv of this.conversations.values()) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getServerBlock, pick } from "./i18n.js";
|
|
2
|
+
import { modelSessionId } from "./model-session.js";
|
|
2
3
|
const TRANSCRIBE_TIMEOUT_MS = Number(process.env.PI_WEB_VISION_TIMEOUT_MS ?? 90_000);
|
|
3
4
|
const MAX_TRANSCRIBE_TOKENS = 4000;
|
|
4
5
|
export function findVisionModels(runtime) {
|
|
@@ -99,6 +100,7 @@ export async function transcribeImages(runtime, images, options = {}) {
|
|
|
99
100
|
const msg = await runtime.completeSimple(model, context, {
|
|
100
101
|
signal: ac.signal,
|
|
101
102
|
maxTokens: MAX_TRANSCRIBE_TOKENS,
|
|
103
|
+
sessionId: modelSessionId(),
|
|
102
104
|
});
|
|
103
105
|
if (msg.stopReason === "error" || msg.stopReason === "aborted") {
|
|
104
106
|
throw new Error(msg.errorMessage ||
|
|
@@ -33,6 +33,83 @@ export async function canonicalPath(path) {
|
|
|
33
33
|
return join(await canonicalPath(parent), relative(parent, path));
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
+
/** filter.* override 缓存:key 是「配置文件指纹」,值是要透传给 git 的 `-c` 参数。 */
|
|
37
|
+
const FILTER_OVERRIDE_CACHE = new Map();
|
|
38
|
+
/**
|
|
39
|
+
* 仓库身份查询缓存:`rev-parse --show-toplevel` / `--git-common-dir` / `--absolute-git-dir`/
|
|
40
|
+
* `--show-object-format` / `--is-inside-work-tree` 在一条集成管线里被反复问(实测 41+25+16 次/管线)。
|
|
41
|
+
* 这些值对一个「目录」是恒定的,缓存可命中 77/82。
|
|
42
|
+
*
|
|
43
|
+
* 安全性:只在能算出 config 指纹(确认在仓内)且未传 index 时启用;key 里带 **cwd**
|
|
44
|
+
* (主仓与各工作树指纹相同但 toplevel 不同,漏 cwd 会串值);仓被重建/换配置 → 指纹变 → 自然失效。
|
|
45
|
+
* 会变的查询(`HEAD`、`--verify`、`status`、`is-shallow-repository`)不在模式表里,永不走缓存。
|
|
46
|
+
*/
|
|
47
|
+
const REPO_QUERY_CACHE = new Map();
|
|
48
|
+
const REPO_QUERY_PATTERNS = [
|
|
49
|
+
["--show-toplevel"],
|
|
50
|
+
["--git-common-dir"],
|
|
51
|
+
["--path-format=absolute", "--git-common-dir"],
|
|
52
|
+
["--absolute-git-dir"],
|
|
53
|
+
["--show-object-format"],
|
|
54
|
+
["--is-inside-work-tree"],
|
|
55
|
+
];
|
|
56
|
+
function repoQueryOf(args) {
|
|
57
|
+
// args 是完整子命令(首项是 `rev-parse`),模式表里只写 flag
|
|
58
|
+
if (args[0] !== "rev-parse")
|
|
59
|
+
return undefined;
|
|
60
|
+
const rest = args.slice(1);
|
|
61
|
+
const hit = REPO_QUERY_PATTERNS.find((pattern) => pattern.length === rest.length && pattern.every((v, i) => rest[i] === v));
|
|
62
|
+
return hit?.join(" ");
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 算出决定 `filter.*`(以及仓库身份查询缓存键)的指纹:仓库配置文件 + `.git` 指针 + commondir。
|
|
66
|
+
*
|
|
67
|
+
* 只认 repo-local config(全局/system 已被 `GIT_CONFIG_GLOBAL` / `GIT_CONFIG_NOSYSTEM` 隔离掉)。
|
|
68
|
+
* 任何一项不确定性都返回 undefined —— 调用方据此不缓存、继续每次探测(宁慢不弱化安全)。
|
|
69
|
+
* 特别地:配置里只要出现 `[include]` / `[includeIf]`,外部文件指纹不可靠,直接不缓存。
|
|
70
|
+
*/
|
|
71
|
+
async function filterConfigFingerprint(cwd) {
|
|
72
|
+
let dir = resolve(cwd);
|
|
73
|
+
for (;;) {
|
|
74
|
+
const dotGit = join(dir, ".git");
|
|
75
|
+
const placed = await lstat(dotGit).catch(() => undefined);
|
|
76
|
+
if (placed) {
|
|
77
|
+
let gitDir = dotGit;
|
|
78
|
+
const parts = [];
|
|
79
|
+
if (placed.isFile()) {
|
|
80
|
+
const pointer = await readFile(dotGit, "utf8").catch(() => undefined);
|
|
81
|
+
const match = pointer ? /^gitdir:\s*(.+)$/m.exec(pointer) : null;
|
|
82
|
+
if (!match || pointer === undefined)
|
|
83
|
+
return undefined;
|
|
84
|
+
gitDir = resolve(dir, match[1].trim());
|
|
85
|
+
// 指针内容必须进指纹:把工作树 .git 换成指向别处的攻击会改这里(实测回归案例)。
|
|
86
|
+
parts.push(`pointer:${pointer.trim()}`);
|
|
87
|
+
}
|
|
88
|
+
else if (!placed.isDirectory())
|
|
89
|
+
return undefined;
|
|
90
|
+
const commonPointer = await readFile(join(gitDir, "commondir"), "utf8").catch(() => undefined);
|
|
91
|
+
const commonDir = commonPointer ? resolve(gitDir, commonPointer.trim()) : gitDir;
|
|
92
|
+
if (commonPointer !== undefined)
|
|
93
|
+
parts.push(`commondir:${commonPointer.trim()}`);
|
|
94
|
+
for (const configPath of [join(commonDir, "config"), join(gitDir, "config.worktree")]) {
|
|
95
|
+
const stat = await lstat(configPath).catch(() => undefined);
|
|
96
|
+
if (!stat)
|
|
97
|
+
continue;
|
|
98
|
+
const text = await readFile(configPath, "utf8").catch(() => undefined);
|
|
99
|
+
if (text === undefined)
|
|
100
|
+
return undefined;
|
|
101
|
+
if (/(?:^|\n)\s*\[include/i.test(text))
|
|
102
|
+
return undefined;
|
|
103
|
+
parts.push(`${configPath}:${stat.mtimeMs}:${stat.size}`);
|
|
104
|
+
}
|
|
105
|
+
return parts.length ? parts.join("|") : undefined;
|
|
106
|
+
}
|
|
107
|
+
const parent = resolve(dir, "..");
|
|
108
|
+
if (parent === dir)
|
|
109
|
+
return undefined;
|
|
110
|
+
dir = parent;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
36
113
|
export async function git(cwd, args, signal, index, input) {
|
|
37
114
|
checkSignal(signal);
|
|
38
115
|
const env = { ...process.env };
|
|
@@ -65,26 +142,51 @@ export async function git(cwd, args, signal, index, input) {
|
|
|
65
142
|
child.stdin?.on("error", () => { });
|
|
66
143
|
child.stdin?.end(stdin);
|
|
67
144
|
});
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
145
|
+
// filter.* 中和是安全硬化:每次 git 都先探测一次再跑真命令,等于每次逻辑调用两个子进程。
|
|
146
|
+
// 实测一条集成管线(3 次 prepare/verify/confirm)要 462 次 git(11.8s),其中一半是这个探测。
|
|
147
|
+
// 改成按「配置文件指纹」缓存:指纹不变就不重复探测;任何不确定(找不到 .git、配置里有
|
|
148
|
+
// include/includeIf 引入外部文件、stat 失败)一律不缓存,退回原来的每次探测。
|
|
149
|
+
const fingerprint = await filterConfigFingerprint(cwd);
|
|
150
|
+
const repoQuery = fingerprint && !index ? repoQueryOf(args) : undefined;
|
|
151
|
+
// 必须带上 cwd:`--show-toplevel` 按目录变化(主仓与各工作树指纹相同,但 toplevel 不同)
|
|
152
|
+
const repoQueryKey = repoQuery ? [fingerprint, resolve(cwd), repoQuery].join("\u0000") : undefined;
|
|
153
|
+
if (repoQueryKey) {
|
|
154
|
+
const cached = REPO_QUERY_CACHE.get(repoQueryKey);
|
|
155
|
+
if (cached !== undefined) {
|
|
156
|
+
checkSignal(signal);
|
|
157
|
+
return cached;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
let overrides = fingerprint ? FILTER_OVERRIDE_CACHE.get(fingerprint) : undefined;
|
|
161
|
+
if (!overrides) {
|
|
162
|
+
let filters;
|
|
163
|
+
try {
|
|
164
|
+
filters = await execute(["config", "--null", "--get-regexp", "^filter\\..*\\.(clean|smudge|process)$"]);
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
checkSignal(signal);
|
|
168
|
+
if (error.code !== 1)
|
|
169
|
+
throw error;
|
|
170
|
+
filters = "";
|
|
171
|
+
}
|
|
172
|
+
const drivers = new Set(filters
|
|
173
|
+
.split("\0")
|
|
174
|
+
.filter(Boolean)
|
|
175
|
+
.map((entry) => entry.slice(0, entry.indexOf("\n")).replace(/\.(clean|smudge|process)$/, "")));
|
|
176
|
+
overrides = [...drivers].flatMap((driver) => ["clean", "smudge", "process", "required"].flatMap((setting) => [
|
|
177
|
+
"-c",
|
|
178
|
+
`${driver}.${setting}=${setting === "required" ? "false" : ""}`,
|
|
179
|
+
]));
|
|
180
|
+
if (fingerprint) {
|
|
181
|
+
if (FILTER_OVERRIDE_CACHE.size >= 64)
|
|
182
|
+
FILTER_OVERRIDE_CACHE.clear();
|
|
183
|
+
FILTER_OVERRIDE_CACHE.set(fingerprint, overrides);
|
|
184
|
+
}
|
|
71
185
|
}
|
|
72
|
-
catch (error) {
|
|
73
|
-
checkSignal(signal);
|
|
74
|
-
if (error.code !== 1)
|
|
75
|
-
throw error;
|
|
76
|
-
filters = "";
|
|
77
|
-
}
|
|
78
|
-
const drivers = new Set(filters
|
|
79
|
-
.split("\0")
|
|
80
|
-
.filter(Boolean)
|
|
81
|
-
.map((entry) => entry.slice(0, entry.indexOf("\n")).replace(/\.(clean|smudge|process)$/, "")));
|
|
82
|
-
const overrides = [...drivers].flatMap((driver) => ["clean", "smudge", "process", "required"].flatMap((setting) => [
|
|
83
|
-
"-c",
|
|
84
|
-
`${driver}.${setting}=${setting === "required" ? "false" : ""}`,
|
|
85
|
-
]));
|
|
86
186
|
const stdout = await execute(args, input, overrides);
|
|
87
187
|
checkSignal(signal);
|
|
188
|
+
if (repoQueryKey)
|
|
189
|
+
REPO_QUERY_CACHE.set(repoQueryKey, stdout);
|
|
88
190
|
return stdout;
|
|
89
191
|
}
|
|
90
192
|
export async function snapshotTree(cwd, dataDir, signal, namespace = join("canvas", "indexes"), seed = "HEAD") {
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 工作区命令队列(唯一单源)。
|
|
3
|
+
*
|
|
4
|
+
* 「工作区绑定」类命令都在改同一组可变状态:`cs.cwd`、活动对话、runtime 绑定 ——
|
|
5
|
+
* `set_cwd` / `new_chat` / `new_cli_chat` / `switch_session` / `switch_conversation` /
|
|
6
|
+
* `fork_session` / `rollback_session` / `make_dir(setAsCwd)` / 沙盒切换。
|
|
7
|
+
*
|
|
8
|
+
* 每个方法内部都是异步重活(stat 目标目录、恢复最近会话、挂载 runtime、复制沙盒),而 ws 消息是一条
|
|
9
|
+
* 一条派发的:上一条还在 await,下一条已经在跑。于是「先切项目再新建对话」会抢跑 —— `newChat()` 读到的
|
|
10
|
+
* 还是旧 cwd,新对话落进上一个项目、在左栏里像「消失」了(#872)。
|
|
11
|
+
*
|
|
12
|
+
* 这里按会话实例给这些命令一条 FIFO 链:后一条等前一条落定,命令语义不变。派发层只做
|
|
13
|
+
* 「同步认领 + 入队」,不改变 handlers 的同步返回值;队列空闲时入队只多一个微任务。
|
|
14
|
+
*
|
|
15
|
+
* 边界:`prompt` 不进这条链(它自带 targetConversationId,且是热路径);沙盒创建这类带进度界面的
|
|
16
|
+
* 长操作也按普通命令排队,只是会让后续工作区命令等到它落定。
|
|
17
|
+
*/
|
|
18
|
+
const tails = new WeakMap();
|
|
19
|
+
/**
|
|
20
|
+
* 入队执行一条工作区命令;返回本次执行结果(与 `run` 的返回值一致)。
|
|
21
|
+
* 前一条失败不会卡住后一条——各命令自己负责 emit 错误。
|
|
22
|
+
*/
|
|
23
|
+
export function runWorkspaceCommand(session, run) {
|
|
24
|
+
const prev = tails.get(session) ?? Promise.resolve();
|
|
25
|
+
const next = prev.then(run, run);
|
|
26
|
+
const tail = next.then(() => undefined, () => undefined);
|
|
27
|
+
tails.set(session, tail);
|
|
28
|
+
void tail.then(() => {
|
|
29
|
+
if (tails.get(session) === tail)
|
|
30
|
+
tails.delete(session);
|
|
31
|
+
});
|
|
32
|
+
return next;
|
|
33
|
+
}
|
|
34
|
+
/** 队列里是否还有在飞的工作区命令(诊断 / 测试用,不参与调度)。 */
|
|
35
|
+
export function workspaceCommandPending(session) {
|
|
36
|
+
return tails.has(session);
|
|
37
|
+
}
|
|
@@ -3,28 +3,21 @@ import { resolve } from "node:path";
|
|
|
3
3
|
import { pick } from "./i18n.js";
|
|
4
4
|
import { createWorktree, listWorktrees, normalizeWirePath, removeWorktree } from "./worktree-service.js";
|
|
5
5
|
export const WORKTREE_TOOL_NAME = "worktree";
|
|
6
|
+
const WORKTREE_ACTIONS = ["list", "create", "switch", "remove"];
|
|
7
|
+
/** 每 action 要哪些参数,只在 `action` 字段里交代一次;字段本身不再写说明。 */
|
|
8
|
+
export const WORKTREE_ACTION_SIGNATURE = "list | create(path,branch?,newBranch?,commit?,switchTo?) | switch(path) | remove(path,force?)";
|
|
6
9
|
const WorktreeParameters = Type.Object({
|
|
7
|
-
action: Type.
|
|
8
|
-
|
|
10
|
+
action: Type.Unsafe({
|
|
11
|
+
type: "string",
|
|
12
|
+
enum: [...WORKTREE_ACTIONS],
|
|
13
|
+
description: WORKTREE_ACTION_SIGNATURE,
|
|
9
14
|
}),
|
|
10
|
-
path: Type.Optional(Type.String(
|
|
11
|
-
|
|
12
|
-
})),
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
newBranch: Type.Optional(Type.Union([Type.Boolean(), Type.String()], {
|
|
17
|
-
description: "Create and switch to a new branch (boolean true or string branch name).",
|
|
18
|
-
})),
|
|
19
|
-
commit: Type.Optional(Type.String({
|
|
20
|
-
description: "Base commit or branch to branch off from.",
|
|
21
|
-
})),
|
|
22
|
-
switchTo: Type.Optional(Type.Boolean({
|
|
23
|
-
description: "create: true to switch the active workspace to the new worktree immediately.",
|
|
24
|
-
})),
|
|
25
|
-
force: Type.Optional(Type.Boolean({
|
|
26
|
-
description: "remove: true to force removal even if dirty or containing unmerged changes.",
|
|
27
|
-
})),
|
|
15
|
+
path: Type.Optional(Type.String()),
|
|
16
|
+
branch: Type.Optional(Type.String()),
|
|
17
|
+
newBranch: Type.Optional(Type.Unsafe({ type: ["boolean", "string"] })),
|
|
18
|
+
commit: Type.Optional(Type.String()),
|
|
19
|
+
switchTo: Type.Optional(Type.Boolean()),
|
|
20
|
+
force: Type.Optional(Type.Boolean()),
|
|
28
21
|
});
|
|
29
22
|
export function makeWorktreeTool(host, getLang) {
|
|
30
23
|
return {
|