@oyasmi/pipiclaw 0.8.10 → 0.8.11-beta.3
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.
- package/README.md +3 -3
- package/dist/agent/channel-runner.d.ts +11 -0
- package/dist/agent/channel-runner.js +58 -27
- package/dist/agent/commands.js +2 -3
- package/dist/agent/effect-ledger.d.ts +1 -1
- package/dist/agent/effect-ledger.js +2 -2
- package/dist/agent/prompt/sections.js +3 -3
- package/dist/agent/runner-factory.d.ts +2 -0
- package/dist/agent/session-events.js +1 -1
- package/dist/main.js +6 -0
- package/dist/memory/commands.js +6 -1
- package/dist/memory/consolidation.d.ts +8 -1
- package/dist/memory/consolidation.js +34 -6
- package/dist/memory/extraction.d.ts +11 -3
- package/dist/memory/extraction.js +19 -6
- package/dist/memory/files.d.ts +2 -0
- package/dist/memory/files.js +14 -0
- package/dist/memory/maintenance-gates.d.ts +3 -0
- package/dist/memory/maintenance-gates.js +5 -2
- package/dist/memory/maintenance-jobs.js +19 -2
- package/dist/memory/maintenance-state.d.ts +29 -0
- package/dist/memory/maintenance-state.js +100 -8
- package/dist/memory/metadata.d.ts +9 -0
- package/dist/memory/metadata.js +5 -0
- package/dist/memory/probation.d.ts +21 -0
- package/dist/memory/probation.js +48 -0
- package/dist/memory/promotion.d.ts +26 -1
- package/dist/memory/promotion.js +34 -4
- package/dist/memory/recall.js +38 -19
- package/dist/memory/session-corpus.js +12 -11
- package/dist/memory/session-search.js +25 -6
- package/dist/memory/sidecar-worker.js +2 -0
- package/dist/memory/task-digest.d.ts +3 -2
- package/dist/memory/task-digest.js +22 -8
- package/dist/models/auth-cli.d.ts +25 -0
- package/dist/models/auth-cli.js +344 -0
- package/dist/models/login-ui.d.ts +35 -0
- package/dist/models/login-ui.js +145 -0
- package/dist/models/provider-login.d.ts +41 -0
- package/dist/models/provider-login.js +126 -0
- package/dist/models/utils.d.ts +6 -0
- package/dist/models/utils.js +10 -0
- package/dist/playbooks/memory-and-learning.md +7 -1
- package/dist/playbooks/outbound-media.md +7 -33
- package/dist/playbooks/runtime-orientation.md +2 -0
- package/dist/playbooks/task-closeout.md +22 -35
- package/dist/playbooks/task-delegation.md +13 -35
- package/dist/playbooks/task-driving.md +36 -56
- package/dist/playbooks/task-planning.md +26 -45
- package/dist/runtime/bootstrap.js +48 -14
- package/dist/runtime/delivery.js +8 -2
- package/dist/runtime/dingtalk.d.ts +6 -3
- package/dist/runtime/dingtalk.js +6 -39
- package/dist/runtime/events.js +4 -3
- package/dist/runtime/proxy.d.ts +36 -0
- package/dist/runtime/proxy.js +68 -0
- package/dist/runtime/store.d.ts +8 -2
- package/dist/runtime/store.js +12 -6
- package/dist/runtime/task-commands.d.ts +0 -2
- package/dist/runtime/task-commands.js +99 -112
- package/dist/runtime/task-driver.d.ts +5 -0
- package/dist/runtime/task-driver.js +155 -53
- package/dist/runtime/task-migration.d.ts +9 -0
- package/dist/runtime/task-migration.js +75 -2
- package/dist/security/command-guard.js +51 -17
- package/dist/security/path-guard.js +72 -14
- package/dist/shared/open-browser.d.ts +6 -0
- package/dist/shared/open-browser.js +22 -0
- package/dist/shared/recoverable-error.d.ts +1 -1
- package/dist/shared/recoverable-error.js +1 -1
- package/dist/subagents/tool.js +2 -0
- package/dist/tasks/control.d.ts +38 -67
- package/dist/tasks/control.js +90 -152
- package/dist/tasks/ledger.d.ts +104 -22
- package/dist/tasks/ledger.js +419 -56
- package/dist/tasks/store.d.ts +11 -10
- package/dist/tasks/store.js +58 -27
- package/dist/tasks/transitions.d.ts +8 -36
- package/dist/tasks/transitions.js +29 -54
- package/dist/tasks/verification.d.ts +2 -2
- package/dist/tools/index.d.ts +2 -0
- package/dist/tools/index.js +1 -0
- package/dist/tools/memory-manage.js +8 -1
- package/dist/tools/read.js +19 -5
- package/dist/tools/registry.d.ts +1 -0
- package/dist/tools/registry.js +1 -0
- package/dist/tools/task-manage/lifecycle.d.ts +1 -7
- package/dist/tools/task-manage/lifecycle.js +76 -77
- package/dist/tools/task-manage/schema.d.ts +10 -5
- package/dist/tools/task-manage/schema.js +35 -21
- package/dist/tools/task-manage/shared.d.ts +1 -1
- package/dist/tools/task-manage/shared.js +29 -30
- package/dist/tools/task-manage/types.d.ts +7 -1
- package/dist/tools/task-manage/verification.d.ts +4 -5
- package/dist/tools/task-manage/verification.js +43 -15
- package/dist/tools/task-manage.d.ts +1 -1
- package/dist/tools/task-manage.js +9 -9
- package/dist/tui/app.js +1 -2
- package/dist/tui/commands.d.ts +1 -1
- package/dist/tui/commands.js +1 -1
- package/dist/tui/turn-controller.d.ts +1 -1
- package/dist/usage/ledger.d.ts +1 -1
- package/dist/usage/ledger.js +47 -22
- package/dist/usage/render.d.ts +1 -1
- package/dist/usage/render.js +8 -6
- package/package.json +7 -6
package/dist/tasks/control.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { formatLocalTime, parseLocalTime } from "../shared/local-time.js";
|
|
2
2
|
import { errorMessage } from "../shared/text-utils.js";
|
|
3
3
|
export const TASK_PRIORITIES = ["low", "normal", "high", "critical"];
|
|
4
|
-
const
|
|
4
|
+
const WAITING_FOR = ["time", "user", "job", "verification", "external-signal"];
|
|
5
5
|
const VERIFICATION_STATUSES = ["pending", "passed", "failed"];
|
|
6
6
|
const OUTCOMES = ["pending", "running", "progress", "blocked", "failed"];
|
|
7
|
-
|
|
7
|
+
function normalizeLegacyOutcome(value) {
|
|
8
|
+
return value === "verified" || value === "skipped" ? "progress" : value;
|
|
9
|
+
}
|
|
8
10
|
function isRecord(value) {
|
|
9
11
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10
12
|
}
|
|
@@ -46,16 +48,6 @@ function optionalPositive(value) {
|
|
|
46
48
|
}
|
|
47
49
|
return value;
|
|
48
50
|
}
|
|
49
|
-
/**
|
|
50
|
-
* Read `verification.required`, mapping the retired `mode` enum losslessly (spec 036, D5/D8):
|
|
51
|
-
* `"independent"` was the only form that gated `done`, so it becomes `true`; `"evidence"` was
|
|
52
|
-
* maker self-certification and becomes `false`.
|
|
53
|
-
*/
|
|
54
|
-
function parseVerificationRequired(verification) {
|
|
55
|
-
if (typeof verification.required === "boolean")
|
|
56
|
-
return verification.required;
|
|
57
|
-
return verification.mode === "independent";
|
|
58
|
-
}
|
|
59
51
|
function enumValue(value, values, fallback) {
|
|
60
52
|
if (value === undefined)
|
|
61
53
|
return fallback;
|
|
@@ -64,39 +56,49 @@ function enumValue(value, values, fallback) {
|
|
|
64
56
|
}
|
|
65
57
|
return value;
|
|
66
58
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
+
function parseStop(value) {
|
|
66
|
+
if (value === undefined)
|
|
67
|
+
return undefined;
|
|
68
|
+
if (!isRecord(value))
|
|
69
|
+
throw new Error("control.stop must be an object");
|
|
70
|
+
const by = enumValue(value.by, ["user", "governor"], "user");
|
|
71
|
+
const reason = optionalString(value.reason);
|
|
72
|
+
const at = optionalString(value.at);
|
|
73
|
+
if (!reason || !at || parseLocalTime(at) === undefined) {
|
|
74
|
+
throw new Error("control.stop requires a reason and valid at timestamp");
|
|
75
|
+
}
|
|
76
|
+
return { by, reason, at: formatLocalTime(new Date(parseLocalTime(at))) };
|
|
77
|
+
}
|
|
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");
|
|
89
88
|
}
|
|
89
|
+
return { createdBy, createdAt, sourceMessageId };
|
|
90
90
|
}
|
|
91
91
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
* Ignoring them keeps stored tasks readable with no migration script, but silence would be
|
|
95
|
-
* wrong for `parent`/`dependsOn`: the task survives, the ordering constraint it expressed does
|
|
96
|
-
* not. `/tasks doctor` reports whatever a stored control block still carries so the loss is
|
|
97
|
-
* visible rather than silent.
|
|
92
|
+
* Keys from the v1 control block that this version deliberately retires. They remain visible to
|
|
93
|
+
* doctor until the next successful write, but they never enter the v2 control object.
|
|
98
94
|
*/
|
|
99
95
|
export const RETIRED_TASK_CONTROL_KEYS = [
|
|
96
|
+
"sideEffects",
|
|
97
|
+
"externalApproval",
|
|
98
|
+
"approvalBy",
|
|
99
|
+
"approvedAt",
|
|
100
|
+
"approvalBodyHash",
|
|
101
|
+
"pausedBy",
|
|
100
102
|
"parent",
|
|
101
103
|
"dependsOn",
|
|
102
104
|
"worktree",
|
|
@@ -106,7 +108,7 @@ export const RETIRED_TASK_CONTROL_KEYS = [
|
|
|
106
108
|
"budget.maxCostUsd",
|
|
107
109
|
"budget.maxWallTimeMinutes",
|
|
108
110
|
];
|
|
109
|
-
/** Retired keys actually present in a raw stored control block
|
|
111
|
+
/** Retired keys actually present in a raw stored control block. */
|
|
110
112
|
export function retiredTaskControlKeys(raw) {
|
|
111
113
|
if (!isRecord(raw))
|
|
112
114
|
return [];
|
|
@@ -118,13 +120,10 @@ export function retiredTaskControlKeys(raw) {
|
|
|
118
120
|
return isRecord(parent) && Object.hasOwn(parent, nested);
|
|
119
121
|
});
|
|
120
122
|
}
|
|
121
|
-
export function createDefaultTaskControl(requiresVerification = false) {
|
|
123
|
+
export function createDefaultTaskControl(requiresVerification = false, provenance) {
|
|
122
124
|
return {
|
|
123
|
-
version:
|
|
125
|
+
version: 2,
|
|
124
126
|
priority: "normal",
|
|
125
|
-
lastOutcome: "pending",
|
|
126
|
-
sideEffects: "workspace",
|
|
127
|
-
externalApproval: "not-required",
|
|
128
127
|
budget: { maxAttempts: 12 },
|
|
129
128
|
usage: {
|
|
130
129
|
attempts: 0,
|
|
@@ -135,8 +134,14 @@ export function createDefaultTaskControl(requiresVerification = false) {
|
|
|
135
134
|
},
|
|
136
135
|
verification: { required: requiresVerification, status: "pending" },
|
|
137
136
|
attemptGeneration: 0,
|
|
137
|
+
lastOutcome: "pending",
|
|
138
|
+
...(provenance ? { provenance } : {}),
|
|
138
139
|
};
|
|
139
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Read both v1 and v2 files. Retired v1 policy fields are intentionally ignored; the next
|
|
143
|
+
* write emits a v2 object without them. This is a reader migration, not command compatibility.
|
|
144
|
+
*/
|
|
140
145
|
export function parseTaskControl(raw) {
|
|
141
146
|
let value;
|
|
142
147
|
try {
|
|
@@ -145,8 +150,8 @@ export function parseTaskControl(raw) {
|
|
|
145
150
|
catch (error) {
|
|
146
151
|
throw new Error(`control is not valid JSON: ${errorMessage(error)}`);
|
|
147
152
|
}
|
|
148
|
-
if (!isRecord(value) || value.version !== 1) {
|
|
149
|
-
throw new Error("control must be a version 1 JSON object");
|
|
153
|
+
if (!isRecord(value) || (value.version !== 1 && value.version !== 2)) {
|
|
154
|
+
throw new Error("control must be a version 1 or version 2 JSON object; repair it with task_manage set.");
|
|
150
155
|
}
|
|
151
156
|
const budget = isRecord(value.budget) ? value.budget : {};
|
|
152
157
|
const usage = isRecord(value.usage) ? value.usage : {};
|
|
@@ -160,32 +165,25 @@ export function parseTaskControl(raw) {
|
|
|
160
165
|
if (deadline && parseLocalTime(deadline) === undefined) {
|
|
161
166
|
throw new Error("control.deadline must be a valid local time");
|
|
162
167
|
}
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
!/^[a-f0-9]{64}$/i.test(approvalBodyHash))) {
|
|
175
|
-
throw new Error("granted external approval requires external side effects, approvalBy, approvedAt, and approvalBodyHash");
|
|
168
|
+
const waitingFor = value.waitingFor === undefined ? undefined : enumValue(value.waitingFor, WAITING_FOR, "external-signal");
|
|
169
|
+
let stop = parseStop(value.stop);
|
|
170
|
+
// v1 stored the stop dimension as a status-side `pausedBy` value. Preserve its
|
|
171
|
+
// operational meaning while converting it to the v2 structured record.
|
|
172
|
+
if (!stop && value.pausedBy !== undefined) {
|
|
173
|
+
const by = enumValue(value.pausedBy, ["user", "governor"], "user");
|
|
174
|
+
stop = {
|
|
175
|
+
by,
|
|
176
|
+
reason: optionalString(value.blockedReason) ?? `Task stopped by ${by}.`,
|
|
177
|
+
at: formatLocalTime(),
|
|
178
|
+
};
|
|
176
179
|
}
|
|
177
180
|
return {
|
|
178
|
-
version:
|
|
181
|
+
version: 2,
|
|
179
182
|
priority: enumValue(value.priority, TASK_PRIORITIES, "normal"),
|
|
180
183
|
deadline,
|
|
181
184
|
nextAction: optionalString(value.nextAction),
|
|
182
|
-
lastOutcome: enumValue(canonicalEnumValue(value.lastOutcome), OUTCOMES, "pending"),
|
|
183
185
|
blockedReason: optionalString(value.blockedReason),
|
|
184
|
-
|
|
185
|
-
externalApproval,
|
|
186
|
-
approvalBy,
|
|
187
|
-
approvedAt,
|
|
188
|
-
approvalBodyHash,
|
|
186
|
+
waitingFor,
|
|
189
187
|
budget: { maxAttempts: Math.max(1, Math.floor(maxAttempts)) },
|
|
190
188
|
usage: parsedUsage,
|
|
191
189
|
verification: {
|
|
@@ -198,13 +196,18 @@ export function parseTaskControl(raw) {
|
|
|
198
196
|
subjectHash: optionalString(verification.subjectHash),
|
|
199
197
|
},
|
|
200
198
|
attemptGeneration: nonNegativeInteger(value.attemptGeneration),
|
|
199
|
+
lastOutcome: enumValue(normalizeLegacyOutcome(value.lastOutcome), OUTCOMES, "pending"),
|
|
201
200
|
lastStartedAt: optionalString(value.lastStartedAt),
|
|
202
201
|
lastFinishedAt: optionalString(value.lastFinishedAt),
|
|
203
202
|
cycleId: optionalString(value.cycleId),
|
|
204
|
-
|
|
203
|
+
stop,
|
|
204
|
+
provenance: parseProvenance(value.provenance),
|
|
205
205
|
};
|
|
206
206
|
}
|
|
207
|
-
|
|
207
|
+
function zeroUsage() {
|
|
208
|
+
return { attempts: 0, tokens: 0, costUsd: 0, costKnown: true, wallTimeMinutes: 0 };
|
|
209
|
+
}
|
|
210
|
+
/** Reset state that is meaningful only within one recurring task cycle. */
|
|
208
211
|
export function resetTaskControlForCycle(control, cycleId) {
|
|
209
212
|
const normalizedCycleId = cycleId.trim();
|
|
210
213
|
if (!normalizedCycleId)
|
|
@@ -214,29 +217,13 @@ export function resetTaskControlForCycle(control, cycleId) {
|
|
|
214
217
|
nextAction: undefined,
|
|
215
218
|
lastOutcome: "pending",
|
|
216
219
|
blockedReason: undefined,
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
? "required"
|
|
221
|
-
: "not-required",
|
|
222
|
-
approvalBy: undefined,
|
|
223
|
-
approvedAt: undefined,
|
|
224
|
-
approvalBodyHash: undefined,
|
|
225
|
-
usage: {
|
|
226
|
-
attempts: 0,
|
|
227
|
-
tokens: 0,
|
|
228
|
-
costUsd: 0,
|
|
229
|
-
costKnown: true,
|
|
230
|
-
wallTimeMinutes: 0,
|
|
231
|
-
},
|
|
232
|
-
verification: {
|
|
233
|
-
required: control.verification.required,
|
|
234
|
-
status: "pending",
|
|
235
|
-
},
|
|
220
|
+
waitingFor: undefined,
|
|
221
|
+
usage: zeroUsage(),
|
|
222
|
+
verification: { required: control.verification.required, status: "pending" },
|
|
236
223
|
lastStartedAt: undefined,
|
|
237
224
|
lastFinishedAt: undefined,
|
|
238
225
|
cycleId: normalizedCycleId,
|
|
239
|
-
|
|
226
|
+
stop: undefined,
|
|
240
227
|
};
|
|
241
228
|
}
|
|
242
229
|
function patchOptionalString(current, value) {
|
|
@@ -246,25 +233,20 @@ function patchOptionalString(current, value) {
|
|
|
246
233
|
}
|
|
247
234
|
export function applyTaskControlPatch(control, patch) {
|
|
248
235
|
const next = structuredClone(control);
|
|
249
|
-
const invalidatesApproval = control.externalApproval === "granted" && Object.keys(patch).length > 0;
|
|
250
|
-
const explicitlySetsExternalApproval = patch.externalApproval !== undefined;
|
|
251
236
|
if (patch.priority !== undefined)
|
|
252
237
|
next.priority = patch.priority;
|
|
253
238
|
let normalizedDeadlinePatch = patch.deadline;
|
|
254
239
|
if (patch.deadline?.trim()) {
|
|
255
240
|
const deadlineMs = parseLocalTime(patch.deadline);
|
|
256
|
-
if (deadlineMs === undefined)
|
|
241
|
+
if (deadlineMs === undefined)
|
|
257
242
|
throw new Error(`deadline "${patch.deadline}" is not a valid local time.`);
|
|
258
|
-
}
|
|
259
243
|
normalizedDeadlinePatch = formatLocalTime(new Date(deadlineMs));
|
|
260
244
|
}
|
|
261
245
|
next.deadline = patchOptionalString(next.deadline, normalizedDeadlinePatch);
|
|
262
246
|
next.nextAction = patchOptionalString(next.nextAction, patch.nextAction);
|
|
263
247
|
next.blockedReason = patchOptionalString(next.blockedReason, patch.blockedReason);
|
|
264
|
-
if (patch.
|
|
265
|
-
next.
|
|
266
|
-
if (patch.externalApproval !== undefined)
|
|
267
|
-
next.externalApproval = patch.externalApproval;
|
|
248
|
+
if (patch.waitingFor !== undefined)
|
|
249
|
+
next.waitingFor = patch.waitingFor;
|
|
268
250
|
if (patch.maxAttempts !== undefined) {
|
|
269
251
|
if (!Number.isInteger(patch.maxAttempts) || patch.maxAttempts < 1) {
|
|
270
252
|
throw new Error("maxAttempts must be a positive integer.");
|
|
@@ -272,72 +254,28 @@ export function applyTaskControlPatch(control, patch) {
|
|
|
272
254
|
next.budget.maxAttempts = patch.maxAttempts;
|
|
273
255
|
}
|
|
274
256
|
if (patch.verificationRequired !== undefined && patch.verificationRequired !== next.verification.required) {
|
|
275
|
-
next.verification = {
|
|
276
|
-
required: patch.verificationRequired,
|
|
277
|
-
status: "pending",
|
|
278
|
-
};
|
|
279
|
-
}
|
|
280
|
-
if (next.sideEffects !== "external") {
|
|
281
|
-
next.externalApproval = "not-required";
|
|
282
|
-
next.approvalBy = undefined;
|
|
283
|
-
next.approvedAt = undefined;
|
|
284
|
-
next.approvalBodyHash = undefined;
|
|
285
|
-
}
|
|
286
|
-
if (control.sideEffects !== "external" && next.sideEffects === "external" && !explicitlySetsExternalApproval) {
|
|
287
|
-
next.externalApproval = "required";
|
|
288
|
-
}
|
|
289
|
-
// Spec 036 D5: a task that changes an outside system is exactly the one nobody is watching
|
|
290
|
-
// under unattended operation, so it defaults to requiring independent acceptance. An explicit
|
|
291
|
-
// `verificationRequired: false` still wins.
|
|
292
|
-
if (control.sideEffects !== "external" &&
|
|
293
|
-
next.sideEffects === "external" &&
|
|
294
|
-
patch.verificationRequired === undefined &&
|
|
295
|
-
!next.verification.required) {
|
|
296
|
-
next.verification = { required: true, status: "pending" };
|
|
297
|
-
}
|
|
298
|
-
if (invalidatesApproval && next.sideEffects === "external" && !explicitlySetsExternalApproval) {
|
|
299
|
-
next.externalApproval = "required";
|
|
300
|
-
}
|
|
301
|
-
if (next.externalApproval !== "granted") {
|
|
302
|
-
next.approvalBy = undefined;
|
|
303
|
-
next.approvedAt = undefined;
|
|
304
|
-
next.approvalBodyHash = undefined;
|
|
257
|
+
next.verification = { required: patch.verificationRequired, status: "pending" };
|
|
305
258
|
}
|
|
306
259
|
return next;
|
|
307
260
|
}
|
|
308
261
|
export function taskPriorityRank(priority) {
|
|
309
262
|
return { critical: 0, high: 1, normal: 2, low: 3 }[priority];
|
|
310
263
|
}
|
|
311
|
-
|
|
264
|
+
/**
|
|
265
|
+
* Return a deterministic governance violation for a live task. Sleeping tasks have no current
|
|
266
|
+
* work, so neither a deadline nor an attempt budget may stop them. Waiting tasks are subject to
|
|
267
|
+
* their deadline but do not spend attempt budget while parked.
|
|
268
|
+
*/
|
|
269
|
+
export function taskBudgetViolation(control, nowMs, status = "active") {
|
|
270
|
+
if (status === "sleeping")
|
|
271
|
+
return undefined;
|
|
312
272
|
if (control.deadline) {
|
|
313
273
|
const deadlineMs = parseLocalTime(control.deadline);
|
|
314
274
|
if (deadlineMs !== undefined && deadlineMs < nowMs)
|
|
315
275
|
return `deadline exceeded (${control.deadline})`;
|
|
316
276
|
}
|
|
317
|
-
if (control.usage.attempts >= control.budget.maxAttempts) {
|
|
277
|
+
if (status === "active" && control.usage.attempts >= control.budget.maxAttempts) {
|
|
318
278
|
return `attempt budget exhausted (${control.usage.attempts}/${control.budget.maxAttempts})`;
|
|
319
279
|
}
|
|
320
280
|
return undefined;
|
|
321
281
|
}
|
|
322
|
-
export function invalidateTaskVerification(control) {
|
|
323
|
-
if (control.verification.status === "pending")
|
|
324
|
-
return control;
|
|
325
|
-
return {
|
|
326
|
-
...control,
|
|
327
|
-
verification: {
|
|
328
|
-
required: control.verification.required,
|
|
329
|
-
status: "pending",
|
|
330
|
-
},
|
|
331
|
-
};
|
|
332
|
-
}
|
|
333
|
-
export function invalidateTaskApproval(control) {
|
|
334
|
-
if (control.sideEffects !== "external" || control.externalApproval !== "granted")
|
|
335
|
-
return control;
|
|
336
|
-
return {
|
|
337
|
-
...control,
|
|
338
|
-
externalApproval: "required",
|
|
339
|
-
approvalBy: undefined,
|
|
340
|
-
approvedAt: undefined,
|
|
341
|
-
approvalBodyHash: undefined,
|
|
342
|
-
};
|
|
343
|
-
}
|
package/dist/tasks/ledger.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type TaskControl } from "./control.js";
|
|
2
|
+
export type TaskArchiveOutcome = "completed" | "cancelled";
|
|
2
3
|
/**
|
|
3
4
|
* Shared reader for the task ledger (`workspace/<channelId>/tasks/*.md`).
|
|
4
5
|
*
|
|
@@ -7,7 +8,7 @@ import { type TaskControl } from "./control.js";
|
|
|
7
8
|
* halves — a dependency-free `tasks-pending.mjs` sensor under workspace/skills was the
|
|
8
9
|
* other — but the native TaskDriver (spec 022) replaced that sensor, so `actionable` now
|
|
9
10
|
* has a single owner. The parsing stays deliberately literal (flat `key: value` fields,
|
|
10
|
-
*
|
|
11
|
+
* live-vs-archived, wake gating, fail-open on unreadable frontmatter) because task files
|
|
11
12
|
* are hand-editable and must degrade toward "wake me up so I can be fixed".
|
|
12
13
|
* `/tasks`, the task digest, and `task_manage list` all read through here.
|
|
13
14
|
*/
|
|
@@ -15,6 +16,12 @@ export interface TaskFrontmatter {
|
|
|
15
16
|
/** false => frontmatter could not be read (fail-open: the task is treated as actionable). */
|
|
16
17
|
readable: boolean;
|
|
17
18
|
status?: string;
|
|
19
|
+
/** Raw status before the v1 reader migration, for deterministic startup migration/doctor. */
|
|
20
|
+
rawStatus?: string;
|
|
21
|
+
/** True when a legacy terminal file in the active directory needs archiving. */
|
|
22
|
+
archiveOutcome?: TaskArchiveOutcome;
|
|
23
|
+
closedAt?: string;
|
|
24
|
+
enabled: boolean;
|
|
18
25
|
wake?: string;
|
|
19
26
|
/** Five-field cron cadence (host timezone). Present ⇒ this is a recurring task. */
|
|
20
27
|
schedule?: string;
|
|
@@ -41,6 +48,8 @@ export interface TaskLedgerEntry {
|
|
|
41
48
|
wakeMs?: number;
|
|
42
49
|
/** First bullet/line under a "当前周期"/"current cycle" heading, if any (digest only). */
|
|
43
50
|
latestNote?: string;
|
|
51
|
+
/** Parsed `## Plan` section, if the task has one (spec 037, D2). */
|
|
52
|
+
plan?: TaskPlanSummary;
|
|
44
53
|
}
|
|
45
54
|
export interface TaskSkeletonInput {
|
|
46
55
|
title: string;
|
|
@@ -49,6 +58,8 @@ export interface TaskSkeletonInput {
|
|
|
49
58
|
manual?: string;
|
|
50
59
|
verificationPlan?: string;
|
|
51
60
|
verificationRequired?: boolean;
|
|
61
|
+
/** Optional initial `## Plan` steps, one per line; a missing `P<n>` prefix is auto-assigned. */
|
|
62
|
+
plan?: string;
|
|
52
63
|
}
|
|
53
64
|
export declare const DEFAULT_TASK_MANUAL = "- Follow the DoD, keep the current cycle log updated, and schedule check-ins when waiting.";
|
|
54
65
|
export declare const STANDARD_TASK_SECTIONS: readonly [{
|
|
@@ -78,16 +89,76 @@ export declare function normalizeTaskId(id: string): string;
|
|
|
78
89
|
/** The document body after the leading frontmatter block, or the whole content when there is none. */
|
|
79
90
|
export declare function taskBody(content: string): string;
|
|
80
91
|
/**
|
|
81
|
-
* The task's *contract* segment: the body up to (excluding)
|
|
82
|
-
* i.e. the H1 title, Goal, DoD (with its checkbox state), Manual and
|
|
92
|
+
* The task's *contract* segment: the body up to (excluding) whichever of "Plan" or "Current
|
|
93
|
+
* Cycle" appears first — i.e. the H1 title, Goal, DoD (with its checkbox state), Manual and
|
|
94
|
+
* Verification (spec 029, D4).
|
|
83
95
|
*
|
|
84
|
-
* Verification PASS
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
96
|
+
* Verification PASS binds to this segment, not the whole body, so routine `progress` notes
|
|
97
|
+
* (Current Cycle, and — spec 037, D1 — Plan step status) never invalidate a PASS; only a change
|
|
98
|
+
* to what the task promises to do and how it is checked does.
|
|
99
|
+
* Plan is deliberately excluded from the contract even though it always precedes Current Cycle
|
|
100
|
+
* in a freshly rendered skeleton: it is the task's *means*, not its promise, and is meant to be
|
|
101
|
+
* revised without re-triggering verification. This also means a task with an existing PASS can
|
|
102
|
+
* have `## Plan` inserted between Verification and Current Cycle with the contract segment
|
|
103
|
+
* unchanged byte-for-byte, as long as nothing before it changed.
|
|
104
|
+
* A body without either heading (non-standard) falls back to the whole body.
|
|
88
105
|
*/
|
|
89
106
|
export declare function taskContractSegment(body: string): string;
|
|
90
|
-
|
|
107
|
+
export type TaskPlanStepStatus = "todo" | "done" | "blocked" | "dropped";
|
|
108
|
+
export interface TaskPlanStep {
|
|
109
|
+
/** `P<n>` by convention; a hand-written step without one gets its position as a fallback. */
|
|
110
|
+
id: string;
|
|
111
|
+
status: TaskPlanStepStatus;
|
|
112
|
+
text: string;
|
|
113
|
+
/** DoD item numbers this step claims to cover, from a trailing `→ dod:1,2` (or `-> dod:1,2`). */
|
|
114
|
+
dodRefs: number[];
|
|
115
|
+
lineIndex: number;
|
|
116
|
+
}
|
|
117
|
+
export interface TaskPlanSummary {
|
|
118
|
+
steps: TaskPlanStep[];
|
|
119
|
+
/** Count of steps, excluding `dropped` ones. */
|
|
120
|
+
total: number;
|
|
121
|
+
done: number;
|
|
122
|
+
/** The first `todo` or `blocked` step in document order; `undefined` once nothing is left to do. */
|
|
123
|
+
current?: TaskPlanStep;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Parse the optional `## Plan` section: a fourth, hand-maintained layer between the contract
|
|
127
|
+
* (Goal/DoD/Manual/Verification) and the append-only Current Cycle/History log (spec 037, D2).
|
|
128
|
+
*
|
|
129
|
+
* Four checkbox states — `[ ]` todo, `[x]` done, `[!]` blocked, `[~]` dropped — and no separate
|
|
130
|
+
* "doing" marker: the current step is *derived* (first `todo`/`blocked` in document order), not
|
|
131
|
+
* self-reported, for the same reason `task-driver.ts`'s fingerprint excludes the model's own
|
|
132
|
+
* progress notes — a runtime-derived signal cannot be talked into lying about itself.
|
|
133
|
+
*
|
|
134
|
+
* Returns `undefined` when there is no Plan heading, or the heading has no checkbox lines under
|
|
135
|
+
* it (nothing to summarize) — both read the same as "this task has no Plan yet".
|
|
136
|
+
*/
|
|
137
|
+
export declare function parseTaskPlan(content: string): TaskPlanSummary | undefined;
|
|
138
|
+
export interface TaskPlanStepPatch {
|
|
139
|
+
id: string;
|
|
140
|
+
status?: TaskPlanStepStatus;
|
|
141
|
+
text?: string;
|
|
142
|
+
}
|
|
143
|
+
export interface ApplyTaskPlanPatchResult {
|
|
144
|
+
body: string;
|
|
145
|
+
/** Human-readable delta, meant to be folded into the caller's Current Cycle note; `""` if nothing changed. */
|
|
146
|
+
summary: string;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Update or append Plan steps by id (spec 037, D3). An id that already exists gets its
|
|
150
|
+
* status/text patched in place, preserving its `dod` refs and position; an unseen id is appended
|
|
151
|
+
* as a new step (`text` is then required — there is nothing sensible to append otherwise). A task
|
|
152
|
+
* with no `## Plan` section yet gets an empty one inserted before Current Cycle first, so the
|
|
153
|
+
* very first `planSteps` call on a task is also the one that creates its Plan.
|
|
154
|
+
*
|
|
155
|
+
* The returned `summary` is deliberately not a new persisted field (see the file-level doc on
|
|
156
|
+
* `TaskPlanSummary`): it is meant to be appended to the caller's own Current Cycle note, so the
|
|
157
|
+
* change history rides on the log `startTaskCycle` already folds into History — no second,
|
|
158
|
+
* unconsumed revision counter.
|
|
159
|
+
*/
|
|
160
|
+
export declare function applyTaskPlanPatch(body: string, patches: readonly TaskPlanStepPatch[]): ApplyTaskPlanPatchResult;
|
|
161
|
+
/** Parse the leading frontmatter block and normalize legacy v1 fields in memory. */
|
|
91
162
|
export declare function parseTaskFrontmatter(content: string): TaskFrontmatter;
|
|
92
163
|
/**
|
|
93
164
|
* The single shared judgement: is there work to do on this task right now?
|
|
@@ -99,7 +170,7 @@ export declare function parseTaskFrontmatter(content: string): TaskFrontmatter;
|
|
|
99
170
|
* and only that signal may resume it. Without this the runtime's own recommended shape for
|
|
100
171
|
* delegating work (start a blocking wait as a `bash async` job, park the task, end the turn)
|
|
101
172
|
* was re-dispatched the instant the turn ended, found the job still running, answered
|
|
102
|
-
* `[SILENT]`, and after three such wakes
|
|
173
|
+
* `[SILENT]`, and after three such wakes was disabled by the governor. A `waiting` task that
|
|
103
174
|
* *does* carry a wake is an ordinary timed re-check and stays gated on that wake; an
|
|
104
175
|
* unparseable wake still fails open so a hand-edited file surfaces rather than parks forever.
|
|
105
176
|
*/
|
|
@@ -117,29 +188,40 @@ export declare function missingStandardTaskSections(content: string): string[];
|
|
|
117
188
|
* Without the "no checklist items" case, a DoD written as prose or a numbered
|
|
118
189
|
* list (no `- [ ]` anywhere) makes this function return an empty array —
|
|
119
190
|
* indistinguishable from "everything is checked" — which would silently let
|
|
120
|
-
* `task_manage
|
|
191
|
+
* `task_manage request-verification`/`complete` through with nothing ever actually verified.
|
|
121
192
|
*/
|
|
122
193
|
export declare function uncheckedTaskAcceptanceItems(content: string): string[];
|
|
194
|
+
/**
|
|
195
|
+
* Count of checkbox items (checked or not) under the DoD heading, for cross-referencing a Plan
|
|
196
|
+
* step's `→ dod:N` refs (spec 037, D4 — `/tasks doctor`'s drift checks).
|
|
197
|
+
*/
|
|
198
|
+
export declare function countTaskDodItems(content: string): number;
|
|
123
199
|
export declare function renderStandardTaskBody(input: TaskSkeletonInput): string;
|
|
124
200
|
export interface TaskDocumentFields {
|
|
125
201
|
status: string;
|
|
202
|
+
/** Raw v1 value retained only in memory for startup migration. */
|
|
203
|
+
legacyStatus?: string;
|
|
204
|
+
enabled?: boolean;
|
|
126
205
|
wake?: string;
|
|
127
206
|
schedule?: string;
|
|
128
207
|
recurrence?: string;
|
|
129
208
|
control?: TaskControl;
|
|
209
|
+
outcome?: TaskArchiveOutcome;
|
|
210
|
+
closedAt?: string;
|
|
130
211
|
}
|
|
131
212
|
/**
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
213
|
+
* Enforce the v2 write-path invariants. Runtime due transitions are intentionally separate: a
|
|
214
|
+
* waiting task is first written active, and a sleeping task is first opened into a cycle, before
|
|
215
|
+
* the driver dispatches anything.
|
|
216
|
+
*/
|
|
217
|
+
export declare function normalizeTaskFields(fields: TaskDocumentFields, now?: Date): TaskDocumentFields;
|
|
218
|
+
/**
|
|
219
|
+
* Whether an open recurring cycle has already crossed its next schedule occurrence.
|
|
220
|
+
* The runtime must keep working on the old cycle rather than opening a concurrent one.
|
|
221
|
+
* Cycle ids intentionally carry the local calendar date; the optional suffix handles a
|
|
222
|
+
* same-day manual reopen deterministically.
|
|
141
223
|
*/
|
|
142
|
-
export declare function
|
|
224
|
+
export declare function recurringTaskMissedOccurrence(fields: TaskDocumentFields, now?: Date): boolean;
|
|
143
225
|
export declare function renderTaskDocument(fields: TaskDocumentFields, rawBody: string): string;
|
|
144
226
|
/** Append one progress bullet to the standard Current Cycle section. */
|
|
145
227
|
export declare function appendCurrentCycleNote(content: string, note: string): string;
|
|
@@ -147,7 +229,7 @@ export declare function appendCurrentCycleNote(content: string, note: string): s
|
|
|
147
229
|
* Upsert the completion evidence subsection inside Current Cycle.
|
|
148
230
|
*
|
|
149
231
|
* Evidence is part of the cycle log, not a new top-level section. This makes the next
|
|
150
|
-
* `startTaskCycle` fold it into the matching History entry and prevents repeated
|
|
232
|
+
* `startTaskCycle` fold it into the matching History entry and prevents repeated completion
|
|
151
233
|
* attempts from appending duplicate evidence blocks.
|
|
152
234
|
*/
|
|
153
235
|
export declare function upsertCurrentCycleCompletionEvidence(content: string, evidenceLines: readonly string[]): string;
|
|
@@ -157,7 +239,7 @@ export declare function upsertCurrentCycleCompletionEvidence(content: string, ev
|
|
|
157
239
|
* instead of asking the model to hand-edit headings and risk appending future
|
|
158
240
|
* checkpoints to the previous cycle.
|
|
159
241
|
*/
|
|
160
|
-
export declare function startTaskCycle(content: string, cycleId: string): string;
|
|
242
|
+
export declare function startTaskCycle(content: string, cycleId: string, archivePrevious?: boolean): string;
|
|
161
243
|
/** Actionable first; then earliest wake first (unset wake sorts as "ready now"); then id. */
|
|
162
244
|
export declare function compareTaskEntries(a: TaskLedgerEntry, b: TaskLedgerEntry): number;
|
|
163
245
|
/**
|