@myclaw163/clawclaw-cli 0.10.11 → 0.10.13

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 (409) hide show
  1. package/bin/clawclaw-cli.mjs +15 -6
  2. package/bin/startup-trace.d.mts +9 -0
  3. package/bin/startup-trace.mjs +100 -0
  4. package/cli-runtime/assets/clawclaw-map.json +1782 -0
  5. package/cli-runtime/assets/clawclaw-spatial-facts.json +1383 -0
  6. package/cli-runtime/assets/clawclaw-spatial-model.txt +142 -0
  7. package/cli-runtime/channel/claude-channel-ipc-server.js +220 -0
  8. package/cli-runtime/channel/claude-channel-ipc.js +135 -0
  9. package/cli-runtime/channel/claude-channel-server.js +209 -0
  10. package/cli-runtime/cli.js +81 -0
  11. package/cli-runtime/commands/_schema.js +60 -0
  12. package/cli-runtime/commands/account.js +577 -0
  13. package/cli-runtime/commands/auth.js +140 -0
  14. package/cli-runtime/commands/behavior.js +422 -0
  15. package/cli-runtime/commands/capability.js +327 -0
  16. package/cli-runtime/commands/communication.js +339 -0
  17. package/cli-runtime/commands/competition.js +55 -0
  18. package/cli-runtime/commands/config.js +28 -0
  19. package/cli-runtime/commands/data.js +78 -0
  20. package/cli-runtime/commands/events.js +339 -0
  21. package/cli-runtime/commands/game/index.js +646 -0
  22. package/cli-runtime/commands/hub.js +152 -0
  23. package/cli-runtime/commands/load.js +22 -0
  24. package/cli-runtime/commands/memory.js +30 -0
  25. package/cli-runtime/commands/module-runtime-control.js +110 -0
  26. package/cli-runtime/commands/peek.js +38 -0
  27. package/cli-runtime/commands/perception.js +146 -0
  28. package/cli-runtime/commands/persona.js +165 -0
  29. package/cli-runtime/commands/prepare.js +878 -0
  30. package/cli-runtime/commands/setup/codex.js +244 -0
  31. package/cli-runtime/commands/setup/hermes.js +55 -0
  32. package/cli-runtime/commands/setup/index.js +15 -0
  33. package/cli-runtime/commands/setup/openclaw.js +103 -0
  34. package/cli-runtime/commands/skill.js +76 -0
  35. package/cli-runtime/commands/strategy.js +4 -0
  36. package/cli-runtime/commands/trigger.js +271 -0
  37. package/cli-runtime/commands/upgrade.js +112 -0
  38. package/cli-runtime/lib/account-guidance.js +97 -0
  39. package/cli-runtime/lib/agent-workspace-client.js +66 -0
  40. package/cli-runtime/lib/agent-workspace-runtime.js +174 -0
  41. package/cli-runtime/lib/agent-workspace-skills.js +453 -0
  42. package/cli-runtime/lib/agent-workspace-sync.js +812 -0
  43. package/cli-runtime/lib/auth.js +210 -0
  44. package/cli-runtime/lib/capability-cloud-presence.js +134 -0
  45. package/cli-runtime/lib/capability-cloud-refresh.js +263 -0
  46. package/cli-runtime/lib/capability-cloud-sync.js +385 -0
  47. package/cli-runtime/lib/capability-discovery.js +94 -0
  48. package/cli-runtime/lib/capability-load-diagnostics.js +121 -0
  49. package/cli-runtime/lib/capability-operation-name.js +24 -0
  50. package/cli-runtime/lib/capability-operation-rename.js +120 -0
  51. package/cli-runtime/lib/capability-selection.js +69 -0
  52. package/cli-runtime/lib/capability-workspace.js +214 -0
  53. package/cli-runtime/lib/command-error.js +25 -0
  54. package/cli-runtime/lib/command-meta.js +13 -0
  55. package/cli-runtime/lib/competition.js +77 -0
  56. package/cli-runtime/lib/custom-tts.js +363 -0
  57. package/cli-runtime/lib/desktop-auth.js +44 -0
  58. package/cli-runtime/lib/desktop-mode.js +12 -0
  59. package/cli-runtime/lib/diagnostics-config.js +82 -0
  60. package/cli-runtime/lib/game-client.js +602 -0
  61. package/cli-runtime/lib/game-context.js +117 -0
  62. package/cli-runtime/lib/gameplay-config.js +232 -0
  63. package/cli-runtime/lib/host-config-patcher.js +101 -0
  64. package/cli-runtime/lib/http-keepalive.js +15 -0
  65. package/cli-runtime/lib/http-transport.js +163 -0
  66. package/cli-runtime/lib/hub-client.js +292 -0
  67. package/cli-runtime/lib/hub-errors.js +51 -0
  68. package/cli-runtime/lib/hub-reminder.js +65 -0
  69. package/cli-runtime/lib/hub-unzip.js +52 -0
  70. package/cli-runtime/lib/init-command.js +160 -0
  71. package/cli-runtime/lib/load-context.js +97 -0
  72. package/cli-runtime/lib/load-startup-context.js +59 -0
  73. package/cli-runtime/lib/load-startup.js +23 -0
  74. package/cli-runtime/lib/lobby-host-context.js +70 -0
  75. package/cli-runtime/lib/match-state.js +61 -0
  76. package/cli-runtime/lib/normalize.js +28 -0
  77. package/cli-runtime/lib/package-skills.js +15 -0
  78. package/cli-runtime/lib/participation-leave.js +54 -0
  79. package/cli-runtime/lib/participation-status.js +73 -0
  80. package/cli-runtime/lib/perception-config.js +85 -0
  81. package/cli-runtime/lib/persona.js +157 -0
  82. package/cli-runtime/lib/room.js +108 -0
  83. package/cli-runtime/lib/runtime-cadence-config.js +18 -0
  84. package/cli-runtime/lib/server-registry.js +155 -0
  85. package/cli-runtime/lib/server-status.js +44 -0
  86. package/cli-runtime/lib/service-status.js +88 -0
  87. package/cli-runtime/lib/skill-host.js +246 -0
  88. package/cli-runtime/lib/skill-name-conflicts.js +89 -0
  89. package/cli-runtime/lib/skill-version.js +20 -0
  90. package/cli-runtime/lib/training-role.js +23 -0
  91. package/cli-runtime/lib/trigger-config.js +138 -0
  92. package/cli-runtime/lib/user-data.js +336 -0
  93. package/cli-runtime/lib/workspace-argv.js +35 -0
  94. package/cli-runtime/lib/workspace-runtime-lock.js +6 -0
  95. package/cli-runtime/lib/zip-store.js +78 -0
  96. package/cli-runtime/pipeline/canonical-event-presentation.js +32 -0
  97. package/cli-runtime/pipeline/event-format.js +921 -0
  98. package/cli-runtime/pipeline/event-hints.js +235 -0
  99. package/cli-runtime/pipeline/game-sync-event-normalization.js +228 -0
  100. package/cli-runtime/pipeline/player-projection.js +272 -0
  101. package/cli-runtime/pipeline/role-display.js +22 -0
  102. package/cli-runtime/runtime/auto-upgrade.js +30 -0
  103. package/cli-runtime/runtime/canonical-event-emitter.js +58 -0
  104. package/cli-runtime/runtime/canonical-monitor.js +332 -0
  105. package/cli-runtime/runtime/clawclaw/agent-ability-state.js +41 -0
  106. package/cli-runtime/runtime/clawclaw/agent-event-policy.js +58 -0
  107. package/cli-runtime/runtime/clawclaw/behavior-decision.js +84 -0
  108. package/cli-runtime/runtime/clawclaw/behavior-input-fields.js +212 -0
  109. package/cli-runtime/runtime/clawclaw/behavior-input.js +54 -0
  110. package/cli-runtime/runtime/clawclaw/behavior-observation-memory.js +106 -0
  111. package/cli-runtime/runtime/clawclaw/behavior-read-api.js +110 -0
  112. package/cli-runtime/runtime/clawclaw/behavior-reflex-control.js +97 -0
  113. package/cli-runtime/runtime/clawclaw/behavior-start-control.js +159 -0
  114. package/cli-runtime/runtime/clawclaw/index.js +3 -0
  115. package/cli-runtime/runtime/clawclaw/navigation/astar-path.js +244 -0
  116. package/cli-runtime/runtime/clawclaw/navigation/clawclaw-walkable.bin +0 -0
  117. package/cli-runtime/runtime/clawclaw/navigation/distance-field.js +136 -0
  118. package/cli-runtime/runtime/clawclaw/navigation/escape-planner.js +273 -0
  119. package/cli-runtime/runtime/clawclaw/navigation/hide-spots.js +31 -0
  120. package/cli-runtime/runtime/clawclaw/navigation/off-route-points.js +64 -0
  121. package/cli-runtime/runtime/clawclaw/navigation/walkable-grid.js +85 -0
  122. package/cli-runtime/runtime/clawclaw/notification-policy.js +59 -0
  123. package/cli-runtime/runtime/clawclaw/notification-turn.js +28 -0
  124. package/cli-runtime/runtime/clawclaw/notifications.js +65 -0
  125. package/cli-runtime/runtime/clawclaw/observation-frame-projector.js +94 -0
  126. package/cli-runtime/runtime/clawclaw/owner-lock-error.js +17 -0
  127. package/cli-runtime/runtime/clawclaw/owner-lock.js +219 -0
  128. package/cli-runtime/runtime/clawclaw/owner.js +1257 -0
  129. package/cli-runtime/runtime/clawclaw/perception-module-manifest.js +67 -0
  130. package/cli-runtime/runtime/clawclaw/perception-strategy-names.js +12 -0
  131. package/cli-runtime/runtime/clawclaw/persistence-compatibility.js +38 -0
  132. package/cli-runtime/runtime/clawclaw/plugins/action/action-plugin.js +604 -0
  133. package/cli-runtime/runtime/clawclaw/plugins/action/automated-action-normalization.js +67 -0
  134. package/cli-runtime/runtime/clawclaw/plugins/action/index.js +1 -0
  135. package/cli-runtime/runtime/clawclaw/plugins/assembly.js +134 -0
  136. package/cli-runtime/runtime/clawclaw/plugins/behavior/activation-manager.js +1 -0
  137. package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-action.js +26 -0
  138. package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-analysis-thread-host.js +21 -0
  139. package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-analysis-thread-host.ts +25 -0
  140. package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-catalog.js +90 -0
  141. package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-decision-history.js +60 -0
  142. package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-instance-snapshot.js +1 -0
  143. package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-manifest.js +136 -0
  144. package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-module-loader.js +230 -0
  145. package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-normalization.js +92 -0
  146. package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-plugin.js +162 -0
  147. package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-runner.js +20 -0
  148. package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-source.js +493 -0
  149. package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-worker-bridge.js +28 -0
  150. package/cli-runtime/runtime/clawclaw/plugins/behavior/control-driver.js +5 -0
  151. package/cli-runtime/runtime/clawclaw/plugins/behavior/index.js +11 -0
  152. package/cli-runtime/runtime/clawclaw/plugins/behavior/thread-behavior-executor.js +18 -0
  153. package/cli-runtime/runtime/clawclaw/plugins/behavior-input-source.js +233 -0
  154. package/cli-runtime/runtime/clawclaw/plugins/derived-event/derived-event-plugin.js +25 -0
  155. package/cli-runtime/runtime/clawclaw/plugins/derived-event/derived-event-rules.js +289 -0
  156. package/cli-runtime/runtime/clawclaw/plugins/derived-event/index.js +2 -0
  157. package/cli-runtime/runtime/clawclaw/plugins/derived-event/player-change-tracker.js +162 -0
  158. package/cli-runtime/runtime/clawclaw/plugins/derived-event/reminder-plugin.js +182 -0
  159. package/cli-runtime/runtime/clawclaw/plugins/derived-event/reminder-rules.js +1 -0
  160. package/cli-runtime/runtime/clawclaw/plugins/derived-event/reminder-runner.js +83 -0
  161. package/cli-runtime/runtime/clawclaw/plugins/derived-event/reminder-worker.js +35 -0
  162. package/cli-runtime/runtime/clawclaw/plugins/derived-event/reminder-worker.ts +33 -0
  163. package/cli-runtime/runtime/clawclaw/plugins/derived-event/state-change-rules.js +111 -0
  164. package/cli-runtime/runtime/clawclaw/plugins/derived-event/task-change-tracker.js +1 -0
  165. package/cli-runtime/runtime/clawclaw/plugins/game-query/context-capabilities.js +10 -0
  166. package/cli-runtime/runtime/clawclaw/plugins/game-query/game-query-plugin.js +196 -0
  167. package/cli-runtime/runtime/clawclaw/plugins/game-query/index.js +2 -0
  168. package/cli-runtime/runtime/clawclaw/plugins/index.js +9 -0
  169. package/cli-runtime/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-adapter.js +24 -0
  170. package/cli-runtime/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-socket.js +21 -0
  171. package/cli-runtime/runtime/clawclaw/plugins/mailbox/adapters/game-sync-perception-report-adapter.js +84 -0
  172. package/cli-runtime/runtime/clawclaw/plugins/mailbox/adapters/game-sync-runtime-report-adapter.js +54 -0
  173. package/cli-runtime/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.js +61 -0
  174. package/cli-runtime/runtime/clawclaw/plugins/mailbox/consumer-ids.js +10 -0
  175. package/cli-runtime/runtime/clawclaw/plugins/mailbox/desktop-event-socket.js +45 -0
  176. package/cli-runtime/runtime/clawclaw/plugins/mailbox/index.js +11 -0
  177. package/cli-runtime/runtime/clawclaw/plugins/mailbox/mailbox-event-batch-delivery.js +1 -0
  178. package/cli-runtime/runtime/clawclaw/plugins/mailbox/mailbox-plugin.js +13 -0
  179. package/cli-runtime/runtime/clawclaw/plugins/mailbox/mailbox-presentation.js +99 -0
  180. package/cli-runtime/runtime/clawclaw/plugins/mailbox/mailbox-service.js +84 -0
  181. package/cli-runtime/runtime/clawclaw/plugins/perception/contracts.js +14 -0
  182. package/cli-runtime/runtime/clawclaw/plugins/perception/index.js +11 -0
  183. package/cli-runtime/runtime/clawclaw/plugins/perception/map-concurrent.js +1 -0
  184. package/cli-runtime/runtime/clawclaw/plugins/perception/module-input-boundary.js +64 -0
  185. package/cli-runtime/runtime/clawclaw/plugins/perception/module-runner.js +182 -0
  186. package/cli-runtime/runtime/clawclaw/plugins/perception/notification-content.js +47 -0
  187. package/cli-runtime/runtime/clawclaw/plugins/perception/official-module-ids.js +13 -0
  188. package/cli-runtime/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.js +684 -0
  189. package/cli-runtime/runtime/clawclaw/plugins/perception/perception-analysis-thread-worker.js +145 -0
  190. package/cli-runtime/runtime/clawclaw/plugins/perception/perception-analysis-thread-worker.ts +252 -0
  191. package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-loader.js +78 -0
  192. package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-output.js +15 -0
  193. package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-plugin.js +144 -0
  194. package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-runner.js +22 -0
  195. package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-worker.js +18 -0
  196. package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-worker.ts +19 -0
  197. package/cli-runtime/runtime/clawclaw/plugins/perception/perception-plugin.js +1343 -0
  198. package/cli-runtime/runtime/clawclaw/plugins/perception/perception-reducer-thread-pool.js +522 -0
  199. package/cli-runtime/runtime/clawclaw/plugins/perception/perception-reducer-thread-worker.js +161 -0
  200. package/cli-runtime/runtime/clawclaw/plugins/perception/perception-reducer-thread-worker.ts +262 -0
  201. package/cli-runtime/runtime/clawclaw/plugins/perception/perception-source.js +489 -0
  202. package/cli-runtime/runtime/clawclaw/plugins/perception/perception-test-fixtures.js +31 -0
  203. package/cli-runtime/runtime/clawclaw/plugins/perception/replay.js +56 -0
  204. package/cli-runtime/runtime/clawclaw/plugins/perception/report-content.js +39 -0
  205. package/cli-runtime/runtime/clawclaw/plugins/perception/shared/math.js +1 -0
  206. package/cli-runtime/runtime/clawclaw/plugins/perception/spatial-facts.js +103 -0
  207. package/cli-runtime/runtime/clawclaw/plugins/perception/task-baseline.js +29 -0
  208. package/cli-runtime/runtime/clawclaw/plugins/plugin-api-version.js +89 -0
  209. package/cli-runtime/runtime/clawclaw/plugins/source/game-transport.js +204 -0
  210. package/cli-runtime/runtime/clawclaw/plugins/source/index.js +5 -0
  211. package/cli-runtime/runtime/clawclaw/plugins/source/room-transport.js +399 -0
  212. package/cli-runtime/runtime/clawclaw/plugins/source/source-plugin.js +2003 -0
  213. package/cli-runtime/runtime/clawclaw/plugins/source/source-transports.js +26 -0
  214. package/cli-runtime/runtime/clawclaw/plugins/source/types.js +0 -0
  215. package/cli-runtime/runtime/clawclaw/plugins/system-perception/rule-runner.js +90 -0
  216. package/cli-runtime/runtime/clawclaw/plugins/system-perception/sabotage-availability-rule.js +59 -0
  217. package/cli-runtime/runtime/clawclaw/plugins/system-perception/system-perceptions.js +241 -0
  218. package/cli-runtime/runtime/clawclaw/plugins/trigger/contracts.js +12 -0
  219. package/cli-runtime/runtime/clawclaw/plugins/trigger/index.js +4 -0
  220. package/cli-runtime/runtime/clawclaw/plugins/trigger/trigger-module-loader.js +105 -0
  221. package/cli-runtime/runtime/clawclaw/plugins/trigger/trigger-plugin.js +741 -0
  222. package/cli-runtime/runtime/clawclaw/plugins/trigger/trigger-source.js +372 -0
  223. package/cli-runtime/runtime/clawclaw/plugins/trigger/trigger-thread-pool.js +378 -0
  224. package/cli-runtime/runtime/clawclaw/plugins/trigger/trigger-thread-worker.js +118 -0
  225. package/cli-runtime/runtime/clawclaw/plugins/trigger/trigger-thread-worker.ts +168 -0
  226. package/cli-runtime/runtime/clawclaw/reaction-behavior-resolution.js +1 -0
  227. package/cli-runtime/runtime/clawclaw/reaction-manifest.js +62 -0
  228. package/cli-runtime/runtime/clawclaw/reminder-manifest.js +39 -0
  229. package/cli-runtime/runtime/clawclaw/runtime-cadence.js +28 -0
  230. package/cli-runtime/runtime/clawclaw/runtime-data-export.js +321 -0
  231. package/cli-runtime/runtime/clawclaw/runtime-state.js +51 -0
  232. package/cli-runtime/runtime/clawclaw/runtime.js +132 -0
  233. package/cli-runtime/runtime/clawclaw/spatial-api.js +48 -0
  234. package/cli-runtime/runtime/clawclaw/starting-owner-control.js +24 -0
  235. package/cli-runtime/runtime/clawclaw/strategy-memory-rpc.js +1 -0
  236. package/cli-runtime/runtime/clawclaw/strategy-memory.js +6 -0
  237. package/cli-runtime/runtime/clawclaw/task-choice-projection.js +72 -0
  238. package/cli-runtime/runtime/clawclaw-event-catalog.js +284 -0
  239. package/cli-runtime/runtime/clawclaw-position.js +0 -0
  240. package/cli-runtime/runtime/clawclaw-room-state.js +38 -0
  241. package/cli-runtime/runtime/framework/action-diagnostics.js +69 -0
  242. package/cli-runtime/runtime/framework/capability-registry.js +1 -0
  243. package/cli-runtime/runtime/framework/contracts.js +1 -0
  244. package/cli-runtime/runtime/framework/control/control-scheduler.js +1 -0
  245. package/cli-runtime/runtime/framework/control/domain-set.js +1 -0
  246. package/cli-runtime/runtime/framework/control/index.js +1 -0
  247. package/cli-runtime/runtime/framework/control/types.js +1 -0
  248. package/cli-runtime/runtime/framework/control-coordinator.js +1 -0
  249. package/cli-runtime/runtime/framework/events/event-catalog.js +1 -0
  250. package/cli-runtime/runtime/framework/events/event-delivery-service.js +1 -0
  251. package/cli-runtime/runtime/framework/events/event-ingress.js +1 -0
  252. package/cli-runtime/runtime/framework/events/event-repository.js +1 -0
  253. package/cli-runtime/runtime/framework/events/index.js +5 -0
  254. package/cli-runtime/runtime/framework/events/memory-event-repository.js +1 -0
  255. package/cli-runtime/runtime/framework/events/runtime-resume.js +1 -0
  256. package/cli-runtime/runtime/framework/events/sqlite-event-repository.js +6 -0
  257. package/cli-runtime/runtime/framework/events/test-helpers.js +56 -0
  258. package/cli-runtime/runtime/framework/events/types.js +1 -0
  259. package/cli-runtime/runtime/framework/index.js +7 -0
  260. package/cli-runtime/runtime/framework/load-node-sqlite.js +1 -0
  261. package/cli-runtime/runtime/framework/mailbox/coalescer.js +1 -0
  262. package/cli-runtime/runtime/framework/mailbox/host-notification-sink.js +1 -0
  263. package/cli-runtime/runtime/framework/mailbox/identity.js +1 -0
  264. package/cli-runtime/runtime/framework/mailbox/index.js +1 -0
  265. package/cli-runtime/runtime/framework/mailbox/mailbox-dispatcher.js +1 -0
  266. package/cli-runtime/runtime/framework/mailbox/mailbox-repository.js +1 -0
  267. package/cli-runtime/runtime/framework/mailbox/notification-projector.js +1 -0
  268. package/cli-runtime/runtime/framework/mailbox/types.js +1 -0
  269. package/cli-runtime/runtime/framework/modules/runtime-module-loader-hooks.mjs +2 -0
  270. package/cli-runtime/runtime/framework/modules/runtime-module-loader.js +31 -0
  271. package/cli-runtime/runtime/framework/modules/runtime-module-output.js +1 -0
  272. package/cli-runtime/runtime/framework/modules/runtime-module-worker-bootstrap.mjs +3 -0
  273. package/cli-runtime/runtime/framework/participation-manager.js +1 -0
  274. package/cli-runtime/runtime/framework/persistence/async-sqlite-persistence-worker.js +1 -0
  275. package/cli-runtime/runtime/framework/persistence/async-sqlite-persistence-worker.ts +2 -0
  276. package/cli-runtime/runtime/framework/persistence/memory-first-persistence.js +9 -0
  277. package/cli-runtime/runtime/framework/plugins/contracts.js +1 -0
  278. package/cli-runtime/runtime/framework/plugins/index.js +1 -0
  279. package/cli-runtime/runtime/framework/plugins/runtime-event-identity.js +1 -0
  280. package/cli-runtime/runtime/framework/plugins/runtime-input-journal.js +1 -0
  281. package/cli-runtime/runtime/framework/plugins/runtime-plugin-scheduler.js +1 -0
  282. package/cli-runtime/runtime/framework/runtime.js +12 -0
  283. package/cli-runtime/runtime/framework/serial-task-queue.js +1 -0
  284. package/cli-runtime/runtime/framework/state/contracts.js +1 -0
  285. package/cli-runtime/runtime/framework/state/current-state-store.js +1 -0
  286. package/cli-runtime/runtime/framework/state/durable-agent-state-snapshot.js +1 -0
  287. package/cli-runtime/runtime/framework/state/freshness.js +1 -0
  288. package/cli-runtime/runtime/framework/state/history/contracts.js +1 -0
  289. package/cli-runtime/runtime/framework/state/history/history-writer.js +1 -0
  290. package/cli-runtime/runtime/framework/state/history/memory-state-history-repository.js +1 -0
  291. package/cli-runtime/runtime/framework/state/history/sqlite-state-history-repository.js +1 -0
  292. package/cli-runtime/runtime/framework/state/history/trajectory-projector.js +1 -0
  293. package/cli-runtime/runtime/framework/state/index.js +1 -0
  294. package/cli-runtime/runtime/framework/state/state-ingress.js +1 -0
  295. package/cli-runtime/runtime/framework/state/state-provider.js +1 -0
  296. package/cli-runtime/runtime/framework/state/types.js +1 -0
  297. package/cli-runtime/runtime/game-sync-ingress-protocol.js +0 -0
  298. package/cli-runtime/runtime/game-sync-ingress-worker.js +310 -0
  299. package/cli-runtime/runtime/game-sync-ingress-worker.ts +274 -0
  300. package/cli-runtime/runtime/game-sync-protocol.js +278 -0
  301. package/cli-runtime/runtime/host-monitor-rate-gate.js +1 -0
  302. package/cli-runtime/runtime/mailbox-host-relay.js +1 -0
  303. package/cli-runtime/runtime/observability/detail-capture.js +35 -0
  304. package/cli-runtime/runtime/observability/factory.js +137 -0
  305. package/cli-runtime/runtime/observability/index.js +6 -0
  306. package/cli-runtime/runtime/observability/process-timing.js +1 -0
  307. package/cli-runtime/runtime/observability/recorder.js +1 -0
  308. package/cli-runtime/runtime/observability/redaction.js +1 -0
  309. package/cli-runtime/runtime/observability/reporter.js +1 -0
  310. package/cli-runtime/runtime/observability/sinks.js +1 -0
  311. package/cli-runtime/runtime/observability/types.js +1 -0
  312. package/cli-runtime/runtime/owner-control.js +59 -0
  313. package/cli-runtime/runtime/parent-process-watch.js +1 -0
  314. package/cli-runtime/runtime/pending-event-handoff.js +48 -0
  315. package/cli-runtime/runtime/process-identity.js +45 -0
  316. package/cli-runtime/runtime/raw-ws-log.js +181 -0
  317. package/cli-runtime/runtime/runtime-logger.js +79 -0
  318. package/cli-runtime/runtime/threaded-ws-client.js +263 -0
  319. package/cli-runtime/runtime/ws-client.js +563 -0
  320. package/cli-runtime/sdk/action.js +133 -0
  321. package/cli-runtime/sdk/action.ts +160 -0
  322. package/cli-runtime/sdk/behavior-plugin/index.js +23 -0
  323. package/cli-runtime/sdk/behavior-plugin/index.ts +341 -0
  324. package/cli-runtime/sdk/behavior-toolkit/corpse-search.js +56 -0
  325. package/cli-runtime/sdk/behavior-toolkit/corpse-search.ts +87 -0
  326. package/cli-runtime/sdk/behavior-toolkit/escape.js +25 -0
  327. package/cli-runtime/sdk/behavior-toolkit/escape.ts +40 -0
  328. package/cli-runtime/sdk/behavior-toolkit/index.js +7 -0
  329. package/cli-runtime/sdk/behavior-toolkit/index.ts +7 -0
  330. package/cli-runtime/sdk/behavior-toolkit/kill-flow.js +239 -0
  331. package/cli-runtime/sdk/behavior-toolkit/kill-flow.ts +299 -0
  332. package/cli-runtime/sdk/behavior-toolkit/model.js +183 -0
  333. package/cli-runtime/sdk/behavior-toolkit/model.ts +265 -0
  334. package/cli-runtime/sdk/behavior-toolkit/move-gate.js +30 -0
  335. package/cli-runtime/sdk/behavior-toolkit/move-gate.ts +52 -0
  336. package/cli-runtime/sdk/behavior-toolkit/patrol.js +39 -0
  337. package/cli-runtime/sdk/behavior-toolkit/patrol.ts +53 -0
  338. package/cli-runtime/sdk/behavior-toolkit/search.js +81 -0
  339. package/cli-runtime/sdk/behavior-toolkit/search.ts +102 -0
  340. package/cli-runtime/sdk/index.js +78 -0
  341. package/cli-runtime/sdk/index.ts +136 -0
  342. package/cli-runtime/sdk/module-input/index.js +0 -0
  343. package/cli-runtime/sdk/module-input/index.ts +310 -0
  344. package/cli-runtime/sdk/perception-plugin/index.js +79 -0
  345. package/cli-runtime/sdk/perception-plugin/index.ts +251 -0
  346. package/cli-runtime/sdk/perception-plugin/lifecycle.js +18 -0
  347. package/cli-runtime/sdk/perception-plugin/lifecycle.ts +15 -0
  348. package/cli-runtime/sdk/perception-plugin/math.js +99 -0
  349. package/cli-runtime/sdk/perception-plugin/math.ts +107 -0
  350. package/cli-runtime/sdk/perception-plugin/module.js +4 -0
  351. package/cli-runtime/sdk/perception-plugin/module.ts +80 -0
  352. package/cli-runtime/sdk/perception-plugin/reaction.js +6 -0
  353. package/cli-runtime/sdk/perception-plugin/reaction.ts +79 -0
  354. package/cli-runtime/sdk/perception-plugin/reminder-rules.js +131 -0
  355. package/cli-runtime/sdk/perception-plugin/reminder-rules.ts +89 -0
  356. package/cli-runtime/sdk/perception-plugin/reminder.js +8 -0
  357. package/cli-runtime/sdk/perception-plugin/reminder.ts +68 -0
  358. package/cli-runtime/sdk/perception-plugin/task-change-tracker.js +150 -0
  359. package/cli-runtime/sdk/perception-plugin/task-change-tracker.ts +258 -0
  360. package/cli-runtime/sdk/resource-metadata.js +27 -0
  361. package/cli-runtime/sdk/resource-metadata.ts +66 -0
  362. package/cli-runtime/sdk/strategy-memory.js +1 -0
  363. package/cli-runtime/sdk/strategy-memory.ts +1 -0
  364. package/cli-runtime/sdk/strategy-plugin/index.js +6 -0
  365. package/cli-runtime/sdk/strategy-plugin/index.ts +36 -0
  366. package/cli-runtime/sdk/task-availability.js +56 -0
  367. package/cli-runtime/sdk/task-availability.ts +70 -0
  368. package/cli-runtime/sdk/trigger-plugin/index.js +16 -0
  369. package/cli-runtime/sdk/trigger-plugin/index.ts +130 -0
  370. package/cli-runtime/sdk/types.js +25 -0
  371. package/cli-runtime/sdk/types.ts +165 -0
  372. package/cli-runtime/short-command/classifier.js +129 -0
  373. package/cli-runtime/short-command/index.js +7 -0
  374. package/cli-runtime/short-command/presenter.js +225 -0
  375. package/cli-runtime/short-command/process-io.js +13 -0
  376. package/cli-runtime/short-command/response-contract.js +24 -0
  377. package/cli-runtime/short-command/runner.js +94 -0
  378. package/cli-runtime/short-command/sensitive-data-filter.js +92 -0
  379. package/cli-runtime/short-command/transport-response.js +57 -0
  380. package/cli-runtime/short-command/types.js +0 -0
  381. package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/host.js +21 -29
  382. package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/sdk-sdk.js +76 -6
  383. package/docs/configuration.md +13 -0
  384. package/package.json +7 -4
  385. package/scripts/build-cli.mjs +34 -0
  386. package/skills/clawclaw/SKILL.md +1 -1
  387. package/skills/clawclaw/references/STREAM.md +1 -0
  388. package/skills/clawclaw-start/SKILL.md +1 -0
  389. package/skills/clawclaw-start/references/STARTUP.md +1 -0
  390. package/src/cli.ts +75 -77
  391. package/src/commands/auth.ts +3 -2
  392. package/src/commands/game/index.ts +33 -9
  393. package/src/commands/prepare.ts +34 -18
  394. package/src/lib/agent-workspace-client.ts +12 -9
  395. package/src/lib/game-client.ts +1 -1
  396. package/src/lib/http-transport.ts +17 -2
  397. package/src/lib/hub-client.ts +10 -7
  398. package/src/pipeline/event-format.ts +2 -0
  399. package/src/pipeline/event-hints.ts +6 -0
  400. package/src/runtime/clawclaw/notification-policy.ts +1 -1
  401. package/src/runtime/clawclaw/owner-lock.ts +3 -2
  402. package/src/runtime/clawclaw/owner.ts +36 -10
  403. package/src/runtime/clawclaw/plugins/behavior/behavior-worker-bridge.ts +1 -1
  404. package/src/runtime/clawclaw/plugins/mailbox/desktop-event-socket.ts +19 -0
  405. package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.ts +1 -0
  406. package/src/runtime/clawclaw/plugins/source/source-plugin.ts +33 -9
  407. package/src/runtime/clawclaw-event-catalog.ts +1 -0
  408. package/src/runtime/framework/modules/runtime-module-loader.ts +24 -29
  409. package/src/runtime/process-identity.ts +44 -0
