@oyasmi/pipiclaw 0.9.4-beta.1 → 0.9.4

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 (291) 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 +148 -1245
  5. package/dist/agent/maintenance-context.d.ts +1 -1
  6. package/dist/agent/maintenance-context.js +1 -1
  7. package/dist/agent/prompt/resources.d.ts +3 -0
  8. package/dist/agent/prompt/resources.js +7 -1
  9. package/dist/agent/runner-factory.d.ts +1 -43
  10. package/dist/agent/{command-extension.d.ts → session/command-extension.d.ts} +4 -0
  11. package/dist/agent/{command-extension.js → session/command-extension.js} +5 -5
  12. package/dist/agent/{type-guards.d.ts → session/event-guards.d.ts} +2 -2
  13. package/dist/agent/{type-guards.js → session/event-guards.js} +5 -1
  14. package/dist/agent/session/model-selection.d.ts +47 -0
  15. package/dist/agent/session/model-selection.js +99 -0
  16. package/dist/agent/{session-adapter.d.ts → session/session-adapter.d.ts} +21 -1
  17. package/dist/agent/{session-adapter.js → session/session-adapter.js} +83 -1
  18. package/dist/agent/{session-events.d.ts → session/session-events.d.ts} +9 -5
  19. package/dist/agent/{session-events.js → session/session-events.js} +10 -10
  20. package/dist/agent/session/session-host.d.ts +200 -0
  21. package/dist/agent/session/session-host.js +621 -0
  22. package/dist/agent/{session-resource-gate.js → session/session-resource-gate.js} +2 -2
  23. package/dist/agent/{context-budget.js → turn/context-budget.js} +5 -1
  24. package/dist/agent/{progress-formatter.d.ts → turn/progress-formatter.d.ts} +4 -1
  25. package/dist/agent/{run-queue.d.ts → turn/run-queue.d.ts} +1 -1
  26. package/dist/agent/{run-queue.js → turn/run-queue.js} +3 -3
  27. package/dist/{memory → agent/turn}/task-digest.js +4 -4
  28. package/dist/agent/turn/turn-context.d.ts +14 -0
  29. package/dist/agent/turn/turn-context.js +64 -0
  30. package/dist/agent/turn/turn-finish.d.ts +50 -0
  31. package/dist/agent/turn/turn-finish.js +188 -0
  32. package/dist/agent/turn/turn-input.d.ts +43 -0
  33. package/dist/agent/turn/turn-input.js +79 -0
  34. package/dist/agent/turn/turn-pipeline.d.ts +68 -0
  35. package/dist/agent/turn/turn-pipeline.js +257 -0
  36. package/dist/agent/{turn-prompt.d.ts → turn/turn-prompt.d.ts} +2 -2
  37. package/dist/agent/{turn-prompt.js → turn/turn-prompt.js} +6 -2
  38. package/dist/agent/{turn-recovery.js → turn/turn-recovery.js} +1 -1
  39. package/dist/agent/{turn-state.d.ts → turn/turn-state.d.ts} +1 -1
  40. package/dist/agent/types.d.ts +43 -2
  41. package/dist/agent/types.js +1 -1
  42. package/dist/{models/auth-cli.d.ts → app/auth-command.d.ts} +1 -1
  43. package/dist/{models/auth-cli.js → app/auth-command.js} +11 -8
  44. package/dist/{runtime/app-home.d.ts → app/home.d.ts} +0 -2
  45. package/dist/{runtime/app-home.js → app/home.js} +4 -75
  46. package/dist/{app-services.d.ts → app/services.d.ts} +5 -5
  47. package/dist/{app-services.js → app/services.js} +10 -10
  48. package/dist/channel/channel-context.d.ts +12 -2
  49. package/dist/channel/channel-context.js +29 -2
  50. package/dist/channel/channel-event.d.ts +10 -2
  51. package/dist/channel/channel-event.js +1 -1
  52. package/dist/{runtime/project-commands.d.ts → channel/commands.d.ts} +1 -1
  53. package/dist/{runtime/project-commands.js → channel/commands.js} +1 -1
  54. package/dist/channel/store.js +4 -0
  55. package/dist/commands/catalog.d.ts +3 -3
  56. package/dist/commands/catalog.js +3 -3
  57. package/dist/{runtime/report-commands.d.ts → commands/router.d.ts} +10 -3
  58. package/dist/{runtime/report-commands.js → commands/router.js} +5 -5
  59. package/dist/{settings.d.ts → config/settings.d.ts} +7 -8
  60. package/dist/{settings.js → config/settings.js} +7 -10
  61. package/dist/{tools/config.d.ts → config/tools.d.ts} +1 -2
  62. package/dist/{tools/config.js → config/tools.js} +5 -2
  63. package/dist/dingtalk/access-token.d.ts +12 -0
  64. package/dist/dingtalk/access-token.js +51 -0
  65. package/dist/dingtalk/api.d.ts +19 -0
  66. package/dist/dingtalk/api.js +67 -0
  67. package/dist/dingtalk/bot.d.ts +97 -0
  68. package/dist/dingtalk/bot.js +389 -0
  69. package/dist/dingtalk/cards.d.ts +56 -0
  70. package/dist/dingtalk/cards.js +318 -0
  71. package/dist/{runtime → dingtalk}/channel-queue.js +3 -0
  72. package/dist/dingtalk/config.d.ts +19 -0
  73. package/dist/dingtalk/config.js +95 -0
  74. package/dist/dingtalk/connection.d.ts +57 -0
  75. package/dist/dingtalk/connection.js +356 -0
  76. package/dist/dingtalk/conversation-meta.d.ts +16 -0
  77. package/dist/dingtalk/conversation-meta.js +77 -0
  78. package/dist/{runtime → dingtalk}/delivery.d.ts +6 -2
  79. package/dist/dingtalk/handler.d.ts +90 -0
  80. package/dist/dingtalk/handler.js +1 -0
  81. package/dist/dingtalk/inbound.d.ts +66 -0
  82. package/dist/dingtalk/inbound.js +137 -0
  83. package/dist/dingtalk/media.d.ts +66 -0
  84. package/dist/dingtalk/media.js +214 -0
  85. package/dist/events/{event-commands.js → commands.js} +6 -2
  86. package/dist/events/parse.d.ts +14 -0
  87. package/dist/events/parse.js +114 -0
  88. package/dist/events/types.d.ts +93 -0
  89. package/dist/events/types.js +1 -0
  90. package/dist/events/{event-validation.d.ts → validation.d.ts} +1 -1
  91. package/dist/events/watcher.d.ts +67 -0
  92. package/dist/events/{events.js → watcher.js} +6 -109
  93. package/dist/index.d.ts +6 -4
  94. package/dist/index.js +2 -2
  95. package/dist/jobs/launch.d.ts +42 -0
  96. package/dist/jobs/launch.js +118 -0
  97. package/dist/{agent/job-manager.d.ts → jobs/manager.d.ts} +1 -67
  98. package/dist/{agent/job-manager.js → jobs/manager.js} +3 -146
  99. package/dist/jobs/record.d.ts +55 -0
  100. package/dist/jobs/record.js +36 -0
  101. package/dist/main.js +2 -2
  102. package/dist/memory/maintenance-gates.d.ts +2 -2
  103. package/dist/memory/maintenance-tuning.d.ts +15 -0
  104. package/dist/memory/maintenance-tuning.js +3 -0
  105. package/dist/memory/reflect-job.d.ts +2 -2
  106. package/dist/memory/reflect-job.js +4 -2
  107. package/dist/memory/scheduler.d.ts +3 -3
  108. package/dist/memory/scheduler.js +2 -1
  109. package/dist/memory/sidecar-worker.js +1 -1
  110. package/dist/memory/transcript.js +1 -1
  111. package/dist/{agent/model-fallback.d.ts → models/fallback.d.ts} +6 -6
  112. package/dist/{agent/model-fallback.js → models/fallback.js} +15 -28
  113. package/dist/models/login-identity.d.ts +2 -0
  114. package/dist/models/login-identity.js +83 -0
  115. package/dist/models/provider-login.d.ts +3 -1
  116. package/dist/models/provider-login.js +8 -2
  117. package/dist/models/reference.d.ts +20 -0
  118. package/dist/models/{utils.js → reference.js} +0 -48
  119. package/dist/models/{utils.d.ts → runtime.d.ts} +1 -16
  120. package/dist/models/runtime.js +52 -0
  121. package/dist/playbooks/catalog.d.ts +6 -2
  122. package/dist/playbooks/catalog.js +9 -6
  123. package/dist/runtime/bootstrap.d.ts +7 -17
  124. package/dist/runtime/bootstrap.js +37 -755
  125. package/dist/runtime/durable-dispatch.d.ts +17 -4
  126. package/dist/runtime/durable-dispatch.js +60 -18
  127. package/dist/runtime/inbound-images.d.ts +18 -0
  128. package/dist/runtime/inbound-images.js +51 -0
  129. package/dist/runtime/shutdown.d.ts +39 -0
  130. package/dist/runtime/shutdown.js +120 -0
  131. package/dist/runtime/stop-watchdog.d.ts +16 -0
  132. package/dist/runtime/stop-watchdog.js +32 -0
  133. package/dist/runtime/task-driver.d.ts +2 -2
  134. package/dist/runtime/task-driver.js +3 -3
  135. package/dist/runtime/task-migration.js +2 -2
  136. package/dist/runtime/task-spawn.d.ts +1 -1
  137. package/dist/runtime/task-spawn.js +1 -1
  138. package/dist/runtime/turn-handler.d.ts +47 -0
  139. package/dist/runtime/turn-handler.js +318 -0
  140. package/dist/runtime/turn-run.d.ts +52 -0
  141. package/dist/runtime/turn-run.js +318 -0
  142. package/dist/security/command-guard.js +4 -0
  143. package/dist/security/network.js +4 -0
  144. package/dist/security/path-guard.js +4 -0
  145. package/dist/security/types.d.ts +1 -2
  146. package/dist/security/types.js +1 -2
  147. package/dist/shared/exact-keys.d.ts +1 -1
  148. package/dist/shared/host-process.js +1 -1
  149. package/dist/shared/wake-claim.d.ts +1 -1
  150. package/dist/{runtime/skill-commands.d.ts → skills/commands.d.ts} +2 -2
  151. package/dist/{runtime/skill-commands.js → skills/commands.js} +1 -1
  152. package/dist/{agent/workspace-resources.js → skills/loader.js} +1 -1
  153. package/dist/{tools/skill-security.js → skills/validation.js} +4 -0
  154. package/dist/skills/workspace.d.ts +33 -0
  155. package/dist/skills/workspace.js +116 -0
  156. package/dist/{runtime/subagent-commands.d.ts → subagents/commands.d.ts} +4 -3
  157. package/dist/{runtime/subagent-commands.js → subagents/commands.js} +2 -2
  158. package/dist/subagents/completion-wake.d.ts +17 -0
  159. package/dist/subagents/completion-wake.js +76 -0
  160. package/dist/subagents/detached-discovery.js +1 -1
  161. package/dist/subagents/discovery.d.ts +1 -1
  162. package/dist/subagents/discovery.js +2 -2
  163. package/dist/subagents/dispatch.d.ts +33 -0
  164. package/dist/subagents/dispatch.js +190 -0
  165. package/dist/subagents/external/dispatch.d.ts +25 -0
  166. package/dist/subagents/external/dispatch.js +90 -0
  167. package/dist/subagents/external/harness.d.ts +1 -1
  168. package/dist/subagents/external/progress-tail.d.ts +1 -1
  169. package/dist/subagents/external/run.d.ts +2 -1
  170. package/dist/subagents/external/run.js +2 -2
  171. package/dist/subagents/external/settlement.d.ts +1 -1
  172. package/dist/subagents/format.d.ts +1 -1
  173. package/dist/subagents/grace.d.ts +24 -0
  174. package/dist/subagents/grace.js +57 -0
  175. package/dist/subagents/internal/outcome.d.ts +24 -0
  176. package/dist/subagents/internal/outcome.js +149 -0
  177. package/dist/subagents/internal/provider-retry.d.ts +19 -0
  178. package/dist/subagents/internal/provider-retry.js +83 -0
  179. package/dist/subagents/internal/run.d.ts +31 -0
  180. package/dist/subagents/internal/run.js +240 -0
  181. package/dist/subagents/internal/state.d.ts +43 -0
  182. package/dist/subagents/internal/state.js +48 -0
  183. package/dist/subagents/internal/worker.d.ts +51 -0
  184. package/dist/subagents/internal/worker.js +167 -0
  185. package/dist/subagents/result.d.ts +62 -0
  186. package/dist/subagents/result.js +103 -0
  187. package/dist/subagents/run-record.d.ts +222 -0
  188. package/dist/subagents/run-record.js +101 -0
  189. package/dist/subagents/run-registry.d.ts +9 -0
  190. package/dist/subagents/run-registry.js +125 -0
  191. package/dist/subagents/runs.d.ts +7 -243
  192. package/dist/subagents/runs.js +8 -291
  193. package/dist/subagents/task-envelope.d.ts +36 -0
  194. package/dist/subagents/task-envelope.js +168 -0
  195. package/dist/subagents/types.d.ts +154 -0
  196. package/dist/subagents/types.js +1 -0
  197. package/dist/subagents/verification-outcome.d.ts +1 -1
  198. package/dist/tasks/board.d.ts +2 -2
  199. package/dist/tasks/board.js +2 -2
  200. package/dist/tasks/{work-log.d.ts → bound-work.d.ts} +1 -1
  201. package/dist/tasks/{work-log.js → bound-work.js} +1 -1
  202. package/dist/tasks/brief.js +1 -1
  203. package/dist/{runtime/task-commands.d.ts → tasks/commands.d.ts} +1 -1
  204. package/dist/{runtime/task-commands.js → tasks/commands.js} +12 -8
  205. package/dist/tasks/contract-input.d.ts +1 -1
  206. package/dist/tasks/contract-input.js +1 -1
  207. package/dist/tasks/create.js +1 -1
  208. package/dist/tasks/{log.js → loop-log.js} +1 -1
  209. package/dist/tasks/mutation-lock.js +1 -1
  210. package/dist/tasks/session-path.js +1 -1
  211. package/dist/tasks/steer.js +1 -1
  212. package/dist/tasks/store.js +2 -2
  213. package/dist/tools/bash.d.ts +1 -1
  214. package/dist/tools/{tool-details.d.ts → contract/details.d.ts} +2 -2
  215. package/dist/tools/{tool-details.js → contract/details.js} +4 -4
  216. package/dist/tools/{presentation.js → contract/presentation.js} +3 -3
  217. package/dist/tools/event-manage.d.ts +1 -1
  218. package/dist/tools/event-manage.js +4 -4
  219. package/dist/tools/index.d.ts +3 -3
  220. package/dist/tools/index.js +7 -6
  221. package/dist/tools/job.d.ts +1 -1
  222. package/dist/tools/registry.d.ts +7 -7
  223. package/dist/tools/registry.js +6 -6
  224. package/dist/tools/session-search.d.ts +1 -1
  225. package/dist/tools/skill.d.ts +2 -34
  226. package/dist/tools/skill.js +8 -116
  227. package/dist/tools/subagent-manage.js +4 -3
  228. package/dist/tools/subagent.d.ts +46 -0
  229. package/dist/tools/subagent.js +127 -0
  230. package/dist/tools/{task-manage.d.ts → task-manage/factory.d.ts} +7 -3
  231. package/dist/tools/{task-manage.js → task-manage/factory.js} +7 -7
  232. package/dist/tools/task-manage/lifecycle.js +2 -2
  233. package/dist/tools/task-manage/log-view.js +2 -2
  234. package/dist/tools/task-manage/shared.js +3 -3
  235. package/dist/tools/task-manage/step-end.js +3 -3
  236. package/dist/tools/task-manage/types.d.ts +1 -1
  237. package/dist/tools/web-fetch.d.ts +1 -1
  238. package/dist/tools/web-search.d.ts +1 -1
  239. package/dist/tui/app.d.ts +1 -1
  240. package/dist/tui/app.js +6 -6
  241. package/dist/tui/cli.d.ts +1 -1
  242. package/dist/tui/cli.js +1 -1
  243. package/dist/tui/frontend.d.ts +44 -0
  244. package/dist/tui/frontend.js +13 -0
  245. package/dist/tui/pitui-frontend.d.ts +1 -1
  246. package/dist/tui/plain-frontend.d.ts +1 -1
  247. package/dist/tui/renderer.d.ts +3 -42
  248. package/dist/tui/terminal-context.d.ts +2 -2
  249. package/dist/tui/terminal-media-sender.d.ts +1 -1
  250. package/dist/tui/turn-controller.d.ts +1 -1
  251. package/dist/usage/ledger.js +4 -0
  252. package/dist/{shared/types.d.ts → usage/totals.d.ts} +3 -0
  253. package/dist/web/client.d.ts +5 -1
  254. package/dist/web/client.js +4 -0
  255. package/dist/web/config.d.ts +1 -1
  256. package/dist/web/fetch.d.ts +1 -1
  257. package/dist/web/search-providers.d.ts +1 -1
  258. package/dist/web/search.d.ts +1 -1
  259. package/package.json +10 -7
  260. package/dist/events/events.d.ts +0 -159
  261. package/dist/runtime/dingtalk.d.ts +0 -272
  262. package/dist/runtime/dingtalk.js +0 -1470
  263. package/dist/subagents/tool.d.ts +0 -213
  264. package/dist/subagents/tool.js +0 -1282
  265. /package/dist/{runtime → agent/prompt}/workspace-templates.d.ts +0 -0
  266. /package/dist/{runtime → agent/prompt}/workspace-templates.js +0 -0
  267. /package/dist/agent/{session-resource-gate.d.ts → session/session-resource-gate.d.ts} +0 -0
  268. /package/dist/agent/{context-budget.d.ts → turn/context-budget.d.ts} +0 -0
  269. /package/dist/agent/{progress-formatter.js → turn/progress-formatter.js} +0 -0
  270. /package/dist/{memory → agent/turn}/task-digest.d.ts +0 -0
  271. /package/dist/agent/{turn-error.d.ts → turn/turn-error.d.ts} +0 -0
  272. /package/dist/agent/{turn-error.js → turn/turn-error.js} +0 -0
  273. /package/dist/agent/{turn-recovery.d.ts → turn/turn-recovery.d.ts} +0 -0
  274. /package/dist/agent/{turn-state.js → turn/turn-state.js} +0 -0
  275. /package/dist/{runtime → app}/proxy.d.ts +0 -0
  276. /package/dist/{runtime → app}/proxy.js +0 -0
  277. /package/dist/{runtime → dingtalk}/channel-queue.d.ts +0 -0
  278. /package/dist/{runtime → dingtalk}/delivery.js +0 -0
  279. /package/dist/{runtime → dingtalk}/inbound-media.d.ts +0 -0
  280. /package/dist/{runtime → dingtalk}/inbound-media.js +0 -0
  281. /package/dist/events/{event-commands.d.ts → commands.d.ts} +0 -0
  282. /package/dist/events/{event-validation.js → validation.js} +0 -0
  283. /package/dist/{agent/workspace-resources.d.ts → skills/loader.d.ts} +0 -0
  284. /package/dist/{tools/skill-security.d.ts → skills/validation.d.ts} +0 -0
  285. /package/dist/tasks/{ledger.d.ts → contract.d.ts} +0 -0
  286. /package/dist/tasks/{ledger.js → contract.js} +0 -0
  287. /package/dist/tasks/{log.d.ts → loop-log.d.ts} +0 -0
  288. /package/dist/tools/{subagent-tool-names.d.ts → contract/names.d.ts} +0 -0
  289. /package/dist/tools/{subagent-tool-names.js → contract/names.js} +0 -0
  290. /package/dist/tools/{presentation.d.ts → contract/presentation.d.ts} +0 -0
  291. /package/dist/{shared/types.js → usage/totals.js} +0 -0
