@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
@@ -1,15 +1,15 @@
1
1
  /**
2
- * App-home scaffolding: create `~/.pipiclaw` (or `PIPICLAW_HOME`) on first run, validate
3
- * `channel.json`, and parse CLI args shared by every entrypoint. Pure functions over explicit
2
+ * App-home scaffolding: create `~/.pipiclaw` (or `PIPICLAW_HOME`) on first run (writing the
3
+ * `channel.json` template; `dingtalk/config.ts` loads and validates it), and parse CLI args
4
+ * shared by every entrypoint. Pure functions over explicit
4
5
  * `paths`/`io` parameters — no dependency on the runtime wiring in `bootstrap.ts`.
5
6
  */
6
7
  import { chmodSync, existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "fs";
7
8
  import { join } from "path";
9
+ import { DEFAULT_AGENTS, DEFAULT_SOUL } from "../agent/prompt/workspace-templates.js";
8
10
  import * as log from "../log.js";
9
- 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";
11
+ 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";
10
12
  import { errorMessage } from "../shared/text-utils.js";
11
- import { isBusyMessageDefaultConfig, isResponseModeConfig, normalizeBusyMessageDefault, normalizeResponseMode, } from "./dingtalk.js";
12
- import { DEFAULT_AGENTS, DEFAULT_SOUL } from "./workspace-templates.js";
13
13
  const DEFAULT_MEMORY = `# Workspace Memory
14
14
 
15
15
  This file stores stable workspace-level memory.
@@ -158,7 +158,10 @@ function hardenExistingSecretFile(path) {
158
158
  }
159
159
  }
160
160
  catch (err) {
161
- log.logWarning(`Failed to tighten permissions on ${path}`, errorMessage(err));
161
+ log.logWarn("runtime.permissions.tighten_failed", "Config file permission tightening failed", {
162
+ reason: errorMessage(err),
163
+ fields: { path },
164
+ });
162
165
  }
163
166
  }
164
167
  export function bootstrapAppHome(paths = DEFAULT_BOOTSTRAP_PATHS) {
@@ -202,46 +205,6 @@ export function bootstrapAppHome(paths = DEFAULT_BOOTSTRAP_PATHS) {
202
205
  }
203
206
  return { created, channelTemplateCreated };
204
207
  }
205
- function isPlaceholderString(value) {
206
- return value.trim().startsWith("your-");
207
- }
208
- function listChannelConfigIssues(config) {
209
- const issues = [];
210
- if (!config.clientId) {
211
- issues.push("Missing required field `clientId`.");
212
- }
213
- else if (isPlaceholderString(config.clientId)) {
214
- issues.push("Replace placeholder value for `clientId`.");
215
- }
216
- if (!config.clientSecret) {
217
- issues.push("Missing required field `clientSecret`.");
218
- }
219
- else if (isPlaceholderString(config.clientSecret)) {
220
- issues.push("Replace placeholder value for `clientSecret`.");
221
- }
222
- if (config.robotCode && isPlaceholderString(config.robotCode)) {
223
- issues.push("Replace placeholder value for `robotCode`, or set it to an empty string to reuse `clientId`.");
224
- }
225
- if (config.cardTemplateId && isPlaceholderString(config.cardTemplateId)) {
226
- issues.push("Replace placeholder value for `cardTemplateId`, or set it to an empty string to disable AI Card streaming.");
227
- }
228
- if (Array.isArray(config.allowFrom) && config.allowFrom.some((value) => isPlaceholderString(value))) {
229
- issues.push("Replace placeholder values in `allowFrom`, or set it to an empty array to allow all users.");
230
- }
231
- const busyMessageDefault = config.busyMessageDefault;
232
- if (busyMessageDefault !== undefined && !isBusyMessageDefaultConfig(busyMessageDefault)) {
233
- issues.push('Invalid `busyMessageDefault`: expected "steer", "followUp", or "followup".');
234
- }
235
- const responseMode = config.responseMode;
236
- if (responseMode !== undefined && !isResponseModeConfig(responseMode)) {
237
- issues.push('Invalid `responseMode`: expected "full_progress_then_plain_final", "rolling_progress_then_plain_final", or "final_card_only".');
238
- }
239
- const cardAutoLayout = config.cardAutoLayout;
240
- if (cardAutoLayout !== undefined && typeof cardAutoLayout !== "boolean") {
241
- issues.push("Invalid `cardAutoLayout`: expected boolean.");
242
- }
243
- return issues;
244
- }
245
208
  export function printBootstrapSummary(result, io = console, paths = DEFAULT_BOOTSTRAP_PATHS) {
246
209
  if (result.created.length === 0) {
247
210
  return;
@@ -252,35 +215,19 @@ export function printBootstrapSummary(result, io = console, paths = DEFAULT_BOOT
252
215
  }
253
216
  io.log("");
254
217
  }
255
- export function loadConfig(paths = DEFAULT_BOOTSTRAP_PATHS, io = console) {
256
- let parsed;
257
- try {
258
- parsed = JSON.parse(readFileSync(paths.channelConfigPath, "utf-8"));
259
- }
260
- catch (err) {
261
- io.error(`Failed to parse configuration: ${paths.channelConfigPath}`);
262
- io.error(errorMessage(err));
263
- throw new BootstrapExitError(1);
264
- }
265
- const issues = listChannelConfigIssues(parsed);
266
- if (issues.length > 0) {
267
- io.error(`Configuration is not ready: ${paths.channelConfigPath}`);
268
- for (const issue of issues) {
269
- io.error(` - ${issue}`);
270
- }
271
- io.error("");
272
- io.error(`Fill in ${paths.channelConfigPath} and run \`${paths.appName}\` again.`);
273
- throw new BootstrapExitError(1);
274
- }
275
- parsed.cardTemplateKey = parsed.cardTemplateKey || "content";
276
- parsed.robotCode = parsed.robotCode?.trim() ? parsed.robotCode : parsed.clientId;
277
- parsed.busyMessageDefault = normalizeBusyMessageDefault(parsed.busyMessageDefault);
278
- parsed.responseMode = normalizeResponseMode(parsed.responseMode);
279
- parsed.cardAutoLayout = parsed.cardAutoLayout ?? true;
280
- if (Array.isArray(parsed.allowFrom)) {
281
- parsed.allowFrom = parsed.allowFrom.filter((value) => value.trim().length > 0);
282
- }
283
- return parsed;
218
+ /**
219
+ * What a new deployer does after the very first run created the templates (spec 053, D11). A
220
+ * fresh template is not an error, so the caller exits 0 after this; it names the required fields,
221
+ * where they come from, and the model credential step the daemon cannot run without.
222
+ */
223
+ export function printFirstRunGuide(io = console, paths = DEFAULT_BOOTSTRAP_PATHS) {
224
+ io.log("Next steps:");
225
+ io.log(` 1. Edit ${paths.channelConfigPath} — required: clientId, clientSecret`);
226
+ io.log(" (DingTalk Open Platform → your app → Credentials). Optional: cardTemplateId for AI Card");
227
+ io.log(" streaming; set it to an empty string to disable cards.");
228
+ io.log(` 2. Configure a model: run \`${paths.appName} auth login\`, or add a provider to ${paths.modelsConfigPath}.`);
229
+ io.log(` 3. Run \`${paths.appName}\` again.`);
230
+ io.log(`Docs: ${docsUrl("configuration.md")}`);
284
231
  }
