@aburi/diff 0.4.0 → 0.6.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 +5 -2
- package/dist/index.d.mts +44 -449
- package/dist/index.mjs +1 -1
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -12,8 +12,11 @@ Symbols are paired across base / head via cascading stages:
|
|
|
12
12
|
1. **id-match** — `<language>:<path>#<qname>` equal → same Symbol.
|
|
13
13
|
2. **git-rename** — optional table (from `git diff --find-renames`) rescues moved
|
|
14
14
|
files whose ids diverged only in the path segment.
|
|
15
|
-
3. **logic-fingerprint** — remaining Symbols with the same
|
|
16
|
-
hash pair up (rename-invariant, whitespace-invariant).
|
|
15
|
+
3. **logic-fingerprint** — remaining Symbols of the same kind with the same
|
|
16
|
+
`fingerprint.logic` hash pair up (rename-invariant, whitespace-invariant). Where
|
|
17
|
+
that logic names nothing (a class, a body that only calls something), unrelated
|
|
18
|
+
bodies share the hash, so a pair there also needs names of two words or more
|
|
19
|
+
with a similarity of 0.85.
|
|
17
20
|
4. **name+signature** — same simple name + compatible `Signature` (input/output
|
|
18
21
|
set + throws) — the fuzzy layer.
|
|
19
22
|
5. **dropped-weak** — last-resort match for pairs where both sides are dropped
|
package/dist/index.d.mts
CHANGED
|
@@ -1,91 +1,26 @@
|
|
|
1
1
|
import { CallEdge, IntegrityViolation, SerializeOptions } from "@aburi/core";
|
|
2
|
-
import { Component, ComponentDiff, Dependency, DependencyDiff, DependencyEndpoint, DependencyUnknown, DiffResult, IR, IRRef, MatchRationale, NotComparedFile, RelativePath, Signature, SkipReason, SliceRecord, Summary, Symbol, SymbolChange, SymbolDelta, SymbolId } from "@aburi/types";
|
|
2
|
+
import { Component, ComponentDiff, Dependency, DependencyDiff, DependencyEndpoint, DependencyUnknown, DiffResult, DiffSkippedFile, IR, IRRef, Logger, MatchRationale, NotComparedFile, RelativePath, Signature, SkipReason, SliceRecord, Summary, Symbol, SymbolChange, SymbolDelta, SymbolId } from "@aburi/types";
|
|
3
3
|
|
|
4
4
|
//#region src/components.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* `docs/design/diff-algorithm.md` §6.1 — Component diff. Assumes `components[].id` is unique on each side (ir-schema.md §14
|
|
7
|
-
* #2) and does not check it: `buildDiff` establishes that before calling, and a caller
|
|
8
|
-
* reaching this export directly owns the obligation, because the lookup map here is
|
|
9
|
-
* last-write-wins and a repeat is lost rather than reported.
|
|
10
|
-
*
|
|
11
|
-
* Component identity is `id`; when a Component is present in both base and head with the same
|
|
12
|
-
* id, *any* field that differs makes it `changed` — the whole object is compared, not the three
|
|
13
|
-
* axes the delta names. Those two questions were conflated once: a rename, an added language or
|
|
14
|
-
* an edited description left the diff reporting `componentsChanged: 0` and an empty `changed[]`,
|
|
15
|
-
* so the projection layer had no before/after pair to render. The delta booleans stay exactly
|
|
16
|
-
* what they were — a summary of the three axes a reviewer scans for architectural movement — and
|
|
17
|
-
* a `changed[]` entry with all three `false` is a well-formed answer meaning "something else
|
|
18
|
-
* about this component moved", not a bug.
|
|
19
|
-
*
|
|
20
|
-
* `modified` deltas are intentionally absent from this diff (diff-algorithm.md §5.2.3): fields
|
|
21
|
-
* are reported as before/after pairs via the `changed[]` entries so consumers can render them
|
|
22
|
-
* without stringifying arrays.
|
|
23
|
-
*/
|
|
24
5
|
declare function diffComponents(base: readonly Component[], head: readonly Component[]): ComponentDiff;
|
|
25
|
-
/**
|
|
26
|
-
* What one document knows about itself, for deciding whether the *other* document's silence
|
|
27
|
-
* about an edge is evidence.
|
|
28
|
-
*
|
|
29
|
-
* `symbolFiles` is keyed on the endpoint id exactly as `dependencies[]` spells it, and its
|
|
30
|
-
* values come from `symbols[].source.file` — the same space `stats.skippedFiles[].path` is in,
|
|
31
|
-
* and the same space `buildDiff` classifies Symbols by. Reading the file out of the id's path
|
|
32
|
-
* segment instead would introduce a second answer to "which file is this endpoint in", and
|
|
33
|
-
* nothing in the schema forces the two to agree; a Symbol reported `unknown` while its edges
|
|
34
|
-
* stayed `removed` is precisely the inconsistency this exists to remove.
|
|
35
|
-
*
|
|
36
|
-
* A Component endpoint is absent from the map, which is how it stays out of the reclassification
|
|
37
|
-
* without a special case: a Component is an aggregate over roots and has no file to lose.
|
|
38
|
-
*/
|
|
39
6
|
interface DependencySideView {
|
|
40
|
-
/**
|
|
41
|
-
* `source.file` of every Symbol this document holds, by the id an endpoint would name it
|
|
42
|
-
* with. Keyed by `DependencyEndpoint` rather than `SymbolId` because that is the question
|
|
43
|
-
* being asked: the lookup happens with an endpoint whose kind is not yet known, and "absent"
|
|
44
|
-
* is the answer for a Component id. Demanding the kind up front would move that decision to
|
|
45
|
-
* the caller, where it would need a second Symbol-id silhouette test to make.
|
|
46
|
-
*/
|
|
47
7
|
symbolFiles: ReadonlyMap<DependencyEndpoint, RelativePath>;
|
|
48
|
-
/**
|
|
49
|
-
* Files this document never analysed, by path, with the reason it gave. `RelativePath` on
|
|
50
|
-
* both sides of the file space is what states the bridge these two maps exist to make — one
|
|
51
|
-
* map's values are the other's keys — though the alias is unbranded, so it is intent rather
|
|
52
|
-
* than enforcement.
|
|
53
|
-
*/
|
|
54
8
|
lostFiles: ReadonlyMap<RelativePath, SkipReason>;
|
|
9
|
+
/** The skipped files each Component holds, by the document's own `components[]`. */
|
|
10
|
+
componentLostFiles: ReadonlyMap<DependencyEndpoint, readonly DiffSkippedFile[]>;
|
|
55
11
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
*
|
|
63
|
-
* Exported because `DependencySideView` is public and `diffDependencies` requires one: without
|
|
64
|
-
* a factory a caller would have to reproduce the `symbols[].source.file` keying and the
|
|
65
|
-
* `stats.skippedFiles` read, and the likeliest outcome of that is a caller who gets it wrong.
|
|
66
|
-
*/
|
|
67
|
-
declare function dependencySideView(ir: IR): DependencySideView;
|
|
68
|
-
/**
|
|
69
|
-
* `docs/design/diff-algorithm.md` §6.2 — Dependency diff. Identity is the composite
|
|
70
|
-
* `(from, to, via)` triple; direction and effect changes are surfaced as an added + removed
|
|
71
|
-
* pair so `modified` is not part of the schema (§6.2 tail). Uniqueness of that triple is the caller's obligation on the same
|
|
72
|
-
* terms as `diffComponents` above — a repeat here is indistinguishable in the output from
|
|
73
|
-
* the flip it encodes.
|
|
74
|
-
*
|
|
75
|
-
* `sides` is what separates a deletion from a loss (`docs/design/diff-algorithm.md` §6.2.1).
|
|
76
|
-
* It is required rather than optional: omitting it would classify every edge into a lost file
|
|
77
|
-
* as a deletion again — silently, and while still writing `unknown: []`, which this schema
|
|
78
|
-
* defines as "nothing was unknown" rather than "nobody looked". A caller with no skip list to
|
|
79
|
-
* offer says so by passing a side view whose `lostFiles` is empty, which is the honest spelling
|
|
80
|
-
* of an IR written before `stats.skippedFiles` existed.
|
|
81
|
-
*
|
|
82
|
-
* The return type declares `unknown` present, where the schema leaves it optional for documents
|
|
83
|
-
* that predate the field. A reader may find it missing; this function always writes it.
|
|
84
|
-
*/
|
|
85
|
-
declare function diffDependencies(base: readonly Dependency[], head: readonly Dependency[], sides: {
|
|
12
|
+
interface RenameDirections {
|
|
13
|
+
readonly baseToHead: ReadonlyMap<RelativePath, RelativePath>;
|
|
14
|
+
readonly headToBase: ReadonlyMap<RelativePath, readonly RelativePath[]>;
|
|
15
|
+
}
|
|
16
|
+
declare function renameDirections(renames: ReadonlyMap<RelativePath, RelativePath> | null): RenameDirections;
|
|
17
|
+
interface LossSides {
|
|
86
18
|
base: DependencySideView;
|
|
87
19
|
head: DependencySideView;
|
|
88
|
-
|
|
20
|
+
renames: RenameDirections;
|
|
21
|
+
}
|
|
22
|
+
declare function dependencySideView(ir: IR): DependencySideView;
|
|
23
|
+
declare function diffDependencies(base: readonly Dependency[], head: readonly Dependency[], sides: LossSides, pairedHeadIds: ReadonlyMap<DependencyEndpoint, DependencyEndpoint>): DependencyDiff & {
|
|
89
24
|
unknown: DependencyUnknown[];
|
|
90
25
|
};
|
|
91
26
|
//#endregion
|
|
@@ -95,259 +30,72 @@ declare const MAX_LINE_FUZZ = 10;
|
|
|
95
30
|
declare const MIN_LINE_FUZZ = 0;
|
|
96
31
|
interface DeltaOptions {
|
|
97
32
|
/**
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
* the field falls back to `DEFAULT_LINE_FUZZ` (2).
|
|
33
|
+
* How many lines apart, each counted from its own Symbol's first line, an edited rule, call or
|
|
34
|
+
* decorator may sit from its predecessor and still pair with it: an integer from
|
|
35
|
+
* `MIN_LINE_FUZZ` to `MAX_LINE_FUZZ`, `DEFAULT_LINE_FUZZ` when left out.
|
|
102
36
|
*/
|
|
103
37
|
lineFuzz?: number;
|
|
104
38
|
}
|
|
105
|
-
/**
|
|
106
|
-
* §5 — Compute the full per-Symbol delta between two paired Symbols. The three axis
|
|
107
|
-
* booleans (`apiChanged` / `logicChanged` / `syntaxChanged`) come from fingerprint
|
|
108
|
-
* comparison; the array deltas (`rules` / `effects` / `calls` / `decorators`) come from
|
|
109
|
-
* identity-preserving diff with configurable line fuzz.
|
|
110
|
-
*/
|
|
111
39
|
declare function computeSymbolDelta(base: Symbol, head: Symbol, options?: DeltaOptions): SymbolDelta;
|
|
112
40
|
//#endregion
|
|
113
|
-
//#region src/match.d.ts
|
|
114
|
-
/**
|
|
115
|
-
* A concluded pairing of one base Symbol with one head Symbol, along with the
|
|
116
|
-
* `MatchRationale` that placed them in the same pair. Stage 4 uses this shape both to
|
|
117
|
-
* carry results out and to feed the delta / status classifier downstream.
|
|
118
|
-
*/
|
|
41
|
+
//#region src/match/pairing.d.ts
|
|
119
42
|
interface SymbolPair {
|
|
120
43
|
base: Symbol;
|
|
121
44
|
head: Symbol;
|
|
122
45
|
rationale: MatchRationale;
|
|
123
46
|
}
|
|
124
|
-
|
|
125
|
-
type GitRenameMap = ReadonlyMap<string, string>;
|
|
126
|
-
/**
|
|
127
|
-
* §3.1 — segments Symbols with identical `id` into paired matches. Runs first because it
|
|
128
|
-
* is the highest-confidence signal (no heuristics, just hash lookup).
|
|
129
|
-
*
|
|
130
|
-
* Assumes `id` is unique on each side (ir-schema.md §14 #1) and does not check it:
|
|
131
|
-
* `buildDiff` establishes that before calling, and a caller reaching this export directly
|
|
132
|
-
* owns the obligation. A repeat on the head side loses all but the last entry to the lookup
|
|
133
|
-
* map and then removes every one of them from `remainingHead`; a repeat on the base side
|
|
134
|
-
* pairs the same head Symbol more than once. The later stages track consumed base Symbols
|
|
135
|
-
* by id and lose a repeat the same way.
|
|
136
|
-
*/
|
|
137
|
-
declare function matchStageId(base: readonly Symbol[], head: readonly Symbol[]): {
|
|
138
|
-
matched: SymbolPair[];
|
|
139
|
-
remainingBase: Symbol[];
|
|
140
|
-
remainingHead: Symbol[];
|
|
141
|
-
};
|
|
142
|
-
/**
|
|
143
|
-
* §3.2 — git rename detection. When a rename map is available (typical of ref-driven
|
|
144
|
-
* scans), rewrite the base id with the head-side file path and look for a hit. Two base
|
|
145
|
-
* files renamed onto one target predict the same head id, so the claimants are collected
|
|
146
|
-
* before one is chosen.
|
|
147
|
-
*
|
|
148
|
-
* The rewriter only touches the `file` portion of the id — the `<language>:` prefix and
|
|
149
|
-
* the trailing `#<qualified-name>` segment stay unchanged so a moved file with the same
|
|
150
|
-
* qualified name is picked up correctly. When a Symbol's file is not in the rename map,
|
|
151
|
-
* it is left for later stages.
|
|
152
|
-
*/
|
|
153
|
-
declare function matchStageGitRename(remainingBase: readonly Symbol[], remainingHead: readonly Symbol[], renameMap: GitRenameMap | null): {
|
|
154
|
-
matched: SymbolPair[];
|
|
155
|
-
remainingBase: Symbol[];
|
|
156
|
-
remainingHead: Symbol[];
|
|
157
|
-
};
|
|
158
|
-
/**
|
|
159
|
-
* §3.3 — group both sides by `fingerprint.logic` and pair within each group. Two branches:
|
|
160
|
-
* - single base candidate → paired with `logic-fingerprint`, no similarity test
|
|
161
|
-
* - several → `nameSimilarity` disambiguates at ≥ 0.85; a group that cannot reach it is left
|
|
162
|
-
* whole for stage 4 to re-evaluate
|
|
163
|
-
*
|
|
164
|
-
* Dropped symbols are excluded (§3.3 tail) — their logic fingerprint is the sentinel
|
|
165
|
-
* `"000000000000"` and would collide with every other dropped Symbol in the workspace.
|
|
166
|
-
* They flow to the stage-4.5 weak matcher instead.
|
|
167
|
-
*/
|
|
168
|
-
declare function matchStageLogicFingerprint(remainingBase: readonly Symbol[], remainingHead: readonly Symbol[]): {
|
|
47
|
+
interface StageResult {
|
|
169
48
|
matched: SymbolPair[];
|
|
170
49
|
remainingBase: Symbol[];
|
|
171
50
|
remainingHead: Symbol[];
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
*
|
|
190
|
-
* §3.4.3 threshold table, applied per head by the token count of its last name segment:
|
|
191
|
-
* - 1 token → 1.0 (an exact match on both remaining axes)
|
|
192
|
-
* - 2 tokens → 0.95 (strict, avoids `getUser` vs `getUsers`)
|
|
193
|
-
* - default → 0.85
|
|
194
|
-
*
|
|
195
|
-
* §3.4.3 also names two Symbols the stage does not read at all, because for them the score is
|
|
196
|
-
* high on evidence it does not have rather than on a resemblance: one whose signature is
|
|
197
|
-
* null, since `signatureSimilarity(null, null)` is 1.0 and the bucket key restricts it to
|
|
198
|
-
* candidates that are equally signature-less; and one whose qualified name carries a single
|
|
199
|
-
* distinct token, since that is the whole of what its identity amounts to. Neither can be
|
|
200
|
-
* expressed as a threshold — the second wants a bar above the top of the scale.
|
|
201
|
-
*
|
|
202
|
-
* Every pairing in a bucket that clears its head’s threshold becomes a candidate, and the
|
|
203
|
-
* candidates are settled in score order rather than one head at a time — see
|
|
204
|
-
* `acceptInScoreOrder`. That doubles the pairings scored, from a bucket that shrank as heads
|
|
205
|
-
* consumed it to the full bucket every time; `createNameScorer` more than pays for it by
|
|
206
|
-
* tokenising each distinct name once per pass instead of once per comparison.
|
|
207
|
-
*/
|
|
208
|
-
declare function matchStageNameSignature(remainingBase: readonly Symbol[], remainingHead: readonly Symbol[]): {
|
|
209
|
-
matched: SymbolPair[];
|
|
210
|
-
remainingBase: Symbol[];
|
|
211
|
-
remainingHead: Symbol[];
|
|
212
|
-
};
|
|
213
|
-
/**
|
|
214
|
-
* §3.4.5 — dropped-only weak matcher. For dropped Symbols the fingerprint is zeroed, so the
|
|
215
|
-
* only signals left are the trailing segment of the qualified name and the file basename.
|
|
216
|
-
* Either one alone is enough to pair, which is deliberately lax: §3.4.5 accepts a
|
|
217
|
-
* false-positive risk because dropped Symbols sit outside the IR's main review surface.
|
|
218
|
-
*
|
|
219
|
-
* What it does not accept is a signal that identifies nothing. A basename hit on `index.ts`
|
|
220
|
-
* — the most common filename in a TypeScript monorepo — paired every dropped Symbol of one
|
|
221
|
-
* kind under one with every other, at a score they all tied on, and the results landed in
|
|
222
|
-
* `summary.moved`, which `--fail-on moved` gates on. So a half counts only when exactly one
|
|
223
|
-
* dropped base and one dropped head carry that key: such a key names a pair, where a key
|
|
224
|
-
* several Symbols carry names a group, and a group is not a pairing.
|
|
225
|
-
*
|
|
226
|
-
* That makes the candidates the identifying keys themselves — at most one pairing each,
|
|
227
|
-
* two axes, so at most `2 × min(base, head)` of them rather than the cross-product a shared
|
|
228
|
-
* basename used to produce.
|
|
229
|
-
*
|
|
230
|
-
* "Exactly one" is counted over the Symbols this stage is handed, not over every dropped
|
|
231
|
-
* Symbol in the Document — stages 1 and 2 have already taken theirs, and a key they emptied
|
|
232
|
-
* out identifies again. That is the intended reading, since the question is which leftover a
|
|
233
|
-
* key picks out, but it is also how a shared `index.ts` comes back: three dropped classes
|
|
234
|
-
* under one, two of them matched by id, and the basename identifies the two that are left.
|
|
235
|
-
*
|
|
236
|
-
* It also leaves nothing for §3.4.5's 0.5-per-half scale to rank, so §3.8's sweep is the
|
|
237
|
-
* wrong instrument: it settles conflicts by score, and with none to settle by it would drop
|
|
238
|
-
* one identified pairing for another over nothing but the id it sorts under. `bestPairing`
|
|
239
|
-
* takes a maximum matching instead.
|
|
240
|
-
*/
|
|
241
|
-
declare function matchStageDroppedWeak(remainingBase: readonly Symbol[], remainingHead: readonly Symbol[]): {
|
|
242
|
-
matched: SymbolPair[];
|
|
243
|
-
remainingBase: Symbol[];
|
|
244
|
-
remainingHead: Symbol[];
|
|
245
|
-
};
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/match/dropped-weak.d.ts
|
|
54
|
+
declare function matchStageDroppedWeak(remainingBase: readonly Symbol[], remainingHead: readonly Symbol[]): StageResult;
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/match/git-rename.d.ts
|
|
57
|
+
type GitRenameMap = ReadonlyMap<string, string>;
|
|
58
|
+
declare function matchStageGitRename(remainingBase: readonly Symbol[], remainingHead: readonly Symbol[], renameMap: GitRenameMap | null): StageResult;
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/match/id.d.ts
|
|
61
|
+
declare function matchStageId(base: readonly Symbol[], head: readonly Symbol[]): StageResult;
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/match/logic-fingerprint.d.ts
|
|
64
|
+
declare function matchStageLogicFingerprint(remainingBase: readonly Symbol[], remainingHead: readonly Symbol[]): StageResult;
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/match/name-signature.d.ts
|
|
67
|
+
declare function matchStageNameSignature(remainingBase: readonly Symbol[], remainingHead: readonly Symbol[], logger?: Logger): StageResult;
|
|
246
68
|
//#endregion
|
|
247
69
|
//#region src/diff.d.ts
|
|
248
|
-
|
|
249
|
-
* The two counters `buildDiff` always writes, narrowed off `Summary`'s optionals.
|
|
250
|
-
*
|
|
251
|
-
* They are optional on the wire so a diff written before they existed stays valid, and that
|
|
252
|
-
* optionality is about *documents*, not about this function — a caller holding a value it just
|
|
253
|
-
* built should not have to re-decide what "absent" would have meant. Same reason
|
|
254
|
-
* `diffDependencies` declares its `unknown` array present.
|
|
255
|
-
*/
|
|
256
|
-
interface UnknownCounters {
|
|
70
|
+
interface AlwaysEmittedCounters {
|
|
257
71
|
unknown: number;
|
|
258
72
|
depsUnknown: number;
|
|
73
|
+
removedDuplicates: number;
|
|
259
74
|
}
|
|
260
75
|
interface DiffInput {
|
|
261
76
|
baseIR: IR;
|
|
262
77
|
headIR: IR;
|
|
263
|
-
/** IR reference metadata (git ref / file path) for provenance. */
|
|
264
78
|
base: IRRef;
|
|
265
79
|
head: IRRef;
|
|
266
|
-
/** Generator record for the diff output. Defaults to `{name: "aburi", version: "0.0.0"}`. */
|
|
267
80
|
generator?: {
|
|
268
81
|
name: string;
|
|
269
82
|
version: string;
|
|
270
83
|
};
|
|
271
|
-
/** Optional stage-2 rename table. When null/undefined stage 2 is skipped. */
|
|
272
84
|
gitRenames?: GitRenameMap | null;
|
|
273
|
-
/** Passed through to computeSymbolDelta (§5.2.1 line fuzz). */
|
|
274
85
|
delta?: DeltaOptions;
|
|
86
|
+
logger?: Logger;
|
|
275
87
|
}
|
|
276
|
-
/**
|
|
277
|
-
* Top-level entry: run the 5-stage matcher, classify each pair, produce array deltas,
|
|
278
|
-
* fold in Component / Dependency diffs, and assemble the `aburi.diff.v1` JSON projection.
|
|
279
|
-
* The function is pure; write-to-disk is delegated to `writeCanonicalDiff` so callers can
|
|
280
|
-
* pipe the result through additional steps (Markdown projection, `--fail-on` gate) before
|
|
281
|
-
* serialisation.
|
|
282
|
-
*/
|
|
283
88
|
declare function buildDiff(input: DiffInput): DiffResult & {
|
|
284
89
|
notCompared: NotComparedFile[];
|
|
285
|
-
summary: Summary &
|
|
90
|
+
summary: Summary & AlwaysEmittedCounters;
|
|
286
91
|
};
|
|
287
|
-
/**
|
|
288
|
-
* The files a document's scan never analysed, by path, with why.
|
|
289
|
-
*
|
|
290
|
-
* `stats.skippedFiles` is Class B: absent means the writer predates the field, not that
|
|
291
|
-
* nothing was lost. An empty map is the honest answer either way — with no enumeration
|
|
292
|
-
* there is no absence this function can explain, and guessing from
|
|
293
|
-
* `totalFiles > parsedFiles` would attach a reason to whichever Symbols happened to be
|
|
294
|
-
* missing. The CLI says so on stderr instead; a diff cannot invent the list.
|
|
295
|
-
*/
|
|
296
|
-
/**
|
|
297
|
-
* Byte-deterministic serialiser for a DiffResult. Delegates to `@aburi/core`
|
|
298
|
-
* `serializeCanonical` so the sort order, NFC normalisation, and codepoint key sort are
|
|
299
|
-
* shared with the IR side.
|
|
300
|
-
*/
|
|
301
92
|
declare function writeCanonicalDiff(diff: DiffResult, options?: SerializeOptions): string;
|
|
302
93
|
//#endregion
|
|
303
94
|
//#region src/errors.d.ts
|
|
304
|
-
type DiffErrorCode =
|
|
305
|
-
/**
|
|
306
|
-
* `baseIR` or `headIR` is not a Document of the shape `aburi.ir.v1` requires. `buildDiff`
|
|
307
|
-
* establishes that before touching any Symbol, by running invariant #20
|
|
308
|
-
* (`checkDocumentShape`): every field the schema requires, at every depth, named by the
|
|
309
|
-
* record it sits in and the field inside it — so a missing `stats` or `workspace`, a
|
|
310
|
-
* `symbols[3]` with no `fingerprint`, and a `stats.effectPropagation` with no `sccCount`
|
|
311
|
-
* all raise this. Anything here would otherwise crash during classification or the delta
|
|
312
|
-
* with a `TypeError` naming neither the record nor the field.
|
|
313
|
-
*
|
|
314
|
-
* A non-empty `$schema` is raised under this code too. That one is `buildDiff`'s own
|
|
315
|
-
* requirement rather than the schema's — two Documents that both say `""` agree with each
|
|
316
|
-
* other, so `schema-mismatch` would never fire on the pair.
|
|
317
|
-
*
|
|
318
|
-
* Not the semantic invariants: those are statements about a Document whose answer the diff
|
|
319
|
-
* does not depend on, and refusing an unsorted `symbols[]` would withhold a diff the
|
|
320
|
-
* matcher can produce.
|
|
321
|
-
*/
|
|
322
|
-
| "ir-shape-invalid"
|
|
323
|
-
/**
|
|
324
|
-
* `baseIR` or `headIR` repeats an identity the diff keys on: a `symbols[].id`, a
|
|
325
|
-
* `components[].id`, or a `dependencies[]` `(from, to, via)` triple. Distinct from
|
|
326
|
-
* `ir-shape-invalid` because the Document is well-formed — the collision changes the
|
|
327
|
-
* answer rather than preventing one, and ir-schema.md §14 #1 / #2 / #13 already forbid it.
|
|
328
|
-
*/
|
|
329
|
-
| "ir-identity-collision"
|
|
330
|
-
/**
|
|
331
|
-
* A `SliceRecord` broke the derivation invariant of slice-view.md §7.1 / §8.2:
|
|
332
|
-
* `members[]` empty, `members[]` not in strictly ascending order, or `id` not
|
|
333
|
-
* equal to `"slice:" + members[0]`. The last two compare one property against
|
|
334
|
-
* another and so have no JSON Schema equivalent; the pass checks them itself
|
|
335
|
-
* (§7.4). Raised only by an Aburi bug, never by user input — see
|
|
336
|
-
* `SliceRecordViolation.kind` for which clause broke.
|
|
337
|
-
*/
|
|
338
|
-
| "slice-invariant-violated";
|
|
95
|
+
type DiffErrorCode = "schema-mismatch" | "invalid-line-fuzz" | "ir-shape-invalid" | "ir-identity-collision" | "slice-invariant-violated";
|
|
339
96
|
interface DiffErrorDetail {
|
|
340
97
|
code: DiffErrorCode;
|
|
341
|
-
/** Offending value (schema id, fuzz value, etc.) when applicable. */
|
|
342
98
|
value?: string;
|
|
343
|
-
/**
|
|
344
|
-
* Populated only for `ir-shape-invalid`, one entry per breach of invariant #20.
|
|
345
|
-
*
|
|
346
|
-
* The message quotes the first and counts the rest, which is enough to start on and not
|
|
347
|
-
* enough to finish: a caller fixing a hand-assembled Document needs the others without
|
|
348
|
-
* running the diff again per field. `CoreErrorDetail.violations` carries the same array
|
|
349
|
-
* for the same reason, and the two are the same `IntegrityViolation` type.
|
|
350
|
-
*/
|
|
351
99
|
violations?: readonly IntegrityViolation[];
|
|
352
100
|
}
|
|
353
101
|
declare class DiffError extends Error {
|
|
@@ -360,192 +108,39 @@ declare class DiffError extends Error {
|
|
|
360
108
|
}
|
|
361
109
|
//#endregion
|
|
362
110
|
//#region src/signature.d.ts
|
|
363
|
-
/**
|
|
364
|
-
* §3.4.2 signatureSimilarity — averaged type-similarity across `inputs`, `outputs`, and
|
|
365
|
-
* `throws`. Follows diff-algorithm.md §3.4.2:
|
|
366
|
-
* - null + null → 1.0 (both symbols are signature-less; nothing to compare)
|
|
367
|
-
* - null + non-null (either side) → 0.0
|
|
368
|
-
* - both non-null: mean of three subscores
|
|
369
|
-
*
|
|
370
|
-
* Subscores:
|
|
371
|
-
* - inputs: ordered type-string equality rate (`i-th type equal` counts as 1, else 0)
|
|
372
|
-
* - outputs: same shape, but outputs is an array of type strings
|
|
373
|
-
* - throws: unordered set intersection over union
|
|
374
|
-
*
|
|
375
|
-
* Empty subarrays on both sides count as 1.0 (they are trivially equal); on one side only
|
|
376
|
-
* they count as 0.0 (asymmetric information).
|
|
377
|
-
*/
|
|
378
111
|
declare function signatureSimilarity(base: Signature | null | undefined, head: Signature | null | undefined): number;
|
|
379
112
|
//#endregion
|
|
380
113
|
//#region src/similarity.d.ts
|
|
381
|
-
/**
|
|
382
|
-
* String similarity utilities dedicated to the diff engine. Kept in one file so the
|
|
383
|
-
* name/signature/owner formulas are auditable side by side against diff-algorithm.md §3.4.
|
|
384
|
-
*/
|
|
385
|
-
/**
|
|
386
|
-
* Tokenise a qualified name into normalised lowercase word segments. Splits on:
|
|
387
|
-
* - camelCase / PascalCase boundaries (`fooBar` → `foo`, `Bar`)
|
|
388
|
-
* - snake_case underscores (`foo_bar` → `foo`, `bar`)
|
|
389
|
-
* - dotted namespaces (`ns.Class` → `ns`, `Class`)
|
|
390
|
-
* - `::` static-method separator (`Class::method` → `Class`, `method`)
|
|
391
|
-
* - runs of digits (`get2Users` → `get`, `2`, `Users`)
|
|
392
|
-
*
|
|
393
|
-
* The result is de-duplicated so `InvoiceService.createInvoice` collapses to
|
|
394
|
-
* `["invoice", "service", "create"]` — Jaccard similarity relies on set semantics, so
|
|
395
|
-
* repeated tokens must not double-count.
|
|
396
|
-
*
|
|
397
|
-
* **The camel boundary is ASCII.** `isCamelBoundary` compares code points against `a`–`z`,
|
|
398
|
-
* `A`–`Z` and `0`–`9`, so a name written in a script with no ASCII case boundary and no
|
|
399
|
-
* separator comes back whole: `获取用户信息` and `ユーザー情報を取得する` are one token each,
|
|
400
|
-
* and so is `получитьПользователя` — its camel hump does not register. A separator still
|
|
401
|
-
* splits (`ユーザー.取得` gives two), and a mixed name splits on its ASCII half.
|
|
402
|
-
*
|
|
403
|
-
* That makes the token count a poor measure of how much such a name says, which matters
|
|
404
|
-
* wherever a count is read as a proxy for that — see §3.4.3's admissibility rule.
|
|
405
|
-
*/
|
|
406
114
|
declare function tokenizeName(input: string): string[];
|
|
407
|
-
|
|
408
|
-
* Jaccard similarity between two token multisets. Formula: |A ∩ B| / |A ∪ B|.
|
|
409
|
-
* Empty on both sides returns 1.0 (both are "no tokens", which are equivalent for the
|
|
410
|
-
* purpose of §3.4.1). Empty on one side only returns 0.0.
|
|
411
|
-
*/
|
|
115
|
+
declare function nameEvidence(qname: string): number;
|
|
412
116
|
declare function jaccard(a: readonly string[], b: readonly string[]): number;
|
|
413
|
-
/**
|
|
414
|
-
* Jaccard over the tokens of two strings. Part of the module's surface rather than an
|
|
415
|
-
* internal shortcut: the two formulas below go through a token table they share for one
|
|
416
|
-
* matching pass, so this has no caller inside this file.
|
|
417
|
-
*/
|
|
418
117
|
declare function jaccardTokens(a: string, b: string): number;
|
|
419
|
-
|
|
420
|
-
* §3.4.1 — Jaccard over the tokens of the full qualified name. The last segment is not
|
|
421
|
-
* given extra weight; the entire path contributes uniformly because the intersection is
|
|
422
|
-
* what the score should reward.
|
|
423
|
-
*/
|
|
118
|
+
declare function lastSegment(qname: string): string;
|
|
424
119
|
declare function nameSimilarity(baseName: string, headName: string): number;
|
|
425
|
-
/**
|
|
426
|
-
* §3.4.1 — Jaccard over the tokens of the **last segment**: the member name with its owner
|
|
427
|
-
* removed. What §3.4's composite reads, because §3.4.6 decides the owner separately and
|
|
428
|
-
* reading it on both axes charges for it twice.
|
|
429
|
-
*/
|
|
430
120
|
declare function memberSimilarity(baseName: string, headName: string): number;
|
|
431
|
-
/**
|
|
432
|
-
* §3.4.6 (R-8) — whether two Symbols are close enough in *scope* to be the same Symbol: the
|
|
433
|
-
* same owner, or one whose owner was renamed. A gate rather than a score, because grading the
|
|
434
|
-
* owner cannot do what R-8 asks. `UserRepo.findById` and `AdminRepo.findById` agree on their
|
|
435
|
-
* member name and their signature, so a shared `Repo` token at weight 0.2 carries them to
|
|
436
|
-
* 0.8667 against a 0.85 threshold — while `UsersRepository.findById`, which *is* the rename,
|
|
437
|
-
* shares no owner token and scores 0.8000. The collision outscores the rename, and raising the
|
|
438
|
-
* weight only moves both: at 0.3 two three-token class names sharing two tokens land on
|
|
439
|
-
* exactly 0.85.
|
|
440
|
-
*
|
|
441
|
-
* Owner extraction:
|
|
442
|
-
* - `Class::method` → `Class`
|
|
443
|
-
* - `A.B.C.method` → `A.B.C`
|
|
444
|
-
* - `topLevel` → `` (empty)
|
|
445
|
-
*
|
|
446
|
-
* Two empty owners are compatible: top-level Symbols share the one outer scope. One empty and
|
|
447
|
-
* one not are never compatible — the two live at different depths.
|
|
448
|
-
*
|
|
449
|
-
* Otherwise the owners must correspond segment for segment, and within a segment every token
|
|
450
|
-
* on each side must find a distinct partner on the other under `sameWord`. Both sides must be
|
|
451
|
-
* covered, so `UserRepo` and `UserRepoV2` are two classes rather than one renamed — an added
|
|
452
|
-
* token is as much evidence of a sibling as of a rename, and R-8's business is refusing the
|
|
453
|
-
* collision.
|
|
454
|
-
*/
|
|
455
121
|
declare function ownersAreCompatible(baseName: string, headName: string): boolean;
|
|
456
|
-
/** §3.4.1 tail note — used by drop-4.5 weak matcher and threshold lookup. */
|
|
457
|
-
declare function lastSegment(qname: string): string;
|
|
458
122
|
//#endregion
|
|
459
123
|
//#region src/slice.d.ts
|
|
460
|
-
/** The three inputs of the Slice View pass — docs/design/slice-view.md §3. */
|
|
461
124
|
interface SliceInput {
|
|
462
|
-
/** SymbolChange records produced by `buildDiff` (pre-sort is not required). */
|
|
463
125
|
changes: readonly SymbolChange[];
|
|
464
|
-
/**
|
|
465
|
-
* Resolved call edges from the base IR. Typically produced by
|
|
466
|
-
* `reconstructCallEdgesFromIR(baseIR)` inside `buildDiff` — Slice View
|
|
467
|
-
* consumes only resolved edges (§5.4), never `Symbol.calls[]` directly.
|
|
468
|
-
*/
|
|
469
126
|
baseCallEdges: readonly CallEdge[];
|
|
470
|
-
/** Resolved call edges from the head IR (same source rule as base). */
|
|
471
127
|
headCallEdges: readonly CallEdge[];
|
|
472
128
|
}
|
|
473
|
-
/**
|
|
474
|
-
* Slice View clustering pass — docs/design/slice-view.md §2, §4–§8.
|
|
475
|
-
*
|
|
476
|
-
* Groups the changed-Symbol set of a diff into weakly-connected components
|
|
477
|
-
* over the union of base and head call edges. Emits a `SliceRecord[]` whose
|
|
478
|
-
* cluster ids are `"slice:" + <smallest-member Symbol id>`, both `slices[]`
|
|
479
|
-
* and each `members[]` sorted ascending.
|
|
480
|
-
*
|
|
481
|
-
* Pure function: `(changes, baseCallEdges, headCallEdges)` → `SliceRecord[]`.
|
|
482
|
-
* Determinism, idempotence, input-order insensitivity, and locality are all
|
|
483
|
-
* guaranteed — see `computeWeaklyConnectedComponents` in `@aburi/core`.
|
|
484
|
-
*
|
|
485
|
-
* Returns `[]` when no SymbolChange is Node-eligible per §4.1; callers should
|
|
486
|
-
* still serialise the empty array — the Markdown projection omits the section
|
|
487
|
-
* (§9.4 / §12.5) but the JSON always emits the key so consumers never
|
|
488
|
-
* distinguish "field absent" from "no slices" (§11.2).
|
|
489
|
-
*
|
|
490
|
-
* Every returned record has passed `assertSliceRecordInvariant` (§7.4).
|
|
491
|
-
*/
|
|
492
129
|
declare function computeSlices(input: SliceInput): SliceRecord[];
|
|
493
|
-
/**
|
|
494
|
-
* §7.1 — the anchor of a Slice: its lexicographically smallest member.
|
|
495
|
-
*
|
|
496
|
-
* Answers from `members[0]`. `id` is derived from the anchor, so
|
|
497
|
-
* reconstructing the anchor by stripping the `"slice:"` prefix is circular at
|
|
498
|
-
* best and, for a record that broke the derivation, silently wrong: it would
|
|
499
|
-
* name a Symbol that is not in the Slice. `id` is read here only to name the
|
|
500
|
-
* offending record in the error message. Consumers that need the anchor call
|
|
501
|
-
* this; consumers that need a label keep using `id` directly.
|
|
502
|
-
*/
|
|
503
130
|
declare function sliceAnchor(record: SliceRecord): SymbolId;
|
|
504
|
-
|
|
505
|
-
type SliceViolationKind = /** Not a `SliceRecord` at all: not an object, or `id` / `members` of the wrong type. */"malformed-shape" /** `members[]` has no entries, so the Slice has no anchor (§11.1). */ | "members-empty" /** `members[]` is not in strictly ascending order, so `members[0]` need not be the smallest (§8.2, §11.1). */ | "members-unordered" /** `id` is not `"slice:" + members[0]` (§7.1). */ | "id-not-derived" /** The anchor is itself in a reserved id namespace, so `id` would read as a doubled prefix (§7.5). */ | "anchor-in-reserved-namespace";
|
|
131
|
+
type SliceViolationKind = "malformed-shape" | "members-empty" | "members-unordered" | "id-not-derived" | "anchor-in-reserved-namespace";
|
|
506
132
|
interface SliceRecordViolation {
|
|
507
133
|
kind: SliceViolationKind;
|
|
508
|
-
/** The offending record's `id` when it has a usable one, else a short stand-in. */
|
|
509
134
|
subject: string;
|
|
510
|
-
/** Human-facing explanation, suitable for an error message or a validator error. */
|
|
511
135
|
message: string;
|
|
512
136
|
}
|
|
513
|
-
/**
|
|
514
|
-
* Report which clause of the §7.1 / §8.2 invariant a value breaks, or `null`
|
|
515
|
-
* when it is a well-formed `SliceRecord`. Non-throwing counterpart of
|
|
516
|
-
* `assertSliceRecordInvariant`: the pass wants an exception, a schema
|
|
517
|
-
* validator wants a verdict it can turn into its own error.
|
|
518
|
-
*
|
|
519
|
-
* Takes `unknown` rather than `SliceRecord` deliberately. §7.4 layer 2 points
|
|
520
|
-
* this at documents written by third-party or older producers — data that has
|
|
521
|
-
* not been type-checked by definition — so anything that assumed a well-typed
|
|
522
|
-
* argument would crash on exactly the input it exists to reject.
|
|
523
|
-
*/
|
|
524
137
|
declare function sliceRecordViolation(value: unknown): SliceRecordViolation | null;
|
|
525
|
-
/**
|
|
526
|
-
* Throwing form of `sliceRecordViolation`. Raised as a coded `DiffError` so
|
|
527
|
-
* callers branch on `code` rather than parsing the message; which clause broke
|
|
528
|
-
* is `SliceRecordViolation.kind`, for callers that need to tell them apart.
|
|
529
|
-
*/
|
|
530
138
|
declare function assertSliceRecordInvariant(record: SliceRecord): void;
|
|
531
139
|
//#endregion
|
|
532
140
|
//#region src/status.d.ts
|
|
533
141
|
type SymbolStatus = "unchanged" | "moved" | "changed" | "moved+changed" | "dropped-toggled";
|
|
534
|
-
/**
|
|
535
|
-
* §4 — determine which of the five statuses a matched pair falls into. `dropped-toggled`
|
|
536
|
-
* has absolute priority: whenever `dropped` differs between base and head, every other
|
|
537
|
-
* signal is ignored because the underlying fingerprint change is a consequence of the
|
|
538
|
-
* drop-rule flip, not a genuine code edit (§4.1 rationale).
|
|
539
|
-
*
|
|
540
|
-
* "pathChanged" catches both physical file relocation AND in-file rename: any Symbol id
|
|
541
|
-
* mismatch between base and head means the identifier moved, and DF9 ("method rename
|
|
542
|
-
* (same file, same logic) → moved") relies on this. Stage-1 pairs cannot trigger the id branch
|
|
543
|
-
* (they match by exact id), so this only affects stage-2+ pairings where the pair was
|
|
544
|
-
* discovered via fingerprint or name/signature similarity.
|
|
545
|
-
*/
|
|
546
142
|
declare function classifyStatus(base: Symbol, head: Symbol): SymbolStatus;
|
|
547
|
-
/** Direction of a `dropped-toggled` transition (§7.1 SymbolDroppedToggled). */
|
|
548
143
|
type DropDirection = "to-dropped" | "to-kept";
|
|
549
144
|
declare function dropDirection(head: Symbol): DropDirection;
|
|
550
145
|
//#endregion
|
|
551
|
-
export { DEFAULT_LINE_FUZZ, type DeltaOptions, type DependencySideView, DiffError, type DiffErrorCode, type DiffErrorDetail, type DiffInput, type DropDirection, type GitRenameMap, MAX_LINE_FUZZ, MIN_LINE_FUZZ, type SliceInput, type SliceRecordViolation, type SliceViolationKind, type SymbolPair, type SymbolStatus, assertSliceRecordInvariant, buildDiff, classifyStatus, computeSlices, computeSymbolDelta, dependencySideView, diffComponents, diffDependencies, dropDirection, jaccard, jaccardTokens, lastSegment, matchStageDroppedWeak, matchStageGitRename, matchStageId, matchStageLogicFingerprint, matchStageNameSignature, memberSimilarity, nameSimilarity, ownersAreCompatible, signatureSimilarity, sliceAnchor, sliceRecordViolation, tokenizeName, writeCanonicalDiff };
|
|
146
|
+
export { DEFAULT_LINE_FUZZ, type DeltaOptions, type DependencySideView, DiffError, type DiffErrorCode, type DiffErrorDetail, type DiffInput, type DropDirection, type GitRenameMap, MAX_LINE_FUZZ, MIN_LINE_FUZZ, type RenameDirections, type SliceInput, type SliceRecordViolation, type SliceViolationKind, type SymbolPair, type SymbolStatus, assertSliceRecordInvariant, buildDiff, classifyStatus, computeSlices, computeSymbolDelta, dependencySideView, diffComponents, diffDependencies, dropDirection, jaccard, jaccardTokens, lastSegment, matchStageDroppedWeak, matchStageGitRename, matchStageId, matchStageLogicFingerprint, matchStageNameSignature, memberSimilarity, nameEvidence, nameSimilarity, ownersAreCompatible, renameDirections, signatureSimilarity, sliceAnchor, sliceRecordViolation, tokenizeName, writeCanonicalDiff };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{DOCUMENT_SUBJECT as e,RESERVED_LANGUAGE_IDS as t,checkDocumentShape as n,computeWeaklyConnectedComponents as r,reconstructCallEdgesFromIR as i,serializeCanonical as a,trySymbolId as o}from"@aburi/core";var s=class extends Error{code;value;violations;constructor(e,t,n){super(e,n),this.name=`DiffError`,this.code=t.code,this.value=t.value,this.violations=t.violations}};function c(e,t){let n=new Map;for(let t of e)n.set(t.id,t);let r=new Map;for(let e of t)r.set(e.id,e);let i=[],a=[],o=[];for(let[e,t]of r){let r=n.get(e);if(r===void 0){i.push(t);continue}g(r,t)||o.push({before:r,after:t,delta:{rootsChanged:!b(r.roots,t.roots),publicApiChanged:!b(r.publicApi??[],t.publicApi??[]),frameworksChanged:!b(r.frameworks??[],t.frameworks??[])}})}for(let[e,t]of n)r.has(e)||a.push(t);return x(i),x(a),o.sort((e,t)=>e.after.id<t.after.id?-1:+(e.after.id>t.after.id)),{added:i,removed:a,changed:o}}function l(e){let t=new Map;for(let n of e.symbols)t.set(n.id,n.source.file);let n=new Map;for(let t of e.stats.skippedFiles??[])n.set(t.path,t.reason);return{symbolFiles:t,lostFiles:n}}function u(e,t,n){let r=new Map;for(let t of e)r.set(m(t),t);let i=new Map;for(let e of t)i.set(m(e),e);let a=[],o=[],s=[];for(let[e,t]of i){let i=r.get(e);if(i===void 0){let e=d(t,n.head,n.base);e.length>0?s.push({dependency:t,absentFrom:`base`,lostFiles:e}):a.push(t);continue}(i.direction!==t.direction||(i.effect??null)!==(t.effect??null))&&(o.push(i),a.push(t))}for(let[e,t]of r){if(i.has(e))continue;let r=d(t,n.base,n.head);r.length>0?s.push({dependency:t,absentFrom:`head`,lostFiles:r}):o.push(t)}return a.sort(h),o.sort(h),s.sort((e,t)=>h(e.dependency,t.dependency)),{added:a,removed:o,unknown:s}}function d(e,t,n){let r=new Map;for(let i of[e.from,e.to]){let e=t.symbolFiles.get(i);if(e===void 0)continue;let a=n.lostFiles.get(e);a!==void 0&&r.set(e,a)}return[...r.entries()].map(([e,t])=>({path:e,reason:t})).sort((e,t)=>e.path<t.path?-1:+(e.path>t.path))}const f=[`from`,`to`,`via`];function p(e){return e.join(`::`)}function m(e){return p(f.map(t=>e[t]))}function h(e,t){let n=m(e),r=m(t);return n<r?-1:+(n>r)}function g(e,t){return _(e,`base`)===_(t,`head`)}function _(e,t){try{return a(v(e),{format:`compact`})}catch(n){throw new s(`${t} components[id=${e.id}] cannot be compared: ${n instanceof Error?n.message:String(n)}`,{code:`ir-shape-invalid`,value:`components[id=${e.id}]`},{cause:n})}}function v(e){let t={...e};(t.description===null||t.description===void 0)&&delete t.description;for(let e of y){let n=t[e];(n===void 0||Array.isArray(n)&&n.length===0)&&delete t[e]}return t}const y=[`publicApi`,`frameworks`];function b(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function x(e){e.sort((e,t)=>e.id<t.id?-1:+(e.id>t.id))}const S=2,ee=10,te=0;function C(e,t,n={}){let r=ne(n.lineFuzz??2),i={apiChanged:e.fingerprint.api!==t.fingerprint.api,logicChanged:e.fingerprint.logic!==t.fingerprint.logic,syntaxChanged:e.fingerprint.syntax!==t.fingerprint.syntax,componentChanged:(e.component??null)!==(t.component??null),visibilityChanged:e.visibility!==t.visibility};return i.rules=ae(e.rules,t.rules,r),i.effects=se(e.effects,t.effects),i.calls=le(e.calls,t.calls,r),i.decorators=de(e.decorators,t.decorators,r),i.signature=pe(e.signature??null,t.signature??null),i}function ne(e){if(!Number.isFinite(e)||!Number.isInteger(e))throw new s(`config.diff.lineFuzz must be an integer in [0, 10]; got ${String(e)}.`,{code:`invalid-line-fuzz`,value:String(e)});if(e<0||e>10)throw new s(`config.diff.lineFuzz must be within [0, 10]; got ${e}.`,{code:`invalid-line-fuzz`,value:String(e)});return e}function w(e,t,n,r){let i=new Set(e.map((e,t)=>t)),a=new Set(t.map((e,t)=>t)),o=new Map;for(let s of[!0,!1]){let c=(e,t)=>e.key===t.key&&Math.abs(e.line-t.line)<=r&&(!s||n(e.item,t.item));for(let[n,r]of ie(e,t,i,a,c)){i.delete(n),a.delete(r);let t=e[n];t!==void 0&&o.set(r,t)}}let s=[],c=[];for(let[e,r]of t.entries()){let t=o.get(e);t===void 0?s.push(r.item):n(t.item,r.item)||c.push(r.item)}return{added:s,removed:e.filter((e,t)=>i.has(t)).map(e=>e.item),modified:c}}const T={pairs:0,distance:0};function re(e,t){return e.pairs===t.pairs?e.distance<t.distance:e.pairs>t.pairs}function ie(e,t,n,r,i){let a=Array.from({length:e.length+1},()=>Array.from({length:t.length+1},()=>T)),o=(o,s)=>{let c=e[o],l=t[s];if(c===void 0||l===void 0||!n.has(o)||!r.has(s)||!i(c,l))return null;let u=a[o+1]?.[s+1]??T;return{pairs:u.pairs+1,distance:u.distance+Math.abs(c.line-l.line)}};for(let n=e.length-1;n>=0;n--)for(let e=t.length-1;e>=0;e--){let t=a[n+1]?.[e]??T,r=a[n]?.[e+1]??T,i=re(t,r)?t:r,s=o(n,e);s!==null&&re(s,i)&&(i=s);let c=a[n];c!==void 0&&(c[e]=i)}let s=[],c=0,l=0;for(;c<e.length&&l<t.length;){let e=a[c]?.[l]??T,t=o(c,l);if(t!==null&&t.pairs===e.pairs&&t.distance===e.distance){s.push([c,l]),c++,l++;continue}let n=a[c+1]?.[l]??T;n.pairs===e.pairs&&n.distance===e.distance?c++:l++}return s}function ae(e,t,n){let r=e=>({item:e,key:e.type,line:e.line});return w(e.map(r),t.map(r),oe,n)}function oe(e,t){return e.type===t.type&&(e.condition??null)===(t.condition??null)&&(e.what??null)===(t.what??null)&&(e.expr??null)===(t.expr??null)&&(e.loopKind??null)===(t.loopKind??null)}function se(e,t){let n=e=>({item:e,key:`${e.id}::${e.target}`,line:e.line??0});return w(e.map(n),t.map(n),ce,1/0)}function ce(e,t){return e.id===t.id&&e.target===t.target&&e.plugin===t.plugin&&e.confidence===t.confidence}function le(e,t,n){let r=e=>({item:e,key:e.target,line:e.line});return w(e.map(r),t.map(r),ue,n)}function ue(e,t){return e.target===t.target&&(e.resolved??null)===(t.resolved??null)}function de(e,t,n){let r=e=>({item:e,key:e.name,line:e.line});return w(e.map(r),t.map(r),fe,n)}function fe(e,t){if(e.name!==t.name||e.arguments.length!==t.arguments.length)return!1;for(let n=0;n<e.arguments.length;n++)if(e.arguments[n]!==t.arguments[n])return!1;return!0}function pe(e,t){if(e===null&&t===null)return null;if(e===null||t===null){let n={added:[],removed:[],modified:[]},r=e??t;if(r===null)return null;let i=e===null;return{inputs:i?{added:[...r.inputs],removed:[],modified:[]}:{added:[],removed:[...r.inputs],modified:[]},outputs:i?{added:[...r.outputs],removed:[],modified:[]}:{added:[],removed:[...r.outputs],modified:[]},throws:i?{added:[...r.throws],removed:[],modified:[]}:{added:[],removed:[...r.throws],modified:[]},asyncChanged:(e?.async??!1)!==(t?.async??!1),generatorChanged:(e?.generator??!1)!==(t?.generator??!1),typeParametersChanged:!ge(e?.typeParameters??n.added.map(String),t?.typeParameters??n.added.map(String))}}let n=(e,t)=>({item:e,key:`${t}:${e.name}`,line:t});return{inputs:w(e.inputs.map(n),t.inputs.map(n),(e,t)=>e.name===t.name&&e.type===t.type,0),outputs:me(e.outputs,t.outputs),throws:he(e.throws,t.throws),asyncChanged:e.async!==t.async,generatorChanged:e.generator!==t.generator,typeParametersChanged:!ge(e.typeParameters,t.typeParameters)}}function me(e,t){let n=[],r=[],i=Math.max(e.length,t.length);for(let a=0;a<i;a++){let i=a<e.length?e[a]:void 0,o=a<t.length?t[a]:void 0;i===void 0&&o!==void 0?n.push(o):o===void 0&&i!==void 0?r.push(i):i!==o&&(i!==void 0&&r.push(i),o!==void 0&&n.push(o))}return{added:n,removed:r,modified:[]}}function he(e,t){let n=new Set(e),r=new Set(t),i=[],a=[];for(let e of r)n.has(e)||i.push(e);for(let e of n)r.has(e)||a.push(e);return{added:i,removed:a,modified:[]}}function ge(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function E(e,t){let n=e??null,r=t??null;if(n===null&&r===null)return 1;if(n===null||r===null)return 0;let i=D(n.inputs.map(e=>e.type),r.inputs.map(e=>e.type)),a=D(n.outputs,r.outputs),o=_e(n.throws,r.throws);return(i+a+o)/3}function D(e,t){if(e.length===0&&t.length===0)return 1;if(e.length!==t.length)return 0;let n=0;for(let r=0;r<e.length;r++)e[r]===t[r]&&n++;return n/e.length}function _e(e,t){if(e.length===0&&t.length===0)return 1;let n=new Set(e),r=new Set(t),i=0;for(let e of n)r.has(e)&&i++;let a=n.size+r.size-i;return a===0?1:i/a}function O(e){let t=new Set,n=[];for(let r of e.split(/[.:_\-\s/]+/))if(r.length!==0)for(let e of ve(r)){let r=e.toLowerCase();r.length===0||t.has(r)||(t.add(r),n.push(r))}return n}function ve(e){let t=[],n=``;for(let r of e){if(n===``){n=r;continue}ye(n.slice(-1),r)?(t.push(n),n=r):n+=r}return n.length>0&&t.push(n),t}function ye(e,t){let n=e>=`a`&&e<=`z`,r=e>=`A`&&e<=`Z`,i=e>=`0`&&e<=`9`,a=t>=`a`&&t<=`z`,o=t>=`A`&&t<=`Z`;return!!(n&&o||(n||r)&&t>=`0`&&t<=`9`||i&&(a||o))}function be(e,t){return k(new Set(e),new Set(t))}function k(e,t){if(e.size===0&&t.size===0)return 1;if(e.size===0||t.size===0)return 0;let[n,r]=e.size<=t.size?[e,t]:[t,e],i=0;for(let e of n)r.has(e)&&i++;return i/(e.size+t.size-i)}function xe(e,t){return be(O(e),O(t))}const A=e=>new Set(O(e));function Se(e,t){return j(A,e,t)}function Ce(e,t){return M(A,e,t)}function we(e,t){return De(A,e,t)}function Te(e,t){if(e===t)return!0;let[n,r]=e.length<=t.length?[e,t]:[t,e];return Ee(n,r)}function Ee(e,t){return t===`${e}s`||t===`${e}es`?!0:e.endsWith(`y`)&&t===`${e.slice(0,-1)}ies`}function j(e,t,n){return k(e(t),e(n))}function M(e,t,n){return k(e(R(t)),e(R(n)))}function De(e,t,n){let r=L(t),i=L(n);return r===``&&i===``?!0:r===``||i===``?!1:r===i?!0:N(r,i,e)}function N(e,t,n){let r=e.split(`.`),i=t.split(`.`);return r.length===i.length?r.every((e,t)=>{let r=i[t];return r===void 0?!1:e===r?!0:Oe(n(e),n(r))}):!1}function Oe(e,t){if(e.size!==t.size||e.size>32)return!1;let n=[...t],r=new Map;for(let t of e)if(!P(t,n,r,new Set))return!1;return!0}function P(e,t,n,r){for(let i of t){if(r.has(i)||!Te(e,i))continue;r.add(i);let a=n.get(i);if(a===void 0||P(a,t,n,r))return n.set(i,e),!0}return!1}function ke(e,t,n){let r=e.slice(0,F(e)),i=t.slice(0,F(t));if(r===i)return!0;let a=n(r),o=n(i);if(a.size!==o.size||a.size>32)return!1;for(let e of a){let t=!1;for(let n of o)if(Te(e,n)){t=!0;break}if(!t)return!1}return!0}function F(e){let t=e.indexOf(`.`);return t<0?e.length:t}function I(){let e=new Map,t=t=>{let n=e.get(t);if(n!==void 0)return n;let r=new Set(O(t));return e.set(t,r),r},n=new Map,r=e=>{let t=n.get(e);if(t!==void 0)return t;let r=L(e);return n.set(e,r),r};return{name:(e,n)=>j(t,e,n),member:(e,n)=>M(t,e,n),ownersCompatible:(e,n)=>{let i=r(e),a=r(n);return i===a?!0:i===``||a===``||!ke(i,a,t)?!1:N(i,a,t)}}}function L(e){let t=e.indexOf(`::`);if(t>=0)return e.slice(0,t);let n=e.lastIndexOf(`.`);return n>=0?e.slice(0,n):``}function R(e){let t=e.indexOf(`::`);if(t>=0)return e.slice(t+2);let n=e.lastIndexOf(`.`);return n>=0?e.slice(n+1):e}function z(e){e.sort(Ae);let t=new Set,n=new Set,r=[];for(let i of e)t.has(i.base.id)||n.has(i.head.id)||(t.add(i.base.id),n.add(i.head.id),r.push(i));return{pairs:r,baseIds:t,headIds:n}}function Ae(e,t){return e.score===t.score?e.base.id===t.base.id?e.head.id<t.head.id?-1:+(e.head.id>t.head.id):e.base.id<t.base.id?-1:1:t.score-e.score}function B(e,t){return e.filter(e=>!t.has(e.id))}function V(e,t){let n=new Map;for(let e of t)n.set(e.id,e);let r=[],i=[],a=new Set;for(let t of e){let e=n.get(t.id);e===void 0?i.push(t):(r.push({base:t,head:e,rationale:`id-match`}),a.add(t.id))}return{matched:r,remainingBase:i,remainingHead:t.filter(e=>!a.has(e.id))}}function H(e,t,n){if(n===null||n.size===0)return{matched:[],remainingBase:[...e],remainingHead:[...t]};let r=new Map;for(let e of t)r.set(e.id,e);let i=new Map;for(let t of e){let e=n.get(t.source.file);if(e===void 0)continue;let a=Me(t.id,t.source.file,e);if(a===null)continue;let o=r.get(a);if(o===void 0)continue;let s=i.get(a);s===void 0?i.set(a,{head:o,bases:[t]}):s.bases.push(t)}let a=[],o=new Set,s=new Set;for(let{head:e,bases:t}of i.values()){let n=je(t);a.push({base:n,head:e,rationale:`git-rename`}),o.add(n.id),s.add(e.id)}return{matched:a,remainingBase:B(e,o),remainingHead:B(t,s)}}function je(e){let t=e[0];for(let n of e)n.id<t.id&&(t=n);return t}function Me(e,t,n){let r=e.indexOf(`:`),i=e.indexOf(`#`);return r<0||i<0||i<r||e.slice(r+1,i)!==t?e:o({language:e.slice(0,r),file:n,qualifiedName:e.slice(i+1)})}function U(e,t){let n=W(e),r=W(t),i=I(),a=[];for(let[e,t]of r){let r=n.get(e);r!==void 0&&a.push(...Ne(r,t,i))}let o=new Set(a.map(e=>e.base.id)),s=new Set(a.map(e=>e.head.id));return{matched:a,remainingBase:B(e,o),remainingHead:B(t,s)}}function W(e){let t=new Map;for(let n of e){if(n.dropped||n.fingerprint.logic===`000000000000`)continue;let e=t.get(n.fingerprint.logic)??[];e.push(n),t.set(n.fingerprint.logic,e)}return t}function Ne(e,t,n){let r=[...e],i=[...t],a=[];for(;r.length>0&&i.length>0;){let e=r.length===1?r[0]:void 0;if(e!==void 0){let t=Pe(e,i,n);if(t===void 0)break;a.push({base:e,head:t,rationale:`logic-fingerprint`});break}let t=[];for(let e of r)for(let r of i){let i=n.name(e.name,r.name);i>=.85&&t.push({base:e,head:r,score:i})}let o=z(t);if(o.pairs.length===0)break;for(let{base:e,head:t}of o.pairs)a.push({base:e,head:t,rationale:`logic-fingerprint+name-disambiguation`});r=B(r,o.baseIds),i=B(i,o.headIds)}return a}function Pe(e,t,n){let r;for(let i of t){let t=n.name(e.name,i.name);if(r===void 0||t>r.score){r={head:i,score:t};continue}t===r.score&&i.id<r.head.id&&(r={head:i,score:t})}return r?.head}function G(e,t){let n=new Map;for(let t of e){if(t.dropped||!J(t.name))continue;let e=Fe(t),r=n.get(e)??{members:[],byToken:new Map},i=r.members.length;r.members.push(t);for(let e of q(t.name)){let t=r.byToken.get(e)??[];t.push(i),r.byToken.set(e,t)}n.set(e,r)}let r=new Map;for(let e of n.values())r.set(e,new Int32Array(e.members.length));let i=I(),a=[],o=0;for(let e of t){if(e.dropped||e.signature===null||e.signature===void 0||!J(e.name))continue;let t=n.get(Fe(e));if(t===void 0)continue;let s=Re(e.name),c=Ie(s),l=q(e.name),u=0;for(let e of l)u+=t.byToken.get(e)?.length??0;if(u>=t.members.length){for(let n of t.members)K(n,e,i,c,s,a);continue}let d=r.get(t);if(d!==void 0){o++;for(let n of l)for(let r of t.byToken.get(n)??[]){if(d[r]===o)continue;d[r]=o;let n=t.members[r];n!==void 0&&K(n,e,i,c,s,a)}}}let s=z(a);return{matched:s.pairs.map(({base:e,head:t})=>({base:e,head:t,rationale:`name-signature`})),remainingBase:B(e,s.baseIds),remainingHead:B(t,s.headIds)}}function K(e,t,n,r,i,a){let o=n.member(e.name,t.name);if(o<r||!n.ownersCompatible(e.name,t.name))return;let s=.5*o+.3*E(e.signature??null,t.signature??null)+.2*Le;s>=i&&a.push({base:e,head:t,score:s})}function Fe(e){let t=e.signature===null||e.signature===void 0?`no-sig`:`has-sig`;return`${e.kind}::${t}`}function Ie(e){return 2*(e-.5)}function q(e){let t=O(R(e));return t.length===0?[` none`]:t}const Le=1;function Re(e){let t=O(R(e)).length;return t<=1?1:t===2?.95:.85}function J(e){return O(e).length>1}function Y(e,t){let n=e.filter(e=>e.dropped),r=t.filter(e=>e.dropped),i=[];for(let e of[Ue,We])i.push(...Ve(n,r,e));let a=ze(i);return{matched:a.map(({base:e,head:t})=>({base:e,head:t,rationale:`dropped-weak-match`})),remainingBase:B(e,new Set(a.map(e=>e.base.id))),remainingHead:B(t,new Set(a.map(e=>e.head.id)))}}function ze(e){let t=[...e].sort(Be),n=new Map,r=new Map;for(let[e,i]of t.entries())X(n,i.base.id,e),X(r,i.head.id,e);let i=e=>{let i=t[e];return i===void 0?[]:[...n.get(i.base.id)??[],...r.get(i.head.id)??[]].filter(t=>t!==e)},a=t.map(()=>!1),o=[],s=e=>{let n=e,r=!0;for(;!a[n];){a[n]=!0;let e=t[n];r&&e!==void 0&&o.push(e),r=!r;let s=i(n).find(e=>a[e]===!1);if(s===void 0)return;n=s}};for(let[e]of t.entries())!a[e]&&i(e).length<=1&&s(e);for(let[e]of t.entries())a[e]||s(e);return o}function Be(e,t){return e.base.id===t.base.id?e.head.id<t.head.id?-1:+(e.head.id>t.head.id):e.base.id<t.base.id?-1:1}function X(e,t,n){let r=e.get(t);r===void 0?e.set(t,[n]):r.push(n)}function Ve(e,t,n){let r=He(e,n),i=He(t,n),a=[];for(let[e,t]of r){let n=i.get(e);n!==void 0&&a.push({base:t,head:n})}return a}function He(e,t){let n=new Map,r=new Set;for(let i of e){let e=t(i);if(!r.has(e)){if(n.has(e)){n.delete(e),r.add(e);continue}n.set(e,i)}}return n}function Ue(e){return`${e.kind}/${R(e.name)}`}function We(e){return`${e.kind}/${Ge(e.source.file)}`}function Ge(e){let t=e.lastIndexOf(`/`);return t>=0?e.slice(t+1):e}function Ke(e){let t=$e(e.changes);if(t.length===0)return[];let n=new Set(t);return r(t,tt(e.baseCallEdges,e.headCallEdges,n),e=>e).map(Je)}function qe(e){return`slice:${e}`}function Je(e){let t=e[0];if(t===void 0)throw new s(`computeSlices: the clustering utility returned an empty component; every weakly-connected component contains at least the node that seeded it (slice-view.md §6).`,{code:`slice-invariant-violated`});let n={id:qe(t),members:[...e]};return Z(n),n}function Ye(e){let t=e.members[0];if(t===void 0){let t=Qe(e.id);throw new s(t.message,{code:`slice-invariant-violated`,value:t.subject})}return t}function Xe(e){if(typeof e!=`object`||!e)return{kind:`malformed-shape`,subject:`<not an object>`,message:`Expected a SliceRecord object; got ${e===null?`null`:typeof e}.`};let{id:t,members:n}=e,r=typeof t==`string`?t:`<missing id>`;if(typeof t!=`string`)return{kind:`malformed-shape`,subject:r,message:`SliceRecord ${r}: id must be a string; got ${typeof t}.`};if(!Array.isArray(n)||n.some(e=>typeof e!=`string`))return{kind:`malformed-shape`,subject:r,message:`SliceRecord ${r}: members must be an array of strings.`};let i=n[0];if(i===void 0)return Qe(r);let a=Ze(i);if(a!==null)return{kind:`anchor-in-reserved-namespace`,subject:r,message:`SliceRecord anchor "${i}" uses the reserved language token "${a}", so its Slice id would repeat the prefix (ir-schema.md §3.5, slice-view.md §7.5).`};for(let e=1;e<n.length;e++){let t=n[e-1],i=n[e];if(!(t<i))return{kind:`members-unordered`,subject:r,message:`SliceRecord ${r}: members[] is not in strictly ascending order at index ${e} ("${i}" follows "${t}"), so members[0] is not necessarily the anchor (slice-view.md §8.2 for the order, §11.1 for uniqueness).`}}let o=qe(i);return t===o?null:{kind:`id-not-derived`,subject:r,message:`SliceRecord id "${t}" is not derived from the anchor "${i}"; expected "${o}" (slice-view.md §7.1).`}}function Ze(e){let n=e.indexOf(`:`);if(n<0)return null;let r=e.slice(0,n);return t.has(r)?r:null}function Qe(e){return{kind:`members-empty`,subject:e,message:`SliceRecord ${e}: members[] is empty, so the Slice has no anchor (slice-view.md §11.1 requires at least one member).`}}function Z(e){let t=Xe(e);if(t!==null)throw new s(t.message,{code:`slice-invariant-violated`,value:t.subject})}function $e(e){let t=[];for(let n of e){let e=et(n);e!==null&&t.push(e)}return t}function et(e){switch(e.status){case`added`:return e.symbol.id;case`removed`:return e.symbol.id;case`unknown`:return e.symbol.id;case`changed`:case`moved+changed`:case`dropped-toggled`:return e.after.id;case`moved`:return null}}function tt(e,t,n){let r=[];for(let t of e)nt(t,n,r);for(let e of t)nt(e,n,r);return r}function nt(e,t,n){!t.has(e.from)||!t.has(e.to)||n.push([e.from,e.to])}function rt(e,t){if(e.dropped!==t.dropped)return`dropped-toggled`;let n=e.source.file!==t.source.file||e.id!==t.id,r=e.fingerprint.api!==t.fingerprint.api||e.fingerprint.logic!==t.fingerprint.logic||e.fingerprint.syntax!==t.fingerprint.syntax;return n&&r?`moved+changed`:n?`moved`:r?`changed`:`unchanged`}function it(e){return e.dropped?`to-dropped`:`to-kept`}const at={name:`aburi`,version:`0.0.0`};function ot(e){ut(e.baseIR,`baseIR`),ut(e.headIR,`headIR`),ct(e.baseIR,e.headIR);let t=V(e.baseIR.symbols,e.headIR.symbols),n=H(t.remainingBase,t.remainingHead,e.gitRenames??null),r=U(n.remainingBase,n.remainingHead),a=G(r.remainingBase,r.remainingHead),o=Y(a.remainingBase,a.remainingHead),s=[...t.matched,...n.matched,...r.matched,...a.matched,...o.matched],d={unknown:0,depsUnknown:0,added:0,removed:0,moved:0,movedChanged:0,changed:0,droppedToggled:0,unchanged:0,droppedAdded:0,droppedRemoved:0,componentsAdded:0,componentsRemoved:0,componentsChanged:0,depsAdded:0,depsRemoved:0},f=0,p=[];for(let t of s){let n=rt(t.base,t.head);if(n===`unchanged`){d.unchanged++;continue}if(n===`dropped-toggled`){d.droppedToggled++,p.push({status:`dropped-toggled`,before:t.base,after:t.head,direction:it(t.head)});continue}if(n===`moved`){d.moved++,p.push({status:`moved`,before:t.base,after:t.head,rationale:t.rationale});continue}if(n===`changed`){d.changed++,p.push({status:`changed`,before:t.base,after:t.head,delta:C(t.base,t.head,e.delta??{})});continue}d.movedChanged++,p.push({status:`moved+changed`,before:t.base,after:t.head,rationale:t.rationale,delta:C(t.base,t.head,e.delta??{})})}let m=o.remainingHead,h=o.remainingBase,g=l(e.baseIR),_=l(e.headIR),v=_.lostFiles,y=g.lostFiles;for(let e of m){if(e.dropped){d.droppedAdded++;continue}let t=y.get(e.source.file);if(t!==void 0){f++,p.push({status:`unknown`,symbol:e,absentFrom:`base`,reason:t});continue}d.added++,p.push({status:`added`,symbol:e})}for(let e of h){if(e.dropped){d.droppedRemoved++;continue}let t=v.get(e.source.file);if(t!==void 0){f++,p.push({status:`unknown`,symbol:e,absentFrom:`head`,reason:t});continue}d.removed++,p.push({status:`removed`,symbol:e})}let b=c(e.baseIR.components,e.headIR.components);d.componentsAdded=b.added.length,d.componentsRemoved=b.removed.length,d.componentsChanged=b.changed.length;let x=u(e.baseIR.dependencies,e.headIR.dependencies,{base:g,head:_});d.depsAdded=x.added.length,d.depsRemoved=x.removed.length,d.depsUnknown=x.unknown.length,d.unknown=f,p.sort(ht);let S=Ke({changes:p,baseCallEdges:i(e.baseIR),headCallEdges:i(e.headIR)});return{$schema:`https://aburi.kage1020.com/schema/aburi.diff.v1.json`,generator:e.generator??at,base:e.base,head:e.head,summary:d,symbols:p,components:b,dependencies:x,slices:S,notCompared:st(y,v)}}function st(e,t){let n=[];for(let[r,i]of e){let e=t.get(r);e!==void 0&&n.push({path:r,baseReason:i,headReason:e})}return n.sort((e,t)=>e.path<t.path?-1:+(e.path>t.path))}function ct(e,t){if(e.$schema!==t.$schema)throw new s(`Base IR schema "${e.$schema}" does not match head IR schema "${t.$schema}"; a diff across schema versions is not supported.`,{code:`schema-mismatch`,value:e.$schema})}const Q=e=>e.join(``),lt=[{field:`symbols`,identityFields:[`id`],keyOf:Q,noun:`id`,show:Q,consequence:`stage 1 pairs Symbols by id and every later stage tracks the base Symbols it has consumed by id, so a repeat leaves one entry out of the diff entirely or classifies its counterpart twice (ir-schema.md §14 #1)`},{field:`components`,identityFields:[`id`],keyOf:Q,noun:`id`,show:Q,consequence:`Component identity is the id, so a repeat hides one entry and can report a change the two revisions do not contain (ir-schema.md §14 #2)`},{field:`dependencies`,identityFields:f,keyOf:p,noun:`(from, to, via) triple`,show:e=>`(${e.join(`, `)})`,consequence:`direction and effect are deliberately outside Dependency identity (§6.2), so a repeat surfaces as an added + removed pair no reader can tell from a real flip (ir-schema.md §14 #13)`}];function ut(e,t){let r=n(e),i=r[0];if(i!==void 0){let e=dt(t,i.subject),n=r.length-1,a=n>0?` (and ${n} more)`:``;throw new s(`${e}: ${i.message}${a}.`,{code:`ir-shape-invalid`,value:e,violations:r.map(e=>({...e,subject:dt(t,e.subject)}))})}if(e.$schema.length===0)throw $(t,`${t}: "$schema" is empty, not a schema URL.`);for(let n of lt)ft(e[n.field],`${t}.${n.field}`,n)}function dt(t,n){return n===e?t:`${t}.${n}`}function ft(e,t,n){if(!Array.isArray(e))throw $(t,`${t} must be an array.`);let r=new Map;for(let[i,a]of e.entries()){let e=`${t}[${i}]`,o=pt(a,e,n),c=n.keyOf(o),l=r.get(c);if(l===void 0){r.set(c,i);continue}let u=n.show(o);throw new s(`${e} repeats the ${n.noun} "${u}" first seen at index ${l}; ${n.consequence}.`,{code:`ir-identity-collision`,value:u})}}function pt(e,t,n){if(typeof e!=`object`||!e||Array.isArray(e))throw $(t,`${t} must be an object; got ${mt(e)}.`);let r=[];for(let i of n.identityFields){let n=e[i];if(typeof n!=`string`)throw $(`${t}.${i}`,`${t}.${i} must be a string; got ${mt(n)}.`);r.push(n)}return r}function $(e,t){return new s(t,{code:`ir-shape-invalid`,value:e})}function mt(e){return e===void 0?`undefined`:e===null?`null`:Array.isArray(e)?`an array`:`a ${typeof e}`}function ht(e,t){if(e.status!==t.status)return e.status<t.status?-1:1;let n=gt(e),r=gt(t);return n<r?-1:+(n>r)}function gt(e){return e.status===`added`||e.status===`removed`||e.status===`unknown`?e.symbol.id:e.after.id}function _t(e,t={}){return a(e,t)}export{S as DEFAULT_LINE_FUZZ,s as DiffError,ee as MAX_LINE_FUZZ,te as MIN_LINE_FUZZ,Z as assertSliceRecordInvariant,ot as buildDiff,rt as classifyStatus,Ke as computeSlices,C as computeSymbolDelta,l as dependencySideView,c as diffComponents,u as diffDependencies,it as dropDirection,be as jaccard,xe as jaccardTokens,R as lastSegment,Y as matchStageDroppedWeak,H as matchStageGitRename,V as matchStageId,U as matchStageLogicFingerprint,G as matchStageNameSignature,Ce as memberSimilarity,Se as nameSimilarity,we as ownersAreCompatible,E as signatureSimilarity,Ye as sliceAnchor,Xe as sliceRecordViolation,O as tokenizeName,_t as writeCanonicalDiff};
|
|
1
|
+
import{DOCUMENT_SUBJECT as e,RESERVED_LANGUAGE_IDS as t,ZERO_FINGERPRINT as n,buildComponentAttribution as r,checkDocumentShape as i,compareBy as a,compareCodeUnit as o,computeWeaklyConnectedComponents as s,exportNames as c,logicNamesNothing as l,reconstructCallEdgesFromIR as u,serializeCanonical as d,stringArraysEqual as f,trySymbolId as ee}from"@aburi/core";import{representativeSymbol as p}from"@aburi/types";var m=class extends Error{code;value;violations;constructor(e,t,n){super(e,n),this.name=`DiffError`,this.code=t.code,this.value=t.value,this.violations=t.violations}};const h=a(e=>e.id);function te(e,t){let n=new Map;for(let t of e)n.set(t.id,t);let r=new Map;for(let e of t)r.set(e.id,e);let i=[],o=[],s=[];for(let[e,t]of r){let r=n.get(e);if(r===void 0){i.push(t);continue}oe(r,t)||s.push({before:r,after:t,delta:{rootsChanged:!f(r.roots,t.roots),publicApiChanged:!f(r.publicApi??[],t.publicApi??[]),frameworksChanged:!f(r.frameworks??[],t.frameworks??[])}})}for(let[e,t]of n)r.has(e)||o.push(t);return i.sort(h),o.sort(h),s.sort(a(e=>e.after.id)),{added:i,removed:o,changed:s}}function g(e){let t=new Map(e??[]),n=new Map;for(let[e,r]of t){let t=n.get(r);t===void 0?n.set(r,[e]):t.push(e)}for(let e of n.values())e.sort(o);return{baseToHead:t,headToBase:n}}function _(e,t,n){let r=n[t],i=[],a=r.lostFiles.get(e);a!==void 0&&i.push({path:e,reason:a});for(let a of ne(e,t,n.renames)){if(a===e)continue;let t=r.lostFiles.get(a);t!==void 0&&i.push({path:a,reason:t})}return i}function v(e,t,n){return _(e,t,n)[0]}function ne(e,t,n){if(t===`base`)return n.headToBase.get(e)??[];let r=n.baseToHead.get(e);return r===void 0?[]:[r]}function y(e){let t=new Map;for(let n of e.symbols)t.set(n.id,n.source.file);let n=new Map,i=new Map,a=r(e.components);for(let{path:t,reason:r}of e.stats.skippedFiles??[]){n.set(t,r);let e=a(t);if(e===null)continue;let o=i.get(e);o===void 0?i.set(e,[{path:t,reason:r}]):o.push({path:t,reason:r})}return{symbolFiles:t,lostFiles:n,componentLostFiles:i}}function re(e,t,n,r){let i=e=>r.get(e)??e,a=new Map;for(let t of e){let e={...t,from:i(t.from),to:i(t.to)},n=w(e),r=a.get(n);if(r!==void 0)throw ae(r,t,e);a.set(n,t)}let o=new Map;for(let e of t)o.set(w(e),e);let s=[],c=[],l=[];for(let[e,t]of o){let r=a.get(e);if(r===void 0){let e=ie(t,`base`,n);e.length>0?l.push({dependency:t,absentFrom:`base`,lostFiles:e}):s.push(t);continue}(r.direction!==t.direction||(r.effect??null)!==(t.effect??null))&&(c.push(r),s.push(t))}for(let[e,t]of a){if(o.has(e))continue;let r=ie(t,`head`,n);r.length>0?l.push({dependency:t,absentFrom:`head`,lostFiles:r}):c.push(t)}return s.sort(T),c.sort(T),l.sort((e,t)=>T(e.dependency,t.dependency)),{added:s,removed:c,unknown:l}}function ie(e,t,n){let r=n[t===`base`?`head`:`base`],i=new Map;for(let a of[e.from,e.to]){let e=r.symbolFiles.get(a);if(e===void 0)continue;let o=v(e,t,n);o!==void 0&&i.set(o.path,o.reason)}for(let r of n[t].componentLostFiles.get(e.from)??[])i.set(r.path,r.reason);return[...i.entries()].map(([e,t])=>({path:e,reason:t})).sort(a(e=>e.path))}function ae(e,t,n){let r=S(C(n));return new m(`baseIR.dependencies holds ${S(C(e))} and ${S(C(t))}, which both read as ${r} under the head ids the Symbol pairing gave their endpoints; one of them would drop out of the diff.`,{code:`ir-identity-collision`,value:r})}const b=[`from`,`to`,`via`];function x(e){return e.join(`::`)}function S(e){return`(${e.join(`, `)})`}function C(e){return b.map(t=>e[t])}function w(e){return x(C(e))}const T=a(w);function oe(e,t){return se(e,`base`)===se(t,`head`)}function se(e,t){try{return d(ce(e),{format:`compact`})}catch(n){throw new m(`${t} components[id=${e.id}] cannot be compared: ${n instanceof Error?n.message:String(n)}`,{code:`ir-shape-invalid`,value:`components[id=${e.id}]`},{cause:n})}}function ce(e){let t={...e};(t.description===null||t.description===void 0)&&delete t.description;for(let e of le){let n=t[e];(n===void 0||Array.isArray(n)&&n.length===0)&&delete t[e]}return t}const le=[`publicApi`,`frameworks`],ue=2,de=10,fe=0;function E(e,t,n={}){let r=pe(n.lineFuzz??2),i=[e.source.startLine,t.source.startLine],a=e.middleware===void 0&&t.middleware===void 0?{}:{middleware:Ee(e.middleware??[],t.middleware??[])};return{apiChanged:e.fingerprint.api!==t.fingerprint.api,logicChanged:e.fingerprint.logic!==t.fingerprint.logic,syntaxChanged:e.fingerprint.syntax!==t.fingerprint.syntax,componentChanged:(e.component??null)!==(t.component??null),visibilityChanged:e.visibility!==t.visibility,confidenceChanged:e.confidence!==t.confidence,rules:ge(e.rules,t.rules,i,r),effects:ve(e.effects,t.effects,i),calls:be(e.calls,t.calls,i,r),decorators:Se(e.decorators,t.decorators,i,r),exportedAs:P(c(e),c(t)),signature:Te(e.signature??null,t.signature??null),...a}}function pe(e){if(!Number.isFinite(e)||!Number.isInteger(e))throw new m(`lineFuzz must be an integer in [0, 10]; got ${String(e)}.`,{code:`invalid-line-fuzz`,value:String(e)});if(e<0||e>10)throw new m(`lineFuzz must be within [0, 10]; got ${e}.`,{code:`invalid-line-fuzz`,value:String(e)});return e}function D(e,t,n,r){return[e.map(e=>r(e,n[0])),t.map(e=>r(e,n[1]))]}function O(e,t,n,r){let i=new Set(e.map((e,t)=>t)),a=new Set(t.map((e,t)=>t)),o=new Map,s=[(e,t)=>e.key===t.key&&n(e.item,t.item),(e,t)=>e.key===t.key&&Math.abs(e.line-t.line)<=r],c=me(e,t);for(let e of s)for(let t of c){let n=he(t.base.filter(e=>i.has(e.index)),t.head.filter(e=>a.has(e.index)),e);for(let[e,t]of n)i.delete(e.index),a.delete(t.index),o.set(t.index,e.element)}let l=[],u=[];for(let[e,r]of t.entries()){let t=o.get(e);t===void 0?l.push(r.item):n(t.item,r.item)||u.push(r.item)}return{added:l,removed:e.filter((e,t)=>i.has(t)).map(e=>e.item),modified:u}}function me(e,t){let n=new Map,r=e=>{let t=n.get(e);return t===void 0&&(t={base:[],head:[]},n.set(e,t)),t};for(let[t,n]of e.entries())r(n.key).base.push({index:t,element:n});for(let[e,n]of t.entries())r(n.key).head.push({index:e,element:n});return[...n.values()].filter(e=>e.base.length>0&&e.head.length>0)}const k={pairs:0,distance:0};function A(e,t){return e.pairs===t.pairs?e.distance<t.distance:e.pairs>t.pairs}function j(e,t){return e.pairs===t.pairs&&e.distance===t.distance}function he(e,t,n){let r=Array.from({length:e.length+1},()=>Array.from({length:t.length+1},()=>k)),i=(e,t)=>r[e]?.[t]??k,a=(r,a)=>{let o=e[r],s=t[a];if(o===void 0||s===void 0||!n(o.element,s.element))return null;let c=i(r+1,a+1),l=c.distance+Math.abs(o.element.line-s.element.line);return{score:{pairs:c.pairs+1,distance:l},pair:[o,s]}};for(let n=e.length-1;n>=0;n--)for(let e=t.length-1;e>=0;e--){let t=i(n+1,e),o=i(n,e+1),s=A(t,o)?t:o,c=a(n,e)?.score;c!==void 0&&A(c,s)&&(s=c);let l=r[n];l!==void 0&&(l[e]=s)}let o=[],s=0,c=0;for(;s<e.length&&c<t.length;){let e=i(s,c),t=a(s,c);t!==null&&j(t.score,e)?(o.push(t.pair),s++,c++):j(i(s+1,c),e)?s++:c++}return o}function ge(e,t,n,r){let[i,a]=D(e,t,n,(e,t)=>({item:e,key:e.type,line:e.line-t}));return O(i,a,_e,r)}function _e(e,t){return e.type===t.type&&(e.condition??null)===(t.condition??null)&&(e.what??null)===(t.what??null)&&(e.expr??null)===(t.expr??null)&&(e.loopKind??null)===(t.loopKind??null)}function ve(e,t,n){let[r,i]=D(e,t,n,(e,t)=>({item:e,key:`${e.id}::${e.target}`,line:e.line===void 0?0:e.line-t}));return O(r,i,ye,1/0)}function ye(e,t){return e.id===t.id&&e.target===t.target&&e.plugin===t.plugin&&e.confidence===t.confidence&&(e.propagated??!1)===(t.propagated??!1)&&f([...e.derivedFrom??[]].sort(o),[...t.derivedFrom??[]].sort(o))}function be(e,t,n,r){let[i,a]=D(e,t,n,(e,t)=>({item:e,key:e.target,line:e.line-t}));return O(i,a,xe,r)}function xe(e,t){return e.target===t.target&&(e.resolved??null)===(t.resolved??null)}function Se(e,t,n,r){let[i,a]=D(e,t,n,(e,t)=>({item:e,key:e.name,line:e.line-t}));return O(i,a,Ce,r)}function Ce(e,t){return e.name===t.name&&(e.qualifier??null)===(t.qualifier??null)&&f(e.arguments,t.arguments)}function we(e,t){return e.name===t.name&&e.type===t.type&&e.optional===!0==(t.optional===!0)&&e.rest===!0==(t.rest===!0)}function Te(e,t){if(e===null)return t===null?null:M(t,`added`);if(t===null)return M(e,`removed`);let n=(e,t)=>({item:e,key:`${t}:${e.name}`,line:t});return{inputs:O(e.inputs.map(n),t.inputs.map(n),we,0),outputs:Oe(e.outputs,t.outputs),throws:P(e.throws,t.throws),asyncChanged:e.async!==t.async,generatorChanged:e.generator!==t.generator,typeParametersChanged:!f(e.typeParameters,t.typeParameters)}}function M(e,t){let n=e=>({added:t===`added`?[...e]:[],removed:t===`removed`?[...e]:[],modified:[]});return{inputs:n(e.inputs),outputs:n(e.outputs),throws:n(e.throws),asyncChanged:e.async,generatorChanged:e.generator,typeParametersChanged:e.typeParameters.length>0}}function Ee(e,t){let n=N(t,e),r=N(e,t),i=e.length-r.length;return{added:n,removed:r,reordered:De(e,t)<i}}function N(e,t){let n=new Map;for(let e of t)n.set(e,(n.get(e)??0)+1);let r=[];for(let t of e){let e=n.get(t)??0;e>0?n.set(t,e-1):r.push(t)}return r}function De(e,t){let n=Array(t.length+1).fill(0);for(let r of e){let e=[0];for(let[i,a]of t.entries())e.push(r===a?(n[i]??0)+1:Math.max(n[i+1]??0,e[i]??0));n=e}return n[t.length]??0}function Oe(e,t){let n=[],r=[],i=Math.max(e.length,t.length);for(let a=0;a<i;a++){let i=a<e.length?e[a]:void 0,o=a<t.length?t[a]:void 0;i===void 0&&o!==void 0?n.push(o):o===void 0&&i!==void 0?r.push(i):i!==o&&(i!==void 0&&r.push(i),o!==void 0&&n.push(o))}return{added:n,removed:r,modified:[]}}function P(e,t){let n=new Set(e),r=new Set(t),i=[],a=[];for(let e of r)n.has(e)||i.push(e);for(let e of n)r.has(e)||a.push(e);return{added:i,removed:a,modified:[]}}function ke(e,t){if(e.$schema!==t.$schema)throw new m(`Base IR schema "${e.$schema}" does not match head IR schema "${t.$schema}"; a diff across schema versions is not supported.`,{code:`schema-mismatch`,value:e.$schema})}const F=e=>e.join(``),Ae=[{field:`symbols`,identities:e=>e.symbols.map(e=>[e.id]),keyOf:F,noun:`id`,show:F,consequence:`stage 1 pairs Symbols by id and every later stage tracks the base Symbols it has consumed by id, so a repeat leaves one entry out of the diff entirely or classifies its counterpart twice`},{field:`components`,identities:e=>e.components.map(e=>[e.id]),keyOf:F,noun:`id`,show:F,consequence:`Component identity is the id, so a repeat hides one entry and can report a change the two revisions do not contain`},{field:`dependencies`,identities:e=>e.dependencies.map(e=>b.map(t=>e[t])),keyOf:x,noun:`(from, to, via) triple`,show:S,consequence:`direction and effect are deliberately outside Dependency identity, so a repeat surfaces as an added + removed pair no reader can tell from a real flip`}];function I(e,t){let n=i(e),r=n[0];if(r!==void 0){let e=L(t,r.subject),i=n.length-1,a=i>0?` (and ${i} more)`:``;throw new m(`${e}: ${r.message}${a}.`,{code:`ir-shape-invalid`,value:e,violations:n.map(e=>({...e,subject:L(t,e.subject)}))})}if(e.$schema.length===0)throw new m(`${t}: "$schema" is empty, not a schema URL.`,{code:`ir-shape-invalid`,value:t});for(let n of Ae)je(n.identities(e),`${t}.${n.field}`,n)}function L(t,n){return n===e?t:`${t}.${n}`}function je(e,t,n){let r=new Map;for(let[i,a]of e.entries()){let e=n.keyOf(a),o=r.get(e);if(o===void 0){r.set(e,i);continue}let s=n.show(a);throw new m(`${t}[${i}] repeats the ${n.noun} "${s}" first seen at index ${o}; ${n.consequence}.`,{code:`ir-identity-collision`,value:s})}}const R={numerator:1,denominator:1},z={numerator:0,denominator:1};function B(e){return e.numerator/e.denominator}function V(e,t){return e.numerator*t.denominator>=t.numerator*e.denominator}function Me(e){return H(e.map(e=>({weight:1,value:e})))}function Ne(e){return H(e)}function H(e){let t=0,n=1,r=0;for(let{weight:i,value:a}of e)t=t*a.denominator+i*a.numerator*n,n*=a.denominator,r+=i;return{numerator:t,denominator:n*r}}function U(e){let t=new Set,n=[];for(let r of e.normalize(`NFC`).split(/[.:_\-\s/]+/))if(r.length!==0)for(let e of Pe(r)){let r=e.toLowerCase();r.length===0||t.has(r)||(t.add(r),n.push(r))}return n}function Pe(e){let t=[],n=``,r=``;for(let i of e){if(n===``){n=i,r=i;continue}Re(r,i)?(t.push(n),n=i):n+=i,r=i}return n.length>0&&t.push(n),t}const Fe=/\p{Ll}/u,Ie=/\p{Lu}|\p{Lt}/u,Le=/\p{Nd}/u;function Re(e,t){let n=Fe.test(e),r=Ie.test(e),i=Le.test(e),a=Fe.test(t),o=Ie.test(t),s=Le.test(t);return!!(n&&o||(n||r)&&s||i&&(a||o))}const ze=/\p{scx=Han}/u,Be=/[\p{scx=Hiragana}\p{scx=Katakana}\p{scx=Hangul}]/u,Ve=/\p{M}/u;function He(e){let t=new Set,n=0,r=0,i=0;for(let a of U(e)){let e=!1;for(let i of a){if(Ve.test(i))continue;let a=ze.test(i);if(!a&&!Be.test(i)){e=!0;continue}t.has(i)||(t.add(i),a?n++:r++)}e&&i++}return i+n/3+r/6}function Ue(e,t){return B(We(e,t))}function We(e,t){return W(new Set(e),new Set(t))}function W(e,t){if(e.size===0&&t.size===0)return R;if(e.size===0||t.size===0)return z;let[n,r]=e.size<=t.size?[e,t]:[t,e],i=0;for(let e of n)r.has(e)&&i++;return{numerator:i,denominator:e.size+t.size-i}}function Ge(e,t){return Ue(U(e),U(t))}function G(e){let t=e.lastIndexOf(`::`),n=e.lastIndexOf(`.`);return t>n?{owner:e.slice(0,t),member:e.slice(t+2)}:n>=0?{owner:e.slice(0,n),member:e.slice(n+1)}:{owner:``,member:e}}function K(e){return G(e).member}const q=e=>new Set(U(e));function Ke(e,t){return Ze(q,e,t)}function qe(e,t){return B(Qe(q,e,t))}function Je(e,t){return $e(G(e).owner,G(t).owner,q)}function Ye(e,t){if(e===t)return!0;let[n,r]=e.length<=t.length?[e,t]:[t,e];return Xe(n,r)}function Xe(e,t){return t===`${e}s`||t===`${e}es`?!0:e.endsWith(`y`)&&t===`${e.slice(0,-1)}ies`}function Ze(e,t,n){return B(W(e(t),e(n)))}function Qe(e,t,n){return W(e(K(t)),e(K(n)))}function $e(e,t,n){return e===t?!0:e===``||t===``||!rt(e,t,n)?!1:et(e,t,n)}function et(e,t,n){let r=e.split(`.`),i=t.split(`.`);return r.length===i.length?r.every((e,t)=>{let r=i[t];return r===void 0?!1:e===r?!0:tt(n(e),n(r))}):!1}function tt(e,t){if(e.size!==t.size||e.size>32)return!1;let n=[...t],r=new Map;for(let t of e)if(!nt(t,n,r,new Set))return!1;return!0}function nt(e,t,n,r){for(let i of t){if(r.has(i)||!Ye(e,i))continue;r.add(i);let a=n.get(i);if(a===void 0||nt(a,t,n,r))return n.set(i,e),!0}return!1}function rt(e,t,n){let r=e.slice(0,it(e)),i=t.slice(0,it(t));if(r===i)return!0;let a=n(r),o=n(i);if(a.size!==o.size||a.size>32)return!1;for(let e of a){let t=!1;for(let n of o)if(Ye(e,n)){t=!0;break}if(!t)return!1}return!0}function it(e){let t=e.indexOf(`.`);return t<0?e.length:t}function J(){let e=new Map,t=t=>{let n=e.get(t);if(n!==void 0)return n;let r=new Set(U(t));return e.set(t,r),r},n=new Map,r=e=>{let t=n.get(e);if(t!==void 0)return t;let r=G(e).owner;return n.set(e,r),r};return{name:(e,n)=>Ze(t,e,n),member:(e,n)=>Qe(t,e,n),ownersCompatible:(e,n)=>$e(r(e),r(n),t)}}function at(e){e.sort(ot);let t=new Set,n=new Set,r=[];for(let i of e)t.has(i.base.id)||n.has(i.head.id)||(t.add(i.base.id),n.add(i.head.id),r.push(i));return{pairs:r,baseIds:t,headIds:n}}function ot(e,t){return t.score-e.score||st(e,t)}function st(e,t){return o(e.base.id,t.base.id)||o(e.head.id,t.head.id)}function Y(e,t){return e.filter(e=>!t.has(e.id))}function X(e,t,n){return{matched:e,remainingBase:Y(t,new Set(e.map(e=>e.base.id))),remainingHead:Y(n,new Set(e.map(e=>e.head.id)))}}function ct(e){return He(e)>1}function lt(e,t){let n=e.filter(e=>e.dropped),r=t.filter(e=>e.dropped),i=[];for(let e of[mt,ht])i.push(...ft(n,r,e));return X(ut(i).map(({base:e,head:t})=>({base:e,head:t,rationale:`dropped-weak-match`})),e,t)}function ut(e){let t=[...e].sort(st),n=new Map,r=new Map;for(let[e,i]of t.entries())dt(n,i.base.id,e),dt(r,i.head.id,e);let i=e=>{let i=t[e];return i===void 0?[]:[...n.get(i.base.id)??[],...r.get(i.head.id)??[]].filter(t=>t!==e)},a=t.map(()=>!1),o=[],s=e=>{let n=e,r=!0;for(;!a[n];){a[n]=!0;let e=t[n];r&&e!==void 0&&o.push(e),r=!r;let s=i(n).find(e=>a[e]===!1);if(s===void 0)return;n=s}};for(let[e]of t.entries())!a[e]&&i(e).length<=1&&s(e);for(let[e]of t.entries())a[e]||s(e);return o}function dt(e,t,n){let r=e.get(t);r===void 0?e.set(t,[n]):r.push(n)}function ft(e,t,n){let r=pt(e,n),i=pt(t,n),a=[];for(let[e,t]of r){let n=i.get(e);n!==void 0&&a.push({base:t,head:n})}return a}function pt(e,t){let n=new Map,r=new Set;for(let i of e){let e=t(i);if(!r.has(e)){if(n.has(e)){n.delete(e),r.add(e);continue}n.set(e,i)}}return n}function mt(e){return`${e.kind}/${K(e.name)}`}function ht(e){return`${e.kind}/${gt(e.source.file)}`}function gt(e){let t=e.lastIndexOf(`/`);return t>=0?e.slice(t+1):e}function _t(e,t,n){if(n===null||n.size===0)return X([],e,t);let r=new Map;for(let e of t)r.set(e.id,e);let i=new Map;for(let t of e){let e=n.get(t.source.file);if(e===void 0)continue;let a=yt(t.id,t.source.file,e);if(a===null)continue;let o=r.get(a);if(o===void 0)continue;let s=i.get(a);s===void 0?i.set(a,{head:o,bases:[t]}):s.bases.push(t)}let a=[];for(let{head:e,bases:t}of i.values())a.push({base:vt(t),head:e,rationale:`git-rename`});return X(a,e,t)}function vt(e){let t=e[0];for(let n of e)n.id<t.id&&(t=n);return t}function yt(e,t,n){let r=e.indexOf(`:`),i=e.indexOf(`#`);return r<0||i<0||i<r||e.slice(r+1,i)!==t?e:ee({language:e.slice(0,r),file:n,qualifiedName:e.slice(i+1)})}function bt(e,t){let n=new Map;for(let e of t)n.set(e.id,e);let r=[];for(let t of e){let e=n.get(t.id);e!==void 0&&r.push({base:t,head:e,rationale:`id-match`})}return X(r,e,t)}function xt(e,t){let n=Z(e),r=Z(t),i=J(),a=[];for(let[e,t]of r){let r=n.get(e);r!==void 0&&a.push(...Tt(r.symbols,t.symbols,i,t.evidenceless))}return X(a,e,t)}function St(e,t){let n=Z(t),r=J(),i=new Map;for(let t of e){if(t.extKind!==null||!Ct(t)||l(t))continue;let e=n.get(wt(t,!1));if(e===void 0)continue;let a=Et(t,e.symbols.filter(e=>e.fingerprint.syntax===t.fingerprint.syntax),r);a!==void 0&&i.set(t.id,a.id)}return i}function Ct(e){return!e.dropped&&e.fingerprint.logic!==n}function wt(e,t){return JSON.stringify([e.kind,e.fingerprint.logic,t])}function Z(e){let t=new Map;for(let n of e){if(!Ct(n))continue;let e=l(n),r=wt(n,e),i=t.get(r);i===void 0?t.set(r,{evidenceless:e,symbols:[n]}):i.symbols.push(n)}return t}function Tt(e,t,n,r){let i=e=>!r||ct(e.name),a=e.filter(i),o=t.filter(i),s=[];for(;a.length>0&&o.length>0;){let e=!r&&a.length===1?a[0]:void 0;if(e!==void 0){let t=Et(e,o,n);if(t===void 0)break;s.push({base:e,head:t,rationale:`logic-fingerprint`});break}let t=[];for(let e of a)for(let r of o){let i=n.name(e.name,r.name);i>=.85&&t.push({base:e,head:r,score:i})}let i=at(t);if(i.pairs.length===0)break;for(let{base:e,head:t}of i.pairs)s.push({base:e,head:t,rationale:`logic-fingerprint+name-disambiguation`});a=Y(a,i.baseIds),o=Y(o,i.headIds)}return s}function Et(e,t,n){let r;for(let i of t){let t=n.name(e.name,i.name);if(r===void 0||t>r.score){r={head:i,score:t};continue}t===r.score&&i.id<r.head.id&&(r={head:i,score:t})}return r?.head}function Dt(e,t){return B(Ot(e,t))}function Ot(e,t){let n=e??null,r=t??null;return n===null&&r===null?R:n===null||r===null?z:Me([kt(n.inputs.map(e=>e.type),r.inputs.map(e=>e.type)),kt(n.outputs,r.outputs),We(n.throws,r.throws)])}function kt(e,t){if(e.length===0&&t.length===0)return R;if(e.length!==t.length)return z;let n=0;for(let r=0;r<e.length;r++)e[r]===t[r]&&n++;return{numerator:n,denominator:e.length}}function At(e,t,n){let r=e=>{if(e.dropped)return!1;let t=Pt(e);return t===void 0?!0:(n?.debug(`diff/stage4: ${e.id} is not compared by name: ${t}`),!1)},i=new Map;for(let t of e){if(!r(t))continue;let e=i.get(t.kind)??{members:[],byToken:new Map,visited:new Int32Array,walks:0},n=e.members.length;e.members.push(t);for(let r of It(t.name)){let t=e.byToken.get(r)??[];t.push(n),e.byToken.set(r,t)}i.set(t.kind,e)}for(let e of i.values())e.visited=new Int32Array(e.members.length);let a=J(),o=[];for(let e of t){if(!r(e))continue;let t=i.get(e.kind);if(t===void 0)continue;let n=Wt(e.name);for(let r of Ft(t,e))jt(r,e,a,n,o)}let s=at(o);return n!==void 0&&Mt(i,t,s,a,n),X(s.pairs.map(({base:e,head:t})=>({base:e,head:t,rationale:`name-signature`})),e,t)}function jt(e,t,n,r,i){let a=n.member(e.name,t.name);if(!V(a,r.memberFloor)||!n.ownersCompatible(e.name,t.name))return;let o=Nt(a,e,t);V(o,r.threshold)&&i.push({base:e,head:t,score:B(o)})}function Mt(e,t,n,r,i){for(let a of t){if(a.dropped||n.headIds.has(a.id)||Pt(a)!==void 0)continue;let t=e.get(a.kind);if(t===void 0)continue;let o=Wt(a.name);for(let e of Ft(t,a)){if(n.baseIds.has(e.id))continue;let t=r.member(e.name,a.name);V(t,o.memberFloor)&&(r.ownersCompatible(e.name,a.name)||V(Nt(t,e,a),o.threshold)&&i.debug(`diff/stage4: ${e.id} and ${a.id} are not paired: their owners do not correspond`))}}}function Nt(e,t,n){return Ne([{weight:Lt,value:e},{weight:Rt,value:Ot(t.signature??null,n.signature??null)},{weight:zt,value:Bt}])}function Pt(e){if(!ct(e.name))return`its name says too little to pair on`;if(e.signature===null||e.signature===void 0)return`it has no signature, and a name alone does not pair`}function Ft(e,t){let n=It(t.name),r=0;for(let t of n)r+=e.byToken.get(t)?.length??0;if(r>=e.members.length)return e.members;e.walks++;let i=[];for(let t of n)for(let n of e.byToken.get(t)??[]){if(e.visited[n]===e.walks)continue;e.visited[n]=e.walks;let t=e.members[n];t!==void 0&&i.push(t)}return i}function It(e){let t=U(K(e));return t.length===0?[` none`]:t}const Lt=5,Rt=3,zt=2,Bt=R;function Q(e){return{threshold:e,memberFloor:{numerator:10*e.numerator-5*e.denominator,denominator:5*e.denominator}}}const Vt=Q(R),Ht=Q({numerator:19,denominator:20}),Ut=Q({numerator:17,denominator:20});function Wt(e){let t=U(K(e)).length;return t<=1?Vt:t===2?Ht:Ut}function Gt(e,t){if(e.dropped!==t.dropped)return`dropped-toggled`;let n=e.source.file!==t.source.file||e.id!==t.id,r=e.fingerprint.api!==t.fingerprint.api||e.fingerprint.logic!==t.fingerprint.logic||e.fingerprint.syntax!==t.fingerprint.syntax||!t.dropped&&e.confidence!==t.confidence;return n&&r?`moved+changed`:n?`moved`:r?`changed`:`unchanged`}function Kt(e){return e.dropped?`to-dropped`:`to-kept`}function qt(e){let t=new Map;for(let n of e)`before`in n&&t.set(n.before.id,n.after.id);return t}function Jt(e){let t=tn(e.changes);if(t.length===0)return[];let n=new Set(t);return s(t,rn(e.baseCallEdges,e.headCallEdges,n,qt(e.changes)),e=>e).map(Xt)}function Yt(e){return`slice:${e}`}function Xt(e){let t=e[0];if(t===void 0)throw new m(`computeSlices: the clustering utility returned an empty component; every weakly-connected component contains at least the node that seeded it.`,{code:`slice-invariant-violated`});let n={id:Yt(t),members:[...e]};return en(n),n}function Zt(e){let t=e.members[0];if(t===void 0){let t=$(e.id);throw new m(t.message,{code:`slice-invariant-violated`,value:t.subject})}return t}function Qt(e){if(typeof e!=`object`||!e)return{kind:`malformed-shape`,subject:`<not an object>`,message:`Expected a SliceRecord object; got ${e===null?`null`:typeof e}.`};let{id:t,members:n}=e,r=typeof t==`string`?t:`<missing id>`;if(typeof t!=`string`)return{kind:`malformed-shape`,subject:r,message:`SliceRecord ${r}: id must be a string; got ${typeof t}.`};if(!Array.isArray(n)||n.some(e=>typeof e!=`string`))return{kind:`malformed-shape`,subject:r,message:`SliceRecord ${r}: members must be an array of strings.`};let i=n[0];if(i===void 0)return $(r);let a=$t(i);if(a!==null)return{kind:`anchor-in-reserved-namespace`,subject:r,message:`SliceRecord anchor "${i}" uses the reserved language token "${a}", so its Slice id would repeat the prefix.`};for(let e=1;e<n.length;e++){let t=n[e-1],i=n[e];if(!(t<i))return{kind:`members-unordered`,subject:r,message:`SliceRecord ${r}: members[] is not in strictly ascending order at index ${e} ("${i}" follows "${t}"), so members[0] is not necessarily the anchor.`}}let o=Yt(i);return t===o?null:{kind:`id-not-derived`,subject:r,message:`SliceRecord id "${t}" is not derived from the anchor "${i}"; expected "${o}".`}}function $t(e){let n=e.indexOf(`:`);if(n<0)return null;let r=e.slice(0,n);return t.has(r)?r:null}function $(e){return{kind:`members-empty`,subject:e,message:`SliceRecord ${e}: members[] is empty, so the Slice has no anchor.`}}function en(e){let t=Qt(e);if(t!==null)throw new m(t.message,{code:`slice-invariant-violated`,value:t.subject})}function tn(e){let t=[];for(let n of e)switch(n.status){case`added`:case`removed`:case`unknown`:case`changed`:case`moved+changed`:case`dropped-toggled`:t.push(p(n).id);break;case`moved`:break;default:return nn(n)}return t}function nn(e){throw Error(`computeSlices: unhandled SymbolChange status ${JSON.stringify(e)}; every status has to declare whether it is a Slice Node.`)}function rn(e,t,n,r){let i=[],a=e=>r.get(e)??e;for(let t of e)an(a(t.from),a(t.to),n,i);for(let e of t)an(e.from,e.to,n,i);return i}function an(e,t,n,r){!n.has(e)||!n.has(t)||r.push([e,t])}const on={name:`aburi`,version:`0.0.0`};function sn(e){I(e.baseIR,`baseIR`),I(e.headIR,`headIR`),ke(e.baseIR,e.headIR);let t=bt(e.baseIR.symbols,e.headIR.symbols),n=_t(t.remainingBase,t.remainingHead,e.gitRenames??null),r=xt(n.remainingBase,n.remainingHead),i=At(r.remainingBase,r.remainingHead,e.logger),a=lt(i.remainingBase,i.remainingHead),o=[...t.matched,...n.matched,...r.matched,...i.matched,...a.matched],s={unknown:0,depsUnknown:0,removedDuplicates:0,added:0,removed:0,moved:0,movedChanged:0,changed:0,droppedToggled:0,unchanged:0,droppedAdded:0,droppedRemoved:0,componentsAdded:0,componentsRemoved:0,componentsChanged:0,depsAdded:0,depsRemoved:0},c=0,l=[];for(let t of o){let n=Gt(t.base,t.head);if(n===`unchanged`){s.unchanged++;continue}if(n===`dropped-toggled`){s.droppedToggled++,l.push({status:`dropped-toggled`,before:t.base,after:t.head,direction:Kt(t.head)});continue}if(n===`moved`){s.moved++,l.push({status:`moved`,before:t.base,after:t.head,rationale:t.rationale});continue}if(n===`changed`){s.changed++,l.push({status:`changed`,before:t.base,after:t.head,delta:E(t.base,t.head,e.delta??{})});continue}s.movedChanged++,l.push({status:`moved+changed`,before:t.base,after:t.head,rationale:t.rationale,delta:E(t.base,t.head,e.delta??{})})}let d={base:y(e.baseIR),head:y(e.headIR),renames:g(e.gitRenames??null)};for(let e of a.remainingHead){if(e.dropped){s.droppedAdded++;continue}let t=v(e.source.file,`base`,d);if(t!==void 0){c++,l.push(ln(e,`base`,t));continue}s.added++,l.push({status:`added`,symbol:e})}let f=[];for(let e of a.remainingBase){if(e.dropped){s.droppedRemoved++;continue}let t=v(e.source.file,`head`,d);if(t!==void 0){c++,l.push(ln(e,`head`,t));continue}f.push(e)}let ee=St(f,e.headIR.symbols);for(let e of f){let t=ee.get(e.id)??null;s.removed++,t!==null&&s.removedDuplicates++,l.push(cn(e,t))}let p=te(e.baseIR.components,e.headIR.components);s.componentsAdded=p.added.length,s.componentsRemoved=p.removed.length,s.componentsChanged=p.changed.length;let m=re(e.baseIR.dependencies,e.headIR.dependencies,d,qt(l));s.depsAdded=m.added.length,s.depsRemoved=m.removed.length,s.depsUnknown=m.unknown.length,s.unknown=c,l.sort(fn);let h=Jt({changes:l,baseCallEdges:u(e.baseIR),headCallEdges:u(e.headIR)});return{$schema:`https://aburi.kage1020.com/schema/aburi.diff.v1.json`,generator:e.generator??on,base:e.base,head:e.head,summary:s,symbols:l,components:p,dependencies:m,slices:h,notCompared:un(d)}}function cn(e,t){return{status:`removed`,symbol:e,duplicateOf:t}}function ln(e,t,n){return{status:`unknown`,symbol:e,absentFrom:t,reason:n.reason,...n.path===e.source.file?{}:{lostPath:n.path}}}function un(e){let t=[];for(let[n,r]of e.base.lostFiles)for(let i of _(n,`head`,e))t.push({path:i.path,...i.path===n?{}:{basePath:n},baseReason:r,headReason:i.reason});return t.sort(dn)}const dn=(e,t)=>o(e.path,t.path)||o(e.basePath??e.path,t.basePath??t.path);function fn(e,t){return o(e.status,t.status)||o(p(e).id,p(t).id)}function pn(e,t={}){return d(e,t)}export{ue as DEFAULT_LINE_FUZZ,m as DiffError,de as MAX_LINE_FUZZ,fe as MIN_LINE_FUZZ,en as assertSliceRecordInvariant,sn as buildDiff,Gt as classifyStatus,Jt as computeSlices,E as computeSymbolDelta,y as dependencySideView,te as diffComponents,re as diffDependencies,Kt as dropDirection,Ue as jaccard,Ge as jaccardTokens,K as lastSegment,lt as matchStageDroppedWeak,_t as matchStageGitRename,bt as matchStageId,xt as matchStageLogicFingerprint,At as matchStageNameSignature,qe as memberSimilarity,He as nameEvidence,Ke as nameSimilarity,Je as ownersAreCompatible,g as renameDirections,Dt as signatureSimilarity,Zt as sliceAnchor,Qt as sliceRecordViolation,U as tokenizeName,pn as writeCanonicalDiff};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aburi/diff",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Aburi diff engine: 5-stage semantic matcher (id / git-rename / logic fingerprint / name+signature / dropped weak) followed by status classification and per-Symbol delta computation, emitting aburi.diff.v1-conformant output for PR-review workflows",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "kage1020",
|
|
@@ -32,15 +32,17 @@
|
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@aburi/core": "0.
|
|
36
|
-
"@aburi/types": "0.
|
|
35
|
+
"@aburi/core": "0.6.0",
|
|
36
|
+
"@aburi/types": "0.6.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/node": "^26.0.1",
|
|
40
40
|
"ajv": "^8.20.0",
|
|
41
41
|
"tsdown": "^0.22.3",
|
|
42
42
|
"typescript": "^6.0.3",
|
|
43
|
-
"vitest": "^4.1.11"
|
|
43
|
+
"vitest": "^4.1.11",
|
|
44
|
+
"@aburi/schema": "0.0.0",
|
|
45
|
+
"@aburi/test-support": "0.0.2"
|
|
44
46
|
},
|
|
45
47
|
"scripts": {
|
|
46
48
|
"build": "tsdown",
|