@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.
- package/dist/agent/channel-runner.d.ts +7 -1
- package/dist/agent/channel-runner.js +42 -15
- package/dist/agent/command-extension.js +24 -27
- package/dist/agent/commands.d.ts +51 -7
- package/dist/agent/commands.js +199 -59
- package/dist/agent/prompt/manifest.js +5 -6
- package/dist/agent/prompt/sections.js +1 -0
- package/dist/agent/reply-limits.d.ts +16 -0
- package/dist/agent/reply-limits.js +17 -0
- package/dist/agent/runner-factory.d.ts +0 -2
- package/dist/agent/session-events.js +2 -2
- package/dist/agent/status-render.js +12 -12
- package/dist/executor.d.ts +14 -0
- package/dist/executor.js +36 -6
- package/dist/main.js +3 -4
- package/dist/memory/commands.js +79 -38
- package/dist/memory/consolidation.d.ts +5 -1
- package/dist/memory/consolidation.js +33 -12
- package/dist/memory/extraction.d.ts +8 -1
- package/dist/memory/extraction.js +47 -4
- package/dist/memory/files.d.ts +0 -1
- package/dist/memory/files.js +24 -5
- package/dist/memory/lifecycle.js +9 -2
- package/dist/memory/maintenance-jobs.js +14 -4
- package/dist/memory/metadata.d.ts +3 -0
- package/dist/memory/metadata.js +7 -0
- package/dist/memory/recall.d.ts +9 -0
- package/dist/memory/recall.js +101 -17
- package/dist/memory/review-log.d.ts +0 -2
- package/dist/memory/review-log.js +0 -0
- package/dist/memory/session-corpus.js +5 -0
- package/dist/memory/session-search.js +9 -0
- package/dist/memory/sidecar-worker.js +4 -0
- package/dist/memory/source-window.d.ts +0 -1
- package/dist/memory/source-window.js +0 -5
- package/dist/memory/task-digest.js +0 -2
- package/dist/playbooks/agent-delegation.md +32 -24
- package/dist/playbooks/background-jobs.md +8 -16
- package/dist/playbooks/event-scheduling.md +13 -15
- package/dist/playbooks/memory-and-learning.md +29 -22
- package/dist/playbooks/outbound-media.md +15 -8
- package/dist/playbooks/runtime-orientation.md +40 -37
- package/dist/playbooks/task-driving.md +34 -38
- package/dist/playbooks/task-planning.md +18 -20
- package/dist/runtime/app-home.d.ts +6 -0
- package/dist/runtime/app-home.js +15 -6
- package/dist/runtime/bootstrap.d.ts +1 -1
- package/dist/runtime/bootstrap.js +57 -62
- package/dist/runtime/channel-context.d.ts +2 -1
- package/dist/runtime/channel-event.d.ts +0 -6
- package/dist/runtime/delivery.js +3 -3
- package/dist/runtime/dingtalk.d.ts +9 -1
- package/dist/runtime/dingtalk.js +27 -13
- package/dist/runtime/event-commands.d.ts +15 -0
- package/dist/runtime/event-commands.js +48 -40
- package/dist/runtime/project-commands.d.ts +16 -0
- package/dist/runtime/project-commands.js +13 -17
- package/dist/runtime/subagent-commands.d.ts +20 -0
- package/dist/runtime/subagent-commands.js +61 -58
- package/dist/runtime/task-commands.d.ts +38 -1
- package/dist/runtime/task-commands.js +135 -234
- package/dist/runtime/task-driver.d.ts +1 -3
- package/dist/runtime/task-driver.js +34 -40
- package/dist/runtime/task-migration.d.ts +7 -6
- package/dist/runtime/task-migration.js +85 -19
- package/dist/runtime/task-wake.d.ts +3 -5
- package/dist/runtime/task-wake.js +7 -15
- package/dist/security/path-guard.js +33 -2
- package/dist/security/types.d.ts +9 -0
- package/dist/subagents/discovery.d.ts +7 -2
- package/dist/subagents/discovery.js +31 -7
- package/dist/subagents/external/claude-code.js +42 -2
- package/dist/subagents/external/run.js +72 -2
- package/dist/subagents/runs.js +28 -3
- package/dist/subagents/tool.d.ts +11 -0
- package/dist/subagents/tool.js +89 -55
- package/dist/subagents/verification-outcome.js +17 -10
- package/dist/tasks/control.d.ts +18 -67
- package/dist/tasks/control.js +44 -176
- package/dist/tasks/ledger.d.ts +7 -13
- package/dist/tasks/ledger.js +13 -49
- package/dist/tasks/store.d.ts +15 -48
- package/dist/tasks/store.js +22 -154
- package/dist/tasks/transitions.d.ts +3 -4
- package/dist/tasks/transitions.js +8 -27
- package/dist/tasks/verification.d.ts +7 -5
- package/dist/tools/bash.d.ts +1 -1
- package/dist/tools/bash.js +77 -59
- package/dist/tools/edit.js +17 -4
- package/dist/tools/grep.js +3 -2
- package/dist/tools/index.d.ts +0 -2
- package/dist/tools/index.js +6 -1
- package/dist/tools/job.js +2 -1
- package/dist/tools/memory-manage.d.ts +1 -0
- package/dist/tools/memory-manage.js +54 -16
- package/dist/tools/read.js +21 -5
- package/dist/tools/registry.d.ts +0 -1
- package/dist/tools/registry.js +0 -1
- package/dist/tools/send-media.js +17 -6
- package/dist/tools/skill-manage.js +12 -11
- package/dist/tools/skill-security.js +1 -1
- package/dist/tools/subagent-manage.d.ts +8 -1
- package/dist/tools/subagent-manage.js +77 -7
- package/dist/tools/task-manage/lifecycle.js +19 -17
- package/dist/tools/task-manage/schema.d.ts +2 -6
- package/dist/tools/task-manage/schema.js +4 -17
- package/dist/tools/task-manage/shared.js +1 -6
- package/dist/tools/task-manage/types.d.ts +0 -3
- package/dist/tools/task-manage/verification.d.ts +9 -6
- package/dist/tools/task-manage/verification.js +19 -71
- package/dist/tools/task-manage.d.ts +1 -1
- package/dist/tools/task-manage.js +3 -5
- package/dist/tools/truncate.d.ts +8 -0
- package/dist/tools/truncate.js +8 -0
- package/dist/tools/web-fetch.js +9 -1
- package/dist/tools/write-content.js +11 -1
- package/dist/tui/app.js +1 -1
- 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/tui/turn-controller.js +14 -4
- package/dist/usage/ledger.d.ts +4 -0
- package/dist/usage/ledger.js +3 -0
- package/dist/usage/render.js +10 -8
- package/examples/sub-agents/README.md +2 -0
- package/package.json +3 -2
|
@@ -6,7 +6,7 @@ import { parseLocalTime } from "../shared/local-time.js";
|
|
|
6
6
|
import { errorMessage } from "../shared/text-utils.js";
|
|
7
7
|
import { taskBudgetViolation } from "../tasks/control.js";
|
|
8
8
|
import { normalizeTaskFields, readActiveTasks, recurringTaskMissedOccurrence, } from "../tasks/ledger.js";
|
|
9
|
-
import { activateWaitingTask,
|
|
9
|
+
import { activateWaitingTask, escalateTask, openRecurringTaskCycle, updateStoredTask } from "../tasks/store.js";
|
|
10
10
|
import { nextTaskWake } from "../tasks/task-schedule.js";
|
|
11
11
|
import { discoverWorkspaceChannelIds } from "./channel-index.js";
|
|
12
12
|
import { isChannelId } from "./channel-paths.js";
|
|
@@ -16,6 +16,10 @@ const NUDGE_DEBOUNCE_MS = 50;
|
|
|
16
16
|
const MIN_SLEEP_MS = 250;
|
|
17
17
|
/** Consecutive no-progress wakes before the governor pauses a task (spec 029, D5). */
|
|
18
18
|
const FUTILE_WAKE_LIMIT = 3;
|
|
19
|
+
/** Wakes-per-cycle ceiling: a deliberately generous circuit breaker, not a normal governance
|
|
20
|
+
* path (deadline and futileCount are). Guards only against a task that keeps "progressing"
|
|
21
|
+
* without ever converging or hitting its deadline. */
|
|
22
|
+
const MAX_WAKES_PER_CYCLE = 500;
|
|
19
23
|
export async function discoverTaskChannels(workspaceDir, knownChannelIds = []) {
|
|
20
24
|
const channels = new Set();
|
|
21
25
|
for (const channelId of knownChannelIds) {
|
|
@@ -33,9 +37,8 @@ function attemptKey(channelId, taskId) {
|
|
|
33
37
|
/**
|
|
34
38
|
* What "this task moved" means to the driver.
|
|
35
39
|
*
|
|
36
|
-
* Do not use mtime/size here
|
|
37
|
-
*
|
|
38
|
-
* continuation interval forever.
|
|
40
|
+
* Do not use mtime/size here: routine frontmatter rewrites (status/note churn) must not read as
|
|
41
|
+
* progress, or governed tasks would retry at the short continuation interval forever.
|
|
39
42
|
*
|
|
40
43
|
* `latestNote` is deliberately absent (spec 031, D7): it is the model's own account of its work,
|
|
41
44
|
* so including it let a wake that did nothing but append a note reset the futile counter forever,
|
|
@@ -48,9 +51,9 @@ function attemptKey(channelId, taskId) {
|
|
|
48
51
|
* checkbox would reset the futile counter and buy the short retry tier — a governor bypass this
|
|
49
52
|
* driver must not offer. The Plan is a capsule/agenda display concern only.
|
|
50
53
|
*
|
|
51
|
-
* nextAction
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
+
* nextAction is also a model-written explanation, not evidence of an effect. Including it would
|
|
55
|
+
* let a progress/set call reset the futile counter without changing the task's externally
|
|
56
|
+
* observable work.
|
|
54
57
|
*/
|
|
55
58
|
function taskFingerprint(entry, effects) {
|
|
56
59
|
const control = entry.frontmatter.control;
|
|
@@ -59,7 +62,6 @@ function taskFingerprint(entry, effects) {
|
|
|
59
62
|
entry.frontmatter.status ?? "",
|
|
60
63
|
entry.frontmatter.wake ?? "",
|
|
61
64
|
entry.frontmatter.schedule ?? "",
|
|
62
|
-
entry.frontmatter.recurrence ?? "",
|
|
63
65
|
control?.verification.status ?? "",
|
|
64
66
|
control?.waitingFor ?? "",
|
|
65
67
|
entry.frontmatter.enabled === false ? "disabled" : "enabled",
|
|
@@ -81,9 +83,9 @@ function taskFingerprint(entry, effects) {
|
|
|
81
83
|
* - the ledger changed with no effect (status/note churn) ⇒ the ordinary continuation delay;
|
|
82
84
|
* - nothing changed ⇒ the long stalled-retry backoff, and the futile counter keeps running.
|
|
83
85
|
*
|
|
84
|
-
* Nothing here relaxes the stop-losses: the fast tier still
|
|
85
|
-
*
|
|
86
|
-
* sooner in wall time instead of an hour per step.
|
|
86
|
+
* Nothing here relaxes the stop-losses: the fast tier still counts toward `MAX_WAKES_PER_CYCLE`
|
|
87
|
+
* and the futile-wake limit, so a task that spins productively-looking still hits the governor —
|
|
88
|
+
* just sooner in wall time instead of an hour per step.
|
|
87
89
|
*/
|
|
88
90
|
function attemptDelayMs(attempt, fingerprint, effects, settings) {
|
|
89
91
|
// A dispatch the channel refused never ran; retry it on the short delay regardless of state.
|
|
@@ -112,7 +114,7 @@ function taskDispatchId(channelId, entry, nowMs) {
|
|
|
112
114
|
const occurrence = entry.frontmatter.control?.cycleId ?? entry.frontmatter.wake ?? `t${nowMs}`;
|
|
113
115
|
return `task:${channelId}:${entry.id}:${occurrence}`;
|
|
114
116
|
}
|
|
115
|
-
export function createTaskDriverEvent(channelId, entry, nowMs
|
|
117
|
+
export function createTaskDriverEvent(channelId, entry, nowMs) {
|
|
116
118
|
const repairOnly = !entry.frontmatter.readable || entry.frontmatter.controlReadable === false;
|
|
117
119
|
const repair = repairOnly
|
|
118
120
|
? ` Task metadata is not readable; repair only the frontmatter/control in tasks/${entry.id}.md, then stop. ` +
|
|
@@ -128,7 +130,6 @@ export function createTaskDriverEvent(channelId, entry, nowMs, attemptGeneration
|
|
|
128
130
|
: "",
|
|
129
131
|
entry.latestNote ? `latest=${entry.latestNote};` : "",
|
|
130
132
|
control?.nextAction ? `next=${control.nextAction};` : "",
|
|
131
|
-
control ? `budget=${control.usage.attempts}/${control.budget.maxAttempts} attempts;` : "",
|
|
132
133
|
]
|
|
133
134
|
.filter(Boolean)
|
|
134
135
|
.join(" ");
|
|
@@ -148,24 +149,6 @@ export function createTaskDriverEvent(channelId, entry, nowMs, attemptGeneration
|
|
|
148
149
|
ts: String(nowMs),
|
|
149
150
|
conversationType: channelId.startsWith("group_") ? "2" : "1",
|
|
150
151
|
dispatchId: taskDispatchId(channelId, entry, nowMs),
|
|
151
|
-
taskAttemptGeneration: attemptGeneration,
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
/** Durable checker wake created by request-verification; it is a normal main-agent turn. */
|
|
155
|
-
export function createTaskVerificationEvent(channelId, entry, nowMs) {
|
|
156
|
-
const control = entry.frontmatter.control;
|
|
157
|
-
return {
|
|
158
|
-
type: channelId.startsWith("group_") ? "group" : "dm",
|
|
159
|
-
channelId,
|
|
160
|
-
user: "TASK_VERIFIER",
|
|
161
|
-
userName: "TASK_VERIFIER",
|
|
162
|
-
text: `[TASK_VERIFY:${entry.id}] Verify task ${entry.id} independently. ` +
|
|
163
|
-
`Read tasks/${entry.id}.md and the workspace verification instructions, then run a read-only ` +
|
|
164
|
-
`subagent with purpose=verify. Import its attestation with task_manage verify using the returned run id. ` +
|
|
165
|
-
`Do not modify the workspace or task contract; if verification fails, record the failure and leave the task recoverable.`,
|
|
166
|
-
ts: String(nowMs),
|
|
167
|
-
conversationType: channelId.startsWith("group_") ? "2" : "1",
|
|
168
|
-
dispatchId: `task:${channelId}:${entry.id}:verification:${control?.cycleId ?? `t${nowMs}`}`,
|
|
169
152
|
};
|
|
170
153
|
}
|
|
171
154
|
/** sleeping + a schedule cadence + a valid wake that is due → time to open the next cycle. */
|
|
@@ -511,17 +494,28 @@ export class TaskDriver {
|
|
|
511
494
|
}
|
|
512
495
|
continue;
|
|
513
496
|
}
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
entry.
|
|
519
|
-
|
|
497
|
+
const cycleId = entry.frontmatter.control?.cycleId;
|
|
498
|
+
const wakeCount = !repairOnly && previous && previous.cycleId === cycleId ? previous.wakeCount + 1 : 1;
|
|
499
|
+
if (wakeCount > MAX_WAKES_PER_CYCLE) {
|
|
500
|
+
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
|
+
}
|
|
509
|
+
this.attempts.delete(key);
|
|
510
|
+
this.lastDispatchedTaskId.set(channelId, entry.id);
|
|
511
|
+
log.logWarning(`[${channelId}] Task driver disabled ${entry.id} (governor)`, reason);
|
|
512
|
+
}
|
|
513
|
+
continue;
|
|
514
|
+
}
|
|
515
|
+
const event = createTaskDriverEvent(channelId, entry, nowMs);
|
|
520
516
|
const accepted = await this.options.dispatch(event);
|
|
521
517
|
this.observeDispatch(event, accepted);
|
|
522
|
-
|
|
523
|
-
await releaseTaskAttemptClaim(channelDir, entry.id, claim);
|
|
524
|
-
this.attempts.set(key, { fingerprint, atMs: nowMs, accepted, effects, futileCount });
|
|
518
|
+
this.attempts.set(key, { fingerprint, atMs: nowMs, accepted, effects, futileCount, wakeCount, cycleId });
|
|
525
519
|
this.lastDispatchedTaskId.set(channelId, entry.id);
|
|
526
520
|
if (accepted) {
|
|
527
521
|
dispatched++;
|
|
@@ -10,11 +10,12 @@
|
|
|
10
10
|
*/
|
|
11
11
|
export declare function migrateLegacyTaskScheduleEvents(workspaceDir: string): Promise<void>;
|
|
12
12
|
/**
|
|
13
|
-
* Deterministically upgrade active
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
13
|
+
* Deterministically upgrade every active task file to the current (v3) control contract and
|
|
14
|
+
* status vocabulary (spec 043, phase 5). Unlike the earlier marker-gated pass, this scans and
|
|
15
|
+
* self-heals on every startup: each file is judged independently by what it actually contains
|
|
16
|
+
* (`control.version` and the raw `status` value), not by whether a one-time marker was written.
|
|
17
|
+
* A hand-edited or freshly-restored legacy file is repaired the next time the daemon starts, no
|
|
18
|
+
* matter how it got there. It never dispatches a task or performs an external action, and every
|
|
19
|
+
* file is protected by the same per-task mutation lock as normal lifecycle writes.
|
|
19
20
|
*/
|
|
20
21
|
export declare function migrateLegacyTaskState(workspaceDir: string): Promise<void>;
|
|
@@ -3,11 +3,12 @@ import { join } from "node:path";
|
|
|
3
3
|
import * as log from "../log.js";
|
|
4
4
|
import { formatLocalTime } from "../shared/local-time.js";
|
|
5
5
|
import { errorMessage } from "../shared/text-utils.js";
|
|
6
|
-
import { createDefaultTaskControl } from "../tasks/control.js";
|
|
6
|
+
import { createDefaultTaskControl, parseLegacyTaskControl } from "../tasks/control.js";
|
|
7
7
|
import { appendCurrentCycleNote, parseTaskFrontmatter } from "../tasks/ledger.js";
|
|
8
8
|
import { withTaskMutation } from "../tasks/mutation-lock.js";
|
|
9
9
|
import { readStoredTask, updateStoredTask, writeStoredTask } from "../tasks/store.js";
|
|
10
10
|
import { parseTaskEventName, taskEventPrefix } from "../tasks/task-events.js";
|
|
11
|
+
import { TASK_STATUSES } from "../tasks/transitions.js";
|
|
11
12
|
import { parseScheduledEventContent } from "./events.js";
|
|
12
13
|
import { discoverTaskChannels } from "./task-driver.js";
|
|
13
14
|
/**
|
|
@@ -72,13 +73,62 @@ export async function migrateLegacyTaskScheduleEvents(workspaceDir) {
|
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
75
|
}
|
|
76
|
+
function legacyStatusMigration(rawStatus, recurring) {
|
|
77
|
+
switch (rawStatus) {
|
|
78
|
+
case "done":
|
|
79
|
+
return recurring ? { status: "sleeping" } : { status: "active", archiveOutcome: "completed" };
|
|
80
|
+
case "cancelled":
|
|
81
|
+
return { status: "active", archiveOutcome: "cancelled" };
|
|
82
|
+
case "paused":
|
|
83
|
+
return { status: "active", stopActor: "user" };
|
|
84
|
+
case "escalated":
|
|
85
|
+
return { status: "active", stopActor: "governor" };
|
|
86
|
+
case "awaiting-user":
|
|
87
|
+
case "blocked":
|
|
88
|
+
return { status: "waiting" };
|
|
89
|
+
default:
|
|
90
|
+
return {
|
|
91
|
+
status: rawStatus !== undefined && TASK_STATUSES.includes(rawStatus)
|
|
92
|
+
? rawStatus
|
|
93
|
+
: "active",
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/** Whether the control block needs a durable upgrade: absent, or not strict-v3-parseable. */
|
|
98
|
+
function needsControlMigration(frontmatter) {
|
|
99
|
+
return frontmatter.controlReadable === false || !frontmatter.control;
|
|
100
|
+
}
|
|
101
|
+
/** Whether the raw on-disk status needs a durable rewrite into the current vocabulary. */
|
|
102
|
+
function needsStatusMigration(frontmatter) {
|
|
103
|
+
const raw = frontmatter.rawStatus;
|
|
104
|
+
return raw !== undefined && !TASK_STATUSES.includes(raw);
|
|
105
|
+
}
|
|
75
106
|
/**
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
107
|
+
* Reconstruct a v3 control block for a file the strict reader rejected. Returns `undefined` only
|
|
108
|
+
* when the stored control is genuinely unparseable (neither v3, nor legacy v1/v2) — that file is
|
|
109
|
+
* left untouched for `/tasks doctor` to report, exactly like before this migration ran.
|
|
110
|
+
*/
|
|
111
|
+
function resolveMigratedControl(frontmatter) {
|
|
112
|
+
if (frontmatter.controlReadable === false) {
|
|
113
|
+
if (!frontmatter.controlRaw)
|
|
114
|
+
return createDefaultTaskControl();
|
|
115
|
+
try {
|
|
116
|
+
return parseLegacyTaskControl(frontmatter.controlRaw);
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return createDefaultTaskControl();
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Deterministically upgrade every active task file to the current (v3) control contract and
|
|
126
|
+
* status vocabulary (spec 043, phase 5). Unlike the earlier marker-gated pass, this scans and
|
|
127
|
+
* self-heals on every startup: each file is judged independently by what it actually contains
|
|
128
|
+
* (`control.version` and the raw `status` value), not by whether a one-time marker was written.
|
|
129
|
+
* A hand-edited or freshly-restored legacy file is repaired the next time the daemon starts, no
|
|
130
|
+
* matter how it got there. It never dispatches a task or performs an external action, and every
|
|
131
|
+
* file is protected by the same per-task mutation lock as normal lifecycle writes.
|
|
82
132
|
*/
|
|
83
133
|
export async function migrateLegacyTaskState(workspaceDir) {
|
|
84
134
|
const channels = await discoverTaskChannels(workspaceDir);
|
|
@@ -101,22 +151,40 @@ export async function migrateLegacyTaskState(workspaceDir) {
|
|
|
101
151
|
const frontmatter = parseTaskFrontmatter(raw);
|
|
102
152
|
if (!frontmatter.readable)
|
|
103
153
|
return;
|
|
104
|
-
|
|
105
|
-
|
|
154
|
+
const controlNeedsMigration = needsControlMigration(frontmatter);
|
|
155
|
+
if (!controlNeedsMigration && !needsStatusMigration(frontmatter))
|
|
156
|
+
return; // already v3
|
|
157
|
+
let migratedControl = frontmatter.control;
|
|
158
|
+
if (controlNeedsMigration) {
|
|
159
|
+
migratedControl = resolveMigratedControl(frontmatter);
|
|
160
|
+
if (!migratedControl)
|
|
161
|
+
return; // genuinely corrupt; leave for doctor
|
|
162
|
+
}
|
|
106
163
|
const document = await readStoredTask(channelDir, id, false, true);
|
|
107
164
|
if (!document)
|
|
108
165
|
return;
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
document.fields.
|
|
112
|
-
|
|
113
|
-
|
|
166
|
+
document.fields.control = migratedControl;
|
|
167
|
+
const legacy = legacyStatusMigration(frontmatter.rawStatus, Boolean(frontmatter.schedule));
|
|
168
|
+
document.fields.status = legacy.status;
|
|
169
|
+
if (legacy.archiveOutcome)
|
|
170
|
+
document.fields.outcome = legacy.archiveOutcome;
|
|
171
|
+
if (legacy.stopActor) {
|
|
172
|
+
document.fields.enabled = false;
|
|
173
|
+
if (document.fields.control && !document.fields.control.stop) {
|
|
174
|
+
document.fields.control.stop = {
|
|
175
|
+
by: legacy.stopActor,
|
|
176
|
+
reason: `Task stopped by ${legacy.stopActor}.`,
|
|
177
|
+
at: formatLocalTime(),
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
// Very old hand-written tasks may have parked without ever recording a wake. Give the
|
|
182
|
+
// waiting state an explicit note before any active driver wake can act on it silently.
|
|
183
|
+
if (legacy.status === "waiting" &&
|
|
114
184
|
!document.fields.wake &&
|
|
115
185
|
document.fields.control &&
|
|
116
186
|
!document.fields.control.waitingFor) {
|
|
117
187
|
document.fields.control.waitingFor = "external-signal";
|
|
118
|
-
document.fields.control.blockedReason ??=
|
|
119
|
-
"Legacy waiting task requires review after the autonomy state upgrade.";
|
|
120
188
|
document.body = appendCurrentCycleNote(document.body, "Migration note: this task remains waiting after the autonomy state upgrade; review its external condition before resuming.");
|
|
121
189
|
}
|
|
122
190
|
if (document.fields.outcome) {
|
|
@@ -130,9 +198,7 @@ export async function migrateLegacyTaskState(workspaceDir) {
|
|
|
130
198
|
return;
|
|
131
199
|
}
|
|
132
200
|
await writeStoredTask(document);
|
|
133
|
-
|
|
134
|
-
log.logInfo(`Migrated task ${id} to TaskControl v2`, channelId);
|
|
135
|
-
}
|
|
201
|
+
log.logInfo(`Migrated task ${id} to TaskControl v3`, channelId);
|
|
136
202
|
});
|
|
137
203
|
}
|
|
138
204
|
catch (error) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Verifying and claiming a background job's or delegation run's completion wake before it may
|
|
3
|
-
* activate a
|
|
4
|
-
*
|
|
3
|
+
* activate a parked task (spec 040, D7/T9). Split out of `bootstrap.ts`: these are pure functions
|
|
4
|
+
* over an explicit `event`/`workspaceDir`/`executor`, with no dependency on
|
|
5
5
|
* `createRuntimeContext`'s closures.
|
|
6
6
|
*/
|
|
7
7
|
import { type JobSnapshot } from "../agent/job-manager.js";
|
|
@@ -33,7 +33,6 @@ export declare function isTrustedInternalWake(event: ChannelEvent, kind: "job" |
|
|
|
33
33
|
};
|
|
34
34
|
export interface ClaimedDelegationWake {
|
|
35
35
|
taskId: string;
|
|
36
|
-
generation?: number;
|
|
37
36
|
activated: boolean;
|
|
38
37
|
finish(): Promise<void>;
|
|
39
38
|
rollback(): Promise<void>;
|
|
@@ -44,11 +43,10 @@ export interface ClaimedDelegationWake {
|
|
|
44
43
|
export declare function claimVerifiedDelegationWake(event: ChannelEvent, workspaceDir: string, hooks?: WakeTaskTransitionHooks): Promise<ClaimedDelegationWake | undefined>;
|
|
45
44
|
export interface ClaimedJobWake {
|
|
46
45
|
taskId: string;
|
|
47
|
-
generation?: number;
|
|
48
46
|
activated: boolean;
|
|
49
47
|
finish(): Promise<void>;
|
|
50
48
|
}
|
|
51
49
|
/** Same shape as `claimVerifiedDelegationWake`, for a `[JOB:<jobId>] ... belongs to task
|
|
52
|
-
* <taskId>.` completion wake. A background job has no
|
|
50
|
+
* <taskId>.` completion wake. A background job has no rollback bookkeeping — its wake
|
|
53
51
|
* activation is a single unconditional step — so `ClaimedJobWake` omits `rollback`. */
|
|
54
52
|
export declare function claimVerifiedJobWake(event: ChannelEvent, workspaceDir: string, executor: Executor, hooks?: WakeTaskTransitionHooks): Promise<ClaimedJobWake | undefined>;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Verifying and claiming a background job's or delegation run's completion wake before it may
|
|
3
|
-
* activate a
|
|
4
|
-
*
|
|
3
|
+
* activate a parked task (spec 040, D7/T9). Split out of `bootstrap.ts`: these are pure functions
|
|
4
|
+
* over an explicit `event`/`workspaceDir`/`executor`, with no dependency on
|
|
5
5
|
* `createRuntimeContext`'s closures.
|
|
6
6
|
*/
|
|
7
7
|
import { getChannelJobManager } from "../agent/job-manager.js";
|
|
8
8
|
import { getSubAgentRunManager } from "../subagents/runs.js";
|
|
9
|
-
import {
|
|
9
|
+
import { activateWaitingTask, rollbackWaitingTask } from "../tasks/store.js";
|
|
10
10
|
import { getChannelDir } from "./channel-paths.js";
|
|
11
11
|
/**
|
|
12
12
|
* Whether a `[JOB:<jobId>] ... belongs to task <taskId>.` wake actually names a job that: exists
|
|
@@ -55,25 +55,18 @@ export async function claimVerifiedDelegationWake(event, workspaceDir, hooks) {
|
|
|
55
55
|
return undefined;
|
|
56
56
|
}
|
|
57
57
|
const channelDir = getChannelDir(workspaceDir, event.channelId);
|
|
58
|
-
const
|
|
59
|
-
kind: "subagent",
|
|
60
|
-
resourceId: wake.resourceId,
|
|
61
|
-
dispatchId: event.dispatchId,
|
|
62
|
-
};
|
|
63
|
-
const activated = await activateWaitingTaskAndClaimAttempt(channelDir, wake.taskId, "external-signal", new Date(), hooks, handoff);
|
|
58
|
+
const activated = await activateWaitingTask(channelDir, wake.taskId, hooks);
|
|
64
59
|
return {
|
|
65
60
|
taskId: wake.taskId,
|
|
66
|
-
generation: activated?.generation,
|
|
67
61
|
activated: activated !== undefined,
|
|
68
62
|
finish: async () => {
|
|
69
63
|
await runManager.finishWakeConsumption(wake.resourceId, event.dispatchId);
|
|
70
|
-
await finishWakeTaskActivation(channelDir, wake.taskId, handoff);
|
|
71
64
|
},
|
|
72
|
-
rollback: () =>
|
|
65
|
+
rollback: () => rollbackWaitingTask(channelDir, wake.taskId, "external-signal"),
|
|
73
66
|
};
|
|
74
67
|
}
|
|
75
68
|
/** Same shape as `claimVerifiedDelegationWake`, for a `[JOB:<jobId>] ... belongs to task
|
|
76
|
-
* <taskId>.` completion wake. A background job has no
|
|
69
|
+
* <taskId>.` completion wake. A background job has no rollback bookkeeping — its wake
|
|
77
70
|
* activation is a single unconditional step — so `ClaimedJobWake` omits `rollback`. */
|
|
78
71
|
export async function claimVerifiedJobWake(event, workspaceDir, executor, hooks) {
|
|
79
72
|
const wake = event.internalWake;
|
|
@@ -87,10 +80,9 @@ export async function claimVerifiedJobWake(event, workspaceDir, executor, hooks)
|
|
|
87
80
|
return undefined;
|
|
88
81
|
}
|
|
89
82
|
const channelDir = getChannelDir(workspaceDir, event.channelId);
|
|
90
|
-
const activated = await
|
|
83
|
+
const activated = await activateWaitingTask(channelDir, wake.taskId, hooks);
|
|
91
84
|
return {
|
|
92
85
|
taskId: wake.taskId,
|
|
93
|
-
generation: activated?.generation,
|
|
94
86
|
activated: activated !== undefined,
|
|
95
87
|
finish: async () => {
|
|
96
88
|
await jobManager.finishWakeConsumption(wake.resourceId, event.dispatchId);
|
|
@@ -224,6 +224,28 @@ function isAgentWorkspaceSkillsRead(path, operation, ctx) {
|
|
|
224
224
|
}
|
|
225
225
|
return startsWithPathPrefix(path, normalize(join(ctx.agentWorkspaceDir, "skills")));
|
|
226
226
|
}
|
|
227
|
+
/**
|
|
228
|
+
* Runtime-owned exception for the channel's own directory, in the same spirit as `skills/`: spec
|
|
229
|
+
* 043's D5 puts `SESSION.md`, channel `MEMORY.md`, `HISTORY.md` and `tasks/` in the AgentWorkspace
|
|
230
|
+
* precisely so a channel keeps its continuity across project switches — but D6.2's project bound
|
|
231
|
+
* then put them outside every allowed root, so a task wake could tell the model to open
|
|
232
|
+
* `tasks/<id>.md` and the guard would refuse.
|
|
233
|
+
*
|
|
234
|
+
* Reads are allowed throughout. Writes are allowed only under `tasks/`: the three memory files are
|
|
235
|
+
* runtime-maintained and go through `memory_manage` (a file write there races the maintenance
|
|
236
|
+
* queue), while a task's body is model-authored prose that `task_manage` cannot rewrite — `set`
|
|
237
|
+
* replaces frontmatter and keeps the body verbatim, so revising a task contract needs `edit`.
|
|
238
|
+
*/
|
|
239
|
+
function isChannelDirAccess(path, operation, ctx) {
|
|
240
|
+
if (!ctx.channelDir) {
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
const channelDir = normalize(ctx.channelDir);
|
|
244
|
+
if (!startsWithPathPrefix(path, channelDir)) {
|
|
245
|
+
return false;
|
|
246
|
+
}
|
|
247
|
+
return operation === "read" || startsWithPathPrefix(path, normalize(join(channelDir, "tasks")));
|
|
248
|
+
}
|
|
227
249
|
function isDeniedSystemPath(path) {
|
|
228
250
|
if (isWithinTemp(path)) {
|
|
229
251
|
return false;
|
|
@@ -270,6 +292,7 @@ export function guardPath(rawPath, operation, ctx) {
|
|
|
270
292
|
agentWorkspaceDir: resolveRootForGuard(ctx.agentWorkspaceDir, ctx),
|
|
271
293
|
homeDir: resolveRootForGuard(homeDir, ctx),
|
|
272
294
|
projectRoot: ctx.projectRoot ? resolveRootForGuard(ctx.projectRoot, ctx) : ctx.projectRoot,
|
|
295
|
+
channelDir: ctx.channelDir ? resolveRootForGuard(ctx.channelDir, ctx) : ctx.channelDir,
|
|
273
296
|
};
|
|
274
297
|
const resolvedTarget = resolveTargetPath(rawPath, ctx);
|
|
275
298
|
const guardedPath = resolveForGuard(resolvedTarget, ctx);
|
|
@@ -300,11 +323,19 @@ export function guardPath(rawPath, operation, ctx) {
|
|
|
300
323
|
}
|
|
301
324
|
if (pathAllowedByDefaults(guardedPath, effectiveCtx) ||
|
|
302
325
|
isBundledPlaybookRead(guardedPath, operation) ||
|
|
303
|
-
isAgentWorkspaceSkillsRead(guardedPath, operation, effectiveCtx)
|
|
326
|
+
isAgentWorkspaceSkillsRead(guardedPath, operation, effectiveCtx) ||
|
|
327
|
+
isChannelDirAccess(guardedPath, operation, effectiveCtx)) {
|
|
304
328
|
return { allowed: true, operation, rawPath, resolvedPath: guardedPath };
|
|
305
329
|
}
|
|
306
330
|
if (isDeniedSystemPath(guardedPath)) {
|
|
307
331
|
return formatBlockedResult(operation, rawPath, guardedPath, "system-path", `${operation === "read" ? "Reading" : "Writing"} system paths is not allowed by default`);
|
|
308
332
|
}
|
|
309
|
-
|
|
333
|
+
// The reason names the roots that are actually in effect. Under `boundary: "project"` the
|
|
334
|
+
// generic wording ("outside workspace, home, and temp") is worse than unhelpful: workspace and
|
|
335
|
+
// home are themselves out of bounds there, so a model taking it at face value retries against a
|
|
336
|
+
// path that can never be allowed.
|
|
337
|
+
const verb = operation === "read" ? "Reading" : "Writing";
|
|
338
|
+
return formatBlockedResult(operation, rawPath, guardedPath, "outside-allowed-roots", effectiveCtx.boundary === "project"
|
|
339
|
+
? `${verb} outside the current project root (${effectiveCtx.projectRoot ?? "unset"}) is not allowed`
|
|
340
|
+
: `${verb} outside workspace, home, and temp paths is not allowed`);
|
|
310
341
|
}
|
package/dist/security/types.d.ts
CHANGED
|
@@ -46,6 +46,15 @@ export interface SecurityRuntimeContext {
|
|
|
46
46
|
* defaults — `agentWorkspaceDir` + temp + `homeDir`.
|
|
47
47
|
*/
|
|
48
48
|
boundary?: "project" | "unbounded";
|
|
49
|
+
/**
|
|
50
|
+
* The channel's own directory (`<agentWorkspaceDir>/<channelId>`), when the caller is bound to
|
|
51
|
+
* one. It lives under `agentWorkspaceDir`, so it only matters under `boundary: "project"`,
|
|
52
|
+
* where it carries the channel's continuity across project switches (spec 043, D5) and would
|
|
53
|
+
* otherwise fall outside every allowed root. Omit it for callers that are not channel-bound —
|
|
54
|
+
* a sub-agent, for one, gets channel state through its injected context blocks, not by reading
|
|
55
|
+
* the channel's files.
|
|
56
|
+
*/
|
|
57
|
+
channelDir?: string;
|
|
49
58
|
homeDir?: string;
|
|
50
59
|
}
|
|
51
60
|
export interface PathGuardContext extends SecurityRuntimeContext {
|
|
@@ -100,10 +100,9 @@ export interface SubAgentConfig {
|
|
|
100
100
|
* The role is still listed — never silently dropped (D5) — and invocation must explain why. */
|
|
101
101
|
unavailable?: string;
|
|
102
102
|
}
|
|
103
|
-
export interface ResolvedSubAgentConfig extends Omit<SubAgentConfig, "model" | "modelRef"
|
|
103
|
+
export interface ResolvedSubAgentConfig extends Omit<SubAgentConfig, "model" | "modelRef"> {
|
|
104
104
|
model: Model<Api>;
|
|
105
105
|
modelRef: string;
|
|
106
|
-
thinkingLevel: SubAgentThinkingLevel;
|
|
107
106
|
}
|
|
108
107
|
export interface SubAgentDiscoveryResult {
|
|
109
108
|
directory: string;
|
|
@@ -124,7 +123,12 @@ export interface SubAgentInvocationOverrides {
|
|
|
124
123
|
thinkingLevel?: string;
|
|
125
124
|
/** Drives the thinkingLevel default: "verify" defaults on, everything else stays off. */
|
|
126
125
|
purpose?: string;
|
|
126
|
+
mutates?: string;
|
|
127
127
|
}
|
|
128
|
+
/** Internal work/verify default, aligned with the main agent's DEFAULT_MAIN_THINKING_LEVEL
|
|
129
|
+
* (channel-runner.ts). External work leaves thinkingLevel unset instead (see resolveSubAgentConfig):
|
|
130
|
+
* pipiclaw has no standing to pick a reasoning effort for another CLI's own configuration. */
|
|
131
|
+
export declare const DEFAULT_THINKING_LEVEL: SubAgentThinkingLevel;
|
|
128
132
|
export declare function validateSubAgentTask(task: string): string | undefined;
|
|
129
133
|
export declare function getSubAgentsDir(workspaceDir: string): string;
|
|
130
134
|
/**
|
|
@@ -163,6 +167,7 @@ export declare function resolveSubAgentConfig(availableModels: Model<Api>[], cur
|
|
|
163
167
|
subagentDefaultModelRef?: string): {
|
|
164
168
|
config?: ResolvedSubAgentConfig;
|
|
165
169
|
error?: string;
|
|
170
|
+
warning?: string;
|
|
166
171
|
};
|
|
167
172
|
export declare function formatSubAgentList(agents: SubAgentConfig[], maxItems?: number): string;
|
|
168
173
|
/**
|
|
@@ -62,9 +62,10 @@ const ALLOWED_EFFORTS = Object.keys(SUB_AGENT_EFFORT_PRESETS);
|
|
|
62
62
|
* i.e. paths-only injection — remains expressible in frontmatter.
|
|
63
63
|
*/
|
|
64
64
|
const ALLOWED_CONTEXT_CHOICES = ["none", "session", "relevant"];
|
|
65
|
-
/** verify
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
/** Internal work/verify default, aligned with the main agent's DEFAULT_MAIN_THINKING_LEVEL
|
|
66
|
+
* (channel-runner.ts). External work leaves thinkingLevel unset instead (see resolveSubAgentConfig):
|
|
67
|
+
* pipiclaw has no standing to pick a reasoning effort for another CLI's own configuration. */
|
|
68
|
+
export const DEFAULT_THINKING_LEVEL = "medium";
|
|
68
69
|
function validateTextLength(value, maxChars, label) {
|
|
69
70
|
if (value.length <= maxChars) {
|
|
70
71
|
return undefined;
|
|
@@ -676,6 +677,13 @@ subagentDefaultModelRef) {
|
|
|
676
677
|
'"model" frontmatter. The "model" invocation parameter has no effect on external roles and is never resolved against models.json.',
|
|
677
678
|
};
|
|
678
679
|
}
|
|
680
|
+
// External `mutates` is the role file's own self-declaration (checked against its harness/command),
|
|
681
|
+
// same reasoning as `model` above — the caller cannot override what the external role attests about itself.
|
|
682
|
+
if (effectiveRuntime === "external" && overrides.mutates !== undefined) {
|
|
683
|
+
return {
|
|
684
|
+
error: `Sub-agent "${baseConfig?.name}" is external; "mutates" comes from its role file, not the invocation parameter.`,
|
|
685
|
+
};
|
|
686
|
+
}
|
|
679
687
|
const tools = overrides.tools
|
|
680
688
|
? validateToolNames(overrides.tools)
|
|
681
689
|
: { tools: baseConfig?.tools ?? [...DEFAULT_SUB_AGENT_TOOLS] };
|
|
@@ -741,9 +749,24 @@ subagentDefaultModelRef) {
|
|
|
741
749
|
return { error: thinkingLevelOverride.error };
|
|
742
750
|
}
|
|
743
751
|
const purpose = overrides.purpose === "verify" ? "verify" : "work";
|
|
744
|
-
const
|
|
745
|
-
|
|
746
|
-
|
|
752
|
+
const explicitThinkingLevel = thinkingLevelOverride?.value ?? baseConfig?.thinkingLevel;
|
|
753
|
+
// External work is not defaulted: pipiclaw has no standing to pick a reasoning effort for
|
|
754
|
+
// another CLI's own configuration. External verify still defaults — it is the last unattended
|
|
755
|
+
// gate before an attestation is trusted, and "whatever that machine happens to have configured"
|
|
756
|
+
// is not an acceptable substitute for real reasoning.
|
|
757
|
+
const thinkingLevel = explicitThinkingLevel ??
|
|
758
|
+
(effectiveRuntime === "external" && purpose !== "verify" ? undefined : DEFAULT_THINKING_LEVEL);
|
|
759
|
+
const mutatesOverride = parseMutates(overrides.mutates);
|
|
760
|
+
if (mutatesOverride.error) {
|
|
761
|
+
return { error: mutatesOverride.error };
|
|
762
|
+
}
|
|
763
|
+
const mutates = mutatesOverride.value ?? baseConfig?.mutates ?? inferMutatesFromTools(tools.tools);
|
|
764
|
+
// Same rationale as the predefined-role bashWithoutMutatesWarning above (D6): `bash` can write
|
|
765
|
+
// regardless of what `tools` otherwise implies. Inline roles have no frontmatter to declare it
|
|
766
|
+
// in, so the warning goes back to the model in the result text instead of a discovery-time log.
|
|
767
|
+
const bashWithoutMutatesWarning = !baseConfig && tools.tools.includes("bash") && mutatesOverride.value === undefined
|
|
768
|
+
? 'tools include bash but "mutates" is not declared; if this task writes to the workspace, pass mutates: "write" so it takes the exclusive workspace write lease'
|
|
769
|
+
: undefined;
|
|
747
770
|
const systemPrompt = overrides.systemPrompt?.trim() || baseConfig?.systemPrompt || "";
|
|
748
771
|
if (!systemPrompt) {
|
|
749
772
|
return { error: "Sub-agent system prompt cannot be empty." };
|
|
@@ -755,6 +778,7 @@ subagentDefaultModelRef) {
|
|
|
755
778
|
}
|
|
756
779
|
}
|
|
757
780
|
return {
|
|
781
|
+
warning: bashWithoutMutatesWarning,
|
|
758
782
|
config: {
|
|
759
783
|
name: overrides.name?.trim() || baseConfig?.name || "dynamic-subagent",
|
|
760
784
|
description: baseConfig?.description || "Inline sub-agent",
|
|
@@ -778,7 +802,7 @@ subagentDefaultModelRef) {
|
|
|
778
802
|
shell: baseConfig?.shell,
|
|
779
803
|
env: baseConfig?.env,
|
|
780
804
|
workload: baseConfig?.workload,
|
|
781
|
-
mutates
|
|
805
|
+
mutates,
|
|
782
806
|
externalModelRef: baseConfig?.externalModelRef,
|
|
783
807
|
unavailable: baseConfig?.unavailable,
|
|
784
808
|
},
|