project-librarian 0.4.0 → 0.4.2
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/README.ko.md +49 -9
- package/README.md +44 -4
- package/dist/agent-surfaces.js +67 -0
- package/dist/args.js +94 -89
- package/dist/code-index/evidence.js +79 -0
- package/dist/code-index/extractors/config.js +58 -0
- package/dist/code-index/extractors/light-languages.js +52 -0
- package/dist/code-index/extractors/registry.js +137 -0
- package/dist/code-index/extractors/shared.js +36 -0
- package/dist/code-index/extractors/tree-sitter.js +319 -0
- package/dist/code-index/extractors/types.js +2 -0
- package/dist/code-index/extractors/typescript.js +211 -0
- package/dist/code-index/incremental.js +16 -0
- package/dist/code-index/index-health.js +164 -0
- package/dist/code-index/modes.js +309 -0
- package/dist/code-index/ownership.js +183 -0
- package/dist/code-index/reports.js +322 -0
- package/dist/code-index/schema.js +196 -0
- package/dist/code-index/search.js +153 -0
- package/dist/code-index-file-policy.js +21 -27
- package/dist/code-index.js +167 -1850
- package/dist/init-project-wiki.js +105 -66
- package/dist/install-skill.js +3 -3
- package/dist/mcp-server.js +60 -6
- package/dist/migration.js +10 -6
- package/dist/modes.js +121 -63
- package/dist/path-ignore-policy.js +30 -0
- package/dist/wiki-corpus.js +25 -0
- package/dist/wiki-diagnostics.js +19 -0
- package/dist/wiki-files.js +2 -1
- package/dist/wiki-graph.js +1 -2
- package/package.json +15 -3
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.collectCodeEvidence = collectCodeEvidence;
|
|
4
|
+
const ownership_1 = require("./ownership");
|
|
5
|
+
const search_1 = require("./search");
|
|
6
|
+
function sortedUnique(values) {
|
|
7
|
+
return Array.from(new Set(values.filter(Boolean))).sort();
|
|
8
|
+
}
|
|
9
|
+
function ownerRowsForFilePaths(filePaths, options) {
|
|
10
|
+
const ownership = (0, ownership_1.ownershipContext)();
|
|
11
|
+
const ownersByName = new Map();
|
|
12
|
+
for (const filePath of filePaths) {
|
|
13
|
+
const info = (0, ownership_1.ownershipInfo)(filePath, ownership);
|
|
14
|
+
const current = ownersByName.get(info.owner) ?? {
|
|
15
|
+
codeowners: new Set(),
|
|
16
|
+
files: 0,
|
|
17
|
+
owner: info.owner,
|
|
18
|
+
owner_source: info.owner_source,
|
|
19
|
+
sample_files: [],
|
|
20
|
+
};
|
|
21
|
+
current.files += 1;
|
|
22
|
+
if (current.sample_files.length < options.ownerSampleLimit)
|
|
23
|
+
current.sample_files.push(filePath);
|
|
24
|
+
if (options.includeOwnerCodeowners && info.codeowners) {
|
|
25
|
+
for (const owner of info.codeowners.split(", ").filter(Boolean))
|
|
26
|
+
current.codeowners.add(owner);
|
|
27
|
+
}
|
|
28
|
+
ownersByName.set(info.owner, current);
|
|
29
|
+
}
|
|
30
|
+
return Array.from(ownersByName.values()).map((owner) => {
|
|
31
|
+
const row = {
|
|
32
|
+
files: owner.files,
|
|
33
|
+
owner: owner.owner,
|
|
34
|
+
owner_source: owner.owner_source,
|
|
35
|
+
sample_files: owner.sample_files,
|
|
36
|
+
};
|
|
37
|
+
if (options.includeOwnerCodeowners)
|
|
38
|
+
row.codeowners = Array.from(owner.codeowners).sort().join(", ");
|
|
39
|
+
return row;
|
|
40
|
+
}).sort((left, right) => right.files - left.files || left.owner.localeCompare(right.owner));
|
|
41
|
+
}
|
|
42
|
+
function collectCodeEvidence(database, query, options) {
|
|
43
|
+
const normalized = query.trim();
|
|
44
|
+
const like = (0, search_1.containsLikePattern)(normalized);
|
|
45
|
+
const files = (0, search_1.searchFiles)(database, normalized, options.fileLimit);
|
|
46
|
+
const symbols = (0, search_1.searchSymbols)(database, normalized, options.symbolLimit);
|
|
47
|
+
const routes = database.prepare("SELECT method, route, file_path, line, handler FROM routes WHERE route LIKE ? ESCAPE '\\' OR handler LIKE ? ESCAPE '\\' OR file_path LIKE ? ESCAPE '\\' ORDER BY file_path, line LIMIT ?").all(like, like, like, options.routeLimit);
|
|
48
|
+
const imports = database.prepare("SELECT from_file, to_ref, imported, line, raw FROM imports WHERE from_file LIKE ? ESCAPE '\\' OR to_ref LIKE ? ESCAPE '\\' OR imported LIKE ? ESCAPE '\\' ORDER BY from_file, line LIMIT ?").all(like, like, like, options.importLimit);
|
|
49
|
+
const outgoingEdges = options.includeEdgeEvidenceMatches
|
|
50
|
+
? database.prepare("SELECT kind, source_kind, source, target_kind, target, file_path, line, evidence FROM edges WHERE file_path LIKE ? ESCAPE '\\' OR source LIKE ? ESCAPE '\\' OR evidence LIKE ? ESCAPE '\\' ORDER BY file_path, line LIMIT ?").all(like, like, like, options.edgeLimit)
|
|
51
|
+
: database.prepare("SELECT kind, source_kind, source, target_kind, target, file_path, line, evidence FROM edges WHERE file_path LIKE ? ESCAPE '\\' OR source LIKE ? ESCAPE '\\' ORDER BY file_path, line LIMIT ?").all(like, like, options.edgeLimit);
|
|
52
|
+
const incomingEdges = options.includeEdgeEvidenceMatches
|
|
53
|
+
? database.prepare("SELECT kind, source_kind, source, target_kind, target, file_path, line, evidence FROM edges WHERE target LIKE ? ESCAPE '\\' OR evidence LIKE ? ESCAPE '\\' ORDER BY file_path, line LIMIT ?").all(like, like, options.edgeLimit)
|
|
54
|
+
: database.prepare("SELECT kind, source_kind, source, target_kind, target, file_path, line, evidence FROM edges WHERE target LIKE ? ESCAPE '\\' ORDER BY file_path, line LIMIT ?").all(like, options.edgeLimit);
|
|
55
|
+
const routeTargets = routes.map((row) => `${String(row.method)} ${String(row.route)}`);
|
|
56
|
+
const routeEdges = options.includeRouteEdges && routeTargets.length > 0
|
|
57
|
+
? database.prepare(`SELECT kind, source_kind, source, target_kind, target, file_path, line, evidence FROM edges WHERE source IN (${routeTargets.map(() => "?").join(", ")}) ORDER BY file_path, line LIMIT ?`).all(...routeTargets, options.routeEdgeLimit)
|
|
58
|
+
: [];
|
|
59
|
+
const relatedFilePaths = sortedUnique([
|
|
60
|
+
...files.map((row) => String(row.path ?? "")),
|
|
61
|
+
...symbols.map((row) => String(row.file_path ?? "")),
|
|
62
|
+
...routes.map((row) => String(row.file_path ?? "")),
|
|
63
|
+
...imports.map((row) => String(row.from_file ?? "")),
|
|
64
|
+
...outgoingEdges.map((row) => String(row.file_path ?? "")),
|
|
65
|
+
...incomingEdges.map((row) => String(row.file_path ?? "")),
|
|
66
|
+
...routeEdges.map((row) => String(row.file_path ?? "")),
|
|
67
|
+
]);
|
|
68
|
+
return {
|
|
69
|
+
files,
|
|
70
|
+
imports,
|
|
71
|
+
incomingEdges,
|
|
72
|
+
owners: ownerRowsForFilePaths(relatedFilePaths, options),
|
|
73
|
+
relatedFilePaths,
|
|
74
|
+
outgoingEdges,
|
|
75
|
+
routeEdges,
|
|
76
|
+
routes,
|
|
77
|
+
symbols,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.indexConfigs = indexConfigs;
|
|
37
|
+
const path = __importStar(require("node:path"));
|
|
38
|
+
const shared_1 = require("./shared");
|
|
39
|
+
function indexConfigs(file, insertConfig) {
|
|
40
|
+
if (path.basename(file.path) === "package.json") {
|
|
41
|
+
try {
|
|
42
|
+
const parsed = JSON.parse(file.text);
|
|
43
|
+
for (const [name, value] of Object.entries(parsed.scripts ?? {}))
|
|
44
|
+
insertConfig.run(`script:${name}`, value, file.path, 1);
|
|
45
|
+
for (const [name, value] of Object.entries(parsed.dependencies ?? {}))
|
|
46
|
+
insertConfig.run(`dependency:${name}`, value, file.path, 1);
|
|
47
|
+
for (const [name, value] of Object.entries(parsed.devDependencies ?? {}))
|
|
48
|
+
insertConfig.run(`devDependency:${name}`, value, file.path, 1);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
insertConfig.run("parse-error", "package.json is not valid JSON", file.path, 1);
|
|
52
|
+
}
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
(0, shared_1.insertMatches)(file, /^\s*([A-Za-z0-9_.-]+)\s*[:=]\s*(.+)$/gm, (match, line) => {
|
|
56
|
+
insertConfig.run(match[1] ?? "", (match[2] ?? "").trim(), file.path, line);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.indexPythonLight = indexPythonLight;
|
|
4
|
+
exports.indexGoLight = indexGoLight;
|
|
5
|
+
const shared_1 = require("./shared");
|
|
6
|
+
function indexPythonLight(file, statements) {
|
|
7
|
+
const symbolPatterns = [
|
|
8
|
+
[/^\s*def\s+([A-Za-z_]\w*)\s*\(([^)]*)\)/gm, "function", (match) => `def ${match[1] ?? ""}(${match[2] ?? ""})`],
|
|
9
|
+
[/^\s*class\s+([A-Za-z_]\w*)/gm, "class", (match) => `class ${match[1] ?? ""}`],
|
|
10
|
+
];
|
|
11
|
+
for (const [regex, kind, signature] of symbolPatterns) {
|
|
12
|
+
(0, shared_1.insertMatches)(file, regex, (match, line) => (0, shared_1.insertSymbol)(statements, match[1] ?? "", kind, file, line, signature(match)));
|
|
13
|
+
}
|
|
14
|
+
const importPatterns = [
|
|
15
|
+
[/^\s*from\s+([A-Za-z0-9_.$]+)\s+import\s+(.+)$/gm, (match) => [match[1] ?? "", match[2] ?? ""]],
|
|
16
|
+
[/^\s*import\s+([A-Za-z0-9_.$, \t]+)$/gm, (match) => [match[1] ?? "", ""]],
|
|
17
|
+
];
|
|
18
|
+
for (const [regex, fields] of importPatterns) {
|
|
19
|
+
(0, shared_1.insertMatches)(file, regex, (match, line) => {
|
|
20
|
+
const [toRef, imported] = fields(match);
|
|
21
|
+
statements.insertImport.run(file.path, toRef, imported.trim(), line, match[0].trim());
|
|
22
|
+
(0, shared_1.insertEdge)(statements, "import", "file", file.path, "module", toRef, file, line, match[0].trim());
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function indexGoLight(file, statements) {
|
|
27
|
+
const symbolPatterns = [
|
|
28
|
+
[/^\s*func\s*\(\s*[^)]*\)\s*([A-Za-z_]\w*)\s*\(([^)]*)\)/gm, "method", (match) => match[1] ?? "", (match) => `func (...) ${match[1] ?? ""}(${match[2] ?? ""})`],
|
|
29
|
+
[/^\s*func\s+([A-Za-z_]\w*)\s*\(([^)]*)\)/gm, "function", (match) => match[1] ?? "", (match) => `func ${match[1] ?? ""}(${match[2] ?? ""})`],
|
|
30
|
+
[/^\s*type\s+([A-Za-z_]\w*)\s+(struct|interface)?/gm, "type", (match) => match[1] ?? "", (match) => `type ${match[1] ?? ""} ${match[2] ?? ""}`.trim()],
|
|
31
|
+
[/^\s*const\s+([A-Za-z_]\w*)\b/gm, "constant", (match) => match[1] ?? "", (match) => `const ${match[1] ?? ""}`],
|
|
32
|
+
[/^\s*var\s+([A-Za-z_]\w*)\b/gm, "variable", (match) => match[1] ?? "", (match) => `var ${match[1] ?? ""}`],
|
|
33
|
+
];
|
|
34
|
+
for (const [regex, kind, name, signature] of symbolPatterns) {
|
|
35
|
+
(0, shared_1.insertMatches)(file, regex, (match, line) => (0, shared_1.insertSymbol)(statements, name(match), kind, file, line, signature(match)));
|
|
36
|
+
}
|
|
37
|
+
(0, shared_1.insertMatches)(file, /^\s*import\s+(?:(?:([A-Za-z_]\w*|[_.])\s+)?\"([^\"]+)\"|`([^`]+)`)/gm, (match, line) => {
|
|
38
|
+
const imported = match[1] ?? "";
|
|
39
|
+
const toRef = match[2] ?? match[3] ?? "";
|
|
40
|
+
(0, shared_1.insertGoImport)(file, statements, toRef, imported, line, match[0].trim());
|
|
41
|
+
});
|
|
42
|
+
(0, shared_1.insertMatches)(file, /^\s*import\s*\(([\s\S]*?)^\s*\)/gm, (blockMatch) => {
|
|
43
|
+
const block = blockMatch[1] ?? "";
|
|
44
|
+
const blockStart = blockMatch.index ?? 0;
|
|
45
|
+
for (const lineMatch of block.matchAll(/^\s*(?:([A-Za-z_]\w*|[_.])\s+)?\"([^\"]+)\"/gm)) {
|
|
46
|
+
const imported = lineMatch[1] ?? "";
|
|
47
|
+
const toRef = lineMatch[2] ?? "";
|
|
48
|
+
const line = (0, shared_1.lineNumber)(file.text, blockStart + (lineMatch.index ?? 0));
|
|
49
|
+
(0, shared_1.insertGoImport)(file, statements, toRef, imported, line, lineMatch[0].trim());
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.extractionProfile = extractionProfile;
|
|
37
|
+
exports.createExtractionBackendRegistry = createExtractionBackendRegistry;
|
|
38
|
+
const path = __importStar(require("node:path"));
|
|
39
|
+
const config_1 = require("./config");
|
|
40
|
+
const light_languages_1 = require("./light-languages");
|
|
41
|
+
const tree_sitter_1 = require("./tree-sitter");
|
|
42
|
+
const typescript_1 = require("./typescript");
|
|
43
|
+
function treeSitterProfile(relativePath) {
|
|
44
|
+
const extension = path.extname(relativePath).toLowerCase();
|
|
45
|
+
if ([".ts", ".mts", ".cts"].includes(extension))
|
|
46
|
+
return "tree-sitter-typescript";
|
|
47
|
+
if (extension === ".tsx")
|
|
48
|
+
return "tree-sitter-tsx";
|
|
49
|
+
if ([".js", ".mjs", ".cjs", ".jsx"].includes(extension))
|
|
50
|
+
return "tree-sitter-javascript";
|
|
51
|
+
if (extension === ".py")
|
|
52
|
+
return "tree-sitter-python";
|
|
53
|
+
if (extension === ".go")
|
|
54
|
+
return "tree-sitter-go";
|
|
55
|
+
if ([".c", ".h"].includes(extension))
|
|
56
|
+
return "tree-sitter-c";
|
|
57
|
+
if ([".cc", ".cpp", ".cxx", ".hpp", ".hh", ".hxx"].includes(extension))
|
|
58
|
+
return "tree-sitter-cpp";
|
|
59
|
+
if (extension === ".cs")
|
|
60
|
+
return "tree-sitter-csharp";
|
|
61
|
+
if (extension === ".java")
|
|
62
|
+
return "tree-sitter-java";
|
|
63
|
+
if ([".kt", ".kts"].includes(extension))
|
|
64
|
+
return "tree-sitter-kotlin";
|
|
65
|
+
if (extension === ".php")
|
|
66
|
+
return "tree-sitter-php";
|
|
67
|
+
if (extension === ".rs")
|
|
68
|
+
return "tree-sitter-rust";
|
|
69
|
+
if (extension === ".swift")
|
|
70
|
+
return "tree-sitter-swift";
|
|
71
|
+
return "inventory-only";
|
|
72
|
+
}
|
|
73
|
+
function extractionProfile(relativePath, language, parserMode) {
|
|
74
|
+
if (language === "config")
|
|
75
|
+
return "config";
|
|
76
|
+
if (parserMode === "tree-sitter")
|
|
77
|
+
return treeSitterProfile(relativePath);
|
|
78
|
+
if (isJavaScriptLikeProfileInput(language))
|
|
79
|
+
return "typescript-ast";
|
|
80
|
+
if (language === "python")
|
|
81
|
+
return "python-light";
|
|
82
|
+
if (language === "go")
|
|
83
|
+
return "go-light";
|
|
84
|
+
return "inventory-only";
|
|
85
|
+
}
|
|
86
|
+
function isJavaScriptLikeProfileInput(language) {
|
|
87
|
+
return language === "javascript" || language === "typescript";
|
|
88
|
+
}
|
|
89
|
+
function createExtractionBackendRegistry(fail) {
|
|
90
|
+
const extractionBackends = [
|
|
91
|
+
{
|
|
92
|
+
id: "typescript-compiler",
|
|
93
|
+
index: typescript_1.indexJavaScriptLike,
|
|
94
|
+
label: "TypeScript compiler API",
|
|
95
|
+
profile: "typescript-ast",
|
|
96
|
+
strength: "structural",
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
id: "regex-light",
|
|
100
|
+
index: light_languages_1.indexPythonLight,
|
|
101
|
+
label: "Python lightweight regex",
|
|
102
|
+
profile: "python-light",
|
|
103
|
+
strength: "light",
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
id: "regex-light",
|
|
107
|
+
index: light_languages_1.indexGoLight,
|
|
108
|
+
label: "Go lightweight regex",
|
|
109
|
+
profile: "go-light",
|
|
110
|
+
strength: "light",
|
|
111
|
+
},
|
|
112
|
+
...(0, tree_sitter_1.treeSitterBackends)(fail),
|
|
113
|
+
{
|
|
114
|
+
id: "config-key-value",
|
|
115
|
+
index: (file, statements) => (0, config_1.indexConfigs)(file, statements.insertConfig),
|
|
116
|
+
label: "Configuration key/value extractor",
|
|
117
|
+
profile: "config",
|
|
118
|
+
strength: "config",
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
id: "inventory-only",
|
|
122
|
+
index: () => undefined,
|
|
123
|
+
label: "Inventory-only file listing",
|
|
124
|
+
profile: "inventory-only",
|
|
125
|
+
strength: "inventory",
|
|
126
|
+
},
|
|
127
|
+
];
|
|
128
|
+
const extractionBackendsByProfile = new Map(extractionBackends.map((backend) => [backend.profile, backend]));
|
|
129
|
+
return {
|
|
130
|
+
backendForProfile(profile) {
|
|
131
|
+
const backend = extractionBackendsByProfile.get(profile);
|
|
132
|
+
if (!backend)
|
|
133
|
+
fail(`missing extraction backend for profile: ${profile}`);
|
|
134
|
+
return backend;
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.oneLine = oneLine;
|
|
4
|
+
exports.lineNumber = lineNumber;
|
|
5
|
+
exports.insertSymbol = insertSymbol;
|
|
6
|
+
exports.insertEdge = insertEdge;
|
|
7
|
+
exports.insertMatches = insertMatches;
|
|
8
|
+
exports.insertGoImport = insertGoImport;
|
|
9
|
+
function oneLine(text) {
|
|
10
|
+
return text.replace(/\s+/g, " ").trim().slice(0, 240);
|
|
11
|
+
}
|
|
12
|
+
function lineNumber(text, index) {
|
|
13
|
+
return text.slice(0, index).split(/\r?\n/).length;
|
|
14
|
+
}
|
|
15
|
+
function insertSymbol(statements, name, kind, file, line, signature) {
|
|
16
|
+
if (!name)
|
|
17
|
+
return;
|
|
18
|
+
statements.insertSymbol.run(name, kind, file.path, line, signature);
|
|
19
|
+
statements.insertSymbolFts.run(name, kind, file.path, signature);
|
|
20
|
+
}
|
|
21
|
+
function insertEdge(statements, kind, sourceKind, source, targetKind, target, file, line, evidence) {
|
|
22
|
+
if (!target)
|
|
23
|
+
return;
|
|
24
|
+
statements.insertEdge.run(kind, sourceKind, source, targetKind, target, file.path, line, evidence);
|
|
25
|
+
}
|
|
26
|
+
function insertMatches(file, regex, insert) {
|
|
27
|
+
for (const match of file.text.matchAll(regex)) {
|
|
28
|
+
insert(match, lineNumber(file.text, match.index ?? 0));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function insertGoImport(file, statements, toRef, imported, line, raw) {
|
|
32
|
+
if (!toRef)
|
|
33
|
+
return;
|
|
34
|
+
statements.insertImport.run(file.path, toRef, imported, line, raw);
|
|
35
|
+
insertEdge(statements, "import", "file", file.path, "module", toRef, file, line, raw);
|
|
36
|
+
}
|