285
232
  /**
286
233
  * The one place that lists `pipiclaw`'s top-level subcommands. `parseArgs`'s own `--help` uses it;
@@ -41,11 +41,13 @@ export function installLlmProxy() {
41
41
  parsed = new URL(explicitProxy);
42
42
  }
43
43
  catch {
44
- log.logWarning("PIPICLAW_PROXY is not a valid URL; LLM requests will connect directly", explicitProxy);
44
+ log.logWarn("runtime.proxy.invalid", "PIPICLAW_PROXY is not a valid URL; LLM requests connect directly", {
45
+ reason: explicitProxy,
46
+ });
45
47
  return { installed: false, source: "none" };
46
48
  }
47
49
  if (!SUPPORTED_PROXY_PROTOCOLS.has(parsed.protocol)) {
48
- log.logWarning(`PIPICLAW_PROXY uses unsupported protocol "${parsed.protocol}" (only http:// and https:// proxy URLs are supported, no SOCKS); LLM requests will connect directly`, explicitProxy);
50
+ log.logWarn("runtime.proxy.unsupported", "PIPICLAW_PROXY protocol unsupported (http/https only, no SOCKS); LLM requests connect directly", { reason: explicitProxy, fields: { protocol: parsed.protocol } });
49
51
  return { installed: false, source: "none" };
50
52
  }
51
53
  const noProxy = process.env.PIPICLAW_NO_PROXY?.trim();
@@ -1,16 +1,16 @@
1
- import { type BootstrapPaths } from "./runtime/app-home.js";
2
- import { PipiclawSettingsManager } from "./settings.js";
1
+ import { PipiclawSettingsManager } from "../config/settings.js";
2
+ import { type BootstrapPaths } from "./home.js";
3
3
  /**
4
4
  * Transport-neutral app services shared by the DingTalk runtime, the terminal TUI, and the
5
5
  * `pipiclaw auth` CLI: loads settings (surfacing load errors) and reports tool/security config
6
6
  * diagnostics. Does NOT touch DingTalk config, so non-DingTalk entrypoints can call it without
7
7
  * any DingTalk credentials.
8
8
  *
9
- * Lives at the package root rather than in `runtime/` on purpose: `models/auth-cli.ts` needs it
9
+ * Lives in `app/` rather than in `runtime/` on purpose: `app/auth-command.ts` needs it
10
10
  * before a runner or channel exists, and `runtime/bootstrap.ts` separately depends on `models/`
11
11
  * (for the default model reference) — parking this function inside `bootstrap.ts` made `models`
12
- * and `runtime` depend on each other. Everything this function touches (`settings.ts`,
13
- * `tools/config.ts`, `security/config.ts`, `runtime/app-home.ts`, `runtime/proxy.ts`) has no
12
+ * and `runtime` depend on each other. Everything this function touches (`config/settings.ts`,
13
+ * `config/tools.ts`, `security/config.ts`, `app/home.ts`, `app/proxy.ts`) has no
14
14
  * import back to `models/`, so this file doesn't reintroduce the cycle it was extracted to break.
15
15
  */
