@myclaw163/clawclaw-cli 0.8.4 → 0.8.6

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.
Files changed (330) hide show
  1. package/README.md +4 -3
  2. package/docs/configuration.md +44 -26
  3. package/docs/custom-modules/README.md +7 -10
  4. package/docs/custom-modules/behavior.md +10 -19
  5. package/docs/custom-modules/perception.md +1 -1
  6. package/docs/custom-modules/trigger.md +1 -1
  7. package/docs/runtime/README.md +4 -4
  8. package/docs/runtime/official-perception-modules.md +2 -2
  9. package/docs/runtime/owner-lifecycle-and-observability.md +1 -1
  10. package/package.json +15 -2
  11. package/scripts/enable_ccl_permissions.cjs +4 -2
  12. package/scripts/find-hide-spots.py +2 -2
  13. package/scripts/postinstall.mjs +1 -4
  14. package/scripts/sync-bundled-skill.mjs +12 -159
  15. package/skills/clawclaw/SKILL.md +25 -18
  16. package/skills/clawclaw/references/BEHAVIORS.md +15 -11
  17. package/skills/clawclaw/references/COMMANDS.md +45 -41
  18. package/skills/clawclaw/references/HUB.md +25 -38
  19. package/skills/clawclaw/references/TACTICS.md +1 -1
  20. package/src/commands/account.ts +58 -14
  21. package/src/commands/behavior.ts +116 -38
  22. package/src/commands/hub.ts +110 -153
  23. package/src/commands/load.ts +138 -33
  24. package/src/commands/perception.ts +55 -24
  25. package/src/commands/persona.ts +66 -20
  26. package/src/commands/skill.ts +12 -48
  27. package/src/commands/trigger.ts +68 -40
  28. package/src/lib/account-guidance.ts +54 -9
  29. package/src/lib/agent-workspace-client.ts +135 -0
  30. package/src/lib/agent-workspace-runtime.ts +154 -0
  31. package/src/lib/agent-workspace-skills.ts +177 -0
  32. package/src/lib/agent-workspace-sync.ts +852 -0
  33. package/src/lib/gameplay-config.ts +29 -15
  34. package/src/lib/hub-client.ts +252 -34
  35. package/src/lib/hub-reminder.ts +24 -11
  36. package/src/lib/init-command.ts +0 -6
  37. package/src/lib/load-context.ts +12 -6
  38. package/src/lib/persona.ts +141 -69
  39. package/src/lib/server-status.ts +78 -0
  40. package/src/lib/skill-host.ts +160 -0
  41. package/src/lib/user-data.ts +197 -4
  42. package/src/runtime/clawclaw/behavior-read-api.ts +1 -1
  43. package/src/{strategies/pathfind → runtime/clawclaw/navigation}/astar-path.ts +1 -1
  44. package/src/{strategies/pathfind → runtime/clawclaw/navigation}/escape-planner.ts +1 -1
  45. package/src/{strategies → runtime/clawclaw/navigation}/hide-spots.ts +2 -2
  46. package/src/{strategies → runtime/clawclaw/navigation}/off-route-points.ts +6 -3
  47. package/src/{strategies/pathfind → runtime/clawclaw/navigation}/walkable-grid.ts +1 -1
  48. package/src/runtime/clawclaw/owner.ts +63 -19
  49. package/src/runtime/clawclaw/plugins/behavior/activation-manager.ts +8 -2
  50. package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +2 -2
  51. package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.ts +1 -1
  52. package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +4 -1
  53. package/src/runtime/clawclaw/plugins/perception/perception-source.ts +11 -5
  54. package/src/runtime/clawclaw/plugins/perception/replay.ts +0 -2
  55. package/src/runtime/framework/modules/runtime-module-loader.ts +0 -54
  56. package/src/sdk/behavior-toolkit/escape.ts +2 -2
  57. package/personas//345/217/243/346/230/257/345/277/203/351/235/236.md +0 -50
  58. package/personas//345/277/240/345/277/203/350/200/201/344/273/206.md +0 -51
  59. package/personas//346/227/240/344/272/272/350/256/276.md +0 -1
  60. package/personas//350/264/253/345/230/264/346/215/237/345/217/213.md +0 -48
  61. package/personas//350/275/257/350/220/214/350/205/271/351/273/221.md +0 -51
  62. package/scripts/compare-perception-replays.test.ts +0 -188
  63. package/scripts/enable_ccl_permissions.test.mjs +0 -163
  64. package/scripts/enable_monitor.test.mjs +0 -201
  65. package/scripts/sync-bundled-skill.test.mjs +0 -152
  66. package/scripts/watch-perception-events.test.ts +0 -43
  67. package/src/behaviors/official-finite/do-task.ts +0 -211
  68. package/src/behaviors/official-finite/evade.ts +0 -78
  69. package/src/behaviors/official-finite/find-player.ts +0 -50
  70. package/src/behaviors/official-finite/follow-player.ts +0 -70
  71. package/src/behaviors/official-finite/go-to.ts +0 -69
  72. package/src/behaviors/official-finite/hide-temporarily.ts +0 -77
  73. package/src/behaviors/official-finite/hold-position.ts +0 -48
  74. package/src/behaviors/official-finite/hunt-player.ts +0 -47
  75. package/src/behaviors/official-finite/index.test.ts +0 -249
  76. package/src/behaviors/official-finite/index.ts +0 -44
  77. package/src/behaviors/official-finite/inspect-corpse.ts +0 -64
  78. package/src/behaviors/official-finite/patrol-area.ts +0 -80
  79. package/src/behaviors/official-finite/report-corpse.ts +0 -73
  80. package/src/behaviors/official-finite/seek-kill-opportunity.ts +0 -152
  81. package/src/behaviors/official-finite/shared.ts +0 -27
  82. package/src/channel/claude-channel-server.test.ts +0 -202
  83. package/src/commands/account.test.ts +0 -570
  84. package/src/commands/behavior.test.ts +0 -158
  85. package/src/commands/communication.test.ts +0 -282
  86. package/src/commands/competition.test.ts +0 -116
  87. package/src/commands/data.test.ts +0 -89
  88. package/src/commands/events-canonical-state.test.ts +0 -406
  89. package/src/commands/events.test.ts +0 -58
  90. package/src/commands/game/index.test.ts +0 -1251
  91. package/src/commands/game-map.test.ts +0 -69
  92. package/src/commands/hub.test.ts +0 -124
  93. package/src/commands/load.test.ts +0 -440
  94. package/src/commands/perception.test.ts +0 -75
  95. package/src/commands/setup/hermes.test.ts +0 -96
  96. package/src/commands/setup/openclaw.test.ts +0 -124
  97. package/src/commands/trigger.test.ts +0 -140
  98. package/src/commands/upgrade.test.ts +0 -82
  99. package/src/lib/account-guidance.test.ts +0 -36
  100. package/src/lib/auth.test.ts +0 -151
  101. package/src/lib/behavior-export.test.ts +0 -326
  102. package/src/lib/behavior-export.ts +0 -537
  103. package/src/lib/clawclaw-skill-spectate-guidance.test.ts +0 -21
  104. package/src/lib/custom-tts.test.ts +0 -387
  105. package/src/lib/diagnostics-config.test.ts +0 -59
  106. package/src/lib/game-client-tts.test.ts +0 -151
  107. package/src/lib/game-client.test.ts +0 -250
  108. package/src/lib/gameplay-config.test.ts +0 -301
  109. package/src/lib/host-config-patcher.test.ts +0 -130
  110. package/src/lib/http-transport.test.ts +0 -124
  111. package/src/lib/hub-client.test.ts +0 -57
  112. package/src/lib/hub-install.test.ts +0 -135
  113. package/src/lib/hub-install.ts +0 -185
  114. package/src/lib/hub-unzip.test.ts +0 -69
  115. package/src/lib/init-command.test.ts +0 -103
  116. package/src/lib/load-context.test.ts +0 -62
  117. package/src/lib/match-state.test.ts +0 -134
  118. package/src/lib/official-resource-sync.test.ts +0 -199
  119. package/src/lib/official-resource-sync.ts +0 -221
  120. package/src/lib/perception-config.test.ts +0 -143
  121. package/src/lib/perception-export.test.ts +0 -145
  122. package/src/lib/perception-export.ts +0 -178
  123. package/src/lib/persona.test.ts +0 -84
  124. package/src/lib/room.test.ts +0 -88
  125. package/src/lib/server-registry.test.ts +0 -64
  126. package/src/lib/service-status.test.ts +0 -81
  127. package/src/lib/skill-version.test.ts +0 -48
  128. package/src/lib/trigger-config.test.ts +0 -102
  129. package/src/lib/trigger-export.test.ts +0 -80
  130. package/src/lib/trigger-export.ts +0 -210
  131. package/src/lib/user-data.test.ts +0 -121
  132. package/src/lib/workspace-argv.test.ts +0 -49
  133. package/src/pipeline/canonical-event-presentation.test.ts +0 -257
  134. package/src/pipeline/event-format.test.ts +0 -879
  135. package/src/pipeline/event-hints.test.ts +0 -337
  136. package/src/pipeline/game-sync-event-normalization.test.ts +0 -419
  137. package/src/pipeline/player-projection.test.ts +0 -247
  138. package/src/runtime/auto-upgrade.test.ts +0 -66
  139. package/src/runtime/canonical-event-emitter.test.ts +0 -70
  140. package/src/runtime/canonical-monitor.test.ts +0 -577
  141. package/src/runtime/clawclaw/agent-event-policy.test.ts +0 -60
  142. package/src/runtime/clawclaw/behavior-decision.test.ts +0 -43
  143. package/src/runtime/clawclaw/behavior-input-fields.test.ts +0 -175
  144. package/src/runtime/clawclaw/behavior-input.test.ts +0 -173
  145. package/src/runtime/clawclaw/behavior-observation-memory.test.ts +0 -59
  146. package/src/runtime/clawclaw/behavior-read-api.test.ts +0 -123
  147. package/src/runtime/clawclaw/notifications.test.ts +0 -47
  148. package/src/runtime/clawclaw/owner-lock.test.ts +0 -221
  149. package/src/runtime/clawclaw/owner.test.ts +0 -203
  150. package/src/runtime/clawclaw/plugins/action/action-plugin.test.ts +0 -328
  151. package/src/runtime/clawclaw/plugins/assembly.test.ts +0 -200
  152. package/src/runtime/clawclaw/plugins/behavior/activation-manager.test.ts +0 -180
  153. package/src/runtime/clawclaw/plugins/behavior/behavior-action.test.ts +0 -43
  154. package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.test.ts +0 -156
  155. package/src/runtime/clawclaw/plugins/behavior/behavior-module-loader.test.ts +0 -182
  156. package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.test.ts +0 -1094
  157. package/src/runtime/clawclaw/plugins/behavior/behavior-source.test.ts +0 -174
  158. package/src/runtime/clawclaw/plugins/behavior/control-driver.test.ts +0 -195
  159. package/src/runtime/clawclaw/plugins/behavior/official-goal-behavior.ts +0 -757
  160. package/src/runtime/clawclaw/plugins/behavior/thread-behavior-executor.test.ts +0 -283
  161. package/src/runtime/clawclaw/plugins/behavior-input-source.test.ts +0 -80
  162. package/src/runtime/clawclaw/plugins/derived-event/derived-event-plugin.test.ts +0 -267
  163. package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.test.ts +0 -226
  164. package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-adapter.test.ts +0 -239
  165. package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.test.ts +0 -407
  166. package/src/runtime/clawclaw/plugins/mailbox/desktop-event-push.integration.test.ts +0 -397
  167. package/src/runtime/clawclaw/plugins/mailbox/desktop-event-socket.test.ts +0 -270
  168. package/src/runtime/clawclaw/plugins/mailbox/mailbox-agent-event-batch.test.ts +0 -166
  169. package/src/runtime/clawclaw/plugins/mailbox/mailbox-event-batch-delivery.test.ts +0 -194
  170. package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.test.ts +0 -87
  171. package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.test.ts +0 -2012
  172. package/src/runtime/clawclaw/plugins/perception/module-runner.test.ts +0 -214
  173. package/src/runtime/clawclaw/plugins/perception/modules/co-movement-module.ts +0 -347
  174. package/src/runtime/clawclaw/plugins/perception/modules/corpse-visibility-module.test.ts +0 -92
  175. package/src/runtime/clawclaw/plugins/perception/modules/corpse-visibility-module.ts +0 -248
  176. package/src/runtime/clawclaw/plugins/perception/modules/follow-module.ts +0 -389
  177. package/src/runtime/clawclaw/plugins/perception/modules/index.ts +0 -8
  178. package/src/runtime/clawclaw/plugins/perception/modules/motion-module.test.ts +0 -342
  179. package/src/runtime/clawclaw/plugins/perception/modules/motion-module.ts +0 -475
  180. package/src/runtime/clawclaw/plugins/perception/modules/parallel-module-test-helpers.ts +0 -30
  181. package/src/runtime/clawclaw/plugins/perception/modules/relation-stability.test.ts +0 -304
  182. package/src/runtime/clawclaw/plugins/perception/modules/route-module.test.ts +0 -179
  183. package/src/runtime/clawclaw/plugins/perception/modules/route-module.ts +0 -364
  184. package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.test.ts +0 -81
  185. package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.ts +0 -200
  186. package/src/runtime/clawclaw/plugins/perception/modules/stop-module.test.ts +0 -216
  187. package/src/runtime/clawclaw/plugins/perception/modules/stop-module.ts +0 -284
  188. package/src/runtime/clawclaw/plugins/perception/modules/temporal-evidence.test.ts +0 -120
  189. package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.test.ts +0 -105
  190. package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.ts +0 -269
  191. package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.test.ts +0 -865
  192. package/src/runtime/clawclaw/plugins/perception/perception-plugin.test.ts +0 -1878
  193. package/src/runtime/clawclaw/plugins/perception/perception-source.test.ts +0 -278
  194. package/src/runtime/clawclaw/plugins/perception/replay.test.ts +0 -77
  195. package/src/runtime/clawclaw/plugins/runtime-plugins.test.ts +0 -853
  196. package/src/runtime/clawclaw/plugins/source/game-transport.test.ts +0 -287
  197. package/src/runtime/clawclaw/plugins/source/player-change-tracker.test.ts +0 -321
  198. package/src/runtime/clawclaw/plugins/source/room-transport.test.ts +0 -307
  199. package/src/runtime/clawclaw/plugins/source/source-plugin.test.ts +0 -2646
  200. package/src/runtime/clawclaw/plugins/source/task-change-tracker.test.ts +0 -212
  201. package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.test.ts +0 -548
  202. package/src/runtime/clawclaw/plugins/trigger/trigger-source.test.ts +0 -169
  203. package/src/runtime/clawclaw/runtime-data-export.test.ts +0 -249
  204. package/src/runtime/clawclaw-event-catalog.test.ts +0 -128
  205. package/src/runtime/framework/action-diagnostics.test.ts +0 -81
  206. package/src/runtime/framework/capability-registry.test.ts +0 -423
  207. package/src/runtime/framework/control-coordinator.test.ts +0 -675
  208. package/src/runtime/framework/events/event-delivery-service.test.ts +0 -84
  209. package/src/runtime/framework/events/event-ingress.test.ts +0 -203
  210. package/src/runtime/framework/events/mailbox-event-repositories.test.ts +0 -710
  211. package/src/runtime/framework/events/sqlite-event-repository.test.ts +0 -802
  212. package/src/runtime/framework/mailbox/coalescer.test.ts +0 -55
  213. package/src/runtime/framework/mailbox/identity.test.ts +0 -38
  214. package/src/runtime/framework/mailbox/mailbox-dispatcher.test.ts +0 -513
  215. package/src/runtime/framework/mailbox/notification-projector.test.ts +0 -77
  216. package/src/runtime/framework/modules/runtime-module-loader.test.ts +0 -435
  217. package/src/runtime/framework/participation-manager.test.ts +0 -108
  218. package/src/runtime/framework/plugins/runtime-input-journal.test.ts +0 -179
  219. package/src/runtime/framework/plugins/runtime-plugin-scheduler.test.ts +0 -2040
  220. package/src/runtime/framework/state/durable-agent-state-snapshot.test.ts +0 -144
  221. package/src/runtime/framework/state/history/sqlite-state-history-repository.test.ts +0 -157
  222. package/src/runtime/framework/state/history/state-history.test.ts +0 -251
  223. package/src/runtime/framework/state/state-core.test.ts +0 -197
  224. package/src/runtime/game-sync-protocol.test.ts +0 -123
  225. package/src/runtime/host-monitor-rate-gate.test.ts +0 -73
  226. package/src/runtime/mailbox-host-relay.test.ts +0 -293
  227. package/src/runtime/observability/observability.test.ts +0 -583
  228. package/src/runtime/owner-control.test.ts +0 -153
  229. package/src/runtime/parent-process-watch.test.ts +0 -27
  230. package/src/runtime/pending-event-handoff.test.ts +0 -29
  231. package/src/runtime/raw-ws-log.test.ts +0 -102
  232. package/src/runtime/runtime-logger.test.ts +0 -58
  233. package/src/runtime/runtime-persistence.test.ts +0 -26
  234. package/src/runtime/runtime.test.ts +0 -1770
  235. package/src/runtime/ws-client.test.ts +0 -562
  236. package/src/sdk/action.test.ts +0 -8
  237. package/src/sdk/behavior-plugin/index.test.ts +0 -74
  238. package/src/sdk/index.test.ts +0 -45
  239. package/src/sdk/module-input/index.test.ts +0 -49
  240. package/src/sdk/perception-plugin/index.test.ts +0 -22
  241. package/src/sdk/resource-metadata.test.ts +0 -40
  242. package/src/sdk/trigger-plugin/index.test.ts +0 -41
  243. package/src/short-command/classifier.test.ts +0 -107
  244. package/src/short-command/presenter.test.ts +0 -119
  245. package/src/short-command/runner.test.ts +0 -78
  246. package/src/short-command/sensitive-data-filter.test.ts +0 -56
  247. package/src/short-command/transport-response.test.ts +0 -39
  248. package/src/strategies/avoid-lone.ts +0 -32
  249. package/src/strategies/avoid-players.ts +0 -43
  250. package/src/strategies/corpse-patrol.ts +0 -50
  251. package/src/strategies/crab-sabotage.ts +0 -48
  252. package/src/strategies/custom-module.test.ts +0 -267
  253. package/src/strategies/find-player.ts +0 -49
  254. package/src/strategies/game-utils.test.ts +0 -305
  255. package/src/strategies/game-utils.ts +0 -927
  256. package/src/strategies/goals/anchor-linger.ts +0 -77
  257. package/src/strategies/goals/avoid-lone-top.ts +0 -189
  258. package/src/strategies/goals/avoid-players-top.test.ts +0 -95
  259. package/src/strategies/goals/avoid-players-top.ts +0 -122
  260. package/src/strategies/goals/conversation-goal.ts +0 -51
  261. package/src/strategies/goals/corpse-patrol-top.ts +0 -120
  262. package/src/strategies/goals/crab-octopus-reflexes.ts +0 -109
  263. package/src/strategies/goals/crab-sabotage-top.test.ts +0 -131
  264. package/src/strategies/goals/crab-sabotage-top.ts +0 -139
  265. package/src/strategies/goals/emergency-hunt-goal.ts +0 -40
  266. package/src/strategies/goals/find-player-top.ts +0 -136
  267. package/src/strategies/goals/flee-players-goal.ts +0 -55
  268. package/src/strategies/goals/follow-companion-goal.ts +0 -130
  269. package/src/strategies/goals/goal-manager.ts +0 -41
  270. package/src/strategies/goals/goal-root-strategy.ts +0 -49
  271. package/src/strategies/goals/goal.ts +0 -28
  272. package/src/strategies/goals/hide-top.ts +0 -240
  273. package/src/strategies/goals/keep-away-goal.ts +0 -243
  274. package/src/strategies/goals/kill-frenzy-top.ts +0 -90
  275. package/src/strategies/goals/kill-lone-top.test.ts +0 -96
  276. package/src/strategies/goals/kill-lone-top.ts +0 -166
  277. package/src/strategies/goals/kill-target-goal.ts +0 -69
  278. package/src/strategies/goals/kill-target-top.test.ts +0 -65
  279. package/src/strategies/goals/kill-target-top.ts +0 -121
  280. package/src/strategies/goals/leaf-goal.ts +0 -27
  281. package/src/strategies/goals/linger-corpse-goal.ts +0 -43
  282. package/src/strategies/goals/lone-kill-core.ts +0 -86
  283. package/src/strategies/goals/lone-kill-goal.ts +0 -24
  284. package/src/strategies/goals/lone-kill-task-top.test.ts +0 -84
  285. package/src/strategies/goals/lone-kill-task-top.ts +0 -133
  286. package/src/strategies/goals/move-room-goal.ts +0 -102
  287. package/src/strategies/goals/normal-shrimp-top.test.ts +0 -112
  288. package/src/strategies/goals/normal-shrimp-top.ts +0 -248
  289. package/src/strategies/goals/paradise-fish-top.test.ts +0 -203
  290. package/src/strategies/goals/paradise-fish-top.ts +0 -234
  291. package/src/strategies/goals/patrol-top.ts +0 -68
  292. package/src/strategies/goals/report-patrol-top.ts +0 -97
  293. package/src/strategies/goals/safe-task-goal.ts +0 -130
  294. package/src/strategies/goals/social-task-top.ts +0 -192
  295. package/src/strategies/goals/task-kill-report-top.ts +0 -187
  296. package/src/strategies/goals/task-only-top.test.ts +0 -88
  297. package/src/strategies/goals/task-only-top.ts +0 -64
  298. package/src/strategies/goals/task-or-patrol-goal.ts +0 -59
  299. package/src/strategies/goals/task-report-top.ts +0 -57
  300. package/src/strategies/goals/wander-task-goal.ts +0 -33
  301. package/src/strategies/goals/warrior-shrimp-top.test.ts +0 -138
  302. package/src/strategies/goals/warrior-shrimp-top.ts +0 -293
  303. package/src/strategies/greeting.ts +0 -60
  304. package/src/strategies/hide.ts +0 -51
  305. package/src/strategies/kill-frenzy.ts +0 -32
  306. package/src/strategies/kill-lone.ts +0 -52
  307. package/src/strategies/kill-target.ts +0 -48
  308. package/src/strategies/lone-kill-task.ts +0 -48
  309. package/src/strategies/meeting-gate.test.ts +0 -59
  310. package/src/strategies/meeting-gate.ts +0 -28
  311. package/src/strategies/move-room.ts +0 -46
  312. package/src/strategies/official-long-behavior.test.ts +0 -89
  313. package/src/strategies/paradise-fish.ts +0 -70
  314. package/src/strategies/pathfind/astar-path.test.ts +0 -198
  315. package/src/strategies/pathfind/escape-planner.test.ts +0 -223
  316. package/src/strategies/patrol.ts +0 -32
  317. package/src/strategies/player-targets.test.ts +0 -10
  318. package/src/strategies/player-targets.ts +0 -18
  319. package/src/strategies/report-patrol.ts +0 -32
  320. package/src/strategies/shrimp-memory.ts +0 -87
  321. package/src/strategies/social-task.ts +0 -67
  322. package/src/strategies/speech-module.ts +0 -123
  323. package/src/strategies/task-kill-report.ts +0 -49
  324. package/src/strategies/task-only.test.ts +0 -138
  325. package/src/strategies/task-only.ts +0 -34
  326. package/src/strategies/task-report.ts +0 -50
  327. package/src/strategies/types.ts +0 -116
  328. package/src/strategies/warrior-memory.ts +0 -54
  329. /package/src/{strategies/pathfind → runtime/clawclaw/navigation}/clawclaw-walkable.bin +0 -0
  330. /package/src/{strategies/pathfind → runtime/clawclaw/navigation}/distance-field.ts +0 -0
