@oyasmi/pipiclaw 0.9.1-beta.1 → 0.9.1

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 (126) hide show
  1. package/dist/agent/channel-runner.d.ts +7 -1
  2. package/dist/agent/channel-runner.js +42 -15
  3. package/dist/agent/command-extension.js +24 -27
  4. package/dist/agent/commands.d.ts +51 -7
  5. package/dist/agent/commands.js +199 -59
  6. package/dist/agent/prompt/manifest.js +5 -6
  7. package/dist/agent/prompt/sections.js +1 -0
  8. package/dist/agent/reply-limits.d.ts +16 -0
  9. package/dist/agent/reply-limits.js +17 -0
  10. package/dist/agent/runner-factory.d.ts +0 -2
  11. package/dist/agent/session-events.js +2 -2
  12. package/dist/agent/status-render.js +12 -12
  13. package/dist/executor.d.ts +14 -0
  14. package/dist/executor.js +36 -6
  15. package/dist/main.js +3 -4
  16. package/dist/memory/commands.js +79 -38
  17. package/dist/memory/consolidation.d.ts +5 -1
  18. package/dist/memory/consolidation.js +33 -12
  19. package/dist/memory/extraction.d.ts +8 -1
  20. package/dist/memory/extraction.js +47 -4
  21. package/dist/memory/files.d.ts +0 -1
  22. package/dist/memory/files.js +24 -5
  23. package/dist/memory/lifecycle.js +9 -2
  24. package/dist/memory/maintenance-jobs.js +14 -4
  25. package/dist/memory/metadata.d.ts +3 -0
  26. package/dist/memory/metadata.js +7 -0
  27. package/dist/memory/recall.d.ts +9 -0
  28. package/dist/memory/recall.js +101 -17
  29. package/dist/memory/review-log.d.ts +0 -2
  30. package/dist/memory/review-log.js +0 -0
  31. package/dist/memory/session-corpus.js +5 -0
  32. package/dist/memory/session-search.js +9 -0
  33. package/dist/memory/sidecar-worker.js +4 -0
  34. package/dist/memory/source-window.d.ts +0 -1
  35. package/dist/memory/source-window.js +0 -5
  36. package/dist/memory/task-digest.js +0 -2
  37. package/dist/playbooks/agent-delegation.md +32 -24
  38. package/dist/playbooks/background-jobs.md +8 -16
  39. package/dist/playbooks/event-scheduling.md +13 -15
  40. package/dist/playbooks/memory-and-learning.md +29 -22
  41. package/dist/playbooks/outbound-media.md +15 -8
  42. package/dist/playbooks/runtime-orientation.md +40 -37
  43. package/dist/playbooks/task-driving.md +34 -38
  44. package/dist/playbooks/task-planning.md +18 -20
  45. package/dist/runtime/app-home.d.ts +6 -0
  46. package/dist/runtime/app-home.js +15 -6
  47. package/dist/runtime/bootstrap.d.ts +1 -1
  48. package/dist/runtime/bootstrap.js +57 -62
  49. package/dist/runtime/channel-context.d.ts +2 -1
  50. package/dist/runtime/channel-event.d.ts +0 -6
  51. package/dist/runtime/delivery.js +3 -3
  52. package/dist/runtime/dingtalk.d.ts +9 -1
  53. package/dist/runtime/dingtalk.js +27 -13
  54. package/dist/runtime/event-commands.d.ts +15 -0
  55. package/dist/runtime/event-commands.js +48 -40
  56. package/dist/runtime/project-commands.d.ts +16 -0
  57. package/dist/runtime/project-commands.js +13 -17
  58. package/dist/runtime/subagent-commands.d.ts +20 -0
  59. package/dist/runtime/subagent-commands.js +61 -58
  60. package/dist/runtime/task-commands.d.ts +38 -1
  61. package/dist/runtime/task-commands.js +135 -234
  62. package/dist/runtime/task-driver.d.ts +1 -3
  63. package/dist/runtime/task-driver.js +34 -40
  64. package/dist/runtime/task-migration.d.ts +7 -6
  65. package/dist/runtime/task-migration.js +85 -19
  66. package/dist/runtime/task-wake.d.ts +3 -5
  67. package/dist/runtime/task-wake.js +7 -15
  68. package/dist/security/path-guard.js +33 -2
  69. package/dist/security/types.d.ts +9 -0
  70. package/dist/subagents/discovery.d.ts +7 -2
  71. package/dist/subagents/discovery.js +31 -7
  72. package/dist/subagents/external/claude-code.js +42 -2
  73. package/dist/subagents/external/run.js +72 -2
  74. package/dist/subagents/runs.js +28 -3
  75. package/dist/subagents/tool.d.ts +11 -0
  76. package/dist/subagents/tool.js +89 -55
  77. package/dist/subagents/verification-outcome.js +17 -10
  78. package/dist/tasks/control.d.ts +18 -67
  79. package/dist/tasks/control.js +44 -176
  80. package/dist/tasks/ledger.d.ts +7 -13
  81. package/dist/tasks/ledger.js +13 -49
  82. package/dist/tasks/store.d.ts +15 -48
  83. package/dist/tasks/store.js +22 -154
  84. package/dist/tasks/transitions.d.ts +3 -4
  85. package/dist/tasks/transitions.js +8 -27
  86. package/dist/tasks/verification.d.ts +7 -5
  87. package/dist/tools/bash.d.ts +1 -1
  88. package/dist/tools/bash.js +77 -59
  89. package/dist/tools/edit.js +17 -4
  90. package/dist/tools/grep.js +3 -2
  91. package/dist/tools/index.d.ts +0 -2
  92. package/dist/tools/index.js +6 -1
  93. package/dist/tools/job.js +2 -1
  94. package/dist/tools/memory-manage.d.ts +1 -0
  95. package/dist/tools/memory-manage.js +54 -16
  96. package/dist/tools/read.js +21 -5
  97. package/dist/tools/registry.d.ts +0 -1
  98. package/dist/tools/registry.js +0 -1
  99. package/dist/tools/send-media.js +17 -6
  100. package/dist/tools/skill-manage.js +12 -11
  101. package/dist/tools/skill-security.js +1 -1
  102. package/dist/tools/subagent-manage.d.ts +8 -1
  103. package/dist/tools/subagent-manage.js +77 -7
  104. package/dist/tools/task-manage/lifecycle.js +19 -17
  105. package/dist/tools/task-manage/schema.d.ts +2 -6
  106. package/dist/tools/task-manage/schema.js +4 -17
  107. package/dist/tools/task-manage/shared.js +1 -6
  108. package/dist/tools/task-manage/types.d.ts +0 -3
  109. package/dist/tools/task-manage/verification.d.ts +9 -6
  110. package/dist/tools/task-manage/verification.js +19 -71
  111. package/dist/tools/task-manage.d.ts +1 -1
  112. package/dist/tools/task-manage.js +3 -5
  113. package/dist/tools/truncate.d.ts +8 -0
  114. package/dist/tools/truncate.js +8 -0
  115. package/dist/tools/web-fetch.js +9 -1
  116. package/dist/tools/write-content.js +11 -1
  117. package/dist/tui/app.js +1 -1
  118. package/dist/tui/commands.d.ts +1 -1
  119. package/dist/tui/commands.js +1 -1
  120. package/dist/tui/turn-controller.d.ts +1 -1
  121. package/dist/tui/turn-controller.js +14 -4
  122. package/dist/usage/ledger.d.ts +4 -0
  123. package/dist/usage/ledger.js +3 -0
  124. package/dist/usage/render.js +10 -8
  125. package/examples/sub-agents/README.md +2 -0
  126. package/package.json +3 -2