16
16
  export declare function prepareAppServices(paths?: BootstrapPaths): {
@@ -1,21 +1,21 @@
1
- import * as log from "./log.js";
2
- import { DEFAULT_BOOTSTRAP_PATHS } from "./runtime/app-home.js";
3
- import { installLlmProxy } from "./runtime/proxy.js";
4
- import { loadSecurityConfigWithDiagnostics } from "./security/config.js";
5
- import { PipiclawSettingsManager } from "./settings.js";
6
- import { formatConfigDiagnostic } from "./shared/config-diagnostic.js";
7
- import { loadToolsConfigWithDiagnostics } from "./tools/config.js";
1
+ import { PipiclawSettingsManager } from "../config/settings.js";
2
+ import { loadToolsConfigWithDiagnostics } from "../config/tools.js";
3
+ import * as log from "../log.js";
4
+ import { loadSecurityConfigWithDiagnostics } from "../security/config.js";
5
+ import { formatConfigDiagnostic } from "../shared/config-diagnostic.js";
6
+ import { DEFAULT_BOOTSTRAP_PATHS } from "./home.js";
7
+ import { installLlmProxy } from "./proxy.js";
8
8
  /**
9
9
  * Transport-neutral app services shared by the DingTalk runtime, the terminal TUI, and the
10
10
  * `pipiclaw auth` CLI: loads settings (surfacing load errors) and reports tool/security config
11
11
  * diagnostics. Does NOT touch DingTalk config, so non-DingTalk entrypoints can call it without
12
12
  * any DingTalk credentials.
13
13
  *
14
- * Lives at the package root rather than in `runtime/` on purpose: `models/auth-cli.ts` needs it
14
+ * Lives in `app/` rather than in `runtime/` on purpose: `app/auth-command.ts` needs it
15
15
  * before a runner or channel exists, and `runtime/bootstrap.ts` separately depends on `models/`
16
16
  * (for the default model reference) — parking this function inside `bootstrap.ts` made `models`
17
- * and `runtime` depend on each other. Everything this function touches (`settings.ts`,
18
- * `tools/config.ts`, `security/config.ts`, `runtime/app-home.ts`, `runtime/proxy.ts`) has no
17
+ * and `runtime` depend on each other. Everything this function touches (`config/settings.ts`,
18
+ * `config/tools.ts`, `security/config.ts`, `app/home.ts`, `app/proxy.ts`) has no
19
19
  * import back to `models/`, so this file doesn't reintroduce the cycle it was extracted to break.
20
20
  */
21
21
  export function prepareAppServices(paths = DEFAULT_BOOTSTRAP_PATHS) {
@@ -24,20 +24,23 @@ export function prepareAppServices(paths = DEFAULT_BOOTSTRAP_PATHS) {
24
24
  installLlmProxy();
25
25
  const settingsManager = new PipiclawSettingsManager(paths.appHomeDir);
26
26
  for (const { scope, error } of settingsManager.drainErrors()) {
27
- log.logWarning(`Failed to load ${scope} settings`, `${error.message}\n${paths.settingsConfigPath}`);
27
+ log.logWarn("config.settings.load_failed", "Settings load failed", {
28
+ reason: error.message,
29
+ fields: { scope, path: paths.settingsConfigPath },
30
+ });
28
31
  }
29
32
  // Errors already went out above with a richer message; this pass exists for the
30
33
  // warnings, chiefly retired settings keys (spec 035 D3).
31
34
  for (const diagnostic of settingsManager.getDiagnostics()) {
32
35
  if (diagnostic.severity === "error")
33
36
  continue;
34
- log.logWarning(formatConfigDiagnostic(diagnostic), diagnostic.path);
37
+ log.logWarn("config.diagnostic", formatConfigDiagnostic(diagnostic), { fields: { path: diagnostic.path } });
35
38
  }
36
39
  for (const diagnostic of loadToolsConfigWithDiagnostics(paths.appHomeDir).diagnostics) {
37
- log.logWarning(formatConfigDiagnostic(diagnostic), diagnostic.path);
40
+ log.logWarn("config.diagnostic", formatConfigDiagnostic(diagnostic), { fields: { path: diagnostic.path } });
38
41
  }
39
42
  for (const diagnostic of loadSecurityConfigWithDiagnostics(paths.appHomeDir).diagnostics) {
40
- log.logWarning(formatConfigDiagnostic(diagnostic), diagnostic.path);
43
+ log.logWarn("config.diagnostic", formatConfigDiagnostic(diagnostic), { fields: { path: diagnostic.path } });
41
44
  }
42
45
  return { settingsManager };
43
46
  }
@@ -3,12 +3,12 @@
3
3
  *
4
4
  * `ChannelContext` is the surface a `ChannelRunner` turn writes to: progress
5
5
  * updates, the final answer, side notices, and lifecycle hooks. The DingTalk
6
- * transport implements it via AI Card streaming (`runtime/delivery.ts`); the
6
+ * transport implements it via AI Card streaming (`dingtalk/delivery.ts`); the
7
7
  * terminal TUI implements it by rendering to the console (`tui/`). The runner
8
8
  * and `session-events` depend only on this interface, never on a concrete
9
9
  * transport.
10
10
  *
11
- * These declarations previously lived in `runtime/dingtalk.ts` under the name
11
+ * These declarations previously lived in `dingtalk/bot.ts` under the name
12
12
  * `DingTalkContext`; they were lifted out (and renamed) so a second transport
13
13
  * can implement the contract without importing anything DingTalk-specific. They
14
14
  * live in `src/channel/` rather than `src/runtime/` because a port belongs with
@@ -24,6 +24,16 @@ import type { InboundImage } from "./channel-event.js";
24
24
  export type ProgressStyle = "full" | "rolling" | "none";
25
25
  /** How the final answer is delivered. */
26
26
  export type FinalDelivery = "plain" | "card";
27
+ /**
28
+ * User-facing delivery preset (`channel.json` `responseMode`, `settings.json` `tui.responseMode`).
29
+ * Transport-neutral on purpose: the DingTalk bot and the TUI both map it onto
30
+ * `ProgressStyle` / `FinalDelivery` and nothing else should branch on the raw strings.
31
+ */
32
+ export type ResponseMode = "full_progress_then_plain_final" | "rolling_progress_then_plain_final" | "final_card_only";
33
+ export declare function progressStyleOf(mode: ResponseMode): ProgressStyle;
34
+ export declare function finalDeliveryOf(mode: ResponseMode): FinalDelivery;
35
+ export declare function isResponseModeConfig(value: unknown): value is ResponseMode;
36
+ export declare function normalizeResponseMode(value: unknown): ResponseMode;
27
37
  /**
28
38
  * A file the agent wants to push to a channel as a native attachment (image or
29
39
  * downloadable file), as opposed to text/markdown in the transcript.
@@ -3,12 +3,12 @@
3
3
  *
4
4
  * `ChannelContext` is the surface a `ChannelRunner` turn writes to: progress
5
5
  * updates, the final answer, side notices, and lifecycle hooks. The DingTalk
6
- * transport implements it via AI Card streaming (`runtime/delivery.ts`); the
6
+ * transport implements it via AI Card streaming (`dingtalk/delivery.ts`); the
7
7
  * terminal TUI implements it by rendering to the console (`tui/`). The runner
8
8
  * and `session-events` depend only on this interface, never on a concrete
9
9
  * transport.
10
10
  *
11
- * These declarations previously lived in `runtime/dingtalk.ts` under the name
11
+ * These declarations previously lived in `dingtalk/bot.ts` under the name
12
12
  * `DingTalkContext`; they were lifted out (and renamed) so a second transport
13
13
  * can implement the contract without importing anything DingTalk-specific. They
14
14
  * live in `src/channel/` rather than `src/runtime/` because a port belongs with
@@ -16,6 +16,33 @@
16
16
  * `tui` all depend on this file, and none of them should be reading anything out
17
17
  * of the DingTalk transport's directory to get it.
18
18
  */
19
+ const RESPONSE_MODE_VALUES = [
20
+ "full_progress_then_plain_final",
21
+ "rolling_progress_then_plain_final",
22
+ "final_card_only",
23
+ ];
24
+ export function progressStyleOf(mode) {
25
+ if (mode === "final_card_only")
26
+ return "none";
27
+ if (mode === "rolling_progress_then_plain_final")
28
+ return "rolling";
29
+ return "full";
30
+ }
31
+ export function finalDeliveryOf(mode) {
32
+ return mode === "final_card_only" ? "card" : "plain";
33
+ }
34
+ export function isResponseModeConfig(value) {
35
+ return typeof value === "string" && RESPONSE_MODE_VALUES.includes(value);
36
+ }
37
+ export function normalizeResponseMode(value) {
38
+ if (value === undefined) {
39
+ return "full_progress_then_plain_final";
40
+ }
41
+ if (isResponseModeConfig(value)) {
42
+ return value;
43
+ }
44
+ throw new Error('Invalid `responseMode`: expected "full_progress_then_plain_final", "rolling_progress_then_plain_final", or "final_card_only".');
45
+ }
19
46
  /**
20
47
  * A context whose user-visible writes are dropped (spec 051, D3).
21
48
  *
@@ -3,7 +3,7 @@
3
3
  * `MAX_IMAGE_BYTES` mirrors the *send* limit); this instead mirrors `tools/truncate.ts`'s
4
4
  * `MAX_INLINE_BINARY_BYTES` — the same ceiling `read` already applies to an on-disk image — so
5
5
  * "a picture the user sent" and "a picture `read` loads from disk" behave identically for the
6
- * model. Lives here, not in the DingTalk-specific `runtime/inbound-media.ts`, because both the
6
+ * model. Lives here, not in the DingTalk-specific `dingtalk/inbound-media.ts`, because both the
7
7
  * transport (rejecting an oversized download) and `agent/channel-runner.ts` (skipping an
8
8
  * oversized file before base64-encoding it) need the same number, and `agent/` never imports
9
9
  * from `runtime/` (spec 049).
@@ -39,7 +39,7 @@ export interface InboundImage {
39
39
  * A message or wake, from any producer: a real inbound DingTalk message, a scheduled event, a
40
40
  * task-driver wake, or a job/subagent completion. `conversationId` is the one field genuinely
41
41
  * DingTalk-specific (needed to reply into the right conversation); every synthetic producer
42
- * (job-manager, task-driver, events, subagents/runs) leaves it unset rather than faking a value,
42
+ * (jobs/manager, task-driver, events, subagents/runs) leaves it unset rather than faking a value,
43
43
  * since it has no DingTalk conversation to route into. `conversationType` is not DingTalk-specific
44
44
  * in practice — every producer, real or synthetic, can derive "1"/"2" from the channelId prefix —
45
45
  * so it stays required.
@@ -80,3 +80,11 @@ export interface ChannelEvent {
80
80
  */
81
81
  presentation?: "awaited";
82
82
  }
83
+ /**
84
+ * The one thing in-process producers (scheduled events, durable dispatch) need from a transport:
85
+ * hand it a synthetic event for its per-channel queue. `false` means the queue rejected it (full
86
+ * or stopped), so the caller keeps ownership and may retry. Implemented by `DingTalkBot`.
87
+ */
88
+ export interface ChannelEventSink {
89
+ enqueueEvent(event: ChannelEvent): boolean;
90
+ }
@@ -3,7 +3,7 @@
3
3
  * `MAX_IMAGE_BYTES` mirrors the *send* limit); this instead mirrors `tools/truncate.ts`'s
