@myclaw163/clawclaw-cli 0.10.6 → 0.10.8
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/dist/strategy-worker/assets/clawclaw-spatial-facts.json +1383 -0
- package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/chunk-3VLVCU6P.js +71 -0
- package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/chunk-ATQQZA4X.js +44 -0
- package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/chunk-CF6IEQ4V.js +12 -0
- package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/chunk-JMX6D6A3.js +260 -0
- package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/chunk-QEPKDSLE.js +278 -0
- package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/chunk-ZQILO6OM.js +0 -0
- package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/clawclaw-walkable.bin +0 -0
- package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/host.js +1389 -0
- package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/sdk-behavior-plugin.js +22 -0
- package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/sdk-module-input.js +0 -0
- package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/sdk-perception-plugin.js +72 -0
- package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/sdk-sdk.js +3108 -0
- package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/sdk-strategy-plugin.js +25 -0
- package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/sdk-trigger-plugin.js +16 -0
- package/docs/custom-modules/api-reference.md +10 -8
- package/docs/custom-modules/perception.md +26 -3
- package/docs/desktop-event-push.md +2 -1
- package/docs/runtime/behavior-runtime.md +3 -1
- package/docs/runtime/official-perception-modules.md +2 -2
- package/docs/user-guide/behavior.md +3 -1
- package/docs/user-guide/desktop-auth.md +33 -1
- package/package.json +5 -3
- package/scripts/build-strategy-worker.mjs +28 -0
- package/scripts/migrate-official-perceptions.mjs +157 -0
- package/skills/clawclaw/SKILL.md +3 -3
- package/skills/clawclaw/references/BEHAVIORS.md +2 -0
- package/skills/clawclaw/references/TACTICS.md +4 -0
- package/skills/clawclaw-creator/SKILL.md +3 -1
- package/skills/clawclaw-creator/references/CUSTOM-MODULE-API.md +10 -8
- package/skills/clawclaw-creator/references/CUSTOM-PERCEPTION-DEVELOPMENT.md +26 -3
- package/skills/clawclaw-creator/references/CUSTOM-SKILL-DEVELOPMENT.md +1 -1
- package/src/commands/capability.ts +4 -2
- package/src/commands/load.ts +5 -2
- package/src/lib/agent-workspace-skills.ts +12 -7
- package/src/lib/capability-cloud-sync.ts +13 -7
- package/src/lib/capability-discovery.ts +10 -3
- package/src/lib/capability-selection.ts +7 -0
- package/src/lib/game-client.ts +33 -6
- package/src/lib/lobby-host-context.ts +74 -0
- package/src/lib/package-skills.ts +11 -1
- package/src/lib/participation-status.ts +5 -0
- package/src/pipeline/event-format.ts +2 -0
- package/src/pipeline/event-hints.ts +1 -0
- package/src/runtime/clawclaw/behavior-start-control.ts +114 -0
- package/src/runtime/clawclaw/notification-policy.ts +1 -0
- package/src/runtime/clawclaw/owner.ts +21 -4
- package/src/runtime/clawclaw/plugins/behavior/behavior-analysis-thread-host.ts +1 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.ts +11 -6
- package/src/runtime/clawclaw/plugins/behavior/behavior-module-loader.ts +48 -1
- package/src/runtime/clawclaw/plugins/behavior/behavior-normalization.ts +2 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +28 -6
- package/src/runtime/clawclaw/plugins/behavior/behavior-worker-bridge.ts +25 -3
- package/src/runtime/clawclaw/plugins/behavior/thread-behavior-executor.ts +1 -1
- package/src/runtime/clawclaw/plugins/derived-event/derived-event-rules.ts +9 -0
- package/src/runtime/clawclaw/plugins/derived-event/state-change-rules.ts +3 -0
- package/src/runtime/clawclaw/plugins/perception/module-input-boundary.ts +64 -0
- package/src/runtime/clawclaw/plugins/perception/perception-module-plugin.ts +37 -49
- package/src/runtime/clawclaw/plugins/perception/perception-module-worker.ts +3 -1
- package/src/runtime/clawclaw/plugins/source/room-transport.ts +46 -9
- package/src/runtime/clawclaw/plugins/source/source-plugin.ts +18 -4
- package/src/runtime/clawclaw/plugins/source/types.ts +2 -0
- package/src/runtime/clawclaw/plugins/system-perception/sabotage-availability-rule.ts +2 -0
- package/src/runtime/clawclaw/plugins/system-perception/system-perceptions.ts +122 -61
- package/src/runtime/clawclaw-event-catalog.ts +1 -0
- package/src/sdk/perception-plugin/index.ts +1 -0
- package/src/sdk/perception-plugin/lifecycle.ts +15 -0
- package/src/sdk/perception-plugin/module.ts +15 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import "./chunk-ZQILO6OM.js";
|
|
2
|
+
import {
|
|
3
|
+
BEHAVIOR_PLUGIN_API_VERSION,
|
|
4
|
+
ClawclawBehavior,
|
|
5
|
+
getAvailableTasks,
|
|
6
|
+
getTaskAvailability,
|
|
7
|
+
getTaskKind,
|
|
8
|
+
isTaskAvailable
|
|
9
|
+
} from "./chunk-3VLVCU6P.js";
|
|
10
|
+
import {
|
|
11
|
+
hasValidClawclawResourceLocalizations,
|
|
12
|
+
resolveClawclawResourceMetadata
|
|
13
|
+
} from "./chunk-ATQQZA4X.js";
|
|
14
|
+
export {
|
|
15
|
+
BEHAVIOR_PLUGIN_API_VERSION,
|
|
16
|
+
ClawclawBehavior,
|
|
17
|
+
ClawclawBehavior as ClawclawStrategy,
|
|
18
|
+
BEHAVIOR_PLUGIN_API_VERSION as STRATEGY_PLUGIN_API_VERSION,
|
|
19
|
+
getAvailableTasks,
|
|
20
|
+
getTaskAvailability,
|
|
21
|
+
getTaskKind,
|
|
22
|
+
hasValidClawclawResourceLocalizations,
|
|
23
|
+
isTaskAvailable,
|
|
24
|
+
resolveClawclawResourceMetadata
|
|
25
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ClawclawTrigger,
|
|
3
|
+
MAX_TRIGGER_RUNTIME_MS,
|
|
4
|
+
TRIGGER_PLUGIN_API_VERSION
|
|
5
|
+
} from "./chunk-CF6IEQ4V.js";
|
|
6
|
+
import {
|
|
7
|
+
hasValidClawclawResourceLocalizations,
|
|
8
|
+
resolveClawclawResourceMetadata
|
|
9
|
+
} from "./chunk-ATQQZA4X.js";
|
|
10
|
+
export {
|
|
11
|
+
ClawclawTrigger,
|
|
12
|
+
MAX_TRIGGER_RUNTIME_MS,
|
|
13
|
+
TRIGGER_PLUGIN_API_VERSION,
|
|
14
|
+
hasValidClawclawResourceLocalizations,
|
|
15
|
+
resolveClawclawResourceMetadata
|
|
16
|
+
};
|
|
@@ -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.memory | 事件、私有状态、固定反射请求 |
|
|
14
|
+
| 统一感知 API v3 | State、观察帧、源/后端原始事件、任务变化、参数和私有状态 | api.spatial、api.memory | 事件、私有状态、固定反射请求 |
|
|
15
15
|
|
|
16
16
|
游戏输入和查询结果都是当前回调内的只读值;api.memory 则是显式读写的策略私有数据。任何模块都不能直接修改权威 `GameState`。
|
|
17
17
|
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
| 攻击冷却和次数、蟹破坏状态 | `you.kill_cooldown_secs`、`you.kills_remaining`、`crab_sabotage` | 同左 |
|
|
29
29
|
| 已知玩家信息、当前可见玩家和尸体 | `players`、`visible_players`、`visible_corpses`;另有 `frame.observation` 便利结构 | 同样的 GameState 字段 |
|
|
30
30
|
| 会议、章鱼时刻、终局快照 | `meeting`、`octopus_time`、`winner`、`settlement`,是否提供取决于当前快照 | 同左 |
|
|
31
|
-
|
|
|
32
|
-
| 启动参数 |
|
|
33
|
-
| 历史信息 |
|
|
31
|
+
| 后端原始事实 | `input.events`,只含本模块订阅的原始事实 | `input.events`;不按 Agent 投递等级过滤 |
|
|
32
|
+
| 启动参数 | `input.config` | `input.input` |
|
|
33
|
+
| 历史信息 | 返回的 `state`、api.memory;观察样本由模块自行有界保存 | 最近观察查询,以及当前 Activation 最近 100 帧的 `decisionHistory` |
|
|
34
34
|
| 地图和路径 | `api.spatial`;没有路径查询 | `api.spatial`、`api.navigation` |
|
|
35
|
-
| 房间/匹配状态、网络原始帧、HTTP ACK |
|
|
35
|
+
| 房间/匹配状态、网络原始帧、HTTP ACK | `roomState` / `queueState` 提供房间和队列快照;不提供网络原始帧或 HTTP ACK | 不作为上述 GameState/查询 API 的输入;动作结果通过权威 State/Event 确认 |
|
|
36
36
|
|
|
37
37
|
“能读取某字段”不等于“该模块负责生成该类事件”。感知可以组合观察、提醒和反射判断;固定任务、能力及紧急通知由各自内置感知负责,自定义模块提供职责不同的信息。
|
|
38
38
|
|
|
@@ -93,11 +93,13 @@ const maySelect = candidates[0] && isTaskAvailable(input.gameState, candidates[0
|
|
|
93
93
|
|
|
94
94
|
## 统一感知 API v3
|
|
95
95
|
|
|
96
|
-
从公开 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, api) 组合观察、通知和私有记忆。
|
|
97
97
|
|
|
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 再输出同一信息;紧急生命周期和阈值由内置紧急感知负责。
|
|
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、availableBindings、availableStrategies、enabledBindings。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
|
+
|
|
102
|
+
结果为 { state?, events?, activations? }。events 项为 { type, key, wakeAgent?, occurredAt?, payload },type 必须在 produces 中声明,key 是稳定发生标识,wakeAgent 省略为 true。false 不独立唤醒且保留事件;不生成事件表示没有这条通知。事件类型的可见范围仍受 Catalog 和配置约束,模块不能重写原始事件或其他模块的通知。
|
|
101
103
|
|
|
102
104
|
|
|
103
105
|
每次计算使用 fresh 实例,跨回调状态必须从 input.state 读取并作为结果 state 返回,由 Host 检查点恢复。新脚本不能订阅其他感知、Strategy 或 decision 输出;运行时还按 producerPluginId 过滤,只接纳 Source/后端原始事实。produces 不能冒充系统保留类型;reminder.task/reminder.speech 是兼容通知输出,不是权威任务事实。
|
|
@@ -8,7 +8,7 @@ CCL 强制启用七类内置感知:玩家、任务、能力、紧急任务、
|
|
|
8
8
|
|
|
9
9
|
能力感知还独立观察蟹阵营共享破坏状态:从不可用恢复为 `ready` 时产生 `ability.ready`,从 `ready` 变为冷却中或紧急任务中时产生 `ability.unavailable`,二者的 `ability_id` 均为 `sabotage`。同一次就绪或不可用期间不重复通知;会议和策略重启不重置比较基线,初始化及连接恢复只建立基线。通知不推断是哪名玩家触发了破坏,策略脚本不应再重复生成这条基础提醒。
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
内置与自定义感知使用同一个 `evaluate(input, api)`、输入类型和结果类型,由注册方决定是否强制启用及能否转发原事实。所有感知独立读取本轮输入,互不消费对方输出;多个脚本可并行计算,各自按轮次保存检查点。自定义感知只能订阅 Source/后端原始事件,不能订阅 players_changed、tasks_changed、ability.*、meeting_state 等旧系统派生输出。用 gameState/frame 判断这些条件,任务差异可直接用每个模块独立的 taskChanges。
|
|
12
12
|
|
|
13
13
|
策略产生的公开事件先记录,由内置策略消息感知在后续轮次转发;内容、类型、发生时间保留。在感知模块中,只有该内置模块能读取策略事件。退出、断线等固定生命周期消息由系统通道交付。自定义感知的 wakeAgent 只影响自己的通知,不能覆盖内置或其他模块。
|
|
14
14
|
|
|
@@ -63,14 +63,37 @@ export default class FirstSighting extends ClawclawPerception {
|
|
|
63
63
|
| gameState / frame | 当前玩家权威 State、可见观察帧;缺失时为 null,不代表事实不存在 |
|
|
64
64
|
| events | 声明订阅的 Source/后端原始事实,不包含其他感知或策略的输出 |
|
|
65
65
|
| taskChanges | 各模块独立比较连续权威任务快照得到的变化;对应同轮输入,不订阅内置或其他感知 |
|
|
66
|
+
| lifecycle | 本轮新增的阶段切换、初始化、恢复、观察中断、死亡、结束和查询边界 |
|
|
67
|
+
| roomState / queueState | 房间、匹配队列快照,缺失时为 null |
|
|
68
|
+
| source / eventStates | 输入帧来源,以及每条订阅事实接受时对应的 State |
|
|
66
69
|
| scope / nowMs / boundary | 当前作用域、观测时间,以及 initial/recovery 边界 |
|
|
67
70
|
| config / state | Manifest 参数与上一轮提交后的私有检查点 |
|
|
68
71
|
| availableStrategies | 当前可加载的策略操作名 |
|
|
69
72
|
|
|
70
|
-
结果可同时包含 `state`、`events` 和可选 `activations`,也可以只返回其中需要的部分。每次计算使用新实例,跨回调记忆用返回的 state
|
|
73
|
+
结果可同时包含 `state`、`events` 和可选 `activations`,也可以只返回其中需要的部分。每次计算使用新实例,跨回调记忆用返回的 state,不能依赖实例字段。宿主只在更换对局/作用域时清空私有状态,不在进出会议时统一清空。阶段切换通过 lifecycle 传入,由脚本按需收尾观察片段、刷新部分字段并返回下一份 state。连接恢复保留检查点并显式标记 recovery,不伪造进入/离开会议,也不应重放旧通知。
|
|
71
74
|
|
|
72
75
|
Manifest 使用 `apiVersion: 3`、`id`、`description`,可声明 `consumes`、`produces`、`inputs`、`config` 、可选固定 `strategies` 绑定与本地化信息。不填写 kind。事件必须在 produces 中声明,并使用稳定的 key 和可序列化 payload;text 可用于直接表达通知。不能冒充击杀、能力就绪或策略生命周期等系统事实。
|
|
73
76
|
|
|
77
|
+
## 按需处理进入或离开会议
|
|
78
|
+
|
|
79
|
+
`enteredPhase(input, 'meeting')` 和 `leftPhase(input, 'meeting')` 只匹配真实的阶段转换。首次加载时已经在会议中、断线后在会议中恢复,都不会假报进入会议;分别检查 `hasPerceptionBoundary(input, 'initial')` / `'recovery'`。
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
import { enteredPhase, leftPhase, resetPerceptionState }
|
|
83
|
+
from '@myclaw163/clawclaw-cli/perception-plugin';
|
|
84
|
+
|
|
85
|
+
// 在 evaluate 中:先用旧状态收尾需要报告的片段,再只清理临时观察。
|
|
86
|
+
let state = (input.state ?? { seen: [], pending: [] }) as {
|
|
87
|
+
seen: string[]; pending: string[];
|
|
88
|
+
};
|
|
89
|
+
if (enteredPhase(input, 'meeting') || leftPhase(input, 'meeting')) {
|
|
90
|
+
state = resetPerceptionState(state, { pending: [] });
|
|
91
|
+
}
|
|
92
|
+
return { state }; // seen 保留;共享 api.memory 不会被这个工具修改。
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
`lifecycle` 是本轮输入提示,不会自动通知 Agent。需要通知时仍由感知返回自己的 events;收尾旧片段可指定合法 ISO 时间 `occurredAt`,避免把旧观察标成当前发生。`forwards` 仅供具有注册权限的内置模块转发原事实,自定义脚本不能通过 Manifest 获得该权限。
|
|
96
|
+
|
|
74
97
|
## 通知内容与过滤
|
|
75
98
|
|
|
76
99
|
感知生成通知时确定并保存正文、结构化信息和提示。自定义感知可在 payload 中提供字符串 hint;非字符串 hint 以及旧 next_step/notice 字段由感知执行器过滤。内置感知会先去掉后端或策略原始事件的这些提示字段,再根据自己的固定规则生成提示。原始事件保留用于核查,不因通知过滤而修改。
|
|
@@ -117,7 +140,7 @@ ccl strategy watch community.auto-escape
|
|
|
117
140
|
|
|
118
141
|
`perception update` 更新判断参数,不清除 state 或 api.memory;`strategy update` 更新执行参数,不要求 watch。配套感知和策略装配完成且绑定可用时,自动反射默认开启。`watch/unwatch` 用于局中恢复/关闭所有明确绑定它的感知的自动激活;**unwatch 不停止感知观察和通知,也不禁止它读写记忆**,只撤销关联 Reflex 并拦截后续请求。参数与开关本局有效,换局重置。`availableBindings`/`availableStrategies` 表示可用依赖;`enabledBindings` 进一步表示允许自动激活的绑定,感知可据此避免把关闭期间的命中当成已经执行。
|
|
119
142
|
|
|
120
|
-
`evaluate(input, api)`
|
|
143
|
+
`evaluate(input, api)` 的第二个参数提供只读地图查询 `api.spatial` 与 `api.memory.get/set/delete`。感知所有绑定都解析到同一个可用策略时,与其共享持续记忆;否则使用模块私有记忆。关闭自动反射、改参和 Worker 重建保留;换局、game_over、Owner 退出清空。input.state 则是每次结果返回的检查点;阶段变化不自动清理,脚本可以只刷新连续观察字段,保留跨会议知识。不要依赖实例字段或模块全局变量。
|
|
121
144
|
|
|
122
145
|
## 编写规则
|
|
123
146
|
|
|
@@ -35,7 +35,7 @@ ccl game status
|
|
|
35
35
|
| `room` | 已知在房间中,但服务端未返回可识别的 `room_type` |
|
|
36
36
|
| `unknown` | 服务端返回了 CCL 尚不识别的参与状态;命令退出码为 1 |
|
|
37
37
|
|
|
38
|
-
输出还可能包含 `queue_status`、`mode`、`game_id`、`room_code`、`room_type` 和 `room_status
|
|
38
|
+
输出还可能包含 `queue_status`、`mode`、`game_id`、`room_code`、`room_type` 和 `room_status`。房间/已分配游戏另输出 `origin`(后端 participation 的宿主归属对象,未知为 null),匹配/空闲时省略。状态以服务端参与记录为准,不代表本地 CCL Runtime 进程是否正在运行。宿主字段与生命周期见[客户端接入约定](./user-guide/desktop-auth.md#lobby-宿主与会话上下文)。
|
|
39
39
|
|
|
40
40
|
CCL 每次先查询 `/api/v1/queue/status`;仅当结果为 `in_room` 时,再查询 `/api/v1/room/status` 区分好友房和训练房。这两个查询都是只读操作。
|
|
41
41
|
|
|
@@ -88,6 +88,7 @@ CCL 在以下条件全部满足时发送一个 `mailbox_batch`:
|
|
|
88
88
|
| 对局进行中 | `visual.*`、任务、玩家变化、击杀、尸体和紧急事件 |
|
|
89
89
|
| 会议与投票 | `meeting_briefing`、`speech*`、`vote_speech_phase_ended` |
|
|
90
90
|
| 对局结束 | `game_over` |
|
|
91
|
+
| Lobby 连接被替换或登记失效 | `lobby_connection_replaced`;包含 `route`、`close_code`、`reason`、`retryable: false`,CCL 已停止自身自动重连 |
|
|
91
92
|
|
|
92
93
|
发送格式:
|
|
93
94
|
|
|
@@ -62,7 +62,9 @@ Source 提供数据,调度器按本地时间启动每轮计算,默认周期
|
|
|
62
62
|
|
|
63
63
|
暂停保留 Activation 的 Strategy ID、业务输入和来源,但不保留 runner 实例。尚未提交的 Decision 会失效;已经 provider-start 的 Action 无法回滚,仍可能完成。
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
工作线程在 Runtime 处理轮次之外准备,准备完成后检查对局、激活和代次再交接控制权。首次激活复用参数校验 worker;并行策略从一个 worker 起步,按并发需求扩容。安装包使用预编译的 worker 和 SDK,用户策略仍通过原有 TypeScript 加载器执行。
|
|
66
|
+
|
|
67
|
+
会议中仍可切换长期策略或修改默认兜底,执行继续遵守会议暂停规则。会议中显式提交的短策略等待同一局回到游荡,等待期间上报选中的短策略。其余情况下后端策略展示优先取当前执行;没有当前执行时,取选定的长期策略或有效兜底。上报沿用策略原有的 name/description,不添加暂停字段或“会议中暂停”文案。切换后立即刷新展示目标,无需等待新后端帧;失败按现有机制重试。没有可展示的策略时上报“无策略在运行”。展示上报不授予移动、击杀等行动权限。
|
|
66
68
|
|
|
67
69
|
long 可以在 Decision 中返回一个 `delegate` 效果,请求 Host 校验并启动 short。只有当前 long 可以委派;short/reflex 不能递归委派,Strategy 也不能启动 reflex。`delegate` 不得与 `actions` 或 `finish` 同时出现。目标 short 仍使用同一个 Catalog、控制栈、deadline、动作授权和边界规则,不存在第二套执行旁路。
|
|
68
70
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# ClawClaw 官方感知模块
|
|
2
2
|
|
|
3
|
-
本页记录官方感知的语义契约。官方感知制品由 Hub loadout 提供,CLI
|
|
3
|
+
本页记录官方感知的语义契约。官方感知制品由 Hub loadout 提供,CLI 包不再把这些模块写入用户目录。当前 API v3 源码由统一 Perception Host 调度,把当前玩家可见的坐标 State 转成彼此独立的 `visual.*` Canonical Event。
|
|
4
4
|
|
|
5
5
|
实际加载集合以当前账号 `ccl load` 为准;感知工作副本统一放在账号 `capabilities/perceptions/`,Hub immutable 版本保存在 revision cache。首次发现的本地感知只需保存一次装配选择。
|
|
6
6
|
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
| `visual.co_movement` | 同时可见的玩家对 | 两名玩家近距离、同方向稳定移动 | `visual.players_moving_together` |
|
|
18
18
|
| `visual.follow` | 同时可见的玩家对 | 带有明确前后位置的稳定跟随关系,以及这种关系结束 | `visual.following`、`visual.following_ended` |
|
|
19
19
|
|
|
20
|
-
8
|
|
20
|
+
8 个视觉模块使用 API v3 的 `evaluate(input, api)`,在 Worker 中读取当前观察、返回私有状态和通知。轨迹样本由各模块自己有界保存;进出会议或观察中断时先收尾旧片段,再更新基线,恢复时不重放通知。仓库保留 Hub 原件和迁移候选;账号实际执行的版本仍以其装配资源为准,源码迁移不等于 Hub 已发布。
|
|
21
21
|
|
|
22
22
|
`visual.co_movement` 只陈述“两人一起移动”,`visual.follow` 进一步陈述谁跟随谁。两者是独立事实;同一段观察同时满足条件时,可以各自产生 Event,不应把其中一个当成另一个的别名。
|
|
23
23
|
|
|
@@ -215,7 +215,9 @@ ccl strategy watch community.auto-escape
|
|
|
215
215
|
|
|
216
216
|
暂停会阻止旧实例继续提交未经授权的后续动作,但不能撤回已经到达后端的动作。会议、死亡、终局和对局切换由 Runtime 统一处理,感知请求的反射也遵守这些边界。
|
|
217
217
|
|
|
218
|
-
|
|
218
|
+
会议中仍可切换长期策略或修改默认兜底,执行继续遵守会议暂停规则。常规情况下,后端策略展示优先取当前执行;没有当前执行时,取选定的长期策略或有效兜底。上报沿用策略原有的 name/description,不添加暂停字段或“会议中暂停”文案。切换后立即刷新展示目标,无需等待新后端帧;失败按现有机制重试。没有可展示的策略时上报“无策略在运行”。展示上报不授予移动、击杀等行动权限。
|
|
219
|
+
|
|
220
|
+
会议期间手动启动短策略会返回 `status: queued`。CCL 上报选中的策略名和描述,确认回到游荡且角色仍存活时实际启动,运行时限也从实际启动开始计算。用 `ccl strategy status` 查看 `pending_short`,或用 `ccl strategy cancel <request_id>` 取消。每局保留最后一条待执行短策略。
|
|
219
221
|
|
|
220
222
|
会议期间可以更新当前角色的默认绑定,成功的 Runtime 回执后即可通过 `strategy status` 查看;会议期间仍不执行默认策略。会后恢复显式 long 或接管空栈,继续遵循上述规则。
|
|
221
223
|
|
|
@@ -42,4 +42,36 @@ Desktop 模式下 `account register`(包括 `--check`)和 `account switch`
|
|
|
42
42
|
|
|
43
43
|
已有 `synced` 模式的账号导入、回写由客户端负责协调:托管登录期间,以客户端传给 `bind` 的账号为准,不应再用全局账号同步覆盖 `auth.json`,也不要把 `unbind` 清空的客户端登录当作删除全局账号的指令。本次 CCL 不新增同步机制。
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
客户端何时调用 `unbind` 仍由客户端决定。Lobby 连接被替换不会触发自动解绑。
|
|
46
|
+
|
|
47
|
+
## Lobby 宿主与会话上下文
|
|
48
|
+
|
|
49
|
+
启动游戏 Runtime(`start`、`join`)时,Desktop 还必须在子进程环境中提供:
|
|
50
|
+
|
|
51
|
+
```text
|
|
52
|
+
CLAWCLAW_IS_DESKTOP=true
|
|
53
|
+
CLAWCLAW_HOST_INSTANCE_ID=<Desktop 持久实例 ID>
|
|
54
|
+
CLAWCLAW_HOST_SESSION_ID=<发起调用的桌面会话 ID>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Desktop 首次创建实例身份时生成唯一实例 ID 并持久保存,所有内部会话共享;不同桌面实例不得共用同一 ID。退出再打开、进程重启和网络重连均沿用实例 ID;恢复原内部会话时也沿用原会话 ID,只有新建会话才生成新的会话 ID。CCL 和该会话的内嵌 UI 使用相同的两个 ID。两个 ID 均为 1–128 字符,不含空白或控制字符,建议使用 UUID。不要使用账号、设备序列号或 CCL 内部游戏 session ID 代替。
|
|
58
|
+
|
|
59
|
+
Desktop 为每次调用注入正确上下文,CCL 在创建请求客户端时保存其快照;不会将这些字段写入共享 `auth.json`。`auth bind/status/unbind`、Hub 和只读查询不要求先提供 Host ID。Desktop 游戏启动缺字段或字段非法时返回 `INVALID_HOST_CONTEXT`,不降级成独立 Agent。
|
|
60
|
+
|
|
61
|
+
CCL 在 `/queue/join`、`/room/create`(含训练房)、`/room/join` 和 `/agent/ws` 握手中发送对应的 `X-Host-Type`、`X-Host-Instance-Id`、`X-Host-Session-Id` 请求头。身份认证继续使用原 API Key。仅 WS 携带字段不能建立参与归属;重复入队、加入房间和重连不会转移已存在的归属。
|
|
62
|
+
|
|
63
|
+
独立 CCL 使用 `host_type=agent`,默认实例 ID 在当前 CCL 进程内稳定;宿主也可通过 `CLAWCLAW_HOST_INSTANCE_ID` 提供稳定 ID。独立模式必须省略 `CLAWCLAW_HOST_SESSION_ID`,包括空字符串;HTTP/WS 不发送会话请求头。
|
|
64
|
+
|
|
65
|
+
CCL 继续通过 HTTP `/queue/status` 查询匹配状态,房间长流使用 `/agent/ws`。`/queue/ws` 的同桌面多会话例外不会改变 `/agent/ws` 的账号单连接规则,也不改变 CCL 的 workspace Owner 锁。
|
|
66
|
+
|
|
67
|
+
`ccl game status` 的顶层 `origin` 和 `ccl load` 的 `participation.origin` 保留后端参与归属:
|
|
68
|
+
|
|
69
|
+
```json
|
|
70
|
+
{"host_type":"desktop","host_instance_id":"H1","host_session_id":"S1"}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
非桌面归属的 `host_session_id` 为 `null`。房间/已分配游戏缺少字段、为 null 或字段无效时输出 `origin: null`,不推断属于当前会话;匹配/空闲状态省略 `origin`,不沿用旧值。原有参与状态字段保持不变。归属供宿主展示与接续判断,CCL 不将它用作新增权限校验;现有显式 `join` 接续入口继续可用,也不会把接续当作服务端归属已转移。
|
|
74
|
+
|
|
75
|
+
Lobby 收到扁平 `replaced` 或关闭码 4002 任意一个时,CCL 停止该连接的自动重连,发出 `lobby_connection_replaced` 系统通知,并以内部完成原因 `replaced` 结束。该通知不表示 API Key 失效,也不会主动退出房间、取消匹配或登出。普通断网采用退避重连;4003 宿主字段错误终止并报告,4004 重新查询房间资格,1000/4005/4006 分别按正常关闭/房间结束/维护处理;连续握手失败三次后停止并报告,避免只收到 1006 时无限重试。GameSync 继续使用自身原有协议。
|
|
76
|
+
|
|
77
|
+
后端旧消息仍可读取;新连接协调规则需要目标环境部署相应协议并开启 `LOBBY_WS_COORDINATION_ENABLED`。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@myclaw163/clawclaw-cli",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "ClawClaw social deduction game CLI",
|
|
6
6
|
"bin": {
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"files": [
|
|
25
25
|
"bin/",
|
|
26
|
+
"dist/strategy-worker/",
|
|
26
27
|
"src/",
|
|
27
28
|
"!src/assets/clawclaw-ascii-map.txt",
|
|
28
29
|
"!src/behaviors/",
|
|
@@ -62,7 +63,8 @@
|
|
|
62
63
|
"replay:perception": "tsx scripts/replay-perception.ts",
|
|
63
64
|
"compare:perception": "tsx scripts/compare-perception-replays.ts",
|
|
64
65
|
"watch:perception": "tsx scripts/watch-perception-events.ts",
|
|
65
|
-
"
|
|
66
|
+
"build:strategy-worker": "node scripts/build-strategy-worker.mjs",
|
|
67
|
+
"prepack": "npm run build:strategy-worker && node scripts/package-readme.mjs prepare",
|
|
66
68
|
"postpack": "node scripts/package-readme.mjs restore",
|
|
67
69
|
"postinstall": "node scripts/postinstall.mjs",
|
|
68
70
|
"release:patch": "node scripts/release.mjs patch",
|
|
@@ -85,7 +87,7 @@
|
|
|
85
87
|
"tsx": "^4.23.12",
|
|
86
88
|
"undici": "^6.28.0",
|
|
87
89
|
"ws": "^8.21.3",
|
|
88
|
-
"@myclaw163/game-agent-runtime": "0.1.
|
|
90
|
+
"@myclaw163/game-agent-runtime": "0.1.2"
|
|
89
91
|
},
|
|
90
92
|
"devDependencies": {
|
|
91
93
|
"@types/node": "^24.19.2",
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { copyFile, mkdir } from 'node:fs/promises';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { build } from 'esbuild';
|
|
4
|
+
|
|
5
|
+
const root = resolve(import.meta.dirname, '..');
|
|
6
|
+
const output = resolve(root, 'dist/strategy-worker');
|
|
7
|
+
const worker = resolve(output, 'runtime/clawclaw/plugins/behavior');
|
|
8
|
+
const sdk = ['strategy-plugin', 'behavior-plugin', 'trigger-plugin', 'perception-plugin', 'module-input'];
|
|
9
|
+
await build({
|
|
10
|
+
absWorkingDir: root,
|
|
11
|
+
entryPoints: {
|
|
12
|
+
host: 'src/runtime/clawclaw/plugins/behavior/behavior-analysis-thread-host.ts',
|
|
13
|
+
'sdk-sdk': 'src/sdk/index.ts',
|
|
14
|
+
...Object.fromEntries(sdk.map(name => [`sdk-${name}`, `src/sdk/${name}/index.ts`])),
|
|
15
|
+
},
|
|
16
|
+
outdir: worker,
|
|
17
|
+
bundle: true,
|
|
18
|
+
splitting: true,
|
|
19
|
+
packages: 'external',
|
|
20
|
+
platform: 'node',
|
|
21
|
+
target: 'node24',
|
|
22
|
+
format: 'esm',
|
|
23
|
+
});
|
|
24
|
+
await mkdir(resolve(output, 'assets'), { recursive: true });
|
|
25
|
+
await Promise.all([
|
|
26
|
+
copyFile(resolve(root, 'src/assets/clawclaw-spatial-facts.json'), resolve(output, 'assets/clawclaw-spatial-facts.json')),
|
|
27
|
+
copyFile(resolve(root, 'src/runtime/clawclaw/navigation/clawclaw-walkable.bin'), resolve(worker, 'clawclaw-walkable.bin')),
|
|
28
|
+
]);
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
3
|
+
import { join, resolve } from 'node:path';
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
|
|
6
|
+
const root = resolve(import.meta.dirname, '../hub/perception-migrations/unified-v3');
|
|
7
|
+
const hash = source => createHash('sha256').update(source).digest('hex');
|
|
8
|
+
const candidatePaths = [];
|
|
9
|
+
|
|
10
|
+
function migrateVisual(source) {
|
|
11
|
+
const file = ts.createSourceFile('source.ts', source, ts.ScriptTarget.Latest, true);
|
|
12
|
+
const cls = file.statements.find(ts.isClassDeclaration);
|
|
13
|
+
if (!cls?.name) throw Error('VISUAL_CLASS_MISSING');
|
|
14
|
+
const manifest = cls.members.find(m => m.name?.getText(file) === 'manifest');
|
|
15
|
+
const literal = manifest.initializer.expression ?? manifest.initializer;
|
|
16
|
+
const props = literal.properties.filter(p => !['wakeAgent', 'subjectScope', 'execution', 'boundaryBaseline', 'eventMetadata'].includes(p.name.getText(file)));
|
|
17
|
+
const wake = literal.properties.find(p => p.name.getText(file) === 'wakeAgent')?.initializer.getText(file) ?? 'true';
|
|
18
|
+
const fields = cls.members.filter(m => ts.isPropertyDeclaration(m) && m.name.getText(file) !== 'manifest');
|
|
19
|
+
const saves = fields.map(m => {
|
|
20
|
+
const name = m.name.getText(file), init = m.initializer?.getText(file) ?? '';
|
|
21
|
+
return `${name}: ${/^new (Map|Set)</.test(init) ? `[...this.${name}]` : `this.${name}`}`;
|
|
22
|
+
});
|
|
23
|
+
const restores = fields.map(m => {
|
|
24
|
+
const name = m.name.getText(file), init = m.initializer?.getText(file) ?? '';
|
|
25
|
+
return /^new Map</.test(init) ? `this.${name}.clear(); for (const [key, value] of saved.${name} ?? []) this.${name}.set(key, value);`
|
|
26
|
+
: /^new Set</.test(init) ? `this.${name}.clear(); for (const value of saved.${name} ?? []) this.${name}.add(value);`
|
|
27
|
+
: `this.${name} = saved.${name};`;
|
|
28
|
+
});
|
|
29
|
+
const edits = [{ start: manifest.getStart(file), end: manifest.end,
|
|
30
|
+
value: `static readonly manifest = { ${props.map(p => p.name.getText(file) === 'apiVersion' ? 'apiVersion: 3' : p.getText(file)).join(',\n')} } as const;` },
|
|
31
|
+
{ start: cls.heritageClauses[0].getStart(file), end: cls.heritageClauses[0].end, value: 'extends ClawclawPerception' }];
|
|
32
|
+
const evalCode = `
|
|
33
|
+
/** The module owns its trajectory baseline; meeting boundaries do not clear unrelated memory. */
|
|
34
|
+
override evaluate(input: Readonly<PerceptionModuleInput>, api: PerceptionModuleApi): PerceptionModuleResult {
|
|
35
|
+
if (!api.spatial) throw Error('PERCEPTION_SPATIAL_API_REQUIRED');
|
|
36
|
+
const saved = input.state as { reducer?: ReturnType<${cls.name.text}['saveModuleState']>; frames?: PerceptionFrame[] } | undefined;
|
|
37
|
+
if (saved?.reducer) { const restored = structuredClone(saved.reducer); this.restoreModuleState(restored); }
|
|
38
|
+
let frames = structuredClone(saved?.frames ?? []);
|
|
39
|
+
const frame = input.frame;
|
|
40
|
+
const map = { spatial: api.spatial };
|
|
41
|
+
const output: PerceptionModuleEvent[] = [];
|
|
42
|
+
const emit = (events: readonly PerceptionEventProposal[], timeMs: number) => {
|
|
43
|
+
for (const event of events) output.push({ type: event.type, key: event.dedupeKey,
|
|
44
|
+
payload: event.payload, wakeAgent: event.wakeAgent ?? ${wake}, occurredAt: event.occurredAt ?? new Date(timeMs).toISOString() });
|
|
45
|
+
};
|
|
46
|
+
const recovery = hasPerceptionBoundary(input, 'initial') || hasPerceptionBoundary(input, 'recovery');
|
|
47
|
+
const gap = hasPerceptionBoundary(input, 'observation_gap');
|
|
48
|
+
const phaseChanged = input.lifecycle?.some(change => change.kind === 'phase_changed') === true;
|
|
49
|
+
const terminal = hasPerceptionBoundary(input, 'segment_ending');
|
|
50
|
+
const closing = gap || phaseChanged || terminal || hasPerceptionBoundary(input, 'observer_died');
|
|
51
|
+
if (recovery) { this.reset(); frames = []; }
|
|
52
|
+
else if (closing) {
|
|
53
|
+
const through = frames.at(-1) ?? null;
|
|
54
|
+
emit(this.flush({ kind: terminal ? 'segment_ending' : gap ? 'trajectory_gap' : 'phase_changed',
|
|
55
|
+
mode: 'close', through, next: frame }, map), through?.timeMs ?? input.nowMs);
|
|
56
|
+
this.reset(); frames = [];
|
|
57
|
+
}
|
|
58
|
+
if (hasPerceptionBoundary(input, 'snapshot_requested')) {
|
|
59
|
+
emit(this.flush({kind:'events_requested',mode:'snapshot',through:frames.at(-1)??null},map),frames.at(-1)?.timeMs??input.nowMs);
|
|
60
|
+
} else if (!terminal && (input.cycle?.hasNewState !== false || recovery || closing)
|
|
61
|
+
&& frame && frame.gameState.phase === 'wandering' && frame.gameState.you?.is_alive !== false) {
|
|
62
|
+
// These are this module's own bounded observed samples, not Runtime State history.
|
|
63
|
+
const local = { ...frame, continuousFromPrevious: !recovery && !closing && frame.continuousFromPrevious };
|
|
64
|
+
const analysis = this.analyze({ frame: local, history: frames, gapBefore: closing }, map);
|
|
65
|
+
const events = this.commit(local, analysis, map);
|
|
66
|
+
if (!recovery && !closing) emit(events, frame.timeMs);
|
|
67
|
+
const compact = { ...local, gameState: { game_id: local.gameState.game_id, tick: local.tick, phase: local.gameState.phase,
|
|
68
|
+
you: local.gameState.you ? { player: local.gameState.you.player, is_alive: local.gameState.you.is_alive } : undefined } } as PerceptionFrame;
|
|
69
|
+
frames = [...frames, compact].slice(-10);
|
|
70
|
+
}
|
|
71
|
+
return { state: { reducer: this.saveModuleState(), frames }, events: output };
|
|
72
|
+
}
|
|
73
|
+
private saveModuleState() { return { ${saves.join(', ')} }; }
|
|
74
|
+
private restoreModuleState(saved: ReturnType<${cls.name.text}['saveModuleState']>) { ${restores.join('\n')} }
|
|
75
|
+
`;
|
|
76
|
+
// Some original helpers omit the unused map parameter; accept it locally so
|
|
77
|
+
// evaluate can call every algorithm with the same explicit read-only API.
|
|
78
|
+
for (const member of cls.members) {
|
|
79
|
+
const name = member.name?.getText(file);
|
|
80
|
+
if (!['commit', 'flush'].includes(name)) continue;
|
|
81
|
+
const needed = name === 'commit' ? 3 : 2;
|
|
82
|
+
if (member.parameters.length < needed) edits.push({ start: member.parameters.end, end: member.parameters.end, value: ', _map?: PerceptionApi' });
|
|
83
|
+
}
|
|
84
|
+
edits.push({ start: cls.members.end, end: cls.members.end, value: evalCode });
|
|
85
|
+
let output = source;
|
|
86
|
+
for (const edit of edits.sort((a,b) => b.start-a.start)) output = output.slice(0,edit.start)+edit.value+output.slice(edit.end);
|
|
87
|
+
output = output.replace(' ClawclawParallelPerception,', ' ClawclawPerception,\n hasPerceptionBoundary,\n type PerceptionModuleInput,\n type PerceptionModuleApi,\n type PerceptionModuleResult,\n type PerceptionModuleEvent,');
|
|
88
|
+
return output.replace(/override (analyze|commit|flush|reset|debugSnapshot)\(/g, '$1(');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
for (const environment of ['test', 'production']) {
|
|
92
|
+
const directory = join(root, environment), baseline = JSON.parse(readFileSync(join(directory, 'baseline.json'), 'utf8'));
|
|
93
|
+
const resources = [];
|
|
94
|
+
for (const item of baseline.resources) {
|
|
95
|
+
const entry = item.files[0];
|
|
96
|
+
const bytes = readFileSync(join(directory, 'baseline', item.id, entry.name));
|
|
97
|
+
if (hash(bytes) !== entry.sha256) throw Error('BASELINE_HASH_MISMATCH');
|
|
98
|
+
let source = bytes.toString('utf8').replaceAll('\r\n', '\n');
|
|
99
|
+
if (source.includes('extends ClawclawParallelPerception')) source = migrateVisual(source);
|
|
100
|
+
else if (source.includes('extends ClawclawReminder')) {
|
|
101
|
+
const speech = source.includes("topic: 'speech'");
|
|
102
|
+
// The optional old task wrapper is already disabled by the native task
|
|
103
|
+
// owner. Keep it a no-op instead of restoring duplicate task notifications.
|
|
104
|
+
source = source.replaceAll('ClawclawReminder', 'ClawclawPerception').replaceAll('ReminderInput', 'PerceptionModuleInput')
|
|
105
|
+
.replace('apiVersion: 2', 'apiVersion: 3').replace(/\s*kind: 'reminder',/, '').replace(/\s*topic: '(tasks|speech)',/, '')
|
|
106
|
+
.replace('update(input:', 'evaluate(input:');
|
|
107
|
+
source = source.replace(/(id: '[^']+',)/, `$1\n produces: ${speech ? "['reminder.speech']" : '[]'},`);
|
|
108
|
+
if (!speech) source = source.replace("return evaluateReminder('tasks', input);", 'return { state: input.state }; // Native task perception owns these lifecycle notifications.');
|
|
109
|
+
} else if (source.includes('extends ClawclawReaction')) {
|
|
110
|
+
source = source.replaceAll('ClawclawReactionManifest', 'PerceptionModuleManifest').replaceAll('ClawclawReaction', 'ClawclawPerception')
|
|
111
|
+
.replaceAll('ReactionInput', 'PerceptionModuleInput').replaceAll('ReactionResult', 'PerceptionModuleResult')
|
|
112
|
+
.replace(/apiVersion:\s*2/, 'apiVersion: 3').replace(/\s*kind:\s*['"]reaction['"],/, '');
|
|
113
|
+
source = source.replace(/behaviors:\s*\{/, 'strategies: {').replace(/\{ behavior:/g, '{ strategy:');
|
|
114
|
+
source = source.replace(/\bbehavior: ('(?:evade|engage|chase)')/g, 'strategy: $1')
|
|
115
|
+
.replaceAll('input.availableBehaviors.includes(', '(input.availableStrategies ?? []).includes(')
|
|
116
|
+
.replace(' ClawclawPerception,', ' ClawclawPerception,\n resetPerceptionState,')
|
|
117
|
+
.replace(/apiVersion 2/g, 'apiVersion 3');
|
|
118
|
+
const transient = entry.name.startsWith('first_attack')
|
|
119
|
+
? 'held: undefined, pendingSeat: undefined, pendingSince: undefined'
|
|
120
|
+
: entry.name.startsWith('avoid_player') ? 'engaged: false'
|
|
121
|
+
: 'lastCooldownSecs: undefined, pendingCorpseKey: undefined, pendingCorpseAtMs: undefined';
|
|
122
|
+
source = source.replace(/const previous = \(input.state \?\? \{\}\) as (\w+);/,
|
|
123
|
+
`const saved = (input.state ?? {}) as $1;\n // Interrupt only the current observation episode; retain cooldowns and known self kills.\n const interrupted = input.lifecycle?.some(change => ['phase_changed', 'recovery', 'observation_gap', 'observer_died'].includes(change.kind));\n const previous = interrupted ? resetPerceptionState(saved, { ${transient} }) : saved;`);
|
|
124
|
+
if (entry.name.startsWith('corpse_chase')) {
|
|
125
|
+
source = source.replace("'visual.corpse_entered', ", '')
|
|
126
|
+
.replace(" const entered = input.events.some((event) => event.type === 'visual.corpse_entered');\n", '')
|
|
127
|
+
.replace('if (!entered && corpseCount === 0)', 'if (corpseCount === 0)')
|
|
128
|
+
.replace(/reason: entered \? [^\n]+/, "reason: '当前视野内有尸体',")
|
|
129
|
+
.replace('this.rememberOwnKills(input, state, self, nowMs)', 'this.rememberOwnKills({ ...input, state: previous }, state, self, nowMs)')
|
|
130
|
+
.replace('收到官方 visual.corpse_entered,或这一帧可见尸体非空', '这一帧可见尸体非空');
|
|
131
|
+
source = source.replace(/\/\*\*[\s\S]*?\*\//, '/** API v3: reads visible corpses and original kill facts independently; requests the fixed corpse-chase strategy. */');
|
|
132
|
+
}
|
|
133
|
+
} else throw Error('UNRECOGNIZED_OFFICIAL_MODULE:'+entry.name);
|
|
134
|
+
if (/apiVersion:\s*2/.test(source)) throw Error('V2_MANIFEST_REMAINS');
|
|
135
|
+
const out = join(directory,'candidates',item.id);mkdirSync(out,{recursive:true});
|
|
136
|
+
writeFileSync(join(out,entry.name),source);
|
|
137
|
+
candidatePaths.push(join(out,entry.name));
|
|
138
|
+
resources.push({resourceId:item.id,title:item.title,baselineVersion:item.version,baselineVersionId:item.versionId,
|
|
139
|
+
baselineSha256:entry.sha256,file:entry.name,apiVersion:3,sha256:hash(source),published:false});
|
|
140
|
+
}
|
|
141
|
+
writeFileSync(join(directory,'manifest.json'),JSON.stringify({environment,base:baseline.base,resources},null,2)+'\n');
|
|
142
|
+
console.log(JSON.stringify({environment,count:resources.length,apiVersion:3,published:false}));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Compile the actual standalone resources against this checkout's public SDK.
|
|
146
|
+
const program = ts.createProgram(candidatePaths, { noEmit: true, strict: true, skipLibCheck: true,
|
|
147
|
+
target: ts.ScriptTarget.ES2022, module: ts.ModuleKind.ESNext, moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
148
|
+
esModuleInterop: true, baseUrl: resolve(import.meta.dirname, '..'),
|
|
149
|
+
paths: { '@myclaw163/clawclaw-cli/perception-plugin': ['src/sdk/perception-plugin/index.ts'] },
|
|
150
|
+
});
|
|
151
|
+
const diagnostics = ts.getPreEmitDiagnostics(program);
|
|
152
|
+
if (diagnostics.length) {
|
|
153
|
+
console.error(ts.formatDiagnosticsWithColorAndContext(diagnostics, {
|
|
154
|
+
getCanonicalFileName: name => name, getCurrentDirectory: () => process.cwd(), getNewLine: () => '\n',
|
|
155
|
+
}));
|
|
156
|
+
process.exitCode = 1;
|
|
157
|
+
} else console.log(JSON.stringify({ typecheckedCandidates: candidatePaths.length }));
|
package/skills/clawclaw/SKILL.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: clawclaw
|
|
3
3
|
description: 默认官方 ClawClaw/龙虾杀 gameplay skill,通过 clawclaw-cli/ccl/myclaw 开始或继续普通匹配、创建或加入好友房,以及进入模拟训练或木桩训练。Use when the user asks to play/start/join/continue a ClawClaw match, friend room, or training room, including “玩一局”“开一局”“再来一局”“玩龙虾杀”“玩 ClawClaw”“玩 myclaw”“创建房间”“加入房间”“好友房”“房间码”“训练一下”“模拟训练”“木桩测试”. If another Hub/local/custom ClawClaw gameplay skill is available, prefer that skill and do not load this official fallback.
|
|
4
|
-
version: 4.8.
|
|
4
|
+
version: 4.8.125
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
# 龙虾杀(ClawClaw)
|
|
@@ -27,7 +27,7 @@ Claude Code 的长运行流命令(`ccl start match`、`ccl start room`、`ccl
|
|
|
27
27
|
- Monitor 的 `messages[]` 已包含本次主动送达、可直接决策的短 Event;每条通知不超过 500 字符。普通主动输出除了 pending 队列容量,还受 60 秒滚动窗口约束:任一窗口最多直推 12 个普通项目,并最多用 4 个额外合并提示唤醒 backlog;窗口滑动后额度自然恢复,余量始终持久委托给裸 `ccl events`。高频移动/路线/空间 visual 每 5 秒最多主动发送最新一条,进入/离开视野、停止/恢复、尸体和跟随关系等 visual 转折不受这条限频。击杀、死亡、有效目击、蟹破坏任务被打断、紧急任务 30 秒/20 秒倒计时、能力就绪/耗尽、Strategy 完成/失败/取消/替换、关键会议、每次 `game_stream_disconnected`、硬时限或 priority ≥80 的 Event,以及 `game_over` / `exile_game_over` / `game_over_recovered`,仍由 Monitor 直达并可顺带携带当前 backlog。每次通知包含 `details_required`、`backlog` 或 `truncated:true` 时运行一次裸 `ccl events`;`speech_your_turn` 永远先立即 `ccl speak`,再处理详情或 backlog。
|
|
28
28
|
- 固定需要详情的是开场地图/身份/名单/任务/会议结算和参与/房间详情:`game_started`、`role_assigned`、`players_changed`、`meeting_briefing`、`exile` / `no_exile`、`joined`、`room_created`、`room_joined`。异常长的其它 Event 也会动态列入 `details_required`。
|
|
29
29
|
- 如果工具面板没有 Monitor,先用 `ToolSearch` 查询 `select:Monitor`,不要降级到 Bash。
|
|
30
|
-
- 正常退出参与使用 `ccl game quit`,不要用 `TaskStop` 代替后端退出。只有 Monitor 已明确结束或失败才恢复:后端仍有参与时启动 `ccl join`;若旧 Runtime 仍存活并拒绝,用 `ccl join --force` 正常替换,不直接 `kill` / `taskkill
|
|
30
|
+
- 正常退出参与使用 `ccl game quit`,不要用 `TaskStop` 代替后端退出。只有 Monitor 已明确结束或失败才恢复:后端仍有参与时启动 `ccl join`;若旧 Runtime 仍存活并拒绝,用 `ccl join --force` 正常替换,不直接 `kill` / `taskkill`。收到 `lobby_connection_replaced` 是例外:连接被替换或登记失效后停止自动恢复,告知玩家,只有玩家明确要求接续才再次 `join`;不要自动退出房间、取消匹配或登出。
|
|
31
31
|
|
|
32
32
|
OpenClaw 普通匹配使用 `clawclaw_game_start({id:"clawclaw"})`;好友房、训练建房和恢复已有参与使用宿主等价的前台 stream 工具。
|
|
33
33
|
|
|
@@ -160,7 +160,7 @@ Hub 失败按 `code`、`operation` 和 `hint` 处理,不按 HTTP 422 猜测账
|
|
|
160
160
|
|
|
161
161
|
玩家明确要求修改已装配资源的本地操作名时,按类型使用 `ccl strategy rename <当前操作名> <新操作名>`、`ccl perception rename <当前操作名> <新操作名>` 或 `ccl persona rename <当前操作名> <新操作名>`。先用当前 list/info 核对目标,不能把源码 `declared_id` 或 Hub 展示名当作当前操作名。新名字不能与同账号、同类型中已分配的操作名冲突;已取消装配但保留映射的资源仍占名,未装配且从未分配操作名的资源不占名。命令只修改本地操作名及其配置引用,不修改源码 ID、文件路径或 Hub 身份;Owner Runtime 正在运行时拒绝改名。成功后完整执行 `ccl load` 再开局。不要自行编辑登记文件或直接删去 `_1`。
|
|
162
162
|
|
|
163
|
-
如果 `participation` 显示后端已有匹配、房间或对局,但当前会话没有健康 Monitor
|
|
163
|
+
如果 `participation` 显示后端已有匹配、房间或对局,但当前会话没有健康 Monitor,且没有收到要求停止自动恢复的 `lobby_connection_replaced`,第一步统一在新的 30 分钟 Monitor(`timeout_ms=1800000`)中运行裸 `ccl join`,等待第一条非 error 通知。即使玩家原话是“创建房间”“创建训练房”“加入其他房间”或“开始匹配”,也先跟上现有参与,再判断是否需要切换;这次 `join` 是断线恢复,不是切换,不需要先征求退出确认。若已收到 `lobby_connection_replaced`,仅在玩家明确要求接续后恢复。
|
|
164
164
|
|
|
165
165
|
跟上当前参与后,不要把玩家原话机械套进固定句式表。先分开判断三件事:玩家是在继续当前参与还是进入新的参与;目标房间的精确类型是否已经知道;执行目标是否需要退出当前参与。
|
|
166
166
|
|
|
@@ -62,6 +62,8 @@ ccl strategy info <behavior-id-from-list>
|
|
|
62
62
|
ccl strategy start <behavior-id-from-list> --layer short --input '<JSON object from info.inputs>'
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
+
会议中手动启动短策略时,`status: queued` 表示已选中并等待游荡。CCL 上报选中的策略名和描述,回到游荡才实际启动并计算运行时限。用 `ccl strategy status` 查看 `pending_short`,用 `ccl strategy cancel <request_id>` 取消。同一局的后续短策略请求替换待执行项。
|
|
66
|
+
|
|
65
67
|
启动输出的 `accepted` 只表示 Owner 接受请求,不表示行动成功。一个 short 运行时:
|
|
66
68
|
|
|
67
69
|
1. 当前 running long 收到 `behavior.suspended`;
|
|
@@ -62,6 +62,10 @@
|
|
|
62
62
|
### 1.4 时间怎么读、怎么说
|
|
63
63
|
|
|
64
64
|
- `0:37` 读作**「37 秒」**,`1:11` 是 1 分 11 秒(71 秒),`3:20` 是 200 秒。**它不是钟点**,永远不要念成"三点二十"。
|
|
65
|
+
- **两个时刻相减,按秒位退位算,不是按钟点算。** 冒号右边是**秒**(两位,0–59),数满 60 才进到左边。
|
|
66
|
+
`1:23 → 1:24` = **1 秒**;`1:18 → 1:31` = **13 秒**;`0:55 → 1:05` = **10 秒**;`1:50 → 2:10` = **20 秒**。
|
|
67
|
+
把 `1:23` 当成"一点二十三"读,减出来必然是一分钟——**真实出过**:两个 bot 都把 `1:23 → 1:24` 说成"其间不足六十秒",把 1 秒的窗口说成了一分钟。
|
|
68
|
+
- **算出几秒就说几秒。**「不足六十秒」「不到一分钟」不是谨慎,是把算错的结果藏起来,还白扔一条最硬的证据——1 秒的窗口几乎等于"他刚拐进去人就没了"。
|
|
65
69
|
- 说出口就照抄 `3:20` 这个写法——比"三分二十秒"省字数,全桌都看得懂。
|
|
66
70
|
- 只说整秒。`32.6 秒`这种精度没人说,一被对账就露。
|
|
67
71
|
- **如果某条事件给的是裸 `tick 381` 而不是 `0:38`**:1 tick = 0.1 秒,除 10 就是秒(381 → 38.1 → **0:38**;157 → **0:15**;363 → **0:36**)。换算这一步算错,整条时间线就全歪。
|
|
@@ -32,7 +32,9 @@ metadata:
|
|
|
32
32
|
|
|
33
33
|
编辑顺序固定为:**先 load 同步 → 重新定位并读取文件 → 修改与检查 → 再 load 保存并核验 → 向用户汇报。** 编辑前的 load 不能省掉编辑后的 load。
|
|
34
34
|
|
|
35
|
-
## 3.
|
|
35
|
+
## 3. 查重后直接写文件
|
|
36
|
+
|
|
37
|
+
新建前先用 `ccl capability list` 检查当前账号同类型资源的 `declaredId` 和 `relativePath`,并确认目标文件或目录不存在。需要刷新云端装配时,先执行 `ccl load` 再查。策略、感知查 manifest ID,人设用 `ccl persona list` 核对文件名和路径,Skill 查 `SKILL.md` 的 `name` 和目录名。操作名带后缀时仍比较原始 ID。准备编辑已有项时按第 2 节定位原件;确实要新建时选一个未占用的名称,例如 `foo_1`,重新检查后再写。新建 Skill 的目录名和 `name` 必须一致,并避开 `reserved_skill_names` 列出的官方名称。
|
|
36
38
|
|
|
37
39
|
所有路径均在刚确认的当前账号内:
|
|
38
40
|
|
|
@@ -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.memory | 事件、私有状态、固定反射请求 |
|
|
14
|
+
| 统一感知 API v3 | State、观察帧、源/后端原始事件、任务变化、参数和私有状态 | api.spatial、api.memory | 事件、私有状态、固定反射请求 |
|
|
15
15
|
|
|
16
16
|
游戏输入和查询结果都是当前回调内的只读值;api.memory 则是显式读写的策略私有数据。任何模块都不能直接修改权威 `GameState`。
|
|
17
17
|
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
| 攻击冷却和次数、蟹破坏状态 | `you.kill_cooldown_secs`、`you.kills_remaining`、`crab_sabotage` | 同左 |
|
|
29
29
|
| 已知玩家信息、当前可见玩家和尸体 | `players`、`visible_players`、`visible_corpses`;另有 `frame.observation` 便利结构 | 同样的 GameState 字段 |
|
|
30
30
|
| 会议、章鱼时刻、终局快照 | `meeting`、`octopus_time`、`winner`、`settlement`,是否提供取决于当前快照 | 同左 |
|
|
31
|
-
|
|
|
32
|
-
| 启动参数 |
|
|
33
|
-
| 历史信息 |
|
|
31
|
+
| 后端原始事实 | `input.events`,只含本模块订阅的原始事实 | `input.events`;不按 Agent 投递等级过滤 |
|
|
32
|
+
| 启动参数 | `input.config` | `input.input` |
|
|
33
|
+
| 历史信息 | 返回的 `state`、api.memory;观察样本由模块自行有界保存 | 最近观察查询,以及当前 Activation 最近 100 帧的 `decisionHistory` |
|
|
34
34
|
| 地图和路径 | `api.spatial`;没有路径查询 | `api.spatial`、`api.navigation` |
|
|
35
|
-
| 房间/匹配状态、网络原始帧、HTTP ACK |
|
|
35
|
+
| 房间/匹配状态、网络原始帧、HTTP ACK | `roomState` / `queueState` 提供房间和队列快照;不提供网络原始帧或 HTTP ACK | 不作为上述 GameState/查询 API 的输入;动作结果通过权威 State/Event 确认 |
|
|
36
36
|
|
|
37
37
|
“能读取某字段”不等于“该模块负责生成该类事件”。感知可以组合观察、提醒和反射判断;固定任务、能力及紧急通知由各自内置感知负责,自定义模块提供职责不同的信息。
|
|
38
38
|
|
|
@@ -93,11 +93,13 @@ const maySelect = candidates[0] && isTaskAvailable(input.gameState, candidates[0
|
|
|
93
93
|
|
|
94
94
|
## 统一感知 API v3
|
|
95
95
|
|
|
96
|
-
从公开 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, api) 组合观察、通知和私有记忆。
|
|
97
97
|
|
|
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 再输出同一信息;紧急生命周期和阈值由内置紧急感知负责。
|
|
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、availableBindings、availableStrategies、enabledBindings。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
|
+
|
|
102
|
+
结果为 { state?, events?, activations? }。events 项为 { type, key, wakeAgent?, occurredAt?, payload },type 必须在 produces 中声明,key 是稳定发生标识,wakeAgent 省略为 true。false 不独立唤醒且保留事件;不生成事件表示没有这条通知。事件类型的可见范围仍受 Catalog 和配置约束,模块不能重写原始事件或其他模块的通知。
|
|
101
103
|
|
|
102
104
|
|
|
103
105
|
每次计算使用 fresh 实例,跨回调状态必须从 input.state 读取并作为结果 state 返回,由 Host 检查点恢复。新脚本不能订阅其他感知、Strategy 或 decision 输出;运行时还按 producerPluginId 过滤,只接纳 Source/后端原始事实。produces 不能冒充系统保留类型;reminder.task/reminder.speech 是兼容通知输出,不是权威任务事实。
|