@myclaw163/clawclaw-cli 0.8.5 → 0.8.7

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 (119) hide show
  1. package/README.md +1 -1
  2. package/docs/configuration.md +2 -1
  3. package/docs/custom-modules/behavior.md +7 -18
  4. package/docs/custom-modules/trigger.md +3 -4
  5. package/docs/runtime/short-commands-and-capabilities.md +1 -1
  6. package/package.json +9 -3
  7. package/scripts/find-hide-spots.py +2 -2
  8. package/skills/clawclaw/SKILL.md +17 -13
  9. package/skills/clawclaw/references/BEHAVIORS.md +13 -9
  10. package/skills/clawclaw/references/COMMANDS.md +17 -29
  11. package/skills/clawclaw/references/TACTICS.md +1 -1
  12. package/src/commands/load.ts +245 -14
  13. package/src/commands/trigger.ts +22 -13
  14. package/src/lib/capability-load-diagnostics.ts +182 -0
  15. package/src/lib/gameplay-config.ts +10 -0
  16. package/src/lib/hub-reminder.ts +3 -5
  17. package/src/lib/trigger-config.ts +2 -10
  18. package/src/runtime/clawclaw/behavior-read-api.ts +1 -1
  19. package/src/{strategies/pathfind → runtime/clawclaw/navigation}/astar-path.ts +1 -1
  20. package/src/{strategies/pathfind → runtime/clawclaw/navigation}/escape-planner.ts +1 -1
  21. package/src/{strategies → runtime/clawclaw/navigation}/hide-spots.ts +2 -2
  22. package/src/{strategies → runtime/clawclaw/navigation}/off-route-points.ts +6 -3
  23. package/src/{strategies/pathfind → runtime/clawclaw/navigation}/walkable-grid.ts +1 -1
  24. package/src/runtime/clawclaw/owner.ts +4 -6
  25. package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.ts +1 -1
  26. package/src/runtime/framework/modules/runtime-module-loader.ts +0 -54
  27. package/src/sdk/behavior-toolkit/escape.ts +2 -2
  28. package/scripts/build-official-hub-behaviors.mjs +0 -136
  29. package/scripts/build-official-hub-behaviors.test.mjs +0 -178
  30. package/scripts/compare-perception-replays.test.ts +0 -188
  31. package/scripts/enable_ccl_permissions.test.mjs +0 -167
  32. package/scripts/enable_monitor.test.mjs +0 -201
  33. package/scripts/sync-bundled-skill.test.mjs +0 -87
  34. package/scripts/watch-perception-events.test.ts +0 -43
  35. package/src/behaviors/official-finite/do-task.ts +0 -211
  36. package/src/behaviors/official-finite/evade.ts +0 -78
  37. package/src/behaviors/official-finite/find-player.ts +0 -50
  38. package/src/behaviors/official-finite/follow-player.ts +0 -70
  39. package/src/behaviors/official-finite/go-to.ts +0 -69
  40. package/src/behaviors/official-finite/hide-temporarily.ts +0 -77
  41. package/src/behaviors/official-finite/hold-position.ts +0 -48
  42. package/src/behaviors/official-finite/hunt-player.ts +0 -47
  43. package/src/behaviors/official-finite/index.ts +0 -44
  44. package/src/behaviors/official-finite/inspect-corpse.ts +0 -64
  45. package/src/behaviors/official-finite/patrol-area.ts +0 -80
  46. package/src/behaviors/official-finite/report-corpse.ts +0 -73
  47. package/src/behaviors/official-finite/seek-kill-opportunity.ts +0 -152
  48. package/src/behaviors/official-finite/shared.ts +0 -27
  49. package/src/hub-official-behaviors/kill-lone.ts +0 -138
  50. package/src/hub-official-behaviors/patrol.ts +0 -30
  51. package/src/hub-official-behaviors/shared.ts +0 -125
  52. package/src/hub-official-behaviors/task-only.ts +0 -158
  53. package/src/runtime/clawclaw/plugins/behavior/official-goal-behavior.ts +0 -757
  54. package/src/strategies/avoid-lone.ts +0 -32
  55. package/src/strategies/avoid-players.ts +0 -43
  56. package/src/strategies/corpse-patrol.ts +0 -50
  57. package/src/strategies/crab-sabotage.ts +0 -48
  58. package/src/strategies/find-player.ts +0 -49
  59. package/src/strategies/game-utils.ts +0 -927
  60. package/src/strategies/goals/anchor-linger.ts +0 -77
  61. package/src/strategies/goals/avoid-lone-top.ts +0 -189
  62. package/src/strategies/goals/avoid-players-top.ts +0 -122
  63. package/src/strategies/goals/conversation-goal.ts +0 -51
  64. package/src/strategies/goals/corpse-patrol-top.ts +0 -120
  65. package/src/strategies/goals/crab-octopus-reflexes.ts +0 -109
  66. package/src/strategies/goals/crab-sabotage-top.ts +0 -139
  67. package/src/strategies/goals/emergency-hunt-goal.ts +0 -40
  68. package/src/strategies/goals/find-player-top.ts +0 -136
  69. package/src/strategies/goals/flee-players-goal.ts +0 -55
  70. package/src/strategies/goals/follow-companion-goal.ts +0 -130
  71. package/src/strategies/goals/goal-manager.ts +0 -41
  72. package/src/strategies/goals/goal-root-strategy.ts +0 -49
  73. package/src/strategies/goals/goal.ts +0 -28
  74. package/src/strategies/goals/hide-top.ts +0 -240
  75. package/src/strategies/goals/keep-away-goal.ts +0 -243
  76. package/src/strategies/goals/kill-frenzy-top.ts +0 -90
  77. package/src/strategies/goals/kill-lone-top.ts +0 -166
  78. package/src/strategies/goals/kill-target-goal.ts +0 -69
  79. package/src/strategies/goals/kill-target-top.ts +0 -121
  80. package/src/strategies/goals/leaf-goal.ts +0 -27
  81. package/src/strategies/goals/linger-corpse-goal.ts +0 -43
  82. package/src/strategies/goals/lone-kill-core.ts +0 -86
  83. package/src/strategies/goals/lone-kill-goal.ts +0 -24
  84. package/src/strategies/goals/lone-kill-task-top.ts +0 -133
  85. package/src/strategies/goals/move-room-goal.ts +0 -102
  86. package/src/strategies/goals/normal-shrimp-top.ts +0 -248
  87. package/src/strategies/goals/paradise-fish-top.ts +0 -234
  88. package/src/strategies/goals/patrol-top.ts +0 -68
  89. package/src/strategies/goals/report-patrol-top.ts +0 -97
  90. package/src/strategies/goals/safe-task-goal.ts +0 -130
  91. package/src/strategies/goals/social-task-top.ts +0 -192
  92. package/src/strategies/goals/task-kill-report-top.ts +0 -187
  93. package/src/strategies/goals/task-only-top.ts +0 -64
  94. package/src/strategies/goals/task-or-patrol-goal.ts +0 -59
  95. package/src/strategies/goals/task-report-top.ts +0 -57
  96. package/src/strategies/goals/wander-task-goal.ts +0 -33
  97. package/src/strategies/goals/warrior-shrimp-top.ts +0 -293
  98. package/src/strategies/greeting.ts +0 -60
  99. package/src/strategies/hide.ts +0 -51
  100. package/src/strategies/kill-frenzy.ts +0 -32
  101. package/src/strategies/kill-lone.ts +0 -52
  102. package/src/strategies/kill-target.ts +0 -48
  103. package/src/strategies/lone-kill-task.ts +0 -48
  104. package/src/strategies/meeting-gate.ts +0 -28
  105. package/src/strategies/move-room.ts +0 -46
  106. package/src/strategies/paradise-fish.ts +0 -70
  107. package/src/strategies/patrol.ts +0 -32
  108. package/src/strategies/player-targets.ts +0 -18
  109. package/src/strategies/report-patrol.ts +0 -32
  110. package/src/strategies/shrimp-memory.ts +0 -87
  111. package/src/strategies/social-task.ts +0 -67
  112. package/src/strategies/speech-module.ts +0 -123
  113. package/src/strategies/task-kill-report.ts +0 -49
  114. package/src/strategies/task-only.ts +0 -34
  115. package/src/strategies/task-report.ts +0 -50
  116. package/src/strategies/types.ts +0 -116
  117. package/src/strategies/warrior-memory.ts +0 -54
  118. /package/src/{strategies/pathfind → runtime/clawclaw/navigation}/clawclaw-walkable.bin +0 -0
  119. /package/src/{strategies/pathfind → runtime/clawclaw/navigation}/distance-field.ts +0 -0
