@myclaw163/clawclaw-cli 0.10.14 → 0.10.16
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 +1 -1
- package/cli-runtime/commands/behavior.js +2 -2
- package/cli-runtime/commands/prepare.js +1 -0
- package/cli-runtime/runtime/clawclaw/behavior-reflex-control.js +24 -10
- package/cli-runtime/runtime/clawclaw/behavior-trigger.js +38 -0
- package/cli-runtime/runtime/clawclaw/owner.js +18 -5
- package/cli-runtime/runtime/clawclaw/plugins/assembly.js +8 -7
- package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-source.js +37 -15
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-plugin.js +5 -2
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-runner.js +2 -1
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-worker.js +7 -1
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-worker.ts +7 -1
- package/cli-runtime/runtime/clawclaw/plugins/trigger/trigger-plugin.js +32 -11
- package/cli-runtime/sdk/trigger-plugin/index.ts +7 -2
- package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/host.js +58 -0
- package/docs/custom-modules/README.md +8 -8
- package/docs/custom-modules/api-reference.md +9 -32
- package/docs/custom-modules/behavior.md +39 -56
- package/docs/custom-modules/examples/auto-escape.ts +26 -3
- package/docs/custom-modules/perception.md +7 -20
- package/docs/runtime/README.md +2 -2
- package/docs/runtime/agent-notifications.md +1 -1
- package/docs/runtime/behavior-runtime.md +10 -10
- package/docs/runtime/components-and-boundaries.md +8 -8
- package/docs/runtime/events-and-state.md +2 -2
- package/docs/runtime/owner-lifecycle-and-observability.md +2 -2
- package/docs/user-guide/README.md +7 -7
- package/docs/user-guide/api-reference.md +8 -31
- package/docs/user-guide/behavior.md +38 -55
- package/docs/user-guide/perception.md +7 -20
- package/package.json +1 -1
- package/skills/clawclaw/SKILL.md +5 -5
- package/skills/clawclaw/references/BEHAVIORS.md +5 -5
- package/skills/clawclaw/references/COMMANDS.md +2 -2
- package/skills/clawclaw/references/HUB.md +1 -1
- package/skills/clawclaw-creator/SKILL.md +3 -3
- package/skills/clawclaw-creator/references/CUSTOM-BEHAVIOR-DEVELOPMENT.md +39 -56
- package/skills/clawclaw-creator/references/CUSTOM-MODULE-API.md +9 -32
- package/skills/clawclaw-creator/references/CUSTOM-MODULES.md +8 -8
- package/skills/clawclaw-creator/references/CUSTOM-PERCEPTION-DEVELOPMENT.md +6 -19
- package/src/commands/behavior.ts +3 -3
- package/src/commands/prepare.ts +2 -0
- package/src/runtime/clawclaw/behavior-reflex-control.ts +27 -4
- package/src/runtime/clawclaw/behavior-trigger.ts +28 -0
- package/src/runtime/clawclaw/owner.ts +16 -5
- package/src/runtime/clawclaw/plugins/assembly.ts +11 -8
- package/src/runtime/clawclaw/plugins/behavior/behavior-source.ts +40 -14
- package/src/runtime/clawclaw/plugins/perception/perception-module-plugin.ts +6 -2
- package/src/runtime/clawclaw/plugins/perception/perception-module-runner.ts +2 -1
- package/src/runtime/clawclaw/plugins/perception/perception-module-worker.ts +7 -1
- package/src/runtime/clawclaw/plugins/perception/perception-source.ts +1 -0
- package/src/runtime/clawclaw/plugins/trigger/contracts.ts +1 -0
- package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.ts +33 -12
- package/src/sdk/trigger-plugin/index.ts +7 -2
- package/docs/custom-modules/examples/nearby-reflex.ts +0 -22
|
@@ -29,7 +29,7 @@ ccl hub sync <type>/<resource-id> --json
|
|
|
29
29
|
|
|
30
30
|
## 0.8.x Strategy
|
|
31
31
|
|
|
32
|
-
Hub 对外仍叫 Strategy,CCL 内部按 Strategy API v3 加载。一个 Hub Strategy 是一个顶层 `.ts` 或 `.js` 文件:默认导出一个 `ClawclawStrategy` 子类,`static manifest.apiVersion` 必须为 `3
|
|
32
|
+
Hub 对外仍叫 Strategy,CCL 内部按 Strategy API v3 加载。一个 Hub Strategy 是一个顶层 `.ts` 或 `.js` 文件:默认导出一个 `ClawclawStrategy` 子类,`static manifest.apiVersion` 必须为 `3`。反射策略可在同文件具名导出 `Trigger`,装配一次。多选表示多个 Strategy 可用;实际运行仍由 Agent 或默认 long 配置按 long/short/reflex 控制层启动。角色确定后默认 long 立即启动;缺失时只 warning 并 idle。
|
|
33
33
|
|
|
34
34
|
## Skill 更新
|
|
35
35
|
|
|
@@ -18,11 +18,11 @@ metadata:
|
|
|
18
18
|
| 用户需要 | 内容 | 按需阅读 |
|
|
19
19
|
|---|---|---|
|
|
20
20
|
| 持续行动、移动、任务或战斗决策 | 策略 | [模块边界](references/CUSTOM-MODULES.md)、[策略开发](references/CUSTOM-BEHAVIOR-DEVELOPMENT.md) |
|
|
21
|
-
|
|
|
21
|
+
| 观察、判断变化和提醒 | 感知 | [模块边界](references/CUSTOM-MODULES.md)、[感知开发](references/CUSTOM-PERCEPTION-DEVELOPMENT.md) |
|
|
22
22
|
| 教 Agent 分析、组织发言或执行一套流程 | Skill | [游戏 Skill](references/CUSTOM-SKILL-DEVELOPMENT.md) |
|
|
23
23
|
| 玩家声音、性格和表达风格 | 人设 | [人设 Markdown](references/CUSTOM-PERSONA-DEVELOPMENT.md) |
|
|
24
24
|
|
|
25
|
-
精确字段与签名查 [API 参考](references/CUSTOM-MODULE-API.md)
|
|
25
|
+
精确字段与签名查 [API 参考](references/CUSTOM-MODULE-API.md),不要一次加载所有教程。自动反射在同一个策略文件中添加继承 ClawclawPerception 的具名 Trigger,安装并启用一个 Strategy 资源。只需要修改当前局参数时,按现有模块的 manifest 使用 `ccl strategy update` / `ccl perception update`,不用新建源码。
|
|
26
26
|
|
|
27
27
|
## 2. 同步编辑基线,定位当前账号和原文件
|
|
28
28
|
|
|
@@ -55,7 +55,7 @@ metadata:
|
|
|
55
55
|
|
|
56
56
|
写好后运行 `ccl capability list` 发现资源,按本次写入路径找到准确 `selection_ref`。只操作本次任务的目标,不批量启用顺带发现的其他文件。
|
|
57
57
|
|
|
58
|
-
- **新建策略、感知、Skill:** 执行 `ccl capability equip <selection_ref>`。策略的选择器可能仍以 `behavior/` 开头,直接使用 CCL
|
|
58
|
+
- **新建策略、感知、Skill:** 执行 `ccl capability equip <selection_ref>`。策略的选择器可能仍以 `behavior/` 开头,直接使用 CCL 返回值。自动反射只需启用对应 Strategy,并通过 strategy status 核对监听。
|
|
59
59
|
- **新建人设:** 按 [人设流程](references/CUSTOM-PERSONA-DEVELOPMENT.md) 先保存为未启用状态,安装入库成功后问:“人设【名称】写好了,要现在就用吗?”提供“现在用”和“先保存,暂时不用”。用户选择现在用才执行 `ccl persona use`;尚未回答或选择暂时不用时,保留原人设。面向用户不讲 `selection_ref`、操作名后缀等内部细节。用户已经明确选择时不重复询问,单纯要求写人设不等于现在就用。
|
|
60
60
|
- **编辑已有内容:** 完成保存与安装,以编辑前 prepare 同步后的启用状态和人设选择为准;用户要求改好并使用、启用或切换时,显式执行对应 equip/use。不要重放旧本地选择来覆盖用户后来在 Hub 的改动,也不要把编辑自己正在使用的资源改成新建另一个资源。
|
|
61
61
|
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
策略读取当前玩家可获取的游戏状态、事件和只读查询,决定角色接下来做什么,并把动作请求交给 Runtime。Runtime 负责检查控制权和提交;动作是否真正完成,要从后续游戏状态或事件确认。
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
感知识别事实并组织通知。策略负责具体行动,附带 Trigger 时也能自动请求反射。所有输入都受当前玩家视角约束。
|
|
11
11
|
|
|
12
12
|
## 长期、短期和反射
|
|
13
13
|
|
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
|---|---|---|---|
|
|
18
18
|
| 长期 | `long` | 持续执行当前主要目标,例如做任务、巡逻 | Agent/用户主动启动、角色默认策略 |
|
|
19
19
|
| 短期 | `short` | 暂时完成一件有限工作,例如去指定地点 | Agent/用户主动启动、长期策略委派 |
|
|
20
|
-
| 反射 | `reflex` | 条件满足后优先执行即时反应,例如撤离 |
|
|
20
|
+
| 反射 | `reflex` | 条件满足后优先执行即时反应,例如撤离 | 策略内置 Trigger 请求 |
|
|
21
21
|
|
|
22
22
|
控制优先级固定为 **反射 > 短期 > 长期**。例如:长期做任务 → 短期报尸,暂停做任务 → 反射撤离,暂停报尸 → 撤离结束后恢复仍有效的报尸 → 报尸结束后再恢复长期任务。
|
|
23
23
|
|
|
24
|
-
手动命令 `ccl strategy start --layer` 只接受 long 和 short
|
|
24
|
+
手动命令 `ccl strategy start --layer` 只接受 long 和 short。反射由策略内置 Trigger 请求并由 Strategy 插件仲裁,见下文。
|
|
25
25
|
|
|
26
26
|
`long` 不要求永不结束,`short` 和 `reflex` 也不会自动知道业务目标何时完成。模块应在确认目标完成或失败后返回 `finish`;运行时限用于防止有限任务长期占用控制权。
|
|
27
27
|
|
|
@@ -99,25 +99,25 @@ export default class GoToPoint extends ClawclawStrategy<GoToPointInput> {
|
|
|
99
99
|
|
|
100
100
|
把 `finish` 去掉并在到达后继续选择新目标,同一个接口就可以实现长期巡逻。是否写 `finish` 是模块逻辑;本次 Activation 是 long 还是 short,则由启动入口决定。
|
|
101
101
|
|
|
102
|
-
##
|
|
102
|
+
## 单文件反射与局中控制
|
|
103
103
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
### 完整例子:独立撤离策略
|
|
107
|
-
|
|
108
|
-
下面是策略文件 `auto-escape.ts`,只负责前往指定位置:
|
|
104
|
+
运行对局的 CCL 需要 0.10.16 或更新版本,桌面端以实际使用的 CCL 版本为准。一个策略文件同时导出执行类和触发感知。默认导出的 `ClawclawStrategy` 在取得控制权后执行 `decide()`。具名导出的 `Trigger extends ClawclawPerception` 使用感知 API v3,在 `evaluate()` 中通过 `activations` 请求已声明的同文件策略绑定。示例在玩家进入指定范围时前往撤离点。
|
|
109
105
|
|
|
110
106
|
```ts
|
|
111
107
|
import {
|
|
112
108
|
ClawclawStrategy, type StrategyDecision, type StrategyInput, type ClawclawStrategyManifest,
|
|
113
109
|
} from '@myclaw163/clawclaw-cli/strategy-plugin';
|
|
114
110
|
|
|
111
|
+
import {
|
|
112
|
+
ClawclawPerception, type PerceptionModuleInput, type PerceptionModuleResult,
|
|
113
|
+
} from '@myclaw163/clawclaw-cli/perception-plugin';
|
|
114
|
+
|
|
115
115
|
type Parameters = {
|
|
116
116
|
readonly x: number;
|
|
117
117
|
readonly y: number;
|
|
118
118
|
};
|
|
119
119
|
|
|
120
|
-
/**
|
|
120
|
+
/** The strategy executes when it is granted control. */
|
|
121
121
|
export default class AutoEscape extends ClawclawStrategy<Parameters> {
|
|
122
122
|
static readonly manifest = {
|
|
123
123
|
apiVersion: 3,
|
|
@@ -125,8 +125,8 @@ export default class AutoEscape extends ClawclawStrategy<Parameters> {
|
|
|
125
125
|
description: '有人进入设定范围时,前往 Agent 指定的撤离点。靠近不等于对方有敌意。',
|
|
126
126
|
execution: 'serial',
|
|
127
127
|
inputs: [
|
|
128
|
-
{ id: 'x', type: 'number', description: '当前地图上可达的撤离点 X。',
|
|
129
|
-
{ id: 'y', type: 'number', description: '当前地图上可达的撤离点 Y。',
|
|
128
|
+
{ id: 'x', type: 'number', description: '当前地图上可达的撤离点 X。', default: 2708 },
|
|
129
|
+
{ id: 'y', type: 'number', description: '当前地图上可达的撤离点 Y。', default: 2320 },
|
|
130
130
|
],
|
|
131
131
|
runtime: { defaultMs: 10000 },
|
|
132
132
|
} as const satisfies ClawclawStrategyManifest;
|
|
@@ -149,71 +149,54 @@ export default class AutoEscape extends ClawclawStrategy<Parameters> {
|
|
|
149
149
|
return { status: { summary: '等待权威位置确认到达撤离点。', activity: 'moving' } };
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
对应感知文件 `nearby-reflex.ts` 使用统一 API v3,可同时发通知和请求固定反射:
|
|
155
|
-
|
|
156
|
-
```ts
|
|
157
|
-
import { ClawclawPerception, type PerceptionModuleInput, type PerceptionModuleResult } from '@myclaw163/clawclaw-cli/perception-plugin';
|
|
158
152
|
|
|
159
|
-
|
|
160
|
-
export default class NearbyReflex extends ClawclawPerception {
|
|
153
|
+
export class Trigger extends ClawclawPerception {
|
|
161
154
|
static readonly manifest = {
|
|
162
|
-
apiVersion: 3,
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
155
|
+
apiVersion: 3,
|
|
156
|
+
id: 'community.nearby',
|
|
157
|
+
description: '有玩家靠近时请求本策略撤离。',
|
|
158
|
+
inputs: [{ id: 'triggerDistance', type: 'number', description: '触发距离(像素)。', default: 160, min: 1, max: 1000 }],
|
|
159
|
+
strategies: { escape: { name: 'community.auto-escape', reflexPriority: 40, cooldownMs: 3000, rearm: 'after_clear', maxRuntimeMs: 10000 } },
|
|
167
160
|
} as const;
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
activations: nearby ? [{ strategy: 'escape', reason: 'player_nearby' }] : [] };
|
|
161
|
+
|
|
162
|
+
evaluate(input: Readonly<PerceptionModuleInput>): PerceptionModuleResult {
|
|
163
|
+
const players = input.frame?.observation.players ?? [];
|
|
164
|
+
const self = players.find(player => player.observer);
|
|
165
|
+
if (!self) return {};
|
|
166
|
+
const distance = Number(input.config.triggerDistance);
|
|
167
|
+
const nearby = players.some(player => !player.observer && Math.hypot(player.x - self.x, player.y - self.y) <= distance);
|
|
168
|
+
return { activations: nearby ? [{ strategy: 'escape', reason: 'player_nearby' }] : [] };
|
|
177
169
|
}
|
|
178
170
|
}
|
|
179
171
|
```
|
|
180
172
|
|
|
181
|
-
|
|
173
|
+
装配这个文件后运行 `ccl prepare --full`。新装配的源码从下次 Runtime 生效。当前局可以这样设置撤离坐标和触发距离。
|
|
182
174
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
ccl strategy update community.auto-escape --input '{"x":100,"y":200}'
|
|
187
|
-
ccl perception update community.nearby-reflex --input '{"triggerDistance":180}'
|
|
175
|
+
```sh
|
|
176
|
+
ccl strategy watch community.auto-escape --input '{"x":2708,"y":2320}'
|
|
177
|
+
ccl strategy update community.auto-escape --input '{"triggerDistance":180}'
|
|
188
178
|
ccl strategy status community.auto-escape
|
|
189
|
-
ccl perception status community.nearby-reflex
|
|
190
179
|
ccl strategy unwatch community.auto-escape
|
|
191
|
-
ccl strategy watch community.auto-escape
|
|
192
180
|
```
|
|
193
181
|
|
|
194
|
-
`
|
|
195
|
-
|
|
196
|
-
已启用的配套感知与策略在绑定可用时默认允许自动反射,无需先执行 `watch`。`watch` 用于恢复本局关闭的自动激活;`unwatch` 立即禁止后续自动激活,并取消这些绑定当前启动的 Reflex。**关闭后感知继续观察、保存记忆和通知 Agent,手动 long/short 继续可用。** 开启不要求提前提供由感知动态选择的目标;策略真正激活时仍校验完整输入。关闭再开启会重查条件,但保留未结束的冷却。
|
|
197
|
-
|
|
198
|
-
`strategy status [策略名]` 同时显示执行栈、本局参数和感知绑定的开关、可用性、优先级及冷却倒计时;`perception status [感知名]` 显示观察是否正常、参数和绑定。配套策略缺失或不可加载时只跳过该绑定,感知其他通知及健康绑定继续运行。
|
|
199
|
-
|
|
200
|
-
只更新某次执行使用 `strategy update <activation-id> --activation --input '<补丁JSON>'`。各执行层及暂停中的实例都支持改参,保留 Activation ID 和原截止时间,增加实例代际并重新创建执行实例;暂停实例保持暂停。旧计算不能继续提交动作,已提交给后端的动作无法撤回。`strategy cancel` 只取消一次执行,不关闭自动反射。
|
|
182
|
+
装配一个策略文件后,触发感知随对局运行,默认允许自动激活。`unwatch` 禁止自动激活并取消该绑定正在执行的反射,感知继续观察和保存状态。`watch` 恢复自动激活。
|
|
201
183
|
|
|
202
|
-
|
|
184
|
+
`strategy update` 按两个类各自声明的字段更新感知配置或策略输入。策略输入影响本策略当前执行及后续启动默认值。动态命中参数和显式启动参数覆盖本局默认值。只改一次执行时加 `--activation` 并指定 Activation ID。改参保留 Activation ID 和原截止时间,增加实例代际。暂停实例继续暂停。设置在换局或 Owner 退出时清空。
|
|
203
185
|
|
|
186
|
+
跨激活去重使用 `api.memory`。例如 Trigger 查 `handled:<尸体ID>`,追尸策略实际接手现场后再写。单次执行进度可以用实例字段。
|
|
204
187
|
|
|
205
188
|
## 抢占、恢复与结束
|
|
206
189
|
|
|
207
190
|
每层最多有一个激活中的策略;更高层拥有当前控制权:
|
|
208
191
|
|
|
209
192
|
- 新 short 暂停 long,并替换已有 short;新 long 替换已有 long。
|
|
210
|
-
- reflex 抢占 short 和 long
|
|
193
|
+
- reflex 抢占 short 和 long。同一 Trigger 的反射正在执行时不重复启动;不同反射请求只有优先级严格更高时才替换当前反射。
|
|
211
194
|
- reflex 结束后,仍有效的 short 优先恢复,其原始截止时间不会因暂停延长。没有 short 时,等待统一的 `idle_ms` 后交还 long。
|
|
212
195
|
- short 结束后,默认等待 500ms,再恢复 long;没有显式 long 时才启动角色默认策略。
|
|
213
196
|
- long 可通过 `delegate` 委派一个 short;恢复后首次实际决策会收到一次性的 `continuation.delegatedBehavior`。short/reflex 不递归委派。
|
|
214
197
|
- 恢复以最新状态和事件为准,不能假定从暂停处原封不动续跑。私有状态如何保留取决于执行模式,见文末高级说明。
|
|
215
198
|
|
|
216
|
-
暂停会阻止旧实例继续提交未经授权的后续动作,但不能撤回已经到达后端的动作。会议、死亡、终局和对局切换由 Runtime
|
|
199
|
+
暂停会阻止旧实例继续提交未经授权的后续动作,但不能撤回已经到达后端的动作。会议、死亡、终局和对局切换由 Runtime 统一处理,自动反射也遵守这些边界。
|
|
217
200
|
|
|
218
201
|
会议中仍可切换长期策略或修改默认兜底,执行继续遵守会议暂停规则。后端策略展示优先取当前执行;没有当前执行时,取选定的长期策略或有效兜底。上报沿用策略原有的 name/description,不添加暂停字段或“会议中暂停”文案。切换后立即刷新展示目标,无需等待新后端帧;失败按现有机制重试。没有可展示的策略时上报“无策略在运行”。展示上报不授予移动、击杀等行动权限。
|
|
219
202
|
|
|
@@ -345,7 +328,7 @@ Status 不会修改 `GameState`,也不是私有存储。自定义 Event 必须
|
|
|
345
328
|
|
|
346
329
|
本地创建的文件也是账号工作副本。按 [创作流程](../SKILL.md) 定位当前账号,写完并检查后用 `ccl capability list` 获取本次目标的 `selection_ref`,显式 `ccl capability equip <selection_ref>`,再用 `ccl prepare --full` 完成安装并核验,最后向用户汇报。发布到广场另行操作,见[本地编辑、安装与发布到广场](./CUSTOM-MODULES.md#本地编辑安装与发布到广场)。
|
|
347
330
|
|
|
348
|
-
Hub 的 `strategy` 资源使用此 Strategy API v3 合同。一个资源对应一个顶层 `.ts` 或 `.js` 入口文件;文件必须默认导出一个 `ClawclawStrategy`
|
|
331
|
+
Hub 的 `strategy` 资源使用此 Strategy API v3 合同。一个资源对应一个顶层 `.ts` 或 `.js` 入口文件;文件必须默认导出一个 `ClawclawStrategy` 子类,每个导出类各有自己的字面量 `static manifest`。本地 Runtime 虽可加载同目录依赖树,Hub 单文件资源不要使用相对源码依赖。多个已启用 Strategy 只是同时进入 Strategy 目录,不会改变 `reflex > short > long` 和同层单 Activation 规则。
|
|
349
332
|
|
|
350
333
|
把 `.ts` 或 `.js` 文件放在:
|
|
351
334
|
|
|
@@ -429,7 +412,7 @@ execution: 'serial'
|
|
|
429
412
|
|
|
430
413
|
### 感知与策略的局内共享记忆
|
|
431
414
|
|
|
432
|
-
需要跨激活、暂停恢复、改参或 Worker 重建保留的数据,使用 `api.memory
|
|
415
|
+
需要跨激活、暂停恢复、改参或 Worker 重建保留的数据,使用 `api.memory`。同一策略的所有执行实例共享;同一资源的 Trigger 和策略执行类也共享这份局内记忆。
|
|
433
416
|
|
|
434
417
|
```ts
|
|
435
418
|
const handled = await api.memory.get('handled:corpse-id');
|
|
@@ -437,7 +420,7 @@ await api.memory.set('handled:corpse-id', true);
|
|
|
437
420
|
await api.memory.delete('handled:corpse-id');
|
|
438
421
|
```
|
|
439
422
|
|
|
440
|
-
`get` 返回副本,缺失为 undefined;`set` 覆盖,`delete` 删除不存在的键也成功。什么时候写由模块决定,调用成功即生效,不等待 Decision
|
|
423
|
+
`get` 返回副本,缺失为 undefined;`set` 覆盖,`delete` 删除不存在的键也成功。什么时候写由模块决定,调用成功即生效,不等待 Decision 或动作确认,也不会随后续计算失败回滚。Trigger 在检测时读去重标记,追尸策略在实际接手现场后写入。改参、关闭或重新开启反射都保留这份记忆。
|
|
441
424
|
|
|
442
425
|
记忆按当前 Owner、session、segment 和实际策略操作名隔离。跨回调、激活、Worker、改参和 watch/unwatch 保留;换局、game_over、Owner 退出清空,不跨进程恢复。旧回调或已结束作用域拒绝新访问。只接受有界 JSON 值:每命名空间最多 256 键、64 KiB,单键最多 256 UTF-8 字节,深度最多 32;不是权威 State 或 Agent 跨局 memory 文件。
|
|
443
426
|
|
|
@@ -469,5 +452,5 @@ if (input.cycle && !input.cycle.hasNewState && input.events.length === 0) {
|
|
|
469
452
|
## 继续阅读
|
|
470
453
|
|
|
471
454
|
- [感知总览](./CUSTOM-PERCEPTION-DEVELOPMENT.md)
|
|
472
|
-
- [
|
|
455
|
+
- [单文件反射与局中控制](./CUSTOM-BEHAVIOR-DEVELOPMENT.md#单文件反射与局中控制)
|
|
473
456
|
- [API 参考](./CUSTOM-MODULE-API.md)
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
| 模块 | Runtime 主动输入 | 查询与私有能力 | 允许输出 |
|
|
12
12
|
|---|---|---|---|
|
|
13
13
|
| Strategy | 当前 `GameState`、待处理 Event、Activation 参数 | 地图、路径距离、最近观察、api.memory | Action、Status、自定义 Event、结束结果 |
|
|
14
|
-
| 统一感知 API v3 | State、观察帧、源/后端原始事件、任务变化、参数和私有状态 | api.spatial、api.memory |
|
|
14
|
+
| 统一感知 API v3 | State、观察帧、源/后端原始事件、任务变化、参数和私有状态 | api.spatial、api.memory | 事件、私有状态 |
|
|
15
15
|
|
|
16
16
|
游戏输入和查询结果都是当前回调内的只读值;api.memory 则是显式读写的策略私有数据。任何模块都不能直接修改权威 `GameState`。
|
|
17
17
|
|
|
@@ -95,7 +95,7 @@ const maySelect = candidates[0] && isTaskAvailable(input.gameState, candidates[0
|
|
|
95
95
|
|
|
96
96
|
从公开 perception-plugin 入口导入 ClawclawPerception、PerceptionModuleInput、PerceptionModuleResult、PerceptionModuleEvent 和 PerceptionModuleManifest;版本常量为 PERCEPTION_MODULE_API_VERSION=3。新脚本没有三选一的 kind,通过同一个 evaluate(input, api) 组合观察、通知和私有记忆。
|
|
97
97
|
|
|
98
|
-
Manifest 的必需项为 apiVersion:3、id、description;可选 name、localizations、consumes、produces、inputs、config、strategies。输入包含 moduleId、scope、gameState、frame、events、taskChanges、boundary、lifecycle、source、roomState、queueState、eventStates、nowMs、cycle、config、state
|
|
98
|
+
Manifest 的必需项为 apiVersion:3、id、description;可选 name、localizations、consumes、produces、inputs、config、strategies。输入包含 moduleId、scope、gameState、frame、events、taskChanges、boundary、lifecycle、source、roomState、queueState、eventStates、nowMs、cycle、config、state。frame/gameState 可以为 null;events 只含订阅的源/后端原始事实,taskChanges 由该模块自己的基线与本轮权威任务列表比较得到,结合同轮后端事实;不是订阅 tasks_changed。 内置任务感知及 evaluateReminder('tasks') 只把后端 task_* 事实转为基础任务通知,不按 taskChanges 再输出同一信息;紧急生命周期和阈值由内置紧急感知负责。
|
|
99
99
|
|
|
100
100
|
阶段变化不清空 state。`enteredPhase` / `leftPhase` 匹配本轮实际阶段转换,`hasPerceptionBoundary` 检查 initial、recovery 等边界;`resetPerceptionState(state, patch)` 纯函数式替换指定字段,原状态与 api.memory 不受影响。恢复不伪造阶段转换。API 还提供只读 `api.spatial`。事件可带 `occurredAt` 保留观察发生时间;`forwards` 只能由宿主授予转发权限的原生模块使用。
|
|
101
101
|
|
|
@@ -104,7 +104,7 @@ Manifest 的必需项为 apiVersion:3、id、description;可选 name、localiz
|
|
|
104
104
|
|
|
105
105
|
每次计算使用 fresh 实例,跨回调状态必须从 input.state 读取并作为结果 state 返回,由 Host 检查点恢复。新脚本不能订阅其他感知、Strategy 或 decision 输出;运行时还按 producerPluginId 过滤,只接纳 Source/后端原始事实。produces 不能冒充系统保留类型;reminder.task/reminder.speech 是兼容通知输出,不是权威任务事实。
|
|
106
106
|
|
|
107
|
-
|
|
107
|
+
策略文件中的具名触发感知通过 activations 请求同文件策略的 Reflex。
|
|
108
108
|
|
|
109
109
|
## Strategy API
|
|
110
110
|
|
|
@@ -683,40 +683,17 @@ import type {
|
|
|
683
683
|
- 查询 API 只在当前回调活动期间有效,不要保存后延迟调用;
|
|
684
684
|
- 自定义模块是本机可信代码,不是安全沙箱,只安装可信来源。
|
|
685
685
|
|
|
686
|
-
##
|
|
686
|
+
## 策略内置触发感知
|
|
687
687
|
|
|
688
|
-
|
|
688
|
+
CCL 0.10.16 起,策略文件可以具名导出继承 `ClawclawPerception` 的 `Trigger`。使用 `@myclaw163/clawclaw-cli/perception-plugin` 的感知 API v3。`Trigger.manifest` 和普通感知一样声明 `id`、`description`,在 `strategies` 里给本文件默认策略的声明 ID 配置固定绑定。绑定可以指定 `reflexPriority`、`cooldownMs`、`rearm` 和 `maxRuntimeMs`。
|
|
689
689
|
|
|
690
|
-
|
|
691
|
-
strategies: {
|
|
692
|
-
escape: { name: 'community.auto-escape', resourceId: '可选资源ID', layer: 'reflex',
|
|
693
|
-
input: {}, reflexPriority: 40, cooldownMs: 3000, rearm: 'after_clear', maxRuntimeMs: 10000 }
|
|
694
|
-
}
|
|
695
|
-
// evaluate 返回:
|
|
696
|
-
{ state, events, activations: [{ strategy: 'escape', input: {}, reason: 'player_nearby' }] }
|
|
697
|
-
```
|
|
698
|
-
|
|
699
|
-
binding 键必须为合法 ID,最多 16 项。name 必需;resourceId 优先于同名/同源别名匹配。layer 只允许 reflex。reflexPriority 是 -1000000..1000000 的整数;cooldownMs 为 0..86400000;maxRuntimeMs 为 1..120000。rearm 为 after_clear(默认)或 after_cooldown;优先级默认 0、冷却默认 1000ms、最长默认 10000ms。激活 input 覆盖绑定 input,再覆盖本局策略默认参数。未知绑定、重复绑定或非法输出被拒绝。
|
|
700
|
-
|
|
701
|
-
输入 availableBindings/availableStrategies 是实际可用依赖;enabledBindings 是其中当前允许自动激活的绑定。缺失或损坏策略只跳过对应绑定,感知其他通知与健康绑定继续运行。感知同时可发自己的通知,不直接执行 Action。
|
|
702
|
-
|
|
703
|
-
```powershell
|
|
704
|
-
ccl strategy update community.auto-escape --input '{"x":100,"y":200}'
|
|
705
|
-
ccl perception update community.nearby-reflex --input '{"triggerDistance":180}'
|
|
706
|
-
ccl strategy status community.auto-escape
|
|
707
|
-
ccl perception status community.nearby-reflex
|
|
708
|
-
ccl strategy unwatch community.auto-escape
|
|
709
|
-
ccl strategy watch community.auto-escape
|
|
710
|
-
```
|
|
711
|
-
|
|
712
|
-
strategy update 更新全部当前实例及后续启动默认值;显式补丁保留未修改的动态目标。可选 --activation 只改指定激活。保留 ID/截止时间,增加实例代际,暂停实例保持暂停。perception update 只更新判断参数,不清记忆。有效的已启用绑定默认开启;watch/unwatch 只用于局中恢复/关闭自动激活;unwatch 取消关联 Reflex,感知继续观察、记忆和通知。cancel 只取消一次执行。status 返回执行栈、parameters、watches(perception_id/binding/available/reason/enabled/active/priority/armed/cooldown_remaining_ms);perception status 返回观察健康、配置和绑定。
|
|
713
|
-
|
|
714
|
-
设置本局有效,不写 Hub 或 gameplay.json;换局与 Owner 重启恢复默认值及默认开启状态。开启只要求两个资源已安装并启用,不提前校验尚由感知动态选择的目标;激活时校验完整输入。
|
|
690
|
+
`evaluate(input, api)` 接收 `PerceptionModuleInput`,通过 `input.frame`、`input.events`、`input.config` 和 `input.state` 读取观察、事实、配置和上次返回的私有状态。返回 `PerceptionModuleResult`,可含 `state`、`events` 和 `activations`。例如 `{ activations: [{ strategy: 'escape', input: { x: 2708, y: 2320 }, reason: 'player_nearby' }] }` 使用清单里的 `escape` 绑定,激活参数覆盖策略默认值。
|
|
715
691
|
|
|
692
|
+
跨帧判断保存在返回的 `state` 中。触发感知与执行类需要共享的局内记录使用 `api.memory`。例如触发感知按尸体 ID 查询,执行类接手后记录,避免一次未获准的请求占用现场。
|
|
716
693
|
|
|
717
694
|
### api.memory:局内持续记忆
|
|
718
695
|
|
|
719
|
-
StrategyReadApi 和 PerceptionModuleApi
|
|
696
|
+
StrategyReadApi 和 PerceptionModuleApi 均提供以下接口。
|
|
720
697
|
|
|
721
698
|
```ts
|
|
722
699
|
type StrategyMemoryValue = null | boolean | number | string
|
|
@@ -734,7 +711,7 @@ await api.memory.delete('handled:corpse-id');
|
|
|
734
711
|
|
|
735
712
|
get 读取当前值并返回副本,缺失为 undefined;set 覆盖一个键,delete 删除一个键,删除不存在的键成功。调用成功即生效,不需要在 Decision 中返回 memory 字段,也不等待动作确认;后续 Decision 失败不会回滚已成功写入。模块仍须通过权威 State/Event 判断业务结果。回调失效后新的访问会拒绝,但不会撤回此前有效调用完成的写入。
|
|
736
713
|
|
|
737
|
-
|
|
714
|
+
同一策略资源的 Trigger 和执行类共享局内记录。同一策略的不同执行层、激活和 Worker 也共享。宿主按实际操作名隔离不同策略、重名别名、账号和 Owner。
|
|
738
715
|
|
|
739
716
|
生命周期:跨回调、暂停恢复、实例更换、改参、完成重启及 watch/unwatch 保留;新游戏、game_over 或 Owner 退出清空。仅保存在当前进程内存中,不落盘或恢复旧检查点。它与感知私有 state、并行实例 snapshot 和 Agent 跨局 memory 文件是不同数据。
|
|
740
717
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
CCL 内置玩家、任务、能力、紧急任务、房间与流程、会议、策略消息七类感知,强制启用且不可配置;Hub/社区模块另外安装并启用。自定义感知只读 Source/后端原始事实和状态,各感知互不依赖。策略事件由内置感知在后续轮次转发。
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
感知使用统一 Perception API v3
|
|
6
|
+
感知使用统一 Perception API v3,持续观察、记忆和通知。感知和策略分别安装、分别启用,由 Strategy 插件仲裁并执行。
|
|
7
7
|
|
|
8
8
|
内置任务提醒始终启用;社区脚本可追加自己的提醒,不能关闭内置通知。固定倒计时和能力通知由相应内置感知负责,见[自定义局内提醒感知](./CUSTOM-PERCEPTION-DEVELOPMENT.md#内置感知与自定义感知)。感知使用统一 API v3,自定义模块提供职责不同的判断。
|
|
9
9
|
|
|
@@ -14,7 +14,7 @@ CCL 内置玩家、任务、能力、紧急任务、房间与流程、会议、
|
|
|
14
14
|
|
|
15
15
|
| 资源 | 用途 | 代码入口 |
|
|
16
16
|
|---|---|---|
|
|
17
|
-
| 策略 |
|
|
17
|
+
| 策略 | 决定并请求具体动作,条件满足时由同文件 Trigger 请求自动反射 | 默认导出 `ClawclawStrategy` |
|
|
18
18
|
| 感知 | 组合观察、提醒和通知控制 | `ClawclawPerception.evaluate(input)`,API v3 |
|
|
19
19
|
|
|
20
20
|
统一感知共用同一输入输出,一个脚本可组合多种能力。策略的 long、short、reflex 仍是同一模块的三种运行方式。
|
|
@@ -49,10 +49,10 @@ ccl perception --list
|
|
|
49
49
|
- 控制角色行动、理解反射与抢占:[策略教程](./CUSTOM-BEHAVIOR-DEVELOPMENT.md)
|
|
50
50
|
- 先确定需要哪类感知:[感知开发总览](./CUSTOM-PERCEPTION-DEVELOPMENT.md)
|
|
51
51
|
- 配置任务和附近发言提醒:[提醒型感知](./CUSTOM-PERCEPTION-DEVELOPMENT.md#内置感知与自定义感知)
|
|
52
|
-
-
|
|
52
|
+
- 条件满足后自动行动:策略教程的“单文件反射与局中控制”。
|
|
53
53
|
- 查询准确字段和签名:[API 参考](./CUSTOM-MODULE-API.md)
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
首次编写感知,先看开头的统一通知接口,再照首次目击示例理解写法;安装、通知控制与记忆在同一文档中说明。策略教程解释动作、结束和控制权交还。
|
|
56
56
|
|
|
57
57
|
## 感知与策略怎样配合
|
|
58
58
|
|
|
@@ -61,11 +61,11 @@ flowchart LR
|
|
|
61
61
|
Input["当前 State / 可见观察 / 源与后端原始事实"] --> Perception["统一感知 API v3"]
|
|
62
62
|
Perception --> Events["提交自己的事件"]
|
|
63
63
|
Events --> Mailbox["Mailbox / Agent"]
|
|
64
|
-
Perception -->|"
|
|
64
|
+
Perception -->|"请求所属策略"| Strategy["策略执行类"]
|
|
65
65
|
Strategy --> Runtime["Runtime 检查并提交动作"]
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
新感知只读取源与后端原始事实,不依赖其他感知或策略输出。感知独立决定自己的通知。策略负责行动,后续权威状态确认动作结果。
|
|
69
69
|
|
|
70
70
|
## 策略的三种运行方式
|
|
71
71
|
|
|
@@ -73,9 +73,9 @@ flowchart LR
|
|
|
73
73
|
|---|---|
|
|
74
74
|
| `long` | 持续执行主要目标,也用于角色默认策略 |
|
|
75
75
|
| `short` | 暂时完成一件有限工作 |
|
|
76
|
-
| `reflex` |
|
|
76
|
+
| `reflex` | 策略内置 Trigger 条件命中后请求优先执行即时反应 |
|
|
77
77
|
|
|
78
|
-
三层都使用 `ClawclawStrategy`,优先级为 `reflex > short > long`。手动启动支持 long/short
|
|
78
|
+
三层都使用 `ClawclawStrategy`,优先级为 `reflex > short > long`。手动启动支持 long/short,反射由策略内置 Trigger 请求,默认策略 fallback 是空栈时使用哪个 long 的配置。具体启动、暂停恢复与会议边界见[策略教程](./CUSTOM-BEHAVIOR-DEVELOPMENT.md#长期短期和反射)。
|
|
79
79
|
|
|
80
80
|
## 一个模块文件由什么组成
|
|
81
81
|
|
|
@@ -68,7 +68,7 @@ export default class FirstSighting extends ClawclawPerception {
|
|
|
68
68
|
| config / state | Manifest 参数与上一轮提交后的私有检查点 |
|
|
69
69
|
| availableStrategies | 当前可加载的策略操作名 |
|
|
70
70
|
|
|
71
|
-
结果可同时包含 `state`、`events`
|
|
71
|
+
结果可同时包含 `state`、`events` 和 `activations`,也可以只返回其中需要的部分。每次计算使用新实例,跨回调记忆用返回的 state,不能依赖实例字段。宿主只在更换对局/作用域时清空私有状态,不在进出会议时统一清空。阶段切换通过 lifecycle 传入,由脚本按需收尾观察片段、刷新部分字段并返回下一份 state。连接恢复保留检查点并显式标记 recovery,不伪造进入/离开会议,也不应重放旧通知。
|
|
72
72
|
|
|
73
73
|
Manifest 使用 `apiVersion: 3`、`id`、`description`,可声明 `consumes`、`produces`、`inputs`、`config` 、可选固定 `strategies` 绑定与本地化信息。不填写 kind。事件必须在 produces 中声明,并使用稳定的 key 和可序列化 payload;text 可用于直接表达通知。不能冒充击杀、能力就绪或策略生命周期等系统事实。
|
|
74
74
|
|
|
@@ -112,33 +112,20 @@ meeting_briefing 的 speech_order 完全由后端提供:无字段就不补;S
|
|
|
112
112
|
- 返回事件且 `wakeAgent: false`:保存为静默事件,等待后续唤醒时一并送达。
|
|
113
113
|
- 返回事件且 `wakeAgent: true` 或省略:允许按投递规则唤醒 Agent。
|
|
114
114
|
|
|
115
|
-
上述选择只控制该模块自己的输出,不能取消原始输入事实或其他模块的通知。感知不能返回 Action 或权威 State
|
|
115
|
+
上述选择只控制该模块自己的输出,不能取消原始输入事实或其他模块的通知。感知不能返回 Action 或权威 State 补丁。
|
|
116
116
|
|
|
117
117
|
## 输入与职责边界
|
|
118
118
|
|
|
119
|
-
API v3 模块只订阅 Source/后端原始事实;读取可见观察不需要等待其他感知。感知不消费其他感知或策略的输出。Runtime
|
|
119
|
+
API v3 模块只订阅 Source/后端原始事实;读取可见观察不需要等待其他感知。感知不消费其他感知或策略的输出。Runtime 还会按事件生产者隔离输入,不能通过改事件名称绕过。感知返回自己的通知和私有状态,不持有策略控制权。
|
|
120
120
|
|
|
121
121
|
|
|
122
122
|
感知与策略分别安装并启用。
|
|
123
123
|
|
|
124
|
-
##
|
|
124
|
+
## 局中修改感知参数
|
|
125
125
|
|
|
126
|
-
|
|
126
|
+
`ccl perception update <感知名> --input '<补丁JSON>' ` 更新当前局的观察和通知参数。`ccl perception status <感知名>` 查看当前参数和运行状态。
|
|
127
127
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
```powershell
|
|
131
|
-
ccl strategy update community.auto-escape --input '{"x":100,"y":200}'
|
|
132
|
-
ccl perception update community.nearby-reflex --input '{"triggerDistance":180}'
|
|
133
|
-
ccl strategy status community.auto-escape
|
|
134
|
-
ccl perception status community.nearby-reflex
|
|
135
|
-
ccl strategy unwatch community.auto-escape
|
|
136
|
-
ccl strategy watch community.auto-escape
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
`perception update` 更新判断参数,不清除 state 或 api.memory;`strategy update` 更新执行参数,不要求 watch。配套感知和策略安装并启用完成、绑定可用时,自动反射默认开启。`watch/unwatch` 用于局中恢复/关闭所有明确绑定它的感知的自动激活;**unwatch 不停止感知观察和通知,也不禁止它读写记忆**,只撤销关联 Reflex 并拦截后续请求。参数与开关本局有效,换局重置。`availableBindings`/`availableStrategies` 表示可用依赖;`enabledBindings` 进一步表示允许自动激活的绑定,感知可据此避免把关闭期间的命中当成已经执行。
|
|
140
|
-
|
|
141
|
-
`evaluate(input, api)` 的第二个参数提供只读地图查询 `api.spatial` 与 `api.memory.get/set/delete`。感知所有绑定都解析到同一个可用策略时,与其共享持续记忆;否则使用模块私有记忆。关闭自动反射、改参和 Worker 重建保留;换局、game_over、Owner 退出清空。input.state 则是每次结果返回的检查点;阶段变化不自动清理,脚本可以只刷新连续观察字段,保留跨会议知识。不要依赖实例字段或模块全局变量。
|
|
128
|
+
开发自动反射时,在策略文件中增加具名触发感知 Trigger。装配该策略后用 `ccl strategy` 修改触发参数、查看状态和开关。
|
|
142
129
|
|
|
143
130
|
## 编写规则
|
|
144
131
|
|
package/src/commands/behavior.ts
CHANGED
|
@@ -512,14 +512,14 @@ function createStrategyControlCommand(commandName: 'behavior' | 'strategy', depe
|
|
|
512
512
|
behavior.addCommand(fallback);
|
|
513
513
|
|
|
514
514
|
behavior.addCommand(new Command('watch')
|
|
515
|
-
.description('
|
|
515
|
+
.description('Enable automatic reflection for this strategy in the current game')
|
|
516
516
|
.argument('<id>', 'Equipped Behavior operation name')
|
|
517
|
-
.option('--input <json>', 'Optional
|
|
517
|
+
.option('--input <json>', 'Optional match-local strategy parameter patch', value => parseJsonObject(value), {})
|
|
518
518
|
.allowExcessArguments(false).action(async (id: string, opts: { input: Record<string, unknown> }) => {
|
|
519
519
|
await runOwnerCommand(`ccl ${commandName} watch`, 'behavior_watch', { behavior: id, input: opts.input }, true, dependencies);
|
|
520
520
|
}));
|
|
521
521
|
behavior.addCommand(new Command('unwatch')
|
|
522
|
-
.description('Block automatic activation and cancel associated Reflex
|
|
522
|
+
.description('Block automatic activation and cancel the associated Reflex')
|
|
523
523
|
.argument('<id>', 'Equipped Behavior operation name')
|
|
524
524
|
.allowExcessArguments(false).action(async (id: string) => {
|
|
525
525
|
await runOwnerCommand(`ccl ${commandName} unwatch`, 'behavior_unwatch', { behavior: id }, true, dependencies);
|
package/src/commands/prepare.ts
CHANGED
|
@@ -955,6 +955,8 @@ export function createPrepareCommand(dependencies: PrepareCommandDependencies =
|
|
|
955
955
|
description: source.description,
|
|
956
956
|
source: entry.source,
|
|
957
957
|
strategy_type: strategyLifecycle(source.sourcePath),
|
|
958
|
+
...(source.trigger ? { reflex: { available: true } }
|
|
959
|
+
: source.triggerError ? { reflex: { available: false, reason: source.triggerError } } : {}),
|
|
958
960
|
...(source.management.versionNumber ? { version_number: source.management.versionNumber,
|
|
959
961
|
version_description: source.management.versionDescription ?? '' } : {}),
|
|
960
962
|
};
|
|
@@ -2,6 +2,7 @@ import { normalizeBehaviorInput } from './behavior-input-fields.js';
|
|
|
2
2
|
import type { ClawclawBehaviorCatalog } from './plugins/behavior/behavior-catalog.js';
|
|
3
3
|
import type { ClawclawBehaviorPlugin } from './plugins/behavior/behavior-plugin.js';
|
|
4
4
|
import type { ClawclawPerceptionModulePlugin } from './plugins/perception/perception-module-plugin.js';
|
|
5
|
+
import type { ResolvedClawclawPerceptionSource } from './plugins/perception/perception-source.js';
|
|
5
6
|
|
|
6
7
|
type Scope = Readonly<{ sessionId: string; segmentId: string }>;
|
|
7
8
|
const same = (a: Scope, b: Scope) => a.sessionId === b.sessionId && a.segmentId === b.segmentId;
|
|
@@ -14,11 +15,14 @@ export class BehaviorReflexControl {
|
|
|
14
15
|
constructor(private readonly modules: ClawclawPerceptionModulePlugin | undefined,
|
|
15
16
|
private readonly behavior: Pick<ClawclawBehaviorPlugin, 'status' | 'updateReflex' | 'configureInput'>,
|
|
16
17
|
private readonly catalog: Pick<ClawclawBehaviorCatalog, 'list'>,
|
|
17
|
-
private readonly scope: () => Scope
|
|
18
|
+
private readonly scope: () => Scope,
|
|
19
|
+
private readonly embedded: readonly ResolvedClawclawPerceptionSource[] = []) {}
|
|
18
20
|
status(id?: string) {
|
|
19
21
|
this.refreshScope();
|
|
20
22
|
const active = this.behavior.status().stack.reflex;
|
|
21
23
|
return (this.modules?.bindings(id) ?? []).map(binding => ({ ...binding,
|
|
24
|
+
...(this.embedded.some(source => source.id === binding.perception_id)
|
|
25
|
+
? { source: 'strategy', behavior_id: binding.id, config: this.modules?.status(binding.perception_id)[0]?.input } : {}),
|
|
22
26
|
active: active?.triggerId === binding.trigger_id,
|
|
23
27
|
...(active?.triggerId === binding.trigger_id ? { activation_id: active.activationId,
|
|
24
28
|
instance_generation: active.instanceGeneration } : {}), scope: this.currentScope }));
|
|
@@ -51,9 +55,28 @@ export class BehaviorReflexControl {
|
|
|
51
55
|
let input = this.parameters.get(id) ?? {}, updated = 0;
|
|
52
56
|
// A detector may inject required targets later; enabling alone does not prepare a Behavior.
|
|
53
57
|
if (operation === 'update' || Object.keys(patch).length) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
const source = this.embedded.find(source => source.embedded?.strategyId === id);
|
|
59
|
+
const fields = source?.module?.inputs ?? [];
|
|
60
|
+
const detectorPatch: Record<string, unknown> = {};
|
|
61
|
+
const executionPatch: Record<string, unknown> = {};
|
|
62
|
+
for (const [key, value] of Object.entries(patch)) {
|
|
63
|
+
const observed = fields.some(field => field.id === key);
|
|
64
|
+
if (observed) detectorPatch[key] = value;
|
|
65
|
+
if (!observed || entry.inputs.some(field => field.id === key)) executionPatch[key] = value;
|
|
66
|
+
}
|
|
67
|
+
const configureDetector = () => {
|
|
68
|
+
if (source && Object.keys(detectorPatch).length) this.modules?.configure(source.id, detectorPatch, guard);
|
|
69
|
+
};
|
|
70
|
+
if (Object.keys(executionPatch).length || !Object.keys(detectorPatch).length) {
|
|
71
|
+
input = normalizeBehaviorInput({ ...input, ...executionPatch }, entry.inputs);
|
|
72
|
+
updated = await this.behavior.configureInput(id, input, executionPatch, guard, () => {
|
|
73
|
+
configureDetector();
|
|
74
|
+
this.parameters.set(id, input);
|
|
75
|
+
this.modules?.behaviorInputChanged(id);
|
|
76
|
+
});
|
|
77
|
+
} else {
|
|
78
|
+
configureDetector();
|
|
79
|
+
}
|
|
57
80
|
}
|
|
58
81
|
if (operation !== 'update') {
|
|
59
82
|
const triggerIds = this.modules?.setWatch(id,operation === 'enable',guard);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { normalizePerceptionModuleManifest } from './perception-module-manifest.js';
|
|
2
|
+
import type { ResolvedClawclawBehaviorSource } from './plugins/behavior/behavior-source.js';
|
|
3
|
+
import type { ResolvedClawclawPerceptionSource } from './plugins/perception/perception-source.js';
|
|
4
|
+
|
|
5
|
+
export function normalizeStrategyPerception(value: unknown, strategyId: string) {
|
|
6
|
+
const manifest = normalizePerceptionModuleManifest(value);
|
|
7
|
+
const bindings = Object.values(manifest.behaviors ?? {});
|
|
8
|
+
if (!bindings.length || bindings.some(binding => binding.name !== strategyId || binding.resourceId !== undefined)) {
|
|
9
|
+
throw Error('strategy_perception_self_binding_required');
|
|
10
|
+
}
|
|
11
|
+
return manifest;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Route a named perception through the same host as an equipped Hub perception. */
|
|
15
|
+
export function strategyTriggerSource(source: ResolvedClawclawBehaviorSource): ResolvedClawclawPerceptionSource | undefined {
|
|
16
|
+
if (!source.trigger) return undefined;
|
|
17
|
+
const { manifest, sha256 } = source.trigger;
|
|
18
|
+
const id = 'strategy:' + source.id;
|
|
19
|
+
const name = manifest.name ?? manifest.id;
|
|
20
|
+
const behaviors = Object.fromEntries(Object.entries(manifest.behaviors!).map(([key, binding]) =>
|
|
21
|
+
[key, { ...binding, name: source.id }]));
|
|
22
|
+
return { id, name, description: manifest.description, apiVersion: 3,
|
|
23
|
+
sourcePath: source.sourcePath, sourceRoot: source.sourceRoot,
|
|
24
|
+
embedded: { strategyId: source.id, sha256, declaredManifest: manifest },
|
|
25
|
+
module: { ...manifest, behaviors },
|
|
26
|
+
manifest: { apiVersion: 2, id, name, description: manifest.description,
|
|
27
|
+
subjectScope: 'self_and_others', produces: manifest.produces ?? [] } };
|
|
28
|
+
}
|