@yeseh/cortex-cli 0.6.3 → 0.6.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.
- package/dist/category/commands/create.d.ts +44 -0
- package/dist/category/commands/create.d.ts.map +1 -0
- package/dist/category/commands/create.spec.d.ts +7 -0
- package/dist/category/commands/create.spec.d.ts.map +1 -0
- package/dist/category/index.d.ts +19 -0
- package/dist/category/index.d.ts.map +1 -0
- package/dist/commands/init.d.ts +58 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.spec.d.ts +2 -0
- package/dist/commands/init.spec.d.ts.map +1 -0
- package/dist/context.d.ts +18 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.spec.d.ts +2 -0
- package/dist/context.spec.d.ts.map +1 -0
- package/dist/create-cli-command.d.ts +23 -0
- package/dist/create-cli-command.d.ts.map +1 -0
- package/dist/create-cli-command.spec.d.ts +10 -0
- package/dist/create-cli-command.spec.d.ts.map +1 -0
- package/dist/errors.d.ts +57 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.spec.d.ts +2 -0
- package/dist/errors.spec.d.ts.map +1 -0
- package/dist/input.d.ts +42 -0
- package/dist/input.d.ts.map +1 -0
- package/dist/input.spec.d.ts +2 -0
- package/dist/input.spec.d.ts.map +1 -0
- package/dist/memory/commands/add.d.ts +62 -0
- package/dist/memory/commands/add.d.ts.map +1 -0
- package/dist/memory/commands/add.spec.d.ts +7 -0
- package/dist/memory/commands/add.spec.d.ts.map +1 -0
- package/dist/memory/commands/definitions.spec.d.ts +10 -0
- package/dist/memory/commands/definitions.spec.d.ts.map +1 -0
- package/dist/memory/commands/handlers.spec.d.ts +2 -0
- package/dist/memory/commands/handlers.spec.d.ts.map +1 -0
- package/dist/memory/commands/list.d.ts +119 -0
- package/dist/memory/commands/list.d.ts.map +1 -0
- package/dist/memory/commands/list.spec.d.ts +2 -0
- package/dist/memory/commands/list.spec.d.ts.map +1 -0
- package/dist/memory/commands/move.d.ts +42 -0
- package/dist/memory/commands/move.d.ts.map +1 -0
- package/dist/memory/commands/move.spec.d.ts +2 -0
- package/dist/memory/commands/move.spec.d.ts.map +1 -0
- package/dist/memory/commands/remove.d.ts +41 -0
- package/dist/memory/commands/remove.d.ts.map +1 -0
- package/dist/memory/commands/remove.spec.d.ts +2 -0
- package/dist/memory/commands/remove.spec.d.ts.map +1 -0
- package/dist/memory/commands/show.d.ts +81 -0
- package/dist/memory/commands/show.d.ts.map +1 -0
- package/dist/memory/commands/show.spec.d.ts +2 -0
- package/dist/memory/commands/show.spec.d.ts.map +1 -0
- package/dist/memory/commands/test-helpers.spec.d.ts +19 -0
- package/dist/memory/commands/test-helpers.spec.d.ts.map +1 -0
- package/dist/memory/commands/update.d.ts +73 -0
- package/dist/memory/commands/update.d.ts.map +1 -0
- package/dist/memory/commands/update.spec.d.ts +2 -0
- package/dist/memory/commands/update.spec.d.ts.map +1 -0
- package/dist/memory/index.d.ts +29 -0
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.spec.d.ts +10 -0
- package/dist/memory/index.spec.d.ts.map +1 -0
- package/dist/memory/parsing.d.ts +3 -0
- package/dist/memory/parsing.d.ts.map +1 -0
- package/dist/memory/parsing.spec.d.ts +7 -0
- package/dist/memory/parsing.spec.d.ts.map +1 -0
- package/dist/output.d.ts +87 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/output.spec.d.ts +2 -0
- package/dist/output.spec.d.ts.map +1 -0
- package/dist/paths.d.ts +27 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.spec.d.ts +7 -0
- package/dist/paths.spec.d.ts.map +1 -0
- package/dist/program.d.ts +41 -0
- package/dist/program.d.ts.map +1 -0
- package/dist/program.spec.d.ts +11 -0
- package/dist/program.spec.d.ts.map +1 -0
- package/dist/run.d.ts +7 -0
- package/dist/run.d.ts.map +1 -0
- package/dist/run.spec.d.ts +12 -0
- package/dist/run.spec.d.ts.map +1 -0
- package/dist/store/commands/add.d.ts +73 -0
- package/dist/store/commands/add.d.ts.map +1 -0
- package/dist/store/commands/add.spec.d.ts +17 -0
- package/dist/store/commands/add.spec.d.ts.map +1 -0
- package/dist/store/commands/init.d.ts +75 -0
- package/dist/store/commands/init.d.ts.map +1 -0
- package/dist/store/commands/init.spec.d.ts +7 -0
- package/dist/store/commands/init.spec.d.ts.map +1 -0
- package/dist/store/commands/list.d.ts +62 -0
- package/dist/store/commands/list.d.ts.map +1 -0
- package/dist/store/commands/list.spec.d.ts +7 -0
- package/dist/store/commands/list.spec.d.ts.map +1 -0
- package/dist/store/commands/prune.d.ts +92 -0
- package/dist/store/commands/prune.d.ts.map +1 -0
- package/dist/store/commands/prune.spec.d.ts +7 -0
- package/dist/store/commands/prune.spec.d.ts.map +1 -0
- package/dist/store/commands/reindexs.d.ts +54 -0
- package/dist/store/commands/reindexs.d.ts.map +1 -0
- package/dist/store/commands/reindexs.spec.d.ts +7 -0
- package/dist/store/commands/reindexs.spec.d.ts.map +1 -0
- package/dist/store/commands/remove.d.ts +63 -0
- package/dist/store/commands/remove.d.ts.map +1 -0
- package/dist/store/commands/remove.spec.d.ts +17 -0
- package/dist/store/commands/remove.spec.d.ts.map +1 -0
- package/dist/store/index.d.ts +32 -0
- package/dist/store/index.d.ts.map +1 -0
- package/dist/store/index.spec.d.ts +9 -0
- package/dist/store/index.spec.d.ts.map +1 -0
- package/dist/store/utils/resolve-store-name.d.ts +30 -0
- package/dist/store/utils/resolve-store-name.d.ts.map +1 -0
- package/dist/store/utils/resolve-store-name.spec.d.ts +2 -0
- package/dist/store/utils/resolve-store-name.spec.d.ts.map +1 -0
- package/dist/test-helpers.spec.d.ts +224 -0
- package/dist/test-helpers.spec.d.ts.map +1 -0
- package/dist/tests/cli.integration.spec.d.ts +11 -0
- package/dist/tests/cli.integration.spec.d.ts.map +1 -0
- package/dist/toon.d.ts +197 -0
- package/dist/toon.d.ts.map +1 -0
- package/dist/toon.spec.d.ts +9 -0
- package/dist/toon.spec.d.ts.map +1 -0
- package/dist/utils/git.d.ts +20 -0
- package/dist/utils/git.d.ts.map +1 -0
- package/dist/utils/git.spec.d.ts +7 -0
- package/dist/utils/git.spec.d.ts.map +1 -0
- package/package.json +3 -3
- package/src/observability.spec.ts +8 -21
- package/src/observability.ts +26 -7
- package/src/program.ts +1 -1
- package/src/run.ts +0 -0
- package/src/tests/cli.integration.spec.ts +79 -270
- package/src/utils/input.ts +4 -9
- package/src/utils/resolve-default-store.spec.ts +1 -1
- package/src/utils/resolve-default-store.ts +2 -6
|
@@ -18,7 +18,7 @@ const diagnosticsEnabled = process.env.CORTEX_TEST_DIAGNOSTICS === '1';
|
|
|
18
18
|
const formatCliFailure = (
|
|
19
19
|
args: string[],
|
|
20
20
|
result: CliResult,
|
|
21
|
-
extra?: Record<string, unknown
|
|
21
|
+
extra?: Record<string, unknown>
|
|
22
22
|
): string => {
|
|
23
23
|
const extraLines = extra ? `\nextra: ${JSON.stringify(extra, null, 2)}` : '';
|
|
24
24
|
return (
|
|
@@ -88,19 +88,12 @@ const runCortexCli = async (args: string[], options: CliOptions): Promise<CliRes
|
|
|
88
88
|
// Preserve TERM if available (some help formatting can depend on it)
|
|
89
89
|
if (process.env.TERM) env.TERM = process.env.TERM;
|
|
90
90
|
|
|
91
|
-
for (const [
|
|
92
|
-
key, value,
|
|
93
|
-
] of Object.entries(options.env ?? {})) {
|
|
91
|
+
for (const [key, value] of Object.entries(options.env ?? {})) {
|
|
94
92
|
if (typeof value === 'string') env[key] = value;
|
|
95
93
|
}
|
|
96
94
|
|
|
97
95
|
// Use Bun.spawn for cross-platform subprocess spawning
|
|
98
|
-
const proc = Bun.spawn([
|
|
99
|
-
'bun',
|
|
100
|
-
'run',
|
|
101
|
-
scriptPath,
|
|
102
|
-
...args,
|
|
103
|
-
], {
|
|
96
|
+
const proc = Bun.spawn(['bun', 'run', scriptPath, ...args], {
|
|
104
97
|
cwd: options.cwd,
|
|
105
98
|
env,
|
|
106
99
|
stdin: options.stdin !== undefined ? 'pipe' : 'inherit',
|
|
@@ -116,9 +109,7 @@ const runCortexCli = async (args: string[], options: CliOptions): Promise<CliRes
|
|
|
116
109
|
proc.stdin.end();
|
|
117
110
|
}
|
|
118
111
|
|
|
119
|
-
const [
|
|
120
|
-
stdout, stderr,
|
|
121
|
-
] = await Promise.all([
|
|
112
|
+
const [stdout, stderr] = await Promise.all([
|
|
122
113
|
new Response(proc.stdout).text(),
|
|
123
114
|
new Response(proc.stderr).text(),
|
|
124
115
|
]);
|
|
@@ -145,8 +136,7 @@ const runCortexCli = async (args: string[], options: CliOptions): Promise<CliRes
|
|
|
145
136
|
resolvedConfigPath,
|
|
146
137
|
resolvedStoreRoot,
|
|
147
138
|
};
|
|
148
|
-
}
|
|
149
|
-
catch (error) {
|
|
139
|
+
} catch (error) {
|
|
150
140
|
// Handle process errors
|
|
151
141
|
const processError = error as { stdout?: Buffer; stderr?: Buffer; exitCode?: number };
|
|
152
142
|
const stdoutTrimmed = processError.stdout?.toString().trim() ?? '';
|
|
@@ -217,7 +207,7 @@ const createMemoryFile = async (
|
|
|
217
207
|
expiresAt?: Date;
|
|
218
208
|
createdAt?: Date;
|
|
219
209
|
updatedAt?: Date;
|
|
220
|
-
} = {}
|
|
210
|
+
} = {}
|
|
221
211
|
): Promise<void> => {
|
|
222
212
|
const content = options.content ?? 'Test memory content.';
|
|
223
213
|
const tags = options.tags ?? ['test'];
|
|
@@ -239,7 +229,7 @@ const createMemoryFile = async (
|
|
|
239
229
|
expiresAt: options.expiresAt,
|
|
240
230
|
citations: [],
|
|
241
231
|
},
|
|
242
|
-
content
|
|
232
|
+
content
|
|
243
233
|
);
|
|
244
234
|
if (!memoryResult.ok()) {
|
|
245
235
|
throw new Error(`Failed to create memory: ${memoryResult.error.message}`);
|
|
@@ -247,7 +237,7 @@ const createMemoryFile = async (
|
|
|
247
237
|
|
|
248
238
|
const adapter = new FilesystemStorageAdapter(
|
|
249
239
|
new FilesystemConfigAdapter(join(storeRoot, 'config.yaml')),
|
|
250
|
-
{ rootDirectory: storeRoot }
|
|
240
|
+
{ rootDirectory: storeRoot }
|
|
251
241
|
);
|
|
252
242
|
const writeResult = await adapter.memories.save(memoryResult.value.path, memoryResult.value);
|
|
253
243
|
if (!writeResult.ok()) {
|
|
@@ -280,8 +270,7 @@ const createCategory = async (categoryPath: string, storeRoot: string): Promise<
|
|
|
280
270
|
const rootIndexPath = join(storeRoot, 'index.yaml');
|
|
281
271
|
try {
|
|
282
272
|
await fs.access(rootIndexPath);
|
|
283
|
-
}
|
|
284
|
-
catch {
|
|
273
|
+
} catch {
|
|
285
274
|
await fs.writeFile(rootIndexPath, 'memories: []\nsubcategories: []', 'utf8');
|
|
286
275
|
}
|
|
287
276
|
};
|
|
@@ -295,15 +284,14 @@ const createCategoryIndex = async (
|
|
|
295
284
|
storeRoot: string,
|
|
296
285
|
categoryPath: string,
|
|
297
286
|
memories: { path: string; tokenEstimate: number; summary?: string }[] = [],
|
|
298
|
-
subcategories: { path: string; memoryCount?: number }[] = []
|
|
287
|
+
subcategories: { path: string; memoryCount?: number }[] = []
|
|
299
288
|
): Promise<void> => {
|
|
300
289
|
const lines: string[] = [];
|
|
301
290
|
|
|
302
291
|
// Memory section
|
|
303
292
|
if (memories.length === 0) {
|
|
304
293
|
lines.push('memories: []');
|
|
305
|
-
}
|
|
306
|
-
else {
|
|
294
|
+
} else {
|
|
307
295
|
lines.push('memories:');
|
|
308
296
|
for (const memory of memories) {
|
|
309
297
|
lines.push(' -');
|
|
@@ -320,8 +308,7 @@ const createCategoryIndex = async (
|
|
|
320
308
|
// Subcategories section
|
|
321
309
|
if (subcategories.length === 0) {
|
|
322
310
|
lines.push('subcategories: []');
|
|
323
|
-
}
|
|
324
|
-
else {
|
|
311
|
+
} else {
|
|
325
312
|
lines.push('subcategories:');
|
|
326
313
|
for (const sub of subcategories) {
|
|
327
314
|
lines.push(' -');
|
|
@@ -343,8 +330,7 @@ const memoryExists = async (storeRoot: string, slugPath: string): Promise<boolea
|
|
|
343
330
|
try {
|
|
344
331
|
await fs.access(join(storeRoot, `${slugPath}.md`));
|
|
345
332
|
return true;
|
|
346
|
-
}
|
|
347
|
-
catch {
|
|
333
|
+
} catch {
|
|
348
334
|
return false;
|
|
349
335
|
}
|
|
350
336
|
};
|
|
@@ -355,8 +341,7 @@ const memoryExists = async (storeRoot: string, slugPath: string): Promise<boolea
|
|
|
355
341
|
const readMemoryFile = async (storeRoot: string, slugPath: string): Promise<string | null> => {
|
|
356
342
|
try {
|
|
357
343
|
return await fs.readFile(join(storeRoot, `${slugPath}.md`), 'utf8');
|
|
358
|
-
}
|
|
359
|
-
catch {
|
|
344
|
+
} catch {
|
|
360
345
|
return null;
|
|
361
346
|
}
|
|
362
347
|
};
|
|
@@ -380,25 +365,13 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
380
365
|
it('should add a new memory with inline content', async () => {
|
|
381
366
|
await createCategory('project', storeDir);
|
|
382
367
|
const result = await runCortexCli(
|
|
383
|
-
[
|
|
384
|
-
|
|
385
|
-
'add',
|
|
386
|
-
'project/test-memory',
|
|
387
|
-
'--content',
|
|
388
|
-
'This is test content.',
|
|
389
|
-
],
|
|
390
|
-
{ cwd: testProject },
|
|
368
|
+
['memory', 'add', 'project/test-memory', '--content', 'This is test content.'],
|
|
369
|
+
{ cwd: testProject }
|
|
391
370
|
);
|
|
392
371
|
|
|
393
372
|
expectCliOk(
|
|
394
|
-
[
|
|
395
|
-
|
|
396
|
-
'add',
|
|
397
|
-
'project/test-memory',
|
|
398
|
-
'--content',
|
|
399
|
-
'This is test content.',
|
|
400
|
-
],
|
|
401
|
-
result,
|
|
373
|
+
['memory', 'add', 'project/test-memory', '--content', 'This is test content.'],
|
|
374
|
+
result
|
|
402
375
|
);
|
|
403
376
|
expect(result.exitCode).toBe(0);
|
|
404
377
|
expect(result.stdout).toContain('Added memory');
|
|
@@ -423,7 +396,7 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
423
396
|
'--tags',
|
|
424
397
|
'tag1,tag2,tag3',
|
|
425
398
|
],
|
|
426
|
-
{ cwd: testProject }
|
|
399
|
+
{ cwd: testProject }
|
|
427
400
|
);
|
|
428
401
|
|
|
429
402
|
expect(result.exitCode).toBe(0);
|
|
@@ -451,7 +424,7 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
451
424
|
'-t',
|
|
452
425
|
'third',
|
|
453
426
|
],
|
|
454
|
-
{ cwd: testProject }
|
|
427
|
+
{ cwd: testProject }
|
|
455
428
|
);
|
|
456
429
|
|
|
457
430
|
expect(result.exitCode).toBe(0);
|
|
@@ -477,7 +450,7 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
477
450
|
'-t',
|
|
478
451
|
'gamma',
|
|
479
452
|
],
|
|
480
|
-
{ cwd: testProject }
|
|
453
|
+
{ cwd: testProject }
|
|
481
454
|
);
|
|
482
455
|
|
|
483
456
|
expect(result.exitCode).toBe(0);
|
|
@@ -502,7 +475,7 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
502
475
|
'--expires-at',
|
|
503
476
|
expiryDate,
|
|
504
477
|
],
|
|
505
|
-
{ cwd: testProject }
|
|
478
|
+
{ cwd: testProject }
|
|
506
479
|
);
|
|
507
480
|
|
|
508
481
|
expect(result.exitCode).toBe(0);
|
|
@@ -513,12 +486,7 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
513
486
|
});
|
|
514
487
|
|
|
515
488
|
it('should fail when memory path is missing', async () => {
|
|
516
|
-
const result = await runCortexCli([
|
|
517
|
-
'memory',
|
|
518
|
-
'add',
|
|
519
|
-
'--content',
|
|
520
|
-
'No path provided.',
|
|
521
|
-
], {
|
|
489
|
+
const result = await runCortexCli(['memory', 'add', '--content', 'No path provided.'], {
|
|
522
490
|
cwd: testProject,
|
|
523
491
|
});
|
|
524
492
|
|
|
@@ -529,14 +497,8 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
529
497
|
|
|
530
498
|
it('should fail for invalid memory path format', async () => {
|
|
531
499
|
const result = await runCortexCli(
|
|
532
|
-
[
|
|
533
|
-
|
|
534
|
-
'add',
|
|
535
|
-
'invalid-single-segment',
|
|
536
|
-
'--content',
|
|
537
|
-
'Bad path.',
|
|
538
|
-
],
|
|
539
|
-
{ cwd: testProject },
|
|
500
|
+
['memory', 'add', 'invalid-single-segment', '--content', 'Bad path.'],
|
|
501
|
+
{ cwd: testProject }
|
|
540
502
|
);
|
|
541
503
|
|
|
542
504
|
expect(result.exitCode).toBe(1);
|
|
@@ -544,16 +506,10 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
544
506
|
|
|
545
507
|
it('should fail for unknown flags', async () => {
|
|
546
508
|
const result = await runCortexCli(
|
|
547
|
-
[
|
|
548
|
-
'memory',
|
|
549
|
-
'add',
|
|
550
|
-
'project/memory',
|
|
551
|
-
'--unknown-flag',
|
|
552
|
-
'value',
|
|
553
|
-
],
|
|
509
|
+
['memory', 'add', 'project/memory', '--unknown-flag', 'value'],
|
|
554
510
|
{
|
|
555
511
|
cwd: testProject,
|
|
556
|
-
}
|
|
512
|
+
}
|
|
557
513
|
);
|
|
558
514
|
|
|
559
515
|
expect(result.exitCode).toBe(1);
|
|
@@ -568,16 +524,10 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
568
524
|
await fs.writeFile(contentFile, 'Content from file.', 'utf8');
|
|
569
525
|
|
|
570
526
|
const result = await runCortexCli(
|
|
571
|
-
[
|
|
572
|
-
'memory',
|
|
573
|
-
'add',
|
|
574
|
-
'project/file-memory',
|
|
575
|
-
'--file',
|
|
576
|
-
contentFile,
|
|
577
|
-
],
|
|
527
|
+
['memory', 'add', 'project/file-memory', '--file', contentFile],
|
|
578
528
|
{
|
|
579
529
|
cwd: testProject,
|
|
580
|
-
}
|
|
530
|
+
}
|
|
581
531
|
);
|
|
582
532
|
|
|
583
533
|
expect(result.exitCode).toBe(0);
|
|
@@ -596,7 +546,7 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
596
546
|
'--content',
|
|
597
547
|
'Deeply nested content.',
|
|
598
548
|
],
|
|
599
|
-
{ cwd: testProject }
|
|
549
|
+
{ cwd: testProject }
|
|
600
550
|
);
|
|
601
551
|
|
|
602
552
|
expect(result.exitCode).toBe(0);
|
|
@@ -609,14 +559,8 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
609
559
|
await createCategory('project', storeDir);
|
|
610
560
|
const specialContent = 'Special chars: $HOME, `backticks`, "quotes", \'single\'';
|
|
611
561
|
const result = await runCortexCli(
|
|
612
|
-
[
|
|
613
|
-
|
|
614
|
-
'add',
|
|
615
|
-
'project/special-memory',
|
|
616
|
-
'--content',
|
|
617
|
-
specialContent,
|
|
618
|
-
],
|
|
619
|
-
{ cwd: testProject },
|
|
562
|
+
['memory', 'add', 'project/special-memory', '--content', specialContent],
|
|
563
|
+
{ cwd: testProject }
|
|
620
564
|
);
|
|
621
565
|
|
|
622
566
|
expect(result.exitCode).toBe(0);
|
|
@@ -642,9 +586,7 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
642
586
|
});
|
|
643
587
|
|
|
644
588
|
it('should list all memories across categories', async () => {
|
|
645
|
-
const result = await runCortexCli([
|
|
646
|
-
'memory', 'list',
|
|
647
|
-
], { cwd: testProject });
|
|
589
|
+
const result = await runCortexCli(['memory', 'list'], { cwd: testProject });
|
|
648
590
|
|
|
649
591
|
expect(result.exitCode).toBe(0);
|
|
650
592
|
expect(result.stdout).toContain('project/memory-one');
|
|
@@ -653,11 +595,7 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
653
595
|
});
|
|
654
596
|
|
|
655
597
|
it('should list memories in a specific category', async () => {
|
|
656
|
-
const result = await runCortexCli([
|
|
657
|
-
'memory',
|
|
658
|
-
'list',
|
|
659
|
-
'project',
|
|
660
|
-
], {
|
|
598
|
+
const result = await runCortexCli(['memory', 'list', 'project'], {
|
|
661
599
|
cwd: testProject,
|
|
662
600
|
});
|
|
663
601
|
|
|
@@ -668,12 +606,7 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
668
606
|
});
|
|
669
607
|
|
|
670
608
|
it('should output in JSON format', async () => {
|
|
671
|
-
const result = await runCortexCli([
|
|
672
|
-
'memory',
|
|
673
|
-
'list',
|
|
674
|
-
'--format',
|
|
675
|
-
'json',
|
|
676
|
-
], {
|
|
609
|
+
const result = await runCortexCli(['memory', 'list', '--format', 'json'], {
|
|
677
610
|
cwd: testProject,
|
|
678
611
|
});
|
|
679
612
|
|
|
@@ -691,11 +624,7 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
691
624
|
expiresAt: new Date('2020-01-01T00:00:00.000Z'),
|
|
692
625
|
});
|
|
693
626
|
|
|
694
|
-
const result = await runCortexCli([
|
|
695
|
-
'memory',
|
|
696
|
-
'list',
|
|
697
|
-
'project',
|
|
698
|
-
], {
|
|
627
|
+
const result = await runCortexCli(['memory', 'list', 'project'], {
|
|
699
628
|
cwd: testProject,
|
|
700
629
|
});
|
|
701
630
|
|
|
@@ -711,12 +640,7 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
711
640
|
expiresAt: new Date('2020-01-01T00:00:00.000Z'),
|
|
712
641
|
});
|
|
713
642
|
|
|
714
|
-
const result = await runCortexCli([
|
|
715
|
-
'memory',
|
|
716
|
-
'list',
|
|
717
|
-
'project',
|
|
718
|
-
'--include-expired',
|
|
719
|
-
], {
|
|
643
|
+
const result = await runCortexCli(['memory', 'list', 'project', '--include-expired'], {
|
|
720
644
|
cwd: testProject,
|
|
721
645
|
});
|
|
722
646
|
|
|
@@ -726,11 +650,7 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
726
650
|
});
|
|
727
651
|
|
|
728
652
|
it('should return empty list for non-existent category', async () => {
|
|
729
|
-
const result = await runCortexCli([
|
|
730
|
-
'memory',
|
|
731
|
-
'list',
|
|
732
|
-
'nonexistent',
|
|
733
|
-
], {
|
|
653
|
+
const result = await runCortexCli(['memory', 'list', 'nonexistent'], {
|
|
734
654
|
cwd: testProject,
|
|
735
655
|
});
|
|
736
656
|
|
|
@@ -741,12 +661,7 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
741
661
|
|
|
742
662
|
it('should use yaml format for invalid format option', async () => {
|
|
743
663
|
// Invalid formats fall back to default YAML formatting
|
|
744
|
-
const result = await runCortexCli([
|
|
745
|
-
'memory',
|
|
746
|
-
'list',
|
|
747
|
-
'--format',
|
|
748
|
-
'invalid',
|
|
749
|
-
], {
|
|
664
|
+
const result = await runCortexCli(['memory', 'list', '--format', 'invalid'], {
|
|
750
665
|
cwd: testProject,
|
|
751
666
|
});
|
|
752
667
|
|
|
@@ -766,14 +681,8 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
766
681
|
|
|
767
682
|
it('should update memory content', async () => {
|
|
768
683
|
const result = await runCortexCli(
|
|
769
|
-
[
|
|
770
|
-
|
|
771
|
-
'update',
|
|
772
|
-
'project/updatable',
|
|
773
|
-
'--content',
|
|
774
|
-
'Updated content.',
|
|
775
|
-
],
|
|
776
|
-
{ cwd: testProject },
|
|
684
|
+
['memory', 'update', 'project/updatable', '--content', 'Updated content.'],
|
|
685
|
+
{ cwd: testProject }
|
|
777
686
|
);
|
|
778
687
|
|
|
779
688
|
expect(result.exitCode).toBe(0);
|
|
@@ -786,14 +695,8 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
786
695
|
|
|
787
696
|
it('should update memory tags', async () => {
|
|
788
697
|
const result = await runCortexCli(
|
|
789
|
-
[
|
|
790
|
-
|
|
791
|
-
'update',
|
|
792
|
-
'project/updatable',
|
|
793
|
-
'--tags',
|
|
794
|
-
'new-tag,updated',
|
|
795
|
-
],
|
|
796
|
-
{ cwd: testProject },
|
|
698
|
+
['memory', 'update', 'project/updatable', '--tags', 'new-tag,updated'],
|
|
699
|
+
{ cwd: testProject }
|
|
797
700
|
);
|
|
798
701
|
|
|
799
702
|
expect(result.exitCode).toBe(0);
|
|
@@ -812,7 +715,7 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
812
715
|
'--expires-at',
|
|
813
716
|
'2030-01-01T00:00:00.000Z',
|
|
814
717
|
],
|
|
815
|
-
{ cwd: testProject }
|
|
718
|
+
{ cwd: testProject }
|
|
816
719
|
);
|
|
817
720
|
|
|
818
721
|
expect(result.exitCode).toBe(0);
|
|
@@ -830,15 +733,10 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
830
733
|
});
|
|
831
734
|
|
|
832
735
|
const result = await runCortexCli(
|
|
833
|
-
[
|
|
834
|
-
'memory',
|
|
835
|
-
'update',
|
|
836
|
-
'project/with-expiry',
|
|
837
|
-
'--no-expires-at',
|
|
838
|
-
],
|
|
736
|
+
['memory', 'update', 'project/with-expiry', '--no-expires-at'],
|
|
839
737
|
{
|
|
840
738
|
cwd: testProject,
|
|
841
|
-
}
|
|
739
|
+
}
|
|
842
740
|
);
|
|
843
741
|
|
|
844
742
|
expect(result.exitCode).toBe(0);
|
|
@@ -849,14 +747,8 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
849
747
|
|
|
850
748
|
it('should fail when memory does not exist', async () => {
|
|
851
749
|
const result = await runCortexCli(
|
|
852
|
-
[
|
|
853
|
-
|
|
854
|
-
'update',
|
|
855
|
-
'project/nonexistent',
|
|
856
|
-
'--content',
|
|
857
|
-
'New content.',
|
|
858
|
-
],
|
|
859
|
-
{ cwd: testProject },
|
|
750
|
+
['memory', 'update', 'project/nonexistent', '--content', 'New content.'],
|
|
751
|
+
{ cwd: testProject }
|
|
860
752
|
);
|
|
861
753
|
|
|
862
754
|
expect(result.exitCode).toBe(1);
|
|
@@ -864,11 +756,7 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
864
756
|
});
|
|
865
757
|
|
|
866
758
|
it('should fail when no updates provided', async () => {
|
|
867
|
-
const result = await runCortexCli([
|
|
868
|
-
'memory',
|
|
869
|
-
'update',
|
|
870
|
-
'project/updatable',
|
|
871
|
-
], {
|
|
759
|
+
const result = await runCortexCli(['memory', 'update', 'project/updatable'], {
|
|
872
760
|
cwd: testProject,
|
|
873
761
|
});
|
|
874
762
|
|
|
@@ -881,16 +769,10 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
881
769
|
await fs.writeFile(contentFile, 'Content from file update.', 'utf8');
|
|
882
770
|
|
|
883
771
|
const result = await runCortexCli(
|
|
884
|
-
[
|
|
885
|
-
'memory',
|
|
886
|
-
'update',
|
|
887
|
-
'project/updatable',
|
|
888
|
-
'--file',
|
|
889
|
-
contentFile,
|
|
890
|
-
],
|
|
772
|
+
['memory', 'update', 'project/updatable', '--file', contentFile],
|
|
891
773
|
{
|
|
892
774
|
cwd: testProject,
|
|
893
|
-
}
|
|
775
|
+
}
|
|
894
776
|
);
|
|
895
777
|
|
|
896
778
|
expect(result.exitCode).toBe(0);
|
|
@@ -901,16 +783,10 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
901
783
|
|
|
902
784
|
it('should preserve original content when only updating tags', async () => {
|
|
903
785
|
const result = await runCortexCli(
|
|
904
|
-
[
|
|
905
|
-
'memory',
|
|
906
|
-
'update',
|
|
907
|
-
'project/updatable',
|
|
908
|
-
'--tags',
|
|
909
|
-
'new-tag',
|
|
910
|
-
],
|
|
786
|
+
['memory', 'update', 'project/updatable', '--tags', 'new-tag'],
|
|
911
787
|
{
|
|
912
788
|
cwd: testProject,
|
|
913
|
-
}
|
|
789
|
+
}
|
|
914
790
|
);
|
|
915
791
|
|
|
916
792
|
expect(result.exitCode).toBe(0);
|
|
@@ -933,7 +809,7 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
933
809
|
'-t',
|
|
934
810
|
'tag-c',
|
|
935
811
|
],
|
|
936
|
-
{ cwd: testProject }
|
|
812
|
+
{ cwd: testProject }
|
|
937
813
|
);
|
|
938
814
|
|
|
939
815
|
expect(result.exitCode).toBe(0);
|
|
@@ -947,16 +823,8 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
947
823
|
|
|
948
824
|
it('should update memory tags with mixed formats (comma-separated and multiple flags)', async () => {
|
|
949
825
|
const result = await runCortexCli(
|
|
950
|
-
[
|
|
951
|
-
|
|
952
|
-
'update',
|
|
953
|
-
'project/updatable',
|
|
954
|
-
'-t',
|
|
955
|
-
'x,y',
|
|
956
|
-
'-t',
|
|
957
|
-
'z',
|
|
958
|
-
],
|
|
959
|
-
{ cwd: testProject },
|
|
826
|
+
['memory', 'update', 'project/updatable', '-t', 'x,y', '-t', 'z'],
|
|
827
|
+
{ cwd: testProject }
|
|
960
828
|
);
|
|
961
829
|
|
|
962
830
|
expect(result.exitCode).toBe(0);
|
|
@@ -987,11 +855,7 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
987
855
|
});
|
|
988
856
|
|
|
989
857
|
it('should report expired memories with --dry-run', async () => {
|
|
990
|
-
const result = await runCortexCli([
|
|
991
|
-
'store',
|
|
992
|
-
'prune',
|
|
993
|
-
'--dry-run',
|
|
994
|
-
], {
|
|
858
|
+
const result = await runCortexCli(['store', 'prune', '--dry-run'], {
|
|
995
859
|
cwd: testProject,
|
|
996
860
|
});
|
|
997
861
|
|
|
@@ -1006,9 +870,7 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
1006
870
|
});
|
|
1007
871
|
|
|
1008
872
|
it('should delete expired memories without --dry-run', async () => {
|
|
1009
|
-
const result = await runCortexCli([
|
|
1010
|
-
'store', 'prune',
|
|
1011
|
-
], {
|
|
873
|
+
const result = await runCortexCli(['store', 'prune'], {
|
|
1012
874
|
cwd: testProject,
|
|
1013
875
|
});
|
|
1014
876
|
|
|
@@ -1029,11 +891,11 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
1029
891
|
await fs.rm(join(storeDir, 'project', 'expired-one.md'));
|
|
1030
892
|
await fs.rm(join(storeDir, 'project', 'expired-two.md'));
|
|
1031
893
|
|
|
1032
|
-
await createCategoryIndex(storeDir, 'project', [
|
|
894
|
+
await createCategoryIndex(storeDir, 'project', [
|
|
895
|
+
{ path: 'project/fresh-memory', tokenEstimate: 10 },
|
|
896
|
+
]);
|
|
1033
897
|
|
|
1034
|
-
const result = await runCortexCli([
|
|
1035
|
-
'store', 'prune',
|
|
1036
|
-
], {
|
|
898
|
+
const result = await runCortexCli(['store', 'prune'], {
|
|
1037
899
|
cwd: testProject,
|
|
1038
900
|
});
|
|
1039
901
|
|
|
@@ -1054,9 +916,7 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
1054
916
|
});
|
|
1055
917
|
|
|
1056
918
|
it('should rebuild indexes', async () => {
|
|
1057
|
-
const result = await runCortexCli([
|
|
1058
|
-
'store', 'reindex',
|
|
1059
|
-
], {
|
|
919
|
+
const result = await runCortexCli(['store', 'reindex'], {
|
|
1060
920
|
cwd: testProject,
|
|
1061
921
|
});
|
|
1062
922
|
|
|
@@ -1103,17 +963,14 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
1103
963
|
await fs.mkdir(fakeCortex, { recursive: true });
|
|
1104
964
|
// Note: .cortex/memory doesn't exist, so resolution should fail
|
|
1105
965
|
try {
|
|
1106
|
-
const result = await runCortexCli([
|
|
1107
|
-
'memory', 'list',
|
|
1108
|
-
], {
|
|
966
|
+
const result = await runCortexCli(['memory', 'list'], {
|
|
1109
967
|
cwd: emptyDir,
|
|
1110
968
|
});
|
|
1111
969
|
|
|
1112
970
|
// Either fails because no store found, or succeeds with empty list
|
|
1113
971
|
// depending on whether global store exists
|
|
1114
972
|
expect(result.exitCode).toBeGreaterThanOrEqual(0);
|
|
1115
|
-
}
|
|
1116
|
-
finally {
|
|
973
|
+
} finally {
|
|
1117
974
|
await fs.rm(emptyDir, { recursive: true, force: true });
|
|
1118
975
|
}
|
|
1119
976
|
});
|
|
@@ -1141,9 +998,7 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
1141
998
|
});
|
|
1142
999
|
|
|
1143
1000
|
it('should show memory subcommand help', async () => {
|
|
1144
|
-
const result = await runCortexCli([
|
|
1145
|
-
'memory', '--help',
|
|
1146
|
-
], {
|
|
1001
|
+
const result = await runCortexCli(['memory', '--help'], {
|
|
1147
1002
|
cwd: testProject,
|
|
1148
1003
|
});
|
|
1149
1004
|
|
|
@@ -1155,9 +1010,7 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
1155
1010
|
});
|
|
1156
1011
|
|
|
1157
1012
|
it('should show store subcommand help', async () => {
|
|
1158
|
-
const result = await runCortexCli([
|
|
1159
|
-
'store', '--help',
|
|
1160
|
-
], {
|
|
1013
|
+
const result = await runCortexCli(['store', '--help'], {
|
|
1161
1014
|
cwd: testProject,
|
|
1162
1015
|
});
|
|
1163
1016
|
|
|
@@ -1181,28 +1034,14 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
1181
1034
|
|
|
1182
1035
|
try {
|
|
1183
1036
|
const result = await runCortexCli(
|
|
1184
|
-
[
|
|
1185
|
-
'store',
|
|
1186
|
-
'init',
|
|
1187
|
-
storePath,
|
|
1188
|
-
'--name',
|
|
1189
|
-
'my-project',
|
|
1190
|
-
'--format',
|
|
1191
|
-
'json',
|
|
1192
|
-
],
|
|
1037
|
+
['store', 'init', storePath, '--name', 'my-project', '--format', 'json'],
|
|
1193
1038
|
{
|
|
1194
1039
|
cwd: freshDir,
|
|
1195
1040
|
env: { CORTEX_CONFIG_DIR: configDir },
|
|
1196
|
-
}
|
|
1041
|
+
}
|
|
1197
1042
|
);
|
|
1198
1043
|
|
|
1199
|
-
expectCliOk([
|
|
1200
|
-
'store',
|
|
1201
|
-
'init',
|
|
1202
|
-
storePath,
|
|
1203
|
-
'--name',
|
|
1204
|
-
'my-project',
|
|
1205
|
-
], result);
|
|
1044
|
+
expectCliOk(['store', 'init', storePath, '--name', 'my-project'], result);
|
|
1206
1045
|
expect(result.exitCode).toBe(0);
|
|
1207
1046
|
|
|
1208
1047
|
const parsed = JSON.parse(result.stdout) as {
|
|
@@ -1215,8 +1054,7 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
1215
1054
|
const configContent = await fs.readFile(join(configDir, 'config.yaml'), 'utf8');
|
|
1216
1055
|
expect(configContent).toContain('my-project');
|
|
1217
1056
|
expect(configContent).toContain(storePath);
|
|
1218
|
-
}
|
|
1219
|
-
finally {
|
|
1057
|
+
} finally {
|
|
1220
1058
|
await fs.rm(freshDir, { recursive: true, force: true });
|
|
1221
1059
|
}
|
|
1222
1060
|
});
|
|
@@ -1232,34 +1070,19 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
1232
1070
|
|
|
1233
1071
|
try {
|
|
1234
1072
|
const result = await runCortexCli(
|
|
1235
|
-
[
|
|
1236
|
-
'store',
|
|
1237
|
-
'init',
|
|
1238
|
-
storePath,
|
|
1239
|
-
'--name',
|
|
1240
|
-
'new-dir-store',
|
|
1241
|
-
'--format',
|
|
1242
|
-
'json',
|
|
1243
|
-
],
|
|
1073
|
+
['store', 'init', storePath, '--name', 'new-dir-store', '--format', 'json'],
|
|
1244
1074
|
{
|
|
1245
1075
|
cwd: freshDir,
|
|
1246
1076
|
env: { CORTEX_CONFIG_DIR: configDir },
|
|
1247
|
-
}
|
|
1077
|
+
}
|
|
1248
1078
|
);
|
|
1249
1079
|
|
|
1250
|
-
expectCliOk([
|
|
1251
|
-
'store',
|
|
1252
|
-
'init',
|
|
1253
|
-
storePath,
|
|
1254
|
-
'--name',
|
|
1255
|
-
'new-dir-store',
|
|
1256
|
-
], result);
|
|
1080
|
+
expectCliOk(['store', 'init', storePath, '--name', 'new-dir-store'], result);
|
|
1257
1081
|
|
|
1258
1082
|
// The directory must have been created by the init command
|
|
1259
1083
|
const dirStat = await fs.stat(storePath);
|
|
1260
1084
|
expect(dirStat.isDirectory()).toBe(true);
|
|
1261
|
-
}
|
|
1262
|
-
finally {
|
|
1085
|
+
} finally {
|
|
1263
1086
|
await fs.rm(freshDir, { recursive: true, force: true });
|
|
1264
1087
|
}
|
|
1265
1088
|
});
|
|
@@ -1268,24 +1091,10 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
1268
1091
|
// Register a store first using the existing testProject setup
|
|
1269
1092
|
const storePath = join(testProject, '.cortex', 'memory2');
|
|
1270
1093
|
const firstInit = await runCortexCli(
|
|
1271
|
-
[
|
|
1272
|
-
|
|
1273
|
-
'init',
|
|
1274
|
-
storePath,
|
|
1275
|
-
'--name',
|
|
1276
|
-
'existing-store',
|
|
1277
|
-
'--format',
|
|
1278
|
-
'json',
|
|
1279
|
-
],
|
|
1280
|
-
{ cwd: testProject },
|
|
1094
|
+
['store', 'init', storePath, '--name', 'existing-store', '--format', 'json'],
|
|
1095
|
+
{ cwd: testProject }
|
|
1281
1096
|
);
|
|
1282
|
-
expectCliOk([
|
|
1283
|
-
'store',
|
|
1284
|
-
'init',
|
|
1285
|
-
storePath,
|
|
1286
|
-
'--name',
|
|
1287
|
-
'existing-store',
|
|
1288
|
-
], firstInit);
|
|
1097
|
+
expectCliOk(['store', 'init', storePath, '--name', 'existing-store'], firstInit);
|
|
1289
1098
|
|
|
1290
1099
|
// Attempt to init the same name again — should fail
|
|
1291
1100
|
const secondInit = await runCortexCli(
|
|
@@ -1296,7 +1105,7 @@ describe('Cortex CLI Integration Tests', () => {
|
|
|
1296
1105
|
'--name',
|
|
1297
1106
|
'existing-store',
|
|
1298
1107
|
],
|
|
1299
|
-
{ cwd: testProject }
|
|
1108
|
+
{ cwd: testProject }
|
|
1300
1109
|
);
|
|
1301
1110
|
|
|
1302
1111
|
expect(secondInit.exitCode).toBe(1);
|