@aburi/diff 0.1.0 → 0.3.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/LICENSE +202 -0
- package/README.md +4 -4
- package/dist/index.d.mts +294 -42
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1408 -269
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -4
- package/src/components.ts +166 -13
- package/src/delta.ts +129 -30
- package/src/diff.ts +295 -38
- package/src/errors.ts +16 -0
- package/src/index.ts +13 -1
- package/src/match.ts +634 -175
- package/src/similarity.ts +299 -19
- package/src/slice.ts +327 -0
- package/src/status.ts +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,22 +1,87 @@
|
|
|
1
|
-
import { SerializeOptions } from "@aburi/core";
|
|
2
|
-
import { Component, ComponentDiff, Dependency, DependencyDiff, DiffResult, IR, IRRef, MatchRationale, Signature, Symbol, SymbolDelta } from "@aburi/types";
|
|
1
|
+
import { CallEdge, 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";
|
|
3
3
|
|
|
4
4
|
//#region src/components.d.ts
|
|
5
5
|
/**
|
|
6
|
-
* §6.1 — Component diff.
|
|
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
|
|
7
12
|
* base and head with the same id, the three delta booleans describe which axes actually
|
|
8
13
|
* moved (roots reshuffle, public API globs, or framework hint list). `modified` deltas
|
|
9
|
-
* are intentionally absent from this diff (§5.2.3): fields are reported as before/after
|
|
14
|
+
* are intentionally absent from this diff (diff-algorithm.md §5.2.3): fields are reported as before/after
|
|
10
15
|
* pairs via the `changed[]` entries so consumers can render them without stringifying
|
|
11
16
|
* arrays.
|
|
12
17
|
*/
|
|
13
18
|
declare function diffComponents(base: readonly Component[], head: readonly Component[]): ComponentDiff;
|
|
14
19
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
20
|
+
* What one document knows about itself, for deciding whether the *other* document's silence
|
|
21
|
+
* about an edge is evidence.
|
|
22
|
+
*
|
|
23
|
+
* `symbolFiles` is keyed on the endpoint id exactly as `dependencies[]` spells it, and its
|
|
24
|
+
* values come from `symbols[].source.file` — the same space `stats.skippedFiles[].path` is in,
|
|
25
|
+
* and the same space `buildDiff` classifies Symbols by. Reading the file out of the id's path
|
|
26
|
+
* segment instead would introduce a second answer to "which file is this endpoint in", and
|
|
27
|
+
* nothing in the schema forces the two to agree; a Symbol reported `unknown` while its edges
|
|
28
|
+
* stayed `removed` is precisely the inconsistency this exists to remove.
|
|
29
|
+
*
|
|
30
|
+
* A Component endpoint is absent from the map, which is how it stays out of the reclassification
|
|
31
|
+
* without a special case: a Component is an aggregate over roots and has no file to lose.
|
|
32
|
+
*/
|
|
33
|
+
interface DependencySideView {
|
|
34
|
+
/**
|
|
35
|
+
* `source.file` of every Symbol this document holds, by the id an endpoint would name it
|
|
36
|
+
* with. Keyed by `DependencyEndpoint` rather than `SymbolId` because that is the question
|
|
37
|
+
* being asked: the lookup happens with an endpoint whose kind is not yet known, and "absent"
|
|
38
|
+
* is the answer for a Component id. Demanding the kind up front would move that decision to
|
|
39
|
+
* the caller, where it would need a second Symbol-id silhouette test to make.
|
|
40
|
+
*/
|
|
41
|
+
symbolFiles: ReadonlyMap<DependencyEndpoint, RelativePath>;
|
|
42
|
+
/**
|
|
43
|
+
* Files this document never analysed, by path, with the reason it gave. `RelativePath` on
|
|
44
|
+
* both sides of the file space is what states the bridge these two maps exist to make — one
|
|
45
|
+
* map's values are the other's keys — though the alias is unbranded, so it is intent rather
|
|
46
|
+
* than enforcement.
|
|
47
|
+
*/
|
|
48
|
+
lostFiles: ReadonlyMap<RelativePath, SkipReason>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Build a side view from a document. The only construction site there is.
|
|
52
|
+
*
|
|
53
|
+
* `buildDiff` reads `lostFiles` for its own Symbol classification too, from this same object,
|
|
54
|
+
* so "a Symbol reported unknown and the edges it took with it cannot disagree about which file
|
|
55
|
+
* went missing" is a property of the wiring rather than a claim in a comment.
|
|
56
|
+
*
|
|
57
|
+
* Exported because `DependencySideView` is public and `diffDependencies` requires one: without
|
|
58
|
+
* a factory a caller would have to reproduce the `symbols[].source.file` keying and the
|
|
59
|
+
* `stats.skippedFiles` read, and the likeliest outcome of that is a caller who gets it wrong.
|
|
60
|
+
*/
|
|
61
|
+
declare function dependencySideView(ir: IR): DependencySideView;
|
|
62
|
+
/**
|
|
63
|
+
* `docs/design/diff-algorithm.md` §6.2 — Dependency diff. Identity is the composite
|
|
64
|
+
* `(from, to, via)` triple; direction and effect changes are surfaced as an added + removed
|
|
65
|
+
* pair so `modified` is not part of the schema (§6.2 tail). Uniqueness of that triple is the caller's obligation on the same
|
|
66
|
+
* terms as `diffComponents` above — a repeat here is indistinguishable in the output from
|
|
67
|
+
* the flip it encodes.
|
|
68
|
+
*
|
|
69
|
+
* `sides` is what separates a deletion from a loss (`docs/design/diff-algorithm.md` §6.2.1).
|
|
70
|
+
* It is required rather than optional: omitting it would classify every edge into a lost file
|
|
71
|
+
* as a deletion again — silently, and while still writing `unknown: []`, which this schema
|
|
72
|
+
* defines as "nothing was unknown" rather than "nobody looked". A caller with no skip list to
|
|
73
|
+
* offer says so by passing a side view whose `lostFiles` is empty, which is the honest spelling
|
|
74
|
+
* of an IR written before `stats.skippedFiles` existed.
|
|
75
|
+
*
|
|
76
|
+
* The return type declares `unknown` present, where the schema leaves it optional for documents
|
|
77
|
+
* that predate the field. A reader may find it missing; this function always writes it.
|
|
18
78
|
*/
|
|
19
|
-
declare function diffDependencies(base: readonly Dependency[], head: readonly Dependency[]
|
|
79
|
+
declare function diffDependencies(base: readonly Dependency[], head: readonly Dependency[], sides: {
|
|
80
|
+
base: DependencySideView;
|
|
81
|
+
head: DependencySideView;
|
|
82
|
+
}): DependencyDiff & {
|
|
83
|
+
unknown: DependencyUnknown[];
|
|
84
|
+
};
|
|
20
85
|
//#endregion
|
|
21
86
|
//#region src/delta.d.ts
|
|
22
87
|
declare const DEFAULT_LINE_FUZZ = 2;
|
|
@@ -55,6 +120,13 @@ type GitRenameMap = ReadonlyMap<string, string>;
|
|
|
55
120
|
/**
|
|
56
121
|
* §3.1 — segments Symbols with identical `id` into paired matches. Runs first because it
|
|
57
122
|
* is the highest-confidence signal (no heuristics, just hash lookup).
|
|
123
|
+
*
|
|
124
|
+
* Assumes `id` is unique on each side (ir-schema.md §14 #1) and does not check it:
|
|
125
|
+
* `buildDiff` establishes that before calling, and a caller reaching this export directly
|
|
126
|
+
* owns the obligation. A repeat on the head side loses all but the last entry to the lookup
|
|
127
|
+
* map and then removes every one of them from `remainingHead`; a repeat on the base side
|
|
128
|
+
* pairs the same head Symbol more than once. The later stages track consumed base Symbols
|
|
129
|
+
* by id and lose a repeat the same way.
|
|
58
130
|
*/
|
|
59
131
|
declare function matchStageId(base: readonly Symbol[], head: readonly Symbol[]): {
|
|
60
132
|
matched: SymbolPair[];
|
|
@@ -63,7 +135,9 @@ declare function matchStageId(base: readonly Symbol[], head: readonly Symbol[]):
|
|
|
63
135
|
};
|
|
64
136
|
/**
|
|
65
137
|
* §3.2 — git rename detection. When a rename map is available (typical of ref-driven
|
|
66
|
-
* scans), rewrite the base id with the head-side file path and look for a hit.
|
|
138
|
+
* scans), rewrite the base id with the head-side file path and look for a hit. Two base
|
|
139
|
+
* files renamed onto one target predict the same head id, so the claimants are collected
|
|
140
|
+
* before one is chosen.
|
|
67
141
|
*
|
|
68
142
|
* The rewriter only touches the `file` portion of the id — the `<language>:` prefix and
|
|
69
143
|
* the trailing `#<qualified-name>` segment stay unchanged so a moved file with the same
|
|
@@ -76,11 +150,10 @@ declare function matchStageGitRename(remainingBase: readonly Symbol[], remaining
|
|
|
76
150
|
remainingHead: Symbol[];
|
|
77
151
|
};
|
|
78
152
|
/**
|
|
79
|
-
* §3.3 — group
|
|
80
|
-
*
|
|
81
|
-
* -
|
|
82
|
-
*
|
|
83
|
-
* sides in remaining for stage 4 to re-evaluate
|
|
153
|
+
* §3.3 — group both sides by `fingerprint.logic` and pair within each group. Two branches:
|
|
154
|
+
* - single base candidate → paired with `logic-fingerprint`, no similarity test
|
|
155
|
+
* - several → `nameSimilarity` disambiguates at ≥ 0.85; a group that cannot reach it is left
|
|
156
|
+
* whole for stage 4 to re-evaluate
|
|
84
157
|
*
|
|
85
158
|
* Dropped symbols are excluded (§3.3 tail) — their logic fingerprint is the sentinel
|
|
86
159
|
* `"000000000000"` and would collide with every other dropped Symbol in the workspace.
|
|
@@ -96,17 +169,35 @@ declare function matchStageLogicFingerprint(remainingBase: readonly Symbol[], re
|
|
|
96
169
|
* `signatureNullness` distinguishes symbols with no signature (`interface`, `type`,
|
|
97
170
|
* `class`) from callable ones so that a class body is never paired against a function.
|
|
98
171
|
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
172
|
+
* §3.4.6's owner gate runs before the score: a pair whose owners are not the same class, or
|
|
173
|
+
* one a rename of the other, is not the same Symbol however well the rest agrees, and no
|
|
174
|
+
* weight small enough to leave the name axis meaning something can outvote a matching member
|
|
175
|
+
* name and signature.
|
|
176
|
+
*
|
|
177
|
+
* The composite score, over the pairs that clear it:
|
|
178
|
+
* 0.5 * memberSimilarity + 0.3 * signatureSimilarity + 0.2 * OWNER_AXIS_SATISFIED
|
|
179
|
+
*
|
|
180
|
+
* `memberSimilarity` reads the last segment, not the whole qualified name: the gate has
|
|
181
|
+
* already settled the owner, and reading it again on the name axis charges for it twice —
|
|
182
|
+
* which is what kept a renamed class from ever pairing (§3.4.6).
|
|
101
183
|
*
|
|
102
|
-
* §3.4.3 threshold table:
|
|
103
|
-
* - 1
|
|
104
|
-
* - 2
|
|
105
|
-
* - default
|
|
184
|
+
* §3.4.3 threshold table, applied per head by the token count of its last name segment:
|
|
185
|
+
* - 1 token → 1.0 (an exact match on both remaining axes)
|
|
186
|
+
* - 2 tokens → 0.95 (strict, avoids `getUser` vs `getUsers`)
|
|
187
|
+
* - default → 0.85
|
|
106
188
|
*
|
|
107
|
-
* §3.4.3
|
|
108
|
-
*
|
|
109
|
-
*
|
|
189
|
+
* §3.4.3 also names two Symbols the stage does not read at all, because for them the score is
|
|
190
|
+
* high on evidence it does not have rather than on a resemblance: one whose signature is
|
|
191
|
+
* null, since `signatureSimilarity(null, null)` is 1.0 and the bucket key restricts it to
|
|
192
|
+
* candidates that are equally signature-less; and one whose qualified name carries a single
|
|
193
|
+
* distinct token, since that is the whole of what its identity amounts to. Neither can be
|
|
194
|
+
* expressed as a threshold — the second wants a bar above the top of the scale.
|
|
195
|
+
*
|
|
196
|
+
* Every pairing in a bucket that clears its head’s threshold becomes a candidate, and the
|
|
197
|
+
* candidates are settled in score order rather than one head at a time — see
|
|
198
|
+
* `acceptInScoreOrder`. That doubles the pairings scored, from a bucket that shrank as heads
|
|
199
|
+
* consumed it to the full bucket every time; `createNameScorer` more than pays for it by
|
|
200
|
+
* tokenising each distinct name once per pass instead of once per comparison.
|
|
110
201
|
*/
|
|
111
202
|
declare function matchStageNameSignature(remainingBase: readonly Symbol[], remainingHead: readonly Symbol[]): {
|
|
112
203
|
matched: SymbolPair[];
|
|
@@ -114,13 +205,32 @@ declare function matchStageNameSignature(remainingBase: readonly Symbol[], remai
|
|
|
114
205
|
remainingHead: Symbol[];
|
|
115
206
|
};
|
|
116
207
|
/**
|
|
117
|
-
* §3.4.5 — dropped-only weak matcher. For dropped Symbols the fingerprint is zeroed
|
|
118
|
-
*
|
|
119
|
-
*
|
|
208
|
+
* §3.4.5 — dropped-only weak matcher. For dropped Symbols the fingerprint is zeroed, so the
|
|
209
|
+
* only signals left are the trailing segment of the qualified name and the file basename.
|
|
210
|
+
* Either one alone is enough to pair, which is deliberately lax: §3.4.5 accepts a
|
|
211
|
+
* false-positive risk because dropped Symbols sit outside the IR's main review surface.
|
|
212
|
+
*
|
|
213
|
+
* What it does not accept is a signal that identifies nothing. A basename hit on `index.ts`
|
|
214
|
+
* — the most common filename in a TypeScript monorepo — paired every dropped Symbol of one
|
|
215
|
+
* kind under one with every other, at a score they all tied on, and the results landed in
|
|
216
|
+
* `summary.moved`, which `--fail-on moved` gates on. So a half counts only when exactly one
|
|
217
|
+
* dropped base and one dropped head carry that key: such a key names a pair, where a key
|
|
218
|
+
* several Symbols carry names a group, and a group is not a pairing.
|
|
219
|
+
*
|
|
220
|
+
* That makes the candidates the identifying keys themselves — at most one pairing each,
|
|
221
|
+
* two axes, so at most `2 × min(base, head)` of them rather than the cross-product a shared
|
|
222
|
+
* basename used to produce.
|
|
223
|
+
*
|
|
224
|
+
* "Exactly one" is counted over the Symbols this stage is handed, not over every dropped
|
|
225
|
+
* Symbol in the Document — stages 1 and 2 have already taken theirs, and a key they emptied
|
|
226
|
+
* out identifies again. That is the intended reading, since the question is which leftover a
|
|
227
|
+
* key picks out, but it is also how a shared `index.ts` comes back: three dropped classes
|
|
228
|
+
* under one, two of them matched by id, and the basename identifies the two that are left.
|
|
120
229
|
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
230
|
+
* It also leaves nothing for §3.4.5's 0.5-per-half scale to rank, so §3.8's sweep is the
|
|
231
|
+
* wrong instrument: it settles conflicts by score, and with none to settle by it would drop
|
|
232
|
+
* one identified pairing for another over nothing but the id it sorts under. `bestPairing`
|
|
233
|
+
* takes a maximum matching instead.
|
|
124
234
|
*/
|
|
125
235
|
declare function matchStageDroppedWeak(remainingBase: readonly Symbol[], remainingHead: readonly Symbol[]): {
|
|
126
236
|
matched: SymbolPair[];
|
|
@@ -129,6 +239,18 @@ declare function matchStageDroppedWeak(remainingBase: readonly Symbol[], remaini
|
|
|
129
239
|
};
|
|
130
240
|
//#endregion
|
|
131
241
|
//#region src/diff.d.ts
|
|
242
|
+
/**
|
|
243
|
+
* The two counters `buildDiff` always writes, narrowed off `Summary`'s optionals.
|
|
244
|
+
*
|
|
245
|
+
* They are optional on the wire so a diff written before they existed stays valid, and that
|
|
246
|
+
* optionality is about *documents*, not about this function — a caller holding a value it just
|
|
247
|
+
* built should not have to re-decide what "absent" would have meant. Same reason
|
|
248
|
+
* `diffDependencies` declares its `unknown` array present.
|
|
249
|
+
*/
|
|
250
|
+
interface UnknownCounters {
|
|
251
|
+
unknown: number;
|
|
252
|
+
depsUnknown: number;
|
|
253
|
+
}
|
|
132
254
|
interface DiffInput {
|
|
133
255
|
baseIR: IR;
|
|
134
256
|
headIR: IR;
|
|
@@ -152,7 +274,19 @@ interface DiffInput {
|
|
|
152
274
|
* pipe the result through additional steps (Markdown projection, `--fail-on` gate) before
|
|
153
275
|
* serialisation.
|
|
154
276
|
*/
|
|
155
|
-
declare function buildDiff(input: DiffInput): DiffResult
|
|
277
|
+
declare function buildDiff(input: DiffInput): DiffResult & {
|
|
278
|
+
notCompared: NotComparedFile[];
|
|
279
|
+
summary: Summary & UnknownCounters;
|
|
280
|
+
};
|
|
281
|
+
/**
|
|
282
|
+
* The files a document's scan never analysed, by path, with why.
|
|
283
|
+
*
|
|
284
|
+
* `stats.skippedFiles` is Class B: absent means the writer predates the field, not that
|
|
285
|
+
* nothing was lost. An empty map is the honest answer either way — with no enumeration
|
|
286
|
+
* there is no absence this function can explain, and guessing from
|
|
287
|
+
* `totalFiles > parsedFiles` would attach a reason to whichever Symbols happened to be
|
|
288
|
+
* missing. The CLI says so on stderr instead; a diff cannot invent the list.
|
|
289
|
+
*/
|
|
156
290
|
/**
|
|
157
291
|
* Byte-deterministic serialiser for a DiffResult. Delegates to `@aburi/core`
|
|
158
292
|
* `serializeCanonical` so the sort order, NFC normalisation, and codepoint key sort are
|
|
@@ -172,7 +306,23 @@ type DiffErrorCode = /** `base.$schema` and `head.$schema` disagree; a diff acro
|
|
|
172
306
|
* `dependencies`, or an absent `$schema` — anything that would otherwise crash with a
|
|
173
307
|
* cryptic `TypeError: undefined is not iterable` deep in a matching stage.
|
|
174
308
|
*/
|
|
175
|
-
| "ir-shape-invalid"
|
|
309
|
+
| "ir-shape-invalid"
|
|
310
|
+
/**
|
|
311
|
+
* `baseIR` or `headIR` repeats an identity the diff keys on: a `symbols[].id`, a
|
|
312
|
+
* `components[].id`, or a `dependencies[]` `(from, to, via)` triple. Distinct from
|
|
313
|
+
* `ir-shape-invalid` because the Document is well-formed — the collision changes the
|
|
314
|
+
* answer rather than preventing one, and ir-schema.md §14 #1 / #2 / #13 already forbid it.
|
|
315
|
+
*/
|
|
316
|
+
| "ir-identity-collision"
|
|
317
|
+
/**
|
|
318
|
+
* A `SliceRecord` broke the derivation invariant of slice-view.md §7.1 / §8.2:
|
|
319
|
+
* `members[]` empty, `members[]` not in strictly ascending order, or `id` not
|
|
320
|
+
* equal to `"slice:" + members[0]`. The last two compare one property against
|
|
321
|
+
* another and so have no JSON Schema equivalent; the pass checks them itself
|
|
322
|
+
* (§7.4). Raised only by an Aburi bug, never by user input — see
|
|
323
|
+
* `SliceRecordViolation.kind` for which clause broke.
|
|
324
|
+
*/
|
|
325
|
+
| "slice-invariant-violated";
|
|
176
326
|
interface DiffErrorDetail {
|
|
177
327
|
code: DiffErrorCode;
|
|
178
328
|
/** Offending value (schema id, fuzz value, etc.) when applicable. */
|
|
@@ -220,6 +370,15 @@ declare function signatureSimilarity(base: Signature | null | undefined, head: S
|
|
|
220
370
|
* The result is de-duplicated so `InvoiceService.createInvoice` collapses to
|
|
221
371
|
* `["invoice", "service", "create"]` — Jaccard similarity relies on set semantics, so
|
|
222
372
|
* repeated tokens must not double-count.
|
|
373
|
+
*
|
|
374
|
+
* **The camel boundary is ASCII.** `isCamelBoundary` compares code points against `a`–`z`,
|
|
375
|
+
* `A`–`Z` and `0`–`9`, so a name written in a script with no ASCII case boundary and no
|
|
376
|
+
* separator comes back whole: `获取用户信息` and `ユーザー情報を取得する` are one token each,
|
|
377
|
+
* and so is `получитьПользователя` — its camel hump does not register. A separator still
|
|
378
|
+
* splits (`ユーザー.取得` gives two), and a mixed name splits on its ASCII half.
|
|
379
|
+
*
|
|
380
|
+
* That makes the token count a poor measure of how much such a name says, which matters
|
|
381
|
+
* wherever a count is read as a proxy for that — see §3.4.3's admissibility rule.
|
|
223
382
|
*/
|
|
224
383
|
declare function tokenizeName(input: string): string[];
|
|
225
384
|
/**
|
|
@@ -228,7 +387,11 @@ declare function tokenizeName(input: string): string[];
|
|
|
228
387
|
* purpose of §3.4.1). Empty on one side only returns 0.0.
|
|
229
388
|
*/
|
|
230
389
|
declare function jaccard(a: readonly string[], b: readonly string[]): number;
|
|
231
|
-
/**
|
|
390
|
+
/**
|
|
391
|
+
* Jaccard over the tokens of two strings. Part of the module's surface rather than an
|
|
392
|
+
* internal shortcut: the two formulas below go through a token table they share for one
|
|
393
|
+
* matching pass, so this has no caller inside this file.
|
|
394
|
+
*/
|
|
232
395
|
declare function jaccardTokens(a: string, b: string): number;
|
|
233
396
|
/**
|
|
234
397
|
* §3.4.1 — Jaccard over the tokens of the full qualified name. The last segment is not
|
|
@@ -237,23 +400,112 @@ declare function jaccardTokens(a: string, b: string): number;
|
|
|
237
400
|
*/
|
|
238
401
|
declare function nameSimilarity(baseName: string, headName: string): number;
|
|
239
402
|
/**
|
|
240
|
-
* §3.4.
|
|
241
|
-
*
|
|
242
|
-
*
|
|
403
|
+
* §3.4.1 — Jaccard over the tokens of the **last segment**: the member name with its owner
|
|
404
|
+
* removed. What §3.4's composite reads, because §3.4.6 decides the owner separately and
|
|
405
|
+
* reading it on both axes charges for it twice.
|
|
406
|
+
*/
|
|
407
|
+
declare function memberSimilarity(baseName: string, headName: string): number;
|
|
408
|
+
/**
|
|
409
|
+
* §3.4.6 (R-8) — whether two Symbols are close enough in *scope* to be the same Symbol: the
|
|
410
|
+
* same owner, or one whose owner was renamed. A gate rather than a score, because grading the
|
|
411
|
+
* owner cannot do what R-8 asks. `UserRepo.findById` and `AdminRepo.findById` agree on their
|
|
412
|
+
* member name and their signature, so a shared `Repo` token at weight 0.2 carries them to
|
|
413
|
+
* 0.8667 against a 0.85 threshold — while `UsersRepository.findById`, which *is* the rename,
|
|
414
|
+
* shares no owner token and scores 0.8000. The collision outscores the rename, and raising the
|
|
415
|
+
* weight only moves both: at 0.3 two three-token class names sharing two tokens land on
|
|
416
|
+
* exactly 0.85.
|
|
243
417
|
*
|
|
244
418
|
* Owner extraction:
|
|
245
419
|
* - `Class::method` → `Class`
|
|
246
420
|
* - `A.B.C.method` → `A.B.C`
|
|
247
421
|
* - `topLevel` → `` (empty)
|
|
248
422
|
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
423
|
+
* Two empty owners are compatible: top-level Symbols share the one outer scope. One empty and
|
|
424
|
+
* one not are never compatible — the two live at different depths.
|
|
425
|
+
*
|
|
426
|
+
* Otherwise the owners must correspond segment for segment, and within a segment every token
|
|
427
|
+
* on each side must find a distinct partner on the other under `sameWord`. Both sides must be
|
|
428
|
+
* covered, so `UserRepo` and `UserRepoV2` are two classes rather than one renamed — an added
|
|
429
|
+
* token is as much evidence of a sibling as of a rename, and R-8's business is refusing the
|
|
430
|
+
* collision.
|
|
252
431
|
*/
|
|
253
|
-
declare function
|
|
432
|
+
declare function ownersAreCompatible(baseName: string, headName: string): boolean;
|
|
254
433
|
/** §3.4.1 tail note — used by drop-4.5 weak matcher and threshold lookup. */
|
|
255
434
|
declare function lastSegment(qname: string): string;
|
|
256
435
|
//#endregion
|
|
436
|
+
//#region src/slice.d.ts
|
|
437
|
+
/** The three inputs of the Slice View pass — docs/design/slice-view.md §3. */
|
|
438
|
+
interface SliceInput {
|
|
439
|
+
/** SymbolChange records produced by `buildDiff` (pre-sort is not required). */
|
|
440
|
+
changes: readonly SymbolChange[];
|
|
441
|
+
/**
|
|
442
|
+
* Resolved call edges from the base IR. Typically produced by
|
|
443
|
+
* `reconstructCallEdgesFromIR(baseIR)` inside `buildDiff` — Slice View
|
|
444
|
+
* consumes only resolved edges (§5.4), never `Symbol.calls[]` directly.
|
|
445
|
+
*/
|
|
446
|
+
baseCallEdges: readonly CallEdge[];
|
|
447
|
+
/** Resolved call edges from the head IR (same source rule as base). */
|
|
448
|
+
headCallEdges: readonly CallEdge[];
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Slice View clustering pass — docs/design/slice-view.md §2, §4–§8.
|
|
452
|
+
*
|
|
453
|
+
* Groups the changed-Symbol set of a diff into weakly-connected components
|
|
454
|
+
* over the union of base and head call edges. Emits a `SliceRecord[]` whose
|
|
455
|
+
* cluster ids are `"slice:" + <smallest-member Symbol id>`, both `slices[]`
|
|
456
|
+
* and each `members[]` sorted ascending.
|
|
457
|
+
*
|
|
458
|
+
* Pure function: `(changes, baseCallEdges, headCallEdges)` → `SliceRecord[]`.
|
|
459
|
+
* Determinism, idempotence, input-order insensitivity, and locality are all
|
|
460
|
+
* guaranteed — see `computeWeaklyConnectedComponents` in `@aburi/core`.
|
|
461
|
+
*
|
|
462
|
+
* Returns `[]` when no SymbolChange is Node-eligible per §4.1; callers should
|
|
463
|
+
* still serialise the empty array — the Markdown projection omits the section
|
|
464
|
+
* (§9.4 / §12.5) but the JSON always emits the key so consumers never
|
|
465
|
+
* distinguish "field absent" from "no slices" (§11.2).
|
|
466
|
+
*
|
|
467
|
+
* Every returned record has passed `assertSliceRecordInvariant` (§7.4).
|
|
468
|
+
*/
|
|
469
|
+
declare function computeSlices(input: SliceInput): SliceRecord[];
|
|
470
|
+
/**
|
|
471
|
+
* §7.1 — the anchor of a Slice: its lexicographically smallest member.
|
|
472
|
+
*
|
|
473
|
+
* Answers from `members[0]`. `id` is derived from the anchor, so
|
|
474
|
+
* reconstructing the anchor by stripping the `"slice:"` prefix is circular at
|
|
475
|
+
* best and, for a record that broke the derivation, silently wrong: it would
|
|
476
|
+
* name a Symbol that is not in the Slice. `id` is read here only to name the
|
|
477
|
+
* offending record in the error message. Consumers that need the anchor call
|
|
478
|
+
* this; consumers that need a label keep using `id` directly.
|
|
479
|
+
*/
|
|
480
|
+
declare function sliceAnchor(record: SliceRecord): SymbolId;
|
|
481
|
+
/** Which clause of the §7.1 / §8.2 invariant a `SliceRecord` broke. */
|
|
482
|
+
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";
|
|
483
|
+
interface SliceRecordViolation {
|
|
484
|
+
kind: SliceViolationKind;
|
|
485
|
+
/** The offending record's `id` when it has a usable one, else a short stand-in. */
|
|
486
|
+
subject: string;
|
|
487
|
+
/** Human-facing explanation, suitable for an error message or a validator error. */
|
|
488
|
+
message: string;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Report which clause of the §7.1 / §8.2 invariant a value breaks, or `null`
|
|
492
|
+
* when it is a well-formed `SliceRecord`. Non-throwing counterpart of
|
|
493
|
+
* `assertSliceRecordInvariant`: the pass wants an exception, a schema
|
|
494
|
+
* validator wants a verdict it can turn into its own error.
|
|
495
|
+
*
|
|
496
|
+
* Takes `unknown` rather than `SliceRecord` deliberately. §7.4 layer 2 points
|
|
497
|
+
* this at documents written by third-party or older producers — data that has
|
|
498
|
+
* not been type-checked by definition — so anything that assumed a well-typed
|
|
499
|
+
* argument would crash on exactly the input it exists to reject.
|
|
500
|
+
*/
|
|
501
|
+
declare function sliceRecordViolation(value: unknown): SliceRecordViolation | null;
|
|
502
|
+
/**
|
|
503
|
+
* Throwing form of `sliceRecordViolation`. Raised as a coded `DiffError` so
|
|
504
|
+
* callers branch on `code` rather than parsing the message; which clause broke
|
|
505
|
+
* is `SliceRecordViolation.kind`, for callers that need to tell them apart.
|
|
506
|
+
*/
|
|
507
|
+
declare function assertSliceRecordInvariant(record: SliceRecord): void;
|
|
508
|
+
//#endregion
|
|
257
509
|
//#region src/status.d.ts
|
|
258
510
|
type SymbolStatus = "unchanged" | "moved" | "changed" | "moved+changed" | "dropped-toggled";
|
|
259
511
|
/**
|
|
@@ -263,8 +515,8 @@ type SymbolStatus = "unchanged" | "moved" | "changed" | "moved+changed" | "dropp
|
|
|
263
515
|
* drop-rule flip, not a genuine code edit (§4.1 rationale).
|
|
264
516
|
*
|
|
265
517
|
* "pathChanged" catches both physical file relocation AND in-file rename: any Symbol id
|
|
266
|
-
* mismatch between base and head means the identifier moved, and DF9 ("method
|
|
267
|
-
* (
|
|
518
|
+
* mismatch between base and head means the identifier moved, and DF9 ("method rename
|
|
519
|
+
* (same file, same logic) → moved") relies on this. Stage-1 pairs cannot trigger the id branch
|
|
268
520
|
* (they match by exact id), so this only affects stage-2+ pairings where the pair was
|
|
269
521
|
* discovered via fingerprint or name/signature similarity.
|
|
270
522
|
*/
|
|
@@ -273,5 +525,5 @@ declare function classifyStatus(base: Symbol, head: Symbol): SymbolStatus;
|
|
|
273
525
|
type DropDirection = "to-dropped" | "to-kept";
|
|
274
526
|
declare function dropDirection(head: Symbol): DropDirection;
|
|
275
527
|
//#endregion
|
|
276
|
-
export { DEFAULT_LINE_FUZZ, type DeltaOptions, DiffError, type DiffErrorCode, type DiffErrorDetail, type DiffInput, type DropDirection, type GitRenameMap, MAX_LINE_FUZZ, MIN_LINE_FUZZ, type SymbolPair, type SymbolStatus, buildDiff, classifyStatus, computeSymbolDelta, diffComponents, diffDependencies, dropDirection, jaccard, jaccardTokens, lastSegment, matchStageDroppedWeak, matchStageGitRename, matchStageId, matchStageLogicFingerprint, matchStageNameSignature, nameSimilarity,
|
|
528
|
+
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 };
|
|
277
529
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/components.ts","../src/delta.ts","../src/match.ts","../src/diff.ts","../src/errors.ts","../src/signature.ts","../src/similarity.ts","../src/status.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/components.ts","../src/delta.ts","../src/match.ts","../src/diff.ts","../src/errors.ts","../src/signature.ts","../src/similarity.ts","../src/slice.ts","../src/status.ts"],"mappings":";;;;;;;AA2BA;;;;;;;;;;iBAAgB,cAAA,CACd,IAAA,WAAe,SAAA,IACf,IAAA,WAAe,SAAA,KACd,aAAA;;;;AAAa;AAqDhB;;;;;;;;;;UAAiB,kBAAA;EAQf;;;;;;;EAAA,WAAA,EAAa,WAAA,CAAY,kBAAA,EAAoB,YAAA;EAOE;AAAA;AAcjD;;;;EAdE,SAAA,EAAW,WAAA,CAAY,YAAA,EAAc,UAAA;AAAA;;;AAcuB;AAyB9D;;;;;;;;iBAzBgB,kBAAA,CAAmB,EAAA,EAAI,EAAA,GAAK,kBAAk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