pi-web-ui 0.100.0 → 0.102.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.
Files changed (82) hide show
  1. package/CHANGELOG.md +53 -1
  2. package/README.md +46 -44
  3. package/README.zh-CN.md +41 -39
  4. package/bin/pi-web-ui.mjs +17 -19
  5. package/dist/server/agent-formatters.js +191 -0
  6. package/dist/server/agent-service-daemon.js +1266 -0
  7. package/dist/server/agent-service.js +9884 -12815
  8. package/dist/server/approval-default-rules.js +158 -0
  9. package/dist/server/approval-rules.js +41 -167
  10. package/dist/server/ask-user-question-tool.js +104 -0
  11. package/dist/server/attachment-store.js +38 -1
  12. package/dist/server/bash-tool.js +83 -0
  13. package/dist/server/browser-page-tool.js +207 -0
  14. package/dist/server/client-id-utils.js +51 -0
  15. package/dist/server/client-state.js +38 -2
  16. package/dist/server/compaction-markers.js +34 -1
  17. package/dist/server/context-budget-runner.js +43 -0
  18. package/dist/server/dangling-tools.js +18 -5
  19. package/dist/server/delegate-mode.js +1 -0
  20. package/dist/server/dispatch-domain-handlers.js +631 -0
  21. package/dist/server/dispatch-plugin-handlers.js +300 -0
  22. package/dist/server/dsh/dsh-agent-service.js +30 -5
  23. package/dist/server/dsh/runtime/goal-rpc.mjs +5 -1
  24. package/dist/server/goal-evidence.js +9 -2
  25. package/dist/server/goal-service.js +1 -1
  26. package/dist/server/hashline-engine.js +1 -1
  27. package/dist/server/index.js +191 -969
  28. package/dist/server/left-panel-running.js +115 -0
  29. package/dist/server/lsp-tool.js +40 -12
  30. package/dist/server/markers-list-tool.js +34 -0
  31. package/dist/server/market-service.js +277 -0
  32. package/dist/server/mcp-bridge.js +137 -30
  33. package/dist/server/mcp-hot-reload.js +84 -27
  34. package/dist/server/mcp-manager.js +215 -0
  35. package/dist/server/message-entry-resolver.js +32 -0
  36. package/dist/server/orphan-manager.js +44 -0
  37. package/dist/server/persona-chain.js +63 -0
  38. package/dist/server/plan-mode.js +2 -0
  39. package/dist/server/plan-update-tool.js +96 -0
  40. package/dist/server/plugin-api-catalog.js +20 -0
  41. package/dist/server/plugin-facilities.js +13 -3
  42. package/dist/server/plugin-installer.js +6 -1
  43. package/dist/server/plugin-ui-slots.js +39 -0
  44. package/dist/server/plugins.js +72 -38
  45. package/dist/server/preset-fields.js +35 -0
  46. package/dist/server/preset-share.js +9 -0
  47. package/dist/server/process-utils.js +30 -0
  48. package/dist/server/prompt-assembler.js +80 -0
  49. package/dist/server/protocol-version.js +1 -1
  50. package/dist/server/scm-commitmsg.js +74 -0
  51. package/dist/server/serialize.js +97 -7
  52. package/dist/server/session-branch.js +367 -0
  53. package/dist/server/session-parser.js +235 -0
  54. package/dist/server/session-search.js +158 -0
  55. package/dist/server/settings-service.js +28 -1
  56. package/dist/server/skill-content-filler.js +33 -0
  57. package/dist/server/subagent-handoff.js +18 -0
  58. package/dist/server/subagent-helpers.js +88 -0
  59. package/dist/server/terminals.js +155 -58
  60. package/dist/server/tool-guards.js +527 -0
  61. package/dist/server/tool-host-factories.js +217 -0
  62. package/dist/server/tool-manager.js +30 -5
  63. package/dist/server/wait-subscription-scan.js +46 -1
  64. package/dist/server/workspace-snapshot.js +18 -0
  65. package/extensions/webui.ts +90 -24
  66. package/package.json +1 -1
  67. package/plugin-sdk/README.md +17 -0
  68. package/plugin-sdk/index.d.ts +17 -0
  69. package/plugin-sdk/index.mjs +5 -0
  70. package/plugins/catalog.json +20 -0
  71. package/themes/aetheris.css +3 -1
  72. package/themes/translucent.css +8 -1
  73. package/themes/transparent.css +9 -1
  74. package/themes/zhupi-dark.css +3 -14
  75. package/themes/zhupi.css +2 -16
  76. package/web/dist/assets/{TerminalPanel-C3I1Mc-C.js → TerminalPanel-CYGOzbPT.js} +1 -1
  77. package/web/dist/assets/index-CP71PHb6.js +680 -0
  78. package/web/dist/assets/index-ytRwL6j0.css +1 -0
  79. package/web/dist/index.html +2 -2
  80. package/web/dist/sw.js +1 -1
  81. package/web/dist/assets/index-B-E2EM_0.css +0 -1
  82. package/web/dist/assets/index-BYumAaGi.js +0 -379