4
4
  * `MAX_INLINE_BINARY_BYTES` — the same ceiling `read` already applies to an on-disk image — so
5
5
  * "a picture the user sent" and "a picture `read` loads from disk" behave identically for the
6
- * model. Lives here, not in the DingTalk-specific `runtime/inbound-media.ts`, because both the
6
+ * model. Lives here, not in the DingTalk-specific `dingtalk/inbound-media.ts`, because both the
7
7
  * transport (rejecting an oversized download) and `agent/channel-runner.ts` (skipping an
8
8
  * oversized file before base64-encoding it) need the same number, and `agent/` never imports
9
9
  * from `runtime/` (spec 049).
@@ -282,7 +282,10 @@ export function createChannelIndex(options) {
282
282
  })
283
283
  .catch((error) => {
284
284
  dirty = true;
285
- log.logWarning(`Failed to update ${CHANNELS_INDEX_FILENAME}`, errorMessage(error));
285
+ log.logWarn("channel.index.write_failed", "Channel index update failed", {
286
+ reason: errorMessage(error),
287
+ fields: { file: CHANNELS_INDEX_FILENAME },
288
+ });
286
289
  });
287
290
  return pending;
288
291
  };
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * `/project` — the human control path for a channel's project scope (spec 043, D7). Mirrors
3
- * `task-commands.ts`/`subagent-commands.ts`'s shape: pure-ish functions returning markdown, no
3
+ * `tasks/commands.ts`/`subagents/commands.ts`'s shape: pure-ish functions returning markdown, no
4
4
  * bot/event coupling. Mutations never reach the model.
