@oyasmi/pipiclaw 0.9.2-beta.3 → 0.9.2-beta.6

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 (142) hide show
  1. package/README.md +3 -0
  2. package/dist/agent/channel-runner.d.ts +45 -19
  3. package/dist/agent/channel-runner.js +156 -102
  4. package/dist/agent/command-extension.js +1 -1
  5. package/dist/agent/context-budget.d.ts +17 -1
  6. package/dist/agent/context-budget.js +20 -6
  7. package/dist/agent/job-manager.d.ts +3 -1
  8. package/dist/agent/job-manager.js +7 -1
  9. package/dist/agent/prompt/builder.d.ts +0 -1
  10. package/dist/agent/prompt/builder.js +1 -14
  11. package/dist/agent/prompt/manifest.js +2 -1
  12. package/dist/agent/prompt/sections.js +1 -1
  13. package/dist/agent/runner-factory.d.ts +19 -1
  14. package/dist/agent/runner-factory.js +8 -1
  15. package/dist/agent/session-events.d.ts +2 -2
  16. package/dist/agent/session-events.js +2 -22
  17. package/dist/agent/turn-prompt.d.ts +35 -0
  18. package/dist/agent/turn-prompt.js +37 -0
  19. package/dist/agent/turn-recovery.js +1 -1
  20. package/dist/agent/turn-state.d.ts +60 -0
  21. package/dist/agent/turn-state.js +95 -0
  22. package/dist/agent/types.d.ts +5 -4
  23. package/dist/{runtime → channel}/channel-context.d.ts +10 -2
  24. package/dist/{runtime → channel}/channel-context.js +6 -2
  25. package/dist/{runtime → channel}/channel-event.d.ts +39 -0
  26. package/dist/channel/channel-event.js +11 -0
  27. package/dist/channel/channel-paths.d.ts +16 -0
  28. package/dist/{runtime → channel}/channel-paths.js +20 -0
  29. package/dist/{runtime → channel}/project-scope-store.js +6 -11
  30. package/dist/{runtime → channel}/store.d.ts +7 -0
  31. package/dist/{agent/commands.d.ts → commands/catalog.d.ts} +17 -2
  32. package/dist/{agent/commands.js → commands/catalog.js} +30 -0
  33. package/dist/index.d.ts +1 -1
  34. package/dist/log.js +14 -5
  35. package/dist/main.js +29 -0
  36. package/dist/memory/bootstrap.js +3 -5
  37. package/dist/memory/candidates.js +2 -4
  38. package/dist/memory/commands.js +2 -2
  39. package/dist/memory/files.d.ts +0 -1
  40. package/dist/memory/files.js +6 -9
  41. package/dist/memory/maintenance-state.d.ts +8 -0
  42. package/dist/memory/maintenance-state.js +51 -4
  43. package/dist/memory/scheduler.d.ts +6 -0
  44. package/dist/memory/scheduler.js +19 -16
  45. package/dist/playbooks/agent-delegation.md +2 -2
  46. package/dist/runtime/bootstrap.d.ts +14 -8
  47. package/dist/runtime/bootstrap.js +158 -81
  48. package/dist/runtime/delivery.d.ts +3 -3
  49. package/dist/runtime/delivery.js +1 -0
  50. package/dist/runtime/dingtalk.d.ts +62 -6
  51. package/dist/runtime/dingtalk.js +194 -85
  52. package/dist/runtime/durable-dispatch.d.ts +7 -1
  53. package/dist/runtime/durable-dispatch.js +12 -2
  54. package/dist/runtime/event-commands.js +2 -2
  55. package/dist/runtime/events.d.ts +8 -1
  56. package/dist/runtime/events.js +15 -3
  57. package/dist/runtime/inbound-media.d.ts +60 -0
  58. package/dist/runtime/inbound-media.js +95 -0
  59. package/dist/runtime/project-commands.js +2 -2
  60. package/dist/runtime/skill-commands.d.ts +27 -0
  61. package/dist/runtime/skill-commands.js +72 -0
  62. package/dist/runtime/subagent-commands.js +1 -1
  63. package/dist/runtime/task-commands.js +2 -2
  64. package/dist/runtime/task-driver.d.ts +12 -1
  65. package/dist/runtime/task-driver.js +36 -56
  66. package/dist/runtime/task-migration.d.ts +11 -0
  67. package/dist/runtime/task-migration.js +14 -2
  68. package/dist/runtime/task-wake.d.ts +1 -1
  69. package/dist/runtime/task-wake.js +1 -1
  70. package/dist/security/command-guard.js +1 -3
  71. package/dist/security/config.d.ts +1 -1
  72. package/dist/security/config.js +8 -32
  73. package/dist/security/path-guard.js +1 -6
  74. package/dist/security/project-scope.js +1 -3
  75. package/dist/settings.d.ts +3 -2
  76. package/dist/settings.js +82 -20
  77. package/dist/shared/atomic-file.d.ts +2 -3
  78. package/dist/shared/atomic-file.js +8 -9
  79. package/dist/shared/config-diagnostic.d.ts +21 -0
  80. package/dist/shared/config-diagnostic.js +32 -0
  81. package/dist/shared/numeric.d.ts +7 -0
  82. package/dist/shared/numeric.js +19 -0
  83. package/dist/shared/text-utils.d.ts +10 -0
  84. package/dist/shared/text-utils.js +16 -0
  85. package/dist/shared/token-estimate.d.ts +1 -0
  86. package/dist/shared/token-estimate.js +19 -0
  87. package/dist/shared/types.d.ts +23 -0
  88. package/dist/shared/types.js +12 -0
  89. package/dist/shared/with-timeout.d.ts +3 -0
  90. package/dist/shared/with-timeout.js +8 -0
  91. package/dist/subagents/discovery.d.ts +7 -7
  92. package/dist/subagents/discovery.js +27 -59
  93. package/dist/subagents/runs.d.ts +15 -4
  94. package/dist/subagents/runs.js +118 -11
  95. package/dist/subagents/tool.js +199 -131
  96. package/dist/subagents/workspace-lease.js +1 -3
  97. package/dist/tasks/control.d.ts +2 -0
  98. package/dist/tasks/control.js +2 -0
  99. package/dist/tasks/ledger.d.ts +0 -9
  100. package/dist/tasks/ledger.js +92 -158
  101. package/dist/tools/config.d.ts +1 -1
  102. package/dist/tools/config.js +9 -46
  103. package/dist/tools/glob-match.d.ts +25 -4
  104. package/dist/tools/glob-match.js +175 -53
  105. package/dist/tools/glob.js +5 -2
  106. package/dist/tools/index.d.ts +1 -1
  107. package/dist/tools/registry.d.ts +1 -1
  108. package/dist/tools/send-media.d.ts +1 -1
  109. package/dist/tools/skill.d.ts +15 -0
  110. package/dist/tools/skill.js +17 -11
  111. package/dist/tools/truncate.js +24 -28
  112. package/dist/tui/app.js +6 -4
  113. package/dist/tui/commands.d.ts +1 -0
  114. package/dist/tui/commands.js +3 -1
  115. package/dist/tui/terminal-context.d.ts +2 -2
  116. package/dist/tui/terminal-media-sender.d.ts +1 -1
  117. package/dist/tui/turn-controller.d.ts +2 -1
  118. package/dist/tui/turn-controller.js +2 -1
  119. package/dist/web/config.js +3 -15
  120. package/examples/sub-agents/README.md +2 -2
  121. package/examples/sub-agents/builder.md +1 -1
  122. package/examples/sub-agents/documenter.md +1 -1
  123. package/examples/sub-agents/explorer.md +4 -4
  124. package/examples/sub-agents/git-committer.md +5 -4
  125. package/examples/sub-agents/log-sifter.md +4 -4
  126. package/examples/sub-agents/planner.md +1 -1
  127. package/examples/sub-agents/reviewer.md +1 -1
  128. package/examples/sub-agents/verifier.md +1 -1
  129. package/examples/sub-agents/worker.md +3 -3
  130. package/package.json +3 -2
  131. package/dist/agent/index.d.ts +0 -2
  132. package/dist/agent/index.js +0 -1
  133. package/dist/runtime/channel-event.js +0 -1
  134. package/dist/runtime/channel-paths.d.ts +0 -4
  135. /package/dist/{runtime → channel}/active-session-store.d.ts +0 -0
  136. /package/dist/{runtime → channel}/active-session-store.js +0 -0
  137. /package/dist/{runtime → channel}/channel-index.d.ts +0 -0
  138. /package/dist/{runtime → channel}/channel-index.js +0 -0
  139. /package/dist/{runtime → channel}/project-scope-store.d.ts +0 -0
  140. /package/dist/{runtime → channel}/store.js +0 -0
  141. /package/dist/{agent → commands}/reply-limits.d.ts +0 -0
  142. /package/dist/{agent → commands}/reply-limits.js +0 -0