@@ -0,0 +1,363 @@
1
+ import { existsSync, readFileSync } from "fs";
2
+ import { basename, extname } from "path";
3
+ import { getWorkspaceConfigFile, getWorkspaceDir } from "./init-command.js";
4
+ const DEFAULT_TIMEOUT_MS = 1e4;
5
+ const MAX_TIMEOUT_MS = 6e4;
6
+ const MAX_AUDIO_BYTES = 10 * 1024 * 1024;
7
+ const SUPPORTED_AUDIO_FORMATS = "mp3, wav, m4a, ogg, webm";
8
+ const AUDIO_FORMATS = {
9
+ mp3: { format: "mp3", contentType: "audio/mpeg", extension: ".mp3" },
10
+ wav: { format: "wav", contentType: "audio/wav", extension: ".wav" },
11
+ m4a: { format: "m4a", contentType: "audio/mp4", extension: ".m4a" },
12
+ ogg: { format: "ogg", contentType: "audio/ogg", extension: ".ogg" },
13
+ webm: { format: "webm", contentType: "audio/webm", extension: ".webm" }
14
+ };
15
+ const AUDIO_FORMAT_ALIASES = {
16
+ mp3: "mp3",
17
+ mpeg: "mp3",
18
+ "audio/mpeg": "mp3",
19
+ "audio/mp3": "mp3",
20
+ wav: "wav",
21
+ wave: "wav",
22
+ "audio/wav": "wav",
23
+ "audio/x-wav": "wav",
24
+ m4a: "m4a",
25
+ mp4: "m4a",
26
+ "audio/mp4": "m4a",
27
+ "audio/x-m4a": "m4a",
28
+ ogg: "ogg",
29
+ oga: "ogg",
30
+ "audio/ogg": "ogg",
31
+ webm: "webm",
32
+ "audio/webm": "webm"
33
+ };
34
+ class CustomTtsError extends Error {
35
+ constructor(message) {
36
+ super(message);
37
+ this.name = "CustomTtsError";
38
+ }
39
+ }
40
+ function isRecord(value) {
41
+ return typeof value === "object" && value !== null && !Array.isArray(value);
42
+ }
43
+ function validateHttpUrl(raw, field) {
44
+ if (typeof raw !== "string" || raw.trim() === "") {
45
+ throw new CustomTtsError(`${field} must be a non-empty HTTP(S) URL.`);
46
+ }
47
+ let url;
48
+ try {
49
+ url = new URL(raw);
50
+ } catch {
51
+ throw new CustomTtsError(`${field} must be a valid HTTP(S) URL.`);
52
+ }
53
+ if (url.protocol !== "http:" && url.protocol !== "https:") {
54
+ throw new CustomTtsError(`${field} must use http:// or https://.`);
55
+ }
56
+ return url.toString();
57
+ }
58
+ function validateHeaders(raw) {
59
+ if (raw === void 0) return { "Content-Type": "application/json" };
60
+ if (!isRecord(raw)) throw new CustomTtsError("request.headers must be a JSON object.");
61
+ const headers = {};
62
+ for (const [name, value] of Object.entries(raw)) {
63
+ if (typeof value !== "string") {
64
+ throw new CustomTtsError(`request.headers.${name} must be a string.`);
65
+ }
66
+ headers[name] = value;
67
+ }
68
+ if (!Object.keys(headers).some((name) => name.toLowerCase() === "content-type")) {
69
+ headers["Content-Type"] = "application/json";
70
+ }
71
+ return headers;
72
+ }
73
+ function validateTimeout(raw) {
74
+ if (raw === void 0) return DEFAULT_TIMEOUT_MS;
75
+ if (!Number.isInteger(raw) || Number(raw) <= 0 || Number(raw) > MAX_TIMEOUT_MS) {
76
+ throw new CustomTtsError(`request.timeout_ms must be an integer between 1 and ${MAX_TIMEOUT_MS}.`);
77
+ }
78
+ return Number(raw);
79
+ }
80
+ function validateResponse(raw) {
81
+ if (raw === void 0) return { type: "binary" };
82
+ if (!isRecord(raw)) throw new CustomTtsError("response must be a JSON object.");
83
+ const type = raw.type ?? "binary";
84
+ if (type !== "binary" && type !== "json_base64" && type !== "json_url") {
85
+ throw new CustomTtsError("response.type must be binary, json_base64, or json_url.");
86
+ }
87
+ const path = raw.path;
88
+ if (type !== "binary" && (typeof path !== "string" || path.trim() === "")) {
89
+ throw new CustomTtsError(`response.path is required when response.type is ${type}.`);
90
+ }
91
+ if (raw.content_type !== void 0 && (typeof raw.content_type !== "string" || raw.content_type.trim() === "")) {
92
+ throw new CustomTtsError("response.content_type must be a non-empty string.");
93
+ }
94
+ if (raw.format !== void 0 && (typeof raw.format !== "string" || raw.format.trim() === "")) {
95
+ throw new CustomTtsError("response.format must be a non-empty string.");
96
+ }
97
+ if (raw.format_path !== void 0 && (typeof raw.format_path !== "string" || raw.format_path.trim() === "")) {
98
+ throw new CustomTtsError("response.format_path must be a non-empty string.");
99
+ }
100
+ if (type === "binary" && raw.format_path !== void 0) {
101
+ throw new CustomTtsError("response.format_path is only supported for json_base64 and json_url responses.");
102
+ }
103
+ if (raw.filename !== void 0) {
104
+ if (typeof raw.filename !== "string" || raw.filename.trim() === "" || basename(raw.filename) !== raw.filename) {
105
+ throw new CustomTtsError("response.filename must be a plain filename without directories.");
106
+ }
107
+ }
108
+ const configuredFormat = typeof raw.format === "string" ? resolveAudioFormat(raw.format, "response.format") : void 0;
109
+ const configuredContentType = typeof raw.content_type === "string" ? resolveAudioFormat(raw.content_type, "response.content_type") : void 0;
110
+ if (configuredFormat && configuredContentType && configuredFormat.format !== configuredContentType.format) {
111
+ throw new CustomTtsError("response.format and response.content_type describe different audio formats.");
112
+ }
113
+ return {
114
+ type,
115
+ ...typeof path === "string" ? { path } : {},
116
+ ...typeof raw.format === "string" ? { format: raw.format.trim() } : {},
117
+ ...typeof raw.format_path === "string" ? { format_path: raw.format_path.trim() } : {},
118
+ ...typeof raw.content_type === "string" ? { content_type: raw.content_type } : {},
119
+ ...typeof raw.filename === "string" ? { filename: raw.filename } : {}
120
+ };
121
+ }
122
+ function validateTextField(raw) {
123
+ if (raw === void 0) return void 0;
124
+ if (typeof raw !== "string" || raw.trim() === "") {
125
+ throw new CustomTtsError("request.text_field must be a non-empty string.");
126
+ }
127
+ return raw.trim();
128
+ }
129
+ function validateBody(raw) {
130
+ if (raw === void 0) return {};
131
+ if (!isRecord(raw)) throw new CustomTtsError("request.body must be a JSON object.");
132
+ return raw;
133
+ }
134
+ function containsTextPlaceholder(value) {
135
+ if (typeof value === "string") return value.includes("{{text}}");
136
+ if (Array.isArray(value)) return value.some(containsTextPlaceholder);
137
+ if (value !== null && typeof value === "object") {
138
+ return Object.values(value).some(containsTextPlaceholder);
139
+ }
140
+ return false;
141
+ }
142
+ function substituteText(value, text) {
143
+ if (typeof value === "string") return value.replaceAll("{{text}}", text);
144
+ if (Array.isArray(value)) return value.map((item) => substituteText(item, text));
145
+ if (value !== null && typeof value === "object") {
146
+ return Object.fromEntries(
147
+ Object.entries(value).map(([key, item]) => [key, substituteText(item, text)])
148
+ );
149
+ }
150
+ return value;
151
+ }
152
+ function parseCustomTtsConfig(raw) {
153
+ if (!isRecord(raw)) throw new CustomTtsError("TTS config must be a JSON object.");
154
+ if (raw.customize_tts === void 0 || raw.customize_tts === false) return null;
155
+ if (raw.customize_tts !== true) throw new CustomTtsError("customize_tts must be a JSON boolean.");
156
+ if (!isRecord(raw.request)) throw new CustomTtsError("request must be a JSON object.");
157
+ const method = typeof raw.request.method === "string" ? raw.request.method.toUpperCase() : "POST";
158
+ if (method !== "POST") throw new CustomTtsError("request.method currently supports POST only.");
159
+ const textField = validateTextField(raw.request.text_field);
160
+ const body = validateBody(raw.request.body);
161
+ if (!textField && !containsTextPlaceholder(body)) {
162
+ throw new CustomTtsError(
163
+ "Configure request.text_field or place {{text}} in request.body to specify the speech text."
164
+ );
165
+ }
166
+ return {
167
+ customize_tts: true,
168
+ request: {
169
+ url: validateHttpUrl(raw.request.url, "request.url"),
170
+ method: "POST",
171
+ headers: validateHeaders(raw.request.headers),
172
+ ...textField ? { text_field: textField } : {},
173
+ body,
174
+ timeout_ms: validateTimeout(raw.request.timeout_ms)
175
+ },
176
+ response: validateResponse(raw.response)
177
+ };
178
+ }
179
+ function loadCustomTtsConfig(workspaceDir = getWorkspaceDir()) {
180
+ const path = getWorkspaceConfigFile(workspaceDir);
181
+ if (!existsSync(path)) return null;
182
+ let raw;
183
+ try {
184
+ raw = JSON.parse(readFileSync(path, "utf8"));
185
+ } catch (err) {
186
+ const detail = err instanceof Error ? err.message : String(err);
187
+ throw new CustomTtsError(`Cannot parse ${path}: ${detail}`);
188
+ }
189
+ if (!isRecord(raw)) throw new CustomTtsError(`${path} must contain a JSON object.`);
190
+ if (raw.tts === void 0) return null;
191
+ return parseCustomTtsConfig(raw.tts);
192
+ }
193
+ function valueAtPath(value, path) {
194
+ let current = value;
195
+ for (const segment of path.split(".")) {
196
+ if (segment === "") throw new CustomTtsError(`Invalid response.path: ${path}`);
197
+ if (Array.isArray(current) && /^\d+$/.test(segment)) {
198
+ current = current[Number(segment)];
199
+ } else if (isRecord(current)) {
200
+ current = current[segment];
201
+ } else {
202
+ return void 0;
203
+ }
204
+ }
205
+ return current;
206
+ }
207
+ function normalizeContentType(value) {
208
+ const normalized = value?.split(";", 1)[0].trim().toLowerCase();
209
+ return normalized || void 0;
210
+ }
211
+ function resolveAudioFormat(raw, label) {
212
+ const normalized = normalizeContentType(raw)?.replace(/^\./, "");
213
+ const format = normalized ? AUDIO_FORMAT_ALIASES[normalized] : void 0;
214
+ if (!format) {
215
+ throw new CustomTtsError(`${label} has unsupported audio format "${raw}". Supported: ${SUPPORTED_AUDIO_FORMATS}.`);
216
+ }
217
+ return AUDIO_FORMATS[format];
218
+ }
219
+ function formatFromServerContentType(contentType, label) {
220
+ const normalized = normalizeContentType(contentType);
221
+ if (!normalized || normalized === "application/octet-stream" || normalized === "binary/octet-stream") {
222
+ return void 0;
223
+ }
224
+ return resolveAudioFormat(normalized, `${label} content-type`);
225
+ }
226
+ function configuredAudioFormat(response) {
227
+ return response.format ? resolveAudioFormat(response.format, "response.format") : response.content_type ? resolveAudioFormat(response.content_type, "response.content_type") : void 0;
228
+ }
229
+ function selectAudioFormat(response, serverFormats) {
230
+ const authoritative = serverFormats.filter(
231
+ (candidate) => candidate.value !== void 0
232
+ );
233
+ const first = authoritative[0];
234
+ for (const candidate of authoritative.slice(1)) {
235
+ if (candidate.value.format !== first.value.format) {
236
+ throw new CustomTtsError(
237
+ `TTS response audio formats conflict: ${first.label} is ${first.value.format}, ${candidate.label} is ${candidate.value.format}.`
238
+ );
239
+ }
240
+ }
241
+ const configured = configuredAudioFormat(response);
242
+ if (first && configured && first.value.format !== configured.format) {
243
+ throw new CustomTtsError(
244
+ `TTS response audio format ${first.value.format} conflicts with configured format ${configured.format}.`
245
+ );
246
+ }
247
+ if (first) return first.value;
248
+ if (configured) return configured;
249
+ throw new CustomTtsError(
250
+ "Cannot determine custom TTS audio format. Return a supported audio Content-Type/format or set response.format in config.json."
251
+ );
252
+ }
253
+ function validateAudio(audio) {
254
+ if (audio.length === 0) throw new CustomTtsError("Custom TTS returned empty audio.");
255
+ if (audio.length > MAX_AUDIO_BYTES) {
256
+ throw new CustomTtsError(`Custom TTS audio exceeds ${MAX_AUDIO_BYTES / 1024 / 1024} MB.`);
257
+ }
258
+ return audio;
259
+ }
260
+ async function responseError(response, label) {
261
+ let detail = "";
262
+ try {
263
+ detail = (await response.text()).trim().slice(0, 500);
264
+ } catch {
265
+ }
266
+ return new CustomTtsError(`${label} failed with status ${response.status}${detail ? `: ${detail}` : ""}`);
267
+ }
268
+ async function fetchWithTimeout(url, init, timeoutMs, label) {
269
+ try {
270
+ return await fetch(url, { ...init, signal: AbortSignal.timeout(timeoutMs) });
271
+ } catch (err) {
272
+ if (err instanceof Error && (err.name === "AbortError" || err.name === "TimeoutError")) {
273
+ throw new CustomTtsError(`${label} timed out after ${timeoutMs} ms.`);
274
+ }
275
+ throw new CustomTtsError(`${label} failed: ${err instanceof Error ? err.message : String(err)}`);
276
+ }
277
+ }
278
+ function decodeBase64(raw) {
279
+ const dataUrl = raw.match(/^data:([^;,]+)?;base64,([\s\S]*)$/i);
280
+ const encoded = (dataUrl?.[2] ?? raw).replace(/\s+/g, "");
281
+ if (encoded === "") throw new CustomTtsError("Custom TTS returned empty base64 audio.");
282
+ const audio = Buffer.from(encoded, "base64");
283
+ return { audio: validateAudio(audio), contentType: normalizeContentType(dataUrl?.[1]) };
284
+ }
285
+ function finalAudio(audio, response, serverFormats) {
286
+ const format = selectAudioFormat(response, serverFormats);
287
+ const filename = response.filename ?? `tts${format.extension}`;
288
+ const filenameExtension = extname(filename).toLowerCase();
289
+ if (filenameExtension !== format.extension) {
290
+ throw new CustomTtsError(
291
+ `response.filename extension "${filenameExtension || "(none)"}" does not match audio format ${format.format}.`
292
+ );
293
+ }
294
+ return { audio: validateAudio(audio), contentType: format.contentType, filename };
295
+ }
296
+ async function synthesizeCustomTts(text, config) {
297
+ const substitutedBody = substituteText(config.request.body, text);
298
+ const requestBody = config.request.text_field ? { ...substitutedBody, [config.request.text_field]: text } : substitutedBody;
299
+ const response = await fetchWithTimeout(config.request.url, {
300
+ method: config.request.method,
301
+ headers: config.request.headers,
302
+ body: JSON.stringify(requestBody)
303
+ }, config.request.timeout_ms, "Custom TTS request");
304
+ if (!response.ok) throw await responseError(response, "Custom TTS request");
305
+ if (config.response.type === "binary") {
306
+ const contentTypeFormat = formatFromServerContentType(response.headers.get("content-type"), "Custom TTS request");
307
+ return finalAudio(Buffer.from(await response.arrayBuffer()), config.response, [
308
+ { value: contentTypeFormat, label: "HTTP Content-Type" }
309
+ ]);
310
+ }
311
+ let payload;
312
+ try {
313
+ payload = await response.json();
314
+ } catch {
315
+ throw new CustomTtsError("Custom TTS response is not valid JSON.");
316
+ }
317
+ const value = valueAtPath(payload, config.response.path);
318
+ if (typeof value !== "string" || value.trim() === "") {
319
+ throw new CustomTtsError(`Custom TTS response path "${config.response.path}" did not contain a string.`);
320
+ }
321
+ if (config.response.type === "json_base64") {
322
+ const decoded = decodeBase64(value);
323
+ const dataUrlFormat = decoded.contentType ? resolveAudioFormat(decoded.contentType, "Base64 data URL content-type") : void 0;
324
+ const responseFormat2 = config.response.format_path ? valueAtPath(payload, config.response.format_path) : void 0;
325
+ if (config.response.format_path && (typeof responseFormat2 !== "string" || responseFormat2.trim() === "")) {
326
+ throw new CustomTtsError(
327
+ `Custom TTS response format path "${config.response.format_path}" did not contain a string.`
328
+ );
329
+ }
330
+ const formatPathFormat2 = typeof responseFormat2 === "string" ? resolveAudioFormat(responseFormat2, `response.format_path "${config.response.format_path}"`) : void 0;
331
+ return finalAudio(decoded.audio, config.response, [
332
+ { value: dataUrlFormat, label: "Base64 data URL" },
333
+ { value: formatPathFormat2, label: `response.format_path "${config.response.format_path}"` }
334
+ ]);
335
+ }
336
+ const audioUrl = validateHttpUrl(value, `response.${config.response.path}`);
337
+ const responseFormat = config.response.format_path ? valueAtPath(payload, config.response.format_path) : void 0;
338
+ if (config.response.format_path && (typeof responseFormat !== "string" || responseFormat.trim() === "")) {
339
+ throw new CustomTtsError(
340
+ `Custom TTS response format path "${config.response.format_path}" did not contain a string.`
341
+ );
342
+ }
343
+ const formatPathFormat = typeof responseFormat === "string" ? resolveAudioFormat(responseFormat, `response.format_path "${config.response.format_path}"`) : void 0;
344
+ const download = await fetchWithTimeout(audioUrl, { method: "GET" }, config.request.timeout_ms, "Custom TTS audio download");
345
+ if (!download.ok) throw await responseError(download, "Custom TTS audio download");
346
+ const downloadFormat = formatFromServerContentType(download.headers.get("content-type"), "Custom TTS audio download");
347
+ return finalAudio(Buffer.from(await download.arrayBuffer()), config.response, [
348
+ { value: downloadFormat, label: "download HTTP Content-Type" },
349
+ { value: formatPathFormat, label: `response.format_path "${config.response.format_path}"` }
350
+ ]);
351
+ }
352
+ async function synthesizeConfiguredTts(text, workspaceDir = getWorkspaceDir()) {
353
+ const config = loadCustomTtsConfig(workspaceDir);
354
+ if (!config) return null;
355
+ return synthesizeCustomTts(text, config);
356
+ }
357
+ export {
358
+ CustomTtsError,
359
+ loadCustomTtsConfig,
360
+ parseCustomTtsConfig,
361
+ synthesizeConfiguredTts,
362
+ synthesizeCustomTts
363
+ };
@@ -0,0 +1,44 @@
1
+ import { join } from "node:path";
2
+ import { setTimeout as delay } from "node:timers/promises";
3
+ import { getWorkspaceDir } from "./init-command.js";
4
+ import { getRuntimeDir } from "./user-data.js";
5
+ import { tryAcquireWorkspaceRuntimeLock } from "./workspace-runtime-lock.js";
6
+ import { readWorkspaceOwnerRecord, workspaceOwnerIdentity } from "../runtime/clawclaw/owner-lock.js";
7
+ import { readGameStartRuntime, sendOwnerControlRequestTo } from "../runtime/owner-control.js";
8
+ async function stopDesktopRuntime(timeoutMs = 1e4) {
9
+ const workspace = getWorkspaceDir();
10
+ const deadline = Date.now() + timeoutMs;
11
+ let target;
12
+ let stopSent = false;
13
+ do {
14
+ const guard = tryAcquireWorkspaceRuntimeLock(workspace);
15
+ if (guard) {
16
+ guard.release();
17
+ return;
18
+ }
19
+ const owner = readWorkspaceOwnerRecord(workspace);
20
+ if (owner) {
21
+ if (owner.workspace_id !== workspaceOwnerIdentity(workspace) || target !== void 0 && target !== owner.instance_id) {
22
+ throw new Error("Runtime changed while logging out. Retry from the client.");
23
+ }
24
+ target = owner.instance_id;
25
+ if (!stopSent) {
26
+ const pointer = readGameStartRuntime(join(getRuntimeDir(workspace), "accounts", owner.runtime_account_id));
27
+ if (pointer?.instance_id === target && pointer.owner_pid === owner.pid) {
28
+ const response = await sendOwnerControlRequestTo(
29
+ pointer,
30
+ "stop",
31
+ { instance_id: target },
32
+ Math.max(1, Math.min(1e3, deadline - Date.now()))
33
+ );
34
+ stopSent = response?.ok === true;
35
+ }
36
+ }
37
+ }
38
+ await delay(50);
39
+ } while (Date.now() < deadline);
40
+ throw new Error("Runtime did not stop in time. Login binding was retained; retry from the client.");
41
+ }
42
+ export {
43
+ stopDesktopRuntime
44
+ };
@@ -0,0 +1,12 @@
1
+ function isDesktopMode(env = process.env) {
2
+ return env.CLAWCLAW_IS_DESKTOP === "true";
3
+ }
4
+ const DESKTOP_LOGIN_MESSAGE = "\u8BF7\u5728\u5BA2\u6237\u7AEF\u767B\u5F55\u6E38\u620F\u8D26\u53F7\u3002CCL \u7684\u767B\u5F55\u8D26\u53F7\u7531\u5BA2\u6237\u7AEF\u7BA1\u7406\u3002";
5
+ function accountRequiredMessage(standaloneMessage) {
6
+ return isDesktopMode() ? DESKTOP_LOGIN_MESSAGE : standaloneMessage;
7
+ }
8
+ export {
9
+ DESKTOP_LOGIN_MESSAGE,
10
+ accountRequiredMessage,
11
+ isDesktopMode
12
+ };
@@ -0,0 +1,82 @@
1
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { getWorkspaceDir } from "./init-command.js";
3
+ import {
4
+ ensureUserDataLayout,
5
+ getUserDataDiagnosticsConfigFile
6
+ } from "./user-data.js";
7
+ const DIAGNOSTICS_LEVELS = ["errors", "telemetry", "full"];
8
+ const TOP_LEVEL_KEYS = /* @__PURE__ */ new Set(["level", "allow_upload", "capture"]);
9
+ function defaultDiagnosticsConfig() {
10
+ return {
11
+ level: "errors",
12
+ allow_upload: false
13
+ };
14
+ }
15
+ function record(value) {
16
+ return value && typeof value === "object" && !Array.isArray(value) ? value : null;
17
+ }
18
+ function parseDiagnosticsConfig(value) {
19
+ const root = record(value);
20
+ if (!root) throw new Error("user-data/diagnostics.json must contain a JSON object.");
21
+ const unknownKeys = Object.keys(root).filter((key) => !TOP_LEVEL_KEYS.has(key));
22
+ if (unknownKeys.length > 0) {
23
+ throw new Error(`Unknown user-data/diagnostics.json field: ${unknownKeys.join(", ")}`);
24
+ }
25
+ if (!DIAGNOSTICS_LEVELS.includes(root.level)) {
26
+ throw new Error("user-data/diagnostics.json level must be errors, telemetry, or full.");
27
+ }
28
+ if (typeof root.allow_upload !== "boolean") {
29
+ throw new Error("user-data/diagnostics.json allow_upload must be a boolean.");
30
+ }
31
+ let capture;
32
+ if (root.capture !== void 0) {
33
+ const value2 = record(root.capture);
34
+ if (!value2) throw new Error("diagnostics.capture must be an object.");
35
+ if (Object.keys(value2).some((key) => !["actions", "behavior_io", "perception_io", "max_record_bytes"].includes(key))) {
36
+ throw new Error("Unknown diagnostics.capture field.");
37
+ }
38
+ for (const key of ["actions", "behavior_io", "perception_io"]) {
39
+ if (value2[key] !== void 0 && typeof value2[key] !== "boolean") throw new Error(`diagnostics.capture.${key} must be boolean.`);
40
+ }
41
+ if (value2.max_record_bytes !== void 0 && (!Number.isInteger(value2.max_record_bytes) || Number(value2.max_record_bytes) < 4096 || Number(value2.max_record_bytes) > 4 * 1024 * 1024)) {
42
+ throw new Error("diagnostics.capture.max_record_bytes must be 4096..4194304.");
43
+ }
44
+ capture = value2;
45
+ }
46
+ return {
47
+ level: root.level,
48
+ allow_upload: root.allow_upload,
49
+ ...capture ? { capture } : {}
50
+ };
51
+ }
52
+ function writeDiagnosticsConfig(config, workspaceDir = getWorkspaceDir()) {
53
+ ensureUserDataLayout(workspaceDir);
54
+ const normalized = parseDiagnosticsConfig(config);
55
+ writeFileSync(
56
+ getUserDataDiagnosticsConfigFile(workspaceDir),
57
+ `${JSON.stringify(normalized, null, 2)}
58
+ `,
59
+ "utf8"
60
+ );
61
+ return normalized;
62
+ }
63
+ function readDiagnosticsConfig(workspaceDir = getWorkspaceDir()) {
64
+ ensureUserDataLayout(workspaceDir);
65
+ const path = getUserDataDiagnosticsConfigFile(workspaceDir);
66
+ if (!existsSync(path)) return writeDiagnosticsConfig(defaultDiagnosticsConfig(), workspaceDir);
67
+ try {
68
+ return parseDiagnosticsConfig(JSON.parse(readFileSync(path, "utf8")));
69
+ } catch (error) {
70
+ if (error instanceof SyntaxError) {
71
+ throw new Error(`Invalid JSON in ${path}: ${error.message}`);
72
+ }
73
+ throw error;
74
+ }
75
+ }
76
+ export {
77
+ DIAGNOSTICS_LEVELS,
78
+ defaultDiagnosticsConfig,
79
+ parseDiagnosticsConfig,
80
+ readDiagnosticsConfig,
81
+ writeDiagnosticsConfig
82
+ };