pi-web-ui 0.105.1 → 0.107.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 +84 -2
- package/README.md +193 -797
- package/README.zh-CN.md +186 -625
- package/README.zh-TW.md +781 -0
- package/bin/frp-manager.mjs +1488 -0
- package/bin/pi-web-ui.mjs +27 -0
- package/deploy/nginx-subpath.conf +16 -1
- package/dist/server/agent-service-daemon.js +34 -0
- package/dist/server/agent-service.js +259 -60
- package/dist/server/claim-files-tool.js +8 -1
- package/dist/server/client-state.js +136 -30
- package/dist/server/conversation-read-tool.js +12 -4
- package/dist/server/delegate-task.js +9 -1
- package/dist/server/dispatch-domain-handlers.js +15 -0
- package/dist/server/dsh/dsh-agent-service.js +848 -246
- package/dist/server/dsh/dsh-client.js +59 -18
- package/dist/server/dsh/dsh-market-service.js +233 -0
- package/dist/server/dsh/dsh-serialize.js +11 -3
- package/dist/server/dsh/dsh-sessions.js +64 -2
- package/dist/server/dsh/preset-clones.js +12 -1
- package/dist/server/dsh/runtime/goal-rpc.mjs +183 -45
- package/dist/server/durable/durable-agent-service.js +153 -0
- package/dist/server/durable/durable-capabilities.js +11 -0
- package/dist/server/durable/durable-driver.js +481 -0
- package/dist/server/durable/durable-loader.js +38 -0
- package/dist/server/durable/durable-models.js +283 -0
- package/dist/server/durable/durable-storage.js +42 -0
- package/dist/server/durable/durable-tools.js +45 -0
- package/dist/server/durable/index.js +8 -0
- package/dist/server/engine-capabilities.js +91 -0
- package/dist/server/engine-probe.js +391 -0
- package/dist/server/global-loader.js +335 -0
- package/dist/server/goal-service.js +23 -12
- package/dist/server/i18n.js +20 -1
- package/dist/server/index.js +286 -71
- package/dist/server/locales.js +1 -0
- package/dist/server/managed.js +2 -0
- package/dist/server/marker-service.js +5 -19
- package/dist/server/markers/index.js +1 -3
- package/dist/server/mcp-agent-tool.js +10 -7
- package/dist/server/mcp-bridge.js +428 -24
- package/dist/server/model-admin.js +172 -74
- package/dist/server/model-resolver.js +309 -0
- package/dist/server/plugin-installer.js +4 -2
- package/dist/server/plugins.js +89 -12
- package/dist/server/present-files-tool.js +10 -2
- package/dist/server/preset-fields.js +14 -0
- package/dist/server/preset-share.js +2 -0
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/schedule-agent-tool.js +2 -1
- package/dist/server/scm-commitmsg.js +3 -2
- package/dist/server/sdk-origin.js +2 -2
- package/dist/server/serialize.js +1 -1
- package/dist/server/settings-service.js +10 -2
- package/dist/server/skill-discovery.js +161 -0
- package/dist/server/skill-tool.js +2 -1
- package/dist/server/slash-commands.js +154 -73
- package/dist/server/subagent-templates-hant.js +215 -0
- package/dist/server/subagent-templates.js +49 -2
- package/dist/server/subagents.js +22 -12
- package/dist/server/terminals.js +2 -2
- package/dist/server/tool-manager.js +6 -19
- package/dist/server/universal/driver-base.js +60 -0
- package/dist/server/universal/drivers/claude-code.js +463 -0
- package/dist/server/universal/drivers/dsh-driver.js +376 -0
- package/dist/server/universal/drivers/mock-driver.js +103 -0
- package/dist/server/universal/index.js +10 -0
- package/dist/server/universal/session-store.js +100 -0
- package/dist/server/universal/universal-attachments.js +175 -0
- package/dist/server/universal/universal-service.js +166 -0
- package/dist/server/universal/universal-session.js +2664 -0
- package/dist/server/universal/universal-types.js +4 -0
- package/dist/server/update-check.js +24 -9
- package/dist/server/worktree-service.js +1 -1
- package/dist/server/worktree-tool.js +9 -7
- package/package.json +3 -2
- package/plugin-sdk/index.d.ts +12 -2
- package/plugins/catalog.json +50 -5
- package/themes/dark-teal.css +20 -24
- package/themes/flow-light.css +1085 -0
- package/themes/flow.css +1094 -0
- package/themes/md-preview.css +1 -2
- package/themes/wallpaper-flow.css +1158 -0
- package/themes/wallpaper-obsidian.css +743 -0
- package/themes/zhujian-dark.css +0 -7
- package/themes/zhujian.css +0 -7
- package/themes/zhupi-dark.css +0 -7
- package/themes/zhupi.css +0 -7
- package/web/dist/assets/{TerminalPanel-Mk4laCAL.js → TerminalPanel-BnViyTlx.js} +2 -2
- package/web/dist/assets/index-cCRCYMwT.css +1 -0
- package/web/dist/assets/index-fH5vhkAE.js +690 -0
- package/web/dist/index.html +2 -2
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/index-BDLVjBeK.js +0 -690
- package/web/dist/assets/index-BQC6lADz.css +0 -1
|
@@ -19,15 +19,17 @@ import { spawn } from "node:child_process";
|
|
|
19
19
|
import { createHash, randomUUID } from "node:crypto";
|
|
20
20
|
import { createRequire } from "node:module";
|
|
21
21
|
import * as fsPromises from "node:fs/promises";
|
|
22
|
+
import { DEFAULT_PI_CAPABILITIES } from "./engine-capabilities.js";
|
|
22
23
|
import { appendFileSync, existsSync, readFileSync, readdirSync, rmSync, statSync, mkdirSync, watch, writeFileSync, } from "node:fs";
|
|
23
24
|
import { homedir } from "node:os";
|
|
24
25
|
import { basename, delimiter, dirname, join, resolve, sep } from "node:path";
|
|
25
26
|
import { fileURLToPath } from "node:url";
|
|
26
27
|
import { writeAtomicSync } from "./atomic-file.js";
|
|
27
|
-
import { createAgentSessionFromServices, createAgentSessionRuntime, createAgentSessionServices, createBashToolDefinition, createCodemodeExtension, createEditToolDefinition, createFindToolDefinition, createGrepToolDefinition, createLocalBashOperations, createLsToolDefinition, createToolSearchExtension, createWriteToolDefinition, getAgentDir, SessionManager, VERSION, estimateTokens, } from "@earendil-works/pi-coding-agent";
|
|
28
|
+
import { createAgentSessionFromServices, createAgentSessionRuntime, createAgentSessionServices, createBashToolDefinition, createCodemodeExtension, createEditToolDefinition, createFindToolDefinition, createGrepToolDefinition, createLocalBashOperations, createLsToolDefinition, createToolSearchExtension, createWriteToolDefinition, resolveModelScopeWithDiagnostics, getAgentDir, SessionManager, VERSION, estimateTokens, } from "@earendil-works/pi-coding-agent";
|
|
28
29
|
import { Type } from "typebox";
|
|
29
30
|
import { BG_CLEANUP_FALLBACK_MIN, BgServerTracker } from "./bg-servers.js";
|
|
30
31
|
import { checkAll as checkAllUpdates, collectTargets, compareVersions as compareSemver, detectPiSdkSplit, resolveNpmRegistry, sortUpdateItems, } from "./update-check.js";
|
|
32
|
+
import { collectInstalledEngineTargets } from "./engine-probe.js";
|
|
31
33
|
import { checkPluginUpdates } from "./plugin-updater.js";
|
|
32
34
|
import { getAppVersion } from "./pkg-info.js";
|
|
33
35
|
import { isBundledInUse, sdkCopies } from "./sdk-origin.js";
|
|
@@ -49,8 +51,8 @@ import { ModelAdminService } from "./model-admin.js";
|
|
|
49
51
|
import { FilesService, MACHINE_ROOT, desktopDirWire, workspacePath } from "./files-service.js";
|
|
50
52
|
import { buildRemoteWorkspacePersona, createRemoteSdkOperations, formatCwdForPrompt, getGlobalRemoteSshService, isRemoteWorkspaceUri, RemoteSshService, resolveWorkspaceSessionDir, restoreWorkspaceUriFromSessionDir, setGlobalRemoteSshService, } from "./remote-ssh-service.js";
|
|
51
53
|
import { DEFAULT_TOOL_WATCHDOG_TIMEOUT_MS, effectiveToolWatchdogMs, isExtensionDisabled, isExtensionEnabled, isInternalExtension, normalizeDisabledPluginTools, normalizePathKey, normalizeRetryMaxAttempts, normalizeSkillList, ClientStateStore, } from "./client-state.js";
|
|
52
|
-
import { pick, resolveServerLang } from "./i18n.js";
|
|
53
|
-
import { SubagentTemplatesStore, pickTemplatePrompt } from "./subagent-templates.js";
|
|
54
|
+
import { isTraditionalLocale, pick, resolveServerLang } from "./i18n.js";
|
|
55
|
+
import { SubagentTemplatesStore, localizeTemplate, pickTemplatePrompt, } from "./subagent-templates.js";
|
|
54
56
|
import { ApprovalRulesStore, extractTargetPath } from "./approval-rules.js";
|
|
55
57
|
import { ComposerDraftsStore } from "./composer-drafts.js";
|
|
56
58
|
import { SandboxManager, evaluateSandboxJail, isSameOrSubpath, withSandboxJailGate } from "./sandbox-service.js";
|
|
@@ -72,7 +74,7 @@ import { goalReviewDenial, shouldDeferPromptForReview } from "./goal-review-gate
|
|
|
72
74
|
import { readPlanModeFromSession, readPlanFromSession } from "./permission-preset.js";
|
|
73
75
|
import { readDelegateModeFromSession } from "./permission-preset.js";
|
|
74
76
|
import { applyHeadTail, makePersistentTerminalTools, makeTerminalBashTool, stripAnsi, TERMINAL_TOOLS_GUIDANCE, } from "./terminals.js";
|
|
75
|
-
import { applyAgentToolsGating, ASK_USER_QUESTION_TOOL_NAME, BROWSER_PAGE_TOOL_NAME, effectiveDisabledAgentTools, filterToolsByPreset, isAgentToolEnabled, isTerminalGuidanceOn, LAZY_CORE_TOOL_NAMES, lazyLoadingDisabledTools, LOAD_TOOLS_TOOL_NAME, localizedName,
|
|
77
|
+
import { applyAgentToolsGating, ASK_USER_QUESTION_TOOL_NAME, BROWSER_PAGE_TOOL_NAME, effectiveDisabledAgentTools, filterToolsByPreset, isAgentToolEnabled, isTerminalGuidanceOn, LAZY_CORE_TOOL_NAMES, lazyLoadingDisabledTools, LOAD_TOOLS_TOOL_NAME, localizedName, PI_AGENT_PRESETS, PI_PERMISSION_OPTIONS, PLAN_UPDATE_TOOL_NAME, PRESENT_FILES_TOOL_NAME, presetAllowsPluginTools, presetHasQuestionnaire, presetShowsSkillCatalog, } from "./tool-manager.js";
|
|
76
78
|
import { makeLoadToolsTool } from "./load-tools-tool.js";
|
|
77
79
|
import { formatCompactSignature } from "./tool-signature.js";
|
|
78
80
|
import { WebUIContext } from "./webui-context.js";
|
|
@@ -111,6 +113,7 @@ import { makeWorktreeTool, WORKTREE_TOOL_NAME } from "./worktree-tool.js";
|
|
|
111
113
|
import { getWorktreeContext, removeWorktree, normalizeWirePath } from "./worktree-service.js";
|
|
112
114
|
import { sameSessionFile } from "./scheduler-tasks.js";
|
|
113
115
|
import { buildAttachmentMessages, findTurnBaseEntryId, parseModelSpec } from "./attachments.js";
|
|
116
|
+
import { scanAtMentions } from "./universal/universal-attachments.js";
|
|
114
117
|
import { formatQuotedPrompt, formatStreamingPrompt, readTextQuote, splitQuotedPrompt } from "./text-quote.js";
|
|
115
118
|
import { buildVisionBridgePrompt, findVisionModels, transcribeImages } from "./vision-bridge.js";
|
|
116
119
|
import { generateScmCommitMessage } from "./scm-commitmsg.js";
|
|
@@ -206,13 +209,12 @@ import { withPlanModeGate, withGoalReviewGate, withDelegationGate, makeLateToolG
|
|
|
206
209
|
export { withPlanModeGate, withGoalReviewGate, withDelegationGate, makeLateToolGuard, withToolGuard, isInsideWorkspaceRoots, wrapWriteToolWithPermission, EDIT_DESCRIPTION, EDIT_GUIDELINES, wrapEditToolWithPermission, wrapEditSoftToolWithPermission, wrapBashToolWithPermission, };
|
|
207
210
|
import { normalizeSolPlanToPlanSteps, makePlanUpdateTool } from "./plan-update-tool.js";
|
|
208
211
|
export { normalizeSolPlanToPlanSteps, makePlanUpdateTool };
|
|
209
|
-
import { makeMarkersListTool } from "./markers-list-tool.js";
|
|
210
212
|
import { makeAskUserQuestionTool, shouldPopQuestion } from "./ask-user-question-tool.js";
|
|
211
213
|
import { normalizePageCallTimeoutMs, collectBrowserPageArgs, formatPageCallResult, formatBrowserPageError, makeBrowserPageTool, extractShotImage, } from "./browser-page-tool.js";
|
|
212
214
|
export { makeAskUserQuestionTool, shouldPopQuestion, normalizePageCallTimeoutMs, collectBrowserPageArgs, formatPageCallResult, formatBrowserPageError, makeBrowserPageTool, extractShotImage, };
|
|
213
215
|
import { RUN_TASK_CAP, RUN_ARGS_CAP, RUN_RESULT_CAP, getMaxOpenConversations, getMaxSubagents, SUBAGENT_PROMPT_SNAPSHOT_CAP, DEFAULT_CONV_TITLE, truncRun, previewToolResult, atomicWriteFileSync, conversationTitle, pluginToolToDefinition, contentFingerprint, extractPartialText, extractAssistantTextFromContent, firstSentence, modelKeyOf, contextWindowOf, } from "./agent-formatters.js";
|
|
214
216
|
export { workspacePath };
|
|
215
|
-
import { MAX_TRANSCRIPT_SCAN_BYTES,
|
|
217
|
+
import { MAX_TRANSCRIPT_SCAN_BYTES, sessionMatchesMetadata, collectSessionAnchors, piSessionsRoot, isInsideSessionsDir, } from "./session-search.js";
|
|
216
218
|
export { piSessionsRoot, isInsideSessionsDir };
|
|
217
219
|
import { discoverRecentProjectsFromDisk, filterForkedParentSessions, findMostRecentSessionFileFast, parseSessionInfoFast, } from "./session-parser.js";
|
|
218
220
|
import { pickAdoptableOrphan, sameCwd } from "./orphan-manager.js";
|
|
@@ -639,8 +641,89 @@ export class ClientSession {
|
|
|
639
641
|
const conv = this.convs.get(convId);
|
|
640
642
|
return conv?.session ? toSubagentSnapshot(conv) : undefined;
|
|
641
643
|
}
|
|
642
|
-
|
|
643
|
-
|
|
644
|
+
/** B20:跨会话解析 —— 本会话没有就去「当前持有方」取(过户把子代理整体搬走后,
|
|
645
|
+
* 旧 host 闭包仍指向源会话,按 id 全局查才能看到还在跑的子代理,而不是误判
|
|
646
|
+
* 「已移出/不存在」)。findSubagentOwner 按别名表把旧 id 解析成改名后的当前 id。 */
|
|
647
|
+
subagentSnapshotAnywhere(convId) {
|
|
648
|
+
if (this.convs.has(convId))
|
|
649
|
+
return this.getSubagentSnapshot(convId);
|
|
650
|
+
const found = this.findSubagentOwner?.(convId);
|
|
651
|
+
return found && found.session !== this ? found.session.getSubagentSnapshot(found.convId) : undefined;
|
|
652
|
+
}
|
|
653
|
+
/** B20:convId 当前由哪个 ClientSession 持有(本会话优先;查不到兜底本会话)。 */
|
|
654
|
+
subagentOwnerOf(convId) {
|
|
655
|
+
if (!convId)
|
|
656
|
+
return this;
|
|
657
|
+
if (this.convs.has(convId))
|
|
658
|
+
return this;
|
|
659
|
+
return this.findSubagentOwner?.(convId)?.session ?? this;
|
|
660
|
+
}
|
|
661
|
+
/** B20:解析到当前(可能被过户改名)的对话 id;查不到原样返回。 */
|
|
662
|
+
subagentCurrentId(convId) {
|
|
663
|
+
if (this.convs.has(convId))
|
|
664
|
+
return convId;
|
|
665
|
+
return this.findSubagentOwner?.(convId)?.convId ?? convId;
|
|
666
|
+
}
|
|
667
|
+
listSubagentSnapshots(scope, forSelfId) {
|
|
668
|
+
const own = listSubagentSnapshots(this.convs.values(), scope);
|
|
669
|
+
// B20:带 forSelfId 才并入会话外本族(祖先链能走到 forSelfId 的子代理,
|
|
670
|
+
// 过户搬走后 wait_all 的「无参展开」与 list 仍能看到它们);不传 = 只列本会话。
|
|
671
|
+
if (!forSelfId || !this.allSubagentSessions)
|
|
672
|
+
return own;
|
|
673
|
+
const seen = new Set(own.map((s) => s.convId));
|
|
674
|
+
const out = [...own];
|
|
675
|
+
for (const other of this.allSubagentSessions()) {
|
|
676
|
+
if (other === this)
|
|
677
|
+
continue;
|
|
678
|
+
for (const s of other.listSubagentSnapshots(scope)) {
|
|
679
|
+
if (seen.has(s.convId))
|
|
680
|
+
continue;
|
|
681
|
+
if (!this.subagentInFamilyOf(s, forSelfId))
|
|
682
|
+
continue;
|
|
683
|
+
seen.add(s.convId);
|
|
684
|
+
out.push(s);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
return out;
|
|
688
|
+
}
|
|
689
|
+
/** B20:parentId 链向上能否走到 selfId(防环,最多 64 跳)。链上每一跳都按
|
|
690
|
+
* 当前持有方 + 别名解析:过户撞 id 改名后,自省 id 与孩子们记录的 parentId
|
|
691
|
+
* 都可能还是建时旧 id(c1→c2),不比显式相等,比的是「解析后的当前 id」。 */
|
|
692
|
+
subagentInFamilyOf(s, selfId) {
|
|
693
|
+
let curId = s.parentId;
|
|
694
|
+
const seen = new Set();
|
|
695
|
+
let n = 0;
|
|
696
|
+
while (curId && n++ < 64 && !seen.has(curId)) {
|
|
697
|
+
seen.add(curId);
|
|
698
|
+
if (curId === selfId)
|
|
699
|
+
return true;
|
|
700
|
+
const found = this.findSubagentOwner?.(curId);
|
|
701
|
+
if (!found)
|
|
702
|
+
return false;
|
|
703
|
+
if (found.convId === selfId)
|
|
704
|
+
return true;
|
|
705
|
+
const snap = found.session === this
|
|
706
|
+
? this.getSubagentSnapshot(found.convId)
|
|
707
|
+
: found.session.getSubagentSnapshot(found.convId);
|
|
708
|
+
if (!snap)
|
|
709
|
+
return false;
|
|
710
|
+
curId = snap.parentId;
|
|
711
|
+
}
|
|
712
|
+
return false;
|
|
713
|
+
}
|
|
714
|
+
/** B20:subagentHost.spawnSubagent 的委托入口(在**当前**会话上执行模板校验与真正
|
|
715
|
+
* spawn)—— 过户后由 host 按 parentId 的持有方调用,保证新子代理注册进持有方
|
|
716
|
+
* 的 convs(左栏「不见/错位」、cwd 跟错项目才不再发生)。 */
|
|
717
|
+
async spawnSubagentViaHost(prompt, type, cwd, templateName, model, parentId, persist) {
|
|
718
|
+
// 模板:存在且启用时应用;传了名字但不可用 → 抛错让工具转给 AI。
|
|
719
|
+
const tpl = templateName ? this.subagentTemplates.get(templateName) : undefined;
|
|
720
|
+
if (templateName && (!tpl || !tpl.enabled)) {
|
|
721
|
+
throw new Error(pick(this.getLang(), `子代理模板不可用:${templateName}(不存在或已停用)`, `Subagent template unavailable: ${templateName} (missing or disabled)`, "agent.subagent.template.unavailable", { templateName: templateName }));
|
|
722
|
+
}
|
|
723
|
+
// B20:parentId 是建时旧 id 时先解析成当前 id(过户撞 id 改名后,新子代理
|
|
724
|
+
// 的 parentId 必须指向改名后的主对话,否则族展开/lists 都认不出它)。
|
|
725
|
+
const canonParent = parentId ? (this.findSubagentOwner?.(parentId)?.convId ?? parentId) : parentId;
|
|
726
|
+
return this.spawnSubagentConversation(prompt, type, cwd, tpl, model, canonParent, persist);
|
|
644
727
|
}
|
|
645
728
|
subagentRunOutcome(conv) {
|
|
646
729
|
return subagentRunOutcome(conv);
|
|
@@ -1257,6 +1340,13 @@ export class ClientSession {
|
|
|
1257
1340
|
if (fromRunId === toRunId) {
|
|
1258
1341
|
throw new Error("Cannot hand off to oneself");
|
|
1259
1342
|
}
|
|
1343
|
+
// B20:toRunId 可能已随过户搬去另一会话(主机 host 闭包仍指向旧会话)——
|
|
1344
|
+
// 委托给持有它的会话执行,否则「Target subagent not found」。
|
|
1345
|
+
const owner = this.subagentOwnerOf(toRunId);
|
|
1346
|
+
if (owner !== this) {
|
|
1347
|
+
await owner.handoffSubagent(fromRunId, toRunId, payload);
|
|
1348
|
+
return;
|
|
1349
|
+
}
|
|
1260
1350
|
const toConv = this.convs.get(toRunId);
|
|
1261
1351
|
if (!toConv) {
|
|
1262
1352
|
throw new Error(`Target subagent ${toRunId} not found`);
|
|
@@ -1319,41 +1409,52 @@ export class ClientSession {
|
|
|
1319
1409
|
}
|
|
1320
1410
|
subagentHost = {
|
|
1321
1411
|
spawnSubagent: (prompt, type, cwd, templateName, model, parentId, persist) => {
|
|
1322
|
-
//
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
// 模型优先级:显式 model 参数 > 模板自带模型 > 设置面板默认模型;都不给 = 跟随主对话。
|
|
1328
|
-
return this.spawnSubagentConversation(prompt, type, cwd, tpl, model, parentId, persist);
|
|
1412
|
+
// B20:过户后 parentId 的主对话可能已搬去另一个 ClientSession ——
|
|
1413
|
+
// 委托给真正持有父对话的会话 spawn(模板/上限/注册/左栏全随它),
|
|
1414
|
+
// 否则新子代理注册进旧会话、目标页左栏「不见/错位」。
|
|
1415
|
+
const owner = parentId ? this.subagentOwnerOf(parentId) : this;
|
|
1416
|
+
return owner.spawnSubagentViaHost(prompt, type, cwd, templateName, model, parentId, persist);
|
|
1329
1417
|
},
|
|
1330
|
-
getSubagent: (convId) =>
|
|
1331
|
-
|
|
1418
|
+
getSubagent: (convId) => {
|
|
1419
|
+
// B20:本会话查不到就去「当前持有方」查 —— 过户把子代理整体搬走后,
|
|
1420
|
+
// 旧 host 仍指向源会话(搬不动闭包),不跨会话解析 wait_all/get_result
|
|
1421
|
+
// 会以为子代理「已移出/不存在」而其实还在跑。
|
|
1422
|
+
if (this.convs.has(convId))
|
|
1423
|
+
return this.getSubagentSnapshot(convId);
|
|
1424
|
+
const found = this.findSubagentOwner?.(convId);
|
|
1425
|
+
return found && found.session !== this ? found.session.getSubagentSnapshot(found.convId) : undefined;
|
|
1426
|
+
},
|
|
1427
|
+
listSubagents: (scope, forSelfId) => this.listSubagentSnapshots(scope, forSelfId),
|
|
1332
1428
|
handoffSubagent: async (fromRunId, toRunId, payload) => {
|
|
1333
1429
|
await this.handoffSubagent(fromRunId, toRunId, payload);
|
|
1334
1430
|
},
|
|
1335
1431
|
steerSubagent: async (convId, message) => {
|
|
1336
|
-
const
|
|
1432
|
+
const owner = this.subagentOwnerOf(convId);
|
|
1433
|
+
const curId = owner.convs.has(convId) ? convId : this.subagentCurrentId(convId);
|
|
1434
|
+
const conv = owner.convs.get(curId);
|
|
1337
1435
|
if (!conv?.session)
|
|
1338
1436
|
return;
|
|
1339
1437
|
await conv.session.sendUserMessage(message, conv.session.isStreaming ? { deliverAs: "steer" } : undefined);
|
|
1340
1438
|
},
|
|
1341
1439
|
stopSubagent: async (convId) => {
|
|
1342
|
-
const
|
|
1440
|
+
const owner = this.subagentOwnerOf(convId);
|
|
1441
|
+
const curId = owner.convs.has(convId) ? convId : this.subagentCurrentId(convId);
|
|
1442
|
+
const conv = owner.convs.get(curId);
|
|
1343
1443
|
if (conv) {
|
|
1344
1444
|
conv.promptInFlight = false;
|
|
1345
1445
|
if (conv.session.isStreaming || !conv.session.isIdle) {
|
|
1346
|
-
await
|
|
1446
|
+
await owner.interruptRun(conv, pick(owner.getLang(), "用户停止子代理", "User stopped the subagent", "agent.subagent.stop.user"));
|
|
1347
1447
|
}
|
|
1348
1448
|
}
|
|
1349
1449
|
},
|
|
1350
1450
|
getWatchdogTimeoutMs: () => this.getBaseToolWatchdogTimeoutMs(),
|
|
1351
1451
|
// issue #91:子代理工具返回按客户端 UI 语言出中英(英文默认)。
|
|
1352
1452
|
lang: () => this.getLang(),
|
|
1353
|
-
// 只向 AI 暴露 enabled 的模板(停用的对 AI
|
|
1453
|
+
// 只向 AI 暴露 enabled 的模板(停用的对 AI 不可见)。繁中界面用繁中视图(同设置页)。
|
|
1354
1454
|
listTemplates: () => this.subagentTemplates
|
|
1355
1455
|
.list()
|
|
1356
1456
|
.filter((t) => t.enabled)
|
|
1457
|
+
.map((t) => localizeTemplate(t, this.getLocale()))
|
|
1357
1458
|
.map((t) => ({
|
|
1358
1459
|
name: t.name,
|
|
1359
1460
|
description: t.description,
|
|
@@ -1543,7 +1644,7 @@ export class ClientSession {
|
|
|
1543
1644
|
sandboxes;
|
|
1544
1645
|
/** 当前工作区关联的 Git 工作树元数据(用于顶栏横幅与 AI 工具同步)。 */
|
|
1545
1646
|
worktreeInfo = null;
|
|
1546
|
-
/** 内置标记服务(
|
|
1647
|
+
/** 内置标记服务(action/notify/conv 等,可全局/分组开关)。 */
|
|
1547
1648
|
markerSvc;
|
|
1548
1649
|
// -----------------------------------------------------------------------
|
|
1549
1650
|
// 用户提问桥(标准 pi 引擎的 ask_user_question customTool):与 DSH 引擎的
|
|
@@ -1610,7 +1711,7 @@ export class ClientSession {
|
|
|
1610
1711
|
// issue #91:标记引导/错误按客户端 UI 语言出中英(英文默认)。
|
|
1611
1712
|
lang: () => this.getLang(),
|
|
1612
1713
|
});
|
|
1613
|
-
// 标记 widget 动态渲染「当前活动会话」的
|
|
1714
|
+
// 标记 widget 动态渲染「当前活动会话」的 overlay:切换会话时只要刷新
|
|
1614
1715
|
// webUi(见 switchConversation/setCwd/newChat)就会显示对应会话的标记,
|
|
1615
1716
|
// 且与扩展 widget 合并下发、不会互相覆盖。
|
|
1616
1717
|
this.webUi.setDynamicWidget("markers", () => this.markerSvc.overlayLines(this.activeId));
|
|
@@ -1658,6 +1759,7 @@ export class ClientSession {
|
|
|
1658
1759
|
void this.pushSessions();
|
|
1659
1760
|
},
|
|
1660
1761
|
getMcpServers: () => this.listMcpServers(),
|
|
1762
|
+
getLocale: () => this.getLocale(),
|
|
1661
1763
|
}, this.subagentTemplates, this.approvalRules);
|
|
1662
1764
|
this.goalSvc = new GoalService({
|
|
1663
1765
|
clientId,
|
|
@@ -2001,8 +2103,8 @@ export class ClientSession {
|
|
|
2001
2103
|
systemPromptOverride: (base) => {
|
|
2002
2104
|
if (typeof base === "string" && base) {
|
|
2003
2105
|
this.lastBaseSystemPrompt = base;
|
|
2004
|
-
if (apply && apply.promptMode === "replace" &&
|
|
2005
|
-
return
|
|
2106
|
+
if (apply && apply.promptMode === "replace" && this.templatePrompt(apply).trim()) {
|
|
2107
|
+
return this.templatePrompt(apply);
|
|
2006
2108
|
}
|
|
2007
2109
|
}
|
|
2008
2110
|
return undefined;
|
|
@@ -2012,8 +2114,8 @@ export class ClientSession {
|
|
|
2012
2114
|
if (!apply)
|
|
2013
2115
|
this.lastSdkAppendFiles = base.slice();
|
|
2014
2116
|
const out = [...base];
|
|
2015
|
-
if (apply && apply.promptMode === "append" &&
|
|
2016
|
-
out.push(
|
|
2117
|
+
if (apply && apply.promptMode === "append" && this.templatePrompt(apply).trim()) {
|
|
2118
|
+
out.push(this.templatePrompt(apply));
|
|
2017
2119
|
}
|
|
2018
2120
|
// 主会话自定义「追加」已并入组合模板的 {{append}} 覆盖,不再在此注入。
|
|
2019
2121
|
// 计划模式:只规划不实施 —— 硬闸门(server/plan-mode.ts 拒写类/旁路
|
|
@@ -2130,7 +2232,7 @@ export class ClientSession {
|
|
|
2130
2232
|
// 把灵魂段换成模板提示词,自动段保留;SYSTEM.md 情形已在
|
|
2131
2233
|
// systemPromptOverride 整体替换,此处边界不存在会自然跳过。
|
|
2132
2234
|
if (apply) {
|
|
2133
|
-
const tplPrompt =
|
|
2235
|
+
const tplPrompt = this.templatePrompt(apply).trim();
|
|
2134
2236
|
if (apply.promptMode !== "replace" || !tplPrompt)
|
|
2135
2237
|
return undefined;
|
|
2136
2238
|
const boundary = core.indexOf("\n\nAvailable tools:");
|
|
@@ -2223,7 +2325,7 @@ export class ClientSession {
|
|
|
2223
2325
|
? !sessionManager.getEntries().some((e) => e.type === "message")
|
|
2224
2326
|
: sessionManager.buildSessionContext().messages.length === 0;
|
|
2225
2327
|
if (isBlank) {
|
|
2226
|
-
const savedModelId = this.stateStore.getProjectModel(this.clientId, effectiveCwd) ?? this.stateStore.getDefaultModel();
|
|
2328
|
+
const savedModelId = this.stateStore.getProjectModel(this.clientId, effectiveCwd, "pi") ?? this.stateStore.getDefaultModel("pi");
|
|
2227
2329
|
if (savedModelId) {
|
|
2228
2330
|
const slash = savedModelId.indexOf("/");
|
|
2229
2331
|
if (slash > 0 && slash < savedModelId.length - 1) {
|
|
@@ -2344,15 +2446,18 @@ export class ClientSession {
|
|
|
2344
2446
|
// spawn 的 parentId(子代理记到真正的派发会话名下)+ wait_all 的
|
|
2345
2447
|
// selfConvId(调用者自身永不计入等待,防 self-wait deadlock)。
|
|
2346
2448
|
...(ownerId
|
|
2347
|
-
? makeSubagentTools(withSubagentOwner(this.subagentHost, ownerId), undefined,
|
|
2449
|
+
? makeSubagentTools(withSubagentOwner(this.subagentHost, ownerId), undefined,
|
|
2450
|
+
// B20:selfId 必须调用时刻解析,不能死用建时旧 id —— 过户撞 id
|
|
2451
|
+
// 改名后 wait_all 的「排除自身/展开后代」要按 runtime 的当前归属查。
|
|
2452
|
+
() => bridgeAnchor.session
|
|
2453
|
+
? (this.findConversationHome?.(bridgeAnchor.session)?.convId ?? ownerId)
|
|
2454
|
+
: ownerId)
|
|
2348
2455
|
: makeSubagentTools(this.subagentHost)),
|
|
2349
2456
|
// 结构化派单(六段式 + 服务端校验;执行体复用子代理 spawn 通道)。
|
|
2350
2457
|
// owner 包装与上面同理:子代理记到真正的派发会话名下。
|
|
2351
2458
|
...(ownerId
|
|
2352
2459
|
? [makeDelegateTaskTool(withSubagentOwner(this.subagentHost, ownerId))]
|
|
2353
2460
|
: [makeDelegateTaskTool(this.subagentHost)]),
|
|
2354
|
-
// 内置标记只读查询工具(todo/svc 状态查询,写操作走内联标记)。
|
|
2355
|
-
makeMarkersListTool(() => this.activeId, this.markerSvc),
|
|
2356
2461
|
// 结构化任务计划更新(Plan Mode / Step State Machine)。
|
|
2357
2462
|
makePlanUpdateTool(this.planManager, () => {
|
|
2358
2463
|
const id = ownerId ?? this.activeId;
|
|
@@ -2400,8 +2505,8 @@ export class ClientSession {
|
|
|
2400
2505
|
}),
|
|
2401
2506
|
// 延迟加载入口(延迟加载模式默认开):系统提示词只给未加载工具的
|
|
2402
2507
|
// 名字 + 一行摘要,模型用本工具把要用的工具拉进本对话(schema 才随之下发)。
|
|
2403
|
-
//
|
|
2404
|
-
//
|
|
2508
|
+
// 延迟加载开启时常驻在活跃集(见 applyToolGating 的 forceActive);
|
|
2509
|
+
// 延迟加载未开启时不激活、不暴露给模型。
|
|
2405
2510
|
makeLoadToolsTool(this.loadToolsHost(ownerId), () => this.getLang()),
|
|
2406
2511
|
// 技能全文按名加载(名录在 {{skills}} 段):模型不再拼路径调 read。
|
|
2407
2512
|
// 子代理会话同样注册(owner 即真正派发的父对话,读该会话 loader)。
|
|
@@ -3567,7 +3672,7 @@ export class ClientSession {
|
|
|
3567
3672
|
this.scheduleSessionsRefresh();
|
|
3568
3673
|
this.refreshConversationTitle(conv);
|
|
3569
3674
|
// 内联标记不在此兜底扫最后一条 assistant:每条气泡结束已走 message_end
|
|
3570
|
-
//
|
|
3675
|
+
// 即时解析(含中间文本块);这里再扫会把最后一条标记重复执行。
|
|
3571
3676
|
// Manual interrupt (Stop button / abort): the last assistant message
|
|
3572
3677
|
// carries stopReason "aborted". A half-finished run should NOT be
|
|
3573
3678
|
// reviewed (it would fail and inject a revision, only to be stopped
|
|
@@ -3704,6 +3809,14 @@ export class ClientSession {
|
|
|
3704
3809
|
// 每条 assistant 气泡流式结束 → 立即解析其中的内联标记:每个气泡各自
|
|
3705
3810
|
// 生效(不再等整轮 agent_end),同一轮里先前消息的标记也不再丢。
|
|
3706
3811
|
const mm = event.message;
|
|
3812
|
+
if (!conv.turnFirstTokenSeen && mm?.role === "assistant") {
|
|
3813
|
+
conv.turnFirstTokenSeen = true;
|
|
3814
|
+
const durationMs = conv.turnStartAt ? Math.max(1, Date.now() - conv.turnStartAt) : undefined;
|
|
3815
|
+
this.emitRun(conv, {
|
|
3816
|
+
type: "turn_first_token",
|
|
3817
|
+
...(durationMs !== undefined ? { durationMs } : {}),
|
|
3818
|
+
});
|
|
3819
|
+
}
|
|
3707
3820
|
if (mm?.role === "user") {
|
|
3708
3821
|
// 用户消息定稿(无论是空闲首轮提问,还是流式期间从 steer/followUp 队列出队落盘):
|
|
3709
3822
|
// SDK 在 _emit(message_end) 返回后的同一同步 tick 内执行 sessionManager.appendMessage,
|
|
@@ -3738,6 +3851,8 @@ export class ClientSession {
|
|
|
3738
3851
|
break;
|
|
3739
3852
|
}
|
|
3740
3853
|
case "turn_start": {
|
|
3854
|
+
conv.turnFirstTokenSeen = false;
|
|
3855
|
+
conv.turnStartAt = Date.now();
|
|
3741
3856
|
this.emitRun(conv, { type: "turn_start" });
|
|
3742
3857
|
break;
|
|
3743
3858
|
}
|
|
@@ -3746,6 +3861,14 @@ export class ClientSession {
|
|
|
3746
3861
|
break;
|
|
3747
3862
|
}
|
|
3748
3863
|
case "message_update": {
|
|
3864
|
+
if (!conv.turnFirstTokenSeen) {
|
|
3865
|
+
conv.turnFirstTokenSeen = true;
|
|
3866
|
+
const durationMs = conv.turnStartAt ? Math.max(1, Date.now() - conv.turnStartAt) : undefined;
|
|
3867
|
+
this.emitRun(conv, {
|
|
3868
|
+
type: "turn_first_token",
|
|
3869
|
+
...(durationMs !== undefined ? { durationMs } : {}),
|
|
3870
|
+
});
|
|
3871
|
+
}
|
|
3749
3872
|
// Live assistant-message increment, deliberately OUTSIDE the snapshot
|
|
3750
3873
|
// channel: send() drops snapshots under backpressure (big sessions),
|
|
3751
3874
|
// but this small message must always get through or the UI freezes on
|
|
@@ -4125,6 +4248,7 @@ export class ClientSession {
|
|
|
4125
4248
|
// 这个 key 必须整个缺席(不能是显式的 undefined——前端 delta 合并是
|
|
4126
4249
|
// {...ui, ...d.state} 整批覆盖,显式 undefined 会把上次全量带回的草稿洗掉)。
|
|
4127
4250
|
...(withDraft ? { draft: this.draftForSnapshot() } : {}),
|
|
4251
|
+
engineCapabilities: DEFAULT_PI_CAPABILITIES,
|
|
4128
4252
|
tools: state.tools.map((t) => t.name),
|
|
4129
4253
|
version: ++this.version,
|
|
4130
4254
|
piConfigured: this.isPiConfigured(),
|
|
@@ -4132,6 +4256,9 @@ export class ClientSession {
|
|
|
4132
4256
|
stats,
|
|
4133
4257
|
};
|
|
4134
4258
|
}
|
|
4259
|
+
getCapabilities() {
|
|
4260
|
+
return DEFAULT_PI_CAPABILITIES;
|
|
4261
|
+
}
|
|
4135
4262
|
/** Emit one snapshot update — incremental when possible, full otherwise.
|
|
4136
4263
|
*
|
|
4137
4264
|
* Persisted messages are content-immutable with reference-stable objects
|
|
@@ -4272,6 +4399,7 @@ export class ClientSession {
|
|
|
4272
4399
|
...(conversationTitle ? { conversationTitle } : {}),
|
|
4273
4400
|
});
|
|
4274
4401
|
}
|
|
4402
|
+
this.flushSnapshot();
|
|
4275
4403
|
});
|
|
4276
4404
|
}
|
|
4277
4405
|
/** 前端回答模型提问(question_answer → 恢复 askUser 的 Promise)。id 需匹配
|
|
@@ -4293,6 +4421,7 @@ export class ClientSession {
|
|
|
4293
4421
|
this.emit({ type: "question_retracted", id });
|
|
4294
4422
|
// 同上:角标消失也要即时推送(否则要等到 run 结束别处才知道问完了)。
|
|
4295
4423
|
this.emitConversations();
|
|
4424
|
+
this.flushSnapshot();
|
|
4296
4425
|
return true;
|
|
4297
4426
|
}
|
|
4298
4427
|
/** 快照侧的待答提问(UiState.pendingQuestion):只带当前对话的问卷——切回
|
|
@@ -5042,6 +5171,12 @@ export class ClientSession {
|
|
|
5042
5171
|
* 投错。(注意不能用 runtime 对象比:SDK 会把工厂返回值包成新的 AgentSessionRuntime
|
|
5043
5172
|
* 实例,而 `runtime.session` 与本工厂的 `created.session` 是同一个对象。) */
|
|
5044
5173
|
findConversationHome = undefined;
|
|
5174
|
+
/** B20 跨会话子代理归属(attach 时由 AgentService 接线,见 findConversationHome 同款):
|
|
5175
|
+
* - findSubagentOwner:按 convId 找当前持有它的 ClientSession —— 过户把对话(含子代理
|
|
5176
|
+
* 后代)整体搬去另一会话后,旧 host 闭包仍指向源会话,subagent 工具族靠它现查持有方;
|
|
5177
|
+
* - allSubagentSessions:全部客户端会话(wait_all/list 的「本族跨会话展开」用)。 */
|
|
5178
|
+
findSubagentOwner = undefined;
|
|
5179
|
+
allSubagentSessions = undefined;
|
|
5045
5180
|
/** issue #145 跨客户端同会话感知 —— attach 时由 AgentService 接线:
|
|
5046
5181
|
* - findSessionOwner:别处是否已持有同一 session 文件(查重建第二个 writer 用);
|
|
5047
5182
|
* - listProjectRunners:别处在同一 cwd 下正在跑的对话(同项目并行感知用);
|
|
@@ -5222,6 +5357,7 @@ export class ClientSession {
|
|
|
5222
5357
|
try {
|
|
5223
5358
|
const targets = collectTargets(this.agentDir, ClientSession.currentAppVersion(), undefined, {
|
|
5224
5359
|
projectCwd: this.convs.get(this.activeId)?.cwd ?? this.cwd,
|
|
5360
|
+
extraTargets: collectInstalledEngineTargets(),
|
|
5225
5361
|
});
|
|
5226
5362
|
const items = await checkAllUpdates(targets, undefined, () => this.getLang(), resolveNpmRegistry(this.agentDir));
|
|
5227
5363
|
let pluginItems = [];
|
|
@@ -5690,7 +5826,7 @@ export class ClientSession {
|
|
|
5690
5826
|
* message yet (the SDK only flushes a model_change to disk once one exists). */
|
|
5691
5827
|
rememberProjectModel(modelId) {
|
|
5692
5828
|
const cwd = this.cwd;
|
|
5693
|
-
this.stateStore.saveProjectModel(this.clientId, cwd, modelId);
|
|
5829
|
+
this.stateStore.saveProjectModel(this.clientId, cwd, modelId, "pi");
|
|
5694
5830
|
const slash = modelId.indexOf("/");
|
|
5695
5831
|
if (slash <= 0)
|
|
5696
5832
|
return;
|
|
@@ -5708,7 +5844,7 @@ export class ClientSession {
|
|
|
5708
5844
|
* the user switches via the picker. Silent on failure (model no longer in catalog).
|
|
5709
5845
|
* Fallback chain: project memory > GLOBAL default model > SDK default (no-op). */
|
|
5710
5846
|
async restoreProjectModelForCwd(cwd) {
|
|
5711
|
-
const savedModel = this.stateStore.getProjectModel(this.clientId, cwd) ?? this.stateStore.getDefaultModel();
|
|
5847
|
+
const savedModel = this.stateStore.getProjectModel(this.clientId, cwd, "pi") ?? this.stateStore.getDefaultModel("pi");
|
|
5712
5848
|
if (!savedModel)
|
|
5713
5849
|
return;
|
|
5714
5850
|
try {
|
|
@@ -6414,8 +6550,11 @@ export class ClientSession {
|
|
|
6414
6550
|
/* session 未就绪:下次创建/reload 会再应用 */
|
|
6415
6551
|
}
|
|
6416
6552
|
}
|
|
6553
|
+
else {
|
|
6554
|
+
disabled.add(LOAD_TOOLS_TOOL_NAME);
|
|
6555
|
+
}
|
|
6417
6556
|
applyAgentToolsGating(session, [...disabled], targetPreset, {
|
|
6418
|
-
// load_tools
|
|
6557
|
+
// load_tools 不在任何预设白名单里,又必须在延迟加载开启时永远可用(ask 预设本来就无工具,不强加;非延迟加载模式不激活)。
|
|
6419
6558
|
forceActive: lazy && targetPreset !== "ask" ? [LOAD_TOOLS_TOOL_NAME] : [],
|
|
6420
6559
|
});
|
|
6421
6560
|
const ownerId = conv?.id;
|
|
@@ -6977,6 +7116,16 @@ export class ClientSession {
|
|
|
6977
7116
|
getLang() {
|
|
6978
7117
|
return resolveServerLang(this.stateStore.get(this.clientId).locale);
|
|
6979
7118
|
}
|
|
7119
|
+
/** Raw UI locale as the browser reported it ("zh-TW", "zh-HK", …). Unlike
|
|
7120
|
+
* getLang() it is NOT folded: zh-TW / zh-HK / zh-Hant all resolve to "zh"
|
|
7121
|
+
* there, so Traditional-script data variants must key off this instead. */
|
|
7122
|
+
getLocale() {
|
|
7123
|
+
return this.stateStore.get(this.clientId).locale;
|
|
7124
|
+
}
|
|
7125
|
+
/** 子代理模板的系统提示词:繁中界面先套繁中视图(localizeTemplate),再按服务端语言选 zh/en。 */
|
|
7126
|
+
templatePrompt(apply) {
|
|
7127
|
+
return pickTemplatePrompt(localizeTemplate(apply, this.getLocale()), this.getLang());
|
|
7128
|
+
}
|
|
6980
7129
|
/** Persist the browser UI locale (hello.locale / set_locale) and refresh
|
|
6981
7130
|
* lang-aware prompt segments. Reuses the settings reload path, so it is
|
|
6982
7131
|
* streaming-safe (deferred to agent_end mid-run, same as settings). */
|
|
@@ -6985,9 +7134,16 @@ export class ClientSession {
|
|
|
6985
7134
|
if (!code)
|
|
6986
7135
|
return;
|
|
6987
7136
|
const prev = this.getLang();
|
|
7137
|
+
const prevTraditional = isTraditionalLocale(this.getLocale());
|
|
6988
7138
|
this.stateStore.saveLocale(this.clientId, code);
|
|
6989
|
-
if (this.getLang() === prev)
|
|
6990
|
-
|
|
7139
|
+
if (this.getLang() === prev) {
|
|
7140
|
+
// Same server language (every zh* folds to "zh") — no runtime reload needed. But
|
|
7141
|
+
// Simplified ↔ Traditional changes the built-in subagent templates' view, so
|
|
7142
|
+
// re-push the settings snapshot for an open settings panel.
|
|
7143
|
+
if (isTraditionalLocale(this.getLocale()) !== prevTraditional)
|
|
7144
|
+
this.settingsSvc.push();
|
|
7145
|
+
return;
|
|
7146
|
+
}
|
|
6991
7147
|
await this.applySettingsReload();
|
|
6992
7148
|
}
|
|
6993
7149
|
// ---------------------------------------------------------------------------
|
|
@@ -7598,13 +7754,17 @@ export class ClientSession {
|
|
|
7598
7754
|
// Attach files as independent nextTurn context messages (asides) so the
|
|
7599
7755
|
// user message stays clean; they render as separate attachment cards.
|
|
7600
7756
|
// SDK 的流式队列只消费用户消息;引用须与对应队列项一起入队和撤回。
|
|
7757
|
+
const scan = scanAtMentions(trimmedText, this.cwd, [], attachments ?? []);
|
|
7758
|
+
const effectiveAttachments = scan.detectedAttachments.length > 0 ? [...(attachments ?? []), ...scan.detectedAttachments] : attachments;
|
|
7601
7759
|
const streamingQuotes = s.isStreaming
|
|
7602
|
-
? (
|
|
7760
|
+
? (effectiveAttachments ?? [])
|
|
7603
7761
|
.filter((a) => a.mode === "quote")
|
|
7604
7762
|
.map((a) => readTextQuote(a.quote))
|
|
7605
7763
|
.filter((q) => q !== null)
|
|
7606
7764
|
: [];
|
|
7607
|
-
const nonQuoteAttachments = streamingQuotes.length
|
|
7765
|
+
const nonQuoteAttachments = streamingQuotes.length
|
|
7766
|
+
? effectiveAttachments?.filter((a) => a.mode !== "quote")
|
|
7767
|
+
: effectiveAttachments;
|
|
7608
7768
|
const asides = nonQuoteAttachments && nonQuoteAttachments.length > 0
|
|
7609
7769
|
? await buildAttachmentMessages({
|
|
7610
7770
|
cwd: this.cwd,
|
|
@@ -8911,6 +9071,10 @@ export class ClientSession {
|
|
|
8911
9071
|
}
|
|
8912
9072
|
return undefined;
|
|
8913
9073
|
}
|
|
9074
|
+
/** B20:本会话是否持有该对话(AgentService/daemon 按 convId 跨客户端找持有方用)。 */
|
|
9075
|
+
hasConversation(convId) {
|
|
9076
|
+
return this.convs.has(convId);
|
|
9077
|
+
}
|
|
8914
9078
|
/** 过户用的对话摘要(AgentService 拼移动集合 + 容量检查用)。 */
|
|
8915
9079
|
takeoverBriefs() {
|
|
8916
9080
|
return [...this.convs.values()].map((c) => {
|
|
@@ -9647,10 +9811,12 @@ export class ClientSession {
|
|
|
9647
9811
|
const sessions = new Map();
|
|
9648
9812
|
for (const s of visibleInfos) {
|
|
9649
9813
|
const isPinned = this.stateStore?.isSessionPinned(this.cwd, s.path);
|
|
9814
|
+
const displayName = s.name?.trim() || (s.firstMessage ? s.firstMessage.trim().replace(/\s+/g, " ") : undefined);
|
|
9650
9815
|
sessions.set(s.path, {
|
|
9651
9816
|
path: s.path,
|
|
9652
9817
|
...(s.id ? { sessionId: s.id } : {}),
|
|
9653
9818
|
name: s.name,
|
|
9819
|
+
displayName,
|
|
9654
9820
|
firstMessage: s.firstMessage,
|
|
9655
9821
|
messageCount: s.messageCount,
|
|
9656
9822
|
modified: s.modified.getTime(),
|
|
@@ -10576,6 +10742,15 @@ export class ClientSession {
|
|
|
10576
10742
|
const sessionFile = conv.session.sessionFile;
|
|
10577
10743
|
if (sessionFile && resolve(sessionFile) === targetPath) {
|
|
10578
10744
|
await this.switchConversation(conv.id);
|
|
10745
|
+
this.emit({
|
|
10746
|
+
type: "transition_progress",
|
|
10747
|
+
kind: "session",
|
|
10748
|
+
target: targetPath,
|
|
10749
|
+
phase: "done",
|
|
10750
|
+
progress: 100,
|
|
10751
|
+
text: "会话加载完成",
|
|
10752
|
+
textEn: "Session loaded",
|
|
10753
|
+
});
|
|
10579
10754
|
return;
|
|
10580
10755
|
}
|
|
10581
10756
|
}
|
|
@@ -11327,10 +11502,12 @@ export class ClientSession {
|
|
|
11327
11502
|
.slice(0, 50)
|
|
11328
11503
|
.map((s) => {
|
|
11329
11504
|
const isPinned = this.stateStore?.isSessionPinned(this.cwd, s.path);
|
|
11505
|
+
const displayName = s.name?.trim() || (s.firstMessage ? s.firstMessage.trim().replace(/\s+/g, " ") : undefined);
|
|
11330
11506
|
const base = {
|
|
11331
11507
|
path: s.path,
|
|
11332
11508
|
...(s.id ? { sessionId: s.id } : {}),
|
|
11333
11509
|
name: s.name,
|
|
11510
|
+
displayName,
|
|
11334
11511
|
firstMessage: s.firstMessage,
|
|
11335
11512
|
messageCount: s.messageCount,
|
|
11336
11513
|
modified: s.modified.getTime(),
|
|
@@ -11520,13 +11697,16 @@ export class ClientSession {
|
|
|
11520
11697
|
// lifecycle (removal is deferred until the active conversation is
|
|
11521
11698
|
// safely switched away).
|
|
11522
11699
|
const displaced = this.displaceActive();
|
|
11700
|
+
const openRecent = this.settingsSvc?.current.openRecentSessionOnProjectSwitch ?? true;
|
|
11523
11701
|
// Prefer the target project's own most recently active conversation;
|
|
11524
11702
|
// only create a fresh one (resuming its most recent session) when the
|
|
11525
11703
|
// project has none open yet.
|
|
11526
11704
|
let target;
|
|
11527
|
-
|
|
11528
|
-
|
|
11529
|
-
target
|
|
11705
|
+
if (openRecent) {
|
|
11706
|
+
for (const c of this.convs.values()) {
|
|
11707
|
+
if (c.cwd === abs && (!target || c.lastActiveAt > target.lastActiveAt)) {
|
|
11708
|
+
target = c;
|
|
11709
|
+
}
|
|
11530
11710
|
}
|
|
11531
11711
|
}
|
|
11532
11712
|
if (target) {
|
|
@@ -11543,8 +11723,8 @@ export class ClientSession {
|
|
|
11543
11723
|
target: abs,
|
|
11544
11724
|
phase: "fs",
|
|
11545
11725
|
progress: 28,
|
|
11546
|
-
text: `正在同步目录与检查最近会话:${abs}`,
|
|
11547
|
-
textEn: `Validating workspace & checking recent session: ${abs}`,
|
|
11726
|
+
text: openRecent ? `正在同步目录与检查最近会话:${abs}` : `正在切换工作目录:${abs}`,
|
|
11727
|
+
textEn: openRecent ? `Validating workspace & checking recent session: ${abs}` : `Switching workspace: ${abs}`,
|
|
11548
11728
|
});
|
|
11549
11729
|
this.flushSnapshot();
|
|
11550
11730
|
// 让出事件循环,确保首帧进度在同步磁盘扫描前真正发往浏览器
|
|
@@ -11563,7 +11743,7 @@ export class ClientSession {
|
|
|
11563
11743
|
// blank instead.
|
|
11564
11744
|
let resumeSkipped = null;
|
|
11565
11745
|
// 别处无可见行时不扫目录(首访切项目的常见情形零开销)。
|
|
11566
|
-
if ((this.listExternalRunning?.() ?? []).length > 0) {
|
|
11746
|
+
if (openRecent && (this.listExternalRunning?.() ?? []).length > 0) {
|
|
11567
11747
|
try {
|
|
11568
11748
|
const recentPath = await findMostRecentSessionFileFast(sessionBaseDir, abs);
|
|
11569
11749
|
const recent = recentPath ? resolve(recentPath) : undefined;
|
|
@@ -11580,7 +11760,9 @@ export class ClientSession {
|
|
|
11580
11760
|
const terminals = this.makeTerminalManager(conversationId, abs);
|
|
11581
11761
|
// #235:manager+runtime 一起建,转录链损坏时修最近文件后重试一次
|
|
11582
11762
|
// (见 openManagerAndRuntime)。blank(别处在跑)是全新空会话,不会坏。
|
|
11583
|
-
const opened = await this.openManagerAndRuntime(() =>
|
|
11763
|
+
const opened = await this.openManagerAndRuntime(() => resumeSkipped || !openRecent
|
|
11764
|
+
? SessionManager.create(sessionBaseDir)
|
|
11765
|
+
: SessionManager.continueRecent(sessionBaseDir), (m) => createAgentSessionRuntime(this.makeRuntimeFactory(terminals, undefined, conversationId), {
|
|
11584
11766
|
cwd: sessionBaseDir,
|
|
11585
11767
|
agentDir: this.agentDir,
|
|
11586
11768
|
sessionManager: m,
|
|
@@ -11623,7 +11805,7 @@ export class ClientSession {
|
|
|
11623
11805
|
// #436:同 switchSession —— 续聊最近会话若从转录回放恢复了 planMode,
|
|
11624
11806
|
// 工厂里的门控当时读不到它,注册后补一次。
|
|
11625
11807
|
this.applyToolGating(conv.session, conv.agentPreset);
|
|
11626
|
-
if (resumeSkipped) {
|
|
11808
|
+
if (resumeSkipped && openRecent) {
|
|
11627
11809
|
this.emit(resumeSkipped.isStreaming
|
|
11628
11810
|
? {
|
|
11629
11811
|
type: "notice",
|
|
@@ -11976,13 +12158,30 @@ export class ClientSession {
|
|
|
11976
12158
|
// list must never fail because the catalog sync did
|
|
11977
12159
|
});
|
|
11978
12160
|
const available = await mr.getAvailable();
|
|
11979
|
-
|
|
11980
|
-
|
|
11981
|
-
|
|
11982
|
-
|
|
11983
|
-
|
|
11984
|
-
|
|
11985
|
-
|
|
12161
|
+
// 遵循 ~/.pi/agent/settings.json 中的 enabledModels 白名单限定(issue #646)
|
|
12162
|
+
let enabledSet = null;
|
|
12163
|
+
try {
|
|
12164
|
+
const sm = this.session?.settingsManager ?? this.runtime?.services?.settingsManager;
|
|
12165
|
+
const patterns = sm?.getEnabledModels?.();
|
|
12166
|
+
if (Array.isArray(patterns) && patterns.length > 0 && typeof resolveModelScopeWithDiagnostics === "function") {
|
|
12167
|
+
const { scopedModels } = await resolveModelScopeWithDiagnostics(patterns, mr);
|
|
12168
|
+
enabledSet = new Set(scopedModels.map((s) => `${s.model.provider}/${s.model.id}`));
|
|
12169
|
+
}
|
|
12170
|
+
}
|
|
12171
|
+
catch {
|
|
12172
|
+
// 作用域解析异常时静默回退全量(enabledSet 保持 null)
|
|
12173
|
+
}
|
|
12174
|
+
const models = available.map((m) => {
|
|
12175
|
+
const fullId = `${m.provider}/${m.id}`;
|
|
12176
|
+
return {
|
|
12177
|
+
id: fullId,
|
|
12178
|
+
name: this.cleanModelDisplayName(m.name),
|
|
12179
|
+
provider: m.provider,
|
|
12180
|
+
reasoning: m.reasoning,
|
|
12181
|
+
vision: m.input?.includes("image") ?? false,
|
|
12182
|
+
...(enabledSet ? { enabled: enabledSet.has(fullId) } : {}),
|
|
12183
|
+
};
|
|
12184
|
+
});
|
|
11986
12185
|
this.emit({ type: "models", models });
|
|
11987
12186
|
}
|
|
11988
12187
|
catch (err) {
|
|
@@ -12091,7 +12290,7 @@ export class ClientSession {
|
|
|
12091
12290
|
const id = modelId.slice(slash + 1);
|
|
12092
12291
|
if (!mr.getModel(provider, id))
|
|
12093
12292
|
throw new Error(`模型不存在:${modelId}`);
|
|
12094
|
-
this.stateStore.saveDefaultModel(modelId);
|
|
12293
|
+
this.stateStore.saveDefaultModel(modelId, "pi");
|
|
12095
12294
|
const active = this.modelAdmin.getActiveKeyName(provider);
|
|
12096
12295
|
if (active)
|
|
12097
12296
|
this.stateStore.saveDefaultProviderKey(provider, active);
|
|
@@ -12122,7 +12321,7 @@ export class ClientSession {
|
|
|
12122
12321
|
}
|
|
12123
12322
|
/** Clear the GLOBAL default model (new projects fall back to the SDK default). */
|
|
12124
12323
|
clearDefaultModel() {
|
|
12125
|
-
this.stateStore.
|
|
12324
|
+
this.stateStore.saveDefaultModel("", "pi");
|
|
12126
12325
|
try {
|
|
12127
12326
|
this.session.settingsManager.setDefaultModelAndProvider(undefined, undefined);
|
|
12128
12327
|
}
|
|
@@ -12140,7 +12339,7 @@ export class ClientSession {
|
|
|
12140
12339
|
}
|
|
12141
12340
|
/** Push the current global default model (attach + after every change). */
|
|
12142
12341
|
pushDefaultModel() {
|
|
12143
|
-
this.emit({ type: "default_model", modelId: this.stateStore.getDefaultModel() ?? null });
|
|
12342
|
+
this.emit({ type: "default_model", modelId: this.stateStore.getDefaultModel("pi") ?? null });
|
|
12144
12343
|
}
|
|
12145
12344
|
/** 切换模型,失败时抛出(无头路径专用:插件 host.chat / 定时任务)。
|
|
12146
12345
|
* setModel 为兼容 UI 把异常吞成 notice(面板要能看到原因、调用方是 fire-and-forget),
|