@bendyline/gezel-script-stdlib 1.1.18 → 1.1.19

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bendyline/gezel-script-stdlib",
3
- "version": "1.1.18",
3
+ "version": "1.1.19",
4
4
  "description": "Gezel's standard script library: trusted, read-only scripts that check and support craftbook steps.",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -41,7 +41,7 @@
41
41
  "!scripts/**/*.test.ts"
42
42
  ],
43
43
  "dependencies": {
44
- "@bendyline/gezel-sdk": "1.1.18"
44
+ "@bendyline/gezel-sdk": "1.1.19"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@types/node": "^24.13.3",
@@ -55,6 +55,11 @@ export const meta = defineScript({
55
55
  description:
56
56
  'Manifest field holding the expected total item count the batches must cover (default: totalFiles). Set empty to skip the total cross-check.',
57
57
  },
58
+ reviewOutFile: {
59
+ type: 'string',
60
+ description:
61
+ 'Optional artifact path for the batches a reviewer reads: the published array without the batches the manifest marks `generated`. Point `spawn.overFile` here so no child is spawned for a lockfile.',
62
+ },
58
63
  },
59
64
  outputs: {
60
65
  ok: { type: 'boolean', description: 'True when the artifact was written; failures throw.' },
@@ -67,6 +72,14 @@ export const meta = defineScript({
67
72
  description: 'Total exact per-file artifact record paths attached to the batches.',
68
73
  },
69
74
  bytes: { type: 'number', description: 'Size of the written artifact in bytes.' },
75
+ reviewBatches: {
76
+ type: 'number',
77
+ description: 'Batches a reviewer reads (every batch not marked generated).',
78
+ },
79
+ generatedBatches: {
80
+ type: 'number',
81
+ description: 'Batches of generated files the runtime summarizes itself.',
82
+ },
70
83
  },
71
84
  requires: ['artifacts.read', 'artifacts.write'],
72
85
  } as const);
@@ -97,6 +110,10 @@ const outFile = cleanPath(input.outFile, 'outFile');
97
110
  const manifestSuffix = String(input.manifestSuffix ?? '-files.json');
98
111
  const itemsField = String(input.itemsField ?? 'batches');
99
112
  const totalField = input.totalField === undefined ? 'totalFiles' : String(input.totalField);
113
+ const reviewOutFile =
114
+ input.reviewOutFile === undefined || String(input.reviewOutFile).trim() === ''
115
+ ? undefined
116
+ : cleanPath(input.reviewOutFile, 'reviewOutFile');
100
117
 
101
118
  // The changed-file directory can hold thousands of records, while a recursive
102
119
  // artifact listing is deliberately bounded. Manifests are small overview
@@ -146,6 +163,8 @@ interface Batch {
146
163
  end: number;
147
164
  paths: string[];
148
165
  records: string[];
166
+ /** Lockfiles and the like: summarized by the runtime, read by no reviewer. */
167
+ generated?: true;
149
168
  }
150
169
 
151
170
  function isPositiveInt(value: unknown): value is number {
@@ -194,7 +213,13 @@ const parsedBatches: Omit<Batch, 'records'>[] = itemsRaw.map((item, index) => {
194
213
  fail(`${where} repeats '${path}', which another batch already claims.`);
195
214
  seenPaths.add(path);
196
215
  }
197
- return { batchNumber, start, end, paths };
216
+ return {
217
+ batchNumber,
218
+ start,
219
+ end,
220
+ paths,
221
+ ...(fields.generated === true ? { generated: true as const } : {}),
222
+ };
198
223
  });
199
224
 
