@staff0rd/assist 0.860.0 → 0.862.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/dist/index.js CHANGED
@@ -6,7 +6,7 @@ import { Command } from "commander";
6
6
  // package.json
7
7
  var package_default = {
8
8
  name: "@staff0rd/assist",
9
- version: "0.860.0",
9
+ version: "0.862.0",
10
10
  type: "module",
11
11
  main: "dist/index.js",
12
12
  bin: {
@@ -3304,18 +3304,23 @@ function toChecklist(value) {
3304
3304
  }
3305
3305
 
3306
3306
  // src/commands/sessions/shared/toReviewComments.ts
3307
+ function isSide(value) {
3308
+ return value === "LEFT" || value === "RIGHT";
3309
+ }
3307
3310
  function isReviewComment(value) {
3308
3311
  const comment3 = value;
3309
3312
  return typeof comment3?.path === "string" && Number.isInteger(comment3.startLine) && Number.isInteger(comment3.endLine) && typeof comment3.quote === "string" && typeof comment3.note === "string" && comment3.note.trim() !== "";
3310
3313
  }
3311
3314
  function toReviewComments(value) {
3312
3315
  if (!Array.isArray(value)) return void 0;
3313
- return value.filter(isReviewComment).map(({ path: path109, startLine, endLine, quote, note }) => ({
3316
+ return value.filter(isReviewComment).map(({ path: path109, startLine, endLine, quote, note, startSide, side }) => ({
3314
3317
  path: path109,
3315
3318
  startLine,
3316
3319
  endLine,
3317
3320
  quote,
3318
- note
3321
+ note,
3322
+ ...isSide(startSide) ? { startSide } : {},
3323
+ ...isSide(side) ? { side } : {}
3319
3324
  }));
3320
3325
  }
3321
3326
 
@@ -15225,11 +15230,12 @@ function assertProjectScope() {
15225
15230
 
15226
15231
  // src/shared/runGhOrThrow.ts
15227
15232
  import { execFileSync as execFileSync4 } from "child_process";
15228
- function runGhOrThrow(args, fallbackMessage) {
15233
+ function runGhOrThrow(args, fallbackMessage, input) {
15229
15234
  try {
15230
15235
  execFileSync4("gh", args, {
15231
- stdio: ["ignore", "ignore", "pipe"],
15232
- encoding: "utf8"
15236
+ stdio: [input === void 0 ? "ignore" : "pipe", "ignore", "pipe"],
15237
+ encoding: "utf8",
15238
+ ...input === void 0 ? {} : { input }
15233
15239
  });
15234
15240
  } catch (error) {
15235
15241
  const stderr = error.stderr;
@@ -36334,19 +36340,7 @@ function saveHighLevelReview(record) {
36334
36340
  return path109;
36335
36341
  }
36336
36342
 
36337
- // src/commands/review/highLevel/submitHighLevelReview.ts
36338
- import { randomUUID as randomUUID19 } from "crypto";
36339
-
36340
- // src/commands/review/highLevel/formatHighLevelReviewBody.ts
36341
- function indentContinuation(text18) {
36342
- return text18.replace(/\n/g, "\n ");
36343
- }
36344
- function formatItem(item) {
36345
- if (!item.comment) return void 0;
36346
- return `**${item.title}**
36347
-
36348
- ${item.comment}`;
36349
- }
36343
+ // src/commands/review/highLevel/formatReviewComment.ts
36350
36344
  function formatReviewComment({
36351
36345
  path: path109,
36352
36346
  startLine,
@@ -36355,7 +36349,15 @@ function formatReviewComment({
36355
36349
  note
36356
36350
  }) {
36357
36351
  const lines2 = startLine === endLine ? `${startLine}` : `${startLine}-${endLine}`;
36358
- return `- \`${path109}:${lines2}\` ${quote}: ${indentContinuation(note)}`;
36352
+ return `- \`${path109}:${lines2}\` ${quote}: ${note.replace(/\n/g, "\n ")}`;
36353
+ }
36354
+
36355
+ // src/commands/review/highLevel/formatHighLevelReviewBody.ts
36356
+ function formatItem(item) {
36357
+ if (!item.comment) return void 0;
36358
+ return `**${item.title}**
36359
+
36360
+ ${item.comment}`;
36359
36361
  }
36360
36362
  function formatHighLevelReviewBody(items2, reviewComments = []) {
36361
36363
  const sections = items2.map(formatItem).filter((section2) => section2 !== void 0);
@@ -36369,48 +36371,125 @@ ${reviewComments.map(formatReviewComment).join("\n")}`
36369
36371
  }
36370
36372
 
36371
36373
  // src/commands/review/highLevel/postHighLevelReview.ts
36372
- var FLAGS = {
36373
- APPROVE: "--approve",
36374
- COMMENT: "--comment",
36375
- REQUEST_CHANGES: "--request-changes"
36376
- };
36377
- function postHighLevelReview(repo, prNumber, event, body) {
36378
- const args = ["pr", "review", String(prNumber), "--repo", repo, FLAGS[event]];
36379
- if (body) args.push("--body", body);
36380
- runGhOrThrow(args, `Could not review ${repo}#${prNumber}`);
36374
+ function toLineComment(comment3) {
36375
+ const side = comment3.side ?? "RIGHT";
36376
+ const startSide = comment3.startSide ?? "RIGHT";
36377
+ const single = comment3.startLine === comment3.endLine && startSide === side;
36378
+ return {
36379
+ path: comment3.path,
36380
+ body: comment3.note,
36381
+ line: comment3.endLine,
36382
+ side,
36383
+ ...single ? {} : { start_line: comment3.startLine, start_side: startSide }
36384
+ };
36385
+ }
36386
+ function postHighLevelReview(repo, prNumber, { event, body, comments: comments3 }) {
36387
+ const payload = {
36388
+ event,
36389
+ ...body ? { body } : {},
36390
+ comments: comments3.map(toLineComment)
36391
+ };
36392
+ runGhOrThrow(
36393
+ [
36394
+ "api",
36395
+ `repos/${repo}/pulls/${prNumber}/reviews`,
36396
+ "--method",
36397
+ "POST",
36398
+ "--input",
36399
+ "-"
36400
+ ],
36401
+ `Could not review ${repo}#${prNumber}`,
36402
+ JSON.stringify(payload)
36403
+ );
36381
36404
  }
36382
36405
 
36383
- // src/commands/review/highLevel/submitHighLevelReview.ts
36384
- var EVENTS = {
36385
- approve: "APPROVE",
36386
- comment: "COMMENT",
36387
- "request-changes": "REQUEST_CHANGES"
36388
- };
36389
- var LABELS = {
36390
- APPROVE: "Approve",
36391
- COMMENT: "Comment on",
36392
- REQUEST_CHANGES: "Request changes on"
36393
- };
36394
- function post(record, event, body) {
36395
- const target = `${record.repo}#${record.prNumber}`;
36406
+ // src/commands/review/highLevel/patchHunkLines.ts
36407
+ var HUNK_HEADER2 = /^@@ -(\d+)(?:,\d+)? \+(\d+)/;
36408
+ function patchHunkLines(patch2) {
36409
+ const hunks = [];
36410
+ let current;
36411
+ let left = 0;
36412
+ let right = 0;
36413
+ for (const line of patch2.split("\n")) {
36414
+ const header = HUNK_HEADER2.exec(line);
36415
+ if (header) {
36416
+ current = { LEFT: /* @__PURE__ */ new Set(), RIGHT: /* @__PURE__ */ new Set() };
36417
+ hunks.push(current);
36418
+ left = Number(header[1]);
36419
+ right = Number(header[2]);
36420
+ } else if (!current || line.startsWith("\\")) continue;
36421
+ else if (line.startsWith("+")) current.RIGHT.add(right++);
36422
+ else if (line.startsWith("-")) current.LEFT.add(left++);
36423
+ else {
36424
+ current.LEFT.add(left++);
36425
+ current.RIGHT.add(right++);
36426
+ }
36427
+ }
36428
+ return hunks;
36429
+ }
36430
+
36431
+ // src/commands/review/highLevel/splitHighLevelReviewComments.ts
36432
+ function inHunk(comment3, hunk) {
36433
+ return hunk[comment3.startSide ?? "RIGHT"].has(comment3.startLine) && hunk[comment3.side ?? "RIGHT"].has(comment3.endLine);
36434
+ }
36435
+ function splitHighLevelReviewComments(comments3, files) {
36436
+ const hunks = new Map(
36437
+ files.map((file) => [file.path, patchHunkLines(file.patch ?? "")])
36438
+ );
36439
+ const split = { lineLevel: [], remainder: [] };
36440
+ for (const comment3 of comments3) {
36441
+ const onDiff = hunks.get(comment3.path)?.some((hunk) => inHunk(comment3, hunk));
36442
+ (onDiff ? split.lineLevel : split.remainder).push(comment3);
36443
+ }
36444
+ return split;
36445
+ }
36446
+
36447
+ // src/commands/review/highLevel/splitQueuedComments.ts
36448
+ function splitQueuedComments(record) {
36449
+ const queued = record.reviewComments ?? [];
36450
+ if (queued.length === 0) return { lineLevel: [], remainder: [] };
36396
36451
  try {
36397
- postHighLevelReview(record.repo, record.prNumber, event, body);
36452
+ const files = fetchHighLevelFiles(record.prNumber, record.repo);
36453
+ return splitHighLevelReviewComments(queued, files);
36398
36454
  } catch (error) {
36399
36455
  console.error(
36400
- `Could not post the review to ${target}: ${error.message}`
36456
+ `Could not read the PR diff, so every comment goes in the PR-level body: ${error.message}`
36401
36457
  );
36402
- process.exit(1);
36458
+ return { lineLevel: [], remainder: queued };
36403
36459
  }
36404
- console.log(`Review (${event}) posted to ${target}.`);
36405
36460
  }
36406
- async function previewApproved(sessionId, record, event, body) {
36461
+
36462
+ // src/commands/review/highLevel/previewHighLevelReview.ts
36463
+ import { randomUUID as randomUUID19 } from "crypto";
36464
+
36465
+ // src/commands/review/highLevel/formatHighLevelReviewPreview.ts
36466
+ function formatHighLevelReviewPreview(lineLevel, body) {
36467
+ if (lineLevel.length === 0) return body;
36468
+ const sections = [
36469
+ `### Line-level comments
36470
+
36471
+ ${lineLevel.map(formatReviewComment).join("\n")}`
36472
+ ];
36473
+ if (body) sections.push(`### PR-level body
36474
+
36475
+ ${body}`);
36476
+ return sections.join("\n\n");
36477
+ }
36478
+
36479
+ // src/commands/review/highLevel/previewHighLevelReview.ts
36480
+ var LABELS = {
36481
+ APPROVE: "Approve",
36482
+ COMMENT: "Comment on",
36483
+ REQUEST_CHANGES: "Request changes on"
36484
+ };
36485
+ async function previewHighLevelReview(sessionId, record, submission) {
36407
36486
  const decision = await awaitPreviewApproval(
36408
36487
  "Review",
36409
36488
  {
36410
36489
  sessionId,
36411
36490
  requestId: randomUUID19(),
36412
- title: `${LABELS[event]} ${record.repo}#${record.prNumber}`,
36413
- body,
36491
+ title: `${LABELS[submission.event]} ${record.repo}#${record.prNumber}`,
36492
+ body: formatHighLevelReviewPreview(submission.comments, submission.body),
36414
36493
  prNumber: record.prNumber,
36415
36494
  kind: "pr-comment"
36416
36495
  },
@@ -36418,13 +36497,38 @@ async function previewApproved(sessionId, record, event, body) {
36418
36497
  );
36419
36498
  return decision.decision === "approve" && !decision.dismissed;
36420
36499
  }
36500
+
36501
+ // src/commands/review/highLevel/submitHighLevelReview.ts
36502
+ var EVENTS = {
36503
+ approve: "APPROVE",
36504
+ comment: "COMMENT",
36505
+ "request-changes": "REQUEST_CHANGES"
36506
+ };
36507
+ function post(record, submission) {
36508
+ const target = `${record.repo}#${record.prNumber}`;
36509
+ try {
36510
+ postHighLevelReview(record.repo, record.prNumber, submission);
36511
+ } catch (error) {
36512
+ console.error(
36513
+ `Could not post the review to ${target}: ${error.message}`
36514
+ );
36515
+ process.exit(1);
36516
+ }
36517
+ console.log(`Review (${submission.event}) posted to ${target}.`);
36518
+ }
36421
36519
  async function submitHighLevelReview(sessionId, record) {
36422
36520
  const event = EVENTS[record.verdict];
36423
- const body = formatHighLevelReviewBody(record.items, record.reviewComments);
36521
+ const { lineLevel, remainder } = splitQueuedComments(record);
36522
+ const submission = {
36523
+ event,
36524
+ body: formatHighLevelReviewBody(record.items, remainder),
36525
+ comments: lineLevel
36526
+ };
36424
36527
  if (event === "APPROVE" && !record.reviewComments?.length)
36425
- return post(record, event, body);
36426
- if (body && await previewApproved(sessionId, record, event, body))
36427
- return post(record, event, body);
36528
+ return post(record, submission);
36529
+ const hasContent = submission.body || lineLevel.length > 0;
36530
+ if (hasContent && await previewHighLevelReview(sessionId, record, submission))
36531
+ return post(record, submission);
36428
36532
  console.log("Nothing was posted to GitHub.");
36429
36533
  }
36430
36534
 
@@ -36806,7 +36910,7 @@ function partitionFindings(findings) {
36806
36910
 
36807
36911
  // src/commands/review/buildDiffLineIndex.ts
36808
36912
  var FILE_HEADER = /^\+\+\+ (?:b\/)?(.+)$/;
36809
- var HUNK_HEADER2 = /^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@/;
36913
+ var HUNK_HEADER3 = /^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@/;
36810
36914
  function buildDiffLineIndex(diff3) {
36811
36915
  const index2 = /* @__PURE__ */ new Map();
36812
36916
  let currentFile = null;
@@ -36817,7 +36921,7 @@ function buildDiffLineIndex(diff3) {
36817
36921
  currentFile = fileMatch[1] === "/dev/null" ? null : fileMatch[1];
36818
36922
  continue;
36819
36923
  }
36820
- const hunkMatch = line.match(HUNK_HEADER2);
36924
+ const hunkMatch = line.match(HUNK_HEADER3);
36821
36925
  if (hunkMatch) {
36822
36926
  newLine = Number(hunkMatch[1]);
36823
36927
  continue;
@@ -38253,7 +38357,7 @@ async function runReviewPipeline(paths, options2) {
38253
38357
 
38254
38358
  // src/commands/review/annotateDiffWithLineNumbers.ts
38255
38359
  var FILE_HEADER2 = /^\+\+\+ (?:b\/)?(.+)$/;
38256
- var HUNK_HEADER3 = /^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@/;
38360
+ var HUNK_HEADER4 = /^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@/;
38257
38361
  var GUTTER_WIDTH = 6;
38258
38362
  function gutter(lineNumber) {
38259
38363
  const label2 = lineNumber === null ? "" : String(lineNumber);
@@ -38267,7 +38371,7 @@ function annotateDiffWithLineNumbers(diff3) {
38267
38371
  inFile = true;
38268
38372
  return gutter(null) + line;
38269
38373
  }
38270
- const hunkMatch = line.match(HUNK_HEADER3);
38374
+ const hunkMatch = line.match(HUNK_HEADER4);
38271
38375
  if (hunkMatch) {
38272
38376
  newLine = Number(hunkMatch[1]);
38273
38377
  return gutter(null) + line;
@@ -41471,7 +41575,7 @@ function collectFileComments(file, lines2, project) {
41471
41575
 
41472
41576
  // src/commands/verify/blockCodeComments/parseDiffAddedLines.ts
41473
41577
  var FILE_HEADER3 = /^\+\+\+ (?:b\/)?(.+)$/;
41474
- var HUNK_HEADER4 = /^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@/;
41578
+ var HUNK_HEADER5 = /^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@/;
41475
41579
  function parseDiffAddedLines(diff3) {
41476
41580
  const added = /* @__PURE__ */ new Map();
41477
41581
  let currentFile = null;
@@ -41483,7 +41587,7 @@ function parseDiffAddedLines(diff3) {
41483
41587
  currentFile = file === "/dev/null" ? null : file;
41484
41588
  continue;
41485
41589
  }
41486
- const hunkMatch = line.match(HUNK_HEADER4);
41590
+ const hunkMatch = line.match(HUNK_HEADER5);
41487
41591
  if (hunkMatch) {
41488
41592
  newLine = Number(hunkMatch[1]);
41489
41593
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@staff0rd/assist",
3
- "version": "0.860.0",
3
+ "version": "0.862.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "bin": {