@self-review/core 2.0.4 → 2.1.3

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 (68) hide show
  1. package/README.md +441 -0
  2. package/dist/chunk-5SGPWHGH.cjs +106 -0
  3. package/dist/chunk-5SGPWHGH.cjs.map +1 -0
  4. package/dist/chunk-6OEFXBIZ.cjs +5212 -0
  5. package/dist/chunk-6OEFXBIZ.cjs.map +1 -0
  6. package/dist/chunk-6X3PJHP5.cjs +416 -0
  7. package/dist/chunk-6X3PJHP5.cjs.map +1 -0
  8. package/dist/chunk-CJQEOLI3.js +37 -0
  9. package/dist/chunk-CJQEOLI3.js.map +1 -0
  10. package/dist/chunk-IG2YF5LH.js +416 -0
  11. package/dist/chunk-IG2YF5LH.js.map +1 -0
  12. package/dist/chunk-IX226KG4.js +106 -0
  13. package/dist/chunk-IX226KG4.js.map +1 -0
  14. package/dist/chunk-LSLCQQBN.cjs +3684 -0
  15. package/dist/chunk-LSLCQQBN.cjs.map +1 -0
  16. package/dist/chunk-MOYO4RIX.js +3684 -0
  17. package/dist/chunk-MOYO4RIX.js.map +1 -0
  18. package/dist/chunk-TOUYY7I6.js +5212 -0
  19. package/dist/chunk-TOUYY7I6.js.map +1 -0
  20. package/dist/chunk-VOYTFLPH.cjs +37 -0
  21. package/dist/chunk-VOYTFLPH.cjs.map +1 -0
  22. package/dist/filesystem.cjs +56 -0
  23. package/dist/filesystem.cjs.map +1 -0
  24. package/dist/filesystem.d.cts +22 -0
  25. package/dist/filesystem.d.ts +22 -0
  26. package/dist/filesystem.js +56 -0
  27. package/dist/index.cjs +348 -6192
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.cts +80 -1332
  30. package/dist/index.d.ts +80 -1332
  31. package/dist/index.js +234 -5172
  32. package/dist/index.js.map +1 -1
  33. package/dist/node-scan-fs-CaufzUZR.d.cts +5 -0
  34. package/dist/node-scan-fs-DcHI_BYB.d.ts +5 -0
  35. package/dist/operations-Bqhi9EBH.d.ts +765 -0
  36. package/dist/operations-UyiUD2Nx.d.cts +765 -0
  37. package/dist/operations.cjs +91 -0
  38. package/dist/operations.cjs.map +1 -0
  39. package/dist/operations.d.cts +6 -0
  40. package/dist/operations.d.ts +6 -0
  41. package/dist/operations.js +91 -0
  42. package/dist/resume-worker.cjs +152 -0
  43. package/dist/resume-worker.cjs.map +1 -0
  44. package/dist/resume-worker.d.cts +56 -0
  45. package/dist/resume-worker.d.ts +56 -0
  46. package/dist/resume-worker.js +152 -0
  47. package/dist/resume-worker.js.map +1 -0
  48. package/dist/review-request-validation-VJG7XZiE.d.cts +62 -0
  49. package/dist/review-request-validation-VJG7XZiE.d.ts +62 -0
  50. package/dist/review-xml-decoder-COgRtfkf.d.cts +33 -0
  51. package/dist/review-xml-decoder-COgRtfkf.d.ts +33 -0
  52. package/dist/source-identity-CQpAzugz.d.cts +959 -0
  53. package/dist/source-identity-CQpAzugz.d.ts +959 -0
  54. package/dist/validation.cjs +67 -0
  55. package/dist/validation.cjs.map +1 -0
  56. package/dist/validation.d.cts +30 -0
  57. package/dist/validation.d.ts +30 -0
  58. package/dist/validation.js +67 -0
  59. package/dist/validation.js.map +1 -0
  60. package/package.json +44 -3
  61. package/dist/chunk-4YO2MI6B.js +0 -269
  62. package/dist/chunk-4YO2MI6B.js.map +0 -1
  63. package/dist/chunk-QHS36X6T.js +0 -450
  64. package/dist/chunk-QHS36X6T.js.map +0 -1
  65. package/dist/diff-parser-B6S3KG5T.js +0 -9
  66. package/dist/git-N5HVNPKQ.js +0 -24
  67. /package/dist/{diff-parser-B6S3KG5T.js.map → filesystem.js.map} +0 -0
  68. /package/dist/{git-N5HVNPKQ.js.map → operations.js.map} +0 -0
