@voidwire/lore 0.1.6 → 0.1.8

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 (2) hide show
  1. package/lib/prismis.ts +55 -9
  2. package/package.json +1 -1
package/lib/prismis.ts CHANGED
@@ -2,7 +2,9 @@
2
2
  * Prismis API integration
3
3
  *
4
4
  * Queries prismis daemon REST API for semantic search across content.
5
- * Reads host and API key from ~/.config/prismis/config.toml
5
+ * Config priority:
6
+ * 1. ~/.config/lore/config.toml [remote] section
7
+ * 2. ~/.config/prismis/config.toml [api] section (local daemon fallback)
6
8
  */
7
9
 
8
10
  import { readFileSync, existsSync } from "fs";
@@ -18,6 +20,12 @@ export interface PrismisSearchResult {
18
20
  }
19
21
 
20
22
  const DEFAULT_PORT = 8989;
23
+ const LORE_CONFIG_PATH = join(
24
+ process.env.HOME ?? "",
25
+ ".config",
26
+ "lore",
27
+ "config.toml",
28
+ );
21
29
  const PRISMIS_CONFIG_PATH = join(
22
30
  process.env.HOME ?? "",
23
31
  ".config",
@@ -27,10 +35,11 @@ const PRISMIS_CONFIG_PATH = join(
27
35
 
28
36
  export interface PrismisSearchOptions {
29
37
  limit?: number;
38
+ source?: string;
30
39
  }
31
40
 
32
41
  interface PrismisConfig {
33
- host: string;
42
+ url: string;
34
43
  apiKey: string;
35
44
  }
36
45
 
@@ -55,19 +64,41 @@ interface PrismisResponse {
55
64
  }
56
65
 
57
66
  /**
58
- * Read prismis config from config.toml
67
+ * Try to read [remote] section from lore config
59
68
  */
60
- function readPrismisConfig(): PrismisConfig {
69
+ function readLoreRemoteConfig(): PrismisConfig | null {
70
+ if (!existsSync(LORE_CONFIG_PATH)) {
71
+ return null;
72
+ }
73
+
74
+ const content = readFileSync(LORE_CONFIG_PATH, "utf-8");
75
+
76
+ const urlMatch = content.match(/\[remote\][^[]*url\s*=\s*"([^"]+)"/s);
77
+ const keyMatch = content.match(/\[remote\][^[]*key\s*=\s*"([^"]+)"/s);
78
+
79
+ if (urlMatch && keyMatch) {
80
+ return {
81
+ url: urlMatch[1],
82
+ apiKey: keyMatch[1],
83
+ };
84
+ }
85
+
86
+ return null;
87
+ }
88
+
89
+ /**
90
+ * Read prismis config from local prismis config.toml
91
+ */
92
+ function readLocalPrismisConfig(): PrismisConfig {
61
93
  if (!existsSync(PRISMIS_CONFIG_PATH)) {
62
94
  throw new Error(
63
- `Prismis config not found at ${PRISMIS_CONFIG_PATH}. ` +
64
- "Install prismis and run: prismis-cli source add <url>",
95
+ `Prismis config not found. Add [remote] to ~/.config/lore/config.toml ` +
96
+ `or install prismis locally.`,
65
97
  );
66
98
  }
67
99
 
68
100
  const content = readFileSync(PRISMIS_CONFIG_PATH, "utf-8");
69
101
 
70
- // Parse [api] section
71
102
  const keyMatch = content.match(/\[api\][^[]*key\s*=\s*"([^"]+)"/);
72
103
  if (!keyMatch) {
73
104
  throw new Error(
@@ -84,11 +115,22 @@ function readPrismisConfig(): PrismisConfig {
84
115
  }
85
116
 
86
117
  return {
87
- host,
118
+ url: `http://${host}:${DEFAULT_PORT}`,
88
119
  apiKey: keyMatch[1],
89
120
  };
90
121
  }
91
122
 
123
+ /**
124
+ * Read prismis config - tries lore [remote] first, falls back to local prismis
125
+ */
126
+ function readPrismisConfig(): PrismisConfig {
127
+ const remoteConfig = readLoreRemoteConfig();
128
+ if (remoteConfig) {
129
+ return remoteConfig;
130
+ }
131
+ return readLocalPrismisConfig();
132
+ }
133
+
92
134
  /**
93
135
  * Check if prismis daemon is running
94
136
  */
@@ -122,7 +164,7 @@ export async function searchPrismis(
122
164
  ): Promise<PrismisSearchResult[]> {
123
165
  // Read config
124
166
  const config = readPrismisConfig();
125
- const apiBase = `http://${config.host}:${DEFAULT_PORT}`;
167
+ const apiBase = config.url;
126
168
 
127
169
  // Check daemon is running
128
170
  await checkPrismisDaemon(apiBase);
@@ -134,6 +176,10 @@ export async function searchPrismis(
134
176
  compact: "true",
135
177
  });
136
178
 
179
+ if (options.source) {
180
+ params.set("source", options.source);
181
+ }
182
+
137
183
  const response = await fetch(`${apiBase}/api/search?${params}`, {
138
184
  headers: {
139
185
  "X-API-Key": config.apiKey,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voidwire/lore",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Unified knowledge CLI - Search, list, and capture your indexed knowledge",
5
5
  "type": "module",
6
6
  "main": "./index.ts",