@voidwire/lore 0.1.6 → 0.1.7

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 +50 -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",
@@ -30,7 +38,7 @@ export interface PrismisSearchOptions {
30
38
  }
31
39
 
32
40
  interface PrismisConfig {
33
- host: string;
41
+ url: string;
34
42
  apiKey: string;
35
43
  }
36
44
 
@@ -55,19 +63,41 @@ interface PrismisResponse {
55
63
  }
56
64
 
57
65
  /**
58
- * Read prismis config from config.toml
66
+ * Try to read [remote] section from lore config
59
67
  */
60
- function readPrismisConfig(): PrismisConfig {
68
+ function readLoreRemoteConfig(): PrismisConfig | null {
69
+ if (!existsSync(LORE_CONFIG_PATH)) {
70
+ return null;
71
+ }
72
+
73
+ const content = readFileSync(LORE_CONFIG_PATH, "utf-8");
74
+
75
+ const urlMatch = content.match(/\[remote\][^[]*url\s*=\s*"([^"]+)"/s);
76
+ const keyMatch = content.match(/\[remote\][^[]*key\s*=\s*"([^"]+)"/s);
77
+
78
+ if (urlMatch && keyMatch) {
79
+ return {
80
+ url: urlMatch[1],
81
+ apiKey: keyMatch[1],
82
+ };
83
+ }
84
+
85
+ return null;
86
+ }
87
+
88
+ /**
89
+ * Read prismis config from local prismis config.toml
90
+ */
91
+ function readLocalPrismisConfig(): PrismisConfig {
61
92
  if (!existsSync(PRISMIS_CONFIG_PATH)) {
62
93
  throw new Error(
63
- `Prismis config not found at ${PRISMIS_CONFIG_PATH}. ` +
64
- "Install prismis and run: prismis-cli source add <url>",
94
+ `Prismis config not found. Add [remote] to ~/.config/lore/config.toml ` +
95
+ `or install prismis locally.`,
65
96
  );
66
97
  }
67
98
 
68
99
  const content = readFileSync(PRISMIS_CONFIG_PATH, "utf-8");
69
100
 
70
- // Parse [api] section
71
101
  const keyMatch = content.match(/\[api\][^[]*key\s*=\s*"([^"]+)"/);
72
102
  if (!keyMatch) {
73
103
  throw new Error(
@@ -84,11 +114,22 @@ function readPrismisConfig(): PrismisConfig {
84
114
  }
85
115
 
86
116
  return {
87
- host,
117
+ url: `http://${host}:${DEFAULT_PORT}`,
88
118
  apiKey: keyMatch[1],
89
119
  };
90
120
  }
91
121
 
122
+ /**
123
+ * Read prismis config - tries lore [remote] first, falls back to local prismis
124
+ */
125
+ function readPrismisConfig(): PrismisConfig {
126
+ const remoteConfig = readLoreRemoteConfig();
127
+ if (remoteConfig) {
128
+ return remoteConfig;
129
+ }
130
+ return readLocalPrismisConfig();
131
+ }
132
+
92
133
  /**
93
134
  * Check if prismis daemon is running
94
135
  */
@@ -122,7 +163,7 @@ export async function searchPrismis(
122
163
  ): Promise<PrismisSearchResult[]> {
123
164
  // Read config
124
165
  const config = readPrismisConfig();
125
- const apiBase = `http://${config.host}:${DEFAULT_PORT}`;
166
+ const apiBase = config.url;
126
167
 
127
168
  // Check daemon is running
128
169
  await checkPrismisDaemon(apiBase);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voidwire/lore",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Unified knowledge CLI - Search, list, and capture your indexed knowledge",
5
5
  "type": "module",
6
6
  "main": "./index.ts",