@@ -1,283 +0,0 @@
1
- import { mkdtemp, rm, writeFile } from 'node:fs/promises';
2
- import { tmpdir } from 'node:os';
3
- import { join } from 'node:path';
4
- import { threadId as ownerThreadId } from 'node:worker_threads';
5
- import { afterEach, describe, expect, it, vi } from 'vitest';
6
- import type { BehaviorInput } from '../../../../sdk/behavior-plugin/index.js';
7
- import { ClawclawBehaviorCatalog } from './behavior-catalog.js';
8
- import { ClawclawBehaviorRunner } from './behavior-runner.js';
9
- import { inspectClawclawBehaviorSource } from './behavior-source.js';
10
- import { ThreadBehaviorExecutor } from './thread-behavior-executor.js';
11
-
12
- function frame(
13
- epochId: number,
14
- state: Readonly<Record<string, unknown>> = {},
15
- ): BehaviorInput<Record<string, unknown>> {
16
- return {
17
- epochId,
18
- scope: { sessionId: 'session', segmentId: 'segment' },
19
- nowMs: epochId * 100,
20
- gameState: {
21
- game_id: 'fixture-game',
22
- phase: 'wandering',
23
- tick: epochId,
24
- you: {
25
- player: { name: 'fixture-player', seat: 1 },
26
- room: 'fixture-room',
27
- role: 'shrimp_generic',
28
- faction: 'lobster',
29
- is_alive: true,
30
- x: 500,
31
- y: 500,
32
- activity: { kind: 'idle' },
33
- tasks: [],
34
- },
35
- players: [],
36
- visible_players: [],
37
- visible_corpses: [],
38
- ...state,
39
- } as BehaviorInput<Record<string, unknown>>['gameState'],
40
- events: [],
41
- input: {},
42
- };
43
- }
44
-
45
- describe('parallel Behavior Worker executor', () => {
46
- const directories: string[] = [];
47
- const executors: ThreadBehaviorExecutor[] = [];
48
- const runners: ClawclawBehaviorRunner[] = [];
49
-
50
- afterEach(async () => {
51
- await Promise.allSettled(runners.splice(0).map(runner => runner.stop('shutdown')));
52
- await Promise.allSettled(executors.splice(0).map(executor => executor.stop('shutdown')));
53
- await Promise.all(directories.splice(0).map(directory => (
54
- rm(directory, { recursive: true, force: true })
55
- )));
56
- });
57
-
58
- async function fixture(
59
- id: string,
60
- decide: string,
61
- options: Readonly<{ imports?: string; fields?: string }> = {},
62
- ) {
63
- const sourceRoot = await mkdtemp(join(tmpdir(), `ccl-behavior-${id}-`));
64
- directories.push(sourceRoot);
65
- const sourcePath = join(sourceRoot, `${id}.ts`);
66
- await writeFile(sourcePath, `
67
- ${options.imports ?? ''}
68
- import { ClawclawBehavior } from '@myclaw163/clawclaw-cli/behavior-plugin';
69
- export default class FixtureBehavior extends ClawclawBehavior {
70
- static manifest = {
71
- apiVersion: 3,
72
- id: '${id}',
73
- name: '${id}',
74
- description: '${id} Worker fixture.',
75
- localizations: { 'zh-CN': { name: '${id}', description: '${id} Worker fixture.' } },
76
- execution: 'parallel',
77
- inputs: [],
78
- } as const;
79
- ${options.fields ?? ''}
80
- decide(input) { ${decide} }
81
- }
82
- `, 'utf8');
83
- const source = inspectClawclawBehaviorSource(sourcePath, sourceRoot);
84
- expect(source).not.toBeNull();
85
- return source!;
86
- }
87
-
88
- it('routes ClawclawBehaviorRunner parallel Decisions through the Worker pool', async () => {
89
- const source = await fixture(
90
- 'runner-worker-route',
91
- `return { status: { summary: 'runner worker', data: { threadId } } };`,
92
- { imports: `import { threadId } from 'node:worker_threads';` },
93
- );
94
- const prepared = await new ClawclawBehaviorCatalog([source]).prepare(source.id, {});
95
- const runner = new ClawclawBehaviorRunner({
96
- behaviorId: source.id,
97
- activationId: 'activation-worker-route',
98
- instanceGeneration: 1,
99
- prepared,
100
- isActive: () => true,
101
- });
102
- runners.push(runner);
103
-
104
- const decision = await runner.decideParallel(
105
- frame(1),
106
- new AbortController().signal,
107
- );
108
- expect((decision.status?.data as { threadId: number }).threadId).not.toBe(ownerThreadId);
109
- });
110
-
111
- it('prewarms reusable Workers, runs off the Owner thread, and creates a fresh instance per Decision', async () => {
112
- const source = await fixture(
113
- 'worker-isolation',
114
- `
115
- this.calls += 1;
116
- const startedAt = Date.now();
117
- Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, Number(input.gameState.delay_ms ?? 0));
118
- return { status: { summary: 'isolated', data: {
119
- threadId, calls: this.calls, epochId: input.epochId,
120
- startedAt, endedAt: Date.now(), frozen: Object.isFrozen(input.gameState),
121
- } } };
122
- `,
123
- { imports: `import { threadId } from 'node:worker_threads';`, fields: 'calls = 0;' },
124
- );
125
- const executor = new ThreadBehaviorExecutor({ source, poolSize: 2 });
126
- executors.push(executor);
127
- const signal = new AbortController().signal;
128
- await executor.start(signal);
129
- expect(executor.snapshot()).toMatchObject({
130
- state: 'running', workerCount: 2, idleWorkerCount: 2, startedWorkerCount: 2,
131
- });
132
-
133
- const [first, second] = await Promise.all([
134
- executor.update(frame(1, { delay_ms: 80 }), signal),
135
- executor.update(frame(2, { delay_ms: 80 }), signal),
136
- ]);
137
- const left = first.status?.data as Record<string, number | boolean>;
138
- const right = second.status?.data as Record<string, number | boolean>;
139
- expect(left.threadId).not.toBe(ownerThreadId);
140
- expect(right.threadId).not.toBe(ownerThreadId);
141
- expect(new Set([left.threadId, right.threadId]).size).toBe(2);
142
- expect(left.calls).toBe(1);
143
- expect(right.calls).toBe(1);
144
- expect(left.frozen).toBe(true);
145
- expect(right.frozen).toBe(true);
146
- expect(Math.max(Number(left.startedAt), Number(right.startedAt))).toBeLessThan(
147
- Math.min(Number(left.endedAt), Number(right.endedAt)),
148
- );
149
-
150
- await expect(executor.update(frame(3), signal)).resolves.toMatchObject({
151
- status: { data: { calls: 1, epochId: 3 } },
152
- });
153
- });
154
-
155
- it('scales from two Workers to pressure demand, reuses the pool, then retires idle capacity', async () => {
156
- const source = await fixture('worker-scale', `
157
- Atomics.wait(new Int32Array(input.gameState.gate), 0, 0);
158
- return { status: { summary: 'released', data: { epochId: input.epochId } } };
159
- `);
160
- const diagnostics: Array<{ name: string; attributes?: Readonly<Record<string, unknown>> }> = [];
161
- const executor = new ThreadBehaviorExecutor({
162
- source,
163
- poolSize: 4,
164
- idleWorkerTimeoutMs: 50,
165
- diagnostic: (name, attributes) => diagnostics.push({ name, attributes }),
166
- });
167
- executors.push(executor);
168
- const signal = new AbortController().signal;
169
- await executor.start(signal);
170
-
171
- const gate = new SharedArrayBuffer(4);
172
- const wave = Array.from({ length: 4 }, (_, index) => (
173
- executor.update(frame(index + 1, { gate }), signal)
174
- ));
175
- await vi.waitFor(() => expect(executor.snapshot()).toMatchObject({
176
- workerCount: 4,
177
- busyWorkerCount: 4,
178
- queuedRequestCount: 0,
179
- inFlightRequestCount: 4,
180
- startedWorkerCount: 4,
181
- }), { timeout: 10_000 });
182
- expect(diagnostics.filter(entry => (
183
- entry.name === 'behavior.thread.started' && entry.attributes?.reason === 'queue_pressure'
184
- ))).toHaveLength(2);
185
-
186
- Atomics.store(new Int32Array(gate), 0, 1);
187
- Atomics.notify(new Int32Array(gate), 0);
188
- await expect(Promise.all(wave)).resolves.toHaveLength(4);
189
- await expect(executor.update(frame(5, { gate }), signal)).resolves.toMatchObject({
190
- status: { data: { epochId: 5 } },
191
- });
192
- await vi.waitFor(() => expect(executor.snapshot()).toMatchObject({
193
- workerCount: 2,
194
- idleWorkerCount: 2,
195
- busyWorkerCount: 0,
196
- startedWorkerCount: 4,
197
- retiredWorkerCount: 2,
198
- }), { timeout: 5_000 });
199
- });
200
-
201
- it('retires an aborted slot and restores capacity before the next Decision', async () => {
202
- const source = await fixture('worker-abort', `
203
- Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, Number(input.gameState.delay_ms));
204
- return {};
205
- `);
206
- const executor = new ThreadBehaviorExecutor({ source, poolSize: 1 });
207
- executors.push(executor);
208
- await executor.start(new AbortController().signal);
209
- const controller = new AbortController();
210
- const pending = executor.update(frame(1, { delay_ms: 500 }), controller.signal);
211
- await vi.waitFor(() => expect(executor.snapshot().busyWorkerCount).toBe(1));
212
- controller.abort(new Error('superseded'));
213
- await expect(pending).rejects.toThrow('superseded');
214
-
215
- await vi.waitFor(() => expect(executor.snapshot()).toMatchObject({
216
- state: 'running', workerCount: 1, idleWorkerCount: 1,
217
- retiredWorkerCount: 1, startedWorkerCount: 2,
218
- }), { timeout: 5_000 });
219
- await expect(executor.update(
220
- frame(2, { delay_ms: 0 }),
221
- new AbortController().signal,
222
- )).resolves.toEqual({});
223
- });
224
-
225
- it('isolates a crashing Worker and replaces only that slot', async () => {
226
- const source = await fixture('worker-crash', `
227
- if (input.epochId === 1) process.exit(42);
228
- return { status: { summary: 'recovered', data: { epochId: input.epochId } } };
229
- `);
230
- const executor = new ThreadBehaviorExecutor({ source, poolSize: 1 });
231
- executors.push(executor);
232
- const signal = new AbortController().signal;
233
- await executor.start(signal);
234
-
235
- await expect(executor.update(frame(1), signal)).rejects.toThrow('behavior_thread_worker_exited:42');
236
- await vi.waitFor(() => expect(executor.snapshot()).toMatchObject({
237
- state: 'running', workerCount: 1, idleWorkerCount: 1,
238
- retiredWorkerCount: 1, startedWorkerCount: 2,
239
- }), { timeout: 5_000 });
240
- await expect(executor.update(frame(2), signal)).resolves.toMatchObject({
241
- status: { data: { epochId: 2 } },
242
- });
243
- });
244
-
245
- it('refuses to mix a changed local dependency into an existing pool generation', async () => {
246
- const source = await fixture(
247
- 'worker-source-pin',
248
- `return { status: { summary } };`,
249
- { imports: `import { summary } from './worker-helper.ts';` },
250
- );
251
- const helper = join(source.sourceRoot, 'worker-helper.ts');
252
- await writeFile(helper, `export const summary = 'original';\n`, 'utf8');
253
- const executor = new ThreadBehaviorExecutor({ source, poolSize: 1 });
254
- executors.push(executor);
255
- await writeFile(helper, `export const summary = 'changed';\n`, 'utf8');
256
-
257
- await expect(executor.start(new AbortController().signal))
258
- .rejects.toThrow('behavior_source_tree_changed');
259
- });
260
-
261
- it('rechecks the pinned tree after a Worker finishes importing it', async () => {
262
- const source = await fixture(
263
- 'worker-import-pin',
264
- `return { status: { summary } };`,
265
- {
266
- imports: `
267
- import { summary } from './worker-import-helper.ts';
268
- Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 200);
269
- `,
270
- },
271
- );
272
- const helper = join(source.sourceRoot, 'worker-import-helper.ts');
273
- await writeFile(helper, `export const summary = 'original';\n`, 'utf8');
274
- const executor = new ThreadBehaviorExecutor({ source, poolSize: 1 });
275
- executors.push(executor);
276
-
277
- const starting = executor.start(new AbortController().signal);
278
- await new Promise((resolve) => setTimeout(resolve, 75));
279
- await writeFile(helper, `export const summary = 'changed';\n`, 'utf8');
280
-
281
- await expect(starting).rejects.toThrow('behavior_source_tree_changed');
282
- });
283
- });
@@ -1,80 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import {
3
- hasTopLevelManifestProperty,
4
- parseLiteralBehaviorInputFields,
5
- } from './behavior-input-source.js';
6
-
7
- describe('parseLiteralBehaviorInputFields', () => {
8
- it('parses a strict top-level literal without evaluating TypeScript', () => {
9
- const result = parseLiteralBehaviorInputFields(`{
10
- apiVersion: 2,
11
- localizations: { 'zh-CN': { description: 'inputs: not a field' } },
12
- inputs: [
13
- { id: 'name', type: 'string', description: 'Name', default: 'A\\nB' },
14
- { id: 'count', type: 'number', description: 'Count', min: -1.5, max: 1e2 },
15
- { id: 'enabled', type: 'boolean', description: 'Enabled', default: false },
16
- {
17
- id: 'mode', type: 'enum', description: 'Mode',
18
- values: ['safe', 'fast'] as const, default: 'safe',
19
- },
20
- { id: 'tags', type: 'string_list', description: 'Tags', maxItems: 2, default: [] },
21
- { id: 'target', type: 'player_seat', description: 'Target', required: true },
22
- { id: 'allies', type: 'player_seats', description: 'Allies', maxItems: 4 },
23
- ] as const,
24
- produces: [],
25
- }`);
26
-
27
- expect(result.status).toBe('valid');
28
- if (result.status !== 'valid') return;
29
- expect(result.inputs).toHaveLength(7);
30
- expect(result.inputs[0]).toMatchObject({ id: 'name', default: 'A\nB' });
31
- expect(result.inputs[1]).toMatchObject({ min: -1.5, max: 100 });
32
- expect(result.inputs[5]).toMatchObject({ type: 'player_seat', required: true });
33
- expect(Object.isFrozen(result.inputs)).toBe(true);
34
- });
35
-
36
- it('distinguishes missing, dynamic, malformed, and schema-invalid declarations', () => {
37
- expect(parseLiteralBehaviorInputFields('{ apiVersion: 2 }'))
38
- .toEqual({ status: 'missing' });
39
- expect(parseLiteralBehaviorInputFields('{ inputs: getInputs() }'))
40
- .toEqual({ status: 'invalid', diagnostic: 'behavior_inputs_not_literal' });
41
- expect(parseLiteralBehaviorInputFields(`{
42
- inputs: [{ id: 'mode', type: 'enum', description: 'Mode', values: MODES }],
43
- }`)).toEqual({ status: 'invalid', diagnostic: 'behavior_inputs_not_literal' });
44
- expect(parseLiteralBehaviorInputFields(`{
45
- inputs: [{ id: 'count', type: 'number', description: 'Count', min: 3, max: 2 }],
46
- }`)).toEqual({
47
- status: 'invalid',
48
- diagnostic: 'behavior_input_number_bounds_invalid:count',
49
- });
50
- expect(parseLiteralBehaviorInputFields(`{
51
- inputs: [{ id: 'target', type: 'player_seat', description: 'Target', required: true, default: 2 }],
52
- }`)).toEqual({
53
- status: 'invalid',
54
- diagnostic: 'behavior_input_required_default_conflict:target',
55
- });
56
- });
57
-
58
- it('rejects template interpolation and arithmetic instead of evaluating them', () => {
59
- expect(parseLiteralBehaviorInputFields(`{
60
- inputs: [{ id: 'name', type: 'string', description: 'Name', default: \`player-\${seat}\` }],
61
- }`)).toEqual({ status: 'invalid', diagnostic: 'behavior_inputs_not_literal' });
62
- expect(parseLiteralBehaviorInputFields(`{
63
- inputs: [{ id: 'count', type: 'number', description: 'Count', default: 1 + 2 }],
64
- }`)).toEqual({ status: 'invalid', diagnostic: 'behavior_inputs_literal_invalid' });
65
- });
66
-
67
- it('detects only real top-level properties', () => {
68
- expect(hasTopLevelManifestProperty(`{
69
- description: 'mentions controls: without declaring it',
70
- localizations: { 'zh-CN': { controls: [] } },
71
- // controls: []
72
- inputs: [],
73
- }`, 'controls')).toBe(false);
74
- expect(hasTopLevelManifestProperty(`{
75
- description: 'legacy manifest',
76
- 'controls': [],
77
- inputs: [],
78
- }`, 'controls')).toBe(true);
79
- });
80
- });
@@ -1,267 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { createClawclawEventCatalog } from '../../../clawclaw-event-catalog.js';
3
- import { MemoryEventRepository } from '../../../framework/events/index.js';
4
- import { Runtime } from '../../../framework/runtime.js';
5
- import { MemoryStateHistoryRepository } from '../../../framework/state/index.js';
6
- import { projectClawclawCurrentState } from '../../runtime-state.js';
7
- import {
8
- ClawclawDerivedEventPlugin,
9
- CLAWCLAW_DERIVED_EVENT_PLUGIN_ID,
10
- } from './derived-event-plugin.js';
11
- import { EmergencyCountdownDerivedEventRule } from './derived-event-rules.js';
12
-
13
- function roomState(ready: boolean, roomType = 'casual'): Record<string, any> {
14
- return {
15
- schema: 'clawclaw.runtime-state.v1',
16
- stage: 'room',
17
- transport: 'room_ws',
18
- connection: 'connected',
19
- cause: 'room_update',
20
- room: {
21
- phase: 'room_waiting',
22
- room: {
23
- room_code: 'R1',
24
- room_type: roomType,
25
- status: 'waiting',
26
- is_owner: true,
27
- member_count: ready ? 10 : 9,
28
- ready_to_start: ready,
29
- },
30
- },
31
- game_snapshot: { status: 'unavailable' },
32
- };
33
- }
34
-
35
- function gameState(
36
- tick: number,
37
- meeting?: Record<string, any>,
38
- state: Record<string, any> = {},
39
- ): Record<string, any> {
40
- return {
41
- schema: 'clawclaw.runtime-state.v1',
42
- stage: meeting ? 'meeting' : 'game',
43
- transport: 'game_ws',
44
- connection: 'connected',
45
- cause: 'game_snapshot',
46
- game_snapshot: {
47
- status: 'fresh',
48
- state: {
49
- tick,
50
- phase: meeting ? 'meeting' : 'wandering',
51
- ...state,
52
- ...(meeting ? { meeting } : {}),
53
- },
54
- },
55
- };
56
- }
57
-
58
- function storedGameFrame(tick: number, state: Record<string, any>): any {
59
- return {
60
- frameSeq: tick,
61
- epochSeq: tick,
62
- state: gameState(tick, undefined, state),
63
- observedAtMs: tick * 1_000,
64
- receivedAtMs: tick * 1_000,
65
- };
66
- }
67
-
68
- async function fixture(kind: 'room' | 'game') {
69
- const events = new MemoryEventRepository();
70
- const runtime = new Runtime({
71
- adapterId: 'clawclaw',
72
- accountId: `derived-${kind}`,
73
- eventCatalog: createClawclawEventCatalog(),
74
- eventRepository: events,
75
- stateHistoryRepository: new MemoryStateHistoryRepository(),
76
- currentStateFromRuntimeState: projectClawclawCurrentState,
77
- runtimeEpochPlugins: [new ClawclawDerivedEventPlugin()],
78
- initialSegment: { kind, identity: `${kind}-1` },
79
- });
80
- await runtime.start();
81
- let sourceSeq = 0;
82
- const submit = async (state: Record<string, any>) => {
83
- sourceSeq += 1;
84
- await runtime.acceptInputBatch({
85
- scope: runtime.scope(),
86
- sourceId: `test.${kind}`,
87
- connectionId: `${kind}-connection`,
88
- sourceKey: `${kind}:${sourceSeq}`,
89
- sourceSeq,
90
- state,
91
- events: [],
92
- completeness: 'complete',
93
- receivedAt: new Date(sourceSeq * 100).toISOString(),
94
- });
95
- };
96
- return { runtime, events, submit };
97
- }
98
-
99
- describe('ClawclawDerivedEventPlugin', () => {
100
- it('emits room readiness only on a false-to-true transition', async () => {
101
- const { runtime, events, submit } = await fixture('room');
102
- await submit(roomState(false, 'training_simulation'));
103
- await submit(roomState(true, 'training_simulation'));
104
- await submit(roomState(true, 'training_simulation'));
105
- await submit(roomState(false));
106
- await submit(roomState(true));
107
- await runtime.flush();
108
-
109
- const ready = events.listCommittedEvents({
110
- sessionId: runtime.scope().sessionId,
111
- types: ['room_ready_to_start'],
112
- order: 'asc',
113
- });
114
- expect(ready).toHaveLength(2);
115
- expect(ready[0]).toMatchObject({
116
- producer: 'local_synth',
117
- producerPluginId: CLAWCLAW_DERIVED_EVENT_PLUGIN_ID,
118
- payload: {
119
- room_code: 'R1',
120
- room_type: 'training_simulation',
121
- member_count: 10,
122
- ready_to_start: true,
123
- },
124
- });
125
- await runtime.close();
126
- });
127
-
128
- it('emits each changed meeting projection and infers consecutive rounds', async () => {
129
- const { runtime, events, submit } = await fixture('game');
130
- const first = {
131
- caller: 'P1',
132
- sub_phase: 'speech',
133
- current_speaker: 'P2',
134
- speech_order: ['P2', 'P3'],
135
- alive_players: ['P1', 'P2', 'P3'],
136
- };
137
- await submit(gameState(10, first));
138
- await submit(gameState(11, first));
139
- await submit(gameState(12, { ...first, current_speaker: 'P3' }));
140
- await submit(gameState(20));
141
- await submit(gameState(30, { ...first, caller: 'P3' }));
142
- await runtime.flush();
143
-
144
- const meetingStates = events.listCommittedEvents({
145
- sessionId: runtime.scope().sessionId,
146
- types: ['meeting_state'],
147
- order: 'asc',
148
- });
149
- expect(meetingStates.map((event) => event.payload)).toMatchObject([
150
- { tick: 10, round: 1, caller: 'P1', current_speaker: 'P2' },
151
- { tick: 12, round: 1, caller: 'P1', current_speaker: 'P3' },
152
- { tick: 30, round: 2, caller: 'P3', current_speaker: 'P2' },
153
- ]);
154
- expect(meetingStates.every((event) => (
155
- event.producerPluginId === CLAWCLAW_DERIVED_EVENT_PLUGIN_ID
156
- ))).toBe(true);
157
- await runtime.close();
158
- });
159
-
160
- it('emits emergency countdown warnings once at 30s and 20s', async () => {
161
- const { runtime, events, submit } = await fixture('game');
162
- const emergency = (remainingSecs: number) => ({
163
- emergency: {
164
- active: true,
165
- task_name: '修复供氧',
166
- room: '制氧舱',
167
- remaining_secs: remainingSecs,
168
- },
169
- you: { is_alive: true },
170
- });
171
- await submit(gameState(1, undefined, emergency(31)));
172
- await submit(gameState(2, undefined, emergency(29.8)));
173
- await submit(gameState(3, undefined, emergency(25)));
174
- await submit(gameState(4, undefined, emergency(19.7)));
175
- await submit(gameState(5, undefined, emergency(18)));
176
- await runtime.flush();
177
-
178
- const warnings = events.listCommittedEvents({
179
- sessionId: runtime.scope().sessionId,
180
- types: ['emergency_countdown_warning'],
181
- order: 'asc',
182
- });
183
- expect(warnings.map((event) => event.payload)).toMatchObject([{
184
- tick: 2,
185
- threshold_secs: 30,
186
- remaining_secs: 29.8,
187
- }, {
188
- tick: 4,
189
- threshold_secs: 20,
190
- remaining_secs: 19.7,
191
- }]);
192
- expect(warnings.every((event) => (
193
- event.producerPluginId === CLAWCLAW_DERIVED_EVENT_PLUGIN_ID
194
- ))).toBe(true);
195
- await runtime.close();
196
- });
197
-
198
- it('rebuilds countdown rule state without replay and preserves a two-threshold leap', () => {
199
- const emergency = (remainingSecs: number) => ({
200
- emergency: { active: true, task_name: '维修', remaining_secs: remainingSecs },
201
- you: { is_alive: true },
202
- });
203
- const recovered = new EmergencyCountdownDerivedEventRule();
204
- recovered.inspect(storedGameFrame(1, emergency(31)));
205
- recovered.inspect(storedGameFrame(2, emergency(29)));
206
- expect(recovered.inspect(storedGameFrame(3, emergency(25)))).toEqual([]);
207
- expect(recovered.inspect(storedGameFrame(4, emergency(19))).map((event) => (
208
- event.payload.threshold_secs
209
- ))).toEqual([20]);
210
-
211
- const skipped = new EmergencyCountdownDerivedEventRule();
212
- skipped.inspect(storedGameFrame(1, emergency(31)));
213
- expect(skipped.inspect(storedGameFrame(2, emergency(19))).map((event) => (
214
- event.payload.threshold_secs
215
- ))).toEqual([30, 20]);
216
- });
217
-
218
- it('emits ability readiness and finite-use changes from authoritative State transitions', async () => {
219
- const { runtime, events, submit } = await fixture('game');
220
- const pistol = (cooldown: number, remaining: number) => ({
221
- you: {
222
- role: 'shrimp_pistol',
223
- is_alive: true,
224
- kill_cooldown_secs: cooldown,
225
- kills_remaining: remaining,
226
- },
227
- });
228
- await submit(gameState(1, undefined, pistol(1, 1)));
229
- await submit(gameState(2, undefined, pistol(0, 1)));
230
- await submit(gameState(3, undefined, pistol(20, 0)));
231
- await runtime.flush();
232
-
233
- const abilityEvents = events.listCommittedEvents({
234
- sessionId: runtime.scope().sessionId,
235
- types: ['ability.ready', 'ability.exhausted'],
236
- order: 'asc',
237
- });
238
- expect(abilityEvents.map((event) => ({ type: event.type, payload: event.payload })))
239
- .toMatchObject([{
240
- type: 'ability.ready',
241
- payload: { tick: 2, ability_id: 'kill', remaining_uses: 1 },
242
- }, {
243
- type: 'ability.exhausted',
244
- payload: {
245
- tick: 3,
246
- ability_id: 'kill',
247
- previous_remaining_uses: 1,
248
- remaining_uses: 0,
249
- },
250
- }]);
251
- expect(abilityEvents.every((event) => (
252
- event.producerPluginId === CLAWCLAW_DERIVED_EVENT_PLUGIN_ID
253
- ))).toBe(true);
254
- await runtime.close();
255
- });
256
-
257
- it('does not claim backend-owned terminal or turn Events', () => {
258
- expect(new ClawclawDerivedEventPlugin().produces.events).toEqual([
259
- 'room_ready_to_start',
260
- 'meeting_state',
261
- 'emergency_countdown_warning',
262
- 'ability.ready',
263
- 'ability.remaining_uses_changed',
264
- 'ability.exhausted',
265
- ]);
266
- });
267
- });