@myclaw163/clawclaw-cli 0.8.3 → 0.8.5

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 (264) hide show
  1. package/README.md +4 -3
  2. package/docs/configuration.md +44 -26
  3. package/docs/custom-modules/README.md +7 -10
  4. package/docs/custom-modules/api-reference.md +3 -7
  5. package/docs/custom-modules/behavior.md +6 -4
  6. package/docs/custom-modules/perception.md +1 -1
  7. package/docs/custom-modules/trigger.md +1 -1
  8. package/docs/runtime/README.md +4 -4
  9. package/docs/runtime/official-perception-modules.md +2 -2
  10. package/docs/runtime/owner-lifecycle-and-observability.md +1 -1
  11. package/package.json +9 -2
  12. package/scripts/build-official-hub-behaviors.mjs +136 -0
  13. package/scripts/build-official-hub-behaviors.test.mjs +178 -0
  14. package/scripts/enable_ccl_permissions.cjs +4 -2
  15. package/scripts/enable_ccl_permissions.test.mjs +8 -4
  16. package/scripts/postinstall.mjs +1 -4
  17. package/scripts/sync-bundled-skill.mjs +12 -159
  18. package/scripts/sync-bundled-skill.test.mjs +9 -74
  19. package/skills/clawclaw/SKILL.md +18 -13
  20. package/skills/clawclaw/references/BEHAVIORS.md +4 -4
  21. package/skills/clawclaw/references/COMMANDS.md +33 -18
  22. package/skills/clawclaw/references/GAME-MECHANICS.md +16 -18
  23. package/skills/clawclaw/references/HUB.md +25 -38
  24. package/skills/clawclaw/references/STREAM.md +9 -11
  25. package/src/behaviors/official-finite/do-task.ts +70 -0
  26. package/src/behaviors/official-finite/index.ts +0 -3
  27. package/src/commands/account.ts +58 -14
  28. package/src/commands/behavior.ts +116 -38
  29. package/src/commands/hub.ts +110 -153
  30. package/src/commands/load.ts +138 -33
  31. package/src/commands/perception.ts +55 -24
  32. package/src/commands/persona.ts +66 -20
  33. package/src/commands/skill.ts +12 -48
  34. package/src/commands/trigger.ts +68 -40
  35. package/src/hub-official-behaviors/kill-lone.ts +138 -0
  36. package/src/hub-official-behaviors/patrol.ts +30 -0
  37. package/src/hub-official-behaviors/shared.ts +125 -0
  38. package/src/hub-official-behaviors/task-only.ts +158 -0
  39. package/src/lib/account-guidance.ts +54 -9
  40. package/src/lib/agent-workspace-client.ts +135 -0
  41. package/src/lib/agent-workspace-runtime.ts +154 -0
  42. package/src/lib/agent-workspace-skills.ts +177 -0
  43. package/src/lib/agent-workspace-sync.ts +852 -0
  44. package/src/lib/gameplay-config.ts +29 -15
  45. package/src/lib/hub-client.ts +252 -34
  46. package/src/lib/hub-reminder.ts +22 -7
  47. package/src/lib/init-command.ts +0 -6
  48. package/src/lib/load-context.ts +12 -6
  49. package/src/lib/persona.ts +141 -69
  50. package/src/lib/server-status.ts +78 -0
  51. package/src/lib/skill-host.ts +160 -0
  52. package/src/lib/user-data.ts +197 -4
  53. package/src/pipeline/event-format.ts +20 -4
  54. package/src/pipeline/event-hints.ts +20 -6
  55. package/src/pipeline/game-sync-event-normalization.ts +9 -0
  56. package/src/pipeline/role-display.ts +22 -0
  57. package/src/runtime/clawclaw/agent-ability-state.ts +1 -21
  58. package/src/runtime/clawclaw/agent-event-policy.ts +1 -0
  59. package/src/runtime/clawclaw/owner.ts +63 -19
  60. package/src/runtime/clawclaw/plugins/action/action-plugin.ts +8 -1
  61. package/src/runtime/clawclaw/plugins/action/automated-action-normalization.ts +0 -1
  62. package/src/runtime/clawclaw/plugins/behavior/activation-manager.ts +8 -2
  63. package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +2 -2
  64. package/src/runtime/clawclaw/plugins/behavior/official-goal-behavior.ts +0 -9
  65. package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +4 -1
  66. package/src/runtime/clawclaw/plugins/perception/perception-source.ts +11 -5
  67. package/src/runtime/clawclaw/plugins/perception/replay.ts +0 -2
  68. package/src/runtime/clawclaw-event-catalog.ts +2 -0
  69. package/src/runtime/framework/action-diagnostics.ts +1 -0
  70. package/src/runtime/framework/modules/runtime-module-loader.ts +0 -1
  71. package/src/sdk/action.ts +8 -6
  72. package/src/sdk/behavior-plugin/index.ts +1 -2
  73. package/src/sdk/behavior-toolkit/model.ts +2 -0
  74. package/src/sdk/module-input/index.ts +0 -2
  75. package/src/strategies/goals/crab-sabotage-top.ts +5 -61
  76. package/src/strategies/types.ts +0 -6
  77. package/personas//345/217/243/346/230/257/345/277/203/351/235/236.md +0 -50
  78. package/personas//345/277/240/345/277/203/350/200/201/344/273/206.md +0 -51
  79. package/personas//346/227/240/344/272/272/350/256/276.md +0 -1
  80. package/personas//350/264/253/345/230/264/346/215/237/345/217/213.md +0 -48
  81. package/personas//350/275/257/350/220/214/350/205/271/351/273/221.md +0 -51
  82. package/src/behaviors/official-finite/index.test.ts +0 -202
  83. package/src/behaviors/official-finite/trigger-alarm.ts +0 -53
  84. package/src/channel/claude-channel-server.test.ts +0 -202
  85. package/src/commands/account.test.ts +0 -570
  86. package/src/commands/behavior.test.ts +0 -158
  87. package/src/commands/communication.test.ts +0 -282
  88. package/src/commands/competition.test.ts +0 -116
  89. package/src/commands/data.test.ts +0 -89
  90. package/src/commands/events-canonical-state.test.ts +0 -406
  91. package/src/commands/events.test.ts +0 -58
  92. package/src/commands/game/index.test.ts +0 -1251
  93. package/src/commands/game-map.test.ts +0 -69
  94. package/src/commands/hub.test.ts +0 -124
  95. package/src/commands/load.test.ts +0 -440
  96. package/src/commands/perception.test.ts +0 -75
  97. package/src/commands/setup/hermes.test.ts +0 -96
  98. package/src/commands/setup/openclaw.test.ts +0 -124
  99. package/src/commands/trigger.test.ts +0 -140
  100. package/src/commands/upgrade.test.ts +0 -82
  101. package/src/lib/account-guidance.test.ts +0 -36
  102. package/src/lib/auth.test.ts +0 -151
  103. package/src/lib/behavior-export.test.ts +0 -282
  104. package/src/lib/behavior-export.ts +0 -514
  105. package/src/lib/clawclaw-skill-spectate-guidance.test.ts +0 -21
  106. package/src/lib/custom-tts.test.ts +0 -387
  107. package/src/lib/diagnostics-config.test.ts +0 -59
  108. package/src/lib/game-client-tts.test.ts +0 -151
  109. package/src/lib/game-client.test.ts +0 -250
  110. package/src/lib/gameplay-config.test.ts +0 -301
  111. package/src/lib/host-config-patcher.test.ts +0 -130
  112. package/src/lib/http-transport.test.ts +0 -124
  113. package/src/lib/hub-client.test.ts +0 -57
  114. package/src/lib/hub-install.test.ts +0 -135
  115. package/src/lib/hub-install.ts +0 -185
  116. package/src/lib/hub-unzip.test.ts +0 -69
  117. package/src/lib/init-command.test.ts +0 -103
  118. package/src/lib/load-context.test.ts +0 -62
  119. package/src/lib/match-state.test.ts +0 -134
  120. package/src/lib/official-resource-sync.test.ts +0 -199
  121. package/src/lib/official-resource-sync.ts +0 -221
  122. package/src/lib/perception-config.test.ts +0 -143
  123. package/src/lib/perception-export.test.ts +0 -145
  124. package/src/lib/perception-export.ts +0 -178
  125. package/src/lib/persona.test.ts +0 -84
  126. package/src/lib/room.test.ts +0 -88
  127. package/src/lib/server-registry.test.ts +0 -64
  128. package/src/lib/service-status.test.ts +0 -81
  129. package/src/lib/skill-version.test.ts +0 -48
  130. package/src/lib/trigger-config.test.ts +0 -102
  131. package/src/lib/trigger-export.test.ts +0 -80
  132. package/src/lib/trigger-export.ts +0 -210
  133. package/src/lib/user-data.test.ts +0 -121
  134. package/src/lib/workspace-argv.test.ts +0 -49
  135. package/src/pipeline/canonical-event-presentation.test.ts +0 -255
  136. package/src/pipeline/event-format.test.ts +0 -828
  137. package/src/pipeline/event-hints.test.ts +0 -316
  138. package/src/pipeline/game-sync-event-normalization.test.ts +0 -371
  139. package/src/pipeline/player-projection.test.ts +0 -247
  140. package/src/runtime/auto-upgrade.test.ts +0 -66
  141. package/src/runtime/canonical-event-emitter.test.ts +0 -70
  142. package/src/runtime/canonical-monitor.test.ts +0 -577
  143. package/src/runtime/clawclaw/agent-event-policy.test.ts +0 -58
  144. package/src/runtime/clawclaw/behavior-decision.test.ts +0 -43
  145. package/src/runtime/clawclaw/behavior-input-fields.test.ts +0 -175
  146. package/src/runtime/clawclaw/behavior-input.test.ts +0 -173
  147. package/src/runtime/clawclaw/behavior-observation-memory.test.ts +0 -59
  148. package/src/runtime/clawclaw/behavior-read-api.test.ts +0 -123
  149. package/src/runtime/clawclaw/notifications.test.ts +0 -47
  150. package/src/runtime/clawclaw/owner-lock.test.ts +0 -221
  151. package/src/runtime/clawclaw/owner.test.ts +0 -203
  152. package/src/runtime/clawclaw/plugins/action/action-plugin.test.ts +0 -304
  153. package/src/runtime/clawclaw/plugins/assembly.test.ts +0 -200
  154. package/src/runtime/clawclaw/plugins/behavior/activation-manager.test.ts +0 -180
  155. package/src/runtime/clawclaw/plugins/behavior/behavior-action.test.ts +0 -40
  156. package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.test.ts +0 -156
  157. package/src/runtime/clawclaw/plugins/behavior/behavior-module-loader.test.ts +0 -182
  158. package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.test.ts +0 -1094
  159. package/src/runtime/clawclaw/plugins/behavior/behavior-source.test.ts +0 -174
  160. package/src/runtime/clawclaw/plugins/behavior/control-driver.test.ts +0 -195
  161. package/src/runtime/clawclaw/plugins/behavior/thread-behavior-executor.test.ts +0 -283
  162. package/src/runtime/clawclaw/plugins/behavior-input-source.test.ts +0 -80
  163. package/src/runtime/clawclaw/plugins/derived-event/derived-event-plugin.test.ts +0 -267
  164. package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.test.ts +0 -226
  165. package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-adapter.test.ts +0 -239
  166. package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.test.ts +0 -407
  167. package/src/runtime/clawclaw/plugins/mailbox/desktop-event-push.integration.test.ts +0 -397
  168. package/src/runtime/clawclaw/plugins/mailbox/desktop-event-socket.test.ts +0 -270
  169. package/src/runtime/clawclaw/plugins/mailbox/mailbox-agent-event-batch.test.ts +0 -166
  170. package/src/runtime/clawclaw/plugins/mailbox/mailbox-event-batch-delivery.test.ts +0 -194
  171. package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.test.ts +0 -87
  172. package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.test.ts +0 -2012
  173. package/src/runtime/clawclaw/plugins/perception/module-runner.test.ts +0 -214
  174. package/src/runtime/clawclaw/plugins/perception/modules/co-movement-module.ts +0 -347
  175. package/src/runtime/clawclaw/plugins/perception/modules/corpse-visibility-module.test.ts +0 -92
  176. package/src/runtime/clawclaw/plugins/perception/modules/corpse-visibility-module.ts +0 -248
  177. package/src/runtime/clawclaw/plugins/perception/modules/follow-module.ts +0 -389
  178. package/src/runtime/clawclaw/plugins/perception/modules/index.ts +0 -8
  179. package/src/runtime/clawclaw/plugins/perception/modules/motion-module.test.ts +0 -342
  180. package/src/runtime/clawclaw/plugins/perception/modules/motion-module.ts +0 -475
  181. package/src/runtime/clawclaw/plugins/perception/modules/parallel-module-test-helpers.ts +0 -30
  182. package/src/runtime/clawclaw/plugins/perception/modules/relation-stability.test.ts +0 -304
  183. package/src/runtime/clawclaw/plugins/perception/modules/route-module.test.ts +0 -179
  184. package/src/runtime/clawclaw/plugins/perception/modules/route-module.ts +0 -364
  185. package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.test.ts +0 -81
  186. package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.ts +0 -200
  187. package/src/runtime/clawclaw/plugins/perception/modules/stop-module.test.ts +0 -216
  188. package/src/runtime/clawclaw/plugins/perception/modules/stop-module.ts +0 -284
  189. package/src/runtime/clawclaw/plugins/perception/modules/temporal-evidence.test.ts +0 -120
  190. package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.test.ts +0 -105
  191. package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.ts +0 -269
  192. package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.test.ts +0 -865
  193. package/src/runtime/clawclaw/plugins/perception/perception-plugin.test.ts +0 -1878
  194. package/src/runtime/clawclaw/plugins/perception/perception-source.test.ts +0 -278
  195. package/src/runtime/clawclaw/plugins/perception/replay.test.ts +0 -77
  196. package/src/runtime/clawclaw/plugins/runtime-plugins.test.ts +0 -854
  197. package/src/runtime/clawclaw/plugins/source/game-transport.test.ts +0 -287
  198. package/src/runtime/clawclaw/plugins/source/player-change-tracker.test.ts +0 -321
  199. package/src/runtime/clawclaw/plugins/source/room-transport.test.ts +0 -307
  200. package/src/runtime/clawclaw/plugins/source/source-plugin.test.ts +0 -2646
  201. package/src/runtime/clawclaw/plugins/source/task-change-tracker.test.ts +0 -212
  202. package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.test.ts +0 -548
  203. package/src/runtime/clawclaw/plugins/trigger/trigger-source.test.ts +0 -169
  204. package/src/runtime/clawclaw/runtime-data-export.test.ts +0 -249
  205. package/src/runtime/clawclaw-event-catalog.test.ts +0 -126
  206. package/src/runtime/framework/action-diagnostics.test.ts +0 -81
  207. package/src/runtime/framework/capability-registry.test.ts +0 -423
  208. package/src/runtime/framework/control-coordinator.test.ts +0 -675
  209. package/src/runtime/framework/events/event-delivery-service.test.ts +0 -84
  210. package/src/runtime/framework/events/event-ingress.test.ts +0 -203
  211. package/src/runtime/framework/events/mailbox-event-repositories.test.ts +0 -710
  212. package/src/runtime/framework/events/sqlite-event-repository.test.ts +0 -802
  213. package/src/runtime/framework/mailbox/coalescer.test.ts +0 -55
  214. package/src/runtime/framework/mailbox/identity.test.ts +0 -38
  215. package/src/runtime/framework/mailbox/mailbox-dispatcher.test.ts +0 -513
  216. package/src/runtime/framework/mailbox/notification-projector.test.ts +0 -77
  217. package/src/runtime/framework/modules/runtime-module-loader.test.ts +0 -435
  218. package/src/runtime/framework/participation-manager.test.ts +0 -108
  219. package/src/runtime/framework/plugins/runtime-input-journal.test.ts +0 -179
  220. package/src/runtime/framework/plugins/runtime-plugin-scheduler.test.ts +0 -2040
  221. package/src/runtime/framework/state/durable-agent-state-snapshot.test.ts +0 -144
  222. package/src/runtime/framework/state/history/sqlite-state-history-repository.test.ts +0 -157
  223. package/src/runtime/framework/state/history/state-history.test.ts +0 -251
  224. package/src/runtime/framework/state/state-core.test.ts +0 -197
  225. package/src/runtime/game-sync-protocol.test.ts +0 -123
  226. package/src/runtime/host-monitor-rate-gate.test.ts +0 -73
  227. package/src/runtime/mailbox-host-relay.test.ts +0 -293
  228. package/src/runtime/observability/observability.test.ts +0 -583
  229. package/src/runtime/owner-control.test.ts +0 -153
  230. package/src/runtime/parent-process-watch.test.ts +0 -27
  231. package/src/runtime/pending-event-handoff.test.ts +0 -29
  232. package/src/runtime/raw-ws-log.test.ts +0 -102
  233. package/src/runtime/runtime-logger.test.ts +0 -58
  234. package/src/runtime/runtime-persistence.test.ts +0 -26
  235. package/src/runtime/runtime.test.ts +0 -1770
  236. package/src/runtime/ws-client.test.ts +0 -562
  237. package/src/sdk/behavior-plugin/index.test.ts +0 -74
  238. package/src/sdk/index.test.ts +0 -45
  239. package/src/sdk/module-input/index.test.ts +0 -49
  240. package/src/sdk/perception-plugin/index.test.ts +0 -22
  241. package/src/sdk/resource-metadata.test.ts +0 -40
  242. package/src/sdk/trigger-plugin/index.test.ts +0 -41
  243. package/src/short-command/classifier.test.ts +0 -107
  244. package/src/short-command/presenter.test.ts +0 -119
  245. package/src/short-command/runner.test.ts +0 -78
  246. package/src/short-command/sensitive-data-filter.test.ts +0 -56
  247. package/src/short-command/transport-response.test.ts +0 -39
  248. package/src/strategies/custom-module.test.ts +0 -268
  249. package/src/strategies/game-utils.test.ts +0 -306
  250. package/src/strategies/goals/avoid-players-top.test.ts +0 -96
  251. package/src/strategies/goals/crab-sabotage-top.test.ts +0 -145
  252. package/src/strategies/goals/kill-lone-top.test.ts +0 -97
  253. package/src/strategies/goals/kill-target-top.test.ts +0 -66
  254. package/src/strategies/goals/lone-kill-task-top.test.ts +0 -85
  255. package/src/strategies/goals/normal-shrimp-top.test.ts +0 -113
  256. package/src/strategies/goals/paradise-fish-top.test.ts +0 -204
  257. package/src/strategies/goals/task-only-top.test.ts +0 -89
  258. package/src/strategies/goals/warrior-shrimp-top.test.ts +0 -139
  259. package/src/strategies/meeting-gate.test.ts +0 -59
  260. package/src/strategies/official-long-behavior.test.ts +0 -89
  261. package/src/strategies/pathfind/astar-path.test.ts +0 -198
  262. package/src/strategies/pathfind/escape-planner.test.ts +0 -223
  263. package/src/strategies/player-targets.test.ts +0 -10
  264. package/src/strategies/task-only.test.ts +0 -138