@@ -0,0 +1,67 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+
4
+ var _chunkVOYTFLPHcjs = require('./chunk-VOYTFLPH.cjs');
5
+
6
+
7
+ var _chunk5SGPWHGHcjs = require('./chunk-5SGPWHGH.cjs');
8
+
9
+
10
+
11
+ var _chunk6X3PJHP5cjs = require('./chunk-6X3PJHP5.cjs');
12
+
13
+ // src/same-diff-source.ts
14
+ function sameDiffSource(loaded, submitted) {
15
+ if (loaded.type !== submitted.type) return false;
16
+ switch (loaded.type) {
17
+ case "git":
18
+ return submitted.type === "git" && loaded.repository === submitted.repository && loaded.gitDiffArgs === submitted.gitDiffArgs;
19
+ case "directory":
20
+ case "file":
21
+ return (submitted.type === "directory" || submitted.type === "file") && loaded.sourcePath === submitted.sourcePath;
22
+ case "welcome":
23
+ case "loading":
24
+ return true;
25
+ }
26
+ }
27
+
28
+ // src/publication-ownership.ts
29
+ function provenance(remote) {
30
+ if (!remote) return void 0;
31
+ return {
32
+ remoteUrl: remote.remoteUrl,
33
+ remoteForge: remote.remoteForge,
34
+ remoteBaseSha: remote.remoteBaseSha,
35
+ remoteHeadSha: remote.remoteHeadSha
36
+ };
37
+ }
38
+ function capturePublicationOwnership(loaded) {
39
+ if (!loaded || loaded.source.type === "welcome" || loaded.source.type === "loading") return null;
40
+ return { loaded, source: { ...loaded.source }, remote: provenance(loaded.remote) };
41
+ }
42
+ function normalizePublicationState(state, current, admitted) {
43
+ if (!admitted || !current || current !== admitted.loaded || !state.source || !sameDiffSource(admitted.source, current.source) || !sameDiffSource(admitted.source, state.source))
44
+ return null;
45
+ const remote = provenance(current.remote);
46
+ if (_optionalChain([remote, 'optionalAccess', _ => _.remoteUrl]) !== _optionalChain([admitted, 'access', _2 => _2.remote, 'optionalAccess', _3 => _3.remoteUrl]) || _optionalChain([remote, 'optionalAccess', _4 => _4.remoteForge]) !== _optionalChain([admitted, 'access', _5 => _5.remote, 'optionalAccess', _6 => _6.remoteForge]) || _optionalChain([remote, 'optionalAccess', _7 => _7.remoteBaseSha]) !== _optionalChain([admitted, 'access', _8 => _8.remote, 'optionalAccess', _9 => _9.remoteBaseSha]) || _optionalChain([remote, 'optionalAccess', _10 => _10.remoteHeadSha]) !== _optionalChain([admitted, 'access', _11 => _11.remote, 'optionalAccess', _12 => _12.remoteHeadSha]))
47
+ return null;
48
+ const {
49
+ remoteUrl: _url,
50
+ remoteForge: _forge,
51
+ remoteBaseSha: _base,
52
+ remoteHeadSha: _head,
53
+ ...local
54
+ } = state;
55
+ return { ...local, ...admitted.remote };
56
+ }
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+ exports.MAX_CONTEXT_LINES = _chunkVOYTFLPHcjs.MAX_CONTEXT_LINES; exports.ReviewXmlError = _chunk6X3PJHP5cjs.ReviewXmlError; exports.capturePublicationOwnership = capturePublicationOwnership; exports.decodeSuggestionApplyRequest = _chunkVOYTFLPHcjs.decodeSuggestionApplyRequest; exports.normalizeConfigFontSize = _chunk5SGPWHGHcjs.normalizeConfigFontSize; exports.normalizePublicationState = normalizePublicationState; exports.sameDiffSource = sameDiffSource; exports.validateReviewState = _chunk6X3PJHP5cjs.validateReviewState;
67
+ //# sourceMappingURL=validation.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/self-review/self-review/packages/core/dist/validation.cjs","../src/same-diff-source.ts","../src/publication-ownership.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACE;AACA;AACF,wDAA6B;AAC7B;AACA;ACPO,SAAS,cAAA,CAAe,MAAA,EAAoB,SAAA,EAAgC;AACjF,EAAA,GAAA,CAAI,MAAA,CAAO,KAAA,IAAS,SAAA,CAAU,IAAA,EAAM,OAAO,KAAA;AAC3C,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A,GACD,CAAC,QAAA,GACD,QAAA,IAAY,QAAA,CAAS,OAAA,GACrB,CAAC,KAAA,CAAM,OAAA,GACP,CAAC,cAAA,CAAe,QAAA,CAAS,MAAA,EAAQ,OAAA,CAAQ,MAAM,EAAA,GAC/C,CAAC,cAAA,CAAe,QAAA,CAAS,MAAA,EAAQ,KAAA,CAAM,MAAM,CAAA;AAE7C,IAAA,OAAO,IAAA;AACT,EAAA,MAAM,OAAA,EAAS,UAAA,CAAW,OAAA,CAAQ,MAAM,CAAA;AACxC,EAAA,GAAA,iBACE,MAAA,2BAAQ,YAAA,oBAAc,QAAA,qBAAS,MAAA,6BAAQ,YAAA,mBACvC,MAAA,6BAAQ,cAAA,oBAAgB,QAAA,qBAAS,MAAA,6BAAQ,cAAA,mBACzC,MAAA,6BAAQ,gBAAA,oBAAkB,QAAA,qBAAS,MAAA,6BAAQ,gBAAA,mBAC3C,MAAA,+BAAQ,gBAAA,oBAAkB,QAAA,uBAAS,MAAA,+BAAQ,eAAA;AAE3C,IAAA,OAAO,IAAA;AACT,EAAA,MAAM;AAAA,IACJ,SAAA,EAAW,IAAA;AAAA,IACX,WAAA,EAAa,MAAA;AAAA,IACb,aAAA,EAAe,KAAA;AAAA,IACf,aAAA,EAAe,KAAA;AAAA,IACf,GAAG;AAAA,EACL,EAAA,EAAI,KAAA;AACJ,EAAA,OAAO,EAAE,GAAG,KAAA,EAAO,GAAG,QAAA,CAAS,OAAO,CAAA;AACxC;AFXA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,+gBAAC","file":"/home/runner/work/self-review/self-review/packages/core/dist/validation.cjs","sourcesContent":[null,"import type { DiffSource } from './types';\n\n/** Compare only canonical source fields, without normalizing their exact string values.\n * This is DTO equality, not permission to publish a welcome/loading source or provenance.\n */\nexport function sameDiffSource(loaded: DiffSource, submitted: DiffSource): boolean {\n if (loaded.type !== submitted.type) return false;\n switch (loaded.type) {\n case 'git':\n return (\n submitted.type === 'git' &&\n loaded.repository === submitted.repository &&\n loaded.gitDiffArgs === submitted.gitDiffArgs\n );\n case 'directory':\n case 'file':\n return (\n (submitted.type === 'directory' || submitted.type === 'file') &&\n loaded.sourcePath === submitted.sourcePath\n );\n case 'welcome':\n case 'loading':\n return true;\n }\n}\n","// Pure publication ownership policy. Hosts translate refusal with their installed error classes.\nimport type { DiffLoadPayload, DiffSource, RemoteSessionInfo, ReviewState } from './types';\nimport { sameDiffSource } from './same-diff-source';\n\ntype LoadedReview = Pick<DiffLoadPayload, 'source' | 'remote'>;\ntype Provenance = Pick<\n RemoteSessionInfo,\n 'remoteUrl' | 'remoteForge' | 'remoteBaseSha' | 'remoteHeadSha'\n>;\n\nexport interface PublicationOwnership {\n readonly loaded: LoadedReview;\n readonly source: DiffSource;\n readonly remote: Provenance | undefined;\n}\n\nfunction provenance(remote: RemoteSessionInfo | undefined): Provenance | undefined {\n if (!remote) return undefined;\n return {\n remoteUrl: remote.remoteUrl,\n remoteForge: remote.remoteForge,\n remoteBaseSha: remote.remoteBaseSha,\n remoteHeadSha: remote.remoteHeadSha,\n };\n}\n\n/** Capture before asynchronous admission work; preserve the loaded object's public reference alias. */\nexport function capturePublicationOwnership(\n loaded: LoadedReview | null\n): PublicationOwnership | null {\n if (!loaded || loaded.source.type === 'welcome' || loaded.source.type === 'loading') return null;\n return { loaded, source: { ...loaded.source }, remote: provenance(loaded.remote) };\n}\n\n/** Refuse absent, foreign or replaced loads, including in-place canonical source/provenance changes.\n * Keep legitimate state/source extensions; only the four host-owned provenance fields are replaced.\n */\nexport function normalizePublicationState(\n state: ReviewState,\n current: LoadedReview | null,\n admitted: PublicationOwnership | null\n): ReviewState | null {\n if (\n !admitted ||\n !current ||\n current !== admitted.loaded ||\n !state.source ||\n !sameDiffSource(admitted.source, current.source) ||\n !sameDiffSource(admitted.source, state.source)\n )\n return null;\n const remote = provenance(current.remote);\n if (\n remote?.remoteUrl !== admitted.remote?.remoteUrl ||\n remote?.remoteForge !== admitted.remote?.remoteForge ||\n remote?.remoteBaseSha !== admitted.remote?.remoteBaseSha ||\n remote?.remoteHeadSha !== admitted.remote?.remoteHeadSha\n )\n return null;\n const {\n remoteUrl: _url,\n remoteForge: _forge,\n remoteBaseSha: _base,\n remoteHeadSha: _head,\n ...local\n } = state;\n return { ...local, ...admitted.remote };\n}\n"]}
@@ -0,0 +1,30 @@
1
+ export { M as MAX_CONTEXT_LINES, R as ReviewXmlError, d as decodeSuggestionApplyRequest, v as validateReviewState } from './review-request-validation-VJG7XZiE.cjs';
2
+ import { DiffSource, DiffLoadPayload, RemoteSessionInfo, ReviewState } from '@self-review/types';
3
+
4
+ /** Compare only canonical source fields, without normalizing their exact string values.
5
+ * This is DTO equality, not permission to publish a welcome/loading source or provenance.
6
+ */
7
+ declare function sameDiffSource(loaded: DiffSource, submitted: DiffSource): boolean;
8
+
9
+ declare function normalizeConfigFontSize<T extends {
10
+ fontSize: number;
11
+ }>(config: T, fallback?: number): {
12
+ config: T;
13
+ diagnostic?: string;
14
+ };
15
+
16
+ type LoadedReview = Pick<DiffLoadPayload, 'source' | 'remote'>;
17
+ type Provenance = Pick<RemoteSessionInfo, 'remoteUrl' | 'remoteForge' | 'remoteBaseSha' | 'remoteHeadSha'>;
18
+ interface PublicationOwnership {
19
+ readonly loaded: LoadedReview;
20
+ readonly source: DiffSource;
21
+ readonly remote: Provenance | undefined;
22
+ }
23
+ /** Capture before asynchronous admission work; preserve the loaded object's public reference alias. */
24
+ declare function capturePublicationOwnership(loaded: LoadedReview | null): PublicationOwnership | null;
25
+ /** Refuse absent, foreign or replaced loads, including in-place canonical source/provenance changes.
26
+ * Keep legitimate state/source extensions; only the four host-owned provenance fields are replaced.
27
+ */
28
+ declare function normalizePublicationState(state: ReviewState, current: LoadedReview | null, admitted: PublicationOwnership | null): ReviewState | null;
29
+
30
+ export { type PublicationOwnership, capturePublicationOwnership, normalizeConfigFontSize, normalizePublicationState, sameDiffSource };
@@ -0,0 +1,30 @@
1
+ export { M as MAX_CONTEXT_LINES, R as ReviewXmlError, d as decodeSuggestionApplyRequest, v as validateReviewState } from './review-request-validation-VJG7XZiE.js';
2
+ import { DiffSource, DiffLoadPayload, RemoteSessionInfo, ReviewState } from '@self-review/types';
3
+
4
+ /** Compare only canonical source fields, without normalizing their exact string values.
5
+ * This is DTO equality, not permission to publish a welcome/loading source or provenance.
6
+ */
7
+ declare function sameDiffSource(loaded: DiffSource, submitted: DiffSource): boolean;
8
+
9
+ declare function normalizeConfigFontSize<T extends {
10
+ fontSize: number;
11
+ }>(config: T, fallback?: number): {
12
+ config: T;
13
+ diagnostic?: string;
14
+ };
15
+
16
+ type LoadedReview = Pick<DiffLoadPayload, 'source' | 'remote'>;
17
+ type Provenance = Pick<RemoteSessionInfo, 'remoteUrl' | 'remoteForge' | 'remoteBaseSha' | 'remoteHeadSha'>;
18
+ interface PublicationOwnership {
19
+ readonly loaded: LoadedReview;
20
+ readonly source: DiffSource;
21
+ readonly remote: Provenance | undefined;
22
+ }
23
+ /** Capture before asynchronous admission work; preserve the loaded object's public reference alias. */
24
+ declare function capturePublicationOwnership(loaded: LoadedReview | null): PublicationOwnership | null;
25
+ /** Refuse absent, foreign or replaced loads, including in-place canonical source/provenance changes.
26
+ * Keep legitimate state/source extensions; only the four host-owned provenance fields are replaced.
27
+ */
28
+ declare function normalizePublicationState(state: ReviewState, current: LoadedReview | null, admitted: PublicationOwnership | null): ReviewState | null;
29
+
30
+ export { type PublicationOwnership, capturePublicationOwnership, normalizeConfigFontSize, normalizePublicationState, sameDiffSource };
@@ -0,0 +1,67 @@
1
+ import {
2
+ MAX_CONTEXT_LINES,
3
+ decodeSuggestionApplyRequest
4
+ } from "./chunk-CJQEOLI3.js";
5
+ import {
6
+ normalizeConfigFontSize
7
+ } from "./chunk-IX226KG4.js";
8
+ import {
9
+ ReviewXmlError,
10
+ validateReviewState
11
+ } from "./chunk-IG2YF5LH.js";
12
+
13
+ // src/same-diff-source.ts
14
+ function sameDiffSource(loaded, submitted) {
15
+ if (loaded.type !== submitted.type) return false;
16
+ switch (loaded.type) {
17
+ case "git":
18
+ return submitted.type === "git" && loaded.repository === submitted.repository && loaded.gitDiffArgs === submitted.gitDiffArgs;
19
+ case "directory":
20
+ case "file":
21
+ return (submitted.type === "directory" || submitted.type === "file") && loaded.sourcePath === submitted.sourcePath;
22
+ case "welcome":
23
+ case "loading":
24
+ return true;
25
+ }
26
+ }
27
+
28
+ // src/publication-ownership.ts
29
+ function provenance(remote) {
30
+ if (!remote) return void 0;
31
+ return {
32
+ remoteUrl: remote.remoteUrl,
33
+ remoteForge: remote.remoteForge,
34
+ remoteBaseSha: remote.remoteBaseSha,
35
+ remoteHeadSha: remote.remoteHeadSha
36
+ };
37
+ }
38
+ function capturePublicationOwnership(loaded) {
39
+ if (!loaded || loaded.source.type === "welcome" || loaded.source.type === "loading") return null;
40
+ return { loaded, source: { ...loaded.source }, remote: provenance(loaded.remote) };
41
+ }
42
+ function normalizePublicationState(state, current, admitted) {
43
+ if (!admitted || !current || current !== admitted.loaded || !state.source || !sameDiffSource(admitted.source, current.source) || !sameDiffSource(admitted.source, state.source))
44
+ return null;
45
+ const remote = provenance(current.remote);
46
+ if (remote?.remoteUrl !== admitted.remote?.remoteUrl || remote?.remoteForge !== admitted.remote?.remoteForge || remote?.remoteBaseSha !== admitted.remote?.remoteBaseSha || remote?.remoteHeadSha !== admitted.remote?.remoteHeadSha)
47
+ return null;
48
+ const {
49
+ remoteUrl: _url,
50
+ remoteForge: _forge,
51
+ remoteBaseSha: _base,
52
+ remoteHeadSha: _head,
53
+ ...local
54
+ } = state;
55
+ return { ...local, ...admitted.remote };
56
+ }
57
+ export {
58
+ MAX_CONTEXT_LINES,
59
+ ReviewXmlError,
60
+ capturePublicationOwnership,
61
+ decodeSuggestionApplyRequest,
62
+ normalizeConfigFontSize,
63
+ normalizePublicationState,
64
+ sameDiffSource,
65
+ validateReviewState
66
+ };
67
+ //# sourceMappingURL=validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/same-diff-source.ts","../src/publication-ownership.ts"],"sourcesContent":["import type { DiffSource } from './types';\n\n/** Compare only canonical source fields, without normalizing their exact string values.\n * This is DTO equality, not permission to publish a welcome/loading source or provenance.\n */\nexport function sameDiffSource(loaded: DiffSource, submitted: DiffSource): boolean {\n if (loaded.type !== submitted.type) return false;\n switch (loaded.type) {\n case 'git':\n return (\n submitted.type === 'git' &&\n loaded.repository === submitted.repository &&\n loaded.gitDiffArgs === submitted.gitDiffArgs\n );\n case 'directory':\n case 'file':\n return (\n (submitted.type === 'directory' || submitted.type === 'file') &&\n loaded.sourcePath === submitted.sourcePath\n );\n case 'welcome':\n case 'loading':\n return true;\n }\n}\n","// Pure publication ownership policy. Hosts translate refusal with their installed error classes.\nimport type { DiffLoadPayload, DiffSource, RemoteSessionInfo, ReviewState } from './types';\nimport { sameDiffSource } from './same-diff-source';\n\ntype LoadedReview = Pick<DiffLoadPayload, 'source' | 'remote'>;\ntype Provenance = Pick<\n RemoteSessionInfo,\n 'remoteUrl' | 'remoteForge' | 'remoteBaseSha' | 'remoteHeadSha'\n>;\n\nexport interface PublicationOwnership {\n readonly loaded: LoadedReview;\n readonly source: DiffSource;\n readonly remote: Provenance | undefined;\n}\n\nfunction provenance(remote: RemoteSessionInfo | undefined): Provenance | undefined {\n if (!remote) return undefined;\n return {\n remoteUrl: remote.remoteUrl,\n remoteForge: remote.remoteForge,\n remoteBaseSha: remote.remoteBaseSha,\n remoteHeadSha: remote.remoteHeadSha,\n };\n}\n\n/** Capture before asynchronous admission work; preserve the loaded object's public reference alias. */\nexport function capturePublicationOwnership(\n loaded: LoadedReview | null\n): PublicationOwnership | null {\n if (!loaded || loaded.source.type === 'welcome' || loaded.source.type === 'loading') return null;\n return { loaded, source: { ...loaded.source }, remote: provenance(loaded.remote) };\n}\n\n/** Refuse absent, foreign or replaced loads, including in-place canonical source/provenance changes.\n * Keep legitimate state/source extensions; only the four host-owned provenance fields are replaced.\n */\nexport function normalizePublicationState(\n state: ReviewState,\n current: LoadedReview | null,\n admitted: PublicationOwnership | null\n): ReviewState | null {\n if (\n !admitted ||\n !current ||\n current !== admitted.loaded ||\n !state.source ||\n !sameDiffSource(admitted.source, current.source) ||\n !sameDiffSource(admitted.source, state.source)\n )\n return null;\n const remote = provenance(current.remote);\n if (\n remote?.remoteUrl !== admitted.remote?.remoteUrl ||\n remote?.remoteForge !== admitted.remote?.remoteForge ||\n remote?.remoteBaseSha !== admitted.remote?.remoteBaseSha ||\n remote?.remoteHeadSha !== admitted.remote?.remoteHeadSha\n )\n return null;\n const {\n remoteUrl: _url,\n remoteForge: _forge,\n remoteBaseSha: _base,\n remoteHeadSha: _head,\n ...local\n } = state;\n return { ...local, ...admitted.remote };\n}\n"],"mappings":";;;;;;;;;;;;;AAKO,SAAS,eAAe,QAAoB,WAAgC;AACjF,MAAI,OAAO,SAAS,UAAU,KAAM,QAAO;AAC3C,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK;AACH,aACE,UAAU,SAAS,SACnB,OAAO,eAAe,UAAU,cAChC,OAAO,gBAAgB,UAAU;AAAA,IAErC,KAAK;AAAA,IACL,KAAK;AACH,cACG,UAAU,SAAS,eAAe,UAAU,SAAS,WACtD,OAAO,eAAe,UAAU;AAAA,IAEpC,KAAK;AAAA,IACL,KAAK;AACH,aAAO;AAAA,EACX;AACF;;;ACRA,SAAS,WAAW,QAA+D;AACjF,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO;AAAA,IACL,WAAW,OAAO;AAAA,IAClB,aAAa,OAAO;AAAA,IACpB,eAAe,OAAO;AAAA,IACtB,eAAe,OAAO;AAAA,EACxB;AACF;AAGO,SAAS,4BACd,QAC6B;AAC7B,MAAI,CAAC,UAAU,OAAO,OAAO,SAAS,aAAa,OAAO,OAAO,SAAS,UAAW,QAAO;AAC5F,SAAO,EAAE,QAAQ,QAAQ,EAAE,GAAG,OAAO,OAAO,GAAG,QAAQ,WAAW,OAAO,MAAM,EAAE;AACnF;AAKO,SAAS,0BACd,OACA,SACA,UACoB;AACpB,MACE,CAAC,YACD,CAAC,WACD,YAAY,SAAS,UACrB,CAAC,MAAM,UACP,CAAC,eAAe,SAAS,QAAQ,QAAQ,MAAM,KAC/C,CAAC,eAAe,SAAS,QAAQ,MAAM,MAAM;AAE7C,WAAO;AACT,QAAM,SAAS,WAAW,QAAQ,MAAM;AACxC,MACE,QAAQ,cAAc,SAAS,QAAQ,aACvC,QAAQ,gBAAgB,SAAS,QAAQ,eACzC,QAAQ,kBAAkB,SAAS,QAAQ,iBAC3C,QAAQ,kBAAkB,SAAS,QAAQ;AAE3C,WAAO;AACT,QAAM;AAAA,IACJ,WAAW;AAAA,IACX,aAAa;AAAA,IACb,eAAe;AAAA,IACf,eAAe;AAAA,IACf,GAAG;AAAA,EACL,IAAI;AACJ,SAAO,EAAE,GAAG,OAAO,GAAG,SAAS,OAAO;AACxC;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@self-review/core",
3
- "version": "2.0.4",
3
+ "version": "2.1.3",
4
4
  "description": "Core library for self-review: diff parsing, git operations, review session orchestration, remote PR/MR handling, XML serialization, CLI argument parsing, and configuration",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,9 +16,49 @@