5
5
  */
6
6
  type ProjectCommand = {
@@ -1,8 +1,8 @@
1
- import { commitProjectSelection, readProjectSelection } from "../channel/project-scope-store.js";
2
1
  import { renderSubcommandUsage } from "../commands/catalog.js";
3
2
  import { loadSecurityConfigWithDiagnostics } from "../security/config.js";
4
3
  import { currentProjectSandboxStatus, isWithinAllowedRoots, resolveExistingDirectory, resolveProjectAccessPolicy, } from "../security/project-scope.js";
5
4
  import { errorMessage } from "../shared/text-utils.js";
5
+ import { commitProjectSelection, readProjectSelection } from "./project-scope-store.js";
6
6
  function usage() {
7
7
  return renderSubcommandUsage("project");
8
8
  }
@@ -22,33 +22,34 @@ export function parseProjectCommand(args) {
22
22
  throw new Error("用法:/project reset");
23
23
  return { action: "reset" };
24
24
  }
25
- throw new Error(`未知的 /project 子命令:${parts[0]}`);
25
+ throw new Error(`未知子命令 \`${parts[0]}\`。`);
26
26
  }
27
27
  function formatShow(options) {
28
28
  const securityLoad = loadSecurityConfigWithDiagnostics(options.appHomeDir);
29
29
  const resolution = resolveProjectAccessPolicy(securityLoad.config, process.cwd());
30
30
  const sandbox = currentProjectSandboxStatus();
31
31
  const selection = readProjectSelection(options.channelDir);
32
- const lines = ["**项目作用域**"];
32
+ const lines = ["**项目目录**"];
33
33
  if (!selection) {
34
- lines.push(`- 项目目录:\`${resolution.policy.defaultRoot}\`(尚未选择过,将在下次准入时采用 app 默认值)`);
34
+ lines.push(`- 当前:\`${resolution.policy.defaultRoot}\`(尚未选择过,下一条消息起采用默认目录)`);
35
35
  }
36
36
  else {
37
- lines.push(`- 项目目录:\`${selection.projectRoot}\`(${selection.updatedBy},更新于 ${selection.updatedAt})`);
37
+ const by = selection.updatedBy === "tui-command" ? "终端" : "钉钉";
38
+ lines.push(`- 当前:\`${selection.projectRoot}\`(${by}中设置,更新于 ${selection.updatedAt})`);
38
39
  }
39
- lines.push(`- 边界:${resolution.configured ? "project(文件工具被约束在此目录内)" : "unbounded(沿用旧的全局文件权限)"}`);
40
- lines.push(`- Enforcement:${sandbox.level}(${sandbox.summary})`);
40
+ lines.push(`- 访问范围:${resolution.configured ? "仅限项目目录(project)" : "不限制(unbounded,沿用全局文件权限)"}`);
41
+ lines.push(`- 隔离级别:${sandbox.level}(${sandbox.summary})`);
41
42
  if (!resolution.configured) {
42
- lines.push(`- 未配置 projectAccess:\`/project set\` 不可用。在 \`security.json\` 写入 projectAccess 段后即可使用。`);
43
+ lines.push("- `/project set` 不可用:请部署者在 `security.json` 中配置 `projectAccess` 后再用。");
43
44
  }
44
45
  else if (!resolution.mutable) {
45
- lines.push("- projectAccess.defaultRoot 配置有误,项目切换已被禁用,见启动诊断。");
46
+ lines.push("- `projectAccess.defaultRoot` 配置有误,项目切换已被禁用;请部署者查看启动日志。");
46
47
  }
47
48
  else {
48
- lines.push(`- 可选根:${resolution.policy.allowedRoots.map((root) => `\`${root}\``).join("、")}`);
49
+ lines.push(`- 允许的根目录:${resolution.policy.allowedRoots.map((root) => `\`${root}\``).join("、")}`);
49
50
  }
50
51
  for (const diagnostic of resolution.diagnostics) {
51
- lines.push(`- ⚠ ${diagnostic.message}`);
52
+ lines.push(`- ⚠️ ${diagnostic.message}`);
52
53
  }
53
54
  return lines.join("\n");
54
55
  }
@@ -56,22 +57,22 @@ async function applyScopeChange(options, requestedPath, label) {
56
57
  const securityLoad = loadSecurityConfigWithDiagnostics(options.appHomeDir);
57
58
  const resolution = resolveProjectAccessPolicy(securityLoad.config, process.cwd());
58
59
  if (!resolution.configured) {
59
- return `无法切换项目:未配置 projectAccess。在 \`security.json\` 写入 projectAccess 段(defaultRoot/allowedRoots)后重试。`;
60
+ return "无法切换项目:未配置 `projectAccess`。请部署者在 `security.json` 中写入 `projectAccess`(`defaultRoot`、`allowedRoots`)后重试。";
60
61
  }
