@codeledger/cli 0.7.2 → 0.7.3
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/dist/arch-policy/resolve.d.ts +11 -0
- package/dist/arch-policy/resolve.d.ts.map +1 -0
- package/dist/arch-policy/resolve.js +195 -0
- package/dist/arch-policy/resolve.js.map +1 -0
- package/dist/arch-policy/simulate.d.ts +9 -0
- package/dist/arch-policy/simulate.d.ts.map +1 -0
- package/dist/arch-policy/simulate.js +175 -0
- package/dist/arch-policy/simulate.js.map +1 -0
- package/dist/commands/activate.d.ts.map +1 -1
- package/dist/commands/activate.js +86 -0
- package/dist/commands/activate.js.map +1 -1
- package/dist/commands/arch-policy.d.ts +8 -0
- package/dist/commands/arch-policy.d.ts.map +1 -0
- package/dist/commands/arch-policy.js +349 -0
- package/dist/commands/arch-policy.js.map +1 -0
- package/dist/commands/bundle.js.map +1 -1
- package/dist/commands/claims.d.ts +14 -0
- package/dist/commands/claims.d.ts.map +1 -0
- package/dist/commands/claims.js +93 -0
- package/dist/commands/claims.js.map +1 -0
- package/dist/commands/conflicts.d.ts +12 -0
- package/dist/commands/conflicts.d.ts.map +1 -0
- package/dist/commands/conflicts.js +55 -0
- package/dist/commands/conflicts.js.map +1 -0
- package/dist/commands/dashboard.d.ts +12 -0
- package/dist/commands/dashboard.d.ts.map +1 -0
- package/dist/commands/dashboard.js +111 -0
- package/dist/commands/dashboard.js.map +1 -0
- package/dist/commands/discover-check.d.ts +19 -0
- package/dist/commands/discover-check.d.ts.map +1 -0
- package/dist/commands/discover-check.js +256 -0
- package/dist/commands/discover-check.js.map +1 -0
- package/dist/commands/discover-gate.d.ts +20 -0
- package/dist/commands/discover-gate.d.ts.map +1 -0
- package/dist/commands/discover-gate.js +131 -0
- package/dist/commands/discover-gate.js.map +1 -0
- package/dist/commands/discover.d.ts +14 -0
- package/dist/commands/discover.d.ts.map +1 -0
- package/dist/commands/discover.js +120 -0
- package/dist/commands/discover.js.map +1 -0
- package/dist/commands/health.d.ts +8 -0
- package/dist/commands/health.d.ts.map +1 -0
- package/dist/commands/health.js +101 -0
- package/dist/commands/health.js.map +1 -0
- package/dist/commands/intervene.d.ts +11 -0
- package/dist/commands/intervene.d.ts.map +1 -0
- package/dist/commands/intervene.js +94 -0
- package/dist/commands/intervene.js.map +1 -0
- package/dist/commands/interventions.d.ts +8 -0
- package/dist/commands/interventions.d.ts.map +1 -0
- package/dist/commands/interventions.js +69 -0
- package/dist/commands/interventions.js.map +1 -0
- package/dist/commands/policy-author.d.ts +48 -0
- package/dist/commands/policy-author.d.ts.map +1 -0
- package/dist/commands/policy-author.js +396 -0
- package/dist/commands/policy-author.js.map +1 -0
- package/dist/commands/pr-check.d.ts +18 -0
- package/dist/commands/pr-check.d.ts.map +1 -0
- package/dist/commands/pr-check.js +299 -0
- package/dist/commands/pr-check.js.map +1 -0
- package/dist/commands/pulse.d.ts +12 -0
- package/dist/commands/pulse.d.ts.map +1 -0
- package/dist/commands/pulse.js +61 -0
- package/dist/commands/pulse.js.map +1 -0
- package/dist/commands/refine.js.map +1 -1
- package/dist/commands/replay.js.map +1 -1
- package/dist/commands/run.js.map +1 -1
- package/dist/commands/serve.d.ts +7 -0
- package/dist/commands/serve.d.ts.map +1 -1
- package/dist/commands/serve.js +189 -2
- package/dist/commands/serve.js.map +1 -1
- package/dist/commands/upgrade.d.ts +1 -1
- package/dist/commands/upgrade.d.ts.map +1 -1
- package/dist/commands/upgrade.js +5 -1
- package/dist/commands/upgrade.js.map +1 -1
- package/dist/commands/verify.d.ts.map +1 -1
- package/dist/commands/verify.js +129 -1
- package/dist/commands/verify.js.map +1 -1
- package/dist/discovery/blast-radius.d.ts +15 -0
- package/dist/discovery/blast-radius.d.ts.map +1 -0
- package/dist/discovery/blast-radius.js +160 -0
- package/dist/discovery/blast-radius.js.map +1 -0
- package/dist/discovery/cache.d.ts +38 -0
- package/dist/discovery/cache.d.ts.map +1 -0
- package/dist/discovery/cache.js +87 -0
- package/dist/discovery/cache.js.map +1 -0
- package/dist/discovery/diff-compliance.d.ts +19 -0
- package/dist/discovery/diff-compliance.d.ts.map +1 -0
- package/dist/discovery/diff-compliance.js +96 -0
- package/dist/discovery/diff-compliance.js.map +1 -0
- package/dist/discovery/duplicate-detection.d.ts +29 -0
- package/dist/discovery/duplicate-detection.d.ts.map +1 -0
- package/dist/discovery/duplicate-detection.js +133 -0
- package/dist/discovery/duplicate-detection.js.map +1 -0
- package/dist/discovery/gap-analysis.d.ts +16 -0
- package/dist/discovery/gap-analysis.d.ts.map +1 -0
- package/dist/discovery/gap-analysis.js +199 -0
- package/dist/discovery/gap-analysis.js.map +1 -0
- package/dist/discovery/index.d.ts +18 -0
- package/dist/discovery/index.d.ts.map +1 -0
- package/dist/discovery/index.js +565 -0
- package/dist/discovery/index.js.map +1 -0
- package/dist/discovery/override.d.ts +19 -0
- package/dist/discovery/override.d.ts.map +1 -0
- package/dist/discovery/override.js +113 -0
- package/dist/discovery/override.js.map +1 -0
- package/dist/discovery/scoring.d.ts +35 -0
- package/dist/discovery/scoring.d.ts.map +1 -0
- package/dist/discovery/scoring.js +194 -0
- package/dist/discovery/scoring.js.map +1 -0
- package/dist/discovery/source-of-truth.d.ts +17 -0
- package/dist/discovery/source-of-truth.d.ts.map +1 -0
- package/dist/discovery/source-of-truth.js +182 -0
- package/dist/discovery/source-of-truth.js.map +1 -0
- package/dist/discovery/symbol-growth.d.ts +20 -0
- package/dist/discovery/symbol-growth.d.ts.map +1 -0
- package/dist/discovery/symbol-growth.js +111 -0
- package/dist/discovery/symbol-growth.js.map +1 -0
- package/dist/health/advisor.d.ts +18 -0
- package/dist/health/advisor.d.ts.map +1 -0
- package/dist/health/advisor.js +174 -0
- package/dist/health/advisor.js.map +1 -0
- package/dist/health/dashboard.d.ts +96 -0
- package/dist/health/dashboard.d.ts.map +1 -0
- package/dist/health/dashboard.js +468 -0
- package/dist/health/dashboard.js.map +1 -0
- package/dist/hooks/discovery-enforcement.d.ts +9 -0
- package/dist/hooks/discovery-enforcement.d.ts.map +1 -0
- package/dist/hooks/discovery-enforcement.js +137 -0
- package/dist/hooks/discovery-enforcement.js.map +1 -0
- package/dist/hooks/discovery-hook.d.ts +22 -0
- package/dist/hooks/discovery-hook.d.ts.map +1 -0
- package/dist/hooks/discovery-hook.js +199 -0
- package/dist/hooks/discovery-hook.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +180 -2
- package/dist/index.js.map +1 -1
- package/dist/intervention/drift-velocity.d.ts +19 -0
- package/dist/intervention/drift-velocity.d.ts.map +1 -0
- package/dist/intervention/drift-velocity.js +107 -0
- package/dist/intervention/drift-velocity.js.map +1 -0
- package/dist/intervention/engine.d.ts +43 -0
- package/dist/intervention/engine.d.ts.map +1 -0
- package/dist/intervention/engine.js +356 -0
- package/dist/intervention/engine.js.map +1 -0
- package/dist/intervention/templates.d.ts +23 -0
- package/dist/intervention/templates.d.ts.map +1 -0
- package/dist/intervention/templates.js +167 -0
- package/dist/intervention/templates.js.map +1 -0
- package/dist/policy/realtime.d.ts +17 -0
- package/dist/policy/realtime.d.ts.map +1 -0
- package/dist/policy/realtime.js +108 -0
- package/dist/policy/realtime.js.map +1 -0
- package/dist/policy/schema.d.ts.map +1 -1
- package/dist/policy/schema.js +137 -0
- package/dist/policy/schema.js.map +1 -1
- package/dist/session-registry.d.ts +1 -1
- package/dist/session-registry.d.ts.map +1 -1
- package/dist/session-registry.js +2 -0
- package/dist/session-registry.js.map +1 -1
- package/dist/verify/insertion-point-lock.d.ts +12 -0
- package/dist/verify/insertion-point-lock.d.ts.map +1 -0
- package/dist/verify/insertion-point-lock.js +208 -0
- package/dist/verify/insertion-point-lock.js.map +1 -0
- package/dist/verify/symbol-growth.d.ts +13 -0
- package/dist/verify/symbol-growth.d.ts.map +1 -0
- package/dist/verify/symbol-growth.js +143 -0
- package/dist/verify/symbol-growth.js.map +1 -0
- package/package.json +10 -10
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
// ─── Discovery Blast Radius ──────────────────────────────────────────────────
|
|
2
|
+
//
|
|
3
|
+
// Phase 1.4: Compute blast radius for top discovery matches.
|
|
4
|
+
// For each match, determines direct/transitive dependents, shared modules,
|
|
5
|
+
// impacted tests, and risk classification.
|
|
6
|
+
//
|
|
7
|
+
// Deterministic: same inputs → same output. All traversals are bounded.
|
|
8
|
+
/** Maximum BFS depth for transitive dependents */
|
|
9
|
+
const MAX_BFS_DEPTH = 3;
|
|
10
|
+
/** Maximum transitive dependents collected per file */
|
|
11
|
+
const MAX_TRANSITIVE_PER_FILE = 20;
|
|
12
|
+
/** Number of top direct-overlap matches to analyze */
|
|
13
|
+
const TOP_MATCH_COUNT = 5;
|
|
14
|
+
/**
|
|
15
|
+
* BFS to collect transitive dependents up to a bounded depth and count.
|
|
16
|
+
* Returns deduplicated transitive dependents (excluding the root and direct dependents).
|
|
17
|
+
*/
|
|
18
|
+
function collectTransitiveDependents(root, directDeps, depGraph) {
|
|
19
|
+
const visited = new Set([root, ...directDeps]);
|
|
20
|
+
const transitive = [];
|
|
21
|
+
// Seed the BFS queue with direct dependents at depth 1
|
|
22
|
+
let frontier = [...directDeps];
|
|
23
|
+
let depth = 1;
|
|
24
|
+
while (depth < MAX_BFS_DEPTH && frontier.length > 0 && transitive.length < MAX_TRANSITIVE_PER_FILE) {
|
|
25
|
+
const nextFrontier = [];
|
|
26
|
+
for (const node of frontier) {
|
|
27
|
+
const neighbors = depGraph.dependents[node] ?? [];
|
|
28
|
+
for (const neighbor of neighbors) {
|
|
29
|
+
if (visited.has(neighbor))
|
|
30
|
+
continue;
|
|
31
|
+
visited.add(neighbor);
|
|
32
|
+
transitive.push(neighbor);
|
|
33
|
+
nextFrontier.push(neighbor);
|
|
34
|
+
if (transitive.length >= MAX_TRANSITIVE_PER_FILE)
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
if (transitive.length >= MAX_TRANSITIVE_PER_FILE)
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
frontier = nextFrontier;
|
|
41
|
+
depth++;
|
|
42
|
+
}
|
|
43
|
+
return transitive.sort();
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Find shared modules: files imported by both the match file AND at least one of its dependents.
|
|
47
|
+
*/
|
|
48
|
+
function findSharedModules(matchPath, dependents, depGraph) {
|
|
49
|
+
const matchImports = new Set(depGraph.imports[matchPath] ?? []);
|
|
50
|
+
if (matchImports.size === 0)
|
|
51
|
+
return [];
|
|
52
|
+
const shared = new Set();
|
|
53
|
+
for (const dep of dependents) {
|
|
54
|
+
const depImports = depGraph.imports[dep] ?? [];
|
|
55
|
+
for (const imp of depImports) {
|
|
56
|
+
if (matchImports.has(imp) && imp !== matchPath) {
|
|
57
|
+
shared.add(imp);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return [...shared].sort();
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Find impacted tests for a given file path via the test mapping.
|
|
65
|
+
*/
|
|
66
|
+
function findImpactedTests(filePath, allDependents, testMap) {
|
|
67
|
+
if (testMap.length === 0)
|
|
68
|
+
return [];
|
|
69
|
+
// Build a lookup: source_file → test_file[]
|
|
70
|
+
const sourceToTests = new Map();
|
|
71
|
+
for (const mapping of testMap) {
|
|
72
|
+
const existing = sourceToTests.get(mapping.source_file);
|
|
73
|
+
if (existing) {
|
|
74
|
+
existing.push(mapping.test_file);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
sourceToTests.set(mapping.source_file, [mapping.test_file]);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const tests = new Set();
|
|
81
|
+
// Tests for the file itself
|
|
82
|
+
const directTests = sourceToTests.get(filePath);
|
|
83
|
+
if (directTests) {
|
|
84
|
+
for (const t of directTests)
|
|
85
|
+
tests.add(t);
|
|
86
|
+
}
|
|
87
|
+
// Tests for all dependents
|
|
88
|
+
for (const dep of allDependents) {
|
|
89
|
+
const depTests = sourceToTests.get(dep);
|
|
90
|
+
if (depTests) {
|
|
91
|
+
for (const t of depTests)
|
|
92
|
+
tests.add(t);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return [...tests].sort();
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Classify risk based on direct dependent count.
|
|
99
|
+
*/
|
|
100
|
+
function classifyRisk(directDependentCount) {
|
|
101
|
+
if (directDependentCount > 15)
|
|
102
|
+
return 'high';
|
|
103
|
+
if (directDependentCount >= 5)
|
|
104
|
+
return 'medium';
|
|
105
|
+
return 'low';
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Compute blast radius for the top discovery matches.
|
|
109
|
+
*
|
|
110
|
+
* Analyzes the top 5 direct-overlap matches by:
|
|
111
|
+
* 1. Collecting direct dependents from the dep graph
|
|
112
|
+
* 2. BFS for transitive dependents (bounded: max depth 3, max 20 per file)
|
|
113
|
+
* 3. Finding shared modules (imported by both match and its dependents)
|
|
114
|
+
* 4. Mapping impacted tests via testMap
|
|
115
|
+
* 5. Classifying risk based on direct dependent count
|
|
116
|
+
*
|
|
117
|
+
* Returns results sorted by total impact (direct + transitive + tests) descending.
|
|
118
|
+
*/
|
|
119
|
+
export function computeDiscoveryBlastRadius(matches, depGraph, testMap) {
|
|
120
|
+
if (!matches || matches.length === 0)
|
|
121
|
+
return [];
|
|
122
|
+
const safeDepGraph = depGraph ?? { imports: {}, dependents: {} };
|
|
123
|
+
const safeTestMap = testMap ?? [];
|
|
124
|
+
// Filter to direct-overlap matches and take top N
|
|
125
|
+
const directMatches = matches
|
|
126
|
+
.filter((m) => m.overlap === 'direct')
|
|
127
|
+
.slice(0, TOP_MATCH_COUNT);
|
|
128
|
+
// If no direct matches, fall back to top N of all matches
|
|
129
|
+
const candidates = directMatches.length > 0
|
|
130
|
+
? directMatches
|
|
131
|
+
: matches.slice(0, TOP_MATCH_COUNT);
|
|
132
|
+
const results = [];
|
|
133
|
+
for (const match of candidates) {
|
|
134
|
+
const directDependents = (safeDepGraph.dependents[match.file] ?? []).sort();
|
|
135
|
+
const transitiveDependents = collectTransitiveDependents(match.file, directDependents, safeDepGraph);
|
|
136
|
+
const allDependents = [...directDependents, ...transitiveDependents];
|
|
137
|
+
const sharedModules = findSharedModules(match.file, allDependents, safeDepGraph);
|
|
138
|
+
const impactedTests = findImpactedTests(match.file, allDependents, safeTestMap);
|
|
139
|
+
const risk = classifyRisk(directDependents.length);
|
|
140
|
+
results.push({
|
|
141
|
+
system: match.system,
|
|
142
|
+
path: match.file,
|
|
143
|
+
direct_dependents: directDependents,
|
|
144
|
+
transitive_dependents: transitiveDependents,
|
|
145
|
+
shared_modules: sharedModules,
|
|
146
|
+
impacted_tests: impactedTests,
|
|
147
|
+
risk,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
// Sort by total impact descending (deterministic: tie-break on path)
|
|
151
|
+
results.sort((a, b) => {
|
|
152
|
+
const impactA = a.direct_dependents.length + a.transitive_dependents.length + a.impacted_tests.length;
|
|
153
|
+
const impactB = b.direct_dependents.length + b.transitive_dependents.length + b.impacted_tests.length;
|
|
154
|
+
if (impactB !== impactA)
|
|
155
|
+
return impactB - impactA;
|
|
156
|
+
return a.path.localeCompare(b.path);
|
|
157
|
+
});
|
|
158
|
+
return results;
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=blast-radius.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blast-radius.js","sourceRoot":"","sources":["../../src/discovery/blast-radius.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,EAAE;AACF,6DAA6D;AAC7D,2EAA2E;AAC3E,2CAA2C;AAC3C,EAAE;AACF,wEAAwE;AASxE,kDAAkD;AAClD,MAAM,aAAa,GAAG,CAAC,CAAC;AAExB,uDAAuD;AACvD,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAEnC,sDAAsD;AACtD,MAAM,eAAe,GAAG,CAAC,CAAC;AAE1B;;;GAGG;AACH,SAAS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AAM,CAAC;QACtG,MAAM,OAAO,GAAG,CAAC,CAAC,iBAAiB,CAAC,MAAM,GAAG,CAAC,CAAC,qBAAqB,CAAC,MAAM,GAAG,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC;QACtG,IAAI,OAAO,KAAK,OAAO;YAAE,OAAO,OAAO,GAAG,OAAO,CAAC;QAClD,OAAO,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discovery Cache — avoid re-running discovery for the same task within a TTL window.
|
|
3
|
+
*
|
|
4
|
+
* Cache key: SHA-256 of normalized task text.
|
|
5
|
+
* Storage: .codeledger/discovery/{taskHash}.json
|
|
6
|
+
* Default TTL: 60 minutes (configurable).
|
|
7
|
+
*/
|
|
8
|
+
import type { DiscoveryResult } from '@codeledger/types';
|
|
9
|
+
export interface DiscoveryCacheEntry {
|
|
10
|
+
task_hash: string;
|
|
11
|
+
task: string;
|
|
12
|
+
result: DiscoveryResult;
|
|
13
|
+
cached_at: string;
|
|
14
|
+
ttl_seconds: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Compute a stable hash from a task string.
|
|
18
|
+
* Normalizes: lowercase, collapse whitespace, trim.
|
|
19
|
+
*/
|
|
20
|
+
export declare function computeTaskHash(task: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Look up a cached discovery result for the given task.
|
|
23
|
+
* Returns the result if found and within TTL, or null otherwise.
|
|
24
|
+
*/
|
|
25
|
+
export declare function getCachedDiscovery(cwd: string, task: string, ttlSeconds?: number): DiscoveryResult | null;
|
|
26
|
+
/**
|
|
27
|
+
* Write a discovery result to the cache.
|
|
28
|
+
*/
|
|
29
|
+
export declare function cacheDiscoveryResult(cwd: string, task: string, result: DiscoveryResult, ttlSeconds?: number): string;
|
|
30
|
+
/**
|
|
31
|
+
* Read the latest cached discovery result (regardless of task hash).
|
|
32
|
+
*/
|
|
33
|
+
export declare function getLatestDiscovery(cwd: string): DiscoveryCacheEntry | null;
|
|
34
|
+
/**
|
|
35
|
+
* Path to the discovery directory.
|
|
36
|
+
*/
|
|
37
|
+
export declare function discoveryDir(cwd: string): string;
|
|
38
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/discovery/cache.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAQzD,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,eAAe,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGpD;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,UAAU,GAAE,MAA4B,GACvC,eAAe,GAAG,IAAI,CAgBxB;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,eAAe,EACvB,UAAU,GAAE,MAA4B,GACvC,MAAM,CAuBR;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,mBAAmB,GAAG,IAAI,CAS1E;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEhD"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discovery Cache — avoid re-running discovery for the same task within a TTL window.
|
|
3
|
+
*
|
|
4
|
+
* Cache key: SHA-256 of normalized task text.
|
|
5
|
+
* Storage: .codeledger/discovery/{taskHash}.json
|
|
6
|
+
* Default TTL: 60 minutes (configurable).
|
|
7
|
+
*/
|
|
8
|
+
import { createHash } from 'node:crypto';
|
|
9
|
+
import { readFileSync, writeFileSync, existsSync, mkdirSync, statSync } from 'node:fs';
|
|
10
|
+
import { join } from 'node:path';
|
|
11
|
+
/** Default cache TTL in seconds (60 minutes). */
|
|
12
|
+
const DEFAULT_TTL_SECONDS = 3600;
|
|
13
|
+
/** Directory under .codeledger where discovery artifacts are stored. */
|
|
14
|
+
const DISCOVERY_DIR = 'discovery';
|
|
15
|
+
/**
|
|
16
|
+
* Compute a stable hash from a task string.
|
|
17
|
+
* Normalizes: lowercase, collapse whitespace, trim.
|
|
18
|
+
*/
|
|
19
|
+
export function computeTaskHash(task) {
|
|
20
|
+
const normalized = task.toLowerCase().replace(/\s+/g, ' ').trim();
|
|
21
|
+
return createHash('sha256').update(normalized, 'utf8').digest('hex').slice(0, 16);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Look up a cached discovery result for the given task.
|
|
25
|
+
* Returns the result if found and within TTL, or null otherwise.
|
|
26
|
+
*/
|
|
27
|
+
export function getCachedDiscovery(cwd, task, ttlSeconds = DEFAULT_TTL_SECONDS) {
|
|
28
|
+
const hash = computeTaskHash(task);
|
|
29
|
+
const cachePath = join(cwd, '.codeledger', DISCOVERY_DIR, `${hash}.json`);
|
|
30
|
+
if (!existsSync(cachePath))
|
|
31
|
+
return null;
|
|
32
|
+
try {
|
|
33
|
+
const stat = statSync(cachePath);
|
|
34
|
+
const ageSeconds = (Date.now() - stat.mtimeMs) / 1000;
|
|
35
|
+
if (ageSeconds > ttlSeconds)
|
|
36
|
+
return null;
|
|
37
|
+
const entry = JSON.parse(readFileSync(cachePath, 'utf-8'));
|
|
38
|
+
return entry.result;
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Write a discovery result to the cache.
|
|
46
|
+
*/
|
|
47
|
+
export function cacheDiscoveryResult(cwd, task, result, ttlSeconds = DEFAULT_TTL_SECONDS) {
|
|
48
|
+
const hash = computeTaskHash(task);
|
|
49
|
+
const dir = join(cwd, '.codeledger', DISCOVERY_DIR);
|
|
50
|
+
if (!existsSync(dir)) {
|
|
51
|
+
mkdirSync(dir, { recursive: true });
|
|
52
|
+
}
|
|
53
|
+
const entry = {
|
|
54
|
+
task_hash: hash,
|
|
55
|
+
task,
|
|
56
|
+
result,
|
|
57
|
+
cached_at: new Date().toISOString(),
|
|
58
|
+
ttl_seconds: ttlSeconds,
|
|
59
|
+
};
|
|
60
|
+
const cachePath = join(dir, `${hash}.json`);
|
|
61
|
+
writeFileSync(cachePath, JSON.stringify(entry, null, 2) + '\n');
|
|
62
|
+
// Also write latest.json symlink-style (overwrite)
|
|
63
|
+
const latestPath = join(dir, 'latest.json');
|
|
64
|
+
writeFileSync(latestPath, JSON.stringify(entry, null, 2) + '\n');
|
|
65
|
+
return cachePath;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Read the latest cached discovery result (regardless of task hash).
|
|
69
|
+
*/
|
|
70
|
+
export function getLatestDiscovery(cwd) {
|
|
71
|
+
const latestPath = join(cwd, '.codeledger', DISCOVERY_DIR, 'latest.json');
|
|
72
|
+
if (!existsSync(latestPath))
|
|
73
|
+
return null;
|
|
74
|
+
try {
|
|
75
|
+
return JSON.parse(readFileSync(latestPath, 'utf-8'));
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Path to the discovery directory.
|
|
83
|
+
*/
|
|
84
|
+
export function discoveryDir(cwd) {
|
|
85
|
+
return join(cwd, '.codeledger', DISCOVERY_DIR);
|
|
86
|
+
}
|
|
87
|
+
//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nB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAW;IAC5C,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,CAAC,CAAC;IAC1E,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC;QAAE,OAAO,IAAI,CAAC;IAEzC,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAwB,CAAC;IAC9E,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW;IACtC,OAAO,IAAI,CAAC,GAAG,EAAE,aAAa,EAAE,aAAa,CAAC,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Diff Compliance — check PR changed files against discovery constraints.
|
|
3
|
+
*
|
|
4
|
+
* Validates that:
|
|
5
|
+
* 1. No changes in prohibited file zones
|
|
6
|
+
* 2. New files are at insertion points (when extension posture)
|
|
7
|
+
* 3. No parallel directories created when extension is required
|
|
8
|
+
*/
|
|
9
|
+
import type { DiscoveryResult, DiffComplianceResult } from '@codeledger/types';
|
|
10
|
+
/**
|
|
11
|
+
* Check a list of changed files against discovery constraints.
|
|
12
|
+
*
|
|
13
|
+
* @param changedFiles - files from git diff (relative paths)
|
|
14
|
+
* @param newFiles - subset of changedFiles that are newly created
|
|
15
|
+
* @param discovery - discovery result to check against
|
|
16
|
+
* @returns DiffComplianceResult with status and violations
|
|
17
|
+
*/
|
|
18
|
+
export declare function checkDiffCompliance(changedFiles: string[], newFiles: string[], discovery: DiscoveryResult): DiffComplianceResult;
|
|
19
|
+
//# sourceMappingURL=diff-compliance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff-compliance.d.ts","sourceRoot":"","sources":["../../src/discovery/diff-compliance.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,oBAAoB,EAA2B,MAAM,mBAAmB,CAAC;AAExG;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,MAAM,EAAE,EACtB,QAAQ,EAAE,MAAM,EAAE,EAClB,SAAS,EAAE,eAAe,GACzB,oBAAoB,CAgFtB"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Diff Compliance — check PR changed files against discovery constraints.
|
|
3
|
+
*
|
|
4
|
+
* Validates that:
|
|
5
|
+
* 1. No changes in prohibited file zones
|
|
6
|
+
* 2. New files are at insertion points (when extension posture)
|
|
7
|
+
* 3. No parallel directories created when extension is required
|
|
8
|
+
*/
|
|
9
|
+
import { dirname } from 'node:path';
|
|
10
|
+
/**
|
|
11
|
+
* Check a list of changed files against discovery constraints.
|
|
12
|
+
*
|
|
13
|
+
* @param changedFiles - files from git diff (relative paths)
|
|
14
|
+
* @param newFiles - subset of changedFiles that are newly created
|
|
15
|
+
* @param discovery - discovery result to check against
|
|
16
|
+
* @returns DiffComplianceResult with status and violations
|
|
17
|
+
*/
|
|
18
|
+
export function checkDiffCompliance(changedFiles, newFiles, discovery) {
|
|
19
|
+
const violations = [];
|
|
20
|
+
// Check 1: Prohibited files
|
|
21
|
+
// For each changed/new file, check if it matches any prohibited_files pattern
|
|
22
|
+
for (const file of changedFiles) {
|
|
23
|
+
for (const prohibited of discovery.prohibited_files) {
|
|
24
|
+
// prohibited is a directory pattern like "packages/cli/src/foo/"
|
|
25
|
+
// Match if file starts with the prohibited path
|
|
26
|
+
if (file.startsWith(prohibited) || file === prohibited.replace(/\/$/, '')) {
|
|
27
|
+
violations.push({
|
|
28
|
+
type: 'prohibited_file',
|
|
29
|
+
file,
|
|
30
|
+
message: `File is in prohibited zone: ${prohibited}`,
|
|
31
|
+
severity: 'error',
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// Check 2: New files outside insertion points (only when posture requires extension)
|
|
37
|
+
const extensionPostures = ['EXTEND_EXISTING_SYSTEM', 'WRAP_EXISTING_SYSTEM', 'ADD_ADAPTER_LAYER'];
|
|
38
|
+
if (extensionPostures.includes(discovery.posture) && discovery.insertion_points.length > 0) {
|
|
39
|
+
for (const newFile of newFiles) {
|
|
40
|
+
// Skip test files — always allowed
|
|
41
|
+
if (isTestFile(newFile))
|
|
42
|
+
continue;
|
|
43
|
+
const isAtInsertionPoint = discovery.insertion_points.some((ip) => {
|
|
44
|
+
// Exact match or same directory
|
|
45
|
+
if (newFile === ip)
|
|
46
|
+
return true;
|
|
47
|
+
const ipDir = dirname(ip);
|
|
48
|
+
const newDir = dirname(newFile);
|
|
49
|
+
return newDir === ipDir;
|
|
50
|
+
});
|
|
51
|
+
if (!isAtInsertionPoint) {
|
|
52
|
+
violations.push({
|
|
53
|
+
type: 'outside_insertion_points',
|
|
54
|
+
file: newFile,
|
|
55
|
+
message: `New file created outside insertion points (posture: ${discovery.posture})`,
|
|
56
|
+
severity: discovery.posture === 'WRAP_EXISTING_SYSTEM' ? 'error' : 'warn',
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// Check 3: Parallel directory detection
|
|
62
|
+
// If discovery found direct-overlap systems, check if new files create parallel directories
|
|
63
|
+
if (discovery.source_of_truth && newFiles.length > 0) {
|
|
64
|
+
const sotDir = dirname(discovery.source_of_truth.path);
|
|
65
|
+
const sotParent = dirname(sotDir);
|
|
66
|
+
for (const newFile of newFiles) {
|
|
67
|
+
if (isTestFile(newFile))
|
|
68
|
+
continue;
|
|
69
|
+
const newDir = dirname(newFile);
|
|
70
|
+
const newParent = dirname(newDir);
|
|
71
|
+
// If the new file's parent directory is the same as the SoT's parent,
|
|
72
|
+
// but in a different subdirectory, it may be a parallel directory
|
|
73
|
+
if (newParent === sotParent && newDir !== sotDir) {
|
|
74
|
+
violations.push({
|
|
75
|
+
type: 'parallel_directory',
|
|
76
|
+
file: newFile,
|
|
77
|
+
message: `New file creates parallel directory to source-of-truth (${discovery.source_of_truth.system})`,
|
|
78
|
+
severity: 'warn',
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// Determine status
|
|
84
|
+
const hasErrors = violations.some((v) => v.severity === 'error');
|
|
85
|
+
const hasWarnings = violations.some((v) => v.severity === 'warn');
|
|
86
|
+
const status = hasErrors ? 'fail' : hasWarnings ? 'warn' : 'pass';
|
|
87
|
+
return {
|
|
88
|
+
status,
|
|
89
|
+
violations,
|
|
90
|
+
files_checked: changedFiles.length,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function isTestFile(path) {
|
|
94
|
+
return /\.(test|spec)\.[jt]sx?$/.test(path) || path.includes('__tests__') || path.startsWith('tests/');
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=diff-compliance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff-compliance.js","sourceRoot":"","sources":["../../src/discovery/diff-compliance.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CACjC,YAAsB,EACtB,QAAkB,EAClB,SAA0B;IAE1B,MAAM,UAAU,GAA8B,EAAE,CAAC;IAEjD,4BAA4B;IAC5B,8EAA8E;IAC9E,KAAK,MAAM,IAAI,IAAI,YAAY,EAAE,CAAC;QAChC,KAAK,MAAM,UAAU,IAAI,SAAS,CAAC,gBAAgB,EAAE,CAAC;YACpD,iEAAiE;YACjE,gDAAgD;YAChD,IAAI,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,IAAI,KAAK,UAAU,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,CAA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IAAY;IAC9B,OAAO,yBAAyB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;AACzG,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content-Based Duplicate Detection — detect when new files replicate existing system logic.
|
|
3
|
+
*
|
|
4
|
+
* Uses token-level Jaccard similarity to compare new files in a PR diff against
|
|
5
|
+
* source-of-truth files identified by the discovery gate.
|
|
6
|
+
*/
|
|
7
|
+
import type { DiscoveryResult, DuplicateDetectionResult } from '@codeledger/types';
|
|
8
|
+
/**
|
|
9
|
+
* Check new files against source-of-truth files for content duplication.
|
|
10
|
+
*
|
|
11
|
+
* @param cwd - repository root
|
|
12
|
+
* @param newFiles - newly created files from git diff (relative paths)
|
|
13
|
+
* @param discovery - discovery result with source_of_truth and matches
|
|
14
|
+
* @param threshold - Jaccard similarity threshold [0, 1] (default 0.75)
|
|
15
|
+
* @returns DuplicateDetectionResult
|
|
16
|
+
*/
|
|
17
|
+
export declare function detectDuplicates(cwd: string, newFiles: string[], discovery: DiscoveryResult, threshold?: number): DuplicateDetectionResult;
|
|
18
|
+
/**
|
|
19
|
+
* Tokenize source code into a set of meaningful tokens.
|
|
20
|
+
* Strips comments, normalizes whitespace, extracts identifiers and keywords.
|
|
21
|
+
*/
|
|
22
|
+
declare function tokenize(content: string): Set<string>;
|
|
23
|
+
/**
|
|
24
|
+
* Compute Jaccard similarity between two token sets.
|
|
25
|
+
* J(A, B) = |A ∩ B| / |A ∪ B|
|
|
26
|
+
*/
|
|
27
|
+
declare function jaccardSimilarity(a: Set<string>, b: Set<string>): number;
|
|
28
|
+
export { tokenize as _tokenize, jaccardSimilarity as _jaccardSimilarity };
|
|
29
|
+
//# sourceMappingURL=duplicate-detection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duplicate-detection.d.ts","sourceRoot":"","sources":["../../src/discovery/duplicate-detection.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAE,eAAe,EAAE,wBAAwB,EAAkB,MAAM,mBAAmB,CAAC;AAEnG;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAAE,EAClB,SAAS,EAAE,eAAe,EAC1B,SAAS,GAAE,MAAa,GACvB,wBAAwB,CAoE1B;AAED;;;GAGG;AACH,iBAAS,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAuB9C;AAED;;;GAGG;AACH,iBAAS,iBAAiB,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,CAgBjE;AAGD,OAAO,EAAE,QAAQ,IAAI,SAAS,EAAE,iBAAiB,IAAI,kBAAkB,EAAE,CAAC"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content-Based Duplicate Detection — detect when new files replicate existing system logic.
|
|
3
|
+
*
|
|
4
|
+
* Uses token-level Jaccard similarity to compare new files in a PR diff against
|
|
5
|
+
* source-of-truth files identified by the discovery gate.
|
|
6
|
+
*/
|
|
7
|
+
import { readFileSync, existsSync } from 'node:fs';
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
/**
|
|
10
|
+
* Check new files against source-of-truth files for content duplication.
|
|
11
|
+
*
|
|
12
|
+
* @param cwd - repository root
|
|
13
|
+
* @param newFiles - newly created files from git diff (relative paths)
|
|
14
|
+
* @param discovery - discovery result with source_of_truth and matches
|
|
15
|
+
* @param threshold - Jaccard similarity threshold [0, 1] (default 0.75)
|
|
16
|
+
* @returns DuplicateDetectionResult
|
|
17
|
+
*/
|
|
18
|
+
export function detectDuplicates(cwd, newFiles, discovery, threshold = 0.75) {
|
|
19
|
+
const duplicates = [];
|
|
20
|
+
// Collect existing files to compare against: SoT file + top direct matches
|
|
21
|
+
const existingFiles = [];
|
|
22
|
+
if (discovery.source_of_truth) {
|
|
23
|
+
existingFiles.push(discovery.source_of_truth.path);
|
|
24
|
+
}
|
|
25
|
+
for (const match of discovery.matches.filter((m) => m.overlap === 'direct').slice(0, 5)) {
|
|
26
|
+
if (!existingFiles.includes(match.file)) {
|
|
27
|
+
existingFiles.push(match.file);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (existingFiles.length === 0) {
|
|
31
|
+
return { duplicates: [], files_checked: newFiles.length };
|
|
32
|
+
}
|
|
33
|
+
// Pre-tokenize existing files
|
|
34
|
+
const existingTokenSets = [];
|
|
35
|
+
for (const ef of existingFiles) {
|
|
36
|
+
const fullPath = join(cwd, ef);
|
|
37
|
+
if (!existsSync(fullPath))
|
|
38
|
+
continue;
|
|
39
|
+
try {
|
|
40
|
+
const content = readFileSync(fullPath, 'utf-8');
|
|
41
|
+
existingTokenSets.push({ file: ef, tokens: tokenize(content) });
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// Compare each new file against existing files
|
|
48
|
+
for (const newFile of newFiles) {
|
|
49
|
+
// Skip test files
|
|
50
|
+
if (/\.(test|spec)\.[jt]sx?$/.test(newFile))
|
|
51
|
+
continue;
|
|
52
|
+
if (!/\.[jt]sx?$/.test(newFile))
|
|
53
|
+
continue;
|
|
54
|
+
const fullPath = join(cwd, newFile);
|
|
55
|
+
if (!existsSync(fullPath))
|
|
56
|
+
continue;
|
|
57
|
+
let newContent;
|
|
58
|
+
try {
|
|
59
|
+
newContent = readFileSync(fullPath, 'utf-8');
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
// Skip very small files (less than 10 tokens — likely just re-exports or stubs)
|
|
65
|
+
const newTokens = tokenize(newContent);
|
|
66
|
+
if (newTokens.size < 10)
|
|
67
|
+
continue;
|
|
68
|
+
for (const existing of existingTokenSets) {
|
|
69
|
+
const similarity = jaccardSimilarity(newTokens, existing.tokens);
|
|
70
|
+
if (similarity >= threshold) {
|
|
71
|
+
duplicates.push({
|
|
72
|
+
new_file: newFile,
|
|
73
|
+
existing_file: existing.file,
|
|
74
|
+
similarity: Math.round(similarity * 100) / 100,
|
|
75
|
+
message: `New file has ${(similarity * 100).toFixed(0)}% token similarity with ${existing.file}`,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
duplicates,
|
|
82
|
+
files_checked: newFiles.length,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Tokenize source code into a set of meaningful tokens.
|
|
87
|
+
* Strips comments, normalizes whitespace, extracts identifiers and keywords.
|
|
88
|
+
*/
|
|
89
|
+
function tokenize(content) {
|
|
90
|
+
// Remove single-line comments
|
|
91
|
+
let cleaned = content.replace(/\/\/.*$/gm, '');
|
|
92
|
+
// Remove multi-line comments
|
|
93
|
+
cleaned = cleaned.replace(/\/\*[\s\S]*?\*\//g, '');
|
|
94
|
+
// Remove string literals (to avoid false positives from similar strings)
|
|
95
|
+
cleaned = cleaned.replace(/'[^']*'/g, '""');
|
|
96
|
+
cleaned = cleaned.replace(/"[^"]*"/g, '""');
|
|
97
|
+
cleaned = cleaned.replace(/`[^`]*`/g, '""');
|
|
98
|
+
// Extract tokens: identifiers, keywords, operators
|
|
99
|
+
const tokens = new Set();
|
|
100
|
+
const tokenRe = /[a-zA-Z_$][a-zA-Z0-9_$]*/g;
|
|
101
|
+
let m;
|
|
102
|
+
while ((m = tokenRe.exec(cleaned)) !== null) {
|
|
103
|
+
const tok = m[0];
|
|
104
|
+
// Skip very short tokens (single char) and common noise
|
|
105
|
+
if (tok.length > 1) {
|
|
106
|
+
tokens.add(tok.toLowerCase());
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return tokens;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Compute Jaccard similarity between two token sets.
|
|
113
|
+
* J(A, B) = |A ∩ B| / |A ∪ B|
|
|
114
|
+
*/
|
|
115
|
+
function jaccardSimilarity(a, b) {
|
|
116
|
+
if (a.size === 0 && b.size === 0)
|
|
117
|
+
return 1;
|
|
118
|
+
if (a.size === 0 || b.size === 0)
|
|
119
|
+
return 0;
|
|
120
|
+
let intersection = 0;
|
|
121
|
+
const smaller = a.size <= b.size ? a : b;
|
|
122
|
+
const larger = a.size <= b.size ? b : a;
|
|
123
|
+
for (const token of smaller) {
|
|
124
|
+
if (larger.has(token)) {
|
|
125
|
+
intersection++;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
const union = a.size + b.size - intersection;
|
|
129
|
+
return union > 0 ? intersection / union : 0;
|
|
130
|
+
}
|
|
131
|
+
// Export for testing
|
|
132
|
+
export { tokenize as _tokenize, jaccardSimilarity as _jaccardSimilarity };
|
|
133
|
+
//# sourceMappingURL=duplicate-detection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duplicate-detection.js","sourceRoot":"","sources":["../../src/discovery/duplicate-detection.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAC9B,GAAW,EACX,QAAkB,EAClB,SAA0B,EAC1B,YAAoB,IAAI;IAExB,MAAM,UAAU,GAAqB,EAAE,CAAC;IAExC,2EAA2E;IAC3E,MAAM,aAAa,GAAa,EAAE,CAAC;IACnC,IAAI,SAAS,CAAC,eAAe,EAAE,CAAC;QAC9B,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACrD,CA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C;IAExC,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YACtB,YAAY,EAAE,CAAC;QACjB,CAAC;IACH,CAAC;IAED,MAAM,KAAK,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,GAAG,YAAY,CAAC;IAC7C,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9C,CAAC;AAED,qBAAqB;AACrB,OAAO,EAAE,QAAQ,IAAI,SAAS,EAAE,iBAAiB,IAAI,kBAAkB,EAAE,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { DiscoveryMatch, DiscoveryGapAnalysis, DiscoverySourceOfTruth, IntentObject } from '@codeledger/types';
|
|
2
|
+
/**
|
|
3
|
+
* Analyze gaps between what the task requires and what the source-of-truth system provides.
|
|
4
|
+
*
|
|
5
|
+
* Algorithm:
|
|
6
|
+
* 1. Collect all exported symbols from SoT system files
|
|
7
|
+
* 2. Match task keywords/entities against exports to find existing_exports
|
|
8
|
+
* 3. Compute coverage_estimate = matched / total, clamped to [0, 1]
|
|
9
|
+
* 4. Identify missing_capabilities (unmatched entities + keywords)
|
|
10
|
+
* 5. For each missing capability, recommend the closest SoT file as extension target
|
|
11
|
+
* 6. Set warning when coverage > 70%
|
|
12
|
+
*
|
|
13
|
+
* Returns a minimal result with coverage 0 if no sourceOfTruth is provided.
|
|
14
|
+
*/
|
|
15
|
+
export declare function analyzeGaps(sourceOfTruth: DiscoverySourceOfTruth | null | undefined, matches: DiscoveryMatch[], intent: IntentObject | null | undefined, keywords: string[], cwd: string): DiscoveryGapAnalysis;
|
|
16
|
+
//# sourceMappingURL=gap-analysis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gap-analysis.d.ts","sourceRoot":"","sources":["../../src/discovery/gap-analysis.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACpB,sBAAsB,EACtB,YAAY,EACb,MAAM,mBAAmB,CAAC;AAyF3B;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CACzB,aAAa,EAAE,sBAAsB,GAAG,IAAI,GAAG,SAAS,EACxD,OAAO,EAAE,cAAc,EAAE,EACzB,MAAM,EAAE,YAAY,GAAG,IAAI,GAAG,SAAS,EACvC,QAAQ,EAAE,MAAM,EAAE,EAClB,GAAG,EAAE,MAAM,GACV,oBAAoB,CA2HtB"}
|