clawvault 3.0.0 → 3.1.0

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 (60) hide show
  1. package/README.md +156 -105
  2. package/bin/clawvault.js +0 -2
  3. package/bin/register-core-commands.js +20 -2
  4. package/dist/{chunk-3D6BCTP6.js → chunk-33UGEQRT.js} +70 -145
  5. package/dist/{chunk-ZVVFWOLW.js → chunk-3WRJEKN4.js} +1 -1
  6. package/dist/{chunk-DEFFDRVP.js → chunk-3ZIH425O.js} +3 -70
  7. package/dist/{chunk-K234IDRJ.js → chunk-D2H45LON.js} +1 -0
  8. package/dist/{chunk-YKTA5JOJ.js → chunk-H62BP7RI.js} +3 -3
  9. package/dist/{chunk-WGRQ6HDV.js → chunk-LI4O6NVK.js} +1 -1
  10. package/dist/{chunk-7R7O6STJ.js → chunk-OCGVIN3L.js} +1 -1
  11. package/dist/{chunk-GAJV4IGR.js → chunk-YCUNCH2I.js} +3 -7
  12. package/dist/cli/index.cjs +10 -1459
  13. package/dist/cli/index.js +5 -8
  14. package/dist/commands/compat.cjs +70 -145
  15. package/dist/commands/compat.js +1 -1
  16. package/dist/commands/context.cjs +1 -0
  17. package/dist/commands/context.js +3 -3
  18. package/dist/commands/doctor.cjs +68 -144
  19. package/dist/commands/doctor.js +4 -4
  20. package/dist/commands/embed.js +2 -2
  21. package/dist/commands/setup.cjs +2 -69
  22. package/dist/commands/setup.d.cts +0 -1
  23. package/dist/commands/setup.d.ts +0 -1
  24. package/dist/commands/setup.js +2 -2
  25. package/dist/commands/sleep.cjs +1 -0
  26. package/dist/commands/sleep.js +2 -2
  27. package/dist/commands/status.cjs +1 -0
  28. package/dist/commands/status.js +2 -2
  29. package/dist/commands/wake.cjs +1 -0
  30. package/dist/commands/wake.js +2 -2
  31. package/dist/index.cjs +447 -2600
  32. package/dist/index.d.cts +0 -4
  33. package/dist/index.d.ts +0 -4
  34. package/dist/index.js +8 -69
  35. package/dist/plugin/index.cjs +3 -3
  36. package/dist/plugin/index.js +10 -10
  37. package/package.json +11 -17
  38. package/bin/register-tailscale-commands.js +0 -106
  39. package/dist/chunk-IVRIKYFE.js +0 -520
  40. package/dist/chunk-THRJVD4L.js +0 -373
  41. package/dist/chunk-TIGW564L.js +0 -628
  42. package/dist/commands/tailscale.cjs +0 -1532
  43. package/dist/commands/tailscale.d.cts +0 -52
  44. package/dist/commands/tailscale.d.ts +0 -52
  45. package/dist/commands/tailscale.js +0 -26
  46. package/dist/lib/canvas-layout.cjs +0 -136
  47. package/dist/lib/canvas-layout.d.cts +0 -31
  48. package/dist/lib/canvas-layout.d.ts +0 -31
  49. package/dist/lib/canvas-layout.js +0 -92
  50. package/dist/lib/tailscale.cjs +0 -1183
  51. package/dist/lib/tailscale.d.cts +0 -225
  52. package/dist/lib/tailscale.d.ts +0 -225
  53. package/dist/lib/tailscale.js +0 -50
  54. package/dist/lib/webdav.cjs +0 -568
  55. package/dist/lib/webdav.d.cts +0 -109
  56. package/dist/lib/webdav.d.ts +0 -109
  57. package/dist/lib/webdav.js +0 -35
  58. package/hooks/clawvault/HOOK.md +0 -83
  59. package/hooks/clawvault/handler.js +0 -879
  60. package/hooks/clawvault/handler.test.js +0 -354
