@voidwire/lore 0.1.12 → 0.1.13
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/cli.ts +62 -2
- package/index.ts +3 -0
- package/lib/info.ts +2 -1
- package/lib/projects.ts +60 -0
- package/package.json +1 -1
package/cli.ts
CHANGED
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
listDomains,
|
|
29
29
|
info,
|
|
30
30
|
formatInfoHuman,
|
|
31
|
+
projects,
|
|
31
32
|
captureTask,
|
|
32
33
|
captureKnowledge,
|
|
33
34
|
captureNote,
|
|
@@ -377,6 +378,31 @@ function handleInfo(args: string[]): void {
|
|
|
377
378
|
}
|
|
378
379
|
}
|
|
379
380
|
|
|
381
|
+
// ============================================================================
|
|
382
|
+
// Projects Command
|
|
383
|
+
// ============================================================================
|
|
384
|
+
|
|
385
|
+
function handleProjects(args: string[]): void {
|
|
386
|
+
if (hasFlag(args, "help")) {
|
|
387
|
+
showProjectsHelp();
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
try {
|
|
391
|
+
const result = projects();
|
|
392
|
+
|
|
393
|
+
output({
|
|
394
|
+
success: true,
|
|
395
|
+
projects: result,
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
console.error(`✅ ${result.length} projects found`);
|
|
399
|
+
process.exit(0);
|
|
400
|
+
} catch (error) {
|
|
401
|
+
const message = error instanceof Error ? error.message : "Unknown error";
|
|
402
|
+
fail(message, 2);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
380
406
|
// ============================================================================
|
|
381
407
|
// Capture Command
|
|
382
408
|
// ============================================================================
|
|
@@ -700,7 +726,7 @@ Options:
|
|
|
700
726
|
|
|
701
727
|
Output Fields:
|
|
702
728
|
sources Array of {name, count} for each indexed source
|
|
703
|
-
projects Known projects
|
|
729
|
+
projects Known projects across all sources
|
|
704
730
|
last_indexed Most recent timestamp from indexed data
|
|
705
731
|
total_entries Total number of indexed entries
|
|
706
732
|
|
|
@@ -712,6 +738,35 @@ Examples:
|
|
|
712
738
|
process.exit(0);
|
|
713
739
|
}
|
|
714
740
|
|
|
741
|
+
function showProjectsHelp(): void {
|
|
742
|
+
console.log(`
|
|
743
|
+
lore projects - List all known projects
|
|
744
|
+
|
|
745
|
+
Usage:
|
|
746
|
+
lore projects List all unique project names
|
|
747
|
+
|
|
748
|
+
Options:
|
|
749
|
+
--help Show this help
|
|
750
|
+
|
|
751
|
+
Output:
|
|
752
|
+
JSON array of project names, sorted alphabetically.
|
|
753
|
+
Projects are extracted from metadata fields across all sources.
|
|
754
|
+
|
|
755
|
+
Sources checked:
|
|
756
|
+
commits project field
|
|
757
|
+
sessions project field
|
|
758
|
+
tasks project field
|
|
759
|
+
captures context field
|
|
760
|
+
teachings source field
|
|
761
|
+
|
|
762
|
+
Examples:
|
|
763
|
+
lore projects
|
|
764
|
+
lore projects | jq -r '.projects[]'
|
|
765
|
+
lore projects | jq '.projects | length'
|
|
766
|
+
`);
|
|
767
|
+
process.exit(0);
|
|
768
|
+
}
|
|
769
|
+
|
|
715
770
|
function showCaptureHelp(): void {
|
|
716
771
|
console.log(`
|
|
717
772
|
lore capture - Capture knowledge
|
|
@@ -790,11 +845,16 @@ function main(): void {
|
|
|
790
845
|
case "info":
|
|
791
846
|
handleInfo(commandArgs);
|
|
792
847
|
break;
|
|
848
|
+
case "projects":
|
|
849
|
+
handleProjects(commandArgs);
|
|
850
|
+
break;
|
|
793
851
|
case "capture":
|
|
794
852
|
handleCapture(commandArgs);
|
|
795
853
|
break;
|
|
796
854
|
default:
|
|
797
|
-
fail(
|
|
855
|
+
fail(
|
|
856
|
+
`Unknown command: ${command}. Use: search, list, info, projects, or capture`,
|
|
857
|
+
);
|
|
798
858
|
}
|
|
799
859
|
}
|
|
800
860
|
|
package/index.ts
CHANGED
package/lib/info.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import { Database } from "bun:sqlite";
|
|
9
9
|
import { homedir } from "os";
|
|
10
10
|
import { existsSync } from "fs";
|
|
11
|
+
import { projects as getProjects } from "./projects.js";
|
|
11
12
|
|
|
12
13
|
export interface SourceInfo {
|
|
13
14
|
name: string;
|
|
@@ -72,7 +73,7 @@ export function info(): InfoOutput {
|
|
|
72
73
|
|
|
73
74
|
return {
|
|
74
75
|
sources,
|
|
75
|
-
projects:
|
|
76
|
+
projects: getProjects(),
|
|
76
77
|
last_indexed,
|
|
77
78
|
total_entries,
|
|
78
79
|
};
|
package/lib/projects.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* lib/projects.ts - List all known projects across sources
|
|
3
|
+
*
|
|
4
|
+
* Queries distinct project values from metadata fields, handling
|
|
5
|
+
* different field names per source type.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { Database } from "bun:sqlite";
|
|
9
|
+
import { homedir } from "os";
|
|
10
|
+
import { existsSync } from "fs";
|
|
11
|
+
|
|
12
|
+
const PROJECT_FIELD: Record<string, string> = {
|
|
13
|
+
commits: "project",
|
|
14
|
+
sessions: "project",
|
|
15
|
+
tasks: "project",
|
|
16
|
+
captures: "context",
|
|
17
|
+
teachings: "source",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
function getDatabasePath(): string {
|
|
21
|
+
return `${homedir()}/.local/share/lore/lore.db`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Get all unique project names across sources
|
|
26
|
+
*
|
|
27
|
+
* @returns Sorted array of unique project names
|
|
28
|
+
*/
|
|
29
|
+
export function projects(): string[] {
|
|
30
|
+
const dbPath = getDatabasePath();
|
|
31
|
+
|
|
32
|
+
if (!existsSync(dbPath)) {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const db = new Database(dbPath, { readonly: true });
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
const allProjects = new Set<string>();
|
|
40
|
+
|
|
41
|
+
for (const [source, field] of Object.entries(PROJECT_FIELD)) {
|
|
42
|
+
const stmt = db.prepare(`
|
|
43
|
+
SELECT DISTINCT json_extract(metadata, '$.${field}') as proj
|
|
44
|
+
FROM search
|
|
45
|
+
WHERE source = ? AND json_extract(metadata, '$.${field}') IS NOT NULL
|
|
46
|
+
`);
|
|
47
|
+
const results = stmt.all(source) as { proj: string | null }[];
|
|
48
|
+
|
|
49
|
+
for (const r of results) {
|
|
50
|
+
if (r.proj) {
|
|
51
|
+
allProjects.add(r.proj);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return Array.from(allProjects).sort();
|
|
57
|
+
} finally {
|
|
58
|
+
db.close();
|
|
59
|
+
}
|
|
60
|
+
}
|