personal-bot 0.2.12 → 0.2.14

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 (97) hide show
  1. package/.claude-plugin/marketplace.json +18 -0
  2. package/.claude-plugin/plugin.json +15 -0
  3. package/CONTEXT.md +11 -5
  4. package/README.md +33 -16
  5. package/README.zh-CN.md +33 -16
  6. package/docs/README.md +6 -4
  7. package/docs/adr/0001-claude-skill-discovery.md +3 -0
  8. package/docs/adr/0002-claude-native-collaboration.md +3 -0
  9. package/docs/agent-collaboration.md +20 -8
  10. package/docs/architecture-guidelines.md +1 -1
  11. package/docs/capability-design.md +10 -4
  12. package/docs/claude-code-design.md +45 -0
  13. package/docs/claude-code.md +64 -0
  14. package/docs/dsh.md +3 -3
  15. package/docs/file-storage.md +18 -9
  16. package/docs/history.md +17 -9
  17. package/docs/interaction-design.md +9 -1
  18. package/docs/model-context.md +37 -14
  19. package/docs/model-instruction-guidelines.md +3 -3
  20. package/docs/release.md +14 -6
  21. package/docs/technical-design.md +40 -18
  22. package/docs/workspace-configuration.md +34 -26
  23. package/hooks/hooks.json +19 -0
  24. package/lib/claude.d.ts +1 -0
  25. package/lib/claude.js +20 -0
  26. package/lib/client.js +1 -1
  27. package/lib/common/schema.d.ts +2 -0
  28. package/lib/common/schema.js +10 -0
  29. package/lib/common/validation.d.ts +0 -2
  30. package/lib/common/validation.js +0 -10
  31. package/lib/extension/acp-worker.js +6 -3
  32. package/lib/extension/claude-hooks.d.ts +15 -0
  33. package/lib/extension/claude-hooks.js +104 -0
  34. package/lib/extension/dsh/command.js +2 -1
  35. package/lib/extension/dsh/history.js +1 -1
  36. package/lib/extension/dsh/management.js +2 -1
  37. package/lib/integrations/agent-resources.d.ts +1 -1
  38. package/lib/integrations/agent-resources.js +3 -1
  39. package/lib/integrations/dsh/history-summary.js +5 -9
  40. package/lib/integrations/dsh/history.js +13 -5
  41. package/lib/integrations/history-summary.d.ts +2 -0
  42. package/lib/integrations/history-summary.js +21 -10
  43. package/lib/model/agent.d.ts +1 -1
  44. package/lib/model/history.d.ts +11 -4
  45. package/lib/services/history/history-service.d.ts +8 -6
  46. package/lib/services/history/history-service.js +90 -48
  47. package/lib/services/workspace/python-environment-service.d.ts +6 -0
  48. package/lib/services/workspace/python-environment-service.js +25 -9
  49. package/lib/storage/agent-files.js +3 -0
  50. package/lib/storage/history-files.d.ts +2 -1
  51. package/lib/storage/history-files.js +26 -15
  52. package/lib/tools/agents/dsh-tool.js +2 -1
  53. package/lib/tools/history/contract.d.ts +7 -7
  54. package/lib/tools/history/contract.js +4 -3
  55. package/lib/tools/history/dsh-tool.js +2 -1
  56. package/lib/tools/teams/dsh-tool.js +2 -1
  57. package/lib/ui/dsh/management.js +1 -1
  58. package/package.json +33 -30
  59. package/python/README.md +17 -14
  60. package/resources/agents/coordinator.md +1 -1
  61. package/resources/claude/agents/general-purpose.md +12 -0
  62. package/resources/claude/skills/pbot/SKILL.md +17 -0
  63. package/resources/prompts/claude-coordinator.md +1 -0
  64. package/resources/prompts/native-coordinator.md +1 -0
  65. package/resources/prompts/workspace.md +2 -2
  66. package/resources/references/compute.md +2 -2
  67. package/resources/references/task-conductor.md +3 -2
  68. package/resources/skills/provider-connections/SKILL.md +17 -1
  69. package/scripts/README.md +25 -7
  70. package/src/claude.ts +19 -0
  71. package/src/common/schema.ts +11 -0
  72. package/src/common/validation.ts +0 -11
  73. package/src/extension/acp-worker.ts +2 -2
  74. package/src/extension/claude-hooks.ts +94 -0
  75. package/src/extension/dsh/command.ts +2 -1
  76. package/src/extension/dsh/history.ts +1 -1
  77. package/src/extension/dsh/management.ts +2 -1
  78. package/src/integrations/agent-resources.ts +2 -1
  79. package/src/integrations/dsh/history-summary.ts +5 -9
  80. package/src/integrations/dsh/history.ts +12 -6
  81. package/src/integrations/history-summary.ts +18 -8
  82. package/src/integrations/pi/history.ts +16 -15
  83. package/src/model/agent.ts +1 -1
  84. package/src/model/history.ts +12 -4
  85. package/src/pbot.ts +2 -2
  86. package/src/services/history/history-service.ts +82 -41
  87. package/src/services/workspace/python-environment-service.ts +26 -9
  88. package/src/storage/agent-files.ts +4 -1
  89. package/src/storage/history-files.ts +20 -11
  90. package/src/tools/agents/dsh-tool.ts +2 -1
  91. package/src/tools/agents/tool.ts +2 -1
  92. package/src/tools/history/contract.ts +4 -3
  93. package/src/tools/history/dsh-tool.ts +2 -1
  94. package/src/tools/teams/dsh-tool.ts +2 -1
  95. package/src/tools/teams/tool.ts +2 -1
  96. package/src/ui/dsh/management.ts +1 -1
  97. package/npm-shrinkwrap.json +0 -13561
@@ -1,11 +1,12 @@
1
1
  # 技术设计
2
2
 
3
- Personal Bot 提供按工作区加载的 Pi 扩展和原生 dsh Host/Web 接入。模型负责分析、协调和工具使用;扩展负责资料准备、专家会话和共享 Python 环境。安装与命令见[项目 README](../README.md)。
3
+ Personal Bot 提供按工作区加载的 Pi 扩展、原生 dsh Host/Web 接入及 Claude Code 标准插件。模型负责分析、协调和工具使用;Pi/dsh 提供专家协作与历史归档,Claude 通过标准 hooks、技能和原生专家复用资料与共享 Python。安装与命令见[项目 README](../README.md)及 [Claude 使用指南](claude-code.md)。
4
4
 
5
5
  ## 模块与依赖
6
6
 
7
7
  ```text
8
8
  Pi / dsh 命令、工具、事件与原生 Remote
9
+ Claude command hooks / Node 命令
9
10
  ↓
10
11
  tools / extension / ui
11
12
  ↓
@@ -16,7 +17,9 @@ Pi / dsh 命令、工具、事件与原生 Remote
16
17
  integrations
17
18
  ```
18
19
 
19
- src/pbot.ts 装配 Pi 入口,src/dsh.ts 装配 dsh Host,src/ui/dsh/index.ts 装配 Web 客户端;共享业务服务,不引入通用 Host 平台。src/extension/setup-cli.ts 装配独立安装命令;`pbot setup` 通过原生 npm/Pi 准备一个工作区,再启动 Pi 执行 `/pbot init`。安装器的顺序、来源保留与失败恢复由 services/installation 管理,接入层调用实际宿主的包管理接口,不创建模型会话。详见[安装与升级](installation-design.md)。
20
+ src/pbot.ts 装配 Pi,src/dsh.ts 装配 dsh Host,src/ui/dsh/index.ts 装配 Web 客户端。src/claude.ts 是 Claude 标准 command hook 与 Node 命令入口,src/extension/claude-hooks.ts 调用共用工作区和 Python 服务。Claude 静态发现 Markdown 技能与专家,不装配 pbot 历史、ACP 或面板。各宿主共享资料与适用的业务服务。
21
+
22
+ src/extension/setup-cli.ts 装配独立 Pi 安装命令;`pbot setup` 通过原生 npm/Pi 准备工作区,再启动 Pi 执行 `/pbot init`。Claude 使用原生插件 marketplace。安装器顺序、来源保留与失败恢复由 services/installation 管理,详见[安装与升级](installation-design.md)。
20
23
 