16
16
  "types": "dist/index.d.ts",
17
17
  "exports": {
18
18
  ".": {
19
- "types": "./dist/index.d.ts",
19
+ "types": {
20
+ "import": "./dist/index.d.ts",
21
+ "require": "./dist/index.d.cts",
22
+ "default": "./dist/index.d.ts"
23
+ },
20
24
  "import": "./dist/index.js",
21
25
  "require": "./dist/index.cjs"
26
+ },
27
+ "./operations": {
28
+ "types": {
29
+ "import": "./dist/operations.d.ts",
30
+ "require": "./dist/operations.d.cts",
31
+ "default": "./dist/operations.d.ts"
32
+ },
33
+ "import": "./dist/operations.js",
34
+ "require": "./dist/operations.cjs"
35
+ },
36
+ "./filesystem": {
37
+ "types": {
38
+ "import": "./dist/filesystem.d.ts",
39
+ "require": "./dist/filesystem.d.cts",
40
+ "default": "./dist/filesystem.d.ts"
41
+ },
42
+ "import": "./dist/filesystem.js",
43
+ "require": "./dist/filesystem.cjs"
44
+ },
45
+ "./validation": {
46
+ "types": {
47
+ "import": "./dist/validation.d.ts",
48
+ "require": "./dist/validation.d.cts",
49
+ "default": "./dist/validation.d.ts"
50
+ },
51
+ "import": "./dist/validation.js",
52
+ "require": "./dist/validation.cjs"
53
+ },
54
+ "./resume-worker": {
55
+ "types": {
56
+ "import": "./dist/resume-worker.d.ts",
57
+ "require": "./dist/resume-worker.d.cts",
58
+ "default": "./dist/resume-worker.d.ts"
59
+ },
60
+ "import": "./dist/resume-worker.js",
61
+ "require": "./dist/resume-worker.cjs"
22
62
  }
23
63
  },