@@ -1,103 +1,54 @@
1
- export type TaskPriority = "low" | "normal" | "high" | "critical";
2
1
  export type TaskVerificationStatus = "pending" | "passed" | "failed";
3
- export type TaskWaitingFor = "time" | "user" | "job" | "verification" | "external-signal";
4
- /** How the last agent run ended. This is telemetry, not a lifecycle state. */
5
- export type TaskOutcome = "pending" | "running" | "progress" | "blocked" | "failed";
6
- export interface TaskBudget {
7
- maxAttempts: number;
8
- }
9
- export interface TaskUsage {
10
- attempts: number;
11
- tokens: number;
12
- costUsd: number;
13
- /** False when at least one contributing model omitted pricing metadata. */
14
- costKnown: boolean;
15
- wallTimeMinutes: number;
16
- }
2
+ /** Diagnostic display only (spec 043); it does not gate wake activation. */
3
+ export type TaskWaitingFor = "time" | "user" | "job" | "external-signal";
4
+ /**
5
+ * `status` is a display cache only; it never gates `complete` or doctor. Every field that used to
6
+ * mirror the attestation (evidence/bodyHash/checkedAt/subjectHash) is gone — `runId` is enough to
7
+ * re-read the attestation file, which is the sole authority on whether a PASS is real and fresh.
8
+ */
17
9
  export interface TaskVerification {
18
10
  required: boolean;
19
11
  status: TaskVerificationStatus;
20
12
  runId?: string;
21
- evidence?: string;
22
- /** Hash of the task contract segment inspected by the verifier. */
23
- bodyHash?: string;
24
- checkedAt?: string;
25
- /** Git view of the artifacts the verifier inspected. */
26
- subjectHash?: string;
27
13
  }
28
14
  export interface TaskStop {
29
15
  by: "user" | "governor";
30
16
  reason: string;
31
17
  at: string;
32
18
  }
