@sackville-mcp/diff 0.0.1-alpha.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 ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or Derivative
95
+ Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Curtis Autery
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # @sackville-mcp/diff
2
+
3
+ The shared changed-set primitive: pure, zero-dependency unified-diff parsing.
4
+
5
+ Extracted out of `@sackville-mcp/coverage` (mirroring the `@sackville-mcp/safety` /
6
+ `@sackville-mcp/assert` / `@sackville-mcp/artifacts` extractions) the moment a second
7
+ consumer appeared — milestone 5d diff-scopes every verification pillar from one
8
+ diff, and `@sackville-mcp/verify` must runtime-import the parser to derive each
9
+ pillar's scope. Keeping it a dependency-free package is what lets `verify` import
10
+ it without dragging in a pillar's spawn-capable code (its zero-spawn invariant).
11
+
12
+ ## API
13
+
14
+ - `parseUnifiedDiff(diff)` → `DiffFile[]` — per-file new-side **added line
15
+ numbers** (feeds the coverage forgotten-assertion catch). Omits files that
16
+ gained no lines.
17
+ - `changedFiles(diff)` → `string[]` — the **non-deleted paths** a change touched
18
+ (the scope primitive: which tests to re-run, which files to mutate, which
19
+ packages to audit). Includes removal-only modifications and new files; excludes
20
+ deleted files.
21
+
22
+ Both are pure and offline — producing the diff (`git diff`) and reconciling paths
23
+ to coverage keys / package manifests are caller concerns.
@@ -0,0 +1,50 @@
1
+ //#region src/diff.d.ts
2
+ /**
3
+ * Unified-diff parsing — the shared changed-set primitive. Given a unified diff
4
+ * (`git diff` / `diff -u` output), two pure derivations:
5
+ *
6
+ * - {@link parseUnifiedDiff} — the set of lines each file *gained* on the new side
7
+ * (feeds the coverage pillar's forgotten-assertion catch: "of the lines this change
8
+ * introduced, which executable ones were never hit by a test").
9
+ * - {@link changedFiles} — the set of non-deleted files a change touched (the scope
10
+ * primitive: which tests to re-run, which files to mutate, which packages to audit).
11
+ *
12
+ * Pure and offline: producing the diff (shelling out to `git`) and matching its
13
+ * repo-relative paths to absolute keys / package manifests are caller concerns.
14
+ * Keeping the parse pure is what lets every consuming gate stay deterministic — and
15
+ * what lets `@sackville-mcp/verify` runtime-import this without dragging in a pillar's
16
+ * spawn-capable code (this package has zero dependencies).
17
+ *
18
+ * The parser is a state machine that tracks each hunk's declared line counts (from its
19
+ * `@@ -a,b +c,d @@` header) and ends the hunk exactly when those are consumed. That is
20
+ * what lets it tell a file header (`--- `/`+++ `) apart from a removed/added line whose
21
+ * *content* starts with `-`/`+` (e.g. `--- foo`): inside a live hunk every line is body,
22
+ * classified by its first character; once the counts are exhausted, the next `--- `/
23
+ * `+++ ` is a header again — so it is correct even for prefix-less multi-file diffs.
24
+ */
25
+ interface DiffFile {
26
+ /** New-side path, `a/`/`b/` prefix stripped (repo-relative as git emits it). */
27
+ path: string;
28
+ /** Added (new-side) line numbers, sorted ascending, deduped. */
29
+ addedLines: number[];
30
+ }
31
+ /**
32
+ * Parse a unified diff into per-file added-line sets. Files with no new-side lines
33
+ * (pure deletions, or a `+++ /dev/null` target) are omitted. Result is sorted by path.
34
+ */
35
+ declare function parseUnifiedDiff(diff: string): DiffFile[];
36
+ /**
37
+ * The new-side paths a change touched, deduped and sorted — the scope primitive.
38
+ *
39
+ * Distinct from {@link parseUnifiedDiff}, which omits any file that did not *gain*
40
+ * a line: `changedFiles` also includes a file that was modified by removals only
41
+ * (its tests should still re-run). It excludes a deleted file (`+++ /dev/null`) —
42
+ * a gone file is not a test/mutation/audit target. New files are included.
43
+ *
44
+ * Uses the same hunk state machine so a body line beginning with `+++ ` is never
45
+ * mistaken for a file header.
46
+ */
47
+ declare function changedFiles(diff: string): string[];
48
+ //#endregion
49
+ export { type DiffFile, changedFiles, parseUnifiedDiff };
50
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/diff.ts"],"mappings":";;AAwBA;;;;AAIY;AAeZ;;;;AAAwD;AA4ExD;;;;AAAyC;;;;;;;;UA/FxB,QAAA;;EAEf,IAAA;;EAEA,UAAU;AAAA;;;;;iBAeI,gBAAA,CAAiB,IAAA,WAAe,QAAQ;;;;;;;;;;;;iBA4ExC,YAAA,CAAa,IAAY"}
package/dist/index.mjs ADDED
@@ -0,0 +1,113 @@
1
+ //#region src/diff.ts
2
+ const HUNK = /^@@ -\d+(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/;
3
+ /** Strip a leading `a/` or `b/` prefix and any trailing tab-timestamp (POSIX diff). */
4
+ function cleanPath(raw) {
5
+ return (raw.split(" ")[0] ?? raw).replace(/^[ab]\//, "");
6
+ }
7
+ /**
8
+ * Parse a unified diff into per-file added-line sets. Files with no new-side lines
9
+ * (pure deletions, or a `+++ /dev/null` target) are omitted. Result is sorted by path.
10
+ */
11
+ function parseUnifiedDiff(diff) {
12
+ const added = /* @__PURE__ */ new Map();
13
+ let currentFile = null;
14
+ let newLine = 0;
15
+ let remainingOld = 0;
16
+ let remainingNew = 0;
17
+ const inHunk = () => remainingOld > 0 || remainingNew > 0;
18
+ for (const rawLine of diff.split("\n")) {
19
+ const line = rawLine.endsWith("\r") ? rawLine.slice(0, -1) : rawLine;
20
+ if (line.startsWith("diff --git")) {
21
+ remainingOld = 0;
22
+ remainingNew = 0;
23
+ currentFile = null;
24
+ continue;
25
+ }
26
+ const hunk = HUNK.exec(line);
27
+ if (hunk) {
28
+ newLine = Number(hunk[2]);
29
+ remainingOld = hunk[1] === void 0 ? 1 : Number(hunk[1]);
30
+ remainingNew = hunk[3] === void 0 ? 1 : Number(hunk[3]);
31
+ continue;
32
+ }
33
+ if (inHunk()) {
34
+ const marker = line[0];
35
+ if (marker === "+") {
36
+ if (currentFile !== null) {
37
+ let set = added.get(currentFile);
38
+ if (set === void 0) {
39
+ set = /* @__PURE__ */ new Set();
40
+ added.set(currentFile, set);
41
+ }
42
+ set.add(newLine);
43
+ }
44
+ newLine++;
45
+ remainingNew--;
46
+ } else if (marker === "-") remainingOld--;
47
+ else if (marker === "\\") {} else {
48
+ newLine++;
49
+ remainingNew--;
50
+ remainingOld--;
51
+ }
52
+ continue;
53
+ }
54
+ if (line.startsWith("+++ ")) {
55
+ const path = cleanPath(line.slice(4));
56
+ currentFile = path === "/dev/null" ? null : path;
57
+ }
58
+ }
59
+ return [...added.entries()].map(([path, set]) => ({
60
+ path,
61
+ addedLines: [...set].sort((a, b) => a - b)
62
+ })).sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0);
63
+ }
64
+ /**
65
+ * The new-side paths a change touched, deduped and sorted — the scope primitive.
66
+ *
67
+ * Distinct from {@link parseUnifiedDiff}, which omits any file that did not *gain*
68
+ * a line: `changedFiles` also includes a file that was modified by removals only
69
+ * (its tests should still re-run). It excludes a deleted file (`+++ /dev/null`) —
70
+ * a gone file is not a test/mutation/audit target. New files are included.
71
+ *
72
+ * Uses the same hunk state machine so a body line beginning with `+++ ` is never
73
+ * mistaken for a file header.
74
+ */
75
+ function changedFiles(diff) {
76
+ const files = /* @__PURE__ */ new Set();
77
+ let remainingOld = 0;
78
+ let remainingNew = 0;
79
+ const inHunk = () => remainingOld > 0 || remainingNew > 0;
80
+ for (const rawLine of diff.split("\n")) {
81
+ const line = rawLine.endsWith("\r") ? rawLine.slice(0, -1) : rawLine;
82
+ if (line.startsWith("diff --git")) {
83
+ remainingOld = 0;
84
+ remainingNew = 0;
85
+ continue;
86
+ }
87
+ const hunk = HUNK.exec(line);
88
+ if (hunk) {
89
+ remainingOld = hunk[1] === void 0 ? 1 : Number(hunk[1]);
90
+ remainingNew = hunk[3] === void 0 ? 1 : Number(hunk[3]);
91
+ continue;
92
+ }
93
+ if (inHunk()) {
94
+ const marker = line[0];
95
+ if (marker === "+") remainingNew--;
96
+ else if (marker === "-") remainingOld--;
97
+ else if (marker === "\\") {} else {
98
+ remainingNew--;
99
+ remainingOld--;
100
+ }
101
+ continue;
102
+ }
103
+ if (line.startsWith("+++ ")) {
104
+ const path = cleanPath(line.slice(4));
105
+ if (path !== "/dev/null") files.add(path);
106
+ }
107
+ }
108
+ return [...files].sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
109
+ }
110
+ //#endregion
111
+ export { changedFiles, parseUnifiedDiff };
112
+
113
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/diff.ts"],"sourcesContent":["/**\n * Unified-diff parsing — the shared changed-set primitive. Given a unified diff\n * (`git diff` / `diff -u` output), two pure derivations:\n *\n * - {@link parseUnifiedDiff} — the set of lines each file *gained* on the new side\n * (feeds the coverage pillar's forgotten-assertion catch: \"of the lines this change\n * introduced, which executable ones were never hit by a test\").\n * - {@link changedFiles} — the set of non-deleted files a change touched (the scope\n * primitive: which tests to re-run, which files to mutate, which packages to audit).\n *\n * Pure and offline: producing the diff (shelling out to `git`) and matching its\n * repo-relative paths to absolute keys / package manifests are caller concerns.\n * Keeping the parse pure is what lets every consuming gate stay deterministic — and\n * what lets `@sackville-mcp/verify` runtime-import this without dragging in a pillar's\n * spawn-capable code (this package has zero dependencies).\n *\n * The parser is a state machine that tracks each hunk's declared line counts (from its\n * `@@ -a,b +c,d @@` header) and ends the hunk exactly when those are consumed. That is\n * what lets it tell a file header (`--- `/`+++ `) apart from a removed/added line whose\n * *content* starts with `-`/`+` (e.g. `--- foo`): inside a live hunk every line is body,\n * classified by its first character; once the counts are exhausted, the next `--- `/\n * `+++ ` is a header again — so it is correct even for prefix-less multi-file diffs.\n */\n\nexport interface DiffFile {\n /** New-side path, `a/`/`b/` prefix stripped (repo-relative as git emits it). */\n path: string\n /** Added (new-side) line numbers, sorted ascending, deduped. */\n addedLines: number[]\n}\n\nconst HUNK = /^@@ -\\d+(?:,(\\d+))? \\+(\\d+)(?:,(\\d+))? @@/\n\n/** Strip a leading `a/` or `b/` prefix and any trailing tab-timestamp (POSIX diff). */\nfunction cleanPath(raw: string): string {\n const path = raw.split('\\t')[0] ?? raw\n return path.replace(/^[ab]\\//, '')\n}\n\n/**\n * Parse a unified diff into per-file added-line sets. Files with no new-side lines\n * (pure deletions, or a `+++ /dev/null` target) are omitted. Result is sorted by path.\n */\nexport function parseUnifiedDiff(diff: string): DiffFile[] {\n const added = new Map<string, Set<number>>()\n let currentFile: string | null = null\n let newLine = 0\n let remainingOld = 0\n let remainingNew = 0\n const inHunk = () => remainingOld > 0 || remainingNew > 0\n\n for (const rawLine of diff.split('\\n')) {\n const line = rawLine.endsWith('\\r') ? rawLine.slice(0, -1) : rawLine\n\n // A new file header / hunk header always delimits, even mid-hunk.\n if (line.startsWith('diff --git')) {\n remainingOld = 0\n remainingNew = 0\n currentFile = null\n continue\n }\n const hunk = HUNK.exec(line)\n if (hunk) {\n newLine = Number(hunk[2])\n remainingOld = hunk[1] === undefined ? 1 : Number(hunk[1])\n remainingNew = hunk[3] === undefined ? 1 : Number(hunk[3])\n continue\n }\n\n if (inHunk()) {\n const marker = line[0]\n if (marker === '+') {\n if (currentFile !== null) {\n let set = added.get(currentFile)\n if (set === undefined) {\n set = new Set()\n added.set(currentFile, set)\n }\n set.add(newLine)\n }\n newLine++\n remainingNew--\n } else if (marker === '-') {\n remainingOld--\n } else if (marker === '\\\\') {\n // \"\\" — annotates the previous line, counts for neither.\n } else {\n // Context line (' ' prefix, or a trailing-space-stripped blank).\n newLine++\n remainingNew--\n remainingOld--\n }\n continue\n }\n\n // Outside a hunk: file headers (the `+++` new-side path drives `currentFile`).\n if (line.startsWith('+++ ')) {\n const path = cleanPath(line.slice(4))\n currentFile = path === '/dev/null' ? null : path\n }\n // `--- ` (old-side) and other header lines (index, mode, …) need no action.\n }\n\n return [...added.entries()]\n .map(([path, set]) => ({ path, addedLines: [...set].sort((a, b) => a - b) }))\n .sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0))\n}\n\n/**\n * The new-side paths a change touched, deduped and sorted — the scope primitive.\n *\n * Distinct from {@link parseUnifiedDiff}, which omits any file that did not *gain*\n * a line: `changedFiles` also includes a file that was modified by removals only\n * (its tests should still re-run). It excludes a deleted file (`+++ /dev/null`) —\n * a gone file is not a test/mutation/audit target. New files are included.\n *\n * Uses the same hunk state machine so a body line beginning with `+++ ` is never\n * mistaken for a file header.\n */\nexport function changedFiles(diff: string): string[] {\n const files = new Set<string>()\n let remainingOld = 0\n let remainingNew = 0\n const inHunk = () => remainingOld > 0 || remainingNew > 0\n\n for (const rawLine of diff.split('\\n')) {\n const line = rawLine.endsWith('\\r') ? rawLine.slice(0, -1) : rawLine\n\n if (line.startsWith('diff --git')) {\n remainingOld = 0\n remainingNew = 0\n continue\n }\n const hunk = HUNK.exec(line)\n if (hunk) {\n remainingOld = hunk[1] === undefined ? 1 : Number(hunk[1])\n remainingNew = hunk[3] === undefined ? 1 : Number(hunk[3])\n continue\n }\n\n if (inHunk()) {\n const marker = line[0]\n if (marker === '+') {\n remainingNew--\n } else if (marker === '-') {\n remainingOld--\n } else if (marker === '\\\\') {\n // no-op\n } else {\n remainingNew--\n remainingOld--\n }\n continue\n }\n\n if (line.startsWith('+++ ')) {\n const path = cleanPath(line.slice(4))\n if (path !== '/dev/null') files.add(path)\n }\n }\n\n return [...files].sort((a, b) => (a < b ? -1 : a > b ? 1 : 0))\n}\n"],"mappings":"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"}
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@sackville-mcp/diff",
3
+ "version": "0.0.1-alpha.0",
4
+ "type": "module",
5
+ "license": "Apache-2.0",
6
+ "exports": {
7
+ ".": {
8
+ "import": {
9
+ "types": "./dist/index.d.mts",
10
+ "default": "./dist/index.mjs"
11
+ }
12
+ }
13
+ },
14
+ "main": "./dist/index.mjs",
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/ceautery/sackville.git",
24
+ "directory": "packages/diff"
25
+ },
26
+ "scripts": {
27
+ "build": "tsdown src/index.ts --dts",
28
+ "typecheck": "tsc --noEmit"
29
+ }
30
+ }