personal-bot 0.2.14 → 0.2.16

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 (120) hide show
  1. package/.claude-plugin/marketplace.json +3 -3
  2. package/.claude-plugin/plugin.json +2 -2
  3. package/README.md +10 -11
  4. package/README.zh-CN.md +10 -11
  5. package/docs/README.md +2 -2
  6. package/docs/adr/0001-claude-skill-discovery.md +1 -1
  7. package/docs/agent-collaboration.md +8 -9
  8. package/docs/architecture-guidelines.md +1 -1
  9. package/docs/capability-design.md +2 -2
  10. package/docs/claude-code-design.md +10 -11
  11. package/docs/claude-code.md +8 -15
  12. package/docs/dsh.md +18 -19
  13. package/docs/file-storage.md +2 -3
  14. package/docs/installation-design.md +4 -5
  15. package/docs/interaction-design.md +1 -1
  16. package/docs/model-context.md +9 -10
  17. package/docs/release.md +5 -5
  18. package/docs/technical-design.md +16 -21
  19. package/docs/workspace-configuration.md +5 -8
  20. package/hooks/hooks.json +1 -4
  21. package/lib/client.js +3 -15
  22. package/lib/common/schema.d.ts +2 -0
  23. package/lib/common/schema.js +9 -0
  24. package/lib/extension/acp-member.js +1 -3
  25. package/lib/extension/acp-worker.js +3 -22
  26. package/lib/extension/claude-hooks.d.ts +0 -6
  27. package/lib/extension/claude-hooks.js +5 -31
  28. package/lib/extension/dsh/acp-member.js +1 -2
  29. package/lib/extension/dsh/command.js +13 -23
  30. package/lib/extension/dsh/management.d.ts +1 -1
  31. package/lib/extension/dsh/management.js +3 -3
  32. package/lib/extension/dsh/workspace.d.ts +1 -9
  33. package/lib/extension/dsh/workspace.js +4 -31
  34. package/lib/extension/setup-cli.js +4 -4
  35. package/lib/integrations/dsh/dsh-agents.d.ts +1 -2
  36. package/lib/integrations/dsh/dsh-agents.js +0 -4
  37. package/lib/integrations/dsh/resources.d.ts +1 -5
  38. package/lib/integrations/dsh/resources.js +2 -5
  39. package/lib/integrations/installation/processes.js +0 -15
  40. package/lib/model/agent.d.ts +0 -1
  41. package/lib/services/agents/agent-notices.js +1 -1
  42. package/lib/services/agents/agent-service.js +3 -2
  43. package/lib/services/agents/start-options.d.ts +4 -0
  44. package/lib/services/agents/start-options.js +20 -0
  45. package/lib/tools/agents/actions.d.ts +1 -5
  46. package/lib/tools/agents/actions.js +12 -1
  47. package/lib/tools/agents/contract.d.ts +50 -77
  48. package/lib/tools/agents/contract.js +54 -32
  49. package/lib/tools/agents/dsh-tool.js +6 -11
  50. package/lib/tools/history/contract.d.ts +28 -11
  51. package/lib/tools/history/contract.js +18 -12
  52. package/lib/tools/input.d.ts +11 -0
  53. package/lib/tools/input.js +23 -0
  54. package/lib/tools/teams/actions.d.ts +3 -4
  55. package/lib/tools/teams/actions.js +7 -5
  56. package/lib/tools/teams/contract.d.ts +56 -87
  57. package/lib/tools/teams/contract.js +55 -31
  58. package/lib/tools/teams/dsh-tool.js +7 -18
  59. package/lib/ui/dsh/management.js +1 -9
  60. package/lib/ui/dsh/styles.d.ts +1 -1
  61. package/lib/ui/dsh/styles.js +2 -2
  62. package/lib/ui/presentation.js +1 -1
  63. package/package.json +1 -4
  64. package/resources/claude/skills/pbot/SKILL.md +2 -3
  65. package/resources/prompts/native-coordinator.md +1 -1
  66. package/resources/prompts/workspace.md +1 -1
  67. package/resources/references/compute.md +6 -8
  68. package/scripts/README.md +2 -6
  69. package/src/common/schema.ts +10 -0
  70. package/src/extension/acp-member.ts +1 -3
  71. package/src/extension/acp-worker.ts +3 -12
  72. package/src/extension/agent-events.ts +1 -1
  73. package/src/extension/claude-hooks.ts +5 -25
  74. package/src/extension/command.ts +7 -16
  75. package/src/extension/dsh/acp-member.ts +1 -2
  76. package/src/extension/dsh/command.ts +14 -23
  77. package/src/extension/dsh/management.ts +3 -3
  78. package/src/extension/dsh/workspace.ts +5 -26
  79. package/src/extension/events.ts +2 -11
  80. package/src/extension/lifecycle.ts +8 -23
  81. package/src/extension/setup-cli.ts +4 -4
  82. package/src/extension/subagent-entry.ts +6 -12
  83. package/src/integrations/dsh/dsh-agents.ts +1 -4
  84. package/src/integrations/dsh/resources.ts +2 -5
  85. package/src/integrations/installation/processes.ts +0 -13
  86. package/src/integrations/pi/pi-agents.ts +12 -5
  87. package/src/model/agent.ts +1 -1
  88. package/src/pbot.ts +1 -2
  89. package/src/services/agents/agent-notices.ts +1 -1
  90. package/src/services/agents/agent-service.ts +4 -2
  91. package/src/services/agents/start-options.ts +19 -0
  92. package/src/tools/agents/actions.ts +18 -10
  93. package/src/tools/agents/contract.ts +68 -33
  94. package/src/tools/agents/dsh-tool.ts +7 -12
  95. package/src/tools/agents/tool.ts +2 -8
  96. package/src/tools/history/actions.ts +1 -1
  97. package/src/tools/history/contract.ts +27 -14
  98. package/src/tools/input.ts +29 -0
  99. package/src/tools/teams/actions.ts +10 -14
  100. package/src/tools/teams/contract.ts +71 -33
  101. package/src/tools/teams/dsh-tool.ts +7 -18
  102. package/src/tools/teams/tool.ts +3 -13
  103. package/src/ui/dsh/management.ts +2 -8
  104. package/src/ui/dsh/styles.ts +2 -2
  105. package/src/ui/presentation.ts +1 -1
  106. package/lib/integrations/process.d.ts +0 -14
  107. package/lib/integrations/process.js +0 -48
  108. package/lib/integrations/python-activation.d.ts +0 -2
  109. package/lib/integrations/python-activation.js +0 -29
  110. package/lib/services/workspace/python-environment-service.d.ts +0 -21
  111. package/lib/services/workspace/python-environment-service.js +0 -66
  112. package/lib/tools/agents/dsh-contract.d.ts +0 -45
  113. package/lib/tools/agents/dsh-contract.js +0 -19
  114. package/python/README.md +0 -72
  115. package/python/requirements.lock +0 -38
  116. package/scripts/setup-python.py +0 -170
  117. package/src/integrations/process.ts +0 -40
  118. package/src/integrations/python-activation.ts +0 -23
  119. package/src/services/workspace/python-environment-service.ts +0 -61
  120. package/src/tools/agents/dsh-contract.ts +0 -20
