@plannotator/sem-jiff 0.0.0-stage → 0.2.2

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.
Files changed (70) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/LICENSE-APACHE +191 -0
  3. package/LICENSE-MIT +21 -0
  4. package/README.md +122 -2
  5. package/THIRD-PARTY-NOTICES +367 -0
  6. package/dist/candidate.d.ts +14 -0
  7. package/dist/candidate.js +1 -0
  8. package/dist/classifier.d.ts +25 -0
  9. package/dist/classifier.js +32 -0
  10. package/dist/copy-wasm-bin.d.ts +2 -0
  11. package/dist/copy-wasm-bin.js +11 -0
  12. package/dist/copy-wasm.d.ts +3 -0
  13. package/dist/copy-wasm.js +43 -0
  14. package/dist/coverage.d.ts +7 -0
  15. package/dist/coverage.js +43 -0
  16. package/dist/edits.d.ts +10 -0
  17. package/dist/edits.js +230 -0
  18. package/dist/extract.d.ts +5 -0
  19. package/dist/extract.js +24 -0
  20. package/dist/grammars.d.ts +22 -0
  21. package/dist/grammars.js +37 -0
  22. package/dist/index.d.ts +79 -0
  23. package/dist/index.js +581 -0
  24. package/dist/inline.d.ts +21 -0
  25. package/dist/inline.js +959 -0
  26. package/dist/languages.d.ts +2 -0
  27. package/dist/languages.js +28 -0
  28. package/dist/linediff.d.ts +28 -0
  29. package/dist/linediff.js +205 -0
  30. package/dist/opinions.d.ts +84 -0
  31. package/dist/opinions.js +201 -0
  32. package/dist/pairing.d.ts +10 -0
  33. package/dist/pairing.js +269 -0
  34. package/dist/parse.d.ts +119 -0
  35. package/dist/parse.js +1293 -0
  36. package/dist/pierre-types.d.ts +101 -0
  37. package/dist/pierre-types.js +5 -0
  38. package/dist/runtime.d.ts +48 -0
  39. package/dist/runtime.js +60 -0
  40. package/dist/structure.d.ts +23 -0
  41. package/dist/structure.js +1111 -0
  42. package/dist/summary.d.ts +19 -0
  43. package/dist/summary.js +15 -0
  44. package/dist/symbol-types.d.ts +18 -0
  45. package/dist/symbol-types.js +1 -0
  46. package/dist/symbols.d.ts +6 -0
  47. package/dist/symbols.js +458 -0
  48. package/dist/syntax.d.ts +69 -0
  49. package/dist/syntax.js +450 -0
  50. package/dist/textdiff.d.ts +15 -0
  51. package/dist/textdiff.js +64 -0
  52. package/dist/textmoves.d.ts +8 -0
  53. package/dist/textmoves.js +143 -0
  54. package/package.json +108 -4
  55. package/src/candidate.ts +10 -0
  56. package/src/grammars.ts +44 -0
  57. package/src/opinions.ts +271 -0
  58. package/wasm/SHA256SUMS +12 -0
  59. package/wasm/tree-sitter-c_sharp.wasm +0 -0
  60. package/wasm/tree-sitter-go.wasm +0 -0
  61. package/wasm/tree-sitter-java.wasm +0 -0
  62. package/wasm/tree-sitter-kotlin.wasm +0 -0
  63. package/wasm/tree-sitter-php.wasm +0 -0
  64. package/wasm/tree-sitter-python.wasm +0 -0
  65. package/wasm/tree-sitter-ruby.wasm +0 -0
  66. package/wasm/tree-sitter-rust.wasm +0 -0
  67. package/wasm/tree-sitter-swift.wasm +0 -0
  68. package/wasm/tree-sitter-tsx.wasm +0 -0
  69. package/wasm/tree-sitter-typescript.wasm +0 -0
  70. package/wasm/web-tree-sitter.wasm +0 -0
