@myclaw163/clawclaw-cli 0.9.1 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/QUICKSTART_OTHER.md +5 -5
- package/README.md +7 -8
- package/bin/clawclaw-channel.mjs +2 -2
- package/bin/clawclaw-cli.mjs +2 -2
- package/docs/configuration.md +25 -99
- package/docs/custom-modules/README.md +27 -40
- package/docs/custom-modules/api-reference.md +132 -273
- package/docs/custom-modules/behavior.md +185 -75
- package/docs/custom-modules/examples/auto-escape.ts +41 -0
- package/docs/custom-modules/examples/go-to-point.ts +11 -11
- package/docs/custom-modules/examples/nearby-reflex.ts +22 -0
- package/docs/custom-modules/examples/task-reminder.ts +4 -5
- package/docs/custom-modules/perception.md +46 -806
- package/docs/custom-modules/skill.md +1 -1
- package/docs/desktop-event-push.md +3 -3
- package/docs/runtime/README.md +18 -19
- package/docs/runtime/agent-notifications.md +31 -12
- package/docs/runtime/behavior-runtime.md +54 -48
- package/docs/runtime/components-and-boundaries.md +87 -137
- package/docs/runtime/events-and-state.md +52 -17
- package/docs/runtime/framework-package.md +73 -0
- package/docs/runtime/official-perception-modules.md +5 -5
- package/docs/runtime/owner-lifecycle-and-observability.md +6 -6
- package/docs/runtime/short-commands-and-capabilities.md +8 -9
- package/docs/user-guide/README.md +12 -9
- package/docs/user-guide/api-reference.md +132 -180
- package/docs/user-guide/behavior.md +175 -65
- package/docs/user-guide/installation.md +7 -7
- package/docs/user-guide/perception.md +46 -789
- package/docs/user-guide/skill.md +1 -1
- package/package.json +24 -9
- package/scripts/check-framework-boundaries.mjs +27 -0
- package/scripts/check-skill-command-surface.mjs +9 -14
- package/scripts/install-local-runtime.mjs +35 -0
- package/scripts/qa-install.mjs +105 -0
- package/skills/clawclaw/SKILL.md +50 -48
- package/skills/clawclaw/references/BEHAVIORS.md +45 -65
- package/skills/clawclaw/references/CHANNELS.md +2 -2
- package/skills/clawclaw/references/COMMANDS.md +65 -87
- package/skills/clawclaw/references/CUSTOM-BEHAVIOR-DEVELOPMENT.md +185 -75
- package/skills/clawclaw/references/CUSTOM-MODULE-API.md +145 -198
- package/skills/clawclaw/references/CUSTOM-MODULES.md +28 -29
- package/skills/clawclaw/references/CUSTOM-PERCEPTION-DEVELOPMENT.md +46 -811
- package/skills/clawclaw/references/CUSTOM-SKILL-DEVELOPMENT.md +1 -1
- package/skills/clawclaw/references/HUB.md +1 -1
- package/skills/clawclaw/references/STREAM.md +8 -8
- package/skills/clawclaw/references/TACTICS.md +1 -1
- package/src/channel/claude-channel-ipc-server.ts +1 -0
- package/src/cli.ts +4 -2
- package/src/commands/behavior.ts +49 -104
- package/src/commands/capability.ts +3 -3
- package/src/commands/load.ts +18 -25
- package/src/commands/module-runtime-control.ts +113 -0
- package/src/commands/perception.ts +23 -4
- package/src/commands/strategy.ts +2 -0
- package/src/commands/trigger.ts +1 -1
- package/src/lib/capability-load-diagnostics.ts +3 -3
- package/src/lib/perception-config.ts +18 -6
- package/src/lib/runtime-cadence-config.ts +16 -0
- package/src/lib/workspace-runtime-lock.ts +3 -46
- package/src/pipeline/canonical-event-presentation.ts +23 -124
- package/src/pipeline/event-format.ts +12 -21
- package/src/pipeline/event-hints.ts +6 -6
- package/src/pipeline/game-sync-event-normalization.ts +57 -63
- package/src/runtime/clawclaw/behavior-decision.ts +7 -3
- package/src/runtime/clawclaw/behavior-input.ts +8 -4
- package/src/runtime/clawclaw/behavior-observation-memory.ts +3 -2
- package/src/runtime/clawclaw/behavior-read-api.ts +4 -0
- package/src/runtime/clawclaw/behavior-reflex-control.ts +74 -0
- package/src/runtime/clawclaw/notification-policy.ts +42 -0
- package/src/runtime/clawclaw/notification-turn.ts +19 -0
- package/src/runtime/clawclaw/observation-frame-projector.ts +3 -3
- package/src/runtime/clawclaw/owner.ts +67 -8
- package/src/runtime/clawclaw/perception-module-manifest.ts +22 -8
- package/src/runtime/clawclaw/perception-strategy-names.ts +17 -0
- package/src/runtime/clawclaw/persistence-compatibility.ts +36 -0
- package/src/runtime/clawclaw/plugins/action/action-plugin.ts +3 -3
- package/src/runtime/clawclaw/plugins/assembly.ts +29 -41
- package/src/runtime/clawclaw/plugins/behavior/activation-manager.ts +1 -482
- package/src/runtime/clawclaw/plugins/behavior/behavior-analysis-thread-host.ts +17 -186
- package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.ts +2 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-instance-snapshot.ts +1 -123
- package/src/runtime/clawclaw/plugins/behavior/behavior-normalization.ts +3 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +126 -1707
- package/src/runtime/clawclaw/plugins/behavior/behavior-runner.ts +13 -271
- package/src/runtime/clawclaw/plugins/behavior/behavior-source.ts +2 -2
- package/src/runtime/clawclaw/plugins/behavior/behavior-worker-bridge.ts +8 -0
- package/src/runtime/clawclaw/plugins/behavior/control-driver.ts +3 -180
- package/src/runtime/clawclaw/plugins/behavior/thread-behavior-executor.ts +13 -960
- package/src/runtime/clawclaw/plugins/derived-event/derived-event-plugin.ts +9 -107
- package/src/runtime/clawclaw/plugins/derived-event/derived-event-rules.ts +5 -4
- package/src/runtime/clawclaw/plugins/derived-event/reminder-plugin.ts +27 -17
- package/src/runtime/clawclaw/plugins/derived-event/reminder-runner.ts +1 -0
- package/src/runtime/clawclaw/plugins/derived-event/state-change-rules.ts +84 -0
- package/src/runtime/clawclaw/plugins/derived-event/task-change-tracker.ts +1 -0
- package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.ts +4 -4
- package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-adapter.ts +9 -97
- package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-socket.ts +8 -343
- package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.ts +60 -572
- package/src/runtime/clawclaw/plugins/mailbox/desktop-event-socket.ts +6 -434
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-event-batch-delivery.ts +1 -266
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.ts +6 -161
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-presentation.ts +4 -23
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.ts +49 -752
- package/src/runtime/clawclaw/plugins/perception/map-concurrent.ts +1 -0
- package/src/runtime/clawclaw/plugins/perception/notification-content.ts +60 -0
- package/src/runtime/clawclaw/plugins/perception/perception-module-plugin.ts +136 -0
- package/src/runtime/clawclaw/plugins/perception/perception-module-runner.ts +13 -0
- package/src/runtime/clawclaw/plugins/perception/perception-module-worker.ts +13 -24
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +19 -8
- package/src/runtime/clawclaw/plugins/perception/perception-source.ts +23 -15
- package/src/runtime/clawclaw/plugins/perception/task-baseline.ts +29 -0
- package/src/runtime/clawclaw/plugins/source/source-plugin.ts +8 -103
- package/src/runtime/clawclaw/plugins/system-perception/rule-runner.ts +107 -0
- package/src/runtime/clawclaw/plugins/system-perception/system-perceptions.ts +107 -0
- package/src/runtime/clawclaw/plugins/trigger/contracts.ts +3 -1
- package/src/runtime/clawclaw/plugins/trigger/trigger-module-loader.ts +5 -2
- package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.ts +69 -13
- package/src/runtime/clawclaw/plugins/trigger/trigger-thread-pool.ts +13 -1
- package/src/runtime/clawclaw/plugins/trigger/trigger-thread-worker.ts +4 -0
- package/src/runtime/clawclaw/reaction-behavior-resolution.ts +1 -23
- package/src/runtime/clawclaw/reaction-manifest.ts +18 -12
- package/src/runtime/clawclaw/reminder-manifest.ts +5 -2
- package/src/runtime/clawclaw/runtime-cadence.ts +24 -0
- package/src/runtime/clawclaw/runtime-state.ts +12 -1
- package/src/runtime/clawclaw/runtime.ts +11 -3
- package/src/runtime/clawclaw/strategy-memory-rpc.ts +1 -0
- package/src/runtime/clawclaw/strategy-memory.ts +1 -0
- package/src/runtime/clawclaw-event-catalog.ts +17 -17
- package/src/runtime/framework/action-diagnostics.ts +3 -83
- package/src/runtime/framework/capability-registry.ts +2 -395
- package/src/runtime/framework/contracts.ts +2 -144
- package/src/runtime/framework/control/control-scheduler.ts +2 -1268
- package/src/runtime/framework/control/domain-set.ts +2 -81
- package/src/runtime/framework/control/index.ts +1 -3
- package/src/runtime/framework/control/types.ts +2 -191
- package/src/runtime/framework/control-coordinator.ts +2 -11
- package/src/runtime/framework/events/event-catalog.ts +2 -74
- package/src/runtime/framework/events/event-delivery-service.ts +2 -200
- package/src/runtime/framework/events/event-ingress.ts +2 -99
- package/src/runtime/framework/events/event-repository.ts +2 -82
- package/src/runtime/framework/events/index.ts +2 -7
- package/src/runtime/framework/events/memory-event-repository.ts +2 -1100
- package/src/runtime/framework/events/runtime-resume.ts +2 -20
- package/src/runtime/framework/events/sqlite-event-repository.ts +5 -2280
- package/src/runtime/framework/events/test-helpers.ts +1 -1
- package/src/runtime/framework/events/types.ts +2 -312
- package/src/runtime/framework/index.ts +3 -7
- package/src/runtime/framework/load-node-sqlite.ts +2 -17
- package/src/runtime/framework/mailbox/coalescer.ts +2 -83
- package/src/runtime/framework/mailbox/host-notification-sink.ts +2 -44
- package/src/runtime/framework/mailbox/identity.ts +2 -38
- package/src/runtime/framework/mailbox/index.ts +1 -7
- package/src/runtime/framework/mailbox/mailbox-dispatcher.ts +2 -282
- package/src/runtime/framework/mailbox/mailbox-repository.ts +2 -44
- package/src/runtime/framework/mailbox/notification-projector.ts +2 -65
- package/src/runtime/framework/mailbox/types.ts +2 -145
- package/src/runtime/framework/modules/runtime-module-loader-hooks.mjs +2 -154
- package/src/runtime/framework/modules/runtime-module-loader.ts +7 -51
- package/src/runtime/framework/modules/runtime-module-output.ts +2 -24
- package/src/runtime/framework/modules/runtime-module-worker-bootstrap.mjs +3 -23
- package/src/runtime/framework/participation-manager.ts +2 -253
- package/src/runtime/framework/persistence/async-sqlite-persistence-worker.ts +2 -77
- package/src/runtime/framework/persistence/memory-first-persistence.ts +4 -489
- package/src/runtime/framework/plugins/contracts.ts +2 -388
- package/src/runtime/framework/plugins/index.ts +1 -4
- package/src/runtime/framework/plugins/runtime-event-identity.ts +2 -17
- package/src/runtime/framework/plugins/runtime-input-journal.ts +2 -866
- package/src/runtime/framework/plugins/runtime-plugin-scheduler.ts +2 -2060
- package/src/runtime/framework/runtime.ts +5 -1843
- package/src/runtime/framework/serial-task-queue.ts +2 -14
- package/src/runtime/framework/state/contracts.ts +2 -49
- package/src/runtime/framework/state/current-state-store.ts +2 -184
- package/src/runtime/framework/state/durable-agent-state-snapshot.ts +2 -209
- package/src/runtime/framework/state/freshness.ts +2 -72
- package/src/runtime/framework/state/history/contracts.ts +2 -158
- package/src/runtime/framework/state/history/history-writer.ts +2 -194
- package/src/runtime/framework/state/history/memory-state-history-repository.ts +2 -230
- package/src/runtime/framework/state/history/sqlite-state-history-repository.ts +2 -648
- package/src/runtime/framework/state/history/trajectory-projector.ts +2 -209
- package/src/runtime/framework/state/index.ts +1 -13
- package/src/runtime/framework/state/state-ingress.ts +2 -95
- package/src/runtime/framework/state/state-provider.ts +2 -62
- package/src/runtime/framework/state/types.ts +2 -155
- package/src/runtime/host-monitor-rate-gate.ts +1 -123
- package/src/runtime/mailbox-host-relay.ts +1 -326
- package/src/runtime/observability/detail-capture.ts +4 -108
- package/src/runtime/observability/process-timing.ts +2 -59
- package/src/runtime/observability/recorder.ts +2 -238
- package/src/runtime/observability/redaction.ts +2 -181
- package/src/runtime/observability/reporter.ts +2 -154
- package/src/runtime/observability/sinks.ts +2 -135
- package/src/runtime/observability/types.ts +2 -92
- package/src/runtime/owner-control.ts +45 -315
- package/src/runtime/parent-process-watch.ts +1 -51
- package/src/runtime/process-identity.ts +1 -72
- package/src/sdk/behavior-plugin/index.ts +13 -4
- package/src/sdk/index.ts +44 -3
- package/src/sdk/module-input/index.ts +5 -0
- package/src/sdk/perception-plugin/index.ts +9 -5
- package/src/sdk/perception-plugin/module.ts +25 -6
- package/src/sdk/perception-plugin/reaction.ts +1 -1
- package/src/sdk/perception-plugin/reminder-rules.ts +8 -42
- package/src/sdk/perception-plugin/reminder.ts +2 -1
- package/src/{runtime/clawclaw/plugins/source → sdk/perception-plugin}/task-change-tracker.ts +1 -2
- package/src/sdk/strategy-memory.ts +1 -0
- package/src/sdk/strategy-plugin/index.ts +36 -0
- package/src/sdk/trigger-plugin/index.ts +4 -3
- package/docs/custom-modules/examples/nearby-escape.ts +0 -56
- package/docs/custom-modules/examples/nearby-notice.ts +0 -36
- package/docs/custom-modules/trigger.md +0 -295
- package/src/runtime/clawclaw/behavior-activation-capability.ts +0 -21
- package/src/runtime/clawclaw/plugins/perception/reaction-plugin.ts +0 -233
- package/src/runtime/clawclaw/plugins/perception/reaction-runner.ts +0 -49
- package/src/runtime/clawclaw/plugins/perception/reaction-worker.ts +0 -26
- /package/src/runtime/clawclaw/plugins/{source → derived-event}/player-change-tracker.ts +0 -0
|
@@ -2,32 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
这是一份查接口、字段和约束的参考手册,不重复讲模块生命周期、执行模式选择或完整开发流程。需要教程时分别阅读:
|
|
4
4
|
|
|
5
|
-
- [开发
|
|
5
|
+
- [开发 Strategy](./behavior.md)
|
|
6
6
|
- [感知开发总览](./perception.md)
|
|
7
|
-
- [视觉感知](./perception.md#视觉感知)、[提醒型感知](./perception.md#提醒型感知)、[反应型感知](./perception.md#反应型感知)
|
|
8
|
-
- [开发 Trigger](./trigger.md)
|
|
9
7
|
- [自定义模块总览](./README.md)
|
|
10
8
|
|
|
11
|
-
本文按模块组织;每个模块内部依次说明 Runtime
|
|
9
|
+
本文按模块组织;每个模块内部依次说明 Runtime 主动输入、查询 API、允许输出和 Manifest;策略与感知提供局内记忆 api.memory。策略与感知共用的数据结构统一放在文末。
|
|
12
10
|
|
|
13
|
-
| 模块 | Runtime 主动输入 |
|
|
11
|
+
| 模块 | Runtime 主动输入 | 查询与私有能力 | 允许输出 |
|
|
14
12
|
|---|---|---|---|
|
|
15
|
-
|
|
|
16
|
-
| 统一感知 API v3 | State
|
|
17
|
-
| Perception(视觉,v2 兼容) | `ObservationFrame` | 静态地图 | 感知 Event |
|
|
18
|
-
| Reminder(v2 兼容) | GameState、观察帧、订阅事实、任务变化、配置、私有 state | 无查询 API | 任务或附近发言提醒、下一轮私有 state |
|
|
19
|
-
| Reaction(v2 兼容) | GameState、观察帧、订阅事件、配置、私有 state | 无查询 API | 自己的通知、固定策略激活请求、下一轮私有 state |
|
|
20
|
-
| Trigger | `ObservationFrame`、订阅的后端 Event、规则参数 | 地图、路径距离、最近观察 | `TriggerMatch` |
|
|
13
|
+
| Strategy | 当前 `GameState`、待处理 Event、Activation 参数 | 地图、路径距离、最近观察、api.memory | Action、Status、自定义 Event、结束结果 |
|
|
14
|
+
| 统一感知 API v3 | State、观察帧、源/后端原始事件、任务变化、参数和私有状态 | api.memory | 事件、私有状态、固定反射请求 |
|
|
21
15
|
|
|
22
|
-
|
|
16
|
+
游戏输入和查询结果都是当前回调内的只读值;api.memory 则是显式读写的策略私有数据。任何模块都不能直接修改权威 `GameState`。
|
|
23
17
|
|
|
24
|
-
普通任务变化提醒使用[ClawclawReminder(Perception API v2)](./perception.md#提醒型感知)。下表中的 Perception 专指原有视觉 API v2。
|
|
25
18
|
|
|
26
19
|
### 开发时到哪里取信息
|
|
27
20
|
|
|
28
|
-
下面是当前已实现的输入边界。感知列中的路径以 `frame.gameState` 为起点;
|
|
21
|
+
下面是当前已实现的输入边界。感知列中的路径以 `frame.gameState` 为起点;Strategy 列以 `input.gameState` 为起点。两者读取同一种玩家视角 GameState,不包含隐藏玩家的全知状态。
|
|
29
22
|
|
|
30
|
-
| 想获得的信息 | Perception |
|
|
23
|
+
| 想获得的信息 | Perception | Strategy |
|
|
31
24
|
|---|---|---|
|
|
32
25
|
| 自己的位置、角色、生死、当前动作 | `gameState.you`,动作在 `you.activity` | 同左 |
|
|
33
26
|
| 自己的任务及状态、全队任务进度 | `you.tasks`、`task_progress` | 同左 |
|
|
@@ -41,7 +34,7 @@
|
|
|
41
34
|
| 地图和路径 | `api.spatial`;没有路径查询 | `api.spatial`、`api.navigation` |
|
|
42
35
|
| 房间/匹配状态、网络原始帧、HTTP ACK | 不在当前 Perception 公共输入内 | 不作为上述 GameState/查询 API 的输入;动作结果通过权威 State/Event 确认 |
|
|
43
36
|
|
|
44
|
-
|
|
37
|
+
“能读取某字段”不等于“该模块负责生成该类事件”。感知可以组合观察、提醒和反射判断;固定任务、能力及紧急通知由各自内置感知负责,自定义模块提供职责不同的信息。
|
|
45
38
|
|
|
46
39
|
缺失字段表示未提供,不应当作 0、false 或空集合。`emergency.remaining_secs` 也可能为 `null`;不能据此推断已到期。State 说明当前情况;事件保留具体发生经过和原因,两者不能互相完全替代。
|
|
47
40
|
|
|
@@ -65,7 +58,7 @@
|
|
|
65
58
|
```ts
|
|
66
59
|
import {
|
|
67
60
|
getAvailableTasks, getTaskAvailability, isTaskAvailable,
|
|
68
|
-
} from '@myclaw163/clawclaw-cli/
|
|
61
|
+
} from '@myclaw163/clawclaw-cli/strategy-plugin';
|
|
69
62
|
|
|
70
63
|
const allTasks = input.gameState.you?.tasks; // 保留完整任务,可做后续规划
|
|
71
64
|
const candidates = getAvailableTasks(input.gameState); // 仅当前 ready 的个人任务
|
|
@@ -83,65 +76,80 @@ const maySelect = candidates[0] && isTaskAvailable(input.gameState, candidates[0
|
|
|
83
76
|
|
|
84
77
|
`ready` 不保证动作一定成功:距离、路径、队友占用等最终执行条件仍由 Action/服务端校验。任务动作只提交一次,之后从权威 State/Event 确认结果,不能每帧重复请求。未使用这些判断的第三方旧脚本需要修改,恢复完整列表不会自动修正它的选任务逻辑。
|
|
85
78
|
|
|
79
|
+
## 固定周期输入
|
|
80
|
+
|
|
81
|
+
生产 Owner 按本地固定周期调用 v3 感知和策略,默认 100ms;cycle 为可选 ProcessingCycleInfo,可从 Strategy 或 Perception SDK 导入。旧作者测试输入可以省略它。
|
|
82
|
+
|
|
83
|
+
| `cycle` 字段 | 含义 |
|
|
84
|
+
|---|---|
|
|
85
|
+
| `id` / `intervalMs` | 本地周期编号与目标周期;慢计算时实际间隔可更长,不是游戏 tick |
|
|
86
|
+
| `nowMs` | 本地周期开始时间,与 input.nowMs 一致 |
|
|
87
|
+
| `hasNewState` | 相对上一正常 CCL 计算周期是否接纳了新 State;查询/通知排空不消耗该标记,不做内容深比较 |
|
|
88
|
+
| `stateVersion` | 最新 State 的接纳版本;脚本可与自己上次处理的版本比较 |
|
|
89
|
+
| `stateReceivedAtMs` / `stateAgeMs` | 实际状态接收时间及到本轮边界的年龄;本地空周期和查询不会刷新它 |
|
|
90
|
+
| `connectionState` | 当前连接状态,便于脚本判断是否等待恢复 |
|
|
91
|
+
|
|
92
|
+
没有可用 State 时,版本与接收时间可为 null。首次对局 State 到达前策略仍等待;有可用观察后,不因后端没有新 tick 而停止调用。感知与策略的私有记忆、decisionHistory、既有历史输入保持原有含义;不新增共同 State 历史接口。
|
|
93
|
+
|
|
86
94
|
## 统一感知 API v3
|
|
87
95
|
|
|
88
|
-
从公开 perception-plugin 入口导入 ClawclawPerception、PerceptionModuleInput、PerceptionModuleResult、PerceptionModuleEvent 和 PerceptionModuleManifest;版本常量为 PERCEPTION_MODULE_API_VERSION=3。新脚本没有三选一的 kind,通过同一个 evaluate(input)
|
|
96
|
+
从公开 perception-plugin 入口导入 ClawclawPerception、PerceptionModuleInput、PerceptionModuleResult、PerceptionModuleEvent 和 PerceptionModuleManifest;版本常量为 PERCEPTION_MODULE_API_VERSION=3。新脚本没有三选一的 kind,通过同一个 evaluate(input) 组合观察、通知和私有记忆。
|
|
89
97
|
|
|
90
|
-
Manifest 的必需项为 apiVersion:3、id、description;可选 name、localizations、consumes、produces、
|
|
98
|
+
Manifest 的必需项为 apiVersion:3、id、description;可选 name、localizations、consumes、produces、inputs、config、strategies。输入包含 moduleId、scope、gameState、frame、events、taskChanges、boundary、nowMs、cycle、config、state、availableBindings、availableStrategies、enabledBindings。frame/gameState 可以为 null;events 只含订阅的源/后端原始事实,taskChanges 由该模块自己的基线与本轮权威任务列表比较得到,结合同轮后端事实;不是订阅 tasks_changed。 内置任务感知及 evaluateReminder('tasks') 只把后端 task_* 事实转为基础任务通知,不按 taskChanges 再输出同一信息;紧急生命周期和阈值由内置紧急感知负责。
|
|
91
99
|
|
|
92
100
|
结果为 { state?, events?, activations? }。events 项为 { type, key, wakeAgent?, payload },type 必须在 produces 中声明,key 是稳定发生标识,wakeAgent 省略为 true。false 不独立唤醒且保留事件;不生成事件表示没有这条通知。事件类型的可见范围仍受 Catalog 和配置约束,模块不能重写原始事件或其他模块的通知。
|
|
93
101
|
|
|
94
|
-
behaviors 使用固定 key 声明 name、可选 resourceId、layer、input、reflexPriority、cooldownMs、rearm 和 maxRuntimeMs;activations 项引用 { behavior, input?, reason? }。layer 默认 reflex,可指定 short/long。目标按 Hub ID 优先、同名和别名兜底解析;依赖缺失只影响对应绑定。激活不等于动作完成。
|
|
95
102
|
|
|
96
|
-
每次计算使用 fresh 实例,跨回调状态必须从 input.state 读取并作为结果 state 返回,由 Host 检查点恢复。新脚本不能订阅其他感知、
|
|
103
|
+
每次计算使用 fresh 实例,跨回调状态必须从 input.state 读取并作为结果 state 返回,由 Host 检查点恢复。新脚本不能订阅其他感知、Strategy 或 decision 输出;运行时还按 producerPluginId 过滤,只接纳 Source/后端原始事实。produces 不能冒充系统保留类型;reminder.task/reminder.speech 是兼容通知输出,不是权威任务事实。
|
|
97
104
|
|
|
98
|
-
|
|
105
|
+
感知可请求固定 Reflex,感知和策略分别装配。
|
|
99
106
|
|
|
100
|
-
##
|
|
107
|
+
## Strategy API
|
|
101
108
|
|
|
102
109
|
导入入口与当前版本:
|
|
103
110
|
|
|
104
111
|
```ts
|
|
105
112
|
import {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
} from '@myclaw163/clawclaw-cli/
|
|
113
|
+
STRATEGY_PLUGIN_API_VERSION,
|
|
114
|
+
ClawclawStrategy,
|
|
115
|
+
} from '@myclaw163/clawclaw-cli/strategy-plugin';
|
|
109
116
|
|
|
110
|
-
//
|
|
117
|
+
// STRATEGY_PLUGIN_API_VERSION === 3
|
|
111
118
|
```
|
|
112
119
|
|
|
113
|
-
### Runtime 输入:`
|
|
120
|
+
### Runtime 输入:`StrategyInput<TInput>`
|
|
114
121
|
|
|
115
122
|
```ts
|
|
116
|
-
interface
|
|
123
|
+
interface StrategyInput<TInput extends Readonly<Record<string, unknown>>> {
|
|
117
124
|
readonly epochId: number;
|
|
125
|
+
readonly cycle?: ProcessingCycleInfo;
|
|
118
126
|
readonly scope: Readonly<{ sessionId: string; segmentId: string }>;
|
|
119
127
|
readonly nowMs: number;
|
|
120
128
|
readonly gameState: Readonly<GameState>;
|
|
121
129
|
readonly events: readonly Readonly<GameEvent>[];
|
|
122
130
|
readonly input: Readonly<TInput>;
|
|
123
|
-
readonly decisionHistory?: readonly Readonly<
|
|
124
|
-
readonly continuation?: Readonly<
|
|
131
|
+
readonly decisionHistory?: readonly Readonly<StrategyDecisionFrame>[];
|
|
132
|
+
readonly continuation?: Readonly<StrategyContinuation>;
|
|
125
133
|
}
|
|
126
134
|
```
|
|
127
135
|
|
|
128
136
|
| 字段 | 含义 |
|
|
129
137
|
|---|---|
|
|
130
|
-
| `epochId` | Runtime
|
|
138
|
+
| `epochId` | 本次计算的 Runtime 编号;本地周期编号看 cycle.id,不是游戏 tick |
|
|
131
139
|
| `scope` | 当前 Runtime session 与 segment |
|
|
132
|
-
| `nowMs` |
|
|
140
|
+
| `nowMs` | 本地计算周期的时间;后端观察接收时间看 cycle.stateReceivedAtMs |
|
|
133
141
|
| `gameState` | 当前玩家视角的权威 GameSync 快照 |
|
|
134
142
|
| `events` | 该 Activation 尚未消费的有序 Event 片段 |
|
|
135
143
|
| `input` | 按 Manifest 校验并经可选 `normalize()` 处理后的 Activation 参数 |
|
|
136
144
|
| `continuation` | 仅 long 委派的 short 结束并恢复后出现一次;包含 Runtime 生成的 child 终态 |
|
|
137
145
|
| `decisionHistory` | 当前 Activation 最近最多 100 帧的决策记录;当前 Runtime 会提供,类型可选以兼容旧测试输入 |
|
|
138
146
|
|
|
139
|
-
`events`
|
|
147
|
+
`events` 按本 Strategy 的游标提供尚未消费的事实;正常周期不依赖后端 tick 前进。脚本返回空 Decision 也属于一次已处理输入;需要跨轮保留的信息应自行存入私有状态。
|
|
140
148
|
|
|
141
149
|
`decisionHistory` 是当前 Activation 的有界内存快照,不是全局 State/Event 历史,也不表示 Action 已在后端执行成功。它不会跨 Runtime 重启持久恢复;不可据此重放动作。每帧结构为:
|
|
142
150
|
|
|
143
151
|
```ts
|
|
144
|
-
interface
|
|
152
|
+
interface StrategyDecisionFrame {
|
|
145
153
|
readonly epochId: number;
|
|
146
154
|
readonly tick: number;
|
|
147
155
|
readonly instanceGeneration: number;
|
|
@@ -153,10 +161,10 @@ interface BehaviorDecisionFrame {
|
|
|
153
161
|
|
|
154
162
|
`actions` 在有完成的 Decision 时为数组(可为空),没有 Decision 结果时为 `null`。
|
|
155
163
|
|
|
156
|
-
### 查询:`
|
|
164
|
+
### 查询:`StrategyReadApi`
|
|
157
165
|
|
|
158
166
|
```ts
|
|
159
|
-
interface
|
|
167
|
+
interface StrategyReadApi {
|
|
160
168
|
readonly spatial: SpatialApi;
|
|
161
169
|
readonly navigation: {
|
|
162
170
|
pathDistance(from: Readonly<Position>, to: Readonly<Position>): Promise<number | null>;
|
|
@@ -259,15 +267,15 @@ const corpse = api.observation.lastSeenCorpse(targetSeat);
|
|
|
259
267
|
|
|
260
268
|
省略 `targetSeat` 时返回最近观察到的尸体;没有记录时返回 `undefined`。最近观察是历史事实,使用前必须结合 `ageMs` 与当前 `gameState` 复核。
|
|
261
269
|
|
|
262
|
-
### 输出:`
|
|
270
|
+
### 输出:`StrategyDecision`
|
|
263
271
|
|
|
264
272
|
```ts
|
|
265
|
-
interface
|
|
273
|
+
interface StrategyDecision {
|
|
266
274
|
readonly actions?: readonly Readonly<GameAction>[];
|
|
267
|
-
readonly status?: Readonly<
|
|
268
|
-
readonly events?: readonly Readonly<
|
|
269
|
-
readonly delegate?: Readonly<
|
|
270
|
-
readonly finish?: Readonly<
|
|
275
|
+
readonly status?: Readonly<StrategyStatus>;
|
|
276
|
+
readonly events?: readonly Readonly<StrategyEventProposal>[];
|
|
277
|
+
readonly delegate?: Readonly<StrategyDelegation>;
|
|
278
|
+
readonly finish?: Readonly<StrategyFinish>;
|
|
271
279
|
}
|
|
272
280
|
```
|
|
273
281
|
|
|
@@ -279,7 +287,7 @@ interface BehaviorDecision {
|
|
|
279
287
|
- Action 只是一项请求,仍会经过控制权、阶段、角色和安全检查;
|
|
280
288
|
- 未列出的字段会被拒绝,不会透传给后端;
|
|
281
289
|
- 玩家控制目标只使用数字座位,不使用姓名;
|
|
282
|
-
-
|
|
290
|
+
- Strategy 不读取 HTTP ACK 或 Action receipt,应通过后续权威 State/Event 判断业务目标是否完成。
|
|
283
291
|
|
|
284
292
|
#### `move`:移动到房间
|
|
285
293
|
|
|
@@ -318,7 +326,7 @@ interface BehaviorDecision {
|
|
|
318
326
|
}
|
|
319
327
|
```
|
|
320
328
|
|
|
321
|
-
`target_seat` 必须是 `1..10` 的整数。
|
|
329
|
+
`target_seat` 必须是 `1..10` 的整数。Strategy 应先自行追踪目标、复核可见性、距离、角色能力和冷却,再提交击杀请求,并从后续 State/Event 确认结果。
|
|
322
330
|
|
|
323
331
|
#### `speech`
|
|
324
332
|
|
|
@@ -348,7 +356,7 @@ interface BehaviorDecision {
|
|
|
348
356
|
{ action: 'report' }
|
|
349
357
|
```
|
|
350
358
|
|
|
351
|
-
`report` 没有目标字段;后端报告当前范围内可报告的尸体。
|
|
359
|
+
`report` 没有目标字段;后端报告当前范围内可报告的尸体。Strategy 可用尸体座位选择导航目标,但不能把座位或姓名放进 Action payload。
|
|
352
360
|
|
|
353
361
|
#### `think`
|
|
354
362
|
|
|
@@ -358,12 +366,12 @@ interface BehaviorDecision {
|
|
|
358
366
|
|
|
359
367
|
独立 `trigger_alarm` 动作已移除。旧代码应改为在 `GameCrabSabotage.status === 'ready'` 时提交自己持有的破坏任务;不要在任务完成后再请求第二个动作。
|
|
360
368
|
|
|
361
|
-
会议投票不属于 `GameAction`。Agent 或用户在会议阶段使用现有 `ccl vote`,由 Action Plugin 直接提交后端;
|
|
369
|
+
会议投票不属于 `GameAction`。Agent 或用户在会议阶段使用现有 `ccl vote`,由 Action Plugin 直接提交后端;Strategy 不预占 `meeting_vote` 控制域。
|
|
362
370
|
|
|
363
|
-
#### `
|
|
371
|
+
#### `StrategyStatus`
|
|
364
372
|
|
|
365
373
|
```ts
|
|
366
|
-
interface
|
|
374
|
+
interface StrategyStatus {
|
|
367
375
|
readonly summary: string;
|
|
368
376
|
readonly activity?: string;
|
|
369
377
|
readonly room?: string;
|
|
@@ -375,10 +383,10 @@ interface BehaviorStatus {
|
|
|
375
383
|
|
|
376
384
|
`summary` 必须是非空字符串,其余文本字段提供时也必须非空。Status 会发布到 Runtime 的 `behavior.status` 视图;它不是 `GameState` patch,也不是模块私有持久化存储。
|
|
377
385
|
|
|
378
|
-
#### `
|
|
386
|
+
#### `StrategyEventProposal`
|
|
379
387
|
|
|
380
388
|
```ts
|
|
381
|
-
interface
|
|
389
|
+
interface StrategyEventProposal {
|
|
382
390
|
readonly type: string;
|
|
383
391
|
readonly payload: Readonly<Record<string, unknown>>;
|
|
384
392
|
readonly occurredAt?: string;
|
|
@@ -387,21 +395,21 @@ interface BehaviorEventProposal {
|
|
|
387
395
|
|
|
388
396
|
`type` 必须先列在 `manifest.produces` 中;`payload` 必须是普通 JSON 对象。Event 应表示模块已经确认成立的事实。
|
|
389
397
|
|
|
390
|
-
#### `
|
|
398
|
+
#### `StrategyDelegation`
|
|
391
399
|
|
|
392
400
|
```ts
|
|
393
|
-
interface
|
|
394
|
-
readonly
|
|
401
|
+
interface StrategyDelegation {
|
|
402
|
+
readonly strategy: string;
|
|
395
403
|
readonly input?: Readonly<Record<string, unknown>>;
|
|
396
404
|
}
|
|
397
405
|
```
|
|
398
406
|
|
|
399
|
-
只有当前 long Activation 可以使用 `delegate` 启动一个 short。Runtime 会先通过
|
|
407
|
+
只有当前 long Activation 可以使用 `delegate` 启动一个 short。Runtime 会先通过 Strategy Catalog 校验目标与输入,再改变控制栈。`delegate` 不能与 `actions` 或 `finish` 同时返回;short/reflex 使用会让当前 Activation failed。委派 short 的终态通过 long 恢复后的 `continuation.delegatedBehavior` 一次性返回。
|
|
400
408
|
|
|
401
|
-
#### `
|
|
409
|
+
#### `StrategyFinish`
|
|
402
410
|
|
|
403
411
|
```ts
|
|
404
|
-
interface
|
|
412
|
+
interface StrategyFinish {
|
|
405
413
|
readonly outcome: 'completed' | 'failed';
|
|
406
414
|
readonly reason: string;
|
|
407
415
|
readonly summary?: string;
|
|
@@ -410,26 +418,26 @@ interface BehaviorFinish {
|
|
|
410
418
|
|
|
411
419
|
`reason` 必须是非空、稳定、适合程序判断的原因。Runtime 不允许同一 Decision 同时首次提交 Action 并 `finish` 或 `delegate`;应先请求 Action,再在后续权威输入确认目标后结束或委派。
|
|
412
420
|
|
|
413
|
-
### Manifest:`
|
|
421
|
+
### Manifest:`ClawclawStrategyManifest`
|
|
414
422
|
|
|
415
423
|
首次自动上传 Hub 时,默认展示名称取脚本 `id`,默认展示描述取脚本 `description`,分别按 Hub 的 50/600 字符限制截取。之后 Hub 名称、描述独立维护,CCL 随装配版本缓存,用于人类界面和当前策略上报;修改脚本说明不会覆盖 Hub 文案。`ccl load` 和模块详情仍向 Agent 提供脚本描述。本地尚未上传或离线时使用本地登记、缓存的展示信息。新脚本无需填写模块级 `name`,已有脚本仍可读取;感知事件的 `eventMetadata.name`、参数说明和玩家名字不受影响。
|
|
416
424
|
|
|
417
425
|
| 字段 | 类型 | 约束 |
|
|
418
426
|
|---|---|---|
|
|
419
|
-
| `apiVersion` | `3` | 必须等于 `
|
|
427
|
+
| `apiVersion` | `3` | 必须等于 `STRATEGY_PLUGIN_API_VERSION` |
|
|
420
428
|
| `id` | `string` | 稳定且唯一 |
|
|
421
429
|
| `description` | `string` | 非空的 Agent 能力说明 |
|
|
422
430
|
| `name` | `string`,可选 | 兼容已有脚本;新脚本省略,展示信息由 CCL 管理 |
|
|
423
431
|
| `localizations` | object,可选 | 兼容已有脚本的模块文案;人类展示优先采用本地登记或 Hub 下发的文案 |
|
|
424
|
-
| `inputs` | `
|
|
432
|
+
| `inputs` | `StrategyInputFieldSpec[]` | Activation 参数 schema |
|
|
425
433
|
| `execution` | `'parallel' \| 'serial'`,可选 | 省略为 parallel |
|
|
426
434
|
| `stateMode` | `'isolated' \| 'snapshot'`,可选 | 默认 isolated;snapshot 仅支持 parallel,继承同一 activation 内已完成计算的实例快照,不跨进程持久恢复 |
|
|
427
|
-
| `everyTicks` | `number`,可选 |
|
|
435
|
+
| `everyTicks` | `number`,可选 | 旧输入驱动执行器的兼容字段;固定周期 Owner 不据此跳过 decide |
|
|
428
436
|
| `produces` | `string[]`,可选 | 允许发布的自定义 Event type |
|
|
429
|
-
| `runtime` | `
|
|
437
|
+
| `runtime` | `StrategyRuntimeDefaults`,可选 | finite Activation 的默认运行预算 |
|
|
430
438
|
|
|
431
439
|
```ts
|
|
432
|
-
interface
|
|
440
|
+
interface StrategyRuntimeDefaults {
|
|
433
441
|
readonly defaultMs: number;
|
|
434
442
|
readonly deadlineOutcome?: 'completed' | 'failed';
|
|
435
443
|
readonly controlGraceMs?: number;
|
|
@@ -438,7 +446,7 @@ interface BehaviorRuntimeDefaults {
|
|
|
438
446
|
|
|
439
447
|
`defaultMs` 必须是 `1000..120000` 的安全整数;`controlGraceMs` 必须是 `0..30000` 的安全整数。
|
|
440
448
|
|
|
441
|
-
### 参数字段:`
|
|
449
|
+
### 参数字段:`StrategyInputFieldSpec`
|
|
442
450
|
|
|
443
451
|
每个字段都必须包含 `id`、`type` 和非空 `description`。`id` 必须匹配 `[A-Za-z][A-Za-z0-9_.-]{0,79}`。
|
|
444
452
|
|
|
@@ -455,13 +463,13 @@ interface BehaviorRuntimeDefaults {
|
|
|
455
463
|
`required: true` 不能同时声明 `default`。Runtime 不做字符串到数字等隐式转换;Activation 输入中的未知字段会被拒绝。
|
|
456
464
|
`string_list` 或 `player_seats` 标记为 required 时,数组本身也不能为空。
|
|
457
465
|
|
|
458
|
-
### 可选参数整理:`
|
|
466
|
+
### 可选参数整理:`StrategyNormalizationApi`
|
|
459
467
|
|
|
460
468
|
`normalize(input, api)` 只在一次 Activation 启动前调用一次。它可以使用:
|
|
461
469
|
|
|
462
470
|
```ts
|
|
463
|
-
interface
|
|
464
|
-
readonly manifest: Readonly<
|
|
471
|
+
interface StrategyNormalizationApi {
|
|
472
|
+
readonly manifest: Readonly<ClawclawStrategyManifest>;
|
|
465
473
|
timing(input: Readonly<Record<string, unknown>>):
|
|
466
474
|
{ readonly timeout_ms?: number; readonly duration_ms?: number };
|
|
467
475
|
string(value: unknown, field: string): string;
|
|
@@ -482,223 +490,36 @@ interface BehaviorNormalizationApi {
|
|
|
482
490
|
|
|
483
491
|
这里没有动态 `GameState` 或 Action 能力;动态判断放在 `decide()` 中。
|
|
484
492
|
|
|
485
|
-
##
|
|
486
|
-
|
|
487
|
-
### Reaction(感知中的自动触发规则)
|
|
488
|
-
|
|
489
|
-
从 `@myclaw163/clawclaw-cli/perception-plugin` 导入 `ClawclawReaction`、`ReactionInput`、`ReactionResult`。完整示例、参数默认值及缺依赖处理见[反应型感知教程](./perception.md#反应型感知)。
|
|
490
|
-
|
|
491
|
-
`manifest` 为 API v2、`kind: 'reaction'`,声明 `consumes`、`produces`、可选 `behaviors`/`inputs`/`config`。绑定结构为 `{ name, resourceId?, layer?, input?, reflexPriority?, cooldownMs?, rearm?, maxRuntimeMs? }`;ID 优先、同名兜底。
|
|
492
|
-
|
|
493
|
-
`evaluate(input)` 返回 `{ state?, events?, activations? }`。通知使用 `{ type, key, wakeAgent?, payload: { text, ... } }` 且 type 在 `reaction.*` 声明中;激活使用 `{ behavior, input?, reason? }`,引用固定绑定。state 持久到下一次调用,模块实例每次重建。该路径不提供重写其他事件投递策略的接口;同一事件可供所有订阅者各自处理。
|
|
494
|
-
|
|
495
|
-
提醒型感知的主题、输入和输出见[提醒教程](./perception.md#提醒型感知)。以下章节说明视觉类 API,对应[视觉教程](./perception.md#视觉感知);后文 Trigger API 是已有独立脚本的兼容入口。
|
|
496
|
-
|
|
497
|
-
导入入口与当前版本:
|
|
498
|
-
|
|
499
|
-
```ts
|
|
500
|
-
import {
|
|
501
|
-
PERCEPTION_PLUGIN_API_VERSION,
|
|
502
|
-
ClawclawPerception,
|
|
503
|
-
ClawclawParallelPerception,
|
|
504
|
-
} from '@myclaw163/clawclaw-cli/perception-plugin';
|
|
505
|
-
|
|
506
|
-
// PERCEPTION_PLUGIN_API_VERSION === 2
|
|
507
|
-
```
|
|
508
|
-
|
|
509
|
-
### `PerceptionFrame`
|
|
510
|
-
|
|
511
|
-
`PerceptionFrame` 是共享 `ObservationFrame` 的类型别名,字段见[共享观察帧](#共享观察帧)。普通 Perception 的入口是:
|
|
512
|
-
|
|
513
|
-
```ts
|
|
514
|
-
update(
|
|
515
|
-
frame: Readonly<PerceptionFrame>,
|
|
516
|
-
api: PerceptionApi,
|
|
517
|
-
): readonly PerceptionEventProposal[] | void | Promise<readonly PerceptionEventProposal[] | void>;
|
|
518
|
-
```
|
|
519
|
-
|
|
520
|
-
需要 Worker 分析时继承 `ClawclawParallelPerception<TAnalysis>`:
|
|
521
|
-
|
|
522
|
-
```ts
|
|
523
|
-
interface PerceptionAnalysisInput {
|
|
524
|
-
readonly frame: Readonly<PerceptionFrame>;
|
|
525
|
-
readonly history: readonly Readonly<PerceptionFrame>[];
|
|
526
|
-
readonly gapBefore: boolean;
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
analyze(input: Readonly<PerceptionAnalysisInput>, api: PerceptionApi): TAnalysis | Promise<TAnalysis>;
|
|
530
|
-
|
|
531
|
-
commit(
|
|
532
|
-
frame: Readonly<PerceptionFrame>,
|
|
533
|
-
analysis: Readonly<TAnalysis>,
|
|
534
|
-
api: PerceptionApi,
|
|
535
|
-
): readonly PerceptionEventProposal[] | void | Promise<readonly PerceptionEventProposal[] | void>;
|
|
536
|
-
```
|
|
537
|
-
|
|
538
|
-
`history` 只包含旧帧,按时间升序且不包含当前 `frame`;整个窗口最多 10 帧。`gapBefore` 表示已存在前帧,但无法证明轨迹连续。执行模型与状态放置规则见[开发 Perception](./perception.md)。
|
|
539
|
-
|
|
540
|
-
### 查询:`PerceptionApi`
|
|
541
|
-
|
|
542
|
-
```ts
|
|
543
|
-
interface PerceptionApi {
|
|
544
|
-
readonly spatial: SpatialApi;
|
|
545
|
-
}
|
|
546
|
-
```
|
|
547
|
-
|
|
548
|
-
`SpatialApi` 与 Behavior 的 `api.spatial` 相同。Perception 不提供 navigation 或 observation 查询;它应只根据当前/历史观察帧和静态地图形成视觉事实。
|
|
493
|
+
## 独立感知的反射接口与局中控制
|
|
549
494
|
|
|
550
|
-
|
|
495
|
+
感知和 Strategy 是两个资源,必须分别装配。策略只需默认导出 ClawclawStrategy API v3;统一感知 Manifest 可声明固定绑定:
|
|
551
496
|
|
|
552
497
|
```ts
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
readonly dedupeKey: string;
|
|
557
|
-
readonly dedupeScope?: 'segment' | 'session';
|
|
558
|
-
readonly payload: Readonly<Record<string, unknown>>;
|
|
559
|
-
readonly occurredAt?: string;
|
|
498
|
+
strategies: {
|
|
499
|
+
escape: { name: 'community.auto-escape', resourceId: '可选资源ID', layer: 'reflex',
|
|
500
|
+
input: {}, reflexPriority: 40, cooldownMs: 3000, rearm: 'after_clear', maxRuntimeMs: 10000 }
|
|
560
501
|
}
|
|
502
|
+
// evaluate 返回:
|
|
503
|
+
{ state, events, activations: [{ strategy: 'escape', input: {}, reason: 'player_nearby' }] }
|
|
561
504
|
```
|
|
562
505
|
|
|
563
|
-
|
|
564
|
-
|---|---|
|
|
565
|
-
| `type` | 非空,且必须列在 `manifest.produces` |
|
|
566
|
-
| `dedupeKey` | 当前语义片段的稳定、非空身份 |
|
|
567
|
-
| `dedupeScope` | 省略时为 `segment`;可显式选 `segment` 或 `session` |
|
|
568
|
-
| `payload` | 普通、可 clone 的 JSON 对象 |
|
|
569
|
-
| `occurredAt` | 可选的事件发生时间字符串 |
|
|
570
|
-
|
|
571
|
-
Perception 不能返回 Action、Status、State patch 或 Behavior Activation。
|
|
506
|
+
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,再覆盖本局策略默认参数。未知绑定、重复绑定或非法输出被拒绝。
|
|
572
507
|
|
|
573
|
-
|
|
508
|
+
输入 availableBindings/availableStrategies 是实际可用依赖;enabledBindings 是其中当前允许自动激活的绑定。缺失或损坏策略只跳过对应绑定,感知其他通知与健康绑定继续运行。感知同时可发自己的通知,不直接执行 Action。
|
|
574
509
|
|
|
575
|
-
```
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
| 'shutdown';
|
|
583
|
-
readonly mode: 'snapshot' | 'close';
|
|
584
|
-
readonly through: Readonly<PerceptionFrame> | null;
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
flush?(boundary: Readonly<PerceptionBoundary>, api: PerceptionApi):
|
|
588
|
-
readonly PerceptionEventProposal[] | void | Promise<readonly PerceptionEventProposal[] | void>;
|
|
589
|
-
|
|
590
|
-
reset?(reason: 'phase_changed' | 'trajectory_gap' | 'segment_ending' | 'shutdown' | 'replay'):
|
|
591
|
-
void | Promise<void>;
|
|
592
|
-
|
|
593
|
-
debugSnapshot?(): unknown;
|
|
510
|
+
```powershell
|
|
511
|
+
ccl strategy update community.auto-escape --input '{"x":100,"y":200}'
|
|
512
|
+
ccl perception update community.nearby-reflex --input '{"triggerDistance":180}'
|
|
513
|
+
ccl strategy status community.auto-escape
|
|
514
|
+
ccl perception status community.nearby-reflex
|
|
515
|
+
ccl strategy unwatch community.auto-escape
|
|
516
|
+
ccl strategy watch community.auto-escape
|
|
594
517
|
```
|
|
595
518
|
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
### Manifest:`ClawclawPerceptionManifest`
|
|
599
|
-
|
|
600
|
-
| 字段 | 类型 | 约束 |
|
|
601
|
-
|---|---|---|
|
|
602
|
-
| `apiVersion` | `2` | 必须等于 `PERCEPTION_PLUGIN_API_VERSION` |
|
|
603
|
-
| `id` | `string` | 稳定的模块 ID |
|
|
604
|
-
| `description` | `string` | 非空的 Agent 能力说明 |
|
|
605
|
-
| `name` | `string`,可选 | 兼容已有脚本;新脚本省略,展示信息由 CCL 管理 |
|
|
606
|
-
| `localizations` | object,可选 | 兼容已有脚本的模块文案;人类展示优先采用本地登记或 Hub 下发的文案 |
|
|
607
|
-
| `subjectScope` | `'others' \| 'self_and_others' \| 'visible_pairs' \| 'corpses'` | 描述 Event 主体范围 |
|
|
608
|
-
| `produces` | `string[]` | 允许输出的 Event type |
|
|
609
|
-
| `wakeAgent` | boolean,可选 | 模块默认是否主动唤醒 Agent,省略为 true;单条 proposal 可覆盖 |
|
|
610
|
-
| `eventMetadata` | object,可选 | 每种 Event 的名称、说明和本地化 |
|
|
611
|
-
| `execution` | `'parallel_analysis'`,可选 | 启用 `analyze/commit` 接口 |
|
|
612
|
-
| `boundaryBaseline` | `'current_only'`,可选 | 声明边界重建能力 |
|
|
519
|
+
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 返回观察健康、配置和绑定。
|
|
613
520
|
|
|
614
|
-
|
|
521
|
+
设置本局有效,不写 Hub 或 gameplay.json;换局与 Owner 重启恢复默认值及默认开启状态。开启只要求两个资源已装配,不提前校验尚由感知动态选择的目标;激活时校验完整输入。
|
|
615
522
|
|
|
616
|
-
导入入口与当前版本:
|
|
617
|
-
|
|
618
|
-
```ts
|
|
619
|
-
import {
|
|
620
|
-
TRIGGER_PLUGIN_API_VERSION,
|
|
621
|
-
MAX_TRIGGER_RUNTIME_MS,
|
|
622
|
-
ClawclawTrigger,
|
|
623
|
-
} from '@myclaw163/clawclaw-cli/trigger-plugin';
|
|
624
|
-
|
|
625
|
-
// TRIGGER_PLUGIN_API_VERSION === 4
|
|
626
|
-
// MAX_TRIGGER_RUNTIME_MS === 120_000
|
|
627
|
-
```
|
|
628
|
-
|
|
629
|
-
### Runtime 输入:`TriggerInput<TInput>`
|
|
630
|
-
|
|
631
|
-
```ts
|
|
632
|
-
interface TriggerInput<TInput extends Readonly<Record<string, unknown>>> {
|
|
633
|
-
readonly frame: Readonly<ObservationFrame>;
|
|
634
|
-
readonly events: readonly Readonly<GameEvent>[];
|
|
635
|
-
readonly input: Readonly<TInput>;
|
|
636
|
-
}
|
|
637
|
-
```
|
|
638
|
-
|
|
639
|
-
| 字段 | 含义 |
|
|
640
|
-
|---|---|
|
|
641
|
-
| `frame` | 与 Perception 独立收到的同形状观察帧 |
|
|
642
|
-
| `events` | `manifest.consumes` 订阅到的后端推送 Event |
|
|
643
|
-
| `input` | 当前生效的规则参数 |
|
|
644
|
-
|
|
645
|
-
Trigger 与 Perception 之间没有依赖,可以并行计算。`events` 只来自后端输入,不包含 Derived、Perception、Behavior、Trigger 或其他 Runtime 计算插件的输出。
|
|
646
|
-
|
|
647
|
-
### 查询:`TriggerReadApi`
|
|
648
|
-
|
|
649
|
-
```ts
|
|
650
|
-
type TriggerReadApi = BehaviorReadApi;
|
|
651
|
-
```
|
|
652
|
-
|
|
653
|
-
因此 Trigger 可用 `spatial`、`navigation` 和 `observation`,接口和 Behavior 完全一致。Trigger 仍然是只读规则模块,查询 API 不赋予 Action 能力。
|
|
654
|
-
|
|
655
|
-
### 输出:`TriggerMatch`
|
|
656
|
-
|
|
657
|
-
```ts
|
|
658
|
-
interface TriggerMatch {
|
|
659
|
-
readonly reason: string;
|
|
660
|
-
readonly evidence?: Readonly<Record<string, unknown>>;
|
|
661
|
-
readonly behaviorInput?: Readonly<Record<string, unknown>>;
|
|
662
|
-
}
|
|
663
|
-
```
|
|
664
|
-
|
|
665
|
-
| 字段 | 约束 |
|
|
666
|
-
|---|---|
|
|
667
|
-
| `reason` | 必须是非空的稳定命中原因 |
|
|
668
|
-
| `evidence` | 可选、普通、可 clone 的证据对象 |
|
|
669
|
-
| `behaviorInput` | 可选;合并到已配置的目标 Behavior 输入之上 |
|
|
670
|
-
|
|
671
|
-
返回 `undefined` 表示本轮未命中。`TriggerMatch` 不能包含 Action、目标 Behavior ID、Reflex 优先级或 State patch;目标和优先级来自当前已经生效的配置。
|
|
672
|
-
|
|
673
|
-
### 状态重置
|
|
674
|
-
|
|
675
|
-
```ts
|
|
676
|
-
type TriggerResetReason =
|
|
677
|
-
| 'phase_changed'
|
|
678
|
-
| 'trajectory_gap'
|
|
679
|
-
| 'segment_ending'
|
|
680
|
-
| 'shutdown';
|
|
681
|
-
|
|
682
|
-
reset?(reason: TriggerResetReason): void | Promise<void>;
|
|
683
|
-
```
|
|
684
|
-
|
|
685
|
-
### Manifest:`ClawclawTriggerManifest`
|
|
686
|
-
|
|
687
|
-
| 字段 | 类型 | 约束 |
|
|
688
|
-
|---|---|---|
|
|
689
|
-
| `apiVersion` | `4` | 必须等于 `TRIGGER_PLUGIN_API_VERSION` |
|
|
690
|
-
| `id` / `name` / `description` | `string` | 稳定 ID 与非空说明 |
|
|
691
|
-
| `localizations` | object,可选 | 本地化资源文本 |
|
|
692
|
-
| `inputs` | `BehaviorInputFieldSpec[]` | 规则参数;每个字段必须有 `default` |
|
|
693
|
-
| `consumes` | `string[]` | 订阅的后端 Event type;空数组表示只看帧 |
|
|
694
|
-
| `defaultBehavior` | `string` | 默认绑定的固定 Behavior ID |
|
|
695
|
-
| `defaultBehaviorInput` | object | 普通 JSON 对象;默认 Behavior 输入 |
|
|
696
|
-
| `defaultReflexPriority` | `number` | 安全整数;只比较不同 Reflex,不改变 `reflex > short > long` |
|
|
697
|
-
| `defaultCooldownMs` | `number` | 非负安全整数;默认冷却时间 |
|
|
698
|
-
| `defaultRearm` | `'after_clear' \| 'after_cooldown'` | 默认重新武装方式 |
|
|
699
|
-
| `defaultMaxRuntimeMs` | `number` | `1..120000` 的安全整数;默认 Reflex 运行上限 |
|
|
700
|
-
|
|
701
|
-
Trigger 使用与 Behavior 相同的参数字段 schema,但 Trigger 每个参数必须有静态默认值。运行时配置、启用和绑定方式见[开发 Trigger](./trigger.md)。
|
|
702
523
|
|
|
703
524
|
## 共享数据结构
|
|
704
525
|
|
|
@@ -862,6 +683,8 @@ interface VisualCorpse {
|
|
|
862
683
|
|
|
863
684
|
### `GameEvent`
|
|
864
685
|
|
|
686
|
+
会议结果 `exile` / `no_exile` 的 `payload.votes` 可为 `Array<[number, number | null]>`:每项依次是投票者座位、被投者座位,`null` 表示弃票。数字是座位,不是数组下标或玩家 UUID;CCL 保留后端给出的顺序和空数组。感知输出的完整会议通知也保留这份结构,不从 State 重建票型。 原始 GameEvent 的 actor_name/actor_seat 仍可供内部模块读取;给 Agent 的放逐通知以 exiled_player 提供被放逐者信息,不重复输出这两个 actor 字段。
|
|
687
|
+
|
|
865
688
|
```ts
|
|
866
689
|
interface GameEvent {
|
|
867
690
|
readonly eventId: string;
|
|
@@ -878,7 +701,7 @@ interface GameEvent {
|
|
|
878
701
|
|
|
879
702
|
```ts
|
|
880
703
|
import type {
|
|
881
|
-
|
|
704
|
+
StrategyInput,
|
|
882
705
|
GameEvent,
|
|
883
706
|
GameState,
|
|
884
707
|
ObservationFrame,
|
|
@@ -890,3 +713,39 @@ import type {
|
|
|
890
713
|
- 输入、输出和 Worker 分析值必须支持 `structuredClone`;
|
|
891
714
|
- 查询 API 只在当前回调活动期间有效,不要保存后延迟调用;
|
|
892
715
|
- 自定义模块是本机可信代码,不是安全沙箱,只安装可信来源。
|
|
716
|
+
|
|
717
|
+
### api.memory:局内持续记忆
|
|
718
|
+
|
|
719
|
+
StrategyReadApi 和 PerceptionModuleApi 均提供以下接口:
|
|
720
|
+
|
|
721
|
+
```ts
|
|
722
|
+
type StrategyMemoryValue = null | boolean | number | string
|
|
723
|
+
| readonly StrategyMemoryValue[] | {readonly [key: string]: StrategyMemoryValue};
|
|
724
|
+
interface StrategyMemory {
|
|
725
|
+
get<T extends StrategyMemoryValue = StrategyMemoryValue>(key: string): Promise<T | undefined>;
|
|
726
|
+
set(key: string, value: StrategyMemoryValue): Promise<void>;
|
|
727
|
+
delete(key: string): Promise<void>;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
const handled = await api.memory.get('handled:corpse-id');
|
|
731
|
+
await api.memory.set('handled:corpse-id', true);
|
|
732
|
+
await api.memory.delete('handled:corpse-id');
|
|
733
|
+
```
|
|
734
|
+
|
|
735
|
+
get 读取当前值并返回副本,缺失为 undefined;set 覆盖一个键,delete 删除一个键,删除不存在的键成功。调用成功即生效,不需要在 Decision 中返回 memory 字段,也不等待动作确认;后续 Decision 失败不会回滚已成功写入。模块仍须通过权威 State/Event 判断业务结果。回调失效后新的访问会拒绝,但不会撤回此前有效调用完成的写入。
|
|
736
|
+
|
|
737
|
+
感知的所有固定绑定均解析到同一个可用策略时,与该策略双向共享;没有绑定、存在不可用绑定或绑定多个策略时,感知使用自己的私有命名空间。同一策略的不同层/Activation/Worker 也共享。绑定由宿主固定到实际操作名,API 不接受其他策略 ID;不同策略、重名别名、账号和 Owner 相互隔离。
|
|
738
|
+
|
|
739
|
+
生命周期:跨回调、暂停恢复、实例更换、改参、完成重启及 watch/unwatch 保留;新游戏、game_over 或 Owner 退出清空。仅保存在当前进程内存中,不落盘或恢复旧检查点。它与感知私有 state、并行实例 snapshot 和 Agent 跨局 memory 文件是不同数据。
|
|
740
|
+
|
|
741
|
+
限制:JSON 值、最大 32 层嵌套;每资源最多 256 键/64 KiB(UTF-8 键值合计),键名 1–256 字节;游戏作用域总计最多 4 MiB。不支持 undefined、非有限数字、函数、访问器、Map/Set、循环对象。非法/超限写入失败且原值不变。不同键独立更新,同一键按宿主收到的写入顺序生效;多步读改写不是事务。
|
|
742
|
+
|
|
743
|
+
主要错误:strategy_memory_key_invalid、strategy_memory_value_invalid、strategy_memory_limit_exceeded、strategy_memory_inactive;无有效记忆宿主时为 strategy_memory_unavailable。await evaluate/decide 结束后不要保留 API 给异步定时器使用。
|
|
744
|
+
|
|
745
|
+
### 通知内容的归属
|
|
746
|
+
|
|
747
|
+
感知输出的 payload.hint 可为非空字符串,由感知执行器负责校验/保留;非字符串 hint 和旧 next_step/notice 被过滤。内置感知不信任输入事实中的提示,会生成自身的固定提示。通用 EventIngress 只校验和存储,不再承担这些业务字段过滤。通知正文在生产时保存,Mailbox 和 Adapter 不调用当前 State 来补内容。
|
|
748
|
+
|
|
749
|
+
会议发言顺序只接受后端 meeting_briefing.speech_order,不从 State 补齐。此变化不改变 Strategy 的 update/watch/unwatch、感知输入或通知轮次调度。
|
|
750
|
+
|
|
751
|
+
Source 会将 meeting_briefing.speech_order 的名字字符串按同一事件 all_seats 转换为 PlayerRef[];不按座位排序,不读取 State,不补缺失字段。已有数组继续按 PlayerRef 校验。无法唯一转换时保留原字符串,Source 记录 runtime.source.event_field_preserved 诊断,不丢弃会议事件或其同批事件。
|