@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,514 +0,0 @@
1
- // Materialize every bundled long and finite Behavior into one persistent
2
- // authoring directory. Runtime discovery remains static: no module is imported
3
- // until an Activation explicitly prepares it.
4
- import {
5
- existsSync,
6
- readFileSync,
7
- readdirSync,
8
- } from 'node:fs';
9
- import { createHash } from 'node:crypto';
10
- import {
11
- basename,
12
- dirname,
13
- join,
14
- resolve,
15
- } from 'node:path';
16
- import { fileURLToPath } from 'node:url';
17
- import { getWorkspaceDir } from './init-command.js';
18
- import {
19
- hashOfficialResourceContent,
20
- readOfficialResourceManifest,
21
- syncOfficialResources,
22
- writeOfficialResourceManifest,
23
- type OfficialResourceManifestEntry,
24
- type OfficialResourceSyncResult,
25
- } from './official-resource-sync.js';
26
- import {
27
- ensureUserDataLayout,
28
- getUserDataBehaviorsDir,
29
- getUserDataOfficialBehaviorsManifestFile,
30
- } from './user-data.js';
31
- import { isClawclawFixedEventType } from '../runtime/clawclaw-event-catalog.js';
32
- import { ClawclawBehaviorCatalog } from '../runtime/clawclaw/plugins/behavior/behavior-catalog.js';
33
- import {
34
- listClawclawBehaviorSources,
35
- type ClawclawBehaviorSourceProvenance,
36
- type ResolvedClawclawBehaviorSource,
37
- } from '../runtime/clawclaw/plugins/behavior/behavior-source.js';
38
- import { deepFreezeBehaviorValue } from '../runtime/clawclaw/plugins/behavior/behavior-manifest.js';
39
-
40
- const OFFICIAL_BEHAVIOR_EXPORT_FORMAT = 1 as const;
41
-
42
- const OFFICIAL_LONG_BEHAVIOR_FILES = Object.freeze([
43
- 'avoid-lone.ts',
44
- 'avoid-players.ts',
45
- 'corpse-patrol.ts',
46
- 'crab-sabotage.ts',
47
- 'find-player.ts',
48
- 'hide.ts',
49
- 'kill-frenzy.ts',
50
- 'kill-lone.ts',
51
- 'kill-target.ts',
52
- 'lone-kill-task.ts',
53
- 'move-room.ts',
54
- 'paradise-fish.ts',
55
- 'patrol.ts',
56
- 'report-patrol.ts',
57
- 'shrimp-memory.ts',
58
- 'social-task.ts',
59
- 'task-kill-report.ts',
60
- 'task-only.ts',
61
- 'task-report.ts',
62
- 'warrior-memory.ts',
63
- ] as const);
64
-
65
- const OFFICIAL_FINITE_BEHAVIOR_FILES = Object.freeze([
66
- 'do-task.ts',
67
- 'evade.ts',
68
- 'find-player.ts',
69
- 'follow-player.ts',
70
- 'go-to.ts',
71
- 'hide-temporarily.ts',
72
- 'hold-position.ts',
73
- 'hunt-player.ts',
74
- 'inspect-corpse.ts',
75
- 'patrol-area.ts',
76
- 'report-corpse.ts',
77
- 'seek-kill-opportunity.ts',
78
- 'trigger-alarm.ts',
79
- ] as const);
80
-
81
- export type OfficialBehaviorFamily = 'long' | 'finite';
82
-
83
- export interface OfficialBehaviorProvenance {
84
- readonly kind: 'clawclaw.official-behavior';
85
- readonly family: OfficialBehaviorFamily;
86
- /** Package-relative source identity, never a machine-local absolute path. */
87
- readonly source: string;
88
- readonly materializationFormat: typeof OFFICIAL_BEHAVIOR_EXPORT_FORMAT;
89
- }
90
-
91
- export interface OfficialBehaviorManifestEntry extends OfficialResourceManifestEntry {
92
- readonly provenance?: OfficialBehaviorProvenance;
93
- }
94
-
95
- export type OfficialBehaviorManifest = Record<string, OfficialBehaviorManifestEntry>;
96
-
97
- interface BundledOfficialBehaviorSource {
98
- readonly id: string;
99
- readonly className: string;
100
- readonly family: OfficialBehaviorFamily;
101
- readonly fileName: string;
102
- readonly path: string;
103
- readonly source: string;
104
- readonly manifestObject: string;
105
- readonly provenance: OfficialBehaviorProvenance;
106
- readonly sourceHash: string;
107
- }
108
-
109
- function packageSourceRoot(): string {
110
- return join(dirname(fileURLToPath(import.meta.url)), '..');
111
- }
112
-
113
- function readPackageVersion(): string {
114
- try {
115
- const path = join(packageSourceRoot(), '..', 'package.json');
116
- const parsed = JSON.parse(readFileSync(path, 'utf8')) as { version?: unknown };
117
- return typeof parsed.version === 'string' ? parsed.version : '0.0.0';
118
- } catch {
119
- return '0.0.0';
120
- }
121
- }
122
-
123
- function balancedObject(source: string, open: number): string | null {
124
- let depth = 0;
125
- let quote: "'" | '"' | '`' | undefined;
126
- let escaped = false;
127
- let lineComment = false;
128
- let blockComment = false;
129
- for (let index = open; index < source.length; index += 1) {
130
- const char = source[index]!;
131
- const next = source[index + 1];
132
- if (lineComment) {
133
- if (char === '\n' || char === '\r') lineComment = false;
134
- continue;
135
- }
136
- if (blockComment) {
137
- if (char === '*' && next === '/') {
138
- blockComment = false;
139
- index += 1;
140
- }
141
- continue;
142
- }
143
- if (quote) {
144
- if (escaped) escaped = false;
145
- else if (char === '\\') escaped = true;
146
- else if (char === quote) quote = undefined;
147
- continue;
148
- }
149
- if (char === '/' && next === '/') {
150
- lineComment = true;
151
- index += 1;
152
- continue;
153
- }
154
- if (char === '/' && next === '*') {
155
- blockComment = true;
156
- index += 1;
157
- continue;
158
- }
159
- if (char === "'" || char === '"' || char === '`') {
160
- quote = char;
161
- continue;
162
- }
163
- if (char === '{') depth += 1;
164
- else if (char === '}' && --depth === 0) return source.slice(open, index + 1);
165
- }
166
- return null;
167
- }
168
-
169
- function parseBundledBehavior(
170
- family: OfficialBehaviorFamily,
171
- fileName: string,
172
- ): BundledOfficialBehaviorSource {
173
- const relativeSource = family === 'long'
174
- ? `strategies/${fileName}`
175
- : `behaviors/official-finite/${fileName}`;
176
- const path = join(packageSourceRoot(), ...relativeSource.split('/'));
177
- if (!existsSync(path)) throw new Error(`Bundled Behavior source '${relativeSource}' is missing.`);
178
- const source = readFileSync(path, 'utf8');
179
- const classMatch = /export\s+default\s+class\s+([A-Za-z_$][\w$]*)\s+extends\s+ClawclawBehavior(?:\s*<[\s\S]{0,1000}?>)?\s*\{/.exec(source);
180
- if (!classMatch) {
181
- throw new Error(`Bundled Behavior '${relativeSource}' is not a direct ClawclawBehavior class.`);
182
- }
183
- const manifestMatch = /\bstatic\s+(?:override\s+)?(?:readonly\s+)?manifest\s*=\s*\{/.exec(source);
184
- if (!manifestMatch) throw new Error(`Bundled Behavior '${relativeSource}' has no literal manifest.`);
185
- const manifestOpen = manifestMatch.index + manifestMatch[0].lastIndexOf('{');
186
- const manifestObject = balancedObject(source, manifestOpen);
187
- if (!manifestObject) throw new Error(`Bundled Behavior '${relativeSource}' has an invalid manifest.`);
188
- const id = /\bid\s*:\s*(['"])([a-z0-9][a-z0-9._-]*)\1/.exec(manifestObject)?.[2];
189
- if (!id) throw new Error(`Bundled Behavior '${relativeSource}' has no literal id.`);
190
- const provenance: OfficialBehaviorProvenance = Object.freeze({
191
- kind: 'clawclaw.official-behavior',
192
- family,
193
- source: relativeSource,
194
- materializationFormat: OFFICIAL_BEHAVIOR_EXPORT_FORMAT,
195
- });
196
- return Object.freeze({
197
- id,
198
- className: classMatch[1]!,
199
- family,
200
- fileName,
201
- path,
202
- source,
203
- manifestObject,
204
- provenance,
205
- sourceHash: hashOfficialResourceContent(
206
- `${source}\0behavior-export-v${OFFICIAL_BEHAVIOR_EXPORT_FORMAT}\0${JSON.stringify(provenance)}`,
207
- ),
208
- });
209
- }
210
-
211
- function listBundledOfficialBehaviorSources(): readonly BundledOfficialBehaviorSource[] {
212
- const sources = [
213
- ...OFFICIAL_LONG_BEHAVIOR_FILES.map((file) => parseBundledBehavior('long', file)),
214
- ...OFFICIAL_FINITE_BEHAVIOR_FILES.map((file) => parseBundledBehavior('finite', file)),
215
- ];
216
- const ids = new Set<string>();
217
- for (const source of sources) {
218
- if (ids.has(source.id)) throw new Error(`Duplicate bundled Behavior id '${source.id}'.`);
219
- ids.add(source.id);
220
- }
221
- if (sources.filter(({ family }) => family === 'long').length !== 20) {
222
- throw new Error('Expected exactly 20 bundled long Behaviors.');
223
- }
224
- if (sources.filter(({ family }) => family === 'finite').length !== 13) {
225
- throw new Error('Expected exactly 13 bundled finite Behaviors.');
226
- }
227
- return Object.freeze(sources);
228
- }
229
-
230
- /** Stable, non-executable metadata for tooling and tests. */
231
- export function listOfficialBehaviorDefinitions(): readonly Readonly<{
232
- id: string;
233
- family: OfficialBehaviorFamily;
234
- provenance: OfficialBehaviorProvenance;
235
- sourceHash: string;
236
- }>[] {
237
- return listBundledOfficialBehaviorSources().map((source) => Object.freeze({
238
- id: source.id,
239
- family: source.family,
240
- provenance: source.provenance,
241
- sourceHash: source.sourceHash,
242
- }));
243
- }
244
-
245
- function materializeBehavior(source: BundledOfficialBehaviorSource, version: string): string {
246
- const provenance = JSON.stringify(source.provenance);
247
- return [
248
- `// Materialized from official ${source.family} Behavior ${source.id}@${version}.`,
249
- `// provenance: ${provenance}`,
250
- `import {`,
251
- ` ClawclawBehavior,`,
252
- ` type BehaviorDecision,`,
253
- ` type BehaviorInput,`,
254
- ` type BehaviorNormalizationApi,`,
255
- ` type BehaviorReadApi,`,
256
- `} from '@myclaw163/clawclaw-cli/behavior-plugin';`,
257
- `import OfficialBehavior from 'clawclaw-internal:official-behavior/${source.id}';`,
258
- '',
259
- `type AnyBehaviorInput = Readonly<Record<string, unknown>>;`,
260
- `type OfficialBehaviorDelegate = {`,
261
- ` normalize?: (input: AnyBehaviorInput, api: BehaviorNormalizationApi) => AnyBehaviorInput;`,
262
- ` decide: (`,
263
- ` input: Readonly<BehaviorInput<AnyBehaviorInput>>,`,
264
- ` api: BehaviorReadApi,`,
265
- ` ) => BehaviorDecision | void | Promise<BehaviorDecision | void>;`,
266
- `};`,
267
- '',
268
- `export default class ${source.className} extends ClawclawBehavior<AnyBehaviorInput> {`,
269
- ` static override readonly manifest = ${source.manifestObject} as const;`,
270
- '',
271
- ` private readonly implementation = new OfficialBehavior() as unknown as OfficialBehaviorDelegate;`,
272
- '',
273
- ` override normalize(input: AnyBehaviorInput, api: BehaviorNormalizationApi): AnyBehaviorInput {`,
274
- ` return this.implementation.normalize?.(input, api) ?? input;`,
275
- ` }`,
276
- '',
277
- ` override decide(`,
278
- ` input: Readonly<BehaviorInput<AnyBehaviorInput>>,`,
279
- ` api: BehaviorReadApi,`,
280
- ` ): BehaviorDecision | void | Promise<BehaviorDecision | void> {`,
281
- ` return this.implementation.decide(input, api);`,
282
- ` }`,
283
- `}`,
284
- '',
285
- ].join('\n');
286
- }
287
-
288
- function sameProvenance(
289
- value: OfficialBehaviorProvenance | undefined,
290
- expected: OfficialBehaviorProvenance,
291
- ): boolean {
292
- return value?.kind === expected.kind
293
- && value.family === expected.family
294
- && value.source === expected.source
295
- && value.materializationFormat === expected.materializationFormat;
296
- }
297
-
298
- export function readOfficialBehaviorManifest(workspaceDir = getWorkspaceDir()): OfficialBehaviorManifest {
299
- return readOfficialResourceManifest(
300
- getUserDataOfficialBehaviorsManifestFile(workspaceDir),
301
- ) as OfficialBehaviorManifest;
302
- }
303
-
304
- function recordOfficialBehaviorProvenance(
305
- workspaceDir: string,
306
- sources: readonly BundledOfficialBehaviorSource[],
307
- ): void {
308
- const path = getUserDataOfficialBehaviorsManifestFile(workspaceDir);
309
- const manifest = readOfficialBehaviorManifest(workspaceDir);
310
- let changed = false;
311
- for (const source of sources) {
312
- const entry = manifest[source.id];
313
- if (!entry || entry.sourceHash !== source.sourceHash) continue;
314
- if (sameProvenance(entry.provenance, source.provenance)) continue;
315
- manifest[source.id] = { ...entry, provenance: source.provenance };
316
- changed = true;
317
- }
318
- if (changed) writeOfficialResourceManifest(path, manifest);
319
- }
320
-
321
- export interface SyncOfficialBehaviorsOptions {
322
- readonly workspaceDir?: string;
323
- readonly ids?: readonly string[];
324
- readonly force?: boolean;
325
- }
326
-
327
- export async function syncOfficialBehaviors(
328
- options: SyncOfficialBehaviorsOptions = {},
329
- ): Promise<OfficialResourceSyncResult> {
330
- const workspaceDir = options.workspaceDir ?? getWorkspaceDir();
331
- ensureUserDataLayout(workspaceDir);
332
- const destinationDir = getUserDataBehaviorsDir(workspaceDir);
333
- const bundled = listBundledOfficialBehaviorSources();
334
- const installedSources = new Map(
335
- listClawclawBehaviorSources(destinationDir).map((source) => [source.id, source]),
336
- );
337
- const result = await syncOfficialResources({
338
- sources: bundled,
339
- manifestPath: getUserDataOfficialBehaviorsManifestFile(workspaceDir),
340
- destinationPath: (source) => join(destinationDir, `${source.id}.ts`),
341
- hasUntrackedConflict: (source, destination) => {
342
- const installed = installedSources.get(source.id);
343
- return installed !== undefined && resolve(installed.sourcePath) !== resolve(destination);
344
- },
345
- materialize: materializeBehavior,
346
- version: readPackageVersion(),
347
- ids: options.ids,
348
- force: options.force,
349
- notFoundMessage: (id) => `Built-in Behavior '${id}' not found.`,
350
- });
351
- recordOfficialBehaviorProvenance(workspaceDir, bundled);
352
- return result;
353
- }
354
-
355
- function trustedOfficialSource(
356
- workspaceDir: string,
357
- source: ResolvedClawclawBehaviorSource,
358
- bundled: ReadonlyMap<string, BundledOfficialBehaviorSource>,
359
- manifest: OfficialBehaviorManifest,
360
- ): ResolvedClawclawBehaviorSource {
361
- const official = bundled.get(source.id);
362
- const entry = manifest[source.id];
363
- if (!official || !entry) return source;
364
- const canonicalPath = resolve(getUserDataBehaviorsDir(workspaceDir), `${source.id}.ts`);
365
- if (
366
- resolve(source.sourcePath) !== canonicalPath
367
- || entry.format !== 1
368
- || typeof entry.version !== 'string'
369
- || !/^[0-9A-Za-z][0-9A-Za-z.+-]{0,63}$/.test(entry.version)
370
- || entry.sourceHash !== official.sourceHash
371
- || !sameProvenance(entry.provenance, official.provenance)
372
- || typeof entry.installedHash !== 'string'
373
- ) return source;
374
-
375
- let installed: string;
376
- try {
377
- installed = readFileSync(source.sourcePath, 'utf8');
378
- } catch {
379
- return source;
380
- }
381
- const installedHash = hashOfficialResourceContent(installed);
382
- const expected = materializeBehavior(official, entry.version);
383
- // The shared manifest keeps compact operational hashes. Privilege is
384
- // stricter: byte-for-byte deterministic content equality avoids treating a
385
- // truncated-hash collision or a forged manifest as official code.
386
- if (installedHash !== entry.installedHash || installed !== expected) return source;
387
-
388
- const allowReservedProduces = (source.produces ?? []).filter(isClawclawFixedEventType);
389
- const provenance: ClawclawBehaviorSourceProvenance = {
390
- kind: 'official',
391
- family: official.family,
392
- source: official.provenance.source,
393
- };
394
- return deepFreezeBehaviorValue({
395
- ...source,
396
- provenance,
397
- trustedSourceSha256: createHash('sha256').update(installed).digest('hex'),
398
- ...(allowReservedProduces.length === 0 ? {} : { allowReservedProduces }),
399
- });
400
- }
401
-
402
- /**
403
- * Discover one workspace's unified Behavior directory and attach official
404
- * privileges only after deterministic source and installed-content proof.
405
- */
406
- export function listWorkspaceClawclawBehaviorSources(
407
- workspaceDir = getWorkspaceDir(),
408
- ): readonly ResolvedClawclawBehaviorSource[] {
409
- ensureUserDataLayout(workspaceDir);
410
- const bundled = new Map(
411
- listBundledOfficialBehaviorSources().map((source) => [source.id, source]),
412
- );
413
- const manifest = readOfficialBehaviorManifest(workspaceDir);
414
- return Object.freeze(
415
- listClawclawBehaviorSources(getUserDataBehaviorsDir(workspaceDir))
416
- .map((source) => trustedOfficialSource(workspaceDir, source, bundled, manifest)),
417
- );
418
- }
419
-
420
- /** Build the lazy, static catalog used later by the Runtime assembly layer. */
421
- export function createWorkspaceClawclawBehaviorCatalog(
422
- workspaceDir = getWorkspaceDir(),
423
- ): ClawclawBehaviorCatalog {
424
- return new ClawclawBehaviorCatalog(listWorkspaceClawclawBehaviorSources(workspaceDir));
425
- }
426
-
427
- export async function exportBehavior(
428
- id: string,
429
- options: { readonly workspaceDir?: string; readonly force?: boolean } = {},
430
- ): Promise<void> {
431
- const workspaceDir = options.workspaceDir ?? getWorkspaceDir();
432
- const destination = join(getUserDataBehaviorsDir(workspaceDir), `${id}.ts`);
433
- const result = await syncOfficialBehaviors({
434
- workspaceDir,
435
- ids: [id],
436
- force: options.force,
437
- });
438
- if (result.preservedUntracked.includes(id)) {
439
- if (options.force) {
440
- throw new Error(`Another user-owned Behavior source already declares '${id}'; --force does not overwrite a different file path.`);
441
- }
442
- throw new Error(`${destination} already exists and is not tracked. Use --force to overwrite.`);
443
- }
444
- if (result.preservedModified.includes(id)) {
445
- throw new Error(`${destination} was modified. Use --force to overwrite.`);
446
- }
447
- if (result.preservedDeleted.includes(id)) {
448
- throw new Error(`${destination} was deleted after export. Use --force to restore.`);
449
- }
450
- }
451
-
452
- export function detectStaleOfficialBehaviors(
453
- workspaceDir = getWorkspaceDir(),
454
- ): string[] {
455
- const manifest = readOfficialBehaviorManifest(workspaceDir);
456
- const bundled = new Map(
457
- listBundledOfficialBehaviorSources().map((source) => [source.id, source]),
458
- );
459
- return Object.entries(manifest)
460
- .filter(([id, entry]) => {
461
- const source = bundled.get(id);
462
- return !source
463
- || entry.sourceHash !== source.sourceHash
464
- || !sameProvenance(entry.provenance, source.provenance);
465
- })
466
- .map(([id]) => id)
467
- .sort();
468
- }
469
-
470
- /**
471
- * True when the unified Behavior directory contains user-owned source or a
472
- * manifest-tracked official wrapper was edited/deleted. Helper, declaration,
473
- * and test files do not count as gameplay customization.
474
- */
475
- export function hasUserBehaviorCustomization(
476
- workspaceDir = getWorkspaceDir(),
477
- ): boolean {
478
- const directory = getUserDataBehaviorsDir(workspaceDir);
479
- const manifest = readOfficialBehaviorManifest(workspaceDir);
480
- let files: string[];
481
- try {
482
- files = readdirSync(directory);
483
- } catch {
484
- return false;
485
- }
486
-
487
- for (const file of files) {
488
- if (file.startsWith('_')) continue;
489
- if (!/\.(?:ts|tsx|js)$/.test(file)) continue;
490
- if (/\.d\.ts$|\.(?:test|spec)\.(?:ts|tsx|js)$/.test(file)) continue;
491
-
492
- const id = file.endsWith('.ts') ? basename(file, '.ts') : '';
493
- const entry = id ? manifest[id] : undefined;
494
- if (!entry || file !== `${id}.ts` || !entry.installedHash) return true;
495
- try {
496
- if (hashOfficialResourceContent(readFileSync(join(directory, file))) !== entry.installedHash) {
497
- return true;
498
- }
499
- } catch {
500
- return true;
501
- }
502
- }
503
-
504
- for (const [id, entry] of Object.entries(manifest)) {
505
- const path = join(directory, `${id}.ts`);
506
- if (!entry.installedHash || !existsSync(path)) return true;
507
- try {
508
- if (hashOfficialResourceContent(readFileSync(path)) !== entry.installedHash) return true;
509
- } catch {
510
- return true;
511
- }
512
- }
513
- return false;
514
- }
@@ -1,21 +0,0 @@
1
- import { readFileSync } from 'node:fs';
2
- import { join } from 'node:path';
3
- import { describe, expect, it } from 'vitest';
4
-
5
- function skillText(path: string): string {
6
- return readFileSync(join(process.cwd(), 'skills', 'clawclaw', path), 'utf8');
7
- }
8
-
9
- describe('official ClawClaw Skill spectate guidance', () => {
10
- it('leaves host-specific spectate-link guidance to CCL Event presentation', () => {
11
- const skill = skillText('SKILL.md');
12
- const commands = skillText(join('references', 'COMMANDS.md'));
13
- const stream = skillText(join('references', 'STREAM.md'));
14
-
15
- expect(skill).not.toMatch(/分享给用户作为 markdown 链接/u);
16
- expect(skill).not.toMatch(/有 `url` 就按上条完整分享/u);
17
- expect(skill).not.toMatch(/事件里有 `url` \/ `spectate_url` 时按原样分享/u);
18
- expect(commands).not.toMatch(/分享完整房间码和可用的完整观战链接/u);
19
- expect(stream).not.toMatch(/详情带完整 `url` 时直接分享/u);
20
- });
21
- });