@oyasmi/pipiclaw 0.9.6-beta.1 → 0.9.6-beta.2

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 (258) hide show
  1. package/README.en.md +279 -215
  2. package/README.md +274 -213
  3. package/dist/agent/builtin-commands.d.ts +1 -1
  4. package/dist/agent/builtin-commands.js +1 -1
  5. package/dist/agent/channel-runner.d.ts +3 -2
  6. package/dist/agent/channel-runner.js +16 -27
  7. package/dist/agent/maintenance-context.js +2 -2
  8. package/dist/agent/prompt/builder.d.ts +1 -1
  9. package/dist/agent/prompt/builder.js +1 -1
  10. package/dist/agent/prompt/extension.d.ts +1 -1
  11. package/dist/agent/prompt/extension.js +1 -1
  12. package/dist/agent/prompt/manifest.d.ts +6 -1
  13. package/dist/agent/prompt/manifest.js +12 -5
  14. package/dist/agent/prompt/resources.d.ts +0 -3
  15. package/dist/agent/prompt/resources.js +0 -6
  16. package/dist/agent/prompt/sections.d.ts +2 -2
  17. package/dist/agent/prompt/sections.js +36 -26
  18. package/dist/agent/prompt/types.d.ts +1 -1
  19. package/dist/agent/runner-factory.js +1 -1
  20. package/dist/agent/session/command-extension.js +3 -1
  21. package/dist/agent/session/compaction-summary.js +3 -6
  22. package/dist/agent/session/event-guards.d.ts +2 -1
  23. package/dist/agent/session/event-guards.js +6 -0
  24. package/dist/agent/session/model-selection.d.ts +2 -1
  25. package/dist/agent/session/model-selection.js +5 -5
  26. package/dist/agent/session/session-events.js +31 -4
  27. package/dist/agent/session/session-host.d.ts +4 -2
  28. package/dist/agent/session/session-host.js +17 -15
  29. package/dist/agent/status-render.js +3 -0
  30. package/dist/agent/turn/task-digest.d.ts +2 -5
  31. package/dist/agent/turn/task-digest.js +25 -45
  32. package/dist/agent/turn/turn-context.js +4 -6
  33. package/dist/agent/turn/turn-error.d.ts +1 -1
  34. package/dist/agent/turn/turn-error.js +9 -0
  35. package/dist/agent/turn/turn-pipeline.d.ts +10 -5
  36. package/dist/agent/turn/turn-pipeline.js +36 -7
  37. package/dist/agent/turn/turn-prompt.d.ts +2 -0
  38. package/dist/agent/turn/turn-prompt.js +2 -1
  39. package/dist/agent/turn/turn-recovery.js +4 -1
  40. package/dist/agent/types.d.ts +20 -2
  41. package/dist/agent/types.js +2 -0
  42. package/dist/app/auth-command.d.ts +25 -0
  43. package/dist/app/auth-command.js +200 -67
  44. package/dist/app/home.d.ts +7 -8
  45. package/dist/app/home.js +143 -56
  46. package/dist/channel/channel-context.d.ts +6 -0
  47. package/dist/channel/config.d.ts +3 -0
  48. package/dist/channel/config.js +11 -5
  49. package/dist/commands/catalog.js +22 -6
  50. package/dist/desk/commands.d.ts +31 -4
  51. package/dist/desk/commands.js +101 -15
  52. package/dist/desk/paths.d.ts +6 -0
  53. package/dist/desk/paths.js +21 -1
  54. package/dist/desk/registry.d.ts +11 -0
  55. package/dist/desk/registry.js +53 -9
  56. package/dist/desk/types.d.ts +66 -1
  57. package/dist/dingtalk/config.js +10 -10
  58. package/dist/dingtalk/delivery.js +2 -0
  59. package/dist/dingtalk/inbound.js +2 -3
  60. package/dist/events/watcher.d.ts +1 -1
  61. package/dist/events/watcher.js +2 -2
  62. package/dist/main.js +15 -3
  63. package/dist/memory/boundary-work.d.ts +2 -1
  64. package/dist/memory/boundary-work.js +1 -1
  65. package/dist/memory/lifecycle.d.ts +2 -1
  66. package/dist/memory/lifecycle.js +2 -2
  67. package/dist/memory/reflect-job.d.ts +2 -1
  68. package/dist/memory/reflect-job.js +1 -1
  69. package/dist/memory/reflect.d.ts +2 -1
  70. package/dist/memory/reflect.js +2 -1
  71. package/dist/memory/scheduler.d.ts +2 -1
  72. package/dist/memory/scheduler.js +1 -1
  73. package/dist/memory/session-corpus.js +7 -1
  74. package/dist/memory/session-search.d.ts +2 -1
  75. package/dist/memory/session-search.js +1 -1
  76. package/dist/memory/sidecar-worker.d.ts +2 -1
  77. package/dist/memory/sidecar-worker.js +2 -4
  78. package/dist/models/credential-work.d.ts +7 -0
  79. package/dist/models/credential-work.js +36 -0
  80. package/dist/models/login-ui.js +4 -4
  81. package/dist/models/provider-login.js +7 -6
  82. package/dist/models/requests.d.ts +8 -0
  83. package/dist/models/requests.js +69 -0
  84. package/dist/models/runtime.d.ts +3 -1
  85. package/dist/models/runtime.js +9 -2
  86. package/dist/playbooks/agent-delegation.md +19 -45
  87. package/dist/playbooks/background-jobs.md +1 -1
  88. package/dist/playbooks/catalog.js +1 -1
  89. package/dist/playbooks/delegation-inline.md +25 -0
  90. package/dist/playbooks/delegation-recovery.md +28 -0
  91. package/dist/playbooks/event-scheduling.md +18 -37
  92. package/dist/playbooks/event-sensors.md +26 -0
  93. package/dist/playbooks/event-task-template.md +22 -0
  94. package/dist/playbooks/learning-and-skills.md +26 -0
  95. package/dist/playbooks/memory-operations.md +36 -0
  96. package/dist/playbooks/outbound-media.md +2 -2
  97. package/dist/playbooks/runtime-files.md +29 -0
  98. package/dist/playbooks/runtime-operations.md +25 -0
  99. package/dist/playbooks/runtime-orientation.md +18 -53
  100. package/dist/playbooks/task-lead.md +22 -68
  101. package/dist/playbooks/task-manage.md +38 -0
  102. package/dist/playbooks/task-recovery.md +24 -0
  103. package/dist/playbooks/task-verify.md +22 -0
  104. package/dist/runtime/bootstrap.d.ts +4 -0
  105. package/dist/runtime/bootstrap.js +82 -22
  106. package/dist/runtime/daemon-lock.js +3 -3
  107. package/dist/runtime/desk-runtime.d.ts +33 -6
  108. package/dist/runtime/desk-runtime.js +302 -47
  109. package/dist/runtime/ingress-commands.js +24 -4
  110. package/dist/runtime/shutdown.d.ts +3 -1
  111. package/dist/runtime/shutdown.js +1 -0
  112. package/dist/runtime/task-close.d.ts +1 -1
  113. package/dist/runtime/task-close.js +6 -3
  114. package/dist/runtime/task-control.d.ts +1 -3
  115. package/dist/runtime/task-control.js +15 -11
  116. package/dist/runtime/task-input.js +1 -1
  117. package/dist/runtime/task-lane-types.d.ts +12 -2
  118. package/dist/runtime/task-lane-types.js +9 -0
  119. package/dist/runtime/task-lane.d.ts +1 -0
  120. package/dist/runtime/task-lane.js +17 -14
  121. package/dist/runtime/task-step.d.ts +3 -3
  122. package/dist/runtime/task-step.js +23 -14
  123. package/dist/runtime/transports.js +6 -5
  124. package/dist/security/command-guard.js +23 -1
  125. package/dist/subagents/commands.js +14 -5
  126. package/dist/subagents/completion-wake.js +6 -0
  127. package/dist/subagents/dispatch.js +20 -18
  128. package/dist/subagents/external/dispatch.js +20 -14
  129. package/dist/subagents/external/run.js +10 -20
  130. package/dist/subagents/external/settlement.js +5 -1
  131. package/dist/subagents/internal/outcome.js +19 -12
  132. package/dist/subagents/internal/provider-retry.js +1 -3
  133. package/dist/subagents/internal/run.d.ts +1 -1
  134. package/dist/subagents/internal/run.js +27 -4
  135. package/dist/subagents/internal/state.d.ts +1 -3
  136. package/dist/subagents/internal/state.js +1 -2
  137. package/dist/subagents/internal/worker.js +17 -9
  138. package/dist/subagents/result.d.ts +5 -2
  139. package/dist/subagents/result.js +35 -6
  140. package/dist/subagents/run-record.d.ts +21 -0
  141. package/dist/subagents/run-record.js +5 -0
  142. package/dist/subagents/runs.d.ts +4 -7
  143. package/dist/subagents/runs.js +24 -35
  144. package/dist/subagents/task-envelope.js +5 -0
  145. package/dist/subagents/task-settlement.js +1 -0
  146. package/dist/subagents/types.d.ts +14 -4
  147. package/dist/subagents/workspace-lease.d.ts +37 -10
  148. package/dist/subagents/workspace-lease.js +121 -13
  149. package/dist/subagents/worktree.d.ts +47 -5
  150. package/dist/subagents/worktree.js +316 -30
  151. package/dist/tasks/brief.d.ts +5 -1
  152. package/dist/tasks/brief.js +19 -5
  153. package/dist/tasks/commands.d.ts +3 -1
  154. package/dist/tasks/commands.js +17 -6
  155. package/dist/tasks/control.d.ts +9 -0
  156. package/dist/tasks/loop-log.d.ts +10 -0
  157. package/dist/tasks/loop-log.js +1 -1
  158. package/dist/tasks/receipts.d.ts +7 -3
  159. package/dist/tasks/receipts.js +34 -5
  160. package/dist/tools/bash.d.ts +3 -0
  161. package/dist/tools/bash.js +27 -15
  162. package/dist/tools/contract/presentation.js +4 -1
  163. package/dist/tools/edit-diff.d.ts +11 -0
  164. package/dist/tools/edit-diff.js +148 -0
  165. package/dist/tools/edit-match.d.ts +18 -0
  166. package/dist/tools/edit-match.js +242 -0
  167. package/dist/tools/edit.d.ts +10 -2
  168. package/dist/tools/edit.js +91 -361
  169. package/dist/tools/event-manage.d.ts +1 -2
  170. package/dist/tools/event-manage.js +27 -38
  171. package/dist/tools/file-observations.d.ts +9 -0
  172. package/dist/tools/file-observations.js +50 -0
  173. package/dist/tools/glob-match.d.ts +3 -1
  174. package/dist/tools/glob-match.js +40 -17
  175. package/dist/tools/glob.d.ts +1 -0
  176. package/dist/tools/glob.js +39 -19
  177. package/dist/tools/grep-command.d.ts +13 -0
  178. package/dist/tools/grep-command.js +77 -0
  179. package/dist/tools/grep.js +96 -201
  180. package/dist/tools/index.d.ts +4 -1
  181. package/dist/tools/index.js +7 -4
  182. package/dist/tools/job.js +12 -11
  183. package/dist/tools/read.d.ts +2 -0
  184. package/dist/tools/read.js +10 -2
  185. package/dist/tools/registry.d.ts +16 -11
  186. package/dist/tools/registry.js +29 -11
  187. package/dist/tools/session-search.d.ts +2 -1
  188. package/dist/tools/session-search.js +14 -4
  189. package/dist/tools/skill.js +13 -12
  190. package/dist/tools/subagent-manage.js +10 -3
  191. package/dist/tools/subagent.d.ts +22 -2
  192. package/dist/tools/subagent.js +19 -18
  193. package/dist/tools/task-manage/control-tools.js +1 -1
  194. package/dist/tools/task-manage/factory.d.ts +2 -2
  195. package/dist/tools/task-manage/factory.js +39 -3
  196. package/dist/tools/task-manage/lifecycle.d.ts +2 -2
  197. package/dist/tools/task-manage/lifecycle.js +7 -4
  198. package/dist/tools/task-manage/shared.d.ts +1 -1
  199. package/dist/tools/task-manage/types.d.ts +1 -0
  200. package/dist/tools/write-content.d.ts +7 -1
  201. package/dist/tools/write-content.js +18 -6
  202. package/dist/tools/write.d.ts +3 -0
  203. package/dist/tools/write.js +6 -2
  204. package/dist/tui/cli.d.ts +5 -0
  205. package/dist/tui/cli.js +97 -31
  206. package/dist/tui/client.d.ts +5 -0
  207. package/dist/tui/client.js +63 -21
  208. package/dist/tui/frontend.d.ts +2 -0
  209. package/dist/tui/pitui-frontend.d.ts +4 -0
  210. package/dist/tui/pitui-frontend.js +27 -0
  211. package/dist/tui/render.d.ts +1 -0
  212. package/dist/tui/render.js +5 -0
  213. package/dist/tui/session.js +6 -0
  214. package/dist/web/client.d.ts +1 -0
  215. package/dist/web/client.js +11 -0
  216. package/dist/web/fetch.js +6 -3
  217. package/dist/webapi/auth.d.ts +0 -3
  218. package/dist/webapi/auth.js +3 -7
  219. package/dist/webapi/config.js +17 -14
  220. package/dist/webapi/key-command.js +41 -41
  221. package/dist/webapi/response-state.d.ts +7 -1
  222. package/dist/webapi/response-state.js +166 -3
  223. package/dist/webapi/routes/websocket.js +24 -1
  224. package/dist/webapi/server.d.ts +3 -1
  225. package/dist/webapi/server.js +32 -1
  226. package/dist/webapi/service.js +8 -0
  227. package/dist/webapi/transport.d.ts +2 -0
  228. package/dist/webapi/transport.js +11 -1
  229. package/examples/sub-agents/README.md +9 -7
  230. package/examples/sub-agents/agy-main.md +21 -0
  231. package/examples/sub-agents/claude-high.md +21 -0
  232. package/examples/sub-agents/claude-main.md +21 -0
  233. package/examples/sub-agents/codex-flash.md +21 -0
  234. package/examples/sub-agents/codex-high.md +21 -0
  235. package/examples/sub-agents/codex-main.md +21 -0
  236. package/examples/sub-agents/codex-review.md +20 -0
  237. package/examples/sub-agents/cursor-high.md +20 -0
  238. package/examples/sub-agents/cursor-main.md +20 -0
  239. package/examples/sub-agents/glm-flash.md +21 -0
  240. package/examples/sub-agents/glm-high.md +21 -0
  241. package/examples/sub-agents/pi-scout.md +20 -0
  242. package/package.json +8 -9
  243. package/dist/agent/session/request-tools.d.ts +0 -3
  244. package/dist/agent/session/request-tools.js +0 -20
  245. package/dist/models/api-keys.d.ts +0 -11
  246. package/dist/models/api-keys.js +0 -22
  247. package/dist/playbooks/memory-and-learning.md +0 -55
  248. package/examples/sub-agents/agents/agy-main.md +0 -23
  249. package/examples/sub-agents/agents/claude-high.md +0 -23
  250. package/examples/sub-agents/agents/claude-main.md +0 -23
  251. package/examples/sub-agents/agents/codex-flash.md +0 -23
  252. package/examples/sub-agents/agents/codex-high.md +0 -23
  253. package/examples/sub-agents/agents/codex-main.md +0 -23
  254. package/examples/sub-agents/agents/codex-review.md +0 -23
  255. package/examples/sub-agents/agents/cursor-high.md +0 -22
  256. package/examples/sub-agents/agents/cursor-main.md +0 -22
  257. package/examples/sub-agents/agents/glm-flash.md +0 -23
  258. package/examples/sub-agents/agents/glm-high.md +0 -23
