@staff0rd/assist 0.678.0 → 0.680.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.678.0",
9
+ version: "0.680.0",
10
10
  type: "module",
11
11
  main: "dist/index.js",
12
12
  bin: {
@@ -750,6 +750,9 @@ var assistConfigShape = {
750
750
  ).optional(),
751
751
  transcript: transcriptConfigSchema.optional(),
752
752
  cliReadVerbs: z3.record(z3.string(), z3.array(z3.string())).optional(),
753
+ cliHook: z3.strictObject({
754
+ blockNpmRun: z3.boolean().default(true)
755
+ }).optional(),
753
756
  dotnet: z3.strictObject({
754
757
  inspect: z3.strictObject({
755
758
  suppress: z3.array(z3.string()).default([])
@@ -3200,6 +3203,11 @@ var cliHookConfigHelp = [
3200
3203
  key: "cliReadVerbs",
3201
3204
  setter: 'assist config set cliReadVerbs.git "status"',
3202
3205
  note: "extra per-CLI verbs treated as read-only for auto-approval"
3206
+ },
3207
+ {
3208
+ key: "cliHook.blockNpmRun",
3209
+ setter: "assist config set cliHook.blockNpmRun false",
3210
+ note: "when true (default), the hook denies 'npm run' and redirects to 'assist run'"
3203
3211
  }
3204
3212
  ];
3205
3213
 
@@ -17534,8 +17542,8 @@ function unquote(value) {
17534
17542
  return value.replace(/^['"]|['"]$/g, "");
17535
17543
  }
17536
17544
 
17537
- // src/commands/cliHook/findBuiltinDeny.ts
17538
- var BUILTIN_DENIES = [
17545
+ // src/commands/cliHook/builtinDenyRules.ts
17546
+ var PATTERN_DENIES = [
17539
17547
  {
17540
17548
  pattern: "gh pr create",
17541
17549
  message: "Do not run 'gh pr create' directly. Use 'assist prs raise --title <title> --what <what> --why <why>' instead \u2014 it assembles and validates the body before delegating to gh, and gates the PR on the user's approval itself. Run 'assist prs raise --help' and follow its guidance to compose the sections; it is authoritative on how approval is handled in this environment."
@@ -17562,7 +17570,8 @@ var BUILTIN_DENIES = [
17562
17570
  },
17563
17571
  {
17564
17572
  pattern: "npm run",
17565
- message: "Do not run 'npm run' directly. Use 'assist run <name>' for a configured command, or 'assist verify' / 'assist build'. If this repo genuinely needs npm run, set cliHook.blockNpmRun to false in its assist.yml."
17573
+ message: "Do not run 'npm run' directly. Use 'assist run <name>' for a configured command, or 'assist verify' / 'assist build'. If this repo genuinely needs npm run, set cliHook.blockNpmRun to false in its assist.yml.",
17574
+ enabled: () => loadConfig().cliHook?.blockNpmRun !== false
17566
17575
  }
17567
17576
  ];
17568
17577
  var GH_ISSUE_API_MESSAGE = "Do not write to GitHub issue endpoints with 'gh api' \u2014 it bypasses the content validation and the approval pane that every outward-facing issue write goes through. Use 'assist github issue create --title <title> --body <body>' to open an issue, 'assist github issue edit <number>' to rework one's body, 'assist github issue comment <number> --body <body>' to post a comment, or 'assist github issue edit-comment <comment-id> --body <body>' to amend a comment that is already posted. Each validates the content and gates it on the user's approval before anything reaches GitHub; run the command's --help for how to compose it.";
@@ -17577,16 +17586,17 @@ var BRANCH_CREATION_REGEXES = [
17577
17586
  ),
17578
17587
  new RegExp(COMMAND_BOUNDARY + String.raw`git\s+branch\s+(?!-)\S`)
17579
17588
  ];
17580
- function rawDenyRegex(pattern2) {
17589
+ function anywhereTokenSequenceRegex(pattern2) {
17581
17590
  const tokens = pattern2.trim().split(/\s+/).map((token) => token.replace(/[.*+?^${}()|[\]\\]/g, String.raw`\$&`)).join(String.raw`\s+`);
17582
17591
  return new RegExp(`(?<=^|\\s)${tokens}(?=\\s|$)`);
17583
17592
  }
17584
- var RAW_BUILTIN_DENIES = [
17585
- ...BUILTIN_DENIES.map((rule) => {
17586
- const regex = rawDenyRegex(rule.pattern);
17593
+ var builtinDenyRules = [
17594
+ ...PATTERN_DENIES.map((rule) => {
17595
+ const regex = anywhereTokenSequenceRegex(rule.pattern);
17587
17596
  return {
17588
17597
  message: rule.message,
17589
- matches: (text18) => regex.test(text18)
17598
+ matches: (text18) => regex.test(text18),
17599
+ enabled: rule.enabled
17590
17600
  };
17591
17601
  }),
17592
17602
  ...BRANCH_CREATION_REGEXES.map((regex) => ({
@@ -17598,8 +17608,12 @@ var RAW_BUILTIN_DENIES = [
17598
17608
  matches: isGhIssueApiWrite
17599
17609
  }
17600
17610
  ];
17611
+
17612
+ // src/commands/cliHook/findBuiltinDeny.ts
17601
17613
  function matchBuiltinDeny(text18) {
17602
- return RAW_BUILTIN_DENIES.find((rule) => rule.matches(text18));
17614
+ return builtinDenyRules.find(
17615
+ (rule) => rule.matches(text18) && (rule.enabled?.() ?? true)
17616
+ );
17603
17617
  }
17604
17618
  function toDecision(rule) {
17605
17619
  if (!rule) return void 0;
@@ -30710,6 +30724,66 @@ function buildHighLevelStructure(files) {
30710
30724
  };
30711
30725
  }
30712
30726
 
30727
+ // src/commands/review/highLevel/capHighLevelPatches.ts
30728
+ import { minimatch as minimatch7 } from "minimatch";
30729
+
30730
+ // src/commands/review/highLevel/capPatchToBudget.ts
30731
+ function hunksOf(patch2) {
30732
+ const hunks = [];
30733
+ for (const line of patch2.split("\n")) {
30734
+ const last = hunks[hunks.length - 1];
30735
+ if (line.startsWith("@@") || last === void 0) hunks.push(line);
30736
+ else hunks[hunks.length - 1] = `${last}
30737
+ ${line}`;
30738
+ }
30739
+ return hunks;
30740
+ }
30741
+ function capPatchToBudget(patch2, budget) {
30742
+ const kept = [];
30743
+ let lines2 = 0;
30744
+ for (const hunk of hunksOf(patch2)) {
30745
+ const size = hunk.split("\n").length;
30746
+ if (lines2 + size > budget)
30747
+ return {
30748
+ ...kept.length > 0 ? { patch: kept.join("\n") } : {},
30749
+ truncated: true
30750
+ };
30751
+ kept.push(hunk);
30752
+ lines2 += size;
30753
+ }
30754
+ return { patch: patch2, truncated: false };
30755
+ }
30756
+
30757
+ // src/commands/review/highLevel/capHighLevelPatches.ts
30758
+ var MAX_FILE_PATCH_LINES = 1500;
30759
+ var MAX_TOTAL_PATCH_LINES = 2e4;
30760
+ function criticalFirst(files, criticalPaths) {
30761
+ const isCritical = (file) => criticalPaths.some((glob) => minimatch7(file.path, glob));
30762
+ return [...files].sort(
30763
+ (a, b) => Number(isCritical(b)) - Number(isCritical(a))
30764
+ );
30765
+ }
30766
+ function capped(file, budget) {
30767
+ if (file.patch === void 0) return file;
30768
+ const { patch: patch2, truncated } = capPatchToBudget(file.patch, budget);
30769
+ const { patch: _dropped, ...rest } = file;
30770
+ return {
30771
+ ...rest,
30772
+ ...patch2 === void 0 ? {} : { patch: patch2 },
30773
+ ...truncated ? { truncated: true } : {}
30774
+ };
30775
+ }
30776
+ function capHighLevelPatches(files, criticalPaths) {
30777
+ let remaining = MAX_TOTAL_PATCH_LINES;
30778
+ const byPath = /* @__PURE__ */ new Map();
30779
+ for (const file of criticalFirst(files, criticalPaths)) {
30780
+ const result = capped(file, Math.min(MAX_FILE_PATCH_LINES, remaining));
30781
+ remaining -= result.patch?.split("\n").length ?? 0;
30782
+ byPath.set(file.path, result);
30783
+ }
30784
+ return files.map((file) => byPath.get(file.path) ?? file);
30785
+ }
30786
+
30713
30787
  // src/commands/review/highLevel/checkDescriptionLinksIssue.ts
30714
30788
  var ISSUE_URL_PATTERN = /https?:\/\/github\.com\/[\w.-]+\/[\w.-]+\/issues\/\d+/g;
30715
30789
  var CROSS_REPO_PATTERN = /\b[\w.-]+\/[\w.-]+#\d+/g;
@@ -30767,7 +30841,7 @@ function checkDescriptionWordCap(body, cap2) {
30767
30841
  }
30768
30842
 
30769
30843
  // src/commands/review/highLevel/checkUiEvidence.ts
30770
- import { minimatch as minimatch7 } from "minimatch";
30844
+ import { minimatch as minimatch8 } from "minimatch";
30771
30845
  var EVIDENCE_PATTERNS = [
30772
30846
  /!\[[^\]]*\]\([^)]+\)/g,
30773
30847
  /<(?:img|video)\b[^>]*>/gi,
@@ -30790,7 +30864,7 @@ function checkUiEvidence(body, changedFiles2, uiPaths) {
30790
30864
  reason: "review.highLevel.uiPaths is unset, so no UI evidence is required"
30791
30865
  };
30792
30866
  const touched = changedFiles2.filter(
30793
- (file) => uiPaths.some((glob) => minimatch7(file, glob))
30867
+ (file) => uiPaths.some((glob) => minimatch8(file, glob))
30794
30868
  );
30795
30869
  if (touched.length === 0)
30796
30870
  return {
@@ -30957,17 +31031,20 @@ function resolveHighLevelConfig(config) {
30957
31031
  }
30958
31032
 
30959
31033
  // src/commands/review/highLevel/selectCriticalDiffs.ts
30960
- import { minimatch as minimatch8 } from "minimatch";
31034
+ import { minimatch as minimatch9 } from "minimatch";
30961
31035
  function selectCriticalDiffs(files, criticalPaths) {
30962
31036
  if (criticalPaths.length === 0) return [];
30963
- return files.filter((file) => criticalPaths.some((glob) => minimatch8(file.path, glob))).map(({ path: path91, status: status3, additions, deletions, diffUrl: diffUrl2, patch: patch2 }) => ({
30964
- path: path91,
30965
- status: status3,
30966
- additions,
30967
- deletions,
30968
- diffUrl: diffUrl2,
30969
- patch: patch2 ?? null
30970
- }));
31037
+ return files.filter((file) => criticalPaths.some((glob) => minimatch9(file.path, glob))).map(
31038
+ ({ path: path91, status: status3, additions, deletions, diffUrl: diffUrl2, patch: patch2, truncated }) => ({
31039
+ path: path91,
31040
+ status: status3,
31041
+ additions,
31042
+ deletions,
31043
+ diffUrl: diffUrl2,
31044
+ patch: patch2 ?? null,
31045
+ ...truncated ? { truncated: true } : {}
31046
+ })
31047
+ );
30971
31048
  }
30972
31049
 
30973
31050
  // src/commands/review/highLevel/gatherHighLevelSubject.ts
@@ -30975,8 +31052,11 @@ function gatherHighLevelSubject(prNumber, force) {
30975
31052
  const { org, repo } = getRepoInfo();
30976
31053
  const slug2 = `${org}/${repo}`;
30977
31054
  const pr = fetchHighLevelPr(prNumber, { org, repo });
30978
- const files = fetchHighLevelFiles(prNumber, slug2);
30979
31055
  const config = resolveHighLevelConfig(loadConfig());
31056
+ const files = capHighLevelPatches(
31057
+ fetchHighLevelFiles(prNumber, slug2),
31058
+ config.criticalPaths
31059
+ );
30980
31060
  const saved = force ? void 0 : loadHighLevelReview(slug2, pr.headRef, pr.headSha);
30981
31061
  return {
30982
31062
  repo: slug2,
@@ -31030,6 +31110,42 @@ function highLevelChangedFileCount(structure) {
31030
31110
  return structure.added + structure.removed + structure.modified;
31031
31111
  }
31032
31112
 
31113
+ // src/commands/review/highLevel/highLevelPreviewMetadata.ts
31114
+ function highLevelPreviewMetadata(subject) {
31115
+ return [
31116
+ { label: "Branch", value: subject.headRef },
31117
+ { label: "Head", value: subject.headSha.slice(0, 7) },
31118
+ {
31119
+ label: "Changed files",
31120
+ value: String(highLevelChangedFileCount(subject.structure))
31121
+ },
31122
+ { label: "Critical files", value: String(subject.criticalDiffs.length) },
31123
+ ...subject.saved ? [{ label: "Reopened from", value: subject.saved.reviewedAt }] : []
31124
+ ];
31125
+ }
31126
+
31127
+ // src/commands/review/highLevel/highLevelPreviewPayload.ts
31128
+ function highLevelPreviewPayload(subject) {
31129
+ const {
31130
+ repo,
31131
+ prNumber,
31132
+ checks: checks2,
31133
+ structure,
31134
+ criticalDiffs,
31135
+ criticalPaths,
31136
+ saved
31137
+ } = subject;
31138
+ return {
31139
+ repo,
31140
+ prNumber,
31141
+ checks: checks2,
31142
+ structure,
31143
+ criticalDiffs,
31144
+ criticalPaths,
31145
+ ...saved ? { saved } : {}
31146
+ };
31147
+ }
31148
+
31033
31149
  // src/commands/review/highLevel/saveHighLevelReview.ts
31034
31150
  import { mkdirSync as mkdirSync21, writeFileSync as writeFileSync38 } from "fs";
31035
31151
  import { dirname as dirname34 } from "path";
@@ -31042,28 +31158,6 @@ function saveHighLevelReview(record) {
31042
31158
  }
31043
31159
 
31044
31160
  // src/commands/review/highLevel/openHighLevelOverlay.ts
31045
- function payloadOf(subject) {
31046
- const { checks: checks2, structure, criticalDiffs, criticalPaths, saved } = subject;
31047
- return {
31048
- checks: checks2,
31049
- structure,
31050
- criticalDiffs,
31051
- criticalPaths,
31052
- ...saved ? { saved } : {}
31053
- };
31054
- }
31055
- function metadataOf(subject) {
31056
- return [
31057
- { label: "Branch", value: subject.headRef },
31058
- { label: "Head", value: subject.headSha.slice(0, 7) },
31059
- {
31060
- label: "Changed files",
31061
- value: String(highLevelChangedFileCount(subject.structure))
31062
- },
31063
- { label: "Critical files", value: String(subject.criticalDiffs.length) },
31064
- ...subject.saved ? [{ label: "Reopened from", value: subject.saved.reviewedAt }] : []
31065
- ];
31066
- }
31067
31161
  async function openHighLevelOverlay(sessionId, subject) {
31068
31162
  const decision = await awaitPreviewApproval(
31069
31163
  "High-level review",
@@ -31071,10 +31165,10 @@ async function openHighLevelOverlay(sessionId, subject) {
31071
31165
  sessionId,
31072
31166
  requestId: randomUUID17(),
31073
31167
  title: `High-level review of ${subject.repo}#${subject.prNumber}`,
31074
- body: JSON.stringify(payloadOf(subject)),
31168
+ body: JSON.stringify(highLevelPreviewPayload(subject)),
31075
31169
  prNumber: subject.prNumber,
31076
31170
  kind: "high-level-review",
31077
- metadata: metadataOf(subject)
31171
+ metadata: highLevelPreviewMetadata(subject)
31078
31172
  },
31079
31173
  { rejectIsOutcome: true }
31080
31174
  );
@@ -40567,7 +40661,7 @@ async function changedFiles(path91) {
40567
40661
  const lines2 = status3.ok ? nonEmptyLines(status3.out) : [];
40568
40662
  return {
40569
40663
  summary: `${lines2.length} uncommitted ${lines2.length === 1 ? "file" : "files"}`,
40570
- items: capped(lines2)
40664
+ items: capped2(lines2)
40571
40665
  };
40572
40666
  }
40573
40667
  async function unpushedCommits(path91, reason4) {
@@ -40576,13 +40670,13 @@ async function unpushedCommits(path91, reason4) {
40576
40670
  const lines2 = nonEmptyLines(log2.out);
40577
40671
  return {
40578
40672
  summary: `${lines2.length} unpushed ${lines2.length === 1 ? "commit" : "commits"}`,
40579
- items: capped(lines2)
40673
+ items: capped2(lines2)
40580
40674
  };
40581
40675
  }
40582
40676
  function nonEmptyLines(out) {
40583
40677
  return out.split("\n").map((line) => line.trim()).filter((line) => line !== "");
40584
40678
  }
40585
- function capped(lines2) {
40679
+ function capped2(lines2) {
40586
40680
  if (lines2.length <= MAX_ITEMS) return lines2;
40587
40681
  return [
40588
40682
  ...lines2.slice(0, MAX_ITEMS),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@staff0rd/assist",
3
- "version": "0.678.0",
3
+ "version": "0.680.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "bin": {