@oyasmi/pipiclaw 0.8.8-beta.1 → 0.8.8
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 +1 -0
- package/dist/agent/channel-runner.js +8 -0
- package/dist/agent/runner-factory.d.ts +2 -0
- package/dist/playbooks/event-scheduling.md +3 -3
- package/dist/playbooks/task-closeout.md +2 -2
- package/dist/playbooks/task-recurring.md +14 -17
- package/dist/playbooks/task-repair.md +1 -1
- package/dist/runtime/bootstrap.d.ts +13 -2
- package/dist/runtime/bootstrap.js +8 -2
- package/dist/runtime/event-commands.js +1 -3
- package/dist/runtime/events.d.ts +6 -2
- package/dist/runtime/events.js +15 -6
- package/dist/runtime/task-commands.js +25 -6
- package/dist/runtime/task-driver.d.ts +36 -0
- package/dist/runtime/task-driver.js +217 -33
- package/dist/security/path-guard.js +3 -1
- package/dist/settings.d.ts +2 -0
- package/dist/settings.js +5 -0
- package/dist/shared/task-ledger.d.ts +3 -0
- package/dist/shared/task-ledger.js +41 -1
- package/dist/shared/task-schedule.d.ts +18 -0
- package/dist/shared/task-schedule.js +50 -0
- package/dist/tasks/store.js +1 -0
- package/dist/tools/event-manage.js +6 -10
- package/dist/tools/task-manage.d.ts +2 -0
- package/dist/tools/task-manage.js +84 -9
- package/package.json +5 -1
|
@@ -6,6 +6,7 @@ import { parseScheduledEventContent } from "../runtime/events.js";
|
|
|
6
6
|
import { writeFileAtomically } from "../shared/atomic-file.js";
|
|
7
7
|
import { isTaskScheduleEvent, taskEventPrefix, taskScheduleEventFilename } from "../shared/task-events.js";
|
|
8
8
|
import { appendCurrentCycleNote, normalizeTaskId, parseTaskFrontmatter, readActiveTasks, renderStandardTaskBody, renderTaskDocument, startTaskCycle, taskBody, uncheckedTaskAcceptanceItems, } from "../shared/task-ledger.js";
|
|
9
|
+
import { nextTaskWake, validateTaskSchedule } from "../shared/task-schedule.js";
|
|
9
10
|
import { workspaceSubjectHash } from "../tasks/artifact-subject.js";
|
|
10
11
|
import { applyTaskControlPatch, createDefaultTaskControl, invalidateTaskApproval, invalidateTaskVerification, resetTaskControlForCycle, } from "../tasks/control.js";
|
|
11
12
|
import { dependencyState, readStoredTask, taskBodyHash } from "../tasks/store.js";
|
|
@@ -35,7 +36,9 @@ const taskControlSchema = Type.Object({
|
|
|
35
36
|
maxTokens: Type.Optional(Type.Number({ minimum: 0, description: "0 clears this budget." })),
|
|
36
37
|
maxCostUsd: Type.Optional(Type.Number({ minimum: 0, description: "0 clears this budget." })),
|
|
37
38
|
maxWallTimeMinutes: Type.Optional(Type.Number({ minimum: 0, description: "0 clears this budget." })),
|
|
38
|
-
verificationMode: Type.Optional(Type.Union([Type.Literal("evidence"), Type.Literal("independent")]
|
|
39
|
+
verificationMode: Type.Optional(Type.Union([Type.Literal("evidence"), Type.Literal("independent")], {
|
|
40
|
+
description: 'On create, defaults to "evidence" (maker self-checks the DoD against concrete evidence). Set "independent" only when the task produces a checkable artifact (code, config, a runnable command) that a separate read-only verifier sub-agent can inspect — for research/writing/reminder-style tasks, "evidence" is cheaper and just as trustworthy.',
|
|
41
|
+
})),
|
|
39
42
|
worktreePath: Type.Optional(Type.String({ description: "Owned worktree path; empty clears it." })),
|
|
40
43
|
worktreeBranch: Type.Optional(Type.String()),
|
|
41
44
|
});
|
|
@@ -67,7 +70,11 @@ const taskManageSchema = Type.Object({
|
|
|
67
70
|
wake: Type.Optional(Type.String({
|
|
68
71
|
description: "ISO8601 earliest-recheck time for create/progress/set; empty string clears it. The native task driver resumes it; no .checkin event is needed.",
|
|
69
72
|
})),
|
|
70
|
-
|
|
73
|
+
schedule: Type.Optional(Type.String({
|
|
74
|
+
description: "Five-field cron cadence (host timezone) that makes this a recurring task; empty string clears it. " +
|
|
75
|
+
"On done, the driver sleeps the task until the next occurrence and re-opens it with start-cycle. Min every 30 minutes.",
|
|
76
|
+
})),
|
|
77
|
+
recurrence: Type.Optional(Type.String({ description: "Human annotation only (e.g. 每周一); empty string clears it." })),
|
|
71
78
|
note: Type.Optional(Type.String({
|
|
72
79
|
description: "Required for progress: concise Current Cycle entry covering what changed, evidence observed, and the next step.",
|
|
73
80
|
})),
|
|
@@ -147,7 +154,11 @@ function renderTaskSkeleton(request) {
|
|
|
147
154
|
const title = requiredField(request.title, "title", "create");
|
|
148
155
|
const goal = requiredField(request.goal, "goal", "create");
|
|
149
156
|
const dod = requiredField(request.dod, "dod", "create");
|
|
150
|
-
|
|
157
|
+
// Independent verification is a real tax (an extra dispatch round plus a verifier
|
|
158
|
+
// sub-agent run) that only pays off when there is something a read-only verifier can
|
|
159
|
+
// actually check. Default to evidence (maker self-checks the DoD); the tool schema asks
|
|
160
|
+
// the model to opt into independent explicitly for tasks with a checkable artifact.
|
|
161
|
+
const mode = request.control?.verificationMode ?? "evidence";
|
|
151
162
|
const control = applyTaskControlPatch(createDefaultTaskControl(mode), request.control ?? {});
|
|
152
163
|
const fields = applySet({ status: normalizeCreateStatus(request.status), control }, request);
|
|
153
164
|
const body = renderStandardTaskBody({
|
|
@@ -181,6 +192,7 @@ async function readTaskDocument(taskPath, id, allowControlRepair = false) {
|
|
|
181
192
|
fields: {
|
|
182
193
|
status: frontmatter.status ?? "open",
|
|
183
194
|
wake: frontmatter.wake,
|
|
195
|
+
schedule: frontmatter.schedule,
|
|
184
196
|
recurrence: frontmatter.recurrence,
|
|
185
197
|
control: frontmatter.control,
|
|
186
198
|
},
|
|
@@ -211,6 +223,16 @@ function applySet(fields, request) {
|
|
|
211
223
|
next.wake = trimmed;
|
|
212
224
|
}
|
|
213
225
|
}
|
|
226
|
+
if (request.schedule !== undefined) {
|
|
227
|
+
const trimmed = request.schedule.trim();
|
|
228
|
+
if (trimmed === "") {
|
|
229
|
+
next.schedule = undefined;
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
validateTaskSchedule(trimmed);
|
|
233
|
+
next.schedule = trimmed;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
214
236
|
if (request.recurrence !== undefined) {
|
|
215
237
|
const trimmed = request.recurrence.trim();
|
|
216
238
|
next.recurrence = trimmed === "" ? undefined : trimmed;
|
|
@@ -218,6 +240,12 @@ function applySet(fields, request) {
|
|
|
218
240
|
if (request.control !== undefined) {
|
|
219
241
|
next.control = applyTaskControlPatch(next.control ?? createDefaultTaskControl("evidence"), request.control);
|
|
220
242
|
}
|
|
243
|
+
// A done recurring task sleeps until its next occurrence; changing the cadence of a
|
|
244
|
+
// task that is currently done recomputes that wake in the same atomic write.
|
|
245
|
+
if (next.status === "done" && next.schedule) {
|
|
246
|
+
const nextWake = nextTaskWake(next.schedule);
|
|
247
|
+
next.wake = nextWake ? nextWake.toISOString() : undefined;
|
|
248
|
+
}
|
|
221
249
|
return next;
|
|
222
250
|
}
|
|
223
251
|
async function validateTaskRelations(options, id, fields) {
|
|
@@ -331,6 +359,23 @@ async function cleanupTaskEvents(options, id, preserveSchedule = true) {
|
|
|
331
359
|
}
|
|
332
360
|
return { deleted, hasSchedule };
|
|
333
361
|
}
|
|
362
|
+
/**
|
|
363
|
+
* Migration compat: a task may still carry a legacy canonical `.schedule` periodic event
|
|
364
|
+
* as its cadence truth (pre-027). `start-cycle` accepts such a task even without `schedule`
|
|
365
|
+
* frontmatter so an in-flight migration is not blocked mid-cycle.
|
|
366
|
+
*/
|
|
367
|
+
async function hasLegacyScheduleEvent(options, id) {
|
|
368
|
+
const eventPath = join(eventsDir(options), taskScheduleEventFilename(options.channelId, id));
|
|
369
|
+
if (!existsSync(eventPath))
|
|
370
|
+
return false;
|
|
371
|
+
try {
|
|
372
|
+
const type = parseScheduledEventContent(await readFile(eventPath, "utf-8"), taskScheduleEventFilename(options.channelId, id)).type;
|
|
373
|
+
return isTaskScheduleEvent({ use: "schedule", event: { type } });
|
|
374
|
+
}
|
|
375
|
+
catch {
|
|
376
|
+
return false;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
334
379
|
async function setTask(options, request) {
|
|
335
380
|
if (!request.id)
|
|
336
381
|
throw new Error('action "set" requires an id.');
|
|
@@ -468,6 +513,27 @@ async function verifyTask(options, request) {
|
|
|
468
513
|
notice: `任务 \`${id}\` 独立验收结果:${attestation.verdict.toUpperCase()}(run: ${runId})。`,
|
|
469
514
|
};
|
|
470
515
|
}
|
|
516
|
+
/**
|
|
517
|
+
* `verify` writes control.verification from a real attestation file, but the task Markdown
|
|
518
|
+
* itself is writable by the agent's own write/edit tools — nothing stops it from hand-crafting
|
|
519
|
+
* a "passed" verification block that was never backed by a real verifier run. Re-check the
|
|
520
|
+
* attestation file on the consuming side (done/doctor) too, not just at import time.
|
|
521
|
+
*/
|
|
522
|
+
async function assertVerificationAttestationMatches(channelDir, id, verification) {
|
|
523
|
+
if (!verification.runId) {
|
|
524
|
+
throw new Error(`Task "${id}" has no verification run id; rerun task_manage verify before done.`);
|
|
525
|
+
}
|
|
526
|
+
const attestation = await readVerificationAttestation(channelDir, verification.runId);
|
|
527
|
+
if (attestation.taskId !== id) {
|
|
528
|
+
throw new Error(`Verification run "${verification.runId}" belongs to task "${attestation.taskId}", not "${id}"; rerun verification.`);
|
|
529
|
+
}
|
|
530
|
+
if (attestation.verdict !== "pass") {
|
|
531
|
+
throw new Error(`Verification run "${verification.runId}" recorded a FAIL, not a PASS; rerun verification.`);
|
|
532
|
+
}
|
|
533
|
+
if (attestation.bodyHash !== verification.bodyHash) {
|
|
534
|
+
throw new Error(`Task "${id}" control.verification.bodyHash does not match the attestation for run "${verification.runId}"; rerun task_manage verify.`);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
471
537
|
async function unfinishedChildren(options, parentId) {
|
|
472
538
|
const entries = await readActiveTasks(tasksDir(options));
|
|
473
539
|
return entries
|
|
@@ -505,7 +571,7 @@ async function doneTask(options, request) {
|
|
|
505
571
|
}
|
|
506
572
|
if (fields.control?.verification.mode === "independent") {
|
|
507
573
|
const verification = fields.control.verification;
|
|
508
|
-
if (verification.status !== "passed" || !verification.bodyHash) {
|
|
574
|
+
if (verification.status !== "passed" || !verification.bodyHash || !verification.runId) {
|
|
509
575
|
throw new Error(`Task "${id}" requires an independent PASS. Run a purpose=verify sub-agent, then task_manage verify with its run id.`);
|
|
510
576
|
}
|
|
511
577
|
if (verification.bodyHash !== taskBodyHash(body)) {
|
|
@@ -517,18 +583,26 @@ async function doneTask(options, request) {
|
|
|
517
583
|
throw new Error(`Task "${id}" artifacts changed after its independent PASS; rerun verification before done.`);
|
|
518
584
|
}
|
|
519
585
|
}
|
|
586
|
+
await assertVerificationAttestationMatches(options.channelDir, id, verification);
|
|
520
587
|
}
|
|
521
588
|
const bodyWithEvidence = appendCompletionEvidence(body, request);
|
|
522
589
|
if (fields.control) {
|
|
523
590
|
fields.control.lastOutcome = "verified";
|
|
524
591
|
fields.control.blockedReason = undefined;
|
|
525
592
|
}
|
|
526
|
-
|
|
593
|
+
// A recurring task (schedule frontmatter) sleeps in place until its next occurrence;
|
|
594
|
+
// the wake is computed here so "done + wake" fully describes "asleep until next cycle".
|
|
595
|
+
const doneFields = fields.schedule
|
|
596
|
+
? { ...fields, status: "done", wake: nextTaskWake(fields.schedule)?.toISOString() }
|
|
597
|
+
: { ...fields, status: "done" };
|
|
598
|
+
await writeFileAtomically(taskPath, renderTaskFile(doneFields, bodyWithEvidence));
|
|
527
599
|
const { deleted, hasSchedule } = await cleanupTaskEvents(options, id);
|
|
528
|
-
//
|
|
600
|
+
// Recurring (schedule frontmatter, or a legacy .schedule event during migration) →
|
|
601
|
+
// sleeps in place; one-shot → archive.
|
|
602
|
+
const recurring = Boolean(fields.schedule) || hasSchedule;
|
|
529
603
|
let archived = false;
|
|
530
604
|
let finalPath = taskPath;
|
|
531
|
-
if (!
|
|
605
|
+
if (!recurring) {
|
|
532
606
|
const archiveDir = join(dir, "archive");
|
|
533
607
|
await mkdir(archiveDir, { recursive: true });
|
|
534
608
|
finalPath = join(archiveDir, `${id}.md`);
|
|
@@ -590,8 +664,8 @@ async function startCycleTask(options, request) {
|
|
|
590
664
|
if (fields.status !== "done") {
|
|
591
665
|
throw new Error(`Task "${id}" is ${fields.status}, not done. Finish, cancel, or explicitly resolve the current cycle before starting another.`);
|
|
592
666
|
}
|
|
593
|
-
if (!fields.
|
|
594
|
-
throw new Error(`Task "${id}" is not
|
|
667
|
+
if (!fields.schedule && !(await hasLegacyScheduleEvent(options, id))) {
|
|
668
|
+
throw new Error(`Task "${id}" is not recurring. Add a schedule cron with task_manage set before starting a cycle.`);
|
|
595
669
|
}
|
|
596
670
|
const control = fields.control ? resetTaskControlForCycle(fields.control, cycleId) : undefined;
|
|
597
671
|
const nextBody = startTaskCycle(body, cycleId);
|
|
@@ -661,6 +735,7 @@ export function createTaskManageTool(options) {
|
|
|
661
735
|
control: args.control,
|
|
662
736
|
status: args.status,
|
|
663
737
|
wake: args.wake,
|
|
738
|
+
schedule: args.schedule,
|
|
664
739
|
recurrence: args.recurrence,
|
|
665
740
|
note: args.note,
|
|
666
741
|
verifierRunId: args.verifierRunId,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oyasmi/pipiclaw",
|
|
3
|
-
"version": "0.8.8
|
|
3
|
+
"version": "0.8.8",
|
|
4
4
|
"description": "An AI assistant runtime for coding and team workflows, with DingTalk AI Cards, sub-agents, memory, and scheduled events.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -29,6 +29,10 @@
|
|
|
29
29
|
"deadcode": "knip",
|
|
30
30
|
"test": "vitest --run",
|
|
31
31
|
"test:e2e": "vitest --run --config vitest.config.e2e.ts",
|
|
32
|
+
"eval:build": "tsc -p tsconfig.evals.json && node -e \"const fs=require('node:fs'); fs.cpSync('src/playbooks','dist-evals/src/playbooks',{recursive:true})\"",
|
|
33
|
+
"eval": "npm run eval:build && node dist-evals/evals/harness/run.js",
|
|
34
|
+
"eval:diff": "npm run eval:build && node dist-evals/evals/harness/diff.js",
|
|
35
|
+
"eval:promote": "npm run eval:build && node dist-evals/evals/harness/promote.js",
|
|
32
36
|
"test:coverage": "vitest --run --coverage",
|
|
33
37
|
"check": "npm run lint && npm run typecheck && npm run deadcode && npm run test",
|
|
34
38
|
"prepublishOnly": "npm run clean && npm run build && npm run check"
|