package/dist/app/home.js CHANGED
@@ -7,9 +7,10 @@
7
7
  import { chmodSync, existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "fs";
8
8
  import { join } from "path";
9
9
  import { DEFAULT_AGENTS, DEFAULT_SOUL } from "../agent/prompt/workspace-templates.js";
10
+ import { generateWebApiKey, hashWebApiKey } from "../channel/config.js";
10
11
  import { initializeDefaultDesk } from "../desk/default.js";
11
12
  import * as log from "../log.js";
12
- import { APP_HOME_DIR, APP_NAME, AUTH_CONFIG_PATH, CHANNEL_CONFIG_PATH, docsUrl, EVENT_HISTORY_PATH, MODELS_CONFIG_PATH, SECURITY_CONFIG_PATH, SETTINGS_CONFIG_PATH, TOOLS_CONFIG_PATH, WORKSPACE_DIR, } from "../paths.js";
13
+ import { APP_HOME_DIR, APP_NAME, AUTH_CONFIG_PATH, CHANNEL_CONFIG_PATH, EVENT_HISTORY_PATH, MODELS_CONFIG_PATH, SECURITY_CONFIG_PATH, SETTINGS_CONFIG_PATH, TOOLS_CONFIG_PATH, WORKSPACE_DIR, } from "../paths.js";
13
14
  import { errorMessage } from "../shared/text-utils.js";
14
15
  const DEFAULT_MEMORY = `# Workspace Memory
15
16
 
@@ -52,26 +53,71 @@ This file records durable environment facts and notable machine-level changes.
52
53
 
53
54
  <!-- Record important config or environment changes that affect future work. -->
54
55
  `;
55
- const CHANNEL_CONFIG_TEMPLATE = {
56
- dingtalk: {
57
- enabled: true,
58
- clientId: "your-dingtalk-client-id",
59
- clientSecret: "your-dingtalk-client-secret",
60
- robotCode: "your-robot-code",
61
- cardTemplateId: "your-card-template-id",
62
- cardTemplateKey: "content",
63
- allowFrom: ["your-staff-id"],
64
- busyMessageDefault: "steer",
65
- responseMode: "full_progress_then_plain_final",
66
- cardAutoLayout: true,
67
- },
68
- webapi: {
69
- enabled: false,
70
- socket: true,
71
- keys: [],
56
+ function createChannelConfigTemplate() {
57
+ const initialWebApiKey = generateWebApiKey();
58
+ return {
59
+ initialWebApiKey,
60
+ config: {
61
+ dingtalk: {
62
+ enabled: false,
63
+ clientId: "your-dingtalk-client-id",
64
+ clientSecret: "your-dingtalk-client-secret",
65
+ robotCode: "",
66
+ cardTemplateId: "",
67
+ cardTemplateKey: "content",
68
+ allowFrom: [],
69
+ busyMessageDefault: "steer",
70
+ responseMode: "full_progress_then_plain_final",
71
+ cardAutoLayout: true,
72
+ },
73
+ webapi: {
74
+ enabled: true,
75
+ socket: true,
76
+ tcp: "127.0.0.1:8787",
77
+ tls: null,
78
+ keys: [
79
+ {
80
+ name: "default",
81
+ sha256: hashWebApiKey(initialWebApiKey),
82
+ desks: ["default"],
83
+ },
84
+ ],
85
+ },
86
+ },
87
+ };
88
+ }
89
+ const MODELS_CONFIG_TEMPLATE = {
90
+ providers: {},
91
+ _examples: {
92
+ "my-gateway": {
93
+ baseUrl: "https://api.deepseek.com/v1",
94
+ api: "openai-completions",
95
+ apiKey: "DEEPSEEK_API_KEY",
96
+ compat: {
97
+ supportsDeveloperRole: false,
98
+ supportsReasoningEffort: false,
99
+ },
100
+ models: [{ id: "deepseek-chat" }],
101
+ },
72
102
  },
103
+ _notes: [
104
+ "将 _examples 中的条目复制到 providers 下,即可接入 OpenAI 兼容网关、DeepSeek、通义或本地 Ollama。",
105
+ "apiKey 可直接填写密钥字符串、环境变量名(如 DEEPSEEK_API_KEY),或 !command。",
106
+ "配置后可在 settings.json 中补充 defaultProvider 与 defaultModel 指定默认模型。",
107
+ ],
108
+ };
109
+ const SETTINGS_CONFIG_TEMPLATE = {
110
+ defaultThinkingLevel: "medium",
111
+ fallbackModel: null,
112
+ subagentModel: null,
113
+ compaction: { enabled: true },
114
+ retry: { enabled: true },
115
+ memoryMaintenance: { enabled: true },
116
+ sessionSearch: { summarizeWithModel: false },
117
+ logging: { level: "info", file: { enabled: true } },
118
+ tui: { responseMode: "full_progress_then_plain_final" },
119
+ delegation: { notices: "live" },
73
120
  };
74
- const MODELS_CONFIG_TEMPLATE = { providers: {} };
75
121
  const TOOLS_CONFIG_TEMPLATE = {
76
122
  tools: {
77
123
  web: {
@@ -91,10 +137,10 @@ const TOOLS_CONFIG_TEMPLATE = {
91
137
  proxy: "http://127.0.0.1:7890",
92
138
  },
93
139
  _notes: [
94
- "Set tools.web.enable to true to register web_search and web_fetch.",
95
- "Choose a search provider and configure its credentials if needed.",
96
- "If needed, copy _examples.proxy to tools.web.proxy.",
97
- "tools.tasks.enabled is the master switch for autonomous long-running tasks (task_* tools + task driver + task digest).",
140
+ "将 tools.web.enable 设为 true 可启用联网搜索(web_search)与网页读取(web_fetch)。",
141
+ "默认搜索源 duckduckgo 无需 API Key;也可切换为 tavily、jina 或 searxng。",
142
+ "如需为网页工具单独配置代理,可将 _examples.proxy 填入 tools.web.proxy。",
143
+ "tools.tasks.enabled 是后台长程任务的总开关。",
98
144
  ],
99
145
  };
100
146
  const SECURITY_CONFIG_TEMPLATE = {
@@ -205,55 +251,96 @@ export function bootstrapAppHome(paths = DEFAULT_BOOTSTRAP_PATHS) {
205
251
  paths.toolsConfigPath,
206
252
  paths.securityConfigPath,
207
253
  ];
208
- const channelTemplateCreated = writeJsonFileIfMissing(paths.channelConfigPath, CHANNEL_CONFIG_TEMPLATE, "channel.json", created, SECRET_FILE_MODE);
254
+ let channelTemplateCreated = false;
255
+ let initialWebApiKey;
256
+ if (!existsSync(paths.channelConfigPath)) {
257
+ const generated = createChannelConfigTemplate();
258
+ channelTemplateCreated = writeJsonFileIfMissing(paths.channelConfigPath, generated.config, "channel.json", created, SECRET_FILE_MODE);
259
+ if (channelTemplateCreated)
260
+ initialWebApiKey = generated.initialWebApiKey;
261
+ }
209
262
  writeJsonFileIfMissing(paths.authConfigPath, {}, "auth.json", created, SECRET_FILE_MODE);
210
263
  writeJsonFileIfMissing(paths.modelsConfigPath, MODELS_CONFIG_TEMPLATE, "models.json", created, SECRET_FILE_MODE);
211
- writeJsonFileIfMissing(paths.settingsConfigPath, {}, "settings.json", created, SECRET_FILE_MODE);
264
+ writeJsonFileIfMissing(paths.settingsConfigPath, SETTINGS_CONFIG_TEMPLATE, "settings.json", created, SECRET_FILE_MODE);
212
265
  writeJsonFileIfMissing(paths.toolsConfigPath, TOOLS_CONFIG_TEMPLATE, "tools.json", created, SECRET_FILE_MODE);
213
266
  writeJsonFileIfMissing(paths.securityConfigPath, SECURITY_CONFIG_TEMPLATE, "security.json", created, SECRET_FILE_MODE);
214
267
  // Tighten any pre-existing config that predates owner-only creation.
215
268
  for (const secretPath of secretConfigPaths) {
216
269
  hardenExistingSecretFile(secretPath);
217
270
  }
218
- return { created, channelTemplateCreated };
271
+ return {
272
+ created,
273
+ channelTemplateCreated,
274
+ ...(initialWebApiKey ? { initialWebApiKey } : {}),
275
+ };
219
276
  }
220
277
  export function printBootstrapSummary(result, io = console, paths = DEFAULT_BOOTSTRAP_PATHS) {
221
278
  if (result.created.length === 0) {
222
279
  return;
223
280
  }
224
- io.log(`Initialized ${paths.appName} under ${paths.appHomeDir}:`);
281
+ io.log(`已初始化 ${paths.appName} 配置目录(${paths.appHomeDir}):`);
225
282
  for (const item of result.created) {
226
283
  io.log(` - ${item}`);
227
284
  }
228
285
  io.log("");
286
+ if (result.initialWebApiKey) {
287
+ io.log("==================================================================");
288
+ io.log("🔑 已自动生成本机 Web API 默认密钥(名称:default,授权工位:default)");
289
+ io.log(" 明文密钥仅展示这一次,请立即妥善保存(配置文件仅保存其 SHA-256):");
290
+ io.log("");
291
+ io.log(` ${result.initialWebApiKey}`);
292
+ io.log("");
293
+ io.log(" 本机 HTTP 接口:http://127.0.0.1:8787/v1 (Authorization: Bearer <密钥>)");
294
+ io.log(` 若遗忘可执行 \`${paths.appName} webapi key remove default && ${paths.appName} webapi key add default\` 重新生成。`);
295
+ io.log("==================================================================");
296
+ io.log("");
297
+ }
229
298
  }
230
- /**
231
- * What a new deployer does after the very first run created the templates (spec 053, D11). A
232
- * fresh template is not an error, so the caller exits 0 after this; it names the required fields,
233
- * where they come from, and the model credential step the daemon cannot run without.
234
- */
235
- export function printFirstRunGuide(io = console, paths = DEFAULT_BOOTSTRAP_PATHS) {
236
- io.log("Next steps:");
237
- io.log(` 1. Edit ${paths.channelConfigPath} — switch on at least one channel:`);
238
- io.log(" DingTalk: fill the `dingtalk` section — required: clientId, clientSecret (DingTalk Open");
239
- io.log(" Platform → your app → Credentials). Optional: cardTemplateId for AI Card streaming; set it");
240
- io.log(" to an empty string to disable cards.");
241
- io.log(" Web API: set `webapi.enabled` to true (a local socket; see the docs for keys and TCP).");
242
- io.log(` 2. Configure a model: run \`${paths.appName} auth login\`, or add a provider to ${paths.modelsConfigPath}.`);
243
- io.log(` 3. Run \`${paths.appName}\` again.`);
244
- io.log(`Docs: ${docsUrl("configuration.md")}`);
299
+ export function printStartupReadySummary(io, paths, transportNames, modelStatus) {
300
+ let tcpAddress;
301
+ let tlsEnabled = false;
302
+ if (transportNames.includes("webapi")) {
303
+ try {
304
+ const raw = JSON.parse(readFileSync(paths.channelConfigPath, "utf-8"));
305
+ if (typeof raw.webapi?.tcp === "string" && raw.webapi.tcp.trim()) {
306
+ tcpAddress = raw.webapi.tcp.trim();
307
+ }
308
+ tlsEnabled = Boolean(raw.webapi?.tls);
309
+ }
310
+ catch {
311
+ // Best-effort summary only; actual config was already validated by loadTransports.
312
+ }
313
+ }
314
+ io.log("");
315
+ io.log(`🚀 ${paths.appName} 服务已启动(配置目录:${paths.appHomeDir})`);
316
+ if (transportNames.includes("webapi")) {
317
+ const scheme = tlsEnabled ? "https" : "http";
318
+ io.log(` - Web API:已启用${tcpAddress ? `(本机接口 ${scheme}://${tcpAddress}/v1 + 本机 Socket)` : "(本机 Socket)"}`);
319
+ }
320
+ if (transportNames.includes("dingtalk")) {
321
+ io.log(" - 钉钉渠道:已启用(可在钉钉私聊或群内 @机器人 对话)");
322
+ }
323
+ else {
324
+ io.log(` - 钉钉渠道:未启用(如需接入,编辑 ${paths.channelConfigPath} 中 dingtalk 段即可)`);
325
+ }
326
+ if (modelStatus) {
327
+ io.log(modelStatus.ready
328
+ ? ` - 默认模型:${modelStatus.activeModelRef}(已就绪)`
329
+ : ` - 模型状态:⚠️ 尚未检测到凭据(请执行 \`${paths.appName} auth login\` 或配置 ${paths.modelsConfigPath})`);
330
+ }
331
+ io.log(` - 立即对话:打开新终端运行 \`${paths.appName} tui\`(在项目目录下可加 \`--cwd .\`)`);
332
+ io.log("");
245
333
  }
246
334
  /**
247
335
  * The one place that lists `pipiclaw`'s top-level subcommands. `parseArgs`'s own `--help` uses it;
248
- * `main.ts`'s unknown-subcommand branch used to hand-copy the same three lines separately (review
249
- * 2026-08-24 §1.10) — it now calls this instead, so the two can't drift apart again.
336
+ * `main.ts`'s unknown-subcommand branch calls this too so the two cannot drift apart.
250
337
  */
251
338
  export function formatCliCommandsHelp(appName) {
252
339
  return [
253
- ` ${appName} [run] [options] Run the daemon (default)`,
254
- ` ${appName} tui [options] [prompt] Chat with the agent in the terminal`,
255
- ` ${appName} auth status|login|logout Manage provider credentials`,
256
- ` ${appName} webapi key add|list|remove Manage Web API keys`,
340
+ ` ${appName} [run] [options] 启动后台常驻服务(默认开启本机 Web API,按需开启钉钉)`,
341
+ ` ${appName} tui [options] [prompt] 在终端与助手交互对话(自动连接常驻服务或内嵌运行)`,
342
+ ` ${appName} auth status|login|logout 管理模型供应商登录凭据(订阅 OAuth / API Key)`,
343
+ ` ${appName} webapi key add|list|remove 管理 Web API 访问密钥`,
257
344
  ];
258
345
  }
259
346
  export function parseArgs(argv, paths = DEFAULT_BOOTSTRAP_PATHS, io = console) {
@@ -265,16 +352,16 @@ export function parseArgs(argv, paths = DEFAULT_BOOTSTRAP_PATHS, io = console) {
265
352
  continue;
266
353
  }
267
354
  if (arg === "--help" || arg === "-h") {
268
- io.log(`Usage:`);
355
+ io.log("用法:");
269
356
  for (const line of formatCliCommandsHelp(paths.appName))
270
357
  io.log(line);
271
358
  io.log("");
272
- io.log("Options:");
273
- io.log(" --version Print the current version and exit");
274
- io.log(" --help, -h Show this help and exit");
359
+ io.log("选项:");
360
+ io.log(" --version 输出当前版本号并退出");
361
+ io.log(" --help, -h 显示帮助信息并退出");
275
362
  io.log("");
276
- io.log(`Config: ${paths.channelConfigPath}`);
277
- io.log(`Workspace: ${paths.workspaceDir}`);
363
+ io.log(`渠道配置:${paths.channelConfigPath}`);
364
+ io.log(`工作空间:${paths.workspaceDir}`);
278
365
  throw new BootstrapExitError(0);
279
366
  }
280
367
  else if (arg === "--version") {
@@ -282,8 +369,8 @@ export function parseArgs(argv, paths = DEFAULT_BOOTSTRAP_PATHS, io = console) {
282
369
  throw new BootstrapExitError(0);
283
370
  }
284
371
  else {
285
- io.error(`Unknown option: ${arg}`);
286
- io.error(`Run \`${paths.appName} --help\` for usage.`);
372
+ io.error(`未知参数:${arg}`);
373
+ io.error(`运行 \`${paths.appName} --help\` 查看用法。`);
287
374
  throw new BootstrapExitError(1);
288
375
  }
289
376
  }
@@ -35,9 +35,15 @@ export type TurnEvent = {
35
35
  ok: boolean;
36
36
  output: string;
37
37
  failure?: string;
38
+ } | {
39
+ type: "reasoning.delta";
40
+ delta: string;
38
41
  } | {
39
42
  type: "reasoning";
40
43
  text: string;
44
+ } | {
45
+ type: "text.delta";
46
+ delta: string;
41
47
  }
42
48
  /**
43
49
  * A line of the turn's narrative that is not the answer. Without a `level` it is the model's
@@ -2,6 +2,9 @@ export declare const CHANNEL_SECTION_NAMES: readonly ["dingtalk", "webapi"];
2
2
  export type ChannelSectionName = (typeof CHANNEL_SECTION_NAMES)[number];
3
3
  /** The raw content of every section that is switched on. */
4
4
  export type EnabledChannelSections = Partial<Record<ChannelSectionName, unknown>>;
5
+ export declare const hashWebApiKey: (key: string) => string;
6
+ /** A new Web API bearer key: `pk_` and 256 random bits. Shown once; only its SHA-256 hash is persisted. */
7
+ export declare function generateWebApiKey(): string;
5
8
  /** `channel.json` (or one of its sections) cannot be used; `issues` say what to fix. */
6
9
  export declare class ChannelConfigError extends Error {
7
10
  readonly issues: string[];
@@ -4,10 +4,16 @@
4
4
  * that transport's own business, and a section that is off is never looked at beyond its switch,
5
5
  * so credentials can stay in the file while a transport is disabled.
6
6
  */
7
+ import { createHash, randomBytes } from "node:crypto";
7
8
  import { docsUrl } from "../paths.js";
8
9
  import { errorMessage } from "../shared/text-utils.js";
9
10
  import { isPlainObject } from "../shared/type-guards.js";
10
11
  export const CHANNEL_SECTION_NAMES = ["dingtalk", "webapi"];
12
+ export const hashWebApiKey = (key) => createHash("sha256").update(key).digest("hex");
13
+ /** A new Web API bearer key: `pk_` and 256 random bits. Shown once; only its SHA-256 hash is persisted. */
14
+ export function generateWebApiKey() {
15
+ return `pk_${randomBytes(32).toString("base64url")}`;
16
+ }
11
17
  /** `channel.json` (or one of its sections) cannot be used; `issues` say what to fix. */
12
18
  export class ChannelConfigError extends Error {
13
19
  constructor(issues) {
@@ -22,15 +28,15 @@ export function parseChannelConfig(text) {
22
28
  parsed = JSON.parse(text);
23
29
  }
24
30
  catch (error) {
25
- throw new ChannelConfigError([`Not valid JSON: ${errorMessage(error)}`]);
31
+ throw new ChannelConfigError([`JSON 格式无效:${errorMessage(error)}`]);
26
32
  }
27
33
  if (!isPlainObject(parsed)) {
28
- throw new ChannelConfigError(["Expected a JSON object with a `dingtalk` and/or a `webapi` section."]);
34
+ throw new ChannelConfigError(["顶层必须是包含 `dingtalk` 和/或 `webapi` 段的 JSON 对象。"]);
29
35
  }
30
36
  const issues = [];
31
37
  for (const key of Object.keys(parsed)) {
32
38
  if (!CHANNEL_SECTION_NAMES.includes(key)) {
33
- issues.push(`Unknown top-level key \`${key}\`. channel.json has one section per transport (${CHANNEL_SECTION_NAMES.map((name) => `\`${name}\``).join(", ")}); move transport settings into their section (${docsUrl("configuration.md")}).`);
39
+ issues.push(`未知的顶层配置项 \`${key}\`。channel.json 按渠道分段(${CHANNEL_SECTION_NAMES.map((name) => `\`${name}\``).join("、")}),请将渠道参数移入对应分段中(${docsUrl("configuration.md")})。`);
34
40
  }
35
41
  }
36
42
  const enabled = {};
@@ -39,11 +45,11 @@ export function parseChannelConfig(text) {
39
45
  if (section === undefined)
40
46
  continue;
41
47
  if (!isPlainObject(section)) {
42
- issues.push(`\`${name}\` must be an object.`);
48
+ issues.push(`\`${name}\` 段必须是 JSON 对象。`);
43
49
  continue;
44
50
  }
45
51
  if (typeof section.enabled !== "boolean") {
46
- issues.push(`\`${name}.enabled\` must be true or false.`);
52
+ issues.push(`\`${name}.enabled\` 必须是布尔值(true 或 false)。`);
47
53
  continue;
48
54
  }
49
55
  if (section.enabled)
@@ -50,12 +50,16 @@ export const BUILT_IN_COMMANDS = [
50
50
  },
51
51
  {
52
52
  name: "desk",
53
- argumentHint: "[list|new <名字> [目录]|bind <名字>|cwd [目录|--reset]]",
54
- description: "进阶:创建工位、配置工位仓库目录,或把本频道切换到另一个工位",
55
- // list/new/cwd answer mid-turn; bind refuses by itself while this channel is busy (spec 058, D5).
53
+ argumentHint: "[list|new <名字> [目录]|bind <名字>|cwd [目录|--reset]|archive <名字>|unarchive <名字>]",
54
+ description: "进阶:创建工位、配置仓库目录、切换绑定,或归档闲置工位",
55
+ // list/new/cwd/archive/unarchive answer mid-turn; bind refuses by itself while this channel is busy (spec 058, D5).
56
56
  availableWhileBusy: true,
57
57
  subcommands: [
58
- { name: "list", description: "列出所有工位、工作目录和各自绑定的频道(默认动作,可省略)", example: "/desk" },
58
+ {
59
+ name: "list",
60
+ description: "列出所有工位、工作目录、后台状态和绑定的频道(默认动作,可省略)",
61
+ example: "/desk",
62
+ },
59
63
  {
60
64
  name: "new",
61
65
  args: "<名字> [目录绝对路径]",
@@ -65,7 +69,7 @@ export const BUILT_IN_COMMANDS = [
65
69
  {
66
70
  name: "bind",
67
71
  args: "<名字>",
68
- description: "把本频道绑定到这个工位,同时解除原来的绑定;回合进行中不能执行",
72
+ description: "把本频道绑定到这个工位(已归档工位会自动恢复);回合进行中不能执行",
69
73
  example: "/desk bind research",
70
74
  },
71
75
  {
@@ -74,6 +78,18 @@ export const BUILT_IN_COMMANDS = [
74
78
  description: "查看或设置当前工位的工作目录(状态仍保存在工位目录中)",
75
79
  example: "/desk cwd /srv/repo",
76
80
  },
81
+ {
82
+ name: "archive",
83
+ args: "<名字>",
84
+ description: "归档闲置工位:停止定时事件并清理残留终端绑定(默认工位不可归档)",
85
+ example: "/desk archive research",
86
+ },
87
+ {
88
+ name: "unarchive",
89
+ args: "<名字>",
90
+ description: "恢复已归档的工位,不改变当前频道绑定",
91
+ example: "/desk unarchive research",
92
+ },
77
93
  ],
78
94
  },
79
95
  {
@@ -126,7 +142,7 @@ export const BUILT_IN_COMMANDS = [
126
142
  {
127
143
  name: "adopt",
128
144
  args: "<id>",
129
- description: "把任务的汇报频道改到当前频道,解冻因原频道切走而暂停的任务",
145
+ description: "把任务的汇报频道改到当前频道,立即接收暂存汇报并继续交互",
130
146
  example: "/tasks adopt weekly-report",
131
147
  },
132
148
  {
@@ -1,4 +1,4 @@
1
- import type { BindingsFile, CreateDeskOutcome, DeskAvailability, DeskCwdOutcome, DeskSummary } from "./types.js";
1
+ import type { ArchiveDeskOutcome, BindingsFile, CreateDeskOutcome, DeskAvailability, DeskCwdOutcome, DeskSummary, UnarchiveDeskOutcome } from "./types.js";
2
2
  type DeskCommand = {
3
3
  action: "list";
4
4
  } | {
@@ -12,6 +12,12 @@ type DeskCommand = {
12
12
  action: "cwd";
13
13
  cwd?: string;
14
14
  reset?: boolean;
15
+ } | {
16
+ action: "archive";
17
+ name: string;
18
+ } | {
19
+ action: "unarchive";
20
+ name: string;
15
21
  };
16
22
  /** One channel bound to a desk, as `/desk list` shows it. */
17
23
  export interface DeskListChannel {
@@ -19,6 +25,14 @@ export interface DeskListChannel {
19
25
  /** Rendered by the caller (`channel/channel-id.ts`'s `formatChannelLabel`); desk never parses channel ids. */
20
26
  label: string;
21
27
  }
28
+ export interface DeskRuntimeActivity {
29
+ /** Open runnable/waiting tasks in this desk. */
30
+ activeTasks: number;
31
+ /** Outbound task reports/receipts queued in `.delivery/` waiting for a channel. */
32
+ pendingDeliveries: number;
33
+ /** Whether the desk is currently active in `DeskRuntime` (e.g. background tasks or task-spawning events). */
34
+ active: boolean;
35
+ }
22
36
  export interface DeskListItem {
23
37
  name: string;
24
38
  availability: DeskAvailability;
@@ -27,14 +41,23 @@ export interface DeskListItem {
27
41
  current: boolean;
28
42
  /** Custom working directory when `desk.json` overrides `deskDir`. */
29
43
  cwd?: string;
44
+ /** Set when `desk.json` carries `archivedAt`. */
45
+ archived?: boolean;
46
+ activeTasks?: number;
47
+ pendingDeliveries?: number;
48
+ backgroundActive?: boolean;
30
49
  }
31
50
  export type BindOutcome = {
32
51
  kind: "bound";
33
52
  desk: string;
53
+ /** Set when binding to an archived desk automatically restored it. */
54
+ unarchived?: boolean;
34
55
  previousDesk?: string;
35
- /** The previous desk lost its last binding and went dormant. */
56
+ /** The previous desk lost its last binding and has no background work, so it went dormant. */
36
57
  previousDeskDormant?: boolean;
37
- /** Open tasks / events in the previous desk that deliver to this channel and are now suspended. */
58
+ /** Open tasks in the previous desk that keep running in the background (deliveries held until rebound). */
59
+ backgroundTasks?: number;
60
+ /** Open tasks / chat events in the previous desk that deliver to this channel and are suspended. */
38
61
  suspendedTasks?: number;
39
62
  suspendedEvents?: number;
40
63
  } | {
@@ -61,7 +84,7 @@ export type BindOutcome = {
61
84
  * (shown missing, D4), each with the channels bound to it. `label` names a channel (the caller
62
85
  * owns channel ids); `current` is the asking channel's desk.
63
86
  */
64
- export declare function buildDeskList(desks: readonly DeskSummary[], bindings: BindingsFile["bindings"], current: string | undefined, label: (channelId: string) => string): DeskListItem[];
87
+ export declare function buildDeskList(desks: readonly DeskSummary[], bindings: BindingsFile["bindings"], current: string | undefined, label: (channelId: string) => string, activity?: ReadonlyMap<string, DeskRuntimeActivity>): DeskListItem[];
65
88
  export interface DeskCommandPort {
66
89
  list(): Promise<DeskListItem[]>;
67
90
  /** Absolute path of `CHANNELS.md`, where a truncated `/desk list` sends the reader. */
@@ -74,6 +97,10 @@ export interface DeskCommandPort {
74
97
  cwd?: string;
75
98
  reset?: boolean;
76
99
  }): Promise<DeskCwdOutcome>;
100
+ /** Archive an idle desk (`desk.json` `archivedAt`, stopping events and dropping stale TUI bindings). */
101
+ archive?(name: string): Promise<ArchiveDeskOutcome>;
102
+ /** Restore an archived desk without changing channel bindings. */
103
+ unarchive?(name: string): Promise<UnarchiveDeskOutcome>;
77
104
  }
78
105
  /** Exported so `test/commands-subcommands.test.ts` can feed every broadcast example back through it. */
79
106
  export declare function parseDeskCommand(args: string): DeskCommand;