@myclaw163/clawclaw-cli 0.10.15 → 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/runtime/clawclaw/behavior-reflex-control.js +27 -36
- package/cli-runtime/runtime/clawclaw/behavior-trigger.js +25 -46
- package/cli-runtime/runtime/clawclaw/owner.js +7 -6
- package/cli-runtime/runtime/clawclaw/plugins/assembly.js +8 -7
- package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-source.js +6 -5
- 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-module-loader.js +7 -17
- package/cli-runtime/runtime/clawclaw/plugins/trigger/trigger-plugin.js +3 -30
- package/cli-runtime/runtime/clawclaw/plugins/trigger/trigger-thread-worker.js +0 -2
- package/cli-runtime/runtime/clawclaw/plugins/trigger/trigger-thread-worker.ts +0 -2
- package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/host.js +58 -1
- package/docs/custom-modules/README.md +1 -2
- package/docs/custom-modules/api-reference.md +8 -10
- package/docs/custom-modules/behavior.md +21 -23
- package/docs/custom-modules/examples/auto-escape.ts +17 -19
- package/docs/custom-modules/perception.md +2 -2
- package/docs/runtime/README.md +1 -1
- package/docs/runtime/behavior-runtime.md +4 -5
- package/docs/runtime/components-and-boundaries.md +4 -5
- package/docs/runtime/events-and-state.md +1 -1
- package/docs/runtime/owner-lifecycle-and-observability.md +2 -2
- package/docs/user-guide/README.md +1 -1
- package/docs/user-guide/api-reference.md +8 -10
- package/docs/user-guide/behavior.md +21 -23
- package/docs/user-guide/perception.md +2 -2
- package/package.json +1 -1
- package/skills/clawclaw/SKILL.md +3 -3
- package/skills/clawclaw/references/BEHAVIORS.md +1 -1
- package/skills/clawclaw-creator/SKILL.md +1 -1
- package/skills/clawclaw-creator/references/CUSTOM-BEHAVIOR-DEVELOPMENT.md +21 -23
- package/skills/clawclaw-creator/references/CUSTOM-MODULE-API.md +8 -10
- package/skills/clawclaw-creator/references/CUSTOM-MODULES.md +1 -2
- package/skills/clawclaw-creator/references/CUSTOM-PERCEPTION-DEVELOPMENT.md +2 -2
- package/src/runtime/clawclaw/behavior-reflex-control.ts +26 -22
- package/src/runtime/clawclaw/behavior-trigger.ts +20 -41
- package/src/runtime/clawclaw/owner.ts +7 -6
- package/src/runtime/clawclaw/plugins/assembly.ts +11 -8
- package/src/runtime/clawclaw/plugins/behavior/behavior-source.ts +7 -6
- 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/trigger-module-loader.ts +8 -19
- package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.ts +4 -37
- package/src/runtime/clawclaw/plugins/trigger/trigger-source.ts +0 -2
- package/src/runtime/clawclaw/plugins/trigger/trigger-thread-worker.ts +0 -2
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BEHAVIOR_PLUGIN_API_VERSION
|
|
3
3
|
} from "./chunk-3VLVCU6P.js";
|
|
4
|
-
import "./chunk-CF6IEQ4V.js";
|
|
5
4
|
import {
|
|
6
5
|
__reExport,
|
|
7
6
|
hasValidClawclawResourceLocalizations
|
|
@@ -673,6 +672,54 @@ var CLAWCLAW_VISUAL_EVENT_TYPES = [
|
|
|
673
672
|
"visual.following",
|
|
674
673
|
"visual.following_ended"
|
|
675
674
|
];
|
|
675
|
+
var CLAWCLAW_GAME_STREAM_BACKEND_EVENT_TYPES = [
|
|
676
|
+
"enter_room",
|
|
677
|
+
"move_start",
|
|
678
|
+
"move_end",
|
|
679
|
+
"move_interrupted",
|
|
680
|
+
"move",
|
|
681
|
+
"task_started",
|
|
682
|
+
"task_progress",
|
|
683
|
+
"task_completed",
|
|
684
|
+
"task_interrupted",
|
|
685
|
+
"task_sabotaged",
|
|
686
|
+
"task_assigned",
|
|
687
|
+
"kill",
|
|
688
|
+
"killed",
|
|
689
|
+
"murder_witnessed",
|
|
690
|
+
"body_dropped",
|
|
691
|
+
"warrior_shrimp_self_destruct",
|
|
692
|
+
"meeting_start",
|
|
693
|
+
"meeting_briefing",
|
|
694
|
+
"speech_turn",
|
|
695
|
+
"speech_your_turn",
|
|
696
|
+
"speech_next_turn",
|
|
697
|
+
"speech",
|
|
698
|
+
"speech_skipped",
|
|
699
|
+
"vote_phase_start",
|
|
700
|
+
"vote_cast",
|
|
701
|
+
"vote_speech",
|
|
702
|
+
"vote_speech_phase_ended",
|
|
703
|
+
"exile",
|
|
704
|
+
"no_exile",
|
|
705
|
+
"meeting_ended",
|
|
706
|
+
"meeting_result_pending",
|
|
707
|
+
"exile_game_over",
|
|
708
|
+
"game_started",
|
|
709
|
+
"game_over",
|
|
710
|
+
"role_assigned",
|
|
711
|
+
"emergency_started",
|
|
712
|
+
"emergency_resolved",
|
|
713
|
+
"emergency_interrupted",
|
|
714
|
+
"player_spotted",
|
|
715
|
+
"corpse_spotted",
|
|
716
|
+
"octopus_time_start",
|
|
717
|
+
"octopus_time_win",
|
|
718
|
+
"win_blocked_by_octopus",
|
|
719
|
+
"wandering_speech",
|
|
720
|
+
"death_speech",
|
|
721
|
+
"think"
|
|
722
|
+
];
|
|
676
723
|
var CLAWCLAW_BACKEND_AGENT_EVENT_TYPES = [
|
|
677
724
|
"service_status",
|
|
678
725
|
"move_interrupted",
|
|
@@ -1146,6 +1193,16 @@ function normalizeClawclawBehaviorManifest(value, options = {}) {
|
|
|
1146
1193
|
});
|
|
1147
1194
|
}
|
|
1148
1195
|
|
|
1196
|
+
// src/runtime/clawclaw/perception-module-manifest.ts
|
|
1197
|
+
var INPUT_TYPES = /* @__PURE__ */ new Set([
|
|
1198
|
+
...CLAWCLAW_GAME_STREAM_BACKEND_EVENT_TYPES,
|
|
1199
|
+
...CLAWCLAW_BACKEND_AGENT_EVENT_TYPES,
|
|
1200
|
+
...CLAWCLAW_LOCAL_AGENT_EVENT_TYPES.filter((type) => !/^(behavior|reminder|perception)\./.test(type)),
|
|
1201
|
+
"tasks_changed",
|
|
1202
|
+
"meeting_state"
|
|
1203
|
+
]);
|
|
1204
|
+
var PERCEPTION_OWNED_TYPES = /* @__PURE__ */ new Set([...CLAWCLAW_VISUAL_EVENT_TYPES, "reminder.task", "reminder.speech"]);
|
|
1205
|
+
|
|
1149
1206
|
// src/runtime/clawclaw/plugins/behavior/behavior-source.ts
|
|
1150
1207
|
var MAX_BEHAVIOR_SOURCE_BYTES = 2 * 1024 * 1024;
|
|
1151
1208
|
|
|
@@ -61,8 +61,7 @@ flowchart LR
|
|
|
61
61
|
Input["当前 State / 可见观察 / 源与后端原始事实"] --> Perception["统一感知 API v3"]
|
|
62
62
|
Perception --> Events["提交自己的事件"]
|
|
63
63
|
Events --> Mailbox["Mailbox / Agent"]
|
|
64
|
-
|
|
65
|
-
Trigger -->|"请求所属策略"| Strategy["策略执行类"]
|
|
64
|
+
Perception -->|"请求所属策略"| Strategy["策略执行类"]
|
|
66
65
|
Strategy --> Runtime["Runtime 检查并提交动作"]
|
|
67
66
|
```
|
|
68
67
|
|
|
@@ -95,16 +95,16 @@ 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。输入包含 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 再输出同一信息;紧急生命周期和阈值由内置紧急感知负责。
|
|
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
|
|
|
102
|
-
结果为 { state?, events? }。events 项为 { type, key, wakeAgent?, occurredAt?, payload },type 必须在 produces 中声明,key 是稳定发生标识,wakeAgent 省略为 true。false 不独立唤醒且保留事件;不生成事件表示没有这条通知。事件类型的可见范围仍受 Catalog 和配置约束,模块不能重写原始事件或其他模块的通知。
|
|
102
|
+
结果为 { state?, events?, activations? }。events 项为 { type, key, wakeAgent?, occurredAt?, payload },type 必须在 produces 中声明,key 是稳定发生标识,wakeAgent 省略为 true。false 不独立唤醒且保留事件;不生成事件表示没有这条通知。事件类型的可见范围仍受 Catalog 和配置约束,模块不能重写原始事件或其他模块的通知。
|
|
103
103
|
|
|
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
|
|
|
@@ -492,15 +492,13 @@ interface StrategyNormalizationApi {
|
|
|
492
492
|
|
|
493
493
|
这里没有动态 `GameState` 或 Action 能力;动态判断放在 `decide()` 中。
|
|
494
494
|
|
|
495
|
-
##
|
|
495
|
+
## 策略内置触发感知
|
|
496
496
|
|
|
497
|
-
|
|
497
|
+
CCL 0.10.16 起,策略文件可以具名导出继承 `ClawclawPerception` 的 `Trigger`。使用 `@myclaw163/clawclaw-cli/perception-plugin` 的感知 API v3。`Trigger.manifest` 和普通感知一样声明 `id`、`description`,在 `strategies` 里给本文件默认策略的声明 ID 配置固定绑定。绑定可以指定 `reflexPriority`、`cooldownMs`、`rearm` 和 `maxRuntimeMs`。
|
|
498
498
|
|
|
499
|
-
|
|
500
|
-
evaluate(input: Readonly<TriggerInput>, api: TriggerReadApi): TriggerMatch | void | Promise<TriggerMatch | void>
|
|
501
|
-
```
|
|
499
|
+
`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` 绑定,激活参数覆盖策略默认值。
|
|
502
500
|
|
|
503
|
-
|
|
501
|
+
跨帧判断保存在返回的 `state` 中。触发感知与执行类需要共享的局内记录使用 `api.memory`。例如触发感知按尸体 ID 查询,执行类接手后记录,避免一次未获准的请求占用现场。
|
|
504
502
|
|
|
505
503
|
## 共享数据结构
|
|
506
504
|
|
|
@@ -697,7 +695,7 @@ import type {
|
|
|
697
695
|
|
|
698
696
|
### api.memory:局内持续记忆
|
|
699
697
|
|
|
700
|
-
StrategyReadApi
|
|
698
|
+
StrategyReadApi 和 PerceptionModuleApi 均提供以下接口。
|
|
701
699
|
|
|
702
700
|
```ts
|
|
703
701
|
type StrategyMemoryValue = null | boolean | number | string
|
|
@@ -101,7 +101,7 @@ export default class GoToPoint extends ClawclawStrategy<GoToPointInput> {
|
|
|
101
101
|
|
|
102
102
|
## 单文件反射与局中控制
|
|
103
103
|
|
|
104
|
-
|
|
104
|
+
运行对局的 CCL 需要 0.10.16 或更新版本,桌面端以实际使用的 CCL 版本为准。一个策略文件同时导出执行类和触发感知。默认导出的 `ClawclawStrategy` 在取得控制权后执行 `decide()`。具名导出的 `Trigger extends ClawclawPerception` 使用感知 API v3,在 `evaluate()` 中通过 `activations` 请求已声明的同文件策略绑定。示例在玩家进入指定范围时前往撤离点。
|
|
105
105
|
|
|
106
106
|
```ts
|
|
107
107
|
import {
|
|
@@ -109,13 +109,12 @@ import {
|
|
|
109
109
|
} from '@myclaw163/clawclaw-cli/strategy-plugin';
|
|
110
110
|
|
|
111
111
|
import {
|
|
112
|
-
|
|
113
|
-
} from '@myclaw163/clawclaw-cli/
|
|
112
|
+
ClawclawPerception, type PerceptionModuleInput, type PerceptionModuleResult,
|
|
113
|
+
} from '@myclaw163/clawclaw-cli/perception-plugin';
|
|
114
114
|
|
|
115
115
|
type Parameters = {
|
|
116
116
|
readonly x: number;
|
|
117
117
|
readonly y: number;
|
|
118
|
-
readonly triggerDistance: number;
|
|
119
118
|
};
|
|
120
119
|
|
|
121
120
|
/** The strategy executes when it is granted control. */
|
|
@@ -126,9 +125,8 @@ export default class AutoEscape extends ClawclawStrategy<Parameters> {
|
|
|
126
125
|
description: '有人进入设定范围时,前往 Agent 指定的撤离点。靠近不等于对方有敌意。',
|
|
127
126
|
execution: 'serial',
|
|
128
127
|
inputs: [
|
|
129
|
-
{ id: 'x', type: 'number', description: '当前地图上可达的撤离点 X。',
|
|
130
|
-
{ id: 'y', type: 'number', description: '当前地图上可达的撤离点 Y。',
|
|
131
|
-
{ id: 'triggerDistance', type: 'number', description: '触发距离(像素)。', default: 160, min: 1, max: 1000 },
|
|
128
|
+
{ id: 'x', type: 'number', description: '当前地图上可达的撤离点 X。', default: 2708 },
|
|
129
|
+
{ id: 'y', type: 'number', description: '当前地图上可达的撤离点 Y。', default: 2320 },
|
|
132
130
|
],
|
|
133
131
|
runtime: { defaultMs: 10000 },
|
|
134
132
|
} as const satisfies ClawclawStrategyManifest;
|
|
@@ -152,22 +150,22 @@ export default class AutoEscape extends ClawclawStrategy<Parameters> {
|
|
|
152
150
|
}
|
|
153
151
|
}
|
|
154
152
|
|
|
155
|
-
export class Trigger extends
|
|
153
|
+
export class Trigger extends ClawclawPerception {
|
|
156
154
|
static readonly manifest = {
|
|
157
|
-
apiVersion:
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
} as const
|
|
163
|
-
|
|
164
|
-
evaluate(input: Readonly<
|
|
165
|
-
const players = input.frame
|
|
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 } },
|
|
160
|
+
} as const;
|
|
161
|
+
|
|
162
|
+
evaluate(input: Readonly<PerceptionModuleInput>): PerceptionModuleResult {
|
|
163
|
+
const players = input.frame?.observation.players ?? [];
|
|
166
164
|
const self = players.find(player => player.observer);
|
|
167
|
-
if (!self) return;
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
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' }] : [] };
|
|
171
169
|
}
|
|
172
170
|
}
|
|
173
171
|
```
|
|
@@ -181,9 +179,9 @@ ccl strategy status community.auto-escape
|
|
|
181
179
|
ccl strategy unwatch community.auto-escape
|
|
182
180
|
```
|
|
183
181
|
|
|
184
|
-
|
|
182
|
+
装配一个策略文件后,触发感知随对局运行,默认允许自动激活。`unwatch` 禁止自动激活并取消该绑定正在执行的反射,感知继续观察和保存状态。`watch` 恢复自动激活。
|
|
185
183
|
|
|
186
|
-
`strategy update`
|
|
184
|
+
`strategy update` 按两个类各自声明的字段更新感知配置或策略输入。策略输入影响本策略当前执行及后续启动默认值。动态命中参数和显式启动参数覆盖本局默认值。只改一次执行时加 `--activation` 并指定 Activation ID。改参保留 Activation ID 和原截止时间,增加实例代际。暂停实例继续暂停。设置在换局或 Owner 退出时清空。
|
|
187
185
|
|
|
188
186
|
跨激活去重使用 `api.memory`。例如 Trigger 查 `handled:<尸体ID>`,追尸策略实际接手现场后再写。单次执行进度可以用实例字段。
|
|
189
187
|
|
|
@@ -3,13 +3,12 @@ import {
|
|
|
3
3
|
} from '@myclaw163/clawclaw-cli/strategy-plugin';
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
|
-
|
|
7
|
-
} from '@myclaw163/clawclaw-cli/
|
|
6
|
+
ClawclawPerception, type PerceptionModuleInput, type PerceptionModuleResult,
|
|
7
|
+
} from '@myclaw163/clawclaw-cli/perception-plugin';
|
|
8
8
|
|
|
9
9
|
type Parameters = {
|
|
10
10
|
readonly x: number;
|
|
11
11
|
readonly y: number;
|
|
12
|
-
readonly triggerDistance: number;
|
|
13
12
|
};
|
|
14
13
|
|
|
15
14
|
/** The strategy executes when it is granted control. */
|
|
@@ -20,9 +19,8 @@ export default class AutoEscape extends ClawclawStrategy<Parameters> {
|
|
|
20
19
|
description: '有人进入设定范围时,前往 Agent 指定的撤离点。靠近不等于对方有敌意。',
|
|
21
20
|
execution: 'serial',
|
|
22
21
|
inputs: [
|
|
23
|
-
{ id: 'x', type: 'number', description: '当前地图上可达的撤离点 X。',
|
|
24
|
-
{ id: 'y', type: 'number', description: '当前地图上可达的撤离点 Y。',
|
|
25
|
-
{ id: 'triggerDistance', type: 'number', description: '触发距离(像素)。', default: 160, min: 1, max: 1000 },
|
|
22
|
+
{ id: 'x', type: 'number', description: '当前地图上可达的撤离点 X。', default: 2708 },
|
|
23
|
+
{ id: 'y', type: 'number', description: '当前地图上可达的撤离点 Y。', default: 2320 },
|
|
26
24
|
],
|
|
27
25
|
runtime: { defaultMs: 10000 },
|
|
28
26
|
} as const satisfies ClawclawStrategyManifest;
|
|
@@ -46,21 +44,21 @@ export default class AutoEscape extends ClawclawStrategy<Parameters> {
|
|
|
46
44
|
}
|
|
47
45
|
}
|
|
48
46
|
|
|
49
|
-
export class Trigger extends
|
|
47
|
+
export class Trigger extends ClawclawPerception {
|
|
50
48
|
static readonly manifest = {
|
|
51
|
-
apiVersion:
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
} as const
|
|
49
|
+
apiVersion: 3,
|
|
50
|
+
id: 'community.nearby',
|
|
51
|
+
description: '有玩家靠近时请求本策略撤离。',
|
|
52
|
+
inputs: [{ id: 'triggerDistance', type: 'number', description: '触发距离(像素)。', default: 160, min: 1, max: 1000 }],
|
|
53
|
+
strategies: { escape: { name: 'community.auto-escape', reflexPriority: 40, cooldownMs: 3000, rearm: 'after_clear', maxRuntimeMs: 10000 } },
|
|
54
|
+
} as const;
|
|
57
55
|
|
|
58
|
-
evaluate(input: Readonly<
|
|
59
|
-
const players = input.frame
|
|
56
|
+
evaluate(input: Readonly<PerceptionModuleInput>): PerceptionModuleResult {
|
|
57
|
+
const players = input.frame?.observation.players ?? [];
|
|
60
58
|
const self = players.find(player => player.observer);
|
|
61
|
-
if (!self) return;
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
59
|
+
if (!self) return {};
|
|
60
|
+
const distance = Number(input.config.triggerDistance);
|
|
61
|
+
const nearby = players.some(player => !player.observer && Math.hypot(player.x - self.x, player.y - self.y) <= distance);
|
|
62
|
+
return { activations: nearby ? [{ strategy: 'escape', reason: 'player_nearby' }] : [] };
|
|
65
63
|
}
|
|
66
64
|
}
|
|
@@ -70,7 +70,7 @@ export default class FirstSighting extends ClawclawPerception {
|
|
|
70
70
|
| config / state | Manifest 参数与上一轮提交后的私有检查点 |
|
|
71
71
|
| availableStrategies | 当前可加载的策略操作名 |
|
|
72
72
|
|
|
73
|
-
结果可同时包含 `state`、`events`,也可以只返回其中需要的部分。每次计算使用新实例,跨回调记忆用返回的 state,不能依赖实例字段。宿主只在更换对局/作用域时清空私有状态,不在进出会议时统一清空。阶段切换通过 lifecycle 传入,由脚本按需收尾观察片段、刷新部分字段并返回下一份 state。连接恢复保留检查点并显式标记 recovery,不伪造进入/离开会议,也不应重放旧通知。
|
|
73
|
+
结果可同时包含 `state`、`events` 和 `activations`,也可以只返回其中需要的部分。每次计算使用新实例,跨回调记忆用返回的 state,不能依赖实例字段。宿主只在更换对局/作用域时清空私有状态,不在进出会议时统一清空。阶段切换通过 lifecycle 传入,由脚本按需收尾观察片段、刷新部分字段并返回下一份 state。连接恢复保留检查点并显式标记 recovery,不伪造进入/离开会议,也不应重放旧通知。
|
|
74
74
|
|
|
75
75
|
Manifest 使用 `apiVersion: 3`、`id`、`description`,可声明 `consumes`、`produces`、`inputs`、`config` 、可选固定 `strategies` 绑定与本地化信息。不填写 kind。事件必须在 produces 中声明,并使用稳定的 key 和可序列化 payload;text 可用于直接表达通知。不能冒充击杀、能力就绪或策略生命周期等系统事实。
|
|
76
76
|
|
|
@@ -127,7 +127,7 @@ API v3 模块只订阅 Source/后端原始事实;读取可见观察不需要
|
|
|
127
127
|
|
|
128
128
|
`ccl perception update <感知名> --input '<补丁JSON>' ` 更新当前局的观察和通知参数。`ccl perception status <感知名>` 查看当前参数和运行状态。
|
|
129
129
|
|
|
130
|
-
|
|
130
|
+
开发自动反射时,在策略文件中增加具名触发感知 Trigger。装配该策略后用 `ccl strategy` 修改触发参数、查看状态和开关。
|
|
131
131
|
|
|
132
132
|
## 编写规则
|
|
133
133
|
|
package/docs/runtime/README.md
CHANGED
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
|
|
44
44
|
内置与自定义感知并行,没有互相的调度或数据依赖。感知独立观察状态/后端原始事件;Strategy 等待声明的上游,Mailbox 等待通知生产者。策略公开事件由内置感知在后续轮次转发。任务变化由各模块本地比较,不再提供公共 tasks_changed。见[当前装配图](./components-and-boundaries.md#当前装配)。
|
|
45
45
|
|
|
46
|
-
感知使用统一 Perception API v3
|
|
46
|
+
感知使用统一 Perception API v3,持续观察、记忆和通知。策略文件可具名导出触发感知 Trigger,由统一感知插件运行,Strategy 仲裁反射。 分别加载感知和策略资源,由感知请求 Strategy Reflex;Action 仍由 Strategy Decision 经 Action 插件提交。
|
|
47
47
|
|
|
48
48
|
官方 Strategy、Perception 和 Persona 由 Hub loadout 提供,CLI 包不再向用户目录物化官方模块。纯本地模块按账号保存。旧 Strategy/Intent 作者入口、目录和 Runtime Plugin 已删除。
|
|
49
49
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
通用运行机制由 `@myclaw163/game-agent-runtime` 提供,CCL 装配龙虾杀 Source、感知与策略内容、动作实现和游戏规则。感知和策略各自管理脚本,启动入口配合 Owner 连接整个系统;Mailbox 包含宿主输出适配。见[框架包与本地开发](./framework-package.md)。
|
|
4
4
|
|
|
5
|
-
感知使用统一 Perception API v3
|
|
5
|
+
感知使用统一 Perception API v3,持续观察、记忆和通知。策略文件可具名导出触发感知 Trigger,由统一感知插件运行,Strategy 仲裁反射。
|
|
6
6
|
|
|
7
7
|
本页描述当前统一 Strategy Runtime 的实现语义。公共作者接口见[开发 Strategy](../custom-modules/behavior.md)。
|
|
8
8
|
|
|
@@ -14,8 +14,7 @@ flowchart TD
|
|
|
14
14
|
Source --> Scheduler["Runtime 本地调度器<br/>按本地时钟自主循环"]
|
|
15
15
|
Scheduler -->|"本轮最新 State、观察与累计事件"| Perception["感知执行器:并行运行内置与自定义感知"]
|
|
16
16
|
Previous["上一轮策略事件"] --> Perception
|
|
17
|
-
|
|
18
|
-
Trigger -->|"固定请求所属策略"| Strategy["策略执行器:长期 / 短期 / 反射"]
|
|
17
|
+
Perception -->|"固定请求所属策略"| Strategy["策略执行器:长期 / 短期 / 反射"]
|
|
19
18
|
Strategy --> Action["Action:通用准入与龙虾杀动作提交"]
|
|
20
19
|
Action --> Output["发往游戏后端的动作请求"]
|
|
21
20
|
Strategy --> Deferred["本轮策略事件:留待下一轮感知"]
|
|
@@ -73,11 +72,11 @@ long 可以在 Decision 中返回一个 `delegate` 效果,请求 Host 校验
|
|
|
73
72
|
|
|
74
73
|
## 策略内置 Trigger 与本局控制
|
|
75
74
|
|
|
76
|
-
感知使用统一 Perception API v3
|
|
75
|
+
感知使用统一 Perception API v3,持续观察、记忆和通知。策略文件可具名导出触发感知 Trigger,由统一感知插件运行,Strategy 仲裁反射。
|
|
77
76
|
|
|
78
77
|
多个策略的 Trigger 可在后台判断,Strategy 控制栈按优先级仲裁。
|
|
79
78
|
|
|
80
|
-
|
|
79
|
+
单文件策略中的触发感知由 Perception 运行,装配后默认允许自动激活。用 ccl strategy status [id] 核对开关、冷却和实际执行。strategy watch/unwatch 控制本局自动激活,unwatch 同时取消关联 Reflex,感知继续观察。strategy update 更新触发判断、现有执行和后续默认参数,保留 Activation ID 与原截止时间。仅修改一次执行时,指定 Activation ID 并加 --activation。换局或 Owner 退出时重置。
|
|
81
80
|
|
|
82
81
|
完整源码与命令见[策略教程](../custom-modules/behavior.md#单文件反射与局中控制)。
|
|
83
82
|
|
|
@@ -12,8 +12,7 @@ flowchart TD
|
|
|
12
12
|
Source --> Scheduler["Runtime 本地调度器<br/>按本地时钟自主循环"]
|
|
13
13
|
Scheduler -->|"本轮最新 State、观察与累计事件"| Perception["感知执行器:并行运行内置与自定义感知"]
|
|
14
14
|
Previous["上一轮策略事件"] --> Perception
|
|
15
|
-
|
|
16
|
-
Trigger -->|"固定请求所属策略"| Strategy["策略执行器:长期 / 短期 / 反射"]
|
|
15
|
+
Perception -->|"固定请求所属策略"| Strategy["策略执行器:长期 / 短期 / 反射"]
|
|
17
16
|
Strategy --> Action["Action:通用准入与龙虾杀动作提交"]
|
|
18
17
|
Action --> Output["发往游戏后端的动作请求"]
|
|
19
18
|
Strategy --> Deferred["本轮策略事件:留待下一轮感知"]
|
|
@@ -57,11 +56,11 @@ CCL Owner 默认每 100ms 开始一次本地计算周期,可通过 config.json
|
|
|
57
56
|
|
|
58
57
|
## 策略资源与内置 Trigger
|
|
59
58
|
|
|
60
|
-
策略资源默认导出 Strategy
|
|
59
|
+
策略资源默认导出 Strategy 执行类,可在同文件具名导出继承 ClawclawPerception 的 Trigger。感知插件运行该类并判断反射条件,感知持续观察并组织通知。
|
|
61
60
|
|
|
62
61
|
静态发现不执行脚本。感知和策略在不同 Worker 中运行,不能通过全局变量或实例字段共享状态。Host 按固定资源 ID、名称与同源操作名解析绑定;感知只请求固定 Reflex,不提交 Action。
|
|
63
62
|
|
|
64
|
-
|
|
63
|
+
单文件策略中的触发感知由 Perception 运行,装配后默认允许自动激活。用 ccl strategy status [id] 核对开关、冷却和实际执行。strategy watch/unwatch 控制本局自动激活,unwatch 同时取消关联 Reflex,感知继续观察。strategy update 更新触发判断、现有执行和后续默认参数,保留 Activation ID 与原截止时间。仅修改一次执行时,指定 Activation ID 并加 --activation。换局或 Owner 退出时重置。
|
|
65
64
|
|
|
66
65
|
## 策略控制权
|
|
67
66
|
|
|
@@ -91,7 +90,7 @@ CCL Owner 默认每 100ms 开始一次本地计算周期,可通过 config.json
|
|
|
91
90
|
| 统一感知 | src/runtime/clawclaw/plugins/perception/perception-module-plugin.ts |
|
|
92
91
|
| 视觉感知 | src/runtime/clawclaw/plugins/perception/perception-plugin.ts |
|
|
93
92
|
| Reminder | src/runtime/clawclaw/plugins/derived-event/reminder-plugin.ts |
|
|
94
|
-
| 策略内置 Trigger 与装配 | src/runtime/clawclaw/behavior-trigger.ts、plugins/
|
|
93
|
+
| 策略内置 Trigger 与装配 | src/runtime/clawclaw/behavior-trigger.ts、plugins/perception/ |
|
|
95
94
|
| 本局反射控制面 | src/runtime/clawclaw/behavior-reflex-control.ts |
|
|
96
95
|
| Strategy | src/runtime/clawclaw/plugins/behavior/ |
|
|
97
96
|
| Action 与 GameQuery | src/runtime/clawclaw/plugins/action/、game-query/ |
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Event、State 与 History 数据链
|
|
2
2
|
|
|
3
|
-
感知使用统一 Perception API v3
|
|
3
|
+
感知使用统一 Perception API v3,持续观察、记忆和通知。策略文件可具名导出触发感知 Trigger,由统一感知插件运行,Strategy 仲裁反射。
|
|
4
4
|
|
|
5
5
|
组件职责见 [Runtime 组件职责与 Event 归属](./components-and-boundaries.md)。本页说明事实怎样进入 Runtime,并由顶层 Mailbox 从 Ready View 投影到各 Agent 输出。
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Owner、Mailbox 与 Channel 生命周期及可观测性
|
|
2
2
|
|
|
3
|
-
感知使用统一 Perception API v3
|
|
3
|
+
感知使用统一 Perception API v3,持续观察、记忆和通知。策略文件可具名导出触发感知 Trigger,由统一感知插件运行,Strategy 仲裁反射。
|
|
4
4
|
|
|
5
5
|
Owner 持有一次 participation 的游戏资源,并装配 内置与自定义感知、Strategy 控制链和顶层 Mailbox。各插件的等待关系由输入输出契约与 `after` 声明。Claude Code 默认使用 Monitor 直达通知 + `ccl events` 详情查询;Channel MCP server 是环境变量显式启用的可选 transport bridge,不是 Runtime Plugin,也不拥有 Owner。组件边界见 [Runtime 组件职责与 Event 归属](./components-and-boundaries.md)。
|
|
6
6
|
|
|
@@ -30,7 +30,7 @@ Claude Code 加载 `clawclaw-channel` 后启动 MCP stdio 子进程。该进程
|
|
|
30
30
|
|
|
31
31
|
## 启动与重连
|
|
32
32
|
|
|
33
|
-
Owner 打开 Runtime/SQLite,读取当前账号已装配的资源和角色默认 long,构建 Action、内置感知、GameQuery、视觉/统一 Perception、Reminder、Strategy、Mailbox 与输出 Adapter。Owner 从启用的策略中发现具名 Trigger
|
|
33
|
+
Owner 打开 Runtime/SQLite,读取当前账号已装配的资源和角色默认 long,构建 Action、内置感知、GameQuery、视觉/统一 Perception、Reminder、Strategy、Mailbox 与输出 Adapter。Owner 从启用的策略中发现具名 Trigger,自动绑定该策略,两个入口使用同一份源码版本。绑定就绪时默认开启自动反射。角色确定后默认 long 立即启动;缺失只 warning + idle。控制优先级为 reflex > short > long。
|
|
34
34
|
|
|
35
35
|
`--agent-type claude-code` 本身只标识宿主;只有同时设置 `CLAWCLAW_ENABLE_CLAUDE_CHANNELS=1` 才启用 Claude Channel 输出,否则使用默认 Monitor 路由。两种路由都不改变账号选择和游戏生命周期。
|
|
36
36
|
|
|
@@ -14,7 +14,7 @@ CCL 内置玩家、任务、能力、紧急任务、房间与流程、会议、
|
|
|
14
14
|
| 放入本地文件、启用模块或上传至 HUB | [安装、启用与上传](./installation.md) |
|
|
15
15
|
| 控制角色做任务、移动、巡逻或追踪 | [开发策略](./behavior.md) |
|
|
16
16
|
| 开发观察、提醒与通知规则 | [感知开发总览](./perception.md) |
|
|
17
|
-
| 识别目击、停留、路线或跟随 | [编写视觉感知](./perception.md
|
|
17
|
+
| 识别目击、停留、路线或跟随 | [编写视觉感知](./perception.md#完整例子首次目击玩家) |
|
|
18
18
|
| 控制任务变化和附近发言的提醒 | [编写提醒型感知](./perception.md#内置感知与自定义感知) |
|
|
19
19
|
| 条件成立后自动行动、局中改参和开关 | [单文件反射策略](./behavior.md#单文件反射与局中控制) |
|
|
20
20
|
| 查询字段、类型与回调签名 | [API 参考](./api-reference.md) |
|
|
@@ -72,14 +72,14 @@ const maySelect = candidates[0] && isTaskAvailable(input.gameState, candidates[0
|
|
|
72
72
|
|
|
73
73
|
从公开 perception-plugin 入口导入 ClawclawPerception、PerceptionModuleInput、PerceptionModuleResult、PerceptionModuleEvent 和 PerceptionModuleManifest;版本常量为 PERCEPTION_MODULE_API_VERSION=3。新脚本没有三选一的 kind,通过同一个 evaluate(input) 组合观察、通知和私有记忆。
|
|
74
74
|
|
|
75
|
-
Manifest 的必需项为 apiVersion:3、id、description;可选 name、localizations、consumes、produces、inputs、config。输入包含 moduleId、scope、gameState、frame、events、taskChanges、boundary、nowMs、cycle、config、state
|
|
75
|
+
Manifest 的必需项为 apiVersion:3、id、description;可选 name、localizations、consumes、produces、inputs、config、strategies。输入包含 moduleId、scope、gameState、frame、events、taskChanges、boundary、lifecycle、nowMs、cycle、config、state 和绑定的可用状态。frame/gameState 可以为 null;events 只含订阅的源/后端原始事实,taskChanges 由该模块自己的基线与本轮权威任务列表比较得到,结合同轮后端事实;不是订阅 tasks_changed。 内置任务感知及 evaluateReminder('tasks') 只把后端 task_* 事实转为基础任务通知,不按 taskChanges 再输出同一信息;紧急生命周期和阈值由内置紧急感知负责。
|
|
76
76
|
|
|
77
|
-
结果为 { state?, events? }。events 项为 { type, key, wakeAgent?, payload },type 必须在 produces 中声明,key 是稳定发生标识,wakeAgent 省略为 true。false 不独立唤醒且保留事件;不生成事件表示没有这条通知。事件类型的可见范围仍受 Catalog 和配置约束,模块不能重写原始事件或其他模块的通知。
|
|
77
|
+
结果为 { state?, events?, activations? }。events 项为 { type, key, wakeAgent?, payload },type 必须在 produces 中声明,key 是稳定发生标识,wakeAgent 省略为 true。false 不独立唤醒且保留事件;不生成事件表示没有这条通知。事件类型的可见范围仍受 Catalog 和配置约束,模块不能重写原始事件或其他模块的通知。
|
|
78
78
|
|
|
79
79
|
|
|
80
80
|
每次计算使用 fresh 实例,跨回调状态必须从 input.state 读取并作为结果 state 返回,由 Host 检查点恢复。新脚本不能订阅其他感知、Strategy 或 decision 输出;运行时还按 producerPluginId 过滤,只接纳 Source/后端原始事实。produces 不能冒充系统保留类型;reminder.task/reminder.speech 是兼容通知输出,不是权威任务事实。
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
策略文件中的具名触发感知通过 activations 请求同文件策略的 Reflex。
|
|
83
83
|
|
|
84
84
|
|
|
85
85
|
## 策略 API
|
|
@@ -644,19 +644,17 @@ import type {
|
|
|
644
644
|
- 查询 API 只在当前回调活动期间有效,不要保存后延迟调用;
|
|
645
645
|
- 自定义模块是本机可信代码,不是安全沙箱,只安装可信来源。
|
|
646
646
|
|
|
647
|
-
##
|
|
647
|
+
## 策略内置触发感知
|
|
648
648
|
|
|
649
|
-
|
|
649
|
+
CCL 0.10.16 起,策略文件可以具名导出继承 `ClawclawPerception` 的 `Trigger`。使用 `@myclaw163/clawclaw-cli/perception-plugin` 的感知 API v3。`Trigger.manifest` 和普通感知一样声明 `id`、`description`,在 `strategies` 里给本文件默认策略的声明 ID 配置固定绑定。绑定可以指定 `reflexPriority`、`cooldownMs`、`rearm` 和 `maxRuntimeMs`。
|
|
650
650
|
|
|
651
|
-
|
|
652
|
-
evaluate(input: Readonly<TriggerInput>, api: TriggerReadApi): TriggerMatch | void | Promise<TriggerMatch | void>
|
|
653
|
-
```
|
|
651
|
+
`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` 绑定,激活参数覆盖策略默认值。
|
|
654
652
|
|
|
655
|
-
|
|
653
|
+
跨帧判断保存在返回的 `state` 中。触发感知与执行类需要共享的局内记录使用 `api.memory`。例如触发感知按尸体 ID 查询,执行类接手后记录,避免一次未获准的请求占用现场。
|
|
656
654
|
|
|
657
655
|
### api.memory:局内持续记忆
|
|
658
656
|
|
|
659
|
-
StrategyReadApi
|
|
657
|
+
StrategyReadApi 和 PerceptionModuleApi 均提供以下接口。
|
|
660
658
|
|
|
661
659
|
```ts
|
|
662
660
|
type StrategyMemoryValue = null | boolean | number | string
|
|
@@ -101,7 +101,7 @@ export default class GoToPoint extends ClawclawStrategy<GoToPointInput> {
|
|
|
101
101
|
|
|
102
102
|
## 单文件反射与局中控制
|
|
103
103
|
|
|
104
|
-
|
|
104
|
+
运行对局的 CCL 需要 0.10.16 或更新版本,桌面端以实际使用的 CCL 版本为准。一个策略文件同时导出执行类和触发感知。默认导出的 `ClawclawStrategy` 在取得控制权后执行 `decide()`。具名导出的 `Trigger extends ClawclawPerception` 使用感知 API v3,在 `evaluate()` 中通过 `activations` 请求已声明的同文件策略绑定。示例在玩家进入指定范围时前往撤离点。
|
|
105
105
|
|
|
106
106
|
```ts
|
|
107
107
|
import {
|
|
@@ -109,13 +109,12 @@ import {
|
|
|
109
109
|
} from '@myclaw163/clawclaw-cli/strategy-plugin';
|
|
110
110
|
|
|
111
111
|
import {
|
|
112
|
-
|
|
113
|
-
} from '@myclaw163/clawclaw-cli/
|
|
112
|
+
ClawclawPerception, type PerceptionModuleInput, type PerceptionModuleResult,
|
|
113
|
+
} from '@myclaw163/clawclaw-cli/perception-plugin';
|
|
114
114
|
|
|
115
115
|
type Parameters = {
|
|
116
116
|
readonly x: number;
|
|
117
117
|
readonly y: number;
|
|
118
|
-
readonly triggerDistance: number;
|
|
119
118
|
};
|
|
120
119
|
|
|
121
120
|
/** The strategy executes when it is granted control. */
|
|
@@ -126,9 +125,8 @@ export default class AutoEscape extends ClawclawStrategy<Parameters> {
|
|
|
126
125
|
description: '有人进入设定范围时,前往 Agent 指定的撤离点。靠近不等于对方有敌意。',
|
|
127
126
|
execution: 'serial',
|
|
128
127
|
inputs: [
|
|
129
|
-
{ id: 'x', type: 'number', description: '当前地图上可达的撤离点 X。',
|
|
130
|
-
{ id: 'y', type: 'number', description: '当前地图上可达的撤离点 Y。',
|
|
131
|
-
{ id: 'triggerDistance', type: 'number', description: '触发距离(像素)。', default: 160, min: 1, max: 1000 },
|
|
128
|
+
{ id: 'x', type: 'number', description: '当前地图上可达的撤离点 X。', default: 2708 },
|
|
129
|
+
{ id: 'y', type: 'number', description: '当前地图上可达的撤离点 Y。', default: 2320 },
|
|
132
130
|
],
|
|
133
131
|
runtime: { defaultMs: 10000 },
|
|
134
132
|
} as const satisfies ClawclawStrategyManifest;
|
|
@@ -152,22 +150,22 @@ export default class AutoEscape extends ClawclawStrategy<Parameters> {
|
|
|
152
150
|
}
|
|
153
151
|
}
|
|
154
152
|
|
|
155
|
-
export class Trigger extends
|
|
153
|
+
export class Trigger extends ClawclawPerception {
|
|
156
154
|
static readonly manifest = {
|
|
157
|
-
apiVersion:
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
} as const
|
|
163
|
-
|
|
164
|
-
evaluate(input: Readonly<
|
|
165
|
-
const players = input.frame
|
|
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 } },
|
|
160
|
+
} as const;
|
|
161
|
+
|
|
162
|
+
evaluate(input: Readonly<PerceptionModuleInput>): PerceptionModuleResult {
|
|
163
|
+
const players = input.frame?.observation.players ?? [];
|
|
166
164
|
const self = players.find(player => player.observer);
|
|
167
|
-
if (!self) return;
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
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' }] : [] };
|
|
171
169
|
}
|
|
172
170
|
}
|
|
173
171
|
```
|
|
@@ -181,9 +179,9 @@ ccl strategy status community.auto-escape
|
|
|
181
179
|
ccl strategy unwatch community.auto-escape
|
|
182
180
|
```
|
|
183
181
|
|
|
184
|
-
|
|
182
|
+
装配一个策略文件后,触发感知随对局运行,默认允许自动激活。`unwatch` 禁止自动激活并取消该绑定正在执行的反射,感知继续观察和保存状态。`watch` 恢复自动激活。
|
|
185
183
|
|
|
186
|
-
`strategy update`
|
|
184
|
+
`strategy update` 按两个类各自声明的字段更新感知配置或策略输入。策略输入影响本策略当前执行及后续启动默认值。动态命中参数和显式启动参数覆盖本局默认值。只改一次执行时加 `--activation` 并指定 Activation ID。改参保留 Activation ID 和原截止时间,增加实例代际。暂停实例继续暂停。设置在换局或 Owner 退出时清空。
|
|
187
185
|
|
|
188
186
|
跨激活去重使用 `api.memory`。例如 Trigger 查 `handled:<尸体ID>`,追尸策略实际接手现场后再写。单次执行进度可以用实例字段。
|
|
189
187
|
|
|
@@ -67,7 +67,7 @@ export default class FirstSighting extends ClawclawPerception {
|
|
|
67
67
|
| config / state | Manifest 参数与上一轮提交后的私有检查点 |
|
|
68
68
|
| availableStrategies | 当前可加载的策略操作名 |
|
|
69
69
|
|
|
70
|
-
结果可同时包含 `state`、`events`,也可以只返回其中需要的部分。每次计算使用新实例,跨回调记忆用返回的 state
|
|
70
|
+
结果可同时包含 `state`、`events` 和 `activations`,也可以只返回其中需要的部分。每次计算使用新实例,跨回调记忆用返回的 state,不能依赖实例字段。更换游戏作用域时清空这份状态。阶段变化通过 lifecycle 传入,脚本可以按需清理连续观测字段。
|
|
71
71
|
|
|
72
72
|
Manifest 使用 `apiVersion: 3`、`id`、`description`,可声明 `consumes`、`produces`、`inputs`、`config` 、可选固定 `strategies` 绑定与本地化信息。不填写 kind。事件必须在 produces 中声明,并使用稳定的 key 和可序列化 payload;text 可用于直接表达通知。不能冒充击杀、能力就绪或策略生命周期等系统事实。
|
|
73
73
|
|
|
@@ -104,7 +104,7 @@ API v3 模块只订阅 Source/后端原始事实;读取可见观察不需要
|
|
|
104
104
|
|
|
105
105
|
`ccl perception update <感知名> --input '<补丁JSON>' ` 更新当前局的观察和通知参数。`ccl perception status <感知名>` 查看当前参数和运行状态。
|
|
106
106
|
|
|
107
|
-
|
|
107
|
+
开发自动反射时,在策略文件中增加具名触发感知 Trigger。装配该策略后用 `ccl strategy` 修改触发参数、查看状态和开关。
|
|
108
108
|
|
|
109
109
|
## 编写规则
|
|
110
110
|
|