aidoc-kit 1.2.2 → 1.3.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/README.md +45 -5
- package/dist/cli.js +96 -1
- package/dist/cli.js.map +1 -1
- package/dist/codegraph/detect.d.ts +16 -0
- package/dist/codegraph/detect.d.ts.map +1 -0
- package/dist/codegraph/detect.js +68 -0
- package/dist/codegraph/detect.js.map +1 -0
- package/dist/codegraph/loader.d.ts +9 -0
- package/dist/codegraph/loader.d.ts.map +1 -0
- package/dist/codegraph/loader.js +161 -0
- package/dist/codegraph/loader.js.map +1 -0
- package/dist/codegraph/runner.d.ts +18 -0
- package/dist/codegraph/runner.d.ts.map +1 -0
- package/dist/codegraph/runner.js +60 -0
- package/dist/codegraph/runner.js.map +1 -0
- package/dist/core/scanner.js +1 -1
- package/dist/core/scanner.js.map +1 -1
- package/dist/core/writer.d.ts.map +1 -1
- package/dist/core/writer.js +8 -2
- package/dist/core/writer.js.map +1 -1
- package/dist/enricher/basicEnricher.d.ts +27 -0
- package/dist/enricher/basicEnricher.d.ts.map +1 -0
- package/dist/enricher/basicEnricher.js +157 -0
- package/dist/enricher/basicEnricher.js.map +1 -0
- package/dist/graph/query.d.ts +28 -0
- package/dist/graph/query.d.ts.map +1 -0
- package/dist/graph/query.js +24 -0
- package/dist/graph/query.js.map +1 -0
- package/dist/graph/serializer.d.ts +10 -0
- package/dist/graph/serializer.d.ts.map +1 -0
- package/dist/graph/serializer.js +51 -0
- package/dist/graph/serializer.js.map +1 -0
- package/dist/graph/types.d.ts +101 -0
- package/dist/graph/types.d.ts.map +1 -0
- package/dist/graph/types.js +27 -0
- package/dist/graph/types.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -1
- package/dist/index.js.map +1 -1
- package/package.json +9 -2
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.codegraphDbPath = codegraphDbPath;
|
|
4
|
+
exports.runCodegraphIndex = runCodegraphIndex;
|
|
5
|
+
/**
|
|
6
|
+
* @ai-agent general-expert
|
|
7
|
+
* @ai-agent-hint If you are not the general-expert specialist, consider switching to a specialized agent in Copilot Chat. Run `npx aidoc-kit agents` to generate agent instruction files.
|
|
8
|
+
* @ai-runtime UNIVERSEL
|
|
9
|
+
*
|
|
10
|
+
* @ai-context
|
|
11
|
+
* [GENERATED] This file exports: codegraphDbPath, RunIndexOptions, runCodegraphIndex
|
|
12
|
+
* Imported by: src/cli.ts, src/codegraph/loader.ts
|
|
13
|
+
*
|
|
14
|
+
* @ai-when-modifying
|
|
15
|
+
* 1. Check cascade files below before modifying
|
|
16
|
+
* 2. After modifying, ask the developer to run @ai-validate
|
|
17
|
+
* 3. If you have no terminal access, report the command to run
|
|
18
|
+
*
|
|
19
|
+
* @ai-cascade
|
|
20
|
+
* - src/cli.ts
|
|
21
|
+
* - src/codegraph/loader.ts
|
|
22
|
+
*
|
|
23
|
+
* @ai-validate
|
|
24
|
+
* npm run typecheck
|
|
25
|
+
*/
|
|
26
|
+
const node_child_process_1 = require("node:child_process");
|
|
27
|
+
const node_fs_1 = require("node:fs");
|
|
28
|
+
const node_path_1 = require("node:path");
|
|
29
|
+
/** Location of the CodeGraph SQLite index inside a project. */
|
|
30
|
+
function codegraphDbPath(projectRoot) {
|
|
31
|
+
return (0, node_path_1.join)(projectRoot, '.codegraph', 'codegraph.db');
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Run CodeGraph indexing on the target project and verify the index exists.
|
|
35
|
+
*
|
|
36
|
+
* First run: `codegraph init --yes` (initializes .codegraph/ and builds the
|
|
37
|
+
* initial index). Subsequent runs: `codegraph index` (full rebuild) or
|
|
38
|
+
* `codegraph sync` when incremental.
|
|
39
|
+
*
|
|
40
|
+
* The binary is spawned directly (no shell) with inherited stdio so
|
|
41
|
+
* CodeGraph's own progress output stays visible.
|
|
42
|
+
*/
|
|
43
|
+
function runCodegraphIndex(projectRoot, binPath, opts) {
|
|
44
|
+
const initialized = (0, node_fs_1.existsSync)(codegraphDbPath(projectRoot));
|
|
45
|
+
const subcommand = !initialized ? 'init' : opts.incremental ? 'sync' : 'index';
|
|
46
|
+
const args = subcommand === 'init'
|
|
47
|
+
? ['init', '--yes', projectRoot]
|
|
48
|
+
: [subcommand, projectRoot];
|
|
49
|
+
const result = (0, node_child_process_1.spawnSync)(binPath, args, { stdio: 'inherit' });
|
|
50
|
+
if (result.error) {
|
|
51
|
+
throw new Error(`Failed to run codegraph ${subcommand}: ${result.error.message}`);
|
|
52
|
+
}
|
|
53
|
+
if (result.status !== 0) {
|
|
54
|
+
throw new Error(`codegraph ${subcommand} exited with code ${result.status ?? 'unknown'}`);
|
|
55
|
+
}
|
|
56
|
+
if (!(0, node_fs_1.existsSync)(codegraphDbPath(projectRoot))) {
|
|
57
|
+
throw new Error(`codegraph ${subcommand} completed but ${codegraphDbPath(projectRoot)} was not created.`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/codegraph/runner.ts"],"names":[],"mappings":";;AA0BA,0CAEC;AAiBD,8CAwBC;AArED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,2DAA8C;AAC9C,qCAAoC;AACpC,yCAAgC;AAEhC,+DAA+D;AAC/D,SAAgB,eAAe,CAAC,WAAmB;IACjD,OAAO,IAAA,gBAAI,EAAC,WAAW,EAAE,YAAY,EAAE,cAAc,CAAC,CAAA;AACxD,CAAC;AAOD;;;;;;;;;GASG;AACH,SAAgB,iBAAiB,CAC/B,WAAmB,EACnB,OAAe,EACf,IAAqB;IAErB,MAAM,WAAW,GAAG,IAAA,oBAAU,EAAC,eAAe,CAAC,WAAW,CAAC,CAAC,CAAA;IAC5D,MAAM,UAAU,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAA;IAC9E,MAAM,IAAI,GAAG,UAAU,KAAK,MAAM;QAChC,CAAC,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,WAAW,CAAC;QAChC,CAAC,CAAC,CAAC,UAAU,EAAE,WAAW,CAAC,CAAA;IAE7B,MAAM,MAAM,GAAG,IAAA,8BAAS,EAAC,OAAO,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAA;IAE7D,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,2BAA2B,UAAU,KAAK,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;IACnF,CAAC;IACD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,aAAa,UAAU,qBAAqB,MAAM,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC,CAAA;IAC3F,CAAC;IACD,IAAI,CAAC,IAAA,oBAAU,EAAC,eAAe,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC;QAC9C,MAAM,IAAI,KAAK,CACb,aAAa,UAAU,kBAAkB,eAAe,CAAC,WAAW,CAAC,mBAAmB,CACzF,CAAA;IACH,CAAC;AACH,CAAC"}
|
package/dist/core/scanner.js
CHANGED
|
@@ -62,7 +62,7 @@ const node_fs_1 = require("node:fs");
|
|
|
62
62
|
const node_path_1 = require("node:path");
|
|
63
63
|
const EXTENSIONS = new Set(['.ts', '.tsx', '.js', '.jsx']);
|
|
64
64
|
const IGNORED_DIRS = new Set([
|
|
65
|
-
'node_modules', '.git', 'dist', '.next', 'out', 'build', '.codemod', 'coverage',
|
|
65
|
+
'node_modules', '.git', 'dist', '.next', '_next', 'out', 'build', '.codemod', '.codegraph', 'coverage',
|
|
66
66
|
]);
|
|
67
67
|
// ─── Public API ────────────────────────────────────────────────────────────
|
|
68
68
|
/**
|
package/dist/core/scanner.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scanner.js","sourceRoot":"","sources":["../../src/core/scanner.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,sDAgDC;AAqBD,kCAeC;AAED,sCAqCC;AAID,0BA2BC;AA/LD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,+CAAgC;AAChC,qCAA6D;AAC7D,yCAAqE;AAGrE,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAA;AAC1D,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC;IAC3B,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU;
|
|
1
|
+
{"version":3,"file":"scanner.js","sourceRoot":"","sources":["../../src/core/scanner.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,sDAgDC;AAqBD,kCAeC;AAED,sCAqCC;AAID,0BA2BC;AA/LD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,+CAAgC;AAChC,qCAA6D;AAC7D,yCAAqE;AAGrE,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAA;AAC1D,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC;IAC3B,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU;CACvG,CAAC,CAAA;AAEF,8EAA8E;AAE9E;;;;GAIG;AACH,SAAgB,qBAAqB,CAAC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,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"writer.d.ts","sourceRoot":"","sources":["../../src/core/writer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAA6B,UAAU,EAAE,MAAM,UAAU,CAAA;AAKrE,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CAKhF;AAID,wBAAgB,aAAa,CAAC,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CA2G3E;AAID,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAetE"}
|
package/dist/core/writer.js
CHANGED
|
@@ -5,6 +5,7 @@ exports.writeAgentsMd = writeAgentsMd;
|
|
|
5
5
|
exports.writeDocBlock = writeDocBlock;
|
|
6
6
|
const node_fs_1 = require("node:fs");
|
|
7
7
|
const node_path_1 = require("node:path");
|
|
8
|
+
const serializer_1 = require("../graph/serializer");
|
|
8
9
|
// ─── Knowledge base ────────────────────────────────────────────────────────
|
|
9
10
|
function writeKnowledgeBase(result, projectRoot) {
|
|
10
11
|
const outDir = (0, node_path_1.join)(projectRoot, '.codemod');
|
|
@@ -21,9 +22,14 @@ function writeAgentsMd(result, projectRoot) {
|
|
|
21
22
|
`> Generated by aidoc-kit on ${new Date().toISOString().slice(0, 10)}`,
|
|
22
23
|
`> ${result.totalScanned} files scanned — ${result.docs.length} with @ai-* docs`,
|
|
23
24
|
'',
|
|
24
|
-
'## Agents and their domains',
|
|
25
|
-
'',
|
|
26
25
|
];
|
|
26
|
+
// Enriched code graph section — placed first so agents see it before
|
|
27
|
+
// anything else. Only written when aidoc-graph.json exists.
|
|
28
|
+
const graph = (0, serializer_1.readEnrichedGraph)(projectRoot);
|
|
29
|
+
if (graph) {
|
|
30
|
+
lines.push(`## Code graph — query it, never read it in full`, '', `\`${serializer_1.GRAPH_FILENAME}\` (project root) maps every file: role (client/server/universal),`, `criticality 0-100, dependents and dependencies. Generated ${graph.generatedAt.slice(0, 10)}`, `by \`npx aidoc-kit index\` — ${graph.stats.files} files, ${graph.stats.edges} edges.`, '', `Rules for AI agents:`, '', `1. **Never load ${serializer_1.GRAPH_FILENAME} entirely** — it grows with the project. Query it.`, `2. Before modifying a file, check its entry. If \`criticalityLevel\` is \`high\` or`, ` \`critical\`, read every dependent file first.`, `3. Never import a \`role: server\` file from client code.`, `4. Freshness: if \`generatedAt\` is older than the last commit, the graph may be stale —`, ` ask the developer to run \`npx aidoc-kit index --incremental\` (do not run it yourself).`, '', `Queries (replace the path):`, '', '```bash', `# One file's entry (role, criticality, tags)`, `node -e "const g=require('./${serializer_1.GRAPH_FILENAME}');console.log(g.files.find(f=>f.file==='src/foo.ts'))"`, '', `# Who depends on a file (check these before modifying it)`, `node -e "const g=require('./${serializer_1.GRAPH_FILENAME}');console.log([...new Set(g.edges.filter(e=>e.to==='src/foo.ts').map(e=>e.from))])"`, '', `# Most critical files`, `node -e "const g=require('./${serializer_1.GRAPH_FILENAME}');g.files.filter(f=>f.criticality>=55).forEach(f=>console.log(f.criticality,f.file))"`, '```', '');
|
|
31
|
+
}
|
|
32
|
+
lines.push('## Agents and their domains', '');
|
|
27
33
|
for (const [agent, info] of Object.entries(kb.agents)) {
|
|
28
34
|
lines.push(`### ${agent}`, '');
|
|
29
35
|
lines.push(`**Files:** ${info.owns.length}`);
|
package/dist/core/writer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writer.js","sourceRoot":"","sources":["../../src/core/writer.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"writer.js","sourceRoot":"","sources":["../../src/core/writer.ts"],"names":[],"mappings":";;AAOA,gDAKC;AAID,sCA2GC;AAID,sCAeC;AA9ID,qCAAgE;AAChE,yCAAgC;AAEhC,oDAAuE;AAEvE,8EAA8E;AAE9E,SAAgB,kBAAkB,CAAC,MAAkB,EAAE,WAAmB;IACx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AAE,kBAAkB,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAA;YAC5E,kBAAkB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QACjD,CAAC;IACH,CAAC;IAED,OAAO,EAAE,WAAW,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,kBAAkB,EAAE,CAAA;AACxG,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { CriticalityLevel, EnrichedGraph, FileRole, RawGraph } from '../graph/types';
|
|
2
|
+
/**
|
|
3
|
+
* Infer the execution role of a file. Explicit directives win, then path
|
|
4
|
+
* conventions (Next.js API routes, server/ folders, .server/.client
|
|
5
|
+
* suffixes), then content heuristics — same priority order as the
|
|
6
|
+
* @ai-runtime detection in core/transformer.
|
|
7
|
+
*/
|
|
8
|
+
export declare function inferRole(relPath: string, source: string): {
|
|
9
|
+
role: FileRole;
|
|
10
|
+
reason: string;
|
|
11
|
+
};
|
|
12
|
+
export declare function inferTags(relPath: string): string[];
|
|
13
|
+
/**
|
|
14
|
+
* Criticality score, 0-100:
|
|
15
|
+
* - fan-in: 6 points per dependent file, capped at 60 (10+ dependents saturate)
|
|
16
|
+
* - +15 when the file is an API surface
|
|
17
|
+
* - +25 when it belongs to a sensitive domain (auth, billing, payment)
|
|
18
|
+
*/
|
|
19
|
+
export declare function computeCriticality(inDegree: number, tags: string[]): number;
|
|
20
|
+
export declare function criticalityLevel(score: number): CriticalityLevel;
|
|
21
|
+
/**
|
|
22
|
+
* Layer aidoc-kit's intelligence (roles, criticality, tags) on top of the
|
|
23
|
+
* raw CodeGraph output. Pure function apart from reading file sources for
|
|
24
|
+
* directive detection — a file that cannot be read falls back to path rules.
|
|
25
|
+
*/
|
|
26
|
+
export declare function enrichGraph(raw: RawGraph, projectRoot: string): EnrichedGraph;
|
|
27
|
+
//# sourceMappingURL=basicEnricher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"basicEnricher.d.ts","sourceRoot":"","sources":["../../src/enricher/basicEnricher.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EACV,gBAAgB,EAEhB,aAAa,EACb,QAAQ,EACR,QAAQ,EACT,MAAM,gBAAgB,CAAA;AAOvB;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAmB7F;AAcD,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAGnD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAK3E;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,gBAAgB,CAKhE;AAID;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,GAAG,aAAa,CAsD7E"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.inferRole = inferRole;
|
|
4
|
+
exports.inferTags = inferTags;
|
|
5
|
+
exports.computeCriticality = computeCriticality;
|
|
6
|
+
exports.criticalityLevel = criticalityLevel;
|
|
7
|
+
exports.enrichGraph = enrichGraph;
|
|
8
|
+
/**
|
|
9
|
+
* @ai-agent general-expert
|
|
10
|
+
* @ai-agent-hint If you are not the general-expert specialist, consider switching to a specialized agent in Copilot Chat. Run `npx aidoc-kit agents` to generate agent instruction files.
|
|
11
|
+
* @ai-runtime UNIVERSEL
|
|
12
|
+
*
|
|
13
|
+
* @ai-context
|
|
14
|
+
* [GENERATED] This file exports: inferRole, inferTags, computeCriticality, criticalityLevel, enrichGraph
|
|
15
|
+
* Imported by: src/cli.ts
|
|
16
|
+
*
|
|
17
|
+
* @ai-when-modifying
|
|
18
|
+
* 1. Check cascade files below before modifying
|
|
19
|
+
* 2. After modifying, ask the developer to run @ai-validate
|
|
20
|
+
* 3. If you have no terminal access, report the command to run
|
|
21
|
+
*
|
|
22
|
+
* @ai-cascade
|
|
23
|
+
* - src/cli.ts
|
|
24
|
+
*
|
|
25
|
+
* @ai-validate
|
|
26
|
+
* npm run typecheck
|
|
27
|
+
*/
|
|
28
|
+
const node_fs_1 = require("node:fs");
|
|
29
|
+
const node_path_1 = require("node:path");
|
|
30
|
+
// ─── Role inference ────────────────────────────────────────────────────────
|
|
31
|
+
const SERVER_PATH_PATTERN = /(^|\/)(app\/api|pages\/api|server|api)(\/|$)/;
|
|
32
|
+
const CLIENT_HOOKS_PATTERN = /\buseState\b|\buseEffect\b|\buseRef\b|\buseReducer\b|\buseCallback\b|\buseMemo\b/;
|
|
33
|
+
/**
|
|
34
|
+
* Infer the execution role of a file. Explicit directives win, then path
|
|
35
|
+
* conventions (Next.js API routes, server/ folders, .server/.client
|
|
36
|
+
* suffixes), then content heuristics — same priority order as the
|
|
37
|
+
* @ai-runtime detection in core/transformer.
|
|
38
|
+
*/
|
|
39
|
+
function inferRole(relPath, source) {
|
|
40
|
+
const head = source.slice(0, 300);
|
|
41
|
+
if (/^\s*(?:\/\/[^\n]*\n\s*)*['"]use client['"]/.test(head)) {
|
|
42
|
+
return { role: 'client', reason: `'use client' directive` };
|
|
43
|
+
}
|
|
44
|
+
if (/^\s*(?:\/\/[^\n]*\n\s*)*['"]use server['"]/.test(head)) {
|
|
45
|
+
return { role: 'server', reason: `'use server' directive` };
|
|
46
|
+
}
|
|
47
|
+
const normalized = relPath.replace(/\\/g, '/');
|
|
48
|
+
if (/\.server\.[jt]sx?$/.test(normalized))
|
|
49
|
+
return { role: 'server', reason: '.server file suffix' };
|
|
50
|
+
if (/\.client\.[jt]sx?$/.test(normalized))
|
|
51
|
+
return { role: 'client', reason: '.client file suffix' };
|
|
52
|
+
const serverMatch = normalized.match(SERVER_PATH_PATTERN);
|
|
53
|
+
if (serverMatch)
|
|
54
|
+
return { role: 'server', reason: `server path (${serverMatch[2]}/)` };
|
|
55
|
+
if (/['"]firebase-admin['"]/.test(source))
|
|
56
|
+
return { role: 'server', reason: 'firebase-admin import' };
|
|
57
|
+
if (CLIENT_HOOKS_PATTERN.test(source))
|
|
58
|
+
return { role: 'client', reason: 'React hooks usage' };
|
|
59
|
+
return { role: 'universal', reason: 'no client/server signal' };
|
|
60
|
+
}
|
|
61
|
+
// ─── Criticality ───────────────────────────────────────────────────────────
|
|
62
|
+
const TAG_PATTERNS = [
|
|
63
|
+
['api', /(^|\/)(app\/api|pages\/api|api)(\/|$)/],
|
|
64
|
+
['auth', /auth/i],
|
|
65
|
+
['billing', /billing|invoice/i],
|
|
66
|
+
['payment', /payment|stripe|checkout/i],
|
|
67
|
+
];
|
|
68
|
+
/** Tags carrying a criticality bonus beyond plain fan-in. */
|
|
69
|
+
const SENSITIVE_TAGS = new Set(['auth', 'billing', 'payment']);
|
|
70
|
+
function inferTags(relPath) {
|
|
71
|
+
const normalized = relPath.replace(/\\/g, '/');
|
|
72
|
+
return TAG_PATTERNS.filter(([, pattern]) => pattern.test(normalized)).map(([tag]) => tag);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Criticality score, 0-100:
|
|
76
|
+
* - fan-in: 6 points per dependent file, capped at 60 (10+ dependents saturate)
|
|
77
|
+
* - +15 when the file is an API surface
|
|
78
|
+
* - +25 when it belongs to a sensitive domain (auth, billing, payment)
|
|
79
|
+
*/
|
|
80
|
+
function computeCriticality(inDegree, tags) {
|
|
81
|
+
let score = Math.min(60, inDegree * 6);
|
|
82
|
+
if (tags.includes('api'))
|
|
83
|
+
score += 15;
|
|
84
|
+
if (tags.some(t => SENSITIVE_TAGS.has(t)))
|
|
85
|
+
score += 25;
|
|
86
|
+
return Math.min(100, score);
|
|
87
|
+
}
|
|
88
|
+
function criticalityLevel(score) {
|
|
89
|
+
if (score >= 80)
|
|
90
|
+
return 'critical';
|
|
91
|
+
if (score >= 55)
|
|
92
|
+
return 'high';
|
|
93
|
+
if (score >= 25)
|
|
94
|
+
return 'medium';
|
|
95
|
+
return 'low';
|
|
96
|
+
}
|
|
97
|
+
// ─── Enrichment pass ───────────────────────────────────────────────────────
|
|
98
|
+
/**
|
|
99
|
+
* Layer aidoc-kit's intelligence (roles, criticality, tags) on top of the
|
|
100
|
+
* raw CodeGraph output. Pure function apart from reading file sources for
|
|
101
|
+
* directive detection — a file that cannot be read falls back to path rules.
|
|
102
|
+
*/
|
|
103
|
+
function enrichGraph(raw, projectRoot) {
|
|
104
|
+
// Distinct dependents/dependencies per file, all edge kinds included
|
|
105
|
+
const dependents = new Map();
|
|
106
|
+
const dependencies = new Map();
|
|
107
|
+
for (const edge of raw.fileEdges) {
|
|
108
|
+
if (!dependents.has(edge.to))
|
|
109
|
+
dependents.set(edge.to, new Set());
|
|
110
|
+
dependents.get(edge.to).add(edge.from);
|
|
111
|
+
if (!dependencies.has(edge.from))
|
|
112
|
+
dependencies.set(edge.from, new Set());
|
|
113
|
+
dependencies.get(edge.from).add(edge.to);
|
|
114
|
+
}
|
|
115
|
+
const files = raw.files.map(f => {
|
|
116
|
+
let source = '';
|
|
117
|
+
try {
|
|
118
|
+
source = (0, node_fs_1.readFileSync)((0, node_path_1.join)(projectRoot, f.path), 'utf-8');
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
// deleted since indexing, or unreadable — path rules still apply
|
|
122
|
+
}
|
|
123
|
+
const { role, reason } = inferRole(f.path, source);
|
|
124
|
+
const tags = inferTags(f.path);
|
|
125
|
+
const inDegree = dependents.get(f.path)?.size ?? 0;
|
|
126
|
+
const outDegree = dependencies.get(f.path)?.size ?? 0;
|
|
127
|
+
const criticality = computeCriticality(inDegree, tags);
|
|
128
|
+
return {
|
|
129
|
+
file: f.path,
|
|
130
|
+
language: f.language,
|
|
131
|
+
role,
|
|
132
|
+
roleReason: reason,
|
|
133
|
+
criticality,
|
|
134
|
+
criticalityLevel: criticalityLevel(criticality),
|
|
135
|
+
inDegree,
|
|
136
|
+
outDegree,
|
|
137
|
+
tags,
|
|
138
|
+
symbolCount: f.symbolCount,
|
|
139
|
+
};
|
|
140
|
+
});
|
|
141
|
+
const countRole = (role) => files.filter(f => f.role === role).length;
|
|
142
|
+
return {
|
|
143
|
+
version: 1,
|
|
144
|
+
generatedAt: new Date().toISOString(),
|
|
145
|
+
codegraph: { version: raw.codegraphVersion },
|
|
146
|
+
stats: {
|
|
147
|
+
files: files.length,
|
|
148
|
+
edges: raw.fileEdges.length,
|
|
149
|
+
client: countRole('client'),
|
|
150
|
+
server: countRole('server'),
|
|
151
|
+
universal: countRole('universal'),
|
|
152
|
+
},
|
|
153
|
+
files,
|
|
154
|
+
edges: raw.fileEdges,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=basicEnricher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"basicEnricher.js","sourceRoot":"","sources":["../../src/enricher/basicEnricher.ts"],"names":[],"mappings":";;AAyCA,8BAmBC;AAcD,8BAGC;AAQD,gDAKC;AAED,4CAKC;AASD,kCAsDC;AAhKD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qCAAsC;AACtC,yCAAgC;AAShC,8EAA8E;AAE9E,MAAM,mBAAmB,GAAG,8CAA8C,CAAA;AAC1E,MAAM,oBAAoB,GAAG,kFAAkF,CAAA;AAE/G;;;;;GAKG;AACH,SAAgB,SAAS,CAAC,OAAe,EAAE,MAAc;IACvD,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;IACjC,IAAI,4CAA4C,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAC5D,OAAO,EAAE,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you are not the general-expert specialist, consider switching to a specialized agent in Copilot Chat. Run `npx aidoc-kit agents` to generate agent instruction files.
|
|
4
|
+
* @ai-runtime UNIVERSEL
|
|
5
|
+
*
|
|
6
|
+
* @ai-context
|
|
7
|
+
* [GENERATED] This file exports: getDependents, getDependencies, getCriticalFiles
|
|
8
|
+
* Imported by: src/cli.ts
|
|
9
|
+
*
|
|
10
|
+
* @ai-when-modifying
|
|
11
|
+
* 1. Check cascade files below before modifying
|
|
12
|
+
* 2. After modifying, ask the developer to run @ai-validate
|
|
13
|
+
* 3. If you have no terminal access, report the command to run
|
|
14
|
+
*
|
|
15
|
+
* @ai-cascade
|
|
16
|
+
* - src/cli.ts
|
|
17
|
+
*
|
|
18
|
+
* @ai-validate
|
|
19
|
+
* npm run typecheck
|
|
20
|
+
*/
|
|
21
|
+
import type { EnrichedGraph } from './types';
|
|
22
|
+
/** Files that import/call/reference the given file (direct dependents). */
|
|
23
|
+
export declare function getDependents(graph: EnrichedGraph, file: string): string[];
|
|
24
|
+
/** Files the given file imports/calls/references (direct dependencies). */
|
|
25
|
+
export declare function getDependencies(graph: EnrichedGraph, file: string): string[];
|
|
26
|
+
/** Files at or above a criticality level, most critical first. */
|
|
27
|
+
export declare function getCriticalFiles(graph: EnrichedGraph, minLevel?: 'medium' | 'high' | 'critical'): EnrichedGraph['files'];
|
|
28
|
+
//# sourceMappingURL=query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/graph/query.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAM5C,2EAA2E;AAC3E,wBAAgB,aAAa,CAAC,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAE1E;AAED,2EAA2E;AAC3E,wBAAgB,eAAe,CAAC,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAE5E;AAED,kEAAkE;AAClE,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,aAAa,EACpB,QAAQ,GAAE,QAAQ,GAAG,MAAM,GAAG,UAAmB,GAChD,aAAa,CAAC,OAAO,CAAC,CAKxB"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDependents = getDependents;
|
|
4
|
+
exports.getDependencies = getDependencies;
|
|
5
|
+
exports.getCriticalFiles = getCriticalFiles;
|
|
6
|
+
// Minimal query helpers over the enriched graph. Richer APIs (getCallers at
|
|
7
|
+
// symbol level, getImpact, search) are planned on top of the CodeGraph
|
|
8
|
+
// database itself — see ARCHITECTURE.md.
|
|
9
|
+
/** Files that import/call/reference the given file (direct dependents). */
|
|
10
|
+
function getDependents(graph, file) {
|
|
11
|
+
return [...new Set(graph.edges.filter(e => e.to === file).map(e => e.from))];
|
|
12
|
+
}
|
|
13
|
+
/** Files the given file imports/calls/references (direct dependencies). */
|
|
14
|
+
function getDependencies(graph, file) {
|
|
15
|
+
return [...new Set(graph.edges.filter(e => e.from === file).map(e => e.to))];
|
|
16
|
+
}
|
|
17
|
+
/** Files at or above a criticality level, most critical first. */
|
|
18
|
+
function getCriticalFiles(graph, minLevel = 'high') {
|
|
19
|
+
const order = { low: 0, medium: 1, high: 2, critical: 3 };
|
|
20
|
+
return graph.files
|
|
21
|
+
.filter(f => order[f.criticalityLevel] >= order[minLevel])
|
|
22
|
+
.sort((a, b) => b.criticality - a.criticality);
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.js","sourceRoot":"","sources":["../../src/graph/query.ts"],"names":[],"mappings":";;AA2BA,sCAEC;AAGD,0CAEC;AAGD,4CAQC;AAvBD,4EAA4E;AAC5E,uEAAuE;AACvE,yCAAyC;AAEzC,2EAA2E;AAC3E,SAAgB,aAAa,CAAC,KAAoB,EAAE,IAAY;IAC9D,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AAC9E,CAAC;AAED,2EAA2E;AAC3E,SAAgB,eAAe,CAAC,KAAoB,EAAE,IAAY;IAChE,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;AAC9E,CAAC;AAED,kEAAkE;AAClE,SAAgB,gBAAgB,CAC9B,KAAoB,EACpB,WAA2C,MAAM;IAEjD,MAAM,KAAK,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAA;IACzD,OAAO,KAAK,CAAC,KAAK;SACf,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,gBAAgB,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC;SACzD,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,GAAG,CAAC,CAAC,WAAW,CAAC,CAAA;AAClD,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { EnrichedGraph } from './types';
|
|
2
|
+
export declare const GRAPH_FILENAME = "aidoc-graph.json";
|
|
3
|
+
/**
|
|
4
|
+
* Write the enriched graph at the project root. Files and edges are already
|
|
5
|
+
* sorted by path in the loader, so successive runs produce stable diffs.
|
|
6
|
+
*/
|
|
7
|
+
export declare function writeEnrichedGraph(graph: EnrichedGraph, projectRoot: string): string;
|
|
8
|
+
/** Read a previously generated aidoc-graph.json, or null when absent/invalid. */
|
|
9
|
+
export declare function readEnrichedGraph(projectRoot: string): EnrichedGraph | null;
|
|
10
|
+
//# sourceMappingURL=serializer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializer.d.ts","sourceRoot":"","sources":["../../src/graph/serializer.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE5C,eAAO,MAAM,cAAc,qBAAqB,CAAA;AAEhD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAIpF;AAED,iFAAiF;AACjF,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI,CAS3E"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GRAPH_FILENAME = void 0;
|
|
4
|
+
exports.writeEnrichedGraph = writeEnrichedGraph;
|
|
5
|
+
exports.readEnrichedGraph = readEnrichedGraph;
|
|
6
|
+
/**
|
|
7
|
+
* @ai-agent general-expert
|
|
8
|
+
* @ai-agent-hint If you are not the general-expert specialist, consider switching to a specialized agent in Copilot Chat. Run `npx aidoc-kit agents` to generate agent instruction files.
|
|
9
|
+
* @ai-runtime UNIVERSEL
|
|
10
|
+
*
|
|
11
|
+
* @ai-context
|
|
12
|
+
* [GENERATED] This file exports: GRAPH_FILENAME, writeEnrichedGraph, readEnrichedGraph
|
|
13
|
+
* Imported by: src/cli.ts
|
|
14
|
+
*
|
|
15
|
+
* @ai-when-modifying
|
|
16
|
+
* 1. Check cascade files below before modifying
|
|
17
|
+
* 2. After modifying, ask the developer to run @ai-validate
|
|
18
|
+
* 3. If you have no terminal access, report the command to run
|
|
19
|
+
*
|
|
20
|
+
* @ai-cascade
|
|
21
|
+
* - src/cli.ts
|
|
22
|
+
*
|
|
23
|
+
* @ai-validate
|
|
24
|
+
* npm run typecheck
|
|
25
|
+
*/
|
|
26
|
+
const node_fs_1 = require("node:fs");
|
|
27
|
+
const node_path_1 = require("node:path");
|
|
28
|
+
exports.GRAPH_FILENAME = 'aidoc-graph.json';
|
|
29
|
+
/**
|
|
30
|
+
* Write the enriched graph at the project root. Files and edges are already
|
|
31
|
+
* sorted by path in the loader, so successive runs produce stable diffs.
|
|
32
|
+
*/
|
|
33
|
+
function writeEnrichedGraph(graph, projectRoot) {
|
|
34
|
+
const outPath = (0, node_path_1.join)(projectRoot, exports.GRAPH_FILENAME);
|
|
35
|
+
(0, node_fs_1.writeFileSync)(outPath, JSON.stringify(graph, null, 2) + '\n', 'utf-8');
|
|
36
|
+
return outPath;
|
|
37
|
+
}
|
|
38
|
+
/** Read a previously generated aidoc-graph.json, or null when absent/invalid. */
|
|
39
|
+
function readEnrichedGraph(projectRoot) {
|
|
40
|
+
const path = (0, node_path_1.join)(projectRoot, exports.GRAPH_FILENAME);
|
|
41
|
+
if (!(0, node_fs_1.existsSync)(path))
|
|
42
|
+
return null;
|
|
43
|
+
try {
|
|
44
|
+
const parsed = JSON.parse((0, node_fs_1.readFileSync)(path, 'utf-8'));
|
|
45
|
+
return parsed.version === 1 ? parsed : null;
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=serializer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializer.js","sourceRoot":"","sources":["../../src/graph/serializer.ts"],"names":[],"mappings":";;;AA8BA,gDAIC;AAGD,8CASC;AA9CD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qCAAiE;AACjE,yCAAgC;AAGnB,QAAA,cAAc,GAAG,kBAAkB,CAAA;AAEhD;;;GAGG;AACH,SAAgB,kBAAkB,CAAC,KAAoB,EAAE,WAAmB;IAC1E,MAAM,OAAO,GAAG,IAAA,gBAAI,EAAC,WAAW,EAAE,sBAAc,CAAC,CAAA;IACjD,IAAA,uBAAa,EAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,CAAC,CAAA;IACtE,OAAO,OAAO,CAAA;AAChB,CAAC;AAED,iFAAiF;AACjF,SAAgB,iBAAiB,CAAC,WAAmB;IACnD,MAAM,IAAI,GAAG,IAAA,gBAAI,EAAC,WAAW,EAAE,sBAAc,CAAC,CAAA;IAC9C,IAAI,CAAC,IAAA,oBAAU,EAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAA;IAClC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAA,sBAAY,EAAC,IAAI,EAAE,OAAO,CAAC,CAAkB,CAAA;QACvE,OAAO,MAAM,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAA;IAC7C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @ai-agent types-expert
|
|
3
|
+
* @ai-agent-hint If you are not the types-expert specialist, consider switching to a specialized agent in Copilot Chat. Run `npx aidoc-kit agents` to generate agent instruction files.
|
|
4
|
+
* @ai-runtime UNIVERSEL
|
|
5
|
+
*
|
|
6
|
+
* @ai-context
|
|
7
|
+
* [GENERATED] This file exports: RawFile, RawSymbol, RawFileEdge, RawGraph, FileRole, CriticalityLevel, EnrichedFile, EnrichedGraph
|
|
8
|
+
* Imported by: src/codegraph/loader.ts, src/enricher/basicEnricher.ts, src/graph/query.ts, src/graph/serializer.ts
|
|
9
|
+
*
|
|
10
|
+
* @ai-when-modifying
|
|
11
|
+
* 1. Check cascade files below before modifying
|
|
12
|
+
* 2. After modifying, ask the developer to run @ai-validate
|
|
13
|
+
* 3. If you have no terminal access, report the command to run
|
|
14
|
+
*
|
|
15
|
+
* @ai-cascade
|
|
16
|
+
* - src/codegraph/loader.ts
|
|
17
|
+
* - src/enricher/basicEnricher.ts
|
|
18
|
+
* - src/graph/query.ts
|
|
19
|
+
* - src/graph/serializer.ts
|
|
20
|
+
*
|
|
21
|
+
* @ai-validate
|
|
22
|
+
* npm run typecheck
|
|
23
|
+
*/
|
|
24
|
+
/** One indexed source file, as reported by CodeGraph. */
|
|
25
|
+
export interface RawFile {
|
|
26
|
+
/** Project-relative path */
|
|
27
|
+
path: string;
|
|
28
|
+
language: string;
|
|
29
|
+
symbolCount: number;
|
|
30
|
+
}
|
|
31
|
+
/** A symbol extracted by CodeGraph (subset of its `nodes` table). */
|
|
32
|
+
export interface RawSymbol {
|
|
33
|
+
id: string;
|
|
34
|
+
/** function, method, class, interface, constant, type_alias… */
|
|
35
|
+
kind: string;
|
|
36
|
+
name: string;
|
|
37
|
+
qualifiedName: string;
|
|
38
|
+
/** Project-relative path of the declaring file */
|
|
39
|
+
file: string;
|
|
40
|
+
startLine: number;
|
|
41
|
+
endLine: number;
|
|
42
|
+
exported: boolean;
|
|
43
|
+
}
|
|
44
|
+
/** A file-to-file relation aggregated from CodeGraph's symbol-level edges. */
|
|
45
|
+
export interface RawFileEdge {
|
|
46
|
+
from: string;
|
|
47
|
+
to: string;
|
|
48
|
+
/** imports, calls, references, extends… */
|
|
49
|
+
kind: string;
|
|
50
|
+
/** Number of symbol-level edges collapsed into this file-level edge */
|
|
51
|
+
count: number;
|
|
52
|
+
}
|
|
53
|
+
/** The raw knowledge graph read from `.codegraph/codegraph.db`. */
|
|
54
|
+
export interface RawGraph {
|
|
55
|
+
files: RawFile[];
|
|
56
|
+
symbols: RawSymbol[];
|
|
57
|
+
/** Cross-file edges only (same-file edges are dropped during aggregation) */
|
|
58
|
+
fileEdges: RawFileEdge[];
|
|
59
|
+
/** CodeGraph version that produced the index, when recorded */
|
|
60
|
+
codegraphVersion: string | null;
|
|
61
|
+
}
|
|
62
|
+
/** Execution role of a file, inferred by the enricher. */
|
|
63
|
+
export type FileRole = 'client' | 'server' | 'universal';
|
|
64
|
+
export type CriticalityLevel = 'low' | 'medium' | 'high' | 'critical';
|
|
65
|
+
/** One file with aidoc-kit's enrichment layered on top of the raw graph. */
|
|
66
|
+
export interface EnrichedFile {
|
|
67
|
+
file: string;
|
|
68
|
+
language: string;
|
|
69
|
+
role: FileRole;
|
|
70
|
+
/** How the role was determined — directive, path rule or content heuristic */
|
|
71
|
+
roleReason: string;
|
|
72
|
+
/** 0-100, see basicEnricher for the formula */
|
|
73
|
+
criticality: number;
|
|
74
|
+
criticalityLevel: CriticalityLevel;
|
|
75
|
+
/** Distinct files that import/call/reference this one */
|
|
76
|
+
inDegree: number;
|
|
77
|
+
/** Distinct files this one imports/calls/references */
|
|
78
|
+
outDegree: number;
|
|
79
|
+
/** Domain tags inferred from the path: api, auth, billing, payment… */
|
|
80
|
+
tags: string[];
|
|
81
|
+
symbolCount: number;
|
|
82
|
+
}
|
|
83
|
+
/** The enriched graph serialized to `aidoc-graph.json`. */
|
|
84
|
+
export interface EnrichedGraph {
|
|
85
|
+
/** Format version — bump on breaking changes to this shape */
|
|
86
|
+
version: 1;
|
|
87
|
+
generatedAt: string;
|
|
88
|
+
codegraph: {
|
|
89
|
+
version: string | null;
|
|
90
|
+
};
|
|
91
|
+
stats: {
|
|
92
|
+
files: number;
|
|
93
|
+
edges: number;
|
|
94
|
+
client: number;
|
|
95
|
+
server: number;
|
|
96
|
+
universal: number;
|
|
97
|
+
};
|
|
98
|
+
files: EnrichedFile[];
|
|
99
|
+
edges: RawFileEdge[];
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=types.d.ts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