@@ -1,354 +0,0 @@
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_MEMORY_PATH;
50
- delete process.env.OPENCLAW_VAULT_PATH;
51
- delete process.env.OPENCLAW_STATE_DIR;
52
- delete process.env.OPENCLAW_HOME;
53
- delete process.env.OPENCLAW_AGENT_ID;
54
- });
55
-
56
- describe('clawvault hook handler', () => {
57
- it('injects recovery warning on gateway startup when death detected', async () => {
58
- const vaultPath = makeVaultFixture();
59
- process.env.CLAWVAULT_PATH = vaultPath;
60
-
61
- execFileSyncMock.mockImplementation((_command, args) => {
62
- if (args[0] === 'recover') {
63
- return '⚠️ CONTEXT DEATH DETECTED\nWorking on: ship memory graph';
64
- }
65
- return '';
66
- });
67
-
68
- const handler = await loadHandler();
69
- const event = {
70
- type: 'gateway',
71
- action: 'startup',
72
- messages: [{ role: 'user', content: 'hello' }]
73
- };
74
-
75
- await handler(event);
76
-
77
- expect(execFileSyncMock).toHaveBeenCalledWith(
78
- 'clawvault',
79
- expect.arrayContaining(['recover', '--clear', '-v', vaultPath]),
80
- expect.objectContaining({ shell: false })
81
- );
82
- const injected = event.messages.find((message) => message.role === 'system');
83
- expect(injected?.content).toContain('Context death detected');
84
- expect(injected?.content).toContain('ship memory graph');
85
-
86
- fs.rmSync(vaultPath, { recursive: true, force: true });
87
- });
88
-
89
- it('supports alias event names for command:new', async () => {
90
- const vaultPath = makeVaultFixture();
91
- process.env.CLAWVAULT_PATH = vaultPath;
92
- execFileSyncMock.mockReturnValue('');
93
-
94
- const handler = await loadHandler();
95
- await handler({
96
- event: 'command:new',
97
- sessionKey: 'agent:clawdious:main',
98
- context: { commandSource: 'cli' }
99
- });
100
-
101
- expect(execFileSyncMock).toHaveBeenCalledWith(
102
- 'clawvault',
103
- expect.arrayContaining(['checkpoint', '--working-on']),
104
- expect.objectContaining({ shell: false })
105
- );
106
-
107
- fs.rmSync(vaultPath, { recursive: true, force: true });
108
- });
109
-
110
- it('supports slash-prefixed command actions for /new', async () => {
111
- const vaultPath = makeVaultFixture();
112
- process.env.CLAWVAULT_PATH = vaultPath;
113
- execFileSyncMock.mockReturnValue('');
114
-
115
- const handler = await loadHandler();
116
- await handler({
117
- type: 'command',
118
- action: '/new',
119
- sessionKey: 'agent:clawdious:main',
120
- context: { commandSource: 'slash' }
121
- });
122
-
123
- expect(execFileSyncMock).toHaveBeenCalledWith(
124
- 'clawvault',
125
- expect.arrayContaining(['checkpoint', '--working-on']),
126
- expect.objectContaining({ shell: false })
127
- );
128
-
129
- fs.rmSync(vaultPath, { recursive: true, force: true });
130
- });
131
-
132
- it('injects recap and memory context on session start alias event', async () => {
133
- const vaultPath = makeVaultFixture();
134
- process.env.CLAWVAULT_PATH = vaultPath;
135
-
136
- execFileSyncMock.mockImplementation((_command, args) => {
137
- if (args[0] === 'session-recap') {
138
- return JSON.stringify({
139
- messages: [
140
- { role: 'user', text: 'Need a migration plan.' },
141
- { role: 'assistant', text: 'Suggested phased rollout.' }
142
- ]
143
- });
144
- }
145
- if (args[0] === 'context') {
146
- return JSON.stringify({
147
- context: [
148
- {
149
- title: 'Use Postgres',
150
- age: '1 day ago',
151
- snippet: 'Selected Postgres for durability.'
152
- }
153
- ]
154
- });
155
- }
156
- return '';
157
- });
158
-
159
- const handler = await loadHandler();
160
- const event = {
161
- eventName: 'session:start',
162
- sessionKey: 'agent:clawdious:main',
163
- context: { initialPrompt: 'Need migration plan' },
164
- messages: [{ role: 'user', content: 'Need migration plan' }]
165
- };
166
-
167
- await handler(event);
168
-
169
- const contextCall = execFileSyncMock.mock.calls.find((call) => call[1]?.[0] === 'context');
170
- expect(contextCall?.[1]).toEqual(expect.arrayContaining(['--profile', 'auto']));
171
-
172
- const injected = event.messages.find((message) => message.role === 'system');
173
- expect(injected?.content).toContain('Session context restored');
174
- expect(injected?.content).toContain('Recent conversation');
175
- expect(injected?.content).toContain('Relevant memories');
176
- expect(injected?.content).toContain('Use Postgres');
177
-
178
- fs.rmSync(vaultPath, { recursive: true, force: true });
179
- });
180
-
181
- it('delegates profile selection to context auto mode for urgent prompts', async () => {
182
- const vaultPath = makeVaultFixture();
183
- process.env.CLAWVAULT_PATH = vaultPath;
184
-
185
- execFileSyncMock.mockImplementation((_command, args) => {
186
- if (args[0] === 'session-recap') {
187
- return JSON.stringify({ messages: [] });
188
- }
189
- if (args[0] === 'context') {
190
- return JSON.stringify({ context: [] });
191
- }
192
- return '';
193
- });
194
-
195
- const handler = await loadHandler();
196
- await handler({
197
- eventName: 'session:start',
198
- sessionKey: 'agent:clawdious:main',
199
- context: { initialPrompt: 'URGENT outage: rollback failed in production' },
200
- messages: [{ role: 'user', content: 'URGENT outage: rollback failed in production' }]
201
- });
202
-
203
- const contextCall = execFileSyncMock.mock.calls.find((call) => call[1]?.[0] === 'context');
204
- expect(contextCall?.[1]).toEqual(expect.arrayContaining(['--profile', 'auto']));
205
-
206
- fs.rmSync(vaultPath, { recursive: true, force: true });
207
- });
208
-
209
- it('triggers active observation on heartbeat when threshold is crossed', async () => {
210
- const vaultPath = makeVaultFixture();
211
- const sessionId = 'heartbeat-session-1';
212
- const openClawFixture = makeOpenClawSessionFixture('main', sessionId, 70 * 1024);
213
- process.env.CLAWVAULT_PATH = vaultPath;
214
- process.env.OPENCLAW_STATE_DIR = openClawFixture.stateRoot;
215
-
216
- fs.mkdirSync(path.join(vaultPath, '.clawvault'), { recursive: true });
217
- fs.writeFileSync(
218
- path.join(vaultPath, '.clawvault', 'observe-cursors.json'),
219
- JSON.stringify({
220
- [sessionId]: {
221
- lastObservedOffset: 0,
222
- lastObservedAt: '2026-02-14T00:00:00.000Z',
223
- sessionKey: 'agent:main:main',
224
- lastFileSize: 0
225
- }
226
- }),
227
- 'utf-8'
228
- );
229
-
230
- execFileSyncMock.mockReturnValue('');
231
-
232
- const handler = await loadHandler();
233
- await handler({
234
- type: 'gateway',
235
- action: 'heartbeat'
236
- });
237
-
238
- expect(execFileSyncMock).toHaveBeenCalledWith(
239
- 'clawvault',
240
- expect.arrayContaining(['observe', '--cron', '--agent', 'main']),
241
- expect.objectContaining({ shell: false })
242
- );
243
-
244
- fs.rmSync(vaultPath, { recursive: true, force: true });
245
- fs.rmSync(openClawFixture.stateRoot, { recursive: true, force: true });
246
- });
247
-
248
- it('forces active observation flush on compaction events', async () => {
249
- const vaultPath = makeVaultFixture();
250
- process.env.CLAWVAULT_PATH = vaultPath;
251
- execFileSyncMock.mockReturnValue('');
252
-
253
- const handler = await loadHandler();
254
- await handler({
255
- eventName: 'compaction:memoryFlush',
256
- sessionKey: 'agent:clawdious:main'
257
- });
258
-
259
- expect(execFileSyncMock).toHaveBeenCalledWith(
260
- 'clawvault',
261
- expect.arrayContaining(['observe', '--cron', '--min-new', '1']),
262
- expect.objectContaining({ shell: false })
263
- );
264
-
265
- fs.rmSync(vaultPath, { recursive: true, force: true });
266
- });
267
-
268
- it('supports compaction action separator variants', async () => {
269
- const vaultPath = makeVaultFixture();
270
- process.env.CLAWVAULT_PATH = vaultPath;
271
- execFileSyncMock.mockReturnValue('');
272
-
273
- const handler = await loadHandler();
274
- await handler({
275
- type: 'compaction',
276
- action: 'memory_flush',
277
- sessionKey: 'agent:clawdious:main'
278
- });
279
-
280
- expect(execFileSyncMock).toHaveBeenCalledWith(
281
- 'clawvault',
282
- expect.arrayContaining(['observe', '--cron', '--min-new', '1']),
283
- expect.objectContaining({ shell: false })
284
- );
285
-
286
- fs.rmSync(vaultPath, { recursive: true, force: true });
287
- });
288
-
289
- it('discovers canonical ~/memory vault when env and cwd do not provide one', async () => {
290
- const fakeHome = fs.mkdtempSync(path.join(os.tmpdir(), 'clawvault-home-'));
291
- const vaultPath = path.join(fakeHome, 'memory');
292
- fs.mkdirSync(vaultPath, { recursive: true });
293
- fs.writeFileSync(path.join(vaultPath, '.clawvault.json'), JSON.stringify({ name: 'home' }), 'utf-8');
294
- const originalHome = process.env.HOME;
295
- const originalClawvaultPath = process.env.CLAWVAULT_PATH;
296
- const originalOpenclawMemory = process.env.OPENCLAW_MEMORY_PATH;
297
- const originalOpenclawVault = process.env.OPENCLAW_VAULT_PATH;
298
- process.env.HOME = fakeHome;
299
- delete process.env.CLAWVAULT_PATH;
300
- delete process.env.OPENCLAW_MEMORY_PATH;
301
- delete process.env.OPENCLAW_VAULT_PATH;
302
- // Mock cwd to a temp dir without a vault so walk-up doesn't find one
303
- const fakeCwd = fs.mkdtempSync(path.join(os.tmpdir(), 'clawvault-cwd-'));
304
- const originalCwd = process.cwd;
305
- process.cwd = () => fakeCwd;
306
- try {
307
- execFileSyncMock.mockReturnValue('');
308
-
309
- const handler = await loadHandler();
310
- await handler({
311
- eventName: 'compaction:memoryFlush',
312
- sessionKey: 'agent:main:main'
313
- });
314
-
315
- expect(execFileSyncMock).toHaveBeenCalledWith(
316
- 'clawvault',
317
- expect.arrayContaining(['observe', '--cron', '-v', vaultPath]),
318
- expect.objectContaining({ shell: false })
319
- );
320
- } finally {
321
- if (originalHome === undefined) {
322
- delete process.env.HOME;
323
- } else {
324
- process.env.HOME = originalHome;
325
- }
326
- if (originalClawvaultPath !== undefined) process.env.CLAWVAULT_PATH = originalClawvaultPath;
327
- if (originalOpenclawMemory !== undefined) process.env.OPENCLAW_MEMORY_PATH = originalOpenclawMemory;
328
- if (originalOpenclawVault !== undefined) process.env.OPENCLAW_VAULT_PATH = originalOpenclawVault;
329
- process.cwd = originalCwd;
330
- fs.rmSync(fakeHome, { recursive: true, force: true });
331
- fs.rmSync(fakeCwd, { recursive: true, force: true });
332
- }
333
- });
334
-
335
- it('runs weekly reflection on cron.weekly at Sunday midnight', async () => {
336
- const vaultPath = makeVaultFixture();
337
- process.env.CLAWVAULT_PATH = vaultPath;
338
- execFileSyncMock.mockReturnValue('');
339
-
340
- const handler = await loadHandler();
341
- await handler({
342
- eventName: 'cron.weekly',
343
- timestamp: '2026-02-15T00:00:00.000Z'
344
- });
345
-
346
- expect(execFileSyncMock).toHaveBeenCalledWith(
347
- 'clawvault',
348
- expect.arrayContaining(['reflect', '-v', vaultPath]),
349
- expect.objectContaining({ shell: false })
350
- );
351
-
352
- fs.rmSync(vaultPath, { recursive: true, force: true });
353
- });
354
- });