@fabiofiorita/porcelain 0.84.0 → 0.85.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 +1 -1
- package/package.json +1 -1
- package/server/src/cli/main.mjs +649 -6
- package/web/dist/assets/_paired-B6tiTIDs.js +40 -0
- package/web/dist/assets/_paired-BTiwzm1O.js +1 -0
- package/web/dist/assets/{_section-CAKa8OMp.js → _section-C1ant2Gf.js} +1 -1
- package/web/dist/assets/access-Dl1HKbYr.js +17 -0
- package/web/dist/assets/confirmed-read-DcLEUmry.js +133 -0
- package/web/dist/assets/{core-C-3U_QA6.js → core-CzPj8AUX.js} +1 -1
- package/web/dist/assets/{file-editor-DSMrBXg5.js → file-editor-ZzNIR2Bb.js} +9 -9
- package/web/dist/assets/{highlights-CHuyavGs.js → highlights-CkhjI2ek.js} +1 -1
- package/web/dist/assets/index-B38tyj8W.js +1504 -0
- package/web/dist/assets/index-wLG_09Ob.css +2 -0
- package/web/dist/assets/{lazyRouteComponent-DTKAAS-5.js → lazyRouteComponent-Blj06I1z.js} +1 -1
- package/web/dist/assets/pair-BTiwzm1O.js +1 -0
- package/web/dist/assets/pair-Cc4RvFWD.js +1 -0
- package/web/dist/assets/{resolveLanguages-BFlyswXF.js → resolveLanguages-ByH4UCRT.js} +1 -1
- package/web/dist/assets/{shiki-DT5lFKHs.js → shiki-DylxQut3.js} +1 -1
- package/web/dist/assets/{stream-tokenizer-xjU9kpyJ.js → stream-tokenizer-DzPUGMwH.js} +3 -3
- package/web/dist/assets/{themeResolver-BuLDwzP-.js → themeResolver-fzWDoZkr.js} +2 -2
- package/web/dist/assets/{themes-B9aQP4R3.js → themes-K9KCd10n.js} +2 -2
- package/web/dist/assets/useMatch-DOx1OLzI.js +1 -0
- package/web/dist/assets/workspace-error-WdCLSEta.js +1 -0
- package/web/dist/index.html +7 -7
- package/web/dist/assets/_paired-3fQkzk5h.js +0 -40
- package/web/dist/assets/_paired-Bh7pM6sZ.js +0 -1
- package/web/dist/assets/access-BfI2b3uK.js +0 -17
- package/web/dist/assets/confirmed-read-D5mkk70U.js +0 -133
- package/web/dist/assets/index-B96SAxn2.js +0 -1504
- package/web/dist/assets/index-CuqqJO_U.css +0 -2
- package/web/dist/assets/pair-Bh7pM6sZ.js +0 -1
- package/web/dist/assets/pair-CsqLVZUp.js +0 -1
- package/web/dist/assets/useMatch-eXetae_a.js +0 -1
- package/web/dist/assets/workspace-error-CttuFVLN.js +0 -1
package/server/src/cli/main.mjs
CHANGED
|
@@ -4083,10 +4083,17 @@ var startWalkthroughRequestSchema = Schema86.Struct({
|
|
|
4083
4083
|
pullRequestNumber: Schema86.optional(Schema86.Int.check(Schema86.isGreaterThan(0))),
|
|
4084
4084
|
writer: Schema86.optional(writerSchema)
|
|
4085
4085
|
});
|
|
4086
|
+
var readWalkthroughQuerySchema = Schema86.Struct({
|
|
4087
|
+
excerptRunId: Schema86.optional(Schema86.String),
|
|
4088
|
+
excerptStep: Schema86.optional(
|
|
4089
|
+
Schema86.NumberFromString.check(Schema86.isInt(), Schema86.isGreaterThan(0))
|
|
4090
|
+
)
|
|
4091
|
+
});
|
|
4086
4092
|
var readWalkthroughResponseSchema = Schema86.Struct({
|
|
4087
4093
|
walkthrough: nullableAsUndefined(walkthroughRunSchema2),
|
|
4088
4094
|
attempt: Schema86.optional(walkthroughRunSchema2),
|
|
4089
|
-
freshness: walkthroughFreshnessSchema
|
|
4095
|
+
freshness: walkthroughFreshnessSchema,
|
|
4096
|
+
capturedPatch: Schema86.optional(Schema86.String)
|
|
4090
4097
|
});
|
|
4091
4098
|
var walkthroughWriterSettingsSchema = Schema86.Struct({
|
|
4092
4099
|
writer: writerSchema,
|
|
@@ -4127,6 +4134,7 @@ var WalkthroughsApi = class extends porcelainApi.add(
|
|
|
4127
4134
|
{
|
|
4128
4135
|
disableCodecs: true,
|
|
4129
4136
|
params: worktreeParamsSchema,
|
|
4137
|
+
query: readWalkthroughQuerySchema.fields,
|
|
4130
4138
|
success: readWalkthroughResponseSchema,
|
|
4131
4139
|
error: [...worktreeFailures, ...gitReadFailures]
|
|
4132
4140
|
}
|
|
@@ -20322,6 +20330,642 @@ import { Context as Context161, Effect as Effect214, Layer as Layer118 } from "e
|
|
|
20322
20330
|
|
|
20323
20331
|
// packages/walkthroughs/src/services/read-walkthrough-service.ts
|
|
20324
20332
|
import { Context as Context142, Effect as Effect195, Layer as Layer99 } from "effect";
|
|
20333
|
+
|
|
20334
|
+
// node_modules/.pnpm/@pierre+diffs@1.6.4_patch_hash=7a37d94505526b01286480d4f1f5519799f536fae7c931f72a89aab2_7f89f0527c41b64aaa0b77f4c03d048a/node_modules/@pierre/diffs/dist/constants.js
|
|
20335
|
+
var DIFFS_DEVELOPMENT_BUILD = (() => {
|
|
20336
|
+
try {
|
|
20337
|
+
return process.env.NODE_ENV === "development";
|
|
20338
|
+
} catch {
|
|
20339
|
+
return false;
|
|
20340
|
+
}
|
|
20341
|
+
})();
|
|
20342
|
+
var GIT_DIFF_FILE_BREAK_REGEX = /(?=^diff --git)/gm;
|
|
20343
|
+
var FILENAME_HEADER_REGEX = /^(---|\+\+\+)\s+([^\t\r\n]+)/;
|
|
20344
|
+
var INDEX_LINE_METADATA = /^index ([0-9a-f]+)\.\.([0-9a-f]+)(?: (\d+))?$/i;
|
|
20345
|
+
var DEFAULT_VIRTUAL_FILE_METRICS = {
|
|
20346
|
+
hunkLineCount: 50,
|
|
20347
|
+
lineHeight: 20,
|
|
20348
|
+
diffHeaderHeight: 44,
|
|
20349
|
+
spacing: 8
|
|
20350
|
+
};
|
|
20351
|
+
var DEFAULT_CODE_VIEW_FILE_METRICS = {
|
|
20352
|
+
...DEFAULT_VIRTUAL_FILE_METRICS,
|
|
20353
|
+
hunkLineCount: 1
|
|
20354
|
+
};
|
|
20355
|
+
var DEFAULT_EXPANDED_REGION = Object.freeze({
|
|
20356
|
+
fromStart: 0,
|
|
20357
|
+
fromEnd: 0
|
|
20358
|
+
});
|
|
20359
|
+
var EMPTY_LINE_ANNOTATIONS = Object.freeze([]);
|
|
20360
|
+
|
|
20361
|
+
// node_modules/.pnpm/@pierre+diffs@1.6.4_patch_hash=7a37d94505526b01286480d4f1f5519799f536fae7c931f72a89aab2_7f89f0527c41b64aaa0b77f4c03d048a/node_modules/@pierre/diffs/dist/utils/getHunkSideBoundaries.js
|
|
20362
|
+
function getHunkSideStartBoundary(start, count) {
|
|
20363
|
+
return start - (count === 0 ? 0 : 1);
|
|
20364
|
+
}
|
|
20365
|
+
function getHunkSideEndBoundary(start, count) {
|
|
20366
|
+
return getHunkSideStartBoundary(start, count) + count;
|
|
20367
|
+
}
|
|
20368
|
+
|
|
20369
|
+
// node_modules/.pnpm/@pierre+diffs@1.6.4_patch_hash=7a37d94505526b01286480d4f1f5519799f536fae7c931f72a89aab2_7f89f0527c41b64aaa0b77f4c03d048a/node_modules/@pierre/diffs/dist/utils/cleanLastNewline.js
|
|
20370
|
+
function cleanLastNewline(contents) {
|
|
20371
|
+
let end = contents.length;
|
|
20372
|
+
if (contents.charCodeAt(end - 1) === 10) {
|
|
20373
|
+
end--;
|
|
20374
|
+
if (contents.charCodeAt(end - 1) === 13) end--;
|
|
20375
|
+
}
|
|
20376
|
+
return contents.slice(0, end);
|
|
20377
|
+
}
|
|
20378
|
+
|
|
20379
|
+
// node_modules/.pnpm/@pierre+diffs@1.6.4_patch_hash=7a37d94505526b01286480d4f1f5519799f536fae7c931f72a89aab2_7f89f0527c41b64aaa0b77f4c03d048a/node_modules/@pierre/diffs/dist/utils/detachString.js
|
|
20380
|
+
var stringDetachEncoder = new TextEncoder();
|
|
20381
|
+
var stringDetachDecoder = new TextDecoder("utf-8", { ignoreBOM: true });
|
|
20382
|
+
var SURROGATE_CODE_UNIT_PATTERN = /[\uD800-\uDFFF]/;
|
|
20383
|
+
var STRING_DETACH_INITIAL_BUFFER_SIZE = 1024;
|
|
20384
|
+
var stringDetachBuffer = new Uint8Array(STRING_DETACH_INITIAL_BUFFER_SIZE);
|
|
20385
|
+
function releaseStringDetachBuffer() {
|
|
20386
|
+
if (stringDetachBuffer.length !== STRING_DETACH_INITIAL_BUFFER_SIZE) stringDetachBuffer = new Uint8Array(STRING_DETACH_INITIAL_BUFFER_SIZE);
|
|
20387
|
+
}
|
|
20388
|
+
function detachString(value2) {
|
|
20389
|
+
if (value2.length === 0) return value2;
|
|
20390
|
+
if (SURROGATE_CODE_UNIT_PATTERN.test(value2)) return JSON.parse(JSON.stringify(value2));
|
|
20391
|
+
const requiredByteLength = value2.length * 3;
|
|
20392
|
+
if (stringDetachBuffer.length < requiredByteLength) stringDetachBuffer = new Uint8Array(requiredByteLength);
|
|
20393
|
+
const { written } = stringDetachEncoder.encodeInto(value2, stringDetachBuffer);
|
|
20394
|
+
return stringDetachDecoder.decode(stringDetachBuffer.subarray(0, written));
|
|
20395
|
+
}
|
|
20396
|
+
|
|
20397
|
+
// node_modules/.pnpm/@pierre+diffs@1.6.4_patch_hash=7a37d94505526b01286480d4f1f5519799f536fae7c931f72a89aab2_7f89f0527c41b64aaa0b77f4c03d048a/node_modules/@pierre/diffs/dist/utils/parseQuotedDiffFileName.js
|
|
20398
|
+
var filenameDecoder = new TextDecoder("utf-8", { ignoreBOM: true });
|
|
20399
|
+
var NAMED_ESCAPES = {
|
|
20400
|
+
'"': '"',
|
|
20401
|
+
"\\": "\\",
|
|
20402
|
+
a: "\x07",
|
|
20403
|
+
b: "\b",
|
|
20404
|
+
t: " ",
|
|
20405
|
+
n: "\n",
|
|
20406
|
+
v: "\v",
|
|
20407
|
+
f: "\f",
|
|
20408
|
+
r: "\r"
|
|
20409
|
+
};
|
|
20410
|
+
function parseQuotedDiffFileName(input) {
|
|
20411
|
+
if (input[0] !== '"') return;
|
|
20412
|
+
let fileName = "";
|
|
20413
|
+
let index = 1;
|
|
20414
|
+
while (index < input.length) {
|
|
20415
|
+
const char = input[index];
|
|
20416
|
+
if (char === '"') return {
|
|
20417
|
+
fileName,
|
|
20418
|
+
rawLength: index + 1
|
|
20419
|
+
};
|
|
20420
|
+
if (char !== "\\") {
|
|
20421
|
+
fileName += char;
|
|
20422
|
+
index++;
|
|
20423
|
+
continue;
|
|
20424
|
+
}
|
|
20425
|
+
const escaped = NAMED_ESCAPES[input[index + 1]];
|
|
20426
|
+
if (escaped != null) {
|
|
20427
|
+
fileName += escaped;
|
|
20428
|
+
index += 2;
|
|
20429
|
+
continue;
|
|
20430
|
+
}
|
|
20431
|
+
const bytes = [];
|
|
20432
|
+
do {
|
|
20433
|
+
const byte = readOctalByte(input, index + 1);
|
|
20434
|
+
if (byte == null) return;
|
|
20435
|
+
bytes.push(byte);
|
|
20436
|
+
index += 4;
|
|
20437
|
+
} while (input[index] === "\\" && input[index + 1] >= "0" && input[index + 1] <= "7");
|
|
20438
|
+
fileName += filenameDecoder.decode(new Uint8Array(bytes));
|
|
20439
|
+
}
|
|
20440
|
+
}
|
|
20441
|
+
function readOctalByte(input, index) {
|
|
20442
|
+
const first = input.charCodeAt(index) - 48;
|
|
20443
|
+
const second = input.charCodeAt(index + 1) - 48;
|
|
20444
|
+
const third = input.charCodeAt(index + 2) - 48;
|
|
20445
|
+
if (first >= 0 && first <= 3 && second >= 0 && second <= 7 && third >= 0 && third <= 7) return first * 64 + second * 8 + third;
|
|
20446
|
+
}
|
|
20447
|
+
|
|
20448
|
+
// node_modules/.pnpm/@pierre+diffs@1.6.4_patch_hash=7a37d94505526b01286480d4f1f5519799f536fae7c931f72a89aab2_7f89f0527c41b64aaa0b77f4c03d048a/node_modules/@pierre/diffs/dist/utils/realignChangeContent.js
|
|
20449
|
+
var MAX_ALIGNMENT_COMPARISONS = 4096;
|
|
20450
|
+
var MIN_IMPROVEMENT_PER_PAIR = 0.5;
|
|
20451
|
+
function realignChangeContentBySimilarity(diff) {
|
|
20452
|
+
for (const hunk of diff.hunks) for (let index = 0; index < hunk.hunkContent.length; index++) {
|
|
20453
|
+
const content = hunk.hunkContent[index];
|
|
20454
|
+
if (content.type !== "change") continue;
|
|
20455
|
+
const replacement = realignChangeBlock(diff, content);
|
|
20456
|
+
if (replacement != null) {
|
|
20457
|
+
hunk.hunkContent.splice(index, 1, ...replacement);
|
|
20458
|
+
index += replacement.length - 1;
|
|
20459
|
+
}
|
|
20460
|
+
}
|
|
20461
|
+
}
|
|
20462
|
+
function realignChangeBlock(diff, content) {
|
|
20463
|
+
const { deletions, additions, deletionLineIndex, additionLineIndex } = content;
|
|
20464
|
+
const pairCount = Math.min(deletions, additions);
|
|
20465
|
+
const surplus = Math.abs(additions - deletions);
|
|
20466
|
+
if (pairCount === 0 || surplus === 0 || pairCount * (surplus + 1) > MAX_ALIGNMENT_COMPARISONS) return null;
|
|
20467
|
+
const strippedDeletions = [];
|
|
20468
|
+
for (let line = 0; line < deletions; line++) strippedDeletions.push(stripWhitespace(diff.deletionLines[deletionLineIndex + line] ?? ""));
|
|
20469
|
+
const strippedAdditions = [];
|
|
20470
|
+
for (let line = 0; line < additions; line++) strippedAdditions.push(stripWhitespace(diff.additionLines[additionLineIndex + line] ?? ""));
|
|
20471
|
+
const additionsAreLonger = additions > deletions;
|
|
20472
|
+
let bestOffset = 0;
|
|
20473
|
+
let bestScore = -1;
|
|
20474
|
+
for (let offset = 0; offset <= surplus; offset++) {
|
|
20475
|
+
let score = 0;
|
|
20476
|
+
for (let pair2 = 0; pair2 < pairCount; pair2++) score += lineSimilarity(strippedDeletions[pair2 + (additionsAreLonger ? 0 : offset)], strippedAdditions[pair2 + (additionsAreLonger ? offset : 0)]);
|
|
20477
|
+
if (offset === 0) bestScore = score + pairCount * MIN_IMPROVEMENT_PER_PAIR;
|
|
20478
|
+
else if (score > bestScore) {
|
|
20479
|
+
bestScore = score;
|
|
20480
|
+
bestOffset = offset;
|
|
20481
|
+
}
|
|
20482
|
+
}
|
|
20483
|
+
if (bestOffset === 0) return null;
|
|
20484
|
+
const blocks = [];
|
|
20485
|
+
const pushBlock = (blockDeletions, blockAdditions, blockDeletionIndex, blockAdditionIndex) => {
|
|
20486
|
+
if (blockDeletions > 0 || blockAdditions > 0) blocks.push({
|
|
20487
|
+
type: "change",
|
|
20488
|
+
deletions: blockDeletions,
|
|
20489
|
+
additions: blockAdditions,
|
|
20490
|
+
deletionLineIndex: blockDeletionIndex,
|
|
20491
|
+
additionLineIndex: blockAdditionIndex
|
|
20492
|
+
});
|
|
20493
|
+
};
|
|
20494
|
+
if (additionsAreLonger) {
|
|
20495
|
+
pushBlock(0, bestOffset, deletionLineIndex, additionLineIndex);
|
|
20496
|
+
pushBlock(pairCount, pairCount, deletionLineIndex, additionLineIndex + bestOffset);
|
|
20497
|
+
pushBlock(0, additions - pairCount - bestOffset, deletionLineIndex + pairCount, additionLineIndex + bestOffset + pairCount);
|
|
20498
|
+
} else {
|
|
20499
|
+
pushBlock(bestOffset, 0, deletionLineIndex, additionLineIndex);
|
|
20500
|
+
pushBlock(pairCount, pairCount, deletionLineIndex + bestOffset, additionLineIndex);
|
|
20501
|
+
pushBlock(deletions - pairCount - bestOffset, 0, deletionLineIndex + bestOffset + pairCount, additionLineIndex + pairCount);
|
|
20502
|
+
}
|
|
20503
|
+
return blocks;
|
|
20504
|
+
}
|
|
20505
|
+
var WHITESPACE = /\s+/g;
|
|
20506
|
+
function stripWhitespace(line) {
|
|
20507
|
+
return line.replace(WHITESPACE, "");
|
|
20508
|
+
}
|
|
20509
|
+
function lineSimilarity(a, b) {
|
|
20510
|
+
if (a === b) return 1;
|
|
20511
|
+
const maxLength = Math.max(a.length, b.length);
|
|
20512
|
+
const minLength = Math.min(a.length, b.length);
|
|
20513
|
+
if (minLength === 0) return 0;
|
|
20514
|
+
let prefix = 0;
|
|
20515
|
+
while (prefix < minLength && a[prefix] === b[prefix]) prefix++;
|
|
20516
|
+
let suffix = 0;
|
|
20517
|
+
while (suffix < minLength - prefix && a[a.length - 1 - suffix] === b[b.length - 1 - suffix]) suffix++;
|
|
20518
|
+
return (prefix + suffix) / maxLength;
|
|
20519
|
+
}
|
|
20520
|
+
|
|
20521
|
+
// node_modules/.pnpm/@pierre+diffs@1.6.4_patch_hash=7a37d94505526b01286480d4f1f5519799f536fae7c931f72a89aab2_7f89f0527c41b64aaa0b77f4c03d048a/node_modules/@pierre/diffs/dist/utils/parsePatchFiles.js
|
|
20522
|
+
var GIT_DIFF_HEADER_FILENAMES = /^diff --git ("a\/(?:[^"\\]|\\.)*"|a\/.+?) ("b\/(?:[^"\\]|\\.)*"|b\/.+?)$/;
|
|
20523
|
+
function processFile(fileDiffString, options) {
|
|
20524
|
+
try {
|
|
20525
|
+
return _processFile(fileDiffString, options);
|
|
20526
|
+
} finally {
|
|
20527
|
+
releaseStringDetachBuffer();
|
|
20528
|
+
}
|
|
20529
|
+
}
|
|
20530
|
+
function _processFile(fileDiffString, { cacheKey, disableLineMatching = false, isGitDiff = GIT_DIFF_FILE_BREAK_REGEX.test(fileDiffString), oldFile, newFile, throwOnError = false } = {}) {
|
|
20531
|
+
let lastHunkEnd = 0;
|
|
20532
|
+
const hunks = splitAtLinePrefix(fileDiffString, "@@ ");
|
|
20533
|
+
let currentFile;
|
|
20534
|
+
const isPartial = oldFile == null || newFile == null;
|
|
20535
|
+
let deletionLineIndex = 0;
|
|
20536
|
+
let additionLineIndex = 0;
|
|
20537
|
+
for (const hunk of hunks) {
|
|
20538
|
+
const lines = splitWithNewlines(hunk);
|
|
20539
|
+
const firstLine = lines[0];
|
|
20540
|
+
if (firstLine == null) {
|
|
20541
|
+
if (throwOnError) throw Error("parsePatchContent: invalid hunk");
|
|
20542
|
+
else console.error("parsePatchContent: invalid hunk", hunk);
|
|
20543
|
+
continue;
|
|
20544
|
+
}
|
|
20545
|
+
const fileHeader = parseHunkHeader(firstLine);
|
|
20546
|
+
let additionLines = 0;
|
|
20547
|
+
let deletionLines = 0;
|
|
20548
|
+
if (fileHeader == null || currentFile == null) {
|
|
20549
|
+
if (currentFile != null) {
|
|
20550
|
+
if (throwOnError) throw Error("parsePatchContent: Invalid hunk");
|
|
20551
|
+
else console.error("parsePatchContent: Invalid hunk", hunk);
|
|
20552
|
+
continue;
|
|
20553
|
+
}
|
|
20554
|
+
currentFile = {
|
|
20555
|
+
name: "",
|
|
20556
|
+
type: "change",
|
|
20557
|
+
hunks: [],
|
|
20558
|
+
splitLineCount: 0,
|
|
20559
|
+
unifiedLineCount: 0,
|
|
20560
|
+
isPartial,
|
|
20561
|
+
additionLines: !isPartial && oldFile != null && newFile != null ? splitFileContents(newFile.contents) : [],
|
|
20562
|
+
deletionLines: !isPartial && oldFile != null && newFile != null ? splitFileContents(oldFile.contents) : [],
|
|
20563
|
+
additionCharacterCount: !isPartial && oldFile != null && newFile != null ? newFile.contents.length : 0,
|
|
20564
|
+
deletionCharacterCount: !isPartial && oldFile != null && newFile != null ? oldFile.contents.length : 0,
|
|
20565
|
+
cacheKey: maybeDetachOptionalString(cacheKey)
|
|
20566
|
+
};
|
|
20567
|
+
if (currentFile.additionLines.length === 1 && newFile?.contents === "") currentFile.additionLines.length = 0;
|
|
20568
|
+
if (currentFile.deletionLines.length === 1 && oldFile?.contents === "") currentFile.deletionLines.length = 0;
|
|
20569
|
+
for (const line of lines) {
|
|
20570
|
+
if (line.startsWith("diff --git")) {
|
|
20571
|
+
const filenameMatch2 = line.trim().match(GIT_DIFF_HEADER_FILENAMES);
|
|
20572
|
+
if (filenameMatch2 == null) {
|
|
20573
|
+
if (throwOnError) throw Error("parsePatchContent: invalid git diff header");
|
|
20574
|
+
else console.error("parsePatchContent: invalid git diff header", line);
|
|
20575
|
+
continue;
|
|
20576
|
+
}
|
|
20577
|
+
const prevName = decodeDiffFileName(filenameMatch2[1], true);
|
|
20578
|
+
const name = decodeDiffFileName(filenameMatch2[2], true);
|
|
20579
|
+
currentFile.name = detachString(name);
|
|
20580
|
+
if (prevName !== name) currentFile.prevName = detachString(prevName);
|
|
20581
|
+
continue;
|
|
20582
|
+
}
|
|
20583
|
+
const filenameMatch = line.startsWith("---") || line.startsWith("+++") ? line.match(FILENAME_HEADER_REGEX) : null;
|
|
20584
|
+
if (filenameMatch != null) {
|
|
20585
|
+
const [, type, rawFileName] = filenameMatch;
|
|
20586
|
+
const fileName = decodeDiffFileName(rawFileName, isGitDiff);
|
|
20587
|
+
if (type === "---" && fileName !== "/dev/null") {
|
|
20588
|
+
const detachedFileName = detachString(fileName);
|
|
20589
|
+
currentFile.prevName = detachedFileName;
|
|
20590
|
+
currentFile.name = detachedFileName;
|
|
20591
|
+
} else if (type === "+++" && fileName !== "/dev/null") currentFile.name = detachString(fileName);
|
|
20592
|
+
} else if (isGitDiff) {
|
|
20593
|
+
if (line.startsWith("new mode ")) currentFile.mode = detachString(line.slice(8).trim());
|
|
20594
|
+
if (line.startsWith("old mode ")) currentFile.prevMode = detachString(line.slice(8).trim());
|
|
20595
|
+
if (line.startsWith("new file mode")) {
|
|
20596
|
+
currentFile.type = "new";
|
|
20597
|
+
currentFile.mode = detachString(line.slice(13).trim());
|
|
20598
|
+
}
|
|
20599
|
+
if (line.startsWith("deleted file mode")) {
|
|
20600
|
+
currentFile.type = "deleted";
|
|
20601
|
+
currentFile.mode = detachString(line.slice(17).trim());
|
|
20602
|
+
}
|
|
20603
|
+
if (line.startsWith("similarity index")) {
|
|
20604
|
+
if (line.startsWith("similarity index 100%")) currentFile.type = "rename-pure";
|
|
20605
|
+
else currentFile.type = "rename-changed";
|
|
20606
|
+
}
|
|
20607
|
+
if (line.startsWith("index ")) {
|
|
20608
|
+
const [, prevObjectId, newObjectId, mode] = line.trim().match(INDEX_LINE_METADATA) ?? [];
|
|
20609
|
+
if (prevObjectId != null) currentFile.prevObjectId = detachString(prevObjectId);
|
|
20610
|
+
if (newObjectId != null) currentFile.newObjectId = detachString(newObjectId);
|
|
20611
|
+
if (mode != null) currentFile.mode = detachString(mode);
|
|
20612
|
+
}
|
|
20613
|
+
if (line.startsWith("rename from ") || line.startsWith("copy from ")) currentFile.prevName = detachString(decodeDiffFileName(line.slice(line.startsWith("rename") ? 12 : 10)));
|
|
20614
|
+
if (line.startsWith("rename to ") || line.startsWith("copy to ")) currentFile.name = detachString(decodeDiffFileName(line.slice(line.startsWith("rename") ? 10 : 8)));
|
|
20615
|
+
}
|
|
20616
|
+
}
|
|
20617
|
+
continue;
|
|
20618
|
+
}
|
|
20619
|
+
let currentContent;
|
|
20620
|
+
let lastLineType;
|
|
20621
|
+
while (lines.length > 0 && (lines[lines.length - 1] === "\n" || lines[lines.length - 1] === "\r" || lines[lines.length - 1] === "\r\n" || lines[lines.length - 1] === "")) lines.pop();
|
|
20622
|
+
const { additionStart, deletionStart } = fileHeader;
|
|
20623
|
+
deletionLineIndex = isPartial ? deletionLineIndex : deletionStart - 1;
|
|
20624
|
+
additionLineIndex = isPartial ? additionLineIndex : additionStart - 1;
|
|
20625
|
+
const hunkData = {
|
|
20626
|
+
collapsedBefore: 0,
|
|
20627
|
+
splitLineCount: 0,
|
|
20628
|
+
splitLineStart: 0,
|
|
20629
|
+
unifiedLineCount: 0,
|
|
20630
|
+
unifiedLineStart: 0,
|
|
20631
|
+
additionCount: fileHeader.additionCount,
|
|
20632
|
+
additionStart,
|
|
20633
|
+
additionLines,
|
|
20634
|
+
deletionCount: fileHeader.deletionCount,
|
|
20635
|
+
deletionStart,
|
|
20636
|
+
deletionLines,
|
|
20637
|
+
deletionLineIndex,
|
|
20638
|
+
additionLineIndex,
|
|
20639
|
+
hunkContent: [],
|
|
20640
|
+
hunkContext: maybeDetachOptionalString(fileHeader.hunkContext),
|
|
20641
|
+
hunkSpecs: detachString(firstLine),
|
|
20642
|
+
noEOFCRAdditions: false,
|
|
20643
|
+
noEOFCRDeletions: false
|
|
20644
|
+
};
|
|
20645
|
+
let parsedAdditionLines = 0;
|
|
20646
|
+
let parsedDeletionLines = 0;
|
|
20647
|
+
for (let lineIndex = 1; lineIndex < lines.length; lineIndex++) {
|
|
20648
|
+
const rawLine = lines[lineIndex];
|
|
20649
|
+
if (parsedAdditionLines >= hunkData.additionCount && parsedDeletionLines >= hunkData.deletionCount && !rawLine.startsWith("\\")) {
|
|
20650
|
+
if (!(isHunkBodyLine(rawLine) && !isFormatPatchVersionSeparator(rawLine))) break;
|
|
20651
|
+
if (throwOnError) throw Error("parsePatchContent: hunk has more lines than expected");
|
|
20652
|
+
}
|
|
20653
|
+
const firstChar = rawLine[0];
|
|
20654
|
+
if (firstChar !== "+" && firstChar !== "-" && firstChar !== " " && firstChar !== "\\") {
|
|
20655
|
+
if (throwOnError) throw Error("parsePatchContent: invalid hunk line");
|
|
20656
|
+
console.error(`parseLineType: Invalid firstChar: "${firstChar}", full line: "${rawLine}"`);
|
|
20657
|
+
console.error("processFile: invalid rawLine:", rawLine);
|
|
20658
|
+
continue;
|
|
20659
|
+
}
|
|
20660
|
+
const type = parseRawLineType(firstChar);
|
|
20661
|
+
if (type === "addition") {
|
|
20662
|
+
if (throwOnError && parsedAdditionLines >= hunkData.additionCount) throw Error("parsePatchContent: hunk has too many addition lines");
|
|
20663
|
+
const line = getParsedLineContent(rawLine);
|
|
20664
|
+
if (currentContent == null || currentContent.type !== "change") {
|
|
20665
|
+
currentContent = createContentGroup("change", deletionLineIndex, additionLineIndex);
|
|
20666
|
+
hunkData.hunkContent.push(currentContent);
|
|
20667
|
+
}
|
|
20668
|
+
additionLineIndex++;
|
|
20669
|
+
parsedAdditionLines++;
|
|
20670
|
+
if (isPartial) {
|
|
20671
|
+
currentFile.additionLines.push(line);
|
|
20672
|
+
currentFile.additionCharacterCount += line.length;
|
|
20673
|
+
}
|
|
20674
|
+
currentContent.additions++;
|
|
20675
|
+
additionLines++;
|
|
20676
|
+
lastLineType = "addition";
|
|
20677
|
+
} else if (type === "deletion") {
|
|
20678
|
+
if (throwOnError && parsedDeletionLines >= hunkData.deletionCount) throw Error("parsePatchContent: hunk has too many deletion lines");
|
|
20679
|
+
const line = getParsedLineContent(rawLine);
|
|
20680
|
+
if (currentContent == null || currentContent.type !== "change") {
|
|
20681
|
+
currentContent = createContentGroup("change", deletionLineIndex, additionLineIndex);
|
|
20682
|
+
hunkData.hunkContent.push(currentContent);
|
|
20683
|
+
}
|
|
20684
|
+
deletionLineIndex++;
|
|
20685
|
+
parsedDeletionLines++;
|
|
20686
|
+
if (isPartial) {
|
|
20687
|
+
currentFile.deletionLines.push(line);
|
|
20688
|
+
currentFile.deletionCharacterCount += line.length;
|
|
20689
|
+
}
|
|
20690
|
+
currentContent.deletions++;
|
|
20691
|
+
deletionLines++;
|
|
20692
|
+
lastLineType = "deletion";
|
|
20693
|
+
} else if (type === "context") {
|
|
20694
|
+
if (throwOnError && (parsedDeletionLines >= hunkData.deletionCount || parsedAdditionLines >= hunkData.additionCount)) throw Error("parsePatchContent: hunk has too many context lines");
|
|
20695
|
+
const line = getParsedLineContent(rawLine);
|
|
20696
|
+
if (currentContent == null || currentContent.type !== "context") {
|
|
20697
|
+
currentContent = createContentGroup("context", deletionLineIndex, additionLineIndex);
|
|
20698
|
+
hunkData.hunkContent.push(currentContent);
|
|
20699
|
+
}
|
|
20700
|
+
additionLineIndex++;
|
|
20701
|
+
deletionLineIndex++;
|
|
20702
|
+
parsedAdditionLines++;
|
|
20703
|
+
parsedDeletionLines++;
|
|
20704
|
+
if (isPartial) {
|
|
20705
|
+
currentFile.deletionLines.push(line);
|
|
20706
|
+
currentFile.additionLines.push(line);
|
|
20707
|
+
currentFile.deletionCharacterCount += line.length;
|
|
20708
|
+
currentFile.additionCharacterCount += line.length;
|
|
20709
|
+
}
|
|
20710
|
+
currentContent.lines++;
|
|
20711
|
+
lastLineType = "context";
|
|
20712
|
+
} else if (type === "metadata" && currentContent != null) {
|
|
20713
|
+
if (currentContent.type === "context") {
|
|
20714
|
+
hunkData.noEOFCRAdditions = true;
|
|
20715
|
+
hunkData.noEOFCRDeletions = true;
|
|
20716
|
+
} else if (lastLineType === "deletion") hunkData.noEOFCRDeletions = true;
|
|
20717
|
+
else if (lastLineType === "addition") hunkData.noEOFCRAdditions = true;
|
|
20718
|
+
if (isPartial && (lastLineType === "addition" || lastLineType === "context")) {
|
|
20719
|
+
const lastIndex = currentFile.additionLines.length - 1;
|
|
20720
|
+
if (lastIndex >= 0) {
|
|
20721
|
+
const line = currentFile.additionLines[lastIndex];
|
|
20722
|
+
const cleanedLine = cleanLastNewline(line);
|
|
20723
|
+
currentFile.additionLines[lastIndex] = cleanedLine;
|
|
20724
|
+
currentFile.additionCharacterCount += cleanedLine.length - line.length;
|
|
20725
|
+
}
|
|
20726
|
+
}
|
|
20727
|
+
if (isPartial && (lastLineType === "deletion" || lastLineType === "context")) {
|
|
20728
|
+
const lastIndex = currentFile.deletionLines.length - 1;
|
|
20729
|
+
if (lastIndex >= 0) {
|
|
20730
|
+
const line = currentFile.deletionLines[lastIndex];
|
|
20731
|
+
const cleanedLine = cleanLastNewline(line);
|
|
20732
|
+
currentFile.deletionLines[lastIndex] = cleanedLine;
|
|
20733
|
+
currentFile.deletionCharacterCount += cleanedLine.length - line.length;
|
|
20734
|
+
}
|
|
20735
|
+
}
|
|
20736
|
+
}
|
|
20737
|
+
}
|
|
20738
|
+
if (parsedAdditionLines !== hunkData.additionCount || parsedDeletionLines !== hunkData.deletionCount) {
|
|
20739
|
+
if (throwOnError) throw Error("parsePatchContent: hunk line count mismatch");
|
|
20740
|
+
console.error(`parsePatchContent: hunk line count mismatch: "${firstLine.trimEnd()}", declared old/new ${hunkData.deletionCount}/${hunkData.additionCount}, parsed old/new ${parsedDeletionLines}/${parsedAdditionLines}`);
|
|
20741
|
+
const repairedAdditionStart = getHunkSideStartBoundary(hunkData.additionStart, hunkData.additionCount) + (parsedAdditionLines === 0 ? 0 : 1);
|
|
20742
|
+
const repairedDeletionStart = getHunkSideStartBoundary(hunkData.deletionStart, hunkData.deletionCount) + (parsedDeletionLines === 0 ? 0 : 1);
|
|
20743
|
+
if (!isPartial) {
|
|
20744
|
+
const additionStartDelta = repairedAdditionStart - hunkData.additionStart;
|
|
20745
|
+
const deletionStartDelta = repairedDeletionStart - hunkData.deletionStart;
|
|
20746
|
+
hunkData.additionLineIndex += additionStartDelta;
|
|
20747
|
+
hunkData.deletionLineIndex += deletionStartDelta;
|
|
20748
|
+
for (const content of hunkData.hunkContent) {
|
|
20749
|
+
content.additionLineIndex += additionStartDelta;
|
|
20750
|
+
content.deletionLineIndex += deletionStartDelta;
|
|
20751
|
+
}
|
|
20752
|
+
}
|
|
20753
|
+
hunkData.additionStart = repairedAdditionStart;
|
|
20754
|
+
hunkData.deletionStart = repairedDeletionStart;
|
|
20755
|
+
hunkData.additionCount = parsedAdditionLines;
|
|
20756
|
+
hunkData.deletionCount = parsedDeletionLines;
|
|
20757
|
+
}
|
|
20758
|
+
hunkData.additionLines = additionLines;
|
|
20759
|
+
hunkData.deletionLines = deletionLines;
|
|
20760
|
+
hunkData.collapsedBefore = Math.max(getHunkSideStartBoundary(hunkData.additionStart, hunkData.additionCount) - lastHunkEnd, 0);
|
|
20761
|
+
currentFile.hunks.push(hunkData);
|
|
20762
|
+
lastHunkEnd = getHunkSideEndBoundary(hunkData.additionStart, hunkData.additionCount);
|
|
20763
|
+
for (const content of hunkData.hunkContent) if (content.type === "context") {
|
|
20764
|
+
hunkData.splitLineCount += content.lines;
|
|
20765
|
+
hunkData.unifiedLineCount += content.lines;
|
|
20766
|
+
} else {
|
|
20767
|
+
hunkData.splitLineCount += Math.max(content.additions, content.deletions);
|
|
20768
|
+
hunkData.unifiedLineCount += content.deletions + content.additions;
|
|
20769
|
+
}
|
|
20770
|
+
hunkData.splitLineStart = currentFile.splitLineCount + hunkData.collapsedBefore;
|
|
20771
|
+
hunkData.unifiedLineStart = currentFile.unifiedLineCount + hunkData.collapsedBefore;
|
|
20772
|
+
currentFile.splitLineCount += hunkData.collapsedBefore + hunkData.splitLineCount;
|
|
20773
|
+
currentFile.unifiedLineCount += hunkData.collapsedBefore + hunkData.unifiedLineCount;
|
|
20774
|
+
}
|
|
20775
|
+
if (currentFile == null) return;
|
|
20776
|
+
if (throwOnError && isPartial && !isGitDiff && currentFile.hunks.length === 0) throw Error("parsePatchContent: unified file has no hunks");
|
|
20777
|
+
if (currentFile.hunks.length > 0 && !isPartial && currentFile.additionLines.length > 0 && currentFile.deletionLines.length > 0) {
|
|
20778
|
+
const lastHunk = currentFile.hunks[currentFile.hunks.length - 1];
|
|
20779
|
+
const lastHunkEnd2 = getHunkSideEndBoundary(lastHunk.additionStart, lastHunk.additionCount);
|
|
20780
|
+
const totalFileLines = currentFile.additionLines.length;
|
|
20781
|
+
const collapsedAfter = Math.max(totalFileLines - lastHunkEnd2, 0);
|
|
20782
|
+
currentFile.splitLineCount += collapsedAfter;
|
|
20783
|
+
currentFile.unifiedLineCount += collapsedAfter;
|
|
20784
|
+
}
|
|
20785
|
+
if (!isGitDiff) {
|
|
20786
|
+
if (currentFile.prevName != null && currentFile.name !== currentFile.prevName) {
|
|
20787
|
+
if (currentFile.hunks.length > 0) currentFile.type = "rename-changed";
|
|
20788
|
+
else currentFile.type = "rename-pure";
|
|
20789
|
+
} else if ((oldFile == null || oldFile.contents === "") && newFile != null && newFile.contents !== "") currentFile.type = "new";
|
|
20790
|
+
else if (oldFile != null && oldFile.contents !== "" && (newFile == null || newFile.contents === "")) currentFile.type = "deleted";
|
|
20791
|
+
}
|
|
20792
|
+
if (currentFile.type !== "rename-pure" && currentFile.type !== "rename-changed") currentFile.prevName = void 0;
|
|
20793
|
+
if (!disableLineMatching) realignChangeContentBySimilarity(currentFile);
|
|
20794
|
+
return currentFile;
|
|
20795
|
+
}
|
|
20796
|
+
function decodeDiffFileName(value2, stripGitPrefix = false) {
|
|
20797
|
+
const rawName = value2.trim();
|
|
20798
|
+
const name = rawName.startsWith('"') ? parseQuotedDiffFileName(rawName)?.fileName ?? rawName : rawName;
|
|
20799
|
+
return stripGitPrefix && (name.startsWith("a/") || name.startsWith("b/")) ? name.slice(2) : name;
|
|
20800
|
+
}
|
|
20801
|
+
function splitFileContents(contents) {
|
|
20802
|
+
const lines = splitWithNewlines(contents);
|
|
20803
|
+
for (let index = 0; index < lines.length; index++) lines[index] = detachString(lines[index]);
|
|
20804
|
+
return lines;
|
|
20805
|
+
}
|
|
20806
|
+
function splitWithNewlines(contents) {
|
|
20807
|
+
if (contents.length === 0) return [""];
|
|
20808
|
+
const lines = [];
|
|
20809
|
+
let startIndex = 0;
|
|
20810
|
+
for (; ; ) {
|
|
20811
|
+
const newlineIndex = contents.indexOf("\n", startIndex);
|
|
20812
|
+
if (newlineIndex === -1) break;
|
|
20813
|
+
lines.push(contents.slice(startIndex, newlineIndex + 1));
|
|
20814
|
+
startIndex = newlineIndex + 1;
|
|
20815
|
+
}
|
|
20816
|
+
if (startIndex < contents.length) lines.push(contents.slice(startIndex));
|
|
20817
|
+
return lines;
|
|
20818
|
+
}
|
|
20819
|
+
function isHunkBodyLine(line) {
|
|
20820
|
+
const firstChar = line[0];
|
|
20821
|
+
return firstChar === "+" || firstChar === "-" || firstChar === " ";
|
|
20822
|
+
}
|
|
20823
|
+
function isFormatPatchVersionSeparator(line) {
|
|
20824
|
+
if (!line.startsWith("--")) return false;
|
|
20825
|
+
for (let index = 2; index < line.length; index++) {
|
|
20826
|
+
const char = line[index];
|
|
20827
|
+
if (char !== " " && char !== " " && char !== "\n" && char !== "\r") return false;
|
|
20828
|
+
}
|
|
20829
|
+
return true;
|
|
20830
|
+
}
|
|
20831
|
+
function parseHunkHeader(line) {
|
|
20832
|
+
if (!line.startsWith("@@ -")) return;
|
|
20833
|
+
let index = 4;
|
|
20834
|
+
const deletionStartResult = readPositiveInteger(line, index);
|
|
20835
|
+
if (deletionStartResult == null) return;
|
|
20836
|
+
const deletionStart = deletionStartResult.value;
|
|
20837
|
+
index = deletionStartResult.endIndex;
|
|
20838
|
+
let deletionCount = 1;
|
|
20839
|
+
if (line[index] === ",") {
|
|
20840
|
+
const deletionCountResult = readPositiveInteger(line, index + 1);
|
|
20841
|
+
if (deletionCountResult == null) return;
|
|
20842
|
+
deletionCount = deletionCountResult.value;
|
|
20843
|
+
index = deletionCountResult.endIndex;
|
|
20844
|
+
}
|
|
20845
|
+
if (line[index] !== " " || line[index + 1] !== "+") return;
|
|
20846
|
+
index += 2;
|
|
20847
|
+
const additionStartResult = readPositiveInteger(line, index);
|
|
20848
|
+
if (additionStartResult == null) return;
|
|
20849
|
+
const additionStart = additionStartResult.value;
|
|
20850
|
+
index = additionStartResult.endIndex;
|
|
20851
|
+
let additionCount = 1;
|
|
20852
|
+
if (line[index] === ",") {
|
|
20853
|
+
const additionCountResult = readPositiveInteger(line, index + 1);
|
|
20854
|
+
if (additionCountResult == null) return;
|
|
20855
|
+
additionCount = additionCountResult.value;
|
|
20856
|
+
index = additionCountResult.endIndex;
|
|
20857
|
+
}
|
|
20858
|
+
if (line[index] !== " " || line[index + 1] !== "@" || line[index + 2] !== "@") return;
|
|
20859
|
+
let hunkContext;
|
|
20860
|
+
const contextStartIndex = index + 3;
|
|
20861
|
+
if (line[contextStartIndex] === " ") hunkContext = trimLineEnd(line.slice(contextStartIndex + 1));
|
|
20862
|
+
return {
|
|
20863
|
+
additionCount,
|
|
20864
|
+
additionStart,
|
|
20865
|
+
deletionCount,
|
|
20866
|
+
deletionStart,
|
|
20867
|
+
hunkContext
|
|
20868
|
+
};
|
|
20869
|
+
}
|
|
20870
|
+
function readPositiveInteger(value2, startIndex) {
|
|
20871
|
+
let index = startIndex;
|
|
20872
|
+
let parsedValue = 0;
|
|
20873
|
+
for (; index < value2.length; index++) {
|
|
20874
|
+
const digit = value2.charCodeAt(index) - 48;
|
|
20875
|
+
if (digit < 0 || digit > 9) break;
|
|
20876
|
+
parsedValue = parsedValue * 10 + digit;
|
|
20877
|
+
}
|
|
20878
|
+
if (index === startIndex) return;
|
|
20879
|
+
return {
|
|
20880
|
+
value: parsedValue,
|
|
20881
|
+
endIndex: index
|
|
20882
|
+
};
|
|
20883
|
+
}
|
|
20884
|
+
function trimLineEnd(value2) {
|
|
20885
|
+
if (value2.endsWith("\r\n")) return value2.slice(0, -2);
|
|
20886
|
+
if (value2.endsWith("\n")) return value2.slice(0, -1);
|
|
20887
|
+
return value2;
|
|
20888
|
+
}
|
|
20889
|
+
function splitAtLinePrefix(contents, prefix) {
|
|
20890
|
+
if (contents.length === 0) return [""];
|
|
20891
|
+
const newlinePrefix = `
|
|
20892
|
+
${prefix}`;
|
|
20893
|
+
const firstBoundaryIndex = contents.startsWith(prefix) ? 0 : findLinePrefixIndex(contents, newlinePrefix, 0);
|
|
20894
|
+
if (firstBoundaryIndex === -1) return [contents];
|
|
20895
|
+
const parts = [];
|
|
20896
|
+
if (firstBoundaryIndex > 0) parts.push(contents.slice(0, firstBoundaryIndex));
|
|
20897
|
+
let startIndex = firstBoundaryIndex;
|
|
20898
|
+
for (; ; ) {
|
|
20899
|
+
const nextBoundaryIndex = findLinePrefixIndex(contents, newlinePrefix, startIndex + 1);
|
|
20900
|
+
if (nextBoundaryIndex === -1) break;
|
|
20901
|
+
parts.push(contents.slice(startIndex, nextBoundaryIndex));
|
|
20902
|
+
startIndex = nextBoundaryIndex;
|
|
20903
|
+
}
|
|
20904
|
+
parts.push(contents.slice(startIndex));
|
|
20905
|
+
return parts;
|
|
20906
|
+
}
|
|
20907
|
+
function findLinePrefixIndex(contents, newlinePrefix, fromIndex) {
|
|
20908
|
+
const index = contents.indexOf(newlinePrefix, fromIndex);
|
|
20909
|
+
return index === -1 ? -1 : index + 1;
|
|
20910
|
+
}
|
|
20911
|
+
function maybeDetachOptionalString(value2) {
|
|
20912
|
+
return value2 == null ? value2 : detachString(value2);
|
|
20913
|
+
}
|
|
20914
|
+
function parseRawLineType(firstChar) {
|
|
20915
|
+
return firstChar === " " ? "context" : firstChar === "\\" ? "metadata" : firstChar === "+" ? "addition" : "deletion";
|
|
20916
|
+
}
|
|
20917
|
+
function getParsedLineContent(rawLine) {
|
|
20918
|
+
const processedLine = rawLine.slice(1);
|
|
20919
|
+
return detachString(processedLine === "" ? "\n" : processedLine);
|
|
20920
|
+
}
|
|
20921
|
+
function createContentGroup(type, deletionLineIndex, additionLineIndex) {
|
|
20922
|
+
if (type === "change") return {
|
|
20923
|
+
type: "change",
|
|
20924
|
+
additions: 0,
|
|
20925
|
+
deletions: 0,
|
|
20926
|
+
additionLineIndex,
|
|
20927
|
+
deletionLineIndex
|
|
20928
|
+
};
|
|
20929
|
+
return {
|
|
20930
|
+
type: "context",
|
|
20931
|
+
lines: 0,
|
|
20932
|
+
additionLineIndex,
|
|
20933
|
+
deletionLineIndex
|
|
20934
|
+
};
|
|
20935
|
+
}
|
|
20936
|
+
|
|
20937
|
+
// packages/walkthroughs/src/rules/captured-excerpt.ts
|
|
20938
|
+
var MAX_CAPTURED_HUNK_LENGTH = 1048576;
|
|
20939
|
+
function capturedExcerpt(job, step) {
|
|
20940
|
+
if (job.run.state.status !== "ready") return void 0;
|
|
20941
|
+
const excerpt = job.run.state.content.stops[step - 1]?.excerpts[0];
|
|
20942
|
+
if (!excerpt) return void 0;
|
|
20943
|
+
const { path, side, start, end } = excerpt;
|
|
20944
|
+
if (start < 1 || end < start) return void 0;
|
|
20945
|
+
const matches = [];
|
|
20946
|
+
const options = { disableLineMatching: true, throwOnError: true };
|
|
20947
|
+
try {
|
|
20948
|
+
for (const section of job.patch.split(/(?=^diff --git )/m)) {
|
|
20949
|
+
const [header2, ...hunks] = section.split(/(?=^@@ )/m);
|
|
20950
|
+
if (!header2 || hunks.length === 0) continue;
|
|
20951
|
+
const identity3 = processFile(header2, options);
|
|
20952
|
+
if (!identity3 || (side === "old" ? identity3.prevName ?? identity3.name : identity3.name) !== path)
|
|
20953
|
+
continue;
|
|
20954
|
+
const file = processFile(section, options);
|
|
20955
|
+
file?.hunks.forEach((hunk, index) => {
|
|
20956
|
+
const [first, count] = side === "old" ? [hunk.deletionStart, hunk.deletionCount] : [hunk.additionStart, hunk.additionCount];
|
|
20957
|
+
if (start >= first && end < first + count && hunks[index] !== void 0)
|
|
20958
|
+
matches.push(`${header2}${hunks[index]}`);
|
|
20959
|
+
});
|
|
20960
|
+
}
|
|
20961
|
+
const [match] = matches;
|
|
20962
|
+
return matches.length === 1 && match && match.length <= MAX_CAPTURED_HUNK_LENGTH ? match : void 0;
|
|
20963
|
+
} catch {
|
|
20964
|
+
return void 0;
|
|
20965
|
+
}
|
|
20966
|
+
}
|
|
20967
|
+
|
|
20968
|
+
// packages/walkthroughs/src/services/read-walkthrough-service.ts
|
|
20325
20969
|
var ReadWalkthroughService = class _ReadWalkthroughService extends Context142.Service()("@porcelain/walkthroughs/ReadWalkthroughService") {
|
|
20326
20970
|
static layer = Layer99.effect(
|
|
20327
20971
|
_ReadWalkthroughService,
|
|
@@ -20345,8 +20989,10 @@ var ReadWalkthroughService = class _ReadWalkthroughService extends Context142.Se
|
|
|
20345
20989
|
worktreePath: job.worktreePath,
|
|
20346
20990
|
baseRef: job.run.baseRef
|
|
20347
20991
|
}).pipe(Effect195.catch(() => Effect195.succeed(void 0)));
|
|
20992
|
+
const capturedPatch = job !== void 0 && job.run.id === input.excerptRunId && input.excerptStep !== void 0 ? capturedExcerpt(job, input.excerptStep) : void 0;
|
|
20348
20993
|
return {
|
|
20349
20994
|
walkthrough,
|
|
20995
|
+
...capturedPatch === void 0 ? {} : { capturedPatch },
|
|
20350
20996
|
freshness: walkthrough === void 0 || identity3 === void 0 ? "unknown" : identity3.baseOid !== walkthrough.baseOid || identity3.contentTreeOid !== walkthrough.contentTreeOid ? "changed" : "current",
|
|
20351
20997
|
attempt: ready !== void 0 && latest !== void 0 && latest.state.status !== "ready" && latest.id !== ready.id ? latest : void 0
|
|
20352
20998
|
};
|
|
@@ -23021,10 +23667,7 @@ var ReadWalkthroughUseCase = class _ReadWalkthroughUseCase extends Context177.Se
|
|
|
23021
23667
|
execute: Effect229.fn("ReadWalkthroughUseCase.execute")(function* (input) {
|
|
23022
23668
|
return yield* access2.read(
|
|
23023
23669
|
input.worktreeId,
|
|
23024
|
-
() =>
|
|
23025
|
-
const { walkthrough, attempt, freshness } = yield* store.execute(input);
|
|
23026
|
-
return { walkthrough, attempt, freshness };
|
|
23027
|
-
})
|
|
23670
|
+
() => store.execute(input)
|
|
23028
23671
|
);
|
|
23029
23672
|
})
|
|
23030
23673
|
};
|
|
@@ -23462,7 +24105,7 @@ function walkthroughsRoutes(useCases) {
|
|
|
23462
24105
|
({ params, payload }) => useCases.start.execute({ ...params, ...payload }).pipe(Effect239.map(presentWalkthrough))
|
|
23463
24106
|
).handle(
|
|
23464
24107
|
"readWalkthrough",
|
|
23465
|
-
({ params }) => useCases.read.execute(params).pipe(
|
|
24108
|
+
({ params, query }) => useCases.read.execute({ ...params, ...query }).pipe(
|
|
23466
24109
|
Effect239.map((value2) => ({
|
|
23467
24110
|
...value2,
|
|
23468
24111
|
attempt: value2.attempt === void 0 ? void 0 : presentWalkthrough(value2.attempt),
|