33
- export interface TaskProvenance {
34
- createdBy?: string;
35
- createdAt?: string;
36
- sourceMessageId?: string;
37
- }
38
- /** Durable ownership marker for the interval between a structured completion wake activating a
39
- * task and its transport accepting the corresponding turn. */
40
- export interface TaskWakeHandoff {
41
- kind: "subagent";
42
- resourceId: string;
43
- dispatchId: string;
44
- generation: number;
45
- previousLastOutcome: TaskOutcome;
46
- previousBlockedReason?: string;
47
- previousLastStartedAt?: string;
48
- }
49
- /** The v2 persisted control block. Execution authority comes from capability and scope. */
19
+ /** The v3 persisted control block. Execution authority comes from capability and scope. */
50
20
  export interface TaskControl {
51
- version: 2;
52
- priority: TaskPriority;
21
+ version: 3;
53
22
  deadline?: string;
54
23
  nextAction?: string;
55
- blockedReason?: string;
56
24
  waitingFor?: TaskWaitingFor;
57
- budget: TaskBudget;
58
- usage: TaskUsage;
59
25
  verification: TaskVerification;
60
- attemptGeneration: number;
61
- lastOutcome: TaskOutcome;
62
- lastStartedAt?: string;
63
- lastFinishedAt?: string;
64
26
  /** Current or most recently closed recurring occurrence. */
65
27
  cycleId?: string;
66
28
  /** Present only while the task is disabled. */
67
29
  stop?: TaskStop;
68
- provenance?: TaskProvenance;
69
- wakeHandoff?: TaskWakeHandoff;
70
30
  }
71
31
  export interface TaskControlPatch {
72
- priority?: TaskPriority;
73
32
  deadline?: string;
74
33
  nextAction?: string;
75
- blockedReason?: string;
76
34
  waitingFor?: TaskWaitingFor;
77
- maxAttempts?: number;
78
35
  verificationRequired?: boolean;
79
36
  }
80
- export declare const TASK_PRIORITIES: readonly TaskPriority[];
81
- /**
82
- * Keys from the v1 control block that this version deliberately retires. They remain visible to
83
- * doctor until the next successful write, but they never enter the v2 control object.
84
- */
85
- export declare const RETIRED_TASK_CONTROL_KEYS: readonly string[];
86
- /** Retired keys actually present in a raw stored control block. */
87
- export declare function retiredTaskControlKeys(raw: unknown): string[];
88
- export declare function createDefaultTaskControl(requiresVerification?: boolean, provenance?: TaskProvenance): TaskControl;
37
+ export declare function createDefaultTaskControl(requiresVerification?: boolean): TaskControl;
38
+ /** Read the v3 control contract only. Anything else is a read-time failure — see `parseLegacyTaskControl`. */
39
+ export declare function parseTaskControl(raw: string): TaskControl;
89
40
  /**
90
- * Read both v1 and v2 files. Retired v1 policy fields are intentionally ignored; the next
91
- * write emits a v2 object without them. This is a reader migration, not command compatibility.
41
+ * Migration-only reader for v1/v2 control blocks. `parseTaskControl` no longer accepts them —
42
+ * this exists so `migrateLegacyTaskState` (spec 029, D6's window, closed here) can durably
43
+ * upgrade an old file the one time it is encountered. Nothing else may call this.
92
44
  */
93
- export declare function parseTaskControl(raw: string): TaskControl;
45
+ export declare function parseLegacyTaskControl(raw: string): TaskControl;
94
46
  /** Reset state that is meaningful only within one recurring task cycle. */
95
47
  export declare function resetTaskControlForCycle(control: TaskControl, cycleId: string): TaskControl;
96
48
  export declare function applyTaskControlPatch(control: TaskControl, patch: TaskControlPatch): TaskControl;
97
- export declare function taskPriorityRank(priority: TaskPriority): number;
98
49
  /**
99
50
  * Return a deterministic governance violation for a live task. Sleeping tasks have no current
100
- * work, so neither a deadline nor an attempt budget may stop them. Waiting tasks are subject to
101
- * their deadline but do not spend attempt budget while parked.
51
+ * work, so a deadline cannot stop them; waiting and active tasks are both subject to it — a
52
+ * deadline is the user's own intent, not something a task can dodge by parking.
102
53
  */
103
54
  export declare function taskBudgetViolation(control: TaskControl, nowMs: number, status?: "active" | "waiting" | "sleeping"): string | undefined;
@@ -1,12 +1,7 @@
1
1
  import { formatLocalTime, parseLocalTime } from "../shared/local-time.js";
2
2
  import { errorMessage } from "../shared/text-utils.js";
3
- export const TASK_PRIORITIES = ["low", "normal", "high", "critical"];
4
- const WAITING_FOR = ["time", "user", "job", "verification", "external-signal"];
3
+ const WAITING_FOR = ["time", "user", "job", "external-signal"];
5
4
  const VERIFICATION_STATUSES = ["pending", "passed", "failed"];
6
- const OUTCOMES = ["pending", "running", "progress", "blocked", "failed"];
7
- function normalizeLegacyOutcome(value) {
8
- return value === "verified" || value === "skipped" ? "progress" : value;
9
- }
10
5
  function isRecord(value) {
11
6
  return typeof value === "object" && value !== null && !Array.isArray(value);
12
7
  }
@@ -16,38 +11,6 @@ function optionalString(value) {
16
11
  const trimmed = value.trim();
17
12
  return trimmed || undefined;
18
13
  }
