@myclaw163/clawclaw-cli 0.8.4 → 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 (241) hide show
  1. package/README.md +3 -2
  2. package/docs/configuration.md +44 -26
  3. package/docs/custom-modules/README.md +7 -10
  4. package/docs/custom-modules/behavior.md +3 -1
  5. package/docs/custom-modules/perception.md +1 -1
  6. package/docs/custom-modules/trigger.md +1 -1
  7. package/docs/runtime/README.md +4 -4
  8. package/docs/runtime/official-perception-modules.md +2 -2
  9. package/docs/runtime/owner-lifecycle-and-observability.md +1 -1
  10. package/package.json +9 -2
  11. package/scripts/build-official-hub-behaviors.mjs +136 -0
  12. package/scripts/build-official-hub-behaviors.test.mjs +178 -0
  13. package/scripts/enable_ccl_permissions.cjs +4 -2
  14. package/scripts/enable_ccl_permissions.test.mjs +8 -4
  15. package/scripts/postinstall.mjs +1 -4
  16. package/scripts/sync-bundled-skill.mjs +12 -159
  17. package/scripts/sync-bundled-skill.test.mjs +9 -74
  18. package/skills/clawclaw/SKILL.md +14 -9
  19. package/skills/clawclaw/references/BEHAVIORS.md +4 -4
  20. package/skills/clawclaw/references/COMMANDS.md +32 -16
  21. package/skills/clawclaw/references/HUB.md +25 -38
  22. package/src/commands/account.ts +58 -14
  23. package/src/commands/behavior.ts +116 -38
  24. package/src/commands/hub.ts +110 -153
  25. package/src/commands/load.ts +138 -33
  26. package/src/commands/perception.ts +55 -24
  27. package/src/commands/persona.ts +66 -20
  28. package/src/commands/skill.ts +12 -48
  29. package/src/commands/trigger.ts +68 -40
  30. package/src/hub-official-behaviors/kill-lone.ts +138 -0
  31. package/src/hub-official-behaviors/patrol.ts +30 -0
  32. package/src/hub-official-behaviors/shared.ts +125 -0
  33. package/src/hub-official-behaviors/task-only.ts +158 -0
  34. package/src/lib/account-guidance.ts +54 -9
  35. package/src/lib/agent-workspace-client.ts +135 -0
  36. package/src/lib/agent-workspace-runtime.ts +154 -0
  37. package/src/lib/agent-workspace-skills.ts +177 -0
  38. package/src/lib/agent-workspace-sync.ts +852 -0
  39. package/src/lib/gameplay-config.ts +29 -15
  40. package/src/lib/hub-client.ts +252 -34
  41. package/src/lib/hub-reminder.ts +22 -7
  42. package/src/lib/init-command.ts +0 -6
  43. package/src/lib/load-context.ts +12 -6
  44. package/src/lib/persona.ts +141 -69
  45. package/src/lib/server-status.ts +78 -0
  46. package/src/lib/skill-host.ts +160 -0
  47. package/src/lib/user-data.ts +197 -4
  48. package/src/runtime/clawclaw/owner.ts +63 -19
  49. package/src/runtime/clawclaw/plugins/behavior/activation-manager.ts +8 -2
  50. package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +2 -2
  51. package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +4 -1
  52. package/src/runtime/clawclaw/plugins/perception/perception-source.ts +11 -5
  53. package/src/runtime/clawclaw/plugins/perception/replay.ts +0 -2
  54. package/personas//345/217/243/346/230/257/345/277/203/351/235/236.md +0 -50
  55. package/personas//345/277/240/345/277/203/350/200/201/344/273/206.md +0 -51
  56. package/personas//346/227/240/344/272/272/350/256/276.md +0 -1
  57. package/personas//350/264/253/345/230/264/346/215/237/345/217/213.md +0 -48
  58. package/personas//350/275/257/350/220/214/350/205/271/351/273/221.md +0 -51
  59. package/src/behaviors/official-finite/index.test.ts +0 -249
  60. package/src/channel/claude-channel-server.test.ts +0 -202
  61. package/src/commands/account.test.ts +0 -570
  62. package/src/commands/behavior.test.ts +0 -158
  63. package/src/commands/communication.test.ts +0 -282
  64. package/src/commands/competition.test.ts +0 -116
  65. package/src/commands/data.test.ts +0 -89
  66. package/src/commands/events-canonical-state.test.ts +0 -406
  67. package/src/commands/events.test.ts +0 -58
  68. package/src/commands/game/index.test.ts +0 -1251
  69. package/src/commands/game-map.test.ts +0 -69
  70. package/src/commands/hub.test.ts +0 -124
  71. package/src/commands/load.test.ts +0 -440
  72. package/src/commands/perception.test.ts +0 -75
  73. package/src/commands/setup/hermes.test.ts +0 -96
  74. package/src/commands/setup/openclaw.test.ts +0 -124
  75. package/src/commands/trigger.test.ts +0 -140
  76. package/src/commands/upgrade.test.ts +0 -82
  77. package/src/lib/account-guidance.test.ts +0 -36
  78. package/src/lib/auth.test.ts +0 -151
  79. package/src/lib/behavior-export.test.ts +0 -326
  80. package/src/lib/behavior-export.ts +0 -537
  81. package/src/lib/clawclaw-skill-spectate-guidance.test.ts +0 -21
  82. package/src/lib/custom-tts.test.ts +0 -387
  83. package/src/lib/diagnostics-config.test.ts +0 -59
  84. package/src/lib/game-client-tts.test.ts +0 -151
  85. package/src/lib/game-client.test.ts +0 -250
  86. package/src/lib/gameplay-config.test.ts +0 -301
  87. package/src/lib/host-config-patcher.test.ts +0 -130
  88. package/src/lib/http-transport.test.ts +0 -124
  89. package/src/lib/hub-client.test.ts +0 -57
  90. package/src/lib/hub-install.test.ts +0 -135
  91. package/src/lib/hub-install.ts +0 -185
  92. package/src/lib/hub-unzip.test.ts +0 -69
  93. package/src/lib/init-command.test.ts +0 -103
  94. package/src/lib/load-context.test.ts +0 -62
  95. package/src/lib/match-state.test.ts +0 -134
  96. package/src/lib/official-resource-sync.test.ts +0 -199
  97. package/src/lib/official-resource-sync.ts +0 -221
  98. package/src/lib/perception-config.test.ts +0 -143
  99. package/src/lib/perception-export.test.ts +0 -145
  100. package/src/lib/perception-export.ts +0 -178
  101. package/src/lib/persona.test.ts +0 -84
  102. package/src/lib/room.test.ts +0 -88
  103. package/src/lib/server-registry.test.ts +0 -64
  104. package/src/lib/service-status.test.ts +0 -81
  105. package/src/lib/skill-version.test.ts +0 -48
  106. package/src/lib/trigger-config.test.ts +0 -102
  107. package/src/lib/trigger-export.test.ts +0 -80
  108. package/src/lib/trigger-export.ts +0 -210
  109. package/src/lib/user-data.test.ts +0 -121
  110. package/src/lib/workspace-argv.test.ts +0 -49
  111. package/src/pipeline/canonical-event-presentation.test.ts +0 -257
  112. package/src/pipeline/event-format.test.ts +0 -879
  113. package/src/pipeline/event-hints.test.ts +0 -337
  114. package/src/pipeline/game-sync-event-normalization.test.ts +0 -419
  115. package/src/pipeline/player-projection.test.ts +0 -247
  116. package/src/runtime/auto-upgrade.test.ts +0 -66
  117. package/src/runtime/canonical-event-emitter.test.ts +0 -70
  118. package/src/runtime/canonical-monitor.test.ts +0 -577
  119. package/src/runtime/clawclaw/agent-event-policy.test.ts +0 -60
  120. package/src/runtime/clawclaw/behavior-decision.test.ts +0 -43
  121. package/src/runtime/clawclaw/behavior-input-fields.test.ts +0 -175
  122. package/src/runtime/clawclaw/behavior-input.test.ts +0 -173
  123. package/src/runtime/clawclaw/behavior-observation-memory.test.ts +0 -59
  124. package/src/runtime/clawclaw/behavior-read-api.test.ts +0 -123
  125. package/src/runtime/clawclaw/notifications.test.ts +0 -47
  126. package/src/runtime/clawclaw/owner-lock.test.ts +0 -221
  127. package/src/runtime/clawclaw/owner.test.ts +0 -203
  128. package/src/runtime/clawclaw/plugins/action/action-plugin.test.ts +0 -328
  129. package/src/runtime/clawclaw/plugins/assembly.test.ts +0 -200
  130. package/src/runtime/clawclaw/plugins/behavior/activation-manager.test.ts +0 -180
  131. package/src/runtime/clawclaw/plugins/behavior/behavior-action.test.ts +0 -43
  132. package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.test.ts +0 -156
  133. package/src/runtime/clawclaw/plugins/behavior/behavior-module-loader.test.ts +0 -182
  134. package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.test.ts +0 -1094
  135. package/src/runtime/clawclaw/plugins/behavior/behavior-source.test.ts +0 -174
  136. package/src/runtime/clawclaw/plugins/behavior/control-driver.test.ts +0 -195
  137. package/src/runtime/clawclaw/plugins/behavior/thread-behavior-executor.test.ts +0 -283
  138. package/src/runtime/clawclaw/plugins/behavior-input-source.test.ts +0 -80
  139. package/src/runtime/clawclaw/plugins/derived-event/derived-event-plugin.test.ts +0 -267
  140. package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.test.ts +0 -226
  141. package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-adapter.test.ts +0 -239
  142. package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.test.ts +0 -407
  143. package/src/runtime/clawclaw/plugins/mailbox/desktop-event-push.integration.test.ts +0 -397
  144. package/src/runtime/clawclaw/plugins/mailbox/desktop-event-socket.test.ts +0 -270
  145. package/src/runtime/clawclaw/plugins/mailbox/mailbox-agent-event-batch.test.ts +0 -166
  146. package/src/runtime/clawclaw/plugins/mailbox/mailbox-event-batch-delivery.test.ts +0 -194
  147. package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.test.ts +0 -87
  148. package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.test.ts +0 -2012
  149. package/src/runtime/clawclaw/plugins/perception/module-runner.test.ts +0 -214
  150. package/src/runtime/clawclaw/plugins/perception/modules/co-movement-module.ts +0 -347
  151. package/src/runtime/clawclaw/plugins/perception/modules/corpse-visibility-module.test.ts +0 -92
  152. package/src/runtime/clawclaw/plugins/perception/modules/corpse-visibility-module.ts +0 -248
  153. package/src/runtime/clawclaw/plugins/perception/modules/follow-module.ts +0 -389
  154. package/src/runtime/clawclaw/plugins/perception/modules/index.ts +0 -8
  155. package/src/runtime/clawclaw/plugins/perception/modules/motion-module.test.ts +0 -342
  156. package/src/runtime/clawclaw/plugins/perception/modules/motion-module.ts +0 -475
  157. package/src/runtime/clawclaw/plugins/perception/modules/parallel-module-test-helpers.ts +0 -30
  158. package/src/runtime/clawclaw/plugins/perception/modules/relation-stability.test.ts +0 -304
  159. package/src/runtime/clawclaw/plugins/perception/modules/route-module.test.ts +0 -179
  160. package/src/runtime/clawclaw/plugins/perception/modules/route-module.ts +0 -364
  161. package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.test.ts +0 -81
  162. package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.ts +0 -200
  163. package/src/runtime/clawclaw/plugins/perception/modules/stop-module.test.ts +0 -216
  164. package/src/runtime/clawclaw/plugins/perception/modules/stop-module.ts +0 -284
  165. package/src/runtime/clawclaw/plugins/perception/modules/temporal-evidence.test.ts +0 -120
  166. package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.test.ts +0 -105
  167. package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.ts +0 -269
  168. package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.test.ts +0 -865
  169. package/src/runtime/clawclaw/plugins/perception/perception-plugin.test.ts +0 -1878
  170. package/src/runtime/clawclaw/plugins/perception/perception-source.test.ts +0 -278
  171. package/src/runtime/clawclaw/plugins/perception/replay.test.ts +0 -77
  172. package/src/runtime/clawclaw/plugins/runtime-plugins.test.ts +0 -853
  173. package/src/runtime/clawclaw/plugins/source/game-transport.test.ts +0 -287
  174. package/src/runtime/clawclaw/plugins/source/player-change-tracker.test.ts +0 -321
  175. package/src/runtime/clawclaw/plugins/source/room-transport.test.ts +0 -307
  176. package/src/runtime/clawclaw/plugins/source/source-plugin.test.ts +0 -2646
  177. package/src/runtime/clawclaw/plugins/source/task-change-tracker.test.ts +0 -212
  178. package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.test.ts +0 -548
  179. package/src/runtime/clawclaw/plugins/trigger/trigger-source.test.ts +0 -169
  180. package/src/runtime/clawclaw/runtime-data-export.test.ts +0 -249
  181. package/src/runtime/clawclaw-event-catalog.test.ts +0 -128
  182. package/src/runtime/framework/action-diagnostics.test.ts +0 -81
  183. package/src/runtime/framework/capability-registry.test.ts +0 -423
  184. package/src/runtime/framework/control-coordinator.test.ts +0 -675
  185. package/src/runtime/framework/events/event-delivery-service.test.ts +0 -84
  186. package/src/runtime/framework/events/event-ingress.test.ts +0 -203
  187. package/src/runtime/framework/events/mailbox-event-repositories.test.ts +0 -710
  188. package/src/runtime/framework/events/sqlite-event-repository.test.ts +0 -802
  189. package/src/runtime/framework/mailbox/coalescer.test.ts +0 -55
  190. package/src/runtime/framework/mailbox/identity.test.ts +0 -38
  191. package/src/runtime/framework/mailbox/mailbox-dispatcher.test.ts +0 -513
  192. package/src/runtime/framework/mailbox/notification-projector.test.ts +0 -77
  193. package/src/runtime/framework/modules/runtime-module-loader.test.ts +0 -435
  194. package/src/runtime/framework/participation-manager.test.ts +0 -108
  195. package/src/runtime/framework/plugins/runtime-input-journal.test.ts +0 -179
  196. package/src/runtime/framework/plugins/runtime-plugin-scheduler.test.ts +0 -2040
  197. package/src/runtime/framework/state/durable-agent-state-snapshot.test.ts +0 -144
  198. package/src/runtime/framework/state/history/sqlite-state-history-repository.test.ts +0 -157
  199. package/src/runtime/framework/state/history/state-history.test.ts +0 -251
  200. package/src/runtime/framework/state/state-core.test.ts +0 -197
  201. package/src/runtime/game-sync-protocol.test.ts +0 -123
  202. package/src/runtime/host-monitor-rate-gate.test.ts +0 -73
  203. package/src/runtime/mailbox-host-relay.test.ts +0 -293
  204. package/src/runtime/observability/observability.test.ts +0 -583
  205. package/src/runtime/owner-control.test.ts +0 -153
  206. package/src/runtime/parent-process-watch.test.ts +0 -27
  207. package/src/runtime/pending-event-handoff.test.ts +0 -29
  208. package/src/runtime/raw-ws-log.test.ts +0 -102
  209. package/src/runtime/runtime-logger.test.ts +0 -58
  210. package/src/runtime/runtime-persistence.test.ts +0 -26
  211. package/src/runtime/runtime.test.ts +0 -1770
  212. package/src/runtime/ws-client.test.ts +0 -562
  213. package/src/sdk/action.test.ts +0 -8
  214. package/src/sdk/behavior-plugin/index.test.ts +0 -74
  215. package/src/sdk/index.test.ts +0 -45
  216. package/src/sdk/module-input/index.test.ts +0 -49
  217. package/src/sdk/perception-plugin/index.test.ts +0 -22
  218. package/src/sdk/resource-metadata.test.ts +0 -40
  219. package/src/sdk/trigger-plugin/index.test.ts +0 -41
  220. package/src/short-command/classifier.test.ts +0 -107
  221. package/src/short-command/presenter.test.ts +0 -119
  222. package/src/short-command/runner.test.ts +0 -78
  223. package/src/short-command/sensitive-data-filter.test.ts +0 -56
  224. package/src/short-command/transport-response.test.ts +0 -39
  225. package/src/strategies/custom-module.test.ts +0 -267
  226. package/src/strategies/game-utils.test.ts +0 -305
  227. package/src/strategies/goals/avoid-players-top.test.ts +0 -95
  228. package/src/strategies/goals/crab-sabotage-top.test.ts +0 -131
  229. package/src/strategies/goals/kill-lone-top.test.ts +0 -96
  230. package/src/strategies/goals/kill-target-top.test.ts +0 -65
  231. package/src/strategies/goals/lone-kill-task-top.test.ts +0 -84
  232. package/src/strategies/goals/normal-shrimp-top.test.ts +0 -112
  233. package/src/strategies/goals/paradise-fish-top.test.ts +0 -203
  234. package/src/strategies/goals/task-only-top.test.ts +0 -88
  235. package/src/strategies/goals/warrior-shrimp-top.test.ts +0 -138
  236. package/src/strategies/meeting-gate.test.ts +0 -59
  237. package/src/strategies/official-long-behavior.test.ts +0 -89
  238. package/src/strategies/pathfind/astar-path.test.ts +0 -198
  239. package/src/strategies/pathfind/escape-planner.test.ts +0 -223
  240. package/src/strategies/player-targets.test.ts +0 -10
  241. package/src/strategies/task-only.test.ts +0 -138
