pi-web-ui 0.109.0 → 0.111.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 +31 -0
- package/README.md +21 -1
- package/README.zh-CN.md +21 -1
- package/README.zh-TW.md +201 -677
- package/bin/frp-manager.mjs +85 -7
- package/dist/server/agent-formatters.js +10 -6
- package/dist/server/agent-service-daemon.js +29 -11
- package/dist/server/agent-service.js +160 -54
- package/dist/server/attachments.js +140 -37
- package/dist/server/canvas/canvas-agent-tool.js +587 -0
- package/dist/server/canvas/canvas-cards.js +144 -0
- package/dist/server/canvas/canvas-dispatch.js +155 -0
- package/dist/server/canvas/canvas-orchestrator.js +1027 -0
- package/dist/server/canvas/canvas-store.js +260 -0
- package/dist/server/client-id-utils.js +2 -2
- package/dist/server/client-state.js +24 -0
- package/dist/server/context-budget.js +6 -3
- package/dist/server/dispatch-domain-handlers.js +2 -0
- package/dist/server/dispatch-plugin-handlers.js +1 -0
- package/dist/server/dsh/dsh-agent-service.js +115 -9
- package/dist/server/dsh/dsh-client.js +10 -1
- package/dist/server/dsh/runtime/goal-rpc.mjs +128 -3
- package/dist/server/dsh/runtime/launcher.mjs +59 -5
- package/dist/server/dsh/runtime/runtime-root.mjs +353 -40
- package/dist/server/durable/durable-agent-service.js +3 -0
- package/dist/server/durable/durable-driver.js +1 -1
- package/dist/server/durable/durable-tools.js +4 -1
- package/dist/server/file-transfer-routes.js +8 -2
- package/dist/server/files-service.js +33 -6
- package/dist/server/goal-service.js +12 -3
- package/dist/server/index.js +175 -13
- package/dist/server/locales.js +33 -0
- package/dist/server/marker-service.js +10 -14
- package/dist/server/markers/builtins/action.js +5 -6
- package/dist/server/markers/builtins/notify.js +2 -2
- package/dist/server/markers/builtins/rename.js +2 -2
- package/dist/server/markers/marker.js +45 -4
- package/dist/server/markers/registry.js +36 -1
- package/dist/server/message-window.js +193 -0
- package/dist/server/model-admin.js +0 -4
- package/dist/server/office-parse.js +394 -7
- package/dist/server/plugin-api-catalog.js +6 -0
- package/dist/server/plugin-catalog-sync.js +10 -2
- package/dist/server/plugin-catalog.js +63 -10
- package/dist/server/plugins.js +144 -26
- package/dist/server/preset-fields.js +35 -1
- package/dist/server/preset-share.js +5 -3
- package/dist/server/process-utils.js +58 -24
- package/dist/server/prompt-assembler.js +7 -1
- package/dist/server/prompt-composer.js +66 -36
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/remote-ssh-service.js +16 -4
- package/dist/server/settings-service.js +24 -3
- package/dist/server/slash-commands.js +16 -4
- package/dist/server/text-sniff.js +10 -7
- package/dist/server/themes.js +36 -1
- package/dist/server/tool-manager.js +30 -0
- package/dist/server/univer-service.js +448 -0
- package/dist/server/universal/drivers/claude-code.js +19 -2
- package/dist/server/universal/drivers/dsh-driver.js +1 -1
- package/dist/server/universal/universal-attachments.js +5 -0
- package/dist/server/universal/universal-service.js +5 -0
- package/dist/server/universal/universal-session.js +38 -15
- package/dist/server/update-check.js +90 -5
- package/dist/server/workspace-snapshot.js +33 -2
- package/dist/server/worktree-service.js +1 -1
- package/docs/dsh-engine.md +497 -0
- package/package.json +11 -5
- package/plugin-sdk/index.d.ts +37 -0
- package/plugin-sdk/index.mjs +19 -0
- package/plugins/catalog.json +44 -2
- package/themes/aetheris.css +263 -118
- package/themes/bases/flow-base.css +1363 -0
- package/themes/bases/obsidian-base.css +895 -0
- package/themes/bases/zhujian-base.css +687 -0
- package/themes/bases/zhupi-base.css +659 -0
- package/themes/flow-light.css +2 -925
- package/themes/flow.css +1 -936
- package/themes/md-preview.css +113 -0
- package/themes/wallpaper-flow.css +251 -1029
- package/themes/wallpaper-obsidian.css +1 -673
- package/themes/zhujian-dark.css +1 -605
- package/themes/zhujian.css +1 -654
- package/themes/zhupi-dark.css +1 -576
- package/themes/zhupi.css +1 -626
- package/web/dist/assets/{TerminalPanel-BD3a9o-a.js → TerminalPanel-BiUNySMA.js} +2 -2
- package/web/dist/assets/index-B0ajS__T.js +697 -0
- package/web/dist/assets/index-BHik5WGG.css +1 -0
- package/web/dist/assets/{markdown-DXwnfD9T.js → markdown-BJZlfvdP.js} +24 -24
- package/web/dist/assets/markdown-DSNUiDzp.css +1 -0
- package/web/dist/index.html +4 -4
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/es-DIDZppIF.js +0 -2
- package/web/dist/assets/index-AccytlpP.css +0 -1
- package/web/dist/assets/index-B3dar1BK.js +0 -690
- package/web/dist/assets/markdown-CCeVCbci.css +0 -1
|
@@ -17,16 +17,12 @@ import "./patch-remote-catalog.js";
|
|
|
17
17
|
import "./patch-turn-end-boundary.js";
|
|
18
18
|
import { spawn } from "node:child_process";
|
|
19
19
|
import { createHash, randomUUID } from "node:crypto";
|
|
20
|
-
import { createRequire } from "node:module";
|
|
21
20
|
import * as fsPromises from "node:fs/promises";
|
|
22
21
|
import { DEFAULT_PI_CAPABILITIES } from "./engine-capabilities.js";
|
|
23
|
-
import { appendFileSync, existsSync, readFileSync, readdirSync, rmSync,
|
|
22
|
+
import { appendFileSync, existsSync, readFileSync, readdirSync, rmSync, mkdirSync, watch, writeFileSync, } from "node:fs";
|
|
24
23
|
import { homedir } from "node:os";
|
|
25
|
-
import { basename, delimiter,
|
|
26
|
-
import {
|
|
27
|
-
import { writeAtomicSync } from "./atomic-file.js";
|
|
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";
|
|
29
|
-
import { Type } from "typebox";
|
|
24
|
+
import { basename, delimiter, join, resolve } from "node:path";
|
|
25
|
+
import { createAgentSessionFromServices, createAgentSessionRuntime, createAgentSessionServices, createCodemodeExtension, createEditToolDefinition, createFindToolDefinition, createGrepToolDefinition, createLsToolDefinition, createToolSearchExtension, resolveModelScopeWithDiagnostics, getAgentDir, SessionManager, VERSION, } from "@earendil-works/pi-coding-agent";
|
|
30
26
|
import { BG_CLEANUP_FALLBACK_MIN, BgServerTracker } from "./bg-servers.js";
|
|
31
27
|
import { checkAll as checkAllUpdates, collectTargets, compareVersions as compareSemver, detectPiSdkSplit, resolveNpmRegistry, sortUpdateItems, } from "./update-check.js";
|
|
32
28
|
import { collectInstalledEngineTargets } from "./engine-probe.js";
|
|
@@ -39,9 +35,7 @@ import { calibrateSessionLeaf } from "./session-branch.js";
|
|
|
39
35
|
import { danglingToolResultText, findDanglingToolCalls, healDanglingToolCallFile, } from "./dangling-tools.js";
|
|
40
36
|
import { removeQueuedByIndexOrText } from "./queue-utils.js";
|
|
41
37
|
import { syncPluginToolsIntoSession } from "./plugins.js";
|
|
42
|
-
import { modelChangeKey, pickClientConversation
|
|
43
|
-
import { denialText, } from "./plugin-tool-guard.js";
|
|
44
|
-
import { BASH_DESCRIPTION, BASH_PARAMETERS, BASH_PROMPT_GUIDELINES, BASH_PROMPT_SNIPPET } from "./tool-prompts.js";
|
|
38
|
+
import { modelChangeKey, pickClientConversation } from "./plugin-conversation-view.js";
|
|
45
39
|
import { SettingsService } from "./settings-service.js";
|
|
46
40
|
import { GoalService, buildDiffFingerprint, extractErrorSnippetFromSession, lastToolNameOfSession, } from "./goal-service.js";
|
|
47
41
|
import { buildEvidenceDigest, sessionMessagesOf } from "./goal-evidence.js";
|
|
@@ -53,7 +47,7 @@ import { buildRemoteWorkspacePersona, createRemoteSdkOperations, formatCwdForPro
|
|
|
53
47
|
import { DEFAULT_TOOL_WATCHDOG_TIMEOUT_MS, effectiveToolWatchdogMs, isExtensionDisabled, isExtensionEnabled, isInternalExtension, normalizeDisabledPluginTools, normalizePathKey, normalizeRetryMaxAttempts, normalizeSkillList, ClientStateStore, } from "./client-state.js";
|
|
54
48
|
import { isTraditionalLocale, pick, resolveServerLang } from "./i18n.js";
|
|
55
49
|
import { SubagentTemplatesStore, localizeTemplate, pickTemplatePrompt, } from "./subagent-templates.js";
|
|
56
|
-
import { ApprovalRulesStore
|
|
50
|
+
import { ApprovalRulesStore } from "./approval-rules.js";
|
|
57
51
|
import { ComposerDraftsStore } from "./composer-drafts.js";
|
|
58
52
|
import { SandboxManager, evaluateSandboxJail, isSameOrSubpath, withSandboxJailGate } from "./sandbox-service.js";
|
|
59
53
|
import { readPermissionFromSession } from "./permission-preset.js";
|
|
@@ -62,25 +56,22 @@ import { createScheduleToolHost, createConversationReadHost, createClaimToolHost
|
|
|
62
56
|
import { toSubagentSnapshot, listSubagentSnapshots, subagentRunOutcome, roleOutcomeOf, countActiveSubagents, } from "./subagent-helpers.js";
|
|
63
57
|
import { resolveUserMessageEntryId, resolveConversationMessageEntry } from "./message-entry-resolver.js";
|
|
64
58
|
import { fillSkillContents } from "./skill-content-filler.js";
|
|
65
|
-
import {
|
|
59
|
+
import { estimateNonSystemTokens, renderMainCompose } from "./prompt-assembler.js";
|
|
66
60
|
import { formatSubagentHandoffMessage, recordSubagentHandoff } from "./subagent-handoff.js";
|
|
67
61
|
import { executeContextBudgetPruning } from "./context-budget-runner.js";
|
|
68
|
-
import {
|
|
69
|
-
import { approvalSuppressionReason, checkDangerousToolCall, isApprovalPolicyEmpty, pluginApprovalCategory, } from "./tool-approval.js";
|
|
62
|
+
import { approvalSuppressionReason, checkDangerousToolCall, isApprovalPolicyEmpty, } from "./tool-approval.js";
|
|
70
63
|
import { PlanManager } from "./plan-manager.js";
|
|
71
64
|
import { buildPlanModePrompt, planModeDenial, planModeNoticeText, PLAN_MODE_BLOCKED_TOOL_NAMES } from "./plan-mode.js";
|
|
72
|
-
import { DELEGATION_SYSTEM_PROMPT,
|
|
65
|
+
import { DELEGATION_SYSTEM_PROMPT, delegateNoticeText } from "./delegate-mode.js";
|
|
73
66
|
import { goalReviewDenial, shouldDeferPromptForReview } from "./goal-review-gate.js";
|
|
74
67
|
import { readPlanModeFromSession, readPlanFromSession } from "./permission-preset.js";
|
|
75
68
|
import { readDelegateModeFromSession } from "./permission-preset.js";
|
|
76
|
-
import {
|
|
77
|
-
import { applyAgentToolsGating, ASK_USER_QUESTION_TOOL_NAME,
|
|
69
|
+
import { makePersistentTerminalTools, makeTerminalBashTool, stripAnsi, TERMINAL_TOOLS_GUIDANCE } from "./terminals.js";
|
|
70
|
+
import { applyAgentToolsGating, ASK_USER_QUESTION_TOOL_NAME, effectiveDisabledAgentTools, filterToolsByPreset, isAgentToolEnabled, isTerminalGuidanceOn, LAZY_CORE_TOOL_NAMES, lazyLoadingDisabledTools, LOAD_TOOLS_TOOL_NAME, localizedName, PI_AGENT_PRESETS, PI_PERMISSION_OPTIONS, PRESENT_FILES_TOOL_NAME, presetAllowsPluginTools, presetHasQuestionnaire, presetShowsSkillCatalog, } from "./tool-manager.js";
|
|
78
71
|
import { makeLoadToolsTool } from "./load-tools-tool.js";
|
|
79
72
|
import { formatCompactSignature } from "./tool-signature.js";
|
|
80
73
|
import { WebUIContext } from "./webui-context.js";
|
|
81
74
|
import { DEFAULT_COMPACTION_RESERVE_TOKENS, effectiveSoftCap, softCapToReserve } from "./soft-cap.js";
|
|
82
|
-
import { pruneContextHierarchically } from "./context-budget.js";
|
|
83
|
-
import { decodeText } from "./text-sniff.js";
|
|
84
75
|
import { makeEditSoftTool } from "./edit-soft-tool.js";
|
|
85
76
|
// 覆盖 SDK 内置 read:路径是目录时列出目录条目(行为开关 readDirEnabled,默认开)。
|
|
86
77
|
// 覆盖定义与「与扩展同名工具共存」的注入辅助分在两个文件(后者的依据见 tool-overrides.ts)。
|
|
@@ -98,9 +89,9 @@ import { normalizeToolInfo } from "./tool-info.js";
|
|
|
98
89
|
import { applyToolPromptOverrides, effectiveToolPrompt, toolPromptOverrideOf, } from "./tool-prompt-overrides.js";
|
|
99
90
|
import { collectSubagentDescendantIds, makeSubagentTools, subagentTitle, withSubagentOwner, } from "./subagents.js";
|
|
100
91
|
import { makeDelegateTaskTool } from "./delegate-task.js";
|
|
101
|
-
import { makeConversationReadTool,
|
|
92
|
+
import { makeConversationReadTool, toTranscriptInput, } from "./conversation-read-tool.js";
|
|
102
93
|
import { extractTouches, formatTouchesCompact, intersectTouches } from "./conversation-touches.js";
|
|
103
|
-
import { ClaimStore, matchClaims, mergeTouchSidecar,
|
|
94
|
+
import { ClaimStore, matchClaims, mergeTouchSidecar, removeTouchSidecar } from "./claim-store.js";
|
|
104
95
|
import { makeClaimFilesTool } from "./claim-files-tool.js";
|
|
105
96
|
import { makeSkillTool } from "./skill-tool.js";
|
|
106
97
|
import { getCompactedMessages } from "./compacted-history.js";
|
|
@@ -109,7 +100,8 @@ import { makePatchTool } from "./patch-tool.js";
|
|
|
109
100
|
import { makeLspTool } from "./lsp-tool.js";
|
|
110
101
|
import { makeMcpManageTool } from "./mcp-agent-tool.js";
|
|
111
102
|
import { makeSandboxTool } from "./sandbox-tool.js";
|
|
112
|
-
import { makeWorktreeTool
|
|
103
|
+
import { makeWorktreeTool } from "./worktree-tool.js";
|
|
104
|
+
import { makeCanvasTool } from "./canvas/canvas-agent-tool.js";
|
|
113
105
|
import { getWorktreeContext, removeWorktree, normalizeWirePath } from "./worktree-service.js";
|
|
114
106
|
import { sameSessionFile } from "./scheduler-tasks.js";
|
|
115
107
|
import { buildAttachmentMessages, findTurnBaseEntryId, parseModelSpec } from "./attachments.js";
|
|
@@ -117,11 +109,10 @@ import { scanAtMentions } from "./universal/universal-attachments.js";
|
|
|
117
109
|
import { formatQuotedPrompt, formatStreamingPrompt, readTextQuote, splitQuotedPrompt } from "./text-quote.js";
|
|
118
110
|
import { buildVisionBridgePrompt, findVisionModels, transcribeImages } from "./vision-bridge.js";
|
|
119
111
|
import { generateScmCommitMessage } from "./scm-commitmsg.js";
|
|
120
|
-
import { BUILTIN_SOUL, DEFAULT_PROMPT_TEMPLATE, buildToolsSchemaText, estimatePromptTokens, renderPromptTemplate, resolveSectionTexts,
|
|
112
|
+
import { BUILTIN_SOUL, DEFAULT_PROMPT_TEMPLATE, buildToolsSchemaText, estimatePromptTokens, renderPromptTemplate, resolveSectionTexts, } from "./prompt-composer.js";
|
|
121
113
|
import { listAllMcpServers, checkMcpServer, installMcpServer, saveMcpServer as saveMcpServerFile, deleteMcpServer as deleteMcpServerFile, toggleMcpServer as toggleMcpServerFile, } from "./mcp-manager.js";
|
|
122
114
|
import { fetchRemoteMcpMarket, fetchRemoteSkillMarket, fetchRemoteSkillContent } from "./market-service.js";
|
|
123
|
-
import {
|
|
124
|
-
import { findEntryByUiId, serializeMessage, serializeStreamingMessage, stripTransientRetryErrors, } from "./serialize.js";
|
|
115
|
+
import { serializeMessage, serializeStreamingMessage, stripTransientRetryErrors, } from "./serialize.js";
|
|
125
116
|
import { loadCommands, saveCommandsFile, TerminalManager } from "./terminals.js";
|
|
126
117
|
const SNAPSHOT_INTERVAL_MS = 60;
|
|
127
118
|
/** 服务进程所在机器的用户主目录(wire 格式):进程内不变,模块加载时求值一次,
|
|
@@ -212,9 +203,9 @@ export { normalizeSolPlanToPlanSteps, makePlanUpdateTool };
|
|
|
212
203
|
import { makeAskUserQuestionTool, shouldPopQuestion } from "./ask-user-question-tool.js";
|
|
213
204
|
import { normalizePageCallTimeoutMs, collectBrowserPageArgs, formatPageCallResult, formatBrowserPageError, makeBrowserPageTool, extractShotImage, } from "./browser-page-tool.js";
|
|
214
205
|
export { makeAskUserQuestionTool, shouldPopQuestion, normalizePageCallTimeoutMs, collectBrowserPageArgs, formatPageCallResult, formatBrowserPageError, makeBrowserPageTool, extractShotImage, };
|
|
215
|
-
import { RUN_TASK_CAP, RUN_ARGS_CAP,
|
|
206
|
+
import { RUN_TASK_CAP, RUN_ARGS_CAP, getMaxOpenConversations, getMaxSubagents, DEFAULT_CONV_TITLE, truncRun, previewToolResult, atomicWriteFileSync, conversationTitle, pluginToolToDefinition, contentFingerprint, extractPartialText, extractAssistantTextFromContent, firstSentence, modelKeyOf, contextWindowOf, } from "./agent-formatters.js";
|
|
216
207
|
export { workspacePath };
|
|
217
|
-
import {
|
|
208
|
+
import { sessionMatchesMetadata, collectSessionAnchors, piSessionsRoot, isInsideSessionsDir, } from "./session-search.js";
|
|
218
209
|
export { piSessionsRoot, isInsideSessionsDir };
|
|
219
210
|
import { discoverRecentProjectsFromDisk, filterForkedParentSessions, findMostRecentSessionFileFast, parseSessionInfoFast, } from "./session-parser.js";
|
|
220
211
|
import { pickAdoptableOrphan, sameCwd } from "./orphan-manager.js";
|
|
@@ -430,7 +421,7 @@ export class ClientSession {
|
|
|
430
421
|
customType: "terminal-bash-done",
|
|
431
422
|
content: [{ type: "text", text }],
|
|
432
423
|
display: true,
|
|
433
|
-
})
|
|
424
|
+
}, { deliverAs: "nextTurn" })
|
|
434
425
|
.catch(() => { });
|
|
435
426
|
}
|
|
436
427
|
}
|
|
@@ -591,6 +582,10 @@ export class ClientSession {
|
|
|
591
582
|
});
|
|
592
583
|
}
|
|
593
584
|
}
|
|
585
|
+
// 换模型之后同步重算软上限。setModel 的 model_select 不进 session.subscribe,
|
|
586
|
+
// 首轮压缩检查会用到换模型前的 reserve(1M 窗口算出的 74 万泄漏到小窗口上,
|
|
587
|
+
// 触发点变成负数,上下文到几万 token 就压)。
|
|
588
|
+
this.refreshCompactionOverride(conv);
|
|
594
589
|
// 思考强度:模板指定则固定用它,否则跟随派发者当前强度(与「跟随派发者模型」
|
|
595
590
|
// 同一取数源:spawnerSession)。所以子代理默认与派发者一致,而不是默默回到
|
|
596
591
|
// SDK 默认档位。放在换模型之后:setModel 会按模型能力重算强度,我们先让它
|
|
@@ -940,7 +935,17 @@ export class ClientSession {
|
|
|
940
935
|
if (!session || !this.lazyLoadingOn())
|
|
941
936
|
return empty;
|
|
942
937
|
try {
|
|
943
|
-
|
|
938
|
+
// PATCH-F1: 目录排除 MCP deferred 工具——「恒定全集」在 MCP deferred 后会把
|
|
939
|
+
// 数百个工具摘要常驻 tools 节(实测 318 工具时 2042→20854 chars,+75K tok/轮)。
|
|
940
|
+
// deferred 工具按设计不声明给模型,其发现走 mcp 网关(searchTools)与
|
|
941
|
+
// tool_search 的 BM25 元数据(零 schema 注入);目录里列出它们违背 deferred
|
|
942
|
+
// 语义且每轮全价。目录其余部分仍恒定(MCP deferred 集合会话内固定),不影响前缀缓存。
|
|
943
|
+
const mcpDeferred = new Set((session.getAllTools?.() ?? [])
|
|
944
|
+
.filter((t) => typeof t?.namespace?.name === "string" &&
|
|
945
|
+
t.namespace.name.startsWith("mcp__") &&
|
|
946
|
+
(t.exposure ?? "codemode") === "deferred")
|
|
947
|
+
.map((t) => t.name));
|
|
948
|
+
const names = this.allowedToolNames(session, conv).filter((n) => n !== LOAD_TOOLS_TOOL_NAME && !mcpDeferred.has(n));
|
|
944
949
|
const snippets = {};
|
|
945
950
|
const signatures = {};
|
|
946
951
|
for (const name of names) {
|
|
@@ -1190,6 +1195,9 @@ export class ClientSession {
|
|
|
1190
1195
|
contextFiles: src.contextFiles,
|
|
1191
1196
|
skills: effectiveSkills,
|
|
1192
1197
|
skillsFullText: showSkills ? normalizeSkillList(this.settingsSvc.current.skillsFullText) : [],
|
|
1198
|
+
skillsCatalogMaxDesc: this.settingsSvc.current.skillsCatalogMaxDesc,
|
|
1199
|
+
skillsCatalogShowLocation: this.settingsSvc.current.skillsCatalogShowLocation,
|
|
1200
|
+
skillsCatalogBudget: this.settingsSvc.current.skillsCatalogBudget,
|
|
1193
1201
|
};
|
|
1194
1202
|
}
|
|
1195
1203
|
/** skill 全文注入({{skills}} 全文模式):最好努力读名单里技能的文件正文。 */
|
|
@@ -1201,12 +1209,16 @@ export class ClientSession {
|
|
|
1201
1209
|
* 仅在完全默认且全功能 standard 状态下返回 undefined 让 SDK 拼装。 */
|
|
1202
1210
|
renderMainCompose(src) {
|
|
1203
1211
|
const preset = src.preset ?? this.conv?.agentPreset ?? this.settingsSvc.current.defaultAgentPreset ?? "standard";
|
|
1212
|
+
const showSkills = presetShowsSkillCatalog(preset);
|
|
1213
|
+
const effectiveSkills = showSkills ? this.fillSkillContents(src.skills) : [];
|
|
1204
1214
|
return renderMainCompose(this.composeInputs(src), {
|
|
1205
1215
|
promptTemplate: this.settingsSvc.current.promptTemplate,
|
|
1206
1216
|
promptOverrides: this.settingsSvc.current.promptOverrides,
|
|
1207
1217
|
preset,
|
|
1208
1218
|
disabledToolCount: effectiveDisabledAgentTools(this.settingsSvc.current).length,
|
|
1209
1219
|
isLazy: src.lazy,
|
|
1220
|
+
hasSkills: effectiveSkills.length > 0,
|
|
1221
|
+
hasSkillsFullText: (this.settingsSvc.current.skillsFullText?.length ?? 0) > 0,
|
|
1210
1222
|
});
|
|
1211
1223
|
}
|
|
1212
1224
|
/** 从指定会话(缺省 = 活跃会话)收集工具/资源快照 → 一次算出 ①各来源默认(自动)
|
|
@@ -2576,6 +2588,12 @@ export class ClientSession {
|
|
|
2576
2588
|
await this.refreshWorktreeInfo();
|
|
2577
2589
|
},
|
|
2578
2590
|
}, () => this.getLang()),
|
|
2591
|
+
// 画布流水线编辑工具(canvas:增删改查/重排/运行/调试;新节点 cwd 跟随当前项目)。
|
|
2592
|
+
makeCanvasTool({
|
|
2593
|
+
dataDir: this.stateStore.dataDir,
|
|
2594
|
+
lang: () => this.getLang(),
|
|
2595
|
+
getCwd: () => (ownerId ? this.convs.get(ownerId)?.cwd : undefined) ?? effectiveCwd,
|
|
2596
|
+
}),
|
|
2579
2597
|
].map((t) =>
|
|
2580
2598
|
// 目标审查闸门在最外层(理由最贴合此刻);插件工具也在这个数组里,
|
|
2581
2599
|
// 创建时注册的同样被闸门覆盖(后续动态补入的走 syncPluginTools,与
|
|
@@ -5978,18 +5996,20 @@ export class ClientSession {
|
|
|
5978
5996
|
}
|
|
5979
5997
|
}
|
|
5980
5998
|
}
|
|
5981
|
-
/**
|
|
5999
|
+
/** 会话模型或窗口变化时重放该会话的软上限覆盖。SDK 恢复历史会话的模型
|
|
5982
6000
|
* (findInitialModel)与 /model 命令都不经过 pi-web-ui 的 setModel
|
|
5983
6001
|
* 路径,注入过的 reserve 会停留在旧模型窗口的换算值上——例如默认
|
|
5984
6002
|
* 模型(1M 窗口)算出 748576,泄漏到 500K 窗口的会话后压缩触发点
|
|
5985
|
-
* 变成负数,上下文几万 token 就被反复压缩。onEvent
|
|
5986
|
-
*
|
|
6003
|
+
* 变成负数,上下文几万 token 就被反复压缩。onEvent 比对模型 key 与窗口,
|
|
6004
|
+
* 有变化才重放。setModel 本身不发 session 事件,子代理创建路径另有同步重算。 */
|
|
5987
6005
|
reapplySoftCapIfModelChanged(conv) {
|
|
5988
6006
|
try {
|
|
5989
6007
|
const key = modelKeyOf(conv.session);
|
|
5990
|
-
|
|
6008
|
+
const contextWindow = contextWindowOf(conv.session);
|
|
6009
|
+
if (conv.lastModelKey === key && conv.lastContextWindow === contextWindow)
|
|
5991
6010
|
return;
|
|
5992
6011
|
conv.lastModelKey = key;
|
|
6012
|
+
conv.lastContextWindow = contextWindow;
|
|
5993
6013
|
if (key)
|
|
5994
6014
|
this.applyCompactionOverrideForConv(conv, this.settingsSvc.current);
|
|
5995
6015
|
}
|
|
@@ -5997,6 +6017,18 @@ export class ClientSession {
|
|
|
5997
6017
|
// 会话未就绪或已释放 → 留给创建/换模型路径与后续事件重试。
|
|
5998
6018
|
}
|
|
5999
6019
|
}
|
|
6020
|
+
/** setModel 只向扩展发 model_select,不走 session.subscribe,
|
|
6021
|
+
* onEvent 里的重放赶不上首轮压缩检查。换完模型后必须同步重算。 */
|
|
6022
|
+
refreshCompactionOverride(conv) {
|
|
6023
|
+
try {
|
|
6024
|
+
this.applyCompactionOverrideForConv(conv, this.settingsSvc.current);
|
|
6025
|
+
conv.lastModelKey = modelKeyOf(conv.session);
|
|
6026
|
+
conv.lastContextWindow = contextWindowOf(conv.session);
|
|
6027
|
+
}
|
|
6028
|
+
catch {
|
|
6029
|
+
// 会话未就绪 → 首个 SDK 事件仍会走 reapplySoftCapIfModelChanged。
|
|
6030
|
+
}
|
|
6031
|
+
}
|
|
6000
6032
|
/** 当前活动对话的生效软上限(快照底栏标记线用;null = 关闭/未知)。 */
|
|
6001
6033
|
activeSoftCap(contextWindow) {
|
|
6002
6034
|
try {
|
|
@@ -6560,10 +6592,12 @@ export class ClientSession {
|
|
|
6560
6592
|
}
|
|
6561
6593
|
// 延迟加载(默认开):未加载的已登记工具一律当「临时禁用」——与用户禁用名单 /
|
|
6562
6594
|
// 计划模式闸门走同一条门控链,不做第二套机制。加载只是把名字从这份名单里拿出来。
|
|
6595
|
+
let loadedNames = [];
|
|
6563
6596
|
const lazy = this.lazyLoadingOn();
|
|
6564
6597
|
if (lazy) {
|
|
6565
6598
|
try {
|
|
6566
6599
|
const loaded = this.lazyLoadedFor(session, this.sessionHasTranscript(session));
|
|
6600
|
+
loadedNames = [...loaded];
|
|
6567
6601
|
for (const name of lazyLoadingDisabledTools(session.getAllTools().map((t) => t.name), loaded)) {
|
|
6568
6602
|
disabled.add(name);
|
|
6569
6603
|
}
|
|
@@ -6577,7 +6611,10 @@ export class ClientSession {
|
|
|
6577
6611
|
}
|
|
6578
6612
|
applyAgentToolsGating(session, [...disabled], targetPreset, {
|
|
6579
6613
|
// load_tools 不在任何预设白名单里,又必须在延迟加载开启时永远可用(ask 预设本来就无工具,不强加;非延迟加载模式不激活)。
|
|
6580
|
-
|
|
6614
|
+
// 显式 load_tools 加载过的名字一并强制激活:PATCH-B1 门控会无条件剔除
|
|
6615
|
+
// exposure≠direct 的 MCP 工具(连 deferred 的也在内),若这里不把它们
|
|
6616
|
+
// 加回活跃集,会复现 #652 的死路变体——「已加载且目录可见,但永不活跃」。
|
|
6617
|
+
forceActive: lazy && targetPreset !== "ask" ? [LOAD_TOOLS_TOOL_NAME, ...loadedNames] : [],
|
|
6581
6618
|
});
|
|
6582
6619
|
const ownerId = conv?.id;
|
|
6583
6620
|
syncSubagentOverride(session, disabled.has("subagent"), () => ownerId
|
|
@@ -7127,6 +7164,11 @@ export class ClientSession {
|
|
|
7127
7164
|
for (const conv of this.convs.values())
|
|
7128
7165
|
this.syncPluginTools(conv.session);
|
|
7129
7166
|
}
|
|
7167
|
+
/** index.ts 经 pluginMgr.onMarkersChanged 触发:刷新客户端 markers 设置与小部件。 */
|
|
7168
|
+
refreshPluginMarkers() {
|
|
7169
|
+
this.settingsSvc.push();
|
|
7170
|
+
this.markerSvc.pushOverlay(this.activeId);
|
|
7171
|
+
}
|
|
7130
7172
|
async applySettingsReload() {
|
|
7131
7173
|
// 兼容旧入口:reload + 刷目录在宿主回调里完成
|
|
7132
7174
|
return this.settingsSvc.applyRuntime();
|
|
@@ -7293,6 +7335,10 @@ export class ClientSession {
|
|
|
7293
7335
|
* (随主对话一起搬)。activity = 该对话最近一次活跃时间(离线行的宽限期判定用,
|
|
7294
7336
|
* 见 OFFLINE_ROW_TTL_MS)。 */
|
|
7295
7337
|
streamingSummariesAll() {
|
|
7338
|
+
// 画布专用客户端(CanvasStudio)绝不参与聊天会话列表感知,杜绝向 elsewhere 暴露任何条目
|
|
7339
|
+
if (this.clientId?.startsWith("canvas:") || this.clientId?.startsWith("canvas-")) {
|
|
7340
|
+
return [];
|
|
7341
|
+
}
|
|
7296
7342
|
const out = [];
|
|
7297
7343
|
const seenFiles = new Set();
|
|
7298
7344
|
for (const conv of this.convs.values()) {
|
|
@@ -7476,8 +7522,8 @@ export class ClientSession {
|
|
|
7476
7522
|
catch {
|
|
7477
7523
|
// ignore
|
|
7478
7524
|
}
|
|
7525
|
+
const s = this.session;
|
|
7479
7526
|
try {
|
|
7480
|
-
const s = this.session;
|
|
7481
7527
|
// Native slash commands (see NATIVE_COMMANDS) are executed here and
|
|
7482
7528
|
// never reach the SDK. Extension / skill / template commands fall
|
|
7483
7529
|
// through — AgentSession.prompt() handles those itself.
|
|
@@ -7856,18 +7902,21 @@ export class ClientSession {
|
|
|
7856
7902
|
}
|
|
7857
7903
|
}
|
|
7858
7904
|
else {
|
|
7905
|
+
// 空闲提问:必须携带 deliverAs: "nextTurn",将附件(图片、文件引用、视觉证据等)
|
|
7906
|
+
// 注入 SDK 的 _pendingNextTurnMessages,并在随后的 s.prompt() 中由 SDK 作为上下文消息
|
|
7907
|
+
// 传递给 LLM 并落盘(fixes #667)。严禁在此清空 _pendingNextTurnMessages。
|
|
7859
7908
|
for (const aside of asides) {
|
|
7860
|
-
await s.sendCustomMessage(aside.message);
|
|
7909
|
+
await s.sendCustomMessage(aside.message, { deliverAs: "nextTurn" });
|
|
7861
7910
|
}
|
|
7862
7911
|
if (asides.length > 0) {
|
|
7863
7912
|
this.flushSnapshot();
|
|
7864
7913
|
}
|
|
7865
|
-
if (Array.isArray(s._pendingNextTurnMessages)) {
|
|
7866
|
-
s._pendingNextTurnMessages = [];
|
|
7867
|
-
}
|
|
7868
7914
|
}
|
|
7869
7915
|
if (promptAc.signal.aborted) {
|
|
7870
7916
|
conv.activePromptAc = undefined;
|
|
7917
|
+
if (Array.isArray(s._pendingNextTurnMessages)) {
|
|
7918
|
+
s._pendingNextTurnMessages = [];
|
|
7919
|
+
}
|
|
7871
7920
|
// #492:同上——前置阶段的 abort 也必须给回执,不能静默黑洞。
|
|
7872
7921
|
this.emit({
|
|
7873
7922
|
type: "notice",
|
|
@@ -7934,6 +7983,9 @@ export class ClientSession {
|
|
|
7934
7983
|
}
|
|
7935
7984
|
catch (err) {
|
|
7936
7985
|
conv.activePromptAc = undefined;
|
|
7986
|
+
if (Array.isArray(conv.session?._pendingNextTurnMessages)) {
|
|
7987
|
+
conv.session._pendingNextTurnMessages = [];
|
|
7988
|
+
}
|
|
7937
7989
|
this.emit({
|
|
7938
7990
|
type: "notice",
|
|
7939
7991
|
level: "error",
|
|
@@ -9410,8 +9462,21 @@ export class ClientSession {
|
|
|
9410
9462
|
}
|
|
9411
9463
|
/** Switch the ACTIVE conversation without interrupting any other chat. */
|
|
9412
9464
|
async switchConversation(id) {
|
|
9413
|
-
if (
|
|
9465
|
+
if (id === this.activeId)
|
|
9466
|
+
return;
|
|
9467
|
+
if (!this.convs.has(id)) {
|
|
9468
|
+
this.emit({
|
|
9469
|
+
type: "transition_progress",
|
|
9470
|
+
kind: "conversation",
|
|
9471
|
+
target: id,
|
|
9472
|
+
phase: "error",
|
|
9473
|
+
progress: 100,
|
|
9474
|
+
text: "对话已不存在或已结束",
|
|
9475
|
+
textEn: "Conversation no longer exists or has finished",
|
|
9476
|
+
});
|
|
9477
|
+
this.flushSnapshot();
|
|
9414
9478
|
return;
|
|
9479
|
+
}
|
|
9415
9480
|
const displaced = this.displaceActive();
|
|
9416
9481
|
this.activeId = id;
|
|
9417
9482
|
const newCwd = this.conv.cwd;
|
|
@@ -9428,10 +9493,26 @@ export class ClientSession {
|
|
|
9428
9493
|
this.emitConversations();
|
|
9429
9494
|
this.goalSvc.emitGoalStatus();
|
|
9430
9495
|
this.pushTerminals();
|
|
9431
|
-
// The switched-to conversation has its own runtime (own resource cache).
|
|
9432
|
-
void this.pushSlashCommands();
|
|
9433
9496
|
if (cwdChanged) {
|
|
9434
9497
|
this.cwd = newCwd;
|
|
9498
|
+
this.files.unwatchGit();
|
|
9499
|
+
this.roots = this.stateStore.getWorkspaceRoots(this.clientId, newCwd);
|
|
9500
|
+
}
|
|
9501
|
+
// 核心:快照与完成信号优先!在繁重的工作区扫描/设置推送之前第一时间发往
|
|
9502
|
+
// 浏览器,0ms 呈现对话内容与状态,绝不让前端在空转中等待文件树与设置大包。
|
|
9503
|
+
this.flushSnapshot();
|
|
9504
|
+
this.emit({
|
|
9505
|
+
type: "transition_progress",
|
|
9506
|
+
kind: "conversation",
|
|
9507
|
+
target: id,
|
|
9508
|
+
phase: "done",
|
|
9509
|
+
progress: 100,
|
|
9510
|
+
text: "对话切换完成",
|
|
9511
|
+
textEn: "Conversation switched",
|
|
9512
|
+
});
|
|
9513
|
+
// 工作区跟随副作用(命令/项目/会话/文件树/插件通知/设置)异步推进,不阻塞会话呈现
|
|
9514
|
+
void this.pushSlashCommands();
|
|
9515
|
+
if (cwdChanged) {
|
|
9435
9516
|
// 模型/key 恢复不挡快照:后台做,带代际 guard(用户又切走就跳过),
|
|
9436
9517
|
// 做完补一次 flush 刷新模型栏。
|
|
9437
9518
|
{
|
|
@@ -9458,7 +9539,6 @@ export class ClientSession {
|
|
|
9458
9539
|
// 当前打开对话变了 → 插件重拉(轨迹视图切会话后即刷新,不等轮询)。
|
|
9459
9540
|
this.notifyConversationChanged();
|
|
9460
9541
|
this.pushSettings();
|
|
9461
|
-
this.flushSnapshot();
|
|
9462
9542
|
}
|
|
9463
9543
|
/** 左栏「运行的对话」的展示口径(issue #140)。
|
|
9464
9544
|
*
|
|
@@ -9808,11 +9888,11 @@ export class ClientSession {
|
|
|
9808
9888
|
await this.pushSessions();
|
|
9809
9889
|
}
|
|
9810
9890
|
/** 切项目时的会话列表刷新:sessionInfosCache 已按 cwdKey 隔离(30s TTL),
|
|
9811
|
-
*
|
|
9891
|
+
* 若在 TTL 内则直接复用缓存推送,不再全盘清空重扫。 */
|
|
9812
9892
|
refreshSessionsOnSwitch() {
|
|
9813
9893
|
const cwdKey = normalizePathKey(this.cwd);
|
|
9814
9894
|
const cached = ClientSession.sessionInfosCache.get(cwdKey);
|
|
9815
|
-
if (!cached || Date.now() - cached.at >
|
|
9895
|
+
if (!cached || Date.now() - cached.at > ClientSession.SESSION_INFO_CACHE_TTL) {
|
|
9816
9896
|
ClientSession.sessionInfosCache.delete(cwdKey);
|
|
9817
9897
|
}
|
|
9818
9898
|
if (this.sessionsRequested)
|
|
@@ -10794,12 +10874,12 @@ export class ClientSession {
|
|
|
10794
10874
|
return;
|
|
10795
10875
|
}
|
|
10796
10876
|
if (owner) {
|
|
10797
|
-
if (
|
|
10877
|
+
if (owner.clientId.startsWith("scheduler:")) {
|
|
10798
10878
|
this.emit({
|
|
10799
10879
|
type: "notice",
|
|
10800
10880
|
level: "warning",
|
|
10801
|
-
text:
|
|
10802
|
-
textEn: `This conversation is currently used by a background task ("${owner.title}"). Opening was blocked to prevent concurrent writes.`,
|
|
10881
|
+
text: `该对话正在由后台定时任务使用(「${owner.title}」),为避免并发写入,已停止打开。可在后台任务面板查看进度。`,
|
|
10882
|
+
textEn: `This conversation is currently used by a background scheduled task ("${owner.title}"). Opening was blocked to prevent concurrent writes.`,
|
|
10803
10883
|
});
|
|
10804
10884
|
this.flushSnapshot();
|
|
10805
10885
|
return;
|
|
@@ -10909,6 +10989,7 @@ export class ClientSession {
|
|
|
10909
10989
|
// 计划模式的写类/旁路工具剥离对重开的会话同样生效。下同(forkSession/setCwd)。
|
|
10910
10990
|
this.applyToolGating(conv.session, conv.agentPreset);
|
|
10911
10991
|
this.cwd = targetCwd;
|
|
10992
|
+
this.files.unwatchGit();
|
|
10912
10993
|
// 打开的历史会话可能属于另一个项目 —— 工作区跟随面(roots/文件树/
|
|
10913
10994
|
// 历史列表/命令目录/最近项目)必须跟着切,否则 UI 停在旧项目。
|
|
10914
10995
|
this.applyCwdSideEffects(targetCwd);
|
|
@@ -11174,6 +11255,14 @@ export class ClientSession {
|
|
|
11174
11255
|
if (targetConv.session.isStreaming) {
|
|
11175
11256
|
await targetConv.session.abort();
|
|
11176
11257
|
}
|
|
11258
|
+
// 回滚开始时的会话长度:物理还原前复核,若期间已有新回合写入则跳过还原保新改动(#697)
|
|
11259
|
+
let sessionLenAtRollback = -1;
|
|
11260
|
+
try {
|
|
11261
|
+
sessionLenAtRollback = targetConv.session.agent.state.messages.length;
|
|
11262
|
+
}
|
|
11263
|
+
catch {
|
|
11264
|
+
// best effort
|
|
11265
|
+
}
|
|
11177
11266
|
// 重置分支 leaf 到目标 entry.id
|
|
11178
11267
|
targetConv.session.sessionManager.branch(entry.id);
|
|
11179
11268
|
const branchedContext = targetConv.session.sessionManager.buildSessionContext();
|
|
@@ -11224,18 +11313,35 @@ export class ClientSession {
|
|
|
11224
11313
|
// 查找最贴近该 entry 的快照(按 entryId 或 <= entryTs 的最后一份快照)
|
|
11225
11314
|
const matched = findMatchingWorkspaceSnapshot(targetConv.workspaceSnapshots ?? [], entry.id, entryTs);
|
|
11226
11315
|
if (matched) {
|
|
11227
|
-
|
|
11228
|
-
|
|
11229
|
-
|
|
11316
|
+
let sessionLenNow = -1;
|
|
11317
|
+
try {
|
|
11318
|
+
sessionLenNow = targetConv.session.agent.state.messages.length;
|
|
11230
11319
|
}
|
|
11231
|
-
|
|
11320
|
+
catch {
|
|
11321
|
+
// best effort
|
|
11322
|
+
}
|
|
11323
|
+
if (sessionLenAtRollback >= 0 && sessionLenNow > sessionLenAtRollback) {
|
|
11232
11324
|
this.emit({
|
|
11233
11325
|
type: "notice",
|
|
11234
11326
|
level: "warning",
|
|
11235
|
-
text:
|
|
11236
|
-
textEn:
|
|
11327
|
+
text: "检测到回滚期间已有新对话写入,为保护新改动已跳过工作区物理文件还原(会话历史仍已回滚)。",
|
|
11328
|
+
textEn: "New messages arrived during rollback; skipped workspace file restore to protect new changes (history still rolled back).",
|
|
11237
11329
|
});
|
|
11238
11330
|
}
|
|
11331
|
+
else {
|
|
11332
|
+
const res = await restoreWorkspaceSnapshot(targetConv.cwd, matched.snapshotRef);
|
|
11333
|
+
if (res.success) {
|
|
11334
|
+
workspaceRestored = true;
|
|
11335
|
+
}
|
|
11336
|
+
else {
|
|
11337
|
+
this.emit({
|
|
11338
|
+
type: "notice",
|
|
11339
|
+
level: "warning",
|
|
11340
|
+
text: `会话已回滚,但工作区物理文件还原失败:${res.error}`,
|
|
11341
|
+
textEn: `Session rolled back, but workspace file restore failed: ${res.error}`,
|
|
11342
|
+
});
|
|
11343
|
+
}
|
|
11344
|
+
}
|
|
11239
11345
|
}
|
|
11240
11346
|
else {
|
|
11241
11347
|
this.emit({
|