@oyasmi/pipiclaw 0.8.9 → 0.8.10-beta.2
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 +6 -10
- package/dist/agent/maintenance-context.d.ts +0 -1
- package/dist/agent/maintenance-context.js +0 -7
- package/dist/agent/session-events.d.ts +1 -0
- package/dist/agent/session-events.js +10 -0
- package/dist/agent/types.d.ts +7 -0
- package/dist/agent/types.js +2 -0
- package/dist/index.d.ts +16 -34
- package/dist/index.js +14 -32
- package/dist/memory/consolidation.js +0 -1
- package/dist/memory/extraction.d.ts +1 -7
- package/dist/memory/extraction.js +2 -46
- package/dist/memory/lifecycle.js +3 -3
- package/dist/memory/maintenance-gates.d.ts +4 -16
- package/dist/memory/maintenance-gates.js +11 -51
- package/dist/memory/maintenance-jobs.d.ts +3 -14
- package/dist/memory/maintenance-jobs.js +12 -103
- package/dist/memory/maintenance-state.d.ts +2 -6
- package/dist/memory/maintenance-state.js +14 -10
- package/dist/memory/maintenance-tuning.d.ts +37 -0
- package/dist/memory/maintenance-tuning.js +46 -0
- package/dist/memory/promotion.d.ts +0 -22
- package/dist/memory/promotion.js +1 -8
- package/dist/memory/review-log.d.ts +1 -1
- package/dist/memory/scheduler.d.ts +1 -9
- package/dist/memory/scheduler.js +3 -15
- package/dist/memory/source-window.d.ts +2 -2
- package/dist/memory/task-digest.js +2 -5
- package/dist/models/utils.d.ts +5 -0
- package/dist/models/utils.js +10 -0
- package/dist/paths.d.ts +0 -1
- package/dist/paths.js +0 -1
- package/dist/playbooks/task-closeout.md +2 -0
- package/dist/playbooks/task-delegation.md +8 -14
- package/dist/playbooks/task-driving.md +3 -4
- package/dist/playbooks/task-planning.md +8 -9
- package/dist/runtime/bootstrap.d.ts +14 -0
- package/dist/runtime/bootstrap.js +9 -4
- package/dist/runtime/task-commands.js +46 -73
- package/dist/runtime/task-driver.js +6 -23
- package/dist/settings.d.ts +39 -40
- package/dist/settings.js +87 -107
- package/dist/shared/task-ledger.d.ts +19 -2
- package/dist/shared/task-ledger.js +194 -5
- package/dist/subagents/discovery.d.ts +41 -7
- package/dist/subagents/discovery.js +74 -24
- package/dist/subagents/tool.d.ts +3 -12
- package/dist/subagents/tool.js +11 -115
- package/dist/tasks/control.d.ts +57 -27
- package/dist/tasks/control.js +94 -93
- package/dist/tasks/store.d.ts +1 -4
- package/dist/tasks/store.js +1 -39
- package/dist/tasks/transitions.d.ts +1 -1
- package/dist/tasks/transitions.js +1 -0
- package/dist/tasks/verification.d.ts +10 -6
- package/dist/tasks/verification.js +0 -6
- package/dist/tools/memory-manage.js +46 -24
- package/dist/tools/task-manage/create.js +1 -2
- package/dist/tools/task-manage/lifecycle.d.ts +7 -0
- package/dist/tools/task-manage/lifecycle.js +52 -32
- package/dist/tools/task-manage/schema.d.ts +2 -9
- package/dist/tools/task-manage/schema.js +9 -19
- package/dist/tools/task-manage/shared.d.ts +0 -2
- package/dist/tools/task-manage/shared.js +8 -69
- package/dist/tools/task-manage/types.d.ts +1 -1
- package/dist/tools/task-manage/verification.js +5 -6
- package/dist/tools/task-manage.js +4 -2
- package/examples/sub-agents/README.md +1 -1
- package/package.json +3 -1
- package/dist/memory/post-turn-review.d.ts +0 -43
- package/dist/memory/post-turn-review.js +0 -136
- package/dist/memory/promotion-signals.d.ts +0 -5
- package/dist/memory/promotion-signals.js +0 -33
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: task-delegation
|
|
3
|
-
description:
|
|
3
|
+
description: 把工作拆成多个任务(task)、委派子代理(subagent),或交给外部 agent 工具之前。
|
|
4
4
|
requires-tools: task_manage, subagent
|
|
5
5
|
priority: 45
|
|
6
6
|
---
|
|
@@ -9,33 +9,27 @@ priority: 45
|
|
|
9
9
|
|
|
10
10
|
只拆真正可分离、可独立验收的工作。两三步顺序操作留在一个 task,避免调度和 attempt 开销。
|
|
11
11
|
|
|
12
|
-
##
|
|
12
|
+
## 拆分任务
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
- `dependsOn` 表示执行前置;依赖 done 前 driver 不运行 dependent。
|
|
16
|
-
- 父任务可 dependsOn child,等待全部子成果汇合后集成。
|
|
17
|
-
- 依赖缺失、cancelled 或被治理器暂停会令 dependent 被治理器暂停。
|
|
18
|
-
- 父任务有未闭环 child 时不能 done。
|
|
14
|
+
任务之间没有父子或依赖字段,每个任务独立按自己的 DoD 收尾。需要表达先后次序时,把它写进后继任务的 `goal`/`manual`("在 <前置任务> 完成后再开始"),或用 `wake` 把它排到前置任务预计完成之后。
|
|
19
15
|
|
|
20
16
|
## 配置 subagent
|
|
21
17
|
|
|
22
18
|
不需要预先配置:不传 `agent` 时给 `systemPrompt` 即可发起委派,`workspaceDir/sub-agents/` 为空不影响这条路径。若需要可复用角色,把 Markdown 配置放入该目录;runtime 只加载实际存在的配置。仓库提供 explorer、researcher、reviewer、verifier、git-committer 五份可复制模板,见 `examples/sub-agents/`。选择明确适合的配置 agent;没有时使用聚焦的 inline `systemPrompt`。task 描述必须包含目标、范围、相关路径、约束、验收方法和返回格式,因为子代理看不到主对话。
|
|
23
19
|
|
|
24
|
-
|
|
20
|
+
执行预算用 `effort` 三档:`quick`(窄查找)、`standard`(默认)、`deep`(长程分析);精确的轮数/调用数/墙钟数值只在 workspace 配置的 frontmatter 里调,调用时不必给。上下文注入用 `context`:`none`(默认,完全隔离)、`session`、`relevant`。进程内 subagent 同回合同步返回,不需要回访事件;主 agent 负责验收结果和更新台账,子代理不驱动 task/event 台账。触顶时子代理会收敛输出已完成的结论而不是整段丢弃,但预算仍然是真实上限,不要依赖它兜底过大的任务。
|
|
25
21
|
|
|
26
22
|
独立验收必须 `purpose: verify` + `taskId`,见 `task-closeout.md`。
|
|
27
23
|
|
|
28
24
|
## 产物契约与回传预算
|
|
29
25
|
|
|
30
|
-
每次委派都会在 `channelDir/subagent-artifacts/<runId>/` 下建产物目录,子代理的完整输出总会落盘到该目录的 `output.md`,与 `returns` 无关。回传给父代理的文本超过大小预算时会被截断,附上 `output.md` 的绝对路径——父代理判断值得保留的内容,按需 `read` 全文,再决定是否经 `memory_manage`
|
|
26
|
+
每次委派都会在 `channelDir/subagent-artifacts/<runId>/` 下建产物目录,子代理的完整输出总会落盘到该目录的 `output.md`,与 `returns` 无关。回传给父代理的文本超过大小预算时会被截断,附上 `output.md` 的绝对路径——父代理判断值得保留的内容,按需 `read` 全文,再决定是否经 `memory_manage` 提炼为记忆。产物目录不自动清理,由父代理负责闭环:任务收尾时决定保留还是删除。
|
|
31
27
|
|
|
32
28
|
需要子代理把主产出写成文件而不是回传整段文本时传 `returns: "artifact"`,子代理需以 `ARTIFACT: <filename>` 结尾;忘记该标记时会自动降级为纯文本模式。
|
|
33
29
|
|
|
34
|
-
##
|
|
30
|
+
## 文件系统隔离
|
|
35
31
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
已有 worktree 可传 `worktreePath`,但必须位于该 channel 的 `tasks/worktrees/` 下。worktree 不自动删除;父代理必须 review、merge、验证,然后清理 worktree 与分支。创建前处理好主 checkout 的未提交前置改动。
|
|
32
|
+
没有。子代理与主代理共享同一个 checkout,只隔离对话上下文。需要在独立检出上作业时,在宿主侧自行 `git worktree add`,把它当作普通工作目录传给子代理,并自己负责 review、merge 与清理。
|
|
39
33
|
|
|
40
34
|
## 外部 agent 工具
|
|
41
35
|
|
|
@@ -49,4 +43,4 @@ runtime 只规定长程委派的恢复纪律:
|
|
|
49
43
|
4. 如确需条件触发,按 `event-scheduling.md` 使用用户提供的稳定检测命令;不要临时复制未知脚本,也不要把第三方协议写进 runtime playbook。
|
|
50
44
|
5. task 闭环前清理临时事件和外部实例。
|
|
51
45
|
|
|
52
|
-
任何委派都不能转移最终交付责任。父代理必须确认成果已进入目标 checkout
|
|
46
|
+
任何委派都不能转移最终交付责任。父代理必须确认成果已进入目标 checkout,而不是只停留在外部实例或口头报告中。
|
|
@@ -20,7 +20,7 @@ priority: 41
|
|
|
20
20
|
|
|
21
21
|
仍开放且正文或进展发生变化时,用 `task_manage progress` 一次性记录:发生了什么、看到了什么证据、下一步是什么、status 与 `wake`。
|
|
22
22
|
|
|
23
|
-
以下生命周期动作本身就是原子 checkpoint,不要再追加 progress:`candidate`、`done`、`cancel`。
|
|
23
|
+
以下生命周期动作本身就是原子 checkpoint,不要再追加 progress:`candidate`、`done`、`skip`、`cancel`。
|
|
24
24
|
|
|
25
25
|
`verify` 只更新 control、不改正文。PASS 后若还要等外部审批(approval),用 `task_manage set wake=<合理时间>` 停留在 `verifying` 车道——**只改 wake、不换状态**,离开 verifying 会作废 PASS——并请用户 `/tasks approve <id>`。门禁的绑定规则见 `task-closeout.md`。除此之外不要用 `set` 代替正常进度日志。
|
|
26
26
|
|
|
@@ -36,13 +36,13 @@ priority: 41
|
|
|
36
36
|
|
|
37
37
|
## 汇报与静默
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
有用户需要知道的结果、风险、审批请求时正常汇报。周期 occurrence 因去重或产物已存在而明确不执行时,调用 `task_manage skip` 写入简短原因、让任务重新休眠,然后返回 `[SILENT]`;不能只静默而把周期留在 active。除此之外,确实不需要改变任务状态且没有新结果时直接返回 `[SILENT]`。完成时走 `task-closeout.md`。
|
|
40
40
|
|
|
41
41
|
---
|
|
42
42
|
|
|
43
43
|
# 诊断与修复
|
|
44
44
|
|
|
45
|
-
先用 `task_manage list` 看结构化状态;让用户用 `/tasks doctor` 看带 Next step 的一致性检查,用 `/tasks stats <id>`
|
|
45
|
+
先用 `task_manage list` 看结构化状态;让用户用 `/tasks doctor` 看带 Next step 的一致性检查,用 `/tasks stats <id>` 看本周期与累计 attempts/token/cost/wall time、最近结果和 verifier 状态。`cost: unavailable` 表示参与运行的模型缺少价格元数据,不表示免费。
|
|
46
46
|
|
|
47
47
|
## 被治理器暂停(paused + pausedBy=governor)
|
|
48
48
|
|
|
@@ -50,7 +50,6 @@ priority: 41
|
|
|
50
50
|
|
|
51
51
|
- 方向错:修 Manual/`nextAction`、重新拆解或 cancel。
|
|
52
52
|
- 预算确实不足:向用户说明后用 `task_manage set` 调整 budget/deadline,并把 status 设回 `active`。
|
|
53
|
-
- 依赖终止:恢复或重建依赖,或 `set` 更新 `dependsOn`。
|
|
54
53
|
|
|
55
54
|
被暂停的任务不能 progress/candidate;`set`(或 `/tasks resume`)是审查原因后的修复入口,**不要反射性加预算**。
|
|
56
55
|
|
|
@@ -22,21 +22,20 @@ priority: 40
|
|
|
22
22
|
- `manual`:可复用的执行步骤、预检与返工教训。
|
|
23
23
|
- `verificationPlan`:验收者能独立执行的确定性检查。
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
默认不要求独立验收,只有有限尝试预算。任务产出了验收者能独立检查的产物(代码、配置、可运行命令)时,创建时设 `control.verificationRequired: true`;`sideEffects: external` 的任务会自动打开它。
|
|
26
26
|
|
|
27
27
|
## control 决策
|
|
28
28
|
|
|
29
29
|
- `priority` / `deadline`:表达调度重要性和硬期限,不用 `wake` 冒充 deadline。
|
|
30
30
|
- `nextAction`:下一条可执行动作,避免写抽象愿望。
|
|
31
|
-
- `maxAttempts
|
|
32
|
-
- `sideEffects`:`
|
|
33
|
-
- `
|
|
34
|
-
- `parent` / `dependsOn`:只用于真实分解;`parent` 表归属,`dependsOn` 表执行前置。
|
|
35
|
-
|
|
36
|
-
创建和 `set` 会拒绝不存在的关联、自指、parent 环和 dependency 环。父任务可以 `dependsOn` 自己的 child 表达 join;父任务有未闭环 child 时不能 done。
|
|
31
|
+
- `maxAttempts`:唯一的按任务停止条件,按风险和规模收紧。它在**本周期、回合边界**检查,不会中断正在运行的单个回合。
|
|
32
|
+
- `sideEffects`:`workspace` 或 `external`。发送、发布、部署、修改外部系统必须选 `external`,它会要求用户 `/tasks approve` 后才能 done。
|
|
33
|
+
- 任务之间没有父子或依赖字段。需要表达先后次序时写进 `goal`/`manual`,或用 `wake` 把后续任务排到合适的时间;每个任务只按自己的 DoD 收尾。
|
|
37
34
|
|
|
38
35
|
外部副作用与独立验收并存时,DoD/Verification 要验收"**待执行动作及其输入已准备正确**"(内容、目标、参数、预演、回滚方案),不要把尚未获批的外部动作本身写成 candidate 前必须勾选的项——否则会形成"先执行才能勾选"与"先验收批准才能执行"的死循环。实际执行结果由审批记录和 done evidence 收口。
|
|
39
36
|
|
|
37
|
+
DoD 描述最终可验收结果,不把未执行动作写成 `[x] skipped`。存在条件分支时,用一个结果项表达“完成 A,或在条件不成立时交付 B 并附理由”;执行哪条路径由 evidence 证明。
|
|
38
|
+
|
|
40
39
|
## 六个状态与时间
|
|
41
40
|
|
|
42
41
|
每个状态只对应一种 driver 行为:
|
|
@@ -52,7 +51,7 @@ priority: 40
|
|
|
52
51
|
|
|
53
52
|
## 周期性任务(schedule)
|
|
54
53
|
|
|
55
|
-
一个周期任务就是**一个文件**:`tasks/<id>.md`。节奏写在 frontmatter 的 `schedule`(五段 cron
|
|
54
|
+
一个周期任务就是**一个文件**:`tasks/<id>.md`。节奏写在 frontmatter 的 `schedule`(五段 cron,按主机时区解释;部署时用 `TZ` 固定所需 IANA 时区),做法与跨周期经验写在正文。没有配套事件,也没有 `.schedule` 命名约定。`recurrence` 只是给人看的可选标注(如 `每周一`),没有机器语义——**周期性 = `schedule` 是否存在**。
|
|
56
55
|
|
|
57
56
|
```
|
|
58
57
|
task_manage create id=weekly-report title=... goal=... dod=... schedule="30 9 * * 1"
|
|
@@ -62,7 +61,7 @@ cron 最密每 30 分钟一次,落盘前校验。纯提醒不建 task,用普
|
|
|
62
61
|
|
|
63
62
|
**首次执行遵循 cron 语义**:不显式传 `wake` 时,create 会把 `wake` 预约到下一次 occurrence,任务处于 `active` + 未来 `wake`——像 crontab 一样,创建不等于立刻跑。需要立刻开跑就显式传一个当下或过去的 `wake`。
|
|
64
63
|
|
|
65
|
-
到点后 **runtime
|
|
64
|
+
到点后 **runtime 直接开下一周期**,不需要(也没有)手工开周期的动作:折叠上一周期日志和 evidence 入 History、限制工作正文只保留最近周期、清空本周期用量与验收授权元数据、置 `active`,然后派发一条普通驱动唤醒。累计审计 usage 不会清零。你醒来面对的就是一个待推进的新周期,和其他唤醒无异。
|
|
66
65
|
|
|
67
66
|
- 改节奏:`task_manage set schedule="<新 cron>"`;任务当前是 done 时写盘会重算 `wake`。一处真相。
|
|
68
67
|
- 暂停 / 恢复:`/tasks pause <id>` / `/tasks resume <id>`。
|
|
@@ -44,6 +44,20 @@ export interface RuntimeContext {
|
|
|
44
44
|
nudge?(): void;
|
|
45
45
|
runOnce?: (now?: Date) => Promise<void>;
|
|
46
46
|
};
|
|
47
|
+
/**
|
|
48
|
+
* Production maintenance scheduler, exposed for the same reason as `taskDriver`.
|
|
49
|
+
*
|
|
50
|
+
* Evaluation workers run with `startServices: false`, so the background timer never fires and
|
|
51
|
+
* no trial could otherwise reach `SESSION.md` refresh, the memory checkpoint, or consolidation
|
|
52
|
+
* — the whole layered memory pipeline was structurally untestable from a behavior eval.
|
|
53
|
+
* Exposing the instance lets a case drive one real pass at a chosen time instead of faking a
|
|
54
|
+
* clock or re-implementing the job order.
|
|
55
|
+
*/
|
|
56
|
+
memoryMaintenance: {
|
|
57
|
+
start(): void;
|
|
58
|
+
stop(): void;
|
|
59
|
+
runOnce?: (now?: Date) => Promise<void>;
|
|
60
|
+
};
|
|
47
61
|
shutdown: (reason?: NodeJS.Signals | "manual") => Promise<void>;
|
|
48
62
|
}
|
|
49
63
|
export declare const DEFAULT_BOOTSTRAP_PATHS: BootstrapPaths;
|
|
@@ -642,6 +642,7 @@ export function createRuntimeContext(options) {
|
|
|
642
642
|
await finishTaskAttempt(getChannelDir(options.paths.workspaceDir, event.channelId), taskDriverMatch[1], {
|
|
643
643
|
tokens: result.usage.total,
|
|
644
644
|
costUsd: result.usage.cost.total,
|
|
645
|
+
costKnown: result.costKnown === true,
|
|
645
646
|
wallTimeMinutes: result.durationMs / 60_000,
|
|
646
647
|
failed: result.stopReason === "error" || result.stopReason === "aborted",
|
|
647
648
|
silent: result.silent,
|
|
@@ -711,7 +712,6 @@ export function createRuntimeContext(options) {
|
|
|
711
712
|
return loadDetachedMaintenanceContext({
|
|
712
713
|
channelId,
|
|
713
714
|
channelDir: getChannelDir(options.paths.workspaceDir, channelId),
|
|
714
|
-
workspaceDir: options.paths.workspaceDir,
|
|
715
715
|
authConfigPath: options.paths.authConfigPath,
|
|
716
716
|
modelsConfigPath: options.paths.modelsConfigPath,
|
|
717
717
|
settingsManager: runtimeSettingsManager,
|
|
@@ -724,9 +724,6 @@ export function createRuntimeContext(options) {
|
|
|
724
724
|
memoryMaintenance: runtimeSettingsManager.getMemoryMaintenanceSettings(),
|
|
725
725
|
};
|
|
726
726
|
},
|
|
727
|
-
emitNotice: async (channelId, notice) => {
|
|
728
|
-
await bot.sendPlain(channelId, notice);
|
|
729
|
-
},
|
|
730
727
|
intervalMs: options.memoryMaintenanceSchedulerIntervalMs,
|
|
731
728
|
});
|
|
732
729
|
const taskDriver = options.createTaskDriver
|
|
@@ -840,6 +837,7 @@ export function createRuntimeContext(options) {
|
|
|
840
837
|
store,
|
|
841
838
|
bot,
|
|
842
839
|
taskDriver,
|
|
840
|
+
memoryMaintenance: memoryMaintenanceScheduler,
|
|
843
841
|
shutdown: shutdownWithReason,
|
|
844
842
|
};
|
|
845
843
|
}
|
|
@@ -860,6 +858,13 @@ export function prepareAppServices(paths = DEFAULT_BOOTSTRAP_PATHS) {
|
|
|
860
858
|
for (const { scope, error } of settingsManager.drainErrors()) {
|
|
861
859
|
log.logWarning(`Failed to load ${scope} settings`, `${error.message}\n${paths.settingsConfigPath}`);
|
|
862
860
|
}
|
|
861
|
+
// Errors already went out above with a richer message; this pass exists for the
|
|
862
|
+
// warnings, chiefly retired settings keys (spec 035 D3).
|
|
863
|
+
for (const diagnostic of settingsManager.getDiagnostics()) {
|
|
864
|
+
if (diagnostic.severity === "error")
|
|
865
|
+
continue;
|
|
866
|
+
log.logWarning(formatConfigDiagnostic(diagnostic), diagnostic.path);
|
|
867
|
+
}
|
|
863
868
|
for (const diagnostic of loadToolsConfigWithDiagnostics(paths.appHomeDir).diagnostics) {
|
|
864
869
|
log.logWarning(formatConfigDiagnostic(diagnostic), diagnostic.path);
|
|
865
870
|
}
|
|
@@ -4,7 +4,8 @@ import { join, resolve, sep } from "node:path";
|
|
|
4
4
|
import { parseTaskEventName, taskEventPrefix } from "../shared/task-events.js";
|
|
5
5
|
import { extractTaskTitle, missingStandardTaskSections, normalizeTaskId, readActiveTasks, } from "../shared/task-ledger.js";
|
|
6
6
|
import { errorMessage } from "../shared/text-utils.js";
|
|
7
|
-
import {
|
|
7
|
+
import { isRecord } from "../shared/type-guards.js";
|
|
8
|
+
import { retiredTaskControlKeys, taskBudgetViolation } from "../tasks/control.js";
|
|
8
9
|
import { claimTaskAttempt, readStoredTask, releaseTaskAttemptClaim, taskBodyHash, writeStoredTask, } from "../tasks/store.js";
|
|
9
10
|
import { normalizeStoredStatus, resolveTaskTransition } from "../tasks/transitions.js";
|
|
10
11
|
import { readVerificationAttestation } from "../tasks/verification.js";
|
|
@@ -144,34 +145,25 @@ function validWakeMs(entry) {
|
|
|
144
145
|
function issue(problem, nextStep) {
|
|
145
146
|
return `- ${problem}\n Next step: ${nextStep}`;
|
|
146
147
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
148
|
+
/**
|
|
149
|
+
* Render the ordering edges a stored task still declares, e.g. `child → parent, a → b`.
|
|
150
|
+
* Empty when the task carries no retired relation keys (spec 036, D8).
|
|
151
|
+
*/
|
|
152
|
+
function describeDroppedTaskRelations(id, rawControl) {
|
|
153
|
+
if (!isRecord(rawControl))
|
|
154
|
+
return "";
|
|
155
|
+
const edges = [];
|
|
156
|
+
const parent = rawControl.parent;
|
|
157
|
+
if (typeof parent === "string" && parent.trim())
|
|
158
|
+
edges.push(`${id} → ${parent.trim()}`);
|
|
159
|
+
const dependsOn = rawControl.dependsOn;
|
|
160
|
+
if (Array.isArray(dependsOn)) {
|
|
161
|
+
for (const dependency of dependsOn) {
|
|
162
|
+
if (typeof dependency === "string" && dependency.trim())
|
|
163
|
+
edges.push(`${id} → ${dependency.trim()}`);
|
|
159
164
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
visited.add(id);
|
|
163
|
-
active.add(id);
|
|
164
|
-
stack.push(id);
|
|
165
|
-
for (const next of graph.get(id) ?? []) {
|
|
166
|
-
if (graph.has(next))
|
|
167
|
-
visit(next);
|
|
168
|
-
}
|
|
169
|
-
stack.pop();
|
|
170
|
-
active.delete(id);
|
|
171
|
-
};
|
|
172
|
-
for (const id of graph.keys())
|
|
173
|
-
visit(id);
|
|
174
|
-
return Array.from(cycles.values());
|
|
165
|
+
}
|
|
166
|
+
return edges.join(", ");
|
|
175
167
|
}
|
|
176
168
|
async function readActiveTaskContent(channelDir, id) {
|
|
177
169
|
try {
|
|
@@ -190,30 +182,29 @@ async function listTasks(channelDir) {
|
|
|
190
182
|
}
|
|
191
183
|
const blocks = entries.map((entry) => {
|
|
192
184
|
const status = entry.frontmatter.readable ? (entry.frontmatter.status ?? "active") : "⚠ unreadable frontmatter";
|
|
193
|
-
const detail = [` status: ${status}`, `wake: ${relativeWake(entry.wakeMs, now)}`];
|
|
185
|
+
const detail = [` status: ${status}`, `next wake: ${relativeWake(entry.wakeMs, now)}`];
|
|
194
186
|
const control = entry.frontmatter.control;
|
|
195
187
|
if (control) {
|
|
196
188
|
detail.push(`priority: ${control.priority}`);
|
|
197
189
|
detail.push(`attempts: ${control.usage.attempts}/${control.budget.maxAttempts}`);
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
detail.push(`isolation: ${control.isolation}`);
|
|
190
|
+
if (control.verification.required)
|
|
191
|
+
detail.push(`verify: required/${control.verification.status}`);
|
|
201
192
|
if (control.sideEffects !== "workspace") {
|
|
202
193
|
detail.push(`effects: ${control.sideEffects}/${control.externalApproval}`);
|
|
203
194
|
}
|
|
204
195
|
if (control.deadline)
|
|
205
196
|
detail.push(`deadline: ${control.deadline}`);
|
|
206
|
-
if (control.parent)
|
|
207
|
-
detail.push(`parent: ${control.parent}`);
|
|
208
|
-
if (control.dependsOn.length > 0)
|
|
209
|
-
detail.push(`depends: ${control.dependsOn.join(",")}`);
|
|
210
197
|
if (control.nextAction)
|
|
211
198
|
detail.push(`next: ${control.nextAction}`);
|
|
212
|
-
if (control.
|
|
213
|
-
detail.push(
|
|
199
|
+
if (control.cycleId) {
|
|
200
|
+
detail.push(`${status === "done" ? "last" : "current"} cycle: ${control.cycleId}`);
|
|
201
|
+
}
|
|
214
202
|
}
|
|
215
203
|
if (entry.frontmatter.recurrence)
|
|
216
204
|
detail.push(`recurrence: ${entry.frontmatter.recurrence}`);
|
|
205
|
+
if (entry.frontmatter.schedule) {
|
|
206
|
+
detail.push(`schedule timezone: ${Intl.DateTimeFormat().resolvedOptions().timeZone} (host)`);
|
|
207
|
+
}
|
|
217
208
|
return `- ${entry.id} — ${entry.title}\n${detail.join(" ")}`;
|
|
218
209
|
});
|
|
219
210
|
return `# Tasks: ${entries.length} active\n\n${blocks.join("\n")}`;
|
|
@@ -260,7 +251,6 @@ export async function pauseTask(options, idInput) {
|
|
|
260
251
|
task.fields.wake = undefined;
|
|
261
252
|
if (task.fields.control) {
|
|
262
253
|
task.fields.control.pausedBy = "user";
|
|
263
|
-
task.fields.control.lastOutcome = "blocked";
|
|
264
254
|
task.fields.control.blockedReason = `Paused by ${options.approver?.trim() || "a user"}.`;
|
|
265
255
|
}
|
|
266
256
|
await writeStoredTask(task);
|
|
@@ -279,7 +269,6 @@ export async function resumeTask(options, idInput) {
|
|
|
279
269
|
task.fields.wake = undefined;
|
|
280
270
|
if (task.fields.control) {
|
|
281
271
|
task.fields.control.pausedBy = undefined;
|
|
282
|
-
task.fields.control.lastOutcome = "pending";
|
|
283
272
|
task.fields.control.blockedReason = undefined;
|
|
284
273
|
}
|
|
285
274
|
await writeStoredTask(task);
|
|
@@ -301,7 +290,6 @@ async function runTask(options, idInput) {
|
|
|
301
290
|
task.fields.wake = undefined;
|
|
302
291
|
if (task.fields.control) {
|
|
303
292
|
task.fields.control.pausedBy = undefined;
|
|
304
|
-
task.fields.control.lastOutcome = "pending";
|
|
305
293
|
task.fields.control.blockedReason = undefined;
|
|
306
294
|
}
|
|
307
295
|
await writeStoredTask(task);
|
|
@@ -319,14 +307,12 @@ function renderUsageLine(entry) {
|
|
|
319
307
|
if (!control)
|
|
320
308
|
return `- ${entry.id}: legacy task (no governed usage recorded)`;
|
|
321
309
|
const verification = control.verification;
|
|
310
|
+
const cycleCost = control.usage.costKnown ? `$${control.usage.costUsd.toFixed(4)}` : "unavailable";
|
|
322
311
|
return [
|
|
323
312
|
`- ${entry.id} — ${entry.title}`,
|
|
324
|
-
`
|
|
325
|
-
`
|
|
326
|
-
`
|
|
327
|
-
` wall time: ${control.usage.wallTimeMinutes.toFixed(1)}m`,
|
|
328
|
-
` last outcome: ${control.lastOutcome}`,
|
|
329
|
-
` verification: ${verification.mode}/${verification.status}`,
|
|
313
|
+
` this cycle: ${control.usage.attempts}/${control.budget.maxAttempts} attempts, ${control.usage.tokens} tokens, ${cycleCost}, ${control.usage.wallTimeMinutes.toFixed(1)}m`,
|
|
314
|
+
` last run: ${control.lastOutcome}`,
|
|
315
|
+
` verification: ${verification.required ? "required" : "not required"}/${verification.status}`,
|
|
330
316
|
].join("\n");
|
|
331
317
|
}
|
|
332
318
|
async function taskStats(options, idInput) {
|
|
@@ -356,19 +342,17 @@ async function taskStats(options, idInput) {
|
|
|
356
342
|
total.attempts += usage.attempts;
|
|
357
343
|
total.tokens += usage.tokens;
|
|
358
344
|
total.costUsd += usage.costUsd;
|
|
345
|
+
total.costKnown &&= usage.costKnown;
|
|
359
346
|
total.wallTimeMinutes += usage.wallTimeMinutes;
|
|
360
347
|
return total;
|
|
361
|
-
}, { attempts: 0, tokens: 0, costUsd: 0, wallTimeMinutes: 0 });
|
|
348
|
+
}, { attempts: 0, tokens: 0, costUsd: 0, costKnown: true, wallTimeMinutes: 0 });
|
|
362
349
|
const verified = governed.filter((entry) => entry.frontmatter.control?.verification.status === "passed").length;
|
|
363
350
|
const stalled = governed.filter((entry) => entry.frontmatter.control?.lastOutcome === "failed").length;
|
|
364
351
|
return [
|
|
365
352
|
"# Task Stats",
|
|
366
353
|
"",
|
|
367
354
|
`governed tasks: ${governed.length}/${entries.length}`,
|
|
368
|
-
`
|
|
369
|
-
`tokens: ${totals.tokens}`,
|
|
370
|
-
`cost: $${totals.costUsd.toFixed(4)}`,
|
|
371
|
-
`wall time: ${totals.wallTimeMinutes.toFixed(1)}m`,
|
|
355
|
+
`this cycle: ${totals.attempts} attempts, ${totals.tokens} tokens, ${totals.costKnown ? `$${totals.costUsd.toFixed(4)}` : "cost unavailable"}, ${totals.wallTimeMinutes.toFixed(1)}m`,
|
|
372
356
|
`verification PASS: ${verified}`,
|
|
373
357
|
`last-run failures: ${stalled}`,
|
|
374
358
|
"",
|
|
@@ -437,11 +421,6 @@ async function doctor(options) {
|
|
|
437
421
|
if (violation) {
|
|
438
422
|
issues.push(issue(`tasks/${entry.id}.md exceeds its control limit: ${violation}.`, `Review the task, then explicitly raise its budget/deadline or cancel it; the driver will escalate it.`));
|
|
439
423
|
}
|
|
440
|
-
for (const relatedId of [control.parent, ...control.dependsOn].filter((value) => Boolean(value))) {
|
|
441
|
-
if (!activeIds.has(relatedId) && !archivedIds.has(relatedId)) {
|
|
442
|
-
issues.push(issue(`tasks/${entry.id}.md points to missing related task ${relatedId}.`, `Create ${relatedId}, or remove it from parent/dependsOn with task_manage set.`));
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
424
|
if (control.sideEffects === "external" && control.externalApproval === "required") {
|
|
446
425
|
issues.push(issue(`tasks/${entry.id}.md requires external side effects but has no user approval.`, `After reviewing the proposed action, a user must run /tasks approve ${entry.id}.`));
|
|
447
426
|
}
|
|
@@ -450,14 +429,11 @@ async function doctor(options) {
|
|
|
450
429
|
control.approvalBodyHash !== taskBodyHash(storedTask.body)) {
|
|
451
430
|
issues.push(issue(`tasks/${entry.id}.md changed after external-action approval was granted.`, `Review the current action and run /tasks approve ${entry.id} again.`));
|
|
452
431
|
}
|
|
453
|
-
if (control.worktree && !existsSync(control.worktree.path)) {
|
|
454
|
-
issues.push(issue(`tasks/${entry.id}.md records a missing worktree path: ${control.worktree.path}.`, `Clear the stale worktree metadata or create/reassign an isolated worktree.`));
|
|
455
|
-
}
|
|
456
432
|
if (status !== "done" && control.verification.status === "passed" && control.verification.bodyHash) {
|
|
457
433
|
if (storedTask && taskBodyHash(storedTask.body) !== control.verification.bodyHash) {
|
|
458
434
|
issues.push(issue(`tasks/${entry.id}.md changed after its recorded independent PASS.`, `Run a fresh purpose=verify sub-agent and import its attestation before completion.`));
|
|
459
435
|
}
|
|
460
|
-
else if (control.verification.
|
|
436
|
+
else if (control.verification.required) {
|
|
461
437
|
const attestationOk = control.verification.runId
|
|
462
438
|
? await readVerificationAttestation(options.channelDir, control.verification.runId)
|
|
463
439
|
.then((attestation) => attestation.taskId === entry.id && attestation.verdict === "pass")
|
|
@@ -487,20 +463,17 @@ async function doctor(options) {
|
|
|
487
463
|
issues.push(issue(`tasks/${entry.id}.md has an invalid wake value (${entry.frontmatter.wake}); the native driver will treat it as due.`, `Use task_manage set or progress to replace wake with ISO8601, or clear it if the task should continue now.`));
|
|
488
464
|
}
|
|
489
465
|
}
|
|
490
|
-
|
|
491
|
-
|
|
466
|
+
// Spec 036 D8: retired control keys are ignored on read, which keeps stored tasks readable
|
|
467
|
+
// but silently discards whatever `parent`/`dependsOn` once expressed. Report the loss —
|
|
468
|
+
// naming the dropped edges, not just the key — so the user can restate any real ordering.
|
|
492
469
|
for (const entry of entries) {
|
|
493
|
-
const
|
|
494
|
-
if (
|
|
470
|
+
const retired = retiredTaskControlKeys(entry.frontmatter.rawControl);
|
|
471
|
+
if (retired.length === 0)
|
|
495
472
|
continue;
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
issues.push(issue(`Task parent cycle detected: ${cycle.join(" → ")}.`, `Use task_manage set to clear or correct one parent link in this cycle.`));
|
|
501
|
-
}
|
|
502
|
-
for (const cycle of relationCycles(dependencyGraph)) {
|
|
503
|
-
issues.push(issue(`Task dependency cycle detected: ${cycle.join(" → ")}.`, `Use task_manage set to remove one dependsOn edge before the driver can continue these tasks.`));
|
|
473
|
+
const edges = describeDroppedTaskRelations(entry.id, entry.frontmatter.rawControl);
|
|
474
|
+
issues.push(issue(`tasks/${entry.id}.md still carries retired control keys: ${retired.join(", ")}.${edges ? ` Dropped ordering: ${edges}.` : ""}`, edges
|
|
475
|
+
? `These no longer constrain execution. Restate any real ordering in the task body or with wake, then remove the keys (any task_manage write drops them).`
|
|
476
|
+
: `They are ignored; any task_manage write drops them.`));
|
|
504
477
|
}
|
|
505
478
|
for (const event of events) {
|
|
506
479
|
if (!event.id || !event.use) {
|
|
@@ -6,7 +6,7 @@ import { PLAYBOOKS_DIR } from "../paths.js";
|
|
|
6
6
|
import { normalizeTaskFields, readActiveTasks } from "../shared/task-ledger.js";
|
|
7
7
|
import { errorMessage } from "../shared/text-utils.js";
|
|
8
8
|
import { taskBudgetViolation } from "../tasks/control.js";
|
|
9
|
-
import { claimTaskAttempt,
|
|
9
|
+
import { claimTaskAttempt, escalateTask, openRecurringTaskCycle, releaseTaskAttemptClaim, updateStoredTask, } from "../tasks/store.js";
|
|
10
10
|
import { TERMINAL_TASK_STATUSES } from "../tasks/transitions.js";
|
|
11
11
|
/** Short debounce so a burst of nudges collapses into a single rescan. */
|
|
12
12
|
const NUDGE_DEBOUNCE_MS = 50;
|
|
@@ -114,7 +114,8 @@ export function createTaskDriverEvent(channelId, entry, nowMs) {
|
|
|
114
114
|
`Open tasks/${entry.id}.md and read ${join(PLAYBOOKS_DIR, "task-driving.md")} before acting. ` +
|
|
115
115
|
"Advance the next concrete step under the task's current control, acceptance, approval, and verification state. " +
|
|
116
116
|
`If complete or waiting, use the matching task_manage lifecycle/checkpoint action from the playbook.${verificationInstruction} ` +
|
|
117
|
-
"
|
|
117
|
+
"For a recurring occurrence intentionally not run because it is duplicate or already satisfied, call task_manage skip with the reason, then respond with exactly [SILENT]. " +
|
|
118
|
+
"If no task state or tool action is needed and this wake produces no user-visible result, respond with exactly [SILENT].",
|
|
118
119
|
ts: String(nowMs),
|
|
119
120
|
conversationId: "",
|
|
120
121
|
conversationType: channelId.startsWith("group_") ? "2" : "1",
|
|
@@ -149,14 +150,6 @@ function taskEscalationEvent(channelId, entry, reason, nowMs) {
|
|
|
149
150
|
dispatchId: `task:${channelId}:${entry.id}:escalation:${createHash("sha256").update(reason).digest("hex").slice(0, 12)}`,
|
|
150
151
|
};
|
|
151
152
|
}
|
|
152
|
-
function terminalDependencyReason(reason) {
|
|
153
|
-
return reason?.includes(" is missing") ||
|
|
154
|
-
reason?.includes(" is cancelled") ||
|
|
155
|
-
reason?.includes(" is paused by the governor") ||
|
|
156
|
-
reason?.includes("dependency cycle")
|
|
157
|
-
? reason
|
|
158
|
-
: undefined;
|
|
159
|
-
}
|
|
160
153
|
/**
|
|
161
154
|
* Native, token-gated driver for the persistent task ledger.
|
|
162
155
|
*
|
|
@@ -196,6 +189,7 @@ export class TaskDriver {
|
|
|
196
189
|
if (this.loopActive)
|
|
197
190
|
return;
|
|
198
191
|
this.loopActive = true;
|
|
192
|
+
log.logInfo("Task driver started", `schedule timezone=${Intl.DateTimeFormat().resolvedOptions().timeZone} (host)`);
|
|
199
193
|
void this.tick();
|
|
200
194
|
}
|
|
201
195
|
stop() {
|
|
@@ -317,8 +311,7 @@ export class TaskDriver {
|
|
|
317
311
|
const control = candidate.frontmatter.control;
|
|
318
312
|
if (!control || TERMINAL_STATUSES.has(status ?? ""))
|
|
319
313
|
continue;
|
|
320
|
-
const
|
|
321
|
-
const escalationReason = taskBudgetViolation(control, nowMs) ?? terminalDependencyReason(dependencies.reason);
|
|
314
|
+
const escalationReason = taskBudgetViolation(control, nowMs);
|
|
322
315
|
if (!escalationReason)
|
|
323
316
|
continue;
|
|
324
317
|
governanceHandled = true;
|
|
@@ -345,17 +338,7 @@ export class TaskDriver {
|
|
|
345
338
|
const rotatedCandidates = lastIndex >= 0
|
|
346
339
|
? [...candidates.slice(lastIndex + 1), ...candidates.slice(0, lastIndex + 1)]
|
|
347
340
|
: candidates;
|
|
348
|
-
let entry;
|
|
349
|
-
for (const candidate of rotatedCandidates) {
|
|
350
|
-
const control = candidate.frontmatter.control;
|
|
351
|
-
if (control) {
|
|
352
|
-
const dependencies = await dependencyState(channelDir, control.dependsOn, candidate.id);
|
|
353
|
-
if (!dependencies.ready)
|
|
354
|
-
continue;
|
|
355
|
-
}
|
|
356
|
-
entry = candidate;
|
|
357
|
-
break;
|
|
358
|
-
}
|
|
341
|
+
let entry = rotatedCandidates[0];
|
|
359
342
|
if (!entry || dispatched >= settings.maxDispatchesPerTick)
|
|
360
343
|
continue;
|
|
361
344
|
// A cycle-start-ready recurring task is reopened in-process before dispatch: fold the
|