homegraph 1.4.1 → 1.5.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 +48 -11
- package/dist/bin/homegraph.js +295 -72
- package/dist/bin/homegraph.js.map +1 -1
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +32 -11
- package/dist/context/index.js.map +1 -1
- package/dist/db/index.d.ts +143 -1
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +293 -16
- package/dist/db/index.js.map +1 -1
- package/dist/db/queries.d.ts +43 -4
- package/dist/db/queries.d.ts.map +1 -1
- package/dist/db/queries.js +138 -14
- package/dist/db/queries.js.map +1 -1
- package/dist/db/sqlite-adapter.d.ts +24 -17
- package/dist/db/sqlite-adapter.d.ts.map +1 -1
- package/dist/db/sqlite-adapter.js +292 -36
- package/dist/db/sqlite-adapter.js.map +1 -1
- package/dist/db/wal-valve.d.ts +15 -2
- package/dist/db/wal-valve.d.ts.map +1 -1
- package/dist/db/wal-valve.js +88 -6
- package/dist/db/wal-valve.js.map +1 -1
- package/dist/extraction/arkts-batch-worker.js +3 -2
- package/dist/extraction/arkts-batch-worker.js.map +1 -1
- package/dist/extraction/default-ignore.d.ts +39 -0
- package/dist/extraction/default-ignore.d.ts.map +1 -0
- package/dist/extraction/default-ignore.js +221 -0
- package/dist/extraction/default-ignore.js.map +1 -0
- package/dist/extraction/index.d.ts +9 -10
- package/dist/extraction/index.d.ts.map +1 -1
- package/dist/extraction/index.js +227 -323
- package/dist/extraction/index.js.map +1 -1
- package/dist/extraction/languages/arkts.d.ts +90 -6
- package/dist/extraction/languages/arkts.d.ts.map +1 -1
- package/dist/extraction/languages/arkts.js +1579 -128
- package/dist/extraction/languages/arkts.js.map +1 -1
- package/dist/extraction/store-worker.d.ts +20 -0
- package/dist/extraction/store-worker.d.ts.map +1 -0
- package/dist/extraction/store-worker.js +102 -0
- package/dist/extraction/store-worker.js.map +1 -0
- package/dist/extraction/store-writer.d.ts +48 -0
- package/dist/extraction/store-writer.d.ts.map +1 -0
- package/dist/extraction/store-writer.js +167 -0
- package/dist/extraction/store-writer.js.map +1 -0
- package/dist/extraction/tree-sitter.d.ts.map +1 -1
- package/dist/extraction/tree-sitter.js +47 -0
- package/dist/extraction/tree-sitter.js.map +1 -1
- package/dist/extraction/wasm-runtime-flags.d.ts +14 -4
- package/dist/extraction/wasm-runtime-flags.d.ts.map +1 -1
- package/dist/extraction/wasm-runtime-flags.js +55 -7
- package/dist/extraction/wasm-runtime-flags.js.map +1 -1
- package/dist/index.d.ts +16 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +135 -97
- package/dist/index.js.map +1 -1
- package/dist/mcp/query-worker.d.ts +2 -2
- package/dist/mcp/query-worker.js +2 -2
- package/dist/mcp/tools.d.ts.map +1 -1
- package/dist/mcp/tools.js +42 -26
- package/dist/mcp/tools.js.map +1 -1
- package/dist/resolution/callback-synthesizer.d.ts +52 -16
- package/dist/resolution/callback-synthesizer.d.ts.map +1 -1
- package/dist/resolution/callback-synthesizer.js +234 -180
- package/dist/resolution/callback-synthesizer.js.map +1 -1
- package/dist/resolution/cooperative-yield.d.ts +10 -2
- package/dist/resolution/cooperative-yield.d.ts.map +1 -1
- package/dist/resolution/cooperative-yield.js +6 -4
- package/dist/resolution/cooperative-yield.js.map +1 -1
- package/dist/resolution/frameworks/go.d.ts.map +1 -1
- package/dist/resolution/frameworks/go.js +29 -6
- package/dist/resolution/frameworks/go.js.map +1 -1
- package/dist/resolution/import-resolver.d.ts +2 -3
- package/dist/resolution/import-resolver.d.ts.map +1 -1
- package/dist/resolution/import-resolver.js +166 -7
- package/dist/resolution/import-resolver.js.map +1 -1
- package/dist/resolution/index.d.ts +87 -2
- package/dist/resolution/index.d.ts.map +1 -1
- package/dist/resolution/index.js +739 -131
- package/dist/resolution/index.js.map +1 -1
- package/dist/resolution/memory-budget.d.ts +48 -0
- package/dist/resolution/memory-budget.d.ts.map +1 -0
- package/dist/resolution/memory-budget.js +162 -0
- package/dist/resolution/memory-budget.js.map +1 -0
- package/dist/resolution/name-matcher.d.ts +12 -1
- package/dist/resolution/name-matcher.d.ts.map +1 -1
- package/dist/resolution/name-matcher.js +439 -97
- package/dist/resolution/name-matcher.js.map +1 -1
- package/dist/resolution/resolver-pool.d.ts +106 -0
- package/dist/resolution/resolver-pool.d.ts.map +1 -0
- package/dist/resolution/resolver-pool.js +344 -0
- package/dist/resolution/resolver-pool.js.map +1 -0
- package/dist/resolution/resolver-worker.d.ts +17 -0
- package/dist/resolution/resolver-worker.d.ts.map +1 -0
- package/dist/resolution/resolver-worker.js +141 -0
- package/dist/resolution/resolver-worker.js.map +1 -0
- package/dist/resolution/types.d.ts +3 -0
- package/dist/resolution/types.d.ts.map +1 -1
- package/dist/spec/build/diff-parser.d.ts +55 -0
- package/dist/spec/build/diff-parser.d.ts.map +1 -0
- package/dist/spec/build/diff-parser.js +205 -0
- package/dist/spec/build/diff-parser.js.map +1 -0
- package/dist/spec/build/git-scanner.d.ts +93 -0
- package/dist/spec/build/git-scanner.d.ts.map +1 -0
- package/dist/spec/build/git-scanner.js +254 -0
- package/dist/spec/build/git-scanner.js.map +1 -0
- package/dist/spec/build/pipeline.d.ts +54 -0
- package/dist/spec/build/pipeline.d.ts.map +1 -0
- package/dist/spec/build/pipeline.js +170 -0
- package/dist/spec/build/pipeline.js.map +1 -0
- package/dist/spec/build/scan.d.ts +48 -0
- package/dist/spec/build/scan.d.ts.map +1 -0
- package/dist/spec/build/scan.js +89 -0
- package/dist/spec/build/scan.js.map +1 -0
- package/dist/spec/build/scope-resolver.d.ts +50 -0
- package/dist/spec/build/scope-resolver.d.ts.map +1 -0
- package/dist/spec/build/scope-resolver.js +105 -0
- package/dist/spec/build/scope-resolver.js.map +1 -0
- package/dist/spec/build/spec-extractor.d.ts +74 -0
- package/dist/spec/build/spec-extractor.d.ts.map +1 -0
- package/dist/spec/build/spec-extractor.js +344 -0
- package/dist/spec/build/spec-extractor.js.map +1 -0
- package/dist/spec/config.d.ts +35 -1
- package/dist/spec/config.d.ts.map +1 -1
- package/dist/spec/config.js +30 -5
- package/dist/spec/config.js.map +1 -1
- package/dist/spec/db/fts.d.ts.map +1 -1
- package/dist/spec/db/fts.js +19 -50
- package/dist/spec/db/fts.js.map +1 -1
- package/dist/spec/db/index.d.ts +5 -3
- package/dist/spec/db/index.d.ts.map +1 -1
- package/dist/spec/db/index.js +16 -1
- package/dist/spec/db/index.js.map +1 -1
- package/dist/spec/db/persist.d.ts +45 -0
- package/dist/spec/db/persist.d.ts.map +1 -0
- package/dist/spec/db/persist.js +66 -0
- package/dist/spec/db/persist.js.map +1 -0
- package/dist/spec/db/relations.d.ts +80 -1
- package/dist/spec/db/relations.d.ts.map +1 -1
- package/dist/spec/db/relations.js +175 -4
- package/dist/spec/db/relations.js.map +1 -1
- package/dist/spec/db/schema.d.ts +4 -0
- package/dist/spec/db/schema.d.ts.map +1 -1
- package/dist/spec/db/schema.js +4 -0
- package/dist/spec/db/schema.js.map +1 -1
- package/dist/spec/db/schema.sql +5 -1
- package/dist/spec/db/spec-node.d.ts +5 -0
- package/dist/spec/db/spec-node.d.ts.map +1 -1
- package/dist/spec/db/spec-node.js +11 -5
- package/dist/spec/db/spec-node.js.map +1 -1
- package/dist/spec/db/sql-utils.d.ts +11 -0
- package/dist/spec/db/sql-utils.d.ts.map +1 -0
- package/dist/spec/db/sql-utils.js +19 -0
- package/dist/spec/db/sql-utils.js.map +1 -0
- package/dist/spec/evolve/cluster-context.d.ts +30 -0
- package/dist/spec/evolve/cluster-context.d.ts.map +1 -0
- package/dist/spec/evolve/cluster-context.js +78 -0
- package/dist/spec/evolve/cluster-context.js.map +1 -0
- package/dist/spec/evolve/commit-spec-analyzer.d.ts +51 -0
- package/dist/spec/evolve/commit-spec-analyzer.d.ts.map +1 -0
- package/dist/spec/evolve/commit-spec-analyzer.js +88 -0
- package/dist/spec/evolve/commit-spec-analyzer.js.map +1 -0
- package/dist/spec/evolve/commit-spec-persister.d.ts +53 -0
- package/dist/spec/evolve/commit-spec-persister.d.ts.map +1 -0
- package/dist/spec/evolve/commit-spec-persister.js +93 -0
- package/dist/spec/evolve/commit-spec-persister.js.map +1 -0
- package/dist/spec/evolve/impact-locator.d.ts +23 -7
- package/dist/spec/evolve/impact-locator.d.ts.map +1 -1
- package/dist/spec/evolve/impact-locator.js +58 -14
- package/dist/spec/evolve/impact-locator.js.map +1 -1
- package/dist/spec/evolve/pipeline.d.ts +62 -25
- package/dist/spec/evolve/pipeline.d.ts.map +1 -1
- package/dist/spec/evolve/pipeline.js +436 -457
- package/dist/spec/evolve/pipeline.js.map +1 -1
- package/dist/spec/evolve/spec-rewriter.d.ts +13 -13
- package/dist/spec/evolve/spec-rewriter.d.ts.map +1 -1
- package/dist/spec/evolve/spec-rewriter.js +45 -45
- package/dist/spec/evolve/spec-rewriter.js.map +1 -1
- package/dist/spec/git/commits.d.ts +85 -0
- package/dist/spec/git/commits.d.ts.map +1 -0
- package/dist/spec/git/commits.js +218 -0
- package/dist/spec/git/commits.js.map +1 -0
- package/dist/spec/git/exec.d.ts +13 -0
- package/dist/spec/git/exec.d.ts.map +1 -0
- package/dist/spec/git/exec.js +19 -0
- package/dist/spec/git/exec.js.map +1 -0
- package/dist/spec/git/index.d.ts +9 -0
- package/dist/spec/git/index.d.ts.map +1 -0
- package/dist/spec/git/index.js +22 -0
- package/dist/spec/git/index.js.map +1 -0
- package/dist/spec/git-utils.d.ts +8 -0
- package/dist/spec/git-utils.d.ts.map +1 -0
- package/dist/spec/git-utils.js +14 -0
- package/dist/spec/git-utils.js.map +1 -0
- package/dist/spec/graph/index.d.ts +8 -0
- package/dist/spec/graph/index.d.ts.map +1 -0
- package/dist/spec/graph/index.js +17 -0
- package/dist/spec/graph/index.js.map +1 -0
- package/dist/spec/graph/queries.d.ts +6 -35
- package/dist/spec/graph/queries.d.ts.map +1 -1
- package/dist/spec/graph/queries.js +71 -248
- package/dist/spec/graph/queries.js.map +1 -1
- package/dist/spec/llm/agent-client.d.ts +59 -0
- package/dist/spec/llm/agent-client.d.ts.map +1 -0
- package/dist/spec/llm/agent-client.js +213 -0
- package/dist/spec/llm/agent-client.js.map +1 -0
- package/dist/spec/llm/agents/claude-code.d.ts +32 -0
- package/dist/spec/llm/agents/claude-code.d.ts.map +1 -0
- package/dist/spec/llm/agents/claude-code.js +125 -0
- package/dist/spec/llm/agents/claude-code.js.map +1 -0
- package/dist/spec/llm/agents/codex.d.ts +32 -0
- package/dist/spec/llm/agents/codex.d.ts.map +1 -0
- package/dist/spec/llm/agents/codex.js +145 -0
- package/dist/spec/llm/agents/codex.js.map +1 -0
- package/dist/spec/llm/agents/detect-utils.d.ts +28 -0
- package/dist/spec/llm/agents/detect-utils.d.ts.map +1 -0
- package/dist/spec/llm/agents/detect-utils.js +91 -0
- package/dist/spec/llm/agents/detect-utils.js.map +1 -0
- package/dist/spec/llm/agents/deveco-code.d.ts +33 -0
- package/dist/spec/llm/agents/deveco-code.d.ts.map +1 -0
- package/dist/spec/llm/agents/deveco-code.js +165 -0
- package/dist/spec/llm/agents/deveco-code.js.map +1 -0
- package/dist/spec/llm/agents/index.d.ts +31 -0
- package/dist/spec/llm/agents/index.d.ts.map +1 -0
- package/dist/spec/llm/agents/index.js +65 -0
- package/dist/spec/llm/agents/index.js.map +1 -0
- package/dist/spec/llm/agents/types.d.ts +76 -0
- package/dist/spec/llm/agents/types.d.ts.map +1 -0
- package/dist/spec/llm/agents/types.js +15 -0
- package/dist/spec/llm/agents/types.js.map +1 -0
- package/dist/spec/llm/client.d.ts +31 -11
- package/dist/spec/llm/client.d.ts.map +1 -1
- package/dist/spec/llm/client.js +143 -81
- package/dist/spec/llm/client.js.map +1 -1
- package/dist/spec/llm/factory.d.ts +41 -0
- package/dist/spec/llm/factory.d.ts.map +1 -0
- package/dist/spec/llm/factory.js +80 -0
- package/dist/spec/llm/factory.js.map +1 -0
- package/dist/spec/llm/prompts.d.ts +24 -8
- package/dist/spec/llm/prompts.d.ts.map +1 -1
- package/dist/spec/llm/prompts.js +100 -50
- package/dist/spec/llm/prompts.js.map +1 -1
- package/dist/spec/llm/retry.d.ts +53 -0
- package/dist/spec/llm/retry.d.ts.map +1 -0
- package/dist/spec/llm/retry.js +153 -0
- package/dist/spec/llm/retry.js.map +1 -0
- package/dist/spec/mine/clusterer.d.ts +63 -0
- package/dist/spec/mine/clusterer.d.ts.map +1 -0
- package/dist/spec/mine/clusterer.js +904 -0
- package/dist/spec/mine/clusterer.js.map +1 -0
- package/dist/spec/mine/clustering/features.d.ts +38 -0
- package/dist/spec/mine/clustering/features.d.ts.map +1 -0
- package/dist/spec/mine/clustering/features.js +108 -0
- package/dist/spec/mine/clustering/features.js.map +1 -0
- package/dist/spec/mine/clustering/index.d.ts +62 -0
- package/dist/spec/mine/clustering/index.d.ts.map +1 -0
- package/dist/spec/mine/clustering/index.js +259 -0
- package/dist/spec/mine/clustering/index.js.map +1 -0
- package/dist/spec/mine/clustering/leiden.d.ts +61 -0
- package/dist/spec/mine/clustering/leiden.d.ts.map +1 -0
- package/dist/spec/mine/clustering/leiden.js +489 -0
- package/dist/spec/mine/clustering/leiden.js.map +1 -0
- package/dist/spec/mine/clustering/text-similarity.d.ts +22 -0
- package/dist/spec/mine/clustering/text-similarity.d.ts.map +1 -0
- package/dist/spec/mine/clustering/text-similarity.js +98 -0
- package/dist/spec/mine/clustering/text-similarity.js.map +1 -0
- package/dist/spec/mine/generator.d.ts +54 -0
- package/dist/spec/mine/generator.d.ts.map +1 -0
- package/dist/spec/mine/generator.js +267 -0
- package/dist/spec/mine/generator.js.map +1 -0
- package/dist/spec/mine/persist.d.ts +37 -0
- package/dist/spec/mine/persist.d.ts.map +1 -0
- package/dist/spec/mine/persist.js +170 -0
- package/dist/spec/mine/persist.js.map +1 -0
- package/dist/spec/mine/pipeline.d.ts +41 -0
- package/dist/spec/mine/pipeline.d.ts.map +1 -0
- package/dist/spec/mine/pipeline.js +236 -0
- package/dist/spec/mine/pipeline.js.map +1 -0
- package/dist/spec/mine/progress-handler.d.ts +22 -0
- package/dist/spec/mine/progress-handler.d.ts.map +1 -0
- package/dist/spec/mine/progress-handler.js +108 -0
- package/dist/spec/mine/progress-handler.js.map +1 -0
- package/dist/spec/mine/progress.d.ts +23 -0
- package/dist/spec/mine/progress.d.ts.map +1 -0
- package/dist/spec/mine/progress.js +12 -0
- package/dist/spec/mine/progress.js.map +1 -0
- package/dist/spec/mine/scanner.d.ts +59 -0
- package/dist/spec/mine/scanner.d.ts.map +1 -0
- package/dist/spec/mine/scanner.js +383 -0
- package/dist/spec/mine/scanner.js.map +1 -0
- package/dist/spec/types.d.ts +32 -0
- package/dist/spec/types.d.ts.map +1 -1
- package/dist/spec/ui/index.d.ts +9 -0
- package/dist/spec/ui/index.d.ts.map +1 -0
- package/dist/spec/ui/index.js +16 -0
- package/dist/spec/ui/index.js.map +1 -0
- package/dist/spec/ui/progress-handler.d.ts +33 -0
- package/dist/spec/ui/progress-handler.d.ts.map +1 -0
- package/dist/spec/ui/progress-handler.js +132 -0
- package/dist/spec/ui/progress-handler.js.map +1 -0
- package/dist/spec/ui/progress.d.ts +24 -0
- package/dist/spec/ui/progress.d.ts.map +1 -0
- package/dist/spec/ui/progress.js +13 -0
- package/dist/spec/ui/progress.js.map +1 -0
- package/dist/spec/utils/fs.d.ts +45 -0
- package/dist/spec/utils/fs.d.ts.map +1 -0
- package/dist/spec/utils/fs.js +163 -0
- package/dist/spec/utils/fs.js.map +1 -0
- package/dist/spec/utils/index.d.ts +12 -0
- package/dist/spec/utils/index.d.ts.map +1 -0
- package/dist/spec/utils/index.js +26 -0
- package/dist/spec/utils/index.js.map +1 -0
- package/dist/spec/utils/meta.d.ts +32 -0
- package/dist/spec/utils/meta.d.ts.map +1 -0
- package/dist/spec/utils/meta.js +122 -0
- package/dist/spec/utils/meta.js.map +1 -0
- package/dist/spec/utils/truncate.d.ts +86 -0
- package/dist/spec/utils/truncate.d.ts.map +1 -0
- package/dist/spec/utils/truncate.js +172 -0
- package/dist/spec/utils/truncate.js.map +1 -0
- package/dist/spec/utils.d.ts +4 -16
- package/dist/spec/utils.d.ts.map +1 -1
- package/dist/spec/utils.js +6 -58
- package/dist/spec/utils.js.map +1 -1
- package/dist/sync/watcher.d.ts +25 -1
- package/dist/sync/watcher.d.ts.map +1 -1
- package/dist/sync/watcher.js +76 -3
- package/dist/sync/watcher.js.map +1 -1
- package/dist/telemetry/index.js +3 -3
- package/dist/telemetry/index.js.map +1 -1
- package/dist/types.d.ts +3 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +7 -3
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Unified diff parser — converts `git diff` output into structured code
|
|
4
|
+
* fragments.
|
|
5
|
+
*
|
|
6
|
+
* Replaces `commit4spec/reverse_engineer/change_analyzer.py`. Parses
|
|
7
|
+
* unified diff output and extracts file-level change information (change
|
|
8
|
+
* type, line range, diff text).
|
|
9
|
+
*
|
|
10
|
+
* @module spec/build/diff-parser
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.analyzeCommitDiff = analyzeCommitDiff;
|
|
14
|
+
exports.listChangedFiles = listChangedFiles;
|
|
15
|
+
exports.parseDiff = parseDiff;
|
|
16
|
+
const git_1 = require("../git");
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
// analyzeCommitDiff
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
/**
|
|
21
|
+
* Retrieve and parse the diff for a single commit.
|
|
22
|
+
*
|
|
23
|
+
* 1. Call `getCommitDiff(repoPath, commitHash)` to get raw diff text.
|
|
24
|
+
* 2. Parse the diff into structured `DiffFragment` objects.
|
|
25
|
+
* 3. Return the fragments.
|
|
26
|
+
*
|
|
27
|
+
* Returns an empty array when the diff cannot be retrieved or is empty.
|
|
28
|
+
*/
|
|
29
|
+
function analyzeCommitDiff(repoPath, commitHash, preFetchedDiff) {
|
|
30
|
+
const diff = preFetchedDiff ?? (0, git_1.getCommitDiff)(repoPath, commitHash);
|
|
31
|
+
if (!diff) {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
return parseDiff(diff);
|
|
35
|
+
}
|
|
36
|
+
// ---------------------------------------------------------------------------
|
|
37
|
+
// listChangedFiles
|
|
38
|
+
// ---------------------------------------------------------------------------
|
|
39
|
+
/**
|
|
40
|
+
* Parse changed file paths from a unified diff string.
|
|
41
|
+
*
|
|
42
|
+
* Matches `--- a/path` and `+++ b/path` headers to identify files,
|
|
43
|
+
* skipping `/dev/null`. Returns a list of unique changed file paths.
|
|
44
|
+
*
|
|
45
|
+
* Both headers are needed:
|
|
46
|
+
* - `+++ b/` captures added and modified files. For deletions the line is
|
|
47
|
+
* `+++ /dev/null`, which is skipped.
|
|
48
|
+
* - `--- a/` captures deleted files. For additions the line is
|
|
49
|
+
* `--- /dev/null`, which is skipped.
|
|
50
|
+
*/
|
|
51
|
+
function listChangedFiles(diff) {
|
|
52
|
+
const files = new Set();
|
|
53
|
+
const lines = diff.split('\n');
|
|
54
|
+
for (const line of lines) {
|
|
55
|
+
let match = /^\+\+\+ b\/(.+)$/.exec(line);
|
|
56
|
+
if (match) {
|
|
57
|
+
const fp = match[1];
|
|
58
|
+
if (fp !== '/dev/null') {
|
|
59
|
+
files.add(fp);
|
|
60
|
+
}
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
match = /^--- a\/(.+)$/.exec(line);
|
|
64
|
+
if (match) {
|
|
65
|
+
const fp = match[1];
|
|
66
|
+
if (fp !== '/dev/null') {
|
|
67
|
+
files.add(fp);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return Array.from(files);
|
|
72
|
+
}
|
|
73
|
+
// ---------------------------------------------------------------------------
|
|
74
|
+
// parseDiff
|
|
75
|
+
// ---------------------------------------------------------------------------
|
|
76
|
+
/**
|
|
77
|
+
* State-machine parser for unified diff format.
|
|
78
|
+
*
|
|
79
|
+
* Walks through the diff line-by-line, tracking the current file, change
|
|
80
|
+
* type, and line-number range. Accumulates lines into a buffer and emits a
|
|
81
|
+
* `DiffFragment` each time a new `diff --git` section begins (or when the
|
|
82
|
+
* input is exhausted).
|
|
83
|
+
*/
|
|
84
|
+
function parseDiff(diff) {
|
|
85
|
+
const lines = diff.split('\n');
|
|
86
|
+
// ---- state ----
|
|
87
|
+
const fragments = [];
|
|
88
|
+
let buf = [];
|
|
89
|
+
let currentFilePath = null;
|
|
90
|
+
let currentChangeType = 'MODIFY';
|
|
91
|
+
let currentStartLine = 0;
|
|
92
|
+
let currentEndLine = 0;
|
|
93
|
+
let inHunk = false;
|
|
94
|
+
// ---- flush helper ----
|
|
95
|
+
const _flush = () => {
|
|
96
|
+
if (buf.length === 0 || currentFilePath === null) {
|
|
97
|
+
buf = [];
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
// DELETE files have no lines in the new version — use [0, 0].
|
|
101
|
+
let startLine;
|
|
102
|
+
let endLine;
|
|
103
|
+
if (currentChangeType === 'DELETE') {
|
|
104
|
+
startLine = 0;
|
|
105
|
+
endLine = 0;
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
// When no hunk was ever encountered, default startLine to 1.
|
|
109
|
+
startLine = currentStartLine === 0 ? 1 : currentStartLine;
|
|
110
|
+
endLine = currentEndLine;
|
|
111
|
+
}
|
|
112
|
+
fragments.push({
|
|
113
|
+
filePath: currentFilePath,
|
|
114
|
+
changeType: currentChangeType,
|
|
115
|
+
startLine,
|
|
116
|
+
endLine,
|
|
117
|
+
codeDiff: buf.join('\n'),
|
|
118
|
+
});
|
|
119
|
+
buf = [];
|
|
120
|
+
};
|
|
121
|
+
// ---- line-by-line parser ----
|
|
122
|
+
for (const line of lines) {
|
|
123
|
+
// Rule 1 — new file section: flush the previous file.
|
|
124
|
+
if (line.startsWith('diff --git ')) {
|
|
125
|
+
_flush();
|
|
126
|
+
buf = [line];
|
|
127
|
+
currentFilePath = null;
|
|
128
|
+
currentChangeType = 'MODIFY';
|
|
129
|
+
currentStartLine = 0;
|
|
130
|
+
currentEndLine = 0;
|
|
131
|
+
inHunk = false;
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
// Rule 2 — new file mode → change type is ADD.
|
|
135
|
+
if (line.startsWith('new file mode ')) {
|
|
136
|
+
currentChangeType = 'ADD';
|
|
137
|
+
buf.push(line);
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
// Rule 3 — deleted file mode → change type is DELETE.
|
|
141
|
+
if (line.startsWith('deleted file mode ')) {
|
|
142
|
+
currentChangeType = 'DELETE';
|
|
143
|
+
buf.push(line);
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
// Rule 4 — file path lines (--- a/path or +++ b/path).
|
|
147
|
+
if (line.startsWith('--- a/') || line.startsWith('+++ b/')) {
|
|
148
|
+
const isPlus = line.startsWith('+++ b/');
|
|
149
|
+
// Extract the path, skipping `/dev/null`.
|
|
150
|
+
let pathPart = '';
|
|
151
|
+
if (isPlus) {
|
|
152
|
+
pathPart = line.slice(6); // '+++ b/'.length
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
pathPart = line.slice(6); // '--- a/'.length
|
|
156
|
+
}
|
|
157
|
+
if (pathPart !== '/dev/null') {
|
|
158
|
+
currentFilePath = pathPart;
|
|
159
|
+
}
|
|
160
|
+
buf.push(line);
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
// Rule 5 — hunk header: @@ -oldStart[,oldCount] +newStart[,newCount] @@
|
|
164
|
+
const hunkMatch = line.match(/^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@/);
|
|
165
|
+
if (hunkMatch) {
|
|
166
|
+
const newStart = parseInt(hunkMatch[1], 10);
|
|
167
|
+
if (currentStartLine === 0) {
|
|
168
|
+
currentStartLine = newStart;
|
|
169
|
+
}
|
|
170
|
+
currentEndLine = newStart;
|
|
171
|
+
inHunk = true;
|
|
172
|
+
buf.push(line);
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
// Rule 6 — added lines (start with '+', but not '+++').
|
|
176
|
+
if (line.startsWith('+') && !line.startsWith('+++')) {
|
|
177
|
+
if (inHunk) {
|
|
178
|
+
currentEndLine++;
|
|
179
|
+
}
|
|
180
|
+
buf.push(line);
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
// Rule 7 — removed lines (start with '-', but not '---').
|
|
184
|
+
if (line.startsWith('-') && !line.startsWith('---')) {
|
|
185
|
+
buf.push(line);
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
// Rule 8 — context lines (start with a space).
|
|
189
|
+
if (line.startsWith(' ')) {
|
|
190
|
+
if (inHunk) {
|
|
191
|
+
currentEndLine++;
|
|
192
|
+
}
|
|
193
|
+
buf.push(line);
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
// Rule 9 — all other lines (e.g. `rename from` / `rename to`,
|
|
197
|
+
// `similarity index`, `Binary files differ`, `\ No newline at end of
|
|
198
|
+
// file`, blank lines between sections, etc.).
|
|
199
|
+
buf.push(line);
|
|
200
|
+
}
|
|
201
|
+
// Flush the final file.
|
|
202
|
+
_flush();
|
|
203
|
+
return fragments;
|
|
204
|
+
}
|
|
205
|
+
//# sourceMappingURL=diff-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff-parser.js","sourceRoot":"","sources":["../../../src/spec/build/diff-parser.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;AAkCH,8CAUC;AAkBD,4CAqBC;AAcD,8BA0IC;AAzOD,gCAAuC;AAmBvC,8EAA8E;AAC9E,oBAAoB;AACpB,8EAA8E;AAE9E;;;;;;;;GAQG;AACH,SAAgB,iBAAiB,CAC/B,QAAgB,EAChB,UAAkB,EAClB,cAAuB;IAEvB,MAAM,IAAI,GAAG,cAAc,IAAI,IAAA,mBAAa,EAAC,QAAQ,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
|
|
4
|
+
* Replaces `commit4spec/reverse_engineer/git_scanner.py` and
|
|
5
|
+
* `commit4spec/reverse_engineer/git_utils.py`. Discovers spec↔commit pairs via
|
|
6
|
+
* conventional-commit scope extraction: extracts scopes from commit messages
|
|
7
|
+
* and resolves them to spec IDs on disk.
|
|
8
|
+
*
|
|
9
|
+
* All Git operations use `execFileSync` with an args array (never template
|
|
10
|
+
* strings) to avoid shell injection risks — matching the HomeGraph convention
|
|
11
|
+
* in `src/sync/git-hooks.ts` and `src/sync/worktree.ts`.
|
|
12
|
+
*
|
|
13
|
+
* @module spec/build/git-scanner
|
|
14
|
+
*/
|
|
15
|
+
import { SpecConfig } from '../config';
|
|
16
|
+
import { SpecMetadata } from './spec-extractor';
|
|
17
|
+
export interface CommitInfo {
|
|
18
|
+
/** Full 40-char commit hash */
|
|
19
|
+
hash: string;
|
|
20
|
+
/** First line of commit message */
|
|
21
|
+
message: string;
|
|
22
|
+
/** Author name */
|
|
23
|
+
author: string;
|
|
24
|
+
/** Unix epoch milliseconds */
|
|
25
|
+
timestamp: number;
|
|
26
|
+
}
|
|
27
|
+
export interface SpecCommitPair {
|
|
28
|
+
specId: string;
|
|
29
|
+
commitHash: string;
|
|
30
|
+
specMetadata: SpecMetadata | null;
|
|
31
|
+
commitMetadata: CommitInfo | null;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Check whether `repoPath` is a git repository.
|
|
35
|
+
*
|
|
36
|
+
* Runs `git rev-parse --git-dir` and returns `true` on success, `false`
|
|
37
|
+
* when the command fails (not a repo, git not installed, etc.).
|
|
38
|
+
*/
|
|
39
|
+
export declare function isGitRepo(repoPath: string): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Return every commit in `repoPath` as `CommitInfo` objects.
|
|
42
|
+
*
|
|
43
|
+
* Runs `git log --format='%H%n%aI%n%an%n%s%n---END---'` and parses the
|
|
44
|
+
* output one five-line block per commit. Commits are returned in reverse
|
|
45
|
+
* chronological order (most recent first), matching Git's default.
|
|
46
|
+
*
|
|
47
|
+
* An empty repo yields an empty array.
|
|
48
|
+
*/
|
|
49
|
+
export declare function getAllCommits(repoPath: string): CommitInfo[];
|
|
50
|
+
/**
|
|
51
|
+
* Retrieve metadata for a single commit.
|
|
52
|
+
*
|
|
53
|
+
* Runs `git show -s --format='%H%n%aI%n%an%n%s' <commitHash>`. Returns
|
|
54
|
+
* `null` when the command fails (hash not found, invalid repo, etc.).
|
|
55
|
+
*/
|
|
56
|
+
export declare function getCommitInfo(repoPath: string, commitHash: string): CommitInfo | null;
|
|
57
|
+
/**
|
|
58
|
+
* Return the full unified diff introduced by `commitHash`.
|
|
59
|
+
*
|
|
60
|
+
* Strategy:
|
|
61
|
+
* 1. Query the parent hash(es) via `git log --pretty=%P -n 1 <commitHash>`.
|
|
62
|
+
* 2. If a parent exists, diff it against the commit: `git diff <parent> <commitHash>`.
|
|
63
|
+
* 3. For an initial (root) commit with no parent, use `git diff <commitHash>`
|
|
64
|
+
* which shows all files added in that commit.
|
|
65
|
+
*
|
|
66
|
+
* Returns an empty string when any Git command fails.
|
|
67
|
+
*/
|
|
68
|
+
export declare function getCommitDiff(repoPath: string, commitHash: string): string;
|
|
69
|
+
/**
|
|
70
|
+
* Return every commit between `fromHash` (exclusive) and `toHash`
|
|
71
|
+
* (inclusive) in chronological order (oldest first).
|
|
72
|
+
*
|
|
73
|
+
* Runs `git log --reverse --format="..." fromHash..toHash`. Returns an empty
|
|
74
|
+
* array when either hash is not found or the range is empty.
|
|
75
|
+
*
|
|
76
|
+
* Callers should validate that `fromHash` is an ancestor of `toHash` before
|
|
77
|
+
* calling this function (use `git merge-base --is-ancestor`). Results are
|
|
78
|
+
* undefined when the two hashes are on unrelated branches.
|
|
79
|
+
*/
|
|
80
|
+
export declare function getCommitRange(repoPath: string, fromHash: string, toHash: string): CommitInfo[];
|
|
81
|
+
/**
|
|
82
|
+
* Main scanning function — discovers spec↔commit pairs from commit history.
|
|
83
|
+
*
|
|
84
|
+
* Iterates every commit in the repo, extracts a conventional-commit scope from
|
|
85
|
+
* its message, normalizes it, and checks whether the resulting spec ID exists
|
|
86
|
+
* on disk. When a match is found the pair is recorded with full spec and
|
|
87
|
+
* commit metadata.
|
|
88
|
+
*
|
|
89
|
+
* Duplicates (identical specId + commitHash) are de-duplicated via a
|
|
90
|
+
* `Map` keyed on `"${specId}|${commitHash}"`.
|
|
91
|
+
*/
|
|
92
|
+
export declare function scan(repoPath: string, specStoragePath: string, config: SpecConfig): SpecCommitPair[];
|
|
93
|
+
//# sourceMappingURL=git-scanner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git-scanner.d.ts","sourceRoot":"","sources":["../../../src/spec/build/git-scanner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC,OAAO,EAAuB,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAQrE,MAAM,WAAW,UAAU;IACzB,+BAA+B;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,mCAAmC;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,kBAAkB;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,8BAA8B;IAC9B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,YAAY,GAAG,IAAI,CAAC;IAClC,cAAc,EAAE,UAAU,GAAG,IAAI,CAAC;CACnC;AAmBD;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAOnD;AAMD;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,EAAE,CAiC5D;AAMD;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,GACjB,UAAU,GAAG,IAAI,CA4BnB;AAMD;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CA4C1E;AAMD;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GACb,UAAU,EAAE,CAiCd;AAMD;;;;;;;;;;GAUG;AACH,wBAAgB,IAAI,CAClB,QAAQ,EAAE,MAAM,EAChB,eAAe,EAAE,MAAM,EACvB,MAAM,EAAE,UAAU,GACjB,cAAc,EAAE,CA6BlB"}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Git commit history scanning and spec↔commit pairing.
|
|
4
|
+
*
|
|
5
|
+
* Replaces `commit4spec/reverse_engineer/git_scanner.py` and
|
|
6
|
+
* `commit4spec/reverse_engineer/git_utils.py`. Discovers spec↔commit pairs via
|
|
7
|
+
* conventional-commit scope extraction: extracts scopes from commit messages
|
|
8
|
+
* and resolves them to spec IDs on disk.
|
|
9
|
+
*
|
|
10
|
+
* All Git operations use `execFileSync` with an args array (never template
|
|
11
|
+
* strings) to avoid shell injection risks — matching the HomeGraph convention
|
|
12
|
+
* in `src/sync/git-hooks.ts` and `src/sync/worktree.ts`.
|
|
13
|
+
*
|
|
14
|
+
* @module spec/build/git-scanner
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.isGitRepo = isGitRepo;
|
|
18
|
+
exports.getAllCommits = getAllCommits;
|
|
19
|
+
exports.getCommitInfo = getCommitInfo;
|
|
20
|
+
exports.getCommitDiff = getCommitDiff;
|
|
21
|
+
exports.getCommitRange = getCommitRange;
|
|
22
|
+
exports.scan = scan;
|
|
23
|
+
const child_process_1 = require("child_process");
|
|
24
|
+
const scope_resolver_1 = require("./scope-resolver");
|
|
25
|
+
const spec_extractor_1 = require("./spec-extractor");
|
|
26
|
+
const errors_1 = require("../../errors");
|
|
27
|
+
const git_utils_1 = require("../git-utils");
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
// Helpers
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
/**
|
|
32
|
+
* Convert an ISO-8601 string to Unix epoch milliseconds.
|
|
33
|
+
* Returns 0 for invalid or unparseable strings.
|
|
34
|
+
*/
|
|
35
|
+
function parseISOTimestamp(isoString) {
|
|
36
|
+
const ts = new Date(isoString).getTime();
|
|
37
|
+
return isNaN(ts) ? 0 : ts;
|
|
38
|
+
}
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
// isGitRepo
|
|
41
|
+
// ---------------------------------------------------------------------------
|
|
42
|
+
/**
|
|
43
|
+
* Check whether `repoPath` is a git repository.
|
|
44
|
+
*
|
|
45
|
+
* Runs `git rev-parse --git-dir` and returns `true` on success, `false`
|
|
46
|
+
* when the command fails (not a repo, git not installed, etc.).
|
|
47
|
+
*/
|
|
48
|
+
function isGitRepo(repoPath) {
|
|
49
|
+
try {
|
|
50
|
+
(0, child_process_1.execFileSync)('git', ['rev-parse', '--git-dir'], (0, git_utils_1.gitExecOptions)(repoPath));
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// ---------------------------------------------------------------------------
|
|
58
|
+
// getAllCommits
|
|
59
|
+
// ---------------------------------------------------------------------------
|
|
60
|
+
/**
|
|
61
|
+
* Return every commit in `repoPath` as `CommitInfo` objects.
|
|
62
|
+
*
|
|
63
|
+
* Runs `git log --format='%H%n%aI%n%an%n%s%n---END---'` and parses the
|
|
64
|
+
* output one five-line block per commit. Commits are returned in reverse
|
|
65
|
+
* chronological order (most recent first), matching Git's default.
|
|
66
|
+
*
|
|
67
|
+
* An empty repo yields an empty array.
|
|
68
|
+
*/
|
|
69
|
+
function getAllCommits(repoPath) {
|
|
70
|
+
let stdout;
|
|
71
|
+
try {
|
|
72
|
+
stdout = (0, child_process_1.execFileSync)('git', ['log', "--format=%H%x00%aI%x00%an%x00%s%x00"], (0, git_utils_1.gitExecOptions)(repoPath));
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return [];
|
|
76
|
+
}
|
|
77
|
+
const parts = stdout.replace(/\0+$/, '').trim().split('\0');
|
|
78
|
+
const commits = [];
|
|
79
|
+
// Each commit occupies 4 NUL-separated fields: hash, timestamp, author, message
|
|
80
|
+
for (let i = 0; i + 3 < parts.length; i += 4) {
|
|
81
|
+
const hash = parts[i].trim();
|
|
82
|
+
const isoString = parts[i + 1].trim();
|
|
83
|
+
const author = parts[i + 2].trim();
|
|
84
|
+
const message = parts[i + 3].trim();
|
|
85
|
+
if (!hash)
|
|
86
|
+
continue;
|
|
87
|
+
commits.push({
|
|
88
|
+
hash,
|
|
89
|
+
message,
|
|
90
|
+
author,
|
|
91
|
+
timestamp: parseISOTimestamp(isoString),
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return commits;
|
|
95
|
+
}
|
|
96
|
+
// ---------------------------------------------------------------------------
|
|
97
|
+
// getCommitInfo
|
|
98
|
+
// ---------------------------------------------------------------------------
|
|
99
|
+
/**
|
|
100
|
+
* Retrieve metadata for a single commit.
|
|
101
|
+
*
|
|
102
|
+
* Runs `git show -s --format='%H%n%aI%n%an%n%s' <commitHash>`. Returns
|
|
103
|
+
* `null` when the command fails (hash not found, invalid repo, etc.).
|
|
104
|
+
*/
|
|
105
|
+
function getCommitInfo(repoPath, commitHash) {
|
|
106
|
+
let stdout;
|
|
107
|
+
try {
|
|
108
|
+
stdout = (0, child_process_1.execFileSync)('git', ['show', '-s', "--format=%H%n%aI%n%an%n%s", commitHash], (0, git_utils_1.gitExecOptions)(repoPath));
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
const lines = stdout.trim().split('\n');
|
|
114
|
+
if (lines.length < 4)
|
|
115
|
+
return null;
|
|
116
|
+
const hash = lines[0].trim();
|
|
117
|
+
const isoString = lines[1].trim();
|
|
118
|
+
const author = lines[2].trim();
|
|
119
|
+
const message = lines[3].trim();
|
|
120
|
+
if (!hash)
|
|
121
|
+
return null;
|
|
122
|
+
return {
|
|
123
|
+
hash,
|
|
124
|
+
message,
|
|
125
|
+
author,
|
|
126
|
+
timestamp: parseISOTimestamp(isoString),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
// ---------------------------------------------------------------------------
|
|
130
|
+
// getCommitDiff
|
|
131
|
+
// ---------------------------------------------------------------------------
|
|
132
|
+
/**
|
|
133
|
+
* Return the full unified diff introduced by `commitHash`.
|
|
134
|
+
*
|
|
135
|
+
* Strategy:
|
|
136
|
+
* 1. Query the parent hash(es) via `git log --pretty=%P -n 1 <commitHash>`.
|
|
137
|
+
* 2. If a parent exists, diff it against the commit: `git diff <parent> <commitHash>`.
|
|
138
|
+
* 3. For an initial (root) commit with no parent, use `git diff <commitHash>`
|
|
139
|
+
* which shows all files added in that commit.
|
|
140
|
+
*
|
|
141
|
+
* Returns an empty string when any Git command fails.
|
|
142
|
+
*/
|
|
143
|
+
function getCommitDiff(repoPath, commitHash) {
|
|
144
|
+
// Step 1 — get parent hashes.
|
|
145
|
+
let parentStdout;
|
|
146
|
+
try {
|
|
147
|
+
parentStdout = (0, child_process_1.execFileSync)('git', ['log', '--pretty=%P', '-n', '1', commitHash], (0, git_utils_1.gitExecOptions)(repoPath));
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
return '';
|
|
151
|
+
}
|
|
152
|
+
const parents = parentStdout.trim().split(/\s+/).filter(Boolean);
|
|
153
|
+
// Step 2 & 3 — run the appropriate diff.
|
|
154
|
+
try {
|
|
155
|
+
if (parents.length > 0) {
|
|
156
|
+
const diffs = [];
|
|
157
|
+
for (const parent of parents) {
|
|
158
|
+
try {
|
|
159
|
+
diffs.push((0, child_process_1.execFileSync)('git', ['diff', parent, commitHash], (0, git_utils_1.gitExecOptions)(repoPath)));
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
// Skip diffs that fail for an individual parent
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return diffs.join('\n');
|
|
166
|
+
}
|
|
167
|
+
// Initial commit — no parent.
|
|
168
|
+
return (0, child_process_1.execFileSync)('git', ['diff', commitHash], (0, git_utils_1.gitExecOptions)(repoPath));
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
return '';
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
// ---------------------------------------------------------------------------
|
|
175
|
+
// getCommitRange
|
|
176
|
+
// ---------------------------------------------------------------------------
|
|
177
|
+
/**
|
|
178
|
+
* Return every commit between `fromHash` (exclusive) and `toHash`
|
|
179
|
+
* (inclusive) in chronological order (oldest first).
|
|
180
|
+
*
|
|
181
|
+
* Runs `git log --reverse --format="..." fromHash..toHash`. Returns an empty
|
|
182
|
+
* array when either hash is not found or the range is empty.
|
|
183
|
+
*
|
|
184
|
+
* Callers should validate that `fromHash` is an ancestor of `toHash` before
|
|
185
|
+
* calling this function (use `git merge-base --is-ancestor`). Results are
|
|
186
|
+
* undefined when the two hashes are on unrelated branches.
|
|
187
|
+
*/
|
|
188
|
+
function getCommitRange(repoPath, fromHash, toHash) {
|
|
189
|
+
let stdout;
|
|
190
|
+
try {
|
|
191
|
+
stdout = (0, child_process_1.execFileSync)('git', ['log', '--no-merges', '--reverse', `--format=%H%x00%aI%x00%an%x00%s%x00`, `${fromHash}..${toHash}`], (0, git_utils_1.gitExecOptions)(repoPath));
|
|
192
|
+
}
|
|
193
|
+
catch {
|
|
194
|
+
return [];
|
|
195
|
+
}
|
|
196
|
+
const parts = stdout.replace(/\0+$/, '').trim().split('\0');
|
|
197
|
+
const commits = [];
|
|
198
|
+
// Each commit occupies 4 NUL-separated fields: hash, timestamp, author, message
|
|
199
|
+
for (let i = 0; i + 3 < parts.length; i += 4) {
|
|
200
|
+
const hash = parts[i].trim();
|
|
201
|
+
const isoString = parts[i + 1].trim();
|
|
202
|
+
const author = parts[i + 2].trim();
|
|
203
|
+
const message = parts[i + 3].trim();
|
|
204
|
+
if (!hash)
|
|
205
|
+
continue;
|
|
206
|
+
commits.push({
|
|
207
|
+
hash,
|
|
208
|
+
message,
|
|
209
|
+
author,
|
|
210
|
+
timestamp: parseISOTimestamp(isoString),
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
return commits;
|
|
214
|
+
}
|
|
215
|
+
// ---------------------------------------------------------------------------
|
|
216
|
+
// scan
|
|
217
|
+
// ---------------------------------------------------------------------------
|
|
218
|
+
/**
|
|
219
|
+
* Main scanning function — discovers spec↔commit pairs from commit history.
|
|
220
|
+
*
|
|
221
|
+
* Iterates every commit in the repo, extracts a conventional-commit scope from
|
|
222
|
+
* its message, normalizes it, and checks whether the resulting spec ID exists
|
|
223
|
+
* on disk. When a match is found the pair is recorded with full spec and
|
|
224
|
+
* commit metadata.
|
|
225
|
+
*
|
|
226
|
+
* Duplicates (identical specId + commitHash) are de-duplicated via a
|
|
227
|
+
* `Map` keyed on `"${specId}|${commitHash}"`.
|
|
228
|
+
*/
|
|
229
|
+
function scan(repoPath, specStoragePath, config) {
|
|
230
|
+
const pairs = new Map();
|
|
231
|
+
const commits = getAllCommits(repoPath);
|
|
232
|
+
for (const commit of commits) {
|
|
233
|
+
const specId = (0, scope_resolver_1.resolveScopeToSpec)(commit.message, specStoragePath, config);
|
|
234
|
+
if (!specId) {
|
|
235
|
+
(0, errors_1.logDebug)('scan: no scope match', {
|
|
236
|
+
commitHash: commit.hash.slice(0, 7),
|
|
237
|
+
message: commit.message,
|
|
238
|
+
});
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
const specMetadata = (0, spec_extractor_1.extractSpecMetadata)(specStoragePath, specId, config);
|
|
242
|
+
const key = `${specId}|${commit.hash}`;
|
|
243
|
+
if (!pairs.has(key)) {
|
|
244
|
+
pairs.set(key, {
|
|
245
|
+
specId,
|
|
246
|
+
commitHash: commit.hash,
|
|
247
|
+
specMetadata,
|
|
248
|
+
commitMetadata: commit,
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return Array.from(pairs.values());
|
|
253
|
+
}
|
|
254
|
+
//# sourceMappingURL=git-scanner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git-scanner.js","sourceRoot":"","sources":["../../../src/spec/build/git-scanner.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;AAsDH,8BAOC;AAeD,sCAiCC;AAYD,sCA+BC;AAiBD,sCA4CC;AAiBD,wCAqCC;AAiBD,oBAiCC;AA3TD,iDAA6C;AAE7C,qDAAsD;AACtD,qDAAqE;AACrE,yCAAwC;AACxC,4CAA8C;AAwB9C,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E;;;GAGG;AACH,SAAS,iBAAiB,CAAC,SAAiB;IAC1C,MAAM,EAAE,GAAG,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,CAAC;IACzC,OAAO,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAC5B,CAAC;AAED,8EAA8E;AAC9E,YAAY;AACZ,8EAA8E;AAE9E;;;;;GAKG;AACH,SAAgB,SAAS,CAAC,QAAgB;IACxC,IAAI,CAAC;QACH,IAAA,4BAAY,EAAC,KAAK,EAAE,CAAC,WAAW,EAAE,WAAW,CAAC,EAAE,IAAA,0BAAc,EAAC,QAAQ,CAAC,CAAC,CAAC;QAC1E,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,8EAA8E;AAC9E,gBAAgB;AAChB,8EAA8E;AAE9E;;;;;;;;GAQG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E,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,IAAA,iBAAQ,EAAC,sBAAsB,EAAE;gBAC/B,UAAU,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;gBACnC,OAAO,EAAE,MAAM,CAAC,OAAO;aACxB,CAAC,CAAC;YACH,SAAS;QACX,CAAC;QAED,MAAM,YAAY,GAAG,IAAA,oCAAmB,EAAC,eAAe,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QAE1E,MAAM,GAAG,GAAG,GAAG,MAAM,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;QACvC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACpB,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE;gBACb,MAAM;gBACN,UAAU,EAAE,MAAM,CAAC,IAAI;gBACvB,YAAY;gBACZ,cAAc,EAAE,MAAM;aACvB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build pipeline orchestrator — main entry point for building spec
|
|
3
|
+
* knowledge from Git history.
|
|
4
|
+
*
|
|
5
|
+
* Replaces `commit4spec/reverse_engineer/pipeline.py`. Discovers spec↔commit
|
|
6
|
+
* pairs via `scan()`, persists them into the SQLite knowledge graph, and
|
|
7
|
+
* writes a `.homegraph/commit4spec/meta.json` anchor so the self-evolve pipeline can
|
|
8
|
+
* pick up where build left off.
|
|
9
|
+
*
|
|
10
|
+
* @module spec/build/pipeline
|
|
11
|
+
*/
|
|
12
|
+
import { SqliteDatabase } from '../../db/sqlite-adapter';
|
|
13
|
+
import type { ProgressCallback } from '../ui';
|
|
14
|
+
export interface BuildResult {
|
|
15
|
+
specsFound: number;
|
|
16
|
+
commitsFound: number;
|
|
17
|
+
fragmentsFound: number;
|
|
18
|
+
relationsCreated: number;
|
|
19
|
+
totalEntries: number;
|
|
20
|
+
skippedEntries: Array<{
|
|
21
|
+
specId: string;
|
|
22
|
+
reason: string;
|
|
23
|
+
}>;
|
|
24
|
+
upToDate?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Run the full build pipeline.
|
|
28
|
+
*
|
|
29
|
+
* Steps (ported from `pipeline.py:49-151`):
|
|
30
|
+
*
|
|
31
|
+
* 1. Initialise the spec knowledge-graph schema in the database.
|
|
32
|
+
* 2. Discover all specs on disk (for the `totalEntries` count).
|
|
33
|
+
* 3. Scan the repository for spec↔commit pairs.
|
|
34
|
+
* 4. Sort pairs by commit timestamp ascending so that `INSERT OR REPLACE`
|
|
35
|
+
* gives the most-recent commit the final word for each spec node.
|
|
36
|
+
* 5. Process each pair:
|
|
37
|
+
* - Insert a SpecNode (once per specId; deduplicated by commit timestamp).
|
|
38
|
+
* - Insert a CommitNode (once per commit hash).
|
|
39
|
+
* - Insert a SUMMARIZED_FROM relation.
|
|
40
|
+
* - Parse the commit diff into code fragments and persist them.
|
|
41
|
+
* 6. Build a list of specs discovered on disk but never matched to a commit.
|
|
42
|
+
* 7. Write `.homegraph/commit4spec/meta.json`.
|
|
43
|
+
* 8. Return the `BuildResult` with all counts.
|
|
44
|
+
*
|
|
45
|
+
* Edge cases:
|
|
46
|
+
* - Empty pairs → zero counts, write meta anyway, return result.
|
|
47
|
+
* - Pair with commit metadata but no spec metadata → commit and fragments
|
|
48
|
+
* are still persisted; SpecNode and spec_commit_relation are skipped.
|
|
49
|
+
* - Pair with spec metadata but no commit metadata → entire pair is skipped.
|
|
50
|
+
* - Same spec in multiple pairs → only counted once in `specsFound`, but
|
|
51
|
+
* every commit relation is created.
|
|
52
|
+
*/
|
|
53
|
+
export declare function runBuildPipeline(repoPath: string, specStoragePath: string, db: SqliteDatabase, onProgress?: ProgressCallback): BuildResult;
|
|
54
|
+
//# sourceMappingURL=pipeline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../../../src/spec/build/pipeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAWzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAM9C,MAAM,WAAW,WAAW;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,KAAK,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC1D,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,eAAe,EAAE,MAAM,EACvB,EAAE,EAAE,cAAc,EAClB,UAAU,CAAC,EAAE,gBAAgB,GAC5B,WAAW,CAoIb"}
|