clawvault 2.5.1 → 2.5.3

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 (88) hide show
  1. package/README.md +159 -199
  2. package/bin/clawvault.js +111 -111
  3. package/bin/command-registration.test.js +166 -165
  4. package/bin/command-runtime.js +93 -77
  5. package/bin/command-runtime.test.js +154 -102
  6. package/bin/help-contract.test.js +39 -28
  7. package/bin/register-config-commands.js +153 -153
  8. package/bin/register-config-route-commands.test.js +121 -121
  9. package/bin/register-core-commands.js +237 -237
  10. package/bin/register-kanban-commands.js +56 -56
  11. package/bin/register-kanban-commands.test.js +83 -83
  12. package/bin/register-maintenance-commands.js +282 -248
  13. package/bin/register-project-commands.js +209 -209
  14. package/bin/register-project-commands.test.js +206 -201
  15. package/bin/register-query-commands.js +317 -312
  16. package/bin/register-query-commands.test.js +65 -0
  17. package/bin/register-resilience-commands.js +182 -182
  18. package/bin/register-resilience-commands.test.js +81 -81
  19. package/bin/register-route-commands.js +114 -114
  20. package/bin/register-session-lifecycle-commands.js +206 -206
  21. package/bin/register-tailscale-commands.js +106 -106
  22. package/bin/register-task-commands.js +348 -348
  23. package/bin/register-task-commands.test.js +69 -69
  24. package/bin/register-template-commands.js +72 -72
  25. package/bin/register-vault-operations-commands.js +300 -300
  26. package/bin/test-helpers/cli-command-fixtures.js +119 -119
  27. package/dashboard/lib/graph-diff.js +104 -104
  28. package/dashboard/lib/graph-diff.test.js +75 -75
  29. package/dashboard/lib/vault-parser.js +556 -556
  30. package/dashboard/lib/vault-parser.test.js +254 -254
  31. package/dashboard/public/app.js +796 -796
  32. package/dashboard/public/index.html +52 -52
  33. package/dashboard/public/styles.css +221 -221
  34. package/dashboard/server.js +374 -374
  35. package/dist/{chunk-G3OQJ2NQ.js → chunk-2YDBJS7M.js} +1 -1
  36. package/dist/chunk-3FP5BJ42.js +88 -0
  37. package/dist/{chunk-C3PF7WBA.js → chunk-4IV3R2F5.js} +2 -2
  38. package/dist/{chunk-7OHQFMJK.js → chunk-AY4PGUVL.js} +5 -4
  39. package/dist/chunk-FG6RJMCN.js +33 -0
  40. package/dist/{chunk-WIICLBNF.js → chunk-GFJ3LIIB.js} +1 -1
  41. package/dist/chunk-IZEY5S74.js +541 -0
  42. package/dist/chunk-LMEMZGUV.js +332 -0
  43. package/dist/{chunk-6RQPD7X6.js → chunk-M25QVSJM.js} +4 -3
  44. package/dist/{chunk-6B3JWM7J.js → chunk-O7XHXF7F.js} +34 -7
  45. package/dist/chunk-OSMS7QIG.js +406 -0
  46. package/dist/{chunk-PAYUH64O.js → chunk-QVMXF7FY.js} +11 -1
  47. package/dist/{chunk-TMZMN7OS.js → chunk-S2IG7VNM.js} +24 -12
  48. package/dist/{chunk-LMCC5OC7.js → chunk-TPDH3JPP.js} +1 -1
  49. package/dist/cli/index.d.ts +5 -0
  50. package/dist/cli/index.js +31 -0
  51. package/dist/commands/canvas.js +3 -3
  52. package/dist/commands/compat.js +1 -1
  53. package/dist/commands/context.js +4 -4
  54. package/dist/commands/doctor.js +16 -309
  55. package/dist/commands/embed.d.ts +17 -0
  56. package/dist/commands/embed.js +10 -0
  57. package/dist/commands/migrate-observations.js +2 -2
  58. package/dist/commands/observe.d.ts +1 -0
  59. package/dist/commands/observe.js +7 -6
  60. package/dist/commands/rebuild.js +5 -5
  61. package/dist/commands/reflect.js +3 -3
  62. package/dist/commands/replay.js +7 -7
  63. package/dist/commands/setup.d.ts +1 -0
  64. package/dist/commands/setup.js +2 -2
  65. package/dist/commands/sleep.d.ts +2 -1
  66. package/dist/commands/sleep.js +15 -15
  67. package/dist/commands/status.d.ts +9 -1
  68. package/dist/commands/status.js +33 -8
  69. package/dist/commands/wake.d.ts +1 -1
  70. package/dist/commands/wake.js +6 -6
  71. package/dist/index.d.ts +82 -5
  72. package/dist/index.js +127 -105
  73. package/dist/{types-jjuYN2Xn.d.ts → types-C74wgGL1.d.ts} +2 -0
  74. package/hooks/clawvault/HOOK.md +83 -74
  75. package/hooks/clawvault/handler.js +816 -812
  76. package/hooks/clawvault/handler.test.js +263 -263
  77. package/package.json +94 -125
  78. package/templates/checkpoint.md +19 -19
  79. package/templates/daily-note.md +19 -19
  80. package/templates/daily.md +19 -19
  81. package/templates/decision.md +17 -17
  82. package/templates/handoff.md +19 -19
  83. package/templates/lesson.md +16 -16
  84. package/templates/person.md +19 -19
  85. package/templates/project.md +23 -23
  86. package/dist/chunk-2RK2AG32.js +0 -743
  87. package/dist/{chunk-FW465EEA.js → chunk-VXEOHTSL.js} +3 -3
  88. package/dist/{chunk-KCCHROBR.js → chunk-YOSEUUNB.js} +4 -4
