@oyasmi/pipiclaw 0.9.3 → 0.9.4-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 (336) hide show
  1. package/dist/agent/builtin-commands.d.ts +19 -0
  2. package/dist/agent/builtin-commands.js +80 -0
  3. package/dist/agent/channel-runner.d.ts +20 -208
  4. package/dist/agent/channel-runner.js +167 -1188
  5. package/dist/agent/maintenance-context.d.ts +1 -1
  6. package/dist/agent/maintenance-context.js +1 -1
  7. package/dist/agent/prompt/manifest.d.ts +6 -1
  8. package/dist/agent/prompt/manifest.js +45 -64
  9. package/dist/agent/prompt/resources.d.ts +3 -0
  10. package/dist/agent/prompt/resources.js +11 -2
  11. package/dist/agent/runner-factory.d.ts +1 -43
  12. package/dist/agent/{command-extension.d.ts → session/command-extension.d.ts} +4 -0
  13. package/dist/agent/{command-extension.js → session/command-extension.js} +48 -35
  14. package/dist/agent/{type-guards.d.ts → session/event-guards.d.ts} +2 -2
  15. package/dist/agent/{type-guards.js → session/event-guards.js} +5 -1
  16. package/dist/agent/session/model-selection.d.ts +47 -0
  17. package/dist/agent/session/model-selection.js +99 -0
  18. package/dist/agent/{session-adapter.d.ts → session/session-adapter.d.ts} +21 -1
  19. package/dist/agent/session/session-adapter.js +159 -0
  20. package/dist/agent/{session-events.d.ts → session/session-events.d.ts} +9 -5
  21. package/dist/agent/{session-events.js → session/session-events.js} +24 -13
  22. package/dist/agent/session/session-host.d.ts +200 -0
  23. package/dist/agent/session/session-host.js +621 -0
  24. package/dist/agent/{session-resource-gate.js → session/session-resource-gate.js} +5 -3
  25. package/dist/agent/status-render.d.ts +0 -1
  26. package/dist/agent/status-render.js +4 -16
  27. package/dist/agent/{context-budget.js → turn/context-budget.js} +5 -1
  28. package/dist/agent/{progress-formatter.d.ts → turn/progress-formatter.d.ts} +4 -1
  29. package/dist/agent/{run-queue.d.ts → turn/run-queue.d.ts} +1 -1
  30. package/dist/agent/{run-queue.js → turn/run-queue.js} +10 -5
  31. package/dist/{memory → agent/turn}/task-digest.js +4 -4
  32. package/dist/agent/turn/turn-context.d.ts +14 -0
  33. package/dist/agent/turn/turn-context.js +64 -0
  34. package/dist/agent/turn/turn-error.d.ts +31 -0
  35. package/dist/agent/turn/turn-error.js +68 -0
  36. package/dist/agent/turn/turn-finish.d.ts +50 -0
  37. package/dist/agent/turn/turn-finish.js +188 -0
  38. package/dist/agent/turn/turn-input.d.ts +43 -0
  39. package/dist/agent/turn/turn-input.js +79 -0
  40. package/dist/agent/turn/turn-pipeline.d.ts +68 -0
  41. package/dist/agent/turn/turn-pipeline.js +257 -0
  42. package/dist/agent/{turn-prompt.d.ts → turn/turn-prompt.d.ts} +2 -2
  43. package/dist/agent/{turn-prompt.js → turn/turn-prompt.js} +6 -2
  44. package/dist/agent/{turn-recovery.js → turn/turn-recovery.js} +1 -1
  45. package/dist/agent/{turn-state.d.ts → turn/turn-state.d.ts} +1 -1
  46. package/dist/agent/types.d.ts +43 -2
  47. package/dist/agent/types.js +1 -1
  48. package/dist/{models/auth-cli.d.ts → app/auth-command.d.ts} +1 -1
  49. package/dist/{models/auth-cli.js → app/auth-command.js} +14 -10
  50. package/dist/{runtime/app-home.d.ts → app/home.d.ts} +6 -2
  51. package/dist/{runtime/app-home.js → app/home.js} +22 -75
  52. package/dist/{runtime → app}/proxy.js +4 -2
  53. package/dist/{app-services.d.ts → app/services.d.ts} +5 -5
  54. package/dist/{app-services.js → app/services.js} +17 -14
  55. package/dist/channel/channel-context.d.ts +12 -2
  56. package/dist/channel/channel-context.js +29 -2
  57. package/dist/channel/channel-event.d.ts +10 -2
  58. package/dist/channel/channel-event.js +1 -1
  59. package/dist/channel/channel-index.js +4 -1
  60. package/dist/{runtime/project-commands.d.ts → channel/commands.d.ts} +1 -1
  61. package/dist/{runtime/project-commands.js → channel/commands.js} +17 -16
  62. package/dist/channel/project-scope-store.js +1 -1
  63. package/dist/channel/store.js +4 -0
  64. package/dist/commands/catalog.d.ts +24 -7
  65. package/dist/commands/catalog.js +91 -44
  66. package/dist/commands/reply-limits.d.ts +6 -0
  67. package/dist/commands/reply-limits.js +24 -0
  68. package/dist/{runtime/report-commands.d.ts → commands/router.d.ts} +10 -3
  69. package/dist/{runtime/report-commands.js → commands/router.js} +6 -6
  70. package/dist/{settings.d.ts → config/settings.d.ts} +10 -10
  71. package/dist/{settings.js → config/settings.js} +11 -11
  72. package/dist/{tools/config.d.ts → config/tools.d.ts} +1 -2
  73. package/dist/{tools/config.js → config/tools.js} +5 -2
  74. package/dist/dingtalk/access-token.d.ts +12 -0
  75. package/dist/dingtalk/access-token.js +51 -0
  76. package/dist/dingtalk/api.d.ts +19 -0
  77. package/dist/dingtalk/api.js +67 -0
  78. package/dist/dingtalk/bot.d.ts +97 -0
  79. package/dist/dingtalk/bot.js +389 -0
  80. package/dist/dingtalk/cards.d.ts +56 -0
  81. package/dist/dingtalk/cards.js +318 -0
  82. package/dist/{runtime → dingtalk}/channel-queue.js +4 -1
  83. package/dist/dingtalk/config.d.ts +19 -0
  84. package/dist/dingtalk/config.js +95 -0
  85. package/dist/dingtalk/connection.d.ts +57 -0
  86. package/dist/dingtalk/connection.js +356 -0
  87. package/dist/dingtalk/conversation-meta.d.ts +16 -0
  88. package/dist/dingtalk/conversation-meta.js +77 -0
  89. package/dist/{runtime → dingtalk}/delivery.d.ts +6 -2
  90. package/dist/{runtime → dingtalk}/delivery.js +29 -15
  91. package/dist/dingtalk/handler.d.ts +90 -0
  92. package/dist/dingtalk/handler.js +1 -0
  93. package/dist/dingtalk/inbound.d.ts +66 -0
  94. package/dist/dingtalk/inbound.js +137 -0
  95. package/dist/dingtalk/media.d.ts +66 -0
  96. package/dist/dingtalk/media.js +214 -0
  97. package/dist/events/{event-commands.js → commands.js} +99 -45
  98. package/dist/events/parse.d.ts +14 -0
  99. package/dist/events/parse.js +114 -0
  100. package/dist/events/types.d.ts +93 -0
  101. package/dist/events/types.js +1 -0
  102. package/dist/events/{event-validation.d.ts → validation.d.ts} +14 -3
  103. package/dist/events/{event-validation.js → validation.js} +17 -9
  104. package/dist/events/watcher.d.ts +67 -0
  105. package/dist/events/{events.js → watcher.js} +63 -121
  106. package/dist/executor.js +2 -2
  107. package/dist/index.d.ts +6 -4
  108. package/dist/index.js +2 -2
  109. package/dist/jobs/launch.d.ts +42 -0
  110. package/dist/jobs/launch.js +118 -0
  111. package/dist/{agent/job-manager.d.ts → jobs/manager.d.ts} +1 -67
  112. package/dist/{agent/job-manager.js → jobs/manager.js} +34 -157
  113. package/dist/jobs/record.d.ts +55 -0
  114. package/dist/jobs/record.js +36 -0
  115. package/dist/log.d.ts +12 -2
  116. package/dist/log.js +26 -34
  117. package/dist/main.js +3 -3
  118. package/dist/memory/commands.js +29 -23
  119. package/dist/memory/lifecycle.js +26 -5
  120. package/dist/memory/maintenance-gates.d.ts +2 -2
  121. package/dist/memory/maintenance-state.js +4 -1
  122. package/dist/memory/maintenance-tuning.d.ts +15 -0
  123. package/dist/memory/maintenance-tuning.js +3 -0
  124. package/dist/memory/reflect-job.d.ts +2 -2
  125. package/dist/memory/reflect-job.js +4 -2
  126. package/dist/memory/scheduler.d.ts +3 -3
  127. package/dist/memory/scheduler.js +5 -2
  128. package/dist/memory/sidecar-worker.js +1 -1
  129. package/dist/memory/transcript.js +1 -1
  130. package/dist/{agent/model-fallback.d.ts → models/fallback.d.ts} +6 -6
  131. package/dist/{agent/model-fallback.js → models/fallback.js} +15 -28
  132. package/dist/models/login-identity.d.ts +2 -0
  133. package/dist/models/login-identity.js +83 -0
  134. package/dist/models/provider-login.d.ts +3 -1
  135. package/dist/models/provider-login.js +8 -2
  136. package/dist/models/reference.d.ts +20 -0
  137. package/dist/models/{utils.js → reference.js} +0 -48
  138. package/dist/models/{utils.d.ts → runtime.d.ts} +1 -16
  139. package/dist/models/runtime.js +52 -0
  140. package/dist/paths.d.ts +2 -0
  141. package/dist/paths.js +9 -0
  142. package/dist/playbooks/agent-delegation.md +2 -2
  143. package/dist/playbooks/catalog.d.ts +6 -2
  144. package/dist/playbooks/catalog.js +9 -6
  145. package/dist/runtime/bootstrap.d.ts +7 -17
  146. package/dist/runtime/bootstrap.js +70 -659
  147. package/dist/runtime/durable-dispatch.d.ts +43 -4
  148. package/dist/runtime/durable-dispatch.js +153 -3
  149. package/dist/runtime/inbound-images.d.ts +18 -0
  150. package/dist/runtime/inbound-images.js +51 -0
  151. package/dist/runtime/shutdown.d.ts +39 -0
  152. package/dist/runtime/shutdown.js +120 -0
  153. package/dist/runtime/stop-watchdog.d.ts +16 -0
  154. package/dist/runtime/stop-watchdog.js +32 -0
  155. package/dist/runtime/task-driver.d.ts +6 -4
  156. package/dist/runtime/task-driver.js +58 -23
  157. package/dist/runtime/task-migration.js +25 -8
  158. package/dist/runtime/task-spawn.d.ts +1 -1
  159. package/dist/runtime/task-spawn.js +13 -6
  160. package/dist/runtime/turn-handler.d.ts +47 -0
  161. package/dist/runtime/turn-handler.js +318 -0
  162. package/dist/runtime/turn-run.d.ts +52 -0
  163. package/dist/runtime/turn-run.js +318 -0
  164. package/dist/runtime/wake-coalescing.d.ts +18 -0
  165. package/dist/runtime/wake-coalescing.js +29 -0
  166. package/dist/security/block-message.d.ts +22 -1
  167. package/dist/security/block-message.js +66 -1
  168. package/dist/security/command-guard.js +4 -0
  169. package/dist/security/network.d.ts +2 -1
  170. package/dist/security/network.js +7 -2
  171. package/dist/security/path-guard-check.js +2 -2
  172. package/dist/security/path-guard.js +4 -0
  173. package/dist/security/types.d.ts +1 -2
  174. package/dist/security/types.js +1 -2
  175. package/dist/shared/exact-keys.d.ts +1 -1
  176. package/dist/shared/format.d.ts +12 -0
  177. package/dist/shared/format.js +37 -0
  178. package/dist/shared/host-process.js +16 -4
  179. package/dist/shared/wake-claim.d.ts +1 -1
  180. package/dist/shared/with-timeout.d.ts +3 -2
  181. package/dist/shared/with-timeout.js +14 -3
  182. package/dist/{runtime/skill-commands.d.ts → skills/commands.d.ts} +2 -2
  183. package/dist/{runtime/skill-commands.js → skills/commands.js} +18 -11
  184. package/dist/{agent/workspace-resources.js → skills/loader.js} +1 -1
  185. package/dist/{tools/skill-security.js → skills/validation.js} +4 -0
  186. package/dist/skills/workspace.d.ts +33 -0
  187. package/dist/skills/workspace.js +116 -0
  188. package/dist/{runtime/subagent-commands.d.ts → subagents/commands.d.ts} +9 -7
  189. package/dist/{runtime/subagent-commands.js → subagents/commands.js} +116 -77
  190. package/dist/subagents/completion-wake.d.ts +17 -0
  191. package/dist/subagents/completion-wake.js +76 -0
  192. package/dist/subagents/detached-discovery.js +1 -1
  193. package/dist/subagents/discovery.d.ts +1 -1
  194. package/dist/subagents/discovery.js +2 -2
  195. package/dist/subagents/dispatch.d.ts +33 -0
  196. package/dist/subagents/dispatch.js +190 -0
  197. package/dist/subagents/external/claude-code.js +23 -1
  198. package/dist/subagents/external/dispatch.d.ts +25 -0
  199. package/dist/subagents/external/dispatch.js +90 -0
  200. package/dist/subagents/external/harness.d.ts +1 -1
  201. package/dist/subagents/external/progress-tail.d.ts +18 -1
  202. package/dist/subagents/external/progress-tail.js +64 -17
  203. package/dist/subagents/external/run.d.ts +5 -1
  204. package/dist/subagents/external/run.js +23 -9
  205. package/dist/subagents/external/settlement.d.ts +4 -1
  206. package/dist/subagents/external/settlement.js +1 -1
  207. package/dist/subagents/format.d.ts +1 -1
  208. package/dist/subagents/grace.d.ts +24 -0
  209. package/dist/subagents/grace.js +57 -0
  210. package/dist/subagents/internal/outcome.d.ts +24 -0
  211. package/dist/subagents/internal/outcome.js +149 -0
  212. package/dist/subagents/internal/provider-retry.d.ts +19 -0
  213. package/dist/subagents/internal/provider-retry.js +83 -0
  214. package/dist/subagents/internal/run.d.ts +31 -0
  215. package/dist/subagents/internal/run.js +240 -0
  216. package/dist/subagents/internal/state.d.ts +43 -0
  217. package/dist/subagents/internal/state.js +48 -0
  218. package/dist/subagents/internal/worker.d.ts +51 -0
  219. package/dist/subagents/internal/worker.js +167 -0
  220. package/dist/subagents/result.d.ts +62 -0
  221. package/dist/subagents/result.js +103 -0
  222. package/dist/subagents/run-record.d.ts +222 -0
  223. package/dist/subagents/run-record.js +101 -0
  224. package/dist/subagents/run-registry.d.ts +9 -0
  225. package/dist/subagents/run-registry.js +125 -0
  226. package/dist/subagents/runs.d.ts +16 -232
  227. package/dist/subagents/runs.js +132 -310
  228. package/dist/subagents/task-envelope.d.ts +36 -0
  229. package/dist/subagents/task-envelope.js +168 -0
  230. package/dist/subagents/types.d.ts +154 -0
  231. package/dist/subagents/types.js +1 -0
  232. package/dist/subagents/verification-outcome.d.ts +1 -1
  233. package/dist/subagents/workspace-summary.d.ts +16 -4
  234. package/dist/subagents/workspace-summary.js +74 -18
  235. package/dist/tasks/board.d.ts +10 -3
  236. package/dist/tasks/board.js +38 -3
  237. package/dist/tasks/{work-log.d.ts → bound-work.d.ts} +1 -1
  238. package/dist/tasks/{work-log.js → bound-work.js} +1 -1
  239. package/dist/tasks/brief.js +1 -1
  240. package/dist/{runtime/task-commands.d.ts → tasks/commands.d.ts} +1 -1
  241. package/dist/{runtime/task-commands.js → tasks/commands.js} +117 -67
  242. package/dist/tasks/contract-input.d.ts +1 -1
  243. package/dist/tasks/contract-input.js +1 -1
  244. package/dist/tasks/create.js +1 -1
  245. package/dist/tasks/frontmatter.d.ts +5 -0
  246. package/dist/tasks/frontmatter.js +8 -0
  247. package/dist/tasks/{log.d.ts → loop-log.d.ts} +11 -1
  248. package/dist/tasks/{log.js → loop-log.js} +59 -3
  249. package/dist/tasks/mutation-lock.js +1 -1
  250. package/dist/tasks/session-path.js +1 -1
  251. package/dist/tasks/steer.js +1 -1
  252. package/dist/tasks/store.js +6 -4
  253. package/dist/tasks/ticket.d.ts +3 -1
  254. package/dist/tasks/ticket.js +19 -1
  255. package/dist/tools/bash.d.ts +1 -1
  256. package/dist/tools/bash.js +2 -2
  257. package/dist/tools/{tool-details.d.ts → contract/details.d.ts} +11 -3
  258. package/dist/tools/{tool-details.js → contract/details.js} +42 -5
  259. package/dist/tools/{presentation.js → contract/presentation.js} +3 -3
  260. package/dist/tools/event-manage.d.ts +1 -1
  261. package/dist/tools/event-manage.js +4 -4
  262. package/dist/tools/index.d.ts +5 -3
  263. package/dist/tools/index.js +8 -6
  264. package/dist/tools/job.d.ts +1 -1
  265. package/dist/tools/memory-manage.js +4 -1
  266. package/dist/tools/registry.d.ts +7 -7
  267. package/dist/tools/registry.js +6 -6
  268. package/dist/tools/session-search.d.ts +1 -1
  269. package/dist/tools/skill.d.ts +2 -34
  270. package/dist/tools/skill.js +8 -116
  271. package/dist/tools/subagent-manage.d.ts +1 -1
  272. package/dist/tools/subagent-manage.js +19 -13
  273. package/dist/tools/subagent.d.ts +46 -0
  274. package/dist/tools/subagent.js +127 -0
  275. package/dist/tools/{task-manage.d.ts → task-manage/factory.d.ts} +7 -3
  276. package/dist/tools/{task-manage.js → task-manage/factory.js} +7 -7
  277. package/dist/tools/task-manage/lifecycle.js +2 -2
  278. package/dist/tools/task-manage/log-view.js +2 -2
  279. package/dist/tools/task-manage/shared.js +3 -3
  280. package/dist/tools/task-manage/step-end.js +7 -4
  281. package/dist/tools/task-manage/types.d.ts +1 -1
  282. package/dist/tools/web-fetch.d.ts +1 -1
  283. package/dist/tools/web-search.d.ts +1 -1
  284. package/dist/tui/app.d.ts +1 -1
  285. package/dist/tui/app.js +6 -6
  286. package/dist/tui/cli.d.ts +1 -1
  287. package/dist/tui/cli.js +3 -3
  288. package/dist/tui/commands.js +4 -4
  289. package/dist/tui/frontend.d.ts +44 -0
  290. package/dist/tui/frontend.js +13 -0
  291. package/dist/tui/pitui-frontend.d.ts +1 -1
  292. package/dist/tui/pitui-frontend.js +1 -1
  293. package/dist/tui/plain-frontend.d.ts +1 -1
  294. package/dist/tui/renderer.d.ts +3 -42
  295. package/dist/tui/renderer.js +3 -2
  296. package/dist/tui/terminal-context.d.ts +2 -2
  297. package/dist/tui/terminal-media-sender.d.ts +1 -1
  298. package/dist/tui/turn-controller.d.ts +3 -1
  299. package/dist/tui/turn-controller.js +36 -21
  300. package/dist/usage/ledger.js +7 -1
  301. package/dist/usage/render.js +3 -1
  302. package/dist/{shared/types.d.ts → usage/totals.d.ts} +3 -0
  303. package/dist/web/client.d.ts +5 -1
  304. package/dist/web/client.js +4 -0
  305. package/dist/web/config.d.ts +1 -1
  306. package/dist/web/fetch.d.ts +1 -1
  307. package/dist/web/search-providers.d.ts +1 -1
  308. package/dist/web/search.d.ts +1 -1
  309. package/package.json +9 -7
  310. package/dist/agent/session-adapter.js +0 -77
  311. package/dist/events/events.d.ts +0 -159
  312. package/dist/runtime/dingtalk.d.ts +0 -272
  313. package/dist/runtime/dingtalk.js +0 -1416
  314. package/dist/subagents/tool.d.ts +0 -206
  315. package/dist/subagents/tool.js +0 -1088
  316. /package/dist/{runtime → agent/prompt}/workspace-templates.d.ts +0 -0
  317. /package/dist/{runtime → agent/prompt}/workspace-templates.js +0 -0
  318. /package/dist/agent/{session-resource-gate.d.ts → session/session-resource-gate.d.ts} +0 -0
  319. /package/dist/agent/{context-budget.d.ts → turn/context-budget.d.ts} +0 -0
  320. /package/dist/agent/{progress-formatter.js → turn/progress-formatter.js} +0 -0
  321. /package/dist/{memory → agent/turn}/task-digest.d.ts +0 -0
  322. /package/dist/agent/{turn-recovery.d.ts → turn/turn-recovery.d.ts} +0 -0
  323. /package/dist/agent/{turn-state.js → turn/turn-state.js} +0 -0
  324. /package/dist/{runtime → app}/proxy.d.ts +0 -0
  325. /package/dist/{runtime → dingtalk}/channel-queue.d.ts +0 -0
  326. /package/dist/{runtime → dingtalk}/inbound-media.d.ts +0 -0
  327. /package/dist/{runtime → dingtalk}/inbound-media.js +0 -0
  328. /package/dist/events/{event-commands.d.ts → commands.d.ts} +0 -0
  329. /package/dist/{agent/workspace-resources.d.ts → skills/loader.d.ts} +0 -0
  330. /package/dist/{tools/skill-security.d.ts → skills/validation.d.ts} +0 -0
  331. /package/dist/tasks/{ledger.d.ts → contract.d.ts} +0 -0
  332. /package/dist/tasks/{ledger.js → contract.js} +0 -0
  333. /package/dist/tools/{subagent-tool-names.d.ts → contract/names.d.ts} +0 -0
  334. /package/dist/tools/{subagent-tool-names.js → contract/names.js} +0 -0
  335. /package/dist/tools/{presentation.d.ts → contract/presentation.d.ts} +0 -0
  336. /package/dist/{shared/types.js → usage/totals.js} +0 -0