@@ -0,0 +1,101 @@
1
+ export interface SemanticDiffTextPosition {
2
+ /** Source line number, starting at 1. */
3
+ line: number;
4
+ /** Zero-based UTF-16 code-unit offset within the line; a tab counts as one. */
5
+ character: number;
6
+ }
7
+ export interface SemanticDiffTextRange {
8
+ start: SemanticDiffTextPosition;
9
+ /** Exclusive end position. */
10
+ end: SemanticDiffTextPosition;
11
+ }
12
+ export type SemanticDiffOperationType = 'moved' | 'movedWithEdit' | 'edited' | 'added' | 'deleted' | 'renamed' | 'reordered' | 'reformatted' | 'extractedFunction' | 'inlinedFunction';
13
+ export type SemanticDiffSpanRole = 'root' | 'container' | 'body' | 'call' | 'focus';
14
+ export type SemanticDiffFocusKind = 'reformatted';
15
+ export interface SemanticDiffLineRegion {
16
+ start: number;
17
+ end: number;
18
+ }
19
+ export interface SemanticDiffFoldCounts {
20
+ moved: number;
21
+ edited: number;
22
+ removed: number;
23
+ }
24
+ export interface SemanticDiffFold {
25
+ old: SemanticDiffLineRegion;
26
+ operations: number[];
27
+ counts: SemanticDiffFoldCounts;
28
+ }
29
+ export interface SemanticDiffLinePair {
30
+ old: SemanticDiffLineRegion;
31
+ new: SemanticDiffLineRegion;
32
+ }
33
+ export interface SemanticDiffSpanAnchor {
34
+ relation: 'before' | 'after' | 'inside';
35
+ old?: SemanticDiffTextRange[];
36
+ new?: SemanticDiffTextRange[];
37
+ lineAnchor?: number;
38
+ }
39
+ export type SemanticDiffConnectorAttachment = {
40
+ line: number;
41
+ edge: 'before' | 'after';
42
+ } | {
43
+ empty: true;
44
+ };
45
+ interface BaseSemanticDiffPairedSpan {
46
+ relation: 'mapped' | 'moved' | 'replaced';
47
+ old: SemanticDiffTextRange[];
48
+ new: SemanticDiffTextRange[];
49
+ linePairs: SemanticDiffLinePair[];
50
+ }
51
+ interface BaseSemanticDiffIntroducedSpan {
52
+ relation: 'introduced';
53
+ old?: never;
54
+ new: SemanticDiffTextRange[];
55
+ anchors?: SemanticDiffSpanAnchor[];
56
+ }
57
+ interface BaseSemanticDiffRemovedSpan {
58
+ relation: 'removed';
59
+ old: SemanticDiffTextRange[];
60
+ new?: never;
61
+ anchors?: SemanticDiffSpanAnchor[];
62
+ }
63
+ export interface SemanticDiffPairedStructuralSpan extends BaseSemanticDiffPairedSpan {
64
+ role: Exclude<SemanticDiffSpanRole, 'focus'>;
65
+ kind?: never;
66
+ }
67
+ export interface SemanticDiffPairedFocusSpan extends BaseSemanticDiffPairedSpan {
68
+ role: 'focus';
69
+ kind?: SemanticDiffFocusKind;
70
+ }
71
+ export interface SemanticDiffIntroducedStructuralSpan extends BaseSemanticDiffIntroducedSpan {
72
+ role: Exclude<SemanticDiffSpanRole, 'focus'>;
73
+ kind?: never;
74
+ }
75
+ export interface SemanticDiffIntroducedFocusSpan extends BaseSemanticDiffIntroducedSpan {
76
+ role: 'focus';
77
+ kind?: SemanticDiffFocusKind;
78
+ }
79
+ export interface SemanticDiffRemovedStructuralSpan extends BaseSemanticDiffRemovedSpan {
80
+ role: Exclude<SemanticDiffSpanRole, 'focus'>;
81
+ kind?: never;
82
+ }
83
+ export interface SemanticDiffRemovedFocusSpan extends BaseSemanticDiffRemovedSpan {
84
+ role: 'focus';
85
+ kind?: SemanticDiffFocusKind;
86
+ }
87
+ export type SemanticDiffSpan = SemanticDiffPairedStructuralSpan | SemanticDiffPairedFocusSpan | SemanticDiffIntroducedStructuralSpan | SemanticDiffIntroducedFocusSpan | SemanticDiffRemovedStructuralSpan | SemanticDiffRemovedFocusSpan;
88
+ export interface SemanticDiffLineRange extends SemanticDiffLineRegion {
89
+ spanIndex: number;
90
+ anchorIndex?: number;
91
+ attachment?: SemanticDiffConnectorAttachment;
92
+ }
93
+ export interface SemanticDiffOperation {
94
+ type: SemanticDiffOperationType;
95
+ lines: {
96
+ old: SemanticDiffLineRange[];
97
+ new: SemanticDiffLineRange[];
98
+ };
99
+ spans: SemanticDiffSpan[];
100
+ }
101
+ export {};
@@ -0,0 +1,5 @@
1
+ // The operation types the engine returns.
2
+ // Copied from pierrecomputer/pierre, packages/diffs/src/types.ts.
3
+ // Licensed Apache-2.0 by The Pierre Computer Company (Copyright 2025 Pierre Computer Company).
4
+ // Kept verbatim in shape.
5
+ export {};
@@ -0,0 +1,48 @@
1
+ import type { LanguageId } from './languages.js';
2
+ /** A grammar or runtime file: a path or URL to load, or its bytes. */
3
+ export type WasmSource = string | URL | Uint8Array;
4
+ export interface SemDiffSetup {
5
+ /**
6
+ * Where a language's grammar lives. `file` is its package path, e.g.
7
+ * `tree-sitter-go/tree-sitter-go.wasm`. In a browser, return a URL the page can fetch.
8
+ * Default (Node only): resolved from the installed packages.
9
+ */
10
+ locateGrammar?: (file: string, language: LanguageId) => WasmSource | Promise<WasmSource>;
11
+ /** Where web-tree-sitter's own `web-tree-sitter.wasm` lives (default: next to its script). */
12
+ locateRuntime?: (file: string) => string;
13
+ /** Debug output on stderr: why candidates were rejected, the evidence per candidate. */
14
+ debug?: {
15
+ reasons?: boolean;
16
+ features?: boolean;
17
+ };
18
+ /** Let the learned check accept candidates the rules reject (off by default). */
19
+ learned?: boolean;
20
+ /**
21
+ * A second opinion on extract/inline candidates the rules reject, e.g. a decision model's
22
+ * answers looked up ahead of time (harness/compare/clef.py). Return true to accept. It must
23
+ * answer at once: look answers up here, never fetch them.
24
+ */
25
+ secondOpinion?: (candidate: Candidate) => boolean;
26
+ /** Skip the second opinion when the helper's code is still in the caller (default on). */
27
+ secondOpinionCopyCheck?: boolean;
28
+ }
29
+ export type { Candidate } from './candidate.js';
30
+ import type { Candidate } from './candidate.js';
31
+ /** Configure the engine once, before the first diff (later calls replace earlier ones). */
32
+ export declare function configure(s: SemDiffSetup): void;
33
+ export declare const currentSetup: () => SemDiffSetup;
34
+ export declare const flags: {
35
+ reasons: () => boolean;
36
+ features: () => boolean;
37
+ learned: () => boolean;
38
+ };
39
+ export declare const rule: (name: string) => boolean;
40
+ export declare function switchRulesOff(names: Iterable<string>): void;
41
+ export declare const trial: (name: string) => boolean;
42
+ export declare function switchTrialsOn(names: Iterable<string>): void;
43
+ /**
44
+ * The default grammar lookup (Node only, loaded only when needed and never bundled): the file in this
45
+ * package's own `wasm/` folder when it is there (an installed package), else Node's resolver from the
46
+ * grammar packages (the source tree).
47
+ */
48
+ export declare function resolveInNode(file: string): Promise<string>;
@@ -0,0 +1,60 @@
1
+ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
2
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
3
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
4
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
5
+ });
6
+ }
7
+ return path;
8
+ };
9
+ let setup = {};
10
+ /** Configure the engine once, before the first diff (later calls replace earlier ones). */
11
+ export function configure(s) {
12
+ setup = { ...s };
13
+ }
14
+ export const currentSetup = () => setup;
15
+ /** An environment switch, read only where `process` exists (Node); always off in a browser. */
16
+ function env(name) {
17
+ const p = globalThis.process;
18
+ return !!p?.env?.[name];
19
+ }
20
+ export const flags = {
21
+ reasons: () => !!setup.debug?.reasons || env('SEMANTIC_DEBUG'),
22
+ features: () => !!setup.debug?.features || env('SEMANTIC_FEATURES'),
23
+ learned: () => !!setup.learned || env('SEMANTIC_LEARNED'),
24
+ };
25
+ // Rules that can be switched off to measure what each one adds (harness/score.ts). Not part
26
+ // of the public setup: the shipped engine never reads the environment to decide a result.
27
+ const rulesOff = new Set();
28
+ export const rule = (name) => !rulesOff.has(name);
29
+ export function switchRulesOff(names) {
30
+ rulesOff.clear();
31
+ for (const n of names)
32
+ rulesOff.add(n);
33
+ }
34
+ // Trial rules: off unless switched on (harness: SEMANTIC_TRY_<NAME>=1), measured on a fresh draw before
35
+ // they may ship. Like the rule switches, not part of the public setup.
36
+ const trialsOn = new Set();
37
+ export const trial = (name) => trialsOn.has(name);
38
+ export function switchTrialsOn(names) {
39
+ trialsOn.clear();
40
+ for (const n of names)
41
+ trialsOn.add(n);
42
+ }
43
+ /**
44
+ * The default grammar lookup (Node only, loaded only when needed and never bundled): the file in this
45
+ * package's own `wasm/` folder when it is there (an installed package), else Node's resolver from the
46
+ * grammar packages (the source tree).
47
+ */
48
+ export async function resolveInNode(file) {
49
+ const mod = 'node:module';
50
+ const fsName = 'node:fs';
51
+ const urlName = 'node:url';
52
+ const { createRequire } = (await import(__rewriteRelativeImportExtension(/* @vite-ignore */ mod)));
53
+ const { existsSync } = (await import(__rewriteRelativeImportExtension(/* @vite-ignore */ fsName)));
54
+ const { fileURLToPath } = (await import(__rewriteRelativeImportExtension(/* @vite-ignore */ urlName)));
55
+ // Built in a variable, not a template inside `new URL(..., import.meta.url)`: bundlers (Vite) turn that
56
+ // pattern into a glob over ../wasm/ and would pull every grammar into a page build.
57
+ const ownPath = '../wasm/' + file.split('/').pop();
58
+ const own = fileURLToPath(new URL(/* @vite-ignore */ ownPath, import.meta.url));
59
+ return existsSync(own) ? own : createRequire(import.meta.url).resolve(file);
60
+ }
@@ -0,0 +1,23 @@
1
+ import type { Node } from 'web-tree-sitter';
2
+ import { type LanguageConfig } from './parse.js';
3
+ import type { SemanticDiffFold, SemanticDiffOperation } from './pierre-types.js';
4
+ export interface StructureResult {
5
+ operations: SemanticDiffOperation[];
6
+ folds: SemanticDiffFold[];
7
+ /** Old-side lines (doc comments included) of every declaration paired across versions. */
8
+ paired: Array<{
9
+ start: number;
10
+ end: number;
11
+ }>;
12
+ /**
13
+ * Indices into `operations` of `reformatted` claims whose words changed (rule REFORMAT_WORDS): text inside a
14
+ * node that no token covers, such as a Python string's words around an escape, differs. The caller drops them
15
+ * at the end, like a held-back claim, so every other pass sees the same operations either way.
16
+ */
17
+ wordsChanged: Set<number>;
18
+ }
19
+ /**
20
+ * `keptLines` (trial DUP_TIEBREAK): the line diff's unchanged lines, old line to new line. Equally similar same-named
21
+ * declarations pair first where the line diff keeps one unchanged in place.
22
+ */
23
+ export declare function detectStructure(oldRoot: Node, newRoot: Node, cfg: LanguageConfig, keptLines?: Map<number, number>): StructureResult;