@@ -1,84 +1,57 @@
1
1
  import { Type } from "typebox";
2
- export declare const agentDescription = "\u59D4\u6D3E\u4E13\u5BB6\u5E76\u7EE7\u7EED\u5BF9\u8BDD\u3002start \u542F\u52A8\u540E\u5373\u8FD4\u56DE\uFF0C\u5B8C\u6210\u81EA\u52A8\u901A\u77E5\uFF0C\u65E0\u9700\u8F6E\u8BE2\uFF1B\u7701\u7565\u521D\u59CB\u8F93\u5165\u65F6\u5F85\u547D\u3002send \u7EE7\u7EED\u5BF9\u8BDD\uFF0C\u56E2\u961F\u5360\u7528\u671F\u95F4\u4E0D\u53EF\u79C1\u4EBA send\u3002status \u67E5\u770B\u72B6\u6001\uFF0Cread \u8BFB\u53D6\u62A5\u544A\uFF1B\u8BFB\u53D6\u5DF2\u7ED3\u675F\u5468\u671F\u5373\u9886\u53D6\u5176\u901A\u77E5\uFF0C\u5305\u62EC\u90E8\u5206\u8BFB\u53D6\u3002\u7EED\u8BFB\u56FA\u5B9A cycle.cycleId \u5E76\u4F7F\u7528 nextOffset\u3002state \u8868\u793A\u6267\u884C\u72B6\u6001\uFF0Ccycle.state \u8868\u793A\u5DE5\u4F5C\u7ED3\u679C\uFF0Cqueued \u53EA\u8868\u793A\u5165\u961F\u3002stop \u4FDD\u7559\u5386\u53F2\uFF0Cresume \u643A\u65B0 message \u7EE7\u7EED\u3002\u6BCF\u4E2A\u7236\u4F1A\u8BDD\u6700\u591A 50 \u4E2A\u5B58\u6D3B\u4E13\u5BB6\uFF0C\u7A7A\u95F2\u4E5F\u8BA1\u5165\u3002";
3
- export declare const agentStartOptions: {
4
- backend: Type.TOptional<Type.TUnion<[Type.TLiteral<"pi">, Type.TLiteral<"dsh">, Type.TLiteral<"claude">]>>;
5
- name: Type.TOptional<Type.TString>;
6
- message: Type.TOptional<Type.TString>;
7
- files: Type.TOptional<Type.TArray<Type.TString>>;
8
- prompts: Type.TOptional<Type.TArray<Type.TString>>;
9
- provider: Type.TOptional<Type.TString>;
10
- model: Type.TOptional<Type.TString>;
11
- thinking: Type.TOptional<Type.TString>;
12
- cwd: Type.TOptional<Type.TString>;
13
- tools: Type.TOptional<Type.TArray<Type.TString>>;
14
- noExtensions: Type.TOptional<Type.TBoolean>;
15
- noSkills: Type.TOptional<Type.TBoolean>;
16
- noPromptTemplates: Type.TOptional<Type.TBoolean>;
17
- noContextFiles: Type.TOptional<Type.TBoolean>;
18
- };
2
+ import type { AgentStartOptions } from "../../model/agent.js";
3
+ export declare const agentDescription = "\u59D4\u6D3E\u4E13\u5BB6\u5E76\u7EE7\u7EED\u5BF9\u8BDD\u3002start \u542F\u52A8\u540E\u5373\u8FD4\u56DE\uFF0C\u5B8C\u6210\u81EA\u52A8\u901A\u77E5\uFF0C\u65E0\u9700\u8F6E\u8BE2\uFF1B\u7701\u7565\u521D\u59CB\u8F93\u5165\u65F6\u5F85\u547D\u3002send \u7EE7\u7EED\u5BF9\u8BDD\uFF0C\u56E2\u961F\u5360\u7528\u671F\u95F4\u4E0D\u53EF\u79C1\u4EBA send\u3002status \u67E5\u770B\u72B6\u6001\uFF0Cread \u8BFB\u53D6\u62A5\u544A\uFF1B\u8BFB\u53D6\u5DF2\u7ED3\u675F\u5468\u671F\u5373\u9886\u53D6\u5176\u901A\u77E5\uFF0C\u5305\u62EC\u90E8\u5206\u8BFB\u53D6\u3002\u7EED\u8BFB\u56FA\u5B9A cycle.cycleId \u5E76\u4F7F\u7528 nextOffset\u3002state \u8868\u793A\u6267\u884C\u72B6\u6001\uFF0Ccycle.state \u8868\u793A\u5DE5\u4F5C\u7ED3\u679C\uFF0Cqueued \u53EA\u8868\u793A\u5165\u961F\u3002stop \u4FDD\u7559\u5386\u53F2\uFF0Cresume \u643A\u65B0 message \u7EE7\u7EED\u3002\u6BCF\u4E2A\u7236\u4F1A\u8BDD\u6700\u591A 50 \u4E2A\u5B58\u6D3B\u4E13\u5BB6\uFF0C\u7A7A\u95F2\u4E5F\u8BA1\u5165\u3002\u52A8\u4F5C\u53EA\u8BFB\u53D6\u81EA\u5DF1\u7684\u5B57\u6BB5\uFF1B\u5176\u4ED6\u5DF2\u58F0\u660E\u5B57\u6BB5\u5FFD\u7565\u3002";
19
4
  export declare const agentParametersSchema: Type.TObject<{
20
- delivery: Type.TOptional<Type.TUnion<[Type.TLiteral<"steer">, Type.TLiteral<"followUp">]>>;
21
- cycleId: Type.TOptional<Type.TString>;
22
- offset: Type.TOptional<Type.TInteger>;
23
- limit: Type.TOptional<Type.TInteger>;
24
- backend: Type.TOptional<Type.TUnion<[Type.TLiteral<"pi">, Type.TLiteral<"dsh">, Type.TLiteral<"claude">]>>;
25
- name: Type.TOptional<Type.TString>;
26
- message: Type.TOptional<Type.TString>;
27
- files: Type.TOptional<Type.TArray<Type.TString>>;
28
- prompts: Type.TOptional<Type.TArray<Type.TString>>;
29
- provider: Type.TOptional<Type.TString>;
30
- model: Type.TOptional<Type.TString>;
31
- thinking: Type.TOptional<Type.TString>;
32
- cwd: Type.TOptional<Type.TString>;
33
- tools: Type.TOptional<Type.TArray<Type.TString>>;
34
- noExtensions: Type.TOptional<Type.TBoolean>;
35
- noSkills: Type.TOptional<Type.TBoolean>;
36
- noPromptTemplates: Type.TOptional<Type.TBoolean>;
37
- noContextFiles: Type.TOptional<Type.TBoolean>;
5
+ cycleId: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
6
+ offset: Type.TOptional<Type.TUnion<[Type.TInteger, Type.TNull]>>;
7
+ limit: Type.TOptional<Type.TUnion<[Type.TInteger, Type.TNull]>>;
8
+ delivery: Type.TOptional<Type.TUnion<[Type.TUnion<[Type.TLiteral<"steer">, Type.TLiteral<"followUp">]>, Type.TNull]>>;
9
+ backend: Type.TOptional<Type.TUnion<[Type.TUnion<[Type.TLiteral<"pi">, Type.TLiteral<"dsh">, Type.TLiteral<"claude">]>, Type.TNull]>>;
10
+ name: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
11
+ message: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
12
+ files: Type.TOptional<Type.TUnion<[Type.TArray<Type.TString>, Type.TNull]>>;
13
+ provider: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
14
+ model: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
15
+ thinking: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
16
+ cwd: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
17
+ tools: Type.TOptional<Type.TUnion<[Type.TArray<Type.TString>, Type.TNull]>>;
18
+ noExtensions: Type.TOptional<Type.TUnion<[Type.TBoolean, Type.TNull]>>;
19
+ noSkills: Type.TOptional<Type.TUnion<[Type.TBoolean, Type.TNull]>>;
20
+ noPromptTemplates: Type.TOptional<Type.TUnion<[Type.TBoolean, Type.TNull]>>;
21
+ noContextFiles: Type.TOptional<Type.TUnion<[Type.TBoolean, Type.TNull]>>;
38
22
  action: Type.TUnion<[Type.TLiteral<"start">, Type.TLiteral<"send">, Type.TLiteral<"rename">, Type.TLiteral<"status">, Type.TLiteral<"list">, Type.TLiteral<"read">, Type.TLiteral<"stop">, Type.TLiteral<"resume">]>;
39
- agentId: Type.TOptional<Type.TString>;
23
+ agentId: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
40
24
  }>;
