@oyasmi/pipiclaw 0.9.2-beta.6 → 0.9.3-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/README.en.md +250 -0
- package/README.md +2 -0
- package/dist/agent/channel-runner.d.ts +43 -2
- package/dist/agent/channel-runner.js +135 -75
- package/dist/agent/job-manager.d.ts +76 -21
- package/dist/agent/job-manager.js +447 -63
- package/dist/agent/maintenance-context.js +4 -5
- package/dist/agent/prompt/manifest.d.ts +0 -2
- package/dist/agent/prompt/manifest.js +2 -3
- package/dist/agent/prompt/sections.js +3 -3
- package/dist/agent/session-events.js +4 -8
- package/dist/agent/turn-prompt.d.ts +7 -7
- package/dist/agent/turn-prompt.js +6 -9
- package/dist/agent/types.d.ts +12 -0
- package/dist/agent/types.js +1 -0
- package/dist/channel/channel-context.d.ts +13 -0
- package/dist/channel/channel-context.js +21 -1
- package/dist/commands/catalog.js +47 -20
- package/dist/memory/commands.d.ts +8 -0
- package/dist/memory/commands.js +113 -148
- package/dist/memory/index-budget.d.ts +27 -0
- package/dist/memory/index-budget.js +99 -0
- package/dist/memory/journal.d.ts +20 -0
- package/dist/memory/journal.js +78 -0
- package/dist/memory/lifecycle.d.ts +9 -15
- package/dist/memory/lifecycle.js +55 -145
- package/dist/memory/maintenance-gates.d.ts +13 -47
- package/dist/memory/maintenance-gates.js +13 -92
- package/dist/memory/maintenance-state.d.ts +10 -16
- package/dist/memory/maintenance-state.js +12 -59
- package/dist/memory/maintenance-tuning.d.ts +7 -27
- package/dist/memory/maintenance-tuning.js +11 -28
- package/dist/memory/migrate.d.ts +15 -0
- package/dist/memory/migrate.js +364 -0
- package/dist/memory/reflect-job.d.ts +43 -0
- package/dist/memory/reflect-job.js +117 -0
- package/dist/memory/reflect.d.ts +52 -0
- package/dist/memory/reflect.js +313 -0
- package/dist/memory/render.d.ts +14 -0
- package/dist/memory/render.js +28 -0
- package/dist/memory/review-log.d.ts +2 -1
- package/dist/memory/scheduler.d.ts +2 -3
- package/dist/memory/scheduler.js +14 -49
- package/dist/memory/search.d.ts +35 -0
- package/dist/memory/search.js +297 -0
- package/dist/memory/session-search.js +1 -1
- package/dist/memory/store.d.ts +108 -0
- package/dist/memory/store.js +418 -0
- package/dist/memory/task-digest.d.ts +2 -2
- package/dist/memory/task-digest.js +29 -36
- package/dist/memory/tombstones.d.ts +0 -11
- package/dist/memory/tombstones.js +6 -37
- package/dist/playbooks/agent-delegation.md +4 -2
- package/dist/playbooks/background-jobs.md +1 -1
- package/dist/playbooks/event-scheduling.md +6 -2
- package/dist/playbooks/memory-and-learning.md +18 -11
- package/dist/playbooks/outbound-media.md +1 -1
- package/dist/playbooks/runtime-orientation.md +9 -8
- package/dist/playbooks/task-loop.md +88 -0
- package/dist/runtime/bootstrap.d.ts +3 -3
- package/dist/runtime/bootstrap.js +66 -41
- package/dist/runtime/events.d.ts +9 -0
- package/dist/runtime/events.js +43 -4
- package/dist/runtime/task-commands.d.ts +14 -15
- package/dist/runtime/task-commands.js +249 -485
- package/dist/runtime/task-driver.d.ts +41 -29
- package/dist/runtime/task-driver.js +170 -317
- package/dist/runtime/task-migration.d.ts +34 -30
- package/dist/runtime/task-migration.js +229 -183
- package/dist/runtime/task-wake.d.ts +6 -3
- package/dist/runtime/task-wake.js +26 -19
- package/dist/settings.d.ts +0 -29
- package/dist/settings.js +12 -35
- package/dist/shared/markdown-sections.d.ts +0 -1
- package/dist/shared/markdown-sections.js +0 -3
- package/dist/subagents/discovery.d.ts +2 -2
- package/dist/subagents/discovery.js +21 -10
- package/dist/subagents/external/progress-tail.js +6 -1
- package/dist/subagents/external/run.js +1 -0
- package/dist/subagents/runs.d.ts +19 -2
- package/dist/subagents/runs.js +73 -4
- package/dist/subagents/tool.d.ts +10 -8
- package/dist/subagents/tool.js +55 -94
- package/dist/tasks/brief.d.ts +17 -0
- package/dist/tasks/brief.js +57 -0
- package/dist/tasks/budget.d.ts +26 -0
- package/dist/tasks/budget.js +59 -0
- package/dist/tasks/cycle.d.ts +48 -0
- package/dist/tasks/cycle.js +94 -0
- package/dist/tasks/frontmatter.d.ts +73 -0
- package/dist/tasks/frontmatter.js +175 -0
- package/dist/tasks/ledger.d.ts +66 -106
- package/dist/tasks/ledger.js +90 -546
- package/dist/tasks/log.d.ts +88 -0
- package/dist/tasks/log.js +97 -0
- package/dist/tasks/rounds.d.ts +43 -0
- package/dist/tasks/rounds.js +57 -0
- package/dist/tasks/session-path.d.ts +9 -0
- package/dist/tasks/session-path.js +16 -0
- package/dist/tasks/steer.d.ts +8 -0
- package/dist/tasks/steer.js +79 -0
- package/dist/tasks/store.d.ts +60 -35
- package/dist/tasks/store.js +166 -107
- package/dist/tasks/ticket.d.ts +102 -0
- package/dist/tasks/ticket.js +209 -0
- package/dist/tasks/verification.d.ts +16 -0
- package/dist/tasks/verification.js +40 -1
- package/dist/tools/index.d.ts +13 -4
- package/dist/tools/index.js +5 -10
- package/dist/tools/memory-manage.d.ts +6 -16
- package/dist/tools/memory-manage.js +108 -129
- package/dist/tools/presentation.js +2 -1
- package/dist/tools/registry.d.ts +11 -2
- package/dist/tools/registry.js +17 -6
- package/dist/tools/subagent-manage.d.ts +0 -9
- package/dist/tools/subagent-manage.js +8 -17
- package/dist/tools/task-manage/create.js +2 -2
- package/dist/tools/task-manage/lifecycle.d.ts +9 -4
- package/dist/tools/task-manage/lifecycle.js +139 -187
- package/dist/tools/task-manage/log-view.d.ts +8 -0
- package/dist/tools/task-manage/log-view.js +24 -0
- package/dist/tools/task-manage/schema.d.ts +38 -14
- package/dist/tools/task-manage/schema.js +46 -27
- package/dist/tools/task-manage/shared.d.ts +24 -31
- package/dist/tools/task-manage/shared.js +103 -141
- package/dist/tools/task-manage/step-end.d.ts +11 -0
- package/dist/tools/task-manage/step-end.js +136 -0
- package/dist/tools/task-manage/types.d.ts +23 -32
- package/dist/tools/task-manage.d.ts +4 -3
- package/dist/tools/task-manage.js +30 -15
- package/dist/tools/tool-details.d.ts +1 -1
- package/dist/tui/app.js +0 -2
- package/package.json +1 -1
- package/dist/agent/effect-ledger.d.ts +0 -32
- package/dist/agent/effect-ledger.js +0 -89
- package/dist/memory/bootstrap.d.ts +0 -17
- package/dist/memory/bootstrap.js +0 -120
- package/dist/memory/candidates.d.ts +0 -26
- package/dist/memory/candidates.js +0 -202
- package/dist/memory/consolidation.d.ts +0 -54
- package/dist/memory/consolidation.js +0 -292
- package/dist/memory/extraction.d.ts +0 -54
- package/dist/memory/extraction.js +0 -240
- package/dist/memory/files.d.ts +0 -71
- package/dist/memory/files.js +0 -419
- package/dist/memory/maintenance-jobs.d.ts +0 -41
- package/dist/memory/maintenance-jobs.js +0 -265
- package/dist/memory/metadata.d.ts +0 -57
- package/dist/memory/metadata.js +0 -142
- package/dist/memory/probation.d.ts +0 -17
- package/dist/memory/probation.js +0 -44
- package/dist/memory/promotion.d.ts +0 -38
- package/dist/memory/promotion.js +0 -36
- package/dist/memory/recall.d.ts +0 -59
- package/dist/memory/recall.js +0 -746
- package/dist/memory/session.d.ts +0 -24
- package/dist/memory/session.js +0 -273
- package/dist/playbooks/task-driving.md +0 -92
- package/dist/playbooks/task-planning.md +0 -58
- package/dist/tasks/control.d.ts +0 -56
- package/dist/tasks/control.js +0 -169
- package/dist/tasks/transitions.d.ts +0 -16
- package/dist/tasks/transitions.js +0 -48
- package/dist/tools/task-manage/verification.d.ts +0 -19
- package/dist/tools/task-manage/verification.js +0 -91
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: memory-and-learning
|
|
3
|
-
description: 记住或忘记事实(memory
|
|
3
|
+
description: 记住或忘记事实(memory)、在记忆与日志之间取舍,或把经验沉淀成技能(skill)。
|
|
4
4
|
requires-tools: memory_save, memory_search, memory_forget, skill
|
|
5
5
|
order: 20
|
|
6
6
|
---
|
|
@@ -11,34 +11,41 @@ order: 20
|
|
|
11
11
|
|
|
12
12
|
| 信息 | 目标位置 | 入口 |
|
|
13
13
|
|---|---|---|
|
|
14
|
-
|
|
|
15
|
-
|
|
|
14
|
+
| 今天发生了什么、定了什么、卡在哪 | channel `journal/` | 后台反思 pass 自动写,不手工编辑 |
|
|
15
|
+
| 用户是谁:称呼、语言、角色期待、长期偏好 | channel memory,`type: user` | `memory_save` |
|
|
16
|
+
| 怎么工作的纠正、吃过亏的教训 | channel memory,`type: feedback` | `memory_save` |
|
|
17
|
+
| 关于工作对象的稳定事实、决策、约束 | channel memory,`type: project` | `memory_save` |
|
|
18
|
+
| 路径、URL、命令、联系人、id 等指针 | channel memory,`type: reference` | `memory_save` |
|
|
16
19
|
| 单个长程工作的状态和证据 | `tasks/<id>.md` | `task_create`/`task_update`/`task_close`,正文大改才用 `edit` |
|
|
17
20
|
| 机器依赖、安装、配置位置 | workspace `ENVIRONMENT.md` | `read` / `edit`,受项目边界约束 |
|
|
18
21
|
| 跨任务可复用的操作流程 | workspace `skills/` | `write`/`edit` 创建或修改,`skill` 只读列出/加载 |
|
|
19
22
|
| Pipiclaw 自身机制 | runtime playbook | 只读 |
|
|
20
23
|
| 原始对话 | `log.jsonl` / `context.jsonl` | `session_search` |
|
|
21
24
|
|
|
22
|
-
|
|
25
|
+
没有"进行中的事"这一类记忆——未闭合的事项要么建 task(有 wake、有 DoD),要么就是今天的 journal,不写成 memory:memory 没有生命周期,写成"进行中"的记忆只会一直摆在那里过时。
|
|
26
|
+
|
|
27
|
+
channel 的 `memory/*.md` 和生成的 `MEMORY.md` 索引由 runtime 和后台反思 pass 共同持有:可以 `read` 单条记忆的正文,但写入一律走 `memory_save`/`memory_forget`,用文件工具改会被下一次索引重建覆盖(项目边界下 path guard 也会直接拒绝)。`journal/` 只由后台写,不接受任何工具写入。各文件的位置和访问入口见 `runtime-orientation.md`。
|
|
23
28
|
|
|
24
29
|
## 什么时候立即写 durable memory
|
|
25
30
|
|
|
26
|
-
用户明确说"记住、以后默认、偏好、不要再做、忘掉"时,当回合就调用 `memory_save
|
|
31
|
+
用户明确说"记住、以后默认、偏好、不要再做、忘掉"时,当回合就调用 `memory_save`,不等后台反思。这条路径写入的记忆立即永久,不受下面的试用期约束。
|
|
32
|
+
|
|
33
|
+
`memory_save` 参数:`content`(必填,一行,成为这条记忆在索引里的 description)、`name`(可选,kebab-case 短句柄,不给就自动生成)、`type`(可选,四选一,默认 `project`)、`details`(可选,正文,只有打开这条记忆时才会读到)、`replaces`(发现相似条目后二次调用时带上要替换的 `name`,或 `"none"` 表示两条同时成立)。
|
|
27
34
|
|
|
28
|
-
|
|
35
|
+
只保存未来仍有用的事实;一次性进度、猜测、临时计划留给 journal 或 task。
|
|
29
36
|
|
|
30
|
-
`save`
|
|
37
|
+
`save` 撞到相似的已有条目时,工具会先拒绝并把候选 `name` 列出来,要一个决定:带上 `replaces: <name>` 替换旧条目,或 `replaces: "none"` 保留两条。**同一条规则出了新版本就替换**——两个版本并存之后模型读到哪一条全看运气;只有两个事实同时成立才保留两条。整条规则不再成立时用 `memory_forget`(按 `name` 精确删除)。
|
|
31
38
|
|
|
32
|
-
|
|
39
|
+
会话首轮已经看过索引(`<memory_bootstrap>`),中途怀疑"这事以前可能记过、但没在索引里",用 `memory_search` 查——索引不会每轮刷新,反思 pass 中途新增的条目要到下一次首轮才会出现。
|
|
33
40
|
|
|
34
41
|
## 后台自动写入与试用期
|
|
35
42
|
|
|
36
|
-
|
|
43
|
+
后台反思 pass 每次同时产出两样东西:今天 journal 的新增行,以及 memory 的增/改/删/touch。写入按两档:
|
|
37
44
|
|
|
38
45
|
- **硬约束**(`necessity: high`,明确会导致未来回合出错的)直接永久写入。
|
|
39
|
-
- **日常运作知识**(`necessity: medium`:谁负责哪块、术语默认含义、发布或命名惯例、流程签批人)以**试用期**条目写入,默认 30
|
|
46
|
+
- **日常运作知识**(`necessity: medium`:谁负责哪块、术语默认含义、发布或命名惯例、流程签批人)以**试用期**条目写入,默认 30 天;这段时间内被反思 pass 判定"这次对话依赖或印证了它"(touch)即转正为永久,从未被 touch 则到期自动移除。
|
|
40
47
|
|
|
41
|
-
|
|
48
|
+
失效不是遗忘:内容之后仍可被重新学到,只是这一次没被用上,也不留墓碑。这些阈值是代码常量,不在 `settings.json` 里。
|
|
42
49
|
|
|
43
50
|
## ENVIRONMENT.md
|
|
44
51
|
|
|
@@ -17,7 +17,7 @@ order: 30
|
|
|
17
17
|
|
|
18
18
|
## 记录 receipt
|
|
19
19
|
|
|
20
|
-
`send_media` 返回成功 receipt 才算送到。成功后把 receipt(附件名、类型、大小、已发送到当前 channel
|
|
20
|
+
`send_media` 返回成功 receipt 才算送到。成功后把 receipt(附件名、类型、大小、已发送到当前 channel)和时间写进 `task_step_end` 的 `note`;发送前先用 `task_log` 看这份记录里有没有同一附件的成功 receipt,避免重复投递。外部动作的通用幂等纪律见 `task-loop.md`。
|
|
21
21
|
|
|
22
22
|
失败时按同一份纪律 progress 为 active 或 waiting 并写恢复来源,不要把"调用返回了"当成"用户收到了"。
|
|
23
23
|
|
|
@@ -23,10 +23,9 @@ AI Agent 委派(内置 subagent 与外部 claude-code / codex-cli / exec)由
|
|
|
23
23
|
|
|
24
24
|
- `<runtime_turn_context>`:当前 channel 目录的路径。
|
|
25
25
|
- `<task_agenda>`:在办任务的 id、status、enabled、wake、nextAction、Plan 进度和最新一条记录。
|
|
26
|
-
- `<
|
|
27
|
-
- `<durable_memory_snapshot>`:会话首轮的 channel 与 workspace `MEMORY.md` 快照。
|
|
26
|
+
- `<memory_bootstrap>`:**只在会话首轮(含 `/new` 之后、上下文压缩之后)出现**,往后的回合都没有。三段:workspace `MEMORY.md` 全文、channel 记忆索引、当天日志尾部。中途怀疑"这事以前是不是记过",用 `memory_search` 查,不要等下一次首轮。
|
|
28
27
|
|
|
29
|
-
|
|
28
|
+
这些都是摘要。需要某条索引里 `(+)` 标记的记忆正文,或某个任务更早的循环日志时,才去打开对应文件(任务循环的每一步已经拿到完整契约)。
|
|
30
29
|
|
|
31
30
|
## 文件地图与入口
|
|
32
31
|
|
|
@@ -43,7 +42,7 @@ App home(默认 `~/.pipiclaw/`,可由 `PIPICLAW_HOME` 覆盖)——运维
|
|
|
43
42
|
Workspace 根目录——**靠专用工具或只读注入访问**,项目边界下通用文件工具够不到:
|
|
44
43
|
|
|
45
44
|
- `SOUL.md`(身份与表达风格)、`AGENTS.md`(用户/团队工作原则):每回合注入 system prompt。
|
|
46
|
-
- `MEMORY.md
|
|
45
|
+
- `MEMORY.md`:跨频道共享背景,**只由人维护**,没有工具能写它;会话首轮整份注入 `<memory_bootstrap>`。
|
|
47
46
|
- `skills/`:workspace 级程序性知识;`skill` 工具只读列出/加载,创建或修改直接用 `write`/`edit`。读写都始终放行(项目边界的例外)。
|
|
48
47
|
- `sub-agents/`:委派角色定义,目录呈现在 system prompt 里。
|
|
49
48
|
- `events/`:全 workspace 的调度事件,用 `event_manage` 管理。
|
|
@@ -51,14 +50,16 @@ Workspace 根目录——**靠专用工具或只读注入访问**,项目边界
|
|
|
51
50
|
|
|
52
51
|
当前 channel 目录(路径在 `<runtime_turn_context>` 里)——runtime 维护,项目边界下始终可读:
|
|
53
52
|
|
|
54
|
-
- `
|
|
55
|
-
- `
|
|
53
|
+
- `memory/<name>.md`:一条记忆一个文件(frontmatter:`name`/`description`/`type`/`source`/`created`/`updated`/`expires`),可以 `read` 看正文,但**只用 `memory_save`/`memory_forget` 写**——`MEMORY.md` 是从 `memory/` 生成的索引,文件工具直接改会被下一次写入覆盖。
|
|
54
|
+
- `MEMORY.md`:生成物,频道记忆索引,人也能看。
|
|
55
|
+
- `journal/YYYY-MM-DD.md`:按天追加的工作记录(发生了什么、定了什么、卡在哪),只由后台反思 pass 写;今天的尾部已经在 `<memory_bootstrap>` 里,更早的日期用 `memory_search` 或 `read` 查。
|
|
56
|
+
- `tasks/`:长程任务。`<id>.md` 是契约(Goal/DoD/Manual/Verification/Plan),`<id>.jsonl` 是循环日志。建档用 `task_create`,改元数据和 Plan 用 `task_update`,查历史用 `task_log`;循环里推进用 `task_step_end`。正文大改用 `edit`——`task_update` 不动正文。
|
|
56
57
|
- `log.jsonl` / `context.jsonl`:冷存储,用 `session_search` 检索。
|
|
57
58
|
|
|
58
59
|
## 读取顺序
|
|
59
60
|
|
|
60
|
-
1.
|
|
61
|
-
2.
|
|
61
|
+
1. 本回合注入的块(`<runtime_turn_context>`、`<task_agenda>`,首轮再加 `<memory_bootstrap>`)。
|
|
62
|
+
2. 当前工作断点或既有决定:本会话上文 → 今天的 journal 尾部(已在首轮块里)→ 怀疑记过但没在索引里,`memory_search`。
|
|
62
63
|
3. 用户明确引用旧对话而上述都不够:`session_search`。
|
|
63
64
|
4. 环境安装、凭据来源或机器变更:`ENVIRONMENT.md`。
|
|
64
65
|
5. runtime 机制:读对应 playbook,不从旧对话或 workspace 副本猜测。
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: task-loop
|
|
3
|
+
description: 判断该不该建长程任务(task)、怎么写任务契约,以及在任务循环里推进、等待、验收和闭环。
|
|
4
|
+
requires-tools: task_create, task_step_end
|
|
5
|
+
order: 70
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# 长程任务:建档与循环
|
|
9
|
+
|
|
10
|
+
任务是**跨回合恢复**的工作单元。运行时负责调度和兜底,你负责判断。每一步的 brief 已经给了契约全文、最近日志和当前预算;这里讲的是这些数字之外需要你判断的部分。
|
|
11
|
+
|
|
12
|
+
## 什么时候建 task
|
|
13
|
+
|
|
14
|
+
只有工作需要跨回合恢复时才建:多步骤目标、要等人或外部系统、要委派、周期性产出。当前回合能做完的请求不建台账。纯提醒或外部条件探测用 event(见 `event-scheduling.md`);只在当前回合委派一次也不需要 task。
|
|
15
|
+
|
|
16
|
+
只把**可独立推进、可独立验收**的长期工作拆成多个 task。任务之间没有依赖字段:先后条件写进后继任务的 Goal/Manual。
|
|
17
|
+
|
|
18
|
+
## 写契约
|
|
19
|
+
|
|
20
|
+
`task_create` 的四段是整个循环唯一的长期真相,每一步都会完整读到它,所以要短、要准:
|
|
21
|
+
|
|
22
|
+
- `goal`:最终要成立的**结果**,不写行动清单。
|
|
23
|
+
- `dod`:客观验收标准,每项必须是 `- [ ]` checkbox。写不出 checkbox 说明目标还没想清楚。
|
|
24
|
+
- `manual`:可复用的执行步骤、预检、幂等方法、返工教训。这是任务自己的记忆——学到什么就更新它。
|
|
25
|
+
- `verificationPlan`:独立验收者能执行的确定性检查。
|
|
26
|
+
|
|
27
|
+
有代码、配置或可复现产物时设 `verificationRequired: true`;纯提醒、沟通和主观写作保持默认。
|
|
28
|
+
|
|
29
|
+
契约有 4 KB 预算,但它约束的是运行时写的 `## 上次结果`,不会删你写的段落。**每一步的记录不写进契约**,写进 `task_step_end` 的 `note`;历史用 `task_log` 查。
|
|
30
|
+
|
|
31
|
+
`schedule`(五字段 cron,最小 30 分钟)让任务变成周期性的:每个 occurrence 一个 cycle,闭环后自动停到下一次。
|
|
32
|
+
|
|
33
|
+
Task 创建即持续委托:能触达什么由可用工具、security 配置和 Goal 共同约束,没有逐次授权的字段。**Goal 的边界就是授权的边界,宁可写窄。**
|
|
34
|
+
|
|
35
|
+
## Plan:手段层
|
|
36
|
+
|
|
37
|
+
预计需要多步时用 `plan` 创建步骤,或用 `task_update` 的 `planSteps` 更新。Plan 是手段,不是第二份 DoD;每步写可验证产出,可选 `→ dod:1,2` 引用。四态 `[ ]` todo、`[x]` done、`[!]` blocked、`[~]` dropped。周期任务每个新 cycle 会把 Plan 和 DoD 复位。
|
|
38
|
+
|
|
39
|
+
## 在循环里推进
|
|
40
|
+
|
|
41
|
+
每一步先看清 brief 里的 `<task_contract>`、`<task_log>` 和 `<task_state>`,再动手。派发是 at-least-once,**外部动作前先查真实状态**,别重复发送、发布或部署。
|
|
42
|
+
|
|
43
|
+
只推进一个清晰的下一阶段,然后用 `task_step_end` 收尾:
|
|
44
|
+
|
|
45
|
+
- 还能接着干 → `continue`。运行时立刻排下一步,没有等待。
|
|
46
|
+
- 在等一个真实来源 → `park`,带上对应的票。委派用 `run`、后台作业用 `job`、单纯过一阵再看用 `time`、周期任务闭环用 `schedule`、task-owned 传感器事件用 `signal`。
|
|
47
|
+
- 本周期做完了 → `done`,必须给 `summary` 和 `evidence`。
|
|
48
|
+
- 需要用户决定 → `blocked`,写清在等什么。
|
|
49
|
+
|
|
50
|
+
**票必须指向真实存在的东西**:运行时会当场校验,指不到就拒绝。这是设计——一次指不到的等待就是一次永久静默。
|
|
51
|
+
|
|
52
|
+
**默认不向用户发言。** 确实要说才给 `notify`;`blocked` 一定会说。
|
|
53
|
+
|
|
54
|
+
## 外部动作的幂等闭环
|
|
55
|
+
|
|
56
|
+
外部发送、发布、部署或修改前:
|
|
57
|
+
|
|
58
|
+
1. 读 Goal 和 DoD 确认动作仍在范围内,并查询目标真实状态。
|
|
59
|
+
2. 确认此前没有已成功的同一动作;用稳定的 request / message / idempotency key 执行。
|
|
60
|
+
3. 查询并记录真实结果、目标标识、时间和证据到 `note`。
|
|
61
|
+
4. 只有结果已满足 DoD 才 `done`;失败就 `continue` 或 `park` 并写清恢复来源。
|
|
62
|
+
|
|
63
|
+
附件交付的 receipt 规则见 `outbound-media.md`。
|
|
64
|
+
|
|
65
|
+
## 独立验收
|
|
66
|
+
|
|
67
|
+
1. 只有证据成立后才勾选 DoD / Verification checklist。
|
|
68
|
+
2. 像任何委派一样派一个 `purpose: verify`、带 `taskId` 的 sub-agent,然后 `park` 到那个 run 的票上。
|
|
69
|
+
3. checker 只判断、不修复被验收实现,结尾返回 `VERDICT: PASS` 或 `VERDICT: FAIL`。
|
|
70
|
+
4. **结算时运行时自动记账**:校验 attestation(归属、契约 hash、产物 subject),把这一轮写进返工账本,然后兑现你的票。你不需要导入任何东西——醒来时结论已经在 `<task_log>` 里。
|
|
71
|
+
5. attestation 校验不过的 PASS 会被记成 FAIL 并写明原因。标 `advisory` 的结论(带 `bash` 的内置验收者、`mutates: write` 的 verifier、所有外部验收者)只是参考,仍要按风险抽查;强度来源见 `agent-delegation.md`。
|
|
72
|
+
6. `verify: required` 的任务,`done` 要求**本周期**有一条真实 PASS。返工轮次有预算,到顶会停下来问用户。
|
|
73
|
+
|
|
74
|
+
PASS 绑定 Goal/DoD/Manual/Verification 这段契约,不绑定 Plan 和历史。改动契约或被验收产物后必须重新验收。
|
|
75
|
+
|
|
76
|
+
## 预算与停止
|
|
77
|
+
|
|
78
|
+
每个 cycle 有四维预算:步数、墙钟、成本、返工轮次(可在 `task_create`/`task_update` 的 `budget` 里按任务调整)。任一项到顶,运行时停掉任务并给用户一条确定性回执,附加预算的命令。连续两步没有任何工具调用也会被停下——那说明循环在自言自语。
|
|
79
|
+
|
|
80
|
+
**只记录真实工作**:`note` 写做了什么、证据是什么、下一步是什么,不写愿望。
|
|
81
|
+
|
|
82
|
+
## 等待票过期
|
|
83
|
+
|
|
84
|
+
票有兜底时限。到点还没兑现,运行时会把任务重新打开,并在 brief 开头告诉你票过期了。这时**先确认真实状态**(那个 run 到底结束没有?那个条件到底成立没有?),再决定继续还是换一张票。同一 cycle 内第二次过期会停掉任务并通知用户。
|
|
85
|
+
|
|
86
|
+
## 契约损坏
|
|
87
|
+
|
|
88
|
+
frontmatter 不可读或仍是旧版契约时,唤醒会明确要求**只修元数据、不执行任务目标**。用 `edit` 修好首部后就停下,任务工作留给下一步。
|
|
@@ -3,10 +3,10 @@ import type { ChannelEvent } from "../channel/channel-event.js";
|
|
|
3
3
|
import { ChannelStore } from "../channel/store.js";
|
|
4
4
|
import { type Executor } from "../executor.js";
|
|
5
5
|
import { PipiclawSettingsManager } from "../settings.js";
|
|
6
|
-
import type { WakeTaskTransitionHooks } from "../tasks/store.js";
|
|
7
6
|
import { type BootstrapIO, type BootstrapPaths } from "./app-home.js";
|
|
8
7
|
import { DingTalkBot, type DingTalkConfig, type DingTalkHandler } from "./dingtalk.js";
|
|
9
8
|
import { TaskDriver } from "./task-driver.js";
|
|
9
|
+
import type { WakeTaskTransitionHooks } from "./task-wake.js";
|
|
10
10
|
export interface BootstrapOptions {
|
|
11
11
|
env?: NodeJS.ProcessEnv;
|
|
12
12
|
io?: BootstrapIO;
|
|
@@ -33,8 +33,8 @@ export interface RuntimeContext {
|
|
|
33
33
|
* Production maintenance scheduler, exposed for the same reason as `taskDriver`.
|
|
34
34
|
*
|
|
35
35
|
* Evaluation workers run with `startServices: false`, so the background timer never fires and
|
|
36
|
-
* no trial could otherwise reach
|
|
37
|
-
*
|
|
36
|
+
* no trial could otherwise reach the reflect pass — the whole memory pipeline was structurally
|
|
37
|
+
* untestable from a behavior eval.
|
|
38
38
|
* Exposing the instance lets a case drive one real pass at a chosen time instead of faking a
|
|
39
39
|
* clock or re-implementing the job order.
|
|
40
40
|
*/
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { mkdir, writeFile } from "fs/promises";
|
|
2
2
|
import { join, relative } from "path";
|
|
3
|
-
import { channelEffectCount, noteTaskEffects, taskEffectCount } from "../agent/effect-ledger.js";
|
|
4
3
|
import { channelRunningJobLines, configureJobRuntime, restoreChannelJobs } from "../agent/job-manager.js";
|
|
5
4
|
import { loadDetachedMaintenanceContext } from "../agent/maintenance-context.js";
|
|
6
5
|
import { createRunner } from "../agent/runner-factory.js";
|
|
7
6
|
import { renderStatus } from "../agent/status-render.js";
|
|
8
7
|
import { scanWorkspaceForInterruptedTurns } from "../agent/turn-recovery.js";
|
|
9
8
|
import { createFreshActiveSession } from "../channel/active-session-store.js";
|
|
9
|
+
import { muteChannelContext } from "../channel/channel-context.js";
|
|
10
10
|
import { createChannelIndex } from "../channel/channel-index.js";
|
|
11
11
|
import { ensureChannelDir, getChannelDir } from "../channel/channel-paths.js";
|
|
12
12
|
import { resolveProjectScope } from "../channel/project-scope-store.js";
|
|
@@ -14,7 +14,6 @@ import { ChannelStore } from "../channel/store.js";
|
|
|
14
14
|
import { BUILT_IN_COMMANDS, formatUnknownCommandMessage, isRunnerBuiltInCommand, parseBuiltInCommand, slashCommandName, } from "../commands/catalog.js";
|
|
15
15
|
import { createExecutor } from "../executor.js";
|
|
16
16
|
import * as log from "../log.js";
|
|
17
|
-
import { ensureChannelMemoryFilesSync } from "../memory/files.js";
|
|
18
17
|
import { MemoryMaintenanceScheduler } from "../memory/scheduler.js";
|
|
19
18
|
import { defaultModel } from "../models/utils.js";
|
|
20
19
|
import { loadSecurityConfigWithDiagnostics } from "../security/config.js";
|
|
@@ -28,7 +27,10 @@ import { errorMessage } from "../shared/text-utils.js";
|
|
|
28
27
|
import { sleepUnref } from "../shared/with-timeout.js";
|
|
29
28
|
import { loadDetachedSubAgentDiscovery } from "../subagents/detached-discovery.js";
|
|
30
29
|
import { configureSubAgentRuntime, getSubAgentRunManager, restoreAllSubAgentRuns, stopSubAgentGarbageCollector, } from "../subagents/runs.js";
|
|
30
|
+
import { buildTaskStepBrief } from "../tasks/brief.js";
|
|
31
31
|
import { readActiveTasks } from "../tasks/ledger.js";
|
|
32
|
+
import { consumeTaskNotice } from "../tasks/steer.js";
|
|
33
|
+
import { readStoredTask } from "../tasks/store.js";
|
|
32
34
|
import { getToolsConfigPath, loadToolsConfig, loadToolsConfigWithDiagnostics } from "../tools/config.js";
|
|
33
35
|
import { getUsageLedger } from "../usage/ledger.js";
|
|
34
36
|
import { parseUsageMode, renderUsageReport } from "../usage/render.js";
|
|
@@ -45,7 +47,7 @@ import { handleSkillsCommand as runSkillsCommand } from "./skill-commands.js";
|
|
|
45
47
|
import { renderRunNotice, handleSubagentsCommand as runSubagentsCommand } from "./subagent-commands.js";
|
|
46
48
|
import { pauseTask, handleTasksCommand as runTasksCommand } from "./task-commands.js";
|
|
47
49
|
import { createTaskDriverEvent, TaskDriver } from "./task-driver.js";
|
|
48
|
-
import {
|
|
50
|
+
import { migrateTasksToV4 } from "./task-migration.js";
|
|
49
51
|
import { claimVerifiedDelegationWake, claimVerifiedJobWake } from "./task-wake.js";
|
|
50
52
|
const SHUTDOWN_WAIT_MS = 15000;
|
|
51
53
|
const SHUTDOWN_FLUSH_WAIT_MS = 45000;
|
|
@@ -148,6 +150,48 @@ export async function forceEndStuckTurnAfterStop(input) {
|
|
|
148
150
|
}
|
|
149
151
|
function createDingTalkHandler(deps) {
|
|
150
152
|
const { options, store, channelRunners, sessionResetChains, activeTasks, stopWatchdogs, channelIndex, archiveIncomingMessage, getRunner, cliVersion, startedAt, isShuttingDown, getDurableDispatch, getExecutor, getTaskDriver, } = deps;
|
|
153
|
+
/**
|
|
154
|
+
* Turn a `[TASK_DRIVER:<id>]` dispatch into a task loop step: bind the runner to the task
|
|
155
|
+
* cycle's own session and replace the wake text with the step brief. Returns `undefined` for
|
|
156
|
+
* every other event, which then follows the unchanged chat path.
|
|
157
|
+
*
|
|
158
|
+
* Binding failures fall back to the chat path rather than dropping the wake — a task that
|
|
159
|
+
* cannot open its session should still be visible, not silently skipped.
|
|
160
|
+
*/
|
|
161
|
+
const prepareTaskStep = async (event, runner) => {
|
|
162
|
+
const match = /^\[TASK_DRIVER:([A-Za-z0-9._-]+)\]/.exec(event.text);
|
|
163
|
+
if (!match?.[1] || !runner.bindTaskSession)
|
|
164
|
+
return undefined;
|
|
165
|
+
const taskId = match[1];
|
|
166
|
+
const channelDir = ensureChannelDir(options.paths.workspaceDir, event.channelId);
|
|
167
|
+
try {
|
|
168
|
+
const document = await readStoredTask(channelDir, taskId);
|
|
169
|
+
if (!document)
|
|
170
|
+
return undefined;
|
|
171
|
+
const brief = await buildTaskStepBrief({ channelDir, taskId });
|
|
172
|
+
if (!brief)
|
|
173
|
+
return undefined;
|
|
174
|
+
await runner.bindTaskSession(taskId, document.fields.cycle?.id ?? "c-adhoc");
|
|
175
|
+
return { taskId, brief };
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
log.logWarning(`[${event.channelId}] Could not start task step for ${taskId}`, errorMessage(error));
|
|
179
|
+
return undefined;
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
/** Deliver whatever the step asked to say, then hand the runner back to the chat session. */
|
|
183
|
+
const finishTaskStep = async (channelId, taskId, ctx) => {
|
|
184
|
+
const channelDir = ensureChannelDir(options.paths.workspaceDir, channelId);
|
|
185
|
+
try {
|
|
186
|
+
const notice = await consumeTaskNotice(channelDir, taskId);
|
|
187
|
+
if (notice)
|
|
188
|
+
await ctx.respond(notice, true);
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
log.logWarning(`[${channelId}] Could not deliver task notice for ${taskId}`, errorMessage(error));
|
|
192
|
+
}
|
|
193
|
+
await getRunner(channelId).bindChatSession?.();
|
|
194
|
+
};
|
|
151
195
|
const handler = {
|
|
152
196
|
isRunning(channelId) {
|
|
153
197
|
return channelRunners.get(channelId)?.isBusy() ?? false;
|
|
@@ -218,7 +262,6 @@ function createDingTalkHandler(deps) {
|
|
|
218
262
|
.then(async () => {
|
|
219
263
|
try {
|
|
220
264
|
const channelDir = ensureChannelDir(options.paths.workspaceDir, event.channelId);
|
|
221
|
-
ensureChannelMemoryFilesSync(channelDir);
|
|
222
265
|
const access = resolveProjectAccessPolicy(loadSecurityConfigWithDiagnostics(options.paths.appHomeDir).config, process.cwd());
|
|
223
266
|
const scope = resolveProjectScope(channelDir, access);
|
|
224
267
|
if (scope.kind === "blocked") {
|
|
@@ -452,7 +495,8 @@ function createDingTalkHandler(deps) {
|
|
|
452
495
|
// handler, making the busy state observable to another message in the same tick.
|
|
453
496
|
getRunner(event.channelId).beginTurn(event.text);
|
|
454
497
|
},
|
|
455
|
-
async handleEvent(
|
|
498
|
+
async handleEvent(inboundEvent, bot, _isEvent) {
|
|
499
|
+
let event = inboundEvent;
|
|
456
500
|
if (isShuttingDown()) {
|
|
457
501
|
log.logInfo(`[${event.channelId}] Ignoring event during shutdown`);
|
|
458
502
|
return;
|
|
@@ -481,7 +525,15 @@ function createDingTalkHandler(deps) {
|
|
|
481
525
|
// wake (a delegation or job finishing) is the opposite — a human is actually waiting
|
|
482
526
|
// on it — so it renders progress the same way a normal message does (P0-2).
|
|
483
527
|
const backgroundOnly = Boolean(_isEvent) && event.presentation !== "awaited";
|
|
484
|
-
const
|
|
528
|
+
const baseCtx = createDingTalkContext(event, bot, store, backgroundOnly ? "none" : undefined);
|
|
529
|
+
// Spec 051, D3: a task-driver dispatch runs as a *task step* — in the task cycle's
|
|
530
|
+
// own session, with a brief instead of the wake text, and silent unless the step
|
|
531
|
+
// asked for a notify. Everything below (busy state, /stop, delivery) is unchanged;
|
|
532
|
+
// only which session the turn is bound to, and what reaches the channel, differ.
|
|
533
|
+
const taskStep = await prepareTaskStep(event, runner);
|
|
534
|
+
const ctx = taskStep ? muteChannelContext(baseCtx) : baseCtx;
|
|
535
|
+
if (taskStep)
|
|
536
|
+
event = { ...event, text: taskStep.brief };
|
|
485
537
|
if (builtInCommand) {
|
|
486
538
|
const commandStartedAt = Date.now();
|
|
487
539
|
const logCtx = { channelId: event.channelId, userName: event.userName };
|
|
@@ -536,10 +588,6 @@ function createDingTalkHandler(deps) {
|
|
|
536
588
|
if (!backgroundOnly) {
|
|
537
589
|
ctx.primeCard(350);
|
|
538
590
|
}
|
|
539
|
-
// Effects are tallied per channel; the governor needs them per task, so one
|
|
540
|
-
// task-driver turn is measured as a delta (turns on a channel are serialized)
|
|
541
|
-
// and credited to the task it was dispatched for.
|
|
542
|
-
const effectsBefore = channelEffectCount(event.channelId);
|
|
543
591
|
// Both wake formats below carry an unauthenticated claim in plain text: anything
|
|
544
592
|
// that can put a message on this channel can *write* "[JOB:x] ... belongs to task
|
|
545
593
|
// y." or "[SUBAGENT:x] ... belongs to task y." — including another user, or an
|
|
@@ -553,13 +601,10 @@ function createDingTalkHandler(deps) {
|
|
|
553
601
|
const jobMatch = event.internalWake?.kind === "job"
|
|
554
602
|
? [event.text, event.internalWake.resourceId, event.internalWake.taskId]
|
|
555
603
|
: jobTextMatch;
|
|
556
|
-
let recoveredJobTaskId;
|
|
557
604
|
if (jobMatch) {
|
|
558
605
|
const [, jobId, jobTaskId] = jobMatch;
|
|
559
606
|
const claimed = await claimVerifiedJobWake(event, options.paths.workspaceDir, getExecutor(), options.wakeTransitionHooks?.job);
|
|
560
607
|
if (claimed) {
|
|
561
|
-
if (claimed.activated)
|
|
562
|
-
recoveredJobTaskId = claimed.taskId;
|
|
563
608
|
await claimed.finish();
|
|
564
609
|
structuredWakeFinalized = true;
|
|
565
610
|
// Drop without a turn only when something else is still driving this task (a
|
|
@@ -584,13 +629,10 @@ function createDingTalkHandler(deps) {
|
|
|
584
629
|
const delegationMatch = event.internalWake?.kind === "subagent"
|
|
585
630
|
? [event.text, event.internalWake.resourceId, event.internalWake.taskId]
|
|
586
631
|
: delegationTextMatch;
|
|
587
|
-
let recoveredDelegationTaskId;
|
|
588
632
|
if (delegationMatch) {
|
|
589
633
|
const [, runId, delegationTaskId] = delegationMatch;
|
|
590
634
|
const claimed = await claimVerifiedDelegationWake(event, options.paths.workspaceDir, options.wakeTransitionHooks?.subagent);
|
|
591
635
|
if (claimed) {
|
|
592
|
-
if (claimed.activated)
|
|
593
|
-
recoveredDelegationTaskId = claimed.taskId;
|
|
594
636
|
await claimed.finish();
|
|
595
637
|
structuredWakeFinalized = true;
|
|
596
638
|
// See the JOB branch above (P3-1): only skip the turn when the task is still
|
|
@@ -607,14 +649,8 @@ function createDingTalkHandler(deps) {
|
|
|
607
649
|
}
|
|
608
650
|
}
|
|
609
651
|
const result = await runner.run(ctx, store);
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
// The three sources above are mutually exclusive (each regex is anchored at the
|
|
613
|
-
// start of a distinct prefix), so crediting effects to whichever one matched is
|
|
614
|
-
// equivalent to checking all three separately.
|
|
615
|
-
if (taskAttemptId) {
|
|
616
|
-
noteTaskEffects(event.channelId, taskAttemptId, channelEffectCount(event.channelId) - effectsBefore);
|
|
617
|
-
}
|
|
652
|
+
if (taskStep)
|
|
653
|
+
await finishTaskStep(event.channelId, taskStep.taskId, baseCtx);
|
|
618
654
|
if (result.stopReason === "aborted" && runner.getTurnStatus().stopRequested) {
|
|
619
655
|
log.logInfo(`[${event.channelId}] Stopped`);
|
|
620
656
|
}
|
|
@@ -631,8 +667,8 @@ function createDingTalkHandler(deps) {
|
|
|
631
667
|
else
|
|
632
668
|
await getDurableDispatch()?.markRetryable(event.dispatchId);
|
|
633
669
|
runner.endTurn();
|
|
634
|
-
// A finished turn may have written task files
|
|
635
|
-
//
|
|
670
|
+
// A finished turn may have written task files; rescan now so `outcome: continue`
|
|
671
|
+
// queues the next step immediately instead of waiting out the current sleep.
|
|
636
672
|
getTaskDriver().nudge?.();
|
|
637
673
|
}
|
|
638
674
|
})();
|
|
@@ -684,7 +720,6 @@ export async function createRuntimeContext(options) {
|
|
|
684
720
|
return existing;
|
|
685
721
|
}
|
|
686
722
|
const channelDir = ensureChannelDir(options.paths.workspaceDir, channelId);
|
|
687
|
-
ensureChannelMemoryFilesSync(channelDir);
|
|
688
723
|
const runner = createRunner(channelId, channelDir, {
|
|
689
724
|
appHomeDir: options.paths.appHomeDir,
|
|
690
725
|
authConfigPath: options.paths.authConfigPath,
|
|
@@ -825,10 +860,7 @@ export async function createRuntimeContext(options) {
|
|
|
825
860
|
isChannelActive: (channelId) => channelRunners.get(channelId)?.isBusy() ?? false,
|
|
826
861
|
getSettings: () => {
|
|
827
862
|
runtimeSettingsManager.reload();
|
|
828
|
-
return {
|
|
829
|
-
memoryMaintenance: runtimeSettingsManager.getMemoryMaintenanceSettings(),
|
|
830
|
-
sessionMemory: runtimeSettingsManager.getSessionMemorySettings(),
|
|
831
|
-
};
|
|
863
|
+
return { memoryMaintenance: runtimeSettingsManager.getMemoryMaintenanceSettings() };
|
|
832
864
|
},
|
|
833
865
|
intervalMs: options.memoryMaintenanceSchedulerIntervalMs,
|
|
834
866
|
});
|
|
@@ -853,7 +885,6 @@ export async function createRuntimeContext(options) {
|
|
|
853
885
|
isChannelActive: (channelId) => channelRunners.get(channelId)?.isBusy() ?? false,
|
|
854
886
|
dispatch: (event) => durableDispatch?.dispatch(event) ?? false,
|
|
855
887
|
onDispatch: options.onTaskDriverDispatch,
|
|
856
|
-
getEffectCount: taskEffectCount,
|
|
857
888
|
notify: (receipt) => bot.sendPlain(receipt.channelId, receipt.text),
|
|
858
889
|
getSettings: () => {
|
|
859
890
|
runtimeSettingsManager.reload();
|
|
@@ -948,15 +979,9 @@ export async function createRuntimeContext(options) {
|
|
|
948
979
|
});
|
|
949
980
|
}
|
|
950
981
|
if (startServices) {
|
|
951
|
-
//
|
|
952
|
-
//
|
|
953
|
-
|
|
954
|
-
// phase 5): each file is judged by what it actually contains, so this is safe and cheap to run
|
|
955
|
-
// on every startup — a hand-edited or freshly-restored legacy file self-heals on the next boot.
|
|
956
|
-
void Promise.all([
|
|
957
|
-
migrateLegacyTaskScheduleEvents(options.paths.workspaceDir),
|
|
958
|
-
migrateLegacyTaskState(options.paths.workspaceDir),
|
|
959
|
-
]);
|
|
982
|
+
// Upgrade every v3 task file to the v4 contract before the driver relies on it (spec 051, D14). Marker-gated: the pass rewrites
|
|
983
|
+
// bodies and imports history into the loop log, so it must run exactly once per install.
|
|
984
|
+
void migrateTasksToV4(options.paths.workspaceDir, join(options.paths.appHomeDir, "state"));
|
|
960
985
|
eventsWatcher.start();
|
|
961
986
|
memoryMaintenanceScheduler.start();
|
|
962
987
|
taskDriver.start();
|
package/dist/runtime/events.d.ts
CHANGED
|
@@ -115,6 +115,15 @@ export declare class EventsWatcher {
|
|
|
115
115
|
* split that would cut a dotted task id short.
|
|
116
116
|
*/
|
|
117
117
|
private orphanedOwnerReason;
|
|
118
|
+
/**
|
|
119
|
+
* Redeem the owning task's `signal` ticket, if this is a task-owned event and that task is
|
|
120
|
+
* parked on a ticket naming exactly this event. Returns whether the ticket was redeemed.
|
|
121
|
+
*
|
|
122
|
+
* The name match is strict (INV-7): a ticket only accepts the event it names, so an unrelated
|
|
123
|
+
* task-owned event can never resume a task, and a task parked on anything else still gets its
|
|
124
|
+
* ordinary chat wake.
|
|
125
|
+
*/
|
|
126
|
+
private redeemTaskSignal;
|
|
118
127
|
private execute;
|
|
119
128
|
private runPreAction;
|
|
120
129
|
private deleteFile;
|
package/dist/runtime/events.js
CHANGED
|
@@ -10,7 +10,8 @@ import { createJsonlAppender } from "../shared/jsonl-appender.js";
|
|
|
10
10
|
import { formatLocalTime, parseLocalTime } from "../shared/local-time.js";
|
|
11
11
|
import { clipText, errorMessage, eventNameFromFilename } from "../shared/text-utils.js";
|
|
12
12
|
import { isPlainObject } from "../shared/type-guards.js";
|
|
13
|
-
import {
|
|
13
|
+
import { parseTaskFrontmatterV4 } from "../tasks/frontmatter.js";
|
|
14
|
+
import { redeemTicket } from "../tasks/store.js";
|
|
14
15
|
import { parseTaskEventName } from "../tasks/task-events.js";
|
|
15
16
|
import { MAX_EVENT_FILES, MAX_ONE_SHOT_DELAY_MS, validateScheduledEvent } from "./event-validation.js";
|
|
16
17
|
// ============================================================================
|
|
@@ -505,11 +506,37 @@ export class EventsWatcher {
|
|
|
505
506
|
catch {
|
|
506
507
|
return `owning task ${taskId} no longer exists`;
|
|
507
508
|
}
|
|
508
|
-
const frontmatter =
|
|
509
|
-
return frontmatter.
|
|
510
|
-
? `owning task ${taskId} is archived (${frontmatter.
|
|
509
|
+
const frontmatter = parseTaskFrontmatterV4(content);
|
|
510
|
+
return frontmatter.fields.outcome
|
|
511
|
+
? `owning task ${taskId} is archived (${frontmatter.fields.outcome})`
|
|
511
512
|
: undefined;
|
|
512
513
|
}
|
|
514
|
+
/**
|
|
515
|
+
* Redeem the owning task's `signal` ticket, if this is a task-owned event and that task is
|
|
516
|
+
* parked on a ticket naming exactly this event. Returns whether the ticket was redeemed.
|
|
517
|
+
*
|
|
518
|
+
* The name match is strict (INV-7): a ticket only accepts the event it names, so an unrelated
|
|
519
|
+
* task-owned event can never resume a task, and a task parked on anything else still gets its
|
|
520
|
+
* ordinary chat wake.
|
|
521
|
+
*/
|
|
522
|
+
async redeemTaskSignal(filename, event) {
|
|
523
|
+
const name = eventNameFromFilename(filename);
|
|
524
|
+
const parsed = parseTaskEventName(name, event.channelId);
|
|
525
|
+
if (!parsed)
|
|
526
|
+
return false;
|
|
527
|
+
const channelDir = getChannelDir(dirname(this.eventsDir), event.channelId);
|
|
528
|
+
try {
|
|
529
|
+
const redeemed = await redeemTicket(channelDir, parsed.id, (ticket) => ticket.kind === "signal" && ticket.event === name);
|
|
530
|
+
if (!redeemed)
|
|
531
|
+
return false;
|
|
532
|
+
log.logInfo(`Event ${name} redeemed the signal ticket for task ${parsed.id}`);
|
|
533
|
+
return true;
|
|
534
|
+
}
|
|
535
|
+
catch (error) {
|
|
536
|
+
log.logWarning(`Could not redeem signal ticket for task ${parsed.id}`, errorMessage(error));
|
|
537
|
+
return false;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
513
540
|
async execute(filename, event, deleteAfter = true, occurrence = new Date()) {
|
|
514
541
|
const orphaned = await this.orphanedOwnerReason(filename, event);
|
|
515
542
|
if (orphaned) {
|
|
@@ -559,6 +586,18 @@ export class EventsWatcher {
|
|
|
559
586
|
return;
|
|
560
587
|
}
|
|
561
588
|
}
|
|
589
|
+
// Spec 051, D8: the *only* touchpoint between the events subsystem and the task loop. When a
|
|
590
|
+
// task-owned sensor fires and the owning task is parked on a `signal` ticket naming this very
|
|
591
|
+
// event, redeem the ticket and stop — the task's own loop takes it from here, and delivering
|
|
592
|
+
// a chat wake as well would both duplicate the work and route it into the wrong session.
|
|
593
|
+
// Anything else (an ordinary event, or a task that is not waiting on this signal) falls
|
|
594
|
+
// through to the unchanged delivery path below.
|
|
595
|
+
if (await this.redeemTaskSignal(filename, event)) {
|
|
596
|
+
this.appendEventHistory(filename, event, "triggered", "ok", { reason: "redeemed task signal ticket" });
|
|
597
|
+
if (deleteAfter)
|
|
598
|
+
this.deleteFile(filename);
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
562
601
|
let scheduleInfo;
|
|
563
602
|
switch (event.type) {
|
|
564
603
|
case "one-shot":
|
|
@@ -1,28 +1,23 @@
|
|
|
1
|
+
import type { TaskBudget } from "../tasks/frontmatter.js";
|
|
1
2
|
export interface HandleTasksCommandOptions {
|
|
2
3
|
args: string;
|
|
3
4
|
/** The channel directory; tasks live in `<channelDir>/tasks/`. */
|
|
4
5
|
channelDir: string;
|
|
5
|
-
/** Workspace directory;
|
|
6
|
+
/** Workspace directory; kept for callers that still pass it (doctor reads task-owned events). */
|
|
6
7
|
workspaceDir?: string;
|
|
7
8
|
channelId?: string;
|
|
8
9
|
/** Optional immediate task wake, available in the long-lived DingTalk runtime. */
|
|
9
10
|
dispatchTask?: (id: string) => Promise<boolean>;
|
|
10
11
|
}
|
|
11
|
-
/**
|
|
12
|
-
* Fields `/tasks set` can edit directly.
|
|
13
|
-
*
|
|
14
|
-
* Deliberately a small, flat set: the ones a user already knows they want to change (when it
|
|
15
|
-
* should wake, what it should do next, how much rope it has). Everything structural — status
|
|
16
|
-
* transitions and verification — stays with `task_update`/`task_close`/`task_verify`, whose state
|
|
17
|
-
* machine those fields belong to. The value is the rest of the line, so it may contain spaces.
|
|
18
|
-
*/
|
|
19
|
-
declare const SETTABLE_TASK_FIELDS: readonly ["wake", "next", "deadline"];
|
|
20
|
-
type SettableTaskField = (typeof SETTABLE_TASK_FIELDS)[number];
|
|
21
12
|
type TasksCommand = {
|
|
22
13
|
action: "list";
|
|
23
14
|
} | {
|
|
24
15
|
action: "show";
|
|
25
16
|
id: string;
|
|
17
|
+
} | {
|
|
18
|
+
action: "log";
|
|
19
|
+
id: string;
|
|
20
|
+
cycle?: string;
|
|
26
21
|
} | {
|
|
27
22
|
action: "archive";
|
|
28
23
|
} | {
|
|
@@ -33,18 +28,22 @@ type TasksCommand = {
|
|
|
33
28
|
} | {
|
|
34
29
|
action: "resume";
|
|
35
30
|
id: string;
|
|
31
|
+
grants: Partial<TaskBudget>;
|
|
36
32
|
} | {
|
|
37
33
|
action: "run";
|
|
38
34
|
id: string;
|
|
39
35
|
} | {
|
|
40
|
-
action: "
|
|
36
|
+
action: "steer";
|
|
37
|
+
id: string;
|
|
38
|
+
text: string;
|
|
39
|
+
} | {
|
|
40
|
+
action: "reply";
|
|
41
41
|
id: string;
|
|
42
|
-
|
|
43
|
-
value: string;
|
|
42
|
+
text: string;
|
|
44
43
|
};
|
|
45
44
|
/** Exported so `test/commands-subcommands.test.ts` can feed every broadcast example back through it. */
|
|
46
45
|
export declare function parseTasksCommand(args: string): TasksCommand;
|
|
47
46
|
export declare function pauseTask(options: HandleTasksCommandOptions, idInput: string): Promise<string>;
|
|
48
|
-
export declare function resumeTask(options: HandleTasksCommandOptions, idInput: string): Promise<string>;
|
|
47
|
+
export declare function resumeTask(options: HandleTasksCommandOptions, idInput: string, grants?: Partial<TaskBudget>): Promise<string>;
|
|
49
48
|
export declare function handleTasksCommand(options: HandleTasksCommandOptions): Promise<string>;
|
|
50
49
|
export {};
|