61
62
  if (!resolution.mutable) {
62
- return `无法切换项目:projectAccess.defaultRoot 配置有误(见启动诊断),项目切换已被禁用直到修复。`;
63
+ return "无法切换项目:`projectAccess.defaultRoot` 配置有误,修复前项目切换已被禁用;请部署者查看启动日志。";
63
64
  }
64
65
  const real = resolveExistingDirectory(requestedPath);
65
66
  if (!real) {
66
67
  return `无法切换项目:\`${requestedPath}\` 不是一个存在的绝对目录。`;
67
68
  }
68
69
  if (!isWithinAllowedRoots(real, resolution.policy)) {
69
- return `无法切换项目:\`${real}\` 不在允许的可选根内。可选根:${resolution.policy.allowedRoots
70
+ return `无法切换项目:\`${real}\` 不在允许的根目录内。允许的根目录:${resolution.policy.allowedRoots
70
71
  .map((root) => `\`${root}\``)
71
72
  .join("、")}。`;
72
73
  }
73
74
  if (options.isBusy()) {
74
- return "无法切换项目:当前频道有回合正在进行,请等待结束后重试。";
75
+ return "无法切换项目:当前频道有回合正在进行。等它结束后重试,或先用 `/stop` 停止。";
75
76
  }
76
77
  const blockers = await options.listActiveBlockers();
77
78
  if (blockers.length > 0) {
@@ -79,7 +80,7 @@ async function applyScopeChange(options, requestedPath, label) {
79
80
  }
80
81
  await commitProjectSelection(options.channelDir, real, options.actor);
81
82
  await options.onScopeChanged?.();
82
- return `${label}:\`${real}\`。下一次消息将在新的项目目录下运行。`;
83
+ return `${label}:\`${real}\`。下一条消息起在新的项目目录下运行。`;
83
84
  }