@@ -0,0 +1,158 @@
1
+ /**
2
+ * session-search — 会话转录文件扫描、搜索匹配与锚点收集工具。
3
+ *
4
+ * 负责:
5
+ * - piSessionsRoot: 解析 pi 引擎的会话根目录环境变量
6
+ * - isInsideSessionsDir: 校验路径是否在会话目录下,防止任意文件逃逸
7
+ * - sessionMatchesMetadata / messageSearchText: 会话元数据与转录文本检索
8
+ * - collectSessionAnchors: 扫描消息文本中的查询命中锚点
9
+ * - readCwdFromSessionHeader: 轻量探测转录首行 cwd
10
+ *
11
+ * 从 agent-service.ts 抽出为独立模块。
12
+ */
13
+ import { readFileSync, statSync } from "node:fs";
14
+ import * as fsPromises from "node:fs/promises";
15
+ import { basename, resolve, sep } from "node:path";
16
+ /** 转录全文扫描/整读的大小上限(16MB,与 readHistorySession 一致):
17
+ * 超限文件同步 readFileSync 会卡事件循环数百毫秒起,搜索不值得。 */
18
+ export const MAX_TRANSCRIPT_SCAN_BYTES = 16 * 1024 * 1024;
19
+ /** 转录全文进入内存/缓存的字符上限(256K 字符):全文只服务搜索的命中判定
20
+ * (issue #440 拆分后按需加载),封顶保证单条 worst case 内存可控(缓存 256 条
21
+ * × 256K 字符 ≈ 64MB 上界,且只在搜索活动期间存在)。
22
+ * 影响面:超长转录在截断点之后的内容不参与「是否命中」判定;命中后的消息级
23
+ * 定位(collectSessionAnchors)仍扫全文件,不受此上限影响。 */
24
+ export const MAX_SEARCH_TEXT_CHARS = 256 * 1024;
25
+ /** 会话元数据快速匹配(列表初筛):仅比对 session.name、会话文件名与第一条消息。
26
+ * 显示名、当前项目内的文件名片段、首条消息。
27
+ * 转录全文匹配不在这里:全文单条可达 MB 级,不再随列表缓存常驻(issue #440),
28
+ * 由 filterSessionsForSearch 按需加载后判定(口径不变:user 与 assistant 消息文本)。 */
29
+ export function sessionMatchesMetadata(q, s) {
30
+ if (s.name && s.name.toLowerCase().includes(q))
31
+ return true;
32
+ if (basename(s.path).toLowerCase().includes(q))
33
+ return true;
34
+ if (s.firstMessage.toLowerCase().includes(q))
35
+ return true;
36
+ return false;
37
+ }
38
+ /** 抽取一条 AgentMessage 的可搜索文本(user/assistant 的 text 块;
39
+ * 镜像 SDK buildSessionInfo 的 allMessagesText 范围,保证搜索与定位一致)。 */
40
+ export function messageSearchText(m) {
41
+ const c = m.content;
42
+ if (typeof c === "string")
43
+ return c;
44
+ if (!Array.isArray(c))
45
+ return "";
46
+ const parts = [];
47
+ for (const b of c) {
48
+ if (!b || typeof b !== "object")
49
+ continue;
50
+ const blk = b;
51
+ if (blk.type === "text" && typeof blk.text === "string")
52
+ parts.push(blk.text);
53
+ }
54
+ return parts.join("\n");
55
+ }
56
+ /** 扫描一个会话转录文件,收集文本命中查询的消息锚点(role + timestamp,
57
+ * 按转录顺序,最多 cap 个)。仅 user/assistant 消息参与,与搜索范围一致。
58
+ * 超过大小上限的转录直接跳过(stat 先行,不整读)—— 全局搜索逐会话同步
59
+ * 扫描,无上限时一个大转录就能冻住整个事件循环。 */
60
+ export function collectSessionAnchors(filePath, q, cap = 10) {
61
+ const anchors = [];
62
+ if (!q)
63
+ return anchors;
64
+ try {
65
+ if (statSync(filePath).size > MAX_TRANSCRIPT_SCAN_BYTES)
66
+ return anchors;
67
+ const lines = readFileSync(filePath, "utf8").split("\n");
68
+ for (const line of lines) {
69
+ if (!line.trim())
70
+ continue;
71
+ let e;
72
+ try {
73
+ e = JSON.parse(line);
74
+ }
75
+ catch {
76
+ continue;
77
+ }
78
+ if (e?.type !== "message")
79
+ continue;
80
+ const m = e.message;
81
+ if (!m)
82
+ continue;
83
+ if (m.role !== "user" && m.role !== "assistant")
84
+ continue;
85
+ if (typeof m.timestamp !== "number")
86
+ continue;
87
+ const text = messageSearchText(m);
88
+ if (!text || !text.toLowerCase().includes(q))
89
+ continue;
90
+ anchors.push({ role: m.role, timestamp: m.timestamp });
91
+ if (anchors.length >= cap)
92
+ break;
93
+ }
94
+ }
95
+ catch {
96
+ // 单个转录损坏不影响其余会话
97
+ }
98
+ return anchors;
99
+ }
100
+ /**
101
+ * pi 的会话存储根目录。设置了 `PI_CODING_AGENT_SESSION_DIR` 时,pi 将 transcript
102
+ * 以**扁平布局**直接写在根目录顶层(`<root>/<timestamp>_<uuid>.jsonl`,所属 cwd 是
103
+ * 文件内字段);未设置时走 SDK 默认的 `<agentDir>/sessions/--<cwd>--/` 每-cwd
104
+ * 子目录布局(此时必须**不传** sessionDir,让 SDK 落回默认路径)。
105
+ *
106
+ * 注意:未设置 env 时**不要**回退返回 `join(getAgentDir(), "sessions")`——那样会把
107
+ * 根目录强塞给 SDK `list()/listAll()`,它们只会扫根目录**顶层** jsonl,默认子目录布局
108
+ * 下顶层为空,历史对话/最近项目会全丢(回归风险,已在 0.84.4 实证)。
109
+ */
110
+ export function piSessionsRoot() {
111
+ return process.env.PI_CODING_AGENT_SESSION_DIR || undefined;
112
+ }
113
+ /** Guardrail: only transcripts under a sessions root may be opened/deleted/renamed
114
+ * — never arbitrary files. Two roots count as “a sessions root”, and they must stay
115
+ * the **same two** the history list reads from (`loadSessionInfos` →
116
+ * `SessionManager.list(cwd, piSessionsRoot())`):
117
+ *
118
+ * 1. `<agentDir>/sessions/`(SDK 默认的每-cwd 子目录布局)
119
+ * 2. `PI_CODING_AGENT_SESSION_DIR`(扁平「额外会话根」,设了就以它为准扫盘)
120
+ *
121
+ * 只认第 1 条会让设了该变量的用户「历史列得出来、却点不开/删不掉/改不了名」
122
+ * (列表与打开两边口径不一致)。守卫的意图是「不许开任意文件」,不是「只许开
123
+ * 默认目录下的文件」,所以放宽到两个根仍然成立。
124
+ * Shared by deleteSession/renameSession/switchSession so the open path cannot
125
+ * escape the confinement the write paths already enforce. */
126
+ export function isInsideSessionsDir(agentDir, targetPath) {
127
+ const abs = resolve(targetPath);
128
+ const roots = [resolve(agentDir, "sessions")];
129
+ const extra = piSessionsRoot();
130
+ if (extra)
131
+ roots.push(resolve(extra));
132
+ return roots.some((root) => abs.startsWith(root + sep));
133
+ }
134
+ /**
135
+ * 从会话文件首行读取 cwd(轻量探测,最多读取 2KB,绝不完整解析整个 jsonl 消息历史)。
136
+ */
137
+ export async function readCwdFromSessionHeader(filePath) {
138
+ let handle;
139
+ try {
140
+ handle = await fsPromises.open(filePath, "r");
141
+ const buf = Buffer.alloc(2048);
142
+ const { bytesRead } = await handle.read(buf, 0, 2048, 0);
143
+ const text = buf.toString("utf8", 0, bytesRead);
144
+ const nl = text.indexOf("\n");
145
+ const firstLine = nl !== -1 ? text.slice(0, nl) : text;
146
+ if (!firstLine.trim())
147
+ return null;
148
+ const parsed = JSON.parse(firstLine);
149
+ return typeof parsed.cwd === "string" && parsed.cwd.trim() ? parsed.cwd : null;
150
+ }
151
+ catch {
152
+ return null;
153
+ }
154
+ finally {
155
+ if (handle)
156
+ await handle.close().catch(() => { });
157
+ }
158
+ }
@@ -9,7 +9,7 @@
9
9
  import { existsSync, readdirSync, readFileSync } from "node:fs";
