@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,397 +0,0 @@
1
- import { randomUUID } from 'node:crypto';
2
- import { createServer, type Server, type Socket } from 'node:net';
3
- import { afterEach, describe, expect, it, vi } from 'vitest';
4
- import { presentCanonicalEventForDesktop } from '../../../../pipeline/canonical-event-presentation.js';
5
- import { compactStateForEvents } from '../../../../pipeline/event-format.js';
6
- import { createClawclawEventCatalog } from '../../../clawclaw-event-catalog.js';
7
- import {
8
- EventIngress,
9
- MemoryEventRepository,
10
- type CanonicalEvent,
11
- } from '../../../framework/events/index.js';
12
- import type { RuntimeReadyView } from '../../../framework/runtime.js';
13
- import {
14
- AGENT_MAILBOX_COALESCE_MS,
15
- AgentMailboxCoordinator,
16
- } from './agent-mailbox-coordinator.js';
17
- import {
18
- DESKTOP_EVENT_PROTOCOL_SCHEMA,
19
- DesktopEventSocketSink,
20
- } from './desktop-event-socket.js';
21
- import {
22
- ClawclawMailboxPlugin,
23
- CompositeClawclawMailboxDriver,
24
- } from './mailbox-plugin.js';
25
- import { MailboxEventBatchPump } from './mailbox-event-batch-delivery.js';
26
-
27
- interface ReceivedFrame {
28
- atMs: number;
29
- frame: Record<string, any>;
30
- socket: Socket;
31
- }
32
-
33
- const servers: Server[] = [];
34
- const serverSockets: Socket[] = [];
35
-
36
- async function closeServer(server: Server): Promise<void> {
37
- if (!server.listening) return;
38
- await new Promise<void>((resolve, reject) => {
39
- server.close((error) => error ? reject(error) : resolve());
40
- });
41
- }
42
-
43
- afterEach(async () => {
44
- for (const socket of serverSockets.splice(0)) socket.destroy();
45
- await Promise.all(servers.splice(0).map((server) => closeServer(server)));
46
- });
47
-
48
- function delay(milliseconds: number): Promise<void> {
49
- return new Promise((resolve) => setTimeout(resolve, milliseconds));
50
- }
51
-
52
- function readyView(epochSeq: number, eventWatermark: number): RuntimeReadyView {
53
- const scope = {
54
- adapterId: 'clawclaw',
55
- accountId: 'account-1',
56
- sessionId: 'session-1',
57
- segmentId: 'game-1',
58
- segmentSeq: 1,
59
- };
60
- return {
61
- scope,
62
- state: {
63
- state: {
64
- phase: 'wandering',
65
- tick: epochSeq,
66
- you: { name: 'self', seat: 1, alive: true },
67
- },
68
- stateStatus: {
69
- status: 'fresh',
70
- semantics: 'latest_received',
71
- source: 'owner_memory',
72
- scope,
73
- connectionId: 'connection-1',
74
- connectionState: 'connected',
75
- receivedAtMs: Date.now(),
76
- ageMs: 0,
77
- backendTick: epochSeq,
78
- reason: null,
79
- },
80
- },
81
- pluginStates: {},
82
- pluginOutcomes: {},
83
- events: [],
84
- throughCommitSeq: eventWatermark,
85
- frameSeq: epochSeq,
86
- eventWatermark,
87
- epochSeq,
88
- hasMore: false,
89
- };
90
- }
91
-
92
- async function publish(
93
- ingress: EventIngress,
94
- input: {
95
- eventId: string;
96
- type: string;
97
- epochSeq: number;
98
- producer?: 'backend_push' | 'local_synth';
99
- payload?: Record<string, unknown>;
100
- },
101
- ): Promise<CanonicalEvent> {
102
- return (await ingress.publish({
103
- epochSeq: input.epochSeq,
104
- eventId: input.eventId,
105
- type: input.type,
106
- producer: input.producer ?? 'backend_push',
107
- sessionId: 'session-1',
108
- segmentId: 'game-1',
109
- payload: input.payload ?? {},
110
- source: { sourceId: 'test', eventId: `remote:${input.eventId}` },
111
- })).event;
112
- }
113
-
114
- function sendAck(
115
- received: ReceivedFrame,
116
- overrides: Partial<Record<'connection_id' | 'seq' | 'delivery_id', unknown>> = {},
117
- ): void {
118
- const frame = received.frame;
119
- received.socket.write(`${JSON.stringify({
120
- schema: DESKTOP_EVENT_PROTOCOL_SCHEMA,
121
- type: 'ack',
122
- connection_id: frame.connection_id,
123
- seq: frame.seq,
124
- delivery_id: frame.delivery_id,
125
- receipt_id: `wake-${frame.seq}`,
126
- ...overrides,
127
- })}\n`);
128
- }
129
-
130
- describe('Desktop Agent event push integration', () => {
131
- it('pushes sanitized ready visible Events and retries one durable batch until exact ACK', async () => {
132
- const pipeName = `ccl-desktop-integration-${randomUUID()}`;
133
- const socketPath = process.platform === 'win32'
134
- ? `\\\\.\\pipe\\${pipeName}`
135
- : `/tmp/${pipeName}.sock`;
136
- const received: ReceivedFrame[] = [];
137
- let disconnectNextBatch = false;
138
- const server = createServer((socket) => {
139
- serverSockets.push(socket);
140
- socket.setEncoding('utf8');
141
- let buffer = '';
142
- socket.on('data', (chunk: string) => {
143
- buffer += chunk;
144
- for (;;) {
145
- const newline = buffer.indexOf('\n');
146
- if (newline < 0) break;
147
- const line = buffer.slice(0, newline);
148
- buffer = buffer.slice(newline + 1);
149
- if (!line.trim()) continue;
150
- const frame = JSON.parse(line) as Record<string, any>;
151
- received.push({ atMs: Date.now(), frame, socket });
152
- if (frame.type === 'mailbox_batch' && disconnectNextBatch) {
153
- disconnectNextBatch = false;
154
- socket.destroy();
155
- }
156
- }
157
- });
158
- });
159
- servers.push(server);
160
- await new Promise<void>((resolve, reject) => {
161
- server.once('error', reject);
162
- server.listen(socketPath, resolve);
163
- });
164
-
165
- const repository = new MemoryEventRepository();
166
- repository.saveSession({
167
- sessionId: 'session-1',
168
- adapterId: 'clawclaw',
169
- accountId: 'account-1',
170
- status: 'open',
171
- isCurrent: true,
172
- openedAt: '2026-08-04T00:00:00.000Z',
173
- });
174
- repository.saveSegment({
175
- segmentId: 'game-1',
176
- sessionId: 'session-1',
177
- sequence: 1,
178
- kind: 'game',
179
- status: 'open',
180
- isCurrent: true,
181
- openedAt: '2026-08-04T00:00:00.000Z',
182
- });
183
- const ingress = new EventIngress(repository, createClawclawEventCatalog());
184
- let ready = readyView(1, 0);
185
- const coordinator = new AgentMailboxCoordinator({
186
- repository,
187
- readyView: () => structuredClone(ready),
188
- presentEvent: presentCanonicalEventForDesktop,
189
- compactState: compactStateForEvents,
190
- });
191
- let pump: MailboxEventBatchPump | undefined;
192
- const sink = new DesktopEventSocketSink({
193
- socketPath,
194
- token: '0123456789abcdef0123456789abcdef',
195
- ackTimeoutMs: 2_000,
196
- reconnectBaseMs: 10,
197
- reconnectMaxMs: 20,
198
- onConnected: () => pump?.retryNow(),
199
- activeResources: () => ({
200
- locale: 'zh-CN',
201
- strategy: {
202
- id: 'normal-shrimp',
203
- name: '普通虾',
204
- description: '完成任务并保持警觉。',
205
- },
206
- perceptions: [{
207
- id: 'visual.motion',
208
- name: '玩家移动',
209
- description: '感知自己和可见玩家的连续移动片段及显著方向变化。',
210
- }],
211
- }),
212
- eventDescriptors: () => [{
213
- type: 'visual.player_moved',
214
- perception_id: 'visual.motion',
215
- name: '玩家移动',
216
- description: '玩家持续移动形成一段可观察的移动轨迹。',
217
- }],
218
- });
219
- pump = new MailboxEventBatchPump({
220
- source: {
221
- prepare: () => coordinator.prepareEvents({
222
- deliveryVia: 'mailbox_full',
223
- ownerIdPrefix: 'desktop_ipc_test',
224
- }),
225
- renew: (deliveryToken) => coordinator.renew(deliveryToken),
226
- ack: (deliveryToken) => coordinator.ack(deliveryToken),
227
- release: (deliveryToken) => coordinator.release(deliveryToken),
228
- },
229
- sink,
230
- });
231
- const mailbox = new ClawclawMailboxPlugin();
232
- mailbox.attachDriver(new CompositeClawclawMailboxDriver([coordinator, pump]));
233
- sink.start();
234
-
235
- try {
236
- await vi.waitFor(() => {
237
- expect(received.filter(({ frame }) => frame.type === 'hello')).toHaveLength(1);
238
- });
239
- expect(received.find(({ frame }) => frame.type === 'hello')?.frame.active_resources)
240
- .toMatchObject({
241
- locale: 'zh-CN',
242
- strategy: { id: 'normal-shrimp', name: '普通虾' },
243
- perceptions: [{ id: 'visual.motion', name: '玩家移动' }],
244
- });
245
- expect(await mailbox.update({ pendingEvents: [] } as any)).toMatchObject({
246
- outcome: 'noop',
247
- reason: 'no_pending_events',
248
- });
249
-
250
- const internal = await publish(ingress, {
251
- eventId: 'task-assigned-1',
252
- type: 'task_assigned',
253
- epochSeq: 1,
254
- payload: { task_name: 'repair' },
255
- });
256
- ready = readyView(1, internal.commitSeq);
257
- await mailbox.update({ pendingEvents: [internal] } as any);
258
- await delay(AGENT_MAILBOX_COALESCE_MS + 60);
259
- expect(received.filter(({ frame }) => frame.type === 'mailbox_batch')).toHaveLength(0);
260
-
261
- const joined = await publish(ingress, {
262
- eventId: 'joined-1',
263
- type: 'joined',
264
- epochSeq: 2,
265
- producer: 'local_synth',
266
- payload: {
267
- status: 'matched',
268
- url: 'https://example.test/lobby?token=desktop-secret',
269
- queue: {
270
- status: 'matched',
271
- spectate_url: 'https://example.test/lobby?token=nested-desktop-secret',
272
- },
273
- },
274
- });
275
- const longText = `BEGIN-${'x'.repeat(70 * 1024)}-END`;
276
- const speech = await publish(ingress, {
277
- eventId: 'speech-1',
278
- type: 'speech',
279
- epochSeq: 2,
280
- payload: { actor_name: 'player-2', text: longText },
281
- });
282
- expect(speech.deliveryClass).toBe('monitor_and_events');
283
- ready = readyView(2, speech.commitSeq);
284
- const firstObservedAt = Date.now();
285
- await mailbox.update({ pendingEvents: [joined, speech] } as any);
286
- await delay(100);
287
-
288
- const visual = await publish(ingress, {
289
- eventId: 'visual-1',
290
- type: 'visual.player_moved',
291
- epochSeq: 3,
292
- producer: 'local_synth',
293
- payload: { text: 'player-2 moved through engine' },
294
- });
295
- ready = readyView(3, visual.commitSeq);
296
- await mailbox.update({ pendingEvents: [visual] } as any);
297
- expect(received.filter(({ frame }) => frame.type === 'mailbox_batch')).toHaveLength(0);
298
-
299
- await vi.waitFor(() => {
300
- expect(received.filter(({ frame }) => frame.type === 'mailbox_batch')).toHaveLength(1);
301
- }, { timeout: 2_000 });
302
- const firstBatch = received.find(({ frame }) => frame.type === 'mailbox_batch')!;
303
- expect(firstBatch.atMs - firstObservedAt).toBeGreaterThanOrEqual(
304
- AGENT_MAILBOX_COALESCE_MS - 20,
305
- );
306
- expect(firstBatch.frame.payload).toMatchObject({
307
- schema: 'clawclaw.channel-events.v1',
308
- state: { phase: 'wandering', tick: 3 },
309
- });
310
- expect(firstBatch.frame.active_resources).toMatchObject({
311
- locale: 'zh-CN',
312
- strategy: { id: 'normal-shrimp', name: '普通虾' },
313
- perceptions: [{ id: 'visual.motion', name: '玩家移动' }],
314
- });
315
- expect(firstBatch.frame.event_descriptors).toEqual([{
316
- type: 'visual.player_moved',
317
- perception_id: 'visual.motion',
318
- name: '玩家移动',
319
- description: '玩家持续移动形成一段可观察的移动轨迹。',
320
- }]);
321
- expect(firstBatch.frame.payload.events).toEqual([
322
- 'visual.player_moved | player-2 moved through engine',
323
- expect.objectContaining({ type: 'speech', text: longText }),
324
- expect.objectContaining({
325
- type: 'joined',
326
- status: 'matched',
327
- hint: 'The game runtime is attached; do not start a duplicate runtime.',
328
- }),
329
- ]);
330
- expect(JSON.stringify(firstBatch.frame.payload)).not.toContain('desktop-secret');
331
- expect(JSON.stringify(firstBatch.frame.payload)).not.toMatch(/spectate_url/iu);
332
- expect(JSON.stringify(firstBatch.frame.payload)).not.toMatch(/Share this Event/iu);
333
- expect(Buffer.byteLength(JSON.stringify(firstBatch.frame.payload), 'utf8'))
334
- .toBeGreaterThan(64 * 1024);
335
- expect(JSON.stringify(firstBatch.frame.payload)).not.toContain('task_assigned');
336
-
337
- sendAck(firstBatch, { seq: firstBatch.frame.seq + 1 });
338
- await delay(40);
339
- expect(repository.delivery(speech.eventId, 'local-agent')?.detailState).toBe('pending');
340
- sendAck(firstBatch);
341
- await vi.waitFor(() => {
342
- expect(repository.delivery(speech.eventId, 'local-agent')).toMatchObject({
343
- detailState: 'delivered',
344
- detailDeliveryVia: 'mailbox_full',
345
- });
346
- });
347
- await delay(300);
348
- expect(received.filter(({ frame }) => frame.type === 'mailbox_batch')).toHaveLength(1);
349
-
350
- const boundaryEvent = await publish(ingress, {
351
- eventId: 'speech-boundary',
352
- type: 'speech',
353
- epochSeq: 4,
354
- payload: { actor_name: 'player-3', text: 'held behind ReadyView' },
355
- });
356
- const previousReady = ready;
357
- disconnectNextBatch = true;
358
- await mailbox.update({ pendingEvents: [boundaryEvent] } as any);
359
- await delay(AGENT_MAILBOX_COALESCE_MS + 80);
360
- expect(ready).toBe(previousReady);
361
- expect(received.filter(({ frame }) => frame.type === 'mailbox_batch')).toHaveLength(1);
362
-
363
- ready = readyView(4, boundaryEvent.commitSeq);
364
- await vi.waitFor(() => {
365
- expect(received.filter(({ frame }) => frame.type === 'mailbox_batch').length)
366
- .toBeGreaterThanOrEqual(2);
367
- }, { timeout: 2_000 });
368
- await vi.waitFor(() => {
369
- expect(received.filter(({ frame }) => frame.type === 'hello')).toHaveLength(2);
370
- }, { timeout: 2_000 });
371
- await vi.waitFor(() => {
372
- expect(received.filter(({ frame }) => frame.type === 'mailbox_batch')).toHaveLength(3);
373
- }, { timeout: 2_000 });
374
-
375
- const retries = received
376
- .filter(({ frame }) => frame.type === 'mailbox_batch')
377
- .slice(1);
378
- expect(retries).toHaveLength(2);
379
- expect(retries[0].frame.delivery_id).toBe(retries[1].frame.delivery_id);
380
- expect(retries[0].frame.connection_id).not.toBe(retries[1].frame.connection_id);
381
- expect(repository.delivery(boundaryEvent.eventId, 'local-agent')?.detailState)
382
- .toBe('pending');
383
-
384
- sendAck(retries[1]);
385
- await vi.waitFor(() => {
386
- expect(repository.delivery(boundaryEvent.eventId, 'local-agent')).toMatchObject({
387
- detailState: 'delivered',
388
- detailDeliveryVia: 'mailbox_full',
389
- });
390
- });
391
- await delay(300);
392
- expect(received.filter(({ frame }) => frame.type === 'mailbox_batch')).toHaveLength(3);
393
- } finally {
394
- await mailbox.stop('shutdown');
395
- }
396
- }, 10_000);
397
- });
@@ -1,270 +0,0 @@
1
- import { randomUUID } from 'node:crypto';
2
- import { createServer, type Server, type Socket } from 'node:net';
3
- import { afterEach, describe, expect, it, vi } from 'vitest';
4
- import {
5
- DESKTOP_EVENT_PROTOCOL_SCHEMA,
6
- DesktopEventSocketSink,
7
- normalizeDesktopEventSocketPath,
8
- validateDesktopEventToken,
9
- } from './desktop-event-socket.js';
10
-
11
- const servers: Server[] = [];
12
-
13
- async function closeServer(server: Server): Promise<void> {
14
- if (!server.listening) return;
15
- await new Promise<void>((resolve, reject) => {
16
- server.close((error) => error ? reject(error) : resolve());
17
- });
18
- }
19
-
20
- afterEach(async () => {
21
- await Promise.all(servers.splice(0).map((server) => closeServer(server)));
22
- });
23
-
24
- describe('DesktopEventSocketSink', () => {
25
- it('normalizes only local IPC endpoints and validates the nonce', () => {
26
- expect(normalizeDesktopEventSocketPath('clawclaw-desktop', 'win32'))
27
- .toBe('\\\\.\\pipe\\clawclaw-desktop');
28
- expect(normalizeDesktopEventSocketPath('\\\\.\\pipe\\clawclaw-desktop', 'win32'))
29
- .toBe('\\\\.\\pipe\\clawclaw-desktop');
30
- expect(() => normalizeDesktopEventSocketPath('\\\\remote\\pipe\\event', 'win32'))
31
- .toThrow('local named pipe');
32
- expect(normalizeDesktopEventSocketPath('/tmp/clawclaw.sock', 'linux'))
33
- .toBe('/tmp/clawclaw.sock');
34
- expect(() => normalizeDesktopEventSocketPath('relative.sock', 'linux'))
35
- .toThrow('absolute Unix socket');
36
- expect(validateDesktopEventToken('0123456789abcdef')).toBe('0123456789abcdef');
37
- expect(() => validateDesktopEventToken('short')).toThrow('at least 16');
38
- });
39
-
40
- it('reuses one connection and resolves only a matching application ACK', async () => {
41
- const pipeName = `ccl-desktop-test-${randomUUID()}`;
42
- const socketPath = process.platform === 'win32'
43
- ? `\\\\.\\pipe\\${pipeName}`
44
- : `/tmp/${pipeName}.sock`;
45
- const frames: Array<Record<string, any>> = [];
46
- const connections: Socket[] = [];
47
- const server = createServer((socket) => {
48
- connections.push(socket);
49
- socket.setEncoding('utf8');
50
- let buffer = '';
51
- socket.on('data', (chunk: string) => {
52
- buffer += chunk;
53
- for (;;) {
54
- const newline = buffer.indexOf('\n');
55
- if (newline < 0) break;
56
- const line = buffer.slice(0, newline);
57
- buffer = buffer.slice(newline + 1);
58
- if (!line.trim()) continue;
59
- const frame = JSON.parse(line) as Record<string, any>;
60
- frames.push(frame);
61
- if (frame.type !== 'mailbox_batch') continue;
62
- socket.write(`${JSON.stringify({
63
- schema: DESKTOP_EVENT_PROTOCOL_SCHEMA,
64
- type: 'ack',
65
- connection_id: frame.connection_id,
66
- seq: frame.seq + 1,
67
- delivery_id: frame.delivery_id,
68
- })}\n`);
69
- const ack = `${JSON.stringify({
70
- schema: DESKTOP_EVENT_PROTOCOL_SCHEMA,
71
- type: 'ack',
72
- connection_id: frame.connection_id,
73
- seq: frame.seq,
74
- delivery_id: frame.delivery_id,
75
- receipt_id: `wake-${frame.seq}`,
76
- })}\n`;
77
- socket.write(ack.slice(0, 7));
78
- socket.write(ack.slice(7));
79
- }
80
- });
81
- });
82
- servers.push(server);
83
- await new Promise<void>((resolve, reject) => {
84
- server.once('error', reject);
85
- server.listen(socketPath, resolve);
86
- });
87
-
88
- const activeResources = {
89
- locale: 'zh-CN',
90
- strategy: null,
91
- perceptions: [{
92
- id: 'visual.motion',
93
- name: '玩家移动',
94
- description: '感知自己和可见玩家的连续移动片段及显著方向变化。',
95
- }],
96
- } as const;
97
- const eventDescriptors = [{
98
- type: 'visual.player_moved',
99
- perception_id: 'visual.motion',
100
- name: '玩家移动',
101
- description: '玩家持续移动形成一段可观察的移动轨迹。',
102
- }] as const;
103
- const sink = new DesktopEventSocketSink({
104
- socketPath,
105
- token: '0123456789abcdef0123456789abcdef',
106
- reconnectBaseMs: 10,
107
- reconnectMaxMs: 20,
108
- activeResources: () => activeResources,
109
- eventDescriptors: () => eventDescriptors,
110
- });
111
- sink.start();
112
- await vi.waitFor(() => expect(frames[0]).toMatchObject({
113
- schema: DESKTOP_EVENT_PROTOCOL_SCHEMA,
114
- type: 'hello',
115
- token: '0123456789abcdef0123456789abcdef',
116
- pid: process.pid,
117
- active_resources: activeResources,
118
- }));
119
-
120
- const largeText = 'z'.repeat(70 * 1024);
121
- const first = await sink.deliver({
122
- deliveryId: 'delivery-1',
123
- batch: {
124
- state: { phase: 'meeting' },
125
- events: [{ type: 'meeting_briefing', text: largeText }],
126
- },
127
- }, new AbortController().signal);
128
- const second = await sink.deliver({
129
- deliveryId: 'delivery-2',
130
- batch: {
131
- state: { phase: 'wandering' },
132
- events: [
133
- 'visual.player_moved | 1:2,你向右移动。',
134
- 'visual.following | 1:2,玩家2跟随玩家3。',
135
- { type: 'speech_your_turn' },
136
- ],
137
- },
138
- }, new AbortController().signal);
139
-
140
- expect(first.receiptId).toBe('wake-1');
141
- expect(second.receiptId).toBe('wake-2');
142
- expect(connections).toHaveLength(1);
143
- expect(frames.filter((frame) => frame.type === 'mailbox_batch')).toEqual([
144
- expect.objectContaining({
145
- seq: 1,
146
- delivery_id: 'delivery-1',
147
- active_resources: activeResources,
148
- payload: expect.objectContaining({
149
- schema: 'clawclaw.channel-events.v1',
150
- events: [expect.objectContaining({ text: largeText })],
151
- }),
152
- }),
153
- expect.objectContaining({
154
- seq: 2,
155
- delivery_id: 'delivery-2',
156
- event_descriptors: eventDescriptors,
157
- payload: expect.objectContaining({
158
- events: [
159
- 'visual.player_moved | 1:2,你向右移动。',
160
- 'visual.following | 1:2,玩家2跟随玩家3。',
161
- { type: 'speech_your_turn' },
162
- ],
163
- }),
164
- }),
165
- ]);
166
- expect(frames.find((frame) => frame.delivery_id === 'delivery-1'))
167
- .not.toHaveProperty('event_descriptors');
168
-
169
- await sink.close();
170
- });
171
-
172
- it('rejects an unacknowledged batch, reconnects, and permits the durable retry', async () => {
173
- const pipeName = `ccl-desktop-retry-${randomUUID()}`;
174
- const socketPath = process.platform === 'win32'
175
- ? `\\\\.\\pipe\\${pipeName}`
176
- : `/tmp/${pipeName}.sock`;
177
- const hellos: Array<Record<string, any>> = [];
178
- const batches: Array<Record<string, any>> = [];
179
- let connectionNumber = 0;
180
- const server = createServer((socket) => {
181
- connectionNumber += 1;
182
- const currentConnection = connectionNumber;
183
- socket.setEncoding('utf8');
184
- let buffer = '';
185
- socket.on('data', (chunk: string) => {
186
- buffer += chunk;
187
- for (;;) {
188
- const newline = buffer.indexOf('\n');
189
- if (newline < 0) break;
190
- const line = buffer.slice(0, newline);
191
- buffer = buffer.slice(newline + 1);
192
- if (!line.trim()) continue;
193
- const frame = JSON.parse(line) as Record<string, any>;
194
- if (frame.type === 'hello') hellos.push(frame);
195
- if (frame.type !== 'mailbox_batch') continue;
196
- batches.push(frame);
197
- if (currentConnection === 1) {
198
- socket.destroy();
199
- continue;
200
- }
201
- socket.write(`${JSON.stringify({
202
- schema: DESKTOP_EVENT_PROTOCOL_SCHEMA,
203
- type: 'ack',
204
- connection_id: frame.connection_id,
205
- seq: frame.seq,
206
- delivery_id: frame.delivery_id,
207
- })}\n`);
208
- }
209
- });
210
- });
211
- servers.push(server);
212
- await new Promise<void>((resolve, reject) => {
213
- server.once('error', reject);
214
- server.listen(socketPath, resolve);
215
- });
216
-
217
- let strategy = {
218
- id: 'strategy-a',
219
- name: '策略甲',
220
- description: '策略甲描述。',
221
- };
222
- let eventName = '旧玩家移动';
223
- const sink = new DesktopEventSocketSink({
224
- socketPath,
225
- token: '0123456789abcdef0123456789abcdef',
226
- reconnectBaseMs: 10,
227
- reconnectMaxMs: 20,
228
- activeResources: () => ({ locale: 'zh-CN', strategy, perceptions: [] }),
229
- eventDescriptors: () => [{
230
- type: 'visual.player_moved',
231
- perception_id: 'visual.motion',
232
- name: eventName,
233
- description: '重试快照测试。',
234
- }],
235
- });
236
- sink.start();
237
- await vi.waitFor(() => expect(hellos).toHaveLength(1));
238
- const envelope = {
239
- deliveryId: 'durable-delivery',
240
- batch: {
241
- state: null,
242
- events: ['visual.player_moved | 测试移动。'],
243
- },
244
- };
245
-
246
- await expect(sink.deliver(envelope, new AbortController().signal)).rejects.toMatchObject({
247
- code: 'desktop_event_socket_disconnected',
248
- retryable: true,
249
- });
250
- strategy = {
251
- id: 'strategy-b',
252
- name: '策略乙',
253
- description: '策略乙描述。',
254
- };
255
- eventName = '新事件名称';
256
- await vi.waitFor(() => expect(hellos).toHaveLength(2));
257
- await expect(sink.deliver(envelope, new AbortController().signal)).resolves.toMatchObject({
258
- acceptedAt: expect.any(String),
259
- });
260
- expect(hellos[1].connection_id).not.toBe(hellos[0].connection_id);
261
- expect(hellos[1].active_resources.strategy.id).toBe('strategy-b');
262
- expect(batches).toHaveLength(2);
263
- expect(batches[0].active_resources.strategy.id).toBe('strategy-a');
264
- expect(batches[1].active_resources.strategy.id).toBe('strategy-a');
265
- expect(batches[0].event_descriptors[0].name).toBe('旧玩家移动');
266
- expect(batches[1].event_descriptors[0].name).toBe('旧玩家移动');
267
-
268
- await sink.close();
269
- });
270
- });