21
24
  | 目录 | 责任 |
22
25
  | --- | --- |
@@ -24,26 +27,36 @@ src/pbot.ts 装配 Pi 入口,src/dsh.ts 装配 dsh Host,src/ui/dsh/index.ts
24
27
  | src/services/ | 业务规则、状态变更和操作顺序,按 agents、workspace、history、installation 聚合 |
25
28
  | src/model/ | 业务数据类型与窄能力约定,不包含业务实现或宿主 SDK 类型 |
26
29
  | src/integrations/ | Pi/dsh 原生会话、ACP 连接与进程、Python 环境激活 |
27
- | src/storage/ | 原子 JSON、子会话与团队文件 |
30
+ | src/storage/ | 原子 JSON、子会话、pbot 团队和历史文件 |
28
31
  | src/extension/ | 命令、事件和资源生命周期 |
29
32
  | src/ui/ | 确认队列、对话框和专家展示 |
30
33
  | src/common/ | JSON、校验、文件、包路径和版本辅助逻辑 |
31
34
  | resources/ | 角色、技能、提示词、模板和参考资料 |
32
35
 
33
- 服务不依赖 Pi/dsh SDK、工具或 UI。共享进程执行可直接使用,其他宿主能力通过窄接口传入。接入层可引用服务类型;命令和工具通过服务执行状态变更。模型层用 interface/type 描述普通数据和窄能力契约;数据以普通对象进入 JSON、存储和工具结果。
36
+ 服务不依赖宿主 SDK、工具或 UI。共享进程执行可直接使用,其他宿主能力通过窄接口传入。接入层可引用服务类型;命令和工具通过服务执行状态变更。模型层用 interface/type 描述普通数据和窄能力契约;数据以普通对象进入 JSON、存储和工具结果。
37
+
38
+ Claude command hook 是独立 Node 进程,只使用 Node 内置模块和共用资料/Python 服务。通用断言保留在 common/validation,依赖 Ajv 的 JSON Schema 编译放在 common/schema,由 Pi/dsh 工具适配显式引用,避免资料和配置读取加载第三方模块。hook 的 stdout 输出标准 JSON,诊断写 stderr;不加载宿主 SDK、mod API 或内部 MCP。
34
39
 
35
40
  | 主体 | 管理内容 |
36
41
  | --- | --- |
37
42
  | initializeWorkspace / prepareWorkspace | 初始化依次准备资料并写入共用启用配置;资料准备补建目录与根 AGENTS.md |
38
43
  | PythonEnvironmentService | venv 准备、依赖检查、状态与取消等待 |
39
44
  | AgentService / AgentRun / AcpAgentRun | 专家实例、启动预约、代次、inbox、领取/进入/消费/完成与交付资格;ACP prompt 收尾、固定报告与确认关联;拒绝向被团队占用的成员发送私人任务 |
40
- | TeamService | 固定成员、公共消息、有限轮次、团队占用与暂停规则 |
41
- | HistoryService | 双来源问答索引、四叉摘要、查询、来源写锁与过期提交拒绝 |
42
- | WorkspaceInstance / DshWorkspaces | 各宿主工作区及资源生命周期;dsh 按父会话装配,并按工作区共享历史整理 |
45
+ | TeamService | Pi/dsh 的固定成员、公共消息、有限轮次、团队占用与暂停规则 |
46
+ | HistoryService | 三来源问答索引、四叉摘要、查询、来源写锁与精确输入提交核验 |
47
+ | WorkspaceInstance / DshWorkspaces | Pi/dsh 工作区生命周期;dsh 按父会话装配,按工作区共享历史整理 |
48
+
49
+ ## Claude 标准插件入口
50
+
51
+ `hooks/hooks.json` 声明 SessionStart、UserPromptSubmit、SubagentStart、PreToolUse/Skill 和 UserPromptExpansion 的 command handlers,使用独立 `command` 与 `args`,不经 shell 拼接路径。stdin 只消费公开事件字段,stdout 返回标准 hook JSON。固定根目录取 `CLAUDE_PROJECT_DIR`,普通 Node 命令无该变量时使用 cwd。
52
+
53
+ SessionStart 检查并按需准备共享 Python。UserPromptSubmit 重读共用配置、公共约定、角色、根 AGENTS 与工作区职责补充,连同环境状态加入上下文;宿主提供子代理身份时使用专家职责。SubagentStart 只为插件的原生专家添加资料。未启用时不准备环境或加入业务资料,PreToolUse/Skill 与 UserPromptExpansion 分别检查模型调用和用户直接展开的 pbot 方法,拦截时返回初始化入口,管理技能仍可调用。
54
+
55
+ `node <插件>/lib/claude.js init|status|python setup` 调用共用初始化与 Python 服务;`/personal-bot:pbot` 是执行同一入口的原生技能,会调用模型。原生专家 Markdown 由共用职责生成。Claude 不读取内部 transcript、团队配置、启动参数或消息收据,不注册 pbot 模型工具或管理面板。
43
56
 
44
57
  ## 加载与关闭
45
58
 
46
- 宿主原生配置决定插件加载范围,工作区根目录下的 `.pbot/config.json` 决定业务实例是否启动。`services/workspace/workspace-config` 为两种宿主读取同一 JSON;缺失、false 或无效配置保持未启用,错误由状态入口报告,不向父目录继承。规则与修改生效方式见[工作区配置](workspace-configuration.md)。
59
+ 宿主原生配置决定插件加载范围,工作区根目录下的 `.pbot/config.json` 决定业务实例是否启动。`services/workspace/workspace-config` 为三种宿主读取同一 JSON;缺失、false 或无效配置保持未启用,错误由状态入口报告,不向父目录继承。规则与修改生效方式见[工作区配置](workspace-configuration.md)。
47
60
 
48
61
  Pi 的 session_start 读取启动目录配置,仅在 enabled 为 true 时创建实例、注册工具和准备 Python。未启用时保留状态和初始化入口,不注册包内技能,也不注入 pbot 提示词;状态栏显示未启用或已启动。加载本身不开展模型任务。
49
62
 
@@ -51,18 +64,21 @@ Pi 的 `/pbot` 打开原生菜单,状态与长记录使用只读阅读页;ds
51
64
 
52
65
  `/pbot init` 先准备资料,再将共用配置中的 enabled 设为 true,保留其他字段;无效配置在写入前报错。Pi 从未启用状态初始化后调用原生 ctx.reload,让实例、工具、技能和新建根 AGENTS 一起生效;已启动会话仅补建资料,新建 AGENTS 经 `/reload` 加载。`/pbot status` 展示运行状态、路径、版本和完整 Python 状态;模型环境只保留工作区、资源根目录及 Python 状态与就绪目录。实际 cwd 由宿主提供,准备错误日志保留在状态入口。
53
66
 