19
- function finiteNonNegative(value, fallback = 0) {
20
- if (value === undefined)
21
- return fallback;
22
- if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
23
- throw new Error("control usage values must be finite non-negative numbers");
24
- }
25
- return value;
26
- }
27
- function nonNegativeInteger(value, fallback = 0) {
28
- if (value === undefined)
29
- return fallback;
30
- if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
31
- throw new Error("control.attemptGeneration must be a non-negative integer; remove it to rebuild from 0.");
32
- }
33
- return value;
34
- }
35
- function parseTaskUsage(value) {
36
- const attempts = Math.floor(finiteNonNegative(value.attempts));
37
- const tokens = Math.floor(finiteNonNegative(value.tokens));
38
- const costUsd = finiteNonNegative(value.costUsd);
39
- const wallTimeMinutes = finiteNonNegative(value.wallTimeMinutes);
40
- const costKnown = typeof value.costKnown === "boolean" ? value.costKnown : costUsd > 0 || (tokens === 0 && wallTimeMinutes === 0);
41
- return { attempts, tokens, costUsd, costKnown, wallTimeMinutes };
42
- }
43
- function optionalPositive(value) {
44
- if (value === undefined)
45
- return undefined;
46
- if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
47
- throw new Error("control budget values must be finite positive numbers");
48
- }
49
- return value;
50
- }
51
14
  function enumValue(value, values, fallback) {
52
15
  if (value === undefined)
53
16
  return fallback;
@@ -56,12 +19,6 @@ function enumValue(value, values, fallback) {
56
19
  }
57
20
  return value;
58
21
  }
59
- function parseVerificationRequired(verification) {
60
- if (typeof verification.required === "boolean")
61
- return verification.required;
62
- // v1's independent mode was the only mode that represented a real checker gate.
63
- return verification.mode === "independent";
64
- }
65
22
  function parseStop(value) {
66
23
  if (value === undefined)
67
24
  return undefined;
@@ -75,92 +32,50 @@ function parseStop(value) {
75
32
  }
76
33
  return { by, reason, at: formatLocalTime(new Date(parseLocalTime(at))) };
77
34
  }
