@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,250 +0,0 @@
1
- // src/lib/game-client.test.ts
2
- import { describe, it, expect, vi, afterEach } from 'vitest';
3
- import { GameClient } from './game-client.js';
4
-
5
- afterEach(() => { vi.restoreAllMocks(); });
6
-
7
- function makeClient(): GameClient {
8
- return new GameClient({ lobbyUrl: 'https://lobby.example', apiKey: 'key' });
9
- }
10
-
11
- describe('GameClient.joinQueue X-Agent-Type', () => {
12
- it('sends X-Agent-Type header when agentType is provided', async () => {
13
- let captured: any;
14
- vi.stubGlobal('fetch', vi.fn(async (url: string, init: any) => {
15
- captured = { url, headers: init.headers, body: init.body };
16
- return new Response('{"status":"queued"}', { status: 200 });
17
- }));
18
- await makeClient().joinQueue({ gameType: 'clawclaw', mode: 'competition', agentType: 'claude-code' });
19
- expect(captured.url).toBe('https://lobby.example/api/v1/queue/join');
20
- expect(captured.headers['X-Agent-Type']).toBe('claude-code');
21
- // mode still travels in the request body, not the header
22
- expect(JSON.parse(captured.body)).toEqual({ game_type: 'clawclaw', mode: 'competition' });
23
- });
24
-
25
- it('omits X-Agent-Type header when agentType is absent', async () => {
26
- let captured: any;
27
- vi.stubGlobal('fetch', vi.fn(async (_url: string, init: any) => {
28
- captured = init.headers;
29
- return new Response('{"status":"queued"}', { status: 200 });
30
- }));
31
- await makeClient().joinQueue({ gameType: 'clawclaw', mode: 'match' });
32
- expect('X-Agent-Type' in captured).toBe(false);
33
- });
34
-
35
- it('omits X-Agent-Type for the legacy string form', async () => {
36
- let captured: any;
37
- vi.stubGlobal('fetch', vi.fn(async (_url: string, init: any) => {
38
- captured = init.headers;
39
- return new Response('{"status":"queued"}', { status: 200 });
40
- }));
41
- await makeClient().joinQueue('clawclaw');
42
- expect('X-Agent-Type' in captured).toBe(false);
43
- });
44
- });
45
-
46
- describe('GameClient.joinQueue X-LLM-Model', () => {
47
- it('sends X-LLM-Model when provided', async () => {
48
- let captured: any;
49
- vi.stubGlobal('fetch', vi.fn(async (url: string, init: any) => {
50
- captured = { url, headers: init.headers, body: init.body };
51
- return new Response('{"status":"queued"}', { status: 200 });
52
- }));
53
- await makeClient().joinQueue({ gameType: 'clawclaw', agentType: 'claude-code', llmModel: 'claude-opus-4-8' });
54
- expect(captured.headers['X-Agent-Type']).toBe('claude-code');
55
- expect(captured.headers['X-LLM-Model']).toBe('claude-opus-4-8');
56
- // still travels in the request body only, not the headers
57
- expect(JSON.parse(captured.body)).toEqual({ game_type: 'clawclaw', mode: 'match' });
58
- });
59
-
60
- it('omits the header when not provided', async () => {
61
- let captured: any;
62
- vi.stubGlobal('fetch', vi.fn(async (_url: string, init: any) => {
63
- captured = init.headers;
64
- return new Response('{"status":"queued"}', { status: 200 });
65
- }));
66
- await makeClient().joinQueue({ gameType: 'clawclaw', mode: 'match' });
67
- expect('X-LLM-Model' in captured).toBe(false);
68
- });
69
- });
70
-
71
- describe('GameClient room entry metadata', () => {
72
- it('gets the current room status from the lobby', async () => {
73
- let captured: any;
74
- vi.stubGlobal('fetch', vi.fn(async (url: string, init: any) => {
75
- captured = { url, method: init.method };
76
- return new Response('{"success":true,"data":{"room_type":"casual"}}', { status: 200 });
77
- }));
78
-
79
- await makeClient().getRoomStatus();
80
-
81
- expect(captured).toEqual({
82
- url: 'https://lobby.example/api/v1/room/status',
83
- method: 'GET',
84
- });
85
- });
86
-
87
- it('sends agent/model headers while preserving create-room request bodies', async () => {
88
- const calls: Array<{ url: string; headers: Record<string, string>; body?: string }> = [];
89
- vi.stubGlobal('fetch', vi.fn(async (url: string, init: any) => {
90
- calls.push({ url, headers: init.headers, body: init.body });
91
- return new Response('{"success":true}', { status: 200 });
92
- }));
93
- const client = makeClient();
94
-
95
- await client.createRoom({
96
- agentType: 'claude-code',
97
- llmModel: 'claude-opus-4-8',
98
- });
99
- await client.createRoom({
100
- roomType: 'training_simulation',
101
- agentType: 'openclaw',
102
- llmModel: 'deepseek-v4-pro',
103
- });
104
-
105
- expect(calls[0]).toMatchObject({
106
- url: 'https://lobby.example/api/v1/room/create',
107
- headers: {
108
- 'X-Agent-Type': 'claude-code',
109
- 'X-LLM-Model': 'claude-opus-4-8',
110
- },
111
- body: undefined,
112
- });
113
- expect(calls[1]).toMatchObject({
114
- url: 'https://lobby.example/api/v1/room/create',
115
- headers: {
116
- 'X-Agent-Type': 'openclaw',
117
- 'X-LLM-Model': 'deepseek-v4-pro',
118
- },
119
- body: JSON.stringify({ room_type: 'training_simulation' }),
120
- });
121
- });
122
-
123
- it('sends agent/model headers when joining a room', async () => {
124
- let captured: any;
125
- vi.stubGlobal('fetch', vi.fn(async (url: string, init: any) => {
126
- captured = { url, headers: init.headers, body: init.body };
127
- return new Response('{"success":true}', { status: 200 });
128
- }));
129
-
130
- await makeClient().joinRoom('123456', {
131
- agentType: 'claude-code',
132
- llmModel: 'claude-opus-4-8',
133
- });
134
-
135
- expect(captured).toMatchObject({
136
- url: 'https://lobby.example/api/v1/room/join',
137
- headers: {
138
- 'X-Agent-Type': 'claude-code',
139
- 'X-LLM-Model': 'claude-opus-4-8',
140
- },
141
- body: JSON.stringify({ room_code: '123456' }),
142
- });
143
- });
144
- });
145
-
146
- describe('GameClient GameSync resume ownership', () => {
147
- const resumeState = {
148
- gameId: 'G1',
149
- seq: 12,
150
- tick: 120,
151
- locale: 'zh-CN' as const,
152
- state: { phase: 'wandering', you: { x: 10, y: 20 } },
153
- };
154
-
155
- it('keeps a same-game baseline across reconcile and drops it on a game-id change', () => {
156
- const client = makeClient() as any;
157
- client.gameSyncResumeState = structuredClone(resumeState);
158
-
159
- client.setExpectedGameSyncGameId('G1');
160
- client.disconnectWs({ preserveGameSyncResumeState: true });
161
- expect(client.gameSyncResumeState).toEqual(resumeState);
162
- expect(client.expectedGameSyncGameId).toBe('G1');
163
-
164
- client.setExpectedGameSyncGameId('G2');
165
- expect(client.gameSyncResumeState).toBeUndefined();
166
- expect(client.expectedGameSyncGameId).toBe('G2');
167
- });
168
-
169
- it('clears both baseline and identity on a terminal disconnect', () => {
170
- const client = makeClient() as any;
171
- client.gameSyncResumeState = structuredClone(resumeState);
172
- client.setExpectedGameSyncGameId('G1');
173
-
174
- client.disconnectWs();
175
-
176
- expect(client.gameSyncResumeState).toBeUndefined();
177
- expect(client.expectedGameSyncGameId).toBeUndefined();
178
- });
179
-
180
- it('proxies a Source commit to WsClient and retains only that committed baseline', () => {
181
- const client = makeClient() as any;
182
- const acknowledge = vi.fn();
183
- client.setExpectedGameSyncGameId('G1');
184
- client.ws = {
185
- acknowledge,
186
- resumeState,
187
- };
188
-
189
- client.acknowledgeGameSync('frame-token', true);
190
-
191
- expect(acknowledge).toHaveBeenCalledWith('frame-token', true);
192
- expect(client.gameSyncResumeState).toEqual(resumeState);
193
- });
194
- });
195
-
196
- describe('GameClient training room API', () => {
197
- it('sends the exact room type when creating training and keeps casual create bodyless', async () => {
198
- const calls: Array<{ url: string; method: string; body?: string }> = [];
199
- vi.stubGlobal('fetch', vi.fn(async (url: string, init: RequestInit) => {
200
- calls.push({ url, method: String(init.method), body: init.body as string | undefined });
201
- return new Response('{"success":true}', { status: 200 });
202
- }));
203
- const client = makeClient();
204
-
205
- await client.createRoom('training_simulation');
206
- await client.createRoom();
207
-
208
- expect(calls[0]).toEqual({
209
- url: 'https://lobby.example/api/v1/room/create',
210
- method: 'POST',
211
- body: JSON.stringify({ room_type: 'training_simulation' }),
212
- });
213
- expect(calls[1]).toEqual({
214
- url: 'https://lobby.example/api/v1/room/create',
215
- method: 'POST',
216
- body: undefined,
217
- });
218
- });
219
-
220
- it('uses PUT/DELETE for training mode and role lock configuration', async () => {
221
- const calls: Array<{ url: string; method: string; body?: string }> = [];
222
- vi.stubGlobal('fetch', vi.fn(async (url: string, init: RequestInit) => {
223
- calls.push({ url, method: String(init.method), body: init.body as string | undefined });
224
- return new Response('{"success":true}', { status: 200 });
225
- }));
226
- const client = makeClient();
227
-
228
- await client.setTrainingRoomMode('training_dummy');
229
- await client.setTrainingRoleLock(7);
230
- await client.clearTrainingRoleLock();
231
-
232
- expect(calls).toEqual([
233
- {
234
- url: 'https://lobby.example/api/v1/room/training/mode',
235
- method: 'PUT',
236
- body: JSON.stringify({ room_type: 'training_dummy' }),
237
- },
238
- {
239
- url: 'https://lobby.example/api/v1/room/training/role-lock',
240
- method: 'PUT',
241
- body: JSON.stringify({ character_id: 7 }),
242
- },
243
- {
244
- url: 'https://lobby.example/api/v1/room/training/role-lock',
245
- method: 'DELETE',
246
- body: undefined,
247
- },
248
- ]);
249
- });
250
- });
@@ -1,301 +0,0 @@
1
- import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
2
- import { tmpdir } from 'node:os';
3
- import { join } from 'node:path';
4
- import { afterEach, describe, expect, it } from 'vitest';
5
- import {
6
- CLAWCLAW_ROLE_IDS,
7
- DEFAULT_BEHAVIOR_IDLE_MS,
8
- NPM_ROLE_FALLBACK_BEHAVIORS,
9
- defaultGameplayConfig,
10
- parseGameplayConfig,
11
- readGameplayConfig,
12
- updateGameplayConfig,
13
- } from './gameplay-config.js';
14
- import { getUserDataGameplayConfigFile } from './user-data.js';
15
-
16
- const dirs: string[] = [];
17
- const UNIFIED_FIELDS = [
18
- 'disabled_perception_modules',
19
- 'fallback_behaviors',
20
- 'disabled_behaviors',
21
- 'idle_ms',
22
- 'triggers',
23
- ];
24
-
25
- afterEach(() => {
26
- for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true });
27
- });
28
-
29
- function workspace(): string {
30
- const dir = mkdtempSync(join(tmpdir(), 'ccl-gameplay-config-'));
31
- dirs.push(dir);
32
- return dir;
33
- }
34
-
35
- function writeExistingConfig(dir: string, value: unknown): string {
36
- readGameplayConfig(dir);
37
- const path = getUserDataGameplayConfigFile(dir);
38
- writeFileSync(path, JSON.stringify(value, null, 2), 'utf8');
39
- return path;
40
- }
41
-
42
- function legacyDefaults(): Record<string, string | null> {
43
- return { ...NPM_ROLE_FALLBACK_BEHAVIORS };
44
- }
45
-
46
- function legacyConfig(fallbackIdleMs: unknown = 8_000): Record<string, unknown> {
47
- return {
48
- default_strategies: legacyDefaults(),
49
- disabled_strategies: ['runtime-task-demo'],
50
- disabled_perception_modules: [],
51
- disabled_intents: [],
52
- fallback_idle_ms: fallbackIdleMs,
53
- };
54
- }
55
-
56
- describe('gameplay config', () => {
57
- it('creates only the unified public fields with a 500ms default idle timeout', () => {
58
- const dir = workspace();
59
- const config = readGameplayConfig(dir);
60
-
61
- expect(Object.keys(config)).toEqual(UNIFIED_FIELDS);
62
- expect(config).toEqual({
63
- disabled_perception_modules: [],
64
- fallback_behaviors: NPM_ROLE_FALLBACK_BEHAVIORS,
65
- disabled_behaviors: [],
66
- idle_ms: DEFAULT_BEHAVIOR_IDLE_MS,
67
- triggers: {},
68
- });
69
- expect(Object.keys(config.fallback_behaviors)).toEqual(CLAWCLAW_ROLE_IDS);
70
- expect(existsSync(getUserDataGameplayConfigFile(dir))).toBe(true);
71
- expect(Object.keys(JSON.parse(
72
- readFileSync(getUserDataGameplayConfigFile(dir), 'utf8'),
73
- ))).toEqual(UNIFIED_FIELDS);
74
- });
75
-
76
- it('accepts only complete unified public config objects', () => {
77
- const base = defaultGameplayConfig();
78
- const missing = { ...base } as Record<string, unknown>;
79
- delete missing.triggers;
80
-
81
- expect(() => parseGameplayConfig({ ...base, default_strategies: legacyDefaults() }))
82
- .toThrow('contains unknown fields: default_strategies');
83
- expect(() => parseGameplayConfig({ ...base, surprise: true }))
84
- .toThrow('contains unknown fields: surprise');
85
- expect(() => parseGameplayConfig(missing))
86
- .toThrow('triggers must be an object');
87
- expect(() => parseGameplayConfig({ ...base, disabled_perception_modules: null }))
88
- .toThrow('disabled_perception_modules must be an array');
89
- expect(() => parseGameplayConfig({ ...base, fallback_behaviors: null }))
90
- .toThrow('fallback_behaviors must be an object');
91
- expect(() => parseGameplayConfig({ ...base, disabled_behaviors: null }))
92
- .toThrow('disabled_behaviors must be an array');
93
- expect(() => parseGameplayConfig({ ...base, idle_ms: null }))
94
- .toThrow('idle_ms must be an integer from 0 to 60000');
95
- expect(() => parseGameplayConfig({ ...base, triggers: null }))
96
- .toThrow('triggers must be an object');
97
- });
98
-
99
- it('requires exactly every role and a Behavior id or null for each fallback', () => {
100
- const base = defaultGameplayConfig();
101
- const missingRole = { ...base.fallback_behaviors } as Record<string, unknown>;
102
- delete missingRole.shrimp_generic;
103
- const inheritedRole = Object.assign(
104
- Object.create({ shrimp_generic: 'task-report' }) as Record<string, unknown>,
105
- missingRole,
106
- );
107
-
108
- expect(() => parseGameplayConfig({ ...base, fallback_behaviors: missingRole }))
109
- .toThrow('fallback_behaviors.shrimp_generic');
110
- expect(() => parseGameplayConfig({ ...base, fallback_behaviors: inheritedRole }))
111
- .toThrow('fallback_behaviors must be an object');
112
- expect(() => parseGameplayConfig({
113
- ...base,
114
- fallback_behaviors: { ...base.fallback_behaviors, extra_role: 'task-report' },
115
- })).toThrow('Unknown role in user-data/gameplay.json fallback_behaviors: extra_role');
116
- expect(() => parseGameplayConfig({
117
- ...base,
118
- fallback_behaviors: { ...base.fallback_behaviors, shrimp_generic: false },
119
- })).toThrow('fallback_behaviors.shrimp_generic');
120
- expect(parseGameplayConfig({
121
- ...base,
122
- fallback_behaviors: { ...base.fallback_behaviors, shrimp_generic: null },
123
- }).fallback_behaviors.shrimp_generic).toBeNull();
124
- });
125
-
126
- it.each([-1, 60_001, 500.5, '500'])('rejects invalid unified idle value %j', (value) => {
127
- const base = defaultGameplayConfig();
128
- expect(() => parseGameplayConfig({ ...base, idle_ms: value })).toThrow(
129
- 'idle_ms must be an integer from 0 to 60000',
130
- );
131
- });
132
-
133
- it('migrates a legacy file once and immediately removes all legacy fields', () => {
134
- const dir = workspace();
135
- const defaults = legacyDefaults();
136
- defaults.shrimp_generic = 'custom-shrimp';
137
- const path = writeExistingConfig(dir, {
138
- default_strategies: defaults,
139
- disabled_strategies: ['runtime-task-demo', 'custom.long', 'custom.long'],
140
- disabled_perception_modules: ['visual.removed'],
141
- disabled_intents: ['go_to', 'go_to'],
142
- fallback_idle_ms: 8_000,
143
- });
144
-
145
- const config = readGameplayConfig(dir);
146
- const persisted = JSON.parse(readFileSync(path, 'utf8'));
147
-
148
- expect(config.fallback_behaviors.shrimp_generic).toBe('custom-shrimp');
149
- expect(config.disabled_perception_modules).toEqual(['visual.removed']);
150
- expect(config.disabled_behaviors).toEqual(['custom.long', 'go_to']);
151
- expect(config.idle_ms).toBe(500);
152
- expect(config.triggers).toEqual({});
153
- expect(Object.keys(config)).toEqual(UNIFIED_FIELDS);
154
- expect(Object.keys(persisted)).toEqual(UNIFIED_FIELDS);
155
- expect(persisted).toEqual(config);
156
- });
157
-
158
- it('gives unified values precedence while merging legacy disabled ids', () => {
159
- const dir = workspace();
160
- const fallbackBehaviors = {
161
- ...NPM_ROLE_FALLBACK_BEHAVIORS,
162
- shrimp_generic: null,
163
- };
164
- const oldDefaults = legacyDefaults();
165
- oldDefaults.shrimp_generic = 'old-shrimp';
166
- writeExistingConfig(dir, {
167
- disabled_perception_modules: ['visual.current'],
168
- fallback_behaviors: fallbackBehaviors,
169
- disabled_behaviors: ['unified.behavior', 'shared.behavior'],
170
- idle_ms: 750,
171
- triggers: {
172
- 'danger.followed': {
173
- enabled: true,
174
- behavior: 'evade',
175
- reflex_priority: 20,
176
- },
177
- },
178
- default_strategies: oldDefaults,
179
- disabled_strategies: ['runtime-task-demo', 'legacy.strategy', 'shared.behavior'],
180
- disabled_intents: ['legacy.intent', 'shared.behavior'],
181
- fallback_idle_ms: 10_000,
182
- });
183
-
184
- const config = readGameplayConfig(dir);
185
-
186
- expect(config.fallback_behaviors.shrimp_generic).toBeNull();
187
- expect(config.disabled_behaviors).toEqual([
188
- 'unified.behavior',
189
- 'shared.behavior',
190
- 'legacy.strategy',
191
- 'legacy.intent',
192
- ]);
193
- expect(config.idle_ms).toBe(750);
194
- expect(config.triggers['danger.followed']).toEqual({
195
- enabled: true,
196
- behavior: 'evade',
197
- reflex_priority: 20,
198
- });
199
- });
200
-
201
- it('maps the legacy runtime fallback sentinel to official Behavior fallbacks', () => {
202
- const dir = workspace();
203
- writeExistingConfig(dir, {
204
- ...legacyConfig(),
205
- default_strategies: Object.fromEntries(
206
- CLAWCLAW_ROLE_IDS.map((role) => [role, 'runtime-task-demo']),
207
- ),
208
- });
209
-
210
- expect(readGameplayConfig(dir).fallback_behaviors)
211
- .toEqual(NPM_ROLE_FALLBACK_BEHAVIORS);
212
- });
213
-
214
- it.each([
215
- [0, 0],
216
- [750, 750],
217
- [8_000, 500],
218
- [10_000, 10_000],
219
- [60_000, 60_000],
220
- ])('migrates legacy fallback idle %i to unified idle %i', (legacyValue, expected) => {
221
- const dir = workspace();
222
- writeExistingConfig(dir, legacyConfig(legacyValue));
223
-
224
- expect(readGameplayConfig(dir).idle_ms).toBe(expected);
225
- });
226
-
227
- it('uses the unified 500ms default when a legacy file omitted its idle field', () => {
228
- const dir = workspace();
229
- const legacy = legacyConfig();
230
- delete legacy.fallback_idle_ms;
231
- writeExistingConfig(dir, legacy);
232
-
233
- expect(readGameplayConfig(dir).idle_ms).toBe(500);
234
- });
235
-
236
- it.each([-1, 60_001, 500.5, '8000', null])(
237
- 'rejects invalid legacy fallback idle value %j',
238
- (value) => {
239
- const dir = workspace();
240
- writeExistingConfig(dir, legacyConfig(value));
241
-
242
- expect(() => readGameplayConfig(dir)).toThrow(
243
- 'fallback_idle_ms must be an integer from 0 to 60000',
244
- );
245
- },
246
- );
247
-
248
- it('rejects unknown fields even while migrating a legacy file', () => {
249
- const dir = workspace();
250
- writeExistingConfig(dir, { ...legacyConfig(), surprise: true });
251
-
252
- expect(() => readGameplayConfig(dir)).toThrow('contains unknown fields: surprise');
253
- });
254
-
255
- it('updates and normalizes only unified fields', () => {
256
- const dir = workspace();
257
- const config = updateGameplayConfig((current) => {
258
- current.disabled_perception_modules = ['visual.removed', 'visual.removed'];
259
- current.fallback_behaviors.shrimp_generic = null;
260
- current.disabled_behaviors = ['custom.behavior', 'custom.behavior'];
261
- current.idle_ms = 1_000;
262
- current.triggers = {
263
- 'danger.followed': {
264
- enabled: true,
265
- behavior: 'evade',
266
- cooldown_ms: 250,
267
- },
268
- };
269
- }, dir);
270
-
271
- expect(Object.keys(config)).toEqual(UNIFIED_FIELDS);
272
- expect(config.disabled_perception_modules).toEqual(['visual.removed']);
273
- expect(config.fallback_behaviors.shrimp_generic).toBeNull();
274
- expect(config.disabled_behaviors).toEqual(['custom.behavior']);
275
- expect(config.idle_ms).toBe(1_000);
276
- expect(config.triggers['danger.followed']).toEqual({
277
- enabled: true,
278
- behavior: 'evade',
279
- cooldown_ms: 250,
280
- });
281
- });
282
-
283
- it('reads a complete unified file without rewriting it', () => {
284
- const dir = workspace();
285
- const path = writeExistingConfig(dir, defaultGameplayConfig());
286
- const original = `${JSON.stringify(defaultGameplayConfig(), null, 4)}\n`;
287
- writeFileSync(path, original, 'utf8');
288
-
289
- expect(readGameplayConfig(dir)).toEqual(defaultGameplayConfig());
290
- expect(readFileSync(path, 'utf8')).toBe(original);
291
- });
292
-
293
- it('reports malformed JSON without replacing the file', () => {
294
- const dir = workspace();
295
- const path = writeExistingConfig(dir, defaultGameplayConfig());
296
- writeFileSync(path, '{ bad json', 'utf8');
297
-
298
- expect(() => readGameplayConfig(dir)).toThrow(`Invalid JSON in ${path}`);
299
- expect(readFileSync(path, 'utf8')).toBe('{ bad json');
300
- });
301
- });
@@ -1,130 +0,0 @@
1
- import { mkdtempSync, readFileSync, writeFileSync, existsSync, readdirSync } from 'fs';
2
- import { tmpdir } from 'os';
3
- import { dirname, join } from 'path';
4
- import { describe, expect, it } from 'vitest';
5
- import { runHostConfigSetup, unionArrayField, type HostConfigPatcher } from './host-config-patcher.js';
6
-
7
- function tmpConfig(initial: unknown): string {
8
- const dir = mkdtempSync(join(tmpdir(), 'host-cfg-'));
9
- const p = join(dir, 'config.json');
10
- writeFileSync(p, JSON.stringify(initial, null, 2));
11
- return p;
12
- }
13
-
14
- const dummyHost: HostConfigPatcher<{ value: string }> = {
15
- hostName: 'dummy',
16
- resolveConfigPath: () => '/tmp/never-used',
17
- computePatch: (current, opts) => {
18
- const cur = (current as Record<string, unknown> | null) ?? {};
19
- const before = (cur.values as string[] | undefined) ?? [];
20
- if (before.includes(opts.value)) return { next: cur, changes: [], warnings: [] };
21
- return {
22
- next: { ...cur, values: [...before, opts.value] },
23
- changes: [`add ${opts.value} to values`],
24
- warnings: [],
25
- };
26
- },
27
- };
28
-
29
- describe('runHostConfigSetup', () => {
30
- it('prints recommended patch in --print mode without touching disk', () => {
31
- const r = runHostConfigSetup(dummyHost, { value: 'x' }, { print: true });
32
- expect(r.exitCode).toBe(0);
33
- expect(r.output.join('\n')).toContain('"values"');
34
- });
35
-
36
- it('reports missing config file gracefully', () => {
37
- const r = runHostConfigSetup(dummyHost, { value: 'x' }, { configPath: '/no/such/file.json' });
38
- expect(r.exitCode).toBe(0);
39
- expect(r.output.some((l) => l.includes('not found'))).toBe(true);
40
- });
41
-
42
- it('reports malformed JSON with exit 1', () => {
43
- const dir = mkdtempSync(join(tmpdir(), 'host-cfg-bad-'));
44
- const p = join(dir, 'config.json');
45
- writeFileSync(p, '{ not: valid json');
46
- const r = runHostConfigSetup(dummyHost, { value: 'x' }, { configPath: p });
47
- expect(r.exitCode).toBe(1);
48
- expect(r.output.join('\n')).toMatch(/Failed to parse/);
49
- });
50
-
51
- it('returns exit 2 with diff in dry-run when changes pending', () => {
52
- const p = tmpConfig({ values: ['a'] });
53
- const r = runHostConfigSetup(dummyHost, { value: 'b' }, { configPath: p });
54
- expect(r.exitCode).toBe(2);
55
- const txt = r.output.join('\n');
56
- expect(txt).toMatch(/Pending changes/);
57
- expect(txt).toMatch(/Re-run with -y to apply/);
58
- // file unchanged
59
- expect(JSON.parse(readFileSync(p, 'utf-8'))).toEqual({ values: ['a'] });
60
- });
61
-
62
- it('returns exit 0 no-op when already up to date', () => {
63
- const p = tmpConfig({ values: ['a'] });
64
- const r = runHostConfigSetup(dummyHost, { value: 'a' }, { configPath: p });
65
- expect(r.exitCode).toBe(0);
66
- expect(r.output.join('\n')).toMatch(/already up to date/);
67
- });
68
-
69
- it('applies changes atomically with backup when -y', () => {
70
- const p = tmpConfig({ values: ['a'] });
71
- const r = runHostConfigSetup(dummyHost, { value: 'b' }, { configPath: p, yes: true });
72
- expect(r.exitCode).toBe(0);
73
- expect(JSON.parse(readFileSync(p, 'utf-8'))).toEqual({ values: ['a', 'b'] });
74
- const files = readdirSync(dirname(p));
75
- expect(files.some((f) => f.startsWith('config.json.bak.'))).toBe(true);
76
- });
77
-
78
- it('--no-backup skips backup file', () => {
79
- const p = tmpConfig({ values: ['a'] });
80
- const r = runHostConfigSetup(dummyHost, { value: 'b' }, { configPath: p, yes: true, backup: false });
81
- expect(r.exitCode).toBe(0);
82
- const files = readdirSync(dirname(p));
83
- expect(files.some((f) => f.startsWith('config.json.bak.'))).toBe(false);
84
- });
85
-
86
- it('does not leave .tmp file behind on success', () => {
87
- const p = tmpConfig({ values: ['a'] });
88
- runHostConfigSetup(dummyHost, { value: 'b' }, { configPath: p, yes: true, backup: false });
89
- const files = readdirSync(dirname(p));
90
- expect(files.some((f) => f.includes('.tmp.'))).toBe(false);
91
- });
92
-
93
- it('preserves CRLF line endings when original file uses CRLF', () => {
94
- const dir = mkdtempSync(join(tmpdir(), 'host-cfg-crlf-'));
95
- const p = join(dir, 'config.json');
96
- writeFileSync(p, '{\r\n "values": [\r\n "a"\r\n ]\r\n}\r\n');
97
- runHostConfigSetup(dummyHost, { value: 'b' }, { configPath: p, yes: true, backup: false });
98
- const after = readFileSync(p, 'utf-8');
99
- expect(after.includes('\r\n')).toBe(true);
100
- expect(after.replace(/\r\n/g, '<EOL>').includes('\n')).toBe(false);
101
- });
102
-
103
- it('preserves LF line endings when original file uses LF', () => {
104
- const dir = mkdtempSync(join(tmpdir(), 'host-cfg-lf-'));
105
- const p = join(dir, 'config.json');
106
- writeFileSync(p, '{\n "values": [\n "a"\n ]\n}\n');
107
- runHostConfigSetup(dummyHost, { value: 'b' }, { configPath: p, yes: true, backup: false });
108
- const after = readFileSync(p, 'utf-8');
109
- expect(after.includes('\r\n')).toBe(false);
110
- });
111
- });
112
-
113
- describe('unionArrayField', () => {
114
- it('creates new array when field missing', () => {
115
- expect(unionArrayField(undefined, 'x')).toEqual({ next: ['x'], added: true });
116
- });
117
-
118
- it('returns warning when existing value is not an array', () => {
119
- const r = unionArrayField('not-an-array', 'x');
120
- expect(r).toEqual({ warning: 'existing value is not an array, refusing to overwrite' });
121
- });
122
-
123
- it('returns added=false when entry already present', () => {
124
- expect(unionArrayField(['a', 'b'], 'a')).toEqual({ next: ['a', 'b'], added: false });
125
- });
126
-
127
- it('appends entry when missing from array', () => {
128
- expect(unionArrayField(['a'], 'b')).toEqual({ next: ['a', 'b'], added: true });
129
- });
130
- });