10
10
  import { basename, dirname, join } from "node:path";
11
11
  import { fileURLToPath } from "node:url";
12
- import { extensionKey, normalizeBgCleanupMinutes, normalizeDisabledPluginTools, normalizeRetryMaxAttempts, normalizeSkillList, normalizeToolWatchdogTimeoutMs, normalizeUiLayout, settingsPresetToUi, } from "./client-state.js";
12
+ import { extensionKey, normalizeBgCleanupMinutes, normalizeDisabledPluginTools, normalizeRetryMaxAttempts, normalizeKeepRecentMessages, normalizeSkillList, normalizeToolWatchdogTimeoutMs, normalizeUiLayout, settingsPresetToUi, } from "./client-state.js";
13
13
  import { normalizeSoftCapByModel, normalizeSoftCapTokens } from "./soft-cap.js";
14
14
  import { findVisionModels, SYSTEM_PROMPT } from "./vision-bridge.js";
15
15
  import { COMMITMSG_SYSTEM_PROMPT } from "./scm-commitmsg.js";
@@ -279,6 +279,11 @@ export class SettingsService {
279
279
  const legacyTools = deriveLegacy(this.settings.disabledAgentTools ?? []);
280
280
  // 当前会话提示词快照:完整生效文本 + 各来源默认(自动)内容(只读预览)。
281
281
  const promptSnap = this.host.promptSnapshot();
282
+ const mcp = this.host.getMcpServers?.() ?? {
283
+ servers: [],
284
+ globalPath: "",
285
+ projectPath: "",
286
+ };
282
287
  this.host.emit({
283
288
  type: "settings_state",
284
289
  settings: {
@@ -297,6 +302,8 @@ export class SettingsService {
297
302
  readDirEnabled: this.settings.readDirEnabled !== false,
298
303
  bgAutoCleanupMin: normalizeBgCleanupMinutes(this.settings.bgAutoCleanupMin),
299
304
  toolLazyLoading: this.settings.toolLazyLoading !== false,
305
+ codemodeMode: this.settings.codemodeMode ?? "on",
306
+ codemodeInlineBudget: this.settings.codemodeInlineBudget ?? 3000,
300
307
  toolApprovalEnabled: this.settings.toolApprovalEnabled !== false,
301
308
  approvalPolicy: this.host.getApprovalPolicy?.() ?? { allowAll: false, categories: [] },
302
309
  approvalRules: this.approvalRules?.list() ?? [],
@@ -309,6 +316,7 @@ export class SettingsService {
309
316
  thinkingWrap: this.settings.thinkingWrap,
310
317
  toolsWrap: this.settings.toolsWrap,
311
318
  toolImagesEnabled: this.settings.toolImagesEnabled ?? true,
319
+ keepRecentMessages: normalizeKeepRecentMessages(this.settings.keepRecentMessages),
312
320
  visionBridgeEnabled: this.settings.visionBridgeEnabled,
313
321
  visionBridgeModel: this.settings.visionBridgeModel,
314
322
  visionBridgePromptMode: this.settings.visionBridgePromptMode,
@@ -355,6 +363,9 @@ export class SettingsService {
355
363
  quickPhrases: [...this.settings.quickPhrases],
356
364
  quickPhrasesEnabled: this.settings.quickPhrasesEnabled,
357
365
  quickPhrasesSeeded: this.host.stateStore.getQuickPhrasesSeeded(),
366
+ mcpServers: mcp.servers,
367
+ mcpGlobalConfigPath: mcp.globalPath,
368
+ mcpProjectConfigPath: mcp.projectPath,
358
369
  },
359
370
  });
360
371
  }
@@ -508,6 +519,19 @@ export class SettingsService {
508
519
  if (partial.toolLazyLoading !== undefined) {
509
520
  this.settings.toolLazyLoading = partial.toolLazyLoading !== false;
510
521
  }
522
+ let codemodeChanged = false;
523
+ if (partial.codemodeMode !== undefined && partial.codemodeMode !== this.settings.codemodeMode) {
524
+ this.settings.codemodeMode = partial.codemodeMode;
525
+ codemodeChanged = true;
526
+ }
527
+ if (partial.codemodeInlineBudget !== undefined &&
528
+ partial.codemodeInlineBudget !== this.settings.codemodeInlineBudget) {
529
+ this.settings.codemodeInlineBudget = partial.codemodeInlineBudget;
530
+ codemodeChanged = true;
531
+ }
532
+ if (codemodeChanged) {
533
+ this.host.applyCodemodeOverrides?.();
534
+ }
511
535
  // 工具执行审批总开关:审批入口每次实时读取(askApproval 顶部门禁),无需 reload。
512
536
  if (partial.toolApprovalEnabled !== undefined) {
513
537
  this.settings.toolApprovalEnabled = partial.toolApprovalEnabled;
@@ -539,6 +563,9 @@ export class SettingsService {
539
563
  if (partial.toolImagesEnabled !== undefined) {
540
564
  this.settings.toolImagesEnabled = partial.toolImagesEnabled;
541
565
  }
566
+ if (partial.keepRecentMessages !== undefined) {
567
+ this.settings.keepRecentMessages = normalizeKeepRecentMessages(partial.keepRecentMessages);
568
+ }
542
569
  // 编排模式 / skill 全文注入:before_agent_start 逐 run 实时读取(agent-service
543
570
  // composeInputs + 指导块追加),开关下一轮即生效,无需 reload runtime。
544
571
  if (partial.skillsFullText !== undefined) {
@@ -0,0 +1,33 @@
1
+ /**
2
+ * skill-content-filler — 技能全文注入({{skills}} 全文模式)内容填充器。
3
+ *
4
+ * 负责读取名单里技能的文件正文。
5
+ * 单文件 8KB、总量 32KB 封顶,失败/超限/不在名单回落名录(无 content)。
6
+ * 名单为空时零开销:原样返回,不碰磁盘。
7
+ *
8
+ * 从 agent-service.ts 抽出为独立模块。
9
+ */
10
+ import { readFileSync, statSync } from "node:fs";
11
+ import { decodeText } from "./text-sniff.js";
12
+ import { normalizeSkillList } from "./client-state.js";
13
+ export function fillSkillContents(skills, skillsFullTextConfig) {
14
+ const wanted = new Set(normalizeSkillList(skillsFullTextConfig));
15
+ if (wanted.size === 0)
16
+ return skills;
17
+ let budget = 32 * 1024;
18
+ return skills.map((s) => {
19
+ if (!wanted.has(s.name) || !s.filePath || budget <= 0)
20
+ return s;
21
+ try {
22
+ const st = statSync(s.filePath);
23
+ if (!st.isFile() || st.size <= 0 || st.size > 8192)
24
+ return s;
25
+ const raw = decodeText(readFileSync(s.filePath).subarray(0, Math.min(st.size, budget))).trim();
26
+ budget -= raw.length;
27
+ return raw ? { ...s, content: raw } : s;
28
+ }
29
+ catch {
30
+ return s;
31
+ }
32
+ });
33
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * subagent-handoff — 子代理对等直接交接消息格式化与历史记录工具。
3
+ *
4
+ * 负责:
5
+ * - formatSubagentHandoffMessage: 格式化带角色与源 ID 的交接指令
6
+ * - recordSubagentHandoff: 维护限制容量的交接历史时间戳队列
7
+ *
8
+ * 从 agent-service.ts 抽出为独立模块。
9
+ */
10
+ /** 格式化对等交接注入给目标子代理的消息 */
11
+ export function formatSubagentHandoffMessage(fromType, fromRunId, payload) {
12
+ return `[Peer Hand-off from ${fromType} subagent (${fromRunId.slice(0, 8)})]:\n\n${payload}`;
13
+ }
14
+ /** 追加交接记录并维持最近 N 条的滑动窗口 */
15
+ export function recordSubagentHandoff(history, record, maxHistory = 50) {
16
+ const next = [...history, record];
17
+ return next.length > maxHistory ? next.slice(-maxHistory) : next;
18
+ }
@@ -0,0 +1,88 @@
1
+ import { SUBAGENT_PROMPT_SNAPSHOT_CAP } from "./agent-formatters.js";
2
+ /** 子代理最近一次运行的结局:最后一条 assistant 消息的 errorMessage / stopReason。
3
+ * 报错 > 中止 > 正常,三者互斥;无 assistant 消息时返回空。 */
4
+ export function subagentRunOutcome(conv) {
5
+ // 自动重试等待期结局未定:瞬时 error 不算失败,避免向主对话误报
6
+ // 「子代理运行失败」(耗尽后 auto_retry_end 清旗,真正失败照常通知)。
7
+ if (conv.retryState)
8
+ return {};
9
+ try {
10
+ const msgs = conv.session.agent.state.messages;
11
+ for (let i = msgs.length - 1; i >= 0; i--) {
12
+ const m = msgs[i];
13
+ if (m.role !== "assistant")
14
+ continue;
15
+ const err = m.errorMessage;
16
+ if (typeof err === "string" && err.trim()) {
17
+ return { error: err.trim() };
18
+ }
19
+ const stop = m.stopReason;
20
+ if (stop === "aborted" || stop === "cancelled") {
21
+ return { canceled: true };
22
+ }
23
+ break;
24
+ }
25
+ }
26
+ catch {
27
+ // session being replaced — treat as no outcome yet
28
+ }
29
+ return {};
30
+ }
31
+ /** 对话结局 → 角色轮结局(报错 > 中止 > 正常)。 */
32
+ export function roleOutcomeOf(conv) {
33
+ const { error, canceled } = subagentRunOutcome(conv);
34
+ if (error)
35
+ return "error";
36
+ if (canceled)
37
+ return "canceled";
38
+ return "done";
39
+ }
40
+ /** 序列化对话为前端可消费的子代理快照 */
41
+ export function toSubagentSnapshot(conv) {
42
+ const streaming = conv.session.isStreaming;
43
+ const { error, canceled } = subagentRunOutcome(conv);
44
+ const state = streaming ? "running" : canceled ? "canceled" : "done";
45
+ let messageCount = 0;
46
+ try {
47
+ messageCount = conv.session.getSessionStats().totalMessages;
48
+ }
49
+ catch {
50
+ // session being replaced — report defaults
51
+ }
52
+ const fullPrompt = conv.subagentPrompt ?? "";
53
+ const sm = conv.session.sessionManager;
54
+ const isPersisted = !conv.isSubagent || (typeof sm?.isPersisted === "function" && sm.isPersisted());
55
+ return {
56
+ convId: conv.id,
57
+ type: conv.subagentType ?? "general",
58
+ title: conv.title,
59
+ prompt: fullPrompt.length > SUBAGENT_PROMPT_SNAPSHOT_CAP
60
+ ? `${fullPrompt.slice(0, SUBAGENT_PROMPT_SNAPSHOT_CAP)}\n… [truncated]`
61
+ : fullPrompt,
62
+ state,
63
+ streaming,
64
+ error,
65
+ canceled,
66
+ messageCount,
67
+ model: conv.session.model?.id,
68
+ output: conv.session.getLastAssistantText() ?? "",
69
+ parentId: conv.parentId,
70
+ persisted: isPersisted,
71
+ handoffTo: conv.peerHandoffTo ? [...conv.peerHandoffTo] : undefined,
72
+ handoffFrom: conv.peerHandoffFrom ? [...conv.peerHandoffFrom] : undefined,
73
+ };
74
+ }
75
+ /** 列举并排序子代理快照集合 */
76
+ export function listSubagentSnapshots(convs, scope) {
77
+ return [...convs]
78
+ .filter((c) => {
79
+ const isPersisted = !c.isSubagent;
80
+ if (scope === "subagent")
81
+ return c.isSubagent;
82
+ if (scope === "persistent")
83
+ return isPersisted;
84
+ return c.isSubagent || Boolean(c.parentId) || Boolean(c.subagentPrompt);
85
+ })
86
+ .sort((a, b) => a.createdAt - b.createdAt)
87
+ .map((c) => toSubagentSnapshot(c));
88
+ }