@@ -7,10 +7,10 @@
7
7
  * `/skills`), the agent session (`/model`, `/compact`, `/new`) and memory (`/memory`) — and is read
8
8
  * by all of them plus the TUI. Only the catalog and the reply shape are shared: each *handler*
9
9
  * still lives in the layer that owns the state it touches (`runtime/*-commands.ts`,
10
- * `memory/commands.ts`, `agent/command-extension.ts`). This file has no imports at all, so nothing
10
+ * `memory/commands.ts`, `agent/session/command-extension.ts`). This file has no imports at all, so nothing
11
11
  * here can drag a layer into another one.
12
12
  *
13
- * The six reply conventions these commands follow are recorded in AGENTS.md; `reply-limits.ts`
13
+ * The user-facing copy conventions these commands follow are recorded in AGENTS.md; `reply-limits.ts`
14
14
  * next to this file enforces rule 5 (the length budget).
15
15
  */
16
16
  /**
@@ -27,7 +27,7 @@ export const BUILT_IN_COMMANDS = [
27
27
  },
28
28
  {
29
29
  name: "stop",
30
- description: "停止当前回合;若该回合由任务驱动,同时暂停该任务",
30
+ description: "停止当前回合;若该回合是某个任务的一步,同时暂停该任务",
31
31
  examples: ["/stop"],
32
32
  availableWhileBusy: true,
33
33
  runnerHandled: true,
@@ -35,8 +35,9 @@ export const BUILT_IN_COMMANDS = [
35
35
  {
36
36
  name: "steer",
37
37
  argumentHint: "<消息>",
38
- description: "在当前工具步骤结束后调整正在运行的回合",
39
- examples: ["/steer Use the Shanghai time zone and summarize only the latest updates"],
38
+ description: "在当前工具调用结束后调整正在运行的回合",
39
+ examples: ["/steer 改用上海时区,只汇总最新的更新"],
40
+ note: "回合进行中直接发送的普通消息默认按 `/steer` 处理。部署者可以在 channel.json 把 `busyMessageDefault` 设为 `followUp`,改为排到当前回合之后执行;`responseMode` 控制答复的输出形态。",
40
41
  availableWhileBusy: true,
41
42
  runnerHandled: true,
42
43
  },
@@ -44,7 +45,7 @@ export const BUILT_IN_COMMANDS = [
44
45
  name: "followup",
45
46
  argumentHint: "<消息>",
46
47
  description: "排队一条请求,等当前回合结束后再执行",
47
- examples: ["/followup After that, draft a short executive summary"],
48
+ examples: ["/followup 完成后再写一份简短的总结"],
48
49
  availableWhileBusy: true,
49
50
  runnerHandled: true,
50
51
  },
@@ -73,27 +74,27 @@ export const BUILT_IN_COMMANDS = [
73
74
  {
74
75
  name: "tasks",
75
76
  argumentHint: "[show <id>|log <id>|steer <id> <内容>|reply <id> <内容>|pause <id>|resume <id> [+steps N|+usd X]|archive|doctor]",
76
- description: "查看、指挥并诊断本频道的长程任务;pause 只停用执行,保留阶段与等待票",
77
+ description: "查看、指挥并诊断本频道的长程任务;pause 只停止自动执行,保留等待条件",
77
78
  availableWhileBusy: true,
78
79
  subcommands: [
79
80
  { name: "list", description: "列出本频道进行中的任务(默认动作,可省略)", example: "/tasks" },
80
81
  {
81
82
  name: "show",
82
83
  args: "<id>",
83
- description: "查看契约、团队看板、最近日志与用量",
84
+ description: "查看任务说明、工作项、最近记录与用量",
84
85
  example: "/tasks show weekly-report",
85
86
  },
86
87
  {
87
88
  name: "log",
88
89
  args: "<id>",
89
- description: "翻看该任务的循环日志(含派发与结算记录)",
90
+ description: "查看该任务的记录(含每次委派的开始与结束)",
90
91
  example: "/tasks log weekly-report",
91
92
  },
92
93
  { name: "archive", description: "列出已归档(已关闭)的任务", example: "/tasks archive" },
93
94
  {
94
95
  name: "pause",
95
96
  args: "<id>",
96
- description: "停止该任务的自动执行(保留当前阶段与等待票)",
97
+ description: "停止该任务的自动执行(保留等待条件)",
97
98
  example: "/tasks pause weekly-report",
98
99
  },
99
100
  {
@@ -105,7 +106,7 @@ export const BUILT_IN_COMMANDS = [
105
106
  {
106
107
  name: "steer",
107
108
  args: "<id> <内容>",
108
- description: "把一条指示排给该任务的下一步,不打断当前步骤",
109
+ description: "把一条指示排给该任务的下一步,不打断正在执行的这一步",
109
110
  example: "/tasks steer weekly-report 先跑一遍 npm run check",
110
111
  },
111
112
  {
@@ -133,7 +134,7 @@ export const BUILT_IN_COMMANDS = [
133
134
  {
134
135
  name: "context",
135
136
  argumentHint: "[detail]",
136
- description: "显示实际发给模型的内容:system prompt 分段、工具 schema、上一回合上下文",
137
+ description: "显示实际发给模型的内容:系统提示词分段、工具定义、上一回合的上下文",
137
138
  examples: ["/context", "/context detail"],
138
139
  // Read-only accounting of state the runner already holds: no LLM call, no session
139
140
  // access, so it answers mid-turn like /status and /usage do.
@@ -143,7 +144,7 @@ export const BUILT_IN_COMMANDS = [
143
144
  {
144
145
  name: "subagents",
145
146
  argumentHint: "<list [running|failed|all]|show <id>|output <id>|cancel <id|all>|roles [name]>",
146
- description: "查看与控制委派 run(内置与外部)、浏览角色目录;cancel 不经过模型,直接终止",
147
+ description: "查看与控制委派(内置与外部)、浏览角色目录;cancel 不经过模型,直接终止",
147
148
  // A human control path independent of the model (spec 040, D6): /stop no longer kills a
148
149
  // dispatched delegation, so cancel must work even when the model/turn is unavailable.
149
150
  availableWhileBusy: true,
@@ -151,19 +152,19 @@ export const BUILT_IN_COMMANDS = [
151
152
  {
152
153
  name: "list",
153
154
  args: "[running|failed|all]",
154
- description: "运行中的 run + 最近完成的几条(不带筛选时)",
155
+ description: "运行中的委派,以及最近完成的几条(不带筛选时)",
155
156
  example: "/subagents list failed",
156
157
  },
157
158
  {
158
159
  name: "show",
159
160
  args: "<runId>",
160
- description: "单个 run 的完整详情(含实际 argv、stderr 尾部)",
161
+ description: "单个委派的详情(含实际命令行、stderr 尾部)",
161
162
  example: "/subagents show run_a1b2c3",
162
163
  },
163
164
  {
164
165
  name: "output",
165
166
  args: "<runId>",
166
- description: "该 run 的文本产出(output.md 尾部)",
167
+ description: "该委派的文本产出(output.md 尾部)",
167
168
  example: "/subagents output run_a1b2c3",
168
169
  },
169
170
  {
@@ -183,7 +184,7 @@ export const BUILT_IN_COMMANDS = [
183
184
  {
184
185
  name: "project",
185
186
  argumentHint: "[set <absolute-path>|reset]",
186
- description: "查看或切换本频道的项目目录(文件工具/shell 的工作面);set/reset 需频道空闲",
187
+ description: "查看或切换本频道的项目目录(读写文件与执行命令的工作目录);set/reset 需频道空闲",
187
188
  // The read form answers like /status; set/reset validate idleness themselves and reply
188
189
  // with a plain error instead of blocking the built-in-command dispatch path.
189
190
  availableWhileBusy: true,
@@ -192,10 +193,10 @@ export const BUILT_IN_COMMANDS = [
192
193
  {
193
194
  name: "set",
194
195
  args: "<absolute-path>",
195
- description: "切换项目目录(需频道空闲,且目录在允许的可选根内)",
196
+ description: "切换项目目录(需频道空闲,且目录在允许的根目录内)",
196
197
  example: "/project set /home/me/projects/foo",
197
198
  },
198
- { name: "reset", description: "切回 app 默认项目目录", example: "/project reset" },
199
+ { name: "reset", description: "切回默认项目目录", example: "/project reset" },
199
200
  ],
200
201
  },
201
202
  {
@@ -223,11 +224,11 @@ export const SESSION_COMMANDS = [
223
224
  {
224
225
  name: "memory",
225
226
  argumentHint: "[status|list [type]|show <name>|forget <name>|journal [date]]",
226
- description: "查看频道记忆索引、试用期与反思状态;不经过模型的记忆管理入口",
227
+ description: "查看频道记忆、观察期条目与后台整理状态;不经过模型的记忆管理入口",
227
228
  subcommands: [
228
229
  {
229
230
  name: "status",
230
- description: "记忆状态概览:分类计数、试用期、上次反思、索引预算",
231
+ description: "记忆状态概览:分类计数、观察期条目、上次整理、索引大小",
231
232
  example: "/memory status",
232
233
  },
233
234
  {
@@ -239,16 +240,21 @@ export const SESSION_COMMANDS = [
239
240
  {
240
241
  name: "show",
241
242
  args: "<name>",
242
- description: "查看单条记忆的全文与 frontmatter",
243
+ description: "查看单条记忆的全文与元信息",
243
244
  example: "/memory show deploy-window-thursday",
244
245
  },
245
246
  {
246
247
  name: "forget",
247
248
  args: "<name>",
248
- description: "不经过模型直接删除一条记忆(墓碑化,避免被反思重新写入)",
249
+ description: "不经过模型直接删除一条记忆,并记入忽略名单,后台整理不会再自动写回",
249
250
  example: "/memory forget deploy-window-thursday",
250
251
  },
251
- { name: "journal", args: "[YYYY-MM-DD]", description: "查看某天的日志,默认今天", example: "/memory journal" },
252
+ {
253
+ name: "journal",
254
+ args: "[YYYY-MM-DD]",
255
+ description: "查看某天的工作日记,默认今天",
256
+ example: "/memory journal",
257
+ },
252
258
  ],
253
259
  },
254
260
  {
@@ -278,7 +284,7 @@ export const SESSION_COMMANDS = [
278
284
  name: "compact",
279
285
  argumentHint: "[压缩要求]",
280
286
  description: "手动压缩当前会话上下文,可附加自定义要求",
281
- examples: ["/compact", "/compact Keep the latest TODOs and decisions"],
287
+ examples: ["/compact", "/compact 保留最新的待办和决定"],
282
288
  },
283
289
  ];
284
290
  const BUILT_IN_NAMES = new Set(BUILT_IN_COMMANDS.map((command) => command.name));
@@ -305,16 +311,22 @@ const RUNNER_BUILT_IN_NAMES = new Set(BUILT_IN_COMMANDS.filter((command) => comm
305
311
  export function isRunnerBuiltInCommand(command) {
306
312
  return RUNNER_BUILT_IN_NAMES.has(command.name);
307
313
  }
308
- /** Comma-separated list of commands usable while a task is streaming (names only). */
309
- export function formatBusyCommandList() {
310
- return [...BUILT_IN_COMMANDS, ...SESSION_COMMANDS]
311
- .filter((command) => command.availableWhileBusy)
312
- .map((command) => `\`/${command.name}\``)
313
- .join(", ");
314
+ function commandList(specs) {
315
+ return specs.map((command) => `\`/${command.name}\``).join("、");
316
+ }
317
+ /**
318
+ * The reply to a slash command that cannot run mid-turn — one source for DingTalk and the TUI
319
+ * (spec 053, D8). Both lists are derived from `availableWhileBusy`, so a command whose busy
320
+ * behaviour changes moves between them on its own instead of a hand-kept list going stale.
321
+ */
322
+ export function formatBusyHint() {
323
+ const whileBusy = ALL_COMMANDS.filter((command) => command.availableWhileBusy);
324
+ const idleOnly = ALL_COMMANDS.filter((command) => !command.availableWhileBusy);
325
+ return `当前已有回合在运行。运行中可用:${commandList(whileBusy)}。${commandList(idleOnly)} 需要等空闲后再用。`;
314
326
  }
315
327
  /**
316
- * Renders a command's subcommand table as its `usage()` text — the single source `task-commands.ts`,
317
- * `event-commands.ts`, `subagent-commands.ts`, `project-commands.ts`, and `memory/commands.ts` call
328
+ * Renders a command's subcommand table as its `usage()` text — the single source `tasks/commands.ts`,
329
+ * `events/commands.ts`, `subagents/commands.ts`, `channel/commands.ts`, and `memory/commands.ts` call
318
330
  * on a parse error, replacing five hand-written `usage()` bodies (review 2026-08-24 §3.1).
319
331
  */
320
332
  export function renderSubcommandUsage(name) {
@@ -331,8 +343,12 @@ function renderCommandSummaryLine(spec) {
331
343
  }
332
344
  /** The full detail for one command: argument syntax, subcommands or examples. Used by `/help <name>`. */
333
345
  function renderCommandDetail(spec) {
334
- const header = `**/${spec.name}${spec.argumentHint ? ` ${spec.argumentHint}` : ""}**`;
335
- const lines = [header, spec.description];
346
+ const lines = [`**/${spec.name}**`, spec.description];
347
+ // With subcommands, each bullet already spells out its own syntax.
348
+ if (spec.argumentHint && !spec.subcommands?.length)
349
+ lines.push(`用法:\`/${spec.name} ${spec.argumentHint}\``);
350
+ if (spec.note)
351
+ lines.push(spec.note);
336
352
  if (spec.subcommands?.length) {
337
353
  for (const sub of spec.subcommands) {
338
354
  const base = `- \`/${spec.name} ${sub.name}${sub.args ? ` ${sub.args}` : ""}\` — ${sub.description}`;
@@ -351,22 +367,24 @@ export function renderCommandHelp(name) {
351
367
  const spec = ALL_COMMANDS.find((command) => command.name === name);
352
368
  return spec ? renderCommandDetail(spec) : undefined;
353
369
  }
370
+ /**
371
+ * Grouped by when a command can be used — the one thing a user needs to know before sending it —
372
+ * rather than by which layer handles it (spec 053, D4/D8).
373
+ */
354
374
  function renderHelpText() {
355
- const transport = BUILT_IN_COMMANDS.map(renderCommandSummaryLine).join("\n");
356
- const session = SESSION_COMMANDS.map(renderCommandSummaryLine).join("\n");
375
+ const anytime = ALL_COMMANDS.filter((command) => command.availableWhileBusy).map(renderCommandSummaryLine);
376
+ const idleOnly = ALL_COMMANDS.filter((command) => !command.availableWhileBusy).map(renderCommandSummaryLine);
357
377
  return `**斜杠命令**
358
378
 
359
- Pipiclaw 的命令分为两组;用 \`/help <命令名>\` 查看某个命令的详细用法和示例(例如 \`/help tasks\`)。
360
-
361
- **传输层命令** · 由钉钉传输层/运行时直接处理,回合进行中也可以用
379
+ 助手处理一条消息的完整过程称为一个回合。用 \`/help <命令名>\` 查看某个命令的用法和示例,例如 \`/help tasks\`。
362
380
 
363
- ${transport}
381
+ **随时可用** · 回合进行中也可以发送
364
382
 
365
- 回合进行中发送的普通消息按 \`busyMessageDefault\` 处理,默认是 \`steer\`;在 channel.json 里设为 \`followUp\`(或 \`followup\`)则改为排队到当前回合之后执行。channel.json 的 \`responseMode\` 控制输出形态,详见文档。
383
+ ${anytime.join("\n")}
366
384
 
367
- **会话层命令** · 由 Pipiclaw 会话层处理,需要在空闲时使用
385
+ **空闲时可用** · 需要等当前回合结束
368
386
 
369
- ${session}
387
+ ${idleOnly.join("\n")}
370
388
  `;
371
389
  }
372
390
  const HELP_TEXT = renderHelpText();
@@ -404,6 +422,35 @@ export function isKnownCommandName(name, knownSkillNames) {
404
422
  }
405
423
  return false;
406
424
  }
425
+ /**
426
+ * Replies around queueing that DingTalk and the TUI both give (spec 053, D10). One wording per
427
+ * situation, so the two surfaces cannot drift into two languages again.
428
+ */
429
+ export function formatMissingQueueMessage(name) {
430
+ return `缺少消息内容。用法:\`/${name} <消息>\``;
431
+ }
432
+ /** `explainFollowup`: a plain busy-time message was steered implicitly, so say how to defer it instead. */
433
+ export function formatSteerQueued(explainFollowup) {
434
+ const base = "已作为 steer 排队,当前工具调用结束后生效。";
435
+ return explainFollowup ? `${base}想等整个回合结束再执行,用 \`/followup <消息>\`。` : base;
436
+ }
437
+ export function formatFollowupQueued() {
438
+ return "已排队,当前回合结束后执行。";
439
+ }
440
+ export function formatNoRunningTurn(name) {
441
+ switch (name) {
442
+ case "stop":
443
+ return "当前没有运行中的回合,`/stop` 只在回合进行中有用。";
444
+ case "steer":
445
+ return "当前没有运行中的回合,直接发消息即可,不用 `/steer`。";
446
+ case "followup":
447
+ return "当前没有运行中的回合,直接发消息即可;`/followup` 用于回合进行中排队。";
448
+ }
449
+ }
450
+ /** The `/new` confirmation, shared by the DingTalk runtime path and the session-layer command. */
451
+ export function formatNewSessionReply(sessionId) {
452
+ return `已开启新会话(会话 ID:\`${sessionId}\`)。`;
453
+ }
407
454
  export function formatUnknownCommandMessage(name) {
408
455
  return `未知命令 \`/${name}\`。发送 \`/help\` 查看可用命令。`;
409
456
  }
@@ -14,3 +14,9 @@ export interface CapReplyResult {
14
14
  truncated: boolean;
15
15
  }
16
16
  export declare function capReply(text: string, options: CapReplyOptions): CapReplyResult;
17
+ /**
18
+ * Reshape a markdown file for a chat reply (rule 3/4): `#` headings become a bold line and
19
+ * indentation is dropped, since DingTalk keeps neither. Fenced code blocks pass through as-is.
20
+ * Used where a reply quotes a file the user wrote (a task contract, a skill body).
21
+ */
22
+ export declare function flattenMarkdownForChat(text: string): string;
@@ -15,3 +15,27 @@ export function capReply(text, options) {
15
15
  const head = text.slice(0, cut).trimEnd();
16
16
  return { text: `${head}\n\n(内容过长已截断;${options.nextStepHint})`, truncated: true };
17
17
  }
18
+ /**
19
+ * Reshape a markdown file for a chat reply (rule 3/4): `#` headings become a bold line and
20
+ * indentation is dropped, since DingTalk keeps neither. Fenced code blocks pass through as-is.
21
+ * Used where a reply quotes a file the user wrote (a task contract, a skill body).
22
+ */
23
+ export function flattenMarkdownForChat(text) {
24
+ const out = [];
25
+ let fenced = false;
26
+ for (const raw of text.split("\n")) {
27
+ if (/^\s*```/.test(raw)) {
28
+ fenced = !fenced;
29
+ out.push(raw.trim());
30
+ continue;
31
+ }
32
+ if (fenced) {
33
+ out.push(raw);
34
+ continue;
35
+ }
36
+ const trimmed = raw.trim();
37
+ const heading = /^#{1,6}\s+(.*)$/.exec(trimmed);
38
+ out.push(heading ? `**${heading[1]}**` : trimmed);
39
+ }
40
+ return out.join("\n").replace(/\n{3,}/g, "\n\n");
41
+ }
@@ -1,7 +1,6 @@
1
1
  import type { AgentRunner } from "../agent/types.js";
2
- import type { RuntimeCommandName } from "../commands/catalog.js";
3
2
  import type { SubAgentRunManager } from "../subagents/runs.js";
4
- import type { BootstrapPaths } from "./app-home.js";
3
+ import type { RuntimeCommandName } from "./catalog.js";
5
4
  /**
6
5
  * The stateless report commands (`/events /tasks /status /usage /context /subagents /project
7
6
  * /skills`) as one transport-neutral handler. The DingTalk runtime and the terminal TUI both route
@@ -9,9 +8,17 @@ import type { BootstrapPaths } from "./app-home.js";
9
8
  * transport supplies only what is genuinely its own (how to find its runner, how to rebuild one
10
9
  * after `/project`, whether a task can be woken immediately).
11
10
  */
11
+ /** The path fields the reports read; structurally satisfied by the app's `BootstrapPaths`. */
12
+ export interface ReportCommandPaths {
13
+ workspaceDir: string;
14
+ appHomeDir: string;
15
+ eventHistoryPath: string;
16
+ authConfigPath: string;
17
+ modelsConfigPath: string;
18
+ }
12
19
  export interface ReportCommandContext {
13
20
  channelId: string;
14
- paths: Pick<BootstrapPaths, "workspaceDir" | "appHomeDir" | "eventHistoryPath" | "authConfigPath" | "modelsConfigPath">;
21
+ paths: ReportCommandPaths;
15
22
  actor: "dingtalk-command" | "tui-command";
16
23
  version: string;
17
24
  startedAt: number;
@@ -1,13 +1,13 @@
1
1
  import { renderStatus } from "../agent/status-render.js";
2
2
  import { getChannelDir } from "../channel/channel-paths.js";
3
- import { handleEventsCommand } from "../events/event-commands.js";
3
+ import { handleProjectCommand } from "../channel/commands.js";
4
+ import { handleEventsCommand } from "../events/commands.js";
5
+ import { handleSkillsCommand } from "../skills/commands.js";
6
+ import { handleSubagentsCommand } from "../subagents/commands.js";
4
7
  import { loadDetachedSubAgentDiscovery } from "../subagents/detached-discovery.js";
8
+ import { handleTasksCommand } from "../tasks/commands.js";
5
9
  import { getUsageLedger } from "../usage/ledger.js";
6
10
  import { parseUsageMode, renderUsageReport } from "../usage/render.js";
7
- import { handleProjectCommand } from "./project-commands.js";
8
- import { handleSkillsCommand } from "./skill-commands.js";
9
- import { handleSubagentsCommand } from "./subagent-commands.js";
10
- import { handleTasksCommand } from "./task-commands.js";
11
11
  export async function runReportCommand(context, name, args) {
12
12
  const { channelId, paths } = context;
13
13
  const channelDir = getChannelDir(paths.workspaceDir, channelId);
@@ -55,7 +55,7 @@ export async function runReportCommand(context, name, args) {
55
55
  ...context.runManager
56
56
  .list()
57
57
  .filter((record) => record.status === "running")
58
- .map((record) => `subagent run \`${record.runId}\` (${record.agent})`),
58
+ .map((record) => `委派 \`${record.runId}\`(${record.agent})仍在运行`),
59
59
  ...context.runningJobLines(),
60
60
  ],
61
61
  onScopeChanged: context.onScopeChanged,
@@ -1,8 +1,7 @@
1
1
  /** Settings management for pipiclaw: `settings.json` (product intent only) and the code constants that replaced the retired knobs. */
2
2
  import type { ThinkingLevel } from "@earendil-works/pi-agent-core";
3
- import { type MemoryMaintenanceTuning } from "./memory/maintenance-tuning.js";
4
- import type { ResponseMode } from "./runtime/dingtalk.js";
5
- import type { ConfigDiagnostic } from "./shared/config-diagnostic.js";
3
+ import type { ResponseMode } from "../channel/channel-context.js";
4
+ import type { ConfigDiagnostic } from "../shared/config-diagnostic.js";
6
5
  type SettingsError = {
7
6
  scope: "global" | "project";
8
7
  error: Error;
@@ -27,9 +26,10 @@ export interface PipiclawTaskDriverSettings {
27
26
  /** Cap on idle sleep between scans; also the upper bound on how late a manual edit is noticed. */
28
27
  maxSleepMinutes: number;
29
28
  }
30
- export type PipiclawMemoryMaintenanceSettings = MemoryMaintenanceTuning & {
29
+ /** Only the on/off switch is a setting; cadence constants live in `memory/maintenance-tuning.ts`. */
30
+ export interface PipiclawMemoryMaintenanceSettings {
31
31
  enabled: boolean;
32
- };
32
+ }
33
33
  export interface PipiclawLoggingSettings {
34
34
  level: "debug" | "info" | "warn" | "error";
35
35
  file: {
@@ -49,8 +49,9 @@ export interface PipiclawSessionSearchSettings {
49
49
  * How much out-of-band commentary a delegation run (`src/subagents/`) or background job produces
50
50
  * outside of its own completion wake — plain text, not an LLM turn, so it reaches the channel in
51
51
  * roughly the time the run itself takes rather than waiting on a wake turn's latency.
52
- * `"off"` is today's behavior; `"settled"` adds only the one-line completion receipt; `"live"`
53
- * also adds a sparse trickle of running-progress notices for long external runs.
52
+ * `"off"` is today's behavior; `"settled"` adds the one-line completion receipt and the "may be
53
+ * stuck" warning for an external run that stopped producing output; `"live"` also adds a sparse
54
+ * trickle of running-progress notices for long runs (external, or internal ones gone async).
54
55
  */
55
56
  export interface PipiclawDelegationSettings {
56
57
  notices: "off" | "settled" | "live";
@@ -99,9 +100,8 @@ export interface PipiclawSettings {
99
100
  delegation?: Partial<PipiclawDelegationSettings>;
100
101
  }
101
102
  /**
102
- * Every top-level `settings.json` key, read by `test/config-reference-coverage.test.ts` to check
103
- * that `docs/configuration-reference.md` still mentions each one. The two lines below keep this
104
- * list from drifting out of sync with `PipiclawSettings` itself: `satisfies` rejects an extra or
103
+ * Every top-level `settings.json` key. The two lines below keep this list from drifting out of
104
+ * sync with `PipiclawSettings` itself: `satisfies` rejects an extra or
105
105
  * misspelled entry, and the `AssertNoMissingKeys` check rejects an interface field with no entry
106
106
  * here — both at `npm run typecheck`, not by trusting a human to update two places together.
107
107
  */
@@ -1,14 +1,12 @@
1
1
  /** Settings management for pipiclaw: `settings.json` (product intent only) and the code constants that replaced the retired knobs. */
2
2
  import { existsSync, mkdirSync, readFileSync } from "fs";
3
3
  import { dirname, join } from "path";
4
- import * as log from "./log.js";
5
- import { getMemoryMaintenanceTuning } from "./memory/maintenance-tuning.js";
6
- import { writeFileAtomicallySync } from "./shared/atomic-file.js";
7
- import { fileStamp } from "./shared/format.js";
4
+ import * as log from "../log.js";
5
+ import { writeFileAtomicallySync } from "../shared/atomic-file.js";
6
+ import { fileStamp } from "../shared/format.js";
8
7
  /**
9
- * Every top-level `settings.json` key, read by `test/config-reference-coverage.test.ts` to check
10
- * that `docs/configuration-reference.md` still mentions each one. The two lines below keep this
11
- * list from drifting out of sync with `PipiclawSettings` itself: `satisfies` rejects an extra or
8
+ * Every top-level `settings.json` key. The two lines below keep this list from drifting out of
9
+ * sync with `PipiclawSettings` itself: `satisfies` rejects an extra or
12
10
  * misspelled entry, and the `AssertNoMissingKeys` check rejects an interface field with no entry
13
11
  * here — both at `npm run typecheck`, not by trusting a human to update two places together.
14
12
  */
@@ -163,8 +161,8 @@ function findRetiredSettingsKeys(parsed) {
163
161
  * means an unrecognized value is dropped so the documented default applies, and the operator is
164
162
  * told which key was ignored.
165
163
  *
166
- * The value lists are literal rather than imported: `ResponseMode` lives in the DingTalk
167
- * transport, and a value import would tie settings loading to that module's import graph. The
164
+ * The value lists are literal rather than imported: `config` may depend on `channel` for types
165
+ * only (a value import would tie settings loading to the channel module's runtime graph). The
168
166
  * `satisfies` clauses keep them honest against the unions they mirror.
169
167
  */
170
168
  const ENUM_SETTINGS = [
@@ -267,7 +265,10 @@ export class PipiclawSettingsManager {
267
265
  writeFileAtomicallySync(this.settingsPath, JSON.stringify(this.settings, null, 2));
268
266
  }
269
267
  catch (error) {
270
- log.logWarning(`Could not save settings file`, `${this.settingsPath}\n${String(error)}`);
268
+ log.logWarn("config.settings.save_failed", "Settings file save failed", {
269
+ reason: String(error),
270
+ fields: { path: this.settingsPath },
271
+ });
271
272
  }
272
273
  }
273
274
  /**
@@ -329,7 +330,6 @@ export class PipiclawSettingsManager {
329
330
  }
330
331
  getMemoryMaintenanceSettings() {
331
332
  return {
332
- ...getMemoryMaintenanceTuning(),
333
333
  enabled: this.settings.memoryMaintenance?.enabled ?? DEFAULT_MEMORY_MAINTENANCE_ENABLED,
334
334
  };
335
335
  }
@@ -52,8 +52,7 @@ export interface LoadedToolsConfig {
52
52
  diagnostics: ConfigDiagnostic[];
53
53
  }
54
54
  /**
55
- * Every `tools.<key>` section in `tools.json`, read by `test/config-reference-coverage.test.ts`
56
- * to check that `docs/configuration-reference.md` still mentions each one. Kept in sync with
55
+ * Every `tools.<key>` section in `tools.json`. Kept in sync with
57
56
  * `PipiclawToolsConfig["tools"]` by `satisfies` (rejects an extra/misspelled entry) and
58
57
  * `AssertNoMissingKeys` (rejects a section with no entry here) — both at `npm run typecheck`.
59
58
  */
@@ -1,11 +1,14 @@
1
+ /**
2
+ * `tools.json`: the web, rtk, task and inline-delegation tool settings — their types, defaults, the
3
+ * loader with diagnostics, and the path of the file.
4
+ */
1
5
  import { join } from "node:path";
2
6
  import { APP_HOME_DIR } from "../paths.js";
3
7
  import { loadJsonConfig, pushConfigWarning } from "../shared/config-diagnostic.js";
4
8
  import { clampInteger } from "../shared/format.js";
5
9
  import { isRecord } from "../shared/type-guards.js";
6
10
  /**
7
- * Every `tools.<key>` section in `tools.json`, read by `test/config-reference-coverage.test.ts`
8
- * to check that `docs/configuration-reference.md` still mentions each one. Kept in sync with
11
+ * Every `tools.<key>` section in `tools.json`. Kept in sync with
9
12
  * `PipiclawToolsConfig["tools"]` by `satisfies` (rejects an extra/misspelled entry) and
10
13
  * `AssertNoMissingKeys` (rejects a section with no entry here) — both at `npm run typecheck`.
11
14
  */
@@ -0,0 +1,12 @@
1
+ export declare class AccessTokenProvider {
2
+ private credentials;
3
+ private accessToken;
4
+ private tokenExpiry;
5
+ private tokenRefreshPromise;
6
+ constructor(credentials: {
7
+ clientId: string;
8
+ clientSecret: string;
9
+ });
10
+ get(): Promise<string | null>;
11
+ private refresh;
12
+ }
@@ -0,0 +1,51 @@
1
+ /** App access token cache: one token shared by every DingTalk host, refreshed on demand. */
2
+ import axios from "axios";
3
+ import * as log from "../log.js";
4
+ import { errorMessage } from "../shared/text-utils.js";
5
+ import { DINGTALK_API, http } from "./api.js";
6
+ export class AccessTokenProvider {
7
+ constructor(credentials) {
8
+ this.credentials = credentials;
9
+ this.accessToken = null;
10
+ this.tokenExpiry = 0;
11
+ this.tokenRefreshPromise = null;
12
+ }
13
+ async get() {
14
+ if (this.accessToken && Date.now() / 1000 < this.tokenExpiry) {
15
+ return this.accessToken;
16
+ }
17
+ // Coalesce concurrent refresh requests into a single HTTP call
18
+ if (!this.tokenRefreshPromise) {
19
+ this.tokenRefreshPromise = this.refresh().finally(() => {
20
+ this.tokenRefreshPromise = null;
21
+ });
22
+ }
23
+ return this.tokenRefreshPromise;
24
+ }
25
+ async refresh() {
26
+ try {
27
+ const resp = await http.post(`${DINGTALK_API}/v1.0/oauth2/accessToken`, {
28
+ appKey: this.credentials.clientId,
29
+ appSecret: this.credentials.clientSecret,
30
+ }, {
31
+ headers: { "Content-Type": "application/json" },
32
+ });
33
+ const data = resp.data;
34
+ this.accessToken = data.accessToken || null;
35
+ this.tokenExpiry = Date.now() / 1000 + (data.expireIn || 7200) - 60;
36
+ return this.accessToken;
37
+ }
38
+ catch (err) {
39
+ if (axios.isAxiosError(err) && err.response) {
40
+ log.logWarn("dingtalk.token.failed", "Access token request failed", {
41
+ reason: JSON.stringify(err.response.data),
42
+ fields: { status: err.response.status },
43
+ });
44
+ }
45
+ else {
46
+ log.logWarn("dingtalk.token.failed", "Access token request failed", { reason: errorMessage(err) });
47
+ }
48
+ return null;
49
+ }
50
+ }
51
+ }
@@ -0,0 +1,19 @@
1
+ import type { DingTalkConfig } from "./config.js";
2
+ export declare const DINGTALK_API = "https://api.dingtalk.com";
3
+ export declare const DINGTALK_OAPI = "https://oapi.dingtalk.com";
4
+ export declare const http: import("axios").AxiosInstance;
5
+ /** Where a channel's messages go: enough to pick the DM-vs-group endpoint and the recipient. */
6
+ export interface ConversationMeta {
7
+ conversationId: string;
8
+ conversationType: string;
9
+ senderId: string;
10
+ }
11
+ /**
12
+ * POST a robot message with an arbitrary msgKey/msgParam, routing DM vs group
13
+ * to the correct endpoint. The single outbound path for every non-card message:
14
+ * plain text/markdown, images, and files.
15
+ */
16
+ export declare function sendRobotMessage(deps: {
17
+ config: DingTalkConfig;
18
+ getAccessToken: () => Promise<string | null>;
19
+ }, meta: ConversationMeta, msgKey: string, msgParam: string): Promise<boolean>;