@gitkraken/conflict-tools 0.2.4-beta.1 → 0.2.4-beta.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.
- package/CHANGELOG.md +1 -0
- package/dist/git/port-dispatch.d.ts +2 -1
- package/dist/git/port-dispatch.js +2 -1
- package/dist/ports/git.d.ts +5 -0
- package/dist/reference-integrity/detect.js +3 -1
- package/dist/reference-integrity/snapshot.d.ts +8 -3
- package/dist/reference-integrity/snapshot.js +1 -1
- package/dist/types/findings.d.ts +8 -1
- package/dist/types/resolution.d.ts +4 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
|
|
|
10
10
|
### Added
|
|
11
11
|
|
|
12
12
|
- Reference-integrity detection. `resolveConflicts` now attaches a `StepResult.detection` report listing broken references (symbols that resolved in a pre-merge parent but no longer resolve in the merged result, with provenance), duplicate definitions, and syntax errors in the resolved files. Detection is opt-in via a new `ParserPort` (`ResolverDeps.parser`) that supplies parsing/symbol resolution per surface (tree-sitter, language server); when it is absent, unavailable, or a file's language is unsupported, the report says so rather than implying a clean result. Report-only in this release — no automatic fixing.
|
|
13
|
+
- Auto-merged scope for reference-integrity detection: the detector discovers the merge's incoming/auto-merged set itself (new optional `changedFiles` git-port op; `git diff --name-only base..theirs`, base from `refs.base` or `mergeBase`) and includes it in scope, so dangling references in cleanly-merged files are caught. Scope is capped and reported via `DetectionReport.scope`; an optional `ResolutionContext.touchedFiles` overrides discovery. Adds a `dropped-side` finding when a whole-side take (take-ours/take-theirs/fallback) discards a substantial diff from the other side.
|
|
13
14
|
|
|
14
15
|
## [0.2.3] - 2026-07-06
|
|
15
16
|
|
|
@@ -8,6 +8,7 @@ declare function mergeBase(git: ConflictGitPort, a: string, b: string, opts?: Op
|
|
|
8
8
|
declare function blame(git: ConflictGitPort, path: string, opts?: BlameOptions): Promise<string>;
|
|
9
9
|
declare function grep(git: ConflictGitPort, pattern: string, opts?: GrepOptions): Promise<string>;
|
|
10
10
|
declare function diff(git: ConflictGitPort, from: string, to: string, opts?: ConflictDiffOptions): Promise<string>;
|
|
11
|
+
declare function changedFiles(git: ConflictGitPort, from: string, to: string, opts?: OpOptions): Promise<string[]>;
|
|
11
12
|
declare function log(git: ConflictGitPort, opts?: LogOptions): Promise<string>;
|
|
12
13
|
declare function show(git: ConflictGitPort, sha: string, opts?: ShowOptions): Promise<string>;
|
|
13
14
|
declare function writeFile(git: ConflictGitPort, path: string, content: string, opts?: OpOptions): Promise<void>;
|
|
@@ -15,4 +16,4 @@ declare function stageFiles(git: ConflictGitPort, paths: string[], opts?: OpOpti
|
|
|
15
16
|
declare function checkoutFile(git: ConflictGitPort, path: string, side: 'ours' | 'theirs', opts?: OpOptions): Promise<void>;
|
|
16
17
|
declare function removeFile(git: ConflictGitPort, path: string, opts?: OpOptions): Promise<void>;
|
|
17
18
|
//#endregion
|
|
18
|
-
export { blame, checkoutFile, diff, grep, log, mergeBase, readFile, removeFile, show, showFile, stageFiles, unmergedEntries, writeFile };
|
|
19
|
+
export { blame, changedFiles, checkoutFile, diff, grep, log, mergeBase, readFile, removeFile, show, showFile, stageFiles, unmergedEntries, writeFile };
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import{ConflictGitPortMissingOpError as e}from"../ports/git.js";import{sliceLines as t,truncateLines as n,truncateMatches as r}from"./truncation.js";const i={DD:`both-deleted`,AU:`added-by-us`,UD:`deleted-by-them`,UA:`added-by-them`,DU:`deleted-by-us`,AA:`both-added`,UU:`both-modified`};function a(e){return i[e]??e}function o(e){return`Search capped at ${e} matches. There may be more — narrow with a more specific pattern or path.`}function s(t,n){throw new e(t,n)}function c(e,t){return e!=null&&t!=null?`startLine=${e}, endLine=${t}`:e==null?`endLine=${t}`:`startLine=${e}`}async function l(e,t,n){return e.readFile?e.readFile(t,n):s(`readFile`)}async function u(e,r,i,a){let o;if(e.showFile)o=await e.showFile(r,i,a);else if(e.exec){let n=t(await e.exec([`show`,`${r}:${i}`],{signal:a?.signal}),a?.startLine,a?.endLine);if(!n.ok)return n.reason===`invalid-range`?`[Invalid range: ${c(n.startLine,n.endLine)} (startLine must be <= endLine).]`:`[Range out of bounds: file has ${n.total} lines, requested ${c(n.startLine,n.endLine)}.]`;o=n.content}else return s(`showFile`);return n(o,1e3,`Output capped at 1000 lines. Use startLine/endLine to read other regions of the file.`)}async function d(e,t){if(e.unmergedEntries)return e.unmergedEntries(t);if(e.exec){let n=await e.exec([`status`,`--porcelain=v2`],{signal:t?.signal}),r=[];for(let e of n.split(`
|
|
2
|
-
`)){if(!e.startsWith(`u `))continue;let t=e.split(` `),n=t[1]??``,i=t.slice(10).join(` `);r.push({path:i,reason:a(n)})}return r}return s(`unmergedEntries`)}async function f(e,t,n,r){return e.mergeBase?e.mergeBase(t,n,r):e.exec?(await e.exec([`merge-base`,`--`,t,n],{signal:r?.signal})).trim():s(`mergeBase`)}async function p(e,t,r){let i=r?.startLine,a=r?.endLine,o=Number.isFinite(i),l=Number.isFinite(a);if(o&&l&&i>a)return`[Invalid range: ${c(i,a)} (startLine must be <= endLine).]`;let u;if(e.blame)u=await e.blame(t,r);else if(e.exec){let n=[`blame`,`--porcelain`],s=o?Math.max(1,i):void 0,c=l?Math.max(1,a):void 0;s!=null&&c!=null?n.push(`-L`,`${s},${c}`):s==null?c!=null&&n.push(`-L`,`1,${c}`):n.push(`-L`,`${s},`),r?.ref&&n.push(r.ref),n.push(`--`,t),u=await e.exec(n,{signal:r?.signal})}else return s(`blame`);return n(u,1e3,`Output capped at 1000 lines. Use startLine/endLine to inspect other regions.`)}async function m(e,t,n){let i=n?.maxResults,a=i!=null&&Number.isFinite(i)?Math.min(Math.max(1,i),100):100,c;if(e.grep)c=await e.grep(t,n);else if(e.exec){let r=[`grep`,`-n`,`--`,t];n?.ref&&r.push(n.ref),c=await e.exec(r,{signal:n?.signal})}else return s(`grep`);return r(c,a,o(a))}async function h(e,t,n,r){if(e.diff)return e.diff(t,n,r);if(e.exec){let i=[`diff`,t,n];return r?.path&&i.push(`--`,r.path),e.exec(i,{signal:r?.signal})}return s(`diff`)}async function g(e,t
|
|
2
|
+
`)){if(!e.startsWith(`u `))continue;let t=e.split(` `),n=t[1]??``,i=t.slice(10).join(` `);r.push({path:i,reason:a(n)})}return r}return s(`unmergedEntries`)}async function f(e,t,n,r){return e.mergeBase?e.mergeBase(t,n,r):e.exec?(await e.exec([`merge-base`,`--`,t,n],{signal:r?.signal})).trim():s(`mergeBase`)}async function p(e,t,r){let i=r?.startLine,a=r?.endLine,o=Number.isFinite(i),l=Number.isFinite(a);if(o&&l&&i>a)return`[Invalid range: ${c(i,a)} (startLine must be <= endLine).]`;let u;if(e.blame)u=await e.blame(t,r);else if(e.exec){let n=[`blame`,`--porcelain`],s=o?Math.max(1,i):void 0,c=l?Math.max(1,a):void 0;s!=null&&c!=null?n.push(`-L`,`${s},${c}`):s==null?c!=null&&n.push(`-L`,`1,${c}`):n.push(`-L`,`${s},`),r?.ref&&n.push(r.ref),n.push(`--`,t),u=await e.exec(n,{signal:r?.signal})}else return s(`blame`);return n(u,1e3,`Output capped at 1000 lines. Use startLine/endLine to inspect other regions.`)}async function m(e,t,n){let i=n?.maxResults,a=i!=null&&Number.isFinite(i)?Math.min(Math.max(1,i),100):100,c;if(e.grep)c=await e.grep(t,n);else if(e.exec){let r=[`grep`,`-n`,`--`,t];n?.ref&&r.push(n.ref),c=await e.exec(r,{signal:n?.signal})}else return s(`grep`);return r(c,a,o(a))}async function h(e,t,n,r){if(e.diff)return e.diff(t,n,r);if(e.exec){let i=[`diff`,t,n];return r?.path&&i.push(`--`,r.path),e.exec(i,{signal:r?.signal})}return s(`diff`)}async function g(e,t,n,r){return e.changedFiles?e.changedFiles(t,n,r):e.exec?(await e.exec([`diff`,`--name-only`,t,n],{signal:r?.signal})).split(`
|
|
3
|
+
`).map(e=>e.trim()).filter(e=>e.length>0):s(`changedFiles`)}async function _(e,t){let r=t?.maxCount,i=r!=null&&Number.isFinite(r)?Math.min(Math.max(1,r),100):100,a;if(e.log)a=await e.log({...t,maxCount:i});else if(e.exec){let n=[`log`,`--oneline`,`-n`,String(i)];t?.ref&&n.push(t.ref),t?.path&&n.push(`--`,t.path),a=await e.exec(n,{signal:t?.signal})}else return s(`log`);return n(a,100,`Output capped at 100 commits. Use path to scope to a file or refine the ref range.`)}async function v(e,t,r){let i;if(e.show)i=await e.show(t,r);else if(e.exec){let n=[`show`,t];r?.path&&n.push(`--`,r.path),i=await e.exec(n,{signal:r?.signal})}else return s(`show`);return n(i,500,`Output capped at 500 lines. Use show_file_at_ref with startLine/endLine to read specific regions.`)}async function y(e,t,n,r){return e.writeFile?e.writeFile(t,n,r):s(`writeFile`)}async function b(e,t,n){if(e.stageFiles)return e.stageFiles(t,n);if(e.exec){await e.exec([`add`,`--`,...t],{signal:n?.signal});return}return s(`stageFiles`)}async function x(e,t,n,r){if(e.checkoutFile)return e.checkoutFile(t,n,r);if(e.exec){await e.exec([`checkout`,`--${n}`,`--`,t],{signal:r?.signal});return}return s(`checkoutFile`)}async function S(e,t,n){if(e.removeFile)return e.removeFile(t,n);if(e.exec){await e.exec([`rm`,`--`,t],{signal:n?.signal});return}return s(`removeFile`)}export{p as blame,g as changedFiles,x as checkoutFile,h as diff,m as grep,_ as log,f as mergeBase,l as readFile,S as removeFile,v as show,u as showFile,b as stageFiles,d as unmergedEntries,y as writeFile};
|
package/dist/ports/git.d.ts
CHANGED
|
@@ -45,6 +45,11 @@ interface ConflictGitOps {
|
|
|
45
45
|
showFile?: (ref: string, path: string, opts?: ShowFileOptions) => Promise<string>;
|
|
46
46
|
unmergedEntries?: (opts?: OpOptions) => Promise<UnmergedEntry[]>;
|
|
47
47
|
mergeBase?: (a: string, b: string, opts?: OpOptions) => Promise<string>;
|
|
48
|
+
/**
|
|
49
|
+
* Returns the paths changed between two refs (name-only). Used to discover the merge's
|
|
50
|
+
* incoming/auto-merged set for reference-integrity detection.
|
|
51
|
+
*/
|
|
52
|
+
changedFiles?: (from: string, to: string, opts?: OpOptions) => Promise<string[]>;
|
|
48
53
|
/**
|
|
49
54
|
* Returns line-by-line authorship for `path`. When `opts.startLine`/`endLine` are provided,
|
|
50
55
|
* implementations should restrict to that 1-indexed inclusive range. The library does not
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
import{buildSnapshots as e}from"./snapshot.js";async function t(t,r,o){let
|
|
1
|
+
import{buildSnapshots as e}from"./snapshot.js";async function t(t,r,o){let c=o.parser;if(!c)return{findings:[],checks:{referenceIntegrity:`skipped-no-parser`,structural:`skipped-no-parser`}};try{let l=r.refs?await e(t,r,o):null;if(l){let[e,r,o]=await Promise.all([c.analyze(l.ours),c.analyze(l.theirs),c.analyze(l.result)]);return{findings:[...n(e,r,o),...i(o),...a(t,l)],checks:{referenceIntegrity:s([e,r,o])?`partial-unsupported-language`:`ran`,structural:s([o])?`partial-unsupported-language`:`ran`},scope:{analyzed:l.analyzed,truncated:l.truncated}}}let u=new Map(t.map(e=>[e.filePath,e.content])),d=await c.analyze(u);return{findings:i(d),checks:{referenceIntegrity:`skipped-no-refs`,structural:s([d])?`partial-unsupported-language`:`ran`}}}catch{return{findings:[],checks:{referenceIntegrity:`errored`,structural:`errored`}}}}function n(e,t,n){let i=new Map;r(e,`ours`,i),r(t,`theirs`,i);let a=[];for(let[e,t]of n)for(let n of t.references){if(n.resolved)continue;let t=i.get(c(e,n.name));t&&a.push({category:`broken-reference`,severity:`error`,tier:`project`,location:{file:e,line:n.line,symbol:n.name},provenance:t,message:`Reference "${n.name}" resolved before the merge (on ${t.side}) but no longer resolves.`})}return a}function r(e,t,n){for(let[r,i]of e)for(let e of i.references){if(!e.resolved)continue;let i=c(r,e.name);n.has(i)||n.set(i,{side:t,line:e.line})}}function i(e){let t=[];for(let[n,r]of e){let e=new Map;for(let i of r.definitions){let r=e.get(i.name);r==null?e.set(i.name,i.line):t.push({category:`duplicate-definition`,severity:`error`,tier:`file`,location:{file:n,line:i.line,symbol:i.name},message:`Duplicate definition of "${i.name}" (also defined at line ${r}).`})}for(let e of r.syntaxErrors)t.push({category:`syntax-error`,severity:`error`,tier:`file`,location:{file:n,line:e.line},message:e.message})}return t}function a(e,t){let n=[];for(let r of e){let e=r.strategy===`take-ours`?`theirs`:r.strategy===`take-theirs`?`ours`:null;if(!e)continue;let i=(e===`ours`?t.ours:t.theirs).get(r.filePath);if(i==null)continue;let a=o(i,r.content);a<20||n.push({category:`dropped-side`,severity:`error`,tier:`file`,location:{file:r.filePath,line:1},message:`Resolution took "${r.strategy}" wholesale, discarding ~${a} line(s) of the ${e} side.`})}return n}function o(e,t){let n=new Set(t.split(`
|
|
2
|
+
`)),r=0;for(let t of e.split(`
|
|
3
|
+
`))t.trim()!==``&&!n.has(t)&&r++;return r}function s(e){return e.some(e=>{for(let t of e.values())if(t.language===`unsupported`)return!0;return!1})}function c(e,t){return JSON.stringify([e,t])}export{t as detect};
|
|
@@ -7,6 +7,10 @@ interface DetectionSnapshots {
|
|
|
7
7
|
ours: SourceOverlay;
|
|
8
8
|
theirs: SourceOverlay;
|
|
9
9
|
result: SourceOverlay;
|
|
10
|
+
/** Number of files actually included in the snapshots (after the cap). */
|
|
11
|
+
analyzed: number;
|
|
12
|
+
/** Whether the scope exceeded the cap and was truncated. */
|
|
13
|
+
truncated: boolean;
|
|
10
14
|
}
|
|
11
15
|
interface SnapshotDeps {
|
|
12
16
|
git: ConflictGitPort;
|
|
@@ -15,9 +19,10 @@ interface SnapshotDeps {
|
|
|
15
19
|
/**
|
|
16
20
|
* Builds the file-content overlays the detector compares: both pre-merge parents (read from git
|
|
17
21
|
* objects — no working tree needed) and the resolved result (in-memory resolutions overlaid on the
|
|
18
|
-
* surrounding files). Scope is the resolved files plus
|
|
19
|
-
*
|
|
20
|
-
*
|
|
22
|
+
* surrounding files). Scope is the resolved files plus the merge's incoming/auto-merged set, which
|
|
23
|
+
* the detector discovers itself via the git port (`changedFiles(base, theirs)`), unless the consumer
|
|
24
|
+
* supplies `context.touchedFiles` as an override. Returns `null` when `context.refs` is absent — the
|
|
25
|
+
* before/after comparison is impossible without the parent refs.
|
|
21
26
|
*/
|
|
22
27
|
declare function buildSnapshots(resolutions: Resolution[], context: ResolutionContext, deps: SnapshotDeps): Promise<DetectionSnapshots | null>;
|
|
23
28
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{changedFiles as e,mergeBase as t,readFile as n,showFile as r}from"../git/port-dispatch.js";async function i(e,t,n){let r=t.refs;if(!r)return null;let i=n.signal?{signal:n.signal}:void 0,c=new Map(e.map(e=>[e.filePath,e.content])),l=t.touchedFiles??await a(n.git,r,i),u=[],d=new Set;for(let e of[...c.keys(),...l,...t.fileNeighbors??[]])d.has(e)||(d.add(e),u.push(e));let f=u.length>400,p=f?u.slice(0,400):u,m=new Map,h=new Map,g=new Map;for(let e of p){let t=await o(n.git,r.ours,e,i);t!=null&&m.set(e,t);let a=await o(n.git,r.theirs,e,i);a!=null&&h.set(e,a);let l=c.get(e);if(l!=null)g.set(e,l);else{let t=await s(n.git,e,i);t!=null&&g.set(e,t)}}return{ours:m,theirs:h,result:g,analyzed:p.length,truncated:f}}async function a(n,r,i){try{return await e(n,r.base??await t(n,r.ours,r.theirs,i),r.theirs,i)}catch{return[]}}async function o(e,t,n,i){try{return await r(e,t,n,i)}catch{return null}}async function s(e,t,r){try{return await n(e,t,r)}catch{return null}}export{i as buildSnapshots};
|
package/dist/types/findings.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//#region src/types/findings.d.ts
|
|
2
|
-
type FindingCategory = 'broken-reference' | 'duplicate-definition' | 'syntax-error';
|
|
2
|
+
type FindingCategory = 'broken-reference' | 'duplicate-definition' | 'syntax-error' | 'dropped-side';
|
|
3
3
|
type FindingTier = 'file' | 'project';
|
|
4
4
|
interface Finding {
|
|
5
5
|
category: FindingCategory;
|
|
@@ -27,6 +27,13 @@ interface DetectionReport {
|
|
|
27
27
|
referenceIntegrity: CheckStatus;
|
|
28
28
|
structural: CheckStatus;
|
|
29
29
|
};
|
|
30
|
+
/** How many files were analyzed and whether the scope was capped — an honest coverage signal so
|
|
31
|
+
* empty findings on a truncated scope are not read as "clean". Present only when the reference
|
|
32
|
+
* check ran (refs available). */
|
|
33
|
+
scope?: {
|
|
34
|
+
analyzed: number;
|
|
35
|
+
truncated: boolean;
|
|
36
|
+
};
|
|
30
37
|
}
|
|
31
38
|
//#endregion
|
|
32
39
|
export { CheckStatus, DetectionReport, Finding, FindingCategory, FindingTier };
|
|
@@ -69,6 +69,10 @@ interface ResolutionContext {
|
|
|
69
69
|
prDescription?: string;
|
|
70
70
|
previousResolutions?: Resolution[];
|
|
71
71
|
fileNeighbors?: string[];
|
|
72
|
+
/** Files the merge/sync touched beyond the conflict set (chiefly auto-merged incoming changes).
|
|
73
|
+
* Usually left unset — the reference-integrity detector discovers this set itself from `refs`.
|
|
74
|
+
* When provided, it overrides auto-discovery and defines the incoming detection scope. */
|
|
75
|
+
touchedFiles?: string[];
|
|
72
76
|
refs?: ResolutionRefs;
|
|
73
77
|
threeWayDiff?: ThreeWayDiff;
|
|
74
78
|
/** Free-text guidance from the user that applies to the whole file ("prefer logging across the
|