24
64
  "files": [
@@ -34,7 +74,8 @@
34
74
  "fast-xml-parser": "^5.11.2",
35
75
  "ignore": "^7.0.5",
36
76
  "xmllint-wasm": "^5.1.0",
37
- "yaml": "^2.8.2"
77
+ "yaml": "^2.8.2",
78
+ "@self-review/config": "*"
38
79
  },
39
80
  "devDependencies": {
40
81
  "tsup": "^8.0.0",
@@ -1,269 +0,0 @@
1
- // src/diff-parser.ts
2
- function parseDiff(rawDiff) {
3
- return parseDiffWithDiagnostics(rawDiff).files;
4
- }
5
- function parseDiffWithDiagnostics(rawDiff) {
6
- const diagnostics = [];
7
- if (!rawDiff.trim()) {
8
- return { files: [], diagnostics };
9
- }
10
- const lines = rawDiff.split("\n");
11
- if (lines.length > 0 && lines[lines.length - 1] === "") {
12
- lines.pop();
13
- }
14
- const files = [];
15
- let currentFile = null;
16
- let currentHunk = null;
17
- let oldLineNumber = 0;
18
- let newLineNumber = 0;
19
- let remainingOld = 0;
20
- let remainingNew = 0;
21
- let hasModeChange = false;
22
- let skippingSection = false;
23
- function fileLabel() {
24
- return currentFile?.newPath || currentFile?.oldPath || "<unknown file>";
25
- }
26
- function flushHunk() {
27
- if (currentHunk && currentHunk.header && currentFile) {
28
- if (remainingOld > 0 || remainingNew > 0) {
29
- diagnostics.push(
30
- `${fileLabel()}: hunk ${currentHunk.header} ended ${remainingOld} old and ${remainingNew} new lines short of its declared counts`
31
- );
32
- }
33
- currentFile.hunks.push(currentHunk);
34
- }
35
- currentHunk = null;
36
- remainingOld = 0;
37
- remainingNew = 0;
38
- }
39
- function flushFile() {
40
- flushHunk();
41
- if (currentFile && (currentFile.oldPath || currentFile.newPath) && (currentFile.isBinary || currentFile.hunks.length > 0 || currentFile.changeType !== "modified" || hasModeChange)) {
42
- files.push(currentFile);
43
- }
44
- currentFile = null;
45
- hasModeChange = false;
46
- skippingSection = false;
47
- }
48
- for (let i = 0; i < lines.length; i++) {
49
- const line = lines[i];
50
- if (line.startsWith("diff --git ")) {
51
- flushFile();
52
- const gitPaths = parseGitDiffHeader(line);
53
- currentFile = {
54
- oldPath: gitPaths.oldPath,
55
- newPath: gitPaths.newPath,
56
- changeType: "modified",
57
- isBinary: false,
58
- hunks: []
59
- };
60
- continue;
61
- }
62
- const combined = line.match(/^diff --(?:cc|combined) (.*)$/);
63
- if (combined) {
64
- flushFile();
65
- const path = stripPrefix(decodeGitPath(combined[1]));
66
- diagnostics.push(`${path}: combined (merge conflict) diff output is not supported`);
67
- skippingSection = true;
68
- continue;
69
- }
70
- if (skippingSection || !currentFile) continue;
71
- if (line.startsWith("new file mode")) {
72
- currentFile.changeType = "added";
73
- currentFile.oldPath = "";
74
- continue;
75
- }
76
- if (line.startsWith("deleted file mode")) {
77
- currentFile.changeType = "deleted";
78
- currentFile.newPath = "";
79
- continue;
80
- }
81
- if (line.startsWith("new mode ")) {
82
- hasModeChange = true;
83
- continue;
84
- }
85
- if (line.startsWith("rename from ")) {
86
- currentFile.changeType = "renamed";
87
- currentFile.oldPath = decodeGitPath(line.substring("rename from ".length));
88
- continue;
89
- }
90
- if (line.startsWith("rename to ")) {
91
- currentFile.newPath = decodeGitPath(line.substring("rename to ".length));
92
- continue;
93
- }
94
- if (line.startsWith("copy from ")) {
95
- currentFile.changeType = "copied";
96
- currentFile.oldPath = decodeGitPath(line.substring("copy from ".length));
97
- continue;
98
- }
99
- if (line.startsWith("copy to ")) {
100
- currentFile.newPath = decodeGitPath(line.substring("copy to ".length));
101
- continue;
102
- }
103
- if (!currentHunk && line.startsWith("--- ")) {
104
- const path = decodeGitPath(line.substring(4).split(" ")[0]);
105
- currentFile.oldPath = path === "/dev/null" ? "" : stripPrefix(path);
106
- continue;
107
- }
108
- if (!currentHunk && line.startsWith("+++ ")) {
109
- const path = decodeGitPath(line.substring(4).split(" ")[0]);
110
- currentFile.newPath = path === "/dev/null" ? "" : stripPrefix(path);
111
- continue;
112
- }
113
- if (line.startsWith("Binary files ")) {
114
- currentFile.isBinary = true;
115
- continue;
116
- }
117
- if (line === "GIT binary patch") {
118
- currentFile.isBinary = true;
119
- skippingSection = true;
120
- continue;
121
- }
122
- if (line.startsWith("@@")) {
123
- flushHunk();
124
- const match = line.match(/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(.*)$/);
125
- if (!match) {
126
- diagnostics.push(`${fileLabel()}: unrecognized hunk header "${line}"`);
127
- continue;
128
- }
129
- const oldStart = parseInt(match[1], 10);
130
- const oldLines = match[2] ? parseInt(match[2], 10) : 1;
131
- const newStart = parseInt(match[3], 10);
132
- const newLines = match[4] ? parseInt(match[4], 10) : 1;
133
- currentHunk = {
134
- header: line,
135
- oldStart,
136
- oldLines,
137
- newStart,
138
- newLines,
139
- lines: []
140
- };
141
- oldLineNumber = oldStart;
142
- newLineNumber = newStart;
143
- remainingOld = oldLines;
144
- remainingNew = newLines;
145
- continue;
146
- }
147
- if (!currentHunk || !currentHunk.lines) continue;
148
- if (line.startsWith("\\")) {
149
- continue;
150
- }
151
- const marker = line.length === 0 ? " " : line[0];
152
- const content = line.length === 0 ? "" : line.substring(1);
153
- if (marker === "+") {
154
- if (remainingNew <= 0) {
155
- diagnostics.push(
156
- `${fileLabel()}: line beyond the counts of hunk ${currentHunk.header}: "${line}"`
157
- );
158
- continue;
159
- }
160
- currentHunk.lines.push({
161
- type: "addition",
162
- oldLineNumber: null,
163
- newLineNumber,
164
- content
165
- });
166
- newLineNumber++;
167
- remainingNew--;
168
- } else if (marker === "-") {
169
- if (remainingOld <= 0) {
170
- diagnostics.push(
171
- `${fileLabel()}: line beyond the counts of hunk ${currentHunk.header}: "${line}"`
172
- );
173
- continue;
174
- }
175
- currentHunk.lines.push({
176
- type: "deletion",
177
- oldLineNumber,
178
- newLineNumber: null,
179
- content
180
- });
181
- oldLineNumber++;
182
- remainingOld--;
183
- } else if (marker === " ") {
184
- if (remainingOld <= 0 || remainingNew <= 0) {
185
- diagnostics.push(
186
- `${fileLabel()}: line beyond the counts of hunk ${currentHunk.header}: "${line}"`
187
- );
188
- continue;
189
- }
190
- currentHunk.lines.push({
191
- type: "context",
192
- oldLineNumber,
193
- newLineNumber,
194
- content
195
- });
196
- oldLineNumber++;
197
- newLineNumber++;
198
- remainingOld--;
199
- remainingNew--;
200
- } else {
201
- diagnostics.push(
202
- `${fileLabel()}: unrecognized line inside hunk ${currentHunk.header}: "${line}"`
203
- );
204
- }
205
- }
206
- flushFile();
207
- return { files, diagnostics };
208
- }
209
- function stripPrefix(path) {
210
- if (path.length > 2 && path[1] === "/") {
211
- return path.substring(2);
212
- }
213
- return path;
214
- }
215
- var OCTAL_PATH_DECODER = new TextDecoder("utf-8");
216
- function decodeGitPath(path) {
217
- if (!path.startsWith('"') || !path.endsWith('"')) return path;
218
- const escapes = {
219
- a: "\x07",
220
- b: "\b",
221
- f: "\f",
222
- n: "\n",
223
- r: "\r",
224
- t: " ",
225
- v: "\v",
226
- '"': '"',
227
- "\\": "\\"
228
- };
229
- return path.slice(1, -1).replace(/(?:\\[0-7]{1,3})+|\\[abfnrtv"\\]/g, (escape) => {
230
- if (/^\\[0-7]/.test(escape)) {
231
- const bytes = escape.slice(1).split("\\").map((byte) => parseInt(byte, 8));
232
- return OCTAL_PATH_DECODER.decode(Uint8Array.from(bytes));
233
- }
234
- return escapes[escape[1]];
235
- });
236
- }
237
- function parseGitDiffHeader(line) {
238
- const paths = line.substring("diff --git ".length);
239
- const quotedOld = paths.match(/^("(?:\\.|[^"\\])*") (.+)$/);
240
- const quotedNew = paths.match(/^(.+) ("(?:\\.|[^"\\])*")$/);
241
- const quoted = quotedOld || quotedNew;
242
- if (quoted) {
243
- return {
244
- oldPath: stripPrefix(decodeGitPath(quoted[1])),
245
- newPath: stripPrefix(decodeGitPath(quoted[2]))
246
- };
247
- }
248
- const separators = [...paths.matchAll(/ [bwico]\//g)];
249
- const boundary = separators.find(
250
- (match) => stripPrefix(paths.substring(0, match.index)) === stripPrefix(paths.substring(match.index + 1))
251
- ) || separators[0];
252
- if (!boundary) {
253
- const bare = paths.split(" ");
254
- if (bare.length === 2 && bare[0] === bare[1]) {
255
- return { oldPath: bare[0], newPath: bare[1] };
256
- }
257
- return { oldPath: "", newPath: "" };
258
- }
259
- return {
260
- oldPath: stripPrefix(paths.substring(0, boundary.index)),
261
- newPath: stripPrefix(paths.substring(boundary.index + 1))
262
- };
263
- }
264
-
265
- export {
266
- parseDiff,
267
- parseDiffWithDiagnostics
268
- };
269
- //# sourceMappingURL=chunk-4YO2MI6B.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/diff-parser.ts"],"sourcesContent":["// packages/core/src/diff-parser.ts\n// Parse unified diff output into DiffFile[]\n\nimport { DiffFile, DiffHunk, ChangeType } from './types';\n\n/**\n * The files parsed, plus one diagnostic per piece of input that could not be represented\n * faithfully.\n */\nexport interface DiffParseResult {\n files: DiffFile[];\n diagnostics: string[];\n}\n\n/** Parse a unified diff, discarding diagnostics. Prefer {@link parseDiffWithDiagnostics}. */\nexport function parseDiff(rawDiff: string): DiffFile[] {\n return parseDiffWithDiagnostics(rawDiff).files;\n}\n\n/**\n * Parse `git diff` output (a/ b/ prefixes, no color). Every hunk is checked\n * against its `@@` counts; a line over them, a short hunk or an unprefixed line\n * is a diagnostic, never context. Empty lines in an open hunk are the one\n * leniency (`git apply` reads them as empty context). Combined output\n * (`diff --cc`) is reported and skipped.\n */\nexport function parseDiffWithDiagnostics(rawDiff: string): DiffParseResult {\n const diagnostics: string[] = [];\n if (!rawDiff.trim()) {\n return { files: [], diagnostics };\n }\n\n const lines = rawDiff.split('\\n');\n // The empty element after git's final newline is not a line of the last hunk.\n if (lines.length > 0 && lines[lines.length - 1] === '') {\n lines.pop();\n }\n\n const files: DiffFile[] = [];\n let currentFile: Partial<DiffFile> | null = null;\n let currentHunk: Partial<DiffHunk> | null = null;\n let oldLineNumber = 0;\n let newLineNumber = 0;\n let remainingOld = 0;\n let remainingNew = 0;\n let hasModeChange = false;\n // Inside a binary patch body or an unsupported combined section.\n let skippingSection = false;\n\n function fileLabel(): string {\n return currentFile?.newPath || currentFile?.oldPath || '<unknown file>';\n }\n\n function flushHunk(): void {\n if (currentHunk && currentHunk.header && currentFile) {\n if (remainingOld > 0 || remainingNew > 0) {\n diagnostics.push(\n `${fileLabel()}: hunk ${currentHunk.header} ended ${remainingOld} old and ` +\n `${remainingNew} new lines short of its declared counts`\n );\n }\n currentFile.hunks!.push(currentHunk as DiffHunk);\n }\n currentHunk = null;\n remainingOld = 0;\n remainingNew = 0;\n }\n\n function flushFile(): void {\n flushHunk();\n if (\n currentFile &&\n (currentFile.oldPath || currentFile.newPath) &&\n (currentFile.isBinary ||\n currentFile.hunks!.length > 0 ||\n currentFile.changeType !== 'modified' ||\n hasModeChange)\n ) {\n files.push(currentFile as DiffFile);\n }\n currentFile = null;\n hasModeChange = false;\n skippingSection = false;\n }\n\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i];\n\n // Start of a new file\n if (line.startsWith('diff --git ')) {\n flushFile();\n\n // Extract paths from \"diff --git a/<old> b/<new>\" as fallback\n // for binary files that lack --- / +++ lines\n const gitPaths = parseGitDiffHeader(line);\n\n currentFile = {\n oldPath: gitPaths.oldPath,\n newPath: gitPaths.newPath,\n changeType: 'modified' as ChangeType,\n isBinary: false,\n hunks: [],\n };\n continue;\n }\n\n // Two parents against one result: no DiffFile can carry it.\n const combined = line.match(/^diff --(?:cc|combined) (.*)$/);\n if (combined) {\n flushFile();\n const path = stripPrefix(decodeGitPath(combined[1]));\n diagnostics.push(`${path}: combined (merge conflict) diff output is not supported`);\n skippingSection = true;\n continue;\n }\n\n if (skippingSection || !currentFile) continue;\n\n // Detect file mode changes\n if (line.startsWith('new file mode')) {\n currentFile.changeType = 'added';\n currentFile.oldPath = '';\n continue;\n }\n\n if (line.startsWith('deleted file mode')) {\n currentFile.changeType = 'deleted';\n currentFile.newPath = '';\n continue;\n }\n\n if (line.startsWith('new mode ')) {\n hasModeChange = true;\n continue;\n }\n\n if (line.startsWith('rename from ')) {\n currentFile.changeType = 'renamed';\n currentFile.oldPath = decodeGitPath(line.substring('rename from '.length));\n continue;\n }\n\n if (line.startsWith('rename to ')) {\n currentFile.newPath = decodeGitPath(line.substring('rename to '.length));\n continue;\n }\n\n if (line.startsWith('copy from ')) {\n currentFile.changeType = 'copied';\n currentFile.oldPath = decodeGitPath(line.substring('copy from '.length));\n continue;\n }\n\n if (line.startsWith('copy to ')) {\n currentFile.newPath = decodeGitPath(line.substring('copy to '.length));\n continue;\n }\n\n // Parse old file path\n if (!currentHunk && line.startsWith('--- ')) {\n const path = decodeGitPath(line.substring(4).split('\\t')[0]);\n currentFile.oldPath = path === '/dev/null' ? '' : stripPrefix(path);\n continue;\n }\n\n // Parse new file path\n if (!currentHunk && line.startsWith('+++ ')) {\n const path = decodeGitPath(line.substring(4).split('\\t')[0]);\n currentFile.newPath = path === '/dev/null' ? '' : stripPrefix(path);\n continue;\n }\n\n // Detect binary files\n if (line.startsWith('Binary files ')) {\n currentFile.isBinary = true;\n continue;\n }\n\n // `--binary` emits a base85 body after this marker; skip it.\n if (line === 'GIT binary patch') {\n currentFile.isBinary = true;\n skippingSection = true;\n continue;\n }\n\n // Parse hunk header\n if (line.startsWith('@@')) {\n flushHunk();\n\n // Parse hunk header: @@ -oldStart,oldLines +newStart,newLines @@ context\n const match = line.match(/^@@ -(\\d+)(?:,(\\d+))? \\+(\\d+)(?:,(\\d+))? @@(.*)$/);\n if (!match) {\n diagnostics.push(`${fileLabel()}: unrecognized hunk header \"${line}\"`);\n continue;\n }\n const oldStart = parseInt(match[1], 10);\n const oldLines = match[2] ? parseInt(match[2], 10) : 1;\n const newStart = parseInt(match[3], 10);\n const newLines = match[4] ? parseInt(match[4], 10) : 1;\n\n currentHunk = {\n header: line,\n oldStart,\n oldLines,\n newStart,\n newLines,\n lines: [],\n };\n\n oldLineNumber = oldStart;\n newLineNumber = newStart;\n remainingOld = oldLines;\n remainingNew = newLines;\n continue;\n }\n\n // Before the first hunk: file metadata.\n if (!currentHunk || !currentHunk.lines) continue;\n\n if (line.startsWith('\\\\')) {\n continue;\n }\n\n const marker = line.length === 0 ? ' ' : line[0];\n const content = line.length === 0 ? '' : line.substring(1);\n\n if (marker === '+') {\n if (remainingNew <= 0) {\n diagnostics.push(\n `${fileLabel()}: line beyond the counts of hunk ${currentHunk.header}: \"${line}\"`\n );\n continue;\n }\n currentHunk.lines.push({\n type: 'addition',\n oldLineNumber: null,\n newLineNumber: newLineNumber,\n content,\n });\n newLineNumber++;\n remainingNew--;\n } else if (marker === '-') {\n if (remainingOld <= 0) {\n diagnostics.push(\n `${fileLabel()}: line beyond the counts of hunk ${currentHunk.header}: \"${line}\"`\n );\n continue;\n }\n currentHunk.lines.push({\n type: 'deletion',\n oldLineNumber: oldLineNumber,\n newLineNumber: null,\n content,\n });\n oldLineNumber++;\n remainingOld--;\n } else if (marker === ' ') {\n if (remainingOld <= 0 || remainingNew <= 0) {\n diagnostics.push(\n `${fileLabel()}: line beyond the counts of hunk ${currentHunk.header}: \"${line}\"`\n );\n continue;\n }\n currentHunk.lines.push({\n type: 'context',\n oldLineNumber: oldLineNumber,\n newLineNumber: newLineNumber,\n content,\n });\n oldLineNumber++;\n newLineNumber++;\n remainingOld--;\n remainingNew--;\n } else {\n diagnostics.push(\n `${fileLabel()}: unrecognized line inside hunk ${currentHunk.header}: \"${line}\"`\n );\n }\n }\n\n // Save the last hunk and file\n flushFile();\n\n return { files, diagnostics };\n}\n\nfunction stripPrefix(path: string): string {\n // Remove single-character prefix (a/, b/, c/, i/, w/, etc.)\n // Git uses a/b by default, but mnemonicPrefix uses c/i/w/o\n if (path.length > 2 && path[1] === '/') {\n return path.substring(2);\n }\n return path;\n}\n\n// `TextDecoder`, not `Buffer`: this parser also runs in the browser (browser.ts).\nconst OCTAL_PATH_DECODER = new TextDecoder('utf-8');\n\nfunction decodeGitPath(path: string): string {\n if (!path.startsWith('\"') || !path.endsWith('\"')) return path;\n\n const escapes: Record<string, string> = {\n a: '\\x07',\n b: '\\b',\n f: '\\f',\n n: '\\n',\n r: '\\r',\n t: '\\t',\n v: '\\v',\n '\"': '\"',\n '\\\\': '\\\\',\n };\n return path.slice(1, -1).replace(/(?:\\\\[0-7]{1,3})+|\\\\[abfnrtv\"\\\\]/g, escape => {\n if (/^\\\\[0-7]/.test(escape)) {\n // Git quotes UTF-8 bytes as octal, so decode each run together.\n const bytes = escape\n .slice(1)\n .split('\\\\')\n .map(byte => parseInt(byte, 8));\n return OCTAL_PATH_DECODER.decode(Uint8Array.from(bytes));\n }\n return escapes[escape[1]];\n });\n}\n\nfunction parseGitDiffHeader(line: string): {\n oldPath: string;\n newPath: string;\n} {\n const paths = line.substring('diff --git '.length);\n // Quoted paths are single C-style tokens, even when they contain spaces.\n const quotedOld = paths.match(/^(\"(?:\\\\.|[^\"\\\\])*\") (.+)$/);\n const quotedNew = paths.match(/^(.+) (\"(?:\\\\.|[^\"\\\\])*\")$/);\n const quoted = quotedOld || quotedNew;\n if (quoted) {\n return {\n oldPath: stripPrefix(decodeGitPath(quoted[1])),\n newPath: stripPrefix(decodeGitPath(quoted[2])),\n };\n }\n\n // Unquoted names can contain spaces. Prefer a boundary whose two paths\n // agree; rename headers supply the exact paths when they differ.\n const separators = [...paths.matchAll(/ [bwico]\\//g)];\n const boundary =\n separators.find(\n match =>\n stripPrefix(paths.substring(0, match.index)) ===\n stripPrefix(paths.substring(match.index! + 1))\n ) || separators[0];\n if (!boundary) {\n // diff.noprefix: unambiguous only as two bare tokens naming the same path.\n const bare = paths.split(' ');\n if (bare.length === 2 && bare[0] === bare[1]) {\n return { oldPath: bare[0], newPath: bare[1] };\n }\n return { oldPath: '', newPath: '' };\n }\n\n return {\n oldPath: stripPrefix(paths.substring(0, boundary.index)),\n newPath: stripPrefix(paths.substring(boundary.index! + 1)),\n };\n}\n"],"mappings":";AAeO,SAAS,UAAU,SAA6B;AACrD,SAAO,yBAAyB,OAAO,EAAE;AAC3C;AASO,SAAS,yBAAyB,SAAkC;AACzE,QAAM,cAAwB,CAAC;AAC/B,MAAI,CAAC,QAAQ,KAAK,GAAG;AACnB,WAAO,EAAE,OAAO,CAAC,GAAG,YAAY;AAAA,EAClC;AAEA,QAAM,QAAQ,QAAQ,MAAM,IAAI;AAEhC,MAAI,MAAM,SAAS,KAAK,MAAM,MAAM,SAAS,CAAC,MAAM,IAAI;AACtD,UAAM,IAAI;AAAA,EACZ;AAEA,QAAM,QAAoB,CAAC;AAC3B,MAAI,cAAwC;AAC5C,MAAI,cAAwC;AAC5C,MAAI,gBAAgB;AACpB,MAAI,gBAAgB;AACpB,MAAI,eAAe;AACnB,MAAI,eAAe;AACnB,MAAI,gBAAgB;AAEpB,MAAI,kBAAkB;AAEtB,WAAS,YAAoB;AAC3B,WAAO,aAAa,WAAW,aAAa,WAAW;AAAA,EACzD;AAEA,WAAS,YAAkB;AACzB,QAAI,eAAe,YAAY,UAAU,aAAa;AACpD,UAAI,eAAe,KAAK,eAAe,GAAG;AACxC,oBAAY;AAAA,UACV,GAAG,UAAU,CAAC,UAAU,YAAY,MAAM,UAAU,YAAY,YAC3D,YAAY;AAAA,QACnB;AAAA,MACF;AACA,kBAAY,MAAO,KAAK,WAAuB;AAAA,IACjD;AACA,kBAAc;AACd,mBAAe;AACf,mBAAe;AAAA,EACjB;AAEA,WAAS,YAAkB;AACzB,cAAU;AACV,QACE,gBACC,YAAY,WAAW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