54
- 主 reload 在配置仍启用时保留子进程并重新关联,但暂停团队,不继续安排旧批次;配置关闭或损坏时停止所属专家;退出或切换会话时清理子进程、取消环境准备并恢复本实例持有的环境变量。关闭操作幂等。子会话的分支归属、通知和恢复规则见[专家协作](agent-collaboration.md)。
67
+ Pi 主 reload 在配置仍启用时保留子进程并重新关联,但暂停团队,不继续安排旧批次;配置关闭或损坏时停止所属专家;退出或切换会话时清理子进程、取消环境准备并恢复本实例持有的环境变量。关闭操作幂等。子会话的分支归属、通知和恢复规则见[专家协作](agent-collaboration.md)。
55
68
 
56
69
  dsh 为原生 registry 中的每个根 Agent 读取其原始 cwd 下的配置,仅对已启用根目录建立协调者工作区。关闭的工作区保留只读状态和初始化入口,其余业务命令与 Remote 查询拒绝进入;init 写入配置后重新打开同一根目录下尚未启用的主会话,按目录合并并发初始化;首个已启用工作区触发共享 Python 准备。专家使用同进程独立 Agent/Session;组件或所属父 Agent 关闭时取消预约、暂停安排并等待自己拥有的执行资源释放。打开页面、轮询、重连不恢复专家或启动模型,已接纳工作不归浏览器生命周期所有。原生存在但由其他实例持有的专家不能替换或假称已释放。
57
70
 
71
+ Claude 在每次用户提交和适用 hook 中读取固定根目录的配置。hook 没有常驻实例、租约、心跳或后台摘要;配置停用后不再加入业务资料或准备 Python。宿主关闭与原生会话恢复由 Claude 自己管理。Python 用完整解释器路径,不修改宿主环境,插件停用无需恢复 PATH。实现边界见[Claude 接入](claude-code-design.md)。
72
+
58
73
  ## 资源加载
59
74
 
60
75
  | 资源 | 用途与加载方式 |
61
76
  | --- | --- |
62
77
  | resources/prompts/workspace.md | 主会话与专家的公共操作约定、目录用途与异常重试说明 |
63
78
  | resources/agents/、工作区 agents/ | coordinator、general-purpose 职责及同名工作区补充 |
64
- | resources/prompts/team-member.md | 仅在专家处理团队任务时随团队目标与职责加载 |
65
- | resources/prompts/history-summary.md | 两种宿主的独立历史摘要调用,不带主/专家上下文 |
79
+ | resources/prompts/native-coordinator.md、claude-coordinator.md | 在共有 coordinator 职责后组合相应宿主的操作导航 |
80
+ | resources/prompts/team-member.md | 仅在 Pi/dsh 专家处理 pbot 团队任务时随目标与职责加载 |
81
+ | resources/prompts/history-summary.md | Pi/dsh 的独立历史摘要调用,不带主/专家上下文 |
66
82
  | resources/skills/ | 原生技能目录只展示元数据,正文按需读取 |
67
83
  | resources/references/ | 按任务读取;普通计算与指标/回测分开 |
68
84
  | resources/templates/workspace-agents.md | 补建根资料入口的模板,不覆盖现有文件 |
@@ -71,15 +87,17 @@ Pi 包清单关闭包内技能的静态发现,已启用主会话通过 resourc
71
87
 
72
88
  dsh 专家通过原生 composeFrom 应用父会话 preset,再限制其工具。包内技能 provider 仅在已启用主会话和受管专家的 scope 注册,原生文件系统 provider 负责读取和监听;作用域适配保留继承的项目/用户同名方法优先级;公共约定和角色在 system-prompt/assemble 当次刷新,遵守宿主 complete persona 覆盖。团队简报随首个已接纳团队上下文提供,不放在先于 pre-step 求值的动态 system section。
73
89
 
90
+ Claude 根插件静态声明共用 skills、管理技能与 Markdown 原生专家。工作区资料由 command hooks 按当前文件读取;CLAUDE.md 和用户规则仍由 Claude 原生加载。自有原生专家由 SubagentStart 加载工作区补充,团队职责与通信使用 Claude 自己的能力。
91
+
74
92
  同一会话中不变的 section 由宿主沿用,有效系统内容随后续请求传递。团队公共消息按结构化来源与序号去重,压缩后需要的原文通过 read 续取。目录用途常驻,维护方法、接入、计算和调度细节按需读取。具体加载方式见[模型上下文](model-context.md)。
75
93
 
76
94
  公共约定说明工作方式与资料位置,角色说明分工与交付,技能提供专业方法与必要的本地操作约定,工具定义参数与结果语义。委派包含文件修改时说明范围和责任;不重复加入通用授权、证据或验收要求。工具按 action 校验必填与允许字段,返回具体参数错误;status 不读取报告正文。Pi 附件组装保留绝对来源及原生读取结果;dsh 使用原生文件存储与图片准入,Web 通用文件走原生 Session 上传凭证,命令图片使用原生编码图片输入。资料保存由模型按公共约定与维护技能处理,沉淀方法、口径与结论,可再次查询的数据按需获取。布局见[文件存储](file-storage.md)。
77
95
 
78
96
  ## 历史查询
79
97
 
80
- Pi 与 dsh 共用 `.pbot/history/`,共同查询归档,只收录和整理自己的原生来源。两种来源使用相同归档格式,顶层保存 `host`、`id`、`sessionId`、`name` 和 `nodes`;来源识别、读取筛选与写入校验使用必填的 `host` 字段。文件名与根 ID 一致,两端分别使用 `.write-pi`、`.write-dsh` 短写锁。
98
+ Pi、dsh 共用 `.pbot/history/`,查询已有归档,各自只收录和整理本宿主来源。HistoryService 接收一个写来源及显式只读来源集合。顶层保存 `host`、`id`、`sessionId`、`name` 和 `nodes`;host 保留 pi、dsh、claude 数据兼容。Pi/dsh 分别使用 `.write-pi`、`.write-dsh` 短写锁,已有 Claude 归档可继续读取,Claude 插件不生成新归档。
81
99
 
82
- 扫描与模型调用在短写锁外,提交时重读,拒绝过期原文或摘要覆盖。查询不调用模型;正常主交互结束后才在空闲阶段整理,新人工输入优先取消。dsh 使用原生 LLM 路由,不创建额外 Agent,也不写主聊天。原生会话缺失时保留现成归档;损坏文件单独报告,其他归档继续可查。有不可读归档时只更新已识别会话,避免为其原生会话重复分配根 ID。实现与限制见[历史对话](history.md)。
100
+ 扫描与模型调用在短写锁外,提交时重读,拒绝过期原文或摘要覆盖。organize 在本次调用内保留节点与子节点的精确输入,提交前比较结构化数据并检查取消信号。查询不调用模型;正常主交互结束后在空闲阶段整理,新人工输入优先取消。来源消失或部分扫描不会删除已归档分支。有不可读归档时不为未识别会话重复分配根 ID,其他可读归档继续查询。实现与限制见[历史对话](history.md)。
83
101
 
84
102
  ## 原生子会话存储
85
103
 
@@ -95,7 +113,7 @@ dsh 的 `native-session.json` 只保存原生 Session ID,不把它写入 Pi
95
113
 
96
114
  ## ACP 执行
97
115
 
98
- AgentBackends 显式组合当前宿主的原生策略与 pi、dsh、claude 三个 ACP 目标,按成员引用选择策略;默认保持原生。工具 start 的 backend 单独进入启动流程,不写入既有 descriptor.options。WorkspaceConfiguration 提供 acp 命令覆盖,创建时固定解析后的路径和参数,恢复使用保存的入口。backend 参数声明目标程序前提;找不到可执行入口时,由共享接入层返回该目标的安装命令、原生认证提示与路径配置示例,各宿主沿用原生错误展示。
116
+ Pi/dsh 的 AgentBackends 在原生策略与 pi、dsh、claude 三个 ACP 目标间显式选择,默认保持当前宿主原生策略。工具 start 的 backend 单独进入启动流程,不写入既有 descriptor.options。WorkspaceConfiguration 提供 acp 命令覆盖,创建时固定解析后的路径和参数,恢复使用保存的入口。backend 参数声明目标程序前提;找不到可执行入口时,由共享接入层返回该目标的安装命令、原生认证提示与路径配置示例,各宿主沿用原生错误展示。
99
117
 
