@aburi/diff 0.5.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/dist/index.d.mts CHANGED
@@ -1,65 +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` — Component diff. Assumes `components[].id` is unique
7
- * on each side (ir-schema.md #2) and does not check it: `buildDiff` establishes that, and
8
- * a caller reaching this export directly owns the obligation, because the lookup map here is
9
- * last-write-wins.
10
- *
11
- * Any field that differs makes a Component `changed` — the whole object is compared, not the
12
- * three axes the delta names, so a `changed[]` entry with all three booleans `false` is a
13
- * well-formed answer meaning "something else about this component moved". `modified` deltas
14
- * are intentionally absent: fields are reported as before/after pairs.
15
- */
16
5
  declare function diffComponents(base: readonly Component[], head: readonly Component[]): ComponentDiff;
17
- /**
18
- * What one document knows about itself, for deciding whether the *other* document's silence
19
- * about an edge is evidence.
20
- *
21
- * `symbolFiles` is keyed on the endpoint id exactly as `dependencies[]` spells it, and its
22
- * values come from `symbols[].source.file` — the same space `stats.skippedFiles[].path` is in,
23
- * and the same space `buildDiff` classifies Symbols by. Reading the file out of the id's path
24
- * segment instead would be a second answer to "which file is this endpoint in" that nothing
25
- * forces to agree with the first. A Component endpoint is absent from the map, which keeps it
26
- * out of the reclassification without a special case: an aggregate over roots has no file to
27
- * lose.
28
- */
29
6
  interface DependencySideView {
30
- /**
31
- * `source.file` of every Symbol this document holds, keyed by `DependencyEndpoint` rather
32
- * than `SymbolId` because the lookup happens with an endpoint whose kind is not yet known,
33
- * and "absent" is the answer for a Component id.
34
- */
35
7
  symbolFiles: ReadonlyMap<DependencyEndpoint, RelativePath>;
36
- /** Files this document never analysed, by path, with the reason it gave. */
37
8
  lostFiles: ReadonlyMap<RelativePath, SkipReason>;
9
+ /** The skipped files each Component holds, by the document's own `components[]`. */
10
+ componentLostFiles: ReadonlyMap<DependencyEndpoint, readonly DiffSkippedFile[]>;
38
11
  }
39
- /**
40
- * Build a side view from a document. Exported because `DependencySideView` is public and
41
- * `diffDependencies` requires one; `buildDiff` reads `lostFiles` for its own Symbol
42
- * classification from this same object.
43
- */
44
- declare function dependencySideView(ir: IR): DependencySideView;
45
- /**
46
- * `docs/design/diff-algorithm.md` — Dependency diff. Identity is the composite
47
- * `(from, to, via)` triple; direction and effect changes surface as an added + removed pair so
48
- * `modified` is not part of the schema. Uniqueness of the triple is the caller's
49
- * obligation on the same terms as `diffComponents`.
50
- *
51
- * `sides` separates a deletion from a loss and is required rather than optional:
52
- * omitting it would silently classify every edge into a lost file as a deletion while still
53
- * writing `unknown: []`, which the schema defines as "nothing was unknown". A caller with no
54
- * skip list passes a side view whose `lostFiles` is empty.
55
- *
56
- * The return type declares `unknown` present, where the schema leaves it optional for
57
- * documents that predate the field.
58
- */
59
- 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 {
60
18
  base: DependencySideView;
61
19
  head: DependencySideView;
62
- }): DependencyDiff & {
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 & {
63
24
  unknown: DependencyUnknown[];
64
25
  };
65
26
  //#endregion
@@ -69,200 +30,72 @@ declare const MAX_LINE_FUZZ = 10;
69
30
  declare const MIN_LINE_FUZZ = 0;
70
31
  interface DeltaOptions {
71
32
  /**
72
- * Line fuzz for pairing an edited rule/call/decorator with its predecessor
73
- * (diff-algorithm.md); an unchanged one pairs however far it moved. Must be an integer in
74
- * `[MIN_LINE_FUZZ, MAX_LINE_FUZZ]` (`0..10`); anything outside — or a non-finite value —
75
- * throws `DiffError({ code: "invalid-line-fuzz" })`. Setting `0` pairs an edit only with an
76
- * element on the same line, and does not stop an unchanged element from pairing; omitting the
77
- * 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.
78
36
  */
79
37
  lineFuzz?: number;
80
38
  }
81
- /**
82
- * The full per-Symbol delta between two paired Symbols (diff-algorithm.md). The axis booleans
83
- * come from fingerprint comparison; the array deltas from identity-preserving pairing, with line
84
- * fuzz deciding only how far an edited element may sit from the one it replaced.
85
- * `confidenceChanged` is always written, `false` included, so a reader can tell it from a diff
86
- * that predates the field.
87
- */
88
39
  declare function computeSymbolDelta(base: Symbol, head: Symbol, options?: DeltaOptions): SymbolDelta;
89
40
  //#endregion
90
- //#region src/match.d.ts
91
- /**
92
- * A concluded pairing of one base Symbol with one head Symbol, along with the
93
- * `MatchRationale` that placed them in the same pair. Stage 4 uses this shape both to
94
- * carry results out and to feed the delta / status classifier downstream.
95
- */
41
+ //#region src/match/pairing.d.ts
96
42
  interface SymbolPair {
97
43
  base: Symbol;
98
44
  head: Symbol;
99
45
  rationale: MatchRationale;
100
46
  }
101
- /** Optional map returned by git for stage 2 (`old path` → `new path`). */
102
- type GitRenameMap = ReadonlyMap<string, string>;
103
- /**
104
- * Stage 1 (diff-algorithm.md) — segments Symbols with identical `id` into paired matches.
105
- * Runs first because it is the highest-confidence signal (no heuristics, just hash lookup).
106
- *
107
- * Assumes `id` is unique on each side (ir-schema.md #1) and does not check it:
108
- * `buildDiff` establishes that before calling, and a caller reaching this export directly
109
- * owns the obligation. A repeat on the head side loses all but the last entry to the lookup
110
- * map and then removes every one of them from `remainingHead`; a repeat on the base side
111
- * pairs the same head Symbol more than once. The later stages track consumed base Symbols
112
- * by id and lose a repeat the same way.
113
- */
114
- declare function matchStageId(base: readonly Symbol[], head: readonly Symbol[]): {
115
- matched: SymbolPair[];
116
- remainingBase: Symbol[];
117
- remainingHead: Symbol[];
118
- };
119
- /**
120
- * Stage 2 (diff-algorithm.md) — git rename detection. When a rename map is available
121
- * (typical of ref-driven scans), rewrite the base id with the head-side file path and look
122
- * for a hit. Two base files renamed onto one target predict the same head id, so the
123
- * claimants are collected before one is chosen.
124
- *
125
- * The rewriter only touches the `file` portion of the id — the `<language>:` prefix and
126
- * the trailing `#<qualified-name>` segment stay unchanged so a moved file with the same
127
- * qualified name is picked up correctly. When a Symbol's file is not in the rename map,
128
- * it is left for later stages.
129
- */
130
- declare function matchStageGitRename(remainingBase: readonly Symbol[], remainingHead: readonly Symbol[], renameMap: GitRenameMap | null): {
47
+ interface StageResult {
131
48
  matched: SymbolPair[];
132
49
  remainingBase: Symbol[];
133
50
  remainingHead: Symbol[];
134
- };
135
- /**
136
- * Stage 3 (diff-algorithm.md) — group both sides by kind and `fingerprint.logic` and pair
137
- * within each group. Two branches:
138
- * - single base candidate → paired with `logic-fingerprint`, no similarity test
139
- * - several → `nameSimilarity` disambiguates at ≥ 0.85; a group that cannot reach it is left
140
- * whole for stage 4 to re-evaluate
141
- *
142
- * Dropped symbols are excluded — their logic fingerprint is the sentinel
143
- * `"000000000000"` and would collide with every other dropped Symbol in the workspace.
144
- * They flow to the stage-4.5 weak matcher instead.
145
- *
146
- * A logic value that names nothing (`logicNamesNothing`) is shared the same way, but by
147
- * Symbols that are kept: its group forms and pairs, on names alone and without the first
148
- * branch. See `pairWithinLogicGroup`.
149
- */
150
- declare function matchStageLogicFingerprint(remainingBase: readonly Symbol[], remainingHead: readonly Symbol[]): {
151
- matched: SymbolPair[];
152
- remainingBase: Symbol[];
153
- remainingHead: Symbol[];
154
- };
155
- /**
156
- * Stage 4 (diff-algorithm.md) — name + signature similarity with a `(kind, signatureNullness)`
157
- * bucket pre-filter, so a class body is never paired against a function. The owner gate runs
158
- * before the score; over the pairs that clear it:
159
- * 0.5 * memberSimilarity + 0.3 * signatureSimilarity + 0.2 * OWNER_AXIS_SATISFIED
160
- * `memberSimilarity` reads the last segment only, since the gate has settled the owner and
161
- * reading it again would charge twice. Thresholds are per head, see `thresholdFor`; the two
162
- * Symbols the stage does not read at all are explained at `saysEnoughToPair`. Candidates are
163
- * settled in score order (`acceptInScoreOrder`), and `createNameScorer` pays for the full
164
- * bucket being scored by tokenising each name once per pass.
165
- */
166
- declare function matchStageNameSignature(remainingBase: readonly Symbol[], remainingHead: readonly Symbol[]): {
167
- matched: SymbolPair[];
168
- remainingBase: Symbol[];
169
- remainingHead: Symbol[];
170
- };
171
- /**
172
- * Stage 4.5 (diff-algorithm.md) — dropped-only weak matcher. With the fingerprint zeroed, the only
173
- * signals left are the last segment of the qualified name and the file basename, and either alone
174
- * pairs — deliberately lax, since dropped Symbols sit outside the main review surface.
175
- *
176
- * What it does not accept is a signal that identifies nothing: a basename hit on `index.ts`
177
- * paired every dropped Symbol of one kind with every other and landed them in
178
- * `summary.moved`, which `--fail-on moved` gates on. So a half counts only when exactly one
179
- * dropped base and one dropped head carry that key — counted over the Symbols this stage is
180
- * handed, since a key the earlier stages emptied out identifies again. The candidates are
181
- * then the identifying keys themselves, at most `2 × min(base, head)` of them, all worth the
182
- * same; the score-ordered sweep would settle a conflict on nothing but id order, so
183
- * `bestPairing` takes a maximum matching instead.
184
- */
185
- declare function matchStageDroppedWeak(remainingBase: readonly Symbol[], remainingHead: readonly Symbol[]): {
186
- matched: SymbolPair[];
187
- remainingBase: Symbol[];
188
- remainingHead: Symbol[];
189
- };
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;
190
68
  //#endregion
191
69
  //#region src/diff.d.ts
192
- /**
193
- * The two counters `buildDiff` always writes. They are optional on `Summary` only so a diff
194
- * written before they existed stays valid; a caller holding a freshly built value should not
195
- * have to re-decide what "absent" means.
196
- */
197
- interface UnknownCounters {
70
+ interface AlwaysEmittedCounters {
198
71
  unknown: number;
199
72
  depsUnknown: number;
73
+ removedDuplicates: number;
200
74
  }
201
75
  interface DiffInput {
202
76
  baseIR: IR;
203
77
  headIR: IR;
204
- /** IR reference metadata (git ref / file path) for provenance. */
205
78
  base: IRRef;
206
79
  head: IRRef;
207
- /** Generator record for the diff output. Defaults to `{name: "aburi", version: "0.0.0"}`. */
208
80
  generator?: {
209
81
  name: string;
210
82
  version: string;
211
83
  };
212
- /** Optional stage-2 rename table. When null/undefined stage 2 is skipped. */
213
84
  gitRenames?: GitRenameMap | null;
214
- /** Passed through to computeSymbolDelta (line fuzz, diff-algorithm.md). */
215
85
  delta?: DeltaOptions;
86
+ logger?: Logger;
216
87
  }
217
- /**
218
- * Top-level entry: run the 5-stage matcher, classify each pair, produce array deltas,
219
- * fold in Component / Dependency diffs, and assemble the `aburi.diff.v1` JSON projection.
220
- * Pure; `writeCanonicalDiff` serialises, so callers can run the Markdown projection or the
221
- * `--fail-on` gate over the result first.
222
- */
223
88
  declare function buildDiff(input: DiffInput): DiffResult & {
224
89
  notCompared: NotComparedFile[];
225
- summary: Summary & UnknownCounters;
90
+ summary: Summary & AlwaysEmittedCounters;
226
91
  };
227
- /**
228
- * Byte-deterministic serialiser for a DiffResult, sharing `@aburi/core`'s canonical sort
229
- * order, NFC normalisation and key sort with the IR side.
230
- */
231
92
  declare function writeCanonicalDiff(diff: DiffResult, options?: SerializeOptions): string;
232
93
  //#endregion
233
94
  //#region src/errors.d.ts
234
- type DiffErrorCode = /** `base.$schema` and `head.$schema` disagree (diff-algorithm.md). */"schema-mismatch"
235
- /**
236
- * `DeltaOptions.lineFuzz` was not an integer in the documented [0, 10] range
237
- * (diff-algorithm.md).
238
- */
239
- | "invalid-line-fuzz"
240
- /**
241
- * `baseIR` or `headIR` is not a Document of the shape `aburi.ir.v1` requires (invariant #20,
242
- * `checkDocumentShape`), or its `$schema` is empty. Not the semantic invariants — see
243
- * `assertDiffable`.
244
- */
245
- | "ir-shape-invalid"
246
- /**
247
- * `baseIR` or `headIR` repeats an identity the diff keys on: a `symbols[].id`, a
248
- * `components[].id`, or a `dependencies[]` `(from, to, via)` triple. Distinct from
249
- * `ir-shape-invalid` because the Document is well-formed — the collision changes the
250
- * answer rather than preventing one (ir-schema.md #1 / #2 / #13).
251
- */
252
- | "ir-identity-collision"
253
- /**
254
- * A `SliceRecord` broke the derivation invariant of slice-view.md. Raised only by
255
- * an Aburi bug, never by user input — see `SliceRecordViolation.kind` for which clause broke.
256
- */
257
- | "slice-invariant-violated";
95
+ type DiffErrorCode = "schema-mismatch" | "invalid-line-fuzz" | "ir-shape-invalid" | "ir-identity-collision" | "slice-invariant-violated";
258
96
  interface DiffErrorDetail {
259
97
  code: DiffErrorCode;
260
- /** Offending value (schema id, fuzz value, etc.) when applicable. */
261
98
  value?: string;
262
- /**
263
- * Populated only for `ir-shape-invalid`, one entry per breach of invariant #20, so a caller
264
- * repairing a hand-assembled Document sees every breach rather than the first.
265
- */
266
99
  violations?: readonly IntegrityViolation[];
267
100
  }
268
101
  declare class DiffError extends Error {
@@ -275,183 +108,39 @@ declare class DiffError extends Error {
275
108
  }
276
109
  //#endregion
277
110
  //#region src/signature.d.ts
278
- /**
279
- * signatureSimilarity (diff-algorithm.md) — mean of three subscores over `inputs` (ordered
280
- * type equality rate), `outputs` (same) and `throws` (Jaccard). Two null signatures score
281
- * 1.0, one null scores 0.0. Empty on both sides counts as 1.0, empty on one side as 0.0.
282
- */
283
111
  declare function signatureSimilarity(base: Signature | null | undefined, head: Signature | null | undefined): number;
284
112
  //#endregion
285
113
  //#region src/similarity.d.ts
286
- /**
287
- * String similarity utilities dedicated to the diff engine. Kept in one file so the
288
- * name/signature/owner formulas are auditable side by side against diff-algorithm.md.
289
- */
290
- /**
291
- * Tokenise a qualified name into de-duplicated lowercase word segments, splitting on camel /
292
- * Pascal boundaries, `_`, `.`, `::` and digit runs: `InvoiceService.createInvoice` →
293
- * `["invoice", "service", "create"]`. De-duplicated because Jaccard relies on set semantics.
294
- *
295
- * The input is normalised to NFC first, so a name spelled with combining marks tokenises as
296
- * the name it is: `ガ` written U+30AB U+3099 is the same one token as U+30AC, and a Hangul
297
- * syllable written as conjoining jamo is the same one token as its precomposed block.
298
- *
299
- * The camel boundary is Unicode case, not the ASCII ranges, so `получитьПользователя` splits
300
- * at its hump the way `getUser` does. What no case rule can split is a script that has no
301
- * case at all: `ユーザー情報を取得する` and `获取用户信息` come back whole however much they
302
- * say. That is a fact about the writing system rather than about the name, which is why the
303
- * token count is not what diff-algorithm.md §3.4.3 asks how much a name says — see
304
- * `nameEvidence`.
305
- */
306
114
  declare function tokenizeName(input: string): string[];
307
- /**
308
- * How much a qualified name says, counted in words.
309
- *
310
- * The distinct-token count is this number for every name the tokeniser can segment, and every
311
- * caller wanting *granularity* — how coarse a Jaccard over these tokens will be — should keep
312
- * reading that count instead. This answers the different question diff-algorithm.md §3.4.3
313
- * asks: could two unrelated Symbols carry this name by coincidence? One word could be carried
314
- * twice; a phrase could not.
315
- *
316
- * A token of a cased or alphabetic script is one word, so it is worth 1 — `main`, `handler`
317
- * and `initialize` alike, however long they run, because length is not what makes a word
318
- * coincidental. A run of a script that writes no word boundary cannot be segmented, so it is
319
- * counted instead: its characters divided by the longest a single word of that script runs,
320
- * which is a floor on the number of words in it. `获取用户信息` is six Han characters, so it
321
- * says at least two words and is admitted; `ハンドラー` is five kana, so it says at least
322
- * one, which is what `handler` says and not enough to pair on.
323
- *
324
- * Characters are counted once each, the way tokens are — `取得取得` says what `取得` says,
325
- * as `getGet` says what `get` says. Combining marks are not counted: after NFC they are the
326
- * remainder of a character that did not compose, not a word.
327
- *
328
- * The number is a floor rather than a count, so it is fractional where a run is: `取得` is
329
- * two thirds of a word, `getUser` is exactly 2.
330
- */
331
115
  declare function nameEvidence(qname: string): number;
332
- /**
333
- * Jaccard similarity |A ∩ B| / |A ∪ B| over two token lists. Empty on both sides is 1.0
334
- * (both are "no tokens", equivalent for nameSimilarity); empty on one side only is 0.0.
335
- */
336
116
  declare function jaccard(a: readonly string[], b: readonly string[]): number;
337
- /** Jaccard over the tokens of two strings. Public surface only; nothing in this file calls it. */
338
117
  declare function jaccardTokens(a: string, b: string): number;
339
- /** The member name; read by the weak matcher and the threshold lookup. */
340
118
  declare function lastSegment(qname: string): string;
341
- /** Jaccard over the tokens of the full qualified name, every segment weighted alike. */
342
119
  declare function nameSimilarity(baseName: string, headName: string): number;
343
- /**
344
- * Jaccard over the tokens of the **last segment** only. What stage 4's composite reads, because the
345
- * owner gate decides the owner separately and reading it on both axes charges twice.
346
- */
347
120
  declare function memberSimilarity(baseName: string, headName: string): number;
348
- /**
349
- * The owner gate (diff-algorithm.md, R-8) — whether two Symbols are close enough in *scope* to be
350
- * the same Symbol: the same owner, or one whose owner was renamed. A gate rather than a score,
351
- * because grading the owner cannot do what R-8 asks. `UserRepo.findById` and `AdminRepo.findById`
352
- * agree on their member name and their signature, so a shared `Repo` token at weight 0.2 carries
353
- * them to 0.8667 against a 0.85 threshold — while `UsersRepository.findById`, which *is* the
354
- * rename, shares no owner token and scores 0.8000. The collision outscores the rename, and
355
- * raising the weight only moves both: at 0.3 two three-token class names sharing two tokens land
356
- * on exactly 0.85.
357
- *
358
- * Two empty owners are compatible (top-level Symbols share the outer scope); one empty and one
359
- * not never are. Otherwise the owners must correspond segment for segment, every token on each
360
- * side finding a distinct partner under `sameWord`.
361
- */
362
121
  declare function ownersAreCompatible(baseName: string, headName: string): boolean;
363
122
  //#endregion
364
123
  //#region src/slice.d.ts
365
- /** The three inputs of the Slice View pass — docs/design/slice-view.md. */
366
124
  interface SliceInput {
367
- /** SymbolChange records produced by `buildDiff` (pre-sort is not required). */
368
125
  changes: readonly SymbolChange[];
369
- /**
370
- * Resolved call edges from the base IR. Typically produced by
371
- * `reconstructCallEdgesFromIR(baseIR)` inside `buildDiff` — Slice View
372
- * consumes only resolved edges, never `Symbol.calls[]` directly.
373
- */
374
126
  baseCallEdges: readonly CallEdge[];
375
- /** Resolved call edges from the head IR (same source rule as base). */
376
127
  headCallEdges: readonly CallEdge[];
377
128
  }
378
- /**
379
- * Slice View clustering pass — docs/design/slice-view.md.
380
- *
381
- * Groups the changed-Symbol set of a diff into weakly-connected components
382
- * over the union of base and head call edges. Emits a `SliceRecord[]` whose
383
- * cluster ids are `"slice:" + <smallest-member Symbol id>`, both `slices[]`
384
- * and each `members[]` sorted ascending.
385
- *
386
- * Pure function: `(changes, baseCallEdges, headCallEdges)` → `SliceRecord[]`.
387
- * Determinism, idempotence, input-order insensitivity, and locality are all
388
- * guaranteed — see `computeWeaklyConnectedComponents` in `@aburi/core`.
389
- *
390
- * Returns `[]` when no SymbolChange is Node-eligible; callers should
391
- * still serialise the empty array — the Markdown projection omits the section
392
- * but the JSON always emits the key so consumers never
393
- * distinguish "field absent" from "no slices".
394
- *
395
- * Every returned record has passed `assertSliceRecordInvariant`.
396
- */
397
129
  declare function computeSlices(input: SliceInput): SliceRecord[];
398
- /**
399
- * The anchor of a Slice: its lexicographically smallest member.
400
- *
401
- * Answers from `members[0]`. `id` is derived from the anchor, so
402
- * reconstructing the anchor by stripping the `"slice:"` prefix is circular at
403
- * best and, for a record that broke the derivation, silently wrong: it would
404
- * name a Symbol that is not in the Slice. `id` is read here only to name the
405
- * offending record in the error message. Consumers that need the anchor call
406
- * this; consumers that need a label keep using `id` directly.
407
- */
408
130
  declare function sliceAnchor(record: SliceRecord): SymbolId;
409
- /** Which clause of the slice-view.md derivation invariant a `SliceRecord` broke. */
410
- 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. */ | "members-empty" /** `members[]` is not in strictly ascending order, so `members[0]` need not be the smallest. */ | "members-unordered" /** `id` is not `"slice:" + members[0]`. */ | "id-not-derived" /** The anchor is itself in a reserved id namespace, so `id` would read as a doubled prefix. */ | "anchor-in-reserved-namespace";
131
+ type SliceViolationKind = "malformed-shape" | "members-empty" | "members-unordered" | "id-not-derived" | "anchor-in-reserved-namespace";
411
132
  interface SliceRecordViolation {
412
133
  kind: SliceViolationKind;
413
- /** The offending record's `id` when it has a usable one, else a short stand-in. */
414
134
  subject: string;
415
- /** Human-facing explanation, suitable for an error message or a validator error. */
416
135
  message: string;
417
136
  }
418
- /**
419
- * Report which clause of the slice-view.md derivation invariant a value breaks, or `null`
420
- * when it is a well-formed `SliceRecord`. Non-throwing counterpart of
421
- * `assertSliceRecordInvariant`: the pass wants an exception, a schema
422
- * validator wants a verdict it can turn into its own error.
423
- *
424
- * Takes `unknown` rather than `SliceRecord` deliberately. Enforcement layer 2 points
425
- * this at documents written by third-party or older producers — data that has
426
- * not been type-checked by definition — so anything that assumed a well-typed
427
- * argument would crash on exactly the input it exists to reject.
428
- */
429
137
  declare function sliceRecordViolation(value: unknown): SliceRecordViolation | null;
430
- /**
431
- * Throwing form of `sliceRecordViolation`. Raised as a coded `DiffError` so
432
- * callers branch on `code` rather than parsing the message; which clause broke
433
- * is `SliceRecordViolation.kind`, for callers that need to tell them apart.
434
- */
435
138
  declare function assertSliceRecordInvariant(record: SliceRecord): void;
436
139
  //#endregion
437
140
  //#region src/status.d.ts
438
141
  type SymbolStatus = "unchanged" | "moved" | "changed" | "moved+changed" | "dropped-toggled";
439
- /**
440
- * Which of the five statuses a matched pair falls into (diff-algorithm.md). `dropped-toggled`
441
- * has absolute priority: a fingerprint change under a drop-rule flip is a consequence of the
442
- * flip, not a code edit.
443
- *
444
- * `pathChanged` covers both file relocation and in-file rename: any id mismatch means the
445
- * identifier moved, which DF9 ("method rename (same file, same logic) → moved") relies on.
446
- * Stage-1 pairs match by exact id, so only stage-2+ pairings can take the id branch.
447
- *
448
- * A confidence change is a change although no fingerprint reads it: the same code classified
449
- * less surely is something a reviewer has to see, and `unchanged` is never reported. A dropped
450
- * pair keeps its `unchanged`: a dropped Symbol is outside what the diff asks a reviewer to read.
451
- */
452
142
  declare function classifyStatus(base: Symbol, head: Symbol): SymbolStatus;
453
- /** Direction of a `dropped-toggled` transition (SymbolDroppedToggled, diff-algorithm.md). */
454
143
  type DropDirection = "to-dropped" | "to-kept";
455
144
  declare function dropDirection(head: Symbol): DropDirection;
456
145
  //#endregion
457
- 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, nameEvidence, 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,ZERO_FINGERPRINT as n,checkDocumentShape as r,compareBy as i,compareCodeUnit as a,computeWeaklyConnectedComponents as o,logicNamesNothing as s,reconstructCallEdgesFromIR as c,serializeCanonical as l,stringArraysEqual as u,trySymbolId as d}from"@aburi/core";var f=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 p=i(e=>e.id);function m(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 a=[],o=[],s=[];for(let[e,t]of r){let r=n.get(e);if(r===void 0){a.push(t);continue}te(r,t)||s.push({before:r,after:t,delta:{rootsChanged:!u(r.roots,t.roots),publicApiChanged:!u(r.publicApi??[],t.publicApi??[]),frameworksChanged:!u(r.frameworks??[],t.frameworks??[])}})}for(let[e,t]of n)r.has(e)||o.push(t);return a.sort(p),o.sort(p),s.sort(i(e=>e.after.id)),{added:a,removed:o,changed:s}}function h(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 ee(e,t,n){let r=new Map;for(let t of e)r.set(y(t),t);let i=new Map;for(let e of t)i.set(y(e),e);let a=[],o=[],s=[];for(let[e,t]of i){let i=r.get(e);if(i===void 0){let e=g(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=g(t,n.base,n.head);r.length>0?s.push({dependency:t,absentFrom:`head`,lostFiles:r}):o.push(t)}return a.sort(b),o.sort(b),s.sort((e,t)=>b(e.dependency,t.dependency)),{added:a,removed:o,unknown:s}}function g(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(i(e=>e.path))}const _=[`from`,`to`,`via`];function v(e){return e.join(`::`)}function y(e){return v(_.map(t=>e[t]))}const b=i(y);function te(e,t){return x(e,`base`)===x(t,`head`)}function x(e,t){try{return l(ne(e),{format:`compact`})}catch(n){throw new f(`${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 ne(e){let t={...e};(t.description===null||t.description===void 0)&&delete t.description;for(let e of re){let n=t[e];(n===void 0||Array.isArray(n)&&n.length===0)&&delete t[e]}return t}const re=[`publicApi`,`frameworks`],ie=2,ae=10,oe=0;function S(e,t,n={}){let r=se(n.lineFuzz??2);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:de(e.rules,t.rules,r),effects:pe(e.effects,t.effects),calls:he(e.calls,t.calls,r),decorators:_e(e.decorators,t.decorators,r),signature:ye(e.signature??null,t.signature??null)}}function se(e){if(!Number.isFinite(e)||!Number.isInteger(e))throw new f(`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 f(`lineFuzz must be within [0, 10]; got ${e}.`,{code:`invalid-line-fuzz`,value:String(e)});return e}function C(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=ce(e,t);for(let e of s)for(let t of c){let n=ue(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 ce(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 w={pairs:0,distance:0};function le(e,t){return e.pairs===t.pairs?e.distance<t.distance:e.pairs>t.pairs}function ue(e,t,n){let r=Array.from({length:e.length+1},()=>Array.from({length:t.length+1},()=>w)),i=(i,a)=>{let o=e[i],s=t[a];if(o===void 0||s===void 0||!n(o.element,s.element))return null;let c=r[i+1]?.[a+1]??w,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=r[n+1]?.[e]??w,a=r[n]?.[e+1]??w,o=le(t,a)?t:a,s=i(n,e)?.score;s!==void 0&&le(s,o)&&(o=s);let c=r[n];c!==void 0&&(c[e]=o)}let a=[],o=0,s=0;for(;o<e.length&&s<t.length;){let e=r[o]?.[s]??w,t=i(o,s);if(t!==null&&t.score.pairs===e.pairs&&t.score.distance===e.distance){a.push(t.pair),o++,s++;continue}let n=r[o+1]?.[s]??w;n.pairs===e.pairs&&n.distance===e.distance?o++:s++}return a}function de(e,t,n){let r=e=>({item:e,key:e.type,line:e.line});return C(e.map(r),t.map(r),fe,n)}function fe(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 pe(e,t){let n=e=>({item:e,key:`${e.id}::${e.target}`,line:e.line??0});return C(e.map(n),t.map(n),me,1/0)}function me(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)&&u([...e.derivedFrom??[]].sort(a),[...t.derivedFrom??[]].sort(a))}function he(e,t,n){let r=e=>({item:e,key:e.target,line:e.line});return C(e.map(r),t.map(r),ge,n)}function ge(e,t){return e.target===t.target&&(e.resolved??null)===(t.resolved??null)}function _e(e,t,n){let r=e=>({item:e,key:e.name,line:e.line});return C(e.map(r),t.map(r),ve,n)}function ve(e,t){return e.name===t.name&&(e.qualifier??null)===(t.qualifier??null)&&u(e.arguments,t.arguments)}function ye(e,t){if(e===null)return t===null?null:T(t,`added`);if(t===null)return T(e,`removed`);let n=(e,t)=>({item:e,key:`${t}:${e.name}`,line:t});return{inputs:C(e.inputs.map(n),t.inputs.map(n),(e,t)=>e.name===t.name&&e.type===t.type,0),outputs:be(e.outputs,t.outputs),throws:xe(e.throws,t.throws),asyncChanged:e.async!==t.async,generatorChanged:e.generator!==t.generator,typeParametersChanged:!u(e.typeParameters,t.typeParameters)}}function T(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 be(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 xe(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 E(e){let t=new Set,n=[];for(let r of e.normalize(`NFC`).split(/[.:_\-\s/]+/))if(r.length!==0)for(let e of Se(r)){let r=e.toLowerCase();r.length===0||t.has(r)||(t.add(r),n.push(r))}return n}function Se(e){let t=[],n=``,r=``;for(let i of e){if(n===``){n=i,r=i;continue}Te(r,i)?(t.push(n),n=i):n+=i,r=i}return n.length>0&&t.push(n),t}const D=/\p{Ll}/u,Ce=/\p{Lu}|\p{Lt}/u,we=/\p{Nd}/u;function Te(e,t){let n=D.test(e),r=Ce.test(e),i=we.test(e),a=D.test(t),o=Ce.test(t),s=we.test(t);return!!(n&&o||(n||r)&&s||i&&(a||o))}const Ee=/\p{scx=Han}/u,De=/[\p{scx=Hiragana}\p{scx=Katakana}\p{scx=Hangul}]/u,Oe=/\p{M}/u;function O(e){let t=new Set,n=0,r=0,i=0;for(let a of E(e)){let e=!1;for(let i of a){if(Oe.test(i))continue;let a=Ee.test(i);if(!a&&!De.test(i)){e=!0;continue}t.has(i)||(t.add(i),a?n++:r++)}e&&i++}return i+n/3+r/6}function k(e,t){return A(new Set(e),new Set(t))}function A(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 ke(e,t){return k(E(e),E(t))}function j(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 M(e){return j(e).member}const N=e=>new Set(E(e));function Ae(e,t){return F(N,e,t)}function je(e,t){return I(N,e,t)}function Me(e,t){return L(j(e).owner,j(t).owner,N)}function P(e,t){if(e===t)return!0;let[n,r]=e.length<=t.length?[e,t]:[t,e];return Ne(n,r)}function Ne(e,t){return t===`${e}s`||t===`${e}es`?!0:e.endsWith(`y`)&&t===`${e.slice(0,-1)}ies`}function F(e,t,n){return A(e(t),e(n))}function I(e,t,n){return A(e(M(t)),e(M(n)))}function L(e,t,n){return e===t?!0:e===``||t===``||!Ie(e,t,n)?!1:Pe(e,t,n)}function Pe(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:Fe(n(e),n(r))}):!1}function Fe(e,t){if(e.size!==t.size||e.size>32)return!1;let n=[...t],r=new Map;for(let t of e)if(!R(t,n,r,new Set))return!1;return!0}function R(e,t,n,r){for(let i of t){if(r.has(i)||!P(e,i))continue;r.add(i);let a=n.get(i);if(a===void 0||R(a,t,n,r))return n.set(i,e),!0}return!1}function Ie(e,t,n){let r=e.slice(0,z(e)),i=t.slice(0,z(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(P(e,n)){t=!0;break}if(!t)return!1}return!0}function z(e){let t=e.indexOf(`.`);return t<0?e.length:t}function B(){let e=new Map,t=t=>{let n=e.get(t);if(n!==void 0)return n;let r=new Set(E(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=j(e).owner;return n.set(e,r),r};return{name:(e,n)=>F(t,e,n),member:(e,n)=>I(t,e,n),ownersCompatible:(e,n)=>L(r(e),r(n),t)}}function V(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=H(n.inputs.map(e=>e.type),r.inputs.map(e=>e.type)),a=H(n.outputs,r.outputs),o=k(n.throws,r.throws);return(i+a+o)/3}function H(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 U(e){e.sort(Le);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 Le(e,t){return t.score-e.score||W(e,t)}function W(e,t){return a(e.base.id,t.base.id)||a(e.head.id,t.head.id)}function G(e,t){return e.filter(e=>!t.has(e.id))}function K(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:G(t,a)}}function q(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=ze(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=Re(t);a.push({base:n,head:e,rationale:`git-rename`}),o.add(n.id),s.add(e.id)}return{matched:a,remainingBase:G(e,o),remainingHead:G(t,s)}}function Re(e){let t=e[0];for(let n of e)n.id<t.id&&(t=n);return t}function ze(e,t,n){let r=e.indexOf(`:`),i=e.indexOf(`#`);return r<0||i<0||i<r||e.slice(r+1,i)!==t?e:d({language:e.slice(0,r),file:n,qualifiedName:e.slice(i+1)})}function J(e,t){let n=Y(e),r=Y(t),i=B(),a=[];for(let[e,t]of r){let r=n.get(e);r!==void 0&&a.push(...Be(r.symbols,t.symbols,i,t.evidenceless))}let o=new Set(a.map(e=>e.base.id)),s=new Set(a.map(e=>e.head.id));return{matched:a,remainingBase:G(e,o),remainingHead:G(t,s)}}function Y(e){let t=new Map;for(let r of e){if(r.dropped||r.fingerprint.logic===n)continue;let e=s(r),i=JSON.stringify([r.kind,r.fingerprint.logic,e]),a=t.get(i);a===void 0?t.set(i,{evidenceless:e,symbols:[r]}):a.symbols.push(r)}return t}function Be(e,t,n,r){let i=e=>!r||Z(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=Ve(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=U(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=G(a,i.baseIds),o=G(o,i.headIds)}return s}function Ve(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 X(e,t){let n=new Map;for(let t of e){if(t.dropped||!Z(t.name))continue;let e=Ue(t),r=n.get(e)??{members:[],byToken:new Map},i=r.members.length;r.members.push(t);for(let e of Ge(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=B(),a=[],o=0;for(let e of t){if(e.dropped||e.signature===null||e.signature===void 0||!Z(e.name))continue;let t=n.get(Ue(e));if(t===void 0)continue;let s=qe(e.name),c=We(s),l=Ge(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)He(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&&He(n,e,i,c,s,a)}}}let s=U(a);return{matched:s.pairs.map(({base:e,head:t})=>({base:e,head:t,rationale:`name-signature`})),remainingBase:G(e,s.baseIds),remainingHead:G(t,s.headIds)}}function He(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*V(e.signature??null,t.signature??null)+.2*Ke;s>=i&&a.push({base:e,head:t,score:s})}function Ue(e){let t=e.signature===null||e.signature===void 0?`no-sig`:`has-sig`;return`${e.kind}::${t}`}function We(e){return 2*(e-.5)}function Ge(e){let t=E(M(e));return t.length===0?[` none`]:t}const Ke=1;function qe(e){let t=E(M(e)).length;return t<=1?1:t===2?.95:.85}function Z(e){return O(e)>1}function Je(e,t){let n=e.filter(e=>e.dropped),r=t.filter(e=>e.dropped),i=[];for(let e of[$e,et])i.push(...Ze(n,r,e));let a=Ye(i);return{matched:a.map(({base:e,head:t})=>({base:e,head:t,rationale:`dropped-weak-match`})),remainingBase:G(e,new Set(a.map(e=>e.base.id))),remainingHead:G(t,new Set(a.map(e=>e.head.id)))}}function Ye(e){let t=[...e].sort(W),n=new Map,r=new Map;for(let[e,i]of t.entries())Xe(n,i.base.id,e),Xe(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 Xe(e,t,n){let r=e.get(t);r===void 0?e.set(t,[n]):r.push(n)}function Ze(e,t,n){let r=Qe(e,n),i=Qe(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 Qe(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 $e(e){return`${e.kind}/${M(e.name)}`}function et(e){return`${e.kind}/${tt(e.source.file)}`}function tt(e){let t=e.lastIndexOf(`/`);return t>=0?e.slice(t+1):e}function nt(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 rt(e){return e.dropped?`to-dropped`:`to-kept`}function Q(e){return e.status===`added`||e.status===`removed`||e.status===`unknown`?e.symbol:e.after}function it(e){let t=ft(e.changes);if(t.length===0)return[];let n=new Set(t);return o(t,mt(e.baseCallEdges,e.headCallEdges,n),e=>e).map(ot)}function at(e){return`slice:${e}`}function ot(e){let t=e[0];if(t===void 0)throw new f(`computeSlices: the clustering utility returned an empty component; every weakly-connected component contains at least the node that seeded it (slice-view.md).`,{code:`slice-invariant-violated`});let n={id:at(t),members:[...e]};return dt(n),n}function st(e){let t=e.members[0];if(t===void 0){let t=ut(e.id);throw new f(t.message,{code:`slice-invariant-violated`,value:t.subject})}return t}function ct(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 ut(r);let a=lt(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, slice-view.md).`};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 for the order and uniqueness).`}}let o=at(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).`}}function lt(e){let n=e.indexOf(`:`);if(n<0)return null;let r=e.slice(0,n);return t.has(r)?r:null}function ut(e){return{kind:`members-empty`,subject:e,message:`SliceRecord ${e}: members[] is empty, so the Slice has no anchor (slice-view.md requires at least one member).`}}function dt(e){let t=ct(e);if(t!==null)throw new f(t.message,{code:`slice-invariant-violated`,value:t.subject})}function ft(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(Q(n).id);break;case`moved`:break;default:return pt(n)}return t}function pt(e){throw Error(`computeSlices: unhandled SymbolChange status ${JSON.stringify(e)}; every status has to declare whether it is a Slice Node (slice-view.md).`)}function mt(e,t,n){let r=[];for(let t of e)ht(t,n,r);for(let e of t)ht(e,n,r);return r}function ht(e,t,n){!t.has(e.from)||!t.has(e.to)||n.push([e.from,e.to])}const gt={name:`aburi`,version:`0.0.0`};function _t(e){xt(e.baseIR,`baseIR`),xt(e.headIR,`headIR`),yt(e.baseIR,e.headIR);let t=K(e.baseIR.symbols,e.headIR.symbols),n=q(t.remainingBase,t.remainingHead,e.gitRenames??null),r=J(n.remainingBase,n.remainingHead),i=X(r.remainingBase,r.remainingHead),a=Je(i.remainingBase,i.remainingHead),o=[...t.matched,...n.matched,...r.matched,...i.matched,...a.matched],s={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},l=0,u=[];for(let t of o){let n=nt(t.base,t.head);if(n===`unchanged`){s.unchanged++;continue}if(n===`dropped-toggled`){s.droppedToggled++,u.push({status:`dropped-toggled`,before:t.base,after:t.head,direction:rt(t.head)});continue}if(n===`moved`){s.moved++,u.push({status:`moved`,before:t.base,after:t.head,rationale:t.rationale});continue}if(n===`changed`){s.changed++,u.push({status:`changed`,before:t.base,after:t.head,delta:S(t.base,t.head,e.delta??{})});continue}s.movedChanged++,u.push({status:`moved+changed`,before:t.base,after:t.head,rationale:t.rationale,delta:S(t.base,t.head,e.delta??{})})}let d=h(e.baseIR),f=h(e.headIR),p=f.lostFiles,g=d.lostFiles;for(let e of a.remainingHead){if(e.dropped){s.droppedAdded++;continue}let t=g.get(e.source.file);if(t!==void 0){l++,u.push({status:`unknown`,symbol:e,absentFrom:`base`,reason:t});continue}s.added++,u.push({status:`added`,symbol:e})}for(let e of a.remainingBase){if(e.dropped){s.droppedRemoved++;continue}let t=p.get(e.source.file);if(t!==void 0){l++,u.push({status:`unknown`,symbol:e,absentFrom:`head`,reason:t});continue}s.removed++,u.push({status:`removed`,symbol:e})}let _=m(e.baseIR.components,e.headIR.components);s.componentsAdded=_.added.length,s.componentsRemoved=_.removed.length,s.componentsChanged=_.changed.length;let v=ee(e.baseIR.dependencies,e.headIR.dependencies,{base:d,head:f});s.depsAdded=v.added.length,s.depsRemoved=v.removed.length,s.depsUnknown=v.unknown.length,s.unknown=l,u.sort(wt);let y=it({changes:u,baseCallEdges:c(e.baseIR),headCallEdges:c(e.headIR)});return{$schema:`https://aburi.kage1020.com/schema/aburi.diff.v1.json`,generator:e.generator??gt,base:e.base,head:e.head,summary:s,symbols:u,components:_,dependencies:v,slices:y,notCompared:vt(g,p)}}function vt(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(i(e=>e.path))}function yt(e,t){if(e.$schema!==t.$schema)throw new f(`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 $=e=>e.join(``),bt=[{field:`symbols`,identities:e=>e.symbols.map(e=>[e.id]),keyOf:$,noun:`id`,show:$,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 #1)`},{field:`components`,identities:e=>e.components.map(e=>[e.id]),keyOf:$,noun:`id`,show:$,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 #2)`},{field:`dependencies`,identities:e=>e.dependencies.map(e=>_.map(t=>e[t])),keyOf:v,noun:`(from, to, via) triple`,show:e=>`(${e.join(`, `)})`,consequence:`direction and effect are deliberately outside Dependency identity (diff-algorithm.md), so a repeat surfaces as an added + removed pair no reader can tell from a real flip (ir-schema.md #13)`}];function xt(e,t){let n=r(e),i=n[0];if(i!==void 0){let e=St(t,i.subject),r=n.length-1,a=r>0?` (and ${r} more)`:``;throw new f(`${e}: ${i.message}${a}.`,{code:`ir-shape-invalid`,value:e,violations:n.map(e=>({...e,subject:St(t,e.subject)}))})}if(e.$schema.length===0)throw new f(`${t}: "$schema" is empty, not a schema URL.`,{code:`ir-shape-invalid`,value:t});for(let n of bt)Ct(n.identities(e),`${t}.${n.field}`,n)}function St(t,n){return n===e?t:`${t}.${n}`}function Ct(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 f(`${t}[${i}] repeats the ${n.noun} "${s}" first seen at index ${o}; ${n.consequence}.`,{code:`ir-identity-collision`,value:s})}}function wt(e,t){return a(e.status,t.status)||a(Q(e).id,Q(t).id)}function Tt(e,t={}){return l(e,t)}export{ie as DEFAULT_LINE_FUZZ,f as DiffError,ae as MAX_LINE_FUZZ,oe as MIN_LINE_FUZZ,dt as assertSliceRecordInvariant,_t as buildDiff,nt as classifyStatus,it as computeSlices,S as computeSymbolDelta,h as dependencySideView,m as diffComponents,ee as diffDependencies,rt as dropDirection,k as jaccard,ke as jaccardTokens,M as lastSegment,Je as matchStageDroppedWeak,q as matchStageGitRename,K as matchStageId,J as matchStageLogicFingerprint,X as matchStageNameSignature,je as memberSimilarity,O as nameEvidence,Ae as nameSimilarity,Me as ownersAreCompatible,V as signatureSimilarity,st as sliceAnchor,ct as sliceRecordViolation,E as tokenizeName,Tt 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.5.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,8 +32,8 @@
32
32
  "access": "public"
33
33
  },
34
34
  "dependencies": {
35
- "@aburi/core": "0.5.0",
36
- "@aburi/types": "0.5.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",
@@ -41,7 +41,8 @@
41
41
  "tsdown": "^0.22.3",
42
42
  "typescript": "^6.0.3",
43
43
  "vitest": "^4.1.11",
44
- "@aburi/test-support": "0.0.1"
44
+ "@aburi/schema": "0.0.0",
45
+ "@aburi/test-support": "0.0.2"
45
46
  },
46
47
  "scripts": {
47
48
  "build": "tsdown",