@myclaw163/clawclaw-cli 0.8.27 → 0.8.28
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/docs/custom-modules/api-reference.md +2 -2
- package/docs/custom-modules/examples/task-reminder.ts +5 -3
- package/docs/custom-modules/perception.md +1 -1
- package/docs/custom-modules/reminders.md +88 -92
- package/docs/runtime/agent-notifications.md +2 -2
- package/docs/runtime/events-and-state.md +1 -1
- package/package.json +1 -1
- package/skills/clawclaw/SKILL.md +3 -3
- package/skills/clawclaw/references/CHANNELS.md +1 -1
- package/skills/clawclaw/references/COMMANDS.md +1 -1
- package/skills/clawclaw/references/CUSTOM-MODULE-API.md +2 -2
- package/skills/clawclaw/references/CUSTOM-PERCEPTION-DEVELOPMENT.md +1 -1
- package/skills/clawclaw/references/CUSTOM-REMINDER-DEVELOPMENT.md +88 -92
- package/skills/clawclaw/references/STREAM.md +2 -2
- package/src/pipeline/event-format.ts +2 -0
- package/src/runtime/clawclaw/owner.ts +0 -1
- package/src/runtime/clawclaw/plugins/derived-event/reminder-plugin.ts +38 -29
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-presentation.ts +0 -3
- package/src/runtime/clawclaw/plugins/source/source-plugin.ts +2 -26
- package/src/runtime/clawclaw/plugins/source/task-change-tracker.ts +10 -10
- package/src/runtime/clawclaw/runtime.ts +0 -3
- package/src/runtime/clawclaw-event-catalog.ts +6 -8
- package/src/sdk/perception-plugin/reminder-rules.ts +73 -20
- package/src/sdk/perception-plugin/reminder.ts +25 -2
|
@@ -1,71 +1,52 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 开发任务提醒感知
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
从 CCL 0.8.28 起,任务提醒统一由装配的 `reminder.tasks` 或自定义 tasks 脚本产生。CCL 接收后端事实、维护当前游戏 State、提供输入并交付输出;脚本只读这些输入,决定说什么、是否唤醒,不修改游戏 State。
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
| `ability.ready` | 能力 ready 从 false 变为 true 时通知 |
|
|
9
|
-
| `ability.remaining_uses_changed` | 有限次数变化且新值不为 0 时通知 |
|
|
10
|
-
| `ability.exhausted` | 次数变化到 0 时通知,不同时生成上一种事件 |
|
|
5
|
+
## 职责与三种选择
|
|
6
|
+
|
|
7
|
+
任务新增、开始、进度、完成、中断、破坏任务完成、列表移除及信息变化,都由脚本控制。原始 `task_*` 和 `tasks_changed` 留作内部输入,不再直接推给 Agent,也不出现在 Agent 的 `ccl events` 结果里。
|
|
11
8
|
|
|
12
|
-
|
|
9
|
+
| 配置值 | 脚本输出 | Agent 交付 |
|
|
10
|
+
|---|---|---|
|
|
11
|
+
| `wake` | 一条 `reminder.task`,`wakeAgent:true` | 可以触发唤醒,仍服从交付预算 |
|
|
12
|
+
| `silent` | 一条 `reminder.task`,`wakeAgent:false` | 不独立唤醒,随之后的唤醒批次搭便车;Agent 主动读取 events 也可读到 |
|
|
13
|
+
| `state_only` | 不生成该变化的提醒事件 | CCL 照常更新 State;没有待交付提醒 |
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
“仅 State”不用脚本更新 State,也不用返回一条隐藏提醒。脚本对这一项不输出事件即可。内部原始事实仍可用于 Behavior、恢复和诊断,不代表生成了 Agent 提醒。
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
未装配脚本、脚本失败或 tasks 主题冲突时,不产生任务提醒;当前 State 和原始事实仍保留。没有 CCL 自动补发任务完成通知的兜底,请按需要装配任务提醒。
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
以下仍由 CCL 负责:房间/等待、发言、会议、紧急任务生命周期、`emergency_countdown_warning`(跨过 30 秒和 20 秒)、`ability.ready`、`ability.remaining_uses_changed`、`ability.exhausted`。任务脚本不能关闭或冒用这些事件。
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
<workspace>/user-data/accounts/<account-hash>/capabilities/perceptions/
|
|
22
|
-
```
|
|
21
|
+
## 安装与单文件脚本
|
|
23
22
|
|
|
24
|
-
|
|
23
|
+
沿用普通感知的发现、装配、启停和 Hub 流程,无额外命令或配置文件。示例位于 `docs/custom-modules/examples/task-reminder.ts`。
|
|
24
|
+
|
|
25
|
+
本地安装:保存到当前账号 `<workspace>/user-data/accounts/<account-hash>/capabilities/perceptions/`。`ccl perception --help` 显示实际目录;然后执行:
|
|
25
26
|
|
|
26
27
|
```powershell
|
|
27
28
|
ccl perception --list
|
|
28
29
|
ccl perception --enable reminder.tasks
|
|
29
|
-
ccl load
|
|
30
|
-
ccl perception --disable reminder.tasks
|
|
31
30
|
```
|
|
32
31
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
**没有装配 tasks 感知,就不展示这类普通任务变化提醒**;初始化任务信息、任务完成/被打断/被破坏等 CCL 基础通知继续保留,当前任务 State 始终可查询。包内示例不是新账号必然安装的默认装配。
|
|
36
|
-
|
|
37
|
-
参数直接写在脚本中。`manifest.config` 是脚本内集中声明参数的对象,也是代码的一部分,CCL 将它作为 `input.config` 传入;修改源码后重启 Runtime 生效。
|
|
32
|
+
操作名以 list 返回值为准,重名可能有后缀。修改文件后重启 Runtime 生效。也可以从 Hub 装配资源,再用现有 `ccl load` 流程同步;本地安装不要求先上传 Hub。
|
|
38
33
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
Hub 感知资源对应一个顶层 `.ts` 或 `.js` 文件;策略也按单入口文件交付。不能指望 Hub 额外分发旁边的 helper 或配置文件。
|
|
42
|
-
|
|
43
|
-
单文件脚本可以导入 CCL 公共 SDK,由运行环境提供基类、类型和工具,无需一并上传 SDK。下面的例子没有额外用户文件。安装的 CCL 必须实际包含相关导出;旧版本即使也标记为 API v2,仍可能缺少提醒类和工具。
|
|
44
|
-
|
|
45
|
-
原来的 emergency、ability 提醒示例已删除,Manifest 不再接受这两个 topic。若之前自行保存过这些示例,应通过现有感知管理流程卸装;它们不能覆盖恢复后的 CCL 固定通知。
|
|
46
|
-
|
|
47
|
-
## 模块示例
|
|
34
|
+
Hub 感知资源使用一个顶层 `.ts` 或 `.js` 文件。`manifest.config` 就是这个文件里的代码对象,不是旁边的配置文件。公共 SDK 由 CCL 提供,无需一并上传。
|
|
48
35
|
|
|
49
36
|
```ts
|
|
50
|
-
import {
|
|
51
|
-
ClawclawReminder,
|
|
52
|
-
evaluateReminder,
|
|
53
|
-
type ReminderInput,
|
|
54
|
-
} from '@myclaw163/clawclaw-cli/perception-plugin';
|
|
37
|
+
import { ClawclawReminder, evaluateReminder, type ReminderInput } from '@myclaw163/clawclaw-cli/perception-plugin';
|
|
55
38
|
|
|
39
|
+
// Requires CCL >= 0.8.28. This single file includes its own reminder preferences.
|
|
56
40
|
export default class TaskReminder extends ClawclawReminder {
|
|
57
41
|
static readonly manifest = {
|
|
58
42
|
apiVersion: 2,
|
|
59
43
|
kind: 'reminder',
|
|
60
44
|
id: 'reminder.tasks',
|
|
61
|
-
description: '
|
|
45
|
+
description: '统一处理任务新增、开始、进度、完成、中断、破坏及列表变化;分别选择唤醒、搭便车或仅 State。',
|
|
62
46
|
topic: 'tasks',
|
|
63
|
-
consumes: ['
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
added: 'notify',
|
|
67
|
-
updated: 'query',
|
|
68
|
-
},
|
|
47
|
+
consumes: ['task_started', 'task_progress', 'task_assigned', 'task_completed', 'task_interrupted', 'task_sabotaged',
|
|
48
|
+
'emergency_started', 'emergency_resolved', 'emergency_interrupted'],
|
|
49
|
+
config: { started: 'state_only', progress: 'state_only', added: 'wake', completed: 'wake', interrupted: 'wake', sabotaged: 'wake', removed: 'wake', updated: 'silent' },
|
|
69
50
|
} as const;
|
|
70
51
|
|
|
71
52
|
update(input: ReminderInput) {
|
|
@@ -74,74 +55,89 @@ export default class TaskReminder extends ClawclawReminder {
|
|
|
74
55
|
}
|
|
75
56
|
```
|
|
76
57
|
|
|
77
|
-
|
|
58
|
+
## 输入:统一上下文,按需读取
|
|
78
59
|
|
|
79
|
-
|
|
60
|
+
`update(input: ReminderInput)` 接收以下只读上下文。脚本可以只用其中一部分。
|
|
80
61
|
|
|
81
|
-
|
|
62
|
+
| 字段 | 内容 |
|
|
63
|
+
|---|---|
|
|
64
|
+
| `gameState` | 当前账号有权知道的 GameState;没有新鲜游戏状态时为 null |
|
|
65
|
+
| `frame` | 当前 ObservationFrame;无法形成视觉帧时为 null |
|
|
66
|
+
| `facts` | `manifest.consumes` 订阅的有序原始事实,含 eventId、epochId、type、occurredAt、producer、payload |
|
|
67
|
+
| `taskChanges` | 复用 CCL 已有任务列表比较结果,不受 facts 订阅筛选影响 |
|
|
68
|
+
| `boundary` | `initial`、`recovery` 或 null;前两种只建立私有基线,不发送提醒 |
|
|
69
|
+
| `config` | 本文件 manifest.config;可用 manifest.inputs 做字段校验和默认值补齐 |
|
|
70
|
+
| `state` | 上次回调返回的私有记忆,初次为 undefined;不是游戏 State |
|
|
71
|
+
| `scope` | sessionId、segmentId |
|
|
72
|
+
| `nowMs` | 当前输入的观察/接收时间 |
|
|
82
73
|
|
|
83
|
-
|
|
84
|
-
declare function evaluateReminder(
|
|
85
|
-
topic: 'tasks',
|
|
86
|
-
input: ReminderInput,
|
|
87
|
-
): ReminderResult;
|
|
88
|
-
```
|
|
74
|
+
`taskChanges` 每一项包含:稳定的本次变化 `key`、来源 `eventId/epochId`、`change`(added/removed/status_changed/updated)、`task`、可选 `before/from_status/to_status` 和 `baseline`。removed 中 task 是移除前的任务;其余是当前任务。baseline 表示首次任务快照,默认不作为新任务提醒。
|
|
89
75
|
|
|
90
|
-
|
|
76
|
+
这是任务列表已有的结构变化,不是全 State 的通用 diff。其他历史比较可由脚本按需实现并保存在私有 state。身份优先使用 task_id;后端未提供 ID 时,CCL 用名称、地点等识别,改名/移动可能表现为移除加新增,不应据此断言任务被替换。
|
|
91
77
|
|
|
92
|
-
|
|
93
|
-
|---|---|---|
|
|
94
|
-
| `started` | delta 中 status_changed,normal → in_progress | off |
|
|
95
|
-
| `added` | delta 中 added | notify |
|
|
96
|
-
| `updated` | 上述之外的普通 delta,例如 removed 或其他状态变化 | notify |
|
|
78
|
+
输入 State 对齐当前 Runtime epoch;积累的 facts/taskChanges 用 epochId 标明原边界,不能仅因同批交付就认为它们有因果关系。只提供当前账号可知信息,无 Action、凭据或全知数据。
|
|
97
79
|
|
|
98
|
-
|
|
80
|
+
可订阅的事实:`tasks_changed`、`task_started`、`task_progress`、`task_assigned`、`task_completed`、`task_interrupted`、`task_sabotaged`、`role_assigned`、`emergency_started`、`emergency_resolved`、`emergency_interrupted`、`meeting_briefing` 以及三个 `ability.*`。不接受 `*`。订阅固定通知只用于读取上下文,不赋予修改权。
|
|
99
81
|
|
|
100
|
-
|
|
101
|
-
|---|---|
|
|
102
|
-
| `notify` | 可以主动唤醒,仍服从交付预算 |
|
|
103
|
-
| `query` | 仅供 ccl events 查询,不随 Monitor/Channel/Desktop 推送 |
|
|
104
|
-
| `off` | 不展示这条普通任务提醒;账本事实、当前 State 和 Behavior 输入继续保留 |
|
|
82
|
+
视觉脚本仍使用原有视觉回调;本接口是 Reminder 类的上下文,不要求改写现有视觉模块。
|
|
105
83
|
|
|
106
|
-
|
|
84
|
+
## evaluateReminder:可选的默认算法
|
|
107
85
|
|
|
108
|
-
|
|
86
|
+
```ts
|
|
87
|
+
evaluateReminder(topic: 'tasks', input: ReminderInput): ReminderResult
|
|
88
|
+
```
|
|
109
89
|
|
|
110
|
-
|
|
90
|
+
工具只在脚本调用时运行,不自行交付通知。可以直接使用、筛选其 events,或完全自己实现。
|
|
111
91
|
|
|
112
|
-
|
|
92
|
+
| 参数 | 含义 | 示例/工具默认值 |
|
|
93
|
+
|---|---|---|
|
|
94
|
+
| started | 开始任务 | state_only |
|
|
95
|
+
| progress | 后端任务进度事件 | state_only |
|
|
96
|
+
| added | 新分配或列表新增任务 | wake |
|
|
97
|
+
| completed | 后端完成,或列表状态明确变成 completed | wake |
|
|
98
|
+
| interrupted | 后端明确的任务中断 | wake |
|
|
99
|
+
| sabotaged | 后端 task_sabotaged,即破坏任务完成 | wake |
|
|
100
|
+
| removed | 列表移除、原因没有被对应事实解释 | wake |
|
|
101
|
+
| updated | 其他状态或信息变化 | silent |
|
|
113
102
|
|
|
114
|
-
|
|
103
|
+
工具逐条处理,不对整包变化取最高提醒等级:
|
|
115
104
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
105
|
+
1. 初始化/恢复输入只建立基线,不输出提醒。
|
|
106
|
+
2. 从任务事实提取开始、分配、完成等含义,按对应参数产生提醒。
|
|
107
|
+
3. 读取列表变化;同一 epoch 中明确对应同一任务且表达同一变化的事实已经处理过,就不重复提醒。优先匹配 ID,否则只匹配身份没有歧义的任务名称/地点;其他玩家的完成不用于解释自己的任务变化。
|
|
108
|
+
4. 独立变化分别处理。A 完成不能吞掉同帧 B 开始、C 新增。完成提醒中也不夹带下一任务或整个列表,避免绕过 added 的配置。
|
|
109
|
+
5. 列表消失只说明不再列出,不推断完成。明确对应紧急任务生命周期的新增/移除由固定紧急事件表达,避免重复。
|
|
119
110
|
|
|
120
|
-
|
|
111
|
+
例如 A 完成(wake)、B 开始(state_only)、C 新增(silent),输出两条事件:A 完成可唤醒,C 新增可搭便车。B 没有提醒事件,但 CCL 的当前 State 包含三项变化。
|
|
121
112
|
|
|
122
|
-
|
|
123
|
-
|---|---|
|
|
124
|
-
| `gameState` | 当前新鲜玩家视角 GameState;不可用时为 null |
|
|
125
|
-
| `frame` | ObservationFrame;无法形成视觉帧时为 null,仍可能有 gameState |
|
|
126
|
-
| `facts` | 按顺序交付的新增订阅事实,含 eventId、可选 epochId、type、occurredAt、producer、payload |
|
|
127
|
-
| `config` | 本脚本配置,提供 inputs 时会校验和补默认值 |
|
|
128
|
-
| `state` | 宿主保存的上一轮模块状态;首次可能为 undefined |
|
|
129
|
-
| `scope` | sessionId、segmentId |
|
|
130
|
-
| `nowMs` | 当前输入的观察/接收时间 |
|
|
113
|
+
不需要保存历史的默认算法不使用私有 state。去重、时间窗口、合并、按任务/位置/当前行为筛选等复杂规则,可以自己编写。未提供的配置由工具补默认值;未知参数或非法 mode 抛错。
|
|
131
114
|
|
|
132
|
-
|
|
115
|
+
## 输出与执行限制
|
|
133
116
|
|
|
134
|
-
|
|
117
|
+
回调返回对象,只允许 `events` 和 `state`,可返回 `{}`:
|
|
135
118
|
|
|
136
|
-
|
|
119
|
+
```ts
|
|
120
|
+
return {
|
|
121
|
+
events: [{
|
|
122
|
+
type: 'reminder.task',
|
|
123
|
+
key: 'stable-occurrence-key',
|
|
124
|
+
wakeAgent: false,
|
|
125
|
+
payload: { kind: 'added', text: '新增任务:接线。', task_name: '接线' },
|
|
126
|
+
}],
|
|
127
|
+
state: nextPrivateMemory,
|
|
128
|
+
};
|
|
129
|
+
```
|
|
137
130
|
|
|
138
|
-
- `
|
|
139
|
-
- `
|
|
131
|
+
- `type` 固定为 `reminder.task`;payload.text 为非空提醒正文,其他可序列化字段由脚本定义。默认工具还返回 kind、source_event_id 和该项任务信息。
|
|
132
|
+
- `key` 是稳定的单次发生标识(非空、最多 512 字符),同一返回中不能重复。CCL 按模块操作名、key、当前 segment 去重;新一次发生必须使用新 key。
|
|
133
|
+
- `wakeAgent` 必须为布尔值。state_only 没有对应输出结构,直接省略该项。
|
|
134
|
+
- `state` 仅供脚本下次计算和恢复。省略表示下次得到 undefined;保留需显式返回 `{ state: input.state }`。不能用它写游戏 State。
|
|
135
|
+
- 初始/恢复边界允许更新私有记忆,但宿主不发布本轮输出事件。没有新鲜 gameState 时也不发布提醒。
|
|
140
136
|
|
|
141
|
-
|
|
137
|
+
每次 update 创建新实例,跨轮记忆不能依赖实例字段。输入递归只读。Worker old-generation 64MB,加载最多 8 秒、单次 update 最多 500ms,输出必须支持 structuredClone 和 JSON,JSON 不超过 1MiB。非法输出或超时停用该模块并记录诊断,其他固定通知继续运行。Worker 不是文件系统权限沙箱,只装配可信脚本。
|
|
142
138
|
|
|
143
|
-
|
|
139
|
+
同一 tasks 主题只装配一个脚本;冲突时 `ccl load` 报 perception_topic_conflict,Runtime 不任意挑选。
|
|
144
140
|
|
|
145
|
-
|
|
141
|
+
## 从 0.8.27 迁移
|
|
146
142
|
|
|
147
|
-
|
|
143
|
+
这是对原试用提醒接口的调整:`deliveries` 不再接受,`notify/query/off` 改为 `wake/silent/state_only`。旧 query 的含义是仅 events 查询,并不等于新 silent 的搭便车。请替换为本包新示例或更新自定义代码;只升级 CCL 不会自动覆写本地脚本。任务完成/中断/破坏也必须由新脚本处理。公共 Perception API 仍为 v2,但此 Reminder 接口要求 CCL 0.8.28+。
|
|
@@ -104,9 +104,9 @@ Source 在这些已知事实变化时生成 `players_changed`:Monitor 使用
|
|
|
104
104
|
| `cooldown_charged` | 所有未完成破坏任务在共享冷却,等待 `cooldown_remaining_secs` 归零 |
|
|
105
105
|
| `emergency_active` | 已有紧急任务进行中,不能开始新的蟹破坏任务 |
|
|
106
106
|
|
|
107
|
-
不要在紧急任务结束时本地清除冷却;始终等待下一次服务端 `state.crab_sabotage
|
|
107
|
+
不要在紧急任务结束时本地清除冷却;始终等待下一次服务端 `state.crab_sabotage`。原始 `task_interrupted` 供模块读取,表示自己的破坏任务被队友触发紧急任务打断,任务未消耗。任务感知可生成 `reminder.task`(kind:interrupted)通知 Agent;任务现状以 State 为准。
|
|
108
108
|
|
|
109
|
-
|
|
109
|
+
所有原始 `task_*` 和 `tasks_changed` 仅供内部模块读取;Agent 的任务提醒统一为脚本生成的 `reminder.task`。提醒偏好不会影响 State:需要当前任务列表时,读取 `ccl events` 返回的 `state.you.tasks`。Agent 和 Behavior 不自行发 HTTP,也不从零散历史事件拼当前任务列表。
|
|
110
110
|
|
|
111
111
|
`ccl events --backlog` 不新建查询边界,只读取调用时已经 ready 的未读详情和 Monitor 委托余量。旧 participation session 不补发。
|
|
112
112
|
|
|
@@ -416,6 +416,8 @@ function shortBody(event: Record<string, any>, ctx: EventFormatContext): string
|
|
|
416
416
|
const cooldownText = cooldown === undefined ? '' : `;共享冷却剩余${cooldown}秒`;
|
|
417
417
|
return `破坏任务“${firstString(event, ['task_name'])}”因紧急任务开始而中断,任务未消耗${cooldownText}。`;
|
|
418
418
|
}
|
|
419
|
+
case 'reminder.task':
|
|
420
|
+
return firstString(event, ['text'], '任务提醒。');
|
|
419
421
|
case 'tasks_changed':
|
|
420
422
|
return `任务列表已更新(${firstString(event, ['reason'])})。`;
|
|
421
423
|
case 'players_changed':
|
|
@@ -828,7 +828,6 @@ export async function runClawclawOwner(
|
|
|
828
828
|
observability: telemetry,
|
|
829
829
|
runtimeEpochPlugins: epochPlugins,
|
|
830
830
|
visualEventDelivery: perceptionConfig.events.delivery,
|
|
831
|
-
reminderDelivery: true,
|
|
832
831
|
visualEventTypes: assembly.perception.produces.events,
|
|
833
832
|
behaviorEventTypes: assembly.behavior.produces?.events ?? [],
|
|
834
833
|
});
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { RuntimeEpochPlugin, RuntimeEpochPluginContext, RuntimeEpochPluginInput, RuntimeEpochPluginResult } from '../../../framework/plugins/index.js';
|
|
2
|
-
import type {
|
|
3
|
-
import type { ReminderInput, ReminderResult, ReminderTopic } from '../../../../sdk/perception-plugin/reminder.js';
|
|
2
|
+
import type { RuntimeEventProposal } from '../../../framework/plugins/index.js';
|
|
3
|
+
import type { ReminderInput, ReminderResult, ReminderTopic, ReminderTaskChange } from '../../../../sdk/perception-plugin/reminder.js';
|
|
4
4
|
import type { ResolvedClawclawPerceptionSource } from '../perception/perception-source.js';
|
|
5
5
|
import { freshClawclawGameState } from '../../runtime-state.js';
|
|
6
6
|
import { createCanonicalGameState } from '../../behavior-input.js';
|
|
7
7
|
import { ObservationFrameProjector } from '../../observation-frame-projector.js';
|
|
8
|
-
import {
|
|
8
|
+
import { REMINDER_EVENT_TYPES, REMINDER_FACT_TYPES, REMINDER_TOPICS } from './reminder-rules.js';
|
|
9
9
|
import { ReminderRunner } from './reminder-runner.js';
|
|
10
10
|
import { resolveClawclawResourceMetadata } from '../../../../sdk/resource-metadata.js';
|
|
11
11
|
|
|
@@ -20,17 +20,13 @@ interface Checkpoint {
|
|
|
20
20
|
states: Partial<Record<ReminderTopic, { provider: string; value: unknown }>>;
|
|
21
21
|
}
|
|
22
22
|
function empty(): Checkpoint { return { states: {} }; }
|
|
23
|
-
function coreTask(payload: Record<string, unknown>): boolean {
|
|
24
|
-
return !['task_state_changed', 'task_assigned'].includes(String(payload.reason));
|
|
25
|
-
}
|
|
26
23
|
export class ClawclawReminderPlugin implements RuntimeEpochPlugin<Record<string, any>> {
|
|
27
24
|
readonly kind = 'epoch' as const;
|
|
28
25
|
readonly id = CLAWCLAW_REMINDER_PLUGIN_ID;
|
|
29
|
-
readonly version = '
|
|
26
|
+
readonly version = '2';
|
|
30
27
|
readonly after = ['clawclaw.derived-event'];
|
|
31
28
|
readonly consumes = { events: REMINDER_FACT_TYPES };
|
|
32
|
-
readonly produces = { events:
|
|
33
|
-
readonly controlsEventDelivery = REMINDER_CONTROLLED_TYPES;
|
|
29
|
+
readonly produces = { events: REMINDER_EVENT_TYPES } as const;
|
|
34
30
|
readonly catchUp = 'strict_ordered' as const;
|
|
35
31
|
readonly timeoutMs = 3_000;
|
|
36
32
|
private checkpoint: Checkpoint = empty();
|
|
@@ -76,7 +72,12 @@ export class ClawclawReminderPlugin implements RuntimeEpochPlugin<Record<string,
|
|
|
76
72
|
const snapshot = freshClawclawGameState(input.frame.state);
|
|
77
73
|
const game = snapshot ? createCanonicalGameState(snapshot, input.frame.backendTick) : null;
|
|
78
74
|
let next = structuredClone(this.checkpoint);
|
|
79
|
-
|
|
75
|
+
const initial = !!game && next.gameId !== game.game_id;
|
|
76
|
+
const boundary = initial ? 'initial' as const
|
|
77
|
+
: (next.previousConnectionId !== undefined && next.previousConnectionId !== input.epoch.connectionId)
|
|
78
|
+
|| input.epochEvents.some(e => e.type === 'game_stream_reconnected')
|
|
79
|
+
? 'recovery' as const : null;
|
|
80
|
+
if (initial) next = { ...empty(), gameId: game!.game_id };
|
|
80
81
|
const frame = new ObservationFrameProjector().project(input.frame);
|
|
81
82
|
if (frame) {
|
|
82
83
|
const delta = next.previousTick === undefined ? null : frame.tick - next.previousTick;
|
|
@@ -87,18 +88,22 @@ export class ClawclawReminderPlugin implements RuntimeEpochPlugin<Record<string,
|
|
|
87
88
|
} else if (!game) {
|
|
88
89
|
next.previousTick = undefined; next.previousConnectionId = undefined;
|
|
89
90
|
}
|
|
91
|
+
next.previousConnectionId = input.epoch.connectionId;
|
|
90
92
|
const facts = input.pendingEvents;
|
|
91
|
-
const
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
const events: RuntimeEventProposal[] = [];
|
|
94
|
+
const taskChanges: ReminderTaskChange[] = facts.filter(e => e.type === 'tasks_changed').flatMap(e => {
|
|
95
|
+
const delta = Array.isArray(e.payload.delta) ? e.payload.delta : [];
|
|
96
|
+
return delta.map((change, index) => ({ ...change, key: `change:${e.eventId}:${index}`,
|
|
97
|
+
eventId: e.eventId, epochId: e.epochSeq,
|
|
98
|
+
baseline: e.payload.baseline === true || ['tasks_initialized', 'role_assigned'].includes(String(e.payload.reason)),
|
|
99
|
+
} as ReminderTaskChange));
|
|
100
|
+
});
|
|
96
101
|
for (const topic of REMINDER_TOPICS) {
|
|
97
102
|
const selected = this.sources.get(topic)?.[0];
|
|
98
103
|
if (!selected || this.failed.has(topic)) continue;
|
|
99
104
|
const previous = next.states[topic];
|
|
100
105
|
const moduleInput: ReminderInput = {
|
|
101
|
-
scope: input.epoch.scope, frame, gameState: game,
|
|
106
|
+
scope: input.epoch.scope, frame, gameState: game, taskChanges, boundary,
|
|
102
107
|
facts: facts.map(e => ({ eventId: e.eventId, epochId: e.epochSeq, type: e.type,
|
|
103
108
|
occurredAt: e.occurredAt, producer: e.producer, payload: e.payload })),
|
|
104
109
|
config: selected.reminder!.config ?? {}, state: previous?.provider === selected.id ? previous.value : undefined,
|
|
@@ -107,26 +112,30 @@ export class ClawclawReminderPlugin implements RuntimeEpochPlugin<Record<string,
|
|
|
107
112
|
try {
|
|
108
113
|
const result: ReminderResult = await this.runners.get(topic)!.update(moduleInput);
|
|
109
114
|
if (!result || typeof result !== 'object' || Array.isArray(result)
|
|
110
|
-
|| Object.keys(result).some(k => !['state', '
|
|
111
|
-
|| (result.
|
|
115
|
+
|| Object.keys(result).some(k => !['state', 'events'].includes(k))
|
|
116
|
+
|| (result.events !== undefined && !Array.isArray(result.events))
|
|
112
117
|
|| Buffer.byteLength(JSON.stringify(result)) > 1024 * 1024) throw new Error('Invalid reminder output.');
|
|
113
|
-
const accepted:
|
|
114
|
-
const
|
|
115
|
-
for (const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
||
|
|
119
|
-
|
|
118
|
+
const accepted: RuntimeEventProposal[] = [];
|
|
119
|
+
const keys = new Set<string>();
|
|
120
|
+
for (const event of result.events ?? []) {
|
|
121
|
+
if (!event || event.type !== 'reminder.task' || typeof event.key !== 'string'
|
|
122
|
+
|| !event.key.trim() || event.key.length > 512 || keys.has(event.key)
|
|
123
|
+
|| typeof event.wakeAgent !== 'boolean' || !event.payload || Array.isArray(event.payload)
|
|
124
|
+
|| typeof event.payload.text !== 'string' || !event.payload.text.trim()) {
|
|
125
|
+
throw new Error('Invalid task reminder event.');
|
|
120
126
|
}
|
|
121
|
-
|
|
122
|
-
accepted.push({
|
|
127
|
+
keys.add(event.key);
|
|
128
|
+
accepted.push({ type: event.type, dedupeKey: JSON.stringify([selected.id, event.key]),
|
|
129
|
+
dedupeScope: 'segment', wakeAgent: event.wakeAgent, payload: { ...event.payload },
|
|
130
|
+
occurredAt: new Date(moduleInput.nowMs).toISOString() });
|
|
123
131
|
}
|
|
124
|
-
|
|
132
|
+
// Recovery/initial snapshots establish private state, never replay notices.
|
|
133
|
+
if (!boundary && game) events.push(...accepted);
|
|
125
134
|
next.states[topic] = { provider: selected.id, value: structuredClone(result.state) };
|
|
126
135
|
} catch (error) { this.markFailed(topic, context, error); }
|
|
127
136
|
}
|
|
128
137
|
this.checkpoint = next;
|
|
129
|
-
return { outcome: 'processed',
|
|
138
|
+
return { outcome: 'processed', events, checkpoint: next,
|
|
130
139
|
...(input.pendingEvents.length ? { consumeEventsThroughCommitSeq: input.pendingEvents.at(-1)!.commitSeq } : {}) };
|
|
131
140
|
}
|
|
132
141
|
private markFailed(topic: ReminderTopic, context: RuntimeEpochPluginContext<Record<string, any>>, error: unknown): void {
|
|
@@ -1537,32 +1537,8 @@ implements RuntimeSourcePlugin<Record<string, any>, Record<string, unknown>> {
|
|
|
1537
1537
|
selfName: this.profile.agentName,
|
|
1538
1538
|
allowUntickedInitialRole: frame.meta.origin === 'update',
|
|
1539
1539
|
});
|
|
1540
|
-
let taskPayloadAttached = false;
|
|
1541
1540
|
const backendEvents = this.sourceEvents(
|
|
1542
|
-
frame.events,
|
|
1543
|
-
frame.meta,
|
|
1544
|
-
CLAWCLAW_GAME_WS_SOURCE.sourceId,
|
|
1545
|
-
(event, sourceEventIndex) => {
|
|
1546
|
-
if (
|
|
1547
|
-
!taskUpdate.payload
|
|
1548
|
-
|| taskPayloadAttached
|
|
1549
|
-
|| sourceEventIndex !== taskUpdate.attachToEventIndex
|
|
1550
|
-
) return event;
|
|
1551
|
-
taskPayloadAttached = true;
|
|
1552
|
-
const clonedTaskPayload = structuredClone(taskUpdate.payload);
|
|
1553
|
-
const { reason: _taskReason, ...taskPayloadWithoutReason } = clonedTaskPayload;
|
|
1554
|
-
const taskPayload = event.payload.reason === undefined
|
|
1555
|
-
? clonedTaskPayload
|
|
1556
|
-
: taskPayloadWithoutReason;
|
|
1557
|
-
return {
|
|
1558
|
-
...event,
|
|
1559
|
-
payload: {
|
|
1560
|
-
...event.payload,
|
|
1561
|
-
...taskPayload,
|
|
1562
|
-
},
|
|
1563
|
-
};
|
|
1564
|
-
},
|
|
1565
|
-
gameState,
|
|
1541
|
+
frame.events, frame.meta, CLAWCLAW_GAME_WS_SOURCE.sourceId, undefined, gameState,
|
|
1566
1542
|
);
|
|
1567
1543
|
const recoveryIdentity = `${frame.meta.gameId}:${String(frame.meta.sourceSeq)}:${frame.meta.connectionId}`;
|
|
1568
1544
|
const recoveryEvents = frame.meta.origin === 'resume' || frame.meta.snapshotFallback
|
|
@@ -1590,7 +1566,7 @@ implements RuntimeSourcePlugin<Record<string, any>, Record<string, unknown>> {
|
|
|
1590
1566
|
`${frame.meta.gameId}:${String(frame.meta.sourceSeq)}`,
|
|
1591
1567
|
)]
|
|
1592
1568
|
: []),
|
|
1593
|
-
...(taskUpdate.payload
|
|
1569
|
+
...(taskUpdate.payload
|
|
1594
1570
|
? [this.tasksChangedEvent(
|
|
1595
1571
|
taskUpdate.payload,
|
|
1596
1572
|
frame.meta.receivedAt,
|
|
@@ -13,11 +13,13 @@ export interface TaskSnapshot extends Record<string, unknown> {
|
|
|
13
13
|
export interface TaskChangeDetail extends Record<string, unknown> {
|
|
14
14
|
change: 'added' | 'removed' | 'status_changed' | 'updated';
|
|
15
15
|
task: TaskSnapshot;
|
|
16
|
+
before?: TaskSnapshot;
|
|
16
17
|
from_status?: string;
|
|
17
18
|
to_status?: string;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
export interface TasksChangedPayload extends Record<string, unknown> {
|
|
22
|
+
baseline: boolean;
|
|
21
23
|
tick?: number;
|
|
22
24
|
reason:
|
|
23
25
|
| 'role_assigned'
|
|
@@ -38,7 +40,6 @@ export interface TaskProjectionUpdate {
|
|
|
38
40
|
projection: TaskSnapshot[];
|
|
39
41
|
initialized: boolean;
|
|
40
42
|
payload: TasksChangedPayload | null;
|
|
41
|
-
attachToEventIndex?: number;
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
function record(value: unknown): Record<string, any> | null {
|
|
@@ -121,6 +122,7 @@ function taskDelta(
|
|
|
121
122
|
if (before.status !== task.status) {
|
|
122
123
|
delta.push({
|
|
123
124
|
change: 'status_changed',
|
|
125
|
+
before: structuredClone(before),
|
|
124
126
|
task: structuredClone(task),
|
|
125
127
|
...(before.status === undefined ? {} : { from_status: before.status }),
|
|
126
128
|
...(task.status === undefined ? {} : { to_status: task.status }),
|
|
@@ -128,7 +130,7 @@ function taskDelta(
|
|
|
128
130
|
continue;
|
|
129
131
|
}
|
|
130
132
|
if (!sameTask(before, task)) {
|
|
131
|
-
delta.push({ change: 'updated', task: structuredClone(task) });
|
|
133
|
+
delta.push({ change: 'updated', task: structuredClone(task), before: structuredClone(before) });
|
|
132
134
|
}
|
|
133
135
|
}
|
|
134
136
|
return delta;
|
|
@@ -166,7 +168,7 @@ function updateReason(
|
|
|
166
168
|
selfSeat: number | undefined,
|
|
167
169
|
currentTick: number | undefined,
|
|
168
170
|
allowUntickedInitialRole: boolean,
|
|
169
|
-
): Pick<TasksChangedPayload, 'reason'>
|
|
171
|
+
): Pick<TasksChangedPayload, 'reason'> {
|
|
170
172
|
const roleIndex = findLastEventIndex(events, (event) => event.type === 'role_assigned');
|
|
171
173
|
const roleTick = roleIndex >= 0 ? finiteNumber(events[roleIndex]?.tick) : undefined;
|
|
172
174
|
const currentRole = roleIndex >= 0 && (
|
|
@@ -174,7 +176,7 @@ function updateReason(
|
|
|
174
176
|
|| (roleTick === undefined && allowUntickedInitialRole)
|
|
175
177
|
);
|
|
176
178
|
if (currentRole) {
|
|
177
|
-
return { reason: 'role_assigned'
|
|
179
|
+
return { reason: 'role_assigned' };
|
|
178
180
|
}
|
|
179
181
|
// A first snapshot may replay historical task Events. Its current list is
|
|
180
182
|
// an initialization fact, not the after-state of any one historical Event.
|
|
@@ -196,7 +198,7 @@ function updateReason(
|
|
|
196
198
|
const reason = visible.event.type === 'meeting_briefing'
|
|
197
199
|
? 'meeting_started'
|
|
198
200
|
: visible.event.type as TasksChangedPayload['reason'];
|
|
199
|
-
return { reason
|
|
201
|
+
return { reason };
|
|
200
202
|
}
|
|
201
203
|
if (events.some((event) => (
|
|
202
204
|
event.type === 'task_assigned' && actorMatches(event, selfName, selfSeat)
|
|
@@ -206,8 +208,8 @@ function updateReason(
|
|
|
206
208
|
|
|
207
209
|
/**
|
|
208
210
|
* Diff the authoritative task list carried by one complete GameSync State.
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
+
* Source emits a private tasks_changed input, separate from backend facts.
|
|
212
|
+
* Reminder scripts own Agent-facing task notifications.
|
|
211
213
|
*/
|
|
212
214
|
export function nextTaskProjection(input: {
|
|
213
215
|
previous: readonly TaskSnapshot[];
|
|
@@ -247,13 +249,11 @@ export function nextTaskProjection(input: {
|
|
|
247
249
|
projection: current,
|
|
248
250
|
initialized: true,
|
|
249
251
|
payload: {
|
|
252
|
+
baseline: !input.initialized,
|
|
250
253
|
...(tick === undefined ? {} : { tick }),
|
|
251
254
|
reason: reason.reason,
|
|
252
255
|
delta,
|
|
253
256
|
tasks: current.map((task) => structuredClone(task)),
|
|
254
257
|
},
|
|
255
|
-
...(reason.attachToEventIndex === undefined
|
|
256
|
-
? {}
|
|
257
|
-
: { attachToEventIndex: reason.attachToEventIndex }),
|
|
258
258
|
};
|
|
259
259
|
}
|
|
@@ -46,7 +46,6 @@ export type ClawclawRuntimeOptions = Omit<
|
|
|
46
46
|
durableStateSnapshot?: AtomicJsonAgentStateSnapshotStore<Record<string, any>> | false;
|
|
47
47
|
/** Frozen delivery policy for visual Events produced by Perception. */
|
|
48
48
|
visualEventDelivery?: ClawclawVisualEventDelivery;
|
|
49
|
-
reminderDelivery?: boolean;
|
|
50
49
|
/** Visual Event types declared by the selected perception modules. */
|
|
51
50
|
visualEventTypes?: readonly string[];
|
|
52
51
|
/** Event types declared by enabled Intent and Strategy modules at startup. */
|
|
@@ -96,7 +95,6 @@ export function createClawclawRuntime(
|
|
|
96
95
|
stateFreshnessPolicy: configuredFreshness = {},
|
|
97
96
|
stateFreshnessPolicyResolver: configuredResolver,
|
|
98
97
|
visualEventDelivery,
|
|
99
|
-
reminderDelivery,
|
|
100
98
|
visualEventTypes,
|
|
101
99
|
behaviorEventTypes,
|
|
102
100
|
...runtimeOptions
|
|
@@ -145,7 +143,6 @@ export function createClawclawRuntime(
|
|
|
145
143
|
accountId: getRuntimeAccountId(profile),
|
|
146
144
|
eventCatalog: createClawclawEventCatalog({
|
|
147
145
|
visualEventDelivery,
|
|
148
|
-
reminderDelivery,
|
|
149
146
|
visualEventTypes,
|
|
150
147
|
behaviorEventTypes,
|
|
151
148
|
}),
|
|
@@ -30,8 +30,6 @@ export type ClawclawVisualEventDelivery = EventDeliveryClass
|
|
|
30
30
|
| Readonly<Partial<Record<string, EventDeliveryClass>>>;
|
|
31
31
|
|
|
32
32
|
export interface ClawclawEventCatalogOptions {
|
|
33
|
-
/** Task changes start hidden until their ordered reminder rule resolves delivery. */
|
|
34
|
-
reminderDelivery?: boolean;
|
|
35
33
|
/** Defaults to monitor_and_events so visual facts wake the default Agent surface. */
|
|
36
34
|
visualEventDelivery?: ClawclawVisualEventDelivery;
|
|
37
35
|
/** Additional visual Event types declared by selected user perception modules. */
|
|
@@ -103,9 +101,6 @@ export const CLAWCLAW_BACKEND_AGENT_EVENT_TYPES = [
|
|
|
103
101
|
'killed',
|
|
104
102
|
'murder_witnessed',
|
|
105
103
|
'warrior_shrimp_self_destruct',
|
|
106
|
-
'task_completed',
|
|
107
|
-
'task_interrupted',
|
|
108
|
-
'task_sabotaged',
|
|
109
104
|
'body_dropped',
|
|
110
105
|
'corpse_spotted',
|
|
111
106
|
'octopus_time_start',
|
|
@@ -185,7 +180,7 @@ export const CLAWCLAW_LOCAL_AGENT_EVENT_TYPES = [
|
|
|
185
180
|
'behavior.cancelled',
|
|
186
181
|
'behavior.replaced',
|
|
187
182
|
'players_changed',
|
|
188
|
-
'
|
|
183
|
+
'reminder.task',
|
|
189
184
|
'emergency_countdown_warning',
|
|
190
185
|
'ability.ready',
|
|
191
186
|
'ability.remaining_uses_changed',
|
|
@@ -194,6 +189,9 @@ export const CLAWCLAW_LOCAL_AGENT_EVENT_TYPES = [
|
|
|
194
189
|
|
|
195
190
|
/** Durable inputs used by projectors, but never sent directly to the Agent. */
|
|
196
191
|
export const CLAWCLAW_INTERNAL_BACKEND_EVENT_TYPES = [
|
|
192
|
+
'task_completed',
|
|
193
|
+
'task_interrupted',
|
|
194
|
+
'task_sabotaged',
|
|
197
195
|
'enter_room',
|
|
198
196
|
'move_start',
|
|
199
197
|
'move_end',
|
|
@@ -213,6 +211,7 @@ export const CLAWCLAW_INTERNAL_BACKEND_EVENT_TYPES = [
|
|
|
213
211
|
] as const;
|
|
214
212
|
|
|
215
213
|
export const CLAWCLAW_INTERNAL_LOCAL_EVENT_TYPES = [
|
|
214
|
+
'tasks_changed',
|
|
216
215
|
'meeting_state',
|
|
217
216
|
'runtime_started',
|
|
218
217
|
'runtime_stopped',
|
|
@@ -269,8 +268,7 @@ function entries(options: ClawclawEventCatalogOptions = {}): EventCatalogEntry[]
|
|
|
269
268
|
...CLAWCLAW_LOCAL_AGENT_EVENT_TYPES.map((type) => ({
|
|
270
269
|
type,
|
|
271
270
|
producer: 'local_synth' as const,
|
|
272
|
-
deliveryClass:
|
|
273
|
-
? 'internal_only' as const : 'monitor_and_events' as const,
|
|
271
|
+
deliveryClass: 'monitor_and_events' as const,
|
|
274
272
|
})),
|
|
275
273
|
...CLAWCLAW_INTERNAL_BACKEND_EVENT_TYPES.map((type) => ({
|
|
276
274
|
type,
|