@pbuilder/sdk 0.18.0 → 0.20.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 (79) hide show
  1. package/README.md +89 -3
  2. package/dist/acl/irwire/stdio-engine-client.d.ts +2 -1
  3. package/dist/acl/irwire/stdio-engine-client.js +12 -2
  4. package/dist/bin/pbuilder-codegen.js +148 -18
  5. package/dist/bin/pbuilder-conformance.js +24 -5
  6. package/dist/bounded-contexts/authoring/application/usecases/authoring-verbs/index.d.ts +15 -0
  7. package/dist/bounded-contexts/authoring/application/usecases/authoring-verbs/index.js +17 -0
  8. package/dist/bounded-contexts/authoring/application/usecases/run-factory/context.d.ts +21 -5
  9. package/dist/bounded-contexts/authoring/application/usecases/run-factory/context.js +59 -12
  10. package/dist/bounded-contexts/authoring/domain/aggregates/session/session.d.ts +4 -2
  11. package/dist/bounded-contexts/authoring/domain/aggregates/session/session.js +12 -3
  12. package/dist/bounded-contexts/authoring/domain/ports/engine-client.d.ts +2 -1
  13. package/dist/bounded-contexts/authoring/domain/services/define-dialect.d.ts +28 -1
  14. package/dist/bounded-contexts/authoring/domain/services/define-dialect.js +27 -3
  15. package/dist/bounded-contexts/authoring/domain/services/evaluation.d.ts +29 -0
  16. package/dist/bounded-contexts/authoring/domain/services/evaluation.js +43 -0
  17. package/dist/bounded-contexts/authoring/domain/services/glob-match.d.ts +4 -0
  18. package/dist/bounded-contexts/authoring/domain/services/glob-match.js +81 -0
  19. package/dist/bounded-contexts/authoring/domain/services/schema/input-rejection.d.ts +2 -0
  20. package/dist/bounded-contexts/authoring/domain/services/schema/input-rejection.js +8 -0
  21. package/dist/bounded-contexts/authoring/domain/services/schema/schema-parse.d.ts +3 -2
  22. package/dist/bounded-contexts/authoring/domain/services/schema/schema-parse.js +46 -4
  23. package/dist/bounded-contexts/authoring/domain/services/schema/schema-validate.d.ts +18 -2
  24. package/dist/bounded-contexts/authoring/domain/services/schema/schema-validate.js +131 -2
  25. package/dist/bounded-contexts/authoring/domain/valueobjects/authoring-error.d.ts +3 -2
  26. package/dist/bounded-contexts/authoring/domain/valueobjects/authoring-error.js +2 -0
  27. package/dist/bounded-contexts/authoring/domain/valueobjects/findings.d.ts +12 -0
  28. package/dist/bounded-contexts/authoring/domain/valueobjects/findings.js +57 -0
  29. package/dist/bounded-contexts/authoring/domain/valueobjects/schema-model.d.ts +19 -0
  30. package/dist/bounded-contexts/authoring/domain/valueobjects/schema-model.js +1 -0
  31. package/dist/bounded-contexts/authoring/infrastructure/in/codegen/cli.d.ts +7 -2
  32. package/dist/bounded-contexts/authoring/infrastructure/in/codegen/cli.js +28 -7
  33. package/dist/bounded-contexts/authoring/infrastructure/in/codegen/emit-type.d.ts +6 -1
  34. package/dist/bounded-contexts/authoring/infrastructure/in/codegen/emit-type.js +44 -11
  35. package/dist/bounded-contexts/authoring/infrastructure/in/codegen/project-codegen.d.ts +1 -0
  36. package/dist/bounded-contexts/authoring/infrastructure/in/codegen/project-codegen.js +5 -2
  37. package/dist/bounded-contexts/authoring/infrastructure/in/commons/index.d.ts +2 -1
  38. package/dist/bounded-contexts/authoring/infrastructure/in/commons/index.js +1 -1
  39. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/angular/index.d.ts +14 -1
  40. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/angular/index.js +15 -0
  41. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/aspnet/index.d.ts +14 -1
  42. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/aspnet/index.js +15 -0
  43. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/csharp/index.d.ts +14 -1
  44. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/csharp/index.js +15 -0
  45. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/css/index.d.ts +14 -1
  46. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/css/index.js +15 -0
  47. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/json/index.d.ts +14 -1
  48. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/json/index.js +15 -0
  49. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/msbuild/index.d.ts +14 -1
  50. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/msbuild/index.js +15 -0
  51. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/nestjs/index.d.ts +14 -1
  52. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/nestjs/index.js +15 -0
  53. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/index.d.ts +14 -1
  54. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/index.js +15 -0
  55. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/typescript/index.d.ts +14 -1
  56. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/typescript/index.js +15 -0
  57. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/yaml/index.d.ts +14 -1
  58. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/yaml/index.js +15 -0
  59. package/dist/bounded-contexts/authoring/testing/conformance/run-package.d.ts +17 -0
  60. package/dist/bounded-contexts/authoring/testing/conformance/run-package.js +124 -44
  61. package/dist/bounded-contexts/authoring/testing/contract-fake.d.ts +1 -0
  62. package/dist/bounded-contexts/authoring/testing/contract-fake.js +8 -0
  63. package/dist/bounded-contexts/authoring/testing/glob-pattern.d.ts +5 -0
  64. package/dist/bounded-contexts/authoring/testing/glob-pattern.js +20 -0
  65. package/dist/bounded-contexts/authoring/testing/harness/index.d.ts +18 -4
  66. package/dist/bounded-contexts/authoring/testing/harness/index.js +17 -4
  67. package/dist/bounded-contexts/authoring/testing/run-vehicle.d.ts +1 -0
  68. package/dist/bounded-contexts/authoring/testing/run-vehicle.js +4 -0
  69. package/dist/bounded-contexts/runner-hosting/infrastructure/in/bootstrap-bridge.d.ts +3 -0
  70. package/dist/bounded-contexts/runner-hosting/infrastructure/in/bootstrap-bridge.js +4 -0
  71. package/dist/bounded-contexts/runner-hosting/infrastructure/in/runner.js +52 -13
  72. package/dist/bounded-contexts/runner-hosting/infrastructure/in/single-instance-probe.d.ts +14 -3
  73. package/dist/bounded-contexts/runner-hosting/infrastructure/in/single-instance-probe.js +17 -8
  74. package/dist/conformance/index.d.ts +1 -1
  75. package/dist/conformance/index.js +1 -1
  76. package/dist/runner-manifest.json +37 -13
  77. package/dist/shared-kernel/wire-protocol.d.ts +1 -1
  78. package/dist/shared-kernel/wire-protocol.js +1 -1
  79. package/package.json +1 -1
@@ -31,7 +31,8 @@ function matchesType(property, value) {
31
31
  return typeof value === "string" && (property.choices ?? []).includes(value);
32
32
  }
33
33
  }
34
- export function validateInput(schema, input) {
34
+ /** `imposed` names the inputs a role adds, which `schema.json` never declares (A-122). */
35
+ export function validateInput(schema, input, imposed = []) {
35
36
  const findings = [];
36
37
  const record = (input !== null && typeof input === "object" ? input : {});
37
38
  for (const property of schema.properties) {
@@ -56,9 +57,137 @@ export function validateInput(schema, input) {
56
57
  // mapping, slices load-bearing literals).
57
58
  const declaredKeys = new Set(schema.properties.map((property) => property.key));
58
59
  for (const key of Object.keys(record)) {
59
- if (RESERVED_INPUT_KEYS.has(key) || FORBIDDEN_KEYS.has(key) || !declaredKeys.has(key)) {
60
+ if (RESERVED_INPUT_KEYS.has(key) || FORBIDDEN_KEYS.has(key) || !(declaredKeys.has(key) || imposed.includes(key))) {
60
61
  findings.push({ kind: "disallowed-key", field: key });
61
62
  }
62
63
  }
63
64
  return findings;
64
65
  }
66
+ /** E-40: the largest JSON encoding of a Result, in UTF-8 bytes; exactly at it is allowed. */
67
+ export const RESULT_CEILING_BYTES = 1048576;
68
+ /**
69
+ * Checks `value` as the Result of a factory whose declaration is `declared`. Without a
70
+ * declaration only `undefined`, no Result, passes. A Result that passes comes back as a copy
71
+ * parsed from its JSON encoding, so what is committed is exactly what was checked. The
72
+ * declaration is a parameter so a Result shape a role imposes can be checked the same way as
73
+ * one read from `schema.json`.
74
+ */
75
+ export function checkResult(declared, value) {
76
+ if (declared === undefined) {
77
+ return value === undefined ? { result: undefined } : { problem: "the factory declares no Result in schema.json but returned a value" };
78
+ }
79
+ let encoded;
80
+ try {
81
+ const problem = jsonProblem(value, "Result", new Set());
82
+ if (problem !== undefined)
83
+ return { problem };
84
+ encoded = JSON.stringify(value);
85
+ }
86
+ catch (err) {
87
+ // A getter or proxy that throws, or nesting too deep to walk; what it threw is not echoed.
88
+ return { problem: err instanceof RangeError ? "the Result is nested too deeply" : "the Result could not be read" };
89
+ }
90
+ const result = JSON.parse(encoded);
91
+ const problem = shapeProblem(declared, result, "Result");
92
+ if (problem !== undefined)
93
+ return { problem };
94
+ const bytes = Buffer.byteLength(encoded, "utf8");
95
+ return bytes > RESULT_CEILING_BYTES
96
+ ? { problem: `the JSON encoding of the Result is ${bytes} bytes, past the 1 MiB ceiling (${RESULT_CEILING_BYTES} bytes)` }
97
+ : { result };
98
+ }
99
+ // JSON.stringify drops or rewrites what is not JSON (undefined, functions, NaN, a Date's
100
+ // toJSON) instead of failing, so the walk refuses each of them explicitly.
101
+ function jsonProblem(value, where, ancestors) {
102
+ switch (typeof value) {
103
+ case "string":
104
+ case "boolean":
105
+ return undefined;
106
+ case "number":
107
+ // NaN and ±Infinity are the numbers for which this is not 0 (the runner closure admits no Number.isFinite).
108
+ return value - value === 0 ? undefined : `${where} is a non-finite number`;
109
+ case "undefined":
110
+ case "function":
111
+ case "bigint":
112
+ case "symbol":
113
+ return `${where} is ${typeof value === "undefined" ? "undefined" : `a ${typeof value}`}`;
114
+ }
115
+ if (value === null)
116
+ return undefined;
117
+ const object = value;
118
+ if (ancestors.has(object))
119
+ return `${where} is a cycle`;
120
+ if (!Array.isArray(object)) {
121
+ const prototype = Object.getPrototypeOf(object);
122
+ if (prototype !== Object.prototype && prototype !== null) {
123
+ return `${where} is ${object instanceof Date ? "a Date" : object instanceof Map ? "a Map" : "a class instance"}`;
124
+ }
125
+ if (typeof object.toJSON === "function")
126
+ return `${where} has a toJSON method`;
127
+ }
128
+ // Ancestors only, so a value shared twice without a cycle is accepted, as JSON.stringify does.
129
+ ancestors.add(object);
130
+ try {
131
+ const entries = [];
132
+ if (Array.isArray(object)) {
133
+ for (let index = 0; index < object.length; index++)
134
+ entries.push([`${where}[${index}]`, object[index]]);
135
+ }
136
+ else {
137
+ for (const key of Object.keys(object))
138
+ entries.push([`${where}.${key}`, object[key]]);
139
+ }
140
+ for (const [at, item] of entries) {
141
+ const problem = jsonProblem(item, at, ancestors);
142
+ if (problem !== undefined)
143
+ return problem;
144
+ }
145
+ return undefined;
146
+ }
147
+ finally {
148
+ ancestors.delete(object);
149
+ }
150
+ }
151
+ function kindOf(value) {
152
+ if (value === null)
153
+ return "null";
154
+ if (Array.isArray(value))
155
+ return "array";
156
+ return typeof value;
157
+ }
158
+ // Runs on the parsed copy, so every value here is JSON.
159
+ function shapeProblem(declared, value, where) {
160
+ const kind = kindOf(value);
161
+ if (!declared.types.includes(kind))
162
+ return `${where} must be ${declared.types.join(" or ")}`;
163
+ if (kind === "string" && declared.choices !== undefined && !declared.choices.includes(value)) {
164
+ return `${where} must be one of: ${declared.choices.join(", ")}`;
165
+ }
166
+ if (kind === "array" && declared.items !== undefined) {
167
+ const items = declared.items;
168
+ for (const [index, item] of value.entries()) {
169
+ const problem = shapeProblem(items, item, `${where}[${index}]`);
170
+ if (problem !== undefined)
171
+ return problem;
172
+ }
173
+ }
174
+ if (kind === "object" && declared.properties !== undefined) {
175
+ const record = value;
176
+ const required = new Set(declared.required);
177
+ for (const { key, schema } of declared.properties) {
178
+ if (!Object.hasOwn(record, key)) {
179
+ if (required.has(key))
180
+ return `${where}.${key} must be ${schema.types.join(" or ")}`;
181
+ continue;
182
+ }
183
+ const problem = shapeProblem(schema, record[key], `${where}.${key}`);
184
+ if (problem !== undefined)
185
+ return problem;
186
+ }
187
+ const declaredKeys = new Set(declared.properties.map((property) => property.key));
188
+ const extra = Object.keys(record).find((key) => !declaredKeys.has(key));
189
+ if (extra !== undefined)
190
+ return `${where}.${extra} is not declared`;
191
+ }
192
+ return undefined;
193
+ }
@@ -52,11 +52,12 @@ export type AuthoringVerb = "create" | "modify" | "remove" | "rename" | "move" |
52
52
  * case "source-not-found":
53
53
  * case "source-not-regular-file":
54
54
  * case "source-unreadable":
55
+ * case "invalid-result":
55
56
  * console.error(err.message);
56
57
  * break;
57
58
  * }
58
59
  */
59
- export type AuthoringReason = "path-collision" | "path-not-found" | "unrepresentable-content" | "changes-too-large" | "outside-session" | "unknown" | "invalid-input" | "reserved-name" | "source-not-found" | "source-not-regular-file" | "source-unreadable";
60
+ export type AuthoringReason = "path-collision" | "path-not-found" | "unrepresentable-content" | "changes-too-large" | "outside-session" | "unknown" | "invalid-input" | "reserved-name" | "source-not-found" | "source-not-regular-file" | "source-unreadable" | "invalid-result";
60
61
  /**
61
62
  * Distinguishes an engine-refused write from an SDK-side misuse (2.4, ADR-0021) —
62
63
  * DERIVED from `reason`, never producer-set.
@@ -106,7 +107,7 @@ export declare class AuthoringError extends Error {
106
107
  appliedCount: number;
107
108
  /**
108
109
  * Overrides the derived message. REQUIRED for `reason: "invalid-input"` /
109
- * `"reserved-name"` (REQ-AEC-09) — their templates interpolate caller-known data
110
+ * `"reserved-name"` (REQ-AEC-09) / `"invalid-result"` (A-14) — their templates interpolate caller-known data
110
111
  * (`{field}`, `{expectedType}`, `{name}`) `messageFor` cannot derive from `verb`/`path`
111
112
  * alone. Optional for every other reason, which derive their message from `reason` +
112
113
  * `verb` + `path` as before.
@@ -36,6 +36,7 @@ function originFor(reason) {
36
36
  case "source-not-found":
37
37
  case "source-not-regular-file":
38
38
  case "source-unreadable":
39
+ case "invalid-result":
39
40
  return "authoring-rejected";
40
41
  default: {
41
42
  const _exhaustive = reason;
@@ -121,6 +122,7 @@ function messageFor(reason, verb, path) {
121
122
  return `source file unreadable: ${path} could not be read`;
122
123
  case "invalid-input":
123
124
  case "reserved-name":
125
+ case "invalid-result":
124
126
  throw new Error(`messageFor: reason "${reason}" has no default template (REQ-AEC-09) — construct AuthoringError with an explicit \`message\``);
125
127
  // Parity with originFor: noImplicitReturns is off, so without this arm a 13th reason
126
128
  // would fall through to an implicit `undefined` return instead of a build break.
@@ -0,0 +1,12 @@
1
+ import type { ResultSchema } from "./schema-model.ts";
2
+ /** The role a schematic declares in its Collection definition entry (CA-14). */
3
+ export type Role = "generator" | "setup" | "teardown" | "evaluation";
4
+ /** The inputs the role `evaluation` imposes; an author input with either name is rejected (A-122). */
5
+ export declare const SCOPE_INPUTS: readonly string[];
6
+ /** The Findings an evaluation factory returns: what codegen emits as its Result type. */
7
+ export declare const FINDINGS: ResultSchema;
8
+ /**
9
+ * FINDINGS with the `source` the SDK sets. The run boundary checks a returned value against it,
10
+ * so an author-set `source` passes the shape check and is then rejected by name.
11
+ */
12
+ export declare const SOURCED_FINDINGS: ResultSchema;
@@ -0,0 +1,57 @@
1
+ // A-120 / A-121 / A-122: what the role `evaluation` imposes on a factory, as data both codegen and
2
+ // the run boundary read, so the emitted types and the checked shape cannot drift apart.
3
+ /** The inputs the role `evaluation` imposes; an author input with either name is rejected (A-122). */
4
+ export const SCOPE_INPUTS = ["include", "exclude"];
5
+ const STRING = { types: ["string"] };
6
+ const NUMBER = { types: ["number"] };
7
+ const POSITION = {
8
+ types: ["object"],
9
+ properties: [
10
+ { key: "line", schema: NUMBER },
11
+ { key: "column", schema: NUMBER },
12
+ ],
13
+ required: ["line", "column"],
14
+ };
15
+ function findingsWith(extra) {
16
+ const finding = {
17
+ types: ["object"],
18
+ properties: [
19
+ { key: "rule", schema: STRING },
20
+ { key: "message", schema: STRING },
21
+ { key: "severity", schema: { types: ["string"], choices: ["error", "warning"] } },
22
+ { key: "path", schema: STRING },
23
+ {
24
+ key: "range",
25
+ schema: {
26
+ types: ["object"],
27
+ properties: [
28
+ { key: "start", schema: POSITION },
29
+ { key: "end", schema: POSITION },
30
+ ],
31
+ required: ["start"],
32
+ },
33
+ },
34
+ {
35
+ key: "fix",
36
+ schema: {
37
+ types: ["object"],
38
+ properties: [
39
+ { key: "schematic", schema: STRING },
40
+ { key: "inputs", schema: { types: ["object"] } },
41
+ ],
42
+ required: ["schematic"],
43
+ },
44
+ },
45
+ ...extra,
46
+ ],
47
+ required: ["rule", "message", "severity"],
48
+ };
49
+ return { types: ["object"], properties: [{ key: "items", schema: { types: ["array"], items: finding } }], required: ["items"] };
50
+ }
51
+ /** The Findings an evaluation factory returns: what codegen emits as its Result type. */
52
+ export const FINDINGS = findingsWith([]);
53
+ /**
54
+ * FINDINGS with the `source` the SDK sets. The run boundary checks a returned value against it,
55
+ * so an author-set `source` passes the shape check and is then rejected by name.
56
+ */
57
+ export const SOURCED_FINDINGS = findingsWith([{ key: "source", schema: STRING }]);
@@ -8,8 +8,27 @@ export interface SchemaProperty {
8
8
  required?: boolean;
9
9
  description?: string;
10
10
  }
11
+ export type ResultKind = "string" | "number" | "boolean" | "null" | "object" | "array";
12
+ export declare const RESULT_KINDS: ReadonlySet<string>;
13
+ /**
14
+ * The Result a schematic declares under `result` in `schema.json` (A-14): a subset of JSON
15
+ * Schema. `properties` closes an object to the keys it names; without it any JSON object fits.
16
+ */
17
+ export interface ResultSchema {
18
+ types: ResultKind[];
19
+ properties?: Array<{
20
+ key: string;
21
+ schema: ResultSchema;
22
+ }>;
23
+ required?: string[];
24
+ items?: ResultSchema;
25
+ /** The values a string may take. `schema.json` cannot declare it; a shape a role imposes can. */
26
+ choices?: string[];
27
+ }
11
28
  export interface Schema {
12
29
  properties: SchemaProperty[];
30
+ /** Absent when the schematic declares no Result, so its factory must return nothing. */
31
+ result?: ResultSchema;
13
32
  }
14
33
  export declare const RESERVED_LIFECYCLE_NAMES: readonly ["pre-execute", "post-execute"];
15
34
  export declare const FORBIDDEN_KEYS: Set<string>;
@@ -4,6 +4,7 @@
4
4
  // This is a DISTINCT shape from the on-disk wire contract (ADR-0027): the wire form is a
5
5
  // wrapped `{ "properties": { "<key>": {...} } }` map (the SDK<->Go-CLI cross-repo contract);
6
6
  // schema-parse.ts lifts that map into this array, `key` becoming an explicit field.
7
+ export const RESULT_KINDS = new Set(["string", "number", "boolean", "null", "object", "array"]);
7
8
  // Cross-repo lifecycle tokens (2026-07-06 engine handoff) — schematic-level, kebab-case,
8
9
  // case-insensitive matching lives in the reserved-name scan (S-004, ADR-0028).
9
10
  export const RESERVED_LIFECYCLE_NAMES = ["pre-execute", "post-execute"];
@@ -10,11 +10,16 @@ export declare class SchemaSufficiencyFailure extends Error {
10
10
  readonly findings: SufficiencyFinding[];
11
11
  constructor(findings: SufficiencyFinding[]);
12
12
  }
13
+ /** A-120 / A-122: a `schema.json` that declares what the role `evaluation` imposes. */
14
+ export declare class RoleContractFailure extends Error {
15
+ constructor(problem: string);
16
+ }
13
17
  /**
14
18
  * Reads `<packageDir>/schema.json`, parses it, and writes `<packageDir>/schema.generated.ts`
15
- * — the bin's fixed, non-configurable output location (REQ-TFO-05.1/FPS-01).
19
+ * — the bin's fixed, non-configurable output location (REQ-TFO-05.1/FPS-01). `evaluation` is set
20
+ * when the schematic's Collection definition entry declares the role `evaluation`.
16
21
  */
17
- export declare function generateSchema(packageDir: string): GenerateResult;
22
+ export declare function generateSchema(packageDir: string, evaluation?: boolean): GenerateResult;
18
23
  export declare class WriteContainmentRefusal extends Error {
19
24
  constructor(message: string);
20
25
  }
@@ -16,6 +16,7 @@ import { checkSufficiency } from "../../../domain/services/schema/schema-suffici
16
16
  import { isErrnoException } from "../../../../../platform/fs-errors.js";
17
17
  import { emitInputType, UnrecognizedPropertyTypeError } from "./emit-type.js";
18
18
  import { discoverProject } from "./project-codegen.js";
19
+ import { SCOPE_INPUTS } from "../../../domain/valueobjects/findings.js";
19
20
  export const GENERATED_FILENAME = "schema.generated.ts";
20
21
  export const SUCCESS_LINE = "pbuilder-codegen: wrote schema.generated.ts";
21
22
  export const USAGE = [
@@ -35,6 +36,22 @@ export class SchemaSufficiencyFailure extends Error {
35
36
  this.findings = findings;
36
37
  }
37
38
  }
39
+ /** A-120 / A-122: a `schema.json` that declares what the role `evaluation` imposes. */
40
+ export class RoleContractFailure extends Error {
41
+ constructor(problem) {
42
+ super(problem);
43
+ this.name = "RoleContractFailure";
44
+ }
45
+ }
46
+ function checkEvaluationSchema(schema) {
47
+ if (schema.result !== undefined) {
48
+ throw new RoleContractFailure("an evaluation schematic declares a Result, which the role fixes as Findings");
49
+ }
50
+ const imposed = schema.properties.find((property) => SCOPE_INPUTS.includes(property.key));
51
+ if (imposed !== undefined) {
52
+ throw new RoleContractFailure(`an evaluation schematic declares the input ${JSON.stringify(imposed.key)}, which the role imposes`);
53
+ }
54
+ }
38
55
  class OutputWriteFailure extends Error {
39
56
  constructor(outputPath, cause, reason) {
40
57
  const code = isErrnoException(cause) ? cause.code : undefined;
@@ -60,9 +77,10 @@ function assertOutputLeaf(outputPath) {
60
77
  }
61
78
  /**
62
79
  * Reads `<packageDir>/schema.json`, parses it, and writes `<packageDir>/schema.generated.ts`
63
- * — the bin's fixed, non-configurable output location (REQ-TFO-05.1/FPS-01).
80
+ * — the bin's fixed, non-configurable output location (REQ-TFO-05.1/FPS-01). `evaluation` is set
81
+ * when the schematic's Collection definition entry declares the role `evaluation`.
64
82
  */
65
- export function generateSchema(packageDir) {
83
+ export function generateSchema(packageDir, evaluation = false) {
66
84
  const schemaPath = schemaPathFor(packageDir);
67
85
  const raw = readFileSync(schemaPath, "utf-8");
68
86
  const schema = parseSchema(raw);
@@ -70,8 +88,10 @@ export function generateSchema(packageDir) {
70
88
  if (sufficiencyFindings.length > 0) {
71
89
  throw new SchemaSufficiencyFailure(sufficiencyFindings);
72
90
  }
91
+ if (evaluation)
92
+ checkEvaluationSchema(schema);
73
93
  const digest = computeSchemaDigest(raw);
74
- const output = emitInputType(schema, digest);
94
+ const output = emitInputType(schema, digest, evaluation);
75
95
  const outputPath = join(packageDir, GENERATED_FILENAME);
76
96
  try {
77
97
  if (process.platform === "linux" || process.platform === "darwin") {
@@ -288,16 +308,17 @@ function runProject(directory) {
288
308
  seen.add(output);
289
309
  if (!statSync(schemaPath).isFile())
290
310
  throw new Error("nonregular schema");
291
- generateSchema(entry.directory);
311
+ generateSchema(entry.directory, entry.evaluation);
292
312
  generated++;
293
313
  }
294
314
  catch (error) {
295
315
  failed++;
296
316
  const diagnostic = error instanceof SchemaParseFailure ? formatParseError(schemaPath, error)
297
317
  : error instanceof SchemaSufficiencyFailure ? formatSufficiencyError(schemaPath, error)
298
- : error instanceof WriteContainmentRefusal ? "refusing to write outside the selected project root"
299
- : error instanceof OutputWriteFailure ? "cannot write a regular, non-symbolic-link output"
300
- : "cannot read or generate schema.json";
318
+ : error instanceof RoleContractFailure ? `pbuilder-codegen: ${schemaPath}: ${error.message}`
319
+ : error instanceof WriteContainmentRefusal ? "refusing to write outside the selected project root"
320
+ : error instanceof OutputWriteFailure ? "cannot write a regular, non-symbolic-link output"
321
+ : "cannot read or generate schema.json";
301
322
  console.error(`pbuilder-codegen: ${JSON.stringify(entry.label)} (${JSON.stringify(entry.directory)}): ${JSON.stringify(diagnostic)}`);
302
323
  }
303
324
  }
@@ -4,4 +4,9 @@ export declare class UnrecognizedPropertyTypeError extends Error {
4
4
  readonly field: string;
5
5
  constructor(field: string);
6
6
  }
7
- export declare function emitInputType(schema: Schema, digest: string): string;
7
+ /**
8
+ * The Input type, and the Result type when the schema declares a Result (A-15). With the role
9
+ * `evaluation` the Input also holds the scope inputs and the Result is the Findings the role
10
+ * imposes (A-120, A-122); the caller has already refused a schema that declares either.
11
+ */
12
+ export declare function emitInputType(schema: Schema, digest: string, evaluation?: boolean): string;
@@ -6,6 +6,7 @@
6
6
  // discipline still holds so a hostile schema can never distort the emitted TEXT into
7
7
  // something a human misreads or a downstream tool mis-tokenizes.
8
8
  import { RECOGNIZED_KINDS } from "../../../domain/services/schema/schema-sufficiency.js";
9
+ import { FINDINGS } from "../../../domain/valueobjects/findings.js";
9
10
  export const GENERATED_HEADER = "// AUTO-GENERATED by pbuilder-codegen — do not edit. Regenerate: pbuilder-codegen <package-dir>";
10
11
  const IDENTIFIER_RE = /^[A-Za-z_$][\w$]*$/;
11
12
  // schema-parse.ts casts `type` to `SchemaKind` with zero runtime validation (`value.type as
@@ -54,15 +55,47 @@ function emitProperty(property) {
54
55
  : "";
55
56
  return `${doc} ${key}${optional}: ${type};`;
56
57
  }
57
- export function emitInputType(schema, digest) {
58
- const members = schema.properties.map(emitProperty).join("\n");
59
- return [
60
- GENERATED_HEADER,
61
- `// @schema-digest sha256:${digest}`,
62
- "",
63
- "export type Input = {",
64
- members,
65
- "};",
66
- "",
67
- ].join("\n");
58
+ // A-15: the declared Result as a type. Kinds come from the closed set parseSchema checked,
59
+ // and keys go through emitPropertyKey, so no schema text reaches the output unquoted.
60
+ function emitResult(result) {
61
+ return result.types
62
+ .map((kind) => {
63
+ switch (kind) {
64
+ case "array":
65
+ return `Array<${result.items === undefined ? "unknown" : emitResult(result.items)}>`;
66
+ case "object": {
67
+ if (result.properties === undefined)
68
+ return "{ [key: string]: unknown }";
69
+ const required = new Set(result.required);
70
+ const members = result.properties.map(({ key, schema }) => `${emitPropertyKey(key)}${required.has(key) ? "" : "?"}: ${emitResult(schema)}`);
71
+ return members.length === 0 ? "Record<string, never>" : `{ ${members.join("; ")} }`;
72
+ }
73
+ case "string":
74
+ return result.choices === undefined ? kind : result.choices.map((choice) => JSON.stringify(choice)).join(" | ");
75
+ default:
76
+ return kind;
77
+ }
78
+ })
79
+ .join(" | ");
80
+ }
81
+ // A-122: the scope inputs the role `evaluation` imposes, after the author's own.
82
+ const SCOPE_MEMBERS = [
83
+ " /** Globs or literal paths to check */",
84
+ " include?: string[];",
85
+ " /** Globs or literal paths to skip */",
86
+ " exclude?: string[];",
87
+ ];
88
+ /**
89
+ * The Input type, and the Result type when the schema declares a Result (A-15). With the role
90
+ * `evaluation` the Input also holds the scope inputs and the Result is the Findings the role
91
+ * imposes (A-120, A-122); the caller has already refused a schema that declares either.
92
+ */
93
+ export function emitInputType(schema, digest, evaluation = false) {
94
+ const members = [...schema.properties.map(emitProperty), ...(evaluation ? SCOPE_MEMBERS : [])].join("\n");
95
+ const result = evaluation
96
+ ? ["", `export type Findings = ${emitResult(FINDINGS)};`, "", "export type Result = Findings;"]
97
+ : schema.result === undefined
98
+ ? []
99
+ : ["", `export type Result = ${emitResult(schema.result)};`];
100
+ return [GENERATED_HEADER, `// @schema-digest sha256:${digest}`, "", "export type Input = {", members, "};", ...result, ""].join("\n");
68
101
  }
@@ -2,6 +2,7 @@ type ProjectEntry = {
2
2
  kind: "target";
3
3
  label: string;
4
4
  directory: string;
5
+ evaluation: boolean;
5
6
  } | {
6
7
  kind: "failure";
7
8
  label: string;
@@ -11,6 +11,9 @@ function readObject(path) {
11
11
  throw new Error("invalid object");
12
12
  return value;
13
13
  }
14
+ function isEvaluation(registration) {
15
+ return isPlainObject(registration) && registration.role === "evaluation";
16
+ }
14
17
  export function discoverProject(directory) {
15
18
  let selected = resolve(directory ?? process.cwd());
16
19
  if (directory === undefined) {
@@ -77,7 +80,7 @@ export function discoverProject(directory) {
77
80
  try {
78
81
  if (!statSync(module).isFile())
79
82
  throw new Error("nonregular module");
80
- entries.push({ kind: "target", label, directory: dirname(realpathSync(module)) });
83
+ entries.push({ kind: "target", label, directory: dirname(realpathSync(module)), evaluation: isEvaluation(registration) });
81
84
  }
82
85
  catch {
83
86
  entries.push({ kind: "failure", label, diagnostic: `cannot resolve factory module ${JSON.stringify(module)}` });
@@ -120,7 +123,7 @@ export function discoverProject(directory) {
120
123
  }
121
124
  if (factories !== 1)
122
125
  throw new Error("ambiguous or missing factory");
123
- entries.push({ kind: "target", label, directory: realpathSync(path) });
126
+ entries.push({ kind: "target", label, directory: realpathSync(path), evaluation: isEvaluation(registration) });
124
127
  }
125
128
  catch {
126
129
  entries.push({ kind: "failure", label, diagnostic: `directory requires exactly one regular factory.ts or factory.js: ${JSON.stringify(path)}` });
@@ -4,11 +4,12 @@ import { AuthoringError } from "../../../domain/valueobjects/authoring-error.ts"
4
4
  import type { AuthoringVerb, AuthoringReason, AuthoringOrigin } from "../../../domain/valueobjects/authoring-error.ts";
5
5
  import type { ScaffoldArgs } from "../../../application/usecases/scaffold/index.ts";
6
6
  export type { FoundHandle, WritableHandle };
7
+ export type { GlobOptions } from "../../../domain/services/define-dialect.ts";
7
8
  export { AuthoringError };
8
9
  export type { AuthoringVerb, AuthoringReason, AuthoringOrigin };
9
10
  export { classifyContent } from "../../../domain/services/classify-content.ts";
10
11
  export type { ContentState } from "../../../domain/services/classify-content.ts";
11
- export { find, replaceContent, remove, rename, move, copy, pendingDirectives } from "../../../application/usecases/authoring-verbs/index.ts";
12
+ export { find, glob, replaceContent, remove, rename, move, copy, pendingDirectives } from "../../../application/usecases/authoring-verbs/index.ts";
12
13
  /**
13
14
  * Options for the `create` author verb.
14
15
  *
@@ -13,7 +13,7 @@ export { AuthoringError };
13
13
  // from the AuthoringError cluster above — no other component references it.
14
14
  export { classifyContent } from "../../../domain/services/classify-content.js";
15
15
  // The verbs that need no adapting are the use case's own functions.
16
- export { find, replaceContent, remove, rename, move, copy, pendingDirectives } from "../../../application/usecases/authoring-verbs/index.js";
16
+ export { find, glob, replaceContent, remove, rename, move, copy, pendingDirectives } from "../../../application/usecases/authoring-verbs/index.js";
17
17
  export function create(path, opts) {
18
18
  return verbs.create(path, opts, (options) => "templateFile" in opts ? readTemplateFile(opts.templateFile, path, options, opts.force) : opts.template);
19
19
  }
@@ -1,5 +1,5 @@
1
1
  import type { SourceFile } from "ts-morph";
2
- import { type Handle } from "../../../../domain/services/define-dialect.ts";
2
+ import { type GlobOptions, type Handle } from "../../../../domain/services/define-dialect.ts";
3
3
  import { typescriptOps } from "../typescript/pack.ts";
4
4
  import type { ArrayElement } from "../typescript/array-element.ts";
5
5
  import { type InjectionOptions, type InputOptions, type LazyRouteSpec, type NamedImport, type OutputOptions, type RouteSpec, type StateOptions } from "./ops.ts";
@@ -61,3 +61,16 @@ type AngularOps = {
61
61
  * // -> export const appConfig: ApplicationConfig = { providers: [provideRouter(routes), provideHttpClient(withFetch())] };
62
62
  */
63
63
  export declare function find(path: string): Handle<"found", SourceFile, AngularOps & typeof typescriptOps>;
64
+ /**
65
+ * Opens every file `pattern` matches that this dialect edits, ordered by path; a file of any
66
+ * other extension is left out without an error (A-132). Resolves `[]` when none matches. The
67
+ * pattern syntax and `ignore` are commons `glob`'s, and it sees the run as `find` does.
68
+ *
69
+ * @example
70
+ * import * as angular from "@pbuilder/sdk/angular";
71
+ *
72
+ * export const run = async () => {
73
+ * for (const file of await angular.glob("src/app/**\/*.ts")) await file.read();
74
+ * };
75
+ */
76
+ export declare function glob(pattern: string, options?: GlobOptions): Promise<Handle<"found", SourceFile, AngularOps & typeof typescriptOps>[]>;
@@ -66,3 +66,18 @@ const angularDialect = withOps(baseDialect, typescriptOps, angularOps);
66
66
  export function find(path) {
67
67
  return angularDialect.find(path);
68
68
  }
69
+ /**
70
+ * Opens every file `pattern` matches that this dialect edits, ordered by path; a file of any
71
+ * other extension is left out without an error (A-132). Resolves `[]` when none matches. The
72
+ * pattern syntax and `ignore` are commons `glob`'s, and it sees the run as `find` does.
73
+ *
74
+ * @example
75
+ * import * as angular from "@pbuilder/sdk/angular";
76
+ *
77
+ * export const run = async () => {
78
+ * for (const file of await angular.glob("src/app/**\/*.ts")) await file.read();
79
+ * };
80
+ */
81
+ export function glob(pattern, options) {
82
+ return angularDialect.glob(pattern, options);
83
+ }
@@ -1,4 +1,4 @@
1
- import { type Handle } from "../../../../domain/services/define-dialect.ts";
1
+ import { type GlobOptions, type Handle } from "../../../../domain/services/define-dialect.ts";
2
2
  import { type CsharpDocument } from "../csharp/ast.ts";
3
3
  import { type CsharpOps } from "../csharp/pack.ts";
4
4
  import { type Lifetime, type ServiceOptions } from "./ops.ts";
@@ -49,3 +49,16 @@ type AspnetOps = CsharpOps & ServiceOps;
49
49
  * // -> var app = builder.Build();
50
50
  */
51
51
  export declare function find(path: string): Handle<"found", CsharpDocument, AspnetOps>;
52
+ /**
53
+ * Opens every file `pattern` matches that this dialect edits, ordered by path; a file of any
54
+ * other extension is left out without an error (A-132). Resolves `[]` when none matches. The
55
+ * pattern syntax and `ignore` are commons `glob`'s, and it sees the run as `find` does.
56
+ *
57
+ * @example
58
+ * import * as aspnet from "@pbuilder/sdk/aspnet";
59
+ *
60
+ * export const run = async () => {
61
+ * for (const file of await aspnet.glob("src/**\/*.cs")) await file.read();
62
+ * };
63
+ */
64
+ export declare function glob(pattern: string, options?: GlobOptions): Promise<Handle<"found", CsharpDocument, AspnetOps>[]>;
@@ -47,3 +47,18 @@ const aspnetDialect = withOps(defineDialect({ extensions: [".cs"], ast: { parse,
47
47
  export function find(path) {
48
48
  return aspnetDialect.find(path);
49
49
  }
50
+ /**
51
+ * Opens every file `pattern` matches that this dialect edits, ordered by path; a file of any
52
+ * other extension is left out without an error (A-132). Resolves `[]` when none matches. The
53
+ * pattern syntax and `ignore` are commons `glob`'s, and it sees the run as `find` does.
54
+ *
55
+ * @example
56
+ * import * as aspnet from "@pbuilder/sdk/aspnet";
57
+ *
58
+ * export const run = async () => {
59
+ * for (const file of await aspnet.glob("src/**\/*.cs")) await file.read();
60
+ * };
61
+ */
62
+ export function glob(pattern, options) {
63
+ return aspnetDialect.glob(pattern, options);
64
+ }