@oyasmi/pipiclaw 0.8.8-beta.1 → 0.8.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/agent/channel-runner.d.ts +1 -0
- package/dist/agent/channel-runner.js +8 -0
- package/dist/agent/runner-factory.d.ts +2 -0
- package/dist/playbooks/event-scheduling.md +3 -3
- package/dist/playbooks/task-closeout.md +2 -2
- package/dist/playbooks/task-recurring.md +14 -17
- package/dist/playbooks/task-repair.md +1 -1
- package/dist/runtime/bootstrap.d.ts +13 -2
- package/dist/runtime/bootstrap.js +8 -2
- package/dist/runtime/event-commands.js +1 -3
- package/dist/runtime/events.d.ts +6 -2
- package/dist/runtime/events.js +15 -6
- package/dist/runtime/task-commands.js +25 -6
- package/dist/runtime/task-driver.d.ts +36 -0
- package/dist/runtime/task-driver.js +217 -33
- package/dist/security/path-guard.js +3 -1
- package/dist/settings.d.ts +2 -0
- package/dist/settings.js +5 -0
- package/dist/shared/task-ledger.d.ts +3 -0
- package/dist/shared/task-ledger.js +41 -1
- package/dist/shared/task-schedule.d.ts +18 -0
- package/dist/shared/task-schedule.js +50 -0
- package/dist/tasks/store.js +1 -0
- package/dist/tools/event-manage.js +6 -10
- package/dist/tools/task-manage.d.ts +2 -0
- package/dist/tools/task-manage.js +84 -9
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -230,15 +230,15 @@ pipiclaw
|
|
|
230
230
|
- 未知的斜杠命令会被直接拒绝并提示 `/help`,不会作为普通消息发给模型(避免 `/modle` 这类笔误变成一整轮 LLM 调用)。workspace skill 也可作为命令调用(`/skill:<名称>`)。
|
|
231
231
|
- `/model` 依次尝试精确 `provider/modelId`、精确 `modelId`、对完整引用的子串匹配,只有唯一命中时才切换,例如 `/model turbo`。
|
|
232
232
|
|
|
233
|
-
事件与任务的详细用法见 [docs/events-and-
|
|
233
|
+
事件与任务的详细用法见 [docs/events-and-tasks.md](./docs/events-and-tasks.md);子代理见 [docs/sub-agents.md](./docs/sub-agents.md)。
|
|
234
234
|
|
|
235
235
|
## 文档地图(Documentation)
|
|
236
236
|
|
|
237
237
|
| 文档 | 内容 |
|
|
238
238
|
|------|------|
|
|
239
239
|
| [docs/configuration.md](./docs/configuration.md) | 全部配置项:钉钉、模型、settings、tools、TUI、记忆与工作区文件 |
|
|
240
|
-
| [docs/events-and-
|
|
241
|
-
| [docs/
|
|
240
|
+
| [docs/events-and-tasks.md](./docs/events-and-tasks.md) | 定时事件(含 `preAction` 门控、`event_manage`)、任务台账、内建 task driver、`/tasks` 控制面与 `task_manage` 工具 |
|
|
241
|
+
| [docs/sub-agents.md](./docs/sub-agents.md) | 预定义子代理:委派、隔离 worktree 与独立验收 |
|
|
242
242
|
| [docs/runtime-playbooks.md](./docs/runtime-playbooks.md) | Runtime playbooks 与知识分层模型 |
|
|
243
243
|
| [docs/deployment-and-operations.md](./docs/deployment-and-operations.md) | 长期运行、日志、可观测性、升级、备份与排障 |
|
|
244
244
|
| [docs/scaling-and-concurrency.md](./docs/scaling-and-concurrency.md) | 并发模型与容量边界 |
|
|
@@ -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;
|
|
@@ -13,8 +13,8 @@ priority: 30
|
|
|
13
13
|
|
|
14
14
|
- 当前回合立即能做:直接做,不建 immediate。`event_manage` 会拒绝 immediate,防止自触发循环。
|
|
15
15
|
- 将来某时只提醒一次:one-shot,至少提前 2 分钟。
|
|
16
|
-
- 固定节奏重复提醒/检查:periodic,五段 cron
|
|
17
|
-
-
|
|
16
|
+
- 固定节奏重复提醒/检查:periodic,五段 cron(按主机时区解释,无 timezone 字段)。
|
|
17
|
+
- 周期性产出任务:单个 task 文件,节奏写在 frontmatter 的 `schedule`,见 `task-recurring.md`。
|
|
18
18
|
|
|
19
19
|
优先使用 `event_manage`,它会验证 JSON、channel、时间间隔、preAction command guard 和总量。工具不可用时才直接维护 `events/*.json`;无效文件可能被 scheduler 忽略。
|
|
20
20
|
|
|
@@ -25,7 +25,7 @@ priority: 30
|
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
```json
|
|
28
|
-
{"type":"periodic","channelId":"<当前channel>","text":"执行工作日巡检","schedule":"0 9 * * 1-5"
|
|
28
|
+
{"type":"periodic","channelId":"<当前channel>","text":"执行工作日巡检","schedule":"0 9 * * 1-5"}
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
普通 periodic 最小间隔 30 分钟;带 preAction gate 时最小 5 分钟;事件总数上限 50。任务拥有的事件使用 `task.<channelId>.<taskId>.<use>`,便于闭环清理。
|
|
@@ -40,8 +40,8 @@ FAIL 后用 progress 记录失败证据、status 回 in-progress,修复后重
|
|
|
40
40
|
|
|
41
41
|
## done / cancel
|
|
42
42
|
|
|
43
|
-
`task_manage done` 需要 summary 和可查证 evidence,可附 residualRisk。它检查 checkbox、依赖、child、外部授权、独立 PASS,再记录收尾、清理临时 task events
|
|
43
|
+
`task_manage done` 需要 summary 和可查证 evidence,可附 residualRisk。它检查 checkbox、依赖、child、外部授权、独立 PASS,再记录收尾、清理临时 task events;一次性任务归档,有 `schedule` frontmatter 的周期任务算出下一次 `wake` 并原地睡眠。
|
|
44
44
|
|
|
45
|
-
放弃用 `cancel` + reason,不伪装 done。cancel 要求先处理 child
|
|
45
|
+
放弃用 `cancel` + reason,不伪装 done。cancel 要求先处理 child,随后归档并删除全部 task-owned events。
|
|
46
46
|
|
|
47
47
|
完成结论必须来自证据:具体命令、测试结果、review、外部确认或明确的未运行理由。“看起来可以”不是 evidence。
|
|
@@ -1,44 +1,41 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: task-recurring
|
|
3
|
-
description: Before creating, rescheduling, pausing, or retiring a recurring task
|
|
3
|
+
description: Before creating, rescheduling, pausing, or retiring a recurring task.
|
|
4
4
|
requires-tools: task_manage
|
|
5
5
|
priority: 43
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
# 周期性任务
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
一个周期任务就是**一个文件**:`tasks/<id>.md`。节奏在 frontmatter 的 `schedule`(五段 cron,按主机时区解释),做法与跨周期经验在正文。没有配套事件,也没有 `.schedule` 命名约定。
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
- `task.<channelId>.<id>.schedule`:唯一 canonical periodic cadence。
|
|
14
|
-
|
|
15
|
-
节奏在 event,做法在 task。`recurrence` 只是可读标注。
|
|
12
|
+
`recurrence` 只是给人看的可选标注(如 `每周一`),没有机器语义。周期性 = `schedule` 是否存在。
|
|
16
13
|
|
|
17
14
|
## 创建
|
|
18
15
|
|
|
19
|
-
|
|
16
|
+
按 `task-planning.md` 创建 task,并给 `schedule`:
|
|
20
17
|
|
|
21
|
-
```
|
|
22
|
-
|
|
18
|
+
```
|
|
19
|
+
task_manage create id=weekly-report title=... goal=... dod=... schedule="30 9 * * 1"
|
|
23
20
|
```
|
|
24
21
|
|
|
25
|
-
|
|
22
|
+
cron 最密每 30 分钟一次,落盘前校验。纯提醒(无产出、无验收)不建 task,用普通 periodic event。
|
|
26
23
|
|
|
27
24
|
## 周期运行
|
|
28
25
|
|
|
29
|
-
done
|
|
26
|
+
done 的周期任务留在原地睡眠:`task_manage done` 会用 croner 算出下一次 occurrence 写入 `wake`,状态是 `done` + 未来的 `wake`。到点时 driver 自动派发一条 cycle-start 唤醒。
|
|
30
27
|
|
|
31
|
-
-
|
|
28
|
+
- 收到 cycle-start:调用 `task_manage start-cycle`,给稳定 cycleId。它原子折叠上一周期日志、清空本周期用量/验收/授权/worktree 元数据并置 in-progress。
|
|
32
29
|
- 上周期未完成:不要覆盖或虚勾 DoD。先完成、如实缩小本轮范围并验收,或与用户确认后 cancel 整项任务。
|
|
33
30
|
|
|
34
|
-
|
|
31
|
+
周期内继续、等待和恢复只用 task `wake`。
|
|
35
32
|
|
|
36
33
|
## 复盘、调整和退役
|
|
37
34
|
|
|
38
35
|
每轮闭环前把返工原因、预检步骤和格式偏好写回 Manual;跨任务才沉淀 workspace skill。
|
|
39
36
|
|
|
40
|
-
-
|
|
41
|
-
-
|
|
42
|
-
- 退役:`task_manage cancel
|
|
37
|
+
- 改节奏:`task_manage set schedule="<新 cron>"`;若任务当前 done,同一次写入会重算 `wake`。一处真相。
|
|
38
|
+
- 暂停:`/tasks pause <id>`;`/tasks resume` 恢复。
|
|
39
|
+
- 退役:`task_manage cancel`,归档任务并清理全部 task-owned events。
|
|
43
40
|
|
|
44
|
-
不要手工改 status
|
|
41
|
+
不要手工改 status 开周期。
|
|
@@ -40,6 +40,6 @@ PASS 和 external approval 都绑定 task body;PASS 还可能绑定 Git artifa
|
|
|
40
40
|
|
|
41
41
|
## 事件与重启
|
|
42
42
|
|
|
43
|
-
done/cancel 会清理 `task.<channelId>.<id>.*`;孤儿事件用 event_manage
|
|
43
|
+
done/cancel 会清理 `task.<channelId>.<id>.*`;孤儿事件用 event_manage 删除。周期任务的节奏在 frontmatter 的 `schedule`;旧 `.checkin` / `.schedule` 是 legacy,把 cron 折进 frontmatter 后删除事件,以 wake 为单一恢复条件(`/tasks doctor` 会给出迁移提示)。
|
|
44
44
|
|
|
45
45
|
task 文件是恢复真相。daemon 重启会清空内存 cooldown,可推进任务可能很快重放;durable dispatch 租约也提供至少一次派发。每次先核对已完成产物,避免重复外部动作。
|
|
@@ -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;
|
|
@@ -68,8 +75,12 @@ interface RuntimeContextOptions {
|
|
|
68
75
|
createTaskDriver?: () => {
|
|
69
76
|
start(): void;
|
|
70
77
|
stop(): void;
|
|
78
|
+
nudge?(): void;
|
|
71
79
|
};
|
|
72
|
-
|
|
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
|
}
|
|
@@ -423,6 +423,7 @@ export function createRuntimeContext(options) {
|
|
|
423
423
|
appHomeDir: options.paths.appHomeDir,
|
|
424
424
|
authConfigPath: options.paths.authConfigPath,
|
|
425
425
|
modelsConfigPath: options.paths.modelsConfigPath,
|
|
426
|
+
onSessionEvent: options.observer,
|
|
426
427
|
});
|
|
427
428
|
channelRunners.set(channelId, runner);
|
|
428
429
|
}
|
|
@@ -436,7 +437,7 @@ export function createRuntimeContext(options) {
|
|
|
436
437
|
const runner = channelRunners.get(channelId);
|
|
437
438
|
if (runner?.isBusy()) {
|
|
438
439
|
runner.requestStop();
|
|
439
|
-
const taskId = /^\[
|
|
440
|
+
const taskId = /^\[TASK_(?:DRIVER|CYCLE):([A-Za-z0-9._-]+)\]/.exec(runner.getTurnStatus().taskText ?? "")?.[1];
|
|
440
441
|
if (taskId) {
|
|
441
442
|
const pauseResult = await pauseTask({
|
|
442
443
|
args: "",
|
|
@@ -646,6 +647,9 @@ export function createRuntimeContext(options) {
|
|
|
646
647
|
finally {
|
|
647
648
|
await durableDispatch?.markCompleted(event.dispatchId);
|
|
648
649
|
runner.endTurn();
|
|
650
|
+
// A finished turn may have written task files (progress/done/start-cycle); rescan
|
|
651
|
+
// now so a continuing task chain advances immediately instead of after a full sleep.
|
|
652
|
+
taskDriver.nudge?.();
|
|
649
653
|
}
|
|
650
654
|
})();
|
|
651
655
|
activeTasks.add(task);
|
|
@@ -711,12 +715,12 @@ export function createRuntimeContext(options) {
|
|
|
711
715
|
getKnownChannelIds: () => channelRunners.keys(),
|
|
712
716
|
isChannelActive: (channelId) => channelRunners.get(channelId)?.isBusy() ?? false,
|
|
713
717
|
dispatch: (event) => durableDispatch?.dispatch(event) ?? false,
|
|
718
|
+
onDispatch: options.onTaskDriverDispatch,
|
|
714
719
|
getSettings: () => {
|
|
715
720
|
runtimeSettingsManager.reload();
|
|
716
721
|
return runtimeSettingsManager.getTaskDriverSettings();
|
|
717
722
|
},
|
|
718
723
|
isEnabled: () => loadToolsConfig(options.paths.appHomeDir).tools.tasks.enabled,
|
|
719
|
-
intervalMs: options.taskDriverIntervalMs,
|
|
720
724
|
});
|
|
721
725
|
const shutdownWithReason = async (reason = "manual") => {
|
|
722
726
|
if (shutdownPromise) {
|
|
@@ -770,6 +774,7 @@ export function createRuntimeContext(options) {
|
|
|
770
774
|
appHomeDir: options.paths.appHomeDir,
|
|
771
775
|
authConfigPath: options.paths.authConfigPath,
|
|
772
776
|
modelsConfigPath: options.paths.modelsConfigPath,
|
|
777
|
+
onSessionEvent: options.observer,
|
|
773
778
|
}, channelDir);
|
|
774
779
|
}
|
|
775
780
|
const storageFlushes = [
|
|
@@ -809,6 +814,7 @@ export function createRuntimeContext(options) {
|
|
|
809
814
|
handler,
|
|
810
815
|
store,
|
|
811
816
|
bot,
|
|
817
|
+
taskDriver,
|
|
812
818
|
shutdown: shutdownWithReason,
|
|
813
819
|
};
|
|
814
820
|
}
|
|
@@ -72,7 +72,7 @@ function formatEventSummary(name, event) {
|
|
|
72
72
|
lines.push(` at: ${event.at}`);
|
|
73
73
|
}
|
|
74
74
|
if (event.type === "periodic") {
|
|
75
|
-
lines.push(` schedule: ${event.schedule}
|
|
75
|
+
lines.push(` schedule: ${event.schedule}`);
|
|
76
76
|
}
|
|
77
77
|
lines.push(` text: ${clipText(event.text)}`);
|
|
78
78
|
return lines.join("\n");
|
|
@@ -140,8 +140,6 @@ function formatHistoryRecord(record) {
|
|
|
140
140
|
details.push(` channelId: ${record.channelId}`);
|
|
141
141
|
if (record.schedule)
|
|
142
142
|
details.push(` schedule: ${record.schedule}`);
|
|
143
|
-
if (record.timezone)
|
|
144
|
-
details.push(` timezone: ${record.timezone}`);
|
|
145
143
|
if (record.at)
|
|
146
144
|
details.push(` at: ${record.at}`);
|
|
147
145
|
if (record.nextRunAt)
|
package/dist/runtime/events.d.ts
CHANGED
|
@@ -24,7 +24,12 @@ export interface PeriodicEvent {
|
|
|
24
24
|
channelId: string;
|
|
25
25
|
text: string;
|
|
26
26
|
schedule: string;
|
|
27
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Legacy field only. Pre-027 events carried an IANA `timezone`; it is no longer part of
|
|
29
|
+
* the contract (cron follows the host timezone) but is preserved here on load so the
|
|
30
|
+
* watcher can warn when it disagrees with the host, without rejecting or rewriting the file.
|
|
31
|
+
*/
|
|
32
|
+
legacyTimezone?: string;
|
|
28
33
|
preAction?: EventAction;
|
|
29
34
|
}
|
|
30
35
|
export type ScheduledEvent = ImmediateEvent | OneShotEvent | PeriodicEvent;
|
|
@@ -40,7 +45,6 @@ export interface EventHistoryRecord {
|
|
|
40
45
|
result: EventHistoryResult;
|
|
41
46
|
reason?: string;
|
|
42
47
|
schedule?: string;
|
|
43
|
-
timezone?: string;
|
|
44
48
|
at?: string;
|
|
45
49
|
nextRunAt?: string;
|
|
46
50
|
textPreview?: string;
|
package/dist/runtime/events.js
CHANGED
|
@@ -91,15 +91,15 @@ export function parseScheduledEventContent(content, filename) {
|
|
|
91
91
|
if (typeof data.schedule !== "string" || data.schedule.trim().length === 0) {
|
|
92
92
|
throw new Error(`Missing 'schedule' field for periodic event in ${filename}`);
|
|
93
93
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
// A legacy `timezone` is tolerated (never a parse error) and carried through only for
|
|
95
|
+
// the host-mismatch warning; the cron itself is always host-timezone.
|
|
96
|
+
const legacyTimezone = typeof data.timezone === "string" && data.timezone.trim().length > 0 ? data.timezone : undefined;
|
|
97
97
|
return {
|
|
98
98
|
type,
|
|
99
99
|
channelId,
|
|
100
100
|
text,
|
|
101
101
|
schedule: data.schedule,
|
|
102
|
-
|
|
102
|
+
...(legacyTimezone ? { legacyTimezone } : {}),
|
|
103
103
|
...(preAction ? { preAction } : {}),
|
|
104
104
|
};
|
|
105
105
|
}
|
|
@@ -212,7 +212,7 @@ export class EventsWatcher {
|
|
|
212
212
|
result,
|
|
213
213
|
textPreview: truncateTextPreview(event.text),
|
|
214
214
|
...(event.type === "one-shot" ? { at: event.at } : {}),
|
|
215
|
-
...(event.type === "periodic" ? { schedule: event.schedule
|
|
215
|
+
...(event.type === "periodic" ? { schedule: event.schedule } : {}),
|
|
216
216
|
...extra,
|
|
217
217
|
});
|
|
218
218
|
}
|
|
@@ -401,8 +401,17 @@ export class EventsWatcher {
|
|
|
401
401
|
this.timers.set(filename, timer);
|
|
402
402
|
}
|
|
403
403
|
handlePeriodic(filename, event) {
|
|
404
|
+
if (event.legacyTimezone) {
|
|
405
|
+
const hostTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
406
|
+
if (event.legacyTimezone !== hostTimezone) {
|
|
407
|
+
log.logWarning(`Event ${filename} carries a legacy timezone ${event.legacyTimezone} that differs from the host ${hostTimezone}`, "The cron is now interpreted in the host timezone; trigger times may shift.");
|
|
408
|
+
this.appendEventHistory(filename, event, "loaded", "ok", {
|
|
409
|
+
reason: `legacy timezone ${event.legacyTimezone} ignored; using host ${hostTimezone}`,
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
}
|
|
404
413
|
try {
|
|
405
|
-
const cron = new Cron(event.schedule,
|
|
414
|
+
const cron = new Cron(event.schedule, async () => {
|
|
406
415
|
try {
|
|
407
416
|
log.logInfo(`Executing periodic event: ${filename}`);
|
|
408
417
|
this.appendEventHistory(filename, event, "triggered", "ok");
|
|
@@ -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 { isTaskCheckinEvent, isTaskScheduleEvent, parseTaskEventName, taskEventPrefix
|
|
4
|
+
import { isTaskCheckinEvent, isTaskScheduleEvent, 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 { readVerificationAttestation } from "../tasks/verification.js";
|
|
9
10
|
import { parseScheduledEventContent } from "./events.js";
|
|
10
11
|
function usage() {
|
|
11
12
|
return `# Tasks
|
|
@@ -408,6 +409,7 @@ async function doctor(options) {
|
|
|
408
409
|
return "# Task Doctor\n\nNot available: workspaceDir and channelId are required.";
|
|
409
410
|
}
|
|
410
411
|
const now = Date.now();
|
|
412
|
+
const hostTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
411
413
|
const entries = await readActiveTasks(tasksDir(options.channelDir), now);
|
|
412
414
|
const activeIds = new Set(entries.map((entry) => entry.id));
|
|
413
415
|
const archivedIds = await readArchivedTaskIds(options.channelDir);
|
|
@@ -450,10 +452,30 @@ async function doctor(options) {
|
|
|
450
452
|
if (storedTask && taskBodyHash(storedTask.body) !== control.verification.bodyHash) {
|
|
451
453
|
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.`));
|
|
452
454
|
}
|
|
455
|
+
else if (control.verification.mode === "independent") {
|
|
456
|
+
const attestationOk = control.verification.runId
|
|
457
|
+
? await readVerificationAttestation(options.channelDir, control.verification.runId)
|
|
458
|
+
.then((attestation) => attestation.taskId === entry.id && attestation.verdict === "pass")
|
|
459
|
+
.catch(() => false)
|
|
460
|
+
: false;
|
|
461
|
+
if (!attestationOk) {
|
|
462
|
+
issues.push(issue(`tasks/${entry.id}.md records an independent PASS with no matching verifier attestation on disk.`, `Run a fresh purpose=verify sub-agent and import its attestation with task_manage verify before completion.`));
|
|
463
|
+
}
|
|
464
|
+
}
|
|
453
465
|
}
|
|
454
466
|
}
|
|
455
|
-
|
|
456
|
-
|
|
467
|
+
const legacySchedule = eventKey(events, entry.id, "schedule");
|
|
468
|
+
const recurring = Boolean(entry.frontmatter.schedule) || isParseableSchedule(events, entry.id);
|
|
469
|
+
if (status === "done" && !recurring) {
|
|
470
|
+
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
|
+
}
|
|
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
|
+
}
|
|
457
479
|
}
|
|
458
480
|
const content = await readActiveTaskContent(options.channelDir, entry.id);
|
|
459
481
|
if (content === undefined) {
|
|
@@ -465,9 +487,6 @@ async function doctor(options) {
|
|
|
465
487
|
issues.push(issue(`tasks/${entry.id}.md is missing standard section(s): ${missing.join(", ")}.`, `Ask the agent to normalize tasks/${entry.id}.md to the standard task skeleton.`));
|
|
466
488
|
}
|
|
467
489
|
}
|
|
468
|
-
if (entry.frontmatter.recurrence && !isParseableSchedule(events, entry.id)) {
|
|
469
|
-
issues.push(issue(`tasks/${entry.id}.md has recurrence but no parseable ${taskScheduleEventName(options.channelId, entry.id)} event.`, `Create or repair events/${taskScheduleEventName(options.channelId, entry.id)}.json as a periodic event.`));
|
|
470
|
-
}
|
|
471
490
|
if (entry.frontmatter.wake && validWakeMs(entry) === undefined) {
|
|
472
491
|
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.`));
|
|
473
492
|
}
|
|
@@ -6,13 +6,23 @@ 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
|
+
/** Test-only override for the idle-sleep cap; production uses `settings.maxSleepMinutes`. */
|
|
12
15
|
intervalMs?: number;
|
|
13
16
|
}
|
|
14
17
|
export declare function discoverTaskChannels(workspaceDir: string, knownChannelIds?: Iterable<string>): Promise<string[]>;
|
|
15
18
|
export declare function createTaskDriverEvent(channelId: string, entry: TaskLedgerEntry, nowMs: number): DingTalkEvent;
|
|
19
|
+
/**
|
|
20
|
+
* A done recurring task whose schedule has come due. This is the one place the driver
|
|
21
|
+
* wakes a `done` task: to open its next cycle. It uses a `[TASK_CYCLE:...]` tag (not
|
|
22
|
+
* `[TASK_DRIVER:...]`) so the turn is not charged an attempt — start-cycle resets usage
|
|
23
|
+
* anyway, matching the retired periodic-event flow.
|
|
24
|
+
*/
|
|
25
|
+
export declare function createCycleStartEvent(channelId: string, entry: TaskLedgerEntry, nowMs: number): DingTalkEvent;
|
|
16
26
|
/**
|
|
17
27
|
* Native, token-gated driver for the persistent task ledger.
|
|
18
28
|
*
|
|
@@ -24,11 +34,37 @@ export declare function createTaskDriverEvent(channelId: string, entry: TaskLedg
|
|
|
24
34
|
export declare class TaskDriver {
|
|
25
35
|
private readonly options;
|
|
26
36
|
private timer;
|
|
37
|
+
private nudgeTimer;
|
|
38
|
+
private loopActive;
|
|
27
39
|
private running;
|
|
28
40
|
private nextChannelIndex;
|
|
41
|
+
/** Absolute ms of the next moment worth waking for (min wake/deadline/backoff), recomputed each scan. */
|
|
42
|
+
private nextWakeMs;
|
|
29
43
|
private readonly attempts;
|
|
44
|
+
/**
|
|
45
|
+
* Last task id dispatched per channel. Cross-channel fairness is handled by
|
|
46
|
+
* `nextChannelIndex`, but within one channel every tick used to pick the first ready
|
|
47
|
+
* candidate in sort order — an actively-progressing task keeps winning that slot forever,
|
|
48
|
+
* starving every other ready task (including its own unlocked dependents) in the same
|
|
49
|
+
* channel. Remembering the last pick and starting the search just after it gives ready
|
|
50
|
+
* candidates in a channel the same round-robin fairness across ticks.
|
|
51
|
+
*/
|
|
52
|
+
private readonly lastDispatchedTaskId;
|
|
30
53
|
constructor(options: TaskDriverOptions);
|
|
54
|
+
private observeDispatch;
|
|
31
55
|
start(): void;
|
|
32
56
|
stop(): void;
|
|
57
|
+
/**
|
|
58
|
+
* In-process wake: after a turn ends or a task file is written, re-scan promptly instead
|
|
59
|
+
* of waiting out the current sleep. The timer is a hint; the scan re-reads every file, so
|
|
60
|
+
* a stale or missed nudge only costs one capped sleep of latency, never correctness.
|
|
61
|
+
*/
|
|
62
|
+
nudge(): void;
|
|
63
|
+
private tick;
|
|
64
|
+
private scheduleNext;
|
|
65
|
+
/** Fold `candidate` into the earliest interesting wake moment. */
|
|
66
|
+
private noteHorizon;
|
|
67
|
+
private collectHorizons;
|
|
68
|
+
private hasLiveScheduleEvent;
|
|
33
69
|
runOnce(now?: Date): Promise<void>;
|
|
34
70
|
}
|