@bendyline/gezel-script-stdlib 0.1.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.
Files changed (37) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +32 -0
  3. package/package.json +56 -0
  4. package/scripts/checkCitationsResolve.ts +45 -0
  5. package/scripts/checkContains.ts +23 -0
  6. package/scripts/checkCssMinBytes.ts +28 -0
  7. package/scripts/checkDistinctMatches.ts +48 -0
  8. package/scripts/checkFileCount.ts +37 -0
  9. package/scripts/checkFileExists.ts +43 -0
  10. package/scripts/checkFileMinBytes.ts +33 -0
  11. package/scripts/checkFileMinLines.ts +27 -0
  12. package/scripts/checkGrepMatches.ts +46 -0
  13. package/scripts/checkHtmlComplete.ts +34 -0
  14. package/scripts/checkHtmlGame.ts +48 -0
  15. package/scripts/checkImageRefsResolve.ts +40 -0
  16. package/scripts/checkJsParses.ts +69 -0
  17. package/scripts/checkJsonValid.ts +34 -0
  18. package/scripts/checkNamedEntitiesConsistent.ts +40 -0
  19. package/scripts/checkOrderedSections.ts +47 -0
  20. package/scripts/checkOutcomesMet.ts +54 -0
  21. package/scripts/checkPageRenders.ts +72 -0
  22. package/scripts/checkPlanFramed.ts +65 -0
  23. package/scripts/checkPlanReady.ts +94 -0
  24. package/scripts/checkPlanStructure.ts +62 -0
  25. package/scripts/checkReadingLevel.ts +55 -0
  26. package/scripts/checkRecordSchema.ts +57 -0
  27. package/scripts/checkReviewReport.ts +196 -0
  28. package/scripts/checkSecurityReport.ts +48 -0
  29. package/scripts/checkStandaloneJsParses.ts +32 -0
  30. package/scripts/checkStepsHaveDeliverables.ts +74 -0
  31. package/scripts/checkTableShape.ts +56 -0
  32. package/scripts/checkTaskNoteContains.ts +40 -0
  33. package/scripts/checkTotalMinBytes.ts +33 -0
  34. package/scripts/checkValueGrounding.ts +49 -0
  35. package/scripts/checkVerificationStep.ts +68 -0
  36. package/scripts/checkWordBand.ts +51 -0
  37. package/scripts/checkWorkspaceScript.ts +81 -0
