@myclaw163/clawclaw-cli 0.7.15 → 0.8.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_HERMES.md +1 -1
- package/QUICKSTART_OPENCLAW.md +3 -11
- package/QUICKSTART_OTHER.md +8 -8
- package/README.md +18 -9
- package/bin/clawclaw-channel.mjs +13 -0
- package/docs/configuration.md +86 -33
- package/docs/custom-modules/README.md +148 -0
- package/docs/custom-modules/api-reference.md +767 -0
- package/docs/custom-modules/behavior.md +318 -0
- package/docs/custom-modules/perception.md +305 -0
- package/docs/custom-modules/trigger.md +292 -0
- package/docs/desktop-event-push.md +6 -4
- package/docs/runtime/README.md +28 -10
- package/docs/runtime/agent-notifications.md +48 -29
- package/docs/runtime/behavior-runtime.md +139 -0
- package/docs/runtime/components-and-boundaries.md +89 -173
- package/docs/runtime/events-and-state.md +55 -66
- package/docs/runtime/official-perception-modules.md +17 -9
- package/docs/runtime/owner-lifecycle-and-observability.md +62 -39
- package/docs/runtime/perception-replay.md +6 -6
- package/docs/runtime/short-commands-and-capabilities.md +35 -37
- package/package.json +7 -4
- package/scripts/check-skill-command-surface.mjs +54 -10
- package/scripts/compare-perception-replays.test.ts +10 -10
- package/scripts/compare-perception-replays.ts +14 -10
- package/scripts/replay-perception.ts +3 -3
- package/scripts/watch-perception-events.test.ts +1 -1
- package/skills/clawclaw/SKILL.md +97 -59
- package/skills/clawclaw/references/BEHAVIORS.md +154 -0
- package/skills/clawclaw/references/CHANNELS.md +115 -0
- package/skills/clawclaw/references/CHATTERBOX.md +3 -2
- package/skills/clawclaw/references/COMMANDS.md +108 -58
- package/skills/clawclaw/references/GAME-MECHANICS.md +4 -3
- package/skills/clawclaw/references/HUB.md +27 -23
- package/skills/clawclaw/references/STREAM.md +18 -14
- package/skills/clawclaw/references/TACTICS.md +2 -2
- package/src/behaviors/official-finite/do-task.ts +141 -0
- package/src/behaviors/official-finite/evade.ts +78 -0
- package/src/behaviors/official-finite/find-player.ts +50 -0
- package/src/behaviors/official-finite/follow-player.ts +70 -0
- package/src/behaviors/official-finite/go-to.ts +69 -0
- package/src/behaviors/official-finite/hide-temporarily.ts +77 -0
- package/src/behaviors/official-finite/hold-position.ts +48 -0
- package/src/behaviors/official-finite/hunt-player.ts +47 -0
- package/src/behaviors/official-finite/index.test.ts +202 -0
- package/src/behaviors/official-finite/index.ts +47 -0
- package/src/behaviors/official-finite/inspect-corpse.ts +64 -0
- package/src/behaviors/official-finite/patrol-area.ts +80 -0
- package/src/behaviors/official-finite/report-corpse.ts +73 -0
- package/src/behaviors/official-finite/seek-kill-opportunity.ts +152 -0
- package/src/behaviors/official-finite/shared.ts +27 -0
- package/src/behaviors/official-finite/trigger-alarm.ts +53 -0
- package/src/channel/claude-channel-ipc-server.ts +295 -0
- package/src/channel/claude-channel-ipc.ts +152 -0
- package/src/channel/claude-channel-server.test.ts +202 -0
- package/src/channel/claude-channel-server.ts +221 -0
- package/src/cli.ts +4 -2
- package/src/commands/account.test.ts +17 -17
- package/src/commands/behavior.test.ts +158 -0
- package/src/commands/behavior.ts +443 -0
- package/src/commands/communication.test.ts +12 -0
- package/src/commands/communication.ts +6 -3
- package/src/commands/data.test.ts +1 -1
- package/src/commands/data.ts +1 -1
- package/src/commands/events-canonical-state.test.ts +221 -2
- package/src/commands/events.ts +205 -12
- package/src/commands/game/index.test.ts +172 -3
- package/src/commands/game/index.ts +69 -32
- package/src/commands/hub.test.ts +25 -14
- package/src/commands/hub.ts +15 -19
- package/src/commands/load.test.ts +228 -6
- package/src/commands/load.ts +102 -18
- package/src/commands/memory.ts +1 -1
- package/src/commands/peek.ts +1 -1
- package/src/commands/perception.test.ts +30 -1
- package/src/commands/perception.ts +15 -17
- package/src/commands/trigger.test.ts +140 -0
- package/src/commands/trigger.ts +314 -0
- package/src/lib/account-guidance.test.ts +4 -0
- package/src/lib/account-guidance.ts +1 -1
- package/src/lib/behavior-export.test.ts +282 -0
- package/src/lib/behavior-export.ts +514 -0
- package/src/lib/game-client.test.ts +4 -17
- package/src/lib/game-client.ts +3 -0
- package/src/lib/gameplay-config.test.ts +258 -37
- package/src/lib/gameplay-config.ts +175 -35
- package/src/lib/hub-install.test.ts +19 -41
- package/src/lib/hub-install.ts +10 -38
- package/src/lib/hub-reminder.ts +7 -9
- package/src/lib/init-command.ts +1 -1
- package/src/lib/official-resource-sync.test.ts +199 -0
- package/src/lib/official-resource-sync.ts +221 -0
- package/src/lib/perception-config.test.ts +9 -4
- package/src/lib/perception-config.ts +10 -13
- package/src/lib/perception-export.test.ts +145 -0
- package/src/lib/perception-export.ts +178 -0
- package/src/lib/trigger-config.test.ts +102 -0
- package/src/lib/trigger-config.ts +217 -0
- package/src/lib/user-data.test.ts +23 -6
- package/src/lib/user-data.ts +15 -123
- package/src/pipeline/canonical-event-presentation.test.ts +5 -5
- package/src/pipeline/canonical-event-presentation.ts +13 -5
- package/src/pipeline/event-format.test.ts +106 -3
- package/src/pipeline/event-format.ts +172 -4
- package/src/pipeline/event-hints.test.ts +57 -4
- package/src/pipeline/event-hints.ts +34 -8
- package/src/runtime/canonical-monitor.test.ts +2 -0
- package/src/runtime/canonical-monitor.ts +6 -2
- package/src/runtime/clawclaw/agent-event-policy.test.ts +23 -2
- package/src/runtime/clawclaw/agent-event-policy.ts +12 -5
- package/src/runtime/clawclaw/behavior-decision.test.ts +29 -0
- package/src/runtime/clawclaw/behavior-decision.ts +82 -0
- package/src/runtime/clawclaw/behavior-input-fields.test.ts +175 -0
- package/src/runtime/clawclaw/behavior-input-fields.ts +270 -0
- package/src/runtime/clawclaw/behavior-input.test.ts +151 -0
- package/src/runtime/clawclaw/behavior-input.ts +70 -0
- package/src/runtime/clawclaw/behavior-observation-memory.test.ts +59 -0
- package/src/runtime/clawclaw/behavior-observation-memory.ts +142 -0
- package/src/runtime/clawclaw/behavior-read-api.test.ts +123 -0
- package/src/runtime/clawclaw/behavior-read-api.ts +158 -0
- package/src/runtime/clawclaw/{plugins/perception/visual-state-projector.ts → observation-frame-projector.ts} +44 -25
- package/src/runtime/clawclaw/owner.test.ts +187 -0
- package/src/runtime/clawclaw/owner.ts +431 -69
- package/src/runtime/clawclaw/plugins/action/action-plugin.test.ts +304 -0
- package/src/runtime/clawclaw/plugins/action/action-plugin.ts +286 -41
- package/src/runtime/clawclaw/plugins/action/automated-action-normalization.ts +82 -0
- package/src/runtime/clawclaw/plugins/assembly.test.ts +135 -29
- package/src/runtime/clawclaw/plugins/assembly.ts +54 -28
- package/src/runtime/clawclaw/plugins/behavior/activation-manager.test.ts +180 -0
- package/src/runtime/clawclaw/plugins/behavior/activation-manager.ts +468 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-action.test.ts +40 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-action.ts +30 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-analysis-thread-host.ts +152 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.test.ts +156 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.ts +104 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-manifest.ts +173 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-module-loader.test.ts +182 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-module-loader.ts +223 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-normalization.ts +157 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.test.ts +848 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +1347 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-runner.ts +212 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-source.test.ts +174 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-source.ts +621 -0
- package/src/runtime/clawclaw/plugins/behavior/control-driver.test.ts +195 -0
- package/src/runtime/clawclaw/plugins/behavior/control-driver.ts +180 -0
- package/src/runtime/clawclaw/plugins/behavior/index.ts +11 -0
- package/src/runtime/clawclaw/plugins/behavior/official-goal-behavior.ts +766 -0
- package/src/runtime/clawclaw/plugins/behavior/thread-behavior-executor.test.ts +283 -0
- package/src/runtime/clawclaw/plugins/{strategy/thread-strategy-executor.ts → behavior/thread-behavior-executor.ts} +109 -121
- package/src/runtime/clawclaw/plugins/behavior-input-source.test.ts +80 -0
- package/src/runtime/clawclaw/plugins/behavior-input-source.ts +247 -0
- package/src/runtime/clawclaw/plugins/{strategy → game-query}/context-capabilities.ts +1 -1
- package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.test.ts +13 -10
- package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.ts +26 -14
- package/src/runtime/clawclaw/plugins/game-query/index.ts +1 -0
- package/src/runtime/clawclaw/plugins/index.ts +3 -1
- package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-adapter.test.ts +239 -0
- package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-adapter.ts +100 -0
- package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-socket.ts +346 -0
- package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.test.ts +230 -12
- package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.ts +118 -90
- package/src/runtime/clawclaw/plugins/mailbox/consumer-ids.ts +5 -0
- package/src/runtime/clawclaw/plugins/mailbox/index.ts +3 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-agent-event-batch.test.ts +1 -1
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-event-batch-delivery.ts +4 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.test.ts +87 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.ts +70 -12
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-presentation.ts +94 -11
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.test.ts +1229 -345
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.ts +479 -35
- package/src/runtime/clawclaw/plugins/perception/contracts.ts +4 -3
- package/src/runtime/clawclaw/plugins/perception/index.ts +1 -1
- package/src/runtime/clawclaw/plugins/perception/module-runner.test.ts +23 -13
- package/src/runtime/clawclaw/plugins/perception/module-runner.ts +11 -9
- package/src/runtime/clawclaw/plugins/perception/modules/co-movement-module.ts +39 -38
- package/src/runtime/clawclaw/plugins/perception/modules/corpse-visibility-module.test.ts +92 -0
- package/src/runtime/clawclaw/plugins/perception/modules/corpse-visibility-module.ts +248 -0
- package/src/runtime/clawclaw/plugins/perception/modules/follow-module.ts +39 -37
- package/src/runtime/clawclaw/plugins/perception/modules/index.ts +1 -0
- package/src/runtime/clawclaw/plugins/perception/modules/motion-module.test.ts +22 -21
- package/src/runtime/clawclaw/plugins/perception/modules/motion-module.ts +15 -9
- package/src/runtime/clawclaw/plugins/perception/modules/parallel-module-test-helpers.ts +3 -3
- package/src/runtime/clawclaw/plugins/perception/modules/relation-stability.test.ts +33 -18
- package/src/runtime/clawclaw/plugins/perception/modules/route-module.test.ts +6 -7
- package/src/runtime/clawclaw/plugins/perception/modules/route-module.ts +22 -16
- package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.test.ts +6 -7
- package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.ts +18 -12
- package/src/runtime/clawclaw/plugins/perception/modules/stop-module.test.ts +14 -10
- package/src/runtime/clawclaw/plugins/perception/modules/stop-module.ts +20 -14
- package/src/runtime/clawclaw/plugins/perception/modules/temporal-evidence.test.ts +5 -6
- package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.test.ts +5 -6
- package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.ts +49 -34
- package/src/runtime/clawclaw/plugins/perception/official-module-ids.ts +1 -0
- package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.test.ts +126 -20
- package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.ts +24 -3
- package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-worker.ts +59 -46
- package/src/runtime/clawclaw/plugins/perception/perception-module-loader.ts +27 -5
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.test.ts +381 -49
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +267 -245
- package/src/runtime/clawclaw/plugins/perception/perception-source.test.ts +98 -0
- package/src/runtime/clawclaw/plugins/perception/perception-source.ts +89 -16
- package/src/runtime/clawclaw/plugins/perception/perception-test-fixtures.ts +34 -0
- package/src/runtime/clawclaw/plugins/perception/replay.test.ts +27 -15
- package/src/runtime/clawclaw/plugins/perception/replay.ts +10 -5
- package/src/runtime/clawclaw/plugins/perception/shared/math.ts +1 -107
- package/src/runtime/clawclaw/plugins/perception/spatial-facts.ts +7 -10
- package/src/runtime/clawclaw/plugins/plugin-api-version.ts +112 -0
- package/src/runtime/clawclaw/plugins/runtime-plugins.test.ts +389 -559
- package/src/runtime/clawclaw/plugins/source/player-change-tracker.test.ts +56 -5
- package/src/runtime/clawclaw/plugins/source/player-change-tracker.ts +135 -26
- package/src/runtime/clawclaw/plugins/source/source-plugin.test.ts +249 -16
- package/src/runtime/clawclaw/plugins/source/source-plugin.ts +99 -2
- package/src/runtime/clawclaw/plugins/source/task-change-tracker.test.ts +212 -0
- package/src/runtime/clawclaw/plugins/source/task-change-tracker.ts +259 -0
- package/src/runtime/clawclaw/plugins/trigger/contracts.ts +97 -0
- package/src/runtime/clawclaw/plugins/trigger/index.ts +4 -0
- package/src/runtime/clawclaw/plugins/trigger/trigger-module-loader.ts +118 -0
- package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.test.ts +548 -0
- package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.ts +655 -0
- package/src/runtime/clawclaw/plugins/trigger/trigger-source.test.ts +169 -0
- package/src/runtime/clawclaw/plugins/trigger/trigger-source.ts +457 -0
- package/src/runtime/clawclaw/runtime.ts +8 -0
- package/src/runtime/clawclaw/spatial-api.ts +76 -0
- package/src/runtime/clawclaw-event-catalog.test.ts +46 -1
- package/src/runtime/clawclaw-event-catalog.ts +40 -3
- package/src/runtime/framework/capability-registry.test.ts +196 -55
- package/src/runtime/framework/capability-registry.ts +99 -17
- package/src/runtime/framework/contracts.ts +30 -4
- package/src/runtime/framework/control/control-scheduler.ts +13 -5
- package/src/runtime/framework/control/types.ts +11 -4
- package/src/runtime/framework/control-coordinator.test.ts +95 -80
- package/src/runtime/framework/events/event-delivery-service.ts +4 -2
- package/src/runtime/framework/events/event-ingress.test.ts +25 -0
- package/src/runtime/framework/events/event-ingress.ts +2 -1
- package/src/runtime/framework/events/event-repository.ts +24 -2
- package/src/runtime/framework/events/mailbox-event-repositories.test.ts +124 -8
- package/src/runtime/framework/events/memory-event-repository.ts +92 -28
- package/src/runtime/framework/events/sqlite-event-repository.test.ts +604 -2
- package/src/runtime/framework/events/sqlite-event-repository.ts +531 -21
- package/src/runtime/framework/events/types.ts +24 -8
- package/src/runtime/framework/modules/runtime-module-loader-hooks.mjs +38 -1
- package/src/runtime/framework/modules/runtime-module-loader.test.ts +233 -7
- package/src/runtime/framework/modules/runtime-module-loader.ts +69 -4
- package/src/runtime/framework/plugins/contracts.ts +12 -18
- package/src/runtime/framework/plugins/runtime-plugin-scheduler.test.ts +81 -71
- package/src/runtime/framework/plugins/runtime-plugin-scheduler.ts +38 -20
- package/src/runtime/framework/runtime.ts +20 -23
- package/src/runtime/host-monitor-rate-gate.test.ts +73 -0
- package/src/runtime/host-monitor-rate-gate.ts +123 -0
- package/src/runtime/mailbox-host-relay.test.ts +45 -0
- package/src/runtime/mailbox-host-relay.ts +25 -0
- package/src/runtime/observability/factory.ts +4 -4
- package/src/runtime/observability/observability.test.ts +25 -3
- package/src/runtime/observability/reporter.ts +1 -1
- package/src/runtime/observability/types.ts +2 -2
- package/src/runtime/owner-control.ts +10 -2
- package/src/runtime/runtime-logger.test.ts +1 -1
- package/src/runtime/runtime-logger.ts +4 -6
- package/src/runtime/runtime.test.ts +88 -22
- package/src/sdk/action.ts +2 -2
- package/src/sdk/behavior-plugin/index.test.ts +74 -0
- package/src/sdk/behavior-plugin/index.ts +335 -0
- package/src/sdk/behavior-toolkit/corpse-search.ts +87 -0
- package/src/sdk/behavior-toolkit/escape.ts +40 -0
- package/src/sdk/behavior-toolkit/index.ts +7 -0
- package/src/sdk/behavior-toolkit/kill-flow.ts +299 -0
- package/src/sdk/behavior-toolkit/model.ts +263 -0
- package/src/sdk/behavior-toolkit/move-gate.ts +52 -0
- package/src/sdk/behavior-toolkit/patrol.ts +53 -0
- package/src/sdk/behavior-toolkit/search.ts +102 -0
- package/src/sdk/index.test.ts +45 -0
- package/src/sdk/index.ts +67 -73
- package/src/sdk/module-input/index.test.ts +49 -0
- package/src/sdk/module-input/index.ts +229 -0
- package/src/sdk/perception-plugin/index.test.ts +2 -2
- package/src/sdk/perception-plugin/index.ts +51 -142
- package/src/sdk/perception-plugin/math.ts +107 -0
- package/src/sdk/trigger-plugin/index.test.ts +41 -0
- package/src/sdk/trigger-plugin/index.ts +128 -0
- package/src/strategies/avoid-lone.ts +21 -10
- package/src/strategies/avoid-players.ts +26 -16
- package/src/strategies/corpse-patrol.ts +25 -14
- package/src/strategies/crab-sabotage.ts +20 -9
- package/src/strategies/find-player.ts +33 -21
- package/src/strategies/game-utils.ts +1 -1
- package/src/strategies/goals/crab-sabotage-top.test.ts +145 -0
- package/src/strategies/goals/crab-sabotage-top.ts +32 -69
- package/src/strategies/hide.ts +25 -15
- package/src/strategies/kill-frenzy.ts +21 -10
- package/src/strategies/kill-lone.ts +27 -17
- package/src/strategies/kill-target.ts +33 -22
- package/src/strategies/lone-kill-task.ts +20 -9
- package/src/strategies/move-room.ts +29 -18
- package/src/strategies/official-long-behavior.test.ts +89 -0
- package/src/strategies/paradise-fish.ts +29 -18
- package/src/strategies/pathfind/astar-path.test.ts +127 -2
- package/src/strategies/pathfind/astar-path.ts +136 -26
- package/src/strategies/patrol.ts +21 -10
- package/src/strategies/player-targets.test.ts +10 -0
- package/src/strategies/player-targets.ts +13 -0
- package/src/strategies/report-patrol.ts +21 -10
- package/src/strategies/shrimp-memory.ts +30 -19
- package/src/strategies/social-task.ts +34 -23
- package/src/strategies/task-kill-report.ts +33 -22
- package/src/strategies/task-only.test.ts +99 -85
- package/src/strategies/task-only.ts +23 -12
- package/src/strategies/task-report.ts +25 -14
- package/src/strategies/types.ts +8 -8
- package/src/strategies/warrior-memory.ts +29 -19
- package/docs/runtime/strategy-runtime.md +0 -111
- package/docs//350/207/252/345/256/232/344/271/211/346/204/237/347/237/245.md +0 -502
- package/docs//350/207/252/345/256/232/344/271/211/347/255/226/347/225/245.md +0 -395
- package/skills/clawclaw/references/STRATEGIES.md +0 -76
- package/src/commands/strategy.test.ts +0 -209
- package/src/commands/strategy.ts +0 -242
- package/src/lib/strategy-export.test.ts +0 -406
- package/src/lib/strategy-export.ts +0 -381
- package/src/runtime/clawclaw/plugins/perception/official-modules.ts +0 -31
- package/src/runtime/clawclaw/plugins/strategy/examples/task-only-strategy.test.ts +0 -177
- package/src/runtime/clawclaw/plugins/strategy/examples/task-only-strategy.ts +0 -191
- package/src/runtime/clawclaw/plugins/strategy/index.ts +0 -8
- package/src/runtime/clawclaw/plugins/strategy/local-strategy-executor.ts +0 -412
- package/src/runtime/clawclaw/plugins/strategy/strategy-action.ts +0 -80
- package/src/runtime/clawclaw/plugins/strategy/strategy-analysis-thread-host.ts +0 -183
- package/src/runtime/clawclaw/plugins/strategy/strategy-executor-types.ts +0 -29
- package/src/runtime/clawclaw/plugins/strategy/strategy-executor.test.ts +0 -693
- package/src/runtime/clawclaw/plugins/strategy/strategy-game-api.ts +0 -57
- package/src/runtime/clawclaw/plugins/strategy/strategy-module-loader.ts +0 -168
- package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.test.ts +0 -1994
- package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.ts +0 -1579
- package/src/runtime/clawclaw/plugins/strategy/strategy-source.test.ts +0 -153
- package/src/runtime/clawclaw/plugins/strategy/strategy-source.ts +0 -443
- package/src/sdk/strategy-plugin/index.test.ts +0 -958
- package/src/sdk/strategy-plugin/index.ts +0 -1350
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
# 开发 Trigger
|
|
2
|
+
|
|
3
|
+
## Trigger 是什么
|
|
4
|
+
|
|
5
|
+
Trigger 是一类只读观察规则模块:它与 Perception 独立读取同一份连续观察帧,并读取声明订阅的后端 Event;规则命中时申请启动一个预先绑定的 Behavior。它不读取 DerivedEvent、Perception、Behavior 等计算插件的输出,适合不应等待 Agent 思考的即时反应,例如“不信任的玩家持续靠近我,立即开始躲避”。
|
|
6
|
+
|
|
7
|
+
```text
|
|
8
|
+
Observation Frame -> Perception -> visual.* Event --------+
|
|
9
|
+
\-> Trigger -> Reflex Activation --------+-> Behavior -> Action Runtime
|
|
10
|
+
Backend Event ---------^
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
- **Perception** 从观察帧识别可持久化、可复放的事实,例如 `visual.following`。
|
|
14
|
+
- **Trigger** 从同一观察帧独立判断应急规则,命中时只提交 Reflex 启动请求。
|
|
15
|
+
- **Behavior** 决定怎样移动、躲避或结束,并返回 Decision。
|
|
16
|
+
- **Action Runtime** 校验和执行 Decision 中的 Action 请求。
|
|
17
|
+
|
|
18
|
+
Trigger 可以看作另一类观察模块,但输出语义不同:Perception 输出供其他消费者使用的事实 Event,Trigger 输出临时的 Reflex Activation 候选。两者没有运行时依赖,Trigger 也不直接返回 `move`、`kill` 或其他 Action;具体行为始终由 Behavior 实现。
|
|
19
|
+
|
|
20
|
+
本轮统一的是 long、short 和 reflex 三种角色控制。现有公开的独立发言、投票和观战旁白命令仍直接通过 Action Plugin 与后端交互,不会先变成 Trigger 或 Behavior Activation。
|
|
21
|
+
|
|
22
|
+
## 官方已经提供什么
|
|
23
|
+
|
|
24
|
+
CCL 已提供 Trigger API v4、静态发现、Runtime 调度、Reflex 仲裁和管理命令,但当前没有内置官方 Trigger,也不会默认启用新安装的社区 Trigger。本页示例只用于开发说明,不会随 CCL 物化到用户目录。
|
|
25
|
+
|
|
26
|
+
## 一个 Trigger 文件的结构
|
|
27
|
+
|
|
28
|
+
一个 Trigger 是 `ClawclawTrigger` 的子类:
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { ClawclawTrigger } from '@myclaw163/clawclaw-cli/trigger-plugin';
|
|
32
|
+
|
|
33
|
+
export default class MyTrigger extends ClawclawTrigger {
|
|
34
|
+
static readonly manifest = {
|
|
35
|
+
// 模块注册信息、规则参数和默认 Behavior 绑定
|
|
36
|
+
} as const;
|
|
37
|
+
|
|
38
|
+
evaluate(input, api) {
|
|
39
|
+
// 读取当前观察帧和后端 Event,返回命中或 void
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
这三个部分分别是:
|
|
45
|
+
|
|
46
|
+
### `ClawclawTrigger`
|
|
47
|
+
|
|
48
|
+
公开的只读规则基类。文件必须默认导出它的子类,Runtime 才会识别该 Trigger。
|
|
49
|
+
|
|
50
|
+
### `static manifest`
|
|
51
|
+
|
|
52
|
+
声明模块身份、规则参数、订阅的后端 Event,以及默认绑定的 Behavior、优先级、冷却、rearm 和单次运行上限。Manifest 必须是可静态读取的字面量。
|
|
53
|
+
|
|
54
|
+
### `evaluate(input, api)`
|
|
55
|
+
|
|
56
|
+
Runtime 在每个可评估的观察帧调用它。返回 `void` 表示当前不命中;返回 `TriggerMatch` 表示申请启动绑定的 Reflex Behavior。它不能直接返回 Action 或在运行时选择另一个 Behavior。
|
|
57
|
+
|
|
58
|
+
## 最小可运行示例
|
|
59
|
+
|
|
60
|
+
下面的 Trigger 直接读取当前观察帧:不信任的玩家进入指定距离时,申请以 Reflex 层启动 `evade` Behavior。
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
import {
|
|
64
|
+
ClawclawTrigger,
|
|
65
|
+
type ClawclawTriggerManifest,
|
|
66
|
+
type TriggerInput,
|
|
67
|
+
type TriggerMatch,
|
|
68
|
+
type TriggerReadApi,
|
|
69
|
+
} from '@myclaw163/clawclaw-cli/trigger-plugin';
|
|
70
|
+
|
|
71
|
+
type Config = {
|
|
72
|
+
readonly untrusted_seats: readonly number[];
|
|
73
|
+
readonly maximum_distance: number;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export default class UntrustedFollowerTrigger extends ClawclawTrigger<Config> {
|
|
77
|
+
static readonly manifest = {
|
|
78
|
+
apiVersion: 4,
|
|
79
|
+
id: 'community.untrusted-follower',
|
|
80
|
+
name: 'Untrusted Follower',
|
|
81
|
+
description: 'Starts evade when an untrusted player follows me.',
|
|
82
|
+
inputs: [{
|
|
83
|
+
id: 'untrusted_seats',
|
|
84
|
+
type: 'player_seats',
|
|
85
|
+
description: 'Seats that should trigger an immediate response.',
|
|
86
|
+
default: [],
|
|
87
|
+
}, {
|
|
88
|
+
id: 'maximum_distance',
|
|
89
|
+
type: 'number',
|
|
90
|
+
description: 'Maximum nearby distance in pixels.',
|
|
91
|
+
default: 120,
|
|
92
|
+
min: 1,
|
|
93
|
+
}],
|
|
94
|
+
consumes: [],
|
|
95
|
+
defaultBehavior: 'evade',
|
|
96
|
+
defaultBehaviorInput: {},
|
|
97
|
+
defaultReflexPriority: 20,
|
|
98
|
+
defaultCooldownMs: 2_000,
|
|
99
|
+
defaultRearm: 'after_clear',
|
|
100
|
+
defaultMaxRuntimeMs: 8_000,
|
|
101
|
+
} as const satisfies ClawclawTriggerManifest;
|
|
102
|
+
|
|
103
|
+
evaluate(input: Readonly<TriggerInput<Config>>, _api: TriggerReadApi): TriggerMatch | void {
|
|
104
|
+
const self = input.frame.observation.players.find(({ observer }) => observer);
|
|
105
|
+
if (!self) return;
|
|
106
|
+
|
|
107
|
+
const target = input.frame.observation.players.find((player) => (
|
|
108
|
+
!player.observer
|
|
109
|
+
&& player.seat !== undefined
|
|
110
|
+
&& input.input.untrusted_seats.includes(player.seat)
|
|
111
|
+
&& Math.hypot(player.x - self.x, player.y - self.y)
|
|
112
|
+
<= input.input.maximum_distance
|
|
113
|
+
));
|
|
114
|
+
if (!target || target.seat === undefined) return;
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
reason: 'untrusted_player_nearby',
|
|
118
|
+
evidence: {
|
|
119
|
+
frameKey: input.frame.frameKey,
|
|
120
|
+
tick: input.frame.tick,
|
|
121
|
+
playerSeat: target.seat,
|
|
122
|
+
},
|
|
123
|
+
behaviorInput: { player_seats: [target.seat] },
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
需要“连续靠近多帧”时,再用实例字段计数,并在 `reset()` 中清空;相关边界见后文“状态、重复触发与抢占”。
|
|
130
|
+
|
|
131
|
+
## 每帧输入是什么
|
|
132
|
+
|
|
133
|
+
`TriggerInput<TInput>` 包含共享观察帧、后端 Event 和规则参数:
|
|
134
|
+
|
|
135
|
+
| 字段 | 内容 |
|
|
136
|
+
|---|---|
|
|
137
|
+
| `frame` | 与 Perception 独立收到的同一份 `ObservationFrame` |
|
|
138
|
+
| `events` | 本 Trigger 通过 `consumes` 订阅且尚未处理的 Event |
|
|
139
|
+
| `input` | 按 `manifest.inputs` 验证并补默认值后的规则参数 |
|
|
140
|
+
|
|
141
|
+
`input.frame` 提供 `frameKey`、`frameSeq`、`tick`、`timeMs`、`tickDelta`、`continuousFromPrevious`、`gameState` 和 `observation`。Perception 把同一结构称为 `PerceptionFrame`;它是 `ObservationFrame` 的类型别名。两类模块各自维护实例和边界状态,不读取对方输出。
|
|
142
|
+
|
|
143
|
+
### 观察帧和后端 Event
|
|
144
|
+
|
|
145
|
+
Trigger 每次都可以读 `input.frame.gameState` 和 `input.frame.observation`。`manifest.consumes` 只控制哪些 `producer: 'backend_push'` Event 进入 `input.events`:
|
|
146
|
+
|
|
147
|
+
- `consumes: []`:纯观察帧规则,`events` 始终为空;
|
|
148
|
+
- `consumes: ['players_changed']`:只接收列出的 type;
|
|
149
|
+
- `consumes: ['*']`:接收所有后端 Event,仅在确实需要时使用。
|
|
150
|
+
|
|
151
|
+
`input.events` 明确不包含 DerivedEvent、Perception、Behavior 或其他 Runtime 计算插件产生的 Event。Perception 和 Trigger 是同一层的独立消费者,可以并行计算;即使其他插件在墙钟时间上先提交,Runtime 也只把后端 Event 交给 Trigger,避免形成依赖或竞态。需要立即响应的视觉规则必须直接读取观察帧;可复用算法应抽成两类模块都能调用的纯工具,而不是让 Trigger 订阅其他插件。
|
|
152
|
+
|
|
153
|
+
当前 Trigger Host 只在角色存活且阶段为 `wandering` 时评估规则。
|
|
154
|
+
|
|
155
|
+
## 可以查询什么
|
|
156
|
+
|
|
157
|
+
`TriggerReadApi` 与 Behavior 使用同一套只读查询能力:
|
|
158
|
+
|
|
159
|
+
- `api.spatial`:房间几何、坐标所在房间和静态连接关系;
|
|
160
|
+
- `api.navigation.pathDistance()` / `pathDistances()`:两个坐标之间的本地路径距离;
|
|
161
|
+
- `api.observation.lastSeenPlayer()` / `lastSeenCorpse()`:CCL 保存的最近可见观察。
|
|
162
|
+
|
|
163
|
+
`api` 只在当前回调内有效。它不能发送 Action、修改 State,也不会给 Trigger 返回服务器动作回执。
|
|
164
|
+
|
|
165
|
+
## 命中时可以输出什么
|
|
166
|
+
|
|
167
|
+
`evaluate()` 返回 `void` 表示当前不命中;命中时返回 `TriggerMatch`:
|
|
168
|
+
|
|
169
|
+
```ts
|
|
170
|
+
interface TriggerMatch {
|
|
171
|
+
readonly reason: string;
|
|
172
|
+
readonly evidence?: Readonly<Record<string, unknown>>;
|
|
173
|
+
readonly behaviorInput?: Readonly<Record<string, unknown>>;
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
- `reason` 是稳定、可审计的命中原因;
|
|
178
|
+
- `evidence` 记录 Event ID、座位号、距离等支持证据;
|
|
179
|
+
- `behaviorInput` 只能为已绑定 Behavior 补充本次命中的动态参数。
|
|
180
|
+
|
|
181
|
+
`TriggerMatch` 故意没有 `behavior`、`reflexPriority` 或 `actions`。Trigger 不能根据运行时数据任意选择代码或提升权限;这些值来自已审核的有效配置。
|
|
182
|
+
|
|
183
|
+
Behavior 真正收到的 input 合并顺序是:
|
|
184
|
+
|
|
185
|
+
```text
|
|
186
|
+
Manifest defaultBehaviorInput
|
|
187
|
+
<- 当前持久配置的 behavior_input
|
|
188
|
+
<- 本次 TriggerMatch.behaviorInput
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
越靠后的字段覆盖越靠前的同名字段。
|
|
192
|
+
|
|
193
|
+
## Manifest 与配置
|
|
194
|
+
|
|
195
|
+
### Manifest 字段
|
|
196
|
+
|
|
197
|
+
| 字段 | 用途 |
|
|
198
|
+
|---|---|
|
|
199
|
+
| `apiVersion` | Trigger 公共契约版本,当前必须直接写 `4` |
|
|
200
|
+
| `id` | 稳定资源 ID,只使用小写字母、数字、`.`、`_`、`-` |
|
|
201
|
+
| `name` / `description` | 供列表、审查和文档展示的名称与说明 |
|
|
202
|
+
| `localizations` | 可选的本地化名称与说明 |
|
|
203
|
+
| `inputs` | 规则参数 schema;Trigger 的每个字段都必须有 `default` |
|
|
204
|
+
| `consumes` | 进入 `input.events` 的 Event type |
|
|
205
|
+
| `defaultBehavior` | 新注册默认绑定的 Behavior ID |
|
|
206
|
+
| `defaultBehaviorInput` | 该 Behavior 的默认输入 |
|
|
207
|
+
| `defaultReflexPriority` | 与其他 Reflex 竞争时的默认优先级;越大越高 |
|
|
208
|
+
| `defaultCooldownMs` | 一次启动被接受后的默认冷却时间 |
|
|
209
|
+
| `defaultRearm` | 何时允许同一规则再次触发 |
|
|
210
|
+
| `defaultMaxRuntimeMs` | 该 Reflex Behavior 单次激活的默认最长运行时间 |
|
|
211
|
+
|
|
212
|
+
Trigger 的 Manifest 会被静态扫描器从源码字面量中读取。不要用函数调用、展开运算、环境变量或动态表达式生成 Manifest。
|
|
213
|
+
|
|
214
|
+
### 有效配置
|
|
215
|
+
|
|
216
|
+
每个 Trigger 有一套 Manifest 默认值。持久配置在此基础上覆盖以下项目:
|
|
217
|
+
|
|
218
|
+
| 配置 | 含义 |
|
|
219
|
+
|---|---|
|
|
220
|
+
| `enabled` | 是否评估规则;新社区 Trigger 默认为 `false` |
|
|
221
|
+
| `input` | Trigger 规则参数 |
|
|
222
|
+
| `behavior` | 已审核的固定 Behavior 绑定 |
|
|
223
|
+
| `behavior_input` | 传给该 Behavior 的配置输入 |
|
|
224
|
+
| `reflex_priority` | 该 Trigger 启动的 Reflex 相对优先级 |
|
|
225
|
+
| `cooldown_ms` | 被接受的启动之间的最小间隔 |
|
|
226
|
+
| `rearm` | `after_clear` 或 `after_cooldown` |
|
|
227
|
+
| `max_runtime_ms` | Reflex Behavior 单次运行上限 |
|
|
228
|
+
|
|
229
|
+
`behavior` 是“每个 Trigger 的有效配置固定一个”,不是“永远不可修改”。用户或 Agent 可以通过受控管理入口改变绑定;一次 `evaluate()` 不能越过管理面临时选择另一个 Behavior。
|
|
230
|
+
|
|
231
|
+
上表是 `user-data/gameplay.json` 的持久化字段,因此使用 snake_case;对应 CLI 选项使用 `--behavior-input`、`--reflex-priority`、`--cooldown-ms` 和 `--max-runtime-ms`。
|
|
232
|
+
|
|
233
|
+
## 安装、配置和观察
|
|
234
|
+
|
|
235
|
+
把 `.ts` 或 `.js` 文件放在:
|
|
236
|
+
|
|
237
|
+
```text
|
|
238
|
+
<workspace>/user-data/triggers/
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
先静态查看 Manifest,再配置并显式启用:
|
|
242
|
+
|
|
243
|
+
```powershell
|
|
244
|
+
ccl trigger list
|
|
245
|
+
ccl trigger info community.untrusted-follower
|
|
246
|
+
ccl trigger configure community.untrusted-follower `
|
|
247
|
+
--input '{"untrusted_seats":[3,7]}' `
|
|
248
|
+
--behavior evade `
|
|
249
|
+
--behavior-input '{"player_seats":[3,7]}' `
|
|
250
|
+
--reflex-priority 20 `
|
|
251
|
+
--cooldown-ms 2000 `
|
|
252
|
+
--rearm after_clear `
|
|
253
|
+
--max-runtime-ms 8000
|
|
254
|
+
ccl trigger enable community.untrusted-follower
|
|
255
|
+
ccl trigger disable community.untrusted-follower
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
管理命令把配置写入 `user-data/gameplay.json`;存在已附着 Runtime 时会把这份持久配置同步应用,否则在下一次 Runtime 启动时生效。当前没有独立于持久配置的临时 Runtime override。`configure --reset` 清除覆盖值但保留当前 enabled 状态。
|
|
259
|
+
|
|
260
|
+
启用后用 `ccl behavior status` 观察当前 reflex Activation,并结合它启动的 Behavior lifecycle Event 和诊断判断结果。新增或修改 Trigger 源码、Manifest 后需要重启 Runtime。
|
|
261
|
+
|
|
262
|
+
## 状态、重复触发与抢占
|
|
263
|
+
|
|
264
|
+
同一 Trigger 实例会按 epoch 有序调用,类字段可以保存 Runtime 生命期内的短期状态。`continuousFromPrevious: false`、阶段变化、segment 结束或 shutdown 会形成观察边界;Runtime 会调用可选的 `reset(reason)`,模块应在其中清空跨帧证据。这些私有状态不会跨 Runtime 重启持久化。
|
|
265
|
+
|
|
266
|
+
`defaultRearm` / `rearm` 有两种模式:
|
|
267
|
+
|
|
268
|
+
- `after_clear`:一次启动被接受后解除武装;只有规则后续明确返回 `void` 才再次武装,适合“进入危险”这类边沿语义;
|
|
269
|
+
- `after_cooldown`:持续命中也可以在冷却结束后再次申请,适合需要周期重试的规则。
|
|
270
|
+
|
|
271
|
+
冷却和 rearm 状态只在 Reflex 启动被 Behavior 管理器接受后推进;被拒绝的请求不会假装已经触发成功。
|
|
272
|
+
|
|
273
|
+
控制层级固定为:
|
|
274
|
+
|
|
275
|
+
```text
|
|
276
|
+
reflex > short > long
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
`reflexPriority` 只在多个 Reflex 之间比较,不能改变上面的层级。同一时刻只有一个 Reflex 执行:新 Reflex 只有在优先级严格高于当前 Reflex 时才替换它;同一 Trigger 或同级/更低优先级不会重启、排队或抢占。同一 epoch 多个规则命中时,规则 Host 先选优先级最高的一个,平局按 Trigger ID 稳定排序,其他命中不排队。
|
|
280
|
+
|
|
281
|
+
## 错误与安全
|
|
282
|
+
|
|
283
|
+
- 一个 Trigger 加载或 `evaluate()` 失败只记录诊断,不允许用半份结果启动 Behavior。
|
|
284
|
+
- 静态发现器只读源码文本和字面量 Manifest,不 import 或执行第三方代码。管理面中的 `loadable: true` 只代表静态契约可识别,不代表代码已运行、算法正确或源码可信。
|
|
285
|
+
- 真正启用后,Trigger 与 CCL 进程拥有相同权限,不是安全沙箱。只安装和启用已经审查的本地代码。
|
|
286
|
+
|
|
287
|
+
## 继续阅读
|
|
288
|
+
|
|
289
|
+
- [自定义模块总览](./README.md)
|
|
290
|
+
- [开发 Perception](./perception.md)
|
|
291
|
+
- [开发 Behavior](./behavior.md)
|
|
292
|
+
- [自定义模块 API 参考](./api-reference.md)
|
|
@@ -11,7 +11,7 @@ Desktop 先启动本地 IPC server,再成对传入:
|
|
|
11
11
|
--desktop-event-token <nonce>
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
支持顶层 `ccl start match`、`ccl start room`、`ccl start training`、`ccl join` 和 `ccl join room`。未传这两个参数时,CCL 不连接 Desktop,也不发送本文消息。
|
|
15
15
|
|
|
16
16
|
Windows 使用本地 named pipe;Unix 使用绝对 socket 路径。连接是 NDJSON 长连接,每行一个 JSON 对象。
|
|
17
17
|
|
|
@@ -66,7 +66,7 @@ CCL 连接成功后先发送:
|
|
|
66
66
|
|
|
67
67
|
Desktop 必须校验 `schema`、`connection_id` 和启动时约定的 `token`。
|
|
68
68
|
|
|
69
|
-
`active_resources`
|
|
69
|
+
`active_resources` 是连接建立时的当前资源快照。`strategy` 是为兼容现有 Desktop wire schema 保留的字段名,内容表示当前 long Behavior;没有显式 long 时表示当前角色配置的 fallback Behavior,二者都没有时为 `null`。short/reflex 不会改写这个字段。`perceptions` 包含本次 Runtime 已启用的全部感知模块。当前 CCL 固定发送 `zh-CN` 文案。名称和描述来自 Behavior 或 Perception 自己的 manifest;Desktop IPC 和 Mailbox 不维护模块文案映射。manifest 可继续增加其他 locale,传输结构无需变化。
|
|
70
70
|
|
|
71
71
|
## 什么时候发送事件
|
|
72
72
|
|
|
@@ -84,7 +84,7 @@ CCL 在以下条件全部满足时发送一个 `mailbox_batch`:
|
|
|
84
84
|
| 时机 | 典型事件 |
|
|
85
85
|
| --- | --- |
|
|
86
86
|
| 匹配或房间状态变化 | `match_waiting`、`match_start`、`joined`、`room_created`、`room_attached`、`room.self_left` |
|
|
87
|
-
| 对局开始 | `game_started`、`role_assigned
|
|
87
|
+
| 对局开始 | `game_started`、`role_assigned` |
|
|
88
88
|
| 对局进行中 | `visual.*`、任务、玩家变化、击杀、尸体和紧急事件 |
|
|
89
89
|
| 会议与投票 | `meeting_briefing`、`speech*`、`vote_speech_phase_ended` |
|
|
90
90
|
| 对局结束 | `game_over` |
|
|
@@ -131,7 +131,9 @@ CCL 在以下条件全部满足时发送一个 `mailbox_batch`:
|
|
|
131
131
|
}
|
|
132
132
|
```
|
|
133
133
|
|
|
134
|
-
`payload.state` 是当前 Ready View 的紧凑状态,`payload.events` 是本批完整 Agent 事件。`active_resources` 是这一交付批次创建时的资源快照,Desktop
|
|
134
|
+
`payload.state` 是当前 Ready View 的紧凑状态,`payload.events` 是本批完整 Agent 事件。`active_resources` 是这一交付批次创建时的资源快照,Desktop 可据此更新 long/fallback Behavior 和感知窗口;它不属于 `payload` 内的 Agent Mailbox 内容。
|
|
135
|
+
|
|
136
|
+
这是 Desktop IPC 自己保留的 v1/State 兼容契约,不是 Claude Channel 契约。Claude Channel 使用 `clawclaw.channel-events.v2`,只发送 `events[]`。
|
|
135
137
|
|
|
136
138
|
`event_descriptors` 只包含本批 `payload.events` 实际出现、并且由当前激活感知模块声明的 Event type。同一 type 在一批出现多次只附一份描述;非感知事件、禁用模块的 Event type、未激活自定义模块的 Event type,以及没有出现在本批的 Event type 都不列入。名称和描述来自对应感知模块 manifest,当前按 `zh-CN` 解析。没有匹配项时省略整个字段,原有 `payload.events` 结构始终保持不变。
|
|
137
139
|
|
package/docs/runtime/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Runtime 文档索引
|
|
2
2
|
|
|
3
|
-
本目录描述当前
|
|
3
|
+
本目录描述当前 Runtime 代码。Runtime 是游戏无关的执行框架;ClawClaw 通过 Source 和一组 Epoch Plugin 接入。本文档集不把保留源码、目标接口或旧 npm 行为写成当前已装载能力。
|
|
4
4
|
|
|
5
5
|
## 阅读路径
|
|
6
6
|
|
|
@@ -13,36 +13,54 @@
|
|
|
13
13
|
|
|
14
14
|
- [Owner/Relay 生命周期与可观测性](./owner-lifecycle-and-observability.md):前台长进程怎样启动、排空、结束,以及怎样记录积压和插件耗时。
|
|
15
15
|
- [Agent 短指令与 Runtime Capability](./short-commands-and-capabilities.md):`ccl events`、动作和控制命令怎样连接长进程。
|
|
16
|
-
- [Agent 通知与 Mailbox](./agent-notifications.md):Mailbox 怎样使用 Runtime 固定的 Ready View
|
|
16
|
+
- [Agent 通知与 Mailbox](./agent-notifications.md):Mailbox 怎样使用 Runtime 固定的 Ready View,并让 Monitor、`ccl events`、Desktop IPC 和 Channel 各自维护投递状态。
|
|
17
17
|
|
|
18
18
|
### 插件与开发工具
|
|
19
19
|
|
|
20
|
-
- [
|
|
21
|
-
- [
|
|
22
|
-
- [
|
|
20
|
+
- [自定义模块开发](../custom-modules/README.md):先了解能扩展什么、官方已经支持什么,以及该从哪类模块开始。
|
|
21
|
+
- [开发 Behavior](../custom-modules/behavior.md):long、short、reflex 共用的接口、Decision 和生命周期。
|
|
22
|
+
- [开发 Perception](../custom-modules/perception.md):视觉帧、轨迹状态和 Event 输出。
|
|
23
|
+
- [开发 Trigger](../custom-modules/trigger.md):只读规则、固定 Behavior 绑定、重复触发和 Reflex 抢占。
|
|
24
|
+
- [自定义模块 API 参考](../custom-modules/api-reference.md):公共类型、Manifest、输入输出和加载规则。
|
|
25
|
+
- [Behavior Host、Activation 与 Action 边界](./behavior-runtime.md):需要深入实现时再阅读 Behavior 调度、抢占和 Action 边界。
|
|
26
|
+
- [ClawClaw 官方感知模块](./official-perception-modules.md):当前 8 个官方模块分别观察什么、产生哪些 `visual.*` Event,以及默认启用和投递边界。
|
|
23
27
|
- [Perception 离线复放](./perception-replay.md):怎样实时查看感知 Event,并把 State/Event 与观战录像对齐。
|
|
24
28
|
|
|
25
29
|
## 当前实现状态
|
|
26
30
|
|
|
27
|
-
|
|
31
|
+
当前顶层 `ccl start ...` / `ccl join ...` Owner 装载:
|
|
28
32
|
|
|
29
33
|
- `ClawclawSourcePlugin`
|
|
30
34
|
- `ClawclawActionPlugin`
|
|
31
35
|
- `ClawclawDerivedEventPlugin`
|
|
32
36
|
- `ClawclawGameQueryPlugin`
|
|
33
37
|
- `ClawclawPerceptionPlugin`(一个 Epoch Plugin,内部管理已选感知模块)
|
|
34
|
-
- `
|
|
38
|
+
- `ClawclawTriggerPlugin`
|
|
39
|
+
- `ClawclawBehaviorPlugin`
|
|
35
40
|
- `ClawclawMailboxPlugin`
|
|
36
41
|
|
|
37
|
-
|
|
42
|
+
同一 epoch 中,Perception 和 Trigger 独立读取同一观察帧,可以并行计算;Behavior 同时等待二者完成。Trigger 的 Event 输入排除 Perception 输出,只能申请启动配置中绑定的固定 Behavior;Action 仍由 Behavior Decision 经 Action Plugin 提交。
|
|
38
43
|
|
|
39
|
-
|
|
44
|
+
对社区公开的模块面只有三类:Behavior API v3、Trigger API v4、Perception API v2。当前包物化 33 个官方 Behavior 和 8 个官方 Perception,不物化官方 Trigger;社区 Trigger 默认关闭。旧 Strategy/Intent 作者入口、目录和 Runtime Plugin 已删除,不是隐藏兼容层。
|
|
45
|
+
|
|
46
|
+
`ccl speak`、`ccl vote`、`ccl aside` 是有意保留的 direct Agent Action:它们经 Owner、`Runtime.performAction({ kind: 'agent' })` 和 Action Plugin 直接提交,不会创建 Behavior Activation。Behavior 管理命令与这些通信命令不能混为一条生命周期。
|
|
47
|
+
|
|
48
|
+
Behavior Host 管理 long、short、reflex 三层 Activation。serial Behavior 的持久 `decide()` 在 Owner 主线程运行;parallel Behavior 使用自适应 Worker Thread 池,预热 2 个、按压力扩到最多 10 个并在空闲后回收。Perception Plugin 默认加载八个官方模块,也可以通过工作区配置选择;普通 `update()` 与持久 `commit()` 在 Owner 主线程运行,`parallel_analysis` 使用独立的有界 Worker 池。
|
|
49
|
+
|
|
50
|
+
`ccl load` 和资源 `--list/--info` 在判定第三方资源 `loadable` 时只做静态 manifest 契约检查,
|
|
51
|
+
绝不 import 或执行第三方源码;命令仍可按物化规则同步未修改的官方副本。其中
|
|
52
|
+
`loadable: true` 不代表模块已经 import 或运行成功。Runtime 启动时才加载已启用模块并冻结插件图,
|
|
53
|
+
因此源码、manifest 和 enable/disable 变化需要重启。自定义 Behavior、Perception 与 Trigger 源码
|
|
54
|
+
都是与 CCL 同权限运行的受信任本地代码,Worker Thread 不是安全沙箱。房间就绪由 DerivedEvent
|
|
55
|
+
rule 生成。Game Query 通过通用 capability 提供受控只读查询,不是新的 Runtime 插件类型。
|
|
56
|
+
|
|
57
|
+
Runtime 本身只认识 `RuntimeSourcePlugin` 和 `RuntimeEpochPlugin`。DerivedEvent、Perception、Trigger、Behavior、Action、Mailbox 都只是具体游戏给 Epoch Plugin 分配的职责名;Host Relay 和 Owner 不是插件。
|
|
40
58
|
|
|
41
59
|
## 术语
|
|
42
60
|
|
|
43
61
|
| 术语 | 含义 |
|
|
44
62
|
|---|---|
|
|
45
|
-
| Owner | 当前前台 `ccl
|
|
63
|
+
| Owner | 当前前台 `ccl start ...` / `ccl join ...` 进程,持有 Source、Runtime、SQLite、Mailbox、IPC 和可选 Host Relay |
|
|
46
64
|
| epoch | Source 一次 `RuntimeInputBatch` 提交创建的持久化调度单位;不等于游戏 tick |
|
|
47
65
|
| Canonical Event | 经 Event Catalog/EventIngress 校验后写入统一 Ledger 的游戏事实 |
|
|
48
66
|
| State History | Runtime 接受过的完整 State frame 历史,SQLite 持久化并保留内存读取路径 |
|
|
@@ -1,55 +1,74 @@
|
|
|
1
|
-
# Agent
|
|
1
|
+
# Agent Mailbox 与输出适配器
|
|
2
2
|
|
|
3
3
|
## 当前边界
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Owner 持有 Source、Runtime、SQLite、Action,以及并行的 Perception/Trigger 观察分支和下游 Behavior 控制链。所有 Agent 输出先经过同一个 Mailbox 插件;Channel、Desktop IPC、`ccl events` 和 Monitor 都只是它下面的输出适配器。
|
|
6
6
|
|
|
7
7
|
```text
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
Runtime / Canonical Event Repository
|
|
9
|
+
|
|
|
10
|
+
ClawclawMailboxPlugin
|
|
11
|
+
|
|
|
12
|
+
Agent Event Presenter
|
|
13
|
+
|
|
|
14
|
+
AgentMailboxCoordinator
|
|
15
|
+
|
|
|
16
|
+
+--------+----------+------------+---------+
|
|
17
|
+
| | | |
|
|
18
|
+
Desktop IPC Channels ccl events Monitor
|
|
12
19
|
```
|
|
13
20
|
|
|
14
|
-
|
|
21
|
+
输出适配器不是事实生产者。新的游戏事实必须由 Source 或 Epoch Plugin 生成 Canonical Event,再经 Event Catalog 校验并写入 Ledger。Presenter 从同一个 Ready View 投影 Agent 可见 Event;各 Adapter 可独立选择完整 Event、短正文或详情子集,只有契约仍需要 State 的兼容 Adapter 才另外取得紧凑 `state`。
|
|
15
22
|
|
|
16
|
-
|
|
23
|
+
每个可靠输出拥有独立且跨 Owner 重启稳定的 consumer、lease 和投递状态:
|
|
17
24
|
|
|
18
|
-
|
|
25
|
+
- Monitor:`local-agent:monitor`
|
|
26
|
+
- `ccl events`:`local-agent:ccl-events`
|
|
27
|
+
- Desktop IPC:`local-agent:desktop`
|
|
28
|
+
- Claude Channel:`local-agent:claude-channel`
|
|
19
29
|
|
|
20
|
-
|
|
30
|
+
某个输出推进后不会推进其它输出。`ack:none` 的 best-effort 输出不得拥有 durable consumer,也不得推进持久游标。
|
|
21
31
|
|
|
22
|
-
|
|
32
|
+
## Owner 与 Channel 的连接
|
|
23
33
|
|
|
24
|
-
|
|
34
|
+
Claude Code 默认启用 Monitor 直达通知和 `ccl events` 详情查询,不创建 Channel consumer。只有 `--agent-type claude-code` 且 Owner 进程环境包含 `CLAWCLAW_ENABLE_CLAUDE_CHANNELS=1` 时,才装配下面的可选 Channel 链路。
|
|
25
35
|
|
|
26
|
-
|
|
36
|
+
Claude Code 加载的 `clawclaw-channel` 是独立 MCP stdio 进程,只负责 Channel transport。它在 workspace runtime 目录发布带随机 token 的本地 IPC 端点。
|
|
27
37
|
|
|
28
|
-
|
|
38
|
+
可选 Channel 模式下,Agent 通过 Bash 后台启动顶层 `ccl start ... --agent-type claude-code` 或 `ccl join ...`;CCL 自己选择 active account 并拉起 Owner。Owner 的 Channel socket sink 读取端点描述并主动连接,然后把 Mailbox 批次 push 给 Channel。Channel 不绑定 profile、不发现 Owner、不读取 Owner control,也不启停游戏进程。
|
|
29
39
|
|
|
30
|
-
|
|
40
|
+
Owner 暂时连不上 Channel 时仍继续游戏,未投递 Event 留在 Channel consumer;Channel 出现或重启后自动重连。当前一个 Channel bridge 同时接收一个 Owner 连接。
|
|
31
41
|
|
|
32
|
-
##
|
|
42
|
+
## Channel 投递与内部推进
|
|
33
43
|
|
|
34
|
-
|
|
44
|
+
每个 `game_events` 通知包含完整正文:
|
|
35
45
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
46
|
+
```json
|
|
47
|
+
{"schema":"clawclaw.channel-events.v2","events":[]}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Claude Channel v2 只发送按发生顺序排列的 Event,不序列化 Ready View State。感知 Event 仍会频繁进入批次,不在 Channel 层节流;自己的移动由 visual self Event 表达,不加 `self` 摘要。任务列表变化通过 `role_assigned`、自己的 `task_completed` / `task_sabotaged` 或 `tasks_changed` 携带 `reason`、`delta[]` 和完整 `tasks[]`;玩家首帧及变化通过 `players_changed` 携带 `reason`、`changes[]` 和完整 `players[]`。
|
|
51
|
+
|
|
52
|
+
Owner 同一时刻只向 Channel push 一批。`mcp.notification()` 写入 Claude transport 后,Channel IPC server 返回内部 receipt;Owner 的 Mailbox pump 随即推进自己的 consumer。Agent 不调用逐批 ACK。
|
|
53
|
+
|
|
54
|
+
如果 transport 写入失败,Owner 保留 lease 并重连重试。如果通知已经写入但 receipt 丢失,Channel 按内部 `delivery_id` 去重,只重发 receipt,不重复通知。该状态不影响 Desktop、`ccl events` 或 Monitor 的独立 consumer。
|
|
55
|
+
|
|
56
|
+
Desktop IPC 与 `ccl events` 保留各自的 v1/State 兼容契约;它们不是 Claude Channel v2,也不会因 Channel consumer 推进而被推进。裸 `ccl events` 消费 Monitor 标记需要详情的 Event,也消费 Monitor 因瞬时队列压力、60 秒滚动窗口或高频 visual 限频而委托的 durable 普通/visual Event;显式类型查询仍可读取任意 Agent 可见 Event。
|
|
40
57
|
|
|
41
|
-
|
|
58
|
+
需要 State 的兼容 Adapter 会在紧凑 State 中附加 `behavior`:当前 Activation 的 id、Behavior、layer、source、实例代次和可选 `doing`,以及 long/short/reflex 栈。它不包含 Behavior 输入或模块私有状态。Channel v2 和 Monitor 不附带这份 State,而是通过 `behavior.started`、`behavior.suspended`、`behavior.restarted`、`behavior.completed`、`behavior.failed`、`behavior.cancelled`、`behavior.replaced` 接收控制生命周期事实。
|
|
42
59
|
|
|
43
|
-
|
|
60
|
+
`channel_confirm({probe_id})` 只记录 Agent 收到过连接 probe,并停止 probe 重发;它不参与连接、Owner 启动或投递逻辑。
|
|
44
61
|
|
|
45
|
-
|
|
62
|
+
Event 投递等级为:
|
|
46
63
|
|
|
47
|
-
|
|
64
|
+
- `monitor_and_events`:进入 Agent 可见事件流,并有资格进入 Monitor 的有界主动输出。
|
|
65
|
+
- `events_only`:进入 Agent 可见事件流,不主动唤醒 Monitor。
|
|
66
|
+
- `internal_only`:只供明确订阅的内部消费者,不进入 Agent 输出。
|
|
48
67
|
|
|
49
|
-
|
|
68
|
+
## Monitor 直达与详情分流
|
|
50
69
|
|
|
51
|
-
|
|
70
|
+
Monitor 通知不附带 State 或额外 `self`。短事件直接放在 `messages[]` 中;一批放不进 500 字符时先拆成完整通知。普通主动输出有两个独立边界:pending/claimed 容量限制瞬时积压,60 秒滚动窗口限制持续 Host 输出。任一窗口最多直推 12 个普通项目,并最多用 4 个额外 ordinary-only 提示唤醒 backlog;余量委托给 `ccl events` 的 durable consumer,时间滑出窗口后额度自然恢复。高频移动/路线/空间 visual 每 5 秒只主动保留最新一条;进入/离开视野、停止/恢复、尸体和跟随关系等转折不受该限频。提示含 `backlog.remaining_events`、`through_event_commit_seq`、`command:"ccl events"` 和 `guidance`,并标记 `truncated:true`。固定详情和异常过长 Event 仍进入 `details_required[]`。Agent 每次看到 `details_required`、`backlog` 或 `truncated:true` 都运行一次裸 `ccl events`。击杀、死亡、有效目击、Behavior 的 completed/failed/cancelled/replaced 生命周期、关键会议、硬时限或 priority ≥80 的 Event,以及 `game_over` / `exile_game_over`,不委托并可顺带携带当前 backlog;同条通知含 `speech_your_turn` 时必须先发言,不能先查询。
|
|
52
71
|
|
|
53
|
-
|
|
72
|
+
固定详情事件包括 `game_started`、`role_assigned`、`players_changed`、`tasks_changed`、自己的 `task_completed` / `task_sabotaged`、`meeting_briefing`、`exile`、`no_exile`、`joined`、`room_created` 和 `room_joined`。任务与玩家列表因此只在发生变化时占用一次完整上下文;普通感知、移动中断和短发言在滚动预算内由 Monitor 交付,超出后由裸 `ccl events` 交付;高优先级 Behavior 生命周期和终局仍直达。
|
|
54
73
|
|
|
55
|
-
`--visual-board`
|
|
74
|
+
`--visual-board` 和 Perception 复放工具只读 Ledger,不推进任何输出的消费状态。
|