@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,16 @@
1
+ const TRIGGER_PLUGIN_API_VERSION = 4;
2
+ const MAX_TRIGGER_RUNTIME_MS = 12e4;
3
+ import {
4
+ hasValidClawclawResourceLocalizations,
5
+ resolveClawclawResourceMetadata
6
+ } from "../resource-metadata.js";
7
+ class ClawclawTrigger {
8
+ static manifest;
9
+ }
10
+ export {
11
+ ClawclawTrigger,
12
+ MAX_TRIGGER_RUNTIME_MS,
13
+ TRIGGER_PLUGIN_API_VERSION,
14
+ hasValidClawclawResourceLocalizations,
15
+ resolveClawclawResourceMetadata
16
+ };
@@ -0,0 +1,130 @@
1
+ import type {
2
+ BehaviorInputFieldSpec,
3
+ BehaviorReadApi,
4
+ } from '../behavior-plugin/index.js';
5
+ export type { StrategyMemory, StrategyMemoryValue } from '../strategy-memory.js';
6
+ import type {
7
+ GameEvent,
8
+ ObservationFrame,
9
+ } from '../module-input/index.js';
10
+ import type { ClawclawResourceLocalizations } from '../resource-metadata.js';
11
+
12
+ export const TRIGGER_PLUGIN_API_VERSION = 4 as const;
13
+ /** Hard upper bound for one Reflex activation, regardless of module or runtime override. */
14
+ export const MAX_TRIGGER_RUNTIME_MS = 120_000;
15
+
16
+ export {
17
+ hasValidClawclawResourceLocalizations,
18
+ resolveClawclawResourceMetadata,
19
+ } from '../resource-metadata.js';
20
+ export type {
21
+ ClawclawLocalizedResourceText,
22
+ ClawclawResolvedResourceMetadata,
23
+ ClawclawResourceLocalizations,
24
+ ClawclawResourceMetadata,
25
+ } from '../resource-metadata.js';
26
+ export type {
27
+ BehaviorInputFieldSpec,
28
+ BehaviorReadApi,
29
+ } from '../behavior-plugin/index.js';
30
+ export type {
31
+ BehaviorScope,
32
+ GameEvent,
33
+ GameState,
34
+ KnownPlayer,
35
+ ObservationFrame,
36
+ PlayerRef,
37
+ Position,
38
+ VisualCorpse,
39
+ VisualObservation,
40
+ VisualPlayer,
41
+ VisualPosition,
42
+ VisibleCorpse,
43
+ VisiblePlayer,
44
+ } from '../module-input/index.js';
45
+
46
+ /** How a matched Trigger becomes eligible to fire again. */
47
+ export type TriggerRearm = 'after_clear' | 'after_cooldown';
48
+
49
+ /**
50
+ * Statically readable description and safe defaults for one Trigger.
51
+ *
52
+ * `defaultReflexPriority` is only relative to other Reflex activations. It
53
+ * never changes the fixed Runtime control order of reflex > short > long.
54
+ */
55
+ export interface ClawclawTriggerManifest {
56
+ readonly apiVersion: typeof TRIGGER_PLUGIN_API_VERSION;
57
+ readonly id: string;
58
+ readonly name: string;
59
+ readonly description: string;
60
+ readonly localizations?: ClawclawResourceLocalizations;
61
+ /** Rule parameters delivered through TriggerInput.input. Every field needs a default. */
62
+ readonly inputs: readonly BehaviorInputFieldSpec[];
63
+ /** Backend-pushed Event types observed by this Trigger. Empty means frame-only. */
64
+ readonly consumes: readonly string[];
65
+ /** Default fixed Behavior binding; effective configuration may replace this binding. */
66
+ readonly defaultBehavior: string;
67
+ readonly defaultBehaviorInput: Readonly<Record<string, unknown>>;
68
+ /** Relative priority among Reflex activations only. */
69
+ readonly defaultReflexPriority: number;
70
+ readonly defaultCooldownMs: number;
71
+ readonly defaultRearm: TriggerRearm;
72
+ readonly defaultMaxRuntimeMs: number;
73
+ }
74
+
75
+ /**
76
+ * One immutable observation frame, backend-pushed Runtime Events, and configured rule
77
+ * parameters. Perception and Trigger receive the same frame independently;
78
+ * `events` never contains output from any Runtime computation plugin.
79
+ */
80
+ export interface TriggerInput<
81
+ TInput extends Readonly<Record<string, unknown>> = Readonly<Record<string, unknown>>,
82
+ > {
83
+ readonly cycle?: import('../module-input/index.js').ProcessingCycleInfo;
84
+ readonly frame: Readonly<ObservationFrame>;
85
+ readonly events: readonly Readonly<GameEvent>[];
86
+ readonly input: Readonly<TInput>;
87
+ }
88
+
89
+ export type TriggerResetReason =
90
+ | 'phase_changed'
91
+ | 'trajectory_gap'
92
+ | 'segment_ending'
93
+ | 'shutdown';
94
+
95
+ /** Read-only game queries plus private memory shared with the same resource's Behavior. */
96
+ export type TriggerReadApi = BehaviorReadApi;
97
+
98
+ /**
99
+ * One rule match. The target Behavior and Reflex priority deliberately do not
100
+ * appear here: Runtime takes both from the effective, already-authorized
101
+ * Trigger configuration.
102
+ */
103
+ export interface TriggerMatch {
104
+ readonly reason: string;
105
+ readonly evidence?: Readonly<Record<string, unknown>>;
106
+ /** Dynamic values merged over the configured default Behavior input. */
107
+ readonly behaviorInput?: Readonly<Record<string, unknown>>;
108
+ }
109
+
110
+ /** Public authoring surface for one rule; game writes remain Behavior Actions. */
111
+ export abstract class ClawclawTrigger<
112
+ TInput extends Readonly<Record<string, unknown>> = Readonly<Record<string, unknown>>,
113
+ > {
114
+ static readonly manifest?: ClawclawTriggerManifest;
115
+
116
+ abstract evaluate(
117
+ input: Readonly<TriggerInput<TInput>>,
118
+ api: TriggerReadApi,
119
+ ): TriggerMatch | void | Promise<TriggerMatch | void>;
120
+
121
+ /** Clears private cross-frame rule state at an observation boundary. */
122
+ reset?(reason: TriggerResetReason): void | Promise<void>;
123
+ }
124
+
125
+ export interface ClawclawTriggerClass<
126
+ TInput extends Readonly<Record<string, unknown>> = Readonly<Record<string, unknown>>,
127
+ > {
128
+ readonly manifest?: ClawclawTriggerManifest;
129
+ new(): ClawclawTrigger<TInput>;
130
+ }
@@ -0,0 +1,25 @@
1
+ var ActionErrorCode = /* @__PURE__ */ ((ActionErrorCode2) => {
2
+ ActionErrorCode2["TASK_ALREADY_COMPLETED"] = "task_already_completed";
3
+ ActionErrorCode2["TASK_NOT_ASSIGNED"] = "task_not_assigned_to_you";
4
+ ActionErrorCode2["TASK_ALREADY_IN_PROGRESS"] = "task_already_in_progress";
5
+ ActionErrorCode2["NO_SABOTAGE_COMPLETED"] = "no_sabotage_completed";
6
+ ActionErrorCode2["ROLE_CANNOT_KILL"] = "role_cannot_kill";
7
+ ActionErrorCode2["EMERGENCY_ALREADY_ACTIVE"] = "emergency_already_active";
8
+ ActionErrorCode2["ON_COOLDOWN"] = "on_cooldown";
9
+ ActionErrorCode2["TARGET_UNREACHABLE"] = "target_unreachable_or_too_far";
10
+ ActionErrorCode2["PATH_NOT_FOUND"] = "path_not_found";
11
+ ActionErrorCode2["INVALID_POSITION"] = "invalid_position_blocked";
12
+ return ActionErrorCode2;
13
+ })(ActionErrorCode || {});
14
+ var WsConnectionState = /* @__PURE__ */ ((WsConnectionState2) => {
15
+ WsConnectionState2["Disconnected"] = "disconnected";
16
+ WsConnectionState2["Connecting"] = "connecting";
17
+ WsConnectionState2["Connected"] = "connected";
18
+ WsConnectionState2["Reconnecting"] = "reconnecting";
19
+ WsConnectionState2["Switching"] = "switching";
20
+ return WsConnectionState2;
21
+ })(WsConnectionState || {});
22
+ export {
23
+ ActionErrorCode,
24
+ WsConnectionState
25
+ };
@@ -0,0 +1,165 @@
1
+ // ─── Spatial ───
2
+
3
+ export interface Position {
4
+ x: number;
5
+ y: number;
6
+ }
7
+
8
+ export interface MapRoom {
9
+ id: string;
10
+ x: number;
11
+ y: number;
12
+ }
13
+
14
+ // ─── WebSocket Events ───
15
+
16
+ export interface GameEvent {
17
+ type: string;
18
+ [key: string]: any;
19
+ }
20
+
21
+ // ─── Action Error Codes ───
22
+
23
+ export enum ActionErrorCode {
24
+ TASK_ALREADY_COMPLETED = 'task_already_completed',
25
+ TASK_NOT_ASSIGNED = 'task_not_assigned_to_you',
26
+ TASK_ALREADY_IN_PROGRESS = 'task_already_in_progress',
27
+ NO_SABOTAGE_COMPLETED = 'no_sabotage_completed',
28
+ ROLE_CANNOT_KILL = 'role_cannot_kill',
29
+ EMERGENCY_ALREADY_ACTIVE = 'emergency_already_active',
30
+ /** 动作撞上服务端冷却;具体冷却语义由 action 类型决定。 */
31
+ ON_COOLDOWN = 'on_cooldown',
32
+ TARGET_UNREACHABLE = 'target_unreachable_or_too_far',
33
+ PATH_NOT_FOUND = 'path_not_found',
34
+ INVALID_POSITION = 'invalid_position_blocked',
35
+ }
36
+
37
+ // ─── WebSocket Connection State ───
38
+
39
+ export enum WsConnectionState {
40
+ Disconnected = 'disconnected',
41
+ Connecting = 'connecting',
42
+ Connected = 'connected',
43
+ Reconnecting = 'reconnecting',
44
+ Switching = 'switching',
45
+ }
46
+
47
+ // ─── Phase ───
48
+
49
+ export type Phase = 'preparing' | 'wandering' | 'meeting' | 'game_over';
50
+ export type MeetingSubPhase = 'entry' | 'speech' | 'vote';
51
+
52
+ // ─── Game State ───
53
+
54
+ export interface PlayerSelf {
55
+ name: string;
56
+ x: number;
57
+ y: number;
58
+ room: string;
59
+ seat?: number;
60
+ role: string;
61
+ faction: string;
62
+ is_alive: boolean;
63
+ kill_cooldown_secs?: number;
64
+ kills_remaining?: number | null;
65
+ currently_moving?: boolean;
66
+ remaining_secs?: number;
67
+ doing_task?: boolean;
68
+ task_name?: string;
69
+ crab_teammates?: Array<{ seat: number; name: string }>;
70
+ }
71
+
72
+ export interface PlayerInfo {
73
+ name: string;
74
+ seat?: number;
75
+ x: number;
76
+ y: number;
77
+ room: string;
78
+ distance?: number;
79
+ }
80
+
81
+ export interface CorpseInfo {
82
+ name: string;
83
+ seat?: number;
84
+ room: string;
85
+ distance?: number;
86
+ x?: number;
87
+ y?: number;
88
+ }
89
+
90
+ export interface MeetingState {
91
+ caller: string | null;
92
+ sub_phase: MeetingSubPhase;
93
+ alive_players: string[];
94
+ current_speaker?: string | null;
95
+ speeches_so_far?: Record<string, string>;
96
+ speeches?: Record<string, string>;
97
+ votes_submitted?: string[];
98
+ }
99
+
100
+ export interface TaskInfo {
101
+ task_id: string;
102
+ task_name: string;
103
+ room: string;
104
+ status: string;
105
+ x?: number;
106
+ y?: number;
107
+ is_fake_shrimp?: boolean;
108
+ faction?: 'lobster' | 'crab';
109
+ }
110
+
111
+ /**
112
+ * 全局任务站点(map 的 all_task_locations):所有玩家共享、开局固定的任务点位置。与 `your_tasks` /
113
+ * `StrategyContext.taskData`(仅自己被分配、带 status)不同——这里只有位置,没有 status。
114
+ * faction='lobster' 是正常任务点,'crab' 是破坏点。
115
+ */
116
+ export interface TaskLocation {
117
+ name: string;
118
+ room?: string;
119
+ x: number;
120
+ y: number;
121
+ faction?: 'lobster' | 'crab';
122
+ }
123
+
124
+ export interface EmergencyInfo extends TaskInfo {
125
+ remaining_secs: number;
126
+ }
127
+
128
+ export interface GameState {
129
+ phase: Phase;
130
+ tick: number;
131
+ you: PlayerSelf;
132
+ /** Omitted when GameSync has not supplied an authoritative current task list. */
133
+ your_tasks?: TaskInfo[];
134
+ players: PlayerInfo[];
135
+ corpses: CorpseInfo[];
136
+ emergency?: EmergencyInfo;
137
+ /** 服务端下发的「已知存活人数」:存活者 + 本玩家尚未目睹其死亡者之和。残局抢修紧急任务的门槛。 */
138
+ alive_count?: number;
139
+ task_progress?: { completed: number; goal: number };
140
+ new_events?: Array<Record<string, any>>;
141
+ stale: boolean;
142
+ meeting?: MeetingState;
143
+ winner?: string | null;
144
+ win_reason?: string;
145
+ all_players?: Array<{ name: string; role: string; is_alive: boolean; seat: number }>;
146
+ settlement?: Record<string, any>;
147
+ game_id?: string;
148
+ last_ejected?: string | null;
149
+ last_votes?: Record<string, string>;
150
+ [key: string]: any;
151
+ }
152
+
153
+ // ─── Review ───
154
+
155
+ export interface GameResult {
156
+ gameId: string;
157
+ won: boolean;
158
+ role: string;
159
+ faction: string;
160
+ winner: string;
161
+ winReason: string;
162
+ survivedToEnd: boolean;
163
+ totalTicks: number;
164
+ allPlayers: Array<{ name: string; role: string; is_alive: boolean; seat: number }>;
165
+ }
@@ -0,0 +1,129 @@
1
+ import {
2
+ isHttpSuccess
3
+ } from "./transport-response.js";
4
+ function isObjectRoot(value) {
5
+ return !!value && typeof value === "object" && !Array.isArray(value);
6
+ }
7
+ function valueAtPath(root, path) {
8
+ let current = root;
9
+ for (const part of path) {
10
+ if (typeof part === "number") {
11
+ if (!Array.isArray(current) || part < 0 || part >= current.length) {
12
+ return { exists: false, value: void 0 };
13
+ }
14
+ current = current[part];
15
+ continue;
16
+ }
17
+ if (!current || typeof current !== "object" || !Object.prototype.hasOwnProperty.call(current, part)) {
18
+ return { exists: false, value: void 0 };
19
+ }
20
+ current = current[part];
21
+ }
22
+ return { exists: true, value: current };
23
+ }
24
+ function matchesPredicate(actual, predicate) {
25
+ switch (predicate.operator) {
26
+ case "equals":
27
+ return actual.exists && Object.is(actual.value, predicate.value);
28
+ case "one_of":
29
+ return actual.exists && predicate.values.some((value) => Object.is(actual.value, value));
30
+ case "exists":
31
+ return actual.exists === (predicate.value ?? true);
32
+ case "truthy":
33
+ return actual.exists && !!actual.value;
34
+ case "falsy":
35
+ return actual.exists && !actual.value;
36
+ }
37
+ }
38
+ function matchesCondition(root, condition) {
39
+ return matchesPredicate(valueAtPath(root, condition.path), condition.predicate);
40
+ }
41
+ function matchesRule(root, rule) {
42
+ const conditions = Array.isArray(rule.when) ? rule.when : [rule.when];
43
+ return rule.match === "any" ? conditions.some((condition) => matchesCondition(root, condition)) : conditions.every((condition) => matchesCondition(root, condition));
44
+ }
45
+ function missingRequiredPath(root, paths) {
46
+ return paths?.find((path) => !valueAtPath(root, path).exists);
47
+ }
48
+ function printablePath(path) {
49
+ return path.map((part, index) => typeof part === "number" ? `[${part}]` : `${index === 0 ? "" : "."}${part}`).join("");
50
+ }
51
+ class ResponseClassifier {
52
+ classify(response, contract) {
53
+ if (response.body.kind !== "json") {
54
+ return {
55
+ kind: "protocol_failure",
56
+ response,
57
+ reason: response.body.kind === "empty" ? "empty_response_body" : "non_json_response_body"
58
+ };
59
+ }
60
+ if (!isObjectRoot(response.body.value)) {
61
+ return {
62
+ kind: "protocol_failure",
63
+ response,
64
+ reason: "json_root_must_be_object"
65
+ };
66
+ }
67
+ const root = response.body.value;
68
+ if (Object.prototype.hasOwnProperty.call(root, "_ccl")) {
69
+ return {
70
+ kind: "protocol_failure",
71
+ response,
72
+ reason: "reserved_field_conflict:_ccl"
73
+ };
74
+ }
75
+ if (!isHttpSuccess(response)) {
76
+ return { kind: "backend_failure", response, upstreamRoot: root };
77
+ }
78
+ const matched = contract.rules?.find((rule) => matchesRule(root, rule));
79
+ if (matched) {
80
+ if (matched.outcome === "failure") {
81
+ return {
82
+ kind: "backend_failure",
83
+ response,
84
+ upstreamRoot: root,
85
+ guidance: matched.guidance
86
+ };
87
+ }
88
+ if (matched.outcome === "partial") {
89
+ return {
90
+ kind: "partial",
91
+ response,
92
+ upstreamRoot: root,
93
+ guidance: matched.guidance
94
+ };
95
+ }
96
+ const missing = missingRequiredPath(root, contract.requiredSuccessPaths);
97
+ if (missing) {
98
+ return {
99
+ kind: "protocol_failure",
100
+ response,
101
+ upstreamRoot: root,
102
+ reason: `missing_required_success_field:${printablePath(missing)}`
103
+ };
104
+ }
105
+ return { kind: "success", response, upstreamRoot: root, guidance: matched.guidance };
106
+ }
107
+ if (contract.default2xxOutcome === "success") {
108
+ const missing = missingRequiredPath(root, contract.requiredSuccessPaths);
109
+ if (missing) {
110
+ return {
111
+ kind: "protocol_failure",
112
+ response,
113
+ upstreamRoot: root,
114
+ reason: `missing_required_success_field:${printablePath(missing)}`
115
+ };
116
+ }
117
+ return { kind: "success", response, upstreamRoot: root };
118
+ }
119
+ return {
120
+ kind: "protocol_failure",
121
+ response,
122
+ upstreamRoot: root,
123
+ reason: `unclassified_response:${contract.id}`
124
+ };
125
+ }
126
+ }
127
+ export {
128
+ ResponseClassifier
129
+ };
@@ -0,0 +1,7 @@
1
+ export * from "./types.js";
2
+ export * from "./transport-response.js";
3
+ export * from "./response-contract.js";
4
+ export * from "./classifier.js";
5
+ export * from "./sensitive-data-filter.js";
6
+ export * from "./presenter.js";
7
+ export * from "./runner.js";
@@ -0,0 +1,225 @@
1
+ import { randomUUID } from "crypto";
2
+ import { SensitiveDataFilter } from "./sensitive-data-filter.js";
3
+ function cloneObject(value) {
4
+ return JSON.parse(JSON.stringify(value));
5
+ }
6
+ function guidanceFor(classifiedGuidance, overrides) {
7
+ return Object.prototype.hasOwnProperty.call(overrides, "guidance") ? overrides.guidance ?? null : classifiedGuidance ?? null;
8
+ }
9
+ function statusFor(classification) {
10
+ if (classification === "success") return "success";
11
+ if (classification === "partial") return "partial";
12
+ return "failure";
13
+ }
14
+ function sourceFor(classification) {
15
+ return classification === "protocol_failure" ? "protocol" : "backend";
16
+ }
17
+ class ShortCommandPresenter {
18
+ filter;
19
+ diagnosticIdFactory;
20
+ exitCodes;
21
+ constructor(options = {}) {
22
+ this.filter = options.filter ?? new SensitiveDataFilter();
23
+ this.diagnosticIdFactory = options.diagnosticIdFactory ?? (() => `diag_${randomUUID()}`);
24
+ this.exitCodes = {
25
+ success: options.exitCodes?.success ?? 0,
26
+ partial: options.exitCodes?.partial ?? 2,
27
+ failure: options.exitCodes?.failure ?? 1
28
+ };
29
+ }
30
+ presentBackend(classified, context, overrides = {}) {
31
+ const status = statusFor(classified.kind);
32
+ let root = classified.upstreamRoot ? cloneObject(classified.upstreamRoot) : void 0;
33
+ if (classified.kind === "success" && root) {
34
+ if (overrides.projectSuccess) root = overrides.projectSuccess(cloneObject(root));
35
+ if (overrides.enhanceSuccess) {
36
+ root = { ...root, ...overrides.enhanceSuccess(cloneObject(root)) };
37
+ }
38
+ if (Object.prototype.hasOwnProperty.call(root, "_ccl")) {
39
+ return this.presentLocalFailure(
40
+ {
41
+ code: "RESERVED_FIELD_CONFLICT",
42
+ message: "The successful command projection used the reserved _ccl field."
43
+ },
44
+ "protocol",
45
+ context,
46
+ { guidance: overrides.guidance }
47
+ );
48
+ }
49
+ }
50
+ if (!root) {
51
+ const diagnosticId = context.diagnosticId ?? this.diagnosticIdFactory();
52
+ return this.presentLocalFailure(
53
+ {
54
+ code: "PROTOCOL_ERROR",
55
+ message: "The upstream response could not be represented safely."
56
+ },
57
+ "protocol",
58
+ { ...context, diagnosticId },
59
+ {
60
+ ...overrides,
61
+ guidance: guidanceFor(classified.guidance, overrides)
62
+ },
63
+ classified.reason
64
+ );
65
+ }
66
+ const filtered = this.filter.filter(root, {
67
+ status,
68
+ policy: context.descriptor.sensitivePolicy
69
+ });
70
+ const meta = this.buildMeta({
71
+ context,
72
+ status,
73
+ source: sourceFor(classified.kind),
74
+ filteredFields: filtered.filteredFields,
75
+ guidance: guidanceFor(classified.guidance, overrides),
76
+ httpStatus: classified.response.status,
77
+ requestId: classified.response.requestId,
78
+ reason: classified.reason,
79
+ overrides
80
+ });
81
+ return this.finish(filtered.value, meta, status);
82
+ }
83
+ /**
84
+ * Present an owner-adapted backend result without moving the upstream root.
85
+ * This is used when an owner ActionService has already classified a
86
+ * multi-process result and the CLI no longer owns the original Response.
87
+ */
88
+ presentBackendOutcome(upstreamRoot, status, context, overrides = {}, response) {
89
+ if (Object.prototype.hasOwnProperty.call(upstreamRoot, "_ccl")) {
90
+ return this.presentLocalFailure(
91
+ {
92
+ code: "RESERVED_FIELD_CONFLICT",
93
+ message: "The backend result used the reserved _ccl field."
94
+ },
95
+ "protocol",
96
+ context
97
+ );
98
+ }
99
+ let root = cloneObject(upstreamRoot);
100
+ if (status === "success" && overrides.projectSuccess) root = overrides.projectSuccess(cloneObject(root));
101
+ if (status === "success" && overrides.enhanceSuccess) {
102
+ root = { ...root, ...overrides.enhanceSuccess(cloneObject(root)) };
103
+ }
104
+ if (Object.prototype.hasOwnProperty.call(root, "_ccl")) {
105
+ return this.presentLocalFailure(
106
+ {
107
+ code: "RESERVED_FIELD_CONFLICT",
108
+ message: "The successful command projection used the reserved _ccl field."
109
+ },
110
+ "protocol",
111
+ context
112
+ );
113
+ }
114
+ const filtered = this.filter.filter(root, {
115
+ status,
116
+ policy: context.descriptor.sensitivePolicy
117
+ });
118
+ const meta = this.buildMeta({
119
+ context,
120
+ status,
121
+ source: "backend",
122
+ filteredFields: filtered.filteredFields,
123
+ guidance: overrides.guidance ?? null,
124
+ httpStatus: response?.status,
125
+ requestId: response?.requestId,
126
+ overrides
127
+ });
128
+ return this.finish(filtered.value, meta, status);
129
+ }
130
+ presentLocalSuccess(value, source, context, overrides = {}) {
131
+ return this.presentLocalOutcome(value, "success", source, context, overrides);
132
+ }
133
+ presentLocalOutcome(value, status, source, context, overrides = {}, reason) {
134
+ if (Object.prototype.hasOwnProperty.call(value, "_ccl")) {
135
+ return this.presentLocalFailure(
136
+ {
137
+ code: "RESERVED_FIELD_CONFLICT",
138
+ message: "The command result used the reserved _ccl field."
139
+ },
140
+ "protocol",
141
+ context
142
+ );
143
+ }
144
+ let projected = cloneObject(value);
145
+ if (status === "success" && overrides.projectSuccess) projected = overrides.projectSuccess(cloneObject(projected));
146
+ if (status === "success" && overrides.enhanceSuccess) {
147
+ projected = { ...projected, ...overrides.enhanceSuccess(cloneObject(projected)) };
148
+ }
149
+ if (Object.prototype.hasOwnProperty.call(projected, "_ccl")) {
150
+ return this.presentLocalFailure(
151
+ {
152
+ code: "RESERVED_FIELD_CONFLICT",
153
+ message: "The successful command projection used the reserved _ccl field."
154
+ },
155
+ "protocol",
156
+ context
157
+ );
158
+ }
159
+ const filtered = this.filter.filter(projected, {
160
+ status,
161
+ policy: context.descriptor.sensitivePolicy
162
+ });
163
+ const meta = this.buildMeta({
164
+ context,
165
+ status,
166
+ source,
167
+ filteredFields: filtered.filteredFields,
168
+ guidance: overrides.guidance ?? null,
169
+ reason,
170
+ overrides
171
+ });
172
+ return this.finish(filtered.value, meta, status);
173
+ }
174
+ presentLocalFailure(error, source, context, overrides = {}, reason) {
175
+ const root = {
176
+ success: false,
177
+ error: {
178
+ code: error.code,
179
+ message: error.message,
180
+ ...error.details === void 0 ? {} : { details: error.details }
181
+ }
182
+ };
183
+ const filtered = this.filter.filter(root, {
184
+ status: "failure",
185
+ policy: context.descriptor.sensitivePolicy
186
+ });
187
+ const meta = this.buildMeta({
188
+ context,
189
+ status: "failure",
190
+ source,
191
+ filteredFields: filtered.filteredFields,
192
+ guidance: overrides.guidance ?? null,
193
+ reason,
194
+ diagnosticId: context.diagnosticId,
195
+ overrides
196
+ });
197
+ return this.finish(filtered.value, meta, "failure");
198
+ }
199
+ buildMeta(input) {
200
+ return {
201
+ schema: "ccl.command-meta.v1",
202
+ command_id: input.context.commandId,
203
+ command: input.context.descriptor.command,
204
+ command_status: input.status,
205
+ source: input.source,
206
+ service: input.context.descriptor.service,
207
+ operation: input.context.descriptor.operation,
208
+ http_status: input.httpStatus,
209
+ request_id: input.requestId,
210
+ diagnostic_id: input.diagnosticId,
211
+ reason: input.reason,
212
+ failed_effect: input.overrides.failedEffect,
213
+ filtered_fields: input.filteredFields,
214
+ effects: input.overrides.effects,
215
+ guidance: input.guidance
216
+ };
217
+ }
218
+ finish(root, meta, status) {
219
+ const value = { ...root, _ccl: meta };
220
+ return { value, status, exitCode: this.exitCodes[status] };
221
+ }
222
+ }
223
+ export {
224
+ ShortCommandPresenter
225
+ };