@@ -1,188 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import {
3
- comparePerceptionReplays,
4
- type ParsedReplay,
5
- type ReplayProposal,
6
- } from './compare-perception-replays.js';
7
-
8
- function proposal(
9
- type: string,
10
- tick: number,
11
- data: Record<string, unknown>,
12
- ): ReplayProposal {
13
- return {
14
- type,
15
- emittedAtFrameSeq: 2,
16
- emittedAtTick: tick,
17
- payload: {
18
- from_tick: tick,
19
- to_tick: tick,
20
- actors: [5],
21
- text: '',
22
- data,
23
- },
24
- };
25
- }
26
-
27
- function replay(candidate = false): ParsedReplay {
28
- const visible = proposal('visual.player_entered', 3, {
29
- player_id: 'seat:7',
30
- side: '左',
31
- place: '厨房左侧',
32
- });
33
- const route = proposal('visual.player_turned', 12, {
34
- player_id: 'seat:5',
35
- direction: candidate ? '左' : '左上',
36
- });
37
- const movement = candidate
38
- ? [proposal('visual.player_moved', 20, { player_id: 'seat:5', path_length_px: 90 })]
39
- : [
40
- proposal('visual.player_moved', 10, { player_id: 'seat:5', path_length_px: 60 }),
41
- proposal('visual.player_moved', 20, { player_id: 'seat:5', path_length_px: 40 }),
42
- ];
43
- const modules = [
44
- { id: 'visual.motion', produces: ['visual.player_moved', 'visual.player_motion_changed'] },
45
- { id: 'visual.route', produces: ['visual.player_turned', 'visual.player_reversed', 'visual.player_wandering'] },
46
- { id: 'visual.stop', produces: candidate
47
- ? ['visual.player_stopped', 'visual.player_resumed']
48
- : ['visual.player_stopped', 'visual.player_resumed', 'visual.no_significant_stop'] },
49
- { id: 'visual.visibility', produces: ['visual.player_entered', 'visual.player_left'] },
50
- ];
51
- return {
52
- scope: candidate
53
- ? { session_id: 'session', account_id: 'account' }
54
- : { account_id: 'account', session_id: 'session' },
55
- selection: candidate
56
- ? { to_tick: 20, from_tick: 1 }
57
- : { from_tick: 1, to_tick: 20 },
58
- modules: candidate ? [modules[2], modules[0], modules[3], modules[1]] : modules,
59
- frames: candidate
60
- ? [
61
- { frameSeq: 1, perceptionFrame: { observation: { players: [{ observer: true, id: 'seat:5' }] }, tickDelta: 1, tick: 1 } },
62
- { frameSeq: 2, perceptionFrame: { observation: { players: [{ id: 'seat:5', observer: true }] }, tick: 20, tickDelta: 19 } },
63
- ]
64
- : [
65
- { frameSeq: 1, perceptionFrame: { tick: 1, tickDelta: 1, observation: { players: [{ id: 'seat:5', observer: true }] } } },
66
- { frameSeq: 2, perceptionFrame: { tickDelta: 19, tick: 20, observation: { players: [{ observer: true, id: 'seat:5' }] } } },
67
- ],
68
- generated_proposals_covering_selection: [visible, route, ...movement],
69
- };
70
- }
71
-
72
- describe('compare-perception-replays gates', () => {
73
- it('passes a valid reduction with reordered module IDs and changed produces declarations', () => {
74
- const report = comparePerceptionReplays(replay(), replay(true));
75
-
76
- expect(report.inputs.equivalence_checks).toEqual({
77
- scope: true,
78
- selection: true,
79
- module_ids: true,
80
- selected_frame_seqs: true,
81
- perception_frames: true,
82
- });
83
- expect(report.change.motion_path_coverage.percent).toBe(90);
84
- expect(report.passed).toBe(true);
85
- });
86
-
87
- it('fails when a module is deleted even if the remaining proposals are unchanged', () => {
88
- const before = replay();
89
- const after = replay(true);
90
- after.modules = after.modules.filter((module) => module.id !== 'visual.stop');
91
-
92
- const report = comparePerceptionReplays(before, after);
93
-
94
- expect(report.inputs.equivalence_checks.module_ids).toBe(false);
95
- expect(report.gates.same_replay_input).toBe(false);
96
- expect(report.passed).toBe(false);
97
- });
98
-
99
- it('fails when perception frame content changes behind the same frame sequence', () => {
100
- const before = replay();
101
- const after = replay(true);
102
- after.frames[0].perceptionFrame!.observation!.players![0].observer = false;
103
-
104
- const report = comparePerceptionReplays(before, after);
105
-
106
- expect(report.inputs.evidence.before.perception_frames_digest)
107
- .not.toBe(report.inputs.evidence.after.perception_frames_digest);
108
- expect(report.inputs.equivalence_checks.selected_frame_seqs).toBe(true);
109
- expect(report.inputs.equivalence_checks.perception_frames).toBe(false);
110
- expect(report.gates.same_replay_input).toBe(false);
111
- expect(report.passed).toBe(false);
112
- });
113
-
114
- it('fails when motion proposals are deleted instead of compacted', () => {
115
- const before = replay();
116
- const after = replay(true);
117
- after.generated_proposals_covering_selection = after.generated_proposals_covering_selection
118
- .filter((event) => event.type !== 'visual.player_moved');
119
-
120
- const report = comparePerceptionReplays(before, after);
121
-
122
- expect(report.gates.proposal_count_not_increased).toBe(true);
123
- expect(report.change.motion_path_coverage.percent).toBe(0);
124
- expect(report.gates.motion_path_coverage_at_least_90_percent).toBe(false);
125
- expect(report.passed).toBe(false);
126
- });
127
-
128
- it('treats route events as exact high-value signatures', () => {
129
- const before = replay();
130
- const after = replay(true);
131
- after.generated_proposals_covering_selection = after.generated_proposals_covering_selection
132
- .filter((event) => event.type !== 'visual.player_turned');
133
-
134
- const report = comparePerceptionReplays(before, after);
135
-
136
- expect(report.high_value_signature_changes.missing).toHaveLength(1);
137
- expect(report.gates.high_value_signatures_preserved).toBe(false);
138
- expect(report.passed).toBe(false);
139
- });
140
-
141
- it('allows a corrected visibility side label while preserving the transition and place', () => {
142
- const before = replay();
143
- const after = replay(true);
144
- const entered = after.generated_proposals_covering_selection.find(
145
- (event) => event.type === 'visual.player_entered',
146
- )!;
147
- entered.payload.data.side = '右';
148
-
149
- const report = comparePerceptionReplays(before, after);
150
-
151
- expect(report.high_value_signature_changes.missing).toEqual([]);
152
- expect(report.passed).toBe(true);
153
- });
154
-
155
- it('counts flip-flops carried by fused data.direction_change facts', () => {
156
- const before = replay(true);
157
- const after = replay(true);
158
- after.generated_proposals_covering_selection.push(
159
- proposal('visual.player_moved', 30, {
160
- player_id: 'seat:5',
161
- path_length_px: 10,
162
- direction_change: {
163
- from_direction: '左',
164
- to_direction: '右',
165
- to_tick: 30,
166
- },
167
- }),
168
- proposal('visual.player_moved', 34, {
169
- player_id: 'seat:5',
170
- path_length_px: 10,
171
- direction_change: {
172
- from_direction: '右',
173
- to_direction: '左',
174
- to_tick: 34,
175
- },
176
- }),
177
- );
178
-
179
- const report = comparePerceptionReplays(before, after);
180
-
181
- expect(report.after.direction_flip_flop_count).toBe(1);
182
- expect(report.after.direction_flip_flop_examples[0]).toMatchObject({
183
- subject: 'seat:5',
184
- ticks: [30, 34],
185
- directions: ['左', '右', '左'],
186
- });
187
- });
188
- });
@@ -1,167 +0,0 @@
1
- import { spawnSync } from 'node:child_process';
2
- import {
3
- existsSync,
4
- mkdirSync,
5
- mkdtempSync,
6
- readFileSync,
7
- rmSync,
8
- writeFileSync,
9
- } from 'node:fs';
10
- import { tmpdir } from 'node:os';
11
- import { dirname, join, resolve } from 'node:path';
12
- import { afterEach, describe, expect, it } from 'vitest';
13
-
14
- const scriptPath = resolve('scripts', 'enable_ccl_permissions.cjs');
15
- const tempRoots = [];
16
- const requiredAllow = [
17
- 'Bash(ccl)',
18
- 'Bash(ccl *)',
19
- 'PowerShell(ccl)',
20
- 'PowerShell(ccl *)',
21
- 'Bash(clawclaw-cli)',
22
- 'Bash(clawclaw-cli *)',
23
- 'PowerShell(clawclaw-cli)',
24
- 'PowerShell(clawclaw-cli *)',
25
- 'Skill(clawclaw)',
26
- 'Skill(clawclaw *)',
27
- 'Read(~/.claude/skills/clawclaw/**)',
28
- 'Read(~/.agents/skills/clawclaw/**)',
29
- 'Edit(~/.clawclaw/user-data/accounts/**/personas/local/**)',
30
- 'Edit(~/.clawclaw/user-data/accounts/**/personas/hub/**)',
31
- 'Edit(~/.clawclaw/user-data/accounts/**/memory.md)',
32
- 'Edit(~/AppData/Roaming/clawclaw/user-data/accounts/**/personas/local/**)',
33
- 'Edit(~/AppData/Roaming/clawclaw/user-data/accounts/**/personas/hub/**)',
34
- 'Edit(~/AppData/Roaming/clawclaw/user-data/accounts/**/memory.md)',
35
- ];
36
-
37
- function makeRoot(prefix) {
38
- const root = mkdtempSync(join(tmpdir(), prefix));
39
- tempRoots.push(root);
40
- return root;
41
- }
42
-
43
- function writeJson(file, value) {
44
- mkdirSync(dirname(file), { recursive: true });
45
- writeFileSync(file, `${JSON.stringify(value, null, 2)}\n`, 'utf8');
46
- }
47
-
48
- function readJson(file) {
49
- return JSON.parse(readFileSync(file, 'utf8'));
50
- }
51
-
52
- function runScript(args) {
53
- return spawnSync(process.execPath, [scriptPath, ...args], {
54
- cwd: resolve('.'),
55
- encoding: 'utf8',
56
- });
57
- }
58
-
59
- afterEach(() => {
60
- while (tempRoots.length) {
61
- rmSync(tempRoots.pop(), { recursive: true, force: true });
62
- }
63
- });
64
-
65
- describe('enable_ccl_permissions.cjs', () => {
66
- it('adds only missing ClawClaw permission entries and preserves existing settings', () => {
67
- const root = makeRoot('enable-ccl-perms-');
68
- const settingsPath = join(root, '.claude', 'settings.json');
69
- const original = {
70
- env: { KEEP_ME: 'yes' },
71
- permissions: {
72
- allow: ['Bash(node *)', 'Bash(ccl)'],
73
- deny: ['Bash(rm *)'],
74
- },
75
- theme: 'dark',
76
- };
77
- writeJson(settingsPath, original);
78
-
79
- const result = runScript(['--settings', settingsPath]);
80
-
81
- expect(result.status).toBe(0);
82
- const settings = readJson(settingsPath);
83
- expect(settings.env).toEqual(original.env);
84
- expect(settings.permissions.deny).toEqual(original.permissions.deny);
85
- expect(settings.theme).toBe(original.theme);
86
- expect(settings.permissions.allow).toEqual([
87
- 'Bash(node *)',
88
- ...requiredAllow,
89
- ]);
90
- });
91
-
92
- it('allows both the Claude skill link and canonical skill target with portable paths', () => {
93
- const root = makeRoot('enable-ccl-perms-paths-');
94
- const settingsPath = join(root, '.claude', 'settings.json');
95
-
96
- const result = runScript(['--settings', settingsPath]);
97
-
98
- expect(result.status).toBe(0);
99
- const allow = readJson(settingsPath).permissions.allow;
100
- expect(allow).toContain('Read(~/.claude/skills/clawclaw/**)');
101
- expect(allow).toContain('Read(~/.agents/skills/clawclaw/**)');
102
- expect(allow).toContain('Edit(~/.clawclaw/user-data/accounts/**/personas/local/**)');
103
- expect(allow).toContain('Edit(~/.clawclaw/user-data/accounts/**/personas/hub/**)');
104
- expect(allow).toContain('Edit(~/.clawclaw/user-data/accounts/**/memory.md)');
105
- expect(allow).toContain('Edit(~/AppData/Roaming/clawclaw/user-data/accounts/**/personas/local/**)');
106
- expect(allow).toContain('Edit(~/AppData/Roaming/clawclaw/user-data/accounts/**/personas/hub/**)');
107
- expect(allow).toContain('Edit(~/AppData/Roaming/clawclaw/user-data/accounts/**/memory.md)');
108
- expect(allow.filter((entry) => /^(?:Read|Edit)\(/.test(entry))).not.toContainEqual(
109
- expect.stringContaining('\\'),
110
- );
111
- });
112
-
113
- it('is idempotent', () => {
114
- const root = makeRoot('enable-ccl-perms-idem-');
115
- const settingsPath = join(root, '.claude', 'settings.json');
116
- writeJson(settingsPath, { permissions: { allow: requiredAllow } });
117
-
118
- const first = runScript(['--settings', settingsPath]);
119
- const afterFirst = readFileSync(settingsPath, 'utf8');
120
- const second = runScript(['--settings', settingsPath]);
121
- const afterSecond = readFileSync(settingsPath, 'utf8');
122
-
123
- expect(first.status).toBe(0);
124
- expect(second.status).toBe(0);
125
- expect(second.stdout).toContain('already allowed');
126
- expect(afterSecond).toBe(afterFirst);
127
- });
128
-
129
- it('creates a minimal settings file when missing', () => {
130
- const root = makeRoot('enable-ccl-perms-missing-');
131
- const settingsPath = join(root, '.claude', 'settings.json');
132
-
133
- const result = runScript(['--settings', settingsPath]);
134
-
135
- expect(result.status).toBe(0);
136
- expect(existsSync(settingsPath)).toBe(true);
137
- expect(readJson(settingsPath)).toEqual({
138
- permissions: { allow: requiredAllow },
139
- });
140
- });
141
-
142
- it('dry-run does not write', () => {
143
- const root = makeRoot('enable-ccl-perms-dry-');
144
- const settingsPath = join(root, '.claude', 'settings.json');
145
- const original = { permissions: { allow: [] } };
146
- writeJson(settingsPath, original);
147
-
148
- const result = runScript(['--dry-run', '--settings', settingsPath]);
149
-
150
- expect(result.status).toBe(0);
151
- expect(result.stdout).toContain('[DRY RUN]');
152
- expect(readJson(settingsPath)).toEqual(original);
153
- });
154
-
155
- it('fails without writing when permissions.allow is not an array', () => {
156
- const root = makeRoot('enable-ccl-perms-bad-');
157
- const settingsPath = join(root, '.claude', 'settings.json');
158
- const original = { permissions: { allow: 'Bash(ccl)' } };
159
- writeJson(settingsPath, original);
160
-
161
- const result = runScript(['--settings', settingsPath]);
162
-
163
- expect(result.status).toBe(1);
164
- expect(result.stdout).toContain('permissions.allow must be an array');
165
- expect(readJson(settingsPath)).toEqual(original);
166
- });
167
- });
@@ -1,201 +0,0 @@
1
- import { spawnSync } from 'node:child_process';
2
- import {
3
- existsSync,
4
- mkdirSync,
5
- mkdtempSync,
6
- readFileSync,
7
- readdirSync,
8
- rmSync,
9
- writeFileSync,
10
- } from 'node:fs';
11
- import { tmpdir } from 'node:os';
12
- import { dirname, join, resolve } from 'node:path';
13
- import { afterEach, describe, expect, it } from 'vitest';
14
-
15
- const scriptPath = resolve('scripts', 'enable_monitor.cjs');
16
- const tempRoots = [];
17
-
18
- function makeRoot(prefix) {
19
- const root = mkdtempSync(join(tmpdir(), prefix));
20
- tempRoots.push(root);
21
- return root;
22
- }
23
-
24
- function writeJson(file, value) {
25
- mkdirSync(dirname(file), { recursive: true });
26
- writeFileSync(file, `${JSON.stringify(value, null, 2)}\n`, 'utf8');
27
- }
28
-
29
- function readJson(file) {
30
- return JSON.parse(readFileSync(file, 'utf8'));
31
- }
32
-
33
- function runScript(root, args, extraEnv = {}) {
34
- return spawnSync(process.execPath, [scriptPath, ...args], {
35
- cwd: resolve('.'),
36
- encoding: 'utf8',
37
- env: {
38
- ...process.env,
39
- APPDATA: join(root, 'appdata'),
40
- CLAUDE_CODE_GIT_BASH_PATH: '',
41
- ...extraEnv,
42
- },
43
- });
44
- }
45
-
46
- function backupDirs(root) {
47
- const backupRoot = join(root, 'appdata', 'clawclaw', 'claude-config-backups');
48
- if (!existsSync(backupRoot)) return [];
49
- return readdirSync(backupRoot, { withFileTypes: true })
50
- .filter((entry) => entry.isDirectory() && entry.name.startsWith('enable-monitor-'))
51
- .map((entry) => join(backupRoot, entry.name))
52
- .sort();
53
- }
54
-
55
- function makeFakeBash(root) {
56
- const bashPath = join(root, 'Git', 'bin', 'bash.exe');
57
- mkdirSync(dirname(bashPath), { recursive: true });
58
- writeFileSync(bashPath, '');
59
- return bashPath;
60
- }
61
-
62
- afterEach(() => {
63
- while (tempRoots.length) {
64
- rmSync(tempRoots.pop(), { recursive: true, force: true });
65
- }
66
- });
67
-
68
- describe('enable_monitor.cjs', () => {
69
- it('repairs config and settings, backs up originals, and reverts a specified backup', () => {
70
- const root = makeRoot('enable-monitor-ok-');
71
- const configPath = join(root, 'claude.json');
72
- const settingsPath = join(root, '.claude', 'settings.json');
73
- const bashPath = makeFakeBash(root);
74
- const originalConfig = {
75
- cachedGrowthBookFeatures: { existing_flag: true },
76
- cachedGrowthBookFeaturesAt: 123,
77
- };
78
- const originalSettings = {
79
- env: {
80
- ENABLE_TOOL_SEARCH: '0',
81
- CLAUDE_CODE_GIT_BASH_PATH: 'C:\\missing\\bash.exe',
82
- DISABLE_TELEMETRY: '1',
83
- KEEP_ME: 'yes',
84
- },
85
- };
86
- writeJson(configPath, originalConfig);
87
- writeJson(settingsPath, originalSettings);
88
-
89
- const result = runScript(root, [
90
- '--config',
91
- configPath,
92
- '--settings',
93
- settingsPath,
94
- '--git-bash-path',
95
- bashPath,
96
- ]);
97
-
98
- expect(result.status).toBe(0);
99
- const config = readJson(configPath);
100
- const settings = readJson(settingsPath);
101
- expect(config.cachedGrowthBookFeatures.tengu_amber_sentinel).toBe(true);
102
- expect(config.cachedGrowthBookFeatures.existing_flag).toBe(true);
103
- expect(settings.env.ENABLE_TOOL_SEARCH).toBe('true');
104
- expect(settings.env.CLAUDE_CODE_GIT_BASH_PATH).toBe(bashPath);
105
- expect(settings.env.DISABLE_TELEMETRY).toBeUndefined();
106
- expect(settings.env.KEEP_ME).toBe('yes');
107
-
108
- const backups = backupDirs(root);
109
- expect(backups).toHaveLength(1);
110
- expect(readJson(join(backups[0], 'claude.json'))).toEqual(originalConfig);
111
- expect(readJson(join(backups[0], 'settings.json'))).toEqual(originalSettings);
112
- const manifest = readJson(join(backups[0], 'manifest.json'));
113
- expect(manifest.entries.map((entry) => entry.backupFile).sort()).toEqual([
114
- 'claude.json',
115
- 'settings.json',
116
- ]);
117
-
118
- const revert = runScript(root, [
119
- '--revert',
120
- '--revert-backup',
121
- backups[0],
122
- '--config',
123
- configPath,
124
- '--settings',
125
- settingsPath,
126
- ]);
127
-
128
- expect(revert.status).toBe(0);
129
- expect(readJson(configPath)).toEqual(originalConfig);
130
- expect(readJson(settingsPath)).toEqual(originalSettings);
131
- });
132
-
133
- it('dry-run reports changes without writing files or backups', () => {
134
- const root = makeRoot('enable-monitor-dry-');
135
- const configPath = join(root, 'claude.json');
136
- const settingsPath = join(root, '.claude', 'settings.json');
137
- const bashPath = makeFakeBash(root);
138
- const originalConfig = { cachedGrowthBookFeatures: {} };
139
- const originalSettings = { env: { ENABLE_TOOL_SEARCH: '0' } };
140
- writeJson(configPath, originalConfig);
141
- writeJson(settingsPath, originalSettings);
142
-
143
- const result = runScript(root, [
144
- '--dry-run',
145
- '--config',
146
- configPath,
147
- '--settings',
148
- settingsPath,
149
- '--git-bash-path',
150
- bashPath,
151
- ]);
152
-
153
- expect(result.status).toBe(0);
154
- expect(result.stdout).toContain('[DRY RUN] Would write');
155
- expect(readJson(configPath)).toEqual(originalConfig);
156
- expect(readJson(settingsPath)).toEqual(originalSettings);
157
- expect(backupDirs(root)).toHaveLength(0);
158
- });
159
-
160
- it('bad git-bash path blocks flag injection and leaves a backup that can restore partial cleanup', () => {
161
- const root = makeRoot('enable-monitor-bad-bash-');
162
- const configPath = join(root, 'claude.json');
163
- const settingsPath = join(root, '.claude', 'settings.json');
164
- const originalConfig = { cachedGrowthBookFeatures: {} };
165
- const originalSettings = { env: { ENABLE_TOOL_SEARCH: '0' } };
166
- writeJson(configPath, originalConfig);
167
- writeJson(settingsPath, originalSettings);
168
-
169
- const result = runScript(root, [
170
- '--config',
171
- configPath,
172
- '--settings',
173
- settingsPath,
174
- '--git-bash-path',
175
- join(root, 'missing', 'bash.exe'),
176
- ]);
177
-
178
- expect(result.status).toBe(1);
179
- expect(result.stdout).toContain('Backup at:');
180
- expect(readJson(configPath)).toEqual(originalConfig);
181
- expect(readJson(settingsPath).env.ENABLE_TOOL_SEARCH).toBe('true');
182
-
183
- const backups = backupDirs(root);
184
- expect(backups).toHaveLength(1);
185
- expect(readJson(join(backups[0], 'settings.json'))).toEqual(originalSettings);
186
-
187
- const revert = runScript(root, [
188
- '--revert',
189
- '--revert-backup',
190
- backups[0],
191
- '--config',
192
- configPath,
193
- '--settings',
194
- settingsPath,
195
- ]);
196
-
197
- expect(revert.status).toBe(0);
198
- expect(readJson(configPath)).toEqual(originalConfig);
199
- expect(readJson(settingsPath)).toEqual(originalSettings);
200
- });
201
- });
@@ -1,87 +0,0 @@
1
- import { existsSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync } from 'fs';
2
- import { tmpdir } from 'os';
3
- import { join } from 'path';
4
- import { describe, expect, it, vi } from 'vitest';
5
- import { syncBundledSkill } from './sync-bundled-skill.mjs';
6
-
7
- function writeSkill(dir, version, body) {
8
- mkdirSync(dir, { recursive: true });
9
- writeFileSync(join(dir, 'SKILL.md'), `---\nname: clawclaw\nversion: ${version}\n---\n${body}\n`);
10
- }
11
-
12
- function writeInstallDir(root) {
13
- const installDir = join(root, 'pkg');
14
- writeSkill(join(installDir, 'skills', 'clawclaw'), '4.8.18', 'new');
15
- mkdirSync(join(installDir, 'node_modules', 'skills'), { recursive: true });
16
- writeFileSync(join(installDir, 'node_modules', 'skills', 'package.json'), JSON.stringify({
17
- bin: { skills: 'bin/cli.mjs' },
18
- }));
19
- mkdirSync(join(installDir, 'node_modules', 'skills', 'bin'), { recursive: true });
20
- writeFileSync(join(installDir, 'node_modules', 'skills', 'bin', 'cli.mjs'), '');
21
- return installDir;
22
- }
23
-
24
- describe('sync-bundled-skill', () => {
25
- it('runs skills add and directly mirrors the bundled directory without a backup', () => {
26
- const root = mkdtempSync(join(tmpdir(), 'skill-sync-'));
27
- const installDir = writeInstallDir(root);
28
- const old = join(root, 'home', '.codex', 'skills', 'clawclaw');
29
- writeSkill(old, '4.8.17', 'old');
30
- const spawn = vi.fn(() => ({ status: 0 }));
31
-
32
- const result = syncBundledSkill({
33
- installDir,
34
- backupRoot: join(root, 'backups'),
35
- candidateDirs: [old],
36
- spawnSync: spawn,
37
- stdio: 'ignore',
38
- });
39
-
40
- expect(result).toEqual({ skipped: false, updatedTargets: 1 });
41
- expect(readFileSync(join(old, 'SKILL.md'), 'utf8')).toContain('\nnew\n');
42
- expect(spawn).toHaveBeenCalledOnce();
43
- expect(spawn.mock.calls[0][1].slice(1)).toEqual([
44
- 'add',
45
- join(installDir, 'skills', 'clawclaw'),
46
- '-y',
47
- '-g',
48
- ]);
49
- });
50
-
51
- it('does not consult the obsolete backup location', () => {
52
- const root = mkdtempSync(join(tmpdir(), 'skill-backup-fail-'));
53
- const installDir = writeInstallDir(root);
54
- const old = join(root, 'home', '.codex', 'skills', 'clawclaw');
55
- writeSkill(old, '4.8.17', 'old');
56
- const backupRootFile = join(root, 'backups-file');
57
- writeFileSync(backupRootFile, 'not a directory');
58
- const spawn = vi.fn(() => ({ status: 0 }));
59
-
60
- expect(() => syncBundledSkill({
61
- installDir,
62
- backupRoot: backupRootFile,
63
- candidateDirs: [old],
64
- spawnSync: spawn,
65
- stdio: 'ignore',
66
- })).not.toThrow();
67
- expect(spawn).toHaveBeenCalledOnce();
68
- });
69
-
70
- it('does not create a backup when skills add fails', () => {
71
- const root = mkdtempSync(join(tmpdir(), 'skill-add-fail-'));
72
- const installDir = writeInstallDir(root);
73
- const old = join(root, 'home', '.codex', 'skills', 'clawclaw');
74
- const backupRoot = join(root, 'backups');
75
- writeSkill(old, '4.8.17', 'old');
76
- const spawn = vi.fn(() => ({ status: 1 }));
77
-
78
- expect(() => syncBundledSkill({
79
- installDir,
80
- backupRoot,
81
- candidateDirs: [old],
82
- spawnSync: spawn,
83
- stdio: 'ignore',
84
- })).toThrow(/skills add exited/);
85
- expect(existsSync(backupRoot)).toBe(false);
86
- });
87
- });
@@ -1,43 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import type { CanonicalEvent } from '../src/runtime/framework/events/index.js';
3
- import {
4
- formatPerceptionEvent,
5
- parsePerceptionWatchOptions,
6
- } from './watch-perception-events.js';
7
-
8
- describe('perception Event live viewer', () => {
9
- it('uses a fast non-consuming tail by default', () => {
10
- expect(parsePerceptionWatchOptions([])).toEqual({
11
- fromStart: false,
12
- intervalMs: 100,
13
- json: false,
14
- maxEvents: null,
15
- });
16
- expect(parsePerceptionWatchOptions([
17
- '--from-start', '--json', '--interval-ms', '250', '--max-events', '3',
18
- ])).toEqual({ fromStart: true, intervalMs: 250, json: true, maxEvents: 3 });
19
- });
20
-
21
- it('formats the generated interval and text without losing runtime identity', () => {
22
- const event = {
23
- commitSeq: 42,
24
- epochSeq: 19,
25
- eventId: 'visual-42',
26
- sessionId: 'session-1',
27
- segmentId: 'segment-1',
28
- type: 'visual.player_moved',
29
- producer: 'local_synth',
30
- producerPluginId: 'clawclaw.perception',
31
- deliveryClass: 'internal_only',
32
- occurredAt: '2026-07-24T01:02:03.456Z',
33
- receivedAt: '2026-07-24T01:02:03.500Z',
34
- payload: { from_tick: 100, to_tick: 108, text: '7号向右移动。' },
35
- sourceId: 'runtime',
36
- replayed: false,
37
- } satisfies CanonicalEvent;
38
-
39
- expect(formatPerceptionEvent(event)).toBe(
40
- '[01:02:03.456] #42 epoch 19 ticks 100-108 visual.player_moved | 7号向右移动。',
41
- );
42
- });
43
- });