100
118
  integrations/acp/connection 使用官方 TypeScript SDK 的稳定 ACP v1,处理初始化、能力协商、配置选择、会话建立/恢复、进度、权限与关闭。主宿主仍持有自己的原生会话和通知收据。ACP 不继承父侧模型默认值;省略 model 或 thinking 时保留目标的原生默认配置。model-selection 将 Pi 的 provider/model、dsh 的编码模型值和 Claude 别名匹配到目标公开的选择;同名模型优先使用当前提供方,无法消歧时要求显式 provider。先选择模型,再按更新后的选项选择思考等级。首次配置全部成功后才固定原生会话引用,配置失败后的恢复继续应用原参数。worker 将配置选择与有效思考等级保存到独立 acp-model.json;服务只公开当前 generation 的 selection。Claude 从适配器入口或 node 启动脚本定位目标安装中的 SDK,通过 resolveSettings 读取原生配置,将环境变量决定的默认等级传入 SDK effort;显式 thinking 同时通过当前调用的 settings.env 覆盖原生环境等级,保留用户配置文件。只订阅 _claude/sdkMessage 的 system/init,将原生模型 ID 保存为 resolvedModel,与 model 配置别名分开。
101
119
 
@@ -113,7 +131,9 @@ worker 及其子进程属于同一进程组,进程记录绑定 generation,
113
131
 
114
132
  ## 团队接入
115
133
 
116
- 团队采用独立 team.json,不改动旧 AgentMessage、AgentCycle 等持久结构。TeamService 接收普通成员状态与完成记录,安排 roundRobin 或 parallel 轮次;AgentService 再校验并写入原 inbox。父侧原扫描器收集固定叶节点报告并公开原文,不调用主模型转述,不另建执行器或事件总线。
134
+ Claude 使用原生 Agent、团队、成员通信、任务与恢复,不创建 TeamService、pbot_team 或 pbot_team_message。实验团队开关与 teammate 模式由用户管理;原生恢复能力以当前宿主为准,见[专家协作](agent-collaboration.md#claude-原生专家与团队)。
135
+
136
+ Pi/dsh 的 pbot 团队采用独立 team.json,不改动旧 AgentMessage、AgentCycle 等持久结构。TeamService 接收普通成员状态与完成记录,安排 roundRobin 或 parallel 轮次;AgentService 再校验并写入原 inbox。父侧原扫描器收集固定叶节点报告并公开原文,不调用主模型转述,不另建执行器或事件总线。
117
137
 
118
138
  团队关联先保存,再发布输入。跨文件窗口采用保守恢复:不自动重发旧请求,只补交付可核对的完成记录。主/子工具显式注册,子入口只有公共 read/post。Pi 的上下文注入和通知边界分别位于 subagent-entry、agent-events 与 integrations/pi/team-context,服务不持有宿主 ctx。dsh 在原生 pre-step 安全边界注入团队上下文,以持久事件区分领取、进入、消费与正常最终答复;团队投递先取得原生 maintenance 准入,不能把公开 idle 当作独占许可。
119
139
 
@@ -131,7 +151,7 @@ Web 拥有草稿、上传和查询;接纳后的命令归服务端。命令不
131
151
 
132
152
  共享锁串行化跨进程 setup,同一服务合并重叠请求。失败或取消时保留环境并报告状态,其他扩展功能继续可用;可通过 `/pbot python setup` 重试。共享 venv 的解释器无法运行时(基础解释器被移除或升级),在锁内重建该 venv;非 venv 数据、符号链接和其他环境仍拒绝覆盖。
133
153
 
134
- 各宿主装配在当前进程激活 PATH、VIRTUAL_ENV 和 Python 路径变量,供主会话与专家的 Bash 继承;同一 dsh 进程内的工作区共用准备与激活生命周期。关闭时恢复仍由本实例持有的变量。环境更新会影响其他工作区,更新前应停止相关脚本。
154
+ Pi/dsh 在当前宿主进程激活 PATH、VIRTUAL_ENV 和 Python 路径变量,供随后启动的 Bash 继承;同一 dsh 进程内工作区共用激活生命周期。恢复只修改仍由本实例持有的变量。Claude hooks 检查共享环境并给出 `python.executable` 完整路径,由 Bash 显式使用,不修改父宿主环境。环境更新会影响其他工作区,更新前应停止相关脚本。
135
155
 
136
156
  计算通过原生 Bash 和第三方库 API 执行,使用项目自身的目录、输入和输出约定。路径、安装条件与许可见 [Python 说明](../python/README.md)。
137
157
 
@@ -139,8 +159,10 @@ Web 拥有草稿、上传和查询;接纳后的命令归服务端。命令不
139
159
 
140
160
  Pi 将工具纳入 pbot namespace,codemode 按契约组合;dsh 注册原生工具,并在宿主可表达的 schema 之外继续校验完整领域契约。原生 CLI/MCP 与可选 Task Conductor 的接入和授权见[工具与执行](capability-design.md)。
141
161
 
142
- Pi 入口指向 src,由宿主加载 TypeScript 源码;独立 CLI 与 dsh Host/Web 编译到 lib,dist 供测试使用。宿主 SDK 使用 optional peer,dsh SDK 范围为 "*",最低宿主版本由 engines.dsh 声明;开发依赖和锁文件保留精确版本。TypeBox 同样为 optional peer:Pi 通过宿主加载器提供,dsh 构建携带库及许可证,并保留原模块路径以定位资源。
162
+ Pi 入口指向 src,由宿主加载 TypeScript 源码;独立 CLI、dsh Host/Web、Claude Node hooks 编译到 lib,dist 供测试使用。Claude 的 hooks/hooks.json 指向 lib/claude.js;根 manifest 声明技能与原生专家,marketplace 指向同版本 npm 包。原生 marketplace 将包解压到插件缓存,不安装 npm 依赖;Claude hook/CLI 在没有 node_modules 的包目录中直接运行,资源路径相对包内模块定位。
163
+
164
+ 宿主 SDK 使用 optional peer,dsh SDK 范围为 "*",最低宿主版本由 engines.dsh 声明;开发依赖和仓库锁文件保留精确版本。完整开发 npm-shrinkwrap.json 不进入发布包,消费者按正常运行依赖安装,避免 registry 安装展开开发锁中的宿主 SDK。TypeBox 同样为 optional peer:Pi 通过宿主加载器提供,dsh 构建携带库及许可证。Claude 插件使用 Node 命令与共用服务,不加载宿主 SDK;Claude SDK 可选依赖仅供 Pi/dsh 的 Claude ACP 目标使用。
143
165
 
144
- Pi/CLI 支持 Node.js 22.19+,dsh 与完整开发使用 Node.js 24.9+。安装检查发现真实宿主后,在子进程中使用其 SDK 读取配置或切换来源。包内组件共用 package.json 的发布版本;子会话兼容线在 1.0 前按次版本、之后按主版本判断。
166
+ Pi、CLI 与 Claude hooks 支持 Node.js 22.19+,Claude 原生 CLI 最低与当前验证基线为 2.1.325;dsh 与 Linux 完整开发使用 Node.js 24.9+。安装检查发现真实宿主后,在子进程中使用其 SDK。包内组件共用 package.json 发布版本,build:claude 同步插件与 marketplace 版本并生成原生专家文件。构建顺序为 dist → build:cli → build:dsh → build:claude;build:cli 会清理 lib。子会话兼容线在 1.0 前按次版本、之后按主版本判断。
145
167
 
146
168
  构建与安装包检查见[维护脚本](../scripts/README.md),分发流程见[npm 发布](release.md)。
@@ -1,19 +1,28 @@
1
1
  # 工作区配置
2
2
 
3
- Pi 和 dsh 共用工作区根目录下的 `.pbot/config.json`。宿主原生配置负责安装和加载插件,此文件决定 Personal Bot 是否在当前工作区启动,也作为后续工作区功能配置的统一入口。
3
+ Pi、dsh 和 Claude Code 共用工作区根目录下的 `.pbot/config.json`。宿主原生配置负责安装和加载插件,此文件决定 Personal Bot 是否在当前工作区启用,也作为后续工作区功能配置的统一入口。
4
4
 
5
5
  ## 初始化与状态
6
6
 
7
- 安装后,从目标工作区打开 Pi 或 dsh,在聊天框执行:
7
+ 从目标工作区打开宿主,使用相应入口:
8
8
 
9
- ```text
10
- /pbot init
11
- /pbot status
12
- ```
9
+ | 宿主 | 初始化 | 状态 |
10
+ | --- | --- | --- |
11
+ | Pi | `/pbot init` | `/pbot status` |
12
+ | dsh | `/pbot init` 或工作区页初始化按钮 | `/pbot status` 或工作区页 |
13
+ | Claude | 原生技能 `/personal-bot:pbot init` | 原生技能 `/personal-bot:pbot status` |
14
+
15
+ `init` 先补建资料目录和缺失的根 `AGENTS.md`,再将配置中的 `enabled` 设为 true。已有资料、`CLAUDE.md` 和其他配置字段保留;无效配置在写入前报错。
13
16
 
14
- `init` 补建资料目录和缺失的根 `AGENTS.md`,将配置中的 `enabled` 设为 true,并启动 Personal Bot。已有资料和其他配置字段保留。Pi 在首次启用时自动重载;dsh 立即启用此目录下已打开的主会话。已经启动时,再次执行 `init` 主要用于补建资料;Pi 新建的根 AGENTS 经 `/reload` 加载。
17
+ Pi 首次启用时自动重载;已运行时补建的根 AGENTS 经 `/reload` 加载。dsh 立即启用此目录下已打开的主会话。Claude 的技能由模型通过 Bash 执行同一 Node CLI;确定性执行可直接运行:
18
+
19
+ ```sh
20
+ node /absolute/path/to/plugin/lib/claude.js init
21
+ node /absolute/path/to/plugin/lib/claude.js status
22
+ node /absolute/path/to/plugin/lib/claude.js python setup
23
+ ```
15
24
 
16
- Pi 状态栏显示“PBot 未启用”或“PBot 已启动”。dsh 的 Personal Bot 工作区页显示状态,未启用时提供“初始化并启用”按钮。两种宿主都保留 `/pbot status`,其结构化状态包含 `enabled`、运行时 `state`、工作区路径和配置路径。`state` 表示当前运行状态,取值为 `disabled`、`running` 或 `error`。
25
+ Claude CLI 从 `CLAUDE_PROJECT_DIR` 读取固定工作区根;在普通 shell 中未提供该变量时使用当前目录。需要显式指定工作区时,将它设为目标工作区的绝对路径。状态显示工作区、配置与 Python 信息;Claude 没有独立的 `/pbot` 原生命令或管理面板。操作见[Claude 使用指南](claude-code.md)。
17
26
 
18
27
  ## 启用与停用
19
28
 
@@ -25,23 +34,21 @@ Pi 状态栏显示“PBot 未启用”或“PBot 已启动”。dsh 的 Personal
25
34
  }