41
- export declare const agentActionSchema: Type.TUnion<[Type.TObject<{
42
- backend: Type.TOptional<Type.TUnion<[Type.TLiteral<"pi">, Type.TLiteral<"dsh">, Type.TLiteral<"claude">]>>;
43
- name: Type.TOptional<Type.TString>;
44
- message: Type.TOptional<Type.TString>;
45
- files: Type.TOptional<Type.TArray<Type.TString>>;
46
- prompts: Type.TOptional<Type.TArray<Type.TString>>;
47
- provider: Type.TOptional<Type.TString>;
48
- model: Type.TOptional<Type.TString>;
49
- thinking: Type.TOptional<Type.TString>;
50
- cwd: Type.TOptional<Type.TString>;
51
- tools: Type.TOptional<Type.TArray<Type.TString>>;
52
- noExtensions: Type.TOptional<Type.TBoolean>;
53
- noSkills: Type.TOptional<Type.TBoolean>;
54
- noPromptTemplates: Type.TOptional<Type.TBoolean>;
55
- noContextFiles: Type.TOptional<Type.TBoolean>;
56
- action: Type.TLiteral<"start">;
57
- }>, Type.TObject<{
58
- action: Type.TLiteral<"send">;
59
- agentId: Type.TString;
60
- message: Type.TString;
61
- delivery: Type.TOptional<Type.TUnion<[Type.TLiteral<"steer">, Type.TLiteral<"followUp">]>>;
62
- }>, Type.TObject<{
63
- action: Type.TLiteral<"rename">;
64
- agentId: Type.TString;
65
- name: Type.TString;
66
- }>, Type.TObject<{
67
- action: Type.TLiteral<"resume">;
68
- agentId: Type.TString;
69
- message: Type.TString;
70
- }>, Type.TObject<{
71
- action: Type.TLiteral<"list">;
72
- }>, ...Type.TObject<{
73
- action: Type.TLiteral<string>;
74
- agentId: Type.TString;
75
- }>[], Type.TObject<{
76
- cycleId: Type.TOptional<Type.TString>;
77
- offset: Type.TOptional<Type.TInteger>;
78
- limit: Type.TOptional<Type.TInteger>;
79
- action: Type.TLiteral<"read">;
80
- agentId: Type.TString;
81
- }>]>;
25
+ export type AgentAction = "start" | "send" | "rename" | "status" | "list" | "read" | "stop" | "resume";
26
+ export type AgentInput = ({
27
+ action: "start";
28
+ } & AgentStartOptions) | {
29
+ action: "send";
30
+ agentId: string;
31
+ message: string;
32
+ delivery?: "steer" | "followUp";
33
+ } | {
34
+ action: "resume";
35
+ agentId: string;
36
+ message: string;
37
+ } | {
38
+ action: "rename";
39
+ agentId: string;
40
+ name: string;
41
+ } | {
42
+ action: "stop" | "status";
43
+ agentId: string;
44
+ } | {
45
+ action: "list";
46
+ } | {
47
+ action: "read";
48
+ agentId: string;
49
+ cycleId?: string;
50
+ offset?: number;
51
+ limit?: number;
52
+ };
53
+ /** One flat record, one interpreter. Fields outside the selected action are inert. */
54
+ export declare function agentInput(value: unknown): AgentInput;
82
55
  export declare const agentViewSchema: Type.TObject<{
83
56
  agentId: Type.TString;
84
57
  name: Type.TString;
@@ -1,44 +1,66 @@
1
1
  import { Type } from "../../common/typebox.js";
2
- export const agentDescription = "委派专家并继续对话。start 启动后即返回,完成自动通知,无需轮询;省略初始输入时待命。send 继续对话,团队占用期间不可私人 send。status 查看状态,read 读取报告;读取已结束周期即领取其通知,包括部分读取。续读固定 cycle.cycleId 并使用 nextOffset。state 表示执行状态,cycle.state 表示工作结果,queued 只表示入队。stop 保留历史,resume 携新 message 继续。每个父会话最多 50 个存活专家,空闲也计入。";
2
+ import { requireThat } from "../../common/validation.js";
3
+ import { schema } from "../../common/schema.js";
4
+ import { inputObject, need, nullable, pick } from "../input.js";
5
+ export const agentDescription = "委派专家并继续对话。start 启动后即返回,完成自动通知,无需轮询;省略初始输入时待命。send 继续对话,团队占用期间不可私人 send。status 查看状态,read 读取报告;读取已结束周期即领取其通知,包括部分读取。续读固定 cycle.cycleId 并使用 nextOffset。state 表示执行状态,cycle.state 表示工作结果,queued 只表示入队。stop 保留历史,resume 携新 message 继续。每个父会话最多 50 个存活专家,空闲也计入。动作只读取自己的字段;其他已声明字段忽略。";
3
6
  const id = Type.String({ minLength: 1, maxLength: 128 });
4
7
  const message = Type.String({ minLength: 1, maxLength: 24000, description: "本次目标、相关资料、约束和交付要求。" });
5
8
  const name = Type.String({ minLength: 1, maxLength: 64, pattern: "^[^\\r\\n\\x00-\\x1f]+$" });
6
- export const agentStartOptions = {
7
- backend: Type.Optional(Type.Union([Type.Literal("pi"), Type.Literal("dsh"), Type.Literal("claude")], { description: "选择已安装并配置的子代理程序:pi、dsh 或 claude(Claude Code)。省略时使用当前宿主的原生专家;显式选择时使用目标程序自己的配置。团队成员须省略 backend。" })),
8
- name: Type.Optional(name), message: Type.Optional(message),
9
- files: Type.Optional(Type.Array(Type.String({ minLength: 1 }), { maxItems: 32, description: "随初始消息读取的文件;相对路径基于原工作区根目录。" })),
10
- prompts: Type.Optional(Type.Array(message, { maxItems: 32, description: "与 message 按顺序合并为同一初始消息。" })),
11
- provider: Type.Optional(Type.String({ ...id, description: "模型提供方。省略 backend 时默认继承主会话;指定 backend 时,此参数须与 model 一起提供。Claude 子代理省略此参数。" })),
12
- model: Type.Optional(Type.String({ ...id, description: "模型 ID;指定 backend 时也可使用目标公开的完整模型值。默认值:省略 backend 时继承主会话,指定时使用目标配置。Pi/dsh 同名模型可用 provider 区分。" })),
13
- thinking: Type.Optional(Type.String({ minLength: 1, maxLength: 128, description: "思考等级 ID,可单独指定。默认值:省略 backend 时继承主会话,指定时使用目标配置。Pi 使用 off/minimal/low/medium/high/xhigh/max,其他程序使用其原生等级 ID。" })),
14
- cwd: Type.Optional(Type.String({ minLength: 1, description: "执行目录,相对原工作区根目录;省略时使用工作区根目录。" })),
15
- tools: Type.Optional(Type.Array(id, { minItems: 1, description: "Pi/dsh 子代理的工具名;省略时使用所选程序默认工具。Claude 子代理省略此参数并沿用原生配置。" })),
16
- noExtensions: Type.Optional(Type.Boolean({ description: "仅用于 Pi 子代理:关闭其他扩展的自动发现,默认 true。" })),
17
- noSkills: Type.Optional(Type.Boolean({ description: "Pi/dsh 子代理关闭技能发现,默认 false;Claude 子代理省略此参数并沿用原生配置。" })),
18
- noPromptTemplates: Type.Optional(Type.Boolean({ description: "仅用于 Pi 子代理:关闭提示模板发现,默认 false。" })),
19
- noContextFiles: Type.Optional(Type.Boolean({ description: "仅用于 Pi 子代理:关闭原生上下文文件加载,默认 false。" })),
9
+ const startFields = {
10
+ backend: nullable(Type.Union([Type.Literal("pi"), Type.Literal("dsh"), Type.Literal("claude")], { description: "选择 ACP 子代理程序:pi、dsh 或 claude(Claude Code)。省略时使用当前宿主的原生专家;指定时使用目标程序自己的配置。" })),
11
+ name: nullable(name), message: nullable(message),
12
+ files: nullable(Type.Array(Type.String({ minLength: 1 }), { maxItems: 32, description: "随初始消息读取的文件;相对路径基于原工作区根目录。" })),
13
+ provider: nullable(Type.String({ ...id, description: "模型提供方覆盖项;省略时继承主会话或使用 ACP 目标配置。指定时须同时指定 model。" })),
14
+ model: nullable(Type.String({ ...id, description: "模型 ID 覆盖项;省略时继承主会话或使用 ACP 目标配置。Pi/dsh 同名模型可用 provider 区分。" })),
15
+ thinking: nullable(Type.String({ minLength: 1, maxLength: 128, description: "思考等级覆盖项;省略时继承主会话或使用 ACP 目标配置。Pi 使用 off/minimal/low/medium/high/xhigh/max,其他程序使用其原生等级 ID。" })),
16
+ cwd: nullable(Type.String({ minLength: 1, description: "执行目录,相对原工作区根目录;省略时使用工作区根目录。" })),
17
+ tools: nullable(Type.Array(id, { minItems: 1, description: "Pi/dsh 子代理的工具名;省略时使用所选程序默认工具。Claude 子代理忽略此项并沿用原生配置。" })),
18
+ noExtensions: nullable(Type.Boolean({ description: "仅用于 Pi 子代理:关闭其他扩展的自动发现,默认 true。" })),
19
+ noSkills: nullable(Type.Boolean({ description: "Pi/dsh 子代理关闭技能发现,默认 false;Claude 子代理忽略此项并沿用原生配置。" })),
20
+ noPromptTemplates: nullable(Type.Boolean({ description: "仅用于 Pi 子代理:关闭提示模板发现,默认 false。" })),
21
+ noContextFiles: nullable(Type.Boolean({ description: "仅用于 Pi 子代理:关闭原生上下文文件加载,默认 false。" })),
20
22
  };
21
- const page = {
22
- cycleId: Type.Optional(Type.String({ ...id, description: "仅 read:省略时读取最近周期;按 nextOffset 续读时须固定为上页返回的 cycle.cycleId,避免切换到新周期。" })),
23
- offset: Type.Optional(Type.Integer({ minimum: 0, description: "仅 read:报告正文的 UTF-16 字符偏移,默认 0;续读使用上页 nextOffset。" })),
24
- limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 16000, description: "仅 read:最多返回的正文 UTF-16 字符数,默认 16000,不是消息数或 token 数。" })),
25
- };
26
- const delivery = Type.Optional(Type.Union([Type.Literal("steer"), Type.Literal("followUp")], { description: "send 默认 steer 补充当前工作;followUp 排到当前工作之后。capabilities.steer 为 false 的成员运行中使用 followUp。" }));
27
23
  export const agentParametersSchema = Type.Object({
28
24
  action: Type.Union([Type.Literal("start"), Type.Literal("send"), Type.Literal("rename"), Type.Literal("status"), Type.Literal("list"), Type.Literal("read"), Type.Literal("stop"), Type.Literal("resume")], {
29
- description: "start 仅接受启动选项,可省略 message/prompts/files 创建待命会话,禁止 agentId/delivery/分页字段;list 只接受 action;status/stop 只接受并必填 agentId;send 必填 agentId/message,仅可选 delivery;resume 必填 agentId/message;rename 必填 agentId/name;read 必填 agentId,仅可选 cycleId/offset/limit。禁止携带其他 action 的字段。",
25
+ description: "start 创建专家;省略 message/files 即待命。send 必填 agentId/message,可选 delivery。resume 必填 agentId/message。stop/status 必填 agentId。rename 必填 agentId/name。read 必填 agentId,可选 cycleId/offset/limit。list 只需 action。动作只读取自己的字段;其他已声明字段忽略。",
30
26
  }),
31
- agentId: Type.Optional(id), ...agentStartOptions, ...page, delivery,
27
+ agentId: nullable(id), ...startFields,
28
+ cycleId: nullable(Type.String({ ...id, description: "仅 read:省略时读取最近周期;按 nextOffset 续读时须固定为上页返回的 cycle.cycleId,避免切换到新周期。" })),
29
+ offset: nullable(Type.Integer({ minimum: 0, description: "仅 read:报告正文的 UTF-16 字符偏移,默认 0;续读使用上页 nextOffset。" })),
30
+ limit: nullable(Type.Integer({ minimum: 1, maximum: 16000, description: "仅 read:最多返回的正文 UTF-16 字符数,默认 16000,不是消息数或 token 数。" })),
31
+ delivery: nullable(Type.Union([Type.Literal("steer"), Type.Literal("followUp")], { description: "仅 send:默认 steer 补充当前工作;followUp 排到当前工作之后。capabilities.steer 为 false 的成员运行中使用 followUp。" })),
32
32
  }, { additionalProperties: false });