@@ -0,0 +1,196 @@
1
+ import { type InferredInput, defineScript, gezel } from '@bendyline/gezel-sdk';
2
+ import { gateResult } from '@bendyline/gezel-sdk/checks';
3
+
4
+ /**
5
+ * Code-review report gate (runs on a code-review task): the report artifact at
6
+ * `reviews/<reviewId>/report.md` is structurally complete, every cited file is
7
+ * really part of the reviewed change set (manifest entries ∪ diff headers — the
8
+ * anti-fabrication floor that declarative `citationsResolve` cannot provide
9
+ * across the workspace/artifacts boundary), severities use the fixed ladder,
10
+ * and the verdict follows from the findings table.
11
+ */
12
+ export const meta = defineScript({
13
+ name: 'checkReviewReport',
14
+ description:
15
+ 'Gate: a snapshot code-review report is well-formed — Summary/Findings/Verdict sections present, every cited file exists in the reviewed change set (no fabricated paths — the failure names them), severities use critical/major/minor/nit, and any critical or major finding forces a request-changes verdict.',
16
+ kind: 'gate',
17
+ inputs: {
18
+ taskRef: {
19
+ type: 'string',
20
+ description: 'The review task (auto-filled by the runtime when this gate runs from a step).',
21
+ },
22
+ reviewId: {
23
+ type: 'string',
24
+ description:
25
+ 'Snapshot folder under the artifacts drawer (reviews/<reviewId>/). Falls back to the task craftbookParams, then the newest reviews/* folder.',
26
+ },
27
+ },
28
+ outputs: {
29
+ decision: { type: 'string', description: "'approve' or 'reject'." },
30
+ message: { type: 'string', description: 'What passed, or the concrete gaps to fix.' },
31
+ },
32
+ requires: ['tasks.read', 'artifacts.read'],
33
+ } as const);
34
+
35
+ const SEVERITIES = new Set(['critical', 'major', 'minor', 'nit']);
36
+
37
+ interface TaskView {
38
+ craftbookParams?: Record<string, string>;
39
+ }
40
+
41
+ const input = gezel.input as InferredInput<typeof meta>;
42
+
43
+ /** Strip diff/citation prefixes so `a/src/x.ts`, `./src/x.ts`, `src/x.ts` compare equal. */
44
+ function normPath(p: string): string {
45
+ return p
46
+ .trim()
47
+ .replace(/^`|`$/g, '')
48
+ .replace(/^\.\//, '')
49
+ .replace(/^[ab]\//, '')
50
+ .replace(/\\/g, '/');
51
+ }
52
+
53
+ async function resolveReviewId(): Promise<string | undefined> {
54
+ if (input.reviewId) return input.reviewId;
55
+ const task = (await gezel.task.get(input.taskRef ?? '').catch(() => null)) as TaskView | null;
56
+ const fromParams = task?.craftbookParams?.reviewId;
57
+ if (fromParams && !fromParams.includes('{{')) return fromParams;
58
+ const entries = await gezel.artifacts.list('reviews/').catch(() => []);
59
+ const manifests = entries
60
+ .map((e) => /^reviews\/([^/]+)\/manifest\.json$/.exec(e.path)?.[1])
61
+ .filter((id): id is string => !!id)
62
+ .sort();
63
+ return manifests[manifests.length - 1];
64
+ }
65
+
66
+ const gaps: string[] = [];
67
+ let okMessage = '';
68
+
69
+ const reviewId = await resolveReviewId();
70
+ if (!reviewId) {
71
+ gezel.output(
72
+ gateResult(
73
+ false,
74
+ 'No review snapshot found — this gate needs a reviews/<reviewId>/ folder in the artifacts drawer (manifest.json + changes.diff).',
75
+ ),
76
+ );
77
+ } else {
78
+ const reportPath = `reviews/${reviewId}/report.md`;
79
+ const report = await gezel.artifacts.read(reportPath).catch(() => null);
80
+ if (report === null) {
81
+ gezel.output(
82
+ gateResult(
83
+ false,
84
+ `The report has not been written yet — write the complete review to ${reportPath} with one write_artifact call.`,
85
+ ),
86
+ );
87
+ } else {
88
+ // Structural floor — name the exact missing section.
89
+ if (!/##\s+Summary/.test(report)) gaps.push('the `## Summary` section is missing');
90
+ if (!/##\s+Findings/.test(report)) gaps.push('the `## Findings` section is missing');
91
+ const verdictMatch = /Verdict:\s*(approve|request-changes)/i.exec(report);
92
+ if (!verdictMatch) {
93
+ gaps.push(
94
+ 'the `## Verdict` section must contain a `Verdict: approve` or `Verdict: request-changes` line',
95
+ );
96
+ }
97
+
98
+ // The change set = manifest file entries ∪ diff header paths. Deleted
99
+ // files only exist in these two places, which is why the workspace is
100
+ // deliberately NOT consulted here.
101
+ const allowed = new Set<string>();
102
+ const manifestRaw = await gezel.artifacts
103
+ .read(`reviews/${reviewId}/manifest.json`)
104
+ .catch(() => null);
105
+ if (manifestRaw) {
106
+ try {
107
+ const manifest = JSON.parse(manifestRaw) as {
108
+ files?: { path?: string; oldPath?: string }[];
109
+ };
110
+ for (const f of manifest.files ?? []) {
111
+ if (f.path) allowed.add(normPath(f.path));
112
+ if (f.oldPath) allowed.add(normPath(f.oldPath));
113
+ }
114
+ } catch {
115
+ // Unparseable manifest — the diff headers still feed the set.
116
+ }
117
+ }
118
+ const diffRaw = await gezel.artifacts.read(`reviews/${reviewId}/changes.diff`).catch(() => '');
119
+ for (const m of (diffRaw ?? '').matchAll(/^(?:\+\+\+|---) (?:[ab]\/)?(.+)$/gm)) {
120
+ const p = m[1]?.trim();
121
+ if (p && p !== '/dev/null') allowed.add(normPath(p));
122
+ }
123
+
124
+ // Findings table: locate the header row, map columns by name, then
125
+ // walk the data rows for severity vocabulary + cited files.
126
+ const lines = report.split('\n');
127
+ const headerIdx = lines.findIndex((l) => /^\s*\|/.test(l) && /\|\s*Severity\s*\|/i.test(l));
128
+ const rows: { severity: string; file: string; line: number }[] = [];
129
+ if (headerIdx >= 0) {
130
+ const headers = lines[headerIdx]!.split('|').map((c) => c.trim().toLowerCase());
131
+ const sevCol = headers.indexOf('severity');
132
+ const fileCol = headers.indexOf('file');
133
+ for (let i = headerIdx + 1; i < lines.length; i++) {
134
+ const line = lines[i]!;
135
+ if (!/^\s*\|/.test(line)) break;
136
+ if (/^\s*\|[\s|:-]+\|\s*$/.test(line)) continue; // separator row
137
+ const cells = line.split('|').map((c) => c.trim());
138
+ rows.push({
139
+ severity: (cells[sevCol] ?? '').toLowerCase(),
140
+ file: cells[fileCol] ?? '',
141
+ line: i + 1,
142
+ });
143
+ }
144
+ } else if (/##\s+Findings/.test(report)) {
145
+ gaps.push('the Findings section needs a markdown table with a `Severity` column');
146
+ }
147
+
148
+ const badSeverities = rows.filter((r) => r.severity !== '' && !SEVERITIES.has(r.severity));
149
+ if (badSeverities.length > 0) {
150
+ gaps.push(
151
+ `severity must be one of critical/major/minor/nit — fix: ${badSeverities
152
+ .map((r) => `"${r.severity}" (report line ${r.line})`)
153
+ .join(', ')}`,
154
+ );
155
+ }
156
+
157
+ // Citation floor: every File cell and every path:line citation in the
158
+ // prose must name a file from the change set.
159
+ const cited = new Set<string>();
160
+ for (const r of rows) {
161
+ const cell = normPath(r.file.replace(/:\d+(-\d+)?$/, ''));
162
+ if (cell && cell !== '-' && cell !== '—') cited.add(cell);
163
+ }
164
+ for (const m of report.matchAll(/`([^`\s]+?\.[A-Za-z0-9]{1,8}):\d+(?:-\d+)?`/g)) {
165
+ const p = m[1];
166
+ if (p) cited.add(normPath(p));
167
+ }
168
+ const unresolved = [...cited].filter((p) => allowed.size > 0 && !allowed.has(p));
169
+ if (unresolved.length > 0) {
170
+ gaps.push(
171
+ `these cited files are not part of the reviewed change set (only discuss changed files, with paths exactly as they appear in the diff): ${unresolved.join(', ')}`,
172
+ );
173
+ }
174
+
175
+ // Verdict consistency: critical/major ⇒ request-changes.
176
+ const verdict = verdictMatch?.[1]?.toLowerCase();
177
+ const blocking = rows.filter((r) => r.severity === 'critical' || r.severity === 'major');
178
+ if (verdict === 'approve' && blocking.length > 0) {
179
+ gaps.push(
180
+ `the verdict says approve but ${blocking.length} critical/major finding(s) are listed (report line(s) ${blocking
181
+ .map((r) => r.line)
182
+ .join(
183
+ ', ',
184
+ )}) — either downgrade them with justification or change the verdict to request-changes`,
185
+ );
186
+ }
187
+
188
+ okMessage = `report ${reportPath} is well-formed: ${rows.length} finding(s), verdict ${verdict ?? 'n/a'}, ${cited.size} cited file(s) all inside the change set`;
189
+ gezel.output(
190
+ gateResult(
191
+ gaps.length === 0,
192
+ gaps.length === 0 ? okMessage : `The report is not ready — ${gaps.join('; ')}.`,
193
+ ),
194
+ );
195
+ }
196
+ }
@@ -0,0 +1,48 @@
1
+ import { type InferredInput, defineScript, gezel } from '@bendyline/gezel-sdk';
2
+ import { gateResult, securityReport, workspaceFromGezel } from '@bendyline/gezel-sdk/checks';
3
+
4
+ export const meta = defineScript({
5
+ name: 'checkSecurityReport',
6
+ description:
7
+ 'Gate: a whole-codebase security review is well-formed — the findings JSON parses, every finding cites a REAL file:line with a severity and a concrete remediation (no fabricated paths — the failure names them), the report carries the required sections, and (when there are enough findings to cluster) the Systemic Themes section names ≥ minThemes themes with root cause + blast radius; the verdict must match the open severity.',
8
+ kind: 'gate',
9
+ inputs: {
10
+ file: {
11
+ type: 'string',
12
+ description: 'Workspace-relative report markdown (e.g. security-review/REPORT.md).',
13
+ required: true,
14
+ },
15
+ findings: {
16
+ type: 'string',
17
+ description: 'Path to the machine-readable findings JSON.',
18
+ default: 'security-review/findings.json',
19
+ },
20
+ minThemes: {
21
+ type: 'number',
22
+ description: 'Systemic themes required once findings ≥ themeThreshold.',
23
+ default: 2,
24
+ integer: true,
25
+ min: 0,
26
+ },
27
+ themeThreshold: {
28
+ type: 'number',
29
+ description: 'Findings count at/above which systemic-theme synthesis is required.',
30
+ default: 3,
31
+ integer: true,
32
+ min: 0,
33
+ },
34
+ },
35
+ outputs: {
36
+ decision: { type: 'string', description: "'approve' or 'reject'." },
37
+ message: { type: 'string', description: 'What passed, or the concrete gap to fix.' },
38
+ },
39
+ requires: ['workspace.read'],
40
+ } as const);
41
+
42
+ const input = gezel.input as InferredInput<typeof meta>;
43
+ const r = await securityReport(workspaceFromGezel(gezel), input.file, {
44
+ findings: input.findings,
45
+ minThemes: input.minThemes,
46
+ themeThreshold: input.themeThreshold,
47
+ });
48
+ gezel.output(gateResult(r.ok, r.detail));
@@ -0,0 +1,32 @@
1
+ import { type InferredInput, defineScript, gezel } from '@bendyline/gezel-sdk';
2
+ import { gateResult, standaloneJsParses, workspaceFromGezel } from '@bendyline/gezel-sdk/checks';
3
+
4
+ export const meta = defineScript({
5
+ name: 'checkStandaloneJsParses',
6
+ description:
7
+ 'Gate: a standalone .js/.mjs source file parses as JavaScript (imports/exports stripped, then V8-parsed) — catches truncated files and unbalanced braces that a byte floor waves through. TypeScript files need the declarative sourceParses gate check instead.',
8
+ kind: 'gate',
9
+ inputs: {
10
+ file: {
11
+ type: 'string',
12
+ description: 'Workspace-relative source file to check.',
13
+ required: true,
14
+ },
15
+ },
16
+ outputs: {
17
+ decision: { type: 'string', description: "'approve' or 'reject'." },
18
+ message: { type: 'string', description: 'What passed, or the concrete gap to fix.' },
19
+ },
20
+ requires: ['workspace.read'],
21
+ } as const);
22
+
23
+ const input = gezel.input as InferredInput<typeof meta>;
24
+ const content = await workspaceFromGezel(gezel).read(input.file);
25
+ if (content === null) {
26
+ gezel.output(
27
+ gateResult(false, `${input.file} not found — write the deliverable before advancing.`),
28
+ );
29
+ } else {
30
+ const r = standaloneJsParses(content, input.file);
31
+ gezel.output(gateResult(r.ok, r.detail));
32
+ }
@@ -0,0 +1,74 @@
1
+ import { type InferredInput, defineScript, gezel } from '@bendyline/gezel-sdk';
2
+ import { gateResult } from '@bendyline/gezel-sdk/checks';
3
+
4
+ /**
5
+ * Plan gate (runs on a plan-AUTHORING task): every build step of the draft
6
+ * plan has a concrete static outcome with an enforced gate — i.e. a `gate`
7
+ * (≥1 check or script) or an `advanceWhen.file`. Terminal steps are exempt
8
+ * (the final step verifies outcomes, see checkVerificationStep).
9
+ */
10
+ export const meta = defineScript({
11
+ name: 'checkStepsHaveDeliverables',
12
+ description:
13
+ "Plan gate: every non-terminal build step of the draft plan has a concrete deliverable + enforced gate (a gate with checks/scripts, or an advanceWhen.file). Reads the draft via the authoring task's craftbookParams.draftRef.",
14
+ kind: 'gate',
15
+ inputs: {
16
+ taskRef: {
17
+ type: 'string',
18
+ description:
19
+ 'The authoring task (auto-filled by the runtime when this gate runs from a step).',
20
+ },
21
+ },
22
+ outputs: {
23
+ decision: { type: 'string', description: "'approve' or 'reject'." },
24
+ message: { type: 'string', description: 'What passed, or the concrete gap to fix.' },
25
+ },
26
+ requires: ['tasks.read'],
27
+ } as const);
28
+
29
+ interface StepView {
30
+ id: string;
31
+ name?: string;
32
+ terminal?: boolean;
33
+ advanceWhen?: { file?: string } | null;
34
+ gate?: { checks?: unknown[]; scripts?: unknown[] } | null;
35
+ }
36
+ interface DraftView {
37
+ craftbookParams?: Record<string, string>;
38
+ craftbook?: { steps?: StepView[] };
39
+ }
40
+
41
+ const input = gezel.input as InferredInput<typeof meta>;
42
+
43
+ function isGated(s: StepView): boolean {
44
+ const hasGate =
45
+ !!s.gate && ((s.gate.checks?.length ?? 0) > 0 || (s.gate.scripts?.length ?? 0) > 0);
46
+ const hasAdvance = !!s.advanceWhen?.file;
47
+ return hasGate || hasAdvance;
48
+ }
49
+
50
+ let ok = false;
51
+ let message = '';
52
+
53
+ const authoring = (await gezel.task.get(input.taskRef ?? '').catch(() => null)) as DraftView | null;
54
+ const draftRef = authoring?.craftbookParams?.draftRef;
55
+ if (!draftRef) {
56
+ message =
57
+ 'This gate must run on a plan-authoring task whose craftbookParams.draftRef points at the draft plan. Start planning with start_plan.';
58
+ } else {
59
+ const draft = (await gezel.task.get(draftRef).catch(() => null)) as DraftView | null;
60
+ const steps = draft?.craftbook?.steps ?? [];
61
+ const buildSteps = steps.filter((s) => !s.terminal);
62
+ const bare = buildSteps.filter((s) => !isGated(s));
63
+ if (buildSteps.length === 0) {
64
+ message = `The plan has no build steps yet. Add ordered steps with craftbook_add_step({ task: "${draftRef}", ... }) and give each a concrete static outcome with set_step_deliverable({ task: "${draftRef}", stepId, path, kind }).`;
65
+ } else if (bare.length > 0) {
66
+ const names = bare.map((s) => `"${s.name ?? s.id}"`).join(', ');
67
+ message = `These steps have no concrete deliverable + enforced gate: ${names}. For each, call set_step_deliverable({ task: "${draftRef}", stepId, path, kind }) so the step is gated on a named file.`;
68
+ } else {
69
+ ok = true;
70
+ message = `All ${buildSteps.length} build step(s) are gated on a concrete deliverable.`;
71
+ }
72
+ }
73
+
74
+ gezel.output(gateResult(ok, message));
@@ -0,0 +1,56 @@
1
+ import { type InferredInput, defineScript, gezel } from '@bendyline/gezel-sdk';
2
+ import {
3
+ type CellType,
4
+ gateResult,
5
+ tableShape,
6
+ workspaceFromGezel,
7
+ } from '@bendyline/gezel-sdk/checks';
8
+
9
+ export const meta = defineScript({
10
+ name: 'checkTableShape',
11
+ description:
12
+ 'Gate: the first Markdown table in a file has the required columns, a minimum row count, and (optionally) typed columns — e.g. an action-item table with an owner column and ≥ 3 rows.',
13
+ kind: 'gate',
14
+ inputs: {
15
+ file: { type: 'string', description: 'Workspace-relative file to check.', required: true },
16
+ requiredColumns: {
17
+ type: 'json',
18
+ description: 'Array of header names that must be present (case-insensitive).',
19
+ },
20
+ minRows: {
21
+ type: 'number',
22
+ description: 'Minimum number of body rows.',
23
+ default: 1,
24
+ integer: true,
25
+ min: 0,
26
+ },
27
+ columnTypes: {
28
+ type: 'json',
29
+ description:
30
+ 'Optional { column: type } map. Type is one of number/integer/boolean/date/iso-date/email/nonempty, or a regex source.',
31
+ },
32
+ },
33
+ outputs: {
34
+ decision: { type: 'string', description: "'approve' or 'reject'." },
35
+ message: { type: 'string', description: 'What passed, or the concrete gap to fix.' },
36
+ },
37
+ requires: ['workspace.read'],
38
+ } as const);
39
+
40
+ const input = gezel.input as InferredInput<typeof meta>;
41
+ const content = await workspaceFromGezel(gezel).read(input.file);
42
+ if (content === null) {
43
+ gezel.output(
44
+ gateResult(false, `${input.file} not found — write the deliverable before advancing.`),
45
+ );
46
+ } else {
47
+ const requiredColumns = Array.isArray(input.requiredColumns)
48
+ ? input.requiredColumns.map(String)
49
+ : undefined;
50
+ const columnTypes =
51
+ input.columnTypes && typeof input.columnTypes === 'object' && !Array.isArray(input.columnTypes)
52
+ ? (input.columnTypes as Record<string, CellType>)
53
+ : undefined;
54
+ const r = tableShape(content, { requiredColumns, minRows: input.minRows, columnTypes });
55
+ gezel.output(gateResult(r.ok, r.detail));
56
+ }
@@ -0,0 +1,40 @@
1
+ import { type InferredInput, defineScript, gezel } from '@bendyline/gezel-sdk';
2
+ import { gateResult } from '@bendyline/gezel-sdk/checks';
3
+
4
+ export const meta = defineScript({
5
+ name: 'checkTaskNoteContains',
6
+ description:
7
+ 'Gate: the task\'s notes (optionally a specific phase\'s notes) match a pattern — e.g. "an acceptance checklist was written down before building".',
8
+ kind: 'gate',
9
+ inputs: {
10
+ // When this gate runs from a step, the runtime fills taskRef/stepId
11
+ // automatically from the triggering task; they only need to be set
12
+ // by hand for manual runs.
13
+ taskRef: {
14
+ type: 'string',
15
+ description: 'Task to inspect, as "projectId/num".',
16
+ required: true,
17
+ },
18
+ pattern: { type: 'string', description: 'Regular expression to look for.', required: true },
19
+ flags: { type: 'string', description: 'Regex flags, e.g. "i".', default: 'i' },
20
+ stepId: { type: 'string', description: "Restrict to this phase's notes (optional)." },
21
+ },
22
+ outputs: {
23
+ decision: { type: 'string', description: "'approve' or 'reject'." },
24
+ message: { type: 'string', description: 'What passed, or the concrete gap to fix.' },
25
+ },
26
+ requires: ['tasks.read'],
27
+ } as const);
28
+
29
+ const input = gezel.input as InferredInput<typeof meta>;
30
+ const notes = await gezel.task.readNotes(input.taskRef, input.stepId).catch(() => '');
31
+ const re = new RegExp(input.pattern, input.flags ?? 'i');
32
+ const ok = re.test(notes);
33
+ gezel.output(
34
+ gateResult(
35
+ ok,
36
+ ok
37
+ ? `task notes match /${input.pattern}/`
38
+ : `The task notes do not yet contain /${input.pattern}/ — write the required note (use write_task_note) before advancing.`,
39
+ ),
40
+ );
@@ -0,0 +1,33 @@
1
+ import { type InferredInput, defineScript, gezel } from '@bendyline/gezel-sdk';
2
+ import { gateResult, totalMinBytes, workspaceFromGezel } from '@bendyline/gezel-sdk/checks';
3
+
4
+ export const meta = defineScript({
5
+ name: 'checkTotalMinBytes',
6
+ description:
7
+ 'Gate: the combined size of several workspace files clears a floor (e.g. index.html + game.js ≥ 5000 bytes).',
8
+ kind: 'gate',
9
+ inputs: {
10
+ files: {
11
+ type: 'json',
12
+ description: 'Array of workspace-relative file paths, e.g. ["index.html", "game.js"].',
13
+ required: true,
14
+ },
15
+ minBytes: {
16
+ type: 'number',
17
+ description: 'Minimum combined size in bytes.',
18
+ required: true,
19
+ integer: true,
20
+ min: 1,
21
+ },
22
+ },
23
+ outputs: {
24
+ decision: { type: 'string', description: "'approve' or 'reject'." },
25
+ message: { type: 'string', description: 'What passed, or the concrete gap to fix.' },
26
+ },
27
+ requires: ['workspace.read'],
28
+ } as const);
29
+
30
+ const input = gezel.input as InferredInput<typeof meta>;
31
+ const files = Array.isArray(input.files) ? input.files.map(String) : [String(input.files)];
32
+ const r = await totalMinBytes(workspaceFromGezel(gezel), files, input.minBytes);
33
+ gezel.output(gateResult(r.ok, r.detail));
@@ -0,0 +1,49 @@
1
+ import { type InferredInput, defineScript, gezel } from '@bendyline/gezel-sdk';
2
+ import {
3
+ type GroundingFact,
4
+ gateResult,
5
+ valueGrounding,
6
+ workspaceFromGezel,
7
+ } from '@bendyline/gezel-sdk/checks';
8
+
9
+ export const meta = defineScript({
10
+ name: 'checkValueGrounding',
11
+ description:
12
+ "Gate: named facts are grounded in authorized sources — each fact's required value(s) must appear and its forbidden (decoy) value(s) must not. Digit-grouping tolerant. Ported from the decoy-research grader.",
13
+ kind: 'gate',
14
+ inputs: {
15
+ file: {
16
+ type: 'string',
17
+ description: 'Workspace-relative deliverable to check.',
18
+ required: true,
19
+ },
20
+ facts: {
21
+ type: 'json',
22
+ description:
23
+ 'Array of facts: [{ id, label?, required: string[], forbidden?: string[] }]. Values are regex sources matched case-insensitively; a fact passes when ANY required form matches and NO forbidden form does.',
24
+ required: true,
25
+ },
26
+ normalizeDigits: {
27
+ type: 'boolean',
28
+ description: 'Collapse digit-grouping so "4,217,300" matches /4217300/.',
29
+ default: true,
30
+ },
31
+ },
32
+ outputs: {
33
+ decision: { type: 'string', description: "'approve' or 'reject'." },
34
+ message: { type: 'string', description: 'What passed, or the concrete gap to fix.' },
35
+ },
36
+ requires: ['workspace.read'],
37
+ } as const);
38
+
39
+ const input = gezel.input as InferredInput<typeof meta>;
40
+ const content = await workspaceFromGezel(gezel).read(input.file);
41
+ if (content === null) {
42
+ gezel.output(
43
+ gateResult(false, `${input.file} not found — write the deliverable before advancing.`),
44
+ );
45
+ } else {
46
+ const facts = (Array.isArray(input.facts) ? input.facts : []) as GroundingFact[];
47
+ const r = valueGrounding(content, facts, { normalizeDigits: input.normalizeDigits });
48
+ gezel.output(gateResult(r.ok, r.detail));
49
+ }
@@ -0,0 +1,68 @@
1
+ import { type InferredInput, defineScript, gezel } from '@bendyline/gezel-sdk';
2
+ import { gateResult } from '@bendyline/gezel-sdk/checks';
3
+
4
+ /**
5
+ * Plan gate (runs on a plan-AUTHORING task): the draft plan ends with a
6
+ * terminal verification step that checks the outcomes — its prompt references
7
+ * outcome verification (verify_outcome / set_task_status). Reads the draft via
8
+ * the authoring task's `craftbookParams.draftRef`.
9
+ */
10
+ export const meta = defineScript({
11
+ name: 'checkVerificationStep',
12
+ description:
13
+ "Plan gate: the draft plan has a terminal verification step whose prompt checks each outcome (verify_outcome) and closes the task (set_task_status). Reads the draft via the authoring task's craftbookParams.draftRef.",
14
+ kind: 'gate',
15
+ inputs: {
16
+ taskRef: {
17
+ type: 'string',
18
+ description:
19
+ 'The authoring task (auto-filled by the runtime when this gate runs from a step).',
20
+ },
21
+ },
22
+ outputs: {
23
+ decision: { type: 'string', description: "'approve' or 'reject'." },
24
+ message: { type: 'string', description: 'What passed, or the concrete gap to fix.' },
25
+ },
26
+ requires: ['tasks.read'],
27
+ } as const);
28
+
29
+ interface StepView {
30
+ id: string;
31
+ name?: string;
32
+ prompt?: string;
33
+ terminal?: boolean;
34
+ }
35
+ interface DraftView {
36
+ craftbookParams?: Record<string, string>;
37
+ craftbook?: { steps?: StepView[] };
38
+ }
39
+
40
+ const VERIFY_RE = /outcome|verify_outcome|set_task_status/i;
41
+
42
+ const input = gezel.input as InferredInput<typeof meta>;
43
+
44
+ let ok = false;
45
+ let message = '';
46
+
47
+ const authoring = (await gezel.task.get(input.taskRef ?? '').catch(() => null)) as DraftView | null;
48
+ const draftRef = authoring?.craftbookParams?.draftRef;
49
+ if (!draftRef) {
50
+ message =
51
+ 'This gate must run on a plan-authoring task whose craftbookParams.draftRef points at the draft plan. Start planning with start_plan.';
52
+ } else {
53
+ const draft = (await gezel.task.get(draftRef).catch(() => null)) as DraftView | null;
54
+ const steps = draft?.craftbook?.steps ?? [];
55
+ const terminals = steps.filter((s) => s.terminal);
56
+ const verifiers = terminals.filter((s) => VERIFY_RE.test(s.prompt ?? ''));
57
+ ok = verifiers.length >= 1;
58
+ if (ok) {
59
+ message = `Final verification step present ("${verifiers[0]?.name ?? verifiers[0]?.id}").`;
60
+ } else if (terminals.length === 0) {
61
+ message =
62
+ 'The plan has no terminal step. Append a final verification step (terminal: true) whose prompt checks each outcome via verify_outcome({ ref, id, met, evidence }) and then calls set_task_status({ complete }).';
63
+ } else {
64
+ message = `The plan's terminal step does not verify outcomes. Make the final step call verify_outcome for each outcome (citing the produced artifact as evidence) and then set_task_status({ complete }).`;
65
+ }
66
+ }
67
+
68
+ gezel.output(gateResult(ok, message));
@@ -0,0 +1,51 @@
1
+ import { type InferredInput, defineScript, gezel } from '@bendyline/gezel-sdk';
2
+ import { gateResult, wordBand, workspaceFromGezel } from '@bendyline/gezel-sdk/checks';
3
+
4
+ export const meta = defineScript({
5
+ name: 'checkWordBand',
6
+ description:
7
+ "Gate: a file's word count is within [min, max] — floors AND ceilings, because verbosity is a failure mode too. Markdown markup (code fences, links, emphasis) is excluded from the count by default.",
8
+ kind: 'gate',
9
+ inputs: {
10
+ file: { type: 'string', description: 'Workspace-relative file to check.', required: true },
11
+ min: {
12
+ type: 'number',
13
+ description: 'Minimum word count (omit for no floor).',
14
+ integer: true,
15
+ min: 0,
16
+ },
17
+ max: {
18
+ type: 'number',
19
+ description: 'Maximum word count (omit for no ceiling).',
20
+ integer: true,
21
+ min: 0,
22
+ },
23
+ stripMarkdown: {
24
+ type: 'boolean',
25
+ description: 'Exclude Markdown markup from the count.',
26
+ default: true,
27
+ },
28
+ },
29
+ outputs: {
30
+ decision: { type: 'string', description: "'approve' or 'reject'." },
31
+ message: { type: 'string', description: 'What passed, or the concrete gap to fix.' },
32
+ },
33
+ requires: ['workspace.read'],
34
+ } as const);
35
+
36
+ const input = gezel.input as InferredInput<typeof meta>;
37
+ const content = await workspaceFromGezel(gezel).read(input.file);
38
+ if (content === null) {
39
+ gezel.output(
40
+ gateResult(false, `${input.file} not found — write the deliverable before advancing.`),
41
+ );
42
+ } else if (input.min === undefined && input.max === undefined) {
43
+ gezel.output(gateResult(false, 'No band configured — set "min" and/or "max".'));
44
+ } else {
45
+ const r = wordBand(content, {
46
+ min: input.min,
47
+ max: input.max,
48
+ stripMarkdown: input.stripMarkdown,
49
+ });
50
+ gezel.output(gateResult(r.ok, `${input.file}: ${r.detail}`));
51
+ }