@oyasmi/pipiclaw 0.8.8-beta.2 → 0.8.9-beta.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 +1 -0
- package/dist/agent/channel-runner.js +8 -0
- package/dist/agent/runner-factory.d.ts +2 -0
- package/dist/memory/task-digest.js +1 -1
- package/dist/playbooks/task-closeout.md +11 -10
- package/dist/playbooks/task-delegation.md +1 -1
- package/dist/playbooks/task-driving.md +6 -7
- package/dist/playbooks/task-planning.md +7 -5
- package/dist/playbooks/task-recurring.md +7 -4
- package/dist/playbooks/task-repair.md +7 -7
- package/dist/runtime/bootstrap.d.ts +12 -1
- package/dist/runtime/bootstrap.js +9 -1
- package/dist/runtime/task-commands.js +29 -51
- package/dist/runtime/task-driver.d.ts +3 -8
- package/dist/runtime/task-driver.js +97 -84
- package/dist/runtime/task-migration.d.ts +11 -0
- package/dist/runtime/task-migration.js +70 -0
- package/dist/security/path-guard.js +3 -1
- package/dist/shared/task-events.d.ts +0 -26
- package/dist/shared/task-events.js +0 -15
- package/dist/shared/task-ledger.d.ts +23 -1
- package/dist/shared/task-ledger.js +65 -16
- package/dist/tasks/control.d.ts +4 -0
- package/dist/tasks/control.js +3 -0
- package/dist/tasks/store.d.ts +28 -1
- package/dist/tasks/store.js +63 -6
- package/dist/tasks/transitions.d.ts +40 -0
- package/dist/tasks/transitions.js +81 -0
- package/dist/tools/task-manage/create.d.ts +2 -0
- package/dist/tools/task-manage/create.js +34 -0
- package/dist/tools/task-manage/lifecycle.d.ts +6 -0
- package/dist/tools/task-manage/lifecycle.js +196 -0
- package/dist/tools/task-manage/schema.d.ts +43 -0
- package/dist/tools/task-manage/schema.js +89 -0
- package/dist/tools/task-manage/shared.d.ts +36 -0
- package/dist/tools/task-manage/shared.js +246 -0
- package/dist/tools/task-manage/types.d.ts +53 -0
- package/dist/tools/task-manage/types.js +1 -0
- package/dist/tools/task-manage/verification.d.ts +16 -0
- package/dist/tools/task-manage/verification.js +111 -0
- package/dist/tools/task-manage.d.ts +9 -89
- package/dist/tools/task-manage.js +8 -696
- package/package.json +5 -1
|
@@ -12,6 +12,7 @@ export declare class ChannelRunner implements AgentRunner {
|
|
|
12
12
|
private readonly appHomeDir;
|
|
13
13
|
private readonly authConfigPath;
|
|
14
14
|
private readonly modelsConfigPath;
|
|
15
|
+
private readonly onSessionEvent?;
|
|
15
16
|
private readonly workspaceDir;
|
|
16
17
|
private session;
|
|
17
18
|
private agent;
|
|
@@ -74,6 +74,7 @@ export class ChannelRunner {
|
|
|
74
74
|
this.appHomeDir = paths.appHomeDir;
|
|
75
75
|
this.authConfigPath = paths.authConfigPath;
|
|
76
76
|
this.modelsConfigPath = paths.modelsConfigPath;
|
|
77
|
+
this.onSessionEvent = paths.onSessionEvent;
|
|
77
78
|
const executor = createExecutor();
|
|
78
79
|
this.executor = executor;
|
|
79
80
|
this.workspaceDir = resolve(dirname(channelDir));
|
|
@@ -1028,6 +1029,13 @@ export class ChannelRunner {
|
|
|
1028
1029
|
subscribeToSessionEvents() {
|
|
1029
1030
|
this.sessionUnsubscribe?.();
|
|
1030
1031
|
this.sessionUnsubscribe = this.session.subscribe((event) => {
|
|
1032
|
+
// Observation is deliberately before our consumer and must never alter a turn.
|
|
1033
|
+
try {
|
|
1034
|
+
this.onSessionEvent?.(event, this.channelId);
|
|
1035
|
+
}
|
|
1036
|
+
catch (err) {
|
|
1037
|
+
log.logWarning(`[${this.channelId}] session observer failed`, errorMessage(err));
|
|
1038
|
+
}
|
|
1031
1039
|
if (isRecord(event) && event.type === "message_start" && this.turn.phase === "preparing") {
|
|
1032
1040
|
this.turn.phase = "streaming";
|
|
1033
1041
|
}
|
|
@@ -3,6 +3,8 @@ export interface RunnerFactoryPaths {
|
|
|
3
3
|
appHomeDir: string;
|
|
4
4
|
authConfigPath: string;
|
|
5
5
|
modelsConfigPath: string;
|
|
6
|
+
/** Optional, side-effect-free observer used by the behavior-eval harness. */
|
|
7
|
+
onSessionEvent?: (event: unknown, channelId: string) => void;
|
|
6
8
|
}
|
|
7
9
|
export declare function getOrCreateRunner(channelId: string, channelDir: string, paths: RunnerFactoryPaths): AgentRunner;
|
|
8
10
|
export declare function resetRunner(channelId: string, paths?: RunnerFactoryPaths, channelDir?: string): void;
|
|
@@ -18,7 +18,7 @@ function relativeWake(wakeMs, now) {
|
|
|
18
18
|
return `wake ${Math.round(hours / 24)}d`;
|
|
19
19
|
}
|
|
20
20
|
function renderLine(entry, now) {
|
|
21
|
-
const status = entry.frontmatter.readable ? (entry.frontmatter.status ?? "
|
|
21
|
+
const status = entry.frontmatter.readable ? (entry.frontmatter.status ?? "active") : "⚠ unreadable frontmatter";
|
|
22
22
|
const parts = [`${entry.id} — ${entry.title}`, status, relativeWake(entry.wakeMs, now)];
|
|
23
23
|
const control = entry.frontmatter.control;
|
|
24
24
|
if (control) {
|
|
@@ -13,28 +13,29 @@ priority: 42
|
|
|
13
13
|
2. 全部勾完,调用 `task_manage candidate`;该动作追加候选 note、置 verifying、清 wake,本身就是本回合 checkpoint。
|
|
14
14
|
3. checker-only 回合委派全新 subagent:`purpose: verify`、`taskId: <id>`,明确逐项检查方法。
|
|
15
15
|
4. verifier 没有 write/edit;bash 只运行明确的非变更检查。Git checkout 上 runtime 会比较前后状态,变化会使 attestation 无效;非 Git 目录没有完整变更检测,不能把 bash 当成结构性只读沙箱。结尾必须是 `VERDICT: PASS` 或 `VERDICT: FAIL`。
|
|
16
|
-
5. 主回合以 runId 调 `task_manage verify`。attestation 绑定 task
|
|
16
|
+
5. 主回合以 runId 调 `task_manage verify`。attestation 绑定 task 的**契约段** hash(Goal/DoD/Manual/Verification,含勾选状态,不含 Current Cycle/History);Git checkout 上还绑定 HEAD/staged/unstaged/untracked artifact subject。
|
|
17
17
|
|
|
18
|
-
FAIL 后用 progress 记录失败证据、status 回
|
|
18
|
+
FAIL 后用 progress 记录失败证据、status 回 active,修复后重新 candidate。不要让 verifier 顺手修实现。
|
|
19
|
+
|
|
20
|
+
**PASS 绑定契约、不绑日志**:PASS 之后照常 `progress` 记 Current Cycle 日志不会使 PASS 失效;只有改动契约段(Goal/DoD/Manual/Verification 或勾选状态)才会失效。改了契约就诚实重跑验收。
|
|
19
21
|
|
|
20
22
|
## 外部副作用
|
|
21
23
|
|
|
22
|
-
`sideEffects: external` 要求用户通过 `/tasks approve <id>` 授权;agent
|
|
24
|
+
`sideEffects: external` 要求用户通过 `/tasks approve <id>` 授权;agent 不能自授予。授权同样绑定契约段 hash:批准后照常记日志无妨,但改动契约正文会要求重新授权。
|
|
23
25
|
|
|
24
|
-
只做 external、无需 independent verification 时:准备动作 → progress 置
|
|
26
|
+
只做 external、无需 independent verification 时:准备动作 → progress 置 waiting 并请求审批 → 用户 approve → 执行动作 → 直接 done。
|
|
25
27
|
|
|
26
|
-
## independent + external
|
|
28
|
+
## independent + external 同时存在
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
契约-绑定的 hash 让两个门不再相互误伤,日常顺序很简单:
|
|
29
31
|
|
|
30
32
|
1. 完成实现、预演外部动作、勾选 acceptance items。
|
|
31
33
|
2. candidate → verifier → `task_manage verify` 得到 PASS。
|
|
32
|
-
3.
|
|
33
|
-
4. 用户批准后,driver 在 wake
|
|
34
|
+
3. 等待审批:用 `task_manage set wake=<合理时间>` 保留在 `verifying` 车道(**只改 wake,不换状态**——离开 verifying 的 set 会作废 PASS),并请求用户 `/tasks approve <id>`。此时记日志无妨。
|
|
35
|
+
4. 用户批准后,driver 在 wake 到期接续;确认 PASS、approvalBodyHash 与当前产物仍新鲜。
|
|
34
36
|
5. 执行已批准的外部动作,然后直接 done;结果写入 done 的 summary/evidence。
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
如果 wake 到期但用户尚未批准,只用 set 调整 awaiting-user/wake 并提醒,不写 progress note。
|
|
38
|
+
改动契约段或批准范围时,诚实重走相应门禁。
|
|
38
39
|
|
|
39
40
|
建档时 acceptance items 应描述外部动作的**准备质量**(内容、目标、参数、预演、回滚方案),而不是要求在 candidate 前已经发布/发送。最终外部结果由审批记录和 done evidence 证明;否则“先执行才能勾选”会与“先验收、审批才能执行”形成循环。
|
|
40
41
|
|
|
@@ -14,7 +14,7 @@ priority: 45
|
|
|
14
14
|
- child 的 `control.parent` 指向父任务。
|
|
15
15
|
- `dependsOn` 表示执行前置;依赖 done 前 driver 不运行 dependent。
|
|
16
16
|
- 父任务可 dependsOn child,等待全部子成果汇合后集成。
|
|
17
|
-
- 依赖缺失、cancelled
|
|
17
|
+
- 依赖缺失、cancelled 或被治理器暂停会令 dependent 被治理器暂停。
|
|
18
18
|
- 父任务有未闭环 child 时不能 done。
|
|
19
19
|
|
|
20
20
|
## 内建 subagent
|
|
@@ -14,7 +14,7 @@ priority: 41
|
|
|
14
14
|
3. 检查上一步产物是否已经存在。driver/dispatch 提供至少一次恢复,宕机或租约重放可能让同一步再次到达。
|
|
15
15
|
4. 只推进一个清晰的下一阶段;不要在未知状态下重复外部动作。
|
|
16
16
|
|
|
17
|
-
依赖未完成时 driver 跳过任务且不消耗 attempt;依赖缺失/cancelled
|
|
17
|
+
依赖未完成时 driver 跳过任务且不消耗 attempt;依赖缺失/cancelled/被治理器暂停、deadline 或累计预算耗尽会令任务被治理器暂停(`paused` + `pausedBy=governor`)。
|
|
18
18
|
|
|
19
19
|
## 回合结束必须留下确定性状态
|
|
20
20
|
|
|
@@ -25,15 +25,14 @@ priority: 41
|
|
|
25
25
|
- 下一步是什么;
|
|
26
26
|
- status 与 wake。
|
|
27
27
|
|
|
28
|
-
以下生命周期动作本身就是原子 checkpoint,不要再追加 progress:`candidate`、`done`、`cancel
|
|
28
|
+
以下生命周期动作本身就是原子 checkpoint,不要再追加 progress:`candidate`、`done`、`cancel`。
|
|
29
29
|
|
|
30
|
-
`verify` 只更新 control、不改正文。若 PASS 后还要等待 external approval,使用 `task_manage set
|
|
30
|
+
`verify` 只更新 control、不改正文。若 PASS 后还要等待 external approval,使用 `task_manage set wake=<合理时间>` 停留在 `verifying` 车道(只改 wake、不换状态;离开 verifying 会作废 PASS),并向用户请求 `/tasks approve <id>`。PASS 绑定契约段而非日志——记 Current Cycle 日志不会使 PASS 失效,只有改契约(Goal/DoD/Manual/Verification/勾选)才会。除此之外不要用 set 代替正常进度日志。
|
|
31
31
|
|
|
32
32
|
## 等待与继续
|
|
33
33
|
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
- 当前仍可继续:保持 `in-progress`,清空 wake。
|
|
34
|
+
- 等用户/外部系统/委派:`waiting` + 合理 wake,把等谁、等什么写进 `blockedReason`。
|
|
35
|
+
- 当前仍可继续:保持 `active`,清空 wake。
|
|
37
36
|
- 明确停止:由用户 pause;不要用极远 wake 模拟暂停。
|
|
38
37
|
|
|
39
38
|
内建 driver 分钟级扫描 DingTalk `dm_*/group_*` channel。wake 到期后接续;无需 heartbeat、`.checkin` 或额外传感器。TUI 关闭后没有 daemon,不能自动唤醒。
|
|
@@ -42,4 +41,4 @@ priority: 41
|
|
|
42
41
|
|
|
43
42
|
## 汇报与静默
|
|
44
43
|
|
|
45
|
-
有用户需要知道的结果、风险、审批请求时正常汇报。纯内部周期检查且没有新结果时返回 `[SILENT]`。完成时走 `task-closeout.md
|
|
44
|
+
有用户需要知道的结果、风险、审批请求时正常汇报。纯内部周期检查且没有新结果时返回 `[SILENT]`。完成时走 `task-closeout.md`,异常或被治理器暂停走 `task-repair.md`。
|
|
@@ -37,12 +37,14 @@ priority: 40
|
|
|
37
37
|
|
|
38
38
|
## 状态与时间
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
- `
|
|
43
|
-
- `
|
|
40
|
+
六个状态,每个只对应一种 driver 行为:
|
|
41
|
+
|
|
42
|
+
- `active`:可推进(受 wake 门控)。
|
|
43
|
+
- `waiting`:等用户/外部条件/委派结果;等谁、等什么写进 `control.blockedReason`。
|
|
44
44
|
- `verifying`:只做独立验收,不继续实现。
|
|
45
|
-
- `
|
|
45
|
+
- `paused`:明确暂停,driver 不运行。用户暂停 `pausedBy=user`;治理器停止(预算耗尽等)记 `pausedBy=governor`,先诊断再修 control。
|
|
46
|
+
- `done`:完成;有 schedule 则原地睡到下次 occurrence,否则归档。
|
|
47
|
+
- `cancelled`:放弃并归档。
|
|
46
48
|
|
|
47
49
|
`wake` 是最早重新检查时间,不代表截止时间。等待时设置现实的 wake;可继续时清空 wake,让 driver 按 cooldown 接续。
|
|
48
50
|
|
|
@@ -21,11 +21,14 @@ task_manage create id=weekly-report title=... goal=... dod=... schedule="30 9 *
|
|
|
21
21
|
|
|
22
22
|
cron 最密每 30 分钟一次,落盘前校验。纯提醒(无产出、无验收)不建 task,用普通 periodic event。
|
|
23
23
|
|
|
24
|
+
**首次执行遵循 cron 语义**:不显式传 `wake` 时,create 会用 croner 把 `wake` 预约到下一次 occurrence,任务 `active` + 未来 `wake`,到点才由 driver 派发普通驱动唤醒——像 crontab 一样,创建不等于立刻跑。需要立刻开跑就显式传一个当下/过去的 `wake`。
|
|
25
|
+
|
|
24
26
|
## 周期运行
|
|
25
27
|
|
|
26
|
-
done 的周期任务留在原地睡眠:`task_manage done` 会用 croner 算出下一次 occurrence 写入 `wake`,状态是 `done` + 未来的 `wake
|
|
28
|
+
done 的周期任务留在原地睡眠:`task_manage done` 后,"唯一时间规则"会用 croner 算出下一次 occurrence 写入 `wake`,状态是 `done` + 未来的 `wake`。
|
|
29
|
+
|
|
30
|
+
到点时 **runtime 直接开下一周期**(无需你做任何事,也没有 `start-cycle` 动作):折叠上一周期日志入 History、清空本周期用量/验收/授权/worktree 元数据、置 `active`,然后派发一条普通驱动唤醒。你醒来面对的就是一个待推进的新周期,和其他唤醒无异。
|
|
27
31
|
|
|
28
|
-
- 收到 cycle-start:调用 `task_manage start-cycle`,给稳定 cycleId。它原子折叠上一周期日志、清空本周期用量/验收/授权/worktree 元数据并置 in-progress。
|
|
29
32
|
- 上周期未完成:不要覆盖或虚勾 DoD。先完成、如实缩小本轮范围并验收,或与用户确认后 cancel 整项任务。
|
|
30
33
|
|
|
31
34
|
周期内继续、等待和恢复只用 task `wake`。
|
|
@@ -34,8 +37,8 @@ done 的周期任务留在原地睡眠:`task_manage done` 会用 croner 算出
|
|
|
34
37
|
|
|
35
38
|
每轮闭环前把返工原因、预检步骤和格式偏好写回 Manual;跨任务才沉淀 workspace skill。
|
|
36
39
|
|
|
37
|
-
- 改节奏:`task_manage set schedule="<新 cron>"`;若任务当前 done
|
|
40
|
+
- 改节奏:`task_manage set schedule="<新 cron>"`;若任务当前 done,写盘时"唯一时间规则"会重算 `wake`。一处真相。
|
|
38
41
|
- 暂停:`/tasks pause <id>`;`/tasks resume` 恢复。
|
|
39
42
|
- 退役:`task_manage cancel`,归档任务并清理全部 task-owned events。
|
|
40
43
|
|
|
41
|
-
|
|
44
|
+
周期由 runtime 自动开启,不需要(也没有)手工开周期的动作。
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: task-repair
|
|
3
|
-
description: When a task is
|
|
3
|
+
description: When a task is paused by the governor, stalled, not waking, or has broken control metadata.
|
|
4
4
|
requires-tools: task_manage
|
|
5
5
|
priority: 44
|
|
6
6
|
---
|
|
@@ -9,19 +9,19 @@ priority: 44
|
|
|
9
9
|
|
|
10
10
|
先用 `task_manage list` 看结构化状态;让用户用 `/tasks doctor` 看带 Next step 的一致性检查,用 `/tasks stats <id>` 看 attempts/token/cost/wall time、最近结果和 verifier 状态。
|
|
11
11
|
|
|
12
|
-
##
|
|
12
|
+
## 被治理器暂停(paused + pausedBy=governor)
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
治理器在 deadline、累计预算耗尽、terminal dependency,或**连续 3 次唤醒都没有可见进展**(fingerprint 未变,含 silent)时暂停任务(旧称 escalated,现在是 `paused` + `pausedBy=governor`)。先读 Current Cycle 和 stats,判断空转、范围错误、预算过小还是依赖终止。
|
|
15
15
|
|
|
16
16
|
- 方向错:修 Manual/nextAction、重新拆解或 cancel。
|
|
17
|
-
- 预算确实不足:向用户说明后用 `task_manage set` 调整 budget/deadline,并把 status 设回
|
|
17
|
+
- 预算确实不足:向用户说明后用 `task_manage set` 调整 budget/deadline,并把 status 设回 active。
|
|
18
18
|
- 依赖终止:恢复/重建依赖,或 set 更新 dependsOn。
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
被暂停的任务不能 progress/candidate;`set`(或 `/tasks resume`)是审查原因后的修复入口,不要反射性加预算。
|
|
21
21
|
|
|
22
22
|
## 不唤醒或频繁唤醒
|
|
23
23
|
|
|
24
|
-
可推进 = 非 done/cancelled/
|
|
24
|
+
可推进 = 非 done/cancelled/paused,且 wake 缺失、无效或已到期。
|
|
25
25
|
|
|
26
26
|
- paused:用户 `/tasks resume <id>`。
|
|
27
27
|
- wake 太远:纠正 wake;急催用 `/tasks run <id>`。
|
|
@@ -36,7 +36,7 @@ frontmatter 只认开头 `---` 块中的 status/wake/recurrence/control;contro
|
|
|
36
36
|
|
|
37
37
|
## stale gate
|
|
38
38
|
|
|
39
|
-
PASS 和 external approval 都绑定 task
|
|
39
|
+
PASS 和 external approval 都绑定 task 的**契约段**(Goal/DoD/Manual/Verification 及勾选状态,不含 Current Cycle/History);PASS 还可能绑定 Git artifact subject。改契约或产物变化后 done 会拒绝:重跑 verifier 或请用户重新 approve,不绕过。(记 Current Cycle 日志不影响 PASS。)组合流程见 `task-closeout.md`。
|
|
40
40
|
|
|
41
41
|
## 事件与重启
|
|
42
42
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Executor } from "../executor.js";
|
|
2
2
|
import { PipiclawSettingsManager } from "../settings.js";
|
|
3
|
-
import { DingTalkBot, type DingTalkConfig, type DingTalkHandler } from "./dingtalk.js";
|
|
3
|
+
import { DingTalkBot, type DingTalkConfig, type DingTalkEvent, type DingTalkHandler } from "./dingtalk.js";
|
|
4
4
|
import { ChannelStore } from "./store.js";
|
|
5
5
|
export interface BootstrapPaths {
|
|
6
6
|
appName: string;
|
|
@@ -37,6 +37,13 @@ export interface AppContext {
|
|
|
37
37
|
export interface RuntimeContext {
|
|
38
38
|
handler: DingTalkHandler;
|
|
39
39
|
store: ChannelStore;
|
|
40
|
+
/** Production driver instance, exposed so evals can invoke the real scan path. */
|
|
41
|
+
taskDriver: {
|
|
42
|
+
start(): void;
|
|
43
|
+
stop(): void;
|
|
44
|
+
nudge?(): void;
|
|
45
|
+
runOnce?: (now?: Date) => Promise<void>;
|
|
46
|
+
};
|
|
40
47
|
shutdown: (reason?: NodeJS.Signals | "manual") => Promise<void>;
|
|
41
48
|
}
|
|
42
49
|
export declare const DEFAULT_BOOTSTRAP_PATHS: BootstrapPaths;
|
|
@@ -70,6 +77,10 @@ interface RuntimeContextOptions {
|
|
|
70
77
|
stop(): void;
|
|
71
78
|
nudge?(): void;
|
|
72
79
|
};
|
|
80
|
+
/** Receives raw SDK session events after subscription, without changing runtime handling. */
|
|
81
|
+
observer?: (event: unknown, channelId: string) => void;
|
|
82
|
+
/** Receives TaskDriver dispatch outcomes; used only by isolated evaluation workers. */
|
|
83
|
+
onTaskDriverDispatch?: (event: DingTalkEvent, accepted: boolean) => void;
|
|
73
84
|
startServices?: boolean;
|
|
74
85
|
registerSignalHandlers?: boolean;
|
|
75
86
|
}
|
|
@@ -29,6 +29,7 @@ import { createEventsWatcher } from "./events.js";
|
|
|
29
29
|
import { ChannelStore } from "./store.js";
|
|
30
30
|
import { pauseTask, handleTasksCommand as runTasksCommand } from "./task-commands.js";
|
|
31
31
|
import { createTaskDriverEvent, TaskDriver } from "./task-driver.js";
|
|
32
|
+
import { migrateLegacyTaskScheduleEvents } from "./task-migration.js";
|
|
32
33
|
import { DEFAULT_AGENTS, DEFAULT_SOUL } from "./workspace-templates.js";
|
|
33
34
|
const DEFAULT_MEMORY = `# Workspace Memory
|
|
34
35
|
|
|
@@ -423,6 +424,7 @@ export function createRuntimeContext(options) {
|
|
|
423
424
|
appHomeDir: options.paths.appHomeDir,
|
|
424
425
|
authConfigPath: options.paths.authConfigPath,
|
|
425
426
|
modelsConfigPath: options.paths.modelsConfigPath,
|
|
427
|
+
onSessionEvent: options.observer,
|
|
426
428
|
});
|
|
427
429
|
channelRunners.set(channelId, runner);
|
|
428
430
|
}
|
|
@@ -646,7 +648,7 @@ export function createRuntimeContext(options) {
|
|
|
646
648
|
finally {
|
|
647
649
|
await durableDispatch?.markCompleted(event.dispatchId);
|
|
648
650
|
runner.endTurn();
|
|
649
|
-
// A finished turn may have written task files (progress/done/
|
|
651
|
+
// A finished turn may have written task files (progress/done/set); rescan
|
|
650
652
|
// now so a continuing task chain advances immediately instead of after a full sleep.
|
|
651
653
|
taskDriver.nudge?.();
|
|
652
654
|
}
|
|
@@ -714,6 +716,7 @@ export function createRuntimeContext(options) {
|
|
|
714
716
|
getKnownChannelIds: () => channelRunners.keys(),
|
|
715
717
|
isChannelActive: (channelId) => channelRunners.get(channelId)?.isBusy() ?? false,
|
|
716
718
|
dispatch: (event) => durableDispatch?.dispatch(event) ?? false,
|
|
719
|
+
onDispatch: options.onTaskDriverDispatch,
|
|
717
720
|
getSettings: () => {
|
|
718
721
|
runtimeSettingsManager.reload();
|
|
719
722
|
return runtimeSettingsManager.getTaskDriverSettings();
|
|
@@ -772,6 +775,7 @@ export function createRuntimeContext(options) {
|
|
|
772
775
|
appHomeDir: options.paths.appHomeDir,
|
|
773
776
|
authConfigPath: options.paths.authConfigPath,
|
|
774
777
|
modelsConfigPath: options.paths.modelsConfigPath,
|
|
778
|
+
onSessionEvent: options.observer,
|
|
775
779
|
}, channelDir);
|
|
776
780
|
}
|
|
777
781
|
const storageFlushes = [
|
|
@@ -801,6 +805,9 @@ export function createRuntimeContext(options) {
|
|
|
801
805
|
});
|
|
802
806
|
}
|
|
803
807
|
if (startServices) {
|
|
808
|
+
// One-time close of the 027 migration window: fold any residual legacy `.schedule`
|
|
809
|
+
// events into task frontmatter before the driver relies on frontmatter as the only cadence.
|
|
810
|
+
void migrateLegacyTaskScheduleEvents(options.paths.workspaceDir);
|
|
804
811
|
eventsWatcher.start();
|
|
805
812
|
memoryMaintenanceScheduler.start();
|
|
806
813
|
taskDriver.start();
|
|
@@ -811,6 +818,7 @@ export function createRuntimeContext(options) {
|
|
|
811
818
|
handler,
|
|
812
819
|
store,
|
|
813
820
|
bot,
|
|
821
|
+
taskDriver,
|
|
814
822
|
shutdown: shutdownWithReason,
|
|
815
823
|
};
|
|
816
824
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { readdir, readFile } from "node:fs/promises";
|
|
3
3
|
import { join, resolve, sep } from "node:path";
|
|
4
|
-
import {
|
|
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
7
|
import { taskBudgetViolation } from "../tasks/control.js";
|
|
8
8
|
import { claimTaskAttempt, readStoredTask, releaseTaskAttemptClaim, taskBodyHash, writeStoredTask, } from "../tasks/store.js";
|
|
9
|
+
import { normalizeStoredStatus, resolveTaskTransition } from "../tasks/transitions.js";
|
|
9
10
|
import { readVerificationAttestation } from "../tasks/verification.js";
|
|
10
11
|
import { parseScheduledEventContent } from "./events.js";
|
|
11
12
|
function usage() {
|
|
@@ -133,13 +134,6 @@ async function readTaskEvents(workspaceDir, channelId) {
|
|
|
133
134
|
}
|
|
134
135
|
return events;
|
|
135
136
|
}
|
|
136
|
-
function eventKey(events, id, use) {
|
|
137
|
-
return events.find((event) => event.id === id && event.use === use);
|
|
138
|
-
}
|
|
139
|
-
function isParseableSchedule(events, id) {
|
|
140
|
-
const schedule = eventKey(events, id, "schedule");
|
|
141
|
-
return schedule ? isTaskScheduleEvent(schedule) : false;
|
|
142
|
-
}
|
|
143
137
|
function validWakeMs(entry) {
|
|
144
138
|
const wake = entry.frontmatter.wake;
|
|
145
139
|
if (!wake)
|
|
@@ -195,7 +189,7 @@ async function listTasks(channelDir) {
|
|
|
195
189
|
return "# Tasks\n\nNo active tasks.";
|
|
196
190
|
}
|
|
197
191
|
const blocks = entries.map((entry) => {
|
|
198
|
-
const status = entry.frontmatter.readable ? (entry.frontmatter.status ?? "
|
|
192
|
+
const status = entry.frontmatter.readable ? (entry.frontmatter.status ?? "active") : "⚠ unreadable frontmatter";
|
|
199
193
|
const detail = [` status: ${status}`, `wake: ${relativeWake(entry.wakeMs, now)}`];
|
|
200
194
|
const control = entry.frontmatter.control;
|
|
201
195
|
if (control) {
|
|
@@ -232,7 +226,7 @@ async function approveTask(options, idInput) {
|
|
|
232
226
|
const control = task.fields.control;
|
|
233
227
|
if (!control)
|
|
234
228
|
return `Task ${id} has no governed control metadata. Ask the agent to normalize it before approval.`;
|
|
235
|
-
if (task.fields.status === "done" || task.fields.status === "cancelled"
|
|
229
|
+
if (task.fields.status === "done" || task.fields.status === "cancelled") {
|
|
236
230
|
return `Task ${id} is ${task.fields.status} and cannot receive a new external-action approval.`;
|
|
237
231
|
}
|
|
238
232
|
if (control.sideEffects !== "external") {
|
|
@@ -253,14 +247,19 @@ export async function pauseTask(options, idInput) {
|
|
|
253
247
|
const task = await readStoredTask(options.channelDir, id);
|
|
254
248
|
if (!task)
|
|
255
249
|
return `Task not found: ${id}`;
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
}
|
|
259
|
-
if (task.fields.status === "paused")
|
|
250
|
+
const from = normalizeStoredStatus(task.fields.status);
|
|
251
|
+
if (from === "paused")
|
|
260
252
|
return `Task ${id} is already paused.`;
|
|
253
|
+
try {
|
|
254
|
+
resolveTaskTransition("pause", id, from);
|
|
255
|
+
}
|
|
256
|
+
catch (error) {
|
|
257
|
+
return errorMessage(error);
|
|
258
|
+
}
|
|
261
259
|
task.fields.status = "paused";
|
|
262
260
|
task.fields.wake = undefined;
|
|
263
261
|
if (task.fields.control) {
|
|
262
|
+
task.fields.control.pausedBy = "user";
|
|
264
263
|
task.fields.control.lastOutcome = "blocked";
|
|
265
264
|
task.fields.control.blockedReason = `Paused by ${options.approver?.trim() || "a user"}.`;
|
|
266
265
|
}
|
|
@@ -272,11 +271,14 @@ export async function resumeTask(options, idInput) {
|
|
|
272
271
|
const task = await readStoredTask(options.channelDir, id);
|
|
273
272
|
if (!task)
|
|
274
273
|
return `Task not found: ${id}`;
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
274
|
+
const from = normalizeStoredStatus(task.fields.status);
|
|
275
|
+
if (from !== "paused")
|
|
276
|
+
return `Task ${id} is ${from}, not paused.`;
|
|
277
|
+
resolveTaskTransition("resume", id, from);
|
|
278
|
+
task.fields.status = "active";
|
|
278
279
|
task.fields.wake = undefined;
|
|
279
280
|
if (task.fields.control) {
|
|
281
|
+
task.fields.control.pausedBy = undefined;
|
|
280
282
|
task.fields.control.lastOutcome = "pending";
|
|
281
283
|
task.fields.control.blockedReason = undefined;
|
|
282
284
|
}
|
|
@@ -288,13 +290,17 @@ async function runTask(options, idInput) {
|
|
|
288
290
|
const task = await readStoredTask(options.channelDir, id);
|
|
289
291
|
if (!task)
|
|
290
292
|
return `Task not found: ${id}`;
|
|
291
|
-
|
|
292
|
-
|
|
293
|
+
const from = normalizeStoredStatus(task.fields.status);
|
|
294
|
+
try {
|
|
295
|
+
resolveTaskTransition("run", id, from);
|
|
293
296
|
}
|
|
294
|
-
|
|
295
|
-
|
|
297
|
+
catch (error) {
|
|
298
|
+
return errorMessage(error);
|
|
299
|
+
}
|
|
300
|
+
task.fields.status = "active";
|
|
296
301
|
task.fields.wake = undefined;
|
|
297
302
|
if (task.fields.control) {
|
|
303
|
+
task.fields.control.pausedBy = undefined;
|
|
298
304
|
task.fields.control.lastOutcome = "pending";
|
|
299
305
|
task.fields.control.blockedReason = undefined;
|
|
300
306
|
}
|
|
@@ -409,14 +415,13 @@ async function doctor(options) {
|
|
|
409
415
|
return "# Task Doctor\n\nNot available: workspaceDir and channelId are required.";
|
|
410
416
|
}
|
|
411
417
|
const now = Date.now();
|
|
412
|
-
const hostTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
413
418
|
const entries = await readActiveTasks(tasksDir(options.channelDir), now);
|
|
414
419
|
const activeIds = new Set(entries.map((entry) => entry.id));
|
|
415
420
|
const archivedIds = await readArchivedTaskIds(options.channelDir);
|
|
416
421
|
const events = await readTaskEvents(options.workspaceDir, options.channelId);
|
|
417
422
|
const issues = [];
|
|
418
423
|
for (const entry of entries) {
|
|
419
|
-
const status = entry.frontmatter.status ?? "
|
|
424
|
+
const status = entry.frontmatter.status ?? "active";
|
|
420
425
|
if (!entry.frontmatter.readable) {
|
|
421
426
|
issues.push(issue(`tasks/${entry.id}.md has unreadable frontmatter; wake/status cannot be trusted.`, `Fix tasks/${entry.id}.md so it starts with readable status/wake/recurrence frontmatter.`));
|
|
422
427
|
continue;
|
|
@@ -464,19 +469,10 @@ async function doctor(options) {
|
|
|
464
469
|
}
|
|
465
470
|
}
|
|
466
471
|
}
|
|
467
|
-
const
|
|
468
|
-
const recurring = Boolean(entry.frontmatter.schedule) || isParseableSchedule(events, entry.id);
|
|
472
|
+
const recurring = Boolean(entry.frontmatter.schedule);
|
|
469
473
|
if (status === "done" && !recurring) {
|
|
470
474
|
issues.push(issue(`tasks/${entry.id}.md is done but still in the active directory.`, `Archive one-shot task ${entry.id}, or add a schedule cron with task_manage set if it is recurring.`));
|
|
471
475
|
}
|
|
472
|
-
// Migration (027): recurrence cadence now lives in the task's `schedule` frontmatter.
|
|
473
|
-
// A remaining canonical .schedule event should be folded in and deleted.
|
|
474
|
-
if (legacySchedule && isTaskScheduleEvent(legacySchedule)) {
|
|
475
|
-
issues.push(issue(`events/${legacySchedule.filename} is a legacy task .schedule event; cadence is now native to tasks/${entry.id}.md.`, `Fold its cron "${legacySchedule.event.schedule}" into the task's schedule frontmatter with task_manage set, then delete events/${legacySchedule.filename}.`));
|
|
476
|
-
if (legacySchedule.event.legacyTimezone && legacySchedule.event.legacyTimezone !== hostTimezone) {
|
|
477
|
-
issues.push(issue(`events/${legacySchedule.filename} declares timezone ${legacySchedule.event.legacyTimezone}, which differs from the host ${hostTimezone}.`, `Confirm the intended cadence after folding into frontmatter; the cron will run in the host timezone.`));
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
476
|
const content = await readActiveTaskContent(options.channelDir, entry.id);
|
|
481
477
|
if (content === undefined) {
|
|
482
478
|
issues.push(issue(`tasks/${entry.id}.md could not be read during doctor checks.`, `Open tasks/${entry.id}.md manually and repair permissions or file contents.`));
|
|
@@ -490,18 +486,6 @@ async function doctor(options) {
|
|
|
490
486
|
if (entry.frontmatter.wake && validWakeMs(entry) === undefined) {
|
|
491
487
|
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.`));
|
|
492
488
|
}
|
|
493
|
-
const checkin = eventKey(events, entry.id, "checkin");
|
|
494
|
-
if (checkin && isTaskCheckinEvent(checkin)) {
|
|
495
|
-
issues.push(issue(`events/${checkin.filename} is a legacy task checkin; native wake handling makes it redundant.`, `Delete events/${checkin.filename} and keep the task wake value as the single resume condition.`));
|
|
496
|
-
const wakeMs = validWakeMs(entry);
|
|
497
|
-
const atMs = new Date(checkin.event.at).getTime();
|
|
498
|
-
if (wakeMs === undefined) {
|
|
499
|
-
issues.push(issue(`tasks/${entry.id}.md has a .checkin event but no valid wake value.`, `Set tasks/${entry.id}.md wake to ${checkin.event.at}, or delete the stale .checkin event.`));
|
|
500
|
-
}
|
|
501
|
-
else if (Number.isFinite(atMs) && Math.abs(atMs - wakeMs) > 60_000) {
|
|
502
|
-
issues.push(issue(`tasks/${entry.id}.md wake does not match its .checkin event time.`, `Sync tasks/${entry.id}.md wake with events/${checkin.filename} at ${checkin.event.at}.`));
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
489
|
}
|
|
506
490
|
const parentGraph = new Map();
|
|
507
491
|
const dependencyGraph = new Map();
|
|
@@ -534,12 +518,6 @@ async function doctor(options) {
|
|
|
534
518
|
if (archivedIds.has(event.id)) {
|
|
535
519
|
issues.push(issue(`events/${event.filename} points to archived task ${event.id}; closed tasks should have no live events.`, `Delete events/${event.filename}; archived tasks should not wake the agent.`));
|
|
536
520
|
}
|
|
537
|
-
if (event.use === "schedule" && !isTaskScheduleEvent(event)) {
|
|
538
|
-
issues.push(issue(`events/${event.filename} is a schedule event but is not periodic.`, `Change events/${event.filename} to type periodic, or rename it away from .schedule.`));
|
|
539
|
-
}
|
|
540
|
-
if (event.use === "checkin" && !isTaskCheckinEvent(event)) {
|
|
541
|
-
issues.push(issue(`events/${event.filename} is a checkin event but is not one-shot.`, `Change events/${event.filename} to type one-shot, or rename it away from .checkin.`));
|
|
542
|
-
}
|
|
543
521
|
}
|
|
544
522
|
if (issues.length === 0) {
|
|
545
523
|
return "# Task Doctor\n\nNo task ledger issues found.";
|
|
@@ -6,6 +6,8 @@ export interface TaskDriverOptions {
|
|
|
6
6
|
getKnownChannelIds?: () => Iterable<string>;
|
|
7
7
|
isChannelActive: (channelId: string) => boolean;
|
|
8
8
|
dispatch: (event: DingTalkEvent) => boolean | Promise<boolean>;
|
|
9
|
+
/** Optional observability hook. It runs after every production dispatch attempt. */
|
|
10
|
+
onDispatch?: (event: DingTalkEvent, accepted: boolean) => void;
|
|
9
11
|
getSettings: () => PipiclawTaskDriverSettings;
|
|
10
12
|
/** Master autonomy switch (`tools.tasks.enabled`); re-read every tick. Defaults to on. */
|
|
11
13
|
isEnabled?: () => boolean;
|
|
@@ -14,13 +16,6 @@ export interface TaskDriverOptions {
|
|
|
14
16
|
}
|
|
15
17
|
export declare function discoverTaskChannels(workspaceDir: string, knownChannelIds?: Iterable<string>): Promise<string[]>;
|
|
16
18
|
export declare function createTaskDriverEvent(channelId: string, entry: TaskLedgerEntry, nowMs: number): DingTalkEvent;
|
|
17
|
-
/**
|
|
18
|
-
* A done recurring task whose schedule has come due. This is the one place the driver
|
|
19
|
-
* wakes a `done` task: to open its next cycle. It uses a `[TASK_CYCLE:...]` tag (not
|
|
20
|
-
* `[TASK_DRIVER:...]`) so the turn is not charged an attempt — start-cycle resets usage
|
|
21
|
-
* anyway, matching the retired periodic-event flow.
|
|
22
|
-
*/
|
|
23
|
-
export declare function createCycleStartEvent(channelId: string, entry: TaskLedgerEntry, nowMs: number): DingTalkEvent;
|
|
24
19
|
/**
|
|
25
20
|
* Native, token-gated driver for the persistent task ledger.
|
|
26
21
|
*
|
|
@@ -49,6 +44,7 @@ export declare class TaskDriver {
|
|
|
49
44
|
*/
|
|
50
45
|
private readonly lastDispatchedTaskId;
|
|
51
46
|
constructor(options: TaskDriverOptions);
|
|
47
|
+
private observeDispatch;
|
|
52
48
|
start(): void;
|
|
53
49
|
stop(): void;
|
|
54
50
|
/**
|
|
@@ -62,6 +58,5 @@ export declare class TaskDriver {
|
|
|
62
58
|
/** Fold `candidate` into the earliest interesting wake moment. */
|
|
63
59
|
private noteHorizon;
|
|
64
60
|
private collectHorizons;
|
|
65
|
-
private hasLiveScheduleEvent;
|
|
66
61
|
runOnce(now?: Date): Promise<void>;
|
|
67
62
|
}
|