personal-bot 0.2.18 → 0.2.20

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.
@@ -6,12 +6,12 @@
6
6
  "plugins": [
7
7
  {
8
8
  "name": "personal-bot",
9
- "version": "0.2.18",
9
+ "version": "0.2.20",
10
10
  "description": "Workspace materials, skills, and native experts.",
11
11
  "source": {
12
12
  "source": "npm",
13
13
  "package": "personal-bot",
14
- "version": "0.2.18"
14
+ "version": "0.2.20"
15
15
  }
16
16
  }
17
17
  ]
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "personal-bot",
3
- "version": "0.2.18",
3
+ "version": "0.2.20",
4
4
  "description": "Workspace materials, skills, and native experts.",
5
5
  "skills": [
6
6
  "./resources/skills",
package/README.md CHANGED
@@ -152,7 +152,7 @@ Use `pi --resume` to select the main session explicitly; `pi --continue` can sel
152
152
  | Location | Purpose |
153
153
  | --- | --- |
154
154
  | `.pbot/config.json` | Shared Pi/dsh/Claude workspace activation and configuration |
155
- | `AGENTS.md` | Navigation and working agreements |
155
+ | `AGENTS.md` | Project index by directory name and familiar terms, links to other materials, and working agreements |
156
156
  | `areas/`, `projects/` | Long-term goals, tasks, conclusions, and deliverables |
157
157
  | `knowledge/` | Reusable concepts, methods, and analysis definitions |
158
158
  | `.pbot/history/` | Pi/dsh original exchanges in `raw/` and derived summaries in `summary/`; preserved Claude archives |
@@ -165,7 +165,7 @@ Existing layouts and agreements take precedence. Fetch queryable data when neede
165
165
 
166
166
  ## Updates and operating scope
167
167
 
168
- Current release: **0.2.18**. Update through the host's native package manager. For a local Pi source, update the checkout, run `npm ci --ignore-scripts` when dependencies change, then reload or restart. Stop active specialists before changing versions. Recreate specialists across compatibility lines; existing materials, history, and backups are preserved.
168
+ Current release: **0.2.20**. Update through the host's native package manager. For a local Pi source, update the checkout, run `npm ci --ignore-scripts` when dependencies change, then reload or restart. Stop active specialists before changing versions. Recreate specialists across compatibility lines; existing materials, history, and backups are preserved.
169
169
 
170
170
  Operations follow the user's request, existing agreements, and required confirmations. Bash, Python, MCP, and extensions use the actual account and credential permissions. Enforce hard limits through read-only credentials, service controls, or restricted environments. Trades, transfers, and ledger changes require authorization for those operations. After cancellation, timeout, or disconnection, query native status before retrying to avoid duplicate execution.
171
171
 
package/README.zh-CN.md CHANGED
@@ -152,7 +152,7 @@ Pi 主会话恢复用 `pi --resume` 明确选择;`pi --continue` 可能选中
152
152
  | 位置 | 用途 |
153
153
  | --- | --- |
154
154
  | `.pbot/config.json` | Pi/dsh/Claude 共用的工作区启用与配置 |
155
- | `AGENTS.md` | 资料导航与工作约定 |
155
+ | `AGENTS.md` | 项目速查(目录名与常用称呼)、其他资料入口和工作约定 |
156
156
  | `areas/`、`projects/` | 长期目标、任务、结论与交付物 |
157
157
  | `knowledge/` | 可复用的概念、方法与口径 |
158
158
  | `.pbot/history/` | Pi/dsh 的 `raw/` 保存原始问答,`summary/` 保存派生摘要;既有 Claude 归档保留 |
@@ -165,7 +165,7 @@ Pi 主会话恢复用 `pi --resume` 明确选择;`pi --continue` 可能选中
165
165
 
166
166
  ## 更新与操作范围
167
167
 
168
- 当前版本为 **0.2.18**。通过宿主原生包管理更新;本地 Pi 来源更新源码,依赖变化后运行 `npm ci --ignore-scripts`,再重载或重启。更换版本前停止活动专家;不同兼容线的专家需重新创建,旧资料、历史和备份保留。
168
+ 当前版本为 **0.2.20**。通过宿主原生包管理更新;本地 Pi 来源更新源码,依赖变化后运行 `npm ci --ignore-scripts`,再重载或重启。更换版本前停止活动专家;不同兼容线的专家需重新创建,旧资料、历史和备份保留。
169
169
 
170
170
  操作按用户请求、已有约定和必要确认执行。Bash、Python、MCP 和扩展使用实际账户与凭据权限;硬限制应由只读凭据、服务端控制或受限环境提供。交易、转账和账本修改需要相应授权。取消、超时或断连后,先查原生状态再决定是否重试,避免重复执行。
171
171
 
package/docs/history.md CHANGED
@@ -19,7 +19,9 @@ Claude 标准插件使用原生会话与恢复功能,不提供 pbot 历史查
19
19
 
20
20
  Pi 通过 SDK 读取当前会话目录、原生默认目录、当前会话,以及本工作区受管专家的原生引用,按 sessionId 关联已有归档。不在发现范围的会话可通过 Pi 打开并加载 pbot 重新关联。Pi 分配文件名后、首条消息落盘前,文件可以不存在;扫描静默跳过这种空会话。不会扫描旧版 pbot 私有会话布局。
21
21
 
22
- dsh 通过公开 SessionQuery 冷读本工作区根会话与按父关系关联的专家;专家 cwd 不同仍按父归属收录,同目录但属于其他工作区父会话的专家不混入。普通 fork 可以收录。读取不创建 Agent、不恢复会话、不修改原生记录,也不从私有请求日志推断对话。
22
+ dsh 通过公开 SessionQuery 冷读本工作区根会话、普通 fork 和按父关系关联的原生专家。原生专家即使 cwd 不同也按父会话归属收录。专家引用只用于定位仍存在的 dsh 会话。读取不创建 Agent、不恢复会话、不修改原生记录,也不从私有请求日志推断对话。
23
+
24
+ Pi 和 dsh 都按 ACP 成员记录中的目标宿主和实际 `sessionId` 排除该成员的独立会话,包括在工作区根目录启动的成员。已归档的成员问答和摘要保留在磁盘上,刷新后从查询和后续摘要整理中隐藏。识别依赖本机可读的 Pi 或 dsh 成员控制记录,单独复制历史归档时需考虑这一条件。
23
25
 
24
26
  用户输入到有效最终答复组成问答,回答前的人工补充输入保留在同一问答。dsh 的协调者委派输入也保留来源;通知和团队背景不会被当作新的用户问题。工具调用、工具结果和推理不进入问答。中断、截断、缺少正常结束或尚未回答的记录保留为未完成。dsh 必须有持久化的正常 stop 才能确认完成;工具文本和 idle 状态不代替最终回答。
25
27
 
@@ -94,7 +94,7 @@ Claude 根插件静态声明共用 skills、管理技能与 Markdown 原生专
94
94
 
95
95
  ## 历史查询
96
96
 
97
- Pi、dsh 的 HistoryService 各接收一个写来源和显式只读的其他来源。`indexHistory` 只合并原生问答与分支;观察到的后缀保留已有前缀,缺失来源不删除归档。查询视图把问答与独立保存的分层摘要组合起来,按已知分支规划四叉分组,补出会话根和反向导航。旧混合归档提供的摘要链接继续可查,但不作为原生分支证据。Claude 归档只读。布局见[文件存储](file-storage.md#历史索引)。
97
+ Pi、dsh 的 HistoryService 各接收一个写来源和显式只读的其他来源。每次刷新从 Pi 和 dsh 控制目录的 `acp-session.json` 读取 `(backend, sessionId)`,在发现原生会话时跳过已识别的 ACP 成员。扫描结束后重读引用,再过滤索引输入和各来源的归档视图,以覆盖扫描期间刚收到首条输入的成员。后台选择摘要任务时使用同一身份规则。`indexHistory` 只合并原生问答与分支;观察到的后缀保留已有前缀,缺失来源不删除归档。查询视图把问答与独立保存的分层摘要组合起来,按已知分支规划四叉分组,补出会话根和反向导航。旧混合归档提供的摘要链接继续可查,但不作为原生分支证据。Claude 归档只读。布局见[文件存储](file-storage.md#历史索引)。
98
98
 
99
99
  扫描与模型调用在来源短写锁外。索引提交时重读原始归档并比较扫描前的内容;若原文确有修订,先使依赖它的摘要及其上级失效,再发布修订后的问答。摘要提交持同一短锁,重读最新资料,逐项核对目标、子节点顺序和精确输入,检查取消信号,仅写派生文件。不可读的原始归档阻止为未识别会话另分配根 ID;单独的摘要文件损坏不阻止问答查询。查询不调用模型,后台整理触发时机见[历史对话](history.md)。
100
100
 
@@ -1,6 +1,7 @@
1
1
  import { join } from "node:path";
2
2
  import { dshHomePath } from "@deepseek-ai/dsh-home-paths";
3
3
  import { AgentFiles } from "../../storage/agent-files.js";
4
+ import { acpHistorySessions } from "../../storage/acp-history.js";
4
5
  import { HistoryFiles } from "../../storage/history-files.js";
5
6
  import { HistoryService } from "../../services/history/history-service.js";
6
7
  import { DshHistory } from "../../integrations/dsh/history.js";
@@ -17,7 +18,7 @@ export class DshHistoryWork {
17
18
  constructor(ctx, root) {
18
19
  this.ctx = ctx;
19
20
  const agents = new AgentFiles(dshHomePath("pbot", "subagents"), "dsh");
20
- this.service = new HistoryService(root, new HistoryFiles(join(root, ".pbot/history"), "dsh"), new DshHistory(ctx, root, () => agents.list().filter(value => value.workspace === root).map(value => value.agentId)), [new HistoryFiles(join(root, ".pbot/history"), "pi"), new HistoryFiles(join(root, ".pbot/history"), "claude")]);
21
+ this.service = new HistoryService(root, new HistoryFiles(join(root, ".pbot/history"), "dsh"), new DshHistory(ctx, root, () => agents.list().filter(value => value.workspace === root).map(value => value.agentId)), [new HistoryFiles(join(root, ".pbot/history"), "pi"), new HistoryFiles(join(root, ".pbot/history"), "claude")], () => acpHistorySessions({ dsh: agents.root }));
21
22
  }
22
23
  attach(agent) { this.#parents.add(agent); return () => { this.#parents.delete(agent); }; }
23
24
  cancel() { this.#controller?.abort(); }
@@ -9,7 +9,7 @@ export declare class DshHistory implements HistorySource {
9
9
  private readonly relatedSessions;
10
10
  readonly host = "dsh";
11
11
  constructor(ctx: Context, root: string, relatedSessions?: () => string[]);
12
- scan(location: HistoryLocation, signal?: AbortSignal): Promise<{
12
+ scan(location: HistoryLocation, signal?: AbortSignal, excluded?: ReadonlySet<string>): Promise<{
13
13
  sessions: HistorySession[];
14
14
  warnings: string[];
15
15
  }>;
@@ -105,18 +105,22 @@ export class DshHistory {
105
105
  this.root = root;
106
106
  this.relatedSessions = relatedSessions;
107
107
  }
108
- async scan(location, signal) {
108
+ async scan(location, signal, excluded) {
109
109
  requireThat(location.host === "dsh", "dsh 历史只读取 dsh 原生会话。");
110
110
  signal?.throwIfAborted();
111
- const records = await this.ctx.sessionQuery.listSessions(signal), selected = new Set(), warnings = [];
111
+ const records = (await this.ctx.sessionQuery.listSessions(signal)).filter(record => !excluded?.has(record.header.id));
112
+ const selected = new Set(), warnings = [];
113
+ // Expert records also name ACP members and sessions that dsh no longer stores; only real dsh sessions are readable.
114
+ const stored = new Set(records.map(record => record.header.id));
112
115
  try {
113
116
  for (const id of this.relatedSessions())
114
- selected.add(id);
117
+ if (stored.has(id))
118
+ selected.add(id);
115
119
  }
116
120
  catch (error) {
117
121
  warnings.push("专家引用:" + String(error));
118
122
  }
119
- if (location.sessionId)
123
+ if (location.sessionId && !excluded?.has(location.sessionId))
120
124
  selected.add(location.sessionId);
121
125
  for (const record of records) {
122
126
  signal?.throwIfAborted();
@@ -57,7 +57,7 @@ export type HistoryLocation = {
57
57
  };
58
58
  export interface HistorySource {
59
59
  readonly host: HistoryLocation["host"];
60
- scan(location: HistoryLocation, signal?: AbortSignal): Promise<{
60
+ scan(location: HistoryLocation, signal?: AbortSignal, excluded?: ReadonlySet<string>): Promise<{
61
61
  sessions: HistorySession[];
62
62
  warnings: string[];
63
63
  }>;
@@ -18,7 +18,11 @@ export declare class HistoryService {
18
18
  private readonly files;
19
19
  private readonly source;
20
20
  private readonly otherFiles;
21
- constructor(root: string, files: HistoryFiles, source: HistorySource, otherFiles?: readonly HistoryReader[]);
21
+ private readonly acpSessions?;
22
+ constructor(root: string, files: HistoryFiles, source: HistorySource, otherFiles?: readonly HistoryReader[], acpSessions?: (() => {
23
+ ids: Record<HistoryHost, ReadonlySet<string>>;
24
+ warnings: string[];
25
+ }) | undefined);
22
26
  check(): void;
23
27
  get warnings(): string[];
24
28
  get status(): {
@@ -49,6 +49,7 @@ export class HistoryService {
49
49
  files;
50
50
  source;
51
51
  otherFiles;
52
+ acpSessions;
52
53
  #records = [];
53
54
  #closed = false;
54
55
  #loaded = false;
@@ -57,11 +58,12 @@ export class HistoryService {
57
58
  #controller = new AbortController();
58
59
  #sourceWarnings = [];
59
60
  #summaryError;
60
- constructor(root, files, source, otherFiles = []) {
61
+ constructor(root, files, source, otherFiles = [], acpSessions) {
61
62
  this.root = root;
62
63
  this.files = files;
63
64
  this.source = source;
64
65
  this.otherFiles = otherFiles;
66
+ this.acpSessions = acpSessions;
65
67
  requireThat((source.host === "pi" || source.host === "dsh") && source.host === files.host &&
66
68
  new Set([files.host, ...otherFiles.map(value => value.host)]).size === otherFiles.length + 1, "历史来源与归档目录不匹配。");
67
69
  }
@@ -88,7 +90,7 @@ export class HistoryService {
88
90
  signal?.throwIfAborted();
89
91
  const warnings = [], records = [];
90
92
  const warning = (host, error) => { this.check(); signal?.throwIfAborted(); warnings.push(host + ": " + String(error)); };
91
- let known = [];
93
+ let known = [], sessions = [];
92
94
  try {
93
95
  try {
94
96
  this.files.migrate(this.root);
@@ -96,19 +98,25 @@ export class HistoryService {
96
98
  finally {
97
99
  known = this.files.list(this.root);
98
100
  }
99
- const before = new Map(known.map(({ raw }) => [raw.sessionId, raw]));
100
- let sessions = [];
101
- try {
102
- const scanned = await this.source.scan(location, signal);
103
- sessions = scanned.sessions;
104
- warnings.push(...scanned.warnings.map(value => this.files.host + ": " + value));
105
- }
106
- catch (error) {
107
- warning(this.files.host, error);
108
- }
109
- this.check();
110
- signal?.throwIfAborted();
101
+ const scanned = await this.source.scan(location, signal, this.acpSessions?.().ids[this.files.host]);
102
+ sessions = scanned.sessions;
103
+ warnings.push(...scanned.warnings.map(value => this.files.host + ": " + value));
104
+ }
105
+ catch (error) {
106
+ warning(this.files.host, error);
107
+ }
108
+ this.check();
109
+ signal?.throwIfAborted();
110
+ // The worker binds the actual backend ID before delivery, possibly during the native scan.
111
+ const excluded = this.acpSessions?.();
112
+ if (excluded) {
113
+ warnings.push(...excluded.warnings);
114
+ sessions = sessions.filter(session => !excluded.ids[this.files.host].has(session.sessionId));
115
+ }
116
+ const visible = ({ raw }) => !excluded?.ids[raw.host].has(raw.sessionId);
117
+ try {
111
118
  if (sessions.length) {
119
+ const before = new Map(known.map(({ raw }) => [raw.sessionId, raw]));
112
120
  known = this.files.control(() => {
113
121
  this.check();
114
122
  signal?.throwIfAborted();
@@ -141,10 +149,10 @@ export class HistoryService {
141
149
  catch (error) {
142
150
  warning(this.files.host, error);
143
151
  }
144
- records.push(...known.map(view));
152
+ records.push(...known.filter(visible).map(view));
145
153
  for (const files of this.otherFiles) {
146
154
  try {
147
- records.push(...files.list(this.root).map(view));
155
+ records.push(...files.list(this.root).filter(visible).map(view));
148
156
  }
149
157
  catch (error) {
150
158
  warning(files.host, error);
@@ -200,7 +208,8 @@ export class HistoryService {
200
208
  for (;;) {
201
209
  this.check();
202
210
  active.throwIfAborted();
203
- const pending = nextSummary(this.files.list());
211
+ const archives = this.files.list(), excluded = this.acpSessions?.().ids[this.files.host];
212
+ const pending = nextSummary(archives.filter(({ raw }) => !excluded?.has(raw.sessionId)));
204
213
  if (!pending)
205
214
  return;
206
215
  const { record, node, children } = pending;
@@ -0,0 +1,9 @@
1
+ import type { HistoryHost } from "../model/history.js";
2
+ /** A target session can be owned by either coordinator, even when its cwd belongs to another workspace. */
3
+ export declare function acpHistorySessions(directories: {
4
+ pi?: string;
5
+ dsh?: string;
6
+ }): {
7
+ ids: Record<HistoryHost, Set<string>>;
8
+ warnings: string[];
9
+ };
@@ -0,0 +1,45 @@
1
+ import { readdirSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { join } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { readJsonFile } from "./atomic-json.js";
6
+ import { acpReference } from "./acp-files.js";
7
+ function memberDirectory(home, host) {
8
+ if (host === "pi" && home.startsWith("file://"))
9
+ return join(fileURLToPath(home), "pbot/subagents");
10
+ const tilde = home === "~" || home.startsWith("~/") || ((host === "dsh" || process.platform === "win32") && home.startsWith("~\\"));
11
+ return join(tilde ? join(homedir(), home.slice(2)) : home, "pbot/subagents");
12
+ }
13
+ /** A target session can be owned by either coordinator, even when its cwd belongs to another workspace. */
14
+ export function acpHistorySessions(directories) {
15
+ const ids = { pi: new Set(), dsh: new Set(), claude: new Set() };
16
+ const warnings = [];
17
+ const warn = (path, error) => {
18
+ if (error.code !== "ENOENT")
19
+ warnings.push(path + ": " + String(error));
20
+ };
21
+ const homes = { pi: process.env.PI_CODING_AGENT_DIR || "~/.pi/agent", dsh: process.env.DSH_HOME?.trim() ? process.env.DSH_HOME : "~/.dsh" };
22
+ for (const host of ["pi", "dsh"]) {
23
+ let directory = directories[host];
24
+ try {
25
+ directory ??= memberDirectory(homes[host], host);
26
+ for (const entry of readdirSync(directory, { withFileTypes: true })) {
27
+ if (!entry.isDirectory() || entry.name.startsWith("."))
28
+ continue;
29
+ const path = join(directory, entry.name);
30
+ try {
31
+ const ref = readJsonFile(path, "acp-session.json", acpReference);
32
+ if (ref.sessionId !== null)
33
+ ids[ref.backend].add(ref.sessionId);
34
+ }
35
+ catch (error) {
36
+ warn(path, error);
37
+ }
38
+ }
39
+ }
40
+ catch (error) {
41
+ warn(directory ?? homes[host], error);
42
+ }
43
+ }
44
+ return { ids, warnings };
45
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "personal-bot",
3
- "version": "0.2.18",
3
+ "version": "0.2.20",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/realqiyan/personal-bot.git"
@@ -4,7 +4,7 @@
4
4
 
5
5
  ## 工作方式
6
6
 
7
- - 按工作区约定定位相关资料,需要更多线索时读目录入口或搜索,按需使用匹配的技能。
7
+ - 回查或续做项目时,按用户的称呼从根 `AGENTS.md` 找到项目正文。需要更多线索时,按主题或交付物名称搜索。
8
8
  - 操作后查看结果。超时、取消或断连后,先查状态再决定是否重试,避免重复执行。
9
9
  - 使用当前宿主的原生 CLI/MCP。接入与排障使用 provider-connections;按需读取 `providers/<id>/GUIDE.md` 中的数据口径和限制。认证使用原生登录或凭据引用,资料中不保存凭据值。
10
10
 
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: project-maintenance
3
- description: 维护项目结论、分析口径与可复用任务定义。用于资料更新、按既有口径复用任务、成果整理和项目结项。
3
+ description: 维护项目导航、结论和可复用的任务定义,归集交付物,整理结项资料。
4
4
  ---
5
5
 
6
6
  # 项目整理与维护
@@ -11,15 +11,15 @@ description: 维护项目结论、分析口径与可复用任务定义。用于
11
11
 
12
12
  ## 更新所属资料
13
13
 
14
- 从根 AGENTS.md 和相关目录入口定位正文;入口未命中时,按主题、别名或项目名搜索。
15
-
16
14
  按主题合并当前说明,保留继续或复用任务所需的信息。比较新旧内容的对象、时期和条件,替换过时说明,同步引用,保留未解决的冲突。
17
15
 
18
16
  保留历史资料与重要决策的来源和时间,当前说明通过引用连接。用户偏好与约定按用户表达记录,不把推测写成既定约定。
19
17
 
20
18
  从项目结论中提炼可跨任务复用的概念、方法与口径,写入 knowledge/,说明适用条件并引用来源。知识按主题命名,需要保留历史的研究和决策按日期与主题命名。
21
19
 
22
- 尊重根 AGENTS.md 已有的导航格式和工作区约定,只更新受本次变化影响的入口,不为统一样式重排。新建导航时可用 text 目录树,展开到有资料的主题或项目目录并简注用途,也可按已有习惯使用链接列表;任务状态沿用现有标记。结论和未决事项留在正文,导航引用对应资料。
20
+ ## 整理项目导航
21
+
22
+ 沿用工作区的导航约定。根 `AGENTS.md` 的项目速查列出目录名和用户常用的称呼或主题词。采用默认入口的项目用目录名即可,其他项目链接到实际入口。项目进展和结论写在项目正文。
23
23
 
24
24
  ## 复用任务定义
25
25
 
@@ -27,7 +27,7 @@ description: 维护项目结论、分析口径与可复用任务定义。用于
27
27
 
28
28
  重复分析或报告的定义按需包含数据来源与查询方式、对象与筛选范围、期间与时区、单位、指标公式与分母、分组与比较基准、执行入口。单次报告引用所用定义。
29
29
 
30
- 按上次口径重做时,读取已有定义,检查来源、版本与关键前提是否仍适用。更新报告使用本次期间与数据;复现历史结果使用指定输入。口径变化说明对可比性的影响。
30
+ 回查结论时,引用对应时期的正文或交付物。按原口径更新分析时,核对原定义的来源和关键前提,使用本期数据。复现历史结果时,使用当时的输入和版本。口径变化时说明对可比性的影响。
31
31
 
32
32
  ## 成果归集与清理
33
33
 
@@ -37,4 +37,4 @@ description: 维护项目结论、分析口径与可复用任务定义。用于
37
37
 
38
38
  ## 项目结项
39
39
 
40
- 按任务目标检查交付物和执行入口。满足本次用途即可结项;尚有缺口时说明剩余工作,额外建议另列。更新项目状态和相关导航,已知限制留在正文。
40
+ 按任务目标检查交付物和执行入口,在项目正文记录交付结果、剩余工作和复用条件。
@@ -11,3 +11,7 @@
11
11
  ├── scratch/ # 临时脚本、查询与计算数据、下载及运行环境
12
12
  └── agents/ # coordinator.md 与 general-purpose.md 的职责补充
13
13
  ```
14
+
15
+ ## 项目速查
16
+
17
+ 项目默认入口为 `projects/<目录名>/README.md`。
@@ -3,6 +3,7 @@ import type { Context } from "@deepseek-ai/cordis";
3
3
  import type { Agent } from "@deepseek-ai/dsh-agent";
4
4
  import { dshHomePath } from "@deepseek-ai/dsh-home-paths";
5
5
  import { AgentFiles } from "../../storage/agent-files.js";
6
+ import { acpHistorySessions } from "../../storage/acp-history.js";
6
7
  import { HistoryFiles } from "../../storage/history-files.js";
7
8
  import { HistoryService } from "../../services/history/history-service.js";
8
9
  import { DshHistory } from "../../integrations/dsh/history.js";
@@ -20,7 +21,8 @@ export class DshHistoryWork {
20
21
  const agents = new AgentFiles(dshHomePath("pbot", "subagents"), "dsh");
21
22
  this.service = new HistoryService(root, new HistoryFiles(join(root, ".pbot/history"), "dsh"),
22
23
  new DshHistory(ctx, root, () => agents.list().filter(value => value.workspace === root).map(value => value.agentId)),
23
- [new HistoryFiles(join(root, ".pbot/history"), "pi"), new HistoryFiles(join(root, ".pbot/history"), "claude")]);
24
+ [new HistoryFiles(join(root, ".pbot/history"), "pi"), new HistoryFiles(join(root, ".pbot/history"), "claude")],
25
+ () => acpHistorySessions({ dsh: agents.root }));
24
26
  }
25
27
  attach(agent: Agent) { this.#parents.add(agent); return () => { this.#parents.delete(agent); }; }
26
28
  cancel() { this.#controller?.abort(); }
@@ -48,12 +48,15 @@ export function projectDshHistory(header: SessionHeader, events: readonly Sessio
48
48
  export class DshHistory implements HistorySource {
49
49
  readonly host = "dsh";
50
50
  constructor(private readonly ctx: Context, private readonly root: string, private readonly relatedSessions: () => string[] = () => []) {}
51
- async scan(location: HistoryLocation, signal?: AbortSignal) {
51
+ async scan(location: HistoryLocation, signal?: AbortSignal, excluded?: ReadonlySet<string>) {
52
52
  requireThat(location.host === "dsh", "dsh 历史只读取 dsh 原生会话。");
53
53
  signal?.throwIfAborted();
54
- const records = await this.ctx.sessionQuery.listSessions(signal), selected = new Set<string>(), warnings: string[] = [];
55
- try { for (const id of this.relatedSessions()) selected.add(id); } catch (error) { warnings.push("专家引用:" + String(error)); }
56
- if (location.sessionId) selected.add(location.sessionId);
54
+ const records = (await this.ctx.sessionQuery.listSessions(signal)).filter(record => !excluded?.has(record.header.id));
55
+ const selected = new Set<string>(), warnings: string[] = [];
56
+ // Expert records also name ACP members and sessions that dsh no longer stores; only real dsh sessions are readable.
57
+ const stored = new Set<string>(records.map(record => record.header.id));
58
+ try { for (const id of this.relatedSessions()) if (stored.has(id)) selected.add(id); } catch (error) { warnings.push("专家引用:" + String(error)); }
59
+ if (location.sessionId && !excluded?.has(location.sessionId)) selected.add(location.sessionId);
57
60
  for (const record of records) {
58
61
  signal?.throwIfAborted();
59
62
  if ((record.header.origin !== "subagent" || !record.header.parentSession) && record.header.cwd &&
@@ -56,17 +56,21 @@ export const historyLocation = (ctx: ExtensionContext): HistoryLocation => {
56
56
  export class PiHistory implements HistorySource {
57
57
  readonly host = "pi";
58
58
  constructor(private readonly root: string, private readonly relatedFiles: () => string[] = () => []) {}
59
- async scan(location: HistoryLocation, signal?: AbortSignal) {
59
+ async scan(location: HistoryLocation, signal?: AbortSignal, excluded?: ReadonlySet<string>) {
60
60
  requireThat(location.host === "pi", "Pi 历史只读取 Pi 原生会话。");
61
61
  const lists = await Promise.all([SessionManager.list(this.root, undefined, undefined, signal),
62
62
  SessionManager.list(this.root, location.directory, undefined, signal)]);
63
- const files = new Set([...lists.flat().map(session => session.path), ...this.relatedFiles(), ...(location.file ? [location.file] : [])]);
63
+ const files = new Set([...this.relatedFiles(), ...(location.file ? [location.file] : [])]);
64
+ for (const session of lists.flat()) {
65
+ if (excluded?.has(session.id)) files.delete(session.path);
66
+ else files.add(session.path);
67
+ }
64
68
  const sessions: HistorySession[] = [], warnings: string[] = [];
65
69
  for (const file of files) {
66
70
  signal?.throwIfAborted();
67
71
  try {
68
72
  const session = projectHistory(await readFile(file, { encoding: "utf8", signal }));
69
- if (session.branches.length) sessions.push(session);
73
+ if (session.branches.length && !excluded?.has(session.sessionId)) sessions.push(session);
70
74
  } catch (error) {
71
75
  signal?.throwIfAborted();
72
76
  // Pi reserves a filename before the first message; copied archives may also outlive their native files.
@@ -49,7 +49,7 @@ export type HistoryLocation = { host: "pi"; directory: string; file?: string } |
49
49
  { host: "dsh"; sessionId?: string };
50
50
  export interface HistorySource {
51
51
  readonly host: HistoryLocation["host"];
52
- scan(location: HistoryLocation, signal?: AbortSignal): Promise<{ sessions: HistorySession[]; warnings: string[] }>;
52
+ scan(location: HistoryLocation, signal?: AbortSignal, excluded?: ReadonlySet<string>): Promise<{ sessions: HistorySession[]; warnings: string[] }>;
53
53
  }
54
54
  export interface HistorySummaryRequest {
55
55
  system: string;
package/src/pbot.ts CHANGED
@@ -13,6 +13,7 @@ import { HistoryService } from "./services/history/history-service.js";
13
13
  import { HistoryFiles } from "./storage/history-files.js";
14
14
  import { PiHistory } from "./integrations/pi/history.js";
15
15
  import { sessionRef } from "./storage/agent-files.js";
16
+ import { acpHistorySessions } from "./storage/acp-history.js";
16
17
  import { join } from "node:path";
17
18
  import { registerHistoryEvents } from "./extension/history.js";
18
19
 
@@ -26,7 +27,8 @@ export default function pbot(pi: ExtensionAPI) {
26
27
  agents.files.list().filter(agent => agent.workspace === root).flatMap(agent => {
27
28
  const file = agents.files.optional(agent.agentId, "session-ref.json", sessionRef)?.file;
28
29
  return file ? [file] : [];
29
- })), [new HistoryFiles(join(root, ".pbot/history"), "dsh"), new HistoryFiles(join(root, ".pbot/history"), "claude")]);
30
+ })), [new HistoryFiles(join(root, ".pbot/history"), "dsh"), new HistoryFiles(join(root, ".pbot/history"), "claude")],
31
+ () => acpHistorySessions({ pi: agents.files.root }));
30
32
  return new WorkspaceInstance(root, agents, new TeamService(root, agents.files, agents.teamFiles), history);
31
33
  }, instance => registry.register(mainTools(instance.agents, instance.teams, instance.history, instance)), () => registry.hide());
32
34
  registerCommand(pi, lifecycle, confirmations);
@@ -58,7 +58,8 @@ export class HistoryService {
58
58
  #sourceWarnings: string[] = [];
59
59
  #summaryError: string | undefined;
60
60
  constructor(readonly root: string, private readonly files: HistoryFiles, private readonly source: HistorySource,
61
- private readonly otherFiles: readonly HistoryReader[] = []) {
61
+ private readonly otherFiles: readonly HistoryReader[] = [],
62
+ private readonly acpSessions?: () => { ids: Record<HistoryHost, ReadonlySet<string>>; warnings: string[] }) {
62
63
  requireThat((source.host === "pi" || source.host === "dsh") && source.host === files.host &&
63
64
  new Set([files.host, ...otherFiles.map(value => value.host)]).size === otherFiles.length + 1,
64
65
  "历史来源与归档目录不匹配。");
@@ -79,17 +80,23 @@ export class HistoryService {
79
80
  this.check(); signal?.throwIfAborted();
80
81
  const warnings: string[] = [], records: LocatedRecord[] = [];
81
82
  const warning = (host: HistoryHost, error: unknown) => { this.check(); signal?.throwIfAborted(); warnings.push(host + ": " + String(error)); };
82
- let known: HistoryArchive[] = [];
83
+ let known: HistoryArchive[] = [], sessions: HistorySession[] = [];
83
84
  try {
84
85
  try { this.files.migrate(this.root); } finally { known = this.files.list(this.root); }
85
- const before = new Map(known.map(({ raw }) => [raw.sessionId, raw]));
86
- let sessions: HistorySession[] = [];
87
- try {
88
- const scanned = await this.source.scan(location, signal); sessions = scanned.sessions;
89
- warnings.push(...scanned.warnings.map(value => this.files.host + ": " + value));
90
- } catch (error) { warning(this.files.host, error); }
91
- this.check(); signal?.throwIfAborted();
86
+ const scanned = await this.source.scan(location, signal, this.acpSessions?.().ids[this.files.host]); sessions = scanned.sessions;
87
+ warnings.push(...scanned.warnings.map(value => this.files.host + ": " + value));
88
+ } catch (error) { warning(this.files.host, error); }
89
+ this.check(); signal?.throwIfAborted();
90
+ // The worker binds the actual backend ID before delivery, possibly during the native scan.
91
+ const excluded = this.acpSessions?.();
92
+ if (excluded) {
93
+ warnings.push(...excluded.warnings);
94
+ sessions = sessions.filter(session => !excluded.ids[this.files.host].has(session.sessionId));
95
+ }
96
+ const visible = ({ raw }: HistoryArchive) => !excluded?.ids[raw.host].has(raw.sessionId);
97
+ try {
92
98
  if (sessions.length) {
99
+ const before = new Map(known.map(({ raw }) => [raw.sessionId, raw]));
93
100
  known = this.files.control(() => {
94
101
  this.check(); signal?.throwIfAborted();
95
102
  const current = new Map(this.files.list().map(archive => [archive.raw.sessionId, archive]));
@@ -114,9 +121,9 @@ export class HistoryService {
114
121
  });
115
122
  }
116
123
  } catch (error) { warning(this.files.host, error); }
117
- records.push(...known.map(view));
124
+ records.push(...known.filter(visible).map(view));
118
125
  for (const files of this.otherFiles) {
119
- try { records.push(...files.list(this.root).map(view)); }
126
+ try { records.push(...files.list(this.root).filter(visible).map(view)); }
120
127
  catch (error) { warning(files.host, error); }
121
128
  }
122
129
  this.check(); signal?.throwIfAborted(); this.#records = records; this.#sourceWarnings = warnings; this.#loaded = true;
@@ -162,7 +169,8 @@ export class HistoryService {
162
169
  const run = async () => {
163
170
  for (;;) {
164
171
  this.check(); active.throwIfAborted();
165
- const pending = nextSummary(this.files.list());
172
+ const archives = this.files.list(), excluded = this.acpSessions?.().ids[this.files.host];
173
+ const pending = nextSummary(archives.filter(({ raw }) => !excluded?.has(raw.sessionId)));
166
174
  if (!pending) return;
167
175
  const { record, node, children } = pending;
168
176
  const text = await summarize({ system: readFileSync(join(resourceRoot, "prompts/history-summary.md"), "utf8"), maxTokens: 2048,
@@ -0,0 +1,38 @@
1
+ import { readdirSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { join } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import type { HistoryHost } from "../model/history.js";
6
+ import { readJsonFile } from "./atomic-json.js";
7
+ import { acpReference } from "./acp-files.js";
8
+
9
+ function memberDirectory(home: string, host: "pi" | "dsh") {
10
+ if (host === "pi" && home.startsWith("file://")) return join(fileURLToPath(home), "pbot/subagents");
11
+ const tilde = home === "~" || home.startsWith("~/") || ((host === "dsh" || process.platform === "win32") && home.startsWith("~\\"));
12
+ return join(tilde ? join(homedir(), home.slice(2)) : home, "pbot/subagents");
13
+ }
14
+
15
+ /** A target session can be owned by either coordinator, even when its cwd belongs to another workspace. */
16
+ export function acpHistorySessions(directories: { pi?: string; dsh?: string }) {
17
+ const ids: Record<HistoryHost, Set<string>> = { pi: new Set(), dsh: new Set(), claude: new Set() };
18
+ const warnings: string[] = [];
19
+ const warn = (path: string, error: unknown) => {
20
+ if ((error as NodeJS.ErrnoException).code !== "ENOENT") warnings.push(path + ": " + String(error));
21
+ };
22
+ const homes = { pi: process.env.PI_CODING_AGENT_DIR || "~/.pi/agent", dsh: process.env.DSH_HOME?.trim() ? process.env.DSH_HOME : "~/.dsh" };
23
+ for (const host of ["pi", "dsh"] as const) {
24
+ let directory = directories[host];
25
+ try {
26
+ directory ??= memberDirectory(homes[host], host);
27
+ for (const entry of readdirSync(directory, { withFileTypes: true })) {
28
+ if (!entry.isDirectory() || entry.name.startsWith(".")) continue;
29
+ const path = join(directory, entry.name);
30
+ try {
31
+ const ref = readJsonFile(path, "acp-session.json", acpReference);
32
+ if (ref.sessionId !== null) ids[ref.backend].add(ref.sessionId);
33
+ } catch (error) { warn(path, error); }
34
+ }
35
+ } catch (error) { warn(directory ?? homes[host], error); }
36
+ }
37
+ return { ids, warnings };
38
+ }