@@ -0,0 +1,19 @@
1
+ /**
2
+ * The runner-handled built-in slash commands typed on an idle channel (`/help`, `/context`, and the
3
+ * "nothing to stop/steer" replies). The stateless report commands (`/tasks`, `/events`, …) never
4
+ * reach here — they go through `commands/router.ts`.
5
+ */
6
+ import type { ChannelContext } from "../channel/channel-context.js";
7
+ import { type RunnerBuiltInCommand } from "../commands/catalog.js";
8
+ /** The slice of the runner a built-in command reads; everything else it needs is the command itself. */
9
+ export interface BuiltinCommandHost {
10
+ channelId: string;
11
+ ensureSessionReady(): Promise<void>;
12
+ promptTemplates(): ReadonlyArray<{
13
+ name: string;
14
+ }>;
15
+ renderContextReport(args: string): string;
16
+ }
17
+ /** A `/steer` or `/followup` needs a message: the trimmed text, or an error telling the user how. */
18
+ export declare function requireQueuedMessage(text: string, commandName: "steer" | "followup"): string;
19
+ export declare function handleBuiltinCommand(host: BuiltinCommandHost, ctx: ChannelContext, command: RunnerBuiltInCommand): Promise<void>;
@@ -0,0 +1,80 @@
1
+ import { formatMissingQueueMessage, formatNoRunningTurn, renderBuiltInHelp, } from "../commands/catalog.js";
2
+ import * as log from "../log.js";
3
+ import { errorMessage } from "../shared/text-utils.js";
4
+ /** A `/steer` or `/followup` needs a message: the trimmed text, or an error telling the user how. */
5
+ export function requireQueuedMessage(text, commandName) {
6
+ const trimmedText = text.trim();
7
+ if (!trimmedText) {
8
+ throw new Error(formatMissingQueueMessage(commandName));
9
+ }
10
+ return trimmedText;
11
+ }
12
+ /**
13
+ * `/help` — the static per-command listing from `commands.ts`, plus (top-level only) the
14
+ * prompt templates this session can actually invoke via `/<template-name>`. Workspace skills
15
+ * have their own dedicated command (`/skills`) and are deliberately not duplicated here.
16
+ * Prompt templates aren't knowable to `renderBuiltInHelp` itself (it is a pure function with
17
+ * no session state), so the runner appends them here (review 2026-08-24 §1.9).
18
+ */
19
+ function renderHelpWithDiscovery(host, args) {
20
+ const help = renderBuiltInHelp(args);
21
+ if (args.trim()) {
22
+ return help;
23
+ }
24
+ const sections = [help];
25
+ const templates = host.promptTemplates();
26
+ if (templates.length > 0) {
27
+ sections.push(`**提示模板**\n\n${templates.map((template) => `- \`/${template.name}\``).join("\n")}`);
28
+ }
29
+ return sections.join("\n\n");
30
+ }
31
+ async function sendCommandReply(ctx, text, commandName) {
32
+ // Command echoes are ephemeral control-plane traffic, not conversation: keep them out of
33
+ // log.jsonl so they are never re-consumed as memory-extraction input (review 2026-08-24 §1.2).
34
+ const title = commandName ? `/${commandName}` : undefined;
35
+ const delivered = await ctx.respondPlain(text, false, title);
36
+ if (!delivered) {
37
+ await ctx.replaceMessage(text);
38
+ await ctx.flush();
39
+ }
40
+ }
41
+ export async function handleBuiltinCommand(host, ctx, command) {
42
+ try {
43
+ // `/help` and `/context` read the session (prompt templates, active model).
44
+ // The session runtime is built asynchronously after construction, so a command
45
+ // that lands before it is ready would otherwise hit a TypeError (spec 048 F2).
46
+ await host.ensureSessionReady();
47
+ switch (command.name) {
48
+ case "help":
49
+ await sendCommandReply(ctx, renderHelpWithDiscovery(host, command.args), "help");
50
+ return;
51
+ case "context":
52
+ await sendCommandReply(ctx, host.renderContextReport(command.args), "context");
53
+ return;
54
+ case "stop":
55
+ await sendCommandReply(ctx, formatNoRunningTurn("stop"), "stop");
56
+ return;
57
+ case "steer":
58
+ requireQueuedMessage(command.args, "steer");
59
+ await sendCommandReply(ctx, formatNoRunningTurn("steer"), "steer");
60
+ return;
61
+ case "followup":
62
+ requireQueuedMessage(command.args, "followup");
63
+ await sendCommandReply(ctx, formatNoRunningTurn("followup"), "followup");
64
+ return;
65
+ default: {
66
+ // The stateless report commands (events/tasks/status/usage/subagents/project — see
67
+ // `BUILT_IN_COMMANDS`'s `runnerHandled: false` entries) are routed to their own
68
+ // handlers upstream and never reach here; the narrowed parameter type makes that a
69
+ // compile-time guarantee.
70
+ const _exhaustive = command.name;
71
+ throw new Error(`Unhandled built-in command: ${String(_exhaustive)}`);
72
+ }
73
+ }
74
+ }
75
+ catch (err) {
76
+ const errMsg = errorMessage(err);
77
+ log.logWarn("agent.command.failed", "Built-in command failed", { channelId: host.channelId, reason: errMsg });
78
+ await sendCommandReply(ctx, `命令执行失败:${errMsg}`, command.name);
79
+ }
80
+ }
@@ -1,11 +1,11 @@
1
1
  import type { ChannelContext } from "../channel/channel-context.js";
2
- import { type InboundImage } from "../channel/channel-event.js";
2
+ import type { InboundImage } from "../channel/channel-event.js";
3
3
  import type { ChannelStore } from "../channel/store.js";
4
4
  import { type RunnerBuiltInCommand } from "../commands/catalog.js";
5
5
  import type { MemoryMaintenanceRuntimeContext } from "../memory/scheduler.js";
6
- import type { UsageTotals } from "../shared/types.js";
7
- import { type SubAgentDiscoveryResult } from "../subagents/discovery.js";
8
- import type { RunnerDeps, RunnerFactoryPaths } from "./runner-factory.js";
6
+ import type { SubAgentDiscoveryResult } from "../subagents/discovery.js";
7
+ import type { UsageTotals } from "../usage/totals.js";
8
+ import type { RunnerDeps, RunnerFactoryPaths } from "./types.js";
9
9
  import { type AgentRunner, type RunnerStatusSnapshot, type TurnStatus } from "./types.js";
10
10
  export declare class ChannelRunner implements AgentRunner {
11
11
  private readonly executor;
@@ -29,57 +29,23 @@ export declare class ChannelRunner implements AgentRunner {
29
29
  private readonly projectScope;
30
30
  /** Re-read per use, not captured once: an edited security.json takes effect without a restart. */
31
31
  private readonly loadSecurityConfig;
32
- private session;
33
- /** Settings manager owned by the currently bound AgentSession. */
34
- private sessionSettingsManager;
35
- private get agent();
36
- private get sessionManager();
37
32
  private readonly settingsManager;
38
- private modelRuntime;
39
- private modelRegistry;
33
+ private readonly host;
34
+ private readonly turnFinisher;
35
+ private readonly pipeline;
40
36
  private readonly memoryLifecycle;
41
37
  private readonly ledger;
42
38
  private readonly memoryActivityRecorder;
43
- private readonly sessionResourceGate;
44
- private readonly sessionReady;
45
- /**
46
- * Flips true only once `initializeSession` has fully assigned `this.session`
47
- * and loaded its resources. Synchronous dispatch-path callers (`isKnownSlashCommand`)
48
- * must not touch `this.session` before this — the model runtime takes hundreds
49
- * of ms to build and the first message can arrive first (spec 048 F2).
50
- */
51
- private sessionInitialized;
52
- private sessionRuntime;
53
- private sessionUnsubscribe?;
54
- private subAgentDiscovery;
55
- private activeModel;
56
- private currentSkills;
57
- /** Last built system prompt (spec 025): feeds the boundary footer, /context and the debug manifest. */
58
- private lastPromptBuild?;
59
- /** SOUL/AGENTS as resolved for the last build, for the `/context` independent-budget lines. */
60
- private lastWorkspaceResources?;
61
- /** The exact system prompt the provider last received (our prompt + pi's tail + footer). */
62
- private lastFinalPrompt?;
39
+ private readonly models;
63
40
  private lastTurnContextStats?;
64
- private currentTools;
65
- private firstTurnMemoryBootstrapPending;
66
- /** Mirror of `tools.tasks.enabled` from the last tools-config load (see buildRuntimeTools). */
67
- private tasksEnabled;
68
- /**
69
- * Set while this runner is bound to a task's own session (spec 051, D3). Turns are serialized
70
- * per channel, so one runner can carry both surfaces by swapping which session file it is
71
- * bound to between turns — which keeps busy state, `/stop`, steering and turn recovery with
72
- * their existing single owner instead of splitting them across two runner instances.
73
- */
74
- private taskLoop?;
75
41
  /** Single owner of turn state; see TurnPhase in types.ts and TurnStateMachine in turn-state.ts. */
76
42
  private readonly turnState;
77
43
  /** Set once transport-level `/new` replaces this generation. A retired runner is never reused. */
78
44
  private retired;
79
- /** When the primary model last failed and we switched to the backup. null = on primary. */
80
- private primaryFailedAt;
81
45
  private runState;
82
46
  constructor(channelId: string, channelDir: string, paths: RunnerFactoryPaths, deps: RunnerDeps);
47
+ private get session();
48
+ private get sessionManager();
83
49
  beginTurn(taskText: string): void;
84
50
  endTurn(): void;
85
51
  forceEndTurn(reason: string): boolean;
@@ -94,14 +60,6 @@ export declare class ChannelRunner implements AgentRunner {
94
60
  durationMs: number;
95
61
  silent: boolean;
96
62
  }>;
97
- /**
98
- * The epilogue shared by every exit path out of `run()`'s try/catch: debug dump, delivery of
99
- * whatever final message the turn settled on, usage/ledger accounting, the end-of-turn memory
100
- * flush, and clearing run state. Pulled out of `run()` itself only to keep that method's main
101
- * line (prepare → prompt with fallback) readable; every input here is `run()`-local, not
102
- * instance state, so it is threaded through explicitly rather than promoted to a field.
103
- */
104
- private finishTurn;
105
63
  handleBuiltinCommand(ctx: ChannelContext, command: RunnerBuiltInCommand): Promise<void>;
106
64
  /**
107
65
  * True if `text` is a slash command the runtime or session layer can handle:
@@ -126,173 +84,27 @@ export declare class ChannelRunner implements AgentRunner {
126
84
  * often the larger half), and the last turn's dynamic context.
127
85
  */
128
86
  renderContextReport(args?: string): string;
129
- /**
130
- * `/help` — the static per-command listing from `commands.ts`, plus (top-level only) the
131
- * prompt templates this session can actually invoke via `/<template-name>`. Workspace skills
132
- * have their own dedicated command (`/skills`) and are deliberately not duplicated here.
133
- * Prompt templates aren't knowable to `renderBuiltInHelp` itself (it is a pure function with
134
- * no session state), so the runner appends them here (review 2026-08-24 §1.9).
135
- */
136
- private renderHelpWithDiscovery;
137
87
  /** `/subagents list`'s role-directory health tail — whatever this runner already discovered. */
138
88
  getSubAgentDiscoverySnapshot(): SubAgentDiscoveryResult;
139
89
  /**
140
- * The per-turn channel capsule. It replaces the channel paths that used to sit in
141
- * the system prompt: memory/task/event tools are already bound to this channel, so
142
- * the model only needs the directory when it wants to read a file directly.
143
- */
144
- private renderChannelTurnContext;
145
- private sendCommandReply;
146
- /**
147
- * Buffer one activity event. The write itself is batched by the recorder (see
148
- * `createMemoryActivityRecorder`); `run()` flushes at the end of every turn, which is the
149
- * point the maintenance gates actually start looking at this state.
150
- */
151
- private recordMemoryActivity;
152
- /** Best-effort: a lost activity counter delays maintenance, it never breaks a turn. */
153
- private flushMemoryActivity;
154
- private requireQueuedMessage;
155
- private shouldPreserveRawInput;
156
- /**
157
- * Save a message that exceeds the per-turn input budget so its clipped middle stays reachable.
158
- *
159
- * Pasting a long build log or diff is a normal way to start driving work here, and the clip
160
- * keeps head and tail — which is where the failing frames usually are *not*. Landing the
161
- * original under the channel directory puts it inside the paths `read` already allows, so
162
- * recovery is the ordinary paging path rather than a special case.
163
- *
164
- * Best-effort: if the write fails the turn still runs on the clipped text, just without a
165
- * pointer.
166
- */
167
- private persistOversizedInput;
168
- private formatUserMessage;
169
- /**
170
- * Turn `InboundImage`s (already downloaded and persisted by the transport, spec 049) into the
171
- * `ImageContent[]` `AgentSession.prompt`/`steer` accept, plus any notices to surface to the
172
- * user about images that did not make it into this turn.
173
- *
174
- * Two gates apply, both fail *open* toward "still deliver the message" rather than dropping
175
- * the whole turn over one bad attachment:
176
- *
177
- * - The current model's `input` capability (spec 049 D7). A model that does not declare
178
- * `"image"` support has its image blocks silently replaced with a text placeholder by the
179
- * SDK's provider layer — exactly the failure this spec exists to fix, so it is checked
180
- * explicitly here rather than trusted to fail loudly on its own. Re-checked on every call
181
- * (including a mid-turn steer after a model fallback), since a fallback model's capability
182
- * can differ from the one the turn started with.
183
- * - A defense-in-depth size re-check against `MAX_INBOUND_IMAGE_BYTES`. The transport already
184
- * enforces this at download time, but the check is cheap and free of assumptions about how
185
- * an `InboundImage` reached this method.
186
- *
187
- * An image already marked `unsupportedFormat` (sniffing failed at download time) is skipped
188
- * without its own notice — the `[图片N:格式不支持,已保存]` marker already in the message text
189
- * covers it.
190
- */
191
- private prepareInboundImages;
192
- /**
193
- * Single source of truth for the busy-message window: steer is accepted while
194
- * the prompt is being assembled ("preparing") or while the agent loop is
195
- * actually streaming. Re-asserted after every await because the turn can end
196
- * while this call was suspended.
197
- */
198
- private assertBusyWindowOpen;
199
- private queueBusyMessage;
200
- private resetRunState;
201
- private refreshSessionResources;
202
- /**
203
- * At turn start, if a fallback is active and the primary's cooldown has elapsed,
204
- * switch back to the preferred model. Silent — no user notice on recovery.
205
- */
206
- private maybeRestorePrimaryModel;
207
- private setModelWithThinkingPreservation;
208
- private setThinkingLevelCompat;
209
- private cycleThinkingLevelCompat;
210
- /**
211
- * Resolve the configured backup model reference against available models.
212
- * Returns null when unset, unresolvable/ambiguous, or missing an API key —
213
- * each case logs a warning and disables fallback for this turn.
214
- */
215
- private resolveFallbackModel;
216
- private initializeSession;
217
- private reloadSessionResources;
218
- private bindSessionExtensions;
219
- private ensureSessionReady;
220
- private maybeRunPreventiveCompactionForIncomingText;
221
- private refreshSubAgentDiscovery;
222
- private reportSettingsDiagnostics;
223
- private reportConfigDiagnostics;
224
- /**
225
- * Build the Pipiclaw-owned system prompt (spec 025). This replaces pi's default
226
- * base prompt entirely: identity, execution contract, hard invariants, the tool
227
- * catalog and the workspace files are ours. pi still appends its tail (skills,
228
- * date, cwd), and the boundary footer is appended after that by the prompt
229
- * extension.
230
- *
231
- * Nothing channel-specific enters this text — that is what lets two channels in
232
- * one workspace share a cached prompt prefix. Channel facts ride the turn.
233
- */
234
- private buildSystemPrompt;
235
- private createResourceLoader;
236
- private createAgentSessionServices;
237
- /**
238
- * Load a freshly constructed ResourceLoader before an `AgentSession` is built on top of it.
239
- *
240
- * `AgentSession` reads `resourceLoader.getExtensions()` in its constructor, and a loader that
241
- * has never been loaded answers with an *empty* set. Skipping this leaves a replacement session
242
- * with no extensions at all — no command extension (so `/model`, `/thinking`, `/session`,
243
- * `/compact` and `/memory` fall through to the model as plain text), no memory lifecycle, no
244
- * prompt-boundary footer, and no prompt templates. Tolerated on failure the same way
245
- * `reloadSessionResources` tolerates a stuck reload: a degraded session still answers chat.
246
- */
247
- private loadSessionResources;
248
- /**
249
- * Resolve the initial thinking level using the same precedence as pi's SDK:
250
- * session history, configured default, then medium. The effective value is
251
- * clamped to the selected model before the session starts.
252
- */
253
- private initializeThinkingLevel;
254
- private createSessionRuntime;
255
- /**
256
- * Bind this runner to a task cycle's own session (spec 051, D3/INV-5).
257
- *
258
- * Task work must not accumulate in the channel's chat transcript: the one real channel on the
259
- * author's machine had grown to 7.4 MB and been compacted six times because chat and two daily
260
- * tasks shared it, so every compaction damaged all three at once. Swapping the bound session
261
- * per turn gives each task its own bounded context while leaving turn state, `/stop`, and
262
- * delivery exactly where they already are.
90
+ * Bind this runner to a task cycle's own session (spec 051, D3/INV-5): task work must not
91
+ * accumulate in the channel's chat transcript, so each task turn runs in its own bounded session
92
+ * while turn state, `/stop` and delivery stay exactly where they already are.
263
93
  */
264
94
  bindTaskSession(taskId: string): Promise<void>;
265
95
  /** Return to the channel's chat session after a task step. Safe to call when already bound. */
266
96
  bindChatSession(): Promise<void>;
267
- /**
268
- * Re-derive "does this session still owe a memory bootstrap" from the session now bound.
269
- *
270
- * The pending flag used to be set to `true` on every bind, which is right for a fresh task
271
- * session and wrong for the return trip: a chat session that already carries the block would
272
- * be handed a second copy on its next turn, and one interleaved task step could therefore cost
273
- * the whole index again. It was also wrong across a restart, where the field simply starts
274
- * `true` and the resumed session's own history says otherwise.
275
- *
276
- * So the answer comes from the transcript that will actually be sent, not from a boolean that
277
- * has to be kept in step with every binding. The `/new` and post-compaction resets in
278
- * `subscribeToSessionEvents` stay as they are: those are the SDK telling us the context
279
- * generation changed, which is a fact about the session that its message list alone —
280
- * compaction having rewritten it into a summary — cannot be scanned for reliably.
281
- */
282
- private syncMemoryBootstrapPendingFromSession;
283
97
  /** Which task loop this runner is currently bound to, if any. */
284
98
  getTaskLoop(): {
285
99
  taskId: string;
286
100
  } | undefined;
287
- private buildRuntimeTools;
288
- private rebuildSessionTools;
289
- private subscribeToSessionEvents;
290
- /** Gated by the same master autonomy switch as the task_* tools and the TaskDriver. */
291
- private buildTaskDigestForTurn;
292
101
  /**
293
- * Spec 050, D1: assemble `<memory_bootstrap>` for the first turn of a session — workspace
294
- * MEMORY.md (whole H2 sections, budgeted) + the channel index (full, or budget-tiered) +
295
- * today's journal tail.
102
+ * Buffer one activity event. The write itself is batched by the recorder (see
103
+ * `createMemoryActivityRecorder`); `run()` flushes at the end of every turn, which is the
104
+ * point the maintenance gates actually start looking at this state.
296
105
  */
297
- private buildFirstTurnMemoryBootstrap;
106
+ private recordMemoryActivity;
107
+ /** Best-effort: a lost activity counter delays maintenance, it never breaks a turn. */
108
+ private flushMemoryActivity;
109
+ private resetRunState;
298
110
  }