26
35
  ```
27
36
 
28
- 例如,ONEBASE 使用 `~/onebase/.pbot/config.json`。同一 dsh profile 可以同时打开开启和关闭的工作区。
29
-
30
37
  | 配置情况 | 行为 |
31
38
  | --- | --- |
32
- | `enabled: true` | 启动工作区实例,加载工具、提示词和包内技能,并准备 Python |
33
- | 文件不存在、缺少 enabled 或 `enabled: false` | 保持未启用,提示执行 `/pbot init`;保留宿主原生功能 |
34
- | JSON 损坏、字段类型错误或文件不可读取 | 保持未启用,报告配置错误;修复文件后再执行 `init` |
39
+ | `enabled: true` | Pi/dsh 启动业务实例;Claude hooks 加载上下文并准备共享 Python |
40
+ | 文件不存在、缺少 enabled 或 `enabled: false` | 保持未启用,提供状态与初始化入口;宿主原生功能继续使用 |
41
+ | JSON 损坏、字段类型错误或文件不可读取 | 保持未启用,报告具体错误;修复文件后再执行 `init` |
35
42
 
36
- 未启用时,包内技能不会进入原生技能目录,也不注入 pbot 提示词。用户自己的 AGENTS、技能和其他插件仍按宿主配置加载。
43
+ Pi/dsh 未启用时不注册包内技能,也不注入 pbot 提示词。Claude 静态技能名称、简介与原生 agent 仍可被宿主发现;PreToolUse 对 Skill 拦截 pbot 工作方法,保留 `personal-bot:pbot` 初始化技能可用。公共约定、角色和 Python 准备受配置控制。用户自己的指令、技能与其他插件沿用宿主加载规则;已经进入聊天的内容作为历史保留。
37
44
 
38
- 只读取当前工作区根目录,不向父目录查找配置。在 `~/onebase/projects/example` 单独建立会话时,该目录需要自己的配置。受 Personal Bot 管理的专家沿用所属工作区的启用决定,专家的工作目录可以不同。
45
+ 只读取绑定工作区根目录,不向父目录查找。例如在 `~/workspace/projects/example` 单独建立会话时,该目录需要自己的配置。修改 Bash cwd 不改变绑定根目录;Claude 使用 `CLAUDE_PROJECT_DIR` 固定此根。Pi/dsh 受管专家沿用所属工作区的启用决定,其执行目录可以不同。
39
46
 
40
- 配置使用普通 JSON,支持可选的布尔值 enabled 和 ACP 启动配置 acp。其他字段原样保留,后续工作区功能也在此文件中配置。
47
+ 配置使用普通 JSON,支持可选的布尔值 enabled 和供 Pi/dsh 使用的 ACP 启动配置 acp。其他字段原样保留。此文件是唯一业务启用入口;不自动导入旧配置,不从历史或其他资料推断启用,也不增加工作区格式版本。
41
48
 
42
49
  ## ACP 启动配置
43
50
 
44
- 先按[ACP 专家程序安装说明](../README.zh-CN.md#可选安装-acp-专家程序)准备目标。ACP 成员从主宿主进程的 PATH 查找 pi-acp、dsh 和 claude-agent-acp;在启动主宿主的同一终端运行 command -v 可检查安装路径。桌面宿主或服务的 PATH 与终端可能不同,需要固定入口或选择已有 dsh profile 时,在同一配置中覆盖对应目标:
51
+ Pi/dsh 主会话可委派 Pi、dsh 或 Claude ACP 成员。先按[ACP 专家程序安装说明](../README.zh-CN.md#可选安装-acp-专家程序)准备目标。成员从主宿主进程的 PATH 查找 pi-acp、dsh 和 claude-agent-acp;在启动主宿主的同一终端运行 `command -v` 可检查安装路径。桌面宿主或服务的 PATH 与终端可能不同,需要固定入口或选择已有 dsh profile 时,在同一配置中覆盖对应目标:
45
52
 
46
53
  ```json
