@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,75 +0,0 @@
1
- import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
2
- import { tmpdir } from 'node:os';
3
- import { join } from 'node:path';
4
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
5
- import { createPerceptionCommand } from './perception.js';
6
-
7
- let workspaceDir: string;
8
- let logs: string[];
9
-
10
- beforeEach(() => {
11
- workspaceDir = mkdtempSync(join(tmpdir(), 'ccl-perception-command-'));
12
- process.env.CLAWCLAW_WORKSPACE_DIR = workspaceDir;
13
- logs = [];
14
- vi.spyOn(console, 'log').mockImplementation((...args) => logs.push(args.join(' ')));
15
- });
16
-
17
- afterEach(() => {
18
- delete process.env.CLAWCLAW_WORKSPACE_DIR;
19
- vi.restoreAllMocks();
20
- rmSync(workspaceDir, { recursive: true, force: true });
21
- });
22
-
23
- async function run(args: string[]): Promise<void> {
24
- await createPerceptionCommand().parseAsync(['node', 'ccl', ...args]);
25
- }
26
-
27
- describe('perception command', () => {
28
- it('lists installed modules and their enabled state', async () => {
29
- await run(['--list']);
30
- const output = JSON.parse(logs[0]);
31
- expect(output.perception_modules.map((module: any) => module.id))
32
- .toContain('visual.visibility');
33
- expect(output.perception_modules.every((module: any) => module.disabled === false)).toBe(true);
34
- });
35
-
36
- it('keeps missing disabled module ids without reporting an error', async () => {
37
- await run(['--disable', 'visual.removed']);
38
- const config = JSON.parse(
39
- readFileSync(join(workspaceDir, 'user-data', 'gameplay.json'), 'utf8'),
40
- );
41
- expect(config.disabled_perception_modules).toEqual(['visual.removed']);
42
-
43
- await run(['--list']);
44
- expect(JSON.parse(logs.at(-1)!).ignored_disabled_ids).toEqual(['visual.removed']);
45
- });
46
-
47
- it('marks an incompatible source non-loadable with an exact version diagnostic', async () => {
48
- await run(['--list']);
49
- writeFileSync(join(workspaceDir, 'user-data', 'perceptions', 'visual.legacy.ts'), `
50
- import { ClawclawPerception } from '@myclaw163/clawclaw-cli/perception-plugin';
51
- export default class LegacyPerception extends ClawclawPerception {
52
- static manifest = {
53
- apiVersion: 1,
54
- id: 'visual.legacy',
55
- name: 'Legacy perception',
56
- description: 'Legacy Perception API fixture.',
57
- subjectScope: 'others',
58
- produces: ['visual.legacy'],
59
- };
60
- update() {}
61
- }
62
- `, 'utf8');
63
-
64
- await run(['--list']);
65
-
66
- const legacy = JSON.parse(logs.at(-1)!).perception_modules
67
- .find(({ id }: any) => id === 'visual.legacy');
68
- expect(legacy).toMatchObject({
69
- api_version: 1,
70
- expected_api_version: 2,
71
- loadable: false,
72
- compatibility_error: 'perception_api_version_unsupported:expected=2:received=1',
73
- });
74
- });
75
- });
@@ -1,96 +0,0 @@
1
- import { describe, expect, it, vi, beforeEach } from 'vitest';
2
- import { runHermesSetup } from './hermes.js';
3
- import { spawnSync } from 'child_process';
4
-
5
- vi.mock('child_process', () => ({
6
- spawnSync: vi.fn(),
7
- }));
8
-
9
- const mockedSpawnSync = vi.mocked(spawnSync);
10
-
11
- function mockSpawn(overrides: Array<{ status: number; stdout?: string; stderr?: string }>) {
12
- mockedSpawnSync.mockImplementation((_cmd: any, _args?: any, _opts?: any): any => {
13
- const next = overrides.shift();
14
- if (!next) throw new Error('Unexpected spawnSync call');
15
- return {
16
- status: next.status,
17
- stdout: next.stdout ?? '',
18
- stderr: next.stderr ?? '',
19
- };
20
- });
21
- }
22
-
23
- beforeEach(() => {
24
- vi.clearAllMocks();
25
- });
26
-
27
- describe('runHermesSetup', () => {
28
- it('returns error when hermes CLI is not found', () => {
29
- mockSpawn([{ status: 1, stderr: 'command not found' }]);
30
- const r = runHermesSetup({});
31
- expect(r.exitCode).toBe(1);
32
- expect(r.output.some((l) => l.includes('not found'))).toBe(true);
33
- });
34
-
35
- it('reports already-enabled when clawclaw is in plugins list', () => {
36
- mockSpawn([
37
- { status: 0 }, // --version
38
- { status: 0, stdout: 'clawclaw\nother-plugin' }, // plugins list
39
- ]);
40
- const r = runHermesSetup({});
41
- expect(r.exitCode).toBe(0);
42
- expect(r.output.some((l) => l.includes('already enabled'))).toBe(true);
43
- });
44
-
45
- it('dry-run shows pending message when not enabled', () => {
46
- mockSpawn([
47
- { status: 0 }, // --version
48
- { status: 0, stdout: 'other-plugin' }, // plugins list
49
- ]);
50
- const r = runHermesSetup({});
51
- expect(r.exitCode).toBe(2);
52
- expect(r.output.some((l) => l.includes('Dry-run'))).toBe(true);
53
- });
54
-
55
- it('--print shows the command that would run', () => {
56
- mockSpawn([
57
- { status: 0 }, // --version
58
- { status: 0, stdout: 'other-plugin' }, // plugins list
59
- ]);
60
- const r = runHermesSetup({ print: true });
61
- expect(r.exitCode).toBe(0);
62
- expect(r.output.some((l) => l.includes('hermes plugins enable clawclaw'))).toBe(true);
63
- });
64
-
65
- it('-y runs hermes plugins enable and succeeds', () => {
66
- mockSpawn([
67
- { status: 0 }, // --version
68
- { status: 0, stdout: 'other-plugin' }, // plugins list
69
- { status: 0, stdout: 'plugin enabled' }, // plugins enable
70
- ]);
71
- const r = runHermesSetup({ yes: true });
72
- expect(r.exitCode).toBe(0);
73
- expect(r.output.some((l) => l.includes('enabled'))).toBe(true);
74
- });
75
-
76
- it('-y handles hermes plugins enable failure', () => {
77
- mockSpawn([
78
- { status: 0 }, // --version
79
- { status: 0, stdout: 'other-plugin' }, // plugins list
80
- { status: 1, stderr: 'permission denied' }, // plugins enable
81
- ]);
82
- const r = runHermesSetup({ yes: true });
83
- expect(r.exitCode).toBe(1);
84
- expect(r.output.some((l) => l.includes('Failed'))).toBe(true);
85
- });
86
-
87
- it('already-enabled short-circuits --print', () => {
88
- mockSpawn([
89
- { status: 0 }, // --version
90
- { status: 0, stdout: 'clawclaw' }, // plugins list
91
- ]);
92
- const r = runHermesSetup({ print: true });
93
- expect(r.exitCode).toBe(0);
94
- expect(r.output.some((l) => l.includes('already enabled'))).toBe(true);
95
- });
96
- });
@@ -1,124 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { computeOpenclawPatch, resolveOpenclawConfigPath } from './openclaw.js';
3
-
4
- describe('computeOpenclawPatch', () => {
5
- it('on empty config creates entries.enabled and tools.alsoAllow, but does NOT create plugins.allow', () => {
6
- const r = computeOpenclawPatch({}, {});
7
- expect(r.warnings).toEqual([]);
8
- expect(r.next).toEqual({
9
- plugins: { entries: { clawclaw: { enabled: true } } },
10
- tools: { alsoAllow: ['clawclaw', 'clawclaw:*'] },
11
- });
12
- expect(r.changes).toHaveLength(3);
13
- });
14
-
15
- it('null/non-object current is treated as empty', () => {
16
- const r1 = computeOpenclawPatch(null, {});
17
- expect(r1.warnings).toEqual([]);
18
- expect((r1.next as any).plugins.allow).toBeUndefined();
19
- expect((r1.next as any).plugins.entries.clawclaw.enabled).toBe(true);
20
- const r2 = computeOpenclawPatch(['unexpected'], {});
21
- expect(r2.warnings).toEqual([]);
22
- expect((r2.next as any).plugins.allow).toBeUndefined();
23
- });
24
-
25
- it('no-op when everything already present', () => {
26
- const current = {
27
- plugins: { allow: ['clawclaw'], entries: { clawclaw: { enabled: true } } },
28
- tools: { profile: 'coding', alsoAllow: ['clawclaw', 'clawclaw:*'] },
29
- };
30
- const r = computeOpenclawPatch(current, {});
31
- expect(r.changes).toEqual([]);
32
- expect(r.warnings).toEqual([]);
33
- expect(r.next).toEqual(current);
34
- });
35
-
36
- it('appends to existing plugins.allow without dupes', () => {
37
- const r = computeOpenclawPatch({ plugins: { allow: ['other'] } }, {});
38
- expect((r.next as any).plugins.allow).toEqual(['other', 'clawclaw']);
39
- expect(r.changes).toContain('add "clawclaw" to plugins.allow');
40
- });
41
-
42
- it('does not create plugins.allow when it does not exist', () => {
43
- const r = computeOpenclawPatch({ plugins: { entries: { browser: { enabled: true } } } }, {});
44
- expect((r.next as any).plugins.allow).toBeUndefined();
45
- expect((r.next as any).plugins.entries.clawclaw.enabled).toBe(true);
46
- // browser entry preserved
47
- expect((r.next as any).plugins.entries.browser).toEqual({ enabled: true });
48
- });
49
-
50
- it('Set union into existing tools.alsoAllow without dupes', () => {
51
- const r = computeOpenclawPatch({ tools: { profile: 'coding', alsoAllow: ['somethingElse'] } }, {});
52
- expect((r.next as any).tools.alsoAllow).toEqual(['somethingElse', 'clawclaw', 'clawclaw:*']);
53
- expect(r.changes).toContain('add "clawclaw" to tools.alsoAllow');
54
- expect(r.changes).toContain('add "clawclaw:*" to tools.alsoAllow');
55
- });
56
-
57
- it('does not touch tools.profile, even when not coding', () => {
58
- const r = computeOpenclawPatch({ tools: { profile: 'full' } }, {});
59
- expect((r.next as any).tools.profile).toBe('full');
60
- });
61
-
62
- it('does not touch tools.profile when missing (no opinion-setting)', () => {
63
- const r = computeOpenclawPatch({}, {});
64
- expect((r.next as any).tools.profile).toBeUndefined();
65
- });
66
-
67
- it('warns and skips when plugins.allow is not an array', () => {
68
- const r = computeOpenclawPatch({ plugins: { allow: 'oops' } }, {});
69
- expect(r.warnings.some((w) => w.includes('plugins.allow'))).toBe(true);
70
- // unchanged value
71
- expect((r.next as any).plugins.allow).toBe('oops');
72
- });
73
-
74
- it('warns and skips when tools.alsoAllow is not an array', () => {
75
- const r = computeOpenclawPatch({ tools: { alsoAllow: 'oops' } }, {});
76
- expect(r.warnings.some((w) => w.includes('tools.alsoAllow'))).toBe(true);
77
- expect((r.next as any).tools.alsoAllow).toBe('oops');
78
- });
79
-
80
- it('respects explicit enabled:false on entries.clawclaw', () => {
81
- const r = computeOpenclawPatch(
82
- { plugins: { entries: { clawclaw: { enabled: false } } } },
83
- {},
84
- );
85
- expect((r.next as any).plugins.entries.clawclaw.enabled).toBe(false);
86
- expect(r.warnings.some((w) => w.includes('explicitly false'))).toBe(true);
87
- // and we did not mark a change for it
88
- expect(r.changes.some((c) => c.includes('enabled = true'))).toBe(false);
89
- });
90
-
91
- it('--skip-plugins-allow leaves plugins untouched, still patches tools', () => {
92
- const r = computeOpenclawPatch({}, { skipPluginsAllow: true });
93
- expect((r.next as any).plugins).toBeUndefined();
94
- expect((r.next as any).tools.alsoAllow).toEqual(['clawclaw', 'clawclaw:*']);
95
- });
96
-
97
- it('--skip-tools-allow leaves tools untouched, still patches plugins', () => {
98
- const r = computeOpenclawPatch({}, { skipToolsAllow: true });
99
- expect((r.next as any).tools).toBeUndefined();
100
- expect((r.next as any).plugins.entries.clawclaw.enabled).toBe(true);
101
- });
102
-
103
- it('preserves unrelated top-level keys', () => {
104
- const r = computeOpenclawPatch(
105
- { models: { mode: 'replace' }, channels: { telegram: { enabled: true } } },
106
- {},
107
- );
108
- expect((r.next as any).models).toEqual({ mode: 'replace' });
109
- expect((r.next as any).channels).toEqual({ telegram: { enabled: true } });
110
- });
111
- });
112
-
113
- describe('resolveOpenclawConfigPath', () => {
114
- it('uses OPENCLAW_HOME when set', () => {
115
- const p = resolveOpenclawConfigPath({ OPENCLAW_HOME: '/tmp/oc' });
116
- expect(p.replace(/\\/g, '/')).toBe('/tmp/oc/openclaw.json');
117
- });
118
-
119
- it('falls back to ~/.openclaw/openclaw.json', () => {
120
- const p = resolveOpenclawConfigPath({});
121
- expect(p.endsWith('openclaw.json')).toBe(true);
122
- expect(p.includes('.openclaw')).toBe(true);
123
- });
124
- });
@@ -1,140 +0,0 @@
1
- import { Command } from 'commander';
2
- import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
3
- import { tmpdir } from 'node:os';
4
- import { join } from 'node:path';
5
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
6
- import { readGameplayConfig } from '../lib/gameplay-config.js';
7
- import { ensureUserDataLayout, getUserDataTriggersDir } from '../lib/user-data.js';
8
- import { createTriggerCommand, type TriggerCommandDependencies } from './trigger.js';
9
-
10
- describe('trigger command', () => {
11
- let workspaceDir: string;
12
- let previousWorkspace: string | undefined;
13
- let logs: string[];
14
-
15
- beforeEach(() => {
16
- workspaceDir = mkdtempSync(join(tmpdir(), 'ccl-trigger-command-'));
17
- previousWorkspace = process.env.CLAWCLAW_WORKSPACE_DIR;
18
- process.env.CLAWCLAW_WORKSPACE_DIR = workspaceDir;
19
- ensureUserDataLayout(workspaceDir);
20
- logs = [];
21
- vi.spyOn(console, 'log').mockImplementation((...args) => logs.push(args.join(' ')));
22
- writeFileSync(join(getUserDataTriggersDir(workspaceDir), 'tailing.ts'), `
23
- import { ClawclawTrigger } from '@myclaw163/clawclaw-cli/trigger-plugin';
24
- throw new Error('trigger discovery executed player code');
25
- export default class TailingTrigger extends ClawclawTrigger {
26
- static manifest = {
27
- apiVersion: 4,
28
- id: 'tailing',
29
- name: 'Tailing',
30
- description: 'Detects persistent followers.',
31
- inputs: [],
32
- consumes: ['player_moved'],
33
- defaultBehavior: 'evade',
34
- defaultBehaviorInput: {},
35
- defaultReflexPriority: 50,
36
- defaultCooldownMs: 1000,
37
- defaultRearm: 'after_clear',
38
- defaultMaxRuntimeMs: 5000,
39
- };
40
- evaluate() {}
41
- }
42
- `, 'utf8');
43
- });
44
-
45
- afterEach(() => {
46
- if (previousWorkspace === undefined) delete process.env.CLAWCLAW_WORKSPACE_DIR;
47
- else process.env.CLAWCLAW_WORKSPACE_DIR = previousWorkspace;
48
- vi.restoreAllMocks();
49
- rmSync(workspaceDir, { recursive: true, force: true });
50
- });
51
-
52
- async function run(args: string[], dependencies: TriggerCommandDependencies = {}): Promise<void> {
53
- const program = new Command().name('ccl');
54
- program.addCommand(createTriggerCommand(dependencies));
55
- await program.parseAsync(['node', 'ccl', 'trigger', ...args], { from: 'node' });
56
- }
57
-
58
- it('discovers community Trigger manifests statically and keeps them disabled by default', async () => {
59
- await run(['list']);
60
-
61
- const output = JSON.parse(logs.at(-1)!);
62
- expect(output.triggers).toEqual([
63
- expect.objectContaining({
64
- id: 'tailing',
65
- loadable: true,
66
- source: 'community',
67
- effective: expect.objectContaining({
68
- enabled: false,
69
- behavior: 'evade',
70
- reflex_priority: 50,
71
- }),
72
- }),
73
- ]);
74
- expect(readGameplayConfig(workspaceDir).triggers).toEqual({});
75
- });
76
-
77
- it('persists enablement and synchronizes the complete snake_case override to Owner', async () => {
78
- const send = vi.fn(async (_profile: unknown, type: string) => (
79
- type === 'snapshot'
80
- ? { ok: true, scope: { sessionId: 'session-1', segmentId: 'game-1' } }
81
- : { ok: true, type }
82
- ));
83
- const dependencies = {
84
- activeProfile: () => ({ apiKey: 'key', runtimeAccountId: 'account-1' }) as any,
85
- sendOwnerControlRequest: send as any,
86
- };
87
-
88
- await run(['enable', 'tailing'], dependencies);
89
- await run([
90
- 'configure',
91
- 'tailing',
92
- '--behavior',
93
- 'evade',
94
- '--behavior-input',
95
- '{"player_seats":[4]}',
96
- '--reflex-priority',
97
- '90',
98
- '--cooldown-ms',
99
- '2500',
100
- '--rearm',
101
- 'after_cooldown',
102
- '--max-runtime-ms',
103
- '9000',
104
- ], dependencies);
105
-
106
- expect(readGameplayConfig(workspaceDir).triggers.tailing).toEqual({
107
- enabled: true,
108
- behavior: 'evade',
109
- behavior_input: { player_seats: [4] },
110
- reflex_priority: 90,
111
- cooldown_ms: 2500,
112
- rearm: 'after_cooldown',
113
- max_runtime_ms: 9000,
114
- });
115
- expect(send).toHaveBeenLastCalledWith(
116
- expect.objectContaining({ runtimeAccountId: 'account-1' }),
117
- 'trigger_configure',
118
- {
119
- expected_scope: { sessionId: 'session-1', segmentId: 'game-1' },
120
- trigger: 'tailing',
121
- config: {
122
- enabled: true,
123
- behavior: 'evade',
124
- behavior_input: { player_seats: [4] },
125
- reflex_priority: 90,
126
- cooldown_ms: 2500,
127
- rearm: 'after_cooldown',
128
- max_runtime_ms: 9000,
129
- },
130
- },
131
- 30_000,
132
- );
133
- });
134
-
135
- it('rejects unknown Trigger modules instead of pre-authorizing a future installation', async () => {
136
- await expect(run(['enable', 'future-trigger']))
137
- .rejects.toThrow("Unknown or ambiguous trigger module 'future-trigger'.");
138
- expect(readGameplayConfig(workspaceDir).triggers).toEqual({});
139
- });
140
- });
@@ -1,82 +0,0 @@
1
- import { mkdirSync, mkdtempSync, writeFileSync } from 'fs';
2
- import { tmpdir } from 'os';
3
- import { join, resolve } from 'path';
4
- import { describe, expect, it } from 'vitest';
5
- import { installLatestFromNpm, runUpgrade, syncSkillFromInstalledPackage } from './upgrade.js';
6
-
7
- describe('runUpgrade', () => {
8
- it('installs and returns the installed cli version without syncing skill again', () => {
9
- let installed = false;
10
- const result = runUpgrade({
11
- installLatest: () => { installed = true; },
12
- readInstalledCliVersion: () => '0.4.7',
13
- });
14
- expect(installed).toBe(true);
15
- expect(result).toEqual({ version: '0.4.7' });
16
- });
17
-
18
- it('reports error when npm install fails', () => {
19
- const result = runUpgrade({
20
- installLatest: () => { throw new Error('EACCES'); },
21
- readInstalledCliVersion: () => '0.3.4',
22
- });
23
- expect(result.version).toBeUndefined();
24
- expect(result.error).toMatch(/npm install failed/);
25
- });
26
-
27
- it('installs latest from npm without registry flag', () => {
28
- const calls: Array<{ file: string; args: string[]; options: Record<string, unknown> }> = [];
29
- installLatestFromNpm('clawclaw-cli', (file, args, options) => {
30
- calls.push({ file, args, options });
31
- });
32
-
33
- expect(calls).toHaveLength(1);
34
- if (process.platform === 'win32') {
35
- expect(calls[0].file).toBe('cmd.exe');
36
- expect(calls[0].args).toEqual([
37
- '/d',
38
- '/c',
39
- 'npm.cmd install -g clawclaw-cli@latest --foreground-scripts --loglevel=error',
40
- ]);
41
- } else {
42
- expect(calls[0].args).toEqual([
43
- 'install',
44
- '-g',
45
- 'clawclaw-cli@latest',
46
- '--foreground-scripts',
47
- '--loglevel=error',
48
- ]);
49
- }
50
- expect(calls[0].options.stdio).toEqual(['ignore', 'ignore', 'inherit']);
51
- expect(calls[0].options.shell).toBe(false);
52
- });
53
-
54
- it('runs bundled skill sync script for explicit skill update', () => {
55
- const root = mkdtempSync(join(tmpdir(), 'upgrade-skill-'));
56
- const installDir = join(root, 'clawclaw-cli');
57
- const scriptPath = join(installDir, 'scripts', 'sync-bundled-skill.mjs');
58
- mkdirSync(join(installDir, 'scripts'), { recursive: true });
59
- writeFileSync(scriptPath, '');
60
-
61
- const calls: Array<{ file: string; args: string[]; options: Record<string, unknown> }> = [];
62
- syncSkillFromInstalledPackage('clawclaw-cli', (file, args, options) => {
63
- calls.push({ file, args, options });
64
- if (args[0] === 'root' || args.at(-1)?.includes('root -g')) return root;
65
- return '';
66
- });
67
-
68
- expect(calls).toHaveLength(2);
69
- expect(calls[1].file).toBe(process.execPath);
70
- expect(calls[1].args).toEqual([resolve(scriptPath)]);
71
- expect(calls[1].options.stdio).toBe('inherit');
72
- });
73
-
74
- it('reports error when reading installed version fails', () => {
75
- const result = runUpgrade({
76
- installLatest: () => {},
77
- readInstalledCliVersion: () => { throw new Error('missing package'); },
78
- });
79
- expect(result.version).toBeUndefined();
80
- expect(result.error).toMatch(/read installed cli version failed/);
81
- });
82
- });
@@ -1,36 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import {
3
- DEFAULT_NAME_REGISTER_COMMAND,
4
- NAMED_REGISTER_COMMAND,
5
- OFFICIAL_URL,
6
- POST_REGISTRATION_NEXT_STEP,
7
- noAccountMessage,
8
- registrationSuccessOutput,
9
- } from './account-guidance.js';
10
-
11
- describe('account guidance', () => {
12
- it('adds the fixed official URL and next step to registration success output', () => {
13
- const output = registrationSuccessOutput({ ok: true, officialUrl: 'https://example.com/' }, 'lobster-1');
14
-
15
- expect(output).toMatchObject({
16
- ok: true,
17
- message: 'Registered and saved as profile "lobster-1"',
18
- officialUrl: OFFICIAL_URL,
19
- next_step: POST_REGISTRATION_NEXT_STEP,
20
- });
21
- expect(output.next_step).toContain('`ccl load`');
22
- expect(output.next_step).toContain('`ccl start match`');
23
- expect(output.next_step).toContain('`ccl join`');
24
- expect(output.next_step).not.toContain('`ccl game start`');
25
- });
26
-
27
- it('keeps the official URL out of no-account setup guidance', () => {
28
- const message = noAccountMessage('load');
29
-
30
- expect(message).toContain('Cannot load persona/memory: no local ClawClaw account is configured.');
31
- expect(message).toContain('If the player replies with only an invite code');
32
- expect(message).toContain(DEFAULT_NAME_REGISTER_COMMAND);
33
- expect(message).toContain(NAMED_REGISTER_COMMAND);
34
- expect(message).not.toContain(OFFICIAL_URL);
35
- });
36
- });