33
- export const agentActionSchema = Type.Union([
34
- Type.Object({ action: Type.Literal("start"), ...agentStartOptions }, { additionalProperties: false }),
35
- Type.Object({ action: Type.Literal("send"), agentId: id, message, delivery }, { additionalProperties: false }),
36
- Type.Object({ action: Type.Literal("rename"), agentId: id, name }, { additionalProperties: false }),
37
- Type.Object({ action: Type.Literal("resume"), agentId: id, message }, { additionalProperties: false }),
38
- Type.Object({ action: Type.Literal("list") }, { additionalProperties: false }),
39
- ...["stop", "status"].map(action => Type.Object({ action: Type.Literal(action), agentId: id }, { additionalProperties: false })),
40
- Type.Object({ action: Type.Literal("read"), agentId: id, ...page }, { additionalProperties: false }),
41
- ]);
33
+ const startKeys = Object.keys(startFields);
34
+ const valid = schema(agentParametersSchema);
35
+ /** One flat record, one interpreter. Fields outside the selected action are inert. */
36
+ export function agentInput(value) {
37
+ const args = inputObject(value, valid, "专家参数格式无效");
38
+ const action = args.action;
39
+ switch (action) {
40
+ case "start":
41
+ requireThat(!args.provider || args.model !== undefined, "start 需要同时提供 provider 与 model。");
42
+ return { action, ...pick(args, startKeys) };
43
+ case "send":
44
+ return { action, agentId: need("send", args, "agentId"), message: need("send", args, "message"),
45
+ ...(args.delivery === undefined ? {} : { delivery: args.delivery }) };
46
+ case "resume":
47
+ return { action, agentId: need("resume", args, "agentId"), message: need("resume", args, "message") };
48
+ case "rename":
49
+ return { action, agentId: need("rename", args, "agentId"), name: need("rename", args, "name") };
50
+ case "stop":
51
+ case "status":
52
+ return { action, agentId: need(action, args, "agentId") };
53
+ case "list":
54
+ return { action };
55
+ case "read":
56
+ return { action, agentId: need("read", args, "agentId"),
57
+ ...(args.cycleId === undefined ? {} : { cycleId: args.cycleId }),
58
+ ...(args.offset === undefined ? {} : { offset: args.offset }),
59
+ ...(args.limit === undefined ? {} : { limit: args.limit }) };
60
+ default:
61
+ throw new Error("未知的专家 action。");
62
+ }
63
+ }
42
64
  const cycle = Type.Object({ cycleId: Type.String(), startedAt: Type.Number(), finishedAt: Type.Optional(Type.Number()),
43
65
  state: Type.Union([Type.Literal("running"), Type.Literal("completed"), Type.Literal("failed"), Type.Literal("cancelled"), Type.Literal("interrupted")], { description: "本周期的工作结果,正文用 read 读取。" }),
44
66
  requestIds: Type.Array(Type.String()),
@@ -4,13 +4,11 @@ import { requireThat } from "../../common/validation.js";
4
4
  import { schema } from "../../common/schema.js";
5
5
  import { markdownFields } from "../../common/markdown.js";
6
6
  import { executeAgent } from "./actions.js";
7
- import { agentDescription, agentResultSchema } from "./contract.js";
8
- import { dshAgentActionSchema, dshAgentParametersSchema } from "./dsh-contract.js";
7
+ import { agentDescription, agentInput, agentParametersSchema, agentResultSchema } from "./contract.js";
9
8
  export function registerDshAgentTool(ctx, agent, service, owner, check) {
10
- const validators = new Map(dshAgentActionSchema.anyOf.map(row => [row.properties.action.const, schema(row)]));
11
9
  const validOutput = schema(agentResultSchema);
12
10
  ctx.tools.register({ name: "pbot_agent", description: agentDescription,
13
- parameters: dshParameters(dshAgentParametersSchema),
11
+ parameters: dshParameters(agentParametersSchema),
14
12
  output: {
15
13
  schema: dshOutputSchema(agentResultSchema),
16
14
  render: (_args, value) => [{ type: "text", text: "# 专家\n\n" + markdownFields(value) }],
@@ -23,14 +21,11 @@ export function registerDshAgentTool(ctx, agent, service, owner, check) {
23
21
  async execute(args, exec) {
24
22
  check();
25
23
  exec.signal.throwIfAborted();
26
- requireThat(exec.agent === agent && object(args) && typeof args.action === "string", "专家工具会话或参数无效。");
27
- const valid = validators.get(args.action);
28
- requireThat(valid && valid(args), "dsh 专家参数无效或包含不支持的宿主选项。");
29
- const selection = agent.model.current();
30
- const output = await executeAgent(service, args, owner, selection ? {
24
+ requireThat(exec.agent === agent, "专家工具不属于当前会话。");
25
+ const input = agentInput(args), selection = agent.model.current();
26
+ const output = await executeAgent(service, input, owner, selection ? {
31
27
  provider: selection.provider, model: selection.model,
32
- ...(selection.reasoningEffort && (!args.provider || args.provider === selection.provider) && (!args.model || args.model === selection.model)
33
- ? { thinking: selection.reasoningEffort } : {}),
28
+ ...(selection.reasoningEffort ? { thinking: selection.reasoningEffort } : {}),
34
29
  } : {});
35
30
  requireThat(validOutput(output.structuredContent), "专家输出不符合契约。");
36
31
  return output.structuredContent;
@@ -1,4 +1,5 @@
1
- import { Type, type Static } from "typebox";
1
+ import { Type } from "typebox";
2
+ import type { HistoryHost } from "../../model/history.js";
2
3
  export declare const historyResultSchema: Type.TObject<{
3
4
  matches: Type.TOptional<Type.TArray<Type.TObject<{
4
5
  snippet: Type.TString;
@@ -67,15 +68,31 @@ export declare const historyResultSchema: Type.TObject<{
67
68
  export declare const historyDescription = "\u67E5\u8BE2\u5F53\u524D\u5DE5\u4F5C\u533A\u7684 Pi/dsh \u95EE\u7B54\u4E0E\u5DF2\u6709 Claude \u5F52\u6863\uFF0Chost \u53EF\u7B5B\u9009\u6765\u6E90\u3002search \u6309\u4E0D\u533A\u5206\u5927\u5C0F\u5199\u7684\u8FDE\u7EED\u6587\u672C\u5339\u914D\u539F\u6587\u548C\u6458\u8981\uFF1B\u65E0\u5339\u914D\u65F6\u6362\u8BCD\uFF0C\u7701\u7565 query \u5217\u4F1A\u8BDD\u3002read \u6309 parents/children \u7684 id \u5C55\u5F00\uFF0CnextOffset \u7EED\u8BFB\u6B63\u6587\uFF0CnextChildrenOffset \u7EED\u8BFB\u5B50\u8282\u70B9\u3002\u9700\u8981\u5BF9\u8BDD\u7EC6\u8282\u65F6\u8BFB\u53D6 exchange \u539F\u6587\uFF1B\u9700\u8981\u5DE5\u5177\u65E5\u5FD7\u65F6\u67E5\u6240\u5C5E\u5BBF\u4E3B\u7684\u539F\u59CB\u4F1A\u8BDD\u3002";
68
69
  export declare const historyParameters: Type.TObject<{
69
70
  action: Type.TUnion<[Type.TLiteral<"search">, Type.TLiteral<"read">]>;
70
- host: Type.TOptional<Type.TUnion<[Type.TLiteral<"pi">, Type.TLiteral<"dsh">, Type.TLiteral<"claude">]>>;
71
- query: Type.TOptional<Type.TString>;
72
- sessionId: Type.TOptional<Type.TString>;
73
- from: Type.TOptional<Type.TString>;
74
- to: Type.TOptional<Type.TString>;
75
- id: Type.TOptional<Type.TString>;
76
- offset: Type.TOptional<Type.TInteger>;
77
- limit: Type.TOptional<Type.TInteger>;
78
- childrenOffset: Type.TOptional<Type.TInteger>;
71
+ host: Type.TOptional<Type.TUnion<[Type.TUnion<[Type.TLiteral<"pi">, Type.TLiteral<"dsh">, Type.TLiteral<"claude">]>, Type.TNull]>>;
72
+ query: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
73
+ sessionId: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
74
+ from: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
75
+ to: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
76
+ id: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
77
+ offset: Type.TOptional<Type.TUnion<[Type.TInteger, Type.TNull]>>;
78
+ limit: Type.TOptional<Type.TUnion<[Type.TInteger, Type.TNull]>>;
79
+ childrenOffset: Type.TOptional<Type.TUnion<[Type.TInteger, Type.TNull]>>;
79
80
  }>;
80
- export type HistoryInput = Static<typeof historyParameters>;
81
+ export type HistoryInput = {
82
+ action: "search";
83
+ host?: HistoryHost;
84
+ query?: string;
85
+ sessionId?: string;
86
+ from?: string;
87
+ to?: string;
88
+ offset?: number;
89
+ limit?: number;
90
+ } | {
91
+ action: "read";
92
+ id: string;
93
+ host?: HistoryHost;
94
+ offset?: number;
95
+ limit?: number;
96
+ childrenOffset?: number;
97
+ };
81
98
  export declare function historyInput(value: unknown): HistoryInput;
@@ -1,6 +1,7 @@
1
1
  import { Type } from "../../common/typebox.js";
2
2
  import { requireThat } from "../../common/validation.js";
3
3
  import { schema } from "../../common/schema.js";
4
+ import { inputObject, need, nullable, pick } from "../input.js";
4
5
  const host = Type.Union([Type.Literal("pi"), Type.Literal("dsh"), Type.Literal("claude")]);
5
6
  const nullableOffset = Type.Union([Type.Integer(), Type.Null()]);
6
7
  const node = Type.Object({ host, id: Type.String(), kind: Type.Union([Type.Literal("session"), Type.Literal("exchange"), Type.Literal("summary")]),
@@ -15,19 +16,24 @@ export const historyResultSchema = Type.Object({
15
16
  });
16
17
  export const historyDescription = "查询当前工作区的 Pi/dsh 问答与已有 Claude 归档,host 可筛选来源。search 按不区分大小写的连续文本匹配原文和摘要;无匹配时换词,省略 query 列会话。read 按 parents/children 的 id 展开,nextOffset 续读正文,nextChildrenOffset 续读子节点。需要对话细节时读取 exchange 原文;需要工具日志时查所属宿主的原始会话。";
17
18
  export const historyParameters = Type.Object({ action: Type.Union([Type.Literal("search"), Type.Literal("read")]),
18
- host: Type.Optional(host), query: Type.Optional(Type.String()), sessionId: Type.Optional(Type.String()),
19
- from: Type.Optional(Type.String({ description: "search:ISO 日期或时间,下界。" })),
20
- to: Type.Optional(Type.String({ description: "search:ISO 日期或时间,上界。" })),
21
- id: Type.Optional(Type.String({ description: "read 必填:返回的节点 id。" })),
22
- offset: Type.Optional(Type.Integer({ minimum: 0 })),
23
- limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 24000, description: "search:最多 50 条,默认 20;read:字符数,默认 12000。" })),
24
- childrenOffset: Type.Optional(Type.Integer({ minimum: 0 })),
19
+ host: nullable(host), query: nullable(Type.String()), sessionId: nullable(Type.String()),
20
+ from: nullable(Type.String({ description: "search:ISO 日期或时间,下界。" })),
21
+ to: nullable(Type.String({ description: "search:ISO 日期或时间,上界。" })),
22
+ id: nullable(Type.String({ description: "read 必填:返回的节点 id。" })),
23
+ offset: nullable(Type.Integer({ minimum: 0, description: "search:匹配结果偏移;read:正文 UTF-16 字符偏移。默认 0。" })),
24
+ limit: nullable(Type.Integer({ minimum: 1, maximum: 24000, description: "search:最多返回的匹配条数,默认 20,最多 50;read:正文 UTF-16 字符数,默认 12000。" })),
25
+ childrenOffset: nullable(Type.Integer({ minimum: 0 })),
25
26
  }, { additionalProperties: false });
26
27
  const valid = schema(historyParameters);
27
28
  export function historyInput(value) {
28
- requireThat(valid(value), "历史参数无效。");
29
- const args = value;
30
- requireThat(args.action !== "read" || args.id, "read 需要节点 id。");
31
- requireThat(args.action !== "search" || (args.limit ?? 20) <= 50, "search limit 最多 50。");
32
- return args;
29
+ const args = inputObject(value, valid, "历史参数格式无效");
30
+ if (args.action === "search") {
31
+ const limit = args.limit === undefined ? 20 : args.limit;
32
+ requireThat(limit <= 50, "search 的 limit 最多 50。");
33
+ return { action: "search", ...pick(args, ["host", "query", "sessionId", "from", "to", "offset", "limit"]) };
34
+ }
35
+ if (args.action === "read")
36
+ return { action: "read", id: need("read", args, "id"),
37
+ ...pick(args, ["host", "offset", "limit", "childrenOffset"]) };
38
+ throw new Error("未知的历史 action。");
33
39
  }
@@ -0,0 +1,11 @@
1
+ import type { TSchema } from "typebox";
2
+ import { Type } from "typebox";
3
+ import type { ValidateFunction } from "ajv";
4
+ /** Optional tool field that also accepts null, the absence spelling of structured tool calls. */
5
+ export declare function nullable<T extends TSchema>(value: T): Type.TOptional<Type.TUnion<[T, Type.TNull]>>;
6
+ /** Validate one record shape, then treat null as absent before action-specific projection. */
7
+ export declare function inputObject(value: unknown, validate: ValidateFunction, label: string): Record<string, unknown>;
8
+ /** A mode names each missing input instead of reporting a generic invalid-argument error. */
9
+ export declare function need<T>(action: string, args: Record<string, unknown>, key: string): T;
10
+ /** Copy only the fields a mode reads. Fields outside the projection never reach the service. */
11
+ export declare function pick(args: Record<string, unknown>, keys: readonly string[]): Record<string, unknown>;
@@ -0,0 +1,23 @@
1
+ import { Type } from "../common/typebox.js";
2
+ import { object } from "../common/json.js";
3
+ import { schemaDetail } from "../common/schema.js";
4
+ import { requireThat } from "../common/validation.js";
5
+ /** Optional tool field that also accepts null, the absence spelling of structured tool calls. */
6
+ export function nullable(value) {
7
+ return Type.Optional(Type.Union([value, Type.Null()]));
8
+ }
9
+ /** Validate one record shape, then treat null as absent before action-specific projection. */
10
+ export function inputObject(value, validate, label) {
11
+ requireThat(validate(value) && object(value), label + ":" + schemaDetail(validate));
12
+ return Object.fromEntries(Object.entries(value).filter(([, item]) => item !== null));
13
+ }
14
+ /** A mode names each missing input instead of reporting a generic invalid-argument error. */
15
+ export function need(action, args, key) {
16
+ const value = args[key];
17
+ requireThat(value !== undefined, action + " 需要 " + key + "。");
18
+ return value;
19
+ }
20
+ /** Copy only the fields a mode reads. Fields outside the projection never reach the service. */
21
+ export function pick(args, keys) {
22
+ return Object.fromEntries(keys.filter(key => args[key] !== undefined).map(key => [key, args[key]]));
23
+ }
@@ -1,10 +1,9 @@
1
- import type { Static } from "typebox";
2
1
  import type { TeamService } from "../../services/agents/team-service.js";
3
2
  import type { AgentService } from "../../services/agents/agent-service.js";
4
3
  import type { TeamActor } from "../../model/team.js";
5
4
  import type { AgentOwner } from "../../model/agent.js";
6
- import type { teamParametersSchema, teamMessageParametersSchema } from "./contract.js";
7
- export declare function executeTeam(service: TeamService, agents: AgentService, input: Static<typeof teamParametersSchema>, owner: AgentOwner): {
5
+ import type { TeamInput, TeamMessageInput } from "./contract.js";
6
+ export declare function executeTeam(service: TeamService, agents: AgentService, input: TeamInput, owner: AgentOwner): {
8
7
  isError?: boolean;
9
8
  content: {
10
9
  type: "text";
@@ -13,7 +12,7 @@ export declare function executeTeam(service: TeamService, agents: AgentService,
13
12
  details: import("../../common/json.js").Json;
14
13
  structuredContent: import("../../common/json.js").Json;
15
14
  };
16
- export declare function executeTeamMessage(service: TeamService, input: Static<typeof teamMessageParametersSchema>, actor: TeamActor, requestId: string): {
15
+ export declare function executeTeamMessage(service: TeamService, input: TeamMessageInput, actor: TeamActor, requestId: string): {
17
16
  isError?: boolean;
18
17
  content: {
19
18
  type: "text";
@@ -3,28 +3,30 @@ import { markdownResult, result } from "../result.js";
3
3
  export function executeTeam(service, agents, input, owner) {
4
4
  const views = agents.list(owner);
5
5
  service.recover(owner);
6
- let id = input.teamId;
6
+ let id = "";
7
7
  switch (input.action) {
8
8
  case "create":
9
9
  id = service.create(owner, { name: input.name, brief: input.brief, members: input.members }, views).teamId;
10
10
  break;
11
11
  case "list": return markdownResult({ teams: service.list(owner, views) }, "团队列表");
12
- case "read": {
13
- const page = service.read(id, { kind: "coordinator", owner }, input);
14
- return result(page, false, teamMessagesMarkdown(page));
15
- }
16
12
  case "run":
13
+ id = input.teamId;
17
14
  service.run(id, owner, { instruction: input.instruction, mode: input.mode,
18
15
  ...(input.rounds === undefined ? {} : { rounds: input.rounds }),
19
16
  ...(input.maxConcurrent === undefined ? {} : { maxConcurrent: input.maxConcurrent }),
20
17
  ...(input.timeoutSeconds === undefined ? {} : { timeoutSeconds: input.timeoutSeconds }) }, views);
21
18
  break;
22
19
  case "pause":
20
+ id = input.teamId;
23
21
  service.pause(id, owner);
24
22
  break;
25
23
  case "close":
24
+ id = input.teamId;
26
25
  service.close(id, owner, views);
27
26
  break;
27
+ case "status":
28
+ id = input.teamId;
29
+ break;
28
30
  }
29
31
  return markdownResult(service.status(id, owner, views), "团队状态");
30
32
  }