@@ -1,263 +1,263 @@
1
- import { afterEach, describe, expect, it, vi } from 'vitest';
2
- import * as fs from 'fs';
3
- import * as os from 'os';
4
- import * as path from 'path';
5
-
6
- const { execFileSyncMock } = vi.hoisted(() => ({
7
- execFileSyncMock: vi.fn()
8
- }));
9
-
10
- vi.mock('child_process', () => ({
11
- execFileSync: execFileSyncMock
12
- }));
13
-
14
- function makeVaultFixture() {
15
- const root = fs.mkdtempSync(path.join(os.tmpdir(), 'clawvault-hook-'));
16
- fs.writeFileSync(path.join(root, '.clawvault.json'), JSON.stringify({ name: 'test' }), 'utf-8');
17
- return root;
18
- }
19
-
20
- function makeOpenClawSessionFixture(agentId, sessionId, transcriptBytes = 0) {
21
- const stateRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'clawvault-openclaw-'));
22
- const sessionsDir = path.join(stateRoot, 'agents', agentId, 'sessions');
23
- fs.mkdirSync(sessionsDir, { recursive: true });
24
- fs.writeFileSync(
25
- path.join(sessionsDir, 'sessions.json'),
26
- JSON.stringify({
27
- [`agent:${agentId}:main`]: {
28
- sessionId,
29
- updatedAt: Date.now()
30
- }
31
- }),
32
- 'utf-8'
33
- );
34
- const transcriptPath = path.join(sessionsDir, `${sessionId}.jsonl`);
35
- const payload = transcriptBytes > 0 ? 'x'.repeat(transcriptBytes) : '';
36
- fs.writeFileSync(transcriptPath, payload, 'utf-8');
37
- return { stateRoot, sessionsDir, transcriptPath };
38
- }
39
-
40
- async function loadHandler() {
41
- vi.resetModules();
42
- const mod = await import('./handler.js');
43
- return mod.default;
44
- }
45
-
46
- afterEach(() => {
47
- vi.clearAllMocks();
48
- delete process.env.CLAWVAULT_PATH;
49
- delete process.env.OPENCLAW_STATE_DIR;
50
- delete process.env.OPENCLAW_HOME;
51
- delete process.env.OPENCLAW_AGENT_ID;
52
- });
53
-
54
- describe('clawvault hook handler', () => {
55
- it('injects recovery warning on gateway startup when death detected', async () => {
56
- const vaultPath = makeVaultFixture();
57
- process.env.CLAWVAULT_PATH = vaultPath;
58
-
59
- execFileSyncMock.mockImplementation((_command, args) => {
60
- if (args[0] === 'recover') {
61
- return '⚠️ CONTEXT DEATH DETECTED\nWorking on: ship memory graph';
62
- }
63
- return '';
64
- });
65
-
66
- const handler = await loadHandler();
67
- const event = {
68
- type: 'gateway',
69
- action: 'startup',
70
- messages: [{ role: 'user', content: 'hello' }]
71
- };
72
-
73
- await handler(event);
74
-
75
- expect(execFileSyncMock).toHaveBeenCalledWith(
76
- 'clawvault',
77
- expect.arrayContaining(['recover', '--clear', '-v', vaultPath]),
78
- expect.objectContaining({ shell: false })
79
- );
80
- const injected = event.messages.find((message) => message.role === 'system');
81
- expect(injected?.content).toContain('Context death detected');
82
- expect(injected?.content).toContain('ship memory graph');
83
-
84
- fs.rmSync(vaultPath, { recursive: true, force: true });
85
- });
86
-
87
- it('supports alias event names for command:new', async () => {
88
- const vaultPath = makeVaultFixture();
89
- process.env.CLAWVAULT_PATH = vaultPath;
90
- execFileSyncMock.mockReturnValue('');
91
-
92
- const handler = await loadHandler();
93
- await handler({
94
- event: 'command:new',
95
- sessionKey: 'agent:clawdious:main',
96
- context: { commandSource: 'cli' }
97
- });
98
-
99
- expect(execFileSyncMock).toHaveBeenCalledWith(
100
- 'clawvault',
101
- expect.arrayContaining(['checkpoint', '--working-on']),
102
- expect.objectContaining({ shell: false })
103
- );
104
-
105
- fs.rmSync(vaultPath, { recursive: true, force: true });
106
- });
107
-
108
- it('injects recap and memory context on session start alias event', async () => {
109
- const vaultPath = makeVaultFixture();
110
- process.env.CLAWVAULT_PATH = vaultPath;
111
-
112
- execFileSyncMock.mockImplementation((_command, args) => {
113
- if (args[0] === 'session-recap') {
114
- return JSON.stringify({
115
- messages: [
116
- { role: 'user', text: 'Need a migration plan.' },
117
- { role: 'assistant', text: 'Suggested phased rollout.' }
118
- ]
119
- });
120
- }
121
- if (args[0] === 'context') {
122
- return JSON.stringify({
123
- context: [
124
- {
125
- title: 'Use Postgres',
126
- age: '1 day ago',
127
- snippet: 'Selected Postgres for durability.'
128
- }
129
- ]
130
- });
131
- }
132
- return '';
133
- });
134
-
135
- const handler = await loadHandler();
136
- const event = {
137
- eventName: 'session:start',
138
- sessionKey: 'agent:clawdious:main',
139
- context: { initialPrompt: 'Need migration plan' },
140
- messages: [{ role: 'user', content: 'Need migration plan' }]
141
- };
142
-
143
- await handler(event);
144
-
145
- const contextCall = execFileSyncMock.mock.calls.find((call) => call[1]?.[0] === 'context');
146
- expect(contextCall?.[1]).toEqual(expect.arrayContaining(['--profile', 'auto']));
147
-
148
- const injected = event.messages.find((message) => message.role === 'system');
149
- expect(injected?.content).toContain('Session context restored');
150
- expect(injected?.content).toContain('Recent conversation');
151
- expect(injected?.content).toContain('Relevant memories');
152
- expect(injected?.content).toContain('Use Postgres');
153
-
154
- fs.rmSync(vaultPath, { recursive: true, force: true });
155
- });
156
-
157
- it('delegates profile selection to context auto mode for urgent prompts', async () => {
158
- const vaultPath = makeVaultFixture();
159
- process.env.CLAWVAULT_PATH = vaultPath;
160
-
161
- execFileSyncMock.mockImplementation((_command, args) => {
162
- if (args[0] === 'session-recap') {
163
- return JSON.stringify({ messages: [] });
164
- }
165
- if (args[0] === 'context') {
166
- return JSON.stringify({ context: [] });
167
- }
168
- return '';
169
- });
170
-
171
- const handler = await loadHandler();
172
- await handler({
173
- eventName: 'session:start',
174
- sessionKey: 'agent:clawdious:main',
175
- context: { initialPrompt: 'URGENT outage: rollback failed in production' },
176
- messages: [{ role: 'user', content: 'URGENT outage: rollback failed in production' }]
177
- });
178
-
179
- const contextCall = execFileSyncMock.mock.calls.find((call) => call[1]?.[0] === 'context');
180
- expect(contextCall?.[1]).toEqual(expect.arrayContaining(['--profile', 'auto']));
181
-
182
- fs.rmSync(vaultPath, { recursive: true, force: true });
183
- });
184
-
185
- it('triggers active observation on heartbeat when threshold is crossed', async () => {
186
- const vaultPath = makeVaultFixture();
187
- const sessionId = 'heartbeat-session-1';
188
- const openClawFixture = makeOpenClawSessionFixture('clawdious', sessionId, 70 * 1024);
189
- process.env.CLAWVAULT_PATH = vaultPath;
190
- process.env.OPENCLAW_STATE_DIR = openClawFixture.stateRoot;
191
-
192
- fs.mkdirSync(path.join(vaultPath, '.clawvault'), { recursive: true });
193
- fs.writeFileSync(
194
- path.join(vaultPath, '.clawvault', 'observe-cursors.json'),
195
- JSON.stringify({
196
- [sessionId]: {
197
- lastObservedOffset: 0,
198
- lastObservedAt: '2026-02-14T00:00:00.000Z',
199
- sessionKey: 'agent:clawdious:main',
200
- lastFileSize: 0
201
- }
202
- }),
203
- 'utf-8'
204
- );
205
-
206
- execFileSyncMock.mockReturnValue('');
207
-
208
- const handler = await loadHandler();
209
- await handler({
210
- type: 'gateway',
211
- action: 'heartbeat'
212
- });
213
-
214
- expect(execFileSyncMock).toHaveBeenCalledWith(
215
- 'clawvault',
216
- expect.arrayContaining(['observe', '--active', '--agent', 'clawdious']),
217
- expect.objectContaining({ shell: false })
218
- );
219
-
220
- fs.rmSync(vaultPath, { recursive: true, force: true });
221
- fs.rmSync(openClawFixture.stateRoot, { recursive: true, force: true });
222
- });
223
-
224
- it('forces active observation flush on compaction events', async () => {
225
- const vaultPath = makeVaultFixture();
226
- process.env.CLAWVAULT_PATH = vaultPath;
227
- execFileSyncMock.mockReturnValue('');
228
-
229
- const handler = await loadHandler();
230
- await handler({
231
- eventName: 'compaction:memoryFlush',
232
- sessionKey: 'agent:clawdious:main'
233
- });
234
-
235
- expect(execFileSyncMock).toHaveBeenCalledWith(
236
- 'clawvault',
237
- expect.arrayContaining(['observe', '--active', '--min-new', '1']),
238
- expect.objectContaining({ shell: false })
239
- );
240
-
241
- fs.rmSync(vaultPath, { recursive: true, force: true });
242
- });
243
-
244
- it('runs weekly reflection on cron.weekly at Sunday midnight', async () => {
245
- const vaultPath = makeVaultFixture();
246
- process.env.CLAWVAULT_PATH = vaultPath;
247
- execFileSyncMock.mockReturnValue('');
248
-
249
- const handler = await loadHandler();
250
- await handler({
251
- eventName: 'cron.weekly',
252
- timestamp: '2026-02-15T00:00:00.000Z'
253
- });
254
-
255
- expect(execFileSyncMock).toHaveBeenCalledWith(
256
- 'clawvault',
257
- expect.arrayContaining(['reflect', '-v', vaultPath]),
258
- expect.objectContaining({ shell: false })
259
- );
260
-
261
- fs.rmSync(vaultPath, { recursive: true, force: true });
262
- });
263
- });
1
+ import { afterEach, describe, expect, it, vi } from 'vitest';
2
+ import * as fs from 'fs';
3
+ import * as os from 'os';
4
+ import * as path from 'path';
5
+
6
+ const { execFileSyncMock } = vi.hoisted(() => ({
7
+ execFileSyncMock: vi.fn()
8
+ }));
9
+
10
+ vi.mock('child_process', () => ({
11
+ execFileSync: execFileSyncMock
12
+ }));
13
+
14
+ function makeVaultFixture() {
15
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'clawvault-hook-'));
16
+ fs.writeFileSync(path.join(root, '.clawvault.json'), JSON.stringify({ name: 'test' }), 'utf-8');
17
+ return root;
18
+ }
19
+
20
+ function makeOpenClawSessionFixture(agentId, sessionId, transcriptBytes = 0) {
21
+ const stateRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'clawvault-openclaw-'));
22
+ const sessionsDir = path.join(stateRoot, 'agents', agentId, 'sessions');
23
+ fs.mkdirSync(sessionsDir, { recursive: true });
24
+ fs.writeFileSync(
25
+ path.join(sessionsDir, 'sessions.json'),
26
+ JSON.stringify({
27
+ [`agent:${agentId}:main`]: {
28
+ sessionId,
29
+ updatedAt: Date.now()
30
+ }
31
+ }),
32
+ 'utf-8'
33
+ );
34
+ const transcriptPath = path.join(sessionsDir, `${sessionId}.jsonl`);
35
+ const payload = transcriptBytes > 0 ? 'x'.repeat(transcriptBytes) : '';
36
+ fs.writeFileSync(transcriptPath, payload, 'utf-8');
37
+ return { stateRoot, sessionsDir, transcriptPath };
38
+ }
39
+
40
+ async function loadHandler() {
41
+ vi.resetModules();
42
+ const mod = await import('./handler.js');
43
+ return mod.default;
44
+ }
45
+
46
+ afterEach(() => {
47
+ vi.clearAllMocks();
48
+ delete process.env.CLAWVAULT_PATH;
49
+ delete process.env.OPENCLAW_STATE_DIR;
50
+ delete process.env.OPENCLAW_HOME;
51
+ delete process.env.OPENCLAW_AGENT_ID;
52
+ });
53
+
54
+ describe('clawvault hook handler', () => {
55
+ it('injects recovery warning on gateway startup when death detected', async () => {
56
+ const vaultPath = makeVaultFixture();
57
+ process.env.CLAWVAULT_PATH = vaultPath;
58
+
59
+ execFileSyncMock.mockImplementation((_command, args) => {
60
+ if (args[0] === 'recover') {
61
+ return '⚠️ CONTEXT DEATH DETECTED\nWorking on: ship memory graph';
62
+ }
63
+ return '';
64
+ });
65
+
66
+ const handler = await loadHandler();
67
+ const event = {
68
+ type: 'gateway',
69
+ action: 'startup',
70
+ messages: [{ role: 'user', content: 'hello' }]
71
+ };
72
+
73
+ await handler(event);
74
+
75
+ expect(execFileSyncMock).toHaveBeenCalledWith(
76
+ 'clawvault',
77
+ expect.arrayContaining(['recover', '--clear', '-v', vaultPath]),
78
+ expect.objectContaining({ shell: false })
79
+ );
80
+ const injected = event.messages.find((message) => message.role === 'system');
81
+ expect(injected?.content).toContain('Context death detected');
82
+ expect(injected?.content).toContain('ship memory graph');
83
+
84
+ fs.rmSync(vaultPath, { recursive: true, force: true });
85
+ });
86
+
87
+ it('supports alias event names for command:new', async () => {
88
+ const vaultPath = makeVaultFixture();
89
+ process.env.CLAWVAULT_PATH = vaultPath;
90
+ execFileSyncMock.mockReturnValue('');
91
+
92
+ const handler = await loadHandler();
93
+ await handler({
94
+ event: 'command:new',
95
+ sessionKey: 'agent:clawdious:main',
96
+ context: { commandSource: 'cli' }
97
+ });
98
+
99
+ expect(execFileSyncMock).toHaveBeenCalledWith(
100
+ 'clawvault',
101
+ expect.arrayContaining(['checkpoint', '--working-on']),
102
+ expect.objectContaining({ shell: false })
103
+ );
104
+
105
+ fs.rmSync(vaultPath, { recursive: true, force: true });
106
+ });
107
+
108
+ it('injects recap and memory context on session start alias event', async () => {
109
+ const vaultPath = makeVaultFixture();
110
+ process.env.CLAWVAULT_PATH = vaultPath;
111
+
112
+ execFileSyncMock.mockImplementation((_command, args) => {
113
+ if (args[0] === 'session-recap') {
114
+ return JSON.stringify({
115
+ messages: [
116
+ { role: 'user', text: 'Need a migration plan.' },
117
+ { role: 'assistant', text: 'Suggested phased rollout.' }
118
+ ]
119
+ });
120
+ }
121
+ if (args[0] === 'context') {
122
+ return JSON.stringify({
123
+ context: [
124
+ {
125
+ title: 'Use Postgres',
126
+ age: '1 day ago',
127
+ snippet: 'Selected Postgres for durability.'
128
+ }
129
+ ]
130
+ });
131
+ }
132
+ return '';
133
+ });
134
+
135
+ const handler = await loadHandler();
136
+ const event = {
137
+ eventName: 'session:start',
138
+ sessionKey: 'agent:clawdious:main',
139
+ context: { initialPrompt: 'Need migration plan' },
140
+ messages: [{ role: 'user', content: 'Need migration plan' }]
141
+ };
142
+
143
+ await handler(event);
144
+
145
+ const contextCall = execFileSyncMock.mock.calls.find((call) => call[1]?.[0] === 'context');
146
+ expect(contextCall?.[1]).toEqual(expect.arrayContaining(['--profile', 'auto']));
147
+
148
+ const injected = event.messages.find((message) => message.role === 'system');
149
+ expect(injected?.content).toContain('Session context restored');
150
+ expect(injected?.content).toContain('Recent conversation');
151
+ expect(injected?.content).toContain('Relevant memories');
152
+ expect(injected?.content).toContain('Use Postgres');
153
+
154
+ fs.rmSync(vaultPath, { recursive: true, force: true });
155
+ });
156
+
157
+ it('delegates profile selection to context auto mode for urgent prompts', async () => {
158
+ const vaultPath = makeVaultFixture();
159
+ process.env.CLAWVAULT_PATH = vaultPath;
160
+
161
+ execFileSyncMock.mockImplementation((_command, args) => {
162
+ if (args[0] === 'session-recap') {
163
+ return JSON.stringify({ messages: [] });
164
+ }
165
+ if (args[0] === 'context') {
166
+ return JSON.stringify({ context: [] });
167
+ }
168
+ return '';
169
+ });
170
+
171
+ const handler = await loadHandler();
172
+ await handler({
173
+ eventName: 'session:start',
174
+ sessionKey: 'agent:clawdious:main',
175
+ context: { initialPrompt: 'URGENT outage: rollback failed in production' },
176
+ messages: [{ role: 'user', content: 'URGENT outage: rollback failed in production' }]
177
+ });
178
+
179
+ const contextCall = execFileSyncMock.mock.calls.find((call) => call[1]?.[0] === 'context');
180
+ expect(contextCall?.[1]).toEqual(expect.arrayContaining(['--profile', 'auto']));
181
+
182
+ fs.rmSync(vaultPath, { recursive: true, force: true });
183
+ });
184
+
185
+ it('triggers active observation on heartbeat when threshold is crossed', async () => {
186
+ const vaultPath = makeVaultFixture();
187
+ const sessionId = 'heartbeat-session-1';
188
+ const openClawFixture = makeOpenClawSessionFixture('main', sessionId, 70 * 1024);
189
+ process.env.CLAWVAULT_PATH = vaultPath;
190
+ process.env.OPENCLAW_STATE_DIR = openClawFixture.stateRoot;
191
+
192
+ fs.mkdirSync(path.join(vaultPath, '.clawvault'), { recursive: true });
193
+ fs.writeFileSync(
194
+ path.join(vaultPath, '.clawvault', 'observe-cursors.json'),
195
+ JSON.stringify({
196
+ [sessionId]: {
197
+ lastObservedOffset: 0,
198
+ lastObservedAt: '2026-02-14T00:00:00.000Z',
199
+ sessionKey: 'agent:main:main',
200
+ lastFileSize: 0
201
+ }
202
+ }),
203
+ 'utf-8'
204
+ );
205
+
206
+ execFileSyncMock.mockReturnValue('');
207
+
208
+ const handler = await loadHandler();
209
+ await handler({
210
+ type: 'gateway',
211
+ action: 'heartbeat'
212
+ });
213
+
214
+ expect(execFileSyncMock).toHaveBeenCalledWith(
215
+ 'clawvault',
216
+ expect.arrayContaining(['observe', '--cron', '--agent', 'main']),
217
+ expect.objectContaining({ shell: false })
218
+ );
219
+
220
+ fs.rmSync(vaultPath, { recursive: true, force: true });
221
+ fs.rmSync(openClawFixture.stateRoot, { recursive: true, force: true });
222
+ });
223
+
224
+ it('forces active observation flush on compaction events', async () => {
225
+ const vaultPath = makeVaultFixture();
226
+ process.env.CLAWVAULT_PATH = vaultPath;
227
+ execFileSyncMock.mockReturnValue('');
228
+
229
+ const handler = await loadHandler();
230
+ await handler({
231
+ eventName: 'compaction:memoryFlush',
232
+ sessionKey: 'agent:clawdious:main'
233
+ });
234
+
235
+ expect(execFileSyncMock).toHaveBeenCalledWith(
236
+ 'clawvault',
237
+ expect.arrayContaining(['observe', '--cron', '--min-new', '1']),
238
+ expect.objectContaining({ shell: false })
239
+ );
240
+
241
+ fs.rmSync(vaultPath, { recursive: true, force: true });
242
+ });
243
+
244
+ it('runs weekly reflection on cron.weekly at Sunday midnight', async () => {
245
+ const vaultPath = makeVaultFixture();
246
+ process.env.CLAWVAULT_PATH = vaultPath;
247
+ execFileSyncMock.mockReturnValue('');
248
+
249
+ const handler = await loadHandler();
250
+ await handler({
251
+ eventName: 'cron.weekly',
252
+ timestamp: '2026-02-15T00:00:00.000Z'
253
+ });
254
+
255
+ expect(execFileSyncMock).toHaveBeenCalledWith(
256
+ 'clawvault',
257
+ expect.arrayContaining(['reflect', '-v', vaultPath]),
258
+ expect.objectContaining({ shell: false })
259
+ );
260
+
261
+ fs.rmSync(vaultPath, { recursive: true, force: true });
262
+ });
263
+ });