@gitwand/core 2.0.1 → 2.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/README.md +58 -0
- package/dist/__tests__/bench.bench.js +39 -0
- package/dist/__tests__/bench.bench.js.map +1 -1
- package/dist/__tests__/corpus.d.ts.map +1 -1
- package/dist/__tests__/corpus.js +363 -0
- package/dist/__tests__/corpus.js.map +1 -1
- package/dist/__tests__/diff/block-move.test.d.ts +5 -0
- package/dist/__tests__/diff/block-move.test.d.ts.map +1 -0
- package/dist/__tests__/diff/block-move.test.js +132 -0
- package/dist/__tests__/diff/block-move.test.js.map +1 -0
- package/dist/__tests__/diff/histogram.test.d.ts +8 -0
- package/dist/__tests__/diff/histogram.test.d.ts.map +1 -0
- package/dist/__tests__/diff/histogram.test.js +150 -0
- package/dist/__tests__/diff/histogram.test.js.map +1 -0
- package/dist/__tests__/diff/parity.test.d.ts +17 -0
- package/dist/__tests__/diff/parity.test.d.ts.map +1 -0
- package/dist/__tests__/diff/parity.test.js +149 -0
- package/dist/__tests__/diff/parity.test.js.map +1 -0
- package/dist/__tests__/diff.test.js +6 -2
- package/dist/__tests__/diff.test.js.map +1 -1
- package/dist/__tests__/format-profiles/integration.test.d.ts +7 -0
- package/dist/__tests__/format-profiles/integration.test.d.ts.map +1 -0
- package/dist/__tests__/format-profiles/integration.test.js +193 -0
- package/dist/__tests__/format-profiles/integration.test.js.map +1 -0
- package/dist/__tests__/format-profiles/json-patch.test.d.ts +12 -0
- package/dist/__tests__/format-profiles/json-patch.test.d.ts.map +1 -0
- package/dist/__tests__/format-profiles/json-patch.test.js +222 -0
- package/dist/__tests__/format-profiles/json-patch.test.js.map +1 -0
- package/dist/__tests__/format-profiles/registry.test.d.ts +5 -0
- package/dist/__tests__/format-profiles/registry.test.d.ts.map +1 -0
- package/dist/__tests__/format-profiles/registry.test.js +124 -0
- package/dist/__tests__/format-profiles/registry.test.js.map +1 -0
- package/dist/__tests__/patterns/make-score.test.d.ts +9 -0
- package/dist/__tests__/patterns/make-score.test.d.ts.map +1 -0
- package/dist/__tests__/patterns/make-score.test.js +49 -0
- package/dist/__tests__/patterns/make-score.test.js.map +1 -0
- package/dist/__tests__/structural/grandeur-nature.test.d.ts +31 -0
- package/dist/__tests__/structural/grandeur-nature.test.d.ts.map +1 -0
- package/dist/__tests__/structural/grandeur-nature.test.js +264 -0
- package/dist/__tests__/structural/grandeur-nature.test.js.map +1 -0
- package/dist/__tests__/structural/languages.test.d.ts +5 -0
- package/dist/__tests__/structural/languages.test.d.ts.map +1 -0
- package/dist/__tests__/structural/languages.test.js +74 -0
- package/dist/__tests__/structural/languages.test.js.map +1 -0
- package/dist/__tests__/structural/matching.test.d.ts +6 -0
- package/dist/__tests__/structural/matching.test.d.ts.map +1 -0
- package/dist/__tests__/structural/matching.test.js +113 -0
- package/dist/__tests__/structural/matching.test.js.map +1 -0
- package/dist/__tests__/structural/merge.test.d.ts +6 -0
- package/dist/__tests__/structural/merge.test.d.ts.map +1 -0
- package/dist/__tests__/structural/merge.test.js +117 -0
- package/dist/__tests__/structural/merge.test.js.map +1 -0
- package/dist/__tests__/structural/reconstruct.test.d.ts +6 -0
- package/dist/__tests__/structural/reconstruct.test.d.ts.map +1 -0
- package/dist/__tests__/structural/reconstruct.test.js +104 -0
- package/dist/__tests__/structural/reconstruct.test.js.map +1 -0
- package/dist/__tests__/structural/structural-index.test.d.ts +14 -0
- package/dist/__tests__/structural/structural-index.test.d.ts.map +1 -0
- package/dist/__tests__/structural/structural-index.test.js +108 -0
- package/dist/__tests__/structural/structural-index.test.js.map +1 -0
- package/dist/diff/block-move.d.ts +53 -0
- package/dist/diff/block-move.d.ts.map +1 -0
- package/dist/diff/block-move.js +192 -0
- package/dist/diff/block-move.js.map +1 -0
- package/dist/diff/histogram.d.ts +45 -0
- package/dist/diff/histogram.d.ts.map +1 -0
- package/dist/diff/histogram.js +172 -0
- package/dist/diff/histogram.js.map +1 -0
- package/dist/diff/index.d.ts +30 -0
- package/dist/diff/index.d.ts.map +1 -0
- package/dist/diff/index.js +47 -0
- package/dist/diff/index.js.map +1 -0
- package/dist/diff/lcs.d.ts +34 -0
- package/dist/diff/lcs.d.ts.map +1 -0
- package/dist/diff/lcs.js +184 -0
- package/dist/diff/lcs.js.map +1 -0
- package/dist/diff/shared.d.ts +54 -0
- package/dist/diff/shared.d.ts.map +1 -0
- package/dist/diff/shared.js +164 -0
- package/dist/diff/shared.js.map +1 -0
- package/dist/diff.d.ts +6 -65
- package/dist/diff.d.ts.map +1 -1
- package/dist/diff.js +6 -324
- package/dist/diff.js.map +1 -1
- package/dist/format-profiles/index.d.ts +34 -0
- package/dist/format-profiles/index.d.ts.map +1 -0
- package/dist/format-profiles/index.js +86 -0
- package/dist/format-profiles/index.js.map +1 -0
- package/dist/format-profiles/json-patch.d.ts +61 -0
- package/dist/format-profiles/json-patch.d.ts.map +1 -0
- package/dist/format-profiles/json-patch.js +269 -0
- package/dist/format-profiles/json-patch.js.map +1 -0
- package/dist/format-profiles/merge-strategies.d.ts +54 -0
- package/dist/format-profiles/merge-strategies.d.ts.map +1 -0
- package/dist/format-profiles/merge-strategies.js +156 -0
- package/dist/format-profiles/merge-strategies.js.map +1 -0
- package/dist/format-profiles/profiles/composer.d.ts +18 -0
- package/dist/format-profiles/profiles/composer.d.ts.map +1 -0
- package/dist/format-profiles/profiles/composer.js +45 -0
- package/dist/format-profiles/profiles/composer.js.map +1 -0
- package/dist/format-profiles/profiles/helm-values.d.ts +21 -0
- package/dist/format-profiles/profiles/helm-values.d.ts.map +1 -0
- package/dist/format-profiles/profiles/helm-values.js +40 -0
- package/dist/format-profiles/profiles/helm-values.js.map +1 -0
- package/dist/format-profiles/profiles/kubernetes.d.ts +22 -0
- package/dist/format-profiles/profiles/kubernetes.d.ts.map +1 -0
- package/dist/format-profiles/profiles/kubernetes.js +60 -0
- package/dist/format-profiles/profiles/kubernetes.js.map +1 -0
- package/dist/format-profiles/profiles/package-json.d.ts +18 -0
- package/dist/format-profiles/profiles/package-json.d.ts.map +1 -0
- package/dist/format-profiles/profiles/package-json.js +36 -0
- package/dist/format-profiles/profiles/package-json.js.map +1 -0
- package/dist/format-profiles/profiles/tsconfig.d.ts +21 -0
- package/dist/format-profiles/profiles/tsconfig.d.ts.map +1 -0
- package/dist/format-profiles/profiles/tsconfig.js +47 -0
- package/dist/format-profiles/profiles/tsconfig.js.map +1 -0
- package/dist/format-profiles/types.d.ts +67 -0
- package/dist/format-profiles/types.d.ts.map +1 -0
- package/dist/format-profiles/types.js +9 -0
- package/dist/format-profiles/types.js.map +1 -0
- package/dist/index.d.ts +9 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/dist/patterns/insertion-at-boundary.d.ts.map +1 -1
- package/dist/patterns/insertion-at-boundary.js +15 -33
- package/dist/patterns/insertion-at-boundary.js.map +1 -1
- package/dist/patterns/utils.d.ts +11 -8
- package/dist/patterns/utils.d.ts.map +1 -1
- package/dist/patterns/utils.js +28 -10
- package/dist/patterns/utils.js.map +1 -1
- package/dist/resolver/format-dispatch.d.ts.map +1 -1
- package/dist/resolver/format-dispatch.js +3 -1
- package/dist/resolver/format-dispatch.js.map +1 -1
- package/dist/resolver/index.d.ts +14 -0
- package/dist/resolver/index.d.ts.map +1 -1
- package/dist/resolver/index.js +29 -0
- package/dist/resolver/index.js.map +1 -1
- package/dist/resolver/policy.d.ts.map +1 -1
- package/dist/resolver/policy.js +2 -0
- package/dist/resolver/policy.js.map +1 -1
- package/dist/resolvers/dispatcher.d.ts +22 -2
- package/dist/resolvers/dispatcher.d.ts.map +1 -1
- package/dist/resolvers/dispatcher.js +8 -3
- package/dist/resolvers/dispatcher.js.map +1 -1
- package/dist/resolvers/json.d.ts +11 -2
- package/dist/resolvers/json.d.ts.map +1 -1
- package/dist/resolvers/json.js +55 -7
- package/dist/resolvers/json.js.map +1 -1
- package/dist/resolvers/yaml.d.ts +8 -2
- package/dist/resolvers/yaml.d.ts.map +1 -1
- package/dist/resolvers/yaml.js +156 -2
- package/dist/resolvers/yaml.js.map +1 -1
- package/dist/structural/entities.d.ts +44 -0
- package/dist/structural/entities.d.ts.map +1 -0
- package/dist/structural/entities.js +315 -0
- package/dist/structural/entities.js.map +1 -0
- package/dist/structural/index.d.ts +48 -0
- package/dist/structural/index.d.ts.map +1 -0
- package/dist/structural/index.js +177 -0
- package/dist/structural/index.js.map +1 -0
- package/dist/structural/matching.d.ts +46 -0
- package/dist/structural/matching.d.ts.map +1 -0
- package/dist/structural/matching.js +83 -0
- package/dist/structural/matching.js.map +1 -0
- package/dist/structural/merge.d.ts +45 -0
- package/dist/structural/merge.d.ts.map +1 -0
- package/dist/structural/merge.js +127 -0
- package/dist/structural/merge.js.map +1 -0
- package/dist/structural/parsers/adapters/browser.d.ts +22 -0
- package/dist/structural/parsers/adapters/browser.d.ts.map +1 -0
- package/dist/structural/parsers/adapters/browser.js +27 -0
- package/dist/structural/parsers/adapters/browser.js.map +1 -0
- package/dist/structural/parsers/adapters/node.d.ts +18 -0
- package/dist/structural/parsers/adapters/node.d.ts.map +1 -0
- package/dist/structural/parsers/adapters/node.js +42 -0
- package/dist/structural/parsers/adapters/node.js.map +1 -0
- package/dist/structural/parsers/adapters/tauri.d.ts +26 -0
- package/dist/structural/parsers/adapters/tauri.d.ts.map +1 -0
- package/dist/structural/parsers/adapters/tauri.js +34 -0
- package/dist/structural/parsers/adapters/tauri.js.map +1 -0
- package/dist/structural/parsers/grammars/languages.d.ts +32 -0
- package/dist/structural/parsers/grammars/languages.d.ts.map +1 -0
- package/dist/structural/parsers/grammars/languages.js +73 -0
- package/dist/structural/parsers/grammars/languages.js.map +1 -0
- package/dist/structural/parsers/grammars/ts.d.ts +26 -0
- package/dist/structural/parsers/grammars/ts.d.ts.map +1 -0
- package/dist/structural/parsers/grammars/ts.js +46 -0
- package/dist/structural/parsers/grammars/ts.js.map +1 -0
- package/dist/structural/parsers/loader.d.ts +74 -0
- package/dist/structural/parsers/loader.d.ts.map +1 -0
- package/dist/structural/parsers/loader.js +181 -0
- package/dist/structural/parsers/loader.js.map +1 -0
- package/dist/structural/reconstruct.d.ts +28 -0
- package/dist/structural/reconstruct.d.ts.map +1 -0
- package/dist/structural/reconstruct.js +63 -0
- package/dist/structural/reconstruct.js.map +1 -0
- package/dist/types.d.ts +25 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +16 -2
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Grammar loaders for all structural-merge–supported languages.
|
|
3
|
+
*
|
|
4
|
+
* Uses the unified language registry from `languages.ts` to map file paths
|
|
5
|
+
* to the correct `tree-sitter-wasms` grammar WASM.
|
|
6
|
+
*/
|
|
7
|
+
import { loadGrammar } from "../loader.js";
|
|
8
|
+
import { grammarNameForFile, LANGUAGE_SPECS } from "./languages.js";
|
|
9
|
+
// ─── Named loaders (kept for backward compat + direct use) ───────────────────
|
|
10
|
+
/** Load the TypeScript grammar. */
|
|
11
|
+
export async function loadTypeScriptGrammar(opts = {}) {
|
|
12
|
+
return loadGrammar(LANGUAGE_SPECS.typescript.grammarName, opts);
|
|
13
|
+
}
|
|
14
|
+
/** Load the TSX grammar. */
|
|
15
|
+
export async function loadTsxGrammar(opts = {}) {
|
|
16
|
+
return loadGrammar(LANGUAGE_SPECS.tsx.grammarName, opts);
|
|
17
|
+
}
|
|
18
|
+
/** Load the JavaScript grammar (also used for JSX). */
|
|
19
|
+
export async function loadJavaScriptGrammar(opts = {}) {
|
|
20
|
+
return loadGrammar(LANGUAGE_SPECS.javascript.grammarName, opts);
|
|
21
|
+
}
|
|
22
|
+
/** Load the Python grammar. */
|
|
23
|
+
export async function loadPythonGrammar(opts = {}) {
|
|
24
|
+
return loadGrammar(LANGUAGE_SPECS.python.grammarName, opts);
|
|
25
|
+
}
|
|
26
|
+
/** Load the Go grammar. */
|
|
27
|
+
export async function loadGoGrammar(opts = {}) {
|
|
28
|
+
return loadGrammar(LANGUAGE_SPECS.go.grammarName, opts);
|
|
29
|
+
}
|
|
30
|
+
/** Load the Rust grammar. */
|
|
31
|
+
export async function loadRustGrammar(opts = {}) {
|
|
32
|
+
return loadGrammar(LANGUAGE_SPECS.rust.grammarName, opts);
|
|
33
|
+
}
|
|
34
|
+
// ─── Generic loader ───────────────────────────────────────────────────────────
|
|
35
|
+
/**
|
|
36
|
+
* Load the appropriate grammar for a given file path.
|
|
37
|
+
* Returns `null` if the file extension is not supported or the grammar WASM
|
|
38
|
+
* is unavailable.
|
|
39
|
+
*/
|
|
40
|
+
export async function loadGrammarForFile(filePath, opts = {}) {
|
|
41
|
+
const grammarName = grammarNameForFile(filePath);
|
|
42
|
+
if (!grammarName)
|
|
43
|
+
return null;
|
|
44
|
+
return loadGrammar(grammarName, opts);
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=ts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ts.js","sourceRoot":"","sources":["../../../../src/structural/parsers/grammars/ts.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAqC,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEpE,gFAAgF;AAEhF,mCAAmC;AACnC,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,OAAsB,EAAE;IAClE,OAAO,WAAW,CAAC,cAAc,CAAC,UAAU,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;AAClE,CAAC;AAED,4BAA4B;AAC5B,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,OAAsB,EAAE;IAC3D,OAAO,WAAW,CAAC,cAAc,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;AAC3D,CAAC;AAED,uDAAuD;AACvD,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,OAAsB,EAAE;IAClE,OAAO,WAAW,CAAC,cAAc,CAAC,UAAU,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;AAClE,CAAC;AAED,+BAA+B;AAC/B,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,OAAsB,EAAE;IAC9D,OAAO,WAAW,CAAC,cAAc,CAAC,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;AAC9D,CAAC;AAED,2BAA2B;AAC3B,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,OAAsB,EAAE;IAC1D,OAAO,WAAW,CAAC,cAAc,CAAC,EAAE,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;AAC1D,CAAC;AAED,6BAA6B;AAC7B,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,OAAsB,EAAE;IAC5D,OAAO,WAAW,CAAC,cAAc,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;AAC5D,CAAC;AAED,iFAAiF;AAEjF;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,QAAgB,EAChB,OAAsB,EAAE;IAExB,MAAM,WAAW,GAAG,kBAAkB,CAAC,QAAQ,CAAC,CAAC;IACjD,IAAI,CAAC,WAAW;QAAE,OAAO,IAAI,CAAC;IAC9B,OAAO,WAAW,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Grammar loader for web-tree-sitter.
|
|
3
|
+
*
|
|
4
|
+
* Handles environment detection, WASM loading, and in-process caching.
|
|
5
|
+
*
|
|
6
|
+
* `web-tree-sitter` is an **optional** peer dependency — if it is not
|
|
7
|
+
* installed, every function here returns `null` gracefully and the
|
|
8
|
+
* structural merge is silently skipped.
|
|
9
|
+
*/
|
|
10
|
+
/** A loaded tree-sitter Language (opaque to callers). */
|
|
11
|
+
export type Language = unknown;
|
|
12
|
+
/** A ready-to-use tree-sitter Parser (opaque to callers). */
|
|
13
|
+
export type TSParser = unknown;
|
|
14
|
+
export type Environment = "node" | "tauri" | "browser";
|
|
15
|
+
export interface LoaderOptions {
|
|
16
|
+
/** Base URL used by the browser adapter to locate grammar WASM files. */
|
|
17
|
+
grammarBaseUrl?: string;
|
|
18
|
+
/** Directory used by the Tauri adapter to locate grammar WASM files. */
|
|
19
|
+
grammarDir?: string;
|
|
20
|
+
/**
|
|
21
|
+
* URL for `web-tree-sitter.wasm` — the web-tree-sitter runtime WASM.
|
|
22
|
+
* Pass this when the runtime cannot auto-discover the file (e.g. inside a
|
|
23
|
+
* Vite bundle where the hashed asset URL is not predictable).
|
|
24
|
+
* Example: `"/grammars/web-tree-sitter.wasm"`.
|
|
25
|
+
*
|
|
26
|
+
* Internally mapped to `locateFile` for web-tree-sitter v0.26+ (Emscripten).
|
|
27
|
+
*/
|
|
28
|
+
wasmPath?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Custom WASM bytes loader — overrides environment detection entirely.
|
|
31
|
+
* Receives the grammar name (e.g. "tree-sitter-typescript") and must
|
|
32
|
+
* return the raw WASM bytes.
|
|
33
|
+
*/
|
|
34
|
+
customLoader?: (grammarName: string) => Promise<Uint8Array>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Detect the current runtime environment.
|
|
38
|
+
* Priority: Tauri (window.__TAURI_INTERNALS__) > Node.js (process.versions.node) > browser.
|
|
39
|
+
*/
|
|
40
|
+
export declare function detectEnvironment(): Environment;
|
|
41
|
+
/**
|
|
42
|
+
* Ensure web-tree-sitter's WASM runtime is initialized.
|
|
43
|
+
*
|
|
44
|
+
* Idempotent — safe to call multiple times; initialization runs only once.
|
|
45
|
+
*
|
|
46
|
+
* @returns The Parser class, or `null` if web-tree-sitter is unavailable.
|
|
47
|
+
*/
|
|
48
|
+
export declare function ensureParserInitialized(_opts?: LoaderOptions): Promise<any | null>;
|
|
49
|
+
/**
|
|
50
|
+
* Load and cache a tree-sitter grammar by name.
|
|
51
|
+
*
|
|
52
|
+
* Returns `null` (never throws) if:
|
|
53
|
+
* - `web-tree-sitter` is not installed
|
|
54
|
+
* - The grammar WASM file cannot be found or loaded
|
|
55
|
+
*
|
|
56
|
+
* @param grammarName - e.g. "tree-sitter-typescript"
|
|
57
|
+
* @param opts - Optional WASM path / loader overrides
|
|
58
|
+
*/
|
|
59
|
+
export declare function loadGrammar(grammarName: string, opts?: LoaderOptions): Promise<Language | null>;
|
|
60
|
+
/**
|
|
61
|
+
* Create a configured tree-sitter Parser instance.
|
|
62
|
+
*
|
|
63
|
+
* Returns `null` if web-tree-sitter is unavailable.
|
|
64
|
+
*
|
|
65
|
+
* @param language - A language object returned by `loadGrammar()`
|
|
66
|
+
* @param opts - Loader options (passed to `ensureParserInitialized`)
|
|
67
|
+
*/
|
|
68
|
+
export declare function createParser(language: Language, opts?: LoaderOptions): Promise<TSParser | null>;
|
|
69
|
+
/**
|
|
70
|
+
* Reset the in-process grammar cache and initialization state.
|
|
71
|
+
* Intended for use in tests only.
|
|
72
|
+
*/
|
|
73
|
+
export declare function _resetCache(): void;
|
|
74
|
+
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../src/structural/parsers/loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,yDAAyD;AACzD,MAAM,MAAM,QAAQ,GAAG,OAAO,CAAC;AAE/B,6DAA6D;AAC7D,MAAM,MAAM,QAAQ,GAAG,OAAO,CAAC;AAE/B,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;AAEvD,MAAM,WAAW,aAAa;IAC5B,yEAAyE;IACzE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,wEAAwE;IACxE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,YAAY,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;CAC7D;AAaD;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,WAAW,CAY/C;AAuCD;;;;;;GAMG;AAEH,wBAAsB,uBAAuB,CAAC,KAAK,GAAE,aAAkB,GAAG,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC,CAsB5F;AA0BD;;;;;;;;;GASG;AACH,wBAAsB,WAAW,CAC/B,WAAW,EAAE,MAAM,EACnB,IAAI,GAAE,aAAkB,GACvB,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAyB1B;AAED;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAChC,QAAQ,EAAE,QAAQ,EAClB,IAAI,GAAE,aAAkB,GACvB,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAQ1B;AAED;;;GAGG;AACH,wBAAgB,WAAW,IAAI,IAAI,CAKlC"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Grammar loader for web-tree-sitter.
|
|
3
|
+
*
|
|
4
|
+
* Handles environment detection, WASM loading, and in-process caching.
|
|
5
|
+
*
|
|
6
|
+
* `web-tree-sitter` is an **optional** peer dependency — if it is not
|
|
7
|
+
* installed, every function here returns `null` gracefully and the
|
|
8
|
+
* structural merge is silently skipped.
|
|
9
|
+
*/
|
|
10
|
+
// ─── Module-level cache ───────────────────────────────────────────────────────
|
|
11
|
+
const grammarCache = new Map();
|
|
12
|
+
let parserInitialized = false;
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
+
let _ParserClass = null;
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
+
let _LanguageClass = null;
|
|
17
|
+
// ─── Environment detection ────────────────────────────────────────────────────
|
|
18
|
+
/**
|
|
19
|
+
* Detect the current runtime environment.
|
|
20
|
+
* Priority: Tauri (window.__TAURI_INTERNALS__) > Node.js (process.versions.node) > browser.
|
|
21
|
+
*/
|
|
22
|
+
export function detectEnvironment() {
|
|
23
|
+
if (typeof window !== "undefined" &&
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
+
window.__TAURI_INTERNALS__ != null) {
|
|
26
|
+
return "tauri";
|
|
27
|
+
}
|
|
28
|
+
if (typeof process !== "undefined" && process.versions?.node) {
|
|
29
|
+
return "node";
|
|
30
|
+
}
|
|
31
|
+
return "browser";
|
|
32
|
+
}
|
|
33
|
+
// ─── web-tree-sitter dynamic import ──────────────────────────────────────────
|
|
34
|
+
/**
|
|
35
|
+
* Try to dynamically import `web-tree-sitter`.
|
|
36
|
+
* Returns `null` (never throws) if the package is not installed.
|
|
37
|
+
*/
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
|
+
async function tryImportTreeSitter() {
|
|
40
|
+
if (_ParserClass !== null)
|
|
41
|
+
return _ParserClass;
|
|
42
|
+
try {
|
|
43
|
+
// web-tree-sitter is an optional peerDependency — TypeScript cannot
|
|
44
|
+
// resolve it at compile time when it is not installed.
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
46
|
+
// @ts-ignore: optional peer — may not be installed
|
|
47
|
+
const mod = await import("web-tree-sitter");
|
|
48
|
+
// v0.26+ exports named exports (Parser, Language, …) with no default.
|
|
49
|
+
// Earlier versions (≤0.22) had a single default export (the Parser class)
|
|
50
|
+
// with Language available as Parser.Language.
|
|
51
|
+
// Support both shapes.
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
53
|
+
const anyMod = mod;
|
|
54
|
+
if (anyMod.Parser) {
|
|
55
|
+
// v0.26+ shape: { Parser, Language, … }
|
|
56
|
+
_ParserClass = anyMod.Parser;
|
|
57
|
+
_LanguageClass = anyMod.Language;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
// pre-v0.22 shape: default export is the Parser class; Language is Parser.Language
|
|
61
|
+
const ParserDefault = anyMod.default ?? anyMod;
|
|
62
|
+
_ParserClass = ParserDefault;
|
|
63
|
+
_LanguageClass = ParserDefault.Language;
|
|
64
|
+
}
|
|
65
|
+
return _ParserClass;
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Ensure web-tree-sitter's WASM runtime is initialized.
|
|
73
|
+
*
|
|
74
|
+
* Idempotent — safe to call multiple times; initialization runs only once.
|
|
75
|
+
*
|
|
76
|
+
* @returns The Parser class, or `null` if web-tree-sitter is unavailable.
|
|
77
|
+
*/
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
79
|
+
export async function ensureParserInitialized(_opts = {}) {
|
|
80
|
+
const Parser = await tryImportTreeSitter();
|
|
81
|
+
if (!Parser)
|
|
82
|
+
return null;
|
|
83
|
+
if (!parserInitialized) {
|
|
84
|
+
// `wasmPath` lets the caller override where web-tree-sitter finds its own
|
|
85
|
+
// runtime WASM (web-tree-sitter.wasm). This is needed in bundled
|
|
86
|
+
// environments (Vite, Tauri) where the file is served as a static asset.
|
|
87
|
+
//
|
|
88
|
+
// web-tree-sitter v0.26+ uses the Emscripten `locateFile` callback to
|
|
89
|
+
// resolve the WASM URL — there is no `wasmPath` option in that API.
|
|
90
|
+
const initOpts = _opts.wasmPath
|
|
91
|
+
? {
|
|
92
|
+
locateFile: (path) => path.endsWith(".wasm") ? _opts.wasmPath : path,
|
|
93
|
+
}
|
|
94
|
+
: {};
|
|
95
|
+
await Parser.init(initOpts);
|
|
96
|
+
parserInitialized = true;
|
|
97
|
+
}
|
|
98
|
+
return Parser;
|
|
99
|
+
}
|
|
100
|
+
// ─── WASM bytes loading ───────────────────────────────────────────────────────
|
|
101
|
+
async function loadWasmForEnv(env, grammarName, opts) {
|
|
102
|
+
if (env === "node") {
|
|
103
|
+
// vite-ignore: Node-only adapter uses `createRequire` — never bundled for browser/Tauri
|
|
104
|
+
const { loadGrammarBytes } = await import(/* @vite-ignore */ "./adapters/node.js");
|
|
105
|
+
return loadGrammarBytes(grammarName);
|
|
106
|
+
}
|
|
107
|
+
if (env === "tauri") {
|
|
108
|
+
// vite-ignore: Tauri adapter uses @tauri-apps/plugin-fs — not available in web builds
|
|
109
|
+
const { loadGrammarBytes } = await import(/* @vite-ignore */ "./adapters/tauri.js");
|
|
110
|
+
return loadGrammarBytes(grammarName, { grammarDir: opts.grammarDir });
|
|
111
|
+
}
|
|
112
|
+
// browser
|
|
113
|
+
const { loadGrammarBytes } = await import("./adapters/browser.js");
|
|
114
|
+
return loadGrammarBytes(grammarName, { grammarBaseUrl: opts.grammarBaseUrl });
|
|
115
|
+
}
|
|
116
|
+
// ─── Public API ───────────────────────────────────────────────────────────────
|
|
117
|
+
/**
|
|
118
|
+
* Load and cache a tree-sitter grammar by name.
|
|
119
|
+
*
|
|
120
|
+
* Returns `null` (never throws) if:
|
|
121
|
+
* - `web-tree-sitter` is not installed
|
|
122
|
+
* - The grammar WASM file cannot be found or loaded
|
|
123
|
+
*
|
|
124
|
+
* @param grammarName - e.g. "tree-sitter-typescript"
|
|
125
|
+
* @param opts - Optional WASM path / loader overrides
|
|
126
|
+
*/
|
|
127
|
+
export async function loadGrammar(grammarName, opts = {}) {
|
|
128
|
+
const cached = grammarCache.get(grammarName);
|
|
129
|
+
if (cached !== undefined)
|
|
130
|
+
return cached;
|
|
131
|
+
const Parser = await ensureParserInitialized(opts);
|
|
132
|
+
if (!Parser)
|
|
133
|
+
return null;
|
|
134
|
+
try {
|
|
135
|
+
let wasmBytes;
|
|
136
|
+
if (opts.customLoader) {
|
|
137
|
+
wasmBytes = await opts.customLoader(grammarName);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
const env = detectEnvironment();
|
|
141
|
+
wasmBytes = await loadWasmForEnv(env, grammarName, opts);
|
|
142
|
+
}
|
|
143
|
+
// Use the module-level Language class (v0.26+ separate export;
|
|
144
|
+
// fall back to Parser.Language for older versions).
|
|
145
|
+
const LanguageClass = _LanguageClass ?? Parser.Language;
|
|
146
|
+
const language = await LanguageClass.load(wasmBytes);
|
|
147
|
+
grammarCache.set(grammarName, language);
|
|
148
|
+
return language;
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Create a configured tree-sitter Parser instance.
|
|
156
|
+
*
|
|
157
|
+
* Returns `null` if web-tree-sitter is unavailable.
|
|
158
|
+
*
|
|
159
|
+
* @param language - A language object returned by `loadGrammar()`
|
|
160
|
+
* @param opts - Loader options (passed to `ensureParserInitialized`)
|
|
161
|
+
*/
|
|
162
|
+
export async function createParser(language, opts = {}) {
|
|
163
|
+
const Parser = await ensureParserInitialized(opts);
|
|
164
|
+
if (!Parser)
|
|
165
|
+
return null;
|
|
166
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
167
|
+
const parser = new Parser();
|
|
168
|
+
parser.setLanguage(language);
|
|
169
|
+
return parser;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Reset the in-process grammar cache and initialization state.
|
|
173
|
+
* Intended for use in tests only.
|
|
174
|
+
*/
|
|
175
|
+
export function _resetCache() {
|
|
176
|
+
grammarCache.clear();
|
|
177
|
+
parserInitialized = false;
|
|
178
|
+
_ParserClass = null;
|
|
179
|
+
_LanguageClass = null;
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../../../src/structural/parsers/loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAkCH,iFAAiF;AAEjF,MAAM,YAAY,GAAG,IAAI,GAAG,EAAoB,CAAC;AACjD,IAAI,iBAAiB,GAAG,KAAK,CAAC;AAC9B,8DAA8D;AAC9D,IAAI,YAAY,GAAQ,IAAI,CAAC;AAC7B,8DAA8D;AAC9D,IAAI,cAAc,GAAQ,IAAI,CAAC;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AAC;IACnD,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IAEzB,8DAA8D;IAC9D,MAAM,MAAM,GAAG,IAAK,MAAc,EAAE,CAAC;IACrC,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;IAC7B,OAAO,MAAkB,CAAC;AAC5B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW;IACzB,YAAY,CAAC,KAAK,EAAE,CAAC;IACrB,iBAAiB,GAAG,KAAK,CAAC;IAC1B,YAAY,GAAG,IAAI,CAAC;IACpB,cAAc,GAAG,IAAI,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merged file reconstruction from entity merge results.
|
|
3
|
+
*
|
|
4
|
+
* Follows theirs entity order (to preserve incoming structure), interpolating
|
|
5
|
+
* the inter-entity whitespace/comments from the theirs source verbatim.
|
|
6
|
+
* Entities that only exist in ours (ours-added) are appended at the end.
|
|
7
|
+
*/
|
|
8
|
+
import type { TopLevelEntity } from "./entities.js";
|
|
9
|
+
import type { EntityMergeResult } from "./merge.js";
|
|
10
|
+
/**
|
|
11
|
+
* Reconstruct the merged source file from entity merge results.
|
|
12
|
+
*
|
|
13
|
+
* Strategy:
|
|
14
|
+
* 1. Walk theirs entities in order.
|
|
15
|
+
* - Emit the source gap (whitespace, comments) between consecutive
|
|
16
|
+
* entities, taken verbatim from `theirsSource`.
|
|
17
|
+
* - Emit the merged text for each entity (or skip if deleted).
|
|
18
|
+
* 2. Emit the trailing content from `theirsSource` after the last entity.
|
|
19
|
+
* 3. Append any entities that only exist in ours (ours-added), separated
|
|
20
|
+
* by a newline.
|
|
21
|
+
*
|
|
22
|
+
* @param merges - Merge decision per entity signature
|
|
23
|
+
* @param theirsEntities - Top-level entities from the theirs version (ordered)
|
|
24
|
+
* @param oursEntities - Top-level entities from the ours version (ordered)
|
|
25
|
+
* @param theirsSource - Full source text of the theirs version (for gaps)
|
|
26
|
+
*/
|
|
27
|
+
export declare function reconstructFile(merges: EntityMergeResult[], theirsEntities: TopLevelEntity[], oursEntities: TopLevelEntity[], theirsSource: string): string;
|
|
28
|
+
//# sourceMappingURL=reconstruct.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reconstruct.d.ts","sourceRoot":"","sources":["../../src/structural/reconstruct.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,iBAAiB,EAAE,EAC3B,cAAc,EAAE,cAAc,EAAE,EAChC,YAAY,EAAE,cAAc,EAAE,EAC9B,YAAY,EAAE,MAAM,GACnB,MAAM,CA2CR"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merged file reconstruction from entity merge results.
|
|
3
|
+
*
|
|
4
|
+
* Follows theirs entity order (to preserve incoming structure), interpolating
|
|
5
|
+
* the inter-entity whitespace/comments from the theirs source verbatim.
|
|
6
|
+
* Entities that only exist in ours (ours-added) are appended at the end.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Reconstruct the merged source file from entity merge results.
|
|
10
|
+
*
|
|
11
|
+
* Strategy:
|
|
12
|
+
* 1. Walk theirs entities in order.
|
|
13
|
+
* - Emit the source gap (whitespace, comments) between consecutive
|
|
14
|
+
* entities, taken verbatim from `theirsSource`.
|
|
15
|
+
* - Emit the merged text for each entity (or skip if deleted).
|
|
16
|
+
* 2. Emit the trailing content from `theirsSource` after the last entity.
|
|
17
|
+
* 3. Append any entities that only exist in ours (ours-added), separated
|
|
18
|
+
* by a newline.
|
|
19
|
+
*
|
|
20
|
+
* @param merges - Merge decision per entity signature
|
|
21
|
+
* @param theirsEntities - Top-level entities from the theirs version (ordered)
|
|
22
|
+
* @param oursEntities - Top-level entities from the ours version (ordered)
|
|
23
|
+
* @param theirsSource - Full source text of the theirs version (for gaps)
|
|
24
|
+
*/
|
|
25
|
+
export function reconstructFile(merges, theirsEntities, oursEntities, theirsSource) {
|
|
26
|
+
const mergeMap = new Map(merges.map((m) => [m.signature, m]));
|
|
27
|
+
const theirsSigSet = new Set(theirsEntities.map((e) => e.signature));
|
|
28
|
+
const parts = [];
|
|
29
|
+
let lastEnd = 0;
|
|
30
|
+
// ── 1. Follow theirs entity order ────────────────────────
|
|
31
|
+
for (const entity of theirsEntities) {
|
|
32
|
+
const merge = mergeMap.get(entity.signature);
|
|
33
|
+
// Emit the gap between the previous entity and this one (whitespace / comments)
|
|
34
|
+
const gap = theirsSource.slice(lastEnd, entity.startByte);
|
|
35
|
+
if (gap)
|
|
36
|
+
parts.push(gap);
|
|
37
|
+
if (merge?.include && merge.mergedText !== null) {
|
|
38
|
+
parts.push(merge.mergedText);
|
|
39
|
+
}
|
|
40
|
+
// If the entity is excluded (deleted / conflicted), we still advance
|
|
41
|
+
// lastEnd to skip over the theirs text for that entity.
|
|
42
|
+
lastEnd = entity.endByte;
|
|
43
|
+
}
|
|
44
|
+
// ── 2. Trailing content after the last theirs entity ─────
|
|
45
|
+
const trailing = theirsSource.slice(lastEnd);
|
|
46
|
+
if (trailing)
|
|
47
|
+
parts.push(trailing);
|
|
48
|
+
// ── 3. Append ours-added entities ────────────────────────
|
|
49
|
+
for (const entity of oursEntities) {
|
|
50
|
+
if (theirsSigSet.has(entity.signature))
|
|
51
|
+
continue; // already handled above
|
|
52
|
+
const merge = mergeMap.get(entity.signature);
|
|
53
|
+
if (!merge?.include || merge.mergedText === null)
|
|
54
|
+
continue;
|
|
55
|
+
// Ensure there's at least one newline separator before the appended entity
|
|
56
|
+
const last = parts[parts.length - 1] ?? "";
|
|
57
|
+
if (last !== "" && !last.endsWith("\n"))
|
|
58
|
+
parts.push("\n");
|
|
59
|
+
parts.push(merge.mergedText);
|
|
60
|
+
}
|
|
61
|
+
return parts.join("");
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=reconstruct.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reconstruct.js","sourceRoot":"","sources":["../../src/structural/reconstruct.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,eAAe,CAC7B,MAA2B,EAC3B,cAAgC,EAChC,YAA8B,EAC9B,YAAoB;IAEpB,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9D,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IAErE,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,OAAO,GAAG,CAAC,CAAC;IAEhB,4DAA4D;IAC5D,KAAK,MAAM,MAAM,IAAI,cAAc,EAAE,CAAC;QACpC,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAE7C,gFAAgF;QAChF,MAAM,GAAG,GAAG,YAAY,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;QAC1D,IAAI,GAAG;YAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAEzB,IAAI,KAAK,EAAE,OAAO,IAAI,KAAK,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;YAChD,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAC/B,CAAC;QACD,qEAAqE;QACrE,wDAAwD;QAExD,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;IAC3B,CAAC;IAED,4DAA4D;IAC5D,MAAM,QAAQ,GAAG,YAAY,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC7C,IAAI,QAAQ;QAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAEnC,4DAA4D;IAC5D,KAAK,MAAM,MAAM,IAAI,YAAY,EAAE,CAAC;QAClC,IAAI,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC;YAAE,SAAS,CAAC,wBAAwB;QAE1E,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAC7C,IAAI,CAAC,KAAK,EAAE,OAAO,IAAI,KAAK,CAAC,UAAU,KAAK,IAAI;YAAE,SAAS;QAE3D,2EAA2E;QAC3E,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;QAC3C,IAAI,IAAI,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;YAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAE1D,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAC/B,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACxB,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -66,6 +66,19 @@ export interface ConfidenceScore {
|
|
|
66
66
|
* 100 si la base est disponible (diff3 ou zdiff3), 0 sinon (diff2).
|
|
67
67
|
*/
|
|
68
68
|
baseAvailability: number;
|
|
69
|
+
/**
|
|
70
|
+
* v2.1 — Pénalité « instabilité algorithmique » : 0 = pas de signal, 100 =
|
|
71
|
+
* refactoring massif détecté des deux côtés (block-moves majoritaires).
|
|
72
|
+
* Optionnel pour rétro-compat — les patterns qui ne la set pas voient
|
|
73
|
+
* `undefined`. Consommée par `makeScore` avec un poids de −0.10.
|
|
74
|
+
*
|
|
75
|
+
* Alimentée à terme par `detectBlockMove` (primitive livrée en v2.1,
|
|
76
|
+
* branchement scoring repoussé à v2.6 refactoring-aware merge où le signal
|
|
77
|
+
* devient actionnable). En v2.1 la dimension existe et est modélisée, mais
|
|
78
|
+
* aucun pattern ne la set encore — le score reste numériquement identique
|
|
79
|
+
* pour la rétro-compat stricte.
|
|
80
|
+
*/
|
|
81
|
+
algorithmStability?: number;
|
|
69
82
|
};
|
|
70
83
|
/** Facteurs ayant augmenté le score (justifications de haute confiance) */
|
|
71
84
|
boosters: string[];
|
|
@@ -252,5 +265,17 @@ export interface GitWandOptions {
|
|
|
252
265
|
* Exemple : `["src/**\/*.generated.ts", "*.pb.go", "api/openapi-client/**"]`.
|
|
253
266
|
*/
|
|
254
267
|
generatedFiles?: string[];
|
|
268
|
+
/**
|
|
269
|
+
* v2.2 — Désactive globalement les FormatProfile.
|
|
270
|
+
*
|
|
271
|
+
* Quand `true`, les résolveurs JSON et YAML sautent le lookup `profileForFile`
|
|
272
|
+
* et se comportent exactement comme en v2.1 (les arrays modifiés des deux
|
|
273
|
+
* côtés retombent en fallback textuel). Utile pour rollback ponctuel,
|
|
274
|
+
* debug d'un profil mal calibré, ou scénarios où un profil tiers introduit
|
|
275
|
+
* des suppressions silencieuses inattendues.
|
|
276
|
+
*
|
|
277
|
+
* Défaut: `false` (profils actifs).
|
|
278
|
+
*/
|
|
279
|
+
disableFormatProfiles?: boolean;
|
|
255
280
|
}
|
|
256
281
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,iDAAiD;AACjD,MAAM,WAAW,UAAU;IACzB,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,yDAAy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xE,aAAa,CAAC,EAAE,UAAU,CAAC;IAC3B,mDAAmD;IACnD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;OAIG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAE,OAAO,aAAa,EAAE,WAAW,CAAC;IAC3C;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,aAAa,EAAE,WAAW,CAAC,CAAC;IACrE;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B;;;;;;;;;;OAUG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gitwand/core",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "GitWand core — automatic Git conflict resolution engine (powers @gitwand/cli, @gitwand/mcp, and the GitWand desktop app)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -38,14 +38,28 @@
|
|
|
38
38
|
},
|
|
39
39
|
"license": "MIT",
|
|
40
40
|
"author": "Laurent Guitton <lb.guitton@gmail.com>",
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"tree-sitter-wasms": ">=0.1.0",
|
|
43
|
+
"web-tree-sitter": ">=0.20.0"
|
|
44
|
+
},
|
|
45
|
+
"peerDependenciesMeta": {
|
|
46
|
+
"web-tree-sitter": {
|
|
47
|
+
"optional": true
|
|
48
|
+
},
|
|
49
|
+
"tree-sitter-wasms": {
|
|
50
|
+
"optional": true
|
|
51
|
+
}
|
|
52
|
+
},
|
|
41
53
|
"dependencies": {
|
|
42
54
|
"smol-toml": "^1.3.0",
|
|
43
55
|
"yaml": "^2.5.0"
|
|
44
56
|
},
|
|
45
57
|
"devDependencies": {
|
|
46
58
|
"@types/node": "^25.5.0",
|
|
59
|
+
"tree-sitter-wasms": "^0.1.13",
|
|
47
60
|
"typescript": "^5.4.0",
|
|
48
|
-
"vitest": "^3.0.0"
|
|
61
|
+
"vitest": "^3.0.0",
|
|
62
|
+
"web-tree-sitter": "~0.20.7"
|
|
49
63
|
},
|
|
50
64
|
"scripts": {
|
|
51
65
|
"build": "tsc",
|