47
54
  {
@@ -54,21 +61,22 @@ Pi 状态栏显示“PBot 未启用”或“PBot 已启动”。dsh 的 Personal
54
61
  }
55
62
  ```
56
63
 
57
- 每项包含 command 和 args 字符串数组,只需填写要覆盖的目标。使用普通可执行文件和标准 stdio ACP 入口;dsh 入口须接受原生 --patch 叠加成员配置。命令不经过 shell 展开,参数中的相对路径按成员 cwd 解析。模型、认证、MCP 和工具在目标宿主配置,凭据值不写入此文件。
64
+ 每项包含 command 和 args 字符串数组,只填写要覆盖的目标。使用普通可执行文件和标准 stdio ACP 入口;dsh 入口须接受原生 `--patch` 叠加成员配置。命令不经过 shell 展开,参数中的相对路径按成员 cwd 解析。模型、认证、MCP 和工具在目标宿主配置,凭据值不写入此文件。
58
65
 
59
- 创建成员时解析并保存实际可执行路径和参数。手工修改影响重载后的新成员;已有成员恢复继续使用保存的入口和会话引用。acp 字段无效时,按工作区配置错误处理。成员操作见[专家协作](agent-collaboration.md#acp-成员)。
66
+ 创建成员时保存解析后的实际可执行路径和参数。配置生效后的新成员使用新入口;已有成员恢复继续使用保存的入口和会话引用。acp 字段无效时,按工作区配置错误处理。Claude 标准插件不管理 ACP 委派。成员操作见[专家协作](agent-collaboration.md#acp-成员)。
60
67
 
61
68
  ## 应用手工修改
62
69
 
63
- - **Pi**:修改配置后执行原生 `/reload`,或重新启动 Pi。
64
- - **dsh**:修改配置后重启对应服务或桌面宿主。
70
+ | 宿主 | 应用方式 |
71
+ | --- | --- |
72
+ | Pi | 执行原生 `/reload`,或重新启动 Pi |
73
+ | dsh | 重启对应服务或桌面宿主 |
74
+ | Claude | 后续 SessionStart、UserPromptSubmit、SubagentStart、Skill 调用与技能展开检查及 CLI 操作读取当前配置 |
65
75
 
66
- 手工修改前已加载的会话保持原配置。修改 cwd 不改变所属工作区。停用后重载会撤下工具并释放所属专家、团队调度和历史整理;资料、历史与备份保留。需要重新启用时可直接执行 `/pbot init`。
76
+ Pi/dsh 在重载前保持原配置。停用生效后撤下后续业务工具与职责,释放所属执行和历史整理,并暂停团队调度。Claude 停止后续 pbot 上下文注入、工作方法技能与 Python 自动准备;原生会话和团队继续由 Claude 管理。资料、历史与备份保留。重新启用可使用各宿主的 init 入口。
67
77
 
68
- 所有已启用工作区共用用户级 Python venv。dsh 的进程环境激活由整个插件组件持有,同一 Host 中的 Bash 进程可能继承该环境。Python 使用方式见[计算环境](../python/README.md)。
78
+ 所有已启用工作区共用用户级 Python venv。Pi/dsh 激活所在进程环境,dsh 的激活由整个 Host 组件持有。Claude 通过 Bash 使用 `python.executable` 完整路径,不修改 Claude PATH 或环境变量,禁用或卸载无需恢复环境。路径与排障见 [Python 指南](../python/README.md)。
69
79
 
70
80
  ## 安装与更新
71
81
 
72
- 插件安装完成后,通过 `/pbot init` 创建启用配置并启动工作区。`pbot setup` 可在安装后启动 Pi 执行此命令;手工安装后,在目标工作区的聊天框执行。
73
-
74
- 从此前“加载即启动”的版本更新后,同样通过 `init` 启用目标工作区,保留现有安装配置、资料和历史数据。
82
+ 插件安装和工作区启用分别由宿主插件管理与此配置控制。`pbot setup` 可安装 Pi 并启动 `/pbot init`;Claude 使用原生 marketplace 安装。更新保留现有启用配置、资料与历史,新工作区通过相应 init 入口启用。
@@ -0,0 +1,19 @@
1
+ {
2
+ "hooks": {
3
+ "SessionStart": [
4
+ { "hooks": [{ "type": "command", "command": "node", "args": ["${CLAUDE_PLUGIN_ROOT}/lib/claude.js", "hook"], "timeout": 900 }] }
5
+ ],
6
+ "UserPromptSubmit": [
7
+ { "hooks": [{ "type": "command", "command": "node", "args": ["${CLAUDE_PLUGIN_ROOT}/lib/claude.js", "hook"], "timeout": 900 }] }
8
+ ],
9
+ "SubagentStart": [
10
+ { "hooks": [{ "type": "command", "command": "node", "args": ["${CLAUDE_PLUGIN_ROOT}/lib/claude.js", "hook"], "timeout": 30 }] }
11
+ ],
12
+ "PreToolUse": [
13
+ { "matcher": "Skill", "hooks": [{ "type": "command", "command": "node", "args": ["${CLAUDE_PLUGIN_ROOT}/lib/claude.js", "hook"], "timeout": 10 }] }
14
+ ],
15
+ "UserPromptExpansion": [
16
+ { "matcher": "personal-bot:.*", "hooks": [{ "type": "command", "command": "node", "args": ["${CLAUDE_PLUGIN_ROOT}/lib/claude.js", "hook"], "timeout": 10 }] }
17
+ ]
18
+ }
19
+ }
@@ -0,0 +1 @@
1
+ export declare function main(args: readonly string[]): Promise<void>;
package/lib/claude.js ADDED
@@ -0,0 +1,20 @@
1
+ import { realpathSync } from "node:fs";
2
+ import { pathToFileURL } from "node:url";
3
+ import { claudeCommand, claudeHook } from "./extension/claude-hooks.js";
4
+ export async function main(args) {
5
+ if (args[0] === "hook") {
6
+ let input = "";
7
+ process.stdin.setEncoding("utf8");
8
+ for await (const chunk of process.stdin)
9
+ input += String(chunk);
10
+ process.stdout.write(JSON.stringify(await claudeHook(JSON.parse(input))) + "\n");
11
+ }
12
+ else
13
+ process.stdout.write(JSON.stringify(await claudeCommand(args, process.cwd()), null, 2) + "\n");
14
+ }
15
+ if (process.argv[1] && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href) {
16
+ void main(process.argv.slice(2)).catch(error => {
17
+ process.stderr.write("Personal Bot: " + (error instanceof Error ? error.message : String(error)) + "\n");
18
+ process.exitCode = 1;
19
+ });
20
+ }
package/lib/client.js CHANGED
@@ -869,7 +869,7 @@ function showManagement(ctx, parentSessionId) {
869
869
  pageTitle(history, "\u5386\u53F2", "");
870
870
  const searchForm = form(history);
871
871
  searchForm.className = "pbot-search";
872
- const historyQuery = field(searchForm, "\u5173\u952E\u8BCD"), host = select(searchForm, "\u6765\u6E90", [["", "\u5168\u90E8"], ["pi", "Pi"], ["dsh", "dsh"]]);
872
+ const historyQuery = field(searchForm, "\u5173\u952E\u8BCD"), host = select(searchForm, "\u6765\u6E90", [["", "\u5168\u90E8"], ["pi", "Pi"], ["dsh", "dsh"], ["claude", "Claude Code"]]);
873
873
  historyQuery.placeholder = "\u7559\u7A7A\u67E5\u770B\u6700\u8FD1\u4F1A\u8BDD";
874
874
  submit(searchForm, "\u67E5\u8BE2", () => searchHistory());
875
875
  const dateFilters = details(history, "\u65F6\u95F4\u8303\u56F4"), dateGrid = group(dateFilters, "pbot-grid");
@@ -0,0 +1,2 @@
1
+ import type { ValidateFunction } from "ajv";
2
+ export declare function schema(value: unknown): ValidateFunction;
@@ -0,0 +1,10 @@
1
+ import { Ajv } from "ajv";
2
+ import addFormats from "ajv-formats";
3
+ import { object } from "./json.js";
4
+ export function schema(value) {
5
+ if (!object(value))
6
+ throw new Error("需要对象形式的 JSON Schema。");
7
+ const ajv = new Ajv({ strict: false, allErrors: false, validateFormats: true, coerceTypes: false, useDefaults: false, removeAdditional: false });
8
+ addFormats.default(ajv);
9
+ return ajv.compile(value);
10
+ }
@@ -1,3 +1 @@
1
- import type { ValidateFunction } from "ajv";
2
- export declare function schema(value: unknown): ValidateFunction;
3
1
  export declare function requireThat(condition: unknown, message: string): asserts condition;
@@ -1,13 +1,3 @@
1
- import { Ajv } from "ajv";
2
- import addFormats from "ajv-formats";
3
- import { object } from "./json.js";
4
- export function schema(value) {
5
- if (!object(value))
6
- throw new Error("需要对象形式的 JSON Schema。");
7
- const ajv = new Ajv({ strict: false, allErrors: false, validateFormats: true, coerceTypes: false, useDefaults: false, removeAdditional: false });
8
- addFormats.default(ajv);
9
- return ajv.compile(value);
10
- }
11
1
  export function requireThat(condition, message) {
12
2
  if (!condition)
13
3
  throw new Error(message);
@@ -87,7 +87,8 @@ async function main() {
87
87
  try {
88
88
  requireThat(!prompt || reference.backend !== "claude" || connection.systemPrompt, "Claude ACP 后端需要支持 systemPrompt,以加载专家职责与工作区资料。");
89
89
  if (validating) {
90
- process.send?.({ type: "validated" });
90
+ if (process.connected)
91
+ process.send?.({ type: "validated" });
91
92
  return;
92
93
  }
93
94
  if (reference.sessionId === null)
@@ -130,8 +131,10 @@ try {
130
131
  }
131
132
  }
132
133
  catch (error) {
133
- if (validating)
134
- process.send?.({ type: "error", error: String(error) });
134
+ if (validating) {
135
+ if (process.connected)
136
+ process.send?.({ type: "error", error: String(error) });
137
+ }
135
138
  else if (files.read(id, "launch.json", launch).generation === generation) {
136
139
  const stopped = files.read(id, "launch.json", launch).stop;
137
140
  const patch = { state: stopped ? "stopped" : "error", activity: stopped ? "已停止" : "ACP 执行失败", ...(stopped ? {} : { error: String(error) }) };
@@ -0,0 +1,15 @@
1
+ export declare function claudeWorkspaceRoot(cwd: string, projectDirectory?: string | undefined): Promise<string>;
2
+ export declare function claudeCommand(args: readonly string[], cwd: string): Promise<{
3
+ version: string;
4
+ workspaceRoot: string;
5
+ resourceRoot: string;
6
+ configuration: import("../model/workspace-config.js").WorkspaceConfiguration;
7
+ python: {
8
+ executable?: string;
9
+ state: "unprepared" | "preparing" | "ready" | "error";
10
+ directory?: string;
11
+ error?: string;
12
+ };
13
+ }>;
14
+ /** Standard command hooks consume documented stdin fields; native sessions remain entirely host-owned. */
15
+ export declare function claudeHook(value: unknown): Promise<Record<string, unknown>>;
@@ -0,0 +1,104 @@
1
+ import { readFile, realpath, stat } from "node:fs/promises";
2
+ import { isAbsolute, join } from "node:path";
3
+ import { object } from "../common/json.js";
4
+ import { resourceRoot } from "../common/paths.js";
5
+ import { packageVersion } from "../common/version.js";
6
+ import { requireThat } from "../common/validation.js";
7
+ import { agentText } from "../integrations/agent-resources.js";
8
+ import { PythonEnvironmentService } from "../services/workspace/python-environment-service.js";
9
+ import { readWorkspaceConfig } from "../services/workspace/workspace-config.js";
10
+ import { initializeWorkspace } from "../services/workspace/workspace-preparation.js";
11
+ export async function claudeWorkspaceRoot(cwd, projectDirectory = process.env.CLAUDE_PROJECT_DIR) {
12
+ const directory = projectDirectory || cwd;
13
+ requireThat(isAbsolute(directory), "Claude 工作区需要绝对路径。");
14
+ const root = await realpath(directory);
15
+ requireThat((await stat(root)).isDirectory(), "Claude 工作区需要目录。");
16
+ return root;
17
+ }
18
+ async function pythonStatus(root, prepare, force = false) {
19
+ const python = new PythonEnvironmentService(root);
20
+ try {
21
+ if (force)
22
+ await python.setup();
23
+ else {
24
+ const current = await python.inspect();
25
+ if (prepare && current.state === "unprepared")
26
+ await python.setup();
27
+ }
28
+ }
29
+ catch { /* The service retains the preparation or inspection error for status. */ }
30
+ finally {
31
+ await python.close();
32
+ }
33
+ const status = python.status;
34
+ return { ...status, ...(status.state === "ready" ? { executable: join(status.directory, "bin/python") } : {}) };
35
+ }
36
+ function disabled(configuration) {
37
+ return configuration.error ?? "Personal Bot 未在此工作区启用。运行 /personal-bot:pbot init;配置文件:" + configuration.path;
38
+ }
39
+ export async function claudeCommand(args, cwd) {
40
+ const root = await claudeWorkspaceRoot(cwd);
41
+ const action = args.join(" ");
42
+ requireThat(["init", "status", "python setup"].includes(action), "用法:node <插件目录>/lib/claude.js init|status|python setup");
43
+ if (action === "init")
44
+ await initializeWorkspace(root);
45
+ const configuration = await readWorkspaceConfig(root);
46
+ if (action === "python setup")
47
+ requireThat(configuration.enabled, disabled(configuration));
48
+ return { version: packageVersion, workspaceRoot: root, resourceRoot, configuration,
49
+ python: configuration.enabled ? await pythonStatus(root, action !== "status", action === "python setup") : { state: "unprepared" } };
50
+ }
51
+ /** Standard command hooks consume documented stdin fields; native sessions remain entirely host-owned. */
52
+ export async function claudeHook(value) {
53
+ requireThat(object(value) && typeof value.hook_event_name === "string", "Claude hook 输入无效。");
54
+ if (process.env.PBOT_SUBAGENT_RUN_ID)
55
+ return {};
56
+ const event = value.hook_event_name;
57
+ requireThat(["SessionStart", "UserPromptSubmit", "SubagentStart", "PreToolUse", "UserPromptExpansion"].includes(event), "Claude hook 事件未支持。");
58
+ const skillCheck = event === "PreToolUse" || event === "UserPromptExpansion";
59
+ if (skillCheck) {
60
+ const skill = event === "UserPromptExpansion"
61
+ ? value.expansion_type === "slash_command" ? value.command_name : undefined
62
+ : value.tool_name === "Skill" && object(value.tool_input) ? value.tool_input.skill : undefined;
63
+ if (typeof skill !== "string" || !skill.startsWith("personal-bot:") || skill === "personal-bot:pbot")
64
+ return {};
65
+ }
66
+ requireThat(typeof value.cwd === "string", "Claude hook 缺少工作目录。");
67
+ const root = await claudeWorkspaceRoot(value.cwd);
68
+ const configuration = await readWorkspaceConfig(root);
69
+ if (skillCheck) {
70
+ if (configuration.enabled)
71
+ return {};
72
+ return event === "UserPromptExpansion" ? { decision: "block", reason: disabled(configuration) } : { hookSpecificOutput: {
73
+ hookEventName: event, permissionDecision: "deny", permissionDecisionReason: disabled(configuration),
74
+ } };
75
+ }
76
+ if (!configuration.enabled)
77
+ return event === "SubagentStart" ? {} : {
78
+ hookSpecificOutput: { hookEventName: event, additionalContext: disabled(configuration) },
79
+ };
80
+ if (event === "SubagentStart" && value.agent_type !== "personal-bot:general-purpose")
81
+ return {};
82
+ const python = await pythonStatus(root, event === "SessionStart" || event === "UserPromptSubmit");
83
+ if (event === "SessionStart")
84
+ return python.state === "error" ? { systemMessage: python.error } : {};
85
+ const member = event === "SubagentStart" || typeof value.agent_id === "string";
86
+ const role = event === "SubagentStart" ? readFile(join(root, "agents/general-purpose.md"), "utf8").catch(error => {
87
+ if (error.code === "ENOENT")
88
+ return "";
89
+ throw error;
90
+ }) : agentText(member ? "general-purpose" : "coordinator", root, "claude");
91
+ const [workspace, duties, agents] = await Promise.all([
92
+ readFile(join(resourceRoot, "prompts/workspace.md"), "utf8"),
93
+ role,
94
+ readFile(join(root, "AGENTS.md"), "utf8").catch(error => {
95
+ if (error.code === "ENOENT")
96
+ return "";
97
+ throw error;
98
+ }),
99
+ ]);
100
+ return { ...(python.state === "error" ? { systemMessage: python.error } : {}),
101
+ hookSpecificOutput: { hookEventName: event, additionalContext: [
102
+ workspace, duties, agents, JSON.stringify({ workspaceRoot: root, resourceRoot, python }),
103
+ ].filter(Boolean).join("\n\n") } };
104
+ }
@@ -1,6 +1,7 @@
1
1
  import { Type } from "../../common/typebox.js";
2
2
  import { object, json } from "../../common/json.js";
3
- import { requireThat, schema } from "../../common/validation.js";
3
+ import { requireThat } from "../../common/validation.js";
4
+ import { schema } from "../../common/schema.js";
4
5
  import { executeAgent } from "../../tools/agents/actions.js";
5
6
  import { dshAgentActionSchema } from "../../tools/agents/dsh-contract.js";
6
7
  import { executeTeam, executeTeamMessage } from "../../tools/teams/actions.js";
@@ -17,7 +17,7 @@ export class DshHistoryWork {
17
17
  constructor(ctx, root) {
18
18
  this.ctx = ctx;
19
19
  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")));
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
21
  }
22
22
  attach(agent) { this.#parents.add(agent); return () => { this.#parents.delete(agent); }; }
23
23
  cancel() { this.#controller?.abort(); }
@@ -89,7 +89,8 @@ import { SessionId } from "@deepseek-ai/dsh-session";
89
89
  import { extractSessionEventText } from "@deepseek-ai/dsh-session-query";
90
90
  import { Type } from "../../common/typebox.js";
91
91
  import { json } from "../../common/json.js";
92
- import { requireThat, schema } from "../../common/validation.js";
92
+ import { requireThat } from "../../common/validation.js";
93
+ import { schema } from "../../common/schema.js";
93
94
  import { packageVersion } from "../../common/version.js";
94
95
  import { historyInput } from "../../tools/history/contract.js";
95
96
  import { executeHistory } from "../../tools/history/actions.js";
@@ -1 +1 @@
1
- export declare function agentText(agent: "coordinator" | "general-purpose", root: string): Promise<string>;
1
+ export declare function agentText(agent: "coordinator" | "general-purpose", root: string, host?: "pi" | "dsh" | "claude"): Promise<string>;
@@ -2,9 +2,11 @@ import { readFile } from "node:fs/promises";
2
2
  import { join } from "node:path";
3
3
  import { resourceRoot } from "../common/paths.js";
4
4
  import { requireThat } from "../common/validation.js";
5
- export async function agentText(agent, root) {
5
+ export async function agentText(agent, root, host = "pi") {
6
6
  requireThat(agent === "coordinator" || agent === "general-purpose", "未知职责。");
7
7
  let text = await readFile(join(resourceRoot, "agents", agent + ".md"), "utf8");
8
+ if (agent === "coordinator")
9
+ text += "\n\n" + await readFile(join(resourceRoot, "prompts", host === "claude" ? "claude-coordinator.md" : "native-coordinator.md"), "utf8");
8
10
  try {
9
11
  const local = await readFile(join(root, "agents", agent + ".md"), "utf8");
10
12
  text += "\n\n工作区职责补充:\n" + local;
@@ -1,26 +1,22 @@
1
- import { readFile } from "node:fs/promises";
2
- import { join } from "node:path";
3
1
  import { BlockAssembler } from "@deepseek-ai/dsh-llm";
4
- import { resourceRoot } from "../../common/paths.js";
5
2
  import { requireThat } from "../../common/validation.js";
6
3
  import { reduceHistorySummary } from "../history-summary.js";
7
4
  /** Independent text calls through the host's routing and authentication; no Agent or Session messages. */
8
5
  export function dshHistorySummarizer(ctx, selection, sessionId) {
9
- return async (text, signal) => {
6
+ return async (request, signal) => {
10
7
  requireThat(selection, "请先选择 dsh 模型。");
11
8
  signal.throwIfAborted();
12
- const system = await readFile(join(resourceRoot, "prompts/history-summary.md"), { encoding: "utf8", signal });
13
- const prepare = () => ctx.llm.prepareCall({ provider: selection.provider, model: selection.model, maxTokens: 2048 }, signal, (controls, model) => ({ ...controls, ...(model.reasoning?.efforts[0] ? { reasoningEffort: model.reasoning.efforts[0].id } : {}) }));
9
+ const prepare = () => ctx.llm.prepareCall({ provider: selection.provider, model: selection.model, maxTokens: request.maxTokens }, signal, (controls, model) => ({ ...controls, ...(model.reasoning?.efforts[0] ? { reasoningEffort: model.reasoning.efforts[0].id } : {}) }));
14
10
  let first = await prepare();
15
11
  const budget = Math.max(2000, Math.min(24000, Math.floor((first.context?.contextWindow ?? 12000) / 2)));
16
- const ask = async (content, signal) => {
12
+ const ask = async ({ system, prompt }, signal) => {
17
13
  signal.throwIfAborted();
18
14
  const prepared = first ?? await prepare();
19
15
  first = undefined;
20
16
  const assembler = new BlockAssembler();
21
17
  let finished = false;
22
18
  for await (const chunk of prepared.stream({ ...prepared.config, system, sessionId, purpose: "pbot-history", signal, tools: [],
23
- messages: [{ role: "user", content: [{ type: "text", text: content }] }] })) {
19
+ messages: [{ role: "user", content: [{ type: "text", text: prompt }] }] })) {
24
20
  signal.throwIfAborted();
25
21
  assembler.push(chunk);
26
22
  if (chunk.type === "finish")
@@ -35,6 +31,6 @@ export function dshHistorySummarizer(ctx, selection, sessionId) {
35
31
  requireThat(answer, "历史摘要为空。");
36
32
  return answer;
37
33
  };
38
- return reduceHistorySummary(budget, ask)(text, signal);
34
+ return reduceHistorySummary(budget, ask)(request, signal);
39
35
  };
40
36
  }