@pbuilder/sdk 0.14.0 → 0.15.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 (207) hide show
  1. package/README.md +57 -42
  2. package/dist/{transport → acl/irwire}/frame-reader.d.ts +2 -0
  3. package/dist/{transport → acl/irwire}/frame-reader.js +57 -5
  4. package/dist/{transport → acl/irwire}/stdio-engine-client.d.ts +2 -2
  5. package/dist/{transport → acl/irwire}/stdio-engine-client.js +4 -4
  6. package/dist/bin/pbuilder-codegen.js +30 -35
  7. package/dist/bin/pbuilder-runner.js +6 -6
  8. package/dist/bounded-contexts/authoring/application/usecases/authoring-verbs/index.d.ts +106 -0
  9. package/dist/bounded-contexts/authoring/application/usecases/authoring-verbs/index.js +202 -0
  10. package/dist/{pending-directives → bounded-contexts/authoring/application/usecases/pending-directives}/render.d.ts +2 -2
  11. package/dist/{core → bounded-contexts/authoring/application/usecases/run-factory}/context.d.ts +12 -9
  12. package/dist/{core → bounded-contexts/authoring/application/usecases/run-factory}/context.js +59 -120
  13. package/dist/bounded-contexts/authoring/application/usecases/run-factory/driving.d.ts +5 -0
  14. package/dist/bounded-contexts/authoring/application/usecases/run-factory/driving.js +15 -0
  15. package/dist/bounded-contexts/authoring/application/usecases/scaffold/classify-transport.d.ts +51 -0
  16. package/dist/bounded-contexts/authoring/application/usecases/scaffold/classify-transport.js +105 -0
  17. package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/expander.d.ts +2 -1
  18. package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/expander.js +13 -7
  19. package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/index.d.ts +1 -1
  20. package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/index.js +7 -6
  21. package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/path-guards.d.ts +11 -10
  22. package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/path-guards.js +21 -48
  23. package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/walk.d.ts +2 -3
  24. package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/walk.js +37 -56
  25. package/dist/{core → bounded-contexts/authoring/domain/aggregates/session}/session.d.ts +2 -2
  26. package/dist/{core → bounded-contexts/authoring/domain/aggregates/session}/session.js +1 -1
  27. package/dist/{core → bounded-contexts/authoring/domain/entities}/dialect-handle.d.ts +1 -1
  28. package/dist/{core → bounded-contexts/authoring/domain/entities}/dialect-handle.js +10 -10
  29. package/dist/{core → bounded-contexts/authoring/domain/ports}/engine-client.d.ts +1 -1
  30. package/dist/bounded-contexts/authoring/domain/ports/package-files.d.ts +53 -0
  31. package/dist/bounded-contexts/authoring/domain/ports/package-files.js +11 -0
  32. package/dist/{core → bounded-contexts/authoring/domain/services}/define-dialect.d.ts +2 -2
  33. package/dist/{core → bounded-contexts/authoring/domain/services}/define-dialect.js +3 -3
  34. package/dist/{core → bounded-contexts/authoring/domain/services}/directive-factory.d.ts +2 -2
  35. package/dist/{core → bounded-contexts/authoring/domain/services}/directive-factory.js +37 -12
  36. package/dist/{scaffold → bounded-contexts/authoring/domain/services}/filename-pipeline.d.ts +7 -5
  37. package/dist/{scaffold → bounded-contexts/authoring/domain/services}/filename-pipeline.js +28 -8
  38. package/dist/{core/jsx-name-validator.d.ts → bounded-contexts/authoring/domain/services/identifier-names.d.ts} +8 -4
  39. package/dist/{core/jsx-name-validator.js → bounded-contexts/authoring/domain/services/identifier-names.js} +21 -28
  40. package/dist/bounded-contexts/authoring/domain/services/reject-tail.d.ts +9 -0
  41. package/dist/bounded-contexts/authoring/domain/services/reject-tail.js +30 -0
  42. package/dist/bounded-contexts/authoring/domain/services/run-context.d.ts +5 -0
  43. package/dist/bounded-contexts/authoring/domain/services/run-context.js +70 -0
  44. package/dist/{core → bounded-contexts/authoring/domain/services}/schema/input-rejection.d.ts +1 -1
  45. package/dist/{core → bounded-contexts/authoring/domain/services}/schema/input-rejection.js +1 -1
  46. package/dist/bounded-contexts/authoring/domain/services/schema/schema-files.d.ts +2 -0
  47. package/dist/bounded-contexts/authoring/domain/services/schema/schema-files.js +6 -0
  48. package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-locate.d.ts +2 -1
  49. package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-locate.js +13 -2
  50. package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-parse.d.ts +1 -1
  51. package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-parse.js +2 -14
  52. package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-sufficiency.d.ts +4 -3
  53. package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-sufficiency.js +8 -4
  54. package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-validate.d.ts +1 -1
  55. package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-validate.js +1 -1
  56. package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/authoring-error.js +1 -1
  57. package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/wire.d.ts +0 -3
  58. package/dist/bounded-contexts/authoring/domain/valueobjects/wire.js +28 -0
  59. package/dist/bounded-contexts/authoring/infrastructure/in/codegen/cli.d.ts +27 -0
  60. package/dist/bounded-contexts/authoring/infrastructure/in/codegen/cli.js +306 -0
  61. package/dist/bounded-contexts/authoring/infrastructure/in/codegen/emit-type.d.ts +7 -0
  62. package/dist/bounded-contexts/authoring/infrastructure/in/codegen/emit-type.js +68 -0
  63. package/dist/bounded-contexts/authoring/infrastructure/in/codegen/project-codegen.d.ts +19 -0
  64. package/dist/bounded-contexts/authoring/infrastructure/in/codegen/project-codegen.js +131 -0
  65. package/dist/bounded-contexts/authoring/infrastructure/in/commons/index.d.ts +182 -0
  66. package/dist/bounded-contexts/authoring/infrastructure/in/commons/index.js +94 -0
  67. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/angular/index.d.ts +63 -0
  68. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/angular/index.js +68 -0
  69. package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/angular/ops.js +9 -9
  70. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/css/index.d.ts +40 -0
  71. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/css/index.js +38 -0
  72. package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/css/ops.js +2 -2
  73. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/json/index.d.ts +55 -0
  74. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/json/index.js +54 -0
  75. package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/json/ops.d.ts +1 -1
  76. package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/json/ops.js +35 -8
  77. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/nestjs/index.d.ts +43 -0
  78. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/nestjs/index.js +46 -0
  79. package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/nestjs/ops.js +7 -7
  80. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/index.d.ts +52 -0
  81. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/index.js +73 -0
  82. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/jsx-names.d.ts +4 -0
  83. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/jsx-names.js +18 -0
  84. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/match-tails.d.ts +4 -0
  85. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/match-tails.js +25 -0
  86. package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/react/ops.js +5 -3
  87. package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/array-element.d.ts +7 -2
  88. package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/array-element.js +29 -15
  89. package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/ast.d.ts +5 -1
  90. package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/ast.js +22 -4
  91. package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/class-property.js +14 -19
  92. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/typescript/index.d.ts +53 -0
  93. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/typescript/index.js +37 -0
  94. package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/ops.d.ts +6 -1
  95. package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/ops.js +90 -54
  96. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/yaml/index.d.ts +69 -0
  97. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/yaml/index.js +70 -0
  98. package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/paths.d.ts +1 -1
  99. package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/paths.js +2 -2
  100. package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/presentation.js +1 -1
  101. package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/structural.js +2 -2
  102. package/dist/bounded-contexts/authoring/infrastructure/out/fs/package-files.d.ts +8 -0
  103. package/dist/bounded-contexts/authoring/infrastructure/out/fs/package-files.js +133 -0
  104. package/dist/bounded-contexts/authoring/testing/conformance/index.d.ts +157 -0
  105. package/dist/bounded-contexts/authoring/testing/conformance/index.js +261 -0
  106. package/dist/{testing → bounded-contexts/authoring/testing}/contract-fake.d.ts +2 -2
  107. package/dist/{testing → bounded-contexts/authoring/testing}/contract-fake.js +4 -3
  108. package/dist/bounded-contexts/authoring/testing/harness/index.d.ts +89 -0
  109. package/dist/bounded-contexts/authoring/testing/harness/index.js +85 -0
  110. package/dist/{conformance → bounded-contexts/authoring/testing}/run-vehicle.d.ts +1 -1
  111. package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/bootstrap-bridge.js +2 -2
  112. package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/exit-codes.js +5 -4
  113. package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/factory-pointer.js +1 -1
  114. package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/runner.d.ts +4 -0
  115. package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/runner.js +49 -23
  116. package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/single-instance-probe.js +1 -1
  117. package/dist/commons/index.d.ts +1 -278
  118. package/dist/commons/index.js +1 -286
  119. package/dist/conformance/index.d.ts +1 -157
  120. package/dist/conformance/index.js +1 -261
  121. package/dist/dialects/angular/index.d.ts +1 -63
  122. package/dist/dialects/angular/index.js +1 -68
  123. package/dist/dialects/css/index.d.ts +1 -40
  124. package/dist/dialects/css/index.js +1 -38
  125. package/dist/dialects/json/index.d.ts +1 -55
  126. package/dist/dialects/json/index.js +1 -54
  127. package/dist/dialects/nestjs/index.d.ts +1 -43
  128. package/dist/dialects/nestjs/index.js +1 -46
  129. package/dist/dialects/react/index.d.ts +1 -52
  130. package/dist/dialects/react/index.js +1 -73
  131. package/dist/dialects/typescript/index.d.ts +1 -53
  132. package/dist/dialects/typescript/index.js +1 -37
  133. package/dist/dialects/yaml/index.d.ts +1 -69
  134. package/dist/dialects/yaml/index.js +1 -70
  135. package/dist/{core → platform}/deep-equal.js +2 -2
  136. package/dist/{transport → platform}/error-text.js +2 -2
  137. package/dist/runner-manifest.json +66 -46
  138. package/dist/shared-kernel/batch-cap.d.ts +4 -0
  139. package/dist/{core/wire.js → shared-kernel/batch-cap.js} +9 -26
  140. package/dist/{transport → shared-kernel}/framing.js +2 -2
  141. package/dist/{transport → shared-kernel}/wire-protocol.js +1 -1
  142. package/dist/testing/index.d.ts +1 -84
  143. package/dist/testing/index.js +1 -82
  144. package/package.json +9 -3
  145. package/dist/core/index.d.ts +0 -10
  146. package/dist/core/index.js +0 -6
  147. package/dist/core/reject-tail.d.ts +0 -13
  148. package/dist/core/reject-tail.js +0 -52
  149. package/dist/core/schema/schema-discovery.d.ts +0 -13
  150. package/dist/core/schema/schema-discovery.js +0 -51
  151. package/dist/scaffold/classify-transport.d.ts +0 -54
  152. package/dist/scaffold/classify-transport.js +0 -119
  153. /package/dist/{pending-directives → bounded-contexts/authoring/application/usecases/pending-directives}/index.d.ts +0 -0
  154. /package/dist/{pending-directives → bounded-contexts/authoring/application/usecases/pending-directives}/index.js +0 -0
  155. /package/dist/{pending-directives → bounded-contexts/authoring/application/usecases/pending-directives}/render.js +0 -0
  156. /package/dist/{core → bounded-contexts/authoring/domain/entities}/base-handle.d.ts +0 -0
  157. /package/dist/{core → bounded-contexts/authoring/domain/entities}/base-handle.js +0 -0
  158. /package/dist/{core → bounded-contexts/authoring/domain/entities}/handle-state.d.ts +0 -0
  159. /package/dist/{core → bounded-contexts/authoring/domain/entities}/handle-state.js +0 -0
  160. /package/dist/{core → bounded-contexts/authoring/domain/ports}/emit-rejection.d.ts +0 -0
  161. /package/dist/{core → bounded-contexts/authoring/domain/ports}/emit-rejection.js +0 -0
  162. /package/dist/{core → bounded-contexts/authoring/domain/ports}/engine-client.js +0 -0
  163. /package/dist/{commons → bounded-contexts/authoring/domain/services}/classify-content.d.ts +0 -0
  164. /package/dist/{commons → bounded-contexts/authoring/domain/services}/classify-content.js +0 -0
  165. /package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-digest.d.ts +0 -0
  166. /package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-digest.js +0 -0
  167. /package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/authoring-error.d.ts +0 -0
  168. /package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/dialect-error.d.ts +0 -0
  169. /package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/dialect-error.js +0 -0
  170. /package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/json-value.d.ts +0 -0
  171. /package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/json-value.js +0 -0
  172. /package/dist/{core/schema → bounded-contexts/authoring/domain/valueobjects}/schema-model.d.ts +0 -0
  173. /package/dist/{core/schema → bounded-contexts/authoring/domain/valueobjects}/schema-model.js +0 -0
  174. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/angular/ops.d.ts +0 -0
  175. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/css/ast.d.ts +0 -0
  176. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/css/ast.js +0 -0
  177. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/css/ops.d.ts +0 -0
  178. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/json/ast.d.ts +0 -0
  179. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/json/ast.js +0 -0
  180. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/nestjs/ops.d.ts +0 -0
  181. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/react/ast.d.ts +0 -0
  182. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/react/ast.js +0 -0
  183. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/react/ops.d.ts +0 -0
  184. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/class-property.d.ts +0 -0
  185. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/import-order.d.ts +0 -0
  186. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/import-order.js +0 -0
  187. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/pack.d.ts +0 -0
  188. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/pack.js +0 -0
  189. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/ast.d.ts +0 -0
  190. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/ast.js +0 -0
  191. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/documents.d.ts +0 -0
  192. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/documents.js +0 -0
  193. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/presentation.d.ts +0 -0
  194. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/structural.d.ts +0 -0
  195. /package/dist/{testing → bounded-contexts/authoring/testing}/rejection-messages.d.ts +0 -0
  196. /package/dist/{testing → bounded-contexts/authoring/testing}/rejection-messages.js +0 -0
  197. /package/dist/{conformance → bounded-contexts/authoring/testing}/run-vehicle.js +0 -0
  198. /package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/bootstrap-bridge.d.ts +0 -0
  199. /package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/exit-codes.d.ts +0 -0
  200. /package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/factory-pointer.d.ts +0 -0
  201. /package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/single-instance-probe.d.ts +0 -0
  202. /package/dist/{core → platform}/deep-equal.d.ts +0 -0
  203. /package/dist/{transport → platform}/error-text.d.ts +0 -0
  204. /package/dist/{core → platform}/fs-errors.d.ts +0 -0
  205. /package/dist/{core → platform}/fs-errors.js +0 -0
  206. /package/dist/{transport → shared-kernel}/framing.d.ts +0 -0
  207. /package/dist/{transport → shared-kernel}/wire-protocol.d.ts +0 -0
@@ -1,4 +1,4 @@
1
- // The runner composition root (design § 4.2, ADR-01): lives in src/transport/ — NOT bin/ —
1
+ // The runner composition root (design § 4.2, ADR-01): lives in src/bounded-contexts/runner-hosting/infrastructure/in/ — NOT bin/ —
2
2
  // so BOTH entry paths (argv spawn via src/bin/pbuilder-runner.ts, in-process bridge in S-003)
3
3
  // share this ONE validation-gate chokepoint (FIT-15 bars src/->bin/ imports).
4
4
  //
@@ -23,17 +23,19 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
23
23
  import { dirname } from "node:path";
24
24
  import { fileURLToPath } from "node:url";
25
25
  import { readFileSync, statSync } from "node:fs";
26
- import { defineFactory } from "../core/context.js";
27
- import { AuthoringError } from "../core/authoring-error.js";
28
- import { locateFirstJsonSyntaxError } from "../core/schema/schema-locate.js";
29
- import { formatLocator } from "../core/schema/schema-parse.js";
30
- import { FrameReader, FrameFault } from "./frame-reader.js";
31
- import { WIRE_PROTOCOL_VERSION, isStructurallyValidGreeting, versionMatches } from "./wire-protocol.js";
32
- import { StdioEngineClient, TransportFault, IntentRejectedError, OverlappingRunError, } from "./stdio-engine-client.js";
33
- import { boundMessage, composeWithToken, scrubAbsolutePaths, toProjectRelativePath } from "./error-text.js";
26
+ import { defineFactory } from "../../../authoring/application/usecases/run-factory/context.js";
27
+ import { authoringOrigin, describeJsonSyntaxError } from "../../../authoring/application/usecases/run-factory/driving.js";
28
+ import { FrameReader, FrameFault } from "../../../../acl/irwire/frame-reader.js";
29
+ import { WIRE_PROTOCOL_VERSION, isStructurallyValidGreeting, versionMatches } from "../../../../shared-kernel/wire-protocol.js";
30
+ import { StdioEngineClient, TransportFault, IntentRejectedError, OverlappingRunError, } from "../../../../acl/irwire/stdio-engine-client.js";
31
+ import { boundMessage, composeWithToken, scrubAbsolutePaths, toProjectRelativePath } from "../../../../platform/error-text.js";
34
32
  import { parseFactoryPointer, validateFactoryUrl, resolveFactoryExport } from "./factory-pointer.js";
35
33
  import { probeSingleInstance } from "./single-instance-probe.js";
36
34
  import { classifyExitCode } from "./exit-codes.js";
35
+ import { nodePackageFiles } from "../../../authoring/infrastructure/out/fs/package-files.js";
36
+ /** The greeting's own bound: the client's per-call timeout only exists once the greeting is in. */
37
+ export const GREETING_TIMEOUT_MS = 30_000;
38
+ const GREETING_TIMED_OUT = Symbol("greeting timed out");
37
39
  // REQ-RUN-04: the SDK-chosen input-file size cap — same provenance posture as SEC-05's
38
40
  // timeout bound and WPS-06's BATCH_CAP_BYTES (pending engine-side confirmation).
39
41
  export const INPUT_FILE_SIZE_CAP_BYTES = 10 * 1024 * 1024; // 10 MiB
@@ -76,7 +78,7 @@ function parseArgv(argv) {
76
78
  }
77
79
  // REQ-RUN-04: size-cap check BEFORE reading contents; fail-closed on any JSON parse error,
78
80
  // reporting ONLY the parse failure's line/column (never raw file content — mirrors
79
- // `formatParseError`, bin/pbuilder-codegen.ts:126).
81
+ // the codegen adapter's `formatParseError`).
80
82
  function resolveInput(input) {
81
83
  if (input.kind === "inline") {
82
84
  try {
@@ -119,11 +121,7 @@ function resolveInput(input) {
119
121
  return { ok: true, value: JSON.parse(raw) };
120
122
  }
121
123
  catch {
122
- const locator = locateFirstJsonSyntaxError(raw);
123
- return {
124
- ok: false,
125
- message: `pbuilder-runner: --input-file is not valid JSON ${formatLocator(locator?.line, locator?.column)}`,
126
- };
124
+ return { ok: false, message: `pbuilder-runner: --input-file is not valid JSON ${describeJsonSyntaxError(raw)}` };
127
125
  }
128
126
  }
129
127
  // REQ-RUN-07: classifies a factory-module `import()` failure into RUN-07's form 1 — the
@@ -178,14 +176,17 @@ export async function runRunner(argv, io) {
178
176
  throw new OverlappingRunError("pbuilder-runner: a run is already in flight in this process — overlapping run rejected");
179
177
  }
180
178
  runInFlight = true;
179
+ const opened = {};
181
180
  try {
182
- return await runRunnerBody(argv, io);
181
+ return await runRunnerBody(argv, io, opened);
183
182
  }
184
183
  finally {
184
+ // A read still parked when the run ends must not take the bytes of a later run (#167).
185
+ opened.reader?.close();
185
186
  runInFlight = false;
186
187
  }
187
188
  }
188
- async function runRunnerBody(argv, io) {
189
+ async function runRunnerBody(argv, io, opened) {
189
190
  const parsed = parseArgv(argv);
190
191
  if ("error" in parsed) {
191
192
  note(io, parsed.error);
@@ -203,26 +204,50 @@ async function runRunnerBody(argv, io) {
203
204
  return 1;
204
205
  }
205
206
  const reader = new FrameReader(io.input);
207
+ opened.reader = reader;
206
208
  const frames = reader.frames();
207
209
  // WPS-02: fail at greeting, BEFORE any reverse callback can dispatch — the client is not
208
210
  // even constructed until the greeting is accepted. A TRANSPORT fault at greeting time
209
211
  // (judgment-day F4) — an oversize/0x80000000 length prefix (thrown, WPS-04.2/.4), EOF
210
212
  // mid-frame (thrown), or a malformed greeting body (yielded as a FrameFault) — classifies
211
213
  // exit 3 with a bounded note (EXC-01, WPS-07), never an uncaught rejection's raw stack.
212
- // A clean EOF or a structurally-wrong-but-valid frame stays exit 1 (WPS-02.3).
214
+ // A structurally-wrong-but-valid frame stays exit 1 (WPS-02.3); a clean EOF before any frame
215
+ // is the host gone (exit 3, below).
216
+ // A host that never greets, or that is gone before it greets, is a transport fault (exit 3).
217
+ // These two notes are plain stderr, never the `pbuilder-runner: ` sentinel: the engine gives
218
+ // a sentinel note precedence over the exit code and would read them as a developer error.
219
+ const greetingTimeoutMs = io.greetingTimeoutMs ?? GREETING_TIMEOUT_MS;
213
220
  let first;
221
+ let timer;
214
222
  try {
215
- first = await frames.next();
223
+ first = await Promise.race([
224
+ frames.next(),
225
+ new Promise((resolve) => {
226
+ timer = setTimeout(() => resolve(GREETING_TIMED_OUT), greetingTimeoutMs);
227
+ }),
228
+ ]);
216
229
  }
217
230
  catch (err) {
218
231
  note(io, `pbuilder-runner: ${err instanceof TransportFault ? err.message : "transport fault while awaiting the greeting"}`);
219
232
  return classifyExitCode(err);
220
233
  }
221
- if (!first.done && first.value instanceof FrameFault) {
234
+ finally {
235
+ clearTimeout(timer);
236
+ }
237
+ if (first === GREETING_TIMED_OUT) {
238
+ note(io, `the host never sent {method:"ready"} within ${greetingTimeoutMs} ms; check that the engine started the runner ` +
239
+ "with the expected protocol and is not blocked");
240
+ return 3;
241
+ }
242
+ if (first.done) {
243
+ note(io, 'the host closed stdin before sending {method:"ready"}; the engine process probably exited or crashed, see its log');
244
+ return 3;
245
+ }
246
+ if (first.value instanceof FrameFault) {
222
247
  note(io, `pbuilder-runner: ${first.value.fault.message}`);
223
248
  return classifyExitCode(first.value.fault);
224
249
  }
225
- if (first.done || !isStructurallyValidGreeting(first.value)) {
250
+ if (!isStructurallyValidGreeting(first.value)) {
226
251
  note(io, `pbuilder-runner: invalid greeting — expected {method:"ready", protocolVersion:<integer>}`);
227
252
  return 1;
228
253
  }
@@ -274,7 +299,7 @@ async function runRunnerBody(argv, io) {
274
299
  // the factory's own directory — schema-derived validation and reserved-name checks apply
275
300
  // identically on both vehicles.
276
301
  const packageDir = dirname(fileURLToPath(new URL(moduleUrl)));
277
- const run = defineFactory(exportResolution.fn, { packageDir });
302
+ const run = defineFactory(exportResolution.fn, { packageDir, packageFiles: nodePackageFiles });
278
303
  const channel = {
279
304
  write: io.writeFrame,
280
305
  writeStderr: io.writeStderr,
@@ -302,7 +327,8 @@ async function runRunnerBody(argv, io) {
302
327
  // (context.ts's discard-after-throw path) never overrides E1's class. IntentRejectedError
303
328
  // (judgment-day F3): the host's refusal message surfaces — bounded by note() — instead
304
329
  // of being swallowed into a generic "run failed".
305
- const label = err instanceof AuthoringError || err instanceof TransportFault || err instanceof IntentRejectedError
330
+ const label = err instanceof Error &&
331
+ (authoringOrigin(err) !== undefined || err instanceof TransportFault || err instanceof IntentRejectedError)
306
332
  ? err.message
307
333
  : err instanceof Error
308
334
  ? scrubAbsolutePaths(err.message)
@@ -31,7 +31,7 @@ import { existsSync, realpathSync } from "node:fs";
31
31
  import { createRequire } from "node:module";
32
32
  import { fileURLToPath } from "node:url";
33
33
  import { dirname, join } from "node:path";
34
- import { toProjectRelativePath } from "./error-text.js";
34
+ import { toProjectRelativePath } from "../../../../platform/error-text.js";
35
35
  const SDK_SPECIFIER = "@pbuilder/sdk";
36
36
  // Resolution-only: never `import()`s the target, only locates it.
37
37
  function resolveSpecifierPath(specifier, anchorUrl) {
@@ -1,278 +1 @@
1
- import type { JsonValue } from "../core/wire.ts";
2
- import type { FoundHandle, WritableHandle } from "../core/handle-state.ts";
3
- import { AuthoringError } from "../core/authoring-error.ts";
4
- import type { AuthoringVerb, AuthoringReason, AuthoringOrigin } from "../core/authoring-error.ts";
5
- import type { ScaffoldArgs } from "../scaffold/index.ts";
6
- export type { FoundHandle, WritableHandle };
7
- export { AuthoringError };
8
- export type { AuthoringVerb, AuthoringReason, AuthoringOrigin };
9
- export { classifyContent } from "./classify-content.ts";
10
- export type { ContentState } from "./classify-content.ts";
11
- /**
12
- * Options for the `create` author verb.
13
- *
14
- * @example
15
- * const opts: CreateOptions = {
16
- * template: "export const {= .name =} = '{= .value =}';",
17
- * options: { name: "greeting", value: "hello" },
18
- * };
19
- */
20
- export interface CreateOptions {
21
- template: string;
22
- options: JsonValue;
23
- force?: boolean;
24
- }
25
- /**
26
- * Options for the `create({ templateFile })` render request — an explicit, package-local
27
- * alternative to an inline `template` string (REQ-FEH-01). `templateFile` is a
28
- * package-relative path (resolved against the active Session's `packageDir`), read at
29
- * emission time; its content becomes the `create` directive's `template` field —
30
- * the existing `create` IR, zero wire change. `templateFile` REQUESTS a render: a binary
31
- * or oversized source fails loud (`invalid-input`), it never silently falls back to a
32
- * by-reference copy (REQ-FEH-02).
33
- *
34
- * @example
35
- * const opts: CreateFromTemplateFileOptions = {
36
- * templateFile: "tpl.ts.template",
37
- * options: { name: "greeting" },
38
- * };
39
- */
40
- export interface CreateFromTemplateFileOptions {
41
- templateFile: string;
42
- options: JsonValue;
43
- force?: boolean;
44
- }
45
- /**
46
- * Locates an existing file and returns a `FoundHandle` for reading or removing it.
47
- *
48
- * `read()` resolves `string | undefined`: the content, `undefined` when the path does not
49
- * exist, or `""` when the file exists but is empty. Branch on the three outcomes with strict
50
- * `=== undefined` / `=== ""` — NEVER `if (!content)`, which would merge `undefined`, `""`,
51
- * `"0"` and `"false"` and reintroduce the absent-vs-empty bug. Prefer `classifyContent()`
52
- * over manual comparisons — it names the trichotomy and gives exhaustive-switch parity.
53
- *
54
- * @example
55
- * const c = await find("src/config.ts").read();
56
- * if (c === undefined) create("src/config.ts", { template, options });
57
- * else if (c === "") replaceContent("src/config.ts", seedContent);
58
- * else replaceContent("src/config.ts", patch(c));
59
- */
60
- export declare function find(path: string): FoundHandle;
61
- /**
62
- * Schedules a file-creation directive and returns a `WritableHandle` for chaining.
63
- * The file is written when the session flushes — on the next `read()` call (REQ-KIT-02)
64
- * or at run end (REQ-KIT-05). A factory that never calls `read()` still emits all
65
- * buffered directives when the runner resolves.
66
- *
67
- * SEAM-01 (REQ-01): a generic type parameter `S` narrows `options` from the bare
68
- * `JsonValue` to the schema's keys at the type level only — the runtime body is unchanged.
69
- *
70
- * Creating over an existing file is rejected at the engine seam unless
71
- * `{ force: true }` is passed (overwrite-on-collision, ADR-0017 fail-closed) — a
72
- * rejected Session throws `AuthoringError`.
73
- *
74
- * `templateFile` is a THIRD overload (REQ-FEH-01): pass a package-local path instead of an
75
- * inline `template` string — its content is read at emission time and becomes the
76
- * directive's `template` field. `template` and `templateFile` are mutually exclusive forms;
77
- * only usable inside a factory invocation started with packageDir (there is no resolution anchor
78
- * to read a package-local file against otherwise — `invalid-input`, never a cwd fallback).
79
- * `templateFile`'s VALUE is a literal package-relative path, read verbatim by CONTENT —
80
- * it is NOT run through `scaffold`'s filename pipeline (no rename remap, no `__x__` token
81
- * translation, no `.template`-suffix strip applied to the path itself); this is an
82
- * explicit REQUEST to render one named file, unlike `scaffold`'s per-entry filename
83
- * processing. Because `templateFile` REQUESTS a render, it has no silent by-reference
84
- * fallback (REQ-FEH-02): a binary file (a null byte or invalid UTF-8 anywhere in the
85
- * whole file) or a file too large to render inline (over the 4 MiB limit) both reject
86
- * fail-loud with reason `invalid-input` — never a silent copy.
87
- *
88
- * @example
89
- * create("src/index.ts", {
90
- * template: "export const version = '{= .version =}';",
91
- * options: { version: "1.0.0" },
92
- * });
93
- * @example
94
- * create("src/index.ts", {
95
- * templateFile: "index.ts.template",
96
- * options: { version: "1.0.0" },
97
- * });
98
- */
99
- export declare function create<S>(path: string, opts: {
100
- template: string;
101
- options: {
102
- [K in keyof S]: S[K];
103
- };
104
- force?: boolean;
105
- }): WritableHandle;
106
- export declare function create(path: string, opts: CreateOptions): WritableHandle;
107
- export declare function create(path: string, opts: CreateFromTemplateFileOptions): WritableHandle;
108
- /**
109
- * Author-facing options for the `scaffold` verb — walks a package-local folder and mirrors
110
- * it into the target tree. `from`/`to` are mandatory. `options` defaults `{}`, `include`
111
- * defaults to matching everything, `exclude` defaults to matching nothing (`exclude` wins
112
- * on overlap), `rename` defaults to no remap, `force` defaults `false`.
113
- *
114
- * @example
115
- * const opts: ScaffoldOptions = {
116
- * from: "files",
117
- * to: "src/generated",
118
- * options: { name: "Widget" },
119
- * exclude: ["*.spec.ts"],
120
- * };
121
- */
122
- export type ScaffoldOptions = ScaffoldArgs;
123
- /**
124
- * Walks a package-local folder (`from`, resolved against the active Session's `packageDir`)
125
- * and mirrors every entry into `to`, applying the rename → filename-token-translation →
126
- * `.template`-strip pipeline (REQ-FSC-05) and include/exclude glob filtering (REQ-FSC-03,
127
- * `exclude` wins on overlap). Each source classifies by-value or by-reference
128
- * (`content-classification`, entirely sniffed — never author-declared); by-value sources
129
- * emit a `create` directive through the existing IR. A `from` folder with zero entries
130
- * no-ops silently; `include`/`exclude` eliminating every entry rejects fail-loud, naming
131
- * the filters (REQ-FSC-04 — two distinct outcomes, never collapsed). `force` (default
132
- * `false`) passes through unchanged to every emitted directive, no per-file override
133
- * (REQ-FSC-06). Two or more sources collapsing to the same destination reject fail-loud,
134
- * naming every offending source (REQ-FSC-08). Only usable inside a
135
- * factory invocation started with packageDir — there is no resolution anchor to walk a
136
- * package-local folder against otherwise (`invalid-input`, never a cwd fallback).
137
- *
138
- * `rename` is a static REMAP TABLE (`Record<originalSourceRelativePath,
139
- * newDestinationRelativePath>`), matched against the ORIGINAL (pre-token-translation)
140
- * source path — distinct from the `rename()` verb, which renames one already-targeted
141
- * file's basename at emit time, not a folder-walk's per-entry destination.
142
- *
143
- * A NESTED symlinked directory is never descended, regardless of where its target
144
- * resolves — skipped silently, no error; enumeration determinism and cycle-safety are the
145
- * rationale (a symlinked directory could point anywhere, including into a cycle — never
146
- * descending is the simplest invariant that is safe under all targets, REQ-FSC-09). The
147
- * walk ROOT (`from` itself) is held to a stricter standard: a symlinked root REJECTS
148
- * (`invalid-input`) rather than being followed or silently skipped (owner ruling 16) — but
149
- * this check inspects only `from`'s FINAL path component; a symlink at a MID-path segment
150
- * (e.g. `from: "link/sub"`) is not detected and the walk proceeds through it, the same
151
- * documented residual SECURITY.md covers for `create`/`copyIn` reads. The walk is capped
152
- * at 10,000 enumerated entries per call, failing loud and naming the bound past that
153
- * (REQ-FSC-09) — a loop-safety/DoS resource guard no real schematic collection should
154
- * approach.
155
- *
156
- * **Packaging caveat**: the empty-folder no-op (above) depends on `from` existing ON
157
- * DISK at run time — npm tarball packaging commonly DROPS empty directories, so an
158
- * empty `from` folder that relies on this no-op may not survive `npm publish` at all
159
- * (REQ-FSC-04). Ship at least a placeholder file if the folder's presence matters.
160
- *
161
- * Returns `void` (REQ-FSC-07) — fire-and-forget, no chainable handle group.
162
- *
163
- * @example
164
- * scaffold({ from: "files", to: "src/generated", options: { name: "Widget" } });
165
- */
166
- export declare function scaffold(args: ScaffoldOptions): void;
167
- /**
168
- * Emits a by-reference copy of ONE package-local file (`from`, resolved against the active
169
- * run's `packageDir`) to `to` — ALWAYS by-reference, NEVER classified or rendered
170
- * (REQ-FEH-03), regardless of the source's own text-vs-binary shape: a text asset
171
- * containing `{= =}`-like sequences (that `scaffold` would otherwise render as tokens)
172
- * travels verbatim — the documented escape from `scaffold`'s by-value classification
173
- * (`content-classification` REQ-CCL-04). Contrast with tree→tree `copy`: `copyIn`'s source
174
- * is a PACKAGE-LOCAL path read at emission time, not an existing tree entry.
175
- *
176
- * `from`/`to` are mandatory; `force` defaults `false`. A missing `from`/`to` rejects
177
- * fail-loud before any emission (REQ-FEH-04.1/.2). Collision without `force` rejects;
178
- * `force: true` overwrites (`by-reference-copy-wire` REQ-BRC-05). Only usable inside a
179
- * factory invocation started with packageDir — there is no resolution anchor to read a
180
- * package-local file against otherwise (`invalid-input`, never a cwd fallback).
181
- *
182
- * Returns `void` (REQ-FEH-04.3) — NOT a `WritableHandle`, unlike `copy`: a by-reference
183
- * destination's bytes exist only after the ENGINE applies the directive (the fake never
184
- * materializes them, `author-test-harness` REQ-ATH-15) — a handle chaining over tree
185
- * CONTENT would lie about content that was never staged. This asymmetry with `copy`
186
- * (which DOES stage tree→tree content the fake can chain over) is deliberate.
187
- *
188
- * @example
189
- * copyIn("assets/logo.svg", "src/generated/logo.svg");
190
- */
191
- export declare function copyIn(from: string, to: string, opts?: {
192
- force?: boolean;
193
- }): void;
194
- /**
195
- * Schedules an in-place content replacement for an existing file and returns a `WritableHandle`.
196
- * A rejected Session (e.g. the target does not exist) throws `AuthoringError`.
197
- *
198
- * @example
199
- * replaceContent("src/config.json", '{ "version": "2.0.0" }');
200
- */
201
- export declare function replaceContent(path: string, content: string): WritableHandle;
202
- /**
203
- * Schedules a file deletion. Idempotent — deleting an absent file is not an error.
204
- *
205
- * @example
206
- * remove("src/legacy.ts");
207
- */
208
- export declare function remove(path: string): void;
209
- /**
210
- * Schedules a file rename (basename only) and returns a `WritableHandle` for the new path.
211
- * Renaming onto an existing path is rejected at the engine seam unless
212
- * `{ force: true }` is passed (overwrite-on-collision, ADR-0017 fail-closed) — a
213
- * rejected Session throws `AuthoringError`.
214
- *
215
- * @example
216
- * rename("src/foo.ts", "bar.ts");
217
- */
218
- export declare function rename(path: string, newName: string, opts?: {
219
- force?: boolean;
220
- }): WritableHandle;
221
- /**
222
- * Schedules a file move to a different directory and returns a `WritableHandle`.
223
- * Moving onto an existing destination is rejected at the engine seam unless
224
- * `{ force: true }` is passed (overwrite-on-collision, ADR-0017 fail-closed) — a
225
- * rejected Session throws `AuthoringError`.
226
- * A move whose destination equals its source is a no-op, never a collision
227
- * (ADR-0017 self-move amendment).
228
- *
229
- * @example
230
- * move("src/utils/helper.ts", "src/shared");
231
- */
232
- export declare function move(path: string, toDir: string, opts?: {
233
- force?: boolean;
234
- }): WritableHandle;
235
- /**
236
- * Schedules a file copy to a new path and returns a `WritableHandle` for the destination.
237
- * Copying onto an existing destination is rejected at the engine seam unless
238
- * `{ force: true }` is passed (overwrite-on-collision, ADR-0017 fail-closed) — a
239
- * rejected Session throws `AuthoringError`.
240
- *
241
- * @example
242
- * copy("src/template.ts", "src/generated/output.ts");
243
- */
244
- export declare function copy(from: string, to: string, opts?: {
245
- force?: boolean;
246
- }): WritableHandle;
247
- import type { PendingDirective } from "../pending-directives/render.ts";
248
- export type { PendingDirective };
249
- /**
250
- * Returns the Directives still pending in the active Session's buffer, rendered in
251
- * author vocabulary.
252
- *
253
- * Only what is still pending appears — the honest answer to "what will this Session
254
- * still emit", not "what has this Session emitted in total." A `read()` (or any flush)
255
- * drains the pending buffer, so Directives already sent no longer appear.
256
- *
257
- * Entries carry verb and path — no content or byte preview — plus an optional `kind`
258
- * (`"rendered" | "copied"`) present only on the package-local-read verbs whose transport
259
- * is classified: `create` (inline or `templateFile`, `kind: "rendered"`) and `copyIn`
260
- * (`kind: "copied"`). The tree→tree `copy` verb also materializes content but predates
261
- * this axis and is never package-local-read/classified, so it carries no `kind`.
262
- *
263
- * Call it inside an active factory invocation, like every other `./commons` verb.
264
- *
265
- * @example
266
- * const run = () => {
267
- * create("src/index.ts", { template: "export const version = '1.0.0';", options: {} });
268
- * find("src/legacy.ts").remove();
269
- * for (const entry of pendingDirectives()) {
270
- * console.log(entry.verb, entry.path); // "create src/index.ts", then "remove src/legacy.ts"
271
- * }
272
- * };
273
- *
274
- * @throws When called outside an active factory invocation, propagates the standard
275
- * error — authoring verbs "can only be used while a schematic is running" (ADR-0026: the
276
- * message no longer enumerates individual verbs, so it covers `pendingDirectives` too).
277
- */
278
- export declare function pendingDirectives(): PendingDirective[];
1
+ export * from "../bounded-contexts/authoring/infrastructure/in/commons/index.ts";