@@ -1,537 +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
- unlinkSync,
9
- } from 'node:fs';
10
- import { createHash } from 'node:crypto';
11
- import {
12
- basename,
13
- dirname,
14
- join,
15
- resolve,
16
- } from 'node:path';
17
- import { fileURLToPath } from 'node:url';
18
- import { getWorkspaceDir } from './init-command.js';
19
- import {
20
- hashOfficialResourceContent,
21
- isOfficialResourceUnmodified,
22
- readOfficialResourceManifest,
23
- syncOfficialResources,
24
- writeOfficialResourceManifest,
25
- type OfficialResourceManifestEntry,
26
- type OfficialResourceSyncResult,
27
- } from './official-resource-sync.js';
28
- import {
29
- ensureUserDataLayout,
30
- getUserDataBehaviorsDir,
31
- getUserDataOfficialBehaviorsManifestFile,
32
- } from './user-data.js';
33
- import { isClawclawFixedEventType } from '../runtime/clawclaw-event-catalog.js';
34
- import { ClawclawBehaviorCatalog } from '../runtime/clawclaw/plugins/behavior/behavior-catalog.js';
35
- import {
36
- listClawclawBehaviorSources,
37
- type ClawclawBehaviorSourceProvenance,
38
- type ResolvedClawclawBehaviorSource,
39
- } from '../runtime/clawclaw/plugins/behavior/behavior-source.js';
40
- import { deepFreezeBehaviorValue } from '../runtime/clawclaw/plugins/behavior/behavior-manifest.js';
41
-
42
- const OFFICIAL_BEHAVIOR_EXPORT_FORMAT = 1 as const;
43
- const RETIRED_OFFICIAL_BEHAVIOR_IDS = new Set(['trigger_alarm']);
44
-
45
- const OFFICIAL_LONG_BEHAVIOR_FILES = Object.freeze([
46
- 'avoid-lone.ts',
47
- 'avoid-players.ts',
48
- 'corpse-patrol.ts',
49
- 'crab-sabotage.ts',
50
- 'find-player.ts',
51
- 'hide.ts',
52
- 'kill-frenzy.ts',
53
- 'kill-lone.ts',
54
- 'kill-target.ts',
55
- 'lone-kill-task.ts',
56
- 'move-room.ts',
57
- 'paradise-fish.ts',
58
- 'patrol.ts',
59
- 'report-patrol.ts',
60
- 'shrimp-memory.ts',
61
- 'social-task.ts',
62
- 'task-kill-report.ts',
63
- 'task-only.ts',
64
- 'task-report.ts',
65
- 'warrior-memory.ts',
66
- ] as const);
67
-
68
- const OFFICIAL_FINITE_BEHAVIOR_FILES = Object.freeze([
69
- 'do-task.ts',
70
- 'evade.ts',
71
- 'find-player.ts',
72
- 'follow-player.ts',
73
- 'go-to.ts',
74
- 'hide-temporarily.ts',
75
- 'hold-position.ts',
76
- 'hunt-player.ts',
77
- 'inspect-corpse.ts',
78
- 'patrol-area.ts',
79
- 'report-corpse.ts',
80
- 'seek-kill-opportunity.ts',
81
- ] as const);
82
-
83
- export type OfficialBehaviorFamily = 'long' | 'finite';
84
-
85
- export interface OfficialBehaviorProvenance {
86
- readonly kind: 'clawclaw.official-behavior';
87
- readonly family: OfficialBehaviorFamily;
88
- /** Package-relative source identity, never a machine-local absolute path. */
89
- readonly source: string;
90
- readonly materializationFormat: typeof OFFICIAL_BEHAVIOR_EXPORT_FORMAT;
91
- }
92
-
93
- export interface OfficialBehaviorManifestEntry extends OfficialResourceManifestEntry {
94
- readonly provenance?: OfficialBehaviorProvenance;
95
- }
96
-
97
- export type OfficialBehaviorManifest = Record<string, OfficialBehaviorManifestEntry>;
98
-
99
- interface BundledOfficialBehaviorSource {
100
- readonly id: string;
101
- readonly className: string;
102
- readonly family: OfficialBehaviorFamily;
103
- readonly fileName: string;
104
- readonly path: string;
105
- readonly source: string;
106
- readonly manifestObject: string;
107
- readonly provenance: OfficialBehaviorProvenance;
108
- readonly sourceHash: string;
109
- }
110
-
111
- function packageSourceRoot(): string {
112
- return join(dirname(fileURLToPath(import.meta.url)), '..');
113
- }
114
-
115
- function readPackageVersion(): string {
116
- try {
117
- const path = join(packageSourceRoot(), '..', 'package.json');
118
- const parsed = JSON.parse(readFileSync(path, 'utf8')) as { version?: unknown };
119
- return typeof parsed.version === 'string' ? parsed.version : '0.0.0';
120
- } catch {
121
- return '0.0.0';
122
- }
123
- }
124
-
125
- function balancedObject(source: string, open: number): string | null {
126
- let depth = 0;
127
- let quote: "'" | '"' | '`' | undefined;
128
- let escaped = false;
129
- let lineComment = false;
130
- let blockComment = false;
131
- for (let index = open; index < source.length; index += 1) {
132
- const char = source[index]!;
133
- const next = source[index + 1];
134
- if (lineComment) {
135
- if (char === '\n' || char === '\r') lineComment = false;
136
- continue;
137
- }
138
- if (blockComment) {
139
- if (char === '*' && next === '/') {
140
- blockComment = false;
141
- index += 1;
142
- }
143
- continue;
144
- }
145
- if (quote) {
146
- if (escaped) escaped = false;
147
- else if (char === '\\') escaped = true;
148
- else if (char === quote) quote = undefined;
149
- continue;
150
- }
151
- if (char === '/' && next === '/') {
152
- lineComment = true;
153
- index += 1;
154
- continue;
155
- }
156
- if (char === '/' && next === '*') {
157
- blockComment = true;
158
- index += 1;
159
- continue;
160
- }
161
- if (char === "'" || char === '"' || char === '`') {
162
- quote = char;
163
- continue;
164
- }
165
- if (char === '{') depth += 1;
166
- else if (char === '}' && --depth === 0) return source.slice(open, index + 1);
167
- }
168
- return null;
169
- }
170
-
171
- function parseBundledBehavior(
172
- family: OfficialBehaviorFamily,
173
- fileName: string,
174
- ): BundledOfficialBehaviorSource {
175
- const relativeSource = family === 'long'
176
- ? `strategies/${fileName}`
177
- : `behaviors/official-finite/${fileName}`;
178
- const path = join(packageSourceRoot(), ...relativeSource.split('/'));
179
- if (!existsSync(path)) throw new Error(`Bundled Behavior source '${relativeSource}' is missing.`);
180
- const source = readFileSync(path, 'utf8');
181
- const classMatch = /export\s+default\s+class\s+([A-Za-z_$][\w$]*)\s+extends\s+ClawclawBehavior(?:\s*<[\s\S]{0,1000}?>)?\s*\{/.exec(source);
182
- if (!classMatch) {
183
- throw new Error(`Bundled Behavior '${relativeSource}' is not a direct ClawclawBehavior class.`);
184
- }
185
- const manifestMatch = /\bstatic\s+(?:override\s+)?(?:readonly\s+)?manifest\s*=\s*\{/.exec(source);
186
- if (!manifestMatch) throw new Error(`Bundled Behavior '${relativeSource}' has no literal manifest.`);
187
- const manifestOpen = manifestMatch.index + manifestMatch[0].lastIndexOf('{');
188
- const manifestObject = balancedObject(source, manifestOpen);
189
- if (!manifestObject) throw new Error(`Bundled Behavior '${relativeSource}' has an invalid manifest.`);
190
- const id = /\bid\s*:\s*(['"])([a-z0-9][a-z0-9._-]*)\1/.exec(manifestObject)?.[2];
191
- if (!id) throw new Error(`Bundled Behavior '${relativeSource}' has no literal id.`);
192
- const provenance: OfficialBehaviorProvenance = Object.freeze({
193
- kind: 'clawclaw.official-behavior',
194
- family,
195
- source: relativeSource,
196
- materializationFormat: OFFICIAL_BEHAVIOR_EXPORT_FORMAT,
197
- });
198
- return Object.freeze({
199
- id,
200
- className: classMatch[1]!,
201
- family,
202
- fileName,
203
- path,
204
- source,
205
- manifestObject,
206
- provenance,
207
- sourceHash: hashOfficialResourceContent(
208
- `${source}\0behavior-export-v${OFFICIAL_BEHAVIOR_EXPORT_FORMAT}\0${JSON.stringify(provenance)}`,
209
- ),
210
- });
211
- }
212
-
213
- function listBundledOfficialBehaviorSources(): readonly BundledOfficialBehaviorSource[] {
214
- const sources = [
215
- ...OFFICIAL_LONG_BEHAVIOR_FILES.map((file) => parseBundledBehavior('long', file)),
216
- ...OFFICIAL_FINITE_BEHAVIOR_FILES.map((file) => parseBundledBehavior('finite', file)),
217
- ];
218
- const ids = new Set<string>();
219
- for (const source of sources) {
220
- if (ids.has(source.id)) throw new Error(`Duplicate bundled Behavior id '${source.id}'.`);
221
- ids.add(source.id);
222
- }
223
- if (sources.filter(({ family }) => family === 'long').length !== 20) {
224
- throw new Error('Expected exactly 20 bundled long Behaviors.');
225
- }
226
- if (sources.filter(({ family }) => family === 'finite').length !== 12) {
227
- throw new Error('Expected exactly 12 bundled finite Behaviors.');
228
- }
229
- return Object.freeze(sources);
230
- }
231
-
232
- /** Stable, non-executable metadata for tooling and tests. */
233
- export function listOfficialBehaviorDefinitions(): readonly Readonly<{
234
- id: string;
235
- family: OfficialBehaviorFamily;
236
- provenance: OfficialBehaviorProvenance;
237
- sourceHash: string;
238
- }>[] {
239
- return listBundledOfficialBehaviorSources().map((source) => Object.freeze({
240
- id: source.id,
241
- family: source.family,
242
- provenance: source.provenance,
243
- sourceHash: source.sourceHash,
244
- }));
245
- }
246
-
247
- function materializeBehavior(source: BundledOfficialBehaviorSource, version: string): string {
248
- const provenance = JSON.stringify(source.provenance);
249
- return [
250
- `// Materialized from official ${source.family} Behavior ${source.id}@${version}.`,
251
- `// provenance: ${provenance}`,
252
- `import {`,
253
- ` ClawclawBehavior,`,
254
- ` type BehaviorDecision,`,
255
- ` type BehaviorInput,`,
256
- ` type BehaviorNormalizationApi,`,
257
- ` type BehaviorReadApi,`,
258
- `} from '@myclaw163/clawclaw-cli/behavior-plugin';`,
259
- `import OfficialBehavior from 'clawclaw-internal:official-behavior/${source.id}';`,
260
- '',
261
- `type AnyBehaviorInput = Readonly<Record<string, unknown>>;`,
262
- `type OfficialBehaviorDelegate = {`,
263
- ` normalize?: (input: AnyBehaviorInput, api: BehaviorNormalizationApi) => AnyBehaviorInput;`,
264
- ` decide: (`,
265
- ` input: Readonly<BehaviorInput<AnyBehaviorInput>>,`,
266
- ` api: BehaviorReadApi,`,
267
- ` ) => BehaviorDecision | void | Promise<BehaviorDecision | void>;`,
268
- `};`,
269
- '',
270
- `export default class ${source.className} extends ClawclawBehavior<AnyBehaviorInput> {`,
271
- ` static override readonly manifest = ${source.manifestObject} as const;`,
272
- '',
273
- ` private readonly implementation = new OfficialBehavior() as unknown as OfficialBehaviorDelegate;`,
274
- '',
275
- ` override normalize(input: AnyBehaviorInput, api: BehaviorNormalizationApi): AnyBehaviorInput {`,
276
- ` return this.implementation.normalize?.(input, api) ?? input;`,
277
- ` }`,
278
- '',
279
- ` override decide(`,
280
- ` input: Readonly<BehaviorInput<AnyBehaviorInput>>,`,
281
- ` api: BehaviorReadApi,`,
282
- ` ): BehaviorDecision | void | Promise<BehaviorDecision | void> {`,
283
- ` return this.implementation.decide(input, api);`,
284
- ` }`,
285
- `}`,
286
- '',
287
- ].join('\n');
288
- }
289
-
290
- function sameProvenance(
291
- value: OfficialBehaviorProvenance | undefined,
292
- expected: OfficialBehaviorProvenance,
293
- ): boolean {
294
- return value?.kind === expected.kind
295
- && value.family === expected.family
296
- && value.source === expected.source
297
- && value.materializationFormat === expected.materializationFormat;
298
- }
299
-
300
- export function readOfficialBehaviorManifest(workspaceDir = getWorkspaceDir()): OfficialBehaviorManifest {
301
- return readOfficialResourceManifest(
302
- getUserDataOfficialBehaviorsManifestFile(workspaceDir),
303
- ) as OfficialBehaviorManifest;
304
- }
305
-
306
- function recordOfficialBehaviorProvenance(
307
- workspaceDir: string,
308
- sources: readonly BundledOfficialBehaviorSource[],
309
- ): void {
310
- const path = getUserDataOfficialBehaviorsManifestFile(workspaceDir);
311
- const manifest = readOfficialBehaviorManifest(workspaceDir);
312
- let changed = false;
313
- for (const source of sources) {
314
- const entry = manifest[source.id];
315
- if (!entry || entry.sourceHash !== source.sourceHash) continue;
316
- if (sameProvenance(entry.provenance, source.provenance)) continue;
317
- manifest[source.id] = { ...entry, provenance: source.provenance };
318
- changed = true;
319
- }
320
- if (changed) writeOfficialResourceManifest(path, manifest);
321
- }
322
-
323
- function retireRemovedOfficialBehaviors(workspaceDir: string): void {
324
- const manifestPath = getUserDataOfficialBehaviorsManifestFile(workspaceDir);
325
- const manifest = readOfficialBehaviorManifest(workspaceDir);
326
- let changed = false;
327
- for (const id of RETIRED_OFFICIAL_BEHAVIOR_IDS) {
328
- const entry = manifest[id];
329
- if (!entry) continue;
330
- const destination = join(getUserDataBehaviorsDir(workspaceDir), `${id}.ts`);
331
- if (existsSync(destination) && !isOfficialResourceUnmodified(destination, entry)) {
332
- // Preserve user edits, but the retired id is filtered from Runtime discovery.
333
- continue;
334
- }
335
- if (existsSync(destination)) unlinkSync(destination);
336
- delete manifest[id];
337
- changed = true;
338
- }
339
- if (changed) writeOfficialResourceManifest(manifestPath, manifest);
340
- }
341
-
342
- export interface SyncOfficialBehaviorsOptions {
343
- readonly workspaceDir?: string;
344
- readonly ids?: readonly string[];
345
- readonly force?: boolean;
346
- }
347
-
348
- export async function syncOfficialBehaviors(
349
- options: SyncOfficialBehaviorsOptions = {},
350
- ): Promise<OfficialResourceSyncResult> {
351
- const workspaceDir = options.workspaceDir ?? getWorkspaceDir();
352
- ensureUserDataLayout(workspaceDir);
353
- const destinationDir = getUserDataBehaviorsDir(workspaceDir);
354
- const bundled = listBundledOfficialBehaviorSources();
355
- const installedSources = new Map(
356
- listClawclawBehaviorSources(destinationDir).map((source) => [source.id, source]),
357
- );
358
- const result = await syncOfficialResources({
359
- sources: bundled,
360
- manifestPath: getUserDataOfficialBehaviorsManifestFile(workspaceDir),
361
- destinationPath: (source) => join(destinationDir, `${source.id}.ts`),
362
- hasUntrackedConflict: (source, destination) => {
363
- const installed = installedSources.get(source.id);
364
- return installed !== undefined && resolve(installed.sourcePath) !== resolve(destination);
365
- },
366
- materialize: materializeBehavior,
367
- version: readPackageVersion(),
368
- ids: options.ids,
369
- force: options.force,
370
- notFoundMessage: (id) => `Built-in Behavior '${id}' not found.`,
371
- });
372
- if (options.ids === undefined) retireRemovedOfficialBehaviors(workspaceDir);
373
- recordOfficialBehaviorProvenance(workspaceDir, bundled);
374
- return result;
375
- }
376
-
377
- function trustedOfficialSource(
378
- workspaceDir: string,
379
- source: ResolvedClawclawBehaviorSource,
380
- bundled: ReadonlyMap<string, BundledOfficialBehaviorSource>,
381
- manifest: OfficialBehaviorManifest,
382
- ): ResolvedClawclawBehaviorSource {
383
- const official = bundled.get(source.id);
384
- const entry = manifest[source.id];
385
- if (!official || !entry) return source;
386
- const canonicalPath = resolve(getUserDataBehaviorsDir(workspaceDir), `${source.id}.ts`);
387
- if (
388
- resolve(source.sourcePath) !== canonicalPath
389
- || entry.format !== 1
390
- || typeof entry.version !== 'string'
391
- || !/^[0-9A-Za-z][0-9A-Za-z.+-]{0,63}$/.test(entry.version)
392
- || entry.sourceHash !== official.sourceHash
393
- || !sameProvenance(entry.provenance, official.provenance)
394
- || typeof entry.installedHash !== 'string'
395
- ) return source;
396
-
397
- let installed: string;
398
- try {
399
- installed = readFileSync(source.sourcePath, 'utf8');
400
- } catch {
401
- return source;
402
- }
403
- const installedHash = hashOfficialResourceContent(installed);
404
- const expected = materializeBehavior(official, entry.version);
405
- // The shared manifest keeps compact operational hashes. Privilege is
406
- // stricter: byte-for-byte deterministic content equality avoids treating a
407
- // truncated-hash collision or a forged manifest as official code.
408
- if (installedHash !== entry.installedHash || installed !== expected) return source;
409
-
410
- const allowReservedProduces = (source.produces ?? []).filter(isClawclawFixedEventType);
411
- const provenance: ClawclawBehaviorSourceProvenance = {
412
- kind: 'official',
413
- family: official.family,
414
- source: official.provenance.source,
415
- };
416
- return deepFreezeBehaviorValue({
417
- ...source,
418
- provenance,
419
- trustedSourceSha256: createHash('sha256').update(installed).digest('hex'),
420
- ...(allowReservedProduces.length === 0 ? {} : { allowReservedProduces }),
421
- });
422
- }
423
-
424
- /**
425
- * Discover one workspace's unified Behavior directory and attach official
426
- * privileges only after deterministic source and installed-content proof.
427
- */
428
- export function listWorkspaceClawclawBehaviorSources(
429
- workspaceDir = getWorkspaceDir(),
430
- ): readonly ResolvedClawclawBehaviorSource[] {
431
- ensureUserDataLayout(workspaceDir);
432
- const bundled = new Map(
433
- listBundledOfficialBehaviorSources().map((source) => [source.id, source]),
434
- );
435
- const manifest = readOfficialBehaviorManifest(workspaceDir);
436
- return Object.freeze(
437
- listClawclawBehaviorSources(getUserDataBehaviorsDir(workspaceDir))
438
- .filter((source) => !RETIRED_OFFICIAL_BEHAVIOR_IDS.has(source.id))
439
- .map((source) => trustedOfficialSource(workspaceDir, source, bundled, manifest)),
440
- );
441
- }
442
-
443
- /** Build the lazy, static catalog used later by the Runtime assembly layer. */
444
- export function createWorkspaceClawclawBehaviorCatalog(
445
- workspaceDir = getWorkspaceDir(),
446
- ): ClawclawBehaviorCatalog {
447
- return new ClawclawBehaviorCatalog(listWorkspaceClawclawBehaviorSources(workspaceDir));
448
- }
449
-
450
- export async function exportBehavior(
451
- id: string,
452
- options: { readonly workspaceDir?: string; readonly force?: boolean } = {},
453
- ): Promise<void> {
454
- const workspaceDir = options.workspaceDir ?? getWorkspaceDir();
455
- const destination = join(getUserDataBehaviorsDir(workspaceDir), `${id}.ts`);
456
- const result = await syncOfficialBehaviors({
457
- workspaceDir,
458
- ids: [id],
459
- force: options.force,
460
- });
461
- if (result.preservedUntracked.includes(id)) {
462
- if (options.force) {
463
- throw new Error(`Another user-owned Behavior source already declares '${id}'; --force does not overwrite a different file path.`);
464
- }
465
- throw new Error(`${destination} already exists and is not tracked. Use --force to overwrite.`);
466
- }
467
- if (result.preservedModified.includes(id)) {
468
- throw new Error(`${destination} was modified. Use --force to overwrite.`);
469
- }
470
- if (result.preservedDeleted.includes(id)) {
471
- throw new Error(`${destination} was deleted after export. Use --force to restore.`);
472
- }
473
- }
474
-
475
- export function detectStaleOfficialBehaviors(
476
- workspaceDir = getWorkspaceDir(),
477
- ): string[] {
478
- const manifest = readOfficialBehaviorManifest(workspaceDir);
479
- const bundled = new Map(
480
- listBundledOfficialBehaviorSources().map((source) => [source.id, source]),
481
- );
482
- return Object.entries(manifest)
483
- .filter(([id, entry]) => {
484
- const source = bundled.get(id);
485
- return !source
486
- || entry.sourceHash !== source.sourceHash
487
- || !sameProvenance(entry.provenance, source.provenance);
488
- })
489
- .map(([id]) => id)
490
- .sort();
491
- }
492
-
493
- /**
494
- * True when the unified Behavior directory contains user-owned source or a
495
- * manifest-tracked official wrapper was edited/deleted. Helper, declaration,
496
- * and test files do not count as gameplay customization.
497
- */
498
- export function hasUserBehaviorCustomization(
499
- workspaceDir = getWorkspaceDir(),
500
- ): boolean {
501
- const directory = getUserDataBehaviorsDir(workspaceDir);
502
- const manifest = readOfficialBehaviorManifest(workspaceDir);
503
- let files: string[];
504
- try {
505
- files = readdirSync(directory);
506
- } catch {
507
- return false;
508
- }
509
-
510
- for (const file of files) {
511
- if (file.startsWith('_')) continue;
512
- if (!/\.(?:ts|tsx|js)$/.test(file)) continue;
513
- if (/\.d\.ts$|\.(?:test|spec)\.(?:ts|tsx|js)$/.test(file)) continue;
514
-
515
- const id = file.endsWith('.ts') ? basename(file, '.ts') : '';
516
- const entry = id ? manifest[id] : undefined;
517
- if (!entry || file !== `${id}.ts` || !entry.installedHash) return true;
518
- try {
519
- if (hashOfficialResourceContent(readFileSync(join(directory, file))) !== entry.installedHash) {
520
- return true;
521
- }
522
- } catch {
523
- return true;
524
- }
525
- }
526
-
527
- for (const [id, entry] of Object.entries(manifest)) {
528
- const path = join(directory, `${id}.ts`);
529
- if (!entry.installedHash || !existsSync(path)) return true;
530
- try {
531
- if (hashOfficialResourceContent(readFileSync(path)) !== entry.installedHash) return true;
532
- } catch {
533
- return true;
534
- }
535
- }
536
- return false;
537
- }
@@ -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
- });