@oyasmi/pipiclaw 0.8.0 → 0.8.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 (106) hide show
  1. package/README.md +115 -510
  2. package/dist/agent/channel-runner.d.ts +11 -6
  3. package/dist/agent/channel-runner.js +44 -24
  4. package/dist/agent/command-extension.js +5 -4
  5. package/dist/agent/commands.d.ts +50 -0
  6. package/dist/agent/commands.js +176 -67
  7. package/dist/agent/job-manager.d.ts +5 -5
  8. package/dist/agent/prompt-builder.d.ts +3 -13
  9. package/dist/agent/prompt-builder.js +44 -204
  10. package/dist/agent/run-queue.d.ts +1 -2
  11. package/dist/agent/run-queue.js +3 -5
  12. package/dist/agent/runner-factory.d.ts +1 -2
  13. package/dist/agent/runner-factory.js +2 -2
  14. package/dist/agent/status-render.d.ts +0 -7
  15. package/dist/agent/status-render.js +8 -3
  16. package/dist/agent/types.d.ts +4 -3
  17. package/dist/agent/workspace-resources.d.ts +1 -1
  18. package/dist/agent/workspace-resources.js +3 -15
  19. package/dist/executor.d.ts +20 -0
  20. package/dist/{sandbox.js → executor.js} +3 -95
  21. package/dist/index.d.ts +1 -1
  22. package/dist/index.js +1 -1
  23. package/dist/log.d.ts +1 -3
  24. package/dist/log.js +1 -20
  25. package/dist/main.js +14 -4
  26. package/dist/memory/files.js +0 -0
  27. package/dist/memory/lifecycle.js +6 -5
  28. package/dist/memory/maintenance-jobs.d.ts +0 -1
  29. package/dist/memory/maintenance-jobs.js +2 -2
  30. package/dist/memory/maintenance-state.js +2 -1
  31. package/dist/memory/post-turn-review.d.ts +0 -1
  32. package/dist/memory/post-turn-review.js +4 -4
  33. package/dist/memory/scheduler.d.ts +0 -1
  34. package/dist/memory/scheduler.js +2 -2
  35. package/dist/memory/session.js +2 -2
  36. package/dist/paths.d.ts +2 -0
  37. package/dist/paths.js +11 -0
  38. package/dist/playbooks/event-scheduling.md +43 -0
  39. package/dist/playbooks/memory-and-learning.md +45 -0
  40. package/dist/playbooks/runtime-orientation.md +48 -0
  41. package/dist/playbooks/task-closeout.md +45 -0
  42. package/dist/playbooks/task-delegation.md +44 -0
  43. package/dist/playbooks/task-driving.md +43 -0
  44. package/dist/playbooks/task-planning.md +47 -0
  45. package/dist/playbooks/task-recurring.md +42 -0
  46. package/dist/playbooks/task-repair.md +43 -0
  47. package/dist/runtime/bootstrap.d.ts +7 -11
  48. package/dist/runtime/bootstrap.js +50 -57
  49. package/dist/runtime/delivery.js +4 -3
  50. package/dist/runtime/dingtalk.js +50 -57
  51. package/dist/runtime/durable-dispatch.d.ts +2 -0
  52. package/dist/runtime/durable-dispatch.js +29 -1
  53. package/dist/runtime/event-commands.js +4 -4
  54. package/dist/runtime/events.d.ts +1 -1
  55. package/dist/runtime/events.js +5 -5
  56. package/dist/runtime/task-commands.js +9 -4
  57. package/dist/runtime/task-driver.js +12 -14
  58. package/dist/security/config.js +2 -1
  59. package/dist/security/network.js +9 -2
  60. package/dist/security/path-guard.js +12 -24
  61. package/dist/security/types.d.ts +0 -1
  62. package/dist/shared/jsonl-appender.js +2 -1
  63. package/dist/shared/task-ledger.d.ts +9 -1
  64. package/dist/shared/task-ledger.js +28 -14
  65. package/dist/shared/text-utils.d.ts +1 -0
  66. package/dist/shared/text-utils.js +3 -0
  67. package/dist/subagents/discovery.js +3 -2
  68. package/dist/subagents/tool.d.ts +2 -3
  69. package/dist/subagents/tool.js +9 -24
  70. package/dist/tasks/control.js +2 -1
  71. package/dist/tasks/verification.js +2 -1
  72. package/dist/tools/bash.d.ts +1 -1
  73. package/dist/tools/bash.js +3 -5
  74. package/dist/tools/command-optimizer.d.ts +1 -1
  75. package/dist/tools/command-optimizer.js +4 -6
  76. package/dist/tools/config.js +4 -3
  77. package/dist/tools/edit.d.ts +1 -1
  78. package/dist/tools/edit.js +0 -0
  79. package/dist/tools/event-manage.d.ts +0 -1
  80. package/dist/tools/event-manage.js +9 -14
  81. package/dist/tools/grep.d.ts +1 -1
  82. package/dist/tools/grep.js +4 -6
  83. package/dist/tools/index.d.ts +1 -3
  84. package/dist/tools/index.js +1 -4
  85. package/dist/tools/read.d.ts +1 -1
  86. package/dist/tools/read.js +1 -2
  87. package/dist/tools/registry.d.ts +1 -2
  88. package/dist/tools/registry.js +3 -10
  89. package/dist/tools/skill-manage.d.ts +0 -1
  90. package/dist/tools/skill-manage.js +7 -14
  91. package/dist/tools/task-manage.d.ts +0 -1
  92. package/dist/tools/task-manage.js +18 -16
  93. package/dist/tools/write-content.d.ts +1 -1
  94. package/dist/tools/write-content.js +0 -1
  95. package/dist/tools/write.d.ts +1 -1
  96. package/dist/tui/app.d.ts +0 -2
  97. package/dist/tui/app.js +12 -7
  98. package/dist/tui/cli.d.ts +3 -2
  99. package/dist/tui/cli.js +12 -24
  100. package/dist/tui/commands.d.ts +4 -1
  101. package/dist/tui/commands.js +10 -14
  102. package/dist/tui/turn-controller.d.ts +7 -3
  103. package/dist/tui/turn-controller.js +18 -6
  104. package/dist/web/client.js +2 -1
  105. package/package.json +2 -2
  106. package/dist/sandbox.d.ts +0 -42
@@ -0,0 +1,47 @@
1
+ ---
2
+ name: task-planning
3
+ description: Read before creating or restructuring a persistent task, choosing task versus event, writing Goal/DoD/Manual/Verification, or setting control metadata and budgets.
4
+ ---
5
+
6
+ # 长程任务规划与建档
7
+
8
+ ## 什么时候创建 task
9
+
10
+ 只有工作需要跨回合恢复时才建:多步骤目标、等待人或外部系统、委派工作、周期性产出。当前回合能完成的简单请求不要建台账;纯提醒用 event。
11
+
12
+ ## 创建内容
13
+
14
+ 调用 `task_manage create`:
15
+
16
+ - `id`:稳定的 kebab-case。
17
+ - `title`:一句话标题。
18
+ - `goal`:最终要成立的结果,不写行动清单。
19
+ - `dod`:客观验收标准,每项必须是 `- [ ]` checkbox;纯 prose/编号列表会被拒。
20
+ - `manual`:可复用的执行步骤、预检与返工教训。
21
+ - `verificationPlan`:验收者能独立执行的确定性检查。
22
+
23
+ 默认 independent verification 和有限 attempt budget。轻量记录性任务确实无需独立验收时,创建时设 `control.verificationMode: evidence`。
24
+
25
+ ## control 决策
26
+
27
+ - `priority` / `deadline`:表达调度重要性和硬期限,不用 wake 冒充 deadline。
28
+ - `nextAction`:下一条可执行动作,避免写抽象愿望。
29
+ - `maxAttempts` / `maxTokens` / `maxCostUsd` / `maxWallTimeMinutes`:按风险和规模收紧;预算是停止条件,不是目标。
30
+ - `sideEffects`:`read-only`、`workspace` 或 `external`。发送、发布、部署、修改外部系统必须选 external。若同时使用 independent verification,DoD/Verification 要验收“待执行动作及其输入已准备正确”,不要把尚未获批的外部动作本身写成 candidate 前必须勾选的项;实际执行结果由 approval gate 和 done evidence 收口。
31
+ - `isolation: worktree`:写密集型子任务需要隔离共享 checkout 时使用。
32
+ - `parent` / `dependsOn`:只用于真实分解;parent 表归属,dependsOn 表执行前置。
33
+
34
+ 创建和 set 会拒绝不存在的关联、自指、parent 环和 dependency 环。父任务可以 dependsOn 自己的 child,表达 join;父任务有未闭环 child 时不能 done。
35
+
36
+ ## 状态与时间
37
+
38
+ - `open` / `in-progress`:可推进。
39
+ - `awaiting-user`:需要用户输入或批准。
40
+ - `blocked`:等待外部条件或委派结果。
41
+ - `paused`:明确暂停,driver 不运行。
42
+ - `verifying`:只做独立验收,不继续实现。
43
+ - `escalated`:治理器停止任务,先诊断再修 control。
44
+
45
+ `wake` 是最早重新检查时间,不代表截止时间。等待时设置现实的 wake;可继续时清空 wake,让 driver 按 cooldown 接续。
46
+
47
+ 创建后读取落盘文件确认 Goal、DoD、Manual、Verification 和 control 与真实意图一致。后续每个驱动回合按 `task-driving.md` 推进。
@@ -0,0 +1,42 @@
1
+ ---
2
+ name: task-recurring
3
+ description: Read before creating, starting, rescheduling, pausing, completing a cycle of, or retiring a recurring task and its canonical schedule event.
4
+ ---
5
+
6
+ # 周期性任务
7
+
8
+ 一个周期任务由两份真相组成:
9
+
10
+ - `tasks/<id>.md`:目标、DoD、Manual、验收与跨周期经验。
11
+ - `task.<channelId>.<id>.schedule`:唯一 canonical periodic cadence。
12
+
13
+ 节奏在 event,做法在 task。`recurrence` 只是可读标注。
14
+
15
+ ## 创建
16
+
17
+ 先按 `task-planning.md` 创建 task,必须填写 recurrence;再用 `event_manage create` 建 `.schedule`:
18
+
19
+ ```json
20
+ {"type":"periodic","channelId":"<当前channel>","text":"推进任务 weekly-report:读取任务文件,必要时 start-cycle","schedule":"30 9 * * 1","timezone":"Asia/Shanghai"}
21
+ ```
22
+
23
+ 纯提醒没有产出和验收,不建 task,使用普通 periodic event。
24
+
25
+ ## 周期运行
26
+
27
+ done 的周期任务留在原地睡眠,driver 不唤醒;只有 `.schedule` 开启新周期。
28
+
29
+ - 上周期 done:调用 `task_manage start-cycle`,给稳定 cycleId。它原子折叠上一周期日志、清空本周期用量/验收/授权/worktree 元数据并置 in-progress。
30
+ - 上周期未完成:不要覆盖或虚勾 DoD。先完成、如实缩小本轮范围并验收,或与用户确认后 cancel 整项任务。
31
+
32
+ 周期内继续、等待和恢复只使用 task wake,不建 `.checkin`。
33
+
34
+ ## 复盘、调整和退役
35
+
36
+ 每轮闭环前把返工原因、预检步骤和格式偏好写回 Manual;跨任务才沉淀 workspace skill。
37
+
38
+ - 改节奏:整体 update `.schedule`,并用 task_manage set 同步 recurrence 标注。
39
+ - 暂停:pause task;若要完全安静也删除 schedule,恢复时重建。
40
+ - 退役:`task_manage cancel`,它归档任务并删除全部 task-owned events,包括 schedule。
41
+
42
+ 不要手工改 status 开周期,也不要只删 schedule 留下永远不会再开始的活任务。
@@ -0,0 +1,43 @@
1
+ ---
2
+ name: task-repair
3
+ description: Read when a task is escalated, repeatedly stalled, not waking, has broken frontmatter/control, stale approval or verification, terminal dependencies, orphan events, or restart recovery issues.
4
+ ---
5
+
6
+ # 任务诊断与修复
7
+
8
+ 先用 `task_manage list` 看结构化状态;让用户用 `/tasks doctor` 看带 Next step 的一致性检查,用 `/tasks stats <id>` 看 attempts/token/cost/wall time、最近结果和 verifier 状态。
9
+
10
+ ## escalated
11
+
12
+ driver 在 deadline、累计预算耗尽或 terminal dependency 时停止任务。先读 Current Cycle 和 stats,判断空转、范围错误、预算过小还是依赖终止。
13
+
14
+ - 方向错:修 Manual/nextAction、重新拆解或 cancel。
15
+ - 预算确实不足:向用户说明后用 `task_manage set` 调整 budget/deadline,并把 status 设回 in-progress。
16
+ - 依赖终止:恢复/重建依赖,或 set 更新 dependsOn。
17
+
18
+ escalated 不能 progress/candidate;set 是审查原因后的修复入口,不要反射性加预算。
19
+
20
+ ## 不唤醒或频繁唤醒
21
+
22
+ 可推进 = 非 done/cancelled/escalated/paused,且 wake 缺失、无效或已到期。
23
+
24
+ - paused:用户 `/tasks resume <id>`。
25
+ - wake 太远:纠正 wake;急催用 `/tasks run <id>`。
26
+ - TUI 已关闭:没有 daemon,不能自动唤醒。
27
+ - 反复空转:查最新 note/nextAction,修 Manual;不要伪造 progress 换短 cooldown。
28
+
29
+ ## 坏 frontmatter/control
30
+
31
+ frontmatter 只认开头 `---` 块中的 status/wake/recurrence/control;control 必须是单行 JSON。driver 对不可读 frontmatter fail-open 以便唤醒修复,task_manage 对坏 control fail-closed 防止覆盖。
32
+
33
+ 先 read,只有此场景才用 edit 修合法 frontmatter;随后用 task_manage set 让后续更新回到工具轨道。control 不确定时删除坏行,再用 set 重建默认结构。
34
+
35
+ ## stale gate
36
+
37
+ PASS 和 external approval 都绑定 task body;PASS 还可能绑定 Git artifact subject。progress、正文编辑或产物变化后 done 会拒绝:重跑 verifier或请用户重新 approve,不绕过。组合流程见 `task-closeout.md`。
38
+
39
+ ## 事件与重启
40
+
41
+ done/cancel 会清理 `task.<channelId>.<id>.*`;孤儿事件用 event_manage 删除。recurring task 没有 canonical `.schedule` 则补建。旧 `.checkin` 是 legacy,删除并以 wake 为单一恢复条件。
42
+
43
+ task 文件是恢复真相。daemon 重启会清空内存 cooldown,可推进任务可能很快重放;durable dispatch 租约也提供至少一次派发。每次先核对已完成产物,避免重复外部动作。
@@ -1,4 +1,4 @@
1
- import { type Executor, type SandboxConfig } from "../sandbox.js";
1
+ import { type Executor } from "../executor.js";
2
2
  import { PipiclawSettingsManager } from "../settings.js";
3
3
  import { DingTalkBot, type DingTalkConfig, type DingTalkHandler } from "./dingtalk.js";
4
4
  import { ChannelStore } from "./store.js";
@@ -25,9 +25,6 @@ export interface BootstrapOptions {
25
25
  registerSignalHandlers?: boolean;
26
26
  startServices?: boolean;
27
27
  }
28
- export interface ParsedArgs {
29
- sandbox: SandboxConfig;
30
- }
31
28
  export interface BootstrapResult {
32
29
  created: string[];
33
30
  channelTemplateCreated: boolean;
@@ -52,10 +49,9 @@ export declare function readCliVersion(): string;
52
49
  export declare function bootstrapAppHome(paths?: BootstrapPaths): BootstrapResult;
53
50
  export declare function printBootstrapSummary(result: BootstrapResult, io?: BootstrapIO, paths?: BootstrapPaths): void;
54
51
  export declare function loadConfig(paths?: BootstrapPaths, io?: BootstrapIO): DingTalkConfig;
55
- export declare function parseArgs(argv: string[], paths?: BootstrapPaths, io?: BootstrapIO): ParsedArgs;
52
+ export declare function parseArgs(argv: string[], paths?: BootstrapPaths, io?: BootstrapIO): void;
56
53
  interface RuntimeContextOptions {
57
54
  paths: BootstrapPaths;
58
- sandbox: SandboxConfig;
59
55
  dingtalkConfig: DingTalkConfig;
60
56
  createBot?: (handler: DingTalkHandler, config: DingTalkConfig) => DingTalkBot;
61
57
  createEventsWatcher?: (workspaceDir: string, bot: DingTalkBot, executor: Executor, eventHistoryPath: string) => {
@@ -80,9 +76,9 @@ export declare function createRuntimeContext(options: RuntimeContextOptions): Ru
80
76
  };
81
77
  /**
82
78
  * Transport-neutral app services shared by the DingTalk runtime and the terminal
83
- * TUI: loads settings (surfacing load errors), reports tool/security config
84
- * diagnostics, and validates the sandbox. Does NOT touch DingTalk config, so the
85
- * TUI can call it without any DingTalk credentials.
79
+ * TUI: loads settings (surfacing load errors) and reports tool/security config
80
+ * diagnostics. Does NOT touch DingTalk config, so the TUI can call it without any
81
+ * DingTalk credentials.
86
82
  *
87
83
  * Extracted verbatim from `bootstrap()`; the DingTalk path calls it in the same
88
84
  * position (after `loadConfig`, before `logStartup`) so its behavior is
@@ -90,8 +86,8 @@ export declare function createRuntimeContext(options: RuntimeContextOptions): Ru
90
86
  * (DingTalk: `createRuntimeContext`; TUI: right after this) to preserve the
91
87
  * existing "diagnostics logged with default logging config" ordering.
92
88
  */
93
- export declare function prepareAppServices(sandbox: SandboxConfig, paths?: BootstrapPaths, io?: BootstrapIO): Promise<{
89
+ export declare function prepareAppServices(paths?: BootstrapPaths): {
94
90
  settingsManager: PipiclawSettingsManager;
95
- }>;
91
+ };
96
92
  export declare function bootstrap(argv: string[], options?: BootstrapOptions): Promise<AppContext>;
97
93
  export {};
@@ -1,18 +1,19 @@
1
1
  import { chmodSync, existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "fs";
2
2
  import { join } from "path";
3
- import { parseBuiltInCommand } from "../agent/commands.js";
3
+ import { formatUnknownCommandMessage, isRunnerBuiltInCommand, parseBuiltInCommand, slashCommandName, } from "../agent/commands.js";
4
4
  import { getOrCreateRunner } from "../agent/index.js";
5
5
  import { resetRunner } from "../agent/runner-factory.js";
6
6
  import { renderStatus } from "../agent/status-render.js";
7
+ import { createExecutor } from "../executor.js";
7
8
  import * as log from "../log.js";
8
9
  import { ensureChannelMemoryFilesSync } from "../memory/files.js";
9
10
  import { MemoryMaintenanceScheduler } from "../memory/scheduler.js";
10
11
  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 { createExecutor, parseSandboxArg, SandboxConfigError, validateSandbox, } from "../sandbox.js";
12
12
  import { loadSecurityConfigWithDiagnostics } from "../security/config.js";
13
13
  import { PipiclawSettingsManager } from "../settings.js";
14
14
  import { formatConfigDiagnostic } from "../shared/config-diagnostics.js";
15
15
  import { readActiveTasks } from "../shared/task-ledger.js";
16
+ import { errorMessage } from "../shared/text-utils.js";
16
17
  import { finishTaskAttempt } from "../tasks/store.js";
17
18
  import { loadToolsConfigWithDiagnostics } from "../tools/config.js";
18
19
  import { getUsageLedger } from "../usage/ledger.js";
@@ -210,7 +211,7 @@ function hardenExistingSecretFile(path) {
210
211
  }
211
212
  }
212
213
  catch (err) {
213
- log.logWarning(`Failed to tighten permissions on ${path}`, err instanceof Error ? err.message : String(err));
214
+ log.logWarning(`Failed to tighten permissions on ${path}`, errorMessage(err));
214
215
  }
215
216
  }
216
217
  export function bootstrapAppHome(paths = DEFAULT_BOOTSTRAP_PATHS) {
@@ -311,7 +312,7 @@ export function loadConfig(paths = DEFAULT_BOOTSTRAP_PATHS, io = console) {
311
312
  }
312
313
  catch (err) {
313
314
  io.error(`Failed to parse configuration: ${paths.channelConfigPath}`);
314
- io.error(err instanceof Error ? err.message : String(err));
315
+ io.error(errorMessage(err));
315
316
  throw new BootstrapExitError(1);
316
317
  }
317
318
  const issues = listChannelConfigIssues(parsed);
@@ -336,35 +337,22 @@ export function loadConfig(paths = DEFAULT_BOOTSTRAP_PATHS, io = console) {
336
337
  }
337
338
  export function parseArgs(argv, paths = DEFAULT_BOOTSTRAP_PATHS, io = console) {
338
339
  const args = argv.slice(2);
339
- let sandbox = { type: "host" };
340
- const parseSandboxOrExit = (value) => {
341
- try {
342
- return parseSandboxArg(value);
343
- }
344
- catch (err) {
345
- if (err instanceof SandboxConfigError) {
346
- io.error(`Error: ${err.message}`);
347
- throw new BootstrapExitError(1);
348
- }
349
- throw err;
350
- }
351
- };
352
340
  for (let index = 0; index < args.length; index += 1) {
353
341
  const arg = args[index];
354
- if (arg.startsWith("--sandbox=")) {
355
- sandbox = parseSandboxOrExit(arg.slice("--sandbox=".length));
356
- }
357
- else if (arg === "--sandbox") {
358
- sandbox = parseSandboxOrExit(args[index + 1] || "");
359
- index += 1;
342
+ if (index === 0 && arg === "run") {
343
+ // Explicit name for the default daemon mode (`pipiclaw run` == `pipiclaw`).
344
+ continue;
360
345
  }
361
- else if (arg === "--help" || arg === "-h") {
362
- io.log(`Usage: ${paths.appName} [options]`);
346
+ if (arg === "--help" || arg === "-h") {
347
+ io.log(`Usage: ${paths.appName} [command] [options]`);
348
+ io.log("");
349
+ io.log("Commands:");
350
+ io.log(" run Run the long-lived DingTalk daemon (default)");
351
+ io.log(" tui [prompt] Chat with the agent in the terminal");
363
352
  io.log("");
364
353
  io.log("Options:");
365
- io.log(" --sandbox=host Run tools on host (default)");
366
- io.log(" --sandbox=docker:<name> Run tools in Docker container");
367
354
  io.log(" --version Print the current version and exit");
355
+ io.log(" --help, -h Show this help and exit");
368
356
  io.log("");
369
357
  io.log(`Config: ${paths.channelConfigPath}`);
370
358
  io.log(`Workspace: ${paths.workspaceDir}`);
@@ -374,8 +362,12 @@ export function parseArgs(argv, paths = DEFAULT_BOOTSTRAP_PATHS, io = console) {
374
362
  io.log(readCliVersion());
375
363
  throw new BootstrapExitError(0);
376
364
  }
365
+ else {
366
+ io.error(`Unknown option: ${arg}`);
367
+ io.error(`Run \`${paths.appName} --help\` for usage.`);
368
+ throw new BootstrapExitError(1);
369
+ }
377
370
  }
378
- return { sandbox };
379
371
  }
380
372
  function waitForTasks(tasks, timeoutMs) {
381
373
  if (tasks.length === 0) {
@@ -395,7 +387,7 @@ function flushInactiveChannelMemory(channelStates) {
395
387
  continue;
396
388
  }
397
389
  flushes.push(state.runner.flushMemoryForShutdown().catch((err) => {
398
- log.logWarning(`[${channelId}] Failed to flush memory during shutdown`, err instanceof Error ? err.message : String(err));
390
+ log.logWarning(`[${channelId}] Failed to flush memory during shutdown`, errorMessage(err));
399
391
  }));
400
392
  }
401
393
  return flushes;
@@ -421,7 +413,7 @@ export function createRuntimeContext(options) {
421
413
  await store.logMessage(channelId, message);
422
414
  }
423
415
  catch (err) {
424
- log.logWarning(`[${channelId}] Failed to archive ${contextLabel}`, err instanceof Error ? err.message : String(err));
416
+ log.logWarning(`[${channelId}] Failed to archive ${contextLabel}`, errorMessage(err));
425
417
  }
426
418
  };
427
419
  const getState = (channelId) => {
@@ -431,7 +423,7 @@ export function createRuntimeContext(options) {
431
423
  ensureChannelMemoryFilesSync(channelDir);
432
424
  state = {
433
425
  running: false,
434
- runner: getOrCreateRunner(options.sandbox, channelId, channelDir, {
426
+ runner: getOrCreateRunner(channelId, channelDir, {
435
427
  appHomeDir: options.paths.appHomeDir,
436
428
  authConfigPath: options.paths.authConfigPath,
437
429
  modelsConfigPath: options.paths.modelsConfigPath,
@@ -467,8 +459,12 @@ export function createRuntimeContext(options) {
467
459
  if (dropped > 0) {
468
460
  log.logInfo(`[${channelId}] Dropped ${dropped} queued message(s) on stop`);
469
461
  }
462
+ const canceled = await durableDispatch?.cancelChannel(channelId);
463
+ if (canceled) {
464
+ log.logInfo(`[${channelId}] Reset ${canceled} durable-dispatch lease(s) on stop`);
465
+ }
470
466
  void state.runner.abort().catch((err) => {
471
- log.logWarning(`[${channelId}] Failed to abort run`, err instanceof Error ? err.message : String(err));
467
+ log.logWarning(`[${channelId}] Failed to abort run`, errorMessage(err));
472
468
  });
473
469
  log.logInfo(`[${channelId}] Stop requested`);
474
470
  }
@@ -503,7 +499,6 @@ export function createRuntimeContext(options) {
503
499
  state: channelStates.get(event.channelId),
504
500
  version: cliVersion,
505
501
  uptimeMs: Date.now() - startedAt,
506
- sandbox: options.sandbox,
507
502
  });
508
503
  await bot.sendPlain(event.channelId, response);
509
504
  },
@@ -546,7 +541,7 @@ export function createRuntimeContext(options) {
546
541
  return { kind: "handled" };
547
542
  }
548
543
  catch (err) {
549
- const errMsg = err instanceof Error ? err.message : String(err);
544
+ const errMsg = errorMessage(err);
550
545
  if (isNoRunningTaskQueueError(err)) {
551
546
  log.logInfo(`[${event.channelId}] Busy ${mode} window closed; requeueing as a normal message`);
552
547
  return { kind: "requeue", text: trimmedQueueText };
@@ -600,7 +595,17 @@ export function createRuntimeContext(options) {
600
595
  await handler.handleUsageCommand(event, bot, builtInCommand.args);
601
596
  return;
602
597
  }
603
- await state.runner.handleBuiltinCommand(ctx, builtInCommand);
598
+ if (isRunnerBuiltInCommand(builtInCommand)) {
599
+ await state.runner.handleBuiltinCommand(ctx, builtInCommand);
600
+ }
601
+ return;
602
+ }
603
+ // Reject an unknown slash command instead of spending a full LLM turn
604
+ // letting the model guess what `/modle` meant. Session commands,
605
+ // skills, and prompt templates are recognized by isKnownSlashCommand.
606
+ if (event.text.trim().startsWith("/") && !state.runner.isKnownSlashCommand(event.text)) {
607
+ const name = slashCommandName(event.text) ?? "";
608
+ await bot.sendPlain(event.channelId, formatUnknownCommandMessage(name));
604
609
  return;
605
610
  }
606
611
  log.logInfo(`[${event.channelId}] Starting run: ${event.text.substring(0, 50)}`);
@@ -624,7 +629,7 @@ export function createRuntimeContext(options) {
624
629
  }
625
630
  }
626
631
  catch (err) {
627
- log.logWarning(`[${event.channelId}] Run error`, err instanceof Error ? err.message : String(err));
632
+ log.logWarning(`[${event.channelId}] Run error`, errorMessage(err));
628
633
  }
629
634
  finally {
630
635
  await durableDispatch?.markCompleted(event.dispatchId);
@@ -648,7 +653,7 @@ export function createRuntimeContext(options) {
648
653
  stateDir: join(options.paths.appHomeDir, "state", "dispatch"),
649
654
  bot,
650
655
  });
651
- const executor = createExecutor(options.sandbox);
656
+ const executor = createExecutor();
652
657
  const eventsWatcher = options.createEventsWatcher
653
658
  ? options.createEventsWatcher(options.paths.workspaceDir, bot, executor, options.paths.eventHistoryPath)
654
659
  : createEventsWatcher(options.paths.workspaceDir, bot, executor, loadSecurityConfigWithDiagnostics(options.paths.appHomeDir).config.commandGuard, options.paths.eventHistoryPath, (event) => durableDispatch?.dispatch(event) ?? false);
@@ -709,7 +714,7 @@ export function createRuntimeContext(options) {
709
714
  state.stopRequested = true;
710
715
  log.logInfo(`[${channelId}] Aborting active run for shutdown`);
711
716
  aborts.push(state.runner.abort().catch((err) => {
712
- log.logWarning(`[${channelId}] Failed to abort run during shutdown`, err instanceof Error ? err.message : String(err));
717
+ log.logWarning(`[${channelId}] Failed to abort run during shutdown`, errorMessage(err));
713
718
  }));
714
719
  }
715
720
  await Promise.allSettled(aborts);
@@ -769,9 +774,9 @@ export function createRuntimeContext(options) {
769
774
  }
770
775
  /**
771
776
  * Transport-neutral app services shared by the DingTalk runtime and the terminal
772
- * TUI: loads settings (surfacing load errors), reports tool/security config
773
- * diagnostics, and validates the sandbox. Does NOT touch DingTalk config, so the
774
- * TUI can call it without any DingTalk credentials.
777
+ * TUI: loads settings (surfacing load errors) and reports tool/security config
778
+ * diagnostics. Does NOT touch DingTalk config, so the TUI can call it without any
779
+ * DingTalk credentials.
775
780
  *
776
781
  * Extracted verbatim from `bootstrap()`; the DingTalk path calls it in the same
777
782
  * position (after `loadConfig`, before `logStartup`) so its behavior is
@@ -779,7 +784,7 @@ export function createRuntimeContext(options) {
779
784
  * (DingTalk: `createRuntimeContext`; TUI: right after this) to preserve the
780
785
  * existing "diagnostics logged with default logging config" ordering.
781
786
  */
782
- export async function prepareAppServices(sandbox, paths = DEFAULT_BOOTSTRAP_PATHS, io = console) {
787
+ export function prepareAppServices(paths = DEFAULT_BOOTSTRAP_PATHS) {
783
788
  const settingsManager = new PipiclawSettingsManager(paths.appHomeDir);
784
789
  for (const { scope, error } of settingsManager.drainErrors()) {
785
790
  log.logWarning(`Failed to load ${scope} settings`, `${error.message}\n${paths.settingsConfigPath}`);
@@ -790,16 +795,6 @@ export async function prepareAppServices(sandbox, paths = DEFAULT_BOOTSTRAP_PATH
790
795
  for (const diagnostic of loadSecurityConfigWithDiagnostics(paths.appHomeDir).diagnostics) {
791
796
  log.logWarning(formatConfigDiagnostic(diagnostic), diagnostic.path);
792
797
  }
793
- try {
794
- await validateSandbox(sandbox);
795
- }
796
- catch (err) {
797
- if (err instanceof SandboxConfigError) {
798
- io.error(`Error: ${err.message}`);
799
- throw new BootstrapExitError(1);
800
- }
801
- throw err;
802
- }
803
798
  return { settingsManager };
804
799
  }
805
800
  export async function bootstrap(argv, options = {}) {
@@ -807,8 +802,7 @@ export async function bootstrap(argv, options = {}) {
807
802
  const paths = options.paths ?? DEFAULT_BOOTSTRAP_PATHS;
808
803
  const registerSignalHandlers = options.registerSignalHandlers ?? true;
809
804
  const startServices = options.startServices ?? true;
810
- const parsedArgs = parseArgs(argv, paths, io);
811
- const sandbox = parsedArgs.sandbox;
805
+ parseArgs(argv, paths, io);
812
806
  const bootstrapResult = bootstrapAppHome(paths);
813
807
  printBootstrapSummary(bootstrapResult, io, paths);
814
808
  if (bootstrapResult.channelTemplateCreated) {
@@ -817,11 +811,10 @@ export async function bootstrap(argv, options = {}) {
817
811
  }
818
812
  const dingtalkConfig = loadConfig(paths, io);
819
813
  dingtalkConfig.stateDir = paths.workspaceDir;
820
- await prepareAppServices(sandbox, paths, io);
821
- log.logStartup(paths.workspaceDir, sandbox.type === "host" ? "host" : `docker:${sandbox.container}`);
814
+ prepareAppServices(paths);
815
+ log.logStartup(paths.workspaceDir);
822
816
  const runtime = createRuntimeContext({
823
817
  paths,
824
- sandbox,
825
818
  dingtalkConfig,
826
819
  registerSignalHandlers,
827
820
  startServices,
@@ -1,4 +1,5 @@
1
1
  import * as log from "../log.js";
2
+ import { errorMessage } from "../shared/text-utils.js";
2
3
  const MIN_UPDATE_INTERVAL_MS = 800;
3
4
  const ROLLING_WINDOW_SIZE = 3;
4
5
  const NO_CONTENT = "";
@@ -86,7 +87,7 @@ class ChannelDeliveryController {
86
87
  await this.bot.ensureCard(this.event.channelId);
87
88
  }
88
89
  catch (err) {
89
- log.logWarning(`[${this.event.channelId}] Failed to warm AI card`, err instanceof Error ? err.message : String(err));
90
+ log.logWarning(`[${this.event.channelId}] Failed to warm AI card`, errorMessage(err));
90
91
  this.bot.discardCard(this.event.channelId);
91
92
  }
92
93
  }
@@ -99,7 +100,7 @@ class ChannelDeliveryController {
99
100
  }
100
101
  archiveBotResponse(text) {
101
102
  void this.store.logBotResponse(this.event.channelId, text, Date.now().toString()).catch((err) => {
102
- log.logWarning(`[${this.event.channelId}] Failed to archive bot response`, err instanceof Error ? err.message : String(err));
103
+ log.logWarning(`[${this.event.channelId}] Failed to archive bot response`, errorMessage(err));
103
104
  });
104
105
  }
105
106
  async appendProgress(text, shouldLog) {
@@ -272,7 +273,7 @@ class ChannelDeliveryController {
272
273
  }
273
274
  }
274
275
  catch (err) {
275
- log.logWarning(`[${this.event.channelId}] Delivery sync failed`, err instanceof Error ? err.message : String(err));
276
+ log.logWarning(`[${this.event.channelId}] Delivery sync failed`, errorMessage(err));
276
277
  this.bot.discardCard(this.event.channelId);
277
278
  if (mode === "progress") {
278
279
  this.replayRequired = true;