@dahch/muninn 0.0.0-stage → 0.1.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 -0
- package/README.md +152 -2
- package/dist/cli.d.ts +23 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +170 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/check.d.ts +3 -0
- package/dist/commands/check.d.ts.map +1 -0
- package/dist/commands/check.js +56 -0
- package/dist/commands/check.js.map +1 -0
- package/dist/commands/memory.d.ts +6 -0
- package/dist/commands/memory.d.ts.map +1 -0
- package/dist/commands/memory.js +325 -0
- package/dist/commands/memory.js.map +1 -0
- package/dist/contracts/compiler.d.ts +71 -0
- package/dist/contracts/compiler.d.ts.map +1 -0
- package/dist/contracts/compiler.js +362 -0
- package/dist/contracts/compiler.js.map +1 -0
- package/dist/contracts/index.d.ts +2 -0
- package/dist/contracts/index.d.ts.map +1 -0
- package/dist/contracts/index.js +2 -0
- package/dist/contracts/index.js.map +1 -0
- package/dist/db/client.d.ts +84 -0
- package/dist/db/client.d.ts.map +1 -0
- package/dist/db/client.js +264 -0
- package/dist/db/client.js.map +1 -0
- package/dist/db/schema.sql +97 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/indexer/ast-indexer.d.ts +55 -0
- package/dist/indexer/ast-indexer.d.ts.map +1 -0
- package/dist/indexer/ast-indexer.js +445 -0
- package/dist/indexer/ast-indexer.js.map +1 -0
- package/dist/indexer/index.d.ts +2 -0
- package/dist/indexer/index.d.ts.map +1 -0
- package/dist/indexer/index.js +2 -0
- package/dist/indexer/index.js.map +1 -0
- package/dist/mcp/index.d.ts +2 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +2 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/server.d.ts +233 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +495 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/service/index.d.ts +2 -0
- package/dist/service/index.d.ts.map +1 -0
- package/dist/service/index.js +2 -0
- package/dist/service/index.js.map +1 -0
- package/dist/service/memory-service.d.ts +203 -0
- package/dist/service/memory-service.d.ts.map +1 -0
- package/dist/service/memory-service.js +891 -0
- package/dist/service/memory-service.js.map +1 -0
- package/dist/util/path-safety.d.ts +94 -0
- package/dist/util/path-safety.d.ts.map +1 -0
- package/dist/util/path-safety.js +162 -0
- package/dist/util/path-safety.js.map +1 -0
- package/dist/util/text.d.ts +9 -0
- package/dist/util/text.d.ts.map +1 -0
- package/dist/util/text.js +19 -0
- package/dist/util/text.js.map +1 -0
- package/package.json +87 -4
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import ts from "typescript";
|
|
4
|
+
/**
|
|
5
|
+
* Safe default TypeScript compiler options used when tsconfig.json is absent or invalid.
|
|
6
|
+
*/
|
|
7
|
+
export const DEFAULT_COMPILER_OPTIONS = {
|
|
8
|
+
target: ts.ScriptTarget.ES2022,
|
|
9
|
+
module: ts.ModuleKind.NodeNext,
|
|
10
|
+
moduleResolution: ts.ModuleResolutionKind.NodeNext,
|
|
11
|
+
strict: true,
|
|
12
|
+
esModuleInterop: true,
|
|
13
|
+
skipLibCheck: true,
|
|
14
|
+
allowJs: true,
|
|
15
|
+
noEmit: true,
|
|
16
|
+
};
|
|
17
|
+
function mapDiagnosticCategory(category) {
|
|
18
|
+
switch (category) {
|
|
19
|
+
case ts.DiagnosticCategory.Error:
|
|
20
|
+
return "error";
|
|
21
|
+
case ts.DiagnosticCategory.Warning:
|
|
22
|
+
return "warning";
|
|
23
|
+
case ts.DiagnosticCategory.Suggestion:
|
|
24
|
+
return "suggestion";
|
|
25
|
+
case ts.DiagnosticCategory.Message:
|
|
26
|
+
default:
|
|
27
|
+
return "message";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Creates a formatted visual snippet of the line of code containing the error,
|
|
32
|
+
* with a caret pointer underlining the exact error span.
|
|
33
|
+
* Clamps input positions, line lengths, and span lengths to bounded limits (SEC-006, REV-008).
|
|
34
|
+
*/
|
|
35
|
+
export function createVisualSnippet(sourceFile, start, length = 1) {
|
|
36
|
+
const { line, character } = sourceFile.getLineAndCharacterOfPosition(start);
|
|
37
|
+
const lineStarts = sourceFile.getLineStarts();
|
|
38
|
+
const lineStartPos = lineStarts[line];
|
|
39
|
+
const lineEndPos = line < lineStarts.length - 1
|
|
40
|
+
? lineStarts[line + 1]
|
|
41
|
+
: sourceFile.text.length;
|
|
42
|
+
const rawLineText = sourceFile.text
|
|
43
|
+
.substring(lineStartPos, lineEndPos)
|
|
44
|
+
.replace(/\r?\n$/, "");
|
|
45
|
+
// Clamp line text length to max 300 to avoid huge string allocations
|
|
46
|
+
const lineText = rawLineText.length > 300 ? rawLineText.substring(0, 300) : rawLineText;
|
|
47
|
+
const lineNumStr = String(line + 1);
|
|
48
|
+
// Clamp character indentation to max 300
|
|
49
|
+
const safeCharacter = Math.min(Math.max(0, character), 300);
|
|
50
|
+
const indent = " ".repeat(safeCharacter);
|
|
51
|
+
// Clamp span length between 1 and 200, bounded by remaining line text
|
|
52
|
+
const maxSpan = Math.max(1, lineText.length - safeCharacter);
|
|
53
|
+
const spanLength = Math.max(1, Math.min(length || 1, maxSpan, 200));
|
|
54
|
+
const underline = "^".repeat(spanLength);
|
|
55
|
+
return `${lineNumStr} | ${lineText}\n${" ".repeat(lineNumStr.length)} | ${indent}${underline}`;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Formats a raw TypeScript compiler diagnostic into a structured FormattedDiagnostic.
|
|
59
|
+
*/
|
|
60
|
+
export function formatDiagnostic(diagnostic, projectRoot) {
|
|
61
|
+
const category = mapDiagnosticCategory(diagnostic.category);
|
|
62
|
+
const code = `TS${diagnostic.code}`;
|
|
63
|
+
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
|
|
64
|
+
if (!diagnostic.file || diagnostic.start === undefined) {
|
|
65
|
+
return {
|
|
66
|
+
filePath: "tsconfig.json",
|
|
67
|
+
line: 1,
|
|
68
|
+
character: 1,
|
|
69
|
+
code,
|
|
70
|
+
category,
|
|
71
|
+
message,
|
|
72
|
+
snippet: undefined,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
const sourceFile = diagnostic.file;
|
|
76
|
+
const { line, character } = sourceFile.getLineAndCharacterOfPosition(diagnostic.start);
|
|
77
|
+
const relativePath = path.relative(projectRoot, sourceFile.fileName);
|
|
78
|
+
const snippet = createVisualSnippet(sourceFile, diagnostic.start, diagnostic.length ?? 1);
|
|
79
|
+
return {
|
|
80
|
+
filePath: relativePath || sourceFile.fileName,
|
|
81
|
+
line: line + 1,
|
|
82
|
+
character: character + 1,
|
|
83
|
+
code,
|
|
84
|
+
category,
|
|
85
|
+
message,
|
|
86
|
+
snippet,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Loads tsconfig.json strictly from projectRoot without walking up parent directories (REV-005, SEC-007).
|
|
91
|
+
*/
|
|
92
|
+
export function loadProjectConfig(projectRoot) {
|
|
93
|
+
const resolvedRoot = path.resolve(projectRoot);
|
|
94
|
+
const configPath = path.join(resolvedRoot, "tsconfig.json");
|
|
95
|
+
if (!fs.existsSync(configPath)) {
|
|
96
|
+
return {
|
|
97
|
+
configPath: undefined,
|
|
98
|
+
options: { ...DEFAULT_COMPILER_OPTIONS },
|
|
99
|
+
fileNames: [],
|
|
100
|
+
errors: [],
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
const readResult = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
104
|
+
if (readResult.error) {
|
|
105
|
+
return {
|
|
106
|
+
configPath,
|
|
107
|
+
options: { ...DEFAULT_COMPILER_OPTIONS },
|
|
108
|
+
fileNames: [],
|
|
109
|
+
errors: [readResult.error],
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
const parsedConfig = ts.parseJsonConfigFileContent(readResult.config, ts.sys, path.dirname(configPath));
|
|
113
|
+
return {
|
|
114
|
+
configPath,
|
|
115
|
+
options: {
|
|
116
|
+
...DEFAULT_COMPILER_OPTIONS,
|
|
117
|
+
...parsedConfig.options,
|
|
118
|
+
noEmit: true,
|
|
119
|
+
},
|
|
120
|
+
fileNames: parsedConfig.fileNames,
|
|
121
|
+
errors: parsedConfig.errors ?? [],
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
export const TS_JS_EXTENSIONS = new Set([
|
|
125
|
+
".ts",
|
|
126
|
+
".tsx",
|
|
127
|
+
".mts",
|
|
128
|
+
".cts",
|
|
129
|
+
".js",
|
|
130
|
+
".jsx",
|
|
131
|
+
".mjs",
|
|
132
|
+
".cjs",
|
|
133
|
+
]);
|
|
134
|
+
/**
|
|
135
|
+
* Recursively discovers TypeScript/JavaScript source files within a directory.
|
|
136
|
+
*/
|
|
137
|
+
export function findSourceFilesInDir(dir) {
|
|
138
|
+
const results = [];
|
|
139
|
+
try {
|
|
140
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
141
|
+
for (const entry of entries) {
|
|
142
|
+
const fullPath = path.join(dir, entry.name);
|
|
143
|
+
if (entry.isDirectory()) {
|
|
144
|
+
if (entry.name === "node_modules" || entry.name.startsWith(".")) {
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
results.push(...findSourceFilesInDir(fullPath));
|
|
148
|
+
}
|
|
149
|
+
else if (entry.isFile()) {
|
|
150
|
+
const ext = path.extname(entry.name).toLowerCase();
|
|
151
|
+
if (TS_JS_EXTENSIONS.has(ext)) {
|
|
152
|
+
results.push(fullPath);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
// Ignore unreadable paths
|
|
159
|
+
}
|
|
160
|
+
return results;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Validates requested file paths against path traversal and file existence (SEC-001, REV-003).
|
|
164
|
+
*/
|
|
165
|
+
export function resolveTargetFiles(projectRoot, filePaths) {
|
|
166
|
+
if (!filePaths || filePaths.length === 0) {
|
|
167
|
+
return { success: true, targetFiles: undefined };
|
|
168
|
+
}
|
|
169
|
+
const targetFiles = [];
|
|
170
|
+
for (const f of filePaths) {
|
|
171
|
+
const resolved = path.resolve(projectRoot, f);
|
|
172
|
+
const rel = path.relative(projectRoot, resolved);
|
|
173
|
+
// Path traversal containment check (SEC-001)
|
|
174
|
+
if (rel.startsWith("..") || path.isAbsolute(rel)) {
|
|
175
|
+
return {
|
|
176
|
+
success: false,
|
|
177
|
+
failure: {
|
|
178
|
+
valid: false,
|
|
179
|
+
errorsCount: 1,
|
|
180
|
+
diagnostics: [
|
|
181
|
+
{
|
|
182
|
+
filePath: f,
|
|
183
|
+
line: 1,
|
|
184
|
+
character: 1,
|
|
185
|
+
code: "TS6054",
|
|
186
|
+
category: "error",
|
|
187
|
+
message: `File '${f}' is outside project root.`,
|
|
188
|
+
},
|
|
189
|
+
],
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
// Fail-closed non-existent file check (REV-003)
|
|
194
|
+
if (!fs.existsSync(resolved) || !fs.statSync(resolved).isFile()) {
|
|
195
|
+
const relPath = rel || f;
|
|
196
|
+
return {
|
|
197
|
+
success: false,
|
|
198
|
+
failure: {
|
|
199
|
+
valid: false,
|
|
200
|
+
errorsCount: 1,
|
|
201
|
+
diagnostics: [
|
|
202
|
+
{
|
|
203
|
+
filePath: relPath,
|
|
204
|
+
line: 1,
|
|
205
|
+
character: 1,
|
|
206
|
+
code: "TS6053",
|
|
207
|
+
category: "error",
|
|
208
|
+
message: `File '${relPath}' not found.`,
|
|
209
|
+
},
|
|
210
|
+
],
|
|
211
|
+
},
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
targetFiles.push(resolved);
|
|
215
|
+
}
|
|
216
|
+
return { success: true, targetFiles };
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Verifies TypeScript compilation contracts for the given project and files.
|
|
220
|
+
* Returns structured pre-emit diagnostics with line/character locations and visual code snippets.
|
|
221
|
+
*/
|
|
222
|
+
export function verifyTypeScriptContracts(projectRoot, filePaths) {
|
|
223
|
+
const resolvedRoot = path.resolve(projectRoot);
|
|
224
|
+
// 1. Resolve and validate target files for path traversal and missing files (SEC-001, REV-003)
|
|
225
|
+
const targetResolution = resolveTargetFiles(resolvedRoot, filePaths);
|
|
226
|
+
if (!targetResolution.success) {
|
|
227
|
+
return targetResolution.failure;
|
|
228
|
+
}
|
|
229
|
+
const targetFiles = targetResolution.targetFiles;
|
|
230
|
+
const targetFilesSet = targetFiles
|
|
231
|
+
? new Set(targetFiles.map((f) => path.resolve(f)))
|
|
232
|
+
: undefined;
|
|
233
|
+
// 2. Load configuration strictly from project root (REV-005, SEC-007)
|
|
234
|
+
const { configPath, options, fileNames, errors: configErrors } = loadProjectConfig(resolvedRoot);
|
|
235
|
+
// 3. Fail-closed on configuration parse errors (REV-002)
|
|
236
|
+
if (configErrors && configErrors.length > 0) {
|
|
237
|
+
const formattedDiagnostics = configErrors.map((d) => formatDiagnostic(d, resolvedRoot));
|
|
238
|
+
const errorsCount = formattedDiagnostics.filter((d) => d.category === "error").length;
|
|
239
|
+
return {
|
|
240
|
+
valid: errorsCount === 0,
|
|
241
|
+
errorsCount,
|
|
242
|
+
diagnostics: formattedDiagnostics,
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
// 4. Determine rootNames (REV-001, REV-004, SEC-005)
|
|
246
|
+
let rootNames;
|
|
247
|
+
if (targetFiles && targetFiles.length > 0) {
|
|
248
|
+
rootNames = targetFiles;
|
|
249
|
+
}
|
|
250
|
+
else if (fileNames.length > 0) {
|
|
251
|
+
rootNames = fileNames.map((fn) => path.resolve(fn));
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
// If tsconfig not present or has no files, check for sources in src/
|
|
255
|
+
const srcDir = path.join(resolvedRoot, "src");
|
|
256
|
+
if (fs.existsSync(srcDir)) {
|
|
257
|
+
rootNames = findSourceFilesInDir(srcDir);
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
rootNames = [];
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
// If no files to check, return cleanly
|
|
264
|
+
if (rootNames.length === 0) {
|
|
265
|
+
return {
|
|
266
|
+
valid: true,
|
|
267
|
+
errorsCount: 0,
|
|
268
|
+
diagnostics: [],
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
// 5. Create TypeScript program with targeted rootNames (REV-004)
|
|
272
|
+
const program = ts.createProgram({
|
|
273
|
+
rootNames,
|
|
274
|
+
options,
|
|
275
|
+
configFileParsingDiagnostics: configErrors,
|
|
276
|
+
});
|
|
277
|
+
// 6. Targeted diagnostics: iterate over target files instead of full program (REV-004, SEC-005)
|
|
278
|
+
const checkFiles = targetFiles ?? rootNames;
|
|
279
|
+
const rawDiagnostics = [];
|
|
280
|
+
rawDiagnostics.push(...program.getOptionsDiagnostics());
|
|
281
|
+
rawDiagnostics.push(...program.getGlobalDiagnostics());
|
|
282
|
+
for (const tf of checkFiles) {
|
|
283
|
+
const normalized = path.resolve(tf);
|
|
284
|
+
const sourceFile = program.getSourceFile(normalized) ||
|
|
285
|
+
program.getSourceFile(normalized.replace(/\\/g, "/")) ||
|
|
286
|
+
program.getSourceFiles().find((s) => path.resolve(s.fileName) === normalized);
|
|
287
|
+
if (sourceFile) {
|
|
288
|
+
rawDiagnostics.push(...ts.getPreEmitDiagnostics(program, sourceFile));
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
// Deduplicate raw diagnostics
|
|
292
|
+
const seen = new Set();
|
|
293
|
+
const uniqueDiagnostics = [];
|
|
294
|
+
for (const diag of rawDiagnostics) {
|
|
295
|
+
const key = `${diag.file?.fileName}:${diag.start}:${diag.code}:${typeof diag.messageText === "string" ? diag.messageText : diag.messageText.messageText}`;
|
|
296
|
+
if (!seen.has(key)) {
|
|
297
|
+
seen.add(key);
|
|
298
|
+
uniqueDiagnostics.push(diag);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
// 7. Filter diagnostics with trailing separator check (SEC-004)
|
|
302
|
+
const rootWithSep = resolvedRoot.endsWith(path.sep)
|
|
303
|
+
? resolvedRoot
|
|
304
|
+
: resolvedRoot + path.sep;
|
|
305
|
+
const filteredDiagnostics = [];
|
|
306
|
+
for (const diag of uniqueDiagnostics) {
|
|
307
|
+
if (!diag.file) {
|
|
308
|
+
filteredDiagnostics.push(diag);
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
const diagFilePath = path.resolve(diag.file.fileName);
|
|
312
|
+
// Skip node_modules diagnostics
|
|
313
|
+
if (diagFilePath.includes("node_modules")) {
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
if (targetFilesSet) {
|
|
317
|
+
if (targetFilesSet.has(diagFilePath)) {
|
|
318
|
+
filteredDiagnostics.push(diag);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
if (diagFilePath.startsWith(rootWithSep) || diagFilePath === resolvedRoot) {
|
|
323
|
+
filteredDiagnostics.push(diag);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
const formattedDiagnostics = filteredDiagnostics.map((d) => formatDiagnostic(d, resolvedRoot));
|
|
328
|
+
const errorsCount = formattedDiagnostics.filter((d) => d.category === "error").length;
|
|
329
|
+
return {
|
|
330
|
+
valid: errorsCount === 0,
|
|
331
|
+
errorsCount,
|
|
332
|
+
diagnostics: formattedDiagnostics,
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Formats a ContractVerificationResult into a markdown report suitable for
|
|
337
|
+
* gate evaluation and thinker fix prompts.
|
|
338
|
+
*/
|
|
339
|
+
export function formatDiagnosticsReport(result) {
|
|
340
|
+
if (result.valid) {
|
|
341
|
+
return "### TypeScript Compiler Contract: 🟢 PASSED\n\nNo compilation type errors detected.";
|
|
342
|
+
}
|
|
343
|
+
const lines = [
|
|
344
|
+
`### TypeScript Compiler Contract: 🔴 BLOCKED`,
|
|
345
|
+
`Found ${result.errorsCount} type compilation error(s):\n`,
|
|
346
|
+
];
|
|
347
|
+
for (const d of result.diagnostics) {
|
|
348
|
+
lines.push(`- **${d.filePath}:${d.line}:${d.character}** [${d.code}] (${d.category.toUpperCase()}): ${d.message}`);
|
|
349
|
+
if (d.snippet) {
|
|
350
|
+
lines.push("```typescript\n" + d.snippet + "\n```");
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
lines.push("\n### Overall gate: 🔴");
|
|
354
|
+
lines.push(`🛑 BLOCKED: TypeScript compilation contract errors found (${result.errorsCount} error(s)).`);
|
|
355
|
+
return lines.join("\n");
|
|
356
|
+
}
|
|
357
|
+
export const TypeValidator = {
|
|
358
|
+
check: verifyTypeScriptContracts,
|
|
359
|
+
formatReport: formatDiagnosticsReport,
|
|
360
|
+
DEFAULT_COMPILER_OPTIONS,
|
|
361
|
+
};
|
|
362
|
+
//# sourceMappingURL=compiler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiler.js","sourceRoot":"","sources":["../../src/contracts/compiler.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,YAAY,CAAC;AAwB5B;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAuB;IAC1D,MAAM,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM;IAC9B,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ;IAC9B,gBAAgB,EAAE,EAAE,CAAC,oBAAoB,CAAC,QAAQ;IAClD,MAAM,EAAE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C,OAAO,GAAG,OAAO,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;IACrC,KAAK,CAAC,IAAI,CACR,6DAA6D,MAAM,CAAC,WAAW,aAAa,CAC7F,CAAC;IAEF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,KAAK,EAAE,yBAAyB;IAChC,YAAY,EAAE,uBAAuB;IACrC,wBAAwB;CACzB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contracts/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/contracts/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import Database from "better-sqlite3";
|
|
2
|
+
export type ObservationCategory = "decision" | "convention" | "discovery" | "bugfix" | "architecture";
|
|
3
|
+
export interface Project {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
git_remote: string | null;
|
|
7
|
+
root_path: string;
|
|
8
|
+
created_at: string;
|
|
9
|
+
}
|
|
10
|
+
export interface Observation {
|
|
11
|
+
id: string;
|
|
12
|
+
project_id: string;
|
|
13
|
+
category: ObservationCategory;
|
|
14
|
+
title: string;
|
|
15
|
+
content: string;
|
|
16
|
+
topic_key: string | null;
|
|
17
|
+
created_at: string;
|
|
18
|
+
updated_at: string;
|
|
19
|
+
}
|
|
20
|
+
export type EntityType = "file" | "function" | "class" | "interface" | "module";
|
|
21
|
+
export interface Entity {
|
|
22
|
+
id: string;
|
|
23
|
+
project_id: string;
|
|
24
|
+
entity_type: EntityType;
|
|
25
|
+
identifier: string;
|
|
26
|
+
file_path: string;
|
|
27
|
+
}
|
|
28
|
+
export interface ObservationEntity {
|
|
29
|
+
observation_id: string;
|
|
30
|
+
entity_id: string;
|
|
31
|
+
}
|
|
32
|
+
export type DependencyRelationType = "imports" | "calls" | "implements" | "extends" | "references";
|
|
33
|
+
export interface EntityDependency {
|
|
34
|
+
source_entity_id: string;
|
|
35
|
+
target_entity_id: string;
|
|
36
|
+
relation_type: DependencyRelationType;
|
|
37
|
+
}
|
|
38
|
+
export interface EnsureProjectOptions {
|
|
39
|
+
rootPath?: string;
|
|
40
|
+
name?: string;
|
|
41
|
+
gitRemote?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Start directory for the git-root **fallback** when no `rootPath` is given.
|
|
44
|
+
* Callers that also choose the database path pass the same directory, so the
|
|
45
|
+
* database file and the project record can never be resolved from two different
|
|
46
|
+
* roots (ADR-49).
|
|
47
|
+
*/
|
|
48
|
+
startDir?: string;
|
|
49
|
+
}
|
|
50
|
+
export declare const SCHEMA_SQL = "-- Muninn Engine Database Schema\n-- Version 1.0.0\n\n-- Projects table\nCREATE TABLE IF NOT EXISTS projects (\n id TEXT PRIMARY KEY,\n name TEXT NOT NULL,\n git_remote TEXT,\n root_path TEXT NOT NULL UNIQUE,\n created_at DATETIME DEFAULT CURRENT_TIMESTAMP\n);\n\nCREATE INDEX IF NOT EXISTS idx_projects_root_path ON projects(root_path);\n\n-- Observations table\nCREATE TABLE IF NOT EXISTS observations (\n id TEXT PRIMARY KEY,\n project_id TEXT NOT NULL,\n category TEXT CHECK(category IN ('decision', 'convention', 'discovery', 'bugfix', 'architecture')) NOT NULL,\n title TEXT NOT NULL,\n content TEXT NOT NULL,\n topic_key TEXT,\n created_at DATETIME DEFAULT CURRENT_TIMESTAMP,\n updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,\n FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE\n);\n\nCREATE INDEX IF NOT EXISTS idx_observations_project_id ON observations(project_id);\nCREATE INDEX IF NOT EXISTS idx_observations_updated_at ON observations(updated_at);\nCREATE INDEX IF NOT EXISTS idx_observations_project_updated ON observations(project_id, updated_at DESC, created_at DESC);\n\n-- Observations FTS5 virtual table\nCREATE VIRTUAL TABLE IF NOT EXISTS observations_fts USING fts5(\n title,\n content,\n topic_key,\n content='observations',\n content_rowid='rowid'\n);\n\n-- Triggers for automatic FTS5 synchronization\nCREATE TRIGGER IF NOT EXISTS obs_ai AFTER INSERT ON observations BEGIN\n INSERT INTO observations_fts(rowid, title, content, topic_key)\n VALUES (new.rowid, new.title, new.content, new.topic_key);\nEND;\n\nCREATE TRIGGER IF NOT EXISTS obs_ad AFTER DELETE ON observations BEGIN\n INSERT INTO observations_fts(observations_fts, rowid, title, content, topic_key)\n VALUES ('delete', old.rowid, old.title, old.content, old.topic_key);\nEND;\n\nCREATE TRIGGER IF NOT EXISTS obs_au AFTER UPDATE ON observations BEGIN\n INSERT INTO observations_fts(observations_fts, rowid, title, content, topic_key)\n VALUES ('delete', old.rowid, old.title, old.content, old.topic_key);\n INSERT INTO observations_fts(rowid, title, content, topic_key)\n VALUES (new.rowid, new.title, new.content, new.topic_key);\nEND;\n\n-- Entities table\nCREATE TABLE IF NOT EXISTS entities (\n id TEXT PRIMARY KEY,\n project_id TEXT NOT NULL,\n entity_type TEXT CHECK(entity_type IN ('file', 'function', 'class', 'interface', 'module')) NOT NULL,\n identifier TEXT NOT NULL,\n file_path TEXT NOT NULL,\n FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE\n);\n\nCREATE INDEX IF NOT EXISTS idx_entities_project_id ON entities(project_id);\nCREATE INDEX IF NOT EXISTS idx_entities_identifier ON entities(identifier);\nCREATE UNIQUE INDEX IF NOT EXISTS idx_entities_project_identifier ON entities(project_id, identifier);\n\n-- Observation Entities join table\nCREATE TABLE IF NOT EXISTS observation_entities (\n observation_id TEXT NOT NULL,\n entity_id TEXT NOT NULL,\n PRIMARY KEY(observation_id, entity_id),\n FOREIGN KEY(observation_id) REFERENCES observations(id) ON DELETE CASCADE,\n FOREIGN KEY(entity_id) REFERENCES entities(id) ON DELETE CASCADE\n);\n\nCREATE INDEX IF NOT EXISTS idx_observation_entities_entity_id ON observation_entities(entity_id);\n\n-- Entity Dependencies table\n-- Relaciones topol\u00F3gicas entre s\u00EDmbolos (A llama/importa a B, o A implementa a B)\nCREATE TABLE IF NOT EXISTS entity_dependencies (\n source_entity_id TEXT NOT NULL,\n target_entity_id TEXT NOT NULL,\n relation_type TEXT CHECK(relation_type IN ('imports', 'calls', 'implements', 'extends', 'references')) NOT NULL,\n PRIMARY KEY(source_entity_id, target_entity_id, relation_type),\n FOREIGN KEY(source_entity_id) REFERENCES entities(id) ON DELETE CASCADE,\n FOREIGN KEY(target_entity_id) REFERENCES entities(id) ON DELETE CASCADE\n);\n\nCREATE INDEX IF NOT EXISTS idx_entity_deps_source ON entity_dependencies(source_entity_id);\nCREATE INDEX IF NOT EXISTS idx_entity_deps_target ON entity_dependencies(target_entity_id);\n";
|
|
51
|
+
/**
|
|
52
|
+
* Robustly load schema SQL from disk if available, otherwise fallback to embedded SCHEMA_SQL.
|
|
53
|
+
*/
|
|
54
|
+
export declare function loadSchemaSql(): string;
|
|
55
|
+
/**
|
|
56
|
+
* Strips embedded basic auth credentials (e.g. https://user:pass@host/... -> https://host/...)
|
|
57
|
+
* from a git remote URL before saving git_remote.
|
|
58
|
+
*/
|
|
59
|
+
export declare function sanitizeGitRemote(rawUrl: string): string;
|
|
60
|
+
/**
|
|
61
|
+
* Searches upward from startDir for the nearest directory or parent containing a .git folder or file.
|
|
62
|
+
*/
|
|
63
|
+
export declare function findGitRoot(startDir?: string): string | null;
|
|
64
|
+
/**
|
|
65
|
+
* Inspects a git repository root to extract the default origin remote URL if present.
|
|
66
|
+
*/
|
|
67
|
+
export declare function tryGetGitRemote(gitRoot: string): string | null;
|
|
68
|
+
/**
|
|
69
|
+
* Resolves the database path for Muninn.
|
|
70
|
+
* - If customPath is given, return it (e.g. ':memory:' or specific path).
|
|
71
|
+
* - Check if cwd (or startDir) or any parent directory has .git. If so, resolve to `<git_root>/.huginn/muninn.db`.
|
|
72
|
+
* - Fallback to `join(homedir(), '.huginn', 'muninn.db')`.
|
|
73
|
+
*/
|
|
74
|
+
export declare function resolveDatabasePath(customPath?: string, startDir?: string): string;
|
|
75
|
+
/**
|
|
76
|
+
* Initializes and returns a SQLite database instance using better-sqlite3.
|
|
77
|
+
* Configures foreign_keys = ON, journal_mode = WAL, busy_timeout = 5000, recursive_triggers = ON, and executes schema.sql DDL.
|
|
78
|
+
*/
|
|
79
|
+
export declare function getDatabase(dbPath?: string, startDir?: string): Database.Database;
|
|
80
|
+
/**
|
|
81
|
+
* Finds an existing project by root_path or creates a new project record idempotently.
|
|
82
|
+
*/
|
|
83
|
+
export declare function ensureProject(db: Database.Database, options?: EnsureProjectOptions): Project;
|
|
84
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/db/client.ts"],"names":[],"mappings":"AAKA,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAGtC,MAAM,MAAM,mBAAmB,GAC3B,UAAU,GACV,YAAY,GACZ,WAAW,GACX,QAAQ,GACR,cAAc,CAAC;AAEnB,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,mBAAmB,CAAC;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,UAAU,EAAE,MAAM,CAA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