78
- function parseProvenance(value) {
79
- if (value === undefined)
80
- return undefined;
81
- if (!isRecord(value))
82
- throw new Error("control.provenance must be an object");
83
- const createdBy = optionalString(value.createdBy);
84
- const createdAt = optionalString(value.createdAt);
85
- const sourceMessageId = optionalString(value.sourceMessageId);
86
- if (createdAt && parseLocalTime(createdAt) === undefined) {
87
- throw new Error("control.provenance.createdAt must be a valid local time");
88
- }
89
- return { createdBy, createdAt, sourceMessageId };
90
- }
91
- function parseWakeHandoff(value) {
92
- if (value === undefined)
93
- return undefined;
94
- if (!isRecord(value))
95
- throw new Error("control.wakeHandoff must be an object");
96
- if (value.kind !== "subagent" || typeof value.resourceId !== "string" || typeof value.dispatchId !== "string") {
97
- throw new Error("control.wakeHandoff requires kind=subagent, resourceId, and dispatchId");
98
- }
35
+ export function createDefaultTaskControl(requiresVerification = false) {
99
36
  return {
100
- kind: "subagent",
101
- resourceId: value.resourceId,
102
- dispatchId: value.dispatchId,
103
- generation: nonNegativeInteger(value.generation),
104
- previousLastOutcome: enumValue(normalizeLegacyOutcome(value.previousLastOutcome), OUTCOMES, "pending"),
105
- previousBlockedReason: optionalString(value.previousBlockedReason),
106
- previousLastStartedAt: optionalString(value.previousLastStartedAt),
37
+ version: 3,
38
+ verification: { required: requiresVerification, status: "pending" },
107
39
  };
108
40
  }
109
- /**
110
- * Keys from the v1 control block that this version deliberately retires. They remain visible to
111
- * doctor until the next successful write, but they never enter the v2 control object.
112
- */
113
- export const RETIRED_TASK_CONTROL_KEYS = [
114
- "sideEffects",
115
- "externalApproval",
116
- "approvalBy",
117
- "approvedAt",
118
- "approvalBodyHash",
119
- "pausedBy",
120
- "parent",
121
- "dependsOn",
122
- "worktree",
123
- "lifetimeUsage",
124
- "isolation",
125
- "budget.maxTokens",
126
- "budget.maxCostUsd",
127
- "budget.maxWallTimeMinutes",
128
- ];
129
- /** Retired keys actually present in a raw stored control block. */
130
- export function retiredTaskControlKeys(raw) {
131
- if (!isRecord(raw))
132
- return [];
133
- return RETIRED_TASK_CONTROL_KEYS.filter((key) => {
134
- const [head, nested] = key.split(".");
135
- if (!nested)
136
- return Object.hasOwn(raw, head);
137
- const parent = raw[head];
138
- return isRecord(parent) && Object.hasOwn(parent, nested);
139
- });
140
- }
141
- export function createDefaultTaskControl(requiresVerification = false, provenance) {
41
+ /** Read the v3 control contract only. Anything else is a read-time failure — see `parseLegacyTaskControl`. */
42
+ export function parseTaskControl(raw) {
43
+ let value;
44
+ try {
45
+ value = JSON.parse(raw);
46
+ }
47
+ catch (error) {
48
+ throw new Error(`control is not valid JSON: ${errorMessage(error)}`);
49
+ }
50
+ if (!isRecord(value) || value.version !== 3) {
51
+ throw new Error("control must be a version 3 JSON object; repair it with task_manage set.");
52
+ }
53
+ const verification = isRecord(value.verification) ? value.verification : {};
54
+ const deadline = optionalString(value.deadline);
55
+ if (deadline && parseLocalTime(deadline) === undefined) {
56
+ throw new Error("control.deadline must be a valid local time");
57
+ }
58
+ const waitingFor = value.waitingFor === undefined ? undefined : enumValue(value.waitingFor, WAITING_FOR, "external-signal");
142
59
  return {
143
- version: 2,
144
- priority: "normal",
145
- budget: { maxAttempts: 12 },
146
- usage: {
147
- attempts: 0,
148
- tokens: 0,
149
- costUsd: 0,
150
- costKnown: true,
151
- wallTimeMinutes: 0,
60
+ version: 3,
61
+ deadline,
62
+ nextAction: optionalString(value.nextAction),
63
+ waitingFor,
64
+ verification: {
65
+ required: typeof verification.required === "boolean" ? verification.required : false,
66
+ status: enumValue(verification.status, VERIFICATION_STATUSES, "pending"),
67
+ runId: optionalString(verification.runId),
152
68
  },
153
- verification: { required: requiresVerification, status: "pending" },
154
- attemptGeneration: 0,
155
- lastOutcome: "pending",
156
- ...(provenance ? { provenance } : {}),
69
+ cycleId: optionalString(value.cycleId),
70
+ stop: parseStop(value.stop),
157
71
  };
158
72
  }
159
73
  /**
160
- * Read both v1 and v2 files. Retired v1 policy fields are intentionally ignored; the next
161
- * write emits a v2 object without them. This is a reader migration, not command compatibility.
74
+ * Migration-only reader for v1/v2 control blocks. `parseTaskControl` no longer accepts them —
75
+ * this exists so `migrateLegacyTaskState` (spec 029, D6's window, closed here) can durably
76
+ * upgrade an old file the one time it is encountered. Nothing else may call this.
162
77
  */
163
- export function parseTaskControl(raw) {
78
+ export function parseLegacyTaskControl(raw) {
164
79
  let value;
165
80
  try {
166
81
  value = JSON.parse(raw);
@@ -169,24 +84,14 @@ export function parseTaskControl(raw) {
169
84
  throw new Error(`control is not valid JSON: ${errorMessage(error)}`);
170
85
  }
171
86
  if (!isRecord(value) || (value.version !== 1 && value.version !== 2)) {
172
- throw new Error("control must be a version 1 or version 2 JSON object; repair it with task_manage set.");
87
+ throw new Error("legacy control must be a version 1 or version 2 JSON object");
173
88
  }
174
- const budget = isRecord(value.budget) ? value.budget : {};
175
- const usage = isRecord(value.usage) ? value.usage : {};
176
- const parsedUsage = parseTaskUsage(usage);
177
89
  const verification = isRecord(value.verification) ? value.verification : {};
178
- const maxAttempts = optionalPositive(budget.maxAttempts);
179
- if (!maxAttempts || !Number.isInteger(maxAttempts)) {
180
- throw new Error("control.budget.maxAttempts must be a positive integer");
181
- }
182
90
  const deadline = optionalString(value.deadline);
183
- if (deadline && parseLocalTime(deadline) === undefined) {
184
- throw new Error("control.deadline must be a valid local time");
185
- }
186
91
  const waitingFor = value.waitingFor === undefined ? undefined : enumValue(value.waitingFor, WAITING_FOR, "external-signal");
187
92
  let stop = parseStop(value.stop);
188
93
  // v1 stored the stop dimension as a status-side `pausedBy` value. Preserve its
189
- // operational meaning while converting it to the v2 structured record.
94
+ // operational meaning while converting it to the structured record.
190
95
  if (!stop && value.pausedBy !== undefined) {
191
96
  const by = enumValue(value.pausedBy, ["user", "governor"], "user");
192
97
  stop = {
@@ -196,36 +101,20 @@ export function parseTaskControl(raw) {
196
101
  };
197
102
  }
198
103
  return {
199
- version: 2,
200
- priority: enumValue(value.priority, TASK_PRIORITIES, "normal"),
201
- deadline,
104
+ version: 3,
105
+ deadline: deadline && parseLocalTime(deadline) !== undefined ? deadline : undefined,
202
106
  nextAction: optionalString(value.nextAction),
203
- blockedReason: optionalString(value.blockedReason),
204
107
  waitingFor,
205
- budget: { maxAttempts: Math.max(1, Math.floor(maxAttempts)) },
206
- usage: parsedUsage,
207
108
  verification: {
208
- required: parseVerificationRequired(verification),
109
+ // v1's independent mode was the only mode that represented a real checker gate.
110
+ required: typeof verification.required === "boolean" ? verification.required : verification.mode === "independent",
209
111
  status: enumValue(verification.status, VERIFICATION_STATUSES, "pending"),
210
112
  runId: optionalString(verification.runId),
211
- evidence: optionalString(verification.evidence),
212
- bodyHash: optionalString(verification.bodyHash),
213
- checkedAt: optionalString(verification.checkedAt),
214
- subjectHash: optionalString(verification.subjectHash),
215
113
  },
216
- attemptGeneration: nonNegativeInteger(value.attemptGeneration),
217
- lastOutcome: enumValue(normalizeLegacyOutcome(value.lastOutcome), OUTCOMES, "pending"),
218
- lastStartedAt: optionalString(value.lastStartedAt),
219
- lastFinishedAt: optionalString(value.lastFinishedAt),
220
114
  cycleId: optionalString(value.cycleId),
221
115
  stop,
222
- provenance: parseProvenance(value.provenance),
223
- wakeHandoff: parseWakeHandoff(value.wakeHandoff),
224
116
  };
225
117
  }
226
- function zeroUsage() {
227
- return { attempts: 0, tokens: 0, costUsd: 0, costKnown: true, wallTimeMinutes: 0 };
228
- }
229
118
  /** Reset state that is meaningful only within one recurring task cycle. */
230
119
  export function resetTaskControlForCycle(control, cycleId) {
231
120
  const normalizedCycleId = cycleId.trim();
@@ -234,16 +123,10 @@ export function resetTaskControlForCycle(control, cycleId) {
234
123
  return {
235
124
  ...structuredClone(control),
236
125
  nextAction: undefined,
237
- lastOutcome: "pending",
238
- blockedReason: undefined,
239
126
  waitingFor: undefined,
240
- usage: zeroUsage(),
241
127
  verification: { required: control.verification.required, status: "pending" },
242
- lastStartedAt: undefined,
243
- lastFinishedAt: undefined,
244
128
  cycleId: normalizedCycleId,
245
129
  stop: undefined,
246
- wakeHandoff: undefined,
247
130
  };
248
131
  }
249
132
  function patchOptionalString(current, value) {
@@ -253,8 +136,6 @@ function patchOptionalString(current, value) {
253
136
  }
254
137
  export function applyTaskControlPatch(control, patch) {
255
138
  const next = structuredClone(control);
256
- if (patch.priority !== undefined)
257
- next.priority = patch.priority;
258
139
  let normalizedDeadlinePatch = patch.deadline;
259
140
  if (patch.deadline?.trim()) {
260
141
  const deadlineMs = parseLocalTime(patch.deadline);
@@ -264,27 +145,17 @@ export function applyTaskControlPatch(control, patch) {
264
145
  }
265
146
  next.deadline = patchOptionalString(next.deadline, normalizedDeadlinePatch);
266
147
  next.nextAction = patchOptionalString(next.nextAction, patch.nextAction);
267
- next.blockedReason = patchOptionalString(next.blockedReason, patch.blockedReason);
268
148
  if (patch.waitingFor !== undefined)
269
149
  next.waitingFor = patch.waitingFor;
270
- if (patch.maxAttempts !== undefined) {
271
- if (!Number.isInteger(patch.maxAttempts) || patch.maxAttempts < 1) {
272
- throw new Error("maxAttempts must be a positive integer.");
273
- }
274
- next.budget.maxAttempts = patch.maxAttempts;
275
- }
276
150
  if (patch.verificationRequired !== undefined && patch.verificationRequired !== next.verification.required) {
277
151
  next.verification = { required: patch.verificationRequired, status: "pending" };
278
152
  }
279
153
  return next;
280
154
  }
281
- export function taskPriorityRank(priority) {
282
- return { critical: 0, high: 1, normal: 2, low: 3 }[priority];
283
- }
284
155
  /**
285
156
  * Return a deterministic governance violation for a live task. Sleeping tasks have no current
286
- * work, so neither a deadline nor an attempt budget may stop them. Waiting tasks are subject to
287
- * their deadline but do not spend attempt budget while parked.
157
+ * work, so a deadline cannot stop them; waiting and active tasks are both subject to it — a
158
+ * deadline is the user's own intent, not something a task can dodge by parking.
288
159
  */
289
160
  export function taskBudgetViolation(control, nowMs, status = "active") {
290
161
  if (status === "sleeping")
@@ -294,8 +165,5 @@ export function taskBudgetViolation(control, nowMs, status = "active") {
294
165
  if (deadlineMs !== undefined && deadlineMs < nowMs)
295
166
  return `deadline exceeded (${control.deadline})`;
296
167
  }
297
- if (status === "active" && control.usage.attempts >= control.budget.maxAttempts) {
298
- return `attempt budget exhausted (${control.usage.attempts}/${control.budget.maxAttempts})`;
299
- }
300
168
  return undefined;
301
169
  }
@@ -16,7 +16,7 @@ export interface TaskFrontmatter {
16
16
  /** false => frontmatter could not be read (fail-open: the task is treated as actionable). */
17
17
  readable: boolean;
18
18
  status?: string;
19
- /** Raw status before the v1 reader migration, for deterministic startup migration/doctor. */
19
+ /** The unnormalized on-disk status value; startup migration is its only consumer. */
20
20
  rawStatus?: string;
21
21
  /** True when a legacy terminal file in the active directory needs archiving. */
22
22
  archiveOutcome?: TaskArchiveOutcome;
@@ -25,16 +25,11 @@ export interface TaskFrontmatter {
25
25
  wake?: string;
26
26
  /** Five-field cron cadence (host timezone). Present ⇒ this is a recurring task. */
27
27
  schedule?: string;
28
- recurrence?: string;
29
28
  control?: TaskControl;
30
- /** false only when a control field exists but cannot be parsed/validated. */
29
+ /** false only when a control field exists but cannot be parsed/validated as v3. */
31
30
  controlReadable?: boolean;
32
- /**
33
- * The control block exactly as stored, before `parseTaskControl` drops retired keys.
34
- * `/tasks doctor` needs this to report what an older build wrote (spec 036, D8) — the
35
- * parsed `control` above cannot show a key whose whole point is that it is now ignored.
36
- */
37
- rawControl?: unknown;
31
+ /** The unparsed `control:` value; startup migration re-parses this with the legacy reader. */
32
+ controlRaw?: string;
38
33
  }
39
34
  export interface TaskLedgerEntry {
40
35
  /** Filename without `.md`; the task id. */
@@ -188,7 +183,7 @@ export declare function missingStandardTaskSections(content: string): string[];
188
183
  * Without the "no checklist items" case, a DoD written as prose or a numbered
189
184
  * list (no `- [ ]` anywhere) makes this function return an empty array —
190
185
  * indistinguishable from "everything is checked" — which would silently let
191
- * `task_manage request-verification`/`complete` through with nothing ever actually verified.
186
+ * `task_manage complete` through with nothing ever actually verified.
192
187
  */
193
188
  export declare function uncheckedTaskAcceptanceItems(content: string): string[];
194
189
  /**
@@ -204,13 +199,12 @@ export interface TaskDocumentFields {
204
199
  enabled?: boolean;
205
200
  wake?: string;
206
201
  schedule?: string;
207
- recurrence?: string;
208
202
  control?: TaskControl;
209
203
  outcome?: TaskArchiveOutcome;
210
204
  closedAt?: string;
211
205
  }
212
206
  /**
213
- * Enforce the v2 write-path invariants. Runtime due transitions are intentionally separate: a
207
+ * Enforce the v3 write-path invariants. Runtime due transitions are intentionally separate: a
214
208
  * waiting task is first written active, and a sleeping task is first opened into a cycle, before
215
209
  * the driver dispatches anything.
216
210
  */
@@ -240,7 +234,7 @@ export declare function upsertCurrentCycleCompletionEvidence(content: string, ev
240
234
  * checkpoints to the previous cycle.
241
235
  */
242
236
  export declare function startTaskCycle(content: string, cycleId: string, archivePrevious?: boolean): string;
243
- /** Actionable first; then earliest wake first (unset wake sorts as "ready now"); then id. */
237
+ /** Actionable first; then earliest deadline/wake first (unset sorts as "ready now"); then id. */
244
238
  export declare function compareTaskEntries(a: TaskLedgerEntry, b: TaskLedgerEntry): number;
245
239
  /**
246
240
  * Read every `.md` file in `tasks/` (root only — the `archive/` subdirectory is not
@@ -2,19 +2,10 @@ import { readdir, readFile, stat } from "node:fs/promises";
2
2
  import { join } from "node:path";
3
3
  import { formatLocalTime, parseLocalTime } from "../shared/local-time.js";
4
4
  import { RecoverableToolError } from "../shared/recoverable-error.js";
5
- import { createDefaultTaskControl, parseTaskControl, taskPriorityRank } from "./control.js";
5
+ import { parseTaskControl } from "./control.js";
6
6
  import { nextTaskWake } from "./task-schedule.js";
7
- import { normalizeStoredStatus, wasLegacyEscalated } from "./transitions.js";
8
- const FRONTMATTER_FIELDS = [
9
- "status",
10
- "enabled",
11
- "wake",
12
- "schedule",
13
- "recurrence",
14
- "outcome",
15
- "closedAt",
16
- "control",
17
- ];
7
+ import { normalizeStoredStatus } from "./transitions.js";
8
+ const FRONTMATTER_FIELDS = ["status", "enabled", "wake", "schedule", "outcome", "closedAt", "control"];
18
9
  const TASK_ID_PATTERN = /^[A-Za-z0-9._-]+$/;
19
10
  export const DEFAULT_TASK_MANUAL = "- Follow the DoD, keep the current cycle log updated, and schedule check-ins when waiting.";
20
11
  export const STANDARD_TASK_SECTIONS = [
@@ -268,12 +259,7 @@ export function parseTaskFrontmatter(content) {
268
259
  frontmatter.controlReadable = false;
269
260
  }
270
261
  else {
271
- try {
272
- frontmatter.rawControl = JSON.parse(value);
273
- }
274
- catch {
275
- // Leave rawControl unset; the parse below reports the real problem.
276
- }
262
+ frontmatter.controlRaw = value;
277
263
  try {
278
264
  frontmatter.control = parseTaskControl(value);
279
265
  frontmatter.controlReadable = true;
@@ -293,34 +279,18 @@ export function parseTaskFrontmatter(content) {
293
279
  else if (key === "closedAt") {
294
280
  frontmatter.closedAt = value || undefined;
295
281
  }
296
- else if (key === "status" || key === "wake" || key === "schedule" || key === "recurrence") {
282
+ else if (key === "status" || key === "wake" || key === "schedule") {
297
283
  frontmatter[key] = value || undefined;
298
284
  }
299
285
  }
300
286
  }
301
- // Canonicalise the possibly legacy status on read. Terminal v1 values are marked as archive
302
- // outcomes so an active-directory scan can never execute them before startup migration moves
303
- // them. A legacy recurring terminal is the v2 sleeping state.
287
+ // Legacy status vocabulary is a startup-migration concern (`migrateLegacyTaskState`), not a
288
+ // read-time one: any value outside the current three fails open to "active" here, same as an
289
+ // unreadable control block fails open to "actionable" rather than being silently reinterpreted.
304
290
  const rawStatus = frontmatter.status;
305
291
  frontmatter.rawStatus = rawStatus;
306
292
  if (frontmatter.readable) {
307
- if (rawStatus === "done" && !frontmatter.schedule)
308
- frontmatter.archiveOutcome = "completed";
309
- if (rawStatus === "cancelled")
310
- frontmatter.archiveOutcome = "cancelled";
311
- frontmatter.status = normalizeStoredStatus(rawStatus, Boolean(frontmatter.schedule));
312
- if (rawStatus === "paused" || wasLegacyEscalated(rawStatus)) {
313
- frontmatter.enabled = false;
314
- frontmatter.control ??= createDefaultTaskControl();
315
- if (frontmatter.control && !frontmatter.control.stop) {
316
- frontmatter.control.stop = {
317
- by: wasLegacyEscalated(rawStatus) ? "governor" : "user",
318
- reason: frontmatter.control.blockedReason ??
319
- `Task stopped by ${wasLegacyEscalated(rawStatus) ? "governor" : "user"}.`,
320
- at: formatLocalTime(),
321
- };
322
- }
323
- }
293
+ frontmatter.status = normalizeStoredStatus(rawStatus);
324
294
  }
325
295
  return frontmatter;
326
296
  }
@@ -396,7 +366,7 @@ export function missingStandardTaskSections(content) {
396
366
  * Without the "no checklist items" case, a DoD written as prose or a numbered
397
367
  * list (no `- [ ]` anywhere) makes this function return an empty array —
398
368
  * indistinguishable from "everything is checked" — which would silently let
399
- * `task_manage request-verification`/`complete` through with nothing ever actually verified.
369
+ * `task_manage complete` through with nothing ever actually verified.
400
370
  */
401
371
  export function uncheckedTaskAcceptanceItems(content) {
402
372
  const unchecked = [];
@@ -507,14 +477,14 @@ export function renderStandardTaskBody(input) {
507
477
  ].join("\n");
508
478
  }
509
479
  /**
510
- * Enforce the v2 write-path invariants. Runtime due transitions are intentionally separate: a
480
+ * Enforce the v3 write-path invariants. Runtime due transitions are intentionally separate: a
511
481
  * waiting task is first written active, and a sleeping task is first opened into a cycle, before
512
482
  * the driver dispatches anything.
513
483
  */
514
484
  export function normalizeTaskFields(fields, now = new Date()) {
515
485
  const next = {
516
486
  ...fields,
517
- status: normalizeStoredStatus(fields.status, Boolean(fields.schedule)),
487
+ status: normalizeStoredStatus(fields.status),
518
488
  enabled: fields.enabled !== false,
519
489
  };
520
490
  if (next.outcome) {
@@ -605,8 +575,6 @@ export function renderTaskDocument(fields, rawBody) {
605
575
  lines.push(`wake: ${document.wake}`);
606
576
  if (document.schedule)
607
577
  lines.push(`schedule: ${document.schedule}`);
608
- if (document.recurrence)
609
- lines.push(`recurrence: ${document.recurrence}`);
610
578
  if (document.control)
611
579
  lines.push(`control: ${JSON.stringify(document.control)}`);
612
580
  lines.push("---");
@@ -982,17 +950,13 @@ function parseWakeMs(frontmatter) {
982
950
  return undefined;
983
951
  return parseLocalTime(frontmatter.wake);
984
952
  }
985
- /** Actionable first; then earliest wake first (unset wake sorts as "ready now"); then id. */
953
+ /** Actionable first; then earliest deadline/wake first (unset sorts as "ready now"); then id. */
986
954
  export function compareTaskEntries(a, b) {
987
955
  if (a.actionable !== b.actionable)
988
956
  return a.actionable ? -1 : 1;
989
957
  if (a.frontmatter.enabled !== b.frontmatter.enabled)
990
958
  return a.frontmatter.enabled ? -1 : 1;
991
959
  if (a.actionable && b.actionable) {
992
- const ap = taskPriorityRank(a.frontmatter.control?.priority ?? "normal");
993
- const bp = taskPriorityRank(b.frontmatter.control?.priority ?? "normal");
994
- if (ap !== bp)
995
- return ap - bp;
996
960
  const ad = a.frontmatter.control?.deadline
997
961
  ? (parseLocalTime(a.frontmatter.control.deadline) ?? Number.POSITIVE_INFINITY)
998
962
  : Number.POSITIVE_INFINITY;