ts-knowledge-graph 0.1.1 → 0.1.4
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 +104 -43
- package/contribs/web_visualisation/README.md +83 -0
- package/contribs/web_visualisation/web/css/style.css +219 -0
- package/contribs/web_visualisation/web/data/.gitignore +3 -0
- package/contribs/web_visualisation/web/data/kind_descriptions.js +38 -0
- package/contribs/web_visualisation/web/index.html +74 -0
- package/contribs/web_visualisation/web/js/app.js +910 -0
- package/contribs/web_visualisation/web/tsconfig.json +18 -0
- package/contribs/web_visualisation/web/types/app_globals.d.ts +146 -0
- package/dist/benchmark/benchmark_stats.d.ts +41 -0
- package/dist/benchmark/benchmark_stats.d.ts.map +1 -0
- package/dist/benchmark/benchmark_stats.js +61 -0
- package/dist/benchmark/benchmark_stats.js.map +1 -0
- package/dist/benchmark/node_benchmark.d.ts +78 -0
- package/dist/benchmark/node_benchmark.d.ts.map +1 -0
- package/dist/benchmark/node_benchmark.js +112 -0
- package/dist/benchmark/node_benchmark.js.map +1 -0
- package/dist/cli.d.ts +0 -9
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +32 -208
- package/dist/cli.js.map +1 -1
- package/dist/commands/benchmark_command.d.ts +11 -0
- package/dist/commands/benchmark_command.d.ts.map +1 -0
- package/dist/commands/benchmark_command.js +91 -0
- package/dist/commands/benchmark_command.js.map +1 -0
- package/dist/commands/blast_radius_command.d.ts +5 -0
- package/dist/commands/blast_radius_command.d.ts.map +1 -0
- package/dist/commands/blast_radius_command.js +18 -0
- package/dist/commands/blast_radius_command.js.map +1 -0
- package/dist/commands/calls_command.d.ts +5 -0
- package/dist/commands/calls_command.d.ts.map +1 -0
- package/dist/commands/calls_command.js +7 -0
- package/dist/commands/calls_command.js.map +1 -0
- package/dist/commands/command_helpers.d.ts +15 -0
- package/dist/commands/command_helpers.d.ts.map +1 -0
- package/dist/commands/command_helpers.js +61 -0
- package/dist/commands/command_helpers.js.map +1 -0
- package/dist/commands/cost_command.d.ts +13 -0
- package/dist/commands/cost_command.d.ts.map +1 -0
- package/dist/commands/cost_command.js +122 -0
- package/dist/commands/cost_command.js.map +1 -0
- package/dist/commands/dead_exports_command.d.ts +5 -0
- package/dist/commands/dead_exports_command.d.ts.map +1 -0
- package/dist/commands/dead_exports_command.js +7 -0
- package/dist/commands/dead_exports_command.js.map +1 -0
- package/dist/commands/enrich_command.d.ts +7 -0
- package/dist/commands/enrich_command.d.ts.map +1 -0
- package/dist/commands/enrich_command.js +62 -0
- package/dist/commands/enrich_command.js.map +1 -0
- package/dist/commands/extract_command.d.ts +8 -0
- package/dist/commands/extract_command.d.ts.map +1 -0
- package/dist/commands/extract_command.js +49 -0
- package/dist/commands/extract_command.js.map +1 -0
- package/dist/commands/find_command.d.ts +5 -0
- package/dist/commands/find_command.d.ts.map +1 -0
- package/dist/commands/find_command.js +7 -0
- package/dist/commands/find_command.js.map +1 -0
- package/dist/commands/hotspots_command.d.ts +7 -0
- package/dist/commands/hotspots_command.d.ts.map +1 -0
- package/dist/commands/hotspots_command.js +67 -0
- package/dist/commands/hotspots_command.js.map +1 -0
- package/dist/commands/install_command.d.ts +15 -0
- package/dist/commands/install_command.d.ts.map +1 -0
- package/dist/commands/install_command.js +41 -0
- package/dist/commands/install_command.js.map +1 -0
- package/dist/commands/load_command.d.ts +6 -0
- package/dist/commands/load_command.d.ts.map +1 -0
- package/dist/commands/load_command.js +30 -0
- package/dist/commands/load_command.js.map +1 -0
- package/dist/commands/neighbors_command.d.ts +5 -0
- package/dist/commands/neighbors_command.d.ts.map +1 -0
- package/dist/commands/neighbors_command.js +17 -0
- package/dist/commands/neighbors_command.js.map +1 -0
- package/dist/commands/references_command.d.ts +5 -0
- package/dist/commands/references_command.d.ts.map +1 -0
- package/dist/commands/references_command.js +17 -0
- package/dist/commands/references_command.js.map +1 -0
- package/dist/commands/verify_command.d.ts +8 -0
- package/dist/commands/verify_command.d.ts.map +1 -0
- package/dist/commands/verify_command.js +57 -0
- package/dist/commands/verify_command.js.map +1 -0
- package/dist/commands/web_command.d.ts +46 -0
- package/dist/commands/web_command.d.ts.map +1 -0
- package/dist/commands/web_command.js +226 -0
- package/dist/commands/web_command.js.map +1 -0
- package/dist/commands/who_calls_command.d.ts +5 -0
- package/dist/commands/who_calls_command.d.ts.map +1 -0
- package/dist/commands/who_calls_command.js +7 -0
- package/dist/commands/who_calls_command.js.map +1 -0
- package/dist/enrich/cpu_profile.d.ts +127 -0
- package/dist/enrich/cpu_profile.d.ts.map +1 -0
- package/dist/enrich/cpu_profile.js +97 -0
- package/dist/enrich/cpu_profile.js.map +1 -0
- package/dist/enrich/runtime_enricher.d.ts +56 -0
- package/dist/enrich/runtime_enricher.d.ts.map +1 -0
- package/dist/enrich/runtime_enricher.js +80 -0
- package/dist/enrich/runtime_enricher.js.map +1 -0
- package/dist/enrich/runtime_join.d.ts +100 -0
- package/dist/enrich/runtime_join.d.ts.map +1 -0
- package/dist/enrich/runtime_join.js +227 -0
- package/dist/enrich/runtime_join.js.map +1 -0
- package/dist/extract/api_extractor.d.ts +24 -0
- package/dist/extract/api_extractor.d.ts.map +1 -0
- package/dist/extract/api_extractor.js +71 -0
- package/dist/extract/api_extractor.js.map +1 -0
- package/dist/extract/config_extractor.d.ts +22 -0
- package/dist/extract/config_extractor.d.ts.map +1 -0
- package/dist/extract/config_extractor.js +61 -0
- package/dist/extract/config_extractor.js.map +1 -0
- package/dist/extract/endpoint_extractor.d.ts +36 -0
- package/dist/extract/endpoint_extractor.d.ts.map +1 -0
- package/dist/extract/endpoint_extractor.js +117 -0
- package/dist/extract/endpoint_extractor.js.map +1 -0
- package/dist/extract/{graph-builder.d.ts → graph_builder.d.ts} +9 -1
- package/dist/extract/graph_builder.d.ts.map +1 -0
- package/dist/extract/graph_builder.js +61 -0
- package/dist/extract/graph_builder.js.map +1 -0
- package/dist/extract/node_id.d.ts +24 -0
- package/dist/extract/node_id.d.ts.map +1 -0
- package/dist/extract/node_id.js +44 -0
- package/dist/extract/node_id.js.map +1 -0
- package/dist/extract/{project-loader.d.ts → project_loader.d.ts} +1 -1
- package/dist/extract/project_loader.d.ts.map +1 -0
- package/dist/extract/{project-loader.js → project_loader.js} +1 -1
- package/dist/extract/{project-loader.js.map → project_loader.js.map} +1 -1
- package/dist/extract/scope_resolver.d.ts +22 -0
- package/dist/extract/scope_resolver.d.ts.map +1 -0
- package/dist/extract/scope_resolver.js +53 -0
- package/dist/extract/scope_resolver.js.map +1 -0
- package/dist/extract/semantic_extractor.d.ts +47 -0
- package/dist/extract/semantic_extractor.d.ts.map +1 -0
- package/dist/extract/{semantic-extractor.js → semantic_extractor.js} +98 -4
- package/dist/extract/semantic_extractor.js.map +1 -0
- package/dist/extract/{structural-extractor.d.ts → structural_extractor.d.ts} +7 -1
- package/dist/extract/{structural-extractor.d.ts.map → structural_extractor.d.ts.map} +1 -1
- package/dist/extract/{structural-extractor.js → structural_extractor.js} +24 -14
- package/dist/extract/structural_extractor.js.map +1 -0
- package/dist/project_root.d.ts +7 -0
- package/dist/project_root.d.ts.map +1 -0
- package/dist/project_root.js +9 -0
- package/dist/project_root.js.map +1 -0
- package/dist/query/graph_query.d.ts +262 -0
- package/dist/query/graph_query.d.ts.map +1 -0
- package/dist/query/graph_query.js +604 -0
- package/dist/query/graph_query.js.map +1 -0
- package/dist/schema/edge.d.ts +40 -5
- package/dist/schema/edge.d.ts.map +1 -1
- package/dist/schema/edge.js +70 -0
- package/dist/schema/edge.js.map +1 -1
- package/dist/schema/node.d.ts +20 -5
- package/dist/schema/node.d.ts.map +1 -1
- package/dist/schema/node.js +36 -0
- package/dist/schema/node.js.map +1 -1
- package/dist/schema/runtime_manifest.d.ts +36 -0
- package/dist/schema/runtime_manifest.d.ts.map +1 -0
- package/dist/schema/runtime_manifest.js +23 -0
- package/dist/schema/runtime_manifest.js.map +1 -0
- package/dist/store/{jsonl-reader.d.ts → jsonl_reader.d.ts} +1 -1
- package/dist/store/{jsonl-reader.d.ts.map → jsonl_reader.d.ts.map} +1 -1
- package/dist/store/{jsonl-reader.js → jsonl_reader.js} +1 -1
- package/dist/store/{jsonl-reader.js.map → jsonl_reader.js.map} +1 -1
- package/dist/store/{jsonl-store.d.ts → jsonl_store.d.ts} +1 -1
- package/dist/store/{jsonl-store.d.ts.map → jsonl_store.d.ts.map} +1 -1
- package/dist/store/{jsonl-store.js → jsonl_store.js} +1 -1
- package/dist/store/{jsonl-store.js.map → jsonl_store.js.map} +1 -1
- package/dist/store/kuzu_store.d.ts +66 -0
- package/dist/store/kuzu_store.d.ts.map +1 -0
- package/dist/store/kuzu_store.js +156 -0
- package/dist/store/kuzu_store.js.map +1 -0
- package/dist/verify/project_verifier.d.ts +85 -0
- package/dist/verify/project_verifier.d.ts.map +1 -0
- package/dist/verify/project_verifier.js +138 -0
- package/dist/verify/project_verifier.js.map +1 -0
- package/dotclaude_folder/skills/code-graph-query/SKILL.md +91 -0
- package/package.json +88 -5
- package/.env-sample +0 -34
- package/dist/agent/agent-tools.d.ts +0 -13
- package/dist/agent/agent-tools.d.ts.map +0 -1
- package/dist/agent/agent-tools.js +0 -153
- package/dist/agent/agent-tools.js.map +0 -1
- package/dist/agent/code-editor.d.ts +0 -18
- package/dist/agent/code-editor.d.ts.map +0 -1
- package/dist/agent/code-editor.js +0 -43
- package/dist/agent/code-editor.js.map +0 -1
- package/dist/agent/optimizer-agent.d.ts +0 -30
- package/dist/agent/optimizer-agent.d.ts.map +0 -1
- package/dist/agent/optimizer-agent.js +0 -97
- package/dist/agent/optimizer-agent.js.map +0 -1
- package/dist/agent/verifier.d.ts +0 -9
- package/dist/agent/verifier.d.ts.map +0 -1
- package/dist/agent/verifier.js +0 -19
- package/dist/agent/verifier.js.map +0 -1
- package/dist/extract/graph-builder.d.ts.map +0 -1
- package/dist/extract/graph-builder.js +0 -39
- package/dist/extract/graph-builder.js.map +0 -1
- package/dist/extract/node-id.d.ts +0 -8
- package/dist/extract/node-id.d.ts.map +0 -1
- package/dist/extract/node-id.js +0 -22
- package/dist/extract/node-id.js.map +0 -1
- package/dist/extract/project-loader.d.ts.map +0 -1
- package/dist/extract/semantic-extractor.d.ts +0 -22
- package/dist/extract/semantic-extractor.d.ts.map +0 -1
- package/dist/extract/semantic-extractor.js.map +0 -1
- package/dist/extract/structural-extractor.js.map +0 -1
- package/dist/query/graph-query.d.ts +0 -28
- package/dist/query/graph-query.d.ts.map +0 -1
- package/dist/query/graph-query.js +0 -93
- package/dist/query/graph-query.js.map +0 -1
- package/dist/store/kuzu-store.d.ts +0 -14
- package/dist/store/kuzu-store.d.ts.map +0 -1
- package/dist/store/kuzu-store.js +0 -52
- package/dist/store/kuzu-store.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify_command.d.ts","sourceRoot":"","sources":["../../src/commands/verify_command.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAYpC,qBAAa,aAAa;IACzB,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAuBvC,OAAO,CAAC,MAAM,CAAC,KAAK;IAapB,OAAO,CAAC,MAAM,CAAC,UAAU;IAUzB,OAAO,CAAC,MAAM,CAAC,kBAAkB;CASjC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { ProjectVerifier } from '../verify/project_verifier.js';
|
|
3
|
+
export class VerifyCommand {
|
|
4
|
+
static register(program) {
|
|
5
|
+
program
|
|
6
|
+
.command('verify')
|
|
7
|
+
.description('run the project type-check + test gates and return one keep/revert verdict for an edit')
|
|
8
|
+
.option('-C, --cwd <path>', 'project directory whose package.json scripts are run', process.cwd())
|
|
9
|
+
.option('--typecheck-script <name>', 'npm script for the type-check gate', 'typecheck')
|
|
10
|
+
.option('--test-script <name>', 'npm script for the test gate', 'test')
|
|
11
|
+
.option('--skip-typecheck', 'skip the type-check gate', false)
|
|
12
|
+
.option('--skip-tests', 'skip the test gate (degrades to type-check-only)', false)
|
|
13
|
+
.option('--json', 'emit the verdict as JSON', false)
|
|
14
|
+
.action(async (options) => {
|
|
15
|
+
const report = await ProjectVerifier.verify({
|
|
16
|
+
cwd: options.cwd,
|
|
17
|
+
typecheckScript: options.typecheckScript,
|
|
18
|
+
testScript: options.testScript,
|
|
19
|
+
skipTypecheck: options.skipTypecheck === true,
|
|
20
|
+
skipTests: options.skipTests === true,
|
|
21
|
+
});
|
|
22
|
+
VerifyCommand.print(report, options.json === true);
|
|
23
|
+
process.exitCode = report.ok === true ? 0 : 1;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
static print(report, json) {
|
|
27
|
+
if (json === true) {
|
|
28
|
+
console.log(JSON.stringify(report, null, 2));
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
for (const check of report.checks) {
|
|
32
|
+
VerifyCommand.printCheck(check);
|
|
33
|
+
}
|
|
34
|
+
const verdict = report.ok === true ? chalk.green('✓') : chalk.red('✗');
|
|
35
|
+
console.log(`\n${verdict} ${report.summary}`);
|
|
36
|
+
VerifyCommand.printFailureOutput(report);
|
|
37
|
+
}
|
|
38
|
+
static printCheck(check) {
|
|
39
|
+
if (check.status === 'skipped') {
|
|
40
|
+
console.log(`${chalk.yellow('•')} ${chalk.bold(check.name.padEnd(10))} ${chalk.yellow('skipped')} ${chalk.gray(check.skippedReason ?? '')}`);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const mark = check.status === 'pass' ? chalk.green('✓') : chalk.red('✗');
|
|
44
|
+
const timing = chalk.gray(`${(check.durationMs / 1000).toFixed(1)}s`);
|
|
45
|
+
console.log(`${mark} ${chalk.bold(check.name.padEnd(10))} ${chalk.gray(check.command ?? '')} ${timing}`);
|
|
46
|
+
}
|
|
47
|
+
static printFailureOutput(report) {
|
|
48
|
+
if (report.ok === true) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
for (const check of report.checks.filter((candidate) => candidate.status === 'fail')) {
|
|
52
|
+
console.log(chalk.bold(`\n— ${check.name} output (tail) —`));
|
|
53
|
+
console.log(check.output.trimEnd());
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=verify_command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify_command.js","sourceRoot":"","sources":["../../src/commands/verify_command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAe,eAAe,EAAgB,MAAM,+BAA+B,CAAC;AAW3F,MAAM,OAAO,aAAa;IACzB,MAAM,CAAC,QAAQ,CAAC,OAAgB;QAC/B,OAAO;aACL,OAAO,CAAC,QAAQ,CAAC;aACjB,WAAW,CAAC,wFAAwF,CAAC;aACrG,MAAM,CAAC,kBAAkB,EAAE,sDAAsD,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC;aACjG,MAAM,CAAC,2BAA2B,EAAE,oCAAoC,EAAE,WAAW,CAAC;aACtF,MAAM,CAAC,sBAAsB,EAAE,8BAA8B,EAAE,MAAM,CAAC;aACtE,MAAM,CAAC,kBAAkB,EAAE,0BAA0B,EAAE,KAAK,CAAC;aAC7D,MAAM,CAAC,cAAc,EAAE,kDAAkD,EAAE,KAAK,CAAC;aACjF,MAAM,CAAC,QAAQ,EAAE,0BAA0B,EAAE,KAAK,CAAC;aACnD,MAAM,CAAC,KAAK,EAAE,OAA6B,EAAE,EAAE;YAC/C,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC,MAAM,CAAC;gBAC3C,GAAG,EAAE,OAAO,CAAC,GAAG;gBAChB,eAAe,EAAE,OAAO,CAAC,eAAe;gBACxC,UAAU,EAAE,OAAO,CAAC,UAAU;gBAC9B,aAAa,EAAE,OAAO,CAAC,aAAa,KAAK,IAAI;gBAC7C,SAAS,EAAE,OAAO,CAAC,SAAS,KAAK,IAAI;aACrC,CAAC,CAAC;YACH,aAAa,CAAC,KAAK,CAAC,MAAM,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9I,OAAO;QACR,CAAC;QACD,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACzE,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QACtE,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,IAAI,EAAE,CAAC,KAAK,MAAM,EAAE,CAAC,CAAC;IAC3G,CAAC;IAEO,MAAM,CAAC,kBAAkB,CAAC,MAAoB;QACrD,IAAI,MAAM,CAAC,EAAE,KAAK,IAAI,EAAE,CAAC;YACxB,OAAO;QACR,CAAC;QACD,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,KAAK,MAAM,CAAC,EAAE,CAAC;YACtF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,KAAK,CAAC,IAAI,kBAAkB,CAAC,CAAC,CAAC;YAC7D,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;QACrC,CAAC;IACF,CAAC;CACD"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
/**
|
|
3
|
+
* `web` command — serves the knowledge graph database in an interactive web
|
|
4
|
+
* visualisation. The graph is read from Kùzu once at startup and injected into
|
|
5
|
+
* the page as `/data/graph_data.js`; all other assets are served statically
|
|
6
|
+
* from the contribs/web_visualisation/web directory.
|
|
7
|
+
*/
|
|
8
|
+
export declare class WebCommand {
|
|
9
|
+
static register(program: Command): void;
|
|
10
|
+
private static run;
|
|
11
|
+
/**
|
|
12
|
+
* Reads every node and edge from the database and renders them as the
|
|
13
|
+
* `window.GRAPH_DATA` script the visualisation page loads on boot.
|
|
14
|
+
*/
|
|
15
|
+
private static buildDataScript;
|
|
16
|
+
/**
|
|
17
|
+
* Decodes the JSON `metadata` column into a record so the visualisation can
|
|
18
|
+
* read `metadata.runtime`. A missing, empty (`{}`), or malformed value yields
|
|
19
|
+
* `undefined`, which `JSON.stringify` omits — keeping the payload small and
|
|
20
|
+
* letting un-enriched nodes simply carry no metadata.
|
|
21
|
+
*/
|
|
22
|
+
private static decodeMetadata;
|
|
23
|
+
/**
|
|
24
|
+
* Renders the `window.GRAPH_SOURCE` script that lets the visualisation link
|
|
25
|
+
* file paths to GitHub. Returns an empty string when `sourceDir` is not a
|
|
26
|
+
* GitHub work tree, so the page falls back to plain-text file paths.
|
|
27
|
+
*/
|
|
28
|
+
private static buildSourceScript;
|
|
29
|
+
/**
|
|
30
|
+
* Detects the GitHub repository, HEAD commit, and in-repo path prefix for the
|
|
31
|
+
* directory the graph was extracted from. Returns `undefined` when `sourceDir`
|
|
32
|
+
* is not a Git work tree, has no GitHub `origin` remote, or Git is unavailable.
|
|
33
|
+
*/
|
|
34
|
+
private static detectGitHubSource;
|
|
35
|
+
/**
|
|
36
|
+
* Normalises a Git `origin` URL to its GitHub web base
|
|
37
|
+
* (`https://<host>/<owner>/<repo>`), or `undefined` for non-GitHub remotes.
|
|
38
|
+
* Handles the SCP-like (`git@host:owner/repo.git`), `https://`, `git://`, and
|
|
39
|
+
* `ssh://` forms, with or without a trailing `.git`. The host is kept as-is so
|
|
40
|
+
* GitHub Enterprise remotes resolve to their own domain.
|
|
41
|
+
*/
|
|
42
|
+
static githubBaseUrl(remoteUrl: string): string | undefined;
|
|
43
|
+
private static handle;
|
|
44
|
+
private static notFound;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=web_command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web_command.d.ts","sourceRoot":"","sources":["../../src/commands/web_command.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA4CpC;;;;;GAKG;AACH,qBAAa,UAAU;IACtB,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;mBAYlB,GAAG;IAoBxB;;;OAGG;mBACkB,eAAe;IAsCpC;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,cAAc;IAe7B;;;;OAIG;mBACkB,iBAAiB;IAUtC;;;;OAIG;mBACkB,kBAAkB;IAsBvC;;;;;;OAMG;IACH,MAAM,CAAC,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;mBA8BtC,MAAM;IAwB3B,OAAO,CAAC,MAAM,CAAC,QAAQ;CAIvB"}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { readFile } from 'node:fs/promises';
|
|
4
|
+
import { createServer } from 'node:http';
|
|
5
|
+
import { extname, join, normalize, resolve, sep } from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { promisify } from 'node:util';
|
|
8
|
+
import chalk from 'chalk';
|
|
9
|
+
import { KuzuStore } from '../store/kuzu_store.js';
|
|
10
|
+
import { DEFAULT_DB_PATH } from './command_helpers.js';
|
|
11
|
+
const execFileAsync = promisify(execFile);
|
|
12
|
+
/**
|
|
13
|
+
* Static assets of the web visualisation, resolved relative to this module so
|
|
14
|
+
* the same path works from `src/` (tsx) and from `dist/` (published package).
|
|
15
|
+
*/
|
|
16
|
+
const WEB_ROOT = fileURLToPath(new URL('../../contribs/web_visualisation/web', import.meta.url));
|
|
17
|
+
const DATA_SCRIPT_PATH = '/data/graph_data.js';
|
|
18
|
+
const DEFAULT_PORT = '4173';
|
|
19
|
+
const MIME_TYPES = {
|
|
20
|
+
'.css': 'text/css; charset=utf-8',
|
|
21
|
+
'.html': 'text/html; charset=utf-8',
|
|
22
|
+
'.js': 'text/javascript; charset=utf-8',
|
|
23
|
+
'.json': 'application/json; charset=utf-8',
|
|
24
|
+
'.png': 'image/png',
|
|
25
|
+
'.svg': 'image/svg+xml',
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* `web` command — serves the knowledge graph database in an interactive web
|
|
29
|
+
* visualisation. The graph is read from Kùzu once at startup and injected into
|
|
30
|
+
* the page as `/data/graph_data.js`; all other assets are served statically
|
|
31
|
+
* from the contribs/web_visualisation/web directory.
|
|
32
|
+
*/
|
|
33
|
+
export class WebCommand {
|
|
34
|
+
static register(program) {
|
|
35
|
+
program
|
|
36
|
+
.command('web')
|
|
37
|
+
.description('serve the knowledge graph database in a web visualisation')
|
|
38
|
+
.option('-d, --db <path>', 'Kùzu database path', DEFAULT_DB_PATH)
|
|
39
|
+
.option('-p, --port <port>', 'HTTP port to listen on', DEFAULT_PORT)
|
|
40
|
+
.option('-s, --source <dir>', 'project root the graph was extracted from, used to link files to GitHub', '.')
|
|
41
|
+
.action(async (options) => {
|
|
42
|
+
await WebCommand.run(options);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
static async run(options) {
|
|
46
|
+
const dbPath = resolve(options.db);
|
|
47
|
+
if (existsSync(dbPath) === false) {
|
|
48
|
+
console.error(chalk.red(`database not found at ${dbPath} — run \`extract\` then \`load\` first`));
|
|
49
|
+
process.exitCode = 1;
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const sourceScript = await WebCommand.buildSourceScript(resolve(options.source));
|
|
53
|
+
const dataScript = sourceScript + await WebCommand.buildDataScript(dbPath);
|
|
54
|
+
const server = createServer((request, response) => {
|
|
55
|
+
void WebCommand.handle(request, response, dataScript);
|
|
56
|
+
});
|
|
57
|
+
server.listen(Number(options.port), () => {
|
|
58
|
+
console.log(chalk.green(`✓ serving the knowledge graph at http://localhost:${options.port}/`));
|
|
59
|
+
console.log(chalk.gray(' press Ctrl+C to stop'));
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Reads every node and edge from the database and renders them as the
|
|
64
|
+
* `window.GRAPH_DATA` script the visualisation page loads on boot.
|
|
65
|
+
*/
|
|
66
|
+
static async buildDataScript(dbPath) {
|
|
67
|
+
const store = new KuzuStore(dbPath);
|
|
68
|
+
await store.initSchema();
|
|
69
|
+
try {
|
|
70
|
+
const nodeRows = await store.run('MATCH (n:GraphNode) RETURN n.id AS id, n.kind AS kind, n.name AS name, n.filePath AS filePath, n.exported AS exported, n.startLine AS startLine, n.endLine AS endLine, n.metadata AS metadata');
|
|
71
|
+
const edgeRows = await store.run('MATCH (f:GraphNode)-[e:Edge]->(t:GraphNode) RETURN f.id AS from, e.kind AS kind, t.id AS to, e.metadata AS metadata');
|
|
72
|
+
const nodes = nodeRows.map((row) => ({
|
|
73
|
+
id: String(row.id),
|
|
74
|
+
kind: String(row.kind),
|
|
75
|
+
name: String(row.name),
|
|
76
|
+
filePath: String(row.filePath),
|
|
77
|
+
exported: row.exported === true,
|
|
78
|
+
range: {
|
|
79
|
+
startLine: Number(row.startLine),
|
|
80
|
+
startColumn: 0,
|
|
81
|
+
endLine: Number(row.endLine),
|
|
82
|
+
endColumn: 0,
|
|
83
|
+
},
|
|
84
|
+
metadata: WebCommand.decodeMetadata(row.metadata),
|
|
85
|
+
}));
|
|
86
|
+
const edges = edgeRows.map((row, index) => ({
|
|
87
|
+
id: `e${index}`,
|
|
88
|
+
kind: String(row.kind),
|
|
89
|
+
from: String(row.from),
|
|
90
|
+
to: String(row.to),
|
|
91
|
+
metadata: WebCommand.decodeMetadata(row.metadata),
|
|
92
|
+
}));
|
|
93
|
+
console.log(chalk.cyan(`loaded ${nodes.length} nodes, ${edges.length} edges from ${dbPath}`));
|
|
94
|
+
return `window.GRAPH_DATA = ${JSON.stringify({ nodes, edges })};\n`;
|
|
95
|
+
}
|
|
96
|
+
finally {
|
|
97
|
+
await store.close();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Decodes the JSON `metadata` column into a record so the visualisation can
|
|
102
|
+
* read `metadata.runtime`. A missing, empty (`{}`), or malformed value yields
|
|
103
|
+
* `undefined`, which `JSON.stringify` omits — keeping the payload small and
|
|
104
|
+
* letting un-enriched nodes simply carry no metadata.
|
|
105
|
+
*/
|
|
106
|
+
static decodeMetadata(value) {
|
|
107
|
+
if (typeof value !== 'string' || value.length === 0) {
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
try {
|
|
111
|
+
const parsed = JSON.parse(value);
|
|
112
|
+
if (typeof parsed === 'object' && parsed !== null && Object.keys(parsed).length > 0) {
|
|
113
|
+
return parsed;
|
|
114
|
+
}
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Renders the `window.GRAPH_SOURCE` script that lets the visualisation link
|
|
123
|
+
* file paths to GitHub. Returns an empty string when `sourceDir` is not a
|
|
124
|
+
* GitHub work tree, so the page falls back to plain-text file paths.
|
|
125
|
+
*/
|
|
126
|
+
static async buildSourceScript(sourceDir) {
|
|
127
|
+
const github = await WebCommand.detectGitHubSource(sourceDir);
|
|
128
|
+
if (github === undefined) {
|
|
129
|
+
console.log(chalk.gray('no GitHub remote detected — file paths will not link to source'));
|
|
130
|
+
return '';
|
|
131
|
+
}
|
|
132
|
+
console.log(chalk.cyan(`linking files to ${github.baseUrl} @ ${github.commit.slice(0, 7)}`));
|
|
133
|
+
return `window.GRAPH_SOURCE = ${JSON.stringify({ github })};\n`;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Detects the GitHub repository, HEAD commit, and in-repo path prefix for the
|
|
137
|
+
* directory the graph was extracted from. Returns `undefined` when `sourceDir`
|
|
138
|
+
* is not a Git work tree, has no GitHub `origin` remote, or Git is unavailable.
|
|
139
|
+
*/
|
|
140
|
+
static async detectGitHubSource(sourceDir) {
|
|
141
|
+
const git = async (...args) => {
|
|
142
|
+
try {
|
|
143
|
+
const { stdout } = await execFileAsync('git', ['-C', sourceDir, ...args]);
|
|
144
|
+
return stdout.trim();
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
if (await git('rev-parse', '--is-inside-work-tree') !== 'true') {
|
|
151
|
+
return undefined;
|
|
152
|
+
}
|
|
153
|
+
const remoteUrl = await git('remote', 'get-url', 'origin');
|
|
154
|
+
const commit = await git('rev-parse', 'HEAD');
|
|
155
|
+
const baseUrl = remoteUrl === undefined ? undefined : WebCommand.githubBaseUrl(remoteUrl);
|
|
156
|
+
if (baseUrl === undefined || commit === undefined) {
|
|
157
|
+
return undefined;
|
|
158
|
+
}
|
|
159
|
+
return { baseUrl, commit, prefix: await git('rev-parse', '--show-prefix') ?? '' };
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Normalises a Git `origin` URL to its GitHub web base
|
|
163
|
+
* (`https://<host>/<owner>/<repo>`), or `undefined` for non-GitHub remotes.
|
|
164
|
+
* Handles the SCP-like (`git@host:owner/repo.git`), `https://`, `git://`, and
|
|
165
|
+
* `ssh://` forms, with or without a trailing `.git`. The host is kept as-is so
|
|
166
|
+
* GitHub Enterprise remotes resolve to their own domain.
|
|
167
|
+
*/
|
|
168
|
+
static githubBaseUrl(remoteUrl) {
|
|
169
|
+
const trimmed = remoteUrl.trim();
|
|
170
|
+
let host;
|
|
171
|
+
let path;
|
|
172
|
+
if (trimmed.includes('://') === true) {
|
|
173
|
+
try {
|
|
174
|
+
const parsed = new URL(trimmed);
|
|
175
|
+
host = parsed.host;
|
|
176
|
+
path = parsed.pathname;
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
return undefined;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
const scpMatch = trimmed.match(/^[^@]+@([^:]+):(.+)$/);
|
|
184
|
+
if (scpMatch === null) {
|
|
185
|
+
return undefined;
|
|
186
|
+
}
|
|
187
|
+
host = scpMatch[1];
|
|
188
|
+
path = scpMatch[2];
|
|
189
|
+
}
|
|
190
|
+
if (host.toLowerCase().includes('github') === false) {
|
|
191
|
+
return undefined;
|
|
192
|
+
}
|
|
193
|
+
const segments = path.replace(/\.git$/, '').split('/').filter((segment) => segment.length > 0);
|
|
194
|
+
if (segments.length < 2) {
|
|
195
|
+
return undefined;
|
|
196
|
+
}
|
|
197
|
+
return `https://${host}/${segments[0]}/${segments[1]}`;
|
|
198
|
+
}
|
|
199
|
+
static async handle(request, response, dataScript) {
|
|
200
|
+
const url = new URL(request.url ?? '/', 'http://localhost');
|
|
201
|
+
const pathname = url.pathname === '/' ? '/index.html' : url.pathname;
|
|
202
|
+
if (pathname === DATA_SCRIPT_PATH) {
|
|
203
|
+
response.writeHead(200, { 'content-type': MIME_TYPES['.js'] });
|
|
204
|
+
response.end(dataScript);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
const filePath = normalize(join(WEB_ROOT, pathname));
|
|
208
|
+
if (filePath.startsWith(WEB_ROOT + sep) === false) {
|
|
209
|
+
WebCommand.notFound(response);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
try {
|
|
213
|
+
const content = await readFile(filePath);
|
|
214
|
+
response.writeHead(200, { 'content-type': MIME_TYPES[extname(filePath)] ?? 'application/octet-stream' });
|
|
215
|
+
response.end(content);
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
WebCommand.notFound(response);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
static notFound(response) {
|
|
222
|
+
response.writeHead(404, { 'content-type': 'text/plain; charset=utf-8' });
|
|
223
|
+
response.end('not found');
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
//# sourceMappingURL=web_command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web_command.js","sourceRoot":"","sources":["../../src/commands/web_command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAE1C;;;GAGG;AACH,MAAM,QAAQ,GAAG,aAAa,CAAC,IAAI,GAAG,CAAC,sCAAsC,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAEjG,MAAM,gBAAgB,GAAG,qBAAqB,CAAC;AAC/C,MAAM,YAAY,GAAG,MAAM,CAAC;AAE5B,MAAM,UAAU,GAA2B;IAC1C,MAAM,EAAE,yBAAyB;IACjC,OAAO,EAAE,0BAA0B;IACnC,KAAK,EAAE,gCAAgC;IACvC,OAAO,EAAE,iCAAiC;IAC1C,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,eAAe;CACvB,CAAC;AAsBF;;;;;GAKG;AACH,MAAM,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CAAC;YACzC,QAAQ,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,0BAA0B,EAAE,CAAC,CAAC;YACzG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;QAAC,MAAM,CAAC;YACR,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAC/B,CAAC;IACF,CAAC;IAEO,MAAM,CAAC,QAAQ,CAAC,QAAwB;QAC/C,QAAQ,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,2BAA2B,EAAE,CAAC,CAAC;QACzE,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAC3B,CAAC;CACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"who_calls_command.d.ts","sourceRoot":"","sources":["../../src/commands/who_calls_command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,qBAAa,eAAe;IAC3B,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;CAIvC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CommandHelpers } from './command_helpers.js';
|
|
2
|
+
export class WhoCallsCommand {
|
|
3
|
+
static register(program) {
|
|
4
|
+
CommandHelpers.registerSymbolQuery(program, 'who-calls', '<id>', 'list symbols that call <id>', (query, arg) => query.whoCalls(arg));
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=who_calls_command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"who_calls_command.js","sourceRoot":"","sources":["../../src/commands/who_calls_command.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,MAAM,OAAO,eAAe;IAC3B,MAAM,CAAC,QAAQ,CAAC,OAAgB;QAC/B,cAAc,CAAC,mBAAmB,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,6BAA6B,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CAC9G,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;IACvB,CAAC;CACD"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* The on-disk shape of a `node --cpu-prof` output (`.cpuprofile`). `samples`
|
|
4
|
+
* holds one profile-node id per sampling tick; `timeDeltas` holds the elapsed
|
|
5
|
+
* microseconds preceding each tick. Both are optional because some producers
|
|
6
|
+
* emit only per-node `hitCount`.
|
|
7
|
+
*/
|
|
8
|
+
export declare const CpuProfileSchema: z.ZodObject<{
|
|
9
|
+
nodes: z.ZodArray<z.ZodObject<{
|
|
10
|
+
id: z.ZodNumber;
|
|
11
|
+
callFrame: z.ZodObject<{
|
|
12
|
+
functionName: z.ZodString;
|
|
13
|
+
scriptId: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
|
|
14
|
+
url: z.ZodString;
|
|
15
|
+
lineNumber: z.ZodNumber;
|
|
16
|
+
columnNumber: z.ZodNumber;
|
|
17
|
+
}, "strip", z.ZodTypeAny, {
|
|
18
|
+
functionName: string;
|
|
19
|
+
url: string;
|
|
20
|
+
lineNumber: number;
|
|
21
|
+
columnNumber: number;
|
|
22
|
+
scriptId?: string | number | undefined;
|
|
23
|
+
}, {
|
|
24
|
+
functionName: string;
|
|
25
|
+
url: string;
|
|
26
|
+
lineNumber: number;
|
|
27
|
+
columnNumber: number;
|
|
28
|
+
scriptId?: string | number | undefined;
|
|
29
|
+
}>;
|
|
30
|
+
hitCount: z.ZodOptional<z.ZodNumber>;
|
|
31
|
+
children: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
|
|
32
|
+
}, "strip", z.ZodTypeAny, {
|
|
33
|
+
id: number;
|
|
34
|
+
callFrame: {
|
|
35
|
+
functionName: string;
|
|
36
|
+
url: string;
|
|
37
|
+
lineNumber: number;
|
|
38
|
+
columnNumber: number;
|
|
39
|
+
scriptId?: string | number | undefined;
|
|
40
|
+
};
|
|
41
|
+
hitCount?: number | undefined;
|
|
42
|
+
children?: number[] | undefined;
|
|
43
|
+
}, {
|
|
44
|
+
id: number;
|
|
45
|
+
callFrame: {
|
|
46
|
+
functionName: string;
|
|
47
|
+
url: string;
|
|
48
|
+
lineNumber: number;
|
|
49
|
+
columnNumber: number;
|
|
50
|
+
scriptId?: string | number | undefined;
|
|
51
|
+
};
|
|
52
|
+
hitCount?: number | undefined;
|
|
53
|
+
children?: number[] | undefined;
|
|
54
|
+
}>, "many">;
|
|
55
|
+
startTime: z.ZodOptional<z.ZodNumber>;
|
|
56
|
+
endTime: z.ZodOptional<z.ZodNumber>;
|
|
57
|
+
samples: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
|
|
58
|
+
timeDeltas: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
|
|
59
|
+
}, "strip", z.ZodTypeAny, {
|
|
60
|
+
nodes: {
|
|
61
|
+
id: number;
|
|
62
|
+
callFrame: {
|
|
63
|
+
functionName: string;
|
|
64
|
+
url: string;
|
|
65
|
+
lineNumber: number;
|
|
66
|
+
columnNumber: number;
|
|
67
|
+
scriptId?: string | number | undefined;
|
|
68
|
+
};
|
|
69
|
+
hitCount?: number | undefined;
|
|
70
|
+
children?: number[] | undefined;
|
|
71
|
+
}[];
|
|
72
|
+
startTime?: number | undefined;
|
|
73
|
+
endTime?: number | undefined;
|
|
74
|
+
samples?: number[] | undefined;
|
|
75
|
+
timeDeltas?: number[] | undefined;
|
|
76
|
+
}, {
|
|
77
|
+
nodes: {
|
|
78
|
+
id: number;
|
|
79
|
+
callFrame: {
|
|
80
|
+
functionName: string;
|
|
81
|
+
url: string;
|
|
82
|
+
lineNumber: number;
|
|
83
|
+
columnNumber: number;
|
|
84
|
+
scriptId?: string | number | undefined;
|
|
85
|
+
};
|
|
86
|
+
hitCount?: number | undefined;
|
|
87
|
+
children?: number[] | undefined;
|
|
88
|
+
}[];
|
|
89
|
+
startTime?: number | undefined;
|
|
90
|
+
endTime?: number | undefined;
|
|
91
|
+
samples?: number[] | undefined;
|
|
92
|
+
timeDeltas?: number[] | undefined;
|
|
93
|
+
}>;
|
|
94
|
+
export type CpuProfileData = z.infer<typeof CpuProfileSchema>;
|
|
95
|
+
/**
|
|
96
|
+
* One executing location distilled from the profile: its call frame plus the
|
|
97
|
+
* self time and sample count attributed to it. `line` is converted to the
|
|
98
|
+
* one-based convention so it can be compared against graph node ranges.
|
|
99
|
+
*/
|
|
100
|
+
export type FrameSample = {
|
|
101
|
+
functionName: string;
|
|
102
|
+
url: string;
|
|
103
|
+
line: number;
|
|
104
|
+
column: number;
|
|
105
|
+
samples: number;
|
|
106
|
+
selfMicros: number;
|
|
107
|
+
};
|
|
108
|
+
export declare class CpuProfile {
|
|
109
|
+
/**
|
|
110
|
+
* Parses and validates raw `.cpuprofile` JSON text. Throws a `ZodError` if
|
|
111
|
+
* the document does not match the V8 profile shape.
|
|
112
|
+
*/
|
|
113
|
+
static parse(jsonText: string): CpuProfileData;
|
|
114
|
+
/**
|
|
115
|
+
* Collapses the profile into one {@link FrameSample} per profile node that
|
|
116
|
+
* received at least one sample.
|
|
117
|
+
*
|
|
118
|
+
* Self time is summed from `timeDeltas`, attributing `timeDeltas[i]` to
|
|
119
|
+
* `samples[i]` — the standard self-time approximation where total attributed
|
|
120
|
+
* time equals the sum of all deltas. When `samples`/`timeDeltas` are absent,
|
|
121
|
+
* it falls back to each node's `hitCount` with zero self time.
|
|
122
|
+
*/
|
|
123
|
+
static aggregate(profile: CpuProfileData): FrameSample[];
|
|
124
|
+
/** Total number of sampling ticks in the profile, for coverage reporting. */
|
|
125
|
+
static totalSamples(profile: CpuProfileData): number;
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=cpu_profile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cpu_profile.d.ts","sourceRoot":"","sources":["../../src/enrich/cpu_profile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAsBxB;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAM3B,CAAC;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE9D;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,qBAAa,UAAU;IACtB;;;OAGG;IACH,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc;IAI9C;;;;;;;;OAQG;IACH,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,cAAc,GAAG,WAAW,EAAE;IAyCxD,6EAA6E;IAC7E,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM;CAMpD"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* A single call frame as it appears in a V8 CPU profile node. Line and column
|
|
4
|
+
* numbers are **zero-based** in the V8 inspector protocol, unlike the one-based
|
|
5
|
+
* lines ts-morph (and therefore the graph's `range`) uses.
|
|
6
|
+
*/
|
|
7
|
+
const CallFrameSchema = z.object({
|
|
8
|
+
functionName: z.string(),
|
|
9
|
+
scriptId: z.union([z.string(), z.number()]).optional(),
|
|
10
|
+
url: z.string(),
|
|
11
|
+
lineNumber: z.number(),
|
|
12
|
+
columnNumber: z.number(),
|
|
13
|
+
});
|
|
14
|
+
const ProfileNodeSchema = z.object({
|
|
15
|
+
id: z.number(),
|
|
16
|
+
callFrame: CallFrameSchema,
|
|
17
|
+
hitCount: z.number().optional(),
|
|
18
|
+
children: z.array(z.number()).optional(),
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* The on-disk shape of a `node --cpu-prof` output (`.cpuprofile`). `samples`
|
|
22
|
+
* holds one profile-node id per sampling tick; `timeDeltas` holds the elapsed
|
|
23
|
+
* microseconds preceding each tick. Both are optional because some producers
|
|
24
|
+
* emit only per-node `hitCount`.
|
|
25
|
+
*/
|
|
26
|
+
export const CpuProfileSchema = z.object({
|
|
27
|
+
nodes: z.array(ProfileNodeSchema),
|
|
28
|
+
startTime: z.number().optional(),
|
|
29
|
+
endTime: z.number().optional(),
|
|
30
|
+
samples: z.array(z.number()).optional(),
|
|
31
|
+
timeDeltas: z.array(z.number()).optional(),
|
|
32
|
+
});
|
|
33
|
+
export class CpuProfile {
|
|
34
|
+
/**
|
|
35
|
+
* Parses and validates raw `.cpuprofile` JSON text. Throws a `ZodError` if
|
|
36
|
+
* the document does not match the V8 profile shape.
|
|
37
|
+
*/
|
|
38
|
+
static parse(jsonText) {
|
|
39
|
+
return CpuProfileSchema.parse(JSON.parse(jsonText));
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Collapses the profile into one {@link FrameSample} per profile node that
|
|
43
|
+
* received at least one sample.
|
|
44
|
+
*
|
|
45
|
+
* Self time is summed from `timeDeltas`, attributing `timeDeltas[i]` to
|
|
46
|
+
* `samples[i]` — the standard self-time approximation where total attributed
|
|
47
|
+
* time equals the sum of all deltas. When `samples`/`timeDeltas` are absent,
|
|
48
|
+
* it falls back to each node's `hitCount` with zero self time.
|
|
49
|
+
*/
|
|
50
|
+
static aggregate(profile) {
|
|
51
|
+
const samplesByNode = new Map();
|
|
52
|
+
const microsByNode = new Map();
|
|
53
|
+
const samples = profile.samples;
|
|
54
|
+
if (samples !== undefined && samples.length > 0) {
|
|
55
|
+
const deltas = profile.timeDeltas ?? [];
|
|
56
|
+
for (let index = 0; index < samples.length; index += 1) {
|
|
57
|
+
const nodeId = samples[index];
|
|
58
|
+
samplesByNode.set(nodeId, (samplesByNode.get(nodeId) ?? 0) + 1);
|
|
59
|
+
const delta = deltas[index] ?? 0;
|
|
60
|
+
const safeDelta = delta > 0 ? delta : 0;
|
|
61
|
+
microsByNode.set(nodeId, (microsByNode.get(nodeId) ?? 0) + safeDelta);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
for (const node of profile.nodes) {
|
|
66
|
+
const hits = node.hitCount ?? 0;
|
|
67
|
+
if (hits > 0) {
|
|
68
|
+
samplesByNode.set(node.id, hits);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const frames = [];
|
|
73
|
+
for (const node of profile.nodes) {
|
|
74
|
+
const sampleCount = samplesByNode.get(node.id) ?? 0;
|
|
75
|
+
if (sampleCount === 0) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
frames.push({
|
|
79
|
+
functionName: node.callFrame.functionName,
|
|
80
|
+
url: node.callFrame.url,
|
|
81
|
+
line: node.callFrame.lineNumber + 1,
|
|
82
|
+
column: node.callFrame.columnNumber,
|
|
83
|
+
samples: sampleCount,
|
|
84
|
+
selfMicros: microsByNode.get(node.id) ?? 0,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return frames;
|
|
88
|
+
}
|
|
89
|
+
/** Total number of sampling ticks in the profile, for coverage reporting. */
|
|
90
|
+
static totalSamples(profile) {
|
|
91
|
+
if (profile.samples !== undefined && profile.samples.length > 0) {
|
|
92
|
+
return profile.samples.length;
|
|
93
|
+
}
|
|
94
|
+
return profile.nodes.reduce((sum, node) => sum + (node.hitCount ?? 0), 0);
|
|
95
|
+
}
|
|
96
|
+
}
|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