@@ -1,854 +0,0 @@
1
- import { describe, expect, it, vi } from 'vitest';
2
- import { Runtime } from '../../framework/runtime.js';
3
- import { createClawclawEventCatalog } from '../../clawclaw-event-catalog.js';
4
- import {
5
- behaviorControllerSpec,
6
- type BehaviorActionCaller,
7
- } from '../../framework/capability-registry.js';
8
- import {
9
- CLAWCLAW_ACTION_CAPABILITY,
10
- CLAWCLAW_AGENT_CONTROL_LEASE_MS,
11
- ClawclawActionPlugin,
12
- describeClawclawActionControl,
13
- } from './action/index.js';
14
- import { ApiError } from '../../../lib/http-transport.js';
15
- import { jsonTransportResponse } from '../../../short-command/transport-response.js';
16
- import { ClawclawMailboxPlugin } from './mailbox/index.js';
17
-
18
- function deferred<T>() {
19
- let resolve!: (value: T | PromiseLike<T>) => void;
20
- const promise = new Promise<T>((resolvePromise) => { resolve = resolvePromise; });
21
- return { promise, resolve };
22
- }
23
-
24
- function wanderingRuntimeState() {
25
- return {
26
- schema: 'clawclaw.runtime-state.v1' as const,
27
- action_safety_generation: 0,
28
- stage: 'game' as const,
29
- transport: 'game_ws' as const,
30
- connection: 'connected' as const,
31
- cause: 'game_snapshot' as const,
32
- game_snapshot: {
33
- status: 'fresh' as const,
34
- state: { phase: 'wandering' },
35
- },
36
- };
37
- }
38
-
39
- function nonWanderingRuntimeState(
40
- stage: 'matching' | 'room' | 'loading' | 'game' | 'meeting' | 'settlement' | 'ended',
41
- phase: string,
42
- ) {
43
- return {
44
- ...wanderingRuntimeState(),
45
- stage,
46
- game_snapshot: {
47
- status: 'fresh' as const,
48
- state: { phase },
49
- },
50
- };
51
- }
52
-
53
- function eventOnlyRuntimeState() {
54
- return {
55
- ...wanderingRuntimeState(),
56
- cause: 'backend_event' as const,
57
- game_snapshot: { status: 'not_updated' as const },
58
- };
59
- }
60
-
61
- async function fixture() {
62
- const client = {
63
- submitPreparedActionConfirmed: vi.fn().mockResolvedValue(jsonTransportResponse({
64
- success: true,
65
- data: { status: 'queued' },
66
- }, { method: 'POST', path: '/api/v1/game/action' })),
67
- prepareActionForConfirmedSubmission: vi.fn(async (action) => action),
68
- chatRoomConfirmed: vi.fn().mockResolvedValue(jsonTransportResponse({ success: true }, {
69
- method: 'POST', path: '/api/v1/room/chat',
70
- })),
71
- uploadAudio: vi.fn(),
72
- } as any;
73
- const action = new ClawclawActionPlugin(client);
74
- const runtime = new Runtime({
75
- adapterId: 'clawclaw', accountId: 'acct_1', eventCatalog: createClawclawEventCatalog(),
76
- initialSegment: { kind: 'game', identity: 'g1' },
77
- runtimeEpochPlugins: [action],
78
- });
79
- await runtime.start();
80
- action.update({ epoch: { scope: runtime.scope(), state: wanderingRuntimeState() } } as any);
81
- return { runtime, client, action };
82
- }
83
-
84
- async function acceptRuntimeState(
85
- runtime: Runtime,
86
- sourceKey: string,
87
- state: Record<string, any>,
88
- ): Promise<void> {
89
- await runtime.acceptInputBatch({
90
- scope: runtime.scope(),
91
- sourceId: 'test.source',
92
- connectionId: 'connection-1',
93
- sourceKey,
94
- state,
95
- events: [],
96
- completeness: 'complete',
97
- receivedAt: new Date().toISOString(),
98
- });
99
- await runtime.flush();
100
- }
101
-
102
- function wanderingStateWithPlayers(players: readonly Record<string, any>[]) {
103
- return {
104
- ...wanderingRuntimeState(),
105
- game_snapshot: {
106
- status: 'fresh' as const,
107
- state: { phase: 'wandering', players: structuredClone(players) },
108
- },
109
- };
110
- }
111
-
112
- function behaviorCaller(
113
- activationId: string,
114
- layer: BehaviorActionCaller['layer'] = 'long',
115
- ): BehaviorActionCaller {
116
- return { kind: 'behavior', activationId, layer, activationGeneration: 1 };
117
- }
118
-
119
- function registerBehaviorController(
120
- runtime: Runtime,
121
- caller: BehaviorActionCaller,
122
- domains: string[] = ['physical'],
123
- ): void {
124
- runtime.actions.controls.registerController(behaviorControllerSpec(caller, {
125
- scope: runtime.scope(),
126
- domains,
127
- lifecycle: 'persistent',
128
- ready: true,
129
- }));
130
- }
131
-
132
- function behaviorPrecondition(epochSeq = 1) {
133
- return {
134
- behaviorOriginEpochSeq: epochSeq,
135
- behaviorActionSafetyGeneration: 0,
136
- behaviorActivationGeneration: 1,
137
- };
138
- }
139
-
140
- describe('ClawClaw runtime capabilities', () => {
141
- it.each([
142
- ['move', ['physical']],
143
- ['task', ['physical']],
144
- ['kill', ['physical']],
145
- ['report', ['physical']],
146
- ['trigger_alarm', ['physical']],
147
- ['speech', ['communication']],
148
- ['vote', ['meeting_vote']],
149
- ['think', []],
150
- ['strategy', []],
151
- ['future_action', ['*']],
152
- ])('maps %s onto generic control domains', (action, domains) => {
153
- expect(describeClawclawActionControl({ action: { action } })).toEqual({
154
- domains,
155
- agentLeaseMs: CLAWCLAW_AGENT_CONTROL_LEASE_MS,
156
- });
157
- });
158
-
159
- it('does not let transport routing change the action control domain', () => {
160
- expect(describeClawclawActionControl({
161
- route: 'room_chat',
162
- action: { action: 'speech', text: 'hello' },
163
- }).domains).toEqual(['communication']);
164
- expect(describeClawclawActionControl({
165
- route: 'game',
166
- action: { action: 'speech', text: 'hello' },
167
- }).domains).toEqual(['communication']);
168
- });
169
-
170
- it('does not let the physical Agent lease outlast the minimum fallback idle timeout', () => {
171
- expect(CLAWCLAW_AGENT_CONTROL_LEASE_MS).toBeLessThanOrEqual(1_000);
172
- });
173
-
174
- it('conservatively claims all control for a missing action name', () => {
175
- expect(describeClawclawActionControl({ action: {} }).domains).toEqual(['*']);
176
- });
177
-
178
- it('rejects stale scope before calling the backend', async () => {
179
- const { runtime, client } = await fixture();
180
- await expect(runtime.performAction(CLAWCLAW_ACTION_CAPABILITY, {
181
- action: { action: 'move', target_x: 1, target_y: 2 },
182
- }, { sessionId: 'old', segmentId: 'old' }, { kind: 'agent', id: 'a1' }))
183
- .rejects.toThrow('runtime_scope_changed');
184
- expect(client.submitPreparedActionConfirmed).not.toHaveBeenCalled();
185
- });
186
-
187
- it('invalidates an Action provider immediately when the Runtime segment changes', async () => {
188
- const { runtime, client } = await fixture();
189
- await runtime.activateSegment('game', 'g2');
190
-
191
- await expect(runtime.performAction(CLAWCLAW_ACTION_CAPABILITY, {
192
- action: { action: 'move', target_x: 1, target_y: 2 },
193
- }, runtime.publicScope(), { kind: 'agent' })).rejects.toThrow(
194
- 'capability scope is no longer active',
195
- );
196
- expect(client.submitPreparedActionConfirmed).not.toHaveBeenCalled();
197
- await runtime.close();
198
- });
199
-
200
- it('does not submit game Actions before GameSync snapshot/resume completes', async () => {
201
- const { runtime, client, action } = await fixture();
202
- action.update({
203
- epoch: {
204
- scope: runtime.scope(),
205
- state: { ...wanderingRuntimeState(), connection: 'reconnecting' },
206
- },
207
- } as any);
208
-
209
- await expect(runtime.performAction(CLAWCLAW_ACTION_CAPABILITY, {
210
- action: { action: 'move', target_x: 1, target_y: 2 },
211
- }, runtime.publicScope(), { kind: 'agent' })).resolves.toMatchObject({
212
- status: 'failure',
213
- source: 'local',
214
- actionOutcome: 'not_submitted',
215
- error: { error: { code: 'GAME_SYNC_NOT_READY' } },
216
- });
217
- expect(client.prepareActionForConfirmedSubmission).not.toHaveBeenCalled();
218
- expect(client.submitPreparedActionConfirmed).not.toHaveBeenCalled();
219
- await runtime.close();
220
- });
221
-
222
- it('treats the Action response only as an acknowledgement', async () => {
223
- const { runtime } = await fixture();
224
- const response = await runtime.performAction<any, any>(CLAWCLAW_ACTION_CAPABILITY, {
225
- action: { action: 'move', target_x: 1, target_y: 2 },
226
- }, runtime.publicScope(), { kind: 'agent', id: 'a1' });
227
- expect(response.status).toBe('success');
228
- expect(response.value).toMatchObject({ success: true, data: { status: 'queued' } });
229
- expect(runtime.repository.highWaterCommitSeq(runtime.scope().sessionId)).toBe(0);
230
- await runtime.close();
231
- });
232
-
233
- it.each([
234
- ['Agent', { kind: 'agent' as const, id: 'direct-agent' }],
235
- ['User', { kind: 'user' as const, id: 'direct-user' }],
236
- ])('keeps a direct %s caller pending until the HTTP acknowledgement settles', async (
237
- _label,
238
- caller,
239
- ) => {
240
- const { runtime, client } = await fixture();
241
- const acknowledgement = deferred<ReturnType<typeof jsonTransportResponse>>();
242
- client.submitPreparedActionConfirmed.mockReturnValueOnce(acknowledgement.promise);
243
- let resolved = false;
244
-
245
- const pending = runtime.performAction(CLAWCLAW_ACTION_CAPABILITY, {
246
- action: { action: 'move', target_x: 1, target_y: 2 },
247
- }, runtime.publicScope(), caller).then((result) => {
248
- resolved = true;
249
- return result;
250
- });
251
- await vi.waitFor(() => expect(client.submitPreparedActionConfirmed).toHaveBeenCalledOnce());
252
- expect(resolved).toBe(false);
253
-
254
- acknowledgement.resolve(jsonTransportResponse({
255
- success: true,
256
- data: { status: 'queued', duration_secs: 1 },
257
- }, { method: 'POST', path: '/api/v1/game/action' }));
258
- await expect(pending).resolves.toMatchObject({
259
- status: 'success',
260
- source: 'backend',
261
- actionOutcome: 'confirmed',
262
- });
263
- await runtime.close();
264
- });
265
-
266
- it('records ActionPlugin queue and final settlement diagnostics for detached automation', async () => {
267
- const acknowledgement = deferred<ReturnType<typeof jsonTransportResponse>>();
268
- const client = {
269
- submitPreparedActionConfirmed: vi.fn().mockReturnValue(acknowledgement.promise),
270
- prepareActionForConfirmedSubmission: vi.fn(async (action) => action),
271
- chatRoomConfirmed: vi.fn(),
272
- uploadAudio: vi.fn(),
273
- } as any;
274
- const diagnostics = vi.fn();
275
- let service: any;
276
- const action = new ClawclawActionPlugin(client);
277
- action.start({
278
- currentSegment: () => ({ kind: 'game' }),
279
- diagnostic: diagnostics,
280
- capabilities: {
281
- provideAction: (registered: any) => {
282
- service = registered;
283
- return () => {};
284
- },
285
- },
286
- } as any);
287
- const state = wanderingRuntimeState();
288
- const runtimeScope = {
289
- adapterId: 'clawclaw',
290
- accountId: 'acct-detached',
291
- sessionId: 'session-detached',
292
- segmentId: 'segment-detached',
293
- };
294
- action.update({ epoch: { scope: runtimeScope, state } } as any);
295
-
296
- const dispatched = service.perform({
297
- action: { action: 'move', target_x: 1, target_y: 2 },
298
- behaviorOriginEpochSeq: 1,
299
- behaviorActionSafetyGeneration: 0,
300
- behaviorActivationGeneration: 1,
301
- }, runtimeScope, {
302
- kind: 'behavior', activationId: 'diagnostic-behavior', layer: 'long', activationGeneration: 1,
303
- }, {
304
- signal: new AbortController().signal,
305
- revalidate: () => ({ status: 'authorized' }),
306
- latestAcceptedState: () => ({ epochSeq: 1, state }),
307
- });
308
- expect(dispatched.receipt).toMatchObject({
309
- status: 'success', source: 'local', actionOutcome: 'unknown',
310
- });
311
- expect(diagnostics).toHaveBeenCalledWith(
312
- 'runtime.action.provider_queued',
313
- expect.objectContaining({ caller_kind: 'behavior', action_kind: 'move' }),
314
- 'debug',
315
- );
316
-
317
- acknowledgement.resolve(jsonTransportResponse({ success: true }, {
318
- method: 'POST', path: '/api/v1/game/action',
319
- }));
320
- await expect(dispatched.settled).resolves.toMatchObject({
321
- status: 'success', source: 'backend', actionOutcome: 'confirmed',
322
- });
323
- expect(diagnostics).toHaveBeenCalledWith(
324
- 'runtime.action.provider_settled',
325
- expect.objectContaining({
326
- caller_kind: 'behavior',
327
- action_kind: 'move',
328
- status: 'success',
329
- action_outcome: 'confirmed',
330
- }),
331
- 'debug',
332
- );
333
- action.stop();
334
- });
335
-
336
- it.each([
337
- ['manual Agent', { kind: 'agent' as const, id: 'manual-1' }],
338
- ['Behavior', behaviorCaller('seat-target-behavior')],
339
- ])('submits authoritative target seats without names for %s Actions', async (_label, caller) => {
340
- const { runtime, client } = await fixture();
341
- await acceptRuntimeState(runtime, 'authoritative-roster', wanderingStateWithPlayers([
342
- { name: 'same-name', seat: 1 },
343
- { name: 'same-name', seat: 2 },
344
- ]));
345
- // Names and later event-only frames are irrelevant to seat-based targeting.
346
- await acceptRuntimeState(runtime, 'event-only-after-roster', eventOnlyRuntimeState());
347
-
348
- if (caller.kind === 'behavior') registerBehaviorController(runtime, caller);
349
- const request = {
350
- action: { action: 'kill', target_seat: 2 },
351
- ...(caller.kind === 'behavior' ? behaviorPrecondition() : {}),
352
- };
353
-
354
- const result = await runtime.performAction(
355
- CLAWCLAW_ACTION_CAPABILITY,
356
- request,
357
- runtime.publicScope(),
358
- caller,
359
- );
360
- expect(result).toMatchObject(caller.kind === 'agent' ? {
361
- status: 'success',
362
- source: 'backend',
363
- actionOutcome: 'confirmed',
364
- } : {
365
- status: 'success',
366
- source: 'local',
367
- actionOutcome: 'unknown',
368
- });
369
- await runtime.actions.waitForIdle();
370
- expect(client.prepareActionForConfirmedSubmission).toHaveBeenCalledWith({
371
- action: 'kill',
372
- target_seat: 2,
373
- });
374
- expect(client.submitPreparedActionConfirmed).toHaveBeenCalledWith({
375
- action: 'kill',
376
- target_seat: 2,
377
- });
378
- await runtime.close();
379
- });
380
-
381
- it('returns an ActionPlugin receipt before the HTTP acknowledgement for Behavior callers', async () => {
382
- const { runtime, client } = await fixture();
383
- await acceptRuntimeState(runtime, 'detached-origin', wanderingRuntimeState());
384
- const acknowledgement = deferred<ReturnType<typeof jsonTransportResponse>>();
385
- client.submitPreparedActionConfirmed.mockReturnValueOnce(acknowledgement.promise);
386
- const caller = behaviorCaller('detached-behavior');
387
- registerBehaviorController(runtime, caller);
388
- const request = {
389
- action: { action: 'move', target_x: 1, target_y: 2 },
390
- ...behaviorPrecondition(),
391
- };
392
-
393
- await expect(runtime.performAction(
394
- CLAWCLAW_ACTION_CAPABILITY,
395
- request,
396
- runtime.publicScope(),
397
- caller,
398
- )).resolves.toMatchObject({
399
- status: 'success',
400
- source: 'local',
401
- actionOutcome: 'unknown',
402
- value: { accepted: true, status: 'queued' },
403
- });
404
- await vi.waitFor(() => expect(client.submitPreparedActionConfirmed).toHaveBeenCalledOnce());
405
- expect(runtime.actions.controls.snapshot().inFlight).toHaveLength(0);
406
-
407
- acknowledgement.resolve(jsonTransportResponse({
408
- success: true,
409
- data: { status: 'queued', duration_secs: 1 },
410
- }, { method: 'POST', path: '/api/v1/game/action' }));
411
- await runtime.actions.waitForIdle();
412
- expect(runtime.actions.controls.snapshot().inFlight).toHaveLength(0);
413
- await runtime.close();
414
- });
415
-
416
- it('lets one Behavior submit an after-kill move while the kill HTTP settlement is pending', async () => {
417
- const { runtime, client } = await fixture();
418
- await acceptRuntimeState(runtime, 'after-kill-origin', wanderingStateWithPlayers([
419
- { name: 'self-player', seat: 1 },
420
- { name: 'target-player', seat: 2 },
421
- ]));
422
- const caller = behaviorCaller('after-kill-behavior', 'short');
423
- registerBehaviorController(runtime, caller);
424
- const killAcknowledgement = deferred<ReturnType<typeof jsonTransportResponse>>();
425
- client.submitPreparedActionConfirmed
426
- .mockReturnValueOnce(killAcknowledgement.promise)
427
- .mockResolvedValueOnce(jsonTransportResponse({ success: true }, {
428
- method: 'POST', path: '/api/v1/game/action',
429
- }));
430
- const automationPrecondition = behaviorPrecondition();
431
-
432
- await expect(runtime.performAction(CLAWCLAW_ACTION_CAPABILITY, {
433
- action: { action: 'kill', target_seat: 2 },
434
- ...automationPrecondition,
435
- }, runtime.publicScope(), caller)).resolves.toMatchObject({
436
- status: 'success', source: 'local', actionOutcome: 'unknown',
437
- });
438
- await vi.waitFor(() => expect(client.submitPreparedActionConfirmed).toHaveBeenCalledTimes(1));
439
- expect(runtime.actions.controls.snapshot().inFlight).toHaveLength(0);
440
-
441
- await expect(runtime.performAction(CLAWCLAW_ACTION_CAPABILITY, {
442
- action: { action: 'move', target_x: 500, target_y: 0 },
443
- ...automationPrecondition,
444
- }, runtime.publicScope(), caller)).resolves.toMatchObject({
445
- status: 'success', source: 'local', actionOutcome: 'unknown',
446
- });
447
- await vi.waitFor(() => expect(client.submitPreparedActionConfirmed).toHaveBeenCalledTimes(2));
448
- expect(client.submitPreparedActionConfirmed.mock.calls[0]?.[0]).toMatchObject({
449
- action: 'kill', target_seat: 2,
450
- });
451
- expect(client.submitPreparedActionConfirmed.mock.calls[1]?.[0]).toMatchObject({
452
- action: 'move', target_x: 500, target_y: 0,
453
- });
454
-
455
- let drained = false;
456
- const drain = runtime.actions.waitForIdle().then(() => { drained = true; });
457
- await Promise.resolve();
458
- expect(drained).toBe(false);
459
- killAcknowledgement.resolve(jsonTransportResponse({ success: true }, {
460
- method: 'POST', path: '/api/v1/game/action',
461
- }));
462
- await drain;
463
- await runtime.close();
464
- });
465
-
466
- it.each([8, 0])('submits vote target_seat %s without a name target', async (seat) => {
467
- const { runtime, client } = await fixture();
468
- await acceptRuntimeState(runtime, 'vote-without-roster', wanderingRuntimeState());
469
-
470
- await expect(runtime.performAction(CLAWCLAW_ACTION_CAPABILITY, {
471
- action: { action: 'vote', target_seat: seat },
472
- }, runtime.publicScope(), { kind: 'agent' })).resolves.toMatchObject({
473
- status: 'success', source: 'backend', actionOutcome: 'confirmed',
474
- });
475
- expect(client.submitPreparedActionConfirmed).toHaveBeenCalledWith({
476
- action: 'vote', target_seat: seat,
477
- });
478
- await runtime.close();
479
- });
480
-
481
- it.each([
482
- ['missing roster', wanderingRuntimeState()],
483
- [
484
- 'missing seat',
485
- wanderingStateWithPlayers([{ name: 'self-player', seat: 1 }]),
486
- ],
487
- [
488
- 'duplicate seat',
489
- wanderingStateWithPlayers([
490
- { name: 'target-a', seat: 2 },
491
- { name: 'target-b', seat: 2 },
492
- ]),
493
- ],
494
- [
495
- 'duplicate player name',
496
- wanderingStateWithPlayers([
497
- { name: 'same-name', seat: 2 },
498
- { name: 'same-name', seat: 3 },
499
- ]),
500
- ],
501
- ])('does not consult the %s when submitting a seat-based kill', async (_label, state) => {
502
- const { runtime, client } = await fixture();
503
- await acceptRuntimeState(runtime, `seat-only-${_label}`, state);
504
-
505
- await expect(runtime.performAction(CLAWCLAW_ACTION_CAPABILITY, {
506
- action: { action: 'kill', target_seat: 2 },
507
- }, runtime.publicScope(), { kind: 'agent' })).resolves.toMatchObject({
508
- status: 'success',
509
- source: 'backend',
510
- actionOutcome: 'confirmed',
511
- });
512
- expect(client.prepareActionForConfirmedSubmission).toHaveBeenCalledWith({
513
- action: 'kill', target_seat: 2,
514
- });
515
- expect(client.submitPreparedActionConfirmed).toHaveBeenCalledWith({
516
- action: 'kill', target_seat: 2,
517
- });
518
- await runtime.close();
519
- });
520
-
521
- it.each([
522
- ['kill name only', { action: 'kill', target: 'untrusted-name' }],
523
- ['kill string seat', { action: 'kill', target_seat: '2' }],
524
- ['kill seat zero', { action: 'kill', target_seat: 0 }],
525
- ['kill seat eleven', { action: 'kill', target_seat: 11 }],
526
- ['vote negative seat', { action: 'vote', target_seat: -1 }],
527
- ['vote seat eleven', { action: 'vote', target_seat: 11 }],
528
- ])('fails closed for an invalid %s target', async (_label, action) => {
529
- const { runtime, client } = await fixture();
530
-
531
- await expect(runtime.performAction(CLAWCLAW_ACTION_CAPABILITY, {
532
- action,
533
- }, runtime.publicScope(), { kind: 'agent' })).resolves.toMatchObject({
534
- status: 'failure',
535
- source: 'local',
536
- actionOutcome: 'not_submitted',
537
- error: { error: { code: 'INVALID_ACTION_TARGET_SEAT' } },
538
- });
539
- expect(client.prepareActionForConfirmedSubmission).not.toHaveBeenCalled();
540
- expect(client.submitPreparedActionConfirmed).not.toHaveBeenCalled();
541
- await runtime.close();
542
- });
543
-
544
- it('does not invalidate a Behavior Action for a newer event-only State', async () => {
545
- const { runtime, client } = await fixture();
546
- const accept = (sourceKey: string, state: Record<string, any>) => runtime.acceptInputBatch({
547
- scope: runtime.scope(),
548
- sourceId: 'test.source',
549
- connectionId: 'connection-1',
550
- sourceKey,
551
- state,
552
- events: [],
553
- completeness: 'complete',
554
- receivedAt: new Date().toISOString(),
555
- });
556
- await accept('fresh-behavior-origin', wanderingRuntimeState());
557
- await accept('event-only-after-origin', eventOnlyRuntimeState());
558
- await runtime.flush();
559
-
560
- const caller = behaviorCaller('event-only-behavior');
561
- registerBehaviorController(runtime, caller);
562
- await expect(runtime.performAction(CLAWCLAW_ACTION_CAPABILITY, {
563
- action: { action: 'move', target_x: 1, target_y: 2 },
564
- ...behaviorPrecondition(),
565
- }, runtime.publicScope(), caller)).resolves.toMatchObject({
566
- status: 'success',
567
- source: 'local',
568
- actionOutcome: 'unknown',
569
- });
570
- await runtime.actions.waitForIdle();
571
- expect(client.submitPreparedActionConfirmed).toHaveBeenCalledOnce();
572
- await runtime.close();
573
- });
574
-
575
- it('submits room chat through its dedicated HTTP endpoint', async () => {
576
- const { runtime, client } = await fixture();
577
-
578
- await expect(runtime.performAction(CLAWCLAW_ACTION_CAPABILITY, {
579
- route: 'room_chat',
580
- action: { action: 'speech', text: 'hello room' },
581
- }, runtime.publicScope(), { kind: 'agent' })).resolves.toMatchObject({
582
- status: 'success', source: 'backend', actionOutcome: 'confirmed',
583
- });
584
- expect(client.chatRoomConfirmed).toHaveBeenCalledWith('hello room');
585
- expect(client.submitPreparedActionConfirmed).not.toHaveBeenCalled();
586
- await runtime.close();
587
- });
588
-
589
- it('preserves safe backend error fields instead of applying Event hint stripping', async () => {
590
- const { runtime, client } = await fixture();
591
- const upstream = {
592
- success: false,
593
- error: {
594
- code: 'NOT_YOUR_TURN',
595
- message: 'wait',
596
- hint: 'speak only on your turn',
597
- next_step: 'watch the meeting phase',
598
- },
599
- current_status: 'meeting',
600
- };
601
- const response = jsonTransportResponse(upstream, {
602
- method: 'POST',
603
- path: '/api/v1/game/action',
604
- status: 409,
605
- requestId: 'req-1',
606
- });
607
- client.submitPreparedActionConfirmed.mockRejectedValueOnce(new ApiError(
608
- 409,
609
- response.body.rawText,
610
- 'POST',
611
- '/api/v1/game/action',
612
- response,
613
- ));
614
- const result = await runtime.performAction(CLAWCLAW_ACTION_CAPABILITY, {
615
- action: { action: 'speech', text: 'too early' },
616
- }, runtime.publicScope(), { kind: 'agent' });
617
- expect(result).toMatchObject({ status: 'failure', error: upstream });
618
- });
619
-
620
- it('treats a HTTP 200 business error as failure and preserves the backend root', async () => {
621
- const { runtime, client } = await fixture();
622
- const upstream = {
623
- success: false,
624
- error: { code: 'ACTION_FAILED', message: 'not your turn', hint: 'wait' },
625
- current_status: 'meeting',
626
- };
627
- client.submitPreparedActionConfirmed.mockResolvedValueOnce(jsonTransportResponse(upstream, {
628
- method: 'POST', path: '/api/v1/game/action', status: 200,
629
- }));
630
- const result = await runtime.performAction(CLAWCLAW_ACTION_CAPABILITY, {
631
- action: { action: 'speech', text: 'too early' },
632
- }, runtime.publicScope(), { kind: 'agent' });
633
- expect(result).toMatchObject({
634
- status: 'failure', source: 'backend', actionOutcome: 'confirmed', error: upstream,
635
- });
636
- });
637
-
638
- it('marks a lost Action acknowledgement as transport-unknown', async () => {
639
- const { runtime, client } = await fixture();
640
- client.submitPreparedActionConfirmed.mockRejectedValueOnce(new Error('socket reset'));
641
-
642
- const result = await runtime.performAction(CLAWCLAW_ACTION_CAPABILITY, {
643
- action: { action: 'move', target_x: 1, target_y: 2 },
644
- }, runtime.publicScope(), { kind: 'agent' });
645
-
646
- expect(result).toMatchObject({
647
- status: 'failure',
648
- source: 'transport',
649
- actionOutcome: 'unknown',
650
- error: { error: { code: 'ACTION_REQUEST_FAILED', message: 'socket reset' } },
651
- });
652
- });
653
-
654
- it('marks an empty Action response as protocol-unknown', async () => {
655
- const { runtime, client } = await fixture();
656
- client.submitPreparedActionConfirmed.mockResolvedValueOnce({
657
- method: 'POST',
658
- path: '/api/v1/game/action',
659
- status: 200,
660
- headers: {},
661
- body: { kind: 'empty', rawText: '' },
662
- });
663
-
664
- const result = await runtime.performAction(CLAWCLAW_ACTION_CAPABILITY, {
665
- action: { action: 'move', target_x: 1, target_y: 2 },
666
- }, runtime.publicScope(), { kind: 'agent' });
667
-
668
- expect(result).toMatchObject({
669
- status: 'failure',
670
- source: 'protocol',
671
- actionOutcome: 'unknown',
672
- error: { error: { code: 'ACTION_PROTOCOL_ERROR' } },
673
- });
674
- });
675
-
676
- it('preserves an explicit audio upload backend error before submitting speech', async () => {
677
- const { runtime, client } = await fixture();
678
- const upstream = {
679
- success: false,
680
- error: { code: 'UPLOAD_REJECTED', message: 'unsupported audio' },
681
- };
682
- const response = jsonTransportResponse(upstream, {
683
- method: 'POST', path: '/api/v1/agents/upload_audio', status: 200,
684
- });
685
- client.uploadAudio.mockRejectedValueOnce(new ApiError(
686
- 200,
687
- response.body.rawText,
688
- 'POST',
689
- '/api/v1/agents/upload_audio',
690
- response,
691
- ));
692
- const result = await runtime.performAction(CLAWCLAW_ACTION_CAPABILITY, {
693
- action: { action: 'speech', text: 'hello' },
694
- audioFile: { path: 'voice.wav', contentType: 'audio/wav' },
695
- }, runtime.publicScope(), { kind: 'agent' });
696
- expect(result).toMatchObject({
697
- status: 'failure', source: 'backend', actionOutcome: 'not_submitted', error: upstream,
698
- });
699
- expect(client.submitPreparedActionConfirmed).not.toHaveBeenCalled();
700
- });
701
-
702
- it('does not submit after worker authority is revoked during explicit audio upload', async () => {
703
- const { runtime, client } = await fixture();
704
- const upload = deferred<{ audio_url: string }>();
705
- client.uploadAudio.mockReturnValueOnce(upload.promise);
706
- let authorized = true;
707
- const pending = runtime.performAction(CLAWCLAW_ACTION_CAPABILITY, {
708
- action: { action: 'speech', text: 'hello' },
709
- audioFile: { path: 'voice.wav', contentType: 'audio/wav' },
710
- }, runtime.publicScope(), { kind: 'agent', id: 'worker-1' }, {
711
- isAuthorized: () => authorized,
712
- });
713
- await vi.waitFor(() => expect(client.uploadAudio).toHaveBeenCalledOnce());
714
-
715
- authorized = false;
716
- upload.resolve({ audio_url: 'https://example.invalid/voice.wav' });
717
-
718
- await expect(pending).resolves.toMatchObject({
719
- status: 'deferred',
720
- error: { code: 'CONTROL_AUTHORITY_REVOKED' },
721
- });
722
- expect(client.submitPreparedActionConfirmed).not.toHaveBeenCalled();
723
- expect(client.chatRoomConfirmed).not.toHaveBeenCalled();
724
- });
725
-
726
- it('does not submit after the game segment changes during preparation', async () => {
727
- const { runtime, client } = await fixture();
728
- const prepare = deferred<Record<string, unknown>>();
729
- client.prepareActionForConfirmedSubmission.mockReturnValueOnce(prepare.promise);
730
- const oldScope = runtime.publicScope();
731
- const pending = runtime.performAction(CLAWCLAW_ACTION_CAPABILITY, {
732
- action: { action: 'move', target_x: 1, target_y: 2 },
733
- }, oldScope, { kind: 'agent' });
734
- await vi.waitFor(() => (
735
- expect(client.prepareActionForConfirmedSubmission).toHaveBeenCalledOnce()
736
- ));
737
-
738
- await runtime.activateSegment('game', 'g2');
739
- prepare.resolve({ action: 'move', target_x: 1, target_y: 2 });
740
-
741
- await expect(pending).resolves.toMatchObject({
742
- status: 'deferred',
743
- error: { code: 'CONTROL_SCOPE_CHANGED' },
744
- });
745
- expect(client.submitPreparedActionConfirmed).not.toHaveBeenCalled();
746
- });
747
-
748
- it('does not submit prepared work after owner shutdown begins', async () => {
749
- const { runtime, client } = await fixture();
750
- const prepare = deferred<Record<string, unknown>>();
751
- client.prepareActionForConfirmedSubmission.mockReturnValueOnce(prepare.promise);
752
- const pending = runtime.performAction(CLAWCLAW_ACTION_CAPABILITY, {
753
- action: { action: 'speech', text: 'hello' },
754
- }, runtime.publicScope(), { kind: 'agent' });
755
- await vi.waitFor(() => (
756
- expect(client.prepareActionForConfirmedSubmission).toHaveBeenCalledOnce()
757
- ));
758
-
759
- runtime.actions.beginStopping('owner_stopping');
760
- prepare.resolve({ action: 'speech', text: 'hello' });
761
-
762
- await expect(pending).resolves.toMatchObject({
763
- status: 'deferred',
764
- error: { code: 'CONTROL_STOPPING' },
765
- });
766
- expect(client.submitPreparedActionConfirmed).not.toHaveBeenCalled();
767
- });
768
-
769
- it('exposes Action ownership in the generic plugin descriptors', async () => {
770
- const { runtime } = await fixture();
771
-
772
- expect(runtime.runtimeEpochPluginDescriptors()).toEqual(expect.arrayContaining([
773
- expect.objectContaining({
774
- id: 'clawclaw.action',
775
- capabilities: { provides: [CLAWCLAW_ACTION_CAPABILITY] },
776
- }),
777
- ]));
778
- await runtime.close();
779
- });
780
-
781
- it('advances the Mailbox Event cursor without flushing delivery per epoch', async () => {
782
- const driver = {
783
- observeEvents: vi.fn(),
784
- flush: vi.fn(async () => {}),
785
- stop: vi.fn(async () => {}),
786
- };
787
- const mailbox = new ClawclawMailboxPlugin();
788
- mailbox.attachDriver(driver);
789
- const runtime = new Runtime({
790
- adapterId: 'clawclaw',
791
- accountId: 'acct-mailbox',
792
- eventCatalog: createClawclawEventCatalog(),
793
- runtimeEpochPlugins: [mailbox],
794
- initialSegment: { kind: 'game', identity: 'g-mailbox' },
795
- });
796
- await runtime.start();
797
- const scope = runtime.scope();
798
- const input = (sourceKey: string, events: readonly any[]) => ({
799
- scope,
800
- sourceId: 'test.source',
801
- connectionId: 'connection-1',
802
- sourceKey,
803
- state: { stage: 'game', sourceKey },
804
- events,
805
- completeness: 'complete' as const,
806
- receivedAt: new Date().toISOString(),
807
- });
808
-
809
- await runtime.acceptInputBatch(input('one', [{
810
- type: 'task_completed',
811
- payload: { task_name: 'wires' },
812
- }]));
813
- await runtime.flush();
814
- await runtime.acceptInputBatch(input('two', []));
815
- await runtime.flush();
816
-
817
- expect(runtime.inputJournal.pluginProgress(mailbox.id, scope)).toMatchObject({
818
- eventCursor: 1,
819
- completedThroughEpochSeq: 2,
820
- });
821
- expect(driver.observeEvents).toHaveBeenCalledOnce();
822
- expect(driver.observeEvents).toHaveBeenCalledWith([
823
- expect.objectContaining({ type: 'task_completed' }),
824
- ]);
825
- expect(driver.flush).not.toHaveBeenCalled();
826
- await runtime.close();
827
- expect(driver.flush).toHaveBeenCalledOnce();
828
- expect(driver.stop).toHaveBeenCalledOnce();
829
- });
830
-
831
- it('flushes Mailbox delivery before changing the participation segment', async () => {
832
- const driver = {
833
- flush: vi.fn(async () => {}),
834
- stop: vi.fn(async () => {}),
835
- };
836
- const mailbox = new ClawclawMailboxPlugin();
837
- mailbox.attachDriver(driver);
838
- const runtime = new Runtime({
839
- adapterId: 'clawclaw',
840
- accountId: 'acct-mailbox-segment',
841
- eventCatalog: createClawclawEventCatalog(),
842
- runtimeEpochPlugins: [mailbox],
843
- initialSegment: { kind: 'room', identity: 'room-1' },
844
- });
845
- await runtime.start();
846
-
847
- await runtime.activateSegment('game', 'game-1');
848
-
849
- expect(driver.flush).toHaveBeenCalledOnce();
850
- expect(runtime.currentSegment()).toMatchObject({ kind: 'game', identity: 'game-1' });
851
- await runtime.close();
852
- });
853
-
854
- });