84
85
  export async function handleProjectCommand(options) {
85
86
  let command;
@@ -105,7 +105,7 @@ export function resolveProjectScope(channelDir, resolution) {
105
105
  if (resolution.configured && !isWithinAllowedRoots(real, resolution.policy)) {
106
106
  return {
107
107
  kind: "blocked",
108
- reason: `项目目录 ${real} 已不在允许的可选根内(security.json 的 projectAccess 已变更)。请在频道空闲时执行 /project set <path> 或 /project reset。`,
108
+ reason: `项目目录 \`${real}\` 已不在允许的根目录内(security.json 的 projectAccess 已变更)。请在频道空闲时用 \`/project set <路径>\` 或 \`/project reset\` 重新选择。`,
109
109
  };
110
110
  }
111
111
  return { kind: "ready", scope: { projectRoot: real, boundary, sandbox }, selection: existing };
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Per-channel message archive (`log.jsonl`): inbound messages, bot responses and delegation records,
3
+ * with de-duplication, size rotation and a debounced flush.
4
+ */
1
5
  import { existsSync, mkdirSync } from "fs";
2
6
  import { writeFile } from "fs/promises";
3
7
  import { basename, dirname, join } from "path";
@@ -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
  export type BuiltInCommandName = "help" | "steer" | "followup" | "stop" | "events" | "tasks" | "status" | "usage" | "context" | "subagents" | "project" | "skills";
@@ -42,7 +42,7 @@ export interface CommandSubSpec {
42
42
  }
43
43
  /**
44
44
  * Single source of truth for a slash command's metadata. `HELP_TEXT`, the TUI
45
- * autocomplete list, the busy-time hint, and the known-command set are all
45
+ * autocomplete list, the busy-time hint (`formatBusyHint`), and the known-command set are all
46
46
  * derived from these tables — do not hand-maintain those in parallel.
47
47
  *
48
48
  * `subcommands`, where present, is *also* the single source for that command's own `usage()`
@@ -70,6 +70,8 @@ export interface CommandSpec {
70
70
  runnerHandled?: boolean;
71
71
  /** Broadcast list of this command's subcommands, for commands with a `/<name> <action> ...` shape. */
72
72
  subcommands?: CommandSubSpec[];
73
+ /** Extra paragraph shown only in `/help <name>`, for context too specific for the top-level list. */
74
+ note?: string;
73
75
  }
74
76
  /**
75
77
  * Transport commands: handled directly by the runtime layer (never sent to the
@@ -89,11 +91,15 @@ export declare function isBuiltInCommandName(name: string): name is BuiltInComma
89
91
  export declare function isSessionCommandName(name: string): boolean;
90
92
  /** Narrow a parsed built-in to one `ChannelRunner.handleBuiltinCommand` accepts. */
91
93
  export declare function isRunnerBuiltInCommand(command: BuiltInCommand): command is RunnerBuiltInCommand;
92
- /** Comma-separated list of commands usable while a task is streaming (names only). */
93
- export declare function formatBusyCommandList(): string;
94
94
  /**
95
- * Renders a command's subcommand table as its `usage()` text — the single source `task-commands.ts`,
96
- * `event-commands.ts`, `subagent-commands.ts`, `project-commands.ts`, and `memory/commands.ts` call
95
+ * The reply to a slash command that cannot run mid-turn — one source for DingTalk and the TUI
96
+ * (spec 053, D8). Both lists are derived from `availableWhileBusy`, so a command whose busy
97
+ * behaviour changes moves between them on its own instead of a hand-kept list going stale.
98
+ */
99
+ export declare function formatBusyHint(): string;
100
+ /**
101
+ * Renders a command's subcommand table as its `usage()` text — the single source `tasks/commands.ts`,
102
+ * `events/commands.ts`, `subagents/commands.ts`, `channel/commands.ts`, and `memory/commands.ts` call
97
103
  * on a parse error, replacing five hand-written `usage()` bodies (review 2026-08-24 §3.1).
98
104
  */
99
105
  export declare function renderSubcommandUsage(name: string): string;
@@ -113,6 +119,17 @@ export declare function slashCommandName(text: string): string | null;
113
119
  * every `skill:` name rather than trusting it.
114
120
  */
115
121
  export declare function isKnownCommandName(name: string, knownSkillNames?: Iterable<string>): boolean;
122
+ /**
123
+ * Replies around queueing that DingTalk and the TUI both give (spec 053, D10). One wording per
124
+ * situation, so the two surfaces cannot drift into two languages again.
125
+ */
126
+ export declare function formatMissingQueueMessage(name: "steer" | "followup"): string;
127
+ /** `explainFollowup`: a plain busy-time message was steered implicitly, so say how to defer it instead. */
128
+ export declare function formatSteerQueued(explainFollowup: boolean): string;
129
+ export declare function formatFollowupQueued(): string;
130
+ export declare function formatNoRunningTurn(name: "stop" | "steer" | "followup"): string;
131
+ /** The `/new` confirmation, shared by the DingTalk runtime path and the session-layer command. */
132
+ export declare function formatNewSessionReply(sessionId: string): string;
116
133
  export declare function formatUnknownCommandMessage(name: string): string;
117
134
  export declare function parseBuiltInCommand(text: string): BuiltInCommand | null;
118
135
  /**