200
225
  if (totalField !== '') {
@@ -287,6 +312,12 @@ const batches: Batch[] = parsedBatches.map((batch) => ({
287
312
 
288
313
  const content = `${JSON.stringify(batches, null, 2)}\n`;
289
314
  await gezel.artifacts.write(outFile, content);
315
+ // The full array stays the authority for coverage; the fanout gets its own
316
+ // file so the batch numbers a child addresses still match that array.
317
+ const reviewBatches = batches.filter((batch) => !batch.generated);
318
+ if (reviewOutFile !== undefined) {
319
+ await gezel.artifacts.write(reviewOutFile, `${JSON.stringify(reviewBatches, null, 2)}\n`);
320
+ }
290
321
 
291
322
  gezel.output({
292
323
  ok: true,
@@ -296,4 +327,6 @@ gezel.output({
296
327
  paths: seenPaths.size,
297
328
  records: recordsByPath.size,
298
329
  bytes: content.length,
330
+ reviewBatches: reviewBatches.length,
331
+ generatedBatches: batches.length - reviewBatches.length,
299
332
  });
@@ -0,0 +1,118 @@
1
+ import { type InferredInput, defineScript, gezel } from '@bendyline/gezel-sdk';
2
+ import { generatedBatchObservations, generatedFileKind } from '@bendyline/gezel-sdk/checks';
3
+
4
+ /**
5
+ * Write the observations and coverage shard for every batch of generated
6
+ * files (lockfiles, third-party notices) without a model turn.
7
+ *
8
+ * A reviewer adds nothing to these line by line, and they are large: on a
9
+ * 57-file pull request one lockfile and seven notices files were 49% of the
10
+ * patch text, queued as reviewer batches behind a single local engine. The
11
+ * shards have the shape a reviewer's batch has, so the coverage merge, its
12
+ * provenance check and the synthesis index need no second path.
13
+ */
14
+ export const meta = defineScript({
15
+ name: 'publishGeneratedFileObservations',
16
+ description:
17
+ "Action: for each published batch marked `generated`, summarize its files' patches into observations-N.md and write coverage-N.json, so generated files are accounted for without a reviewer.",
18
+ kind: 'action',
19
+ inputs: {
20
+ batchesFile: {
21
+ type: 'string',
22
+ description: 'Artifact path of the runtime-published batch array.',
23
+ required: true,
24
+ },
25
+ shardDir: {
26
+ type: 'string',
27
+ description: 'Artifact directory the observations-N.md and coverage-N.json shards go in.',
28
+ required: true,
29
+ },
30
+ },
31
+ outputs: {
32
+ ok: { type: 'boolean', description: 'True when every generated batch was written.' },
33
+ batches: { type: 'number', description: 'Generated batches written.' },
34
+ files: { type: 'number', description: 'Generated files summarized.' },
35
+ },
36
+ requires: ['artifacts.read', 'artifacts.write'],
37
+ } as const);
38
+
39
+ const input = gezel.input as InferredInput<typeof meta>;
40
+
41
+ function cleanPath(raw: string, label: string): string {
42
+ const value = raw
43
+ .replace(/\\+/g, '/')
44
+ .replace(/^\.?\/+/, '')
45
+ .replace(/^artifacts\/+/i, '')
46
+ .replace(/\/+$/, '')
47
+ .trim();
48
+ if (!value || value.split('/').includes('..')) {
49
+ throw new Error(`${label} must be a safe artifact-relative path.`);
50
+ }
51
+ return value;
52
+ }
53
+
54
+ const batchesFile = cleanPath(input.batchesFile, 'batchesFile');
55
+ const shardDir = cleanPath(input.shardDir, 'shardDir');
56
+ let batches: unknown;
57
+ try {
58
+ batches = JSON.parse(await gezel.artifacts.read(batchesFile));
59
+ } catch (error) {
60
+ throw new Error(
61
+ `Could not read ${batchesFile}: ${error instanceof Error ? error.message : String(error)}`,
62
+ );
63
+ }
64
+ if (!Array.isArray(batches)) throw new Error(`${batchesFile} must be a batch array.`);
65
+
66
+ let written = 0;
67
+ let files = 0;
68
+ for (const value of batches) {
69
+ if (!value || typeof value !== 'object' || Array.isArray(value)) continue;
70
+ const batch = value as Record<string, unknown>;
71
+ if (batch.generated !== true) continue;
72
+ const { batchNumber, start, end, paths, records } = batch;
73
+ if (
74
+ !Number.isSafeInteger(batchNumber) ||
75
+ !Number.isSafeInteger(start) ||
76
+ !Number.isSafeInteger(end) ||
77
+ !Array.isArray(paths) ||
78
+ !Array.isArray(records) ||
79
+ paths.length === 0 ||
80
+ paths.length !== records.length ||
81
+ paths.some((path) => typeof path !== 'string') ||
82
+ records.some((record) => typeof record !== 'string')
83
+ ) {
84
+ throw new Error(`${batchesFile}: a generated batch has invalid bounds, paths or records.`);
85
+ }
86
+ const summarized = await Promise.all(
87
+ (paths as string[]).map(async (path, index) => {
88
+ const kind = generatedFileKind(path);
89
+ // Marked by the connector with this same rule; a mismatch means the
90
+ // batch file was not written by this build, and its coverage is not
91
+ // something to vouch for.
92
+ if (!kind) {
93
+ throw new Error(
94
+ `${batchesFile}: batch ${batchNumber} is marked generated, but ${path} is not a generated file.`,
95
+ );
96
+ }
97
+ const record = await gezel.artifacts.read((records as string[])[index]!).catch(() => null);
98
+ return { path, kind, record };
99
+ }),
100
+ );
101
+ await gezel.artifacts.write(
102
+ `${shardDir}/observations-${batchNumber}.md`,
103
+ generatedBatchObservations({
104
+ batchNumber: batchNumber as number,
105
+ start: start as number,
106
+ end: end as number,
107
+ files: summarized,
108
+ }),
109
+ );
110
+ await gezel.artifacts.write(
111
+ `${shardDir}/coverage-${batchNumber}.json`,
112
+ `${JSON.stringify({ batchNumber, reviewedFiles: paths, reviewedRecords: records }, null, 2)}\n`,
113
+ );
114
+ written += 1;
115
+ files += paths.length;
116
+ }
117
+
118
+ gezel.output({ ok: true, batches: written, files });
@@ -83,8 +83,15 @@ const ranges = batches.map((value, index) => {
83
83
  ) {
84
84
  throw new Error(`Batch ${index + 1} has invalid numbering or bounds.`);
85
85
  }
86
- return { number: index + 1, start: batch.start, end: batch.end, files: batch.paths.length };
86
+ return {
87
+ number: index + 1,
88
+ start: batch.start,
89
+ end: batch.end,
90
+ files: batch.paths.length,
91
+ ...(batch.generated === true ? { generated: true as const } : {}),
92
+ };
87
93
  });
94
+ const generatedRanges = ranges.filter((range) => range.generated);
88
95
  const distribution = new Map<string, number>();
89
96
  for (const value of files) {
90
97
  if (!value || typeof value !== 'object' || Array.isArray(value)) continue;
@@ -103,6 +110,11 @@ const content = `${JSON.stringify(
103
110
  pullRequest: fields.pullRequest,
104
111
  totalFiles,
105
112
  batchCount: ranges.length,
113
+ // What the report states as reviewed by a person-like reader versus
114
+ // summarized from the patch, so "57/57 files" is not read as 57 reviews.
115
+ reviewBatchCount: ranges.length - generatedRanges.length,
116
+ generatedBatchCount: generatedRanges.length,
117
+ generatedFiles: generatedRanges.reduce((sum, range) => sum + range.files, 0),
106
118
  ranges,
107
119
  topAreas,
108
120
  },
@@ -1,4 +1,5 @@
1
1
  import { type InferredInput, defineScript, gezel } from '@bendyline/gezel-sdk';
2
+ import { PR_FINDING_START_RE, prFindingWordingProblem } from '@bendyline/gezel-sdk/checks';
2
3
 
3
4
  /** Compact, deterministic synthesis input from every gated PR-review shard. */
4
5
  export const meta = defineScript({
@@ -55,8 +56,6 @@ function cleanPath(raw: string): string {
55
56
  const batchesFile = cleanPath(input.batchesFile);
56
57
  const shardDir = cleanPath(input.shardDir);
57
58
  const outFile = cleanPath(input.outFile);
58
- const NON_ACTIONABLE_RE =
59
- /\b(?:verified\s+ok|no\s+(?:defect|issue|finding|action\s+needed|functional\s+issue)|not\s+(?:a\s+bug|a\s+(?:functional|correctness)\s+defect|a\s+defect|introduced\s+by\s+this\s+patch|available\s+(?:in|for)\s+this\s+batch)|none\s+needed|acceptable(?:\s+as[- ]is)?|accept\s+as[- ]is|worth\s+noting|future\s+(?:optimization|hardening)|pre[- ]existing|functionally\s+harmless|intentional\s+limitation|needs?\s+(?:(?:central|cross[- ]file)\s+)?verification|requires?\s+(?:central\s+)?verification|central\s+verification|not\s+audited|implementation\s+(?:is\s+)?unknown|no\s+evidence\s+(?:of|that).{0,80}\bavailable|correct\s+(?:and\s+bounded\s+)?fallback|intent\s+is\s+correct|best[- ]effort|harmless\s+here|does\s+not\s+affect\s+runtime\s+behavior|finding\s+is\s+contingent|this\s+finding\s+is\s+contingent|risk\s+(?:is\s+)?low|may|might|could|potential(?:ly)?|possibly|likely|consider(?:ing)?|comment|documentation|documented|discoverability|verify\s+(?:that|the|whether)|verification\s+(?:of|whether)|(?:style|quoting|backslash)\s+(?:inconsistency|concern)|standardiz(?:e|ing)|if\s+.{0,160}\b(?:fails?|missing|empty|malformed|changes?|changed|removed|renamed|never|does\s+not|doesn't))\b/is;
60
59
  const SHORTLIST_LIMIT = 8;
61
60
  const UNKNOWN_SEVERITY_RANK = 3;
62
61
  const SEVERITY_RANK: Record<string, number> = {
@@ -69,7 +68,6 @@ const SEVERITY_RANK: Record<string, number> = {
69
68
  function severityRank(severity: string): number {
70
69
  return SEVERITY_RANK[severity] ?? UNKNOWN_SEVERITY_RANK;
71
70
  }
72
- const FINDING_START_RE = /^\s*(?:#{1,6}\s+|\*\*|[-*]\s+)?B(\d+)-(\d+)\b/i;
73
71
  interface VerificationCandidate {
74
72
  id: string;
75
73
  path: string;
@@ -217,12 +215,12 @@ for (let index = 0; index < parsed.length; index++) {
217
215
  const candidates = [];
218
216
  const overflow: string[] = [];
219
217
  for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) {
220
- const match = FINDING_START_RE.exec(lines[lineIndex]!);
218
+ const match = PR_FINDING_START_RE.exec(lines[lineIndex]!);
221
219
  if (!match) continue;
222
220
  const id = `B${match[1]}-${match[2]}`;
223
221
  const previewLines = [lines[lineIndex]!];
224
222
  for (let next = lineIndex + 1; next < lines.length && previewLines.length < 20; next++) {
225
- if (FINDING_START_RE.test(lines[next]!) || /^\s*#{1,4}\s+/.test(lines[next]!)) break;
223
+ if (PR_FINDING_START_RE.test(lines[next]!) || /^\s*#{1,4}\s+/.test(lines[next]!)) break;
226
224
  previewLines.push(lines[next]!);
227
225
  }
228
226
  const fullPreview = previewLines.join('\n');
@@ -240,8 +238,10 @@ for (let index = 0; index < parsed.length; index++) {
240
238
  'unknown'
241
239
  ).toLowerCase();
242
240
  const candidateScopeRank = scopeRank(fullPreview);
241
+ // The gate's own rule, so a finding it passed is never set aside here for
242
+ // wording the gate allowed.
243
243
  const likelyNonIssue =
244
- NON_ACTIONABLE_RE.test(fullPreview) ||
244
+ prFindingWordingProblem(fullPreview) !== null ||
245
245
  (candidateScopeRank === 2 && !['critical', 'major'].includes(normalizedSeverity));
246
246
  const preview = fullPreview.slice(0, likelyNonIssue ? 240 : 520);
247
247
  if (candidates.length < 20) {
@@ -279,6 +279,7 @@ for (let index = 0; index < parsed.length; index++) {
279
279
  .map((candidate) => candidate.id),
280
280
  overflow,
281
281
  verificationCandidateIds: batchVerificationCandidates.map((candidate) => candidate.id),
282
+ ...(batch.generated === true ? { generated: true } : {}),
282
283
  });
283
284
  }
284
285
  const actionableCandidates = indexedCandidates
@@ -313,6 +314,7 @@ await gezel.artifacts.write(
313
314
  schemaVersion: 2,
314
315
  batchesFile,
315
316
  batchCount: summaries.length,
317
+ generatedBatchCount: summaries.filter((summary) => summary.generated).length,
316
318
  candidateCount,
317
319
  actionableCandidateCount: actionableCandidates.length + overflowCandidates.length,
318
320
  nonActionableCandidateCount: indexedCandidates.filter((candidate) => candidate.likelyNonIssue)