@a13xu/lucid 1.1.0 → 1.9.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.
- package/LICENSE +21 -21
- package/README.md +221 -99
- package/build/config.d.ts +37 -0
- package/build/config.js +45 -0
- package/build/database.d.ts +54 -0
- package/build/database.js +175 -62
- package/build/guardian/checklist.js +66 -66
- package/build/guardian/coding-analyzer.d.ts +11 -0
- package/build/guardian/coding-analyzer.js +393 -0
- package/build/guardian/coding-rules.d.ts +1 -0
- package/build/guardian/coding-rules.js +97 -0
- package/build/index.js +241 -2
- package/build/indexer/ast.d.ts +9 -0
- package/build/indexer/ast.js +158 -0
- package/build/indexer/file.d.ts +15 -0
- package/build/indexer/file.js +100 -0
- package/build/indexer/project.d.ts +8 -0
- package/build/indexer/project.js +320 -0
- package/build/memory/experience.d.ts +11 -0
- package/build/memory/experience.js +85 -0
- package/build/retrieval/context.d.ts +29 -0
- package/build/retrieval/context.js +219 -0
- package/build/retrieval/qdrant.d.ts +16 -0
- package/build/retrieval/qdrant.js +135 -0
- package/build/retrieval/tfidf.d.ts +14 -0
- package/build/retrieval/tfidf.js +64 -0
- package/build/security/alerts.d.ts +44 -0
- package/build/security/alerts.js +228 -0
- package/build/security/env.d.ts +24 -0
- package/build/security/env.js +85 -0
- package/build/security/guard.d.ts +35 -0
- package/build/security/guard.js +133 -0
- package/build/security/ratelimit.d.ts +34 -0
- package/build/security/ratelimit.js +105 -0
- package/build/security/smtp.d.ts +26 -0
- package/build/security/smtp.js +125 -0
- package/build/security/ssrf.d.ts +18 -0
- package/build/security/ssrf.js +109 -0
- package/build/security/waf.d.ts +33 -0
- package/build/security/waf.js +174 -0
- package/build/store/content.d.ts +3 -0
- package/build/store/content.js +11 -0
- package/build/tools/coding-guard.d.ts +24 -0
- package/build/tools/coding-guard.js +82 -0
- package/build/tools/context.d.ts +39 -0
- package/build/tools/context.js +105 -0
- package/build/tools/grep.d.ts +17 -0
- package/build/tools/grep.js +65 -0
- package/build/tools/init.d.ts +51 -0
- package/build/tools/init.js +212 -0
- package/build/tools/remember.d.ts +4 -4
- package/build/tools/reward.d.ts +29 -0
- package/build/tools/reward.js +154 -0
- package/build/tools/sync.d.ts +18 -0
- package/build/tools/sync.js +76 -0
- package/package.json +55 -48
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 a13xu
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 a13xu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,99 +1,221 @@
|
|
|
1
|
-
# @a13xu/lucid
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Stores a knowledge graph (entities, relations, observations)
|
|
6
|
-
|
|
7
|
-
## Install
|
|
8
|
-
|
|
9
|
-
**Requirements:** Node.js 18+
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
#
|
|
13
|
-
npx @a13xu/lucid
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
|
50
|
-
|
|
51
|
-
|
|
|
52
|
-
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
|
60
|
-
|
|
61
|
-
| `
|
|
62
|
-
| `
|
|
63
|
-
| `
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
`
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
1
|
+
# @a13xu/lucid
|
|
2
|
+
|
|
3
|
+
Token-efficient memory, code indexing, and validation for Claude Code agents — backed by **SQLite + FTS5**.
|
|
4
|
+
|
|
5
|
+
Stores a persistent knowledge graph (entities, relations, observations), indexes source files as compressed binary with change detection, retrieves minimal relevant context via TF-IDF or Qdrant, and validates code for LLM drift patterns.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
**Requirements:** Node.js 18+
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# Add to Claude Code (no install needed)
|
|
13
|
+
claude mcp add --transport stdio lucid -- npx -y @a13xu/lucid
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Or add to `.mcp.json` in your project root:
|
|
17
|
+
|
|
18
|
+
```json
|
|
19
|
+
{
|
|
20
|
+
"mcpServers": {
|
|
21
|
+
"lucid": {
|
|
22
|
+
"type": "stdio",
|
|
23
|
+
"command": "npx",
|
|
24
|
+
"args": ["-y", "@a13xu/lucid"],
|
|
25
|
+
"env": {
|
|
26
|
+
"MEMORY_DB_PATH": "/your/project/.claude/memory.db"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Default DB path: `~/.claude/memory.db`
|
|
34
|
+
|
|
35
|
+
## Quick start
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
1. "Index this project" → init_project() → scans CLAUDE.md, package.json, src/**
|
|
39
|
+
2. Write code → sync_file(path) → compressed + hashed + diff stored
|
|
40
|
+
3. "What's relevant?" → get_context("auth flow") → TF-IDF ranked skeletons, ~500 tokens
|
|
41
|
+
4. "What changed?" → get_recent(hours=2) → line diffs of recent edits
|
|
42
|
+
5. "Where is X used?" → grep_code("X") → matching lines only, ~30 tokens
|
|
43
|
+
6. "What do we know?" → recall("query") → knowledge graph search
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Tools (15)
|
|
47
|
+
|
|
48
|
+
### Memory
|
|
49
|
+
| Tool | Description |
|
|
50
|
+
|---|---|
|
|
51
|
+
| `remember` | Store a fact about an entity (project, person, tool, decision…) |
|
|
52
|
+
| `relate` | Create a directed relationship between two entities |
|
|
53
|
+
| `recall` | Full-text search across all memory (FTS5 + LIKE fallback) |
|
|
54
|
+
| `recall_all` | Return the entire knowledge graph with statistics |
|
|
55
|
+
| `forget` | Remove an entity and all its relations |
|
|
56
|
+
| `memory_stats` | DB size, WAL status, entity/relation counts |
|
|
57
|
+
|
|
58
|
+
### Code indexing
|
|
59
|
+
| Tool | Description |
|
|
60
|
+
|---|---|
|
|
61
|
+
| `init_project` | Scan project directory recursively and bootstrap knowledge graph. Reads `CLAUDE.md`, `package.json`/`pyproject.toml`, `README.md`, `.mcp.json`, `logic-guardian.yaml`, all source files. Installs a Claude Code hook for auto-sync. |
|
|
62
|
+
| `sync_file` | Index or re-index a single file after writing/editing. Stores compressed binary (zlib-9), skips instantly if SHA-256 hash unchanged. Stores line-level diff from previous version. |
|
|
63
|
+
| `sync_project` | Re-index entire project incrementally. Reports compression ratio. |
|
|
64
|
+
| `grep_code` | Regex search across all indexed files. Decompresses binary on-the-fly, returns only matching lines with context — ~20-50 tokens vs reading full files. |
|
|
65
|
+
|
|
66
|
+
### Token optimization
|
|
67
|
+
| Tool | Description |
|
|
68
|
+
|---|---|
|
|
69
|
+
| `get_context` | **Smart context retrieval.** Ranks all indexed files by TF-IDF relevance (or Qdrant vector search if `QDRANT_URL` is set), applies recency boost, returns skeletons (imports + signatures only) for large files. Respects `maxContextTokens` budget. |
|
|
70
|
+
| `get_recent` | Return files modified in the last N hours with line-level diffs. |
|
|
71
|
+
|
|
72
|
+
### Logic Guardian
|
|
73
|
+
| Tool | Description |
|
|
74
|
+
|---|---|
|
|
75
|
+
| `validate_file` | Detect LLM drift patterns in a source file: logic inversions, null propagation, type confusion, copy-paste drift, silent exceptions. Supports Python, JS, TS. |
|
|
76
|
+
| `check_drift` | Analyze a code snippet inline without saving to disk. |
|
|
77
|
+
| `get_checklist` | Return the full 5-pass validation protocol (Logic Trace, Contract Verification, Stupid Mistakes, Integration Sanity, Explain It). |
|
|
78
|
+
|
|
79
|
+
## Token optimization in depth
|
|
80
|
+
|
|
81
|
+
### How `get_context` works
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
query: "auth middleware"
|
|
85
|
+
↓
|
|
86
|
+
1. TF-IDF score all indexed files against query
|
|
87
|
+
(or Qdrant top-k if QDRANT_URL is set)
|
|
88
|
+
↓
|
|
89
|
+
2. Boost recently-modified files (+0.3 score)
|
|
90
|
+
↓
|
|
91
|
+
3. Apply whitelist dirs filter (if configured)
|
|
92
|
+
↓
|
|
93
|
+
4. For each file within token budget:
|
|
94
|
+
file < maxTokensPerFile → return full source
|
|
95
|
+
file > maxTokensPerFile → return skeleton only
|
|
96
|
+
(imports + signatures + TODOs)
|
|
97
|
+
+ relevant fragments around query terms
|
|
98
|
+
↓
|
|
99
|
+
output: ~500–2000 tokens vs 5000–20000 for reading full files
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Skeleton pruning (AST-based)
|
|
103
|
+
|
|
104
|
+
Large files are replaced with their structural skeleton:
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
// src/middleware/auth.ts [skeleton]
|
|
108
|
+
// Validates JWT tokens and attaches user to request context
|
|
109
|
+
|
|
110
|
+
import { Request, Response, NextFunction } from "express"
|
|
111
|
+
import { verifyToken } from "../services/jwt.js"
|
|
112
|
+
|
|
113
|
+
// — exports —
|
|
114
|
+
export function authMiddleware(req: Request, res: Response, next: NextFunction): void { … }
|
|
115
|
+
export function requireRole(role: string): RequestHandler { … }
|
|
116
|
+
export type AuthenticatedRequest = Request & { user: User }
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
vs reading the full 200-line file.
|
|
120
|
+
|
|
121
|
+
### Qdrant vector search (optional)
|
|
122
|
+
|
|
123
|
+
Set env vars to enable semantic search instead of TF-IDF:
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
QDRANT_URL=http://localhost:6333
|
|
127
|
+
QDRANT_API_KEY=your-key # optional
|
|
128
|
+
OPENAI_API_KEY=sk-... # for embeddings
|
|
129
|
+
EMBEDDING_MODEL=text-embedding-3-small # optional
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Or in `.mcp.json`:
|
|
133
|
+
```json
|
|
134
|
+
{
|
|
135
|
+
"mcpServers": {
|
|
136
|
+
"lucid": {
|
|
137
|
+
"command": "npx", "args": ["-y", "@a13xu/lucid"],
|
|
138
|
+
"env": {
|
|
139
|
+
"QDRANT_URL": "http://localhost:6333",
|
|
140
|
+
"OPENAI_API_KEY": "sk-..."
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Falls back to TF-IDF automatically if Qdrant is unreachable.
|
|
148
|
+
|
|
149
|
+
### Configuration (`lucid.config.json`)
|
|
150
|
+
|
|
151
|
+
Create in your project root to customize behavior:
|
|
152
|
+
|
|
153
|
+
```json
|
|
154
|
+
{
|
|
155
|
+
"whitelistDirs": ["src", "backend", "api"],
|
|
156
|
+
"blacklistDirs": ["migrations", "fixtures"],
|
|
157
|
+
"maxTokensPerFile": 400,
|
|
158
|
+
"maxContextTokens": 6000,
|
|
159
|
+
"recentWindowHours": 12
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
| Key | Default | Description |
|
|
164
|
+
|---|---|---|
|
|
165
|
+
| `whitelistDirs` | — | Only index/return files from these dirs |
|
|
166
|
+
| `blacklistDirs` | — | Extra dirs to skip (merged with built-in skips) |
|
|
167
|
+
| `maxTokensPerFile` | `400` | Files above this get skeleton treatment |
|
|
168
|
+
| `maxContextTokens` | `4000` | Total token budget for `get_context` |
|
|
169
|
+
| `recentWindowHours` | `24` | "Recently touched" threshold |
|
|
170
|
+
|
|
171
|
+
## Why no vectors by default?
|
|
172
|
+
|
|
173
|
+
Code has explicit structure — no NLP needed for most queries:
|
|
174
|
+
|
|
175
|
+
| Need | Approach | Tokens |
|
|
176
|
+
|---|---|---|
|
|
177
|
+
| "Where is X defined?" | `grep_code("export.*X")` | ~30 |
|
|
178
|
+
| "What does auth.ts export?" | `recall("auth.ts")` | ~50 |
|
|
179
|
+
| "What changed recently?" | `get_recent(hours=2)` | ~200 |
|
|
180
|
+
| "Context for this task" | `get_context("auth flow")` | ~500 |
|
|
181
|
+
| "Project conventions?" | `recall("CLAUDE.md conventions")` | ~80 |
|
|
182
|
+
| Read full file | `Read tool` | ~500–2000 |
|
|
183
|
+
|
|
184
|
+
TF-IDF is fast, deterministic, and requires zero external services. Qdrant is available when you need semantic similarity across large codebases.
|
|
185
|
+
|
|
186
|
+
## Why SQLite + FTS5?
|
|
187
|
+
|
|
188
|
+
| | JSON file | SQLite + FTS5 |
|
|
189
|
+
|---|---|---|
|
|
190
|
+
| Search | O(n) linear scan | O(log n) indexed |
|
|
191
|
+
| Write | Rewrite entire file | Atomic incremental |
|
|
192
|
+
| Concurrent reads | Lock entire file | WAL mode |
|
|
193
|
+
| Code storage | Plain text | Compressed BLOB + hash |
|
|
194
|
+
| Change detection | Manual diff | SHA-256 per file |
|
|
195
|
+
| Diff history | None | Line-level diffs per file |
|
|
196
|
+
|
|
197
|
+
## Entity types
|
|
198
|
+
`person` · `project` · `decision` · `pattern` · `tool` · `config` · `bug` · `convention`
|
|
199
|
+
|
|
200
|
+
## Relation types
|
|
201
|
+
`uses` · `depends_on` · `created_by` · `part_of` · `replaced_by` · `conflicts_with` · `tested_by`
|
|
202
|
+
|
|
203
|
+
## Debugging
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"capabilities":{},"clientInfo":{"name":"test","version":"1.0"},"protocolVersion":"2024-11-05"}}' \
|
|
207
|
+
| npx @a13xu/lucid
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
In Claude Code: run `/mcp` — you should see `lucid` with 15 tools.
|
|
211
|
+
|
|
212
|
+
## Tech stack
|
|
213
|
+
|
|
214
|
+
- **Runtime:** Node.js 18+, TypeScript, ES modules
|
|
215
|
+
- **MCP SDK:** `@modelcontextprotocol/sdk`
|
|
216
|
+
- **Database:** `better-sqlite3` (synchronous, WAL mode)
|
|
217
|
+
- **Compression:** Node.js built-in `zlib` (deflate level 9)
|
|
218
|
+
- **Hashing:** SHA-256 via `crypto` (change detection)
|
|
219
|
+
- **Ranking:** TF-IDF (built-in) or Qdrant (optional, via REST)
|
|
220
|
+
- **Validation:** `zod`
|
|
221
|
+
- **Transport:** stdio
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { SecurityConfig } from "./security/guard.js";
|
|
2
|
+
export interface LucidConfig {
|
|
3
|
+
/** Only index/return files from these directories (e.g. ["src", "lib", "backend"]) */
|
|
4
|
+
whitelistDirs?: string[];
|
|
5
|
+
/** Additional dirs to skip (merged with built-in SKIP_DIRS) */
|
|
6
|
+
blacklistDirs?: string[];
|
|
7
|
+
/** Max estimated tokens to return per file in get_context (default 400) */
|
|
8
|
+
maxTokensPerFile?: number;
|
|
9
|
+
/** Total token budget for get_context response (default 4000) */
|
|
10
|
+
maxContextTokens?: number;
|
|
11
|
+
/** "Recently touched" = modified within N hours (default 24) */
|
|
12
|
+
recentWindowHours?: number;
|
|
13
|
+
/** Security guard configuration */
|
|
14
|
+
security?: SecurityConfig;
|
|
15
|
+
/** Optional Qdrant vector search (falls back to TF-IDF if not configured) */
|
|
16
|
+
qdrant?: {
|
|
17
|
+
url: string;
|
|
18
|
+
apiKey?: string;
|
|
19
|
+
collection?: string;
|
|
20
|
+
/** Embedding endpoint — must be OpenAI-compatible */
|
|
21
|
+
embeddingUrl?: string;
|
|
22
|
+
embeddingApiKey?: string;
|
|
23
|
+
embeddingModel?: string;
|
|
24
|
+
vectorDim?: number;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export interface Defaults {
|
|
28
|
+
maxTokensPerFile: number;
|
|
29
|
+
maxContextTokens: number;
|
|
30
|
+
recentWindowHours: number;
|
|
31
|
+
}
|
|
32
|
+
export declare const DEFAULTS: Defaults;
|
|
33
|
+
export type ResolvedConfig = Defaults & LucidConfig;
|
|
34
|
+
export declare function loadConfig(projectDir?: string): ResolvedConfig;
|
|
35
|
+
/** Qdrant config from lucid.config.json or env vars */
|
|
36
|
+
export declare function getQdrantConfig(cfg: ResolvedConfig): ResolvedConfig["qdrant"] | null;
|
|
37
|
+
export declare function resetConfigCache(): void;
|
package/build/config.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "fs";
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
export const DEFAULTS = {
|
|
4
|
+
maxTokensPerFile: 400,
|
|
5
|
+
maxContextTokens: 4000,
|
|
6
|
+
recentWindowHours: 24,
|
|
7
|
+
};
|
|
8
|
+
let _cached = null;
|
|
9
|
+
export function loadConfig(projectDir) {
|
|
10
|
+
if (_cached)
|
|
11
|
+
return _cached;
|
|
12
|
+
const dirs = [projectDir, process.cwd()].filter(Boolean);
|
|
13
|
+
for (const dir of dirs) {
|
|
14
|
+
const cfgPath = join(dir, "lucid.config.json");
|
|
15
|
+
if (existsSync(cfgPath)) {
|
|
16
|
+
try {
|
|
17
|
+
const raw = JSON.parse(readFileSync(cfgPath, "utf-8"));
|
|
18
|
+
_cached = { ...DEFAULTS, ...raw };
|
|
19
|
+
return _cached;
|
|
20
|
+
}
|
|
21
|
+
catch { /* malformed — skip */ }
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
_cached = { ...DEFAULTS };
|
|
25
|
+
return _cached;
|
|
26
|
+
}
|
|
27
|
+
/** Qdrant config from lucid.config.json or env vars */
|
|
28
|
+
export function getQdrantConfig(cfg) {
|
|
29
|
+
// Env vars override config file
|
|
30
|
+
const url = process.env["QDRANT_URL"] ?? cfg.qdrant?.url;
|
|
31
|
+
if (!url)
|
|
32
|
+
return null;
|
|
33
|
+
return {
|
|
34
|
+
url,
|
|
35
|
+
apiKey: process.env["QDRANT_API_KEY"] ?? cfg.qdrant?.apiKey,
|
|
36
|
+
collection: process.env["QDRANT_COLLECTION"] ?? cfg.qdrant?.collection ?? "lucid",
|
|
37
|
+
embeddingUrl: process.env["EMBEDDING_URL"] ?? cfg.qdrant?.embeddingUrl ?? "https://api.openai.com/v1/embeddings",
|
|
38
|
+
embeddingApiKey: process.env["EMBEDDING_API_KEY"] ?? process.env["OPENAI_API_KEY"] ?? cfg.qdrant?.embeddingApiKey,
|
|
39
|
+
embeddingModel: process.env["EMBEDDING_MODEL"] ?? cfg.qdrant?.embeddingModel ?? "text-embedding-3-small",
|
|
40
|
+
vectorDim: cfg.qdrant?.vectorDim ?? 1536,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export function resetConfigCache() {
|
|
44
|
+
_cached = null;
|
|
45
|
+
}
|
package/build/database.d.ts
CHANGED
|
@@ -3,7 +3,53 @@ import type { EntityRow, RelationRow } from "./types.js";
|
|
|
3
3
|
export declare function initDatabase(): Database.Database;
|
|
4
4
|
type Stmt<P extends unknown[], R> = Database.Statement<P, R>;
|
|
5
5
|
type WriteStmt<P extends unknown[]> = Database.Statement<P, unknown>;
|
|
6
|
+
export interface FileContentRow {
|
|
7
|
+
id: number;
|
|
8
|
+
filepath: string;
|
|
9
|
+
content: Buffer;
|
|
10
|
+
content_hash: string;
|
|
11
|
+
original_size: number;
|
|
12
|
+
compressed_size: number;
|
|
13
|
+
language: string;
|
|
14
|
+
indexed_at: number;
|
|
15
|
+
}
|
|
16
|
+
export interface FileDiffRow {
|
|
17
|
+
filepath: string;
|
|
18
|
+
prev_hash: string;
|
|
19
|
+
diff_text: string;
|
|
20
|
+
changed_at: number;
|
|
21
|
+
}
|
|
22
|
+
export interface ExperienceRow {
|
|
23
|
+
id: number;
|
|
24
|
+
query: string;
|
|
25
|
+
query_terms: string;
|
|
26
|
+
context_fps: string;
|
|
27
|
+
strategy: string;
|
|
28
|
+
reward: number;
|
|
29
|
+
feedback: string | null;
|
|
30
|
+
created_at: number;
|
|
31
|
+
rewarded_at: number | null;
|
|
32
|
+
}
|
|
33
|
+
export interface FileRewardRow {
|
|
34
|
+
filepath: string;
|
|
35
|
+
total_reward: number;
|
|
36
|
+
use_count: number;
|
|
37
|
+
last_rewarded: number | null;
|
|
38
|
+
}
|
|
6
39
|
export interface Statements {
|
|
40
|
+
getFileByPath: Stmt<[string], FileContentRow>;
|
|
41
|
+
upsertFile: WriteStmt<[string, Buffer, string, number, number, string]>;
|
|
42
|
+
getAllFiles: Stmt<[], Pick<FileContentRow, "filepath" | "content" | "language" | "content_hash" | "indexed_at">>;
|
|
43
|
+
getRecentFiles: Stmt<[number], Pick<FileContentRow, "filepath" | "language" | "indexed_at">>;
|
|
44
|
+
deleteFile: WriteStmt<[string]>;
|
|
45
|
+
fileStorageStats: Stmt<[], {
|
|
46
|
+
count: number;
|
|
47
|
+
total_original: number;
|
|
48
|
+
total_compressed: number;
|
|
49
|
+
}>;
|
|
50
|
+
upsertDiff: WriteStmt<[string, string, string]>;
|
|
51
|
+
getDiff: Stmt<[string], FileDiffRow>;
|
|
52
|
+
getRecentDiffs: Stmt<[number], FileDiffRow>;
|
|
7
53
|
getEntityByName: Stmt<[string], EntityRow>;
|
|
8
54
|
insertEntity: WriteStmt<[string, string, string]>;
|
|
9
55
|
updateEntity: WriteStmt<[string, number]>;
|
|
@@ -29,6 +75,14 @@ export interface Statements {
|
|
|
29
75
|
from_name: string;
|
|
30
76
|
to_name: string;
|
|
31
77
|
}>;
|
|
78
|
+
insertExperience: WriteStmt<[string, string, string, string]>;
|
|
79
|
+
updateExperienceReward: WriteStmt<[number, string | null, number]>;
|
|
80
|
+
getExperienceById: Stmt<[number], ExperienceRow>;
|
|
81
|
+
getTopExperiences: Stmt<[number], ExperienceRow>;
|
|
82
|
+
searchExperiencesFTS: Stmt<[string, number], ExperienceRow>;
|
|
83
|
+
upsertFileReward: WriteStmt<[string, number]>;
|
|
84
|
+
getFileRewards: Stmt<[], FileRewardRow>;
|
|
85
|
+
getTopFileRewards: Stmt<[number], FileRewardRow>;
|
|
32
86
|
}
|
|
33
87
|
export declare function prepareStatements(db: Database.Database): Statements;
|
|
34
88
|
export {};
|