@@ -0,0 +1,27 @@
1
+ /**
2
+ * `/skills` — the human control path for a workspace's skill catalog (spec 045's read-only
3
+ * `skill` tool has no channel-command counterpart until now). Mirrors `project-commands.ts`'s
4
+ * shape: pure-ish functions returning markdown, no bot/event coupling.
5
+ *
6
+ * Deliberately a disk scan via `listWorkspaceSkills`, not the live `ChannelRunner`'s already-
7
+ * loaded catalog: that keeps `/skills` usable while a turn is streaming and for a channel with no
8
+ * active runner, and — the whole reason this exists rather than reusing `/help`'s discovery tail
9
+ * — it is the only place that shows a skill that failed the content scan and was silently dropped
10
+ * from `<available_skills>` (`src/agent/workspace-resources.ts`).
11
+ */
12
+ export interface HandleSkillsCommandOptions {
13
+ args: string;
14
+ workspaceDir: string;
15
+ appHomeDir: string;
16
+ channelId?: string;
17
+ }
18
+ type SkillsCommand = {
19
+ action: "list";
20
+ } | {
21
+ action: "show";
22
+ name: string;
23
+ };
24
+ /** Exported so `test/commands-subcommands.test.ts` can feed every broadcast example back through it. */
25
+ export declare function parseSkillsCommand(args: string): SkillsCommand;
26
+ export declare function handleSkillsCommand(options: HandleSkillsCommandOptions): Promise<string>;
27
+ export {};
@@ -0,0 +1,72 @@
1
+ import { renderSubcommandUsage } from "../commands/catalog.js";
2
+ import { capReply } from "../commands/reply-limits.js";
3
+ import { loadSecurityConfigWithDiagnostics } from "../security/config.js";
4
+ import { errorMessage } from "../shared/text-utils.js";
5
+ import { listWorkspaceSkills, loadWorkspaceSkillFile } from "../tools/skill.js";
6
+ function usage() {
7
+ return renderSubcommandUsage("skills");
8
+ }
9
+ /** Exported so `test/commands-subcommands.test.ts` can feed every broadcast example back through it. */
10
+ export function parseSkillsCommand(args) {
11
+ const trimmed = args.trim();
12
+ if (!trimmed || trimmed.toLowerCase() === "list")
13
+ return { action: "list" };
14
+ const parts = trimmed.split(/\s+/);
15
+ if (parts[0]?.toLowerCase() === "show") {
16
+ if (!parts[1] || parts.length > 2)
17
+ throw new Error("用法:/skills show <name>");
18
+ return { action: "show", name: parts[1] };
19
+ }
20
+ throw new Error(`未知的 /skills 子命令:${parts[0]}`);
21
+ }
22
+ async function listSkills(workspaceDir) {
23
+ const skills = await listWorkspaceSkills({ workspaceDir });
24
+ if (skills.length === 0) {
25
+ return (`**Workspace skills**\n\n暂无工作区 skill(\`${workspaceDir}/skills/\` 下没有)。\n\n` +
26
+ "用 write/edit 在 `workspace/skills/<name>/SKILL.md` 直接创建,frontmatter 需要非空的 `name`(与目录名一致)和 `description`。");
27
+ }
28
+ const loaded = skills.filter((skill) => !skill.warning);
29
+ const rejected = skills.filter((skill) => skill.warning);
30
+ const lines = [`**Workspace skills**(${loaded.length} 个)· 用 \`/skill:<名称>\` 调用`, ""];
31
+ if (loaded.length > 0) {
32
+ lines.push(...loaded.map((skill) => `- \`${skill.name}\` — ${skill.description || "(无 description)"}`));
33
+ }
34
+ else {
35
+ lines.push("(全部未通过加载,见下)");
36
+ }
37
+ if (rejected.length > 0) {
38
+ lines.push("", "⚠ 未加载(不在 `<available_skills>` 中,也无法通过 `/skill:名称` 调用)", "");
39
+ lines.push(...rejected.map((skill) => `- \`${skill.name}\` — ${skill.warning}`));
40
+ }
41
+ return capReply(lines.join("\n"), { nextStepHint: "用 `/skills show <name>` 查看单个 skill 的完整正文" }).text;
42
+ }
43
+ async function showSkill(options, name) {
44
+ try {
45
+ const securityConfig = loadSecurityConfigWithDiagnostics(options.appHomeDir).config;
46
+ const file = await loadWorkspaceSkillFile({
47
+ workspaceDir: options.workspaceDir,
48
+ securityConfig,
49
+ channelId: options.channelId,
50
+ }, name);
51
+ const body = `**Skill \`${file.name}\`**\n\n路径:\`${file.path}\`\n\n${file.content}`;
52
+ return capReply(body, { nextStepHint: `用 read 工具打开 ${file.path} 继续查看` }).text;
53
+ }
54
+ catch (error) {
55
+ return `无法查看 skill:${errorMessage(error)}`;
56
+ }
57
+ }
58
+ export async function handleSkillsCommand(options) {
59
+ let command;
60
+ try {
61
+ command = parseSkillsCommand(options.args);
62
+ }
63
+ catch (error) {
64
+ return `${errorMessage(error)}\n\n${usage()}`;
65
+ }
66
+ switch (command.action) {
67
+ case "list":
68
+ return listSkills(options.workspaceDir);
69
+ case "show":
70
+ return showSkill(options, command.name);
71
+ }
72
+ }
@@ -1,6 +1,6 @@
1
1
  import { readFile } from "node:fs/promises";
2
2
  import { join } from "node:path";
3
- import { renderSubcommandUsage } from "../agent/commands.js";
3
+ import { renderSubcommandUsage } from "../commands/catalog.js";
4
4
  import { formatDuration } from "../shared/duration.js";
5
5
  import { errorMessage } from "../shared/text-utils.js";
6
6
  import { formatCost, formatRunDuration, harnessLabel } from "../subagents/format.js";
@@ -1,9 +1,9 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import { readdir, readFile } from "node:fs/promises";
3
3
  import { join, resolve, sep } from "node:path";
4
- import { renderSubcommandUsage } from "../agent/commands.js";
5
4
  import { channelJobTaskIds } from "../agent/job-manager.js";
6
- import { capReply } from "../agent/reply-limits.js";
5
+ import { renderSubcommandUsage } from "../commands/catalog.js";
6
+ import { capReply } from "../commands/reply-limits.js";
7
7
  import { formatLocalTime, parseLocalTime, parseWakeInput } from "../shared/local-time.js";
8
8
  import { errorMessage } from "../shared/text-utils.js";
9
9
  import { channelDelegationTaskIds, getSubAgentRunManager } from "../subagents/runs.js";
@@ -1,6 +1,6 @@
1
+ import type { ChannelEvent } from "../channel/channel-event.js";
1
2
  import type { PipiclawTaskDriverSettings } from "../settings.js";
2
3
  import { type TaskLedgerEntry } from "../tasks/ledger.js";
3
- import type { ChannelEvent } from "./channel-event.js";
4
4
  export interface TaskDriverOptions {
5
5
  workspaceDir: string;
6
6
  getKnownChannelIds?: () => Iterable<string>;
@@ -21,6 +21,10 @@ export interface TaskDriverOptions {
21
21
  /** Direct, non-LLM receipt for deterministic governor stops. */
22
22
  notify?: (event: ChannelEvent) => boolean | Promise<boolean>;
23
23
  }
24
+ /**
25
+ * Channels this driver should scan. Live ids come first so a channel discovered on disk under
26
+ * its escaped directory name never displaces the real id the runner map already knows.
27
+ */
24
28
  export declare function discoverTaskChannels(workspaceDir: string, knownChannelIds?: Iterable<string>): Promise<string[]>;
25
29
  export declare function createTaskDriverEvent(channelId: string, entry: TaskLedgerEntry, nowMs: number): ChannelEvent;
26
30
  export declare function taskGovernorReceipt(channelId: string, entry: TaskLedgerEntry, reason: string, nowMs: number): ChannelEvent;
@@ -66,5 +70,12 @@ export declare class TaskDriver {
66
70
  /** Fold `candidate` into the earliest interesting wake moment. */
67
71
  private noteHorizon;
68
72
  private collectHorizons;
73
+ /**
74
+ * Escalate one task to the governor and best-effort notify, returning whether it actually
75
+ * escalated (a caller only needs to react — reset attempt state, log — when it did). The
76
+ * notify failure itself is never fatal to the escalation: `escalateTask` already made the
77
+ * durable disable; a delivery hiccup is logged and swallowed, not retried here.
78
+ */
79
+ private escalateAndNotify;
69
80
  runOnce(now?: Date): Promise<void>;
70
81
  }
@@ -1,5 +1,7 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { join } from "node:path";
3
+ import { discoverWorkspaceChannelIds } from "../channel/channel-index.js";
4
+ import { dedupeChannelIdsByDirectory, getChannelDir, isChannelId } from "../channel/channel-paths.js";
3
5
  import * as log from "../log.js";
4
6
  import { PLAYBOOKS_DIR } from "../paths.js";
5
7
  import { parseLocalTime } from "../shared/local-time.js";
@@ -8,8 +10,6 @@ import { taskBudgetViolation } from "../tasks/control.js";
8
10
  import { normalizeTaskFields, readActiveTasks, recurringTaskMissedOccurrence, } from "../tasks/ledger.js";
9
11
  import { activateWaitingTask, escalateTask, openRecurringTaskCycle, updateStoredTask } from "../tasks/store.js";
10
12
  import { nextTaskWake } from "../tasks/task-schedule.js";
11
- import { discoverWorkspaceChannelIds } from "./channel-index.js";
12
- import { isChannelId } from "./channel-paths.js";
13
13
  /** Short debounce so a burst of nudges collapses into a single rescan. */
14
14
  const NUDGE_DEBOUNCE_MS = 50;
15
15
  /** Never schedule a scan closer than this, so near-now horizons cannot spin the loop. */
@@ -20,16 +20,15 @@ const FUTILE_WAKE_LIMIT = 3;
20
20
  * path (deadline and futileCount are). Guards only against a task that keeps "progressing"
21
21
  * without ever converging or hitting its deadline. */
22
22
  const MAX_WAKES_PER_CYCLE = 500;
23
+ /**
24
+ * Channels this driver should scan. Live ids come first so a channel discovered on disk under
25
+ * its escaped directory name never displaces the real id the runner map already knows.
26
+ */
23
27
  export async function discoverTaskChannels(workspaceDir, knownChannelIds = []) {
24
- const channels = new Set();
25
- for (const channelId of knownChannelIds) {
26
- if (isChannelId(channelId))
27
- channels.add(channelId);
28
- }
29
- for (const channelId of await discoverWorkspaceChannelIds(workspaceDir)) {
30
- channels.add(channelId);
31
- }
32
- return Array.from(channels).sort();
28
+ return dedupeChannelIdsByDirectory([
29
+ ...[...knownChannelIds].filter(isChannelId),
30
+ ...(await discoverWorkspaceChannelIds(workspaceDir)),
31
+ ]);
33
32
  }
34
33
  function attemptKey(channelId, taskId) {
35
34
  return `${channelId}\0${taskId}`;
@@ -292,6 +291,24 @@ export class TaskDriver {
292
291
  }
293
292
  }
294
293
  }
294
+ /**
295
+ * Escalate one task to the governor and best-effort notify, returning whether it actually
296
+ * escalated (a caller only needs to react — reset attempt state, log — when it did). The
297
+ * notify failure itself is never fatal to the escalation: `escalateTask` already made the
298
+ * durable disable; a delivery hiccup is logged and swallowed, not retried here.
299
+ */
300
+ async escalateAndNotify(channelDir, channelId, entry, reason, nowMs) {
301
+ if (!(await escalateTask(channelDir, entry.id, reason)))
302
+ return false;
303
+ const receipt = taskGovernorReceipt(channelId, entry, reason, nowMs);
304
+ try {
305
+ await this.options.notify?.(receipt);
306
+ }
307
+ catch (error) {
308
+ log.logWarning(`[${channelId}] Task governor receipt failed`, errorMessage(error));
309
+ }
310
+ return true;
311
+ }
295
312
  async runOnce(now = new Date()) {
296
313
  if (this.options.isEnabled?.() === false || this.running)
297
314
  return;
@@ -313,7 +330,9 @@ export class TaskDriver {
313
330
  const channelId = channels[(start + offset) % channels.length];
314
331
  if (!channelId)
315
332
  continue;
316
- const channelDir = join(this.options.workspaceDir, channelId);
333
+ // `channelId` is the raw id, which for a DingTalk group routinely contains `/`;
334
+ // only `getChannelDir` folds it into the escaped directory name that exists on disk.
335
+ const channelDir = getChannelDir(this.options.workspaceDir, channelId);
317
336
  let entries = await readActiveTasks(join(channelDir, "tasks"), nowMs);
318
337
  for (const entry of entries)
319
338
  seen.add(attemptKey(channelId, entry.id));
@@ -335,30 +354,12 @@ export class TaskDriver {
335
354
  if (entry.frontmatter.status !== "sleeping" || entry.frontmatter.enabled === false)
336
355
  continue;
337
356
  if (!entry.frontmatter.schedule) {
338
- const reason = "sleeping recurring task has no schedule";
339
- if (await escalateTask(channelDir, entry.id, reason)) {
340
- const receipt = taskGovernorReceipt(channelId, entry, reason, nowMs);
341
- try {
342
- await this.options.notify?.(receipt);
343
- }
344
- catch (error) {
345
- log.logWarning(`[${channelId}] Task governor receipt failed`, errorMessage(error));
346
- }
347
- }
357
+ await this.escalateAndNotify(channelDir, channelId, entry, "sleeping recurring task has no schedule", nowMs);
348
358
  continue;
349
359
  }
350
360
  const scheduleWake = nextTaskWake(entry.frontmatter.schedule, now);
351
361
  if (!scheduleWake) {
352
- const reason = `sleeping task has invalid schedule: ${entry.frontmatter.schedule}`;
353
- if (await escalateTask(channelDir, entry.id, reason)) {
354
- const receipt = taskGovernorReceipt(channelId, entry, reason, nowMs);
355
- try {
356
- await this.options.notify?.(receipt);
357
- }
358
- catch (error) {
359
- log.logWarning(`[${channelId}] Task governor receipt failed`, errorMessage(error));
360
- }
361
- }
362
+ await this.escalateAndNotify(channelDir, channelId, entry, `sleeping task has invalid schedule: ${entry.frontmatter.schedule}`, nowMs);
362
363
  continue;
363
364
  }
364
365
  if (!needsWakeHeal(entry))
@@ -385,14 +386,7 @@ export class TaskDriver {
385
386
  if (!escalationReason)
386
387
  continue;
387
388
  governanceHandled = true;
388
- if (await escalateTask(channelDir, candidate.id, escalationReason)) {
389
- const receipt = taskGovernorReceipt(channelId, candidate, escalationReason, nowMs);
390
- try {
391
- await this.options.notify?.(receipt);
392
- }
393
- catch (error) {
394
- log.logWarning(`[${channelId}] Task governor receipt failed`, errorMessage(error));
395
- }
389
+ if (await this.escalateAndNotify(channelDir, channelId, candidate, escalationReason, nowMs)) {
396
390
  log.logWarning(`[${channelId}] Task driver disabled ${candidate.id} (governor)`, escalationReason);
397
391
  }
398
392
  break;
@@ -480,14 +474,7 @@ export class TaskDriver {
480
474
  const futileCount = !repairOnly && previous?.accepted && previous.fingerprint === fingerprint ? previous.futileCount + 1 : 0;
481
475
  if (futileCount >= FUTILE_WAKE_LIMIT) {
482
476
  const reason = `task made no visible progress in ${FUTILE_WAKE_LIMIT} consecutive wakes`;
483
- if (await escalateTask(channelDir, entry.id, reason)) {
484
- const receipt = taskGovernorReceipt(channelId, entry, reason, nowMs);
485
- try {
486
- await this.options.notify?.(receipt);
487
- }
488
- catch (error) {
489
- log.logWarning(`[${channelId}] Task governor receipt failed`, errorMessage(error));
490
- }
477
+ if (await this.escalateAndNotify(channelDir, channelId, entry, reason, nowMs)) {
491
478
  this.attempts.delete(key);
492
479
  this.lastDispatchedTaskId.set(channelId, entry.id);
493
480
  log.logWarning(`[${channelId}] Task driver disabled ${entry.id} (governor)`, reason);
@@ -498,14 +485,7 @@ export class TaskDriver {
498
485
  const wakeCount = !repairOnly && previous && previous.cycleId === cycleId ? previous.wakeCount + 1 : 1;
499
486
  if (wakeCount > MAX_WAKES_PER_CYCLE) {
500
487
  const reason = `task exceeded ${MAX_WAKES_PER_CYCLE} wakes in this cycle (runaway failsafe)`;
501
- if (await escalateTask(channelDir, entry.id, reason)) {
502
- const receipt = taskGovernorReceipt(channelId, entry, reason, nowMs);
503
- try {
504
- await this.options.notify?.(receipt);
505
- }
506
- catch (error) {
507
- log.logWarning(`[${channelId}] Task governor receipt failed`, errorMessage(error));
508
- }
488
+ if (await this.escalateAndNotify(channelDir, channelId, entry, reason, nowMs)) {
509
489
  this.attempts.delete(key);
510
490
  this.lastDispatchedTaskId.set(channelId, entry.id);
511
491
  log.logWarning(`[${channelId}] Task driver disabled ${entry.id} (governor)`, reason);
@@ -1,3 +1,14 @@
1
+ /**
2
+ * RETIRE AT v0.9.3 (code review 2026-08-30): both migrations in this file are startup self-heal
3
+ * passes for on-disk state written by pre-0.9 betas (the pre-spec-029 `.schedule` event format,
4
+ * and pre-spec-043 v1/v2 task control blocks and status vocabulary). Every 0.9.2-beta install is
5
+ * a small, actively-developed fleet; by the 0.9.3 stable cut every install will have booted at
6
+ * least once on a version that already runs these passes, so there is no longer any on-disk
7
+ * state left for them to find. At 0.9.3: delete both exported functions here, their call sites
8
+ * in `bootstrap.ts`, `parseLegacyTaskControl` in `../tasks/control.js` (this file's only caller),
9
+ * and the paired legacy-state fold in `../memory/maintenance-state.js` (same rationale, unrelated
10
+ * subsystem). Confirm first that no currently-supported version predates the pass being removed.
11
+ */
1
12
  /**
2
13
  * One-time migration closing the 027 window (spec 029, D6).
3
14
  *
@@ -1,5 +1,6 @@
1
1
  import { mkdir, readdir, readFile, rename, stat, unlink } from "node:fs/promises";
2
2
  import { join } from "node:path";
3
+ import { getChannelDir } from "../channel/channel-paths.js";
3
4
  import * as log from "../log.js";
4
5
  import { formatLocalTime } from "../shared/local-time.js";
5
6
  import { errorMessage } from "../shared/text-utils.js";
@@ -11,6 +12,17 @@ import { parseTaskEventName, taskEventPrefix } from "../tasks/task-events.js";
11
12
  import { TASK_STATUSES } from "../tasks/transitions.js";
12
13
  import { parseScheduledEventContent } from "./events.js";
13
14
  import { discoverTaskChannels } from "./task-driver.js";
15
+ /**
16
+ * RETIRE AT v0.9.3 (code review 2026-08-30): both migrations in this file are startup self-heal
17
+ * passes for on-disk state written by pre-0.9 betas (the pre-spec-029 `.schedule` event format,
18
+ * and pre-spec-043 v1/v2 task control blocks and status vocabulary). Every 0.9.2-beta install is
19
+ * a small, actively-developed fleet; by the 0.9.3 stable cut every install will have booted at
20
+ * least once on a version that already runs these passes, so there is no longer any on-disk
21
+ * state left for them to find. At 0.9.3: delete both exported functions here, their call sites
22
+ * in `bootstrap.ts`, `parseLegacyTaskControl` in `../tasks/control.js` (this file's only caller),
23
+ * and the paired legacy-state fold in `../memory/maintenance-state.js` (same rationale, unrelated
24
+ * subsystem). Confirm first that no currently-supported version predates the pass being removed.
25
+ */
14
26
  /**
15
27
  * One-time migration closing the 027 window (spec 029, D6).
16
28
  *
@@ -54,7 +66,7 @@ export async function migrateLegacyTaskScheduleEvents(workspaceDir) {
54
66
  }
55
67
  try {
56
68
  let folded = false;
57
- const document = await updateStoredTask(join(workspaceDir, channelId), parsed.id, (task) => {
69
+ const document = await updateStoredTask(getChannelDir(workspaceDir, channelId), parsed.id, (task) => {
58
70
  if (!task.fields.schedule) {
59
71
  task.fields.schedule = cron;
60
72
  folded = true;
@@ -133,7 +145,7 @@ function resolveMigratedControl(frontmatter) {
133
145
  export async function migrateLegacyTaskState(workspaceDir) {
134
146
  const channels = await discoverTaskChannels(workspaceDir);
135
147
  for (const channelId of channels) {
136
- const channelDir = join(workspaceDir, channelId);
148
+ const channelDir = getChannelDir(workspaceDir, channelId);
137
149
  const dir = join(channelDir, "tasks");
138
150
  let filenames;
139
151
  try {
@@ -5,10 +5,10 @@
5
5
  * `createRuntimeContext`'s closures.
6
6
  */
7
7
  import { type JobSnapshot } from "../agent/job-manager.js";
8
+ import type { ChannelEvent } from "../channel/channel-event.js";
8
9
  import type { Executor } from "../executor.js";
9
10
  import { type RunRecord } from "../subagents/runs.js";
10
11
  import { type WakeTaskTransitionHooks } from "../tasks/store.js";
11
- import type { ChannelEvent } from "./channel-event.js";
12
12
  /**
13
13
  * Whether a `[JOB:<jobId>] ... belongs to task <taskId>.` wake actually names a job that: exists
14
14
  * on this channel, has actually finished (a still-`running` job cannot have produced this wake —
@@ -5,10 +5,10 @@
5
5
  * `createRuntimeContext`'s closures.
6
6
  */
7
7
  import { getChannelJobManager } from "../agent/job-manager.js";
8
+ import { getChannelDir } from "../channel/channel-paths.js";
8
9
  import { getSubAgentRunManager } from "../subagents/runs.js";
9
10
  import { activateWaitingTask, readStoredTask, rollbackWaitingTask, } from "../tasks/store.js";
10
11
  import { normalizeStoredStatus } from "../tasks/transitions.js";
11
- import { getChannelDir } from "./channel-paths.js";
12
12
  /**
13
13
  * True when `taskId` is currently `active` and enabled — i.e. the task driver already owns
14
14
  * advancing it. A completion wake that could not activate the task (because it was not
@@ -1,8 +1,6 @@
1
1
  import { basename } from "node:path";
2
+ import { stripNullAndNormalize } from "../shared/text-utils.js";
2
3
  const WHITESPACE = /\s+/;
3
- function stripNullAndNormalize(text) {
4
- return text.replace(/\0/g, "").normalize("NFKC");
5
- }
6
4
  function stripComments(command) {
7
5
  let result = "";
8
6
  let inSingle = false;
@@ -1,4 +1,4 @@
1
- import type { ConfigDiagnostic } from "../shared/config-diagnostic.js";
1
+ import { type ConfigDiagnostic } from "../shared/config-diagnostic.js";
2
2
  import type { SecurityConfig } from "./types.js";
3
3
  export interface LoadedSecurityConfig {
4
4
  config: SecurityConfig;
@@ -1,6 +1,6 @@
1
- import { existsSync, readFileSync } from "node:fs";
2
1
  import { join } from "node:path";
3
2
  import { APP_HOME_DIR } from "../paths.js";
3
+ import { loadJsonConfig, pushConfigWarning } from "../shared/config-diagnostic.js";
4
4
  import { errorMessage } from "../shared/text-utils.js";
5
5
  import { isRecord } from "../shared/type-guards.js";
6
6
  export const DEFAULT_SECURITY_CONFIG = {
@@ -51,12 +51,7 @@ function asDenyPatternArray(value, diagnostics, configPath, field) {
51
51
  });
52
52
  }
53
53
  function pushInvalidSecurityDiagnostic(diagnostics, configPath, field, message) {
54
- diagnostics.push({
55
- source: "security",
56
- path: configPath,
57
- severity: "warning",
58
- message: `${field}: ${message}`,
59
- });
54
+ pushConfigWarning(diagnostics, "security", configPath, field, message);
60
55
  }
61
56
  function mergeSecurityConfig(source, configPath, diagnostics) {
62
57
  if (!isRecord(source)) {
@@ -128,31 +123,12 @@ export function getSecurityConfigPath(appHomeDir = APP_HOME_DIR) {
128
123
  return join(appHomeDir, "security.json");
129
124
  }
130
125
  export function loadSecurityConfigWithDiagnostics(appHomeDir = APP_HOME_DIR) {
131
- const configPath = getSecurityConfigPath(appHomeDir);
132
- if (!existsSync(configPath)) {
133
- return { config: DEFAULT_SECURITY_CONFIG, diagnostics: [] };
134
- }
135
- try {
136
- const raw = JSON.parse(readFileSync(configPath, "utf-8"));
137
- const diagnostics = [];
138
- return {
139
- config: mergeSecurityConfig(raw, configPath, diagnostics),
140
- diagnostics,
141
- };
142
- }
143
- catch (error) {
144
- return {
145
- config: DEFAULT_SECURITY_CONFIG,
146
- diagnostics: [
147
- {
148
- source: "security",
149
- path: configPath,
150
- severity: "error",
151
- message: errorMessage(error),
152
- },
153
- ],
154
- };
155
- }
126
+ return loadJsonConfig({
127
+ source: "security",
128
+ path: getSecurityConfigPath(appHomeDir),
129
+ defaults: DEFAULT_SECURITY_CONFIG,
130
+ merge: mergeSecurityConfig,
131
+ });
156
132
  }
157
133
  export function loadSecurityConfig(appHomeDir = APP_HOME_DIR) {
158
134
  return loadSecurityConfigWithDiagnostics(appHomeDir).config;
@@ -2,6 +2,7 @@ import { existsSync, lstatSync, realpathSync } from "node:fs";
2
2
  import { homedir, tmpdir } from "node:os";
3
3
  import { basename, dirname, isAbsolute, join, normalize, resolve } from "node:path";
4
4
  import { PLAYBOOKS_DIR } from "../paths.js";
5
+ import { stripNullAndNormalize, withTrailingSlash } from "../shared/text-utils.js";
5
6
  const PRIVATE_KEY_EXTENSIONS = new Set([".pem", ".key", ".p12", ".pfx"]);
6
7
  const PRIVATE_KEY_NAME_HINTS = /(id_rsa|id_ed25519|private|secret|credentials)/i;
7
8
  const PROC_MEM_PATH = /^\/proc\/\d+\/mem(?:\/|$)/;
@@ -43,12 +44,6 @@ const SYSTEM_DENY_PREFIXES = [
43
44
  "/Library/",
44
45
  "/var/",
45
46
  ];
46
- function stripNullAndNormalize(text) {
47
- return text.replace(/\0/g, "").normalize("NFKC");
48
- }
49
- function withTrailingSlash(path) {
50
- return path.endsWith("/") ? path : `${path}/`;
51
- }
52
47
  function startsWithPathPrefix(path, prefix) {
53
48
  return path === prefix || path.startsWith(withTrailingSlash(prefix));
54
49
  }
@@ -1,6 +1,7 @@
1
1
  import { realpathSync, statSync } from "node:fs";
2
2
  import { homedir } from "node:os";
3
3
  import { isAbsolute, resolve } from "node:path";
4
+ import { withTrailingSlash } from "../shared/text-utils.js";
4
5
  const DIAGNOSTIC_SOURCE = "security";
5
6
  function expandHome(path) {
6
7
  if (path === "~")
@@ -86,9 +87,6 @@ export function resolveProjectAccessPolicy(config, startupCwd) {
86
87
  diagnostics,
87
88
  };
88
89
  }
89
- function withTrailingSlash(path) {
90
- return path.endsWith("/") ? path : `${path}/`;
91
- }
92
90
  /** Prefix match with a path-separator boundary, so `/repo-ab` is not treated as within `/repo-a`. */
93
91
  export function isWithinAllowedRoots(root, policy) {
94
92
  return policy.allowedRoots.some((allowed) => root === allowed || root.startsWith(withTrailingSlash(allowed)));
@@ -142,6 +142,8 @@ export interface PipiclawTuiSettings {
142
142
  */
143
143
  responseMode: ResponseMode;
144
144
  }
145
+ export declare const TASK_DIGEST_SETTINGS: PipiclawTaskDigestSettings;
146
+ export declare const TASK_DRIVER_SETTINGS: PipiclawTaskDriverSettings;
145
147
  /**
146
148
  * Settings manager for pipiclaw.
147
149
  * Stores global settings in the pipiclaw root directory.
@@ -151,6 +153,7 @@ export declare class PipiclawSettingsManager {
151
153
  private settings;
152
154
  private loadErrors;
153
155
  private retiredKeys;
156
+ private invalidEnumValues;
154
157
  /** The file's change token as of the last actual parse; see `reload`. */
155
158
  private loadedStamp;
156
159
  constructor(baseDir: string);
@@ -172,8 +175,6 @@ export declare class PipiclawSettingsManager {
172
175
  setCompactionEnabled(enabled: boolean): void;
173
176
  getRetrySettings(): PipiclawRetrySettings;
174
177
  getMemoryRecallSettings(): PipiclawMemoryRecallSettings;
175
- getTaskDigestSettings(): PipiclawTaskDigestSettings;
176
- getTaskDriverSettings(): PipiclawTaskDriverSettings;
177
178
  getSessionMemorySettings(): PipiclawSessionMemorySettings;
178
179
  getMemoryMaintenanceSettings(): PipiclawMemoryMaintenanceSettings;
179
180
  getSessionSearchSettings(): PipiclawSessionSearchSettings;