@oyasmi/pipiclaw 0.8.7 → 0.8.8-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 +14 -14
- package/dist/models/api-keys.js +1 -1
- package/dist/paths.d.ts +8 -0
- package/dist/paths.js +9 -1
- 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 +3 -2
- package/dist/runtime/bootstrap.js +33 -6
- 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 +33 -0
- package/dist/runtime/task-driver.js +204 -32
- 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/dist/tui/app.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -51,7 +51,7 @@ pipiclaw
|
|
|
51
51
|
程序会创建:
|
|
52
52
|
|
|
53
53
|
```text
|
|
54
|
-
~/.
|
|
54
|
+
~/.pipiclaw/
|
|
55
55
|
├── channel.json # 钉钉应用配置
|
|
56
56
|
├── auth.json # 模型凭据
|
|
57
57
|
├── models.json # 自定义模型提供方
|
|
@@ -62,7 +62,7 @@ pipiclaw
|
|
|
62
62
|
# events/、skills/、sub-agents/ 及各会话通道目录
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
-
默认 app home 是 `~/.
|
|
65
|
+
默认 app home 是 `~/.pipiclaw/`;设置 `PIPICLAW_HOME=/your/path` 可整体迁移。如果 `channel.json` 仍是初始化模板,程序会提示补全配置后再启动,这是正常行为。
|
|
66
66
|
|
|
67
67
|
### 4. 创建钉钉应用(Create a DingTalk App)
|
|
68
68
|
|
|
@@ -75,7 +75,7 @@ pipiclaw
|
|
|
75
75
|
|
|
76
76
|
### 5. 填写 `channel.json`(Fill `channel.json`)
|
|
77
77
|
|
|
78
|
-
编辑 `~/.
|
|
78
|
+
编辑 `~/.pipiclaw/channel.json`:
|
|
79
79
|
|
|
80
80
|
```json
|
|
81
81
|
{
|
|
@@ -102,7 +102,7 @@ pipiclaw
|
|
|
102
102
|
export ANTHROPIC_API_KEY=sk-ant-...
|
|
103
103
|
```
|
|
104
104
|
|
|
105
|
-
或写入 `~/.
|
|
105
|
+
或写入 `~/.pipiclaw/auth.json`:
|
|
106
106
|
|
|
107
107
|
```json
|
|
108
108
|
{
|
|
@@ -110,7 +110,7 @@ export ANTHROPIC_API_KEY=sk-ant-...
|
|
|
110
110
|
}
|
|
111
111
|
```
|
|
112
112
|
|
|
113
|
-
**方案 B:自定义模型提供方。** 适用于 OpenAI-compatible 网关、代理、自建或聚合服务,编辑 `~/.
|
|
113
|
+
**方案 B:自定义模型提供方。** 适用于 OpenAI-compatible 网关、代理、自建或聚合服务,编辑 `~/.pipiclaw/models.json`:
|
|
114
114
|
|
|
115
115
|
```json
|
|
116
116
|
{
|
|
@@ -135,7 +135,7 @@ export ANTHROPIC_API_KEY=sk-ant-...
|
|
|
135
135
|
|
|
136
136
|
### 7. 可选:设置默认模型(Optional: Set a Default Model)
|
|
137
137
|
|
|
138
|
-
编辑 `~/.
|
|
138
|
+
编辑 `~/.pipiclaw/settings.json`:
|
|
139
139
|
|
|
140
140
|
```json
|
|
141
141
|
{
|
|
@@ -156,7 +156,7 @@ pipiclaw
|
|
|
156
156
|
|
|
157
157
|
### 9. 可选:启用内建 Web 工具(Optional: Enable Web Tools)
|
|
158
158
|
|
|
159
|
-
`web_search` / `web_fetch` 默认关闭。首次启动生成的 `~/.
|
|
159
|
+
`web_search` / `web_fetch` 默认关闭。首次启动生成的 `~/.pipiclaw/tools.json` 已带可直接改用的模板,通常只需三步:
|
|
160
160
|
|
|
161
161
|
1. 把 `tools.web.enable` 改成 `true`
|
|
162
162
|
2. 填入搜索 provider 的 `apiKey`(默认示例为 Brave)
|
|
@@ -185,17 +185,17 @@ pipiclaw
|
|
|
185
185
|
|
|
186
186
|
1. 先检查 Node.js 版本,必须 >= 22.19.0;不满足就停下来告诉我,不要继续安装。
|
|
187
187
|
2. 执行 npm install -g @oyasmi/pipiclaw。权限失败时不要自行 sudo,把报错给我并询问怎么处理。
|
|
188
|
-
3. 运行一次 pipiclaw,让它初始化 ~/.
|
|
188
|
+
3. 运行一次 pipiclaw,让它初始化 ~/.pipiclaw/ 和 workspace/。
|
|
189
189
|
4. 逐项询问我是否现在提供:钉钉应用的 clientId 和 clientSecret、AI Card 的
|
|
190
190
|
cardTemplateId、模型接入方式(Anthropic 或自定义 provider)。
|
|
191
|
-
5. 钉钉配置写入 ~/.
|
|
191
|
+
5. 钉钉配置写入 ~/.pipiclaw/channel.json:robotCode 可留空,allowFrom 先设 []。
|
|
192
192
|
AI Card 是推荐配置;我暂不提供 cardTemplateId 时可先留空,但最后要提醒我补上。
|
|
193
193
|
最终文件里不要保留任何 your-* 占位值。
|
|
194
194
|
6. 模型配置:
|
|
195
195
|
- 我选 Anthropic:询问我是否提供 ANTHROPIC_API_KEY;提供就配置到可用,
|
|
196
196
|
不提供就保留默认空 models.json,并告诉我之后要补 auth.json 或环境变量。
|
|
197
197
|
- 我选自定义 provider:至少收集 provider 名称、baseUrl、api 类型、apiKey、
|
|
198
|
-
一个 model id,写入 ~/.
|
|
198
|
+
一个 model id,写入 ~/.pipiclaw/models.json;OpenAI-compatible 服务优先用
|
|
199
199
|
openai-completions,并默认加 compat:supportsDeveloperRole: false、
|
|
200
200
|
supportsReasoningEffort: false。
|
|
201
201
|
- 我不提供的值不要编造。收尾时明确列出还缺什么、该改哪个文件。
|
|
@@ -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) | 并发模型与容量边界 |
|
|
@@ -257,7 +257,7 @@ npm run check # lint + typecheck + deadcode + test
|
|
|
257
257
|
端到端测试说明:
|
|
258
258
|
|
|
259
259
|
- `npm run test:e2e` 运行"除钉钉渠道外"的完整 E2E:真实 runtime、真实工具/记忆/Sidecar/LLM,只 mock 钉钉传输层。
|
|
260
|
-
- 需要可用模型凭据:优先读取 `${PIPICLAW_HOME:-~/.
|
|
260
|
+
- 需要可用模型凭据:优先读取 `${PIPICLAW_HOME:-~/.pipiclaw}/auth.json`,否则回退到 `ANTHROPIC_API_KEY`。
|
|
261
261
|
- 默认模型是 `anthropic/claude-sonnet-4-5`;使用其他 provider 时用 `PIPICLAW_E2E_PROVIDER` / `PIPICLAW_E2E_MODEL` 覆盖,例如 `PIPICLAW_E2E_PROVIDER=zpai PIPICLAW_E2E_MODEL=glm-5-turbo npm run test:e2e`。
|
|
262
262
|
- E2E 不包含在 `npm run test` 中,避免日常测试被真实 LLM 依赖和调用成本影响。
|
|
263
263
|
|
package/dist/models/api-keys.js
CHANGED
|
@@ -18,5 +18,5 @@ export async function getApiKeyForModel(modelRegistry, model) {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
throw new Error(`No API key found for provider: ${model.provider}.\n\n` +
|
|
21
|
-
"Configure credentials in ~/.
|
|
21
|
+
"Configure credentials in ~/.pipiclaw/auth.json or ~/.pipiclaw/models.json, or set the matching provider environment variable.");
|
|
22
22
|
}
|
package/dist/paths.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
export declare const APP_NAME = "pipiclaw";
|
|
2
2
|
/** Prefer live source docs in a checkout; installed packages fall back to dist/playbooks. */
|
|
3
3
|
export declare const PLAYBOOKS_DIR: string;
|
|
4
|
+
/**
|
|
5
|
+
* Legacy default app home used before the `~/.pipiclaw` default (introduced in
|
|
6
|
+
* 0.8.x). Kept only so bootstrap can migrate an existing install to the new
|
|
7
|
+
* default. FIXME(0.9.0): drop this together with the migration in bootstrap.ts.
|
|
8
|
+
*/
|
|
9
|
+
export declare const LEGACY_APP_HOME_DIR: string;
|
|
10
|
+
/** The built-in default app home, independent of any `PIPICLAW_HOME` override. */
|
|
11
|
+
export declare const DEFAULT_APP_HOME_DIR: string;
|
|
4
12
|
export declare const APP_HOME_DIR: string;
|
|
5
13
|
export declare const WORKSPACE_DIR: string;
|
|
6
14
|
export declare const STATE_DIR: string;
|
package/dist/paths.js
CHANGED
|
@@ -12,7 +12,15 @@ const bundledPlaybooksDir = fileURLToPath(new URL("./playbooks", import.meta.url
|
|
|
12
12
|
const checkoutPlaybooksDir = fileURLToPath(new URL("../src/playbooks", import.meta.url));
|
|
13
13
|
/** Prefer live source docs in a checkout; installed packages fall back to dist/playbooks. */
|
|
14
14
|
export const PLAYBOOKS_DIR = existsSync(checkoutPlaybooksDir) ? checkoutPlaybooksDir : bundledPlaybooksDir;
|
|
15
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Legacy default app home used before the `~/.pipiclaw` default (introduced in
|
|
17
|
+
* 0.8.x). Kept only so bootstrap can migrate an existing install to the new
|
|
18
|
+
* default. FIXME(0.9.0): drop this together with the migration in bootstrap.ts.
|
|
19
|
+
*/
|
|
20
|
+
export const LEGACY_APP_HOME_DIR = join(homedir(), ".pi", APP_NAME);
|
|
21
|
+
/** The built-in default app home, independent of any `PIPICLAW_HOME` override. */
|
|
22
|
+
export const DEFAULT_APP_HOME_DIR = join(homedir(), `.${APP_NAME}`);
|
|
23
|
+
export const APP_HOME_DIR = process.env.PIPICLAW_HOME ?? DEFAULT_APP_HOME_DIR;
|
|
16
24
|
export const WORKSPACE_DIR = join(APP_HOME_DIR, "workspace");
|
|
17
25
|
export const STATE_DIR = join(APP_HOME_DIR, "state");
|
|
18
26
|
export const EVENT_STATE_DIR = join(STATE_DIR, "events");
|
|
@@ -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 租约也提供至少一次派发。每次先核对已完成产物,避免重复外部动作。
|
|
@@ -46,7 +46,8 @@ export declare class BootstrapExitError extends Error {
|
|
|
46
46
|
}
|
|
47
47
|
export declare function isBootstrapExitError(error: unknown): error is BootstrapExitError;
|
|
48
48
|
export declare function readCliVersion(): string;
|
|
49
|
-
export declare function
|
|
49
|
+
export declare function migrateLegacyAppHome(targetDir: string, legacyDir: string, io: BootstrapIO): boolean;
|
|
50
|
+
export declare function bootstrapAppHome(paths?: BootstrapPaths, io?: BootstrapIO): BootstrapResult;
|
|
50
51
|
export declare function printBootstrapSummary(result: BootstrapResult, io?: BootstrapIO, paths?: BootstrapPaths): void;
|
|
51
52
|
export declare function loadConfig(paths?: BootstrapPaths, io?: BootstrapIO): DingTalkConfig;
|
|
52
53
|
export declare function parseArgs(argv: string[], paths?: BootstrapPaths, io?: BootstrapIO): void;
|
|
@@ -67,8 +68,8 @@ interface RuntimeContextOptions {
|
|
|
67
68
|
createTaskDriver?: () => {
|
|
68
69
|
start(): void;
|
|
69
70
|
stop(): void;
|
|
71
|
+
nudge?(): void;
|
|
70
72
|
};
|
|
71
|
-
taskDriverIntervalMs?: number;
|
|
72
73
|
startServices?: boolean;
|
|
73
74
|
registerSignalHandlers?: boolean;
|
|
74
75
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { chmodSync, existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "fs";
|
|
1
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from "fs";
|
|
2
2
|
import { join } from "path";
|
|
3
3
|
import { formatUnknownCommandMessage, isRunnerBuiltInCommand, parseBuiltInCommand, slashCommandName, } from "../agent/commands.js";
|
|
4
4
|
import { getOrCreateRunner } from "../agent/index.js";
|
|
@@ -9,7 +9,7 @@ import { createExecutor } from "../executor.js";
|
|
|
9
9
|
import * as log from "../log.js";
|
|
10
10
|
import { ensureChannelMemoryFilesSync } from "../memory/files.js";
|
|
11
11
|
import { MemoryMaintenanceScheduler } from "../memory/scheduler.js";
|
|
12
|
-
import { APP_HOME_DIR, APP_NAME, AUTH_CONFIG_PATH, CHANNEL_CONFIG_PATH, EVENT_HISTORY_PATH, MODELS_CONFIG_PATH, SECURITY_CONFIG_PATH, SETTINGS_CONFIG_PATH, TOOLS_CONFIG_PATH, WORKSPACE_DIR, } from "../paths.js";
|
|
12
|
+
import { APP_HOME_DIR, APP_NAME, AUTH_CONFIG_PATH, CHANNEL_CONFIG_PATH, DEFAULT_APP_HOME_DIR, EVENT_HISTORY_PATH, LEGACY_APP_HOME_DIR, MODELS_CONFIG_PATH, SECURITY_CONFIG_PATH, SETTINGS_CONFIG_PATH, TOOLS_CONFIG_PATH, WORKSPACE_DIR, } from "../paths.js";
|
|
13
13
|
import { loadSecurityConfigWithDiagnostics } from "../security/config.js";
|
|
14
14
|
import { flushSecurityLogs } from "../security/logger.js";
|
|
15
15
|
import { PipiclawSettingsManager } from "../settings.js";
|
|
@@ -185,8 +185,33 @@ function hardenExistingSecretFile(path) {
|
|
|
185
185
|
log.logWarning(`Failed to tighten permissions on ${path}`, errorMessage(err));
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
|
-
|
|
188
|
+
// FIXME(0.9.0): remove this legacy-home migration (and LEGACY_APP_HOME_DIR).
|
|
189
|
+
// The default app home moved from `~/.pi/pipiclaw` to `~/.pipiclaw`. When the
|
|
190
|
+
// new default location is not yet present but a legacy install is, move the old
|
|
191
|
+
// directory over so existing users keep their config/workspace/state with no
|
|
192
|
+
// manual step. Exported for direct testing; the env-gating (only for the real
|
|
193
|
+
// default home, never a custom PIPICLAW_HOME) lives at the call site.
|
|
194
|
+
export function migrateLegacyAppHome(targetDir, legacyDir, io) {
|
|
195
|
+
if (existsSync(targetDir) || !existsSync(legacyDir)) {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
try {
|
|
199
|
+
renameSync(legacyDir, targetDir);
|
|
200
|
+
io.log(`Migrated existing data from ${legacyDir} to ${targetDir}.`);
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
catch (err) {
|
|
204
|
+
io.error(`Failed to migrate ${legacyDir} to ${targetDir}: ${errorMessage(err)}`);
|
|
205
|
+
io.error(`Move it manually, or set PIPICLAW_HOME=${legacyDir} to keep using the old location.`);
|
|
206
|
+
throw new BootstrapExitError(1);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
export function bootstrapAppHome(paths = DEFAULT_BOOTSTRAP_PATHS, io = console) {
|
|
189
210
|
const created = [];
|
|
211
|
+
// FIXME(0.9.0): remove alongside migrateLegacyAppHome.
|
|
212
|
+
if (paths.appHomeDir === DEFAULT_APP_HOME_DIR) {
|
|
213
|
+
migrateLegacyAppHome(paths.appHomeDir, LEGACY_APP_HOME_DIR, io);
|
|
214
|
+
}
|
|
190
215
|
if (!existsSync(paths.appHomeDir)) {
|
|
191
216
|
mkdirSync(paths.appHomeDir, { recursive: true });
|
|
192
217
|
created.push("app home");
|
|
@@ -411,7 +436,7 @@ export function createRuntimeContext(options) {
|
|
|
411
436
|
const runner = channelRunners.get(channelId);
|
|
412
437
|
if (runner?.isBusy()) {
|
|
413
438
|
runner.requestStop();
|
|
414
|
-
const taskId = /^\[
|
|
439
|
+
const taskId = /^\[TASK_(?:DRIVER|CYCLE):([A-Za-z0-9._-]+)\]/.exec(runner.getTurnStatus().taskText ?? "")?.[1];
|
|
415
440
|
if (taskId) {
|
|
416
441
|
const pauseResult = await pauseTask({
|
|
417
442
|
args: "",
|
|
@@ -621,6 +646,9 @@ export function createRuntimeContext(options) {
|
|
|
621
646
|
finally {
|
|
622
647
|
await durableDispatch?.markCompleted(event.dispatchId);
|
|
623
648
|
runner.endTurn();
|
|
649
|
+
// A finished turn may have written task files (progress/done/start-cycle); rescan
|
|
650
|
+
// now so a continuing task chain advances immediately instead of after a full sleep.
|
|
651
|
+
taskDriver.nudge?.();
|
|
624
652
|
}
|
|
625
653
|
})();
|
|
626
654
|
activeTasks.add(task);
|
|
@@ -691,7 +719,6 @@ export function createRuntimeContext(options) {
|
|
|
691
719
|
return runtimeSettingsManager.getTaskDriverSettings();
|
|
692
720
|
},
|
|
693
721
|
isEnabled: () => loadToolsConfig(options.paths.appHomeDir).tools.tasks.enabled,
|
|
694
|
-
intervalMs: options.taskDriverIntervalMs,
|
|
695
722
|
});
|
|
696
723
|
const shutdownWithReason = async (reason = "manual") => {
|
|
697
724
|
if (shutdownPromise) {
|
|
@@ -818,7 +845,7 @@ export async function bootstrap(argv, options = {}) {
|
|
|
818
845
|
const registerSignalHandlers = options.registerSignalHandlers ?? true;
|
|
819
846
|
const startServices = options.startServices ?? true;
|
|
820
847
|
parseArgs(argv, paths, io);
|
|
821
|
-
const bootstrapResult = bootstrapAppHome(paths);
|
|
848
|
+
const bootstrapResult = bootstrapAppHome(paths, io);
|
|
822
849
|
printBootstrapSummary(bootstrapResult, io, paths);
|
|
823
850
|
if (bootstrapResult.channelTemplateCreated) {
|
|
824
851
|
io.error(`Fill in ${paths.channelConfigPath} and run \`${paths.appName}\` again.`);
|
|
@@ -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
|
}
|
|
@@ -9,10 +9,18 @@ export interface TaskDriverOptions {
|
|
|
9
9
|
getSettings: () => PipiclawTaskDriverSettings;
|
|
10
10
|
/** Master autonomy switch (`tools.tasks.enabled`); re-read every tick. Defaults to on. */
|
|
11
11
|
isEnabled?: () => boolean;
|
|
12
|
+
/** Test-only override for the idle-sleep cap; production uses `settings.maxSleepMinutes`. */
|
|
12
13
|
intervalMs?: number;
|
|
13
14
|
}
|
|
14
15
|
export declare function discoverTaskChannels(workspaceDir: string, knownChannelIds?: Iterable<string>): Promise<string[]>;
|
|
15
16
|
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;
|
|
16
24
|
/**
|
|
17
25
|
* Native, token-gated driver for the persistent task ledger.
|
|
18
26
|
*
|
|
@@ -24,11 +32,36 @@ export declare function createTaskDriverEvent(channelId: string, entry: TaskLedg
|
|
|
24
32
|
export declare class TaskDriver {
|
|
25
33
|
private readonly options;
|
|
26
34
|
private timer;
|
|
35
|
+
private nudgeTimer;
|
|
36
|
+
private loopActive;
|
|
27
37
|
private running;
|
|
28
38
|
private nextChannelIndex;
|
|
39
|
+
/** Absolute ms of the next moment worth waking for (min wake/deadline/backoff), recomputed each scan. */
|
|
40
|
+
private nextWakeMs;
|
|
29
41
|
private readonly attempts;
|
|
42
|
+
/**
|
|
43
|
+
* Last task id dispatched per channel. Cross-channel fairness is handled by
|
|
44
|
+
* `nextChannelIndex`, but within one channel every tick used to pick the first ready
|
|
45
|
+
* candidate in sort order — an actively-progressing task keeps winning that slot forever,
|
|
46
|
+
* starving every other ready task (including its own unlocked dependents) in the same
|
|
47
|
+
* channel. Remembering the last pick and starting the search just after it gives ready
|
|
48
|
+
* candidates in a channel the same round-robin fairness across ticks.
|
|
49
|
+
*/
|
|
50
|
+
private readonly lastDispatchedTaskId;
|
|
30
51
|
constructor(options: TaskDriverOptions);
|
|
31
52
|
start(): void;
|
|
32
53
|
stop(): void;
|
|
54
|
+
/**
|
|
55
|
+
* In-process wake: after a turn ends or a task file is written, re-scan promptly instead
|
|
56
|
+
* of waiting out the current sleep. The timer is a hint; the scan re-reads every file, so
|
|
57
|
+
* a stale or missed nudge only costs one capped sleep of latency, never correctness.
|
|
58
|
+
*/
|
|
59
|
+
nudge(): void;
|
|
60
|
+
private tick;
|
|
61
|
+
private scheduleNext;
|
|
62
|
+
/** Fold `candidate` into the earliest interesting wake moment. */
|
|
63
|
+
private noteHorizon;
|
|
64
|
+
private collectHorizons;
|
|
65
|
+
private hasLiveScheduleEvent;
|
|
33
66
|
runOnce(now?: Date): Promise<void>;
|
|
34
67
|
}
|