@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,27 +1,17 @@
1
- // ADR-0001 / ADR-0013: SDK↔engine wire contract (adopts engine ADR-0028 directive shapes).
2
- // The SDK emits these shapes over JSON; the engine deserialises them. Types are opaque to
3
- // the template DSL — SDK treats template/pathTemplate as uninterpreted strings.
1
+ // The engine's byte cap on one IR batch and the frame budget derived from it, shared by the
2
+ // runner bootstrap and Authoring's engine client. Kept free of any context's types: the cap
3
+ // is compared on byte counts only.
4
4
  // ADR-0019: 4 MiB cap on Buffer.byteLength(JSON.stringify(batch), 'utf8') — the fake
5
5
  // (engine stand-in) enforces this at emit, never the SDK (ADR-0018). Provenance: an
6
6
  // SDK-chosen placeholder, not engine-confirmed; cheap to change until the Stage 6
7
7
  // semver freeze.
8
8
  export const BATCH_CAP_BYTES = 4 * 1024 * 1024;
9
- // REQ-WPS-04 / fit-32 (cap-single-source, stdio-engine-client change): the UTF-8 serialized
10
- // byte length of a full Batch envelope — the one measurer both `serializedBatchSize` (below)
11
- // and `exceedsBatchCap`'s outbound leg consume, so the envelope shape can never drift.
12
- export function serializedBatchBytes(batch) {
13
- return Buffer.byteLength(JSON.stringify(batch), "utf8");
14
- }
15
- // The one shared measurer of what `instructions` serialize to inside the wire envelope —
16
- // the SAME shape `Session.flush` emits and the fake's `emit` cap check measures
17
- // (ADR-0018/0019). The expander's chunk heuristic and the batch-cap tests both consume
18
- // this so the envelope shape can never drift between them.
19
- export function serializedBatchSize(instructions) {
20
- const batch = { protocolVersion: 1, force: false, instructions: [...instructions] };
21
- return serializedBatchBytes(batch);
22
- }
23
- export function exceedsBatchCap(subject) {
24
- const bytes = typeof subject === "number" ? subject : serializedBatchBytes(subject);
9
+ // REQ-WPS-04 / fit-32 (cap-single-source): the ONE `> BATCH_CAP_BYTES` comparison in the
10
+ // whole codebase. Both legs measure bytes: the OUTBOUND leg (a serialized Batch plus the
11
+ // frame-envelope allowance, measured in `wire.ts`) and the INBOUND leg (a raw declared length
12
+ // prefix read off the wire before the body is even buffered). `> BATCH_CAP_BYTES`, never `>=`
13
+ // (a size exactly at the cap is WITHIN it, REQ-WPS-04.3).
14
+ export function exceedsBatchCap(bytes) {
25
15
  return bytes > BATCH_CAP_BYTES;
26
16
  }
27
17
  // REQ-WPS-04.1 (spec V4, judgment-day R2): the outbound cap is enforced on the ENCODED
@@ -40,10 +30,3 @@ export const EMIT_FRAME_ENVELOPE_ALLOWANCE_BYTES = Buffer.byteLength(JSON.string
40
30
  // The author-visible outbound batch budget: the largest serialized Batch that is
41
31
  // GUARANTEED to fit an ir.emit frame body within BATCH_CAP_BYTES for any request id.
42
32
  export const EMIT_BATCH_BUDGET_BYTES = BATCH_CAP_BYTES - EMIT_FRAME_ENVELOPE_ALLOWANCE_BYTES;
43
- // The ONE outbound-leg measurer (fit-32 cap-single-source): both `ContractFake.emit` (the
44
- // engine stand-in) and `StdioEngineClient.emit` (the real transport) route through this,
45
- // so the two can never diverge on an accept/reject verdict for the same batch. `>` via
46
- // `exceedsBatchCap`, never a re-derived comparison: exactly-at-budget is WITHIN the budget.
47
- export function exceedsEmitBatchBudget(batch) {
48
- return exceedsBatchCap(serializedBatchBytes(batch) + EMIT_FRAME_ENVELOPE_ALLOWANCE_BYTES);
49
- }
@@ -2,7 +2,7 @@
2
2
  // UTF-8 JSON body, symmetric in both directions (host<->runner). fit-31 (single-owner-of-
3
3
  // framing) guards that no other module re-implements this codec.
4
4
  import { Console } from "node:console";
5
- import { exceedsBatchCap } from "../core/wire.js";
5
+ import { exceedsBatchCap } from "./batch-cap.js";
6
6
  export const LENGTH_PREFIX_BYTES = 4;
7
7
  // REQ-WPS-04.1 (owner ruling R2): the outbound cap is enforced on the ENCODED FRAME BODY, so
8
8
  // the emitting client must serialize the frame value BEFORE the writer does. To keep that a
@@ -45,7 +45,7 @@ export function isOversizeDeclaredLength(bodyLength) {
45
45
  return exceedsBatchCap(bodyLength);
46
46
  }
47
47
  /**
48
- * The ONE sanctioned stdout reference in `src/transport/**` (fit-30 stdout-protocol-sacred):
48
+ * The ONE sanctioned stdout reference in the runner and engine-client code (fit-30 stdout-protocol-sacred):
49
49
  * captures the process's fd-1 write handle AT CALL TIME — call it before any factory import
50
50
  * — so later author-code reassignment of `process.stdout` cannot hijack the wire (the
51
51
  * BRB-02/RUN-08 defence, e2e-proven in S-003).
@@ -1,4 +1,4 @@
1
- // src/transport/wire-protocol.ts — wire-level constants, frame shapes, and structural
1
+ // src/shared-kernel/wire-protocol.ts — wire-level constants, frame shapes, and structural
2
2
  // guards (WPS-02/03/05/09). design.md § 4.3 Data Model gives these signatures verbatim.
3
3
  export const WIRE_PROTOCOL_VERSION = 1; // ready.protocolVersion (transport) — DISTINCT from Batch.protocolVersion (IR)
4
4
  export const BRIDGE_CONTRACT_VERSION = 1; // in-process JS bridge; independent of the wire (BRB-01)
@@ -1,84 +1 @@
1
- import type { Batch, Directive } from "../core/wire.ts";
2
- import type { AuthoringError } from "../core/authoring-error.ts";
3
- /**
4
- * The outcome of running a factory via `runFactoryForTest`.
5
- *
6
- * @example
7
- * const result: RunResult = await runFactoryForTest(run, input);
8
- * if (result.error === undefined) {
9
- * console.log(result.tree.get("src/greeting.ts"));
10
- * }
11
- */
12
- export interface RunResult {
13
- /**
14
- * The committed tree (`ContractFake.committedTree()`), path → content. Committed writes
15
- * ONLY — an unmodified seed path is never present here, even if the factory read it.
16
- * Content is stored verbatim — `{= ... =}` template placeholders are never rendered here;
17
- * interpolation is the engine's job, not the harness's.
18
- */
19
- tree: ReadonlyMap<string, string>;
20
- /** One `Batch` per `emit()` call, in call order. */
21
- emitted: Batch[];
22
- /**
23
- * `undefined` on success. On a rejected write, the attributed `AuthoringError` from the
24
- * emit seam. On a factory throw, the original thrown value, unmodified.
25
- */
26
- error: AuthoringError | unknown;
27
- }
28
- export type { Batch, Directive };
29
- /**
30
- * Runs a bare author factory in-memory against a normative fake engine and returns what
31
- * actually happened — closing the gap where a write-only factory (one that buffers
32
- * directives but is never observed to commit them) has no author-facing test to catch it.
33
- *
34
- * `fn` is the bare `(input) => void | Promise<void>` author function — never a
35
- * `defineFactory`-wrapped runner. `runFactoryForTest` wraps `fn` internally by delegating to
36
- * `defineFactory`, the SAME seam a future production runner will call (single-wrap-seam
37
- * invariant) — it never reimplements the wrap. The harness constructs its own in-memory fake
38
- * and spy client internally — callers never construct or pass a client.
39
- *
40
- * 0.x, semver-exempt: this module's result shape may still change before the SDK's first
41
- * stable release, independent of the kit's own semver policy.
42
- *
43
- * `./testing` is the supported author-facing test harness — distinct from `./conformance`,
44
- * which exercises dialect-authoring conformance, not factory behaviour.
45
- *
46
- * @param fn - the bare authoring function; receives the resolved input.
47
- * @param input - the resolved input passed through to `fn`.
48
- * @param options.seed - pre-existing tree content visible to the factory's own reads
49
- * (`Record<string,string>`) — the SOLE seeding channel; never reflected in `result.tree`
50
- * unless the factory itself modifies the seeded path.
51
- * @param options.packageDir - opts the run into schema-derived run-boundary validation
52
- * against an adjacent `schema.json` (pass `import.meta.dir`, never `import.meta.url`); when
53
- * absent the run is the untyped, unvalidated tier, byte-identical to a run with no
54
- * `packageDir` at all.
55
- *
56
- * @example
57
- * import { runFactoryForTest } from "@pbuilder/sdk/testing";
58
- * import { create, AuthoringError } from "@pbuilder/sdk/commons";
59
- * import { expect, test } from "bun:test";
60
- *
61
- * test("factory writes a greeting file", async () => {
62
- * const run = (input: { name: string }) => {
63
- * create("src/greeting.ts", {
64
- * template: "export const greeting = '{= .name =}';",
65
- * options: { name: input.name },
66
- * });
67
- * };
68
- *
69
- * const result = await runFactoryForTest(run, { name: "hello" });
70
- *
71
- * if (result.error !== undefined) {
72
- * if (result.error instanceof AuthoringError) {
73
- * throw new Error(`unexpected rejection: ${result.error.reason}`);
74
- * }
75
- * throw result.error;
76
- * }
77
- *
78
- * expect(result.tree.get("src/greeting.ts")).toEqual("export const greeting = '{= .name =}';");
79
- * });
80
- */
81
- export declare function runFactoryForTest<O>(fn: (input: O) => void | Promise<void>, input: O, options?: {
82
- seed?: Record<string, string>;
83
- packageDir?: string | URL;
84
- }): Promise<RunResult>;
1
+ export * from "../bounded-contexts/authoring/testing/harness/index.ts";
@@ -1,82 +1 @@
1
- import { defineFactory } from "../core/context.js";
2
- import { ContractFake } from "./contract-fake.js";
3
- /**
4
- * Runs a bare author factory in-memory against a normative fake engine and returns what
5
- * actually happened — closing the gap where a write-only factory (one that buffers
6
- * directives but is never observed to commit them) has no author-facing test to catch it.
7
- *
8
- * `fn` is the bare `(input) => void | Promise<void>` author function — never a
9
- * `defineFactory`-wrapped runner. `runFactoryForTest` wraps `fn` internally by delegating to
10
- * `defineFactory`, the SAME seam a future production runner will call (single-wrap-seam
11
- * invariant) — it never reimplements the wrap. The harness constructs its own in-memory fake
12
- * and spy client internally — callers never construct or pass a client.
13
- *
14
- * 0.x, semver-exempt: this module's result shape may still change before the SDK's first
15
- * stable release, independent of the kit's own semver policy.
16
- *
17
- * `./testing` is the supported author-facing test harness — distinct from `./conformance`,
18
- * which exercises dialect-authoring conformance, not factory behaviour.
19
- *
20
- * @param fn - the bare authoring function; receives the resolved input.
21
- * @param input - the resolved input passed through to `fn`.
22
- * @param options.seed - pre-existing tree content visible to the factory's own reads
23
- * (`Record<string,string>`) — the SOLE seeding channel; never reflected in `result.tree`
24
- * unless the factory itself modifies the seeded path.
25
- * @param options.packageDir - opts the run into schema-derived run-boundary validation
26
- * against an adjacent `schema.json` (pass `import.meta.dir`, never `import.meta.url`); when
27
- * absent the run is the untyped, unvalidated tier, byte-identical to a run with no
28
- * `packageDir` at all.
29
- *
30
- * @example
31
- * import { runFactoryForTest } from "@pbuilder/sdk/testing";
32
- * import { create, AuthoringError } from "@pbuilder/sdk/commons";
33
- * import { expect, test } from "bun:test";
34
- *
35
- * test("factory writes a greeting file", async () => {
36
- * const run = (input: { name: string }) => {
37
- * create("src/greeting.ts", {
38
- * template: "export const greeting = '{= .name =}';",
39
- * options: { name: input.name },
40
- * });
41
- * };
42
- *
43
- * const result = await runFactoryForTest(run, { name: "hello" });
44
- *
45
- * if (result.error !== undefined) {
46
- * if (result.error instanceof AuthoringError) {
47
- * throw new Error(`unexpected rejection: ${result.error.reason}`);
48
- * }
49
- * throw result.error;
50
- * }
51
- *
52
- * expect(result.tree.get("src/greeting.ts")).toEqual("export const greeting = '{= .name =}';");
53
- * });
54
- */
55
- export async function runFactoryForTest(fn, input, options) {
56
- const fake = new ContractFake({ seed: options?.seed ?? {} });
57
- const emitted = [];
58
- const client = {
59
- emit(batch) {
60
- emitted.push(batch);
61
- return fake.emit(batch);
62
- },
63
- read(path) {
64
- return fake.read(path);
65
- },
66
- commit() {
67
- return fake.commit();
68
- },
69
- discard() {
70
- return fake.discard();
71
- },
72
- };
73
- const run = defineFactory(fn, options?.packageDir !== undefined ? { packageDir: options.packageDir } : undefined);
74
- let error;
75
- try {
76
- await run(input, { client });
77
- }
78
- catch (caught) {
79
- error = caught;
80
- }
81
- return { tree: fake.committedTree(), emitted, error };
82
- }
1
+ export * from "../bounded-contexts/authoring/testing/harness/index.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pbuilder/sdk",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "description": "The public TypeScript/Bun authoring layer for Project Builder schematics. Authors file mutations (create, replaceContent, remove, rename, move, copy, copyIn), lowers them to IR, and talks to the Project Builder engine over framed stdio (see docs/engine-sdk-wire-spec.md).",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -10,7 +10,7 @@
10
10
  "type": "git",
11
11
  "url": "git+https://github.com/Project-Builder-Schematics/project-builder-sdk.git"
12
12
  },
13
- "homepage": "https://github.com/Project-Builder-Schematics/project-builder-sdk#readme",
13
+ "homepage": "https://schematics.pbuilder.dev/",
14
14
  "bugs": {
15
15
  "url": "https://github.com/Project-Builder-Schematics/project-builder-sdk/issues"
16
16
  },
@@ -107,9 +107,15 @@
107
107
  "publish:dry": "npm publish --dry-run",
108
108
  "registry:up": "verdaccio --config tools/verdaccio/config.yaml --listen 4873",
109
109
  "publish:local": "npm publish --userconfig tools/verdaccio/npmrc --registry http://localhost:4873 --tag local",
110
- "link:sdk": "bun run build && bun link"
110
+ "link:sdk": "bun run build && bun link",
111
+ "rules:implemented": "bun test ./src/acceptance/runner/implemented.rules.ts",
112
+ "rules:designed": "bun test ./src/acceptance/runner/designed.rules.ts"
111
113
  },
112
114
  "devDependencies": {
115
+ "@cucumber/cucumber-expressions": "20.2.0",
116
+ "@cucumber/gherkin": "43.0.0",
117
+ "@cucumber/messages": "35.0.0",
118
+ "@cucumber/tag-expressions": "11.1.0",
113
119
  "@types/bun": "^1.3.14",
114
120
  "expect-type": "^1.3.0",
115
121
  "typescript": "^7.0.2",
@@ -1,10 +0,0 @@
1
- export type { EngineClient } from "./engine-client.ts";
2
- export type { Batch, Directive, JsonValue } from "./wire.ts";
3
- export { Session } from "./session.ts";
4
- export { DirectiveFactory } from "./directive-factory.ts";
5
- export type { SessionContext } from "./context.ts";
6
- export { defineFactory, currentContext } from "./context.ts";
7
- export type { ReadOps, WriteOps, WritableHandleRef } from "./base-handle.ts";
8
- export type { FoundHandle, WritableHandle } from "./handle-state.ts";
9
- export { defineDialect, defineOpPack, query, withOps } from "./define-dialect.ts";
10
- export type { Dialect, OpPack, Query } from "./define-dialect.ts";
@@ -1,6 +0,0 @@
1
- // Internal kit root (ADR-0009 boundary). Not exported to authors.
2
- // Extraction-ready: becomes @pbuilder/sdk-kit when the first external dialect lands.
3
- export { Session } from "./session.js";
4
- export { DirectiveFactory } from "./directive-factory.js";
5
- export { defineFactory, currentContext } from "./context.js";
6
- export { defineDialect, defineOpPack, query, withOps } from "./define-dialect.js";
@@ -1,13 +0,0 @@
1
- /** Hard 16-char ceiling for the rare diagnostic fragment — never a norm, always a last resort. */
2
- export declare function boundedFragment(s: string, cap?: number): string;
3
- /** `zeroMatchTail`/`multiMatchTail`'s `elementName` echo bound — see the note above `boundedFragment`. */
4
- export declare function elementNameEcho(s: string): string;
5
- /**
6
- * Builds a reject tail naming `argName` + `ruleLabel` plus the standard two-remedy pair (fix
7
- * the name / use `.modify()`) — never the rejected VALUE (REQ-RXD-13.3's zero-echo contract).
8
- */
9
- export declare function nameRuleTail(argName: string, ruleLabel: string): string;
10
- /** A JSX op's zero-match reject tail (REQ-RXD-04.4) — names the missing element, bounded. */
11
- export declare function zeroMatchTail(elementName: string, propNames?: readonly string[]): string;
12
- /** A JSX op's multi-match reject tail (REQ-RXD-04.5) — names the element + count, bounded. */
13
- export declare function multiMatchTail(opName: string, elementName: string, matchCount: number, propNames?: readonly string[]): string;
@@ -1,52 +0,0 @@
1
- // S-001: the no-echo tail chokepoint (design §4.4, ADR-02). Every react validator/targeting
2
- // reject routes its message through here — default ZERO echo of the rejected VALUE (argument
3
- // NAMES may appear freely; the hostile value itself never does). `boundedFragment` exists for
4
- // the rare diagnostic that MUST echo a fixed, non-hostile literal (e.g. a denylist entry) —
5
- // its 16-char cap is a ceiling, not a norm; most tails never call it.
6
- /** Hard 16-char ceiling for the rare diagnostic fragment — never a norm, always a last resort. */
7
- export function boundedFragment(s, cap = 16) {
8
- return s.length > cap ? s.slice(0, cap) : s;
9
- }
10
- // `boundedFragment`'s 16-char cap is sized for REQ-RXD-13's hostile-VALUE diagnostics — never
11
- // widen it, that's a different reject class with a signed cap. `setJsxProp`'s match-count
12
- // rejects (REQ-RXD-04) echo `elementName` instead: a POST-VALIDATION, grammar-constrained
13
- // argument (no quotes, no newlines — never an injection vector), not a hostile value, so
14
- // reusing the 16-char cap here bought nothing but silently mangled ordinary component names
15
- // (`NotificationPreferencesPanel` -> `NotificationPref`) into ones matching nothing in the
16
- // author's source, with no signal anything was cut. This wider cap comfortably covers
17
- // realistic component names; on the rare name that still exceeds it, an explicit `…` marker is
18
- // appended so a cut name is never mistaken for the element's real one.
19
- const ELEMENT_NAME_ECHO_CAP = 100;
20
- /** `zeroMatchTail`/`multiMatchTail`'s `elementName` echo bound — see the note above `boundedFragment`. */
21
- export function elementNameEcho(s) {
22
- return s.length > ELEMENT_NAME_ECHO_CAP ? `${s.slice(0, ELEMENT_NAME_ECHO_CAP)}…` : s;
23
- }
24
- /**
25
- * Builds a reject tail naming `argName` + `ruleLabel` plus the standard two-remedy pair (fix
26
- * the name / use `.modify()`) — never the rejected VALUE (REQ-RXD-13.3's zero-echo contract).
27
- */
28
- export function nameRuleTail(argName, ruleLabel) {
29
- return `\`${argName}\` must ${ruleLabel} — fix the name, or use \`.modify()\` to make this edit directly.`;
30
- }
31
- // ARCH-3 (council; corrected V8 — judgment-day Round 2, Judge B): `setJsxProp`'s match-count
32
- // rejects (REQ-RXD-04) echo a POST-VALIDATION argument value (`elementName`) rather than
33
- // refusing to — deliberate UX (naming which element wasn't found / matched), sanctioned by
34
- // design §4.4. `elementName` is grammar-constrained (no quotes, no newlines — never an
35
- // injection vector), but the grammar has no LENGTH ceiling, so the echo routes through
36
- // `elementNameEcho` (the wide, marked 100-char bound above) — NOT `boundedFragment`'s 16-char
37
- // hostile-value cap — keeping every react reject message bounded without mangling ordinary
38
- // names.
39
- // Target prop NAMES are grammar-validated like `elementName`; their values are never echoed.
40
- function withProps(propNames) {
41
- return propNames.length === 0 ? "" : ` with props ${propNames.map((name) => `\`${elementNameEcho(name)}\``).join(", ")}`;
42
- }
43
- /** A JSX op's zero-match reject tail (REQ-RXD-04.4) — names the missing element, bounded. */
44
- export function zeroMatchTail(elementName, propNames = []) {
45
- return (`no element named \`${elementNameEcho(elementName)}\`${withProps(propNames)} was found — use \`.modify()\` to inspect ` +
46
- "the file and edit it directly.");
47
- }
48
- /** A JSX op's multi-match reject tail (REQ-RXD-04.5) — names the element + count, bounded. */
49
- export function multiMatchTail(opName, elementName, matchCount, propNames = []) {
50
- return (`\`${elementNameEcho(elementName)}\`${withProps(propNames)} matched ${matchCount} elements — ${opName} requires ` +
51
- "exactly one match; use `.modify()` to disambiguate.");
52
- }
@@ -1,13 +0,0 @@
1
- export declare const SCHEMA_FILENAME = "schema.json";
2
- export declare function schemaPathFor(packageDir: string): string;
3
- /**
4
- * Scans a factory package's OWN DIRECTORY ENTRIES (never resolved run-time inputs and
5
- * never `schema.json` field names — REQ-RLN-01) for a reserved-lifecycle-name sibling: a
6
- * `pre-execute`/`post-execute` file (`.ts`/`.js`, case-insensitive) or directory (dir-form,
7
- * e.g. `pre-execute/index.ts`). Returns the matched reserved name, or `undefined` for a
8
- * clean package. A non-existent package directory (ENOENT) is not a failure — returns
9
- * `undefined`, same as "no reserved siblings" (mirrors RBV-03's opt-out posture); any other
10
- * read error (EACCES/EPERM/EISDIR) FAILS CLOSED — thrown, never silently downgraded
11
- * (constraint 4, SEC-3).
12
- */
13
- export declare function findReservedSibling(packageDir: string): string | undefined;
@@ -1,51 +0,0 @@
1
- // Locates a factory package's adjacent schema.json (design §4.2, REQ-FPS-01.1, ADR-0031),
2
- // and (S-004) its reserved-lifecycle-name siblings (REQ-RLN-01, ADR-0028). No configuration
3
- // surface — the canonical shapes are fixed and discoverable from the package directory alone.
4
- import { readdirSync } from "node:fs";
5
- import { join } from "node:path";
6
- import { RESERVED_LIFECYCLE_NAMES } from "./schema-model.js";
7
- import { isErrnoException } from "../fs-errors.js";
8
- export const SCHEMA_FILENAME = "schema.json";
9
- export function schemaPathFor(packageDir) {
10
- return join(packageDir, SCHEMA_FILENAME);
11
- }
12
- const RESERVED_EXTENSIONS = [".ts", ".js"];
13
- // Strips a recognized extension (case-insensitively) so `pre-execute.ts`, `PRE-EXECUTE.TS`,
14
- // and the dir-form entry `pre-execute` (no extension at all) all normalize to the same
15
- // lowercase kebab token before comparison (ADR-0028: case-insensitive, strip-extension).
16
- function normalizeEntry(name) {
17
- const lower = name.toLowerCase();
18
- for (const ext of RESERVED_EXTENSIONS) {
19
- if (lower.endsWith(ext))
20
- return lower.slice(0, -ext.length);
21
- }
22
- return lower;
23
- }
24
- /**
25
- * Scans a factory package's OWN DIRECTORY ENTRIES (never resolved run-time inputs and
26
- * never `schema.json` field names — REQ-RLN-01) for a reserved-lifecycle-name sibling: a
27
- * `pre-execute`/`post-execute` file (`.ts`/`.js`, case-insensitive) or directory (dir-form,
28
- * e.g. `pre-execute/index.ts`). Returns the matched reserved name, or `undefined` for a
29
- * clean package. A non-existent package directory (ENOENT) is not a failure — returns
30
- * `undefined`, same as "no reserved siblings" (mirrors RBV-03's opt-out posture); any other
31
- * read error (EACCES/EPERM/EISDIR) FAILS CLOSED — thrown, never silently downgraded
32
- * (constraint 4, SEC-3).
33
- */
34
- export function findReservedSibling(packageDir) {
35
- let entries;
36
- try {
37
- entries = readdirSync(packageDir);
38
- }
39
- catch (err) {
40
- if (isErrnoException(err) && err.code === "ENOENT")
41
- return undefined;
42
- throw err;
43
- }
44
- for (const entry of entries) {
45
- const normalized = normalizeEntry(entry);
46
- const match = RESERVED_LIFECYCLE_NAMES.find((name) => name === normalized);
47
- if (match !== undefined)
48
- return match;
49
- }
50
- return undefined;
51
- }
@@ -1,54 +0,0 @@
1
- import type { JsonValue } from "../core/wire.ts";
2
- export type ClassificationVerdict = "by-value" | "by-reference";
3
- export type ClassifyResult = {
4
- verdict: "by-value"; /** The file's decoded UTF-8 content. */
5
- content: string;
6
- } | {
7
- verdict: "by-reference";
8
- };
9
- export declare function decodeSniffableText(buf: Buffer): string | null;
10
- export declare function isSniffableText(buf: Buffer): boolean;
11
- interface ClassifyParams {
12
- packageDir: string;
13
- relPath: string;
14
- isTemplateMarked: boolean;
15
- /**
16
- * The `pathTemplate`/`options`/`force` the caller would put on the `create` directive
17
- * IF this source classifies by-value — REQUIRED, never defaulted, so the budget check
18
- * below can never silently regress to a content-only measure (REQ-CCL-02: the budget is
19
- * evaluated against the PROSPECTIVE emitted directive, matching the emit authority
20
- * exactly — see the `serializedBatchSize` call below).
21
- */
22
- destPath: string;
23
- options: JsonValue;
24
- force?: boolean;
25
- /**
26
- * Render-request mode (`create({templateFile})`, REQ-FEH-02): a failed gate throws
27
- * `invalid-input` with THESE caller-pinned message texts instead of degrading to a
28
- * by-reference verdict — the same fail-loud carve-out `.template`-marked entries get,
29
- * with the caller's own message family.
30
- */
31
- failMessages?: {
32
- binary: string;
33
- oversized: string;
34
- };
35
- }
36
- /**
37
- * Classifies ONE package-local source: stat-size gate before any content read
38
- * (REQ-CCL-06) → whole-file UTF-8/null-byte sniff (REQ-CCL-01/03) → serialized-budget
39
- * check (REQ-CCL-02) → verdict. A `.template`-marked source (`isTemplateMarked`, from the
40
- * filename pipeline's post-translation check) NEVER degrades to by-reference on a failed
41
- * gate — it fails loud instead (REQ-CCL-05), same posture `readTemplateFile` applies to
42
- * `create({templateFile})` render requests via `failMessages` (REQ-FEH-02).
43
- */
44
- export declare function classifyTransport(params: ClassifyParams & {
45
- failMessages: {
46
- binary: string;
47
- oversized: string;
48
- };
49
- }): {
50
- verdict: "by-value";
51
- content: string;
52
- };
53
- export declare function classifyTransport(params: ClassifyParams): ClassifyResult;
54
- export {};
@@ -1,119 +0,0 @@
1
- // src/scaffold/classify-transport.ts (ADR-0044): the by-value/by-reference classifier —
2
- // stat-gate → whole-file sniff → serialized-budget → verdict (content-classification
3
- // REQ-CCL-01/02/03/06), plus the `.template`/`templateFile` render-request fail-loud
4
- // carve-out (REQ-CCL-05). PURE per-file decision (Executor Context §18) — it never throws
5
- // for an ORDINARY by-reference verdict; the caller (`expander.ts`) decides what a
6
- // by-reference verdict means for THIS slice (S-003: real `copyIn` emission).
7
- //
8
- // ADR-0077: delegates to `path-guards.ts`'s `statSourceForRead` — IO hygiene (regular-file
9
- // allow-list), no containment ceiling. Runs BEFORE any of this module's own stat/sniff/
10
- // budget checks; the `Stats` it already obtained is reused here for the CCL-06 size gate
11
- // rather than stat'ing the path a second time. A `readFileSync` failure AFTER hygiene has
12
- // already proven a regular file (e.g. a permission/I/O error between stat and read)
13
- // classifies `source-unreadable` (REQ-AEC-10) — distinct from a CONTENT-level classify
14
- // failure (binary/oversized), which stays `invalid-input` for `.template`-marked entries
15
- // only (REQ-CCL-05/AEC-12) and by-reference for everything else.
16
- import { readFileSync } from "node:fs";
17
- import { invalidInput } from "../core/authoring-error.js";
18
- import { EMIT_BATCH_BUDGET_BYTES, serializedBatchSize } from "../core/wire.js";
19
- import { encodeOptions, forceEntry } from "../core/directive-factory.js";
20
- import { sourceRejection, statSourceForRead } from "./path-guards.js";
21
- // REQ-CCL-01's whole-file sniff, scoped to what a render REQUEST needs (S-000): valid UTF-8
22
- // across the ENTIRE buffer (never a prefix sample — REQ-CCL-03) and no null byte anywhere.
23
- // Lives here (the classify leaf) so the module graph stays acyclic — `index.ts` re-exports
24
- // the boolean form for the historical `scaffold/index.ts` surface. A render request has no
25
- // by-reference fallback (REQ-FEH-02), it fails loud. `ignoreBOM: true` is REQUIRED (judgment-
26
- // day iteration 2 fix, REQ-FEH-01.1): `TextDecoder` defaults to stripping a leading UTF-8 BOM
27
- // (`ignoreBOM: false`), which would silently drop bytes from a file's exact content — this
28
- // decoded string becomes the `create` directive's `template` (both the by-value scaffold path
29
- // and `readTemplateFile`), so a BOM-prefixed source must decode BOM-preserving to honor "exact
30
- // content" (REQ-FEH-01.1). `ignoreBOM: true` still fatal-validates the whole buffer in one pass
31
- // — no second decode at the caller.
32
- export function decodeSniffableText(buf) {
33
- if (buf.includes(0))
34
- return null;
35
- try {
36
- return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(buf);
37
- }
38
- catch {
39
- return null;
40
- }
41
- }
42
- export function isSniffableText(buf) {
43
- return decodeSniffableText(buf) !== null;
44
- }
45
- function templateSniffFailMessage(relPath, problem) {
46
- return (`invalid input: source "${relPath}" is marked .template but ${problem} — ` +
47
- "render requests never silently fall back to a copy");
48
- }
49
- export function classifyTransport(params) {
50
- const { packageDir, relPath, isTemplateMarked, destPath, options, force, failMessages } = params;
51
- // The fail-loud message pair for a render REQUEST (either kind); undefined ⇒ a failed
52
- // gate is an ordinary by-reference verdict.
53
- const renderFail = failMessages ??
54
- (isTemplateMarked
55
- ? {
56
- binary: templateSniffFailMessage(relPath, "is not valid text (binary content)"),
57
- oversized: templateSniffFailMessage(relPath, "is too large to render inline (over the 4 MiB limit)"),
58
- }
59
- : undefined);
60
- // IO hygiene completes BEFORE any content read. Throws one of the three surviving
61
- // `source-*` reasons on failure — regardless of `isTemplateMarked` (a missing/
62
- // non-regular SOURCE is a source-read failure, not a classify-level CCL-05 content
63
- // failure; only steps AFTER hygiene get the `.template` invalid-input carve-out below).
64
- const { absPath, stat } = statSourceForRead({ packageDir, relPath });
65
- // Stat-size gate BEFORE any content read (REQ-CCL-06): zero content-read calls for an
66
- // over-budget-by-stat file. Reuses the hygiene guard's own `stat` — no second stat call.
67
- if (stat.size > EMIT_BATCH_BUDGET_BYTES) {
68
- if (renderFail) {
69
- throw invalidInput(renderFail.oversized);
70
- }
71
- return { verdict: "by-reference" };
72
- }
73
- let buf;
74
- try {
75
- buf = readFileSync(absPath);
76
- }
77
- catch {
78
- // Hygiene already proved a readable regular file; a read failure THIS LATE is a
79
- // genuine read-path failure (permission/I/O), never a missing source. Routed through
80
- // `path-guards.ts`'s own `sourceRejection` (judgment-day G4(i)) — a bare
81
- // `new AuthoringError(...)` with no `message` falls to `messageFor`'s generic
82
- // "could not be read" template, silently dropping the failure CATEGORY REQ-AEC-11.1
83
- // mandates; `sourceRejection` is the one place that template is built.
84
- throw sourceRejection("source-unreadable", relPath, "permission or I/O error");
85
- }
86
- const content = decodeSniffableText(buf);
87
- if (content === null) {
88
- if (renderFail) {
89
- throw invalidInput(renderFail.binary);
90
- }
91
- return { verdict: "by-reference" };
92
- }
93
- // Serialized-form budget (REQ-CCL-02): measured against the PROSPECTIVE `create`
94
- // DIRECTIVE this source would emit if classified by-value — envelope, `create` wrapper,
95
- // `pathTemplate`, and `options` all included, never the content string alone — via the
96
- // SAME `serializedBatchSize` helper the fake's real batch-cap check applies at emit time
97
- // (`core/wire.ts`). A lone over-budget directive can never fit any flush group (the
98
- // expander flushes a solo directive as its own group, REQ-04.2), so measuring the
99
- // single-directive batch here is exactly what the emit authority will measure later —
100
- // against `EMIT_BATCH_BUDGET_BYTES`, the SAME boundary `exceedsEmitBatchBudget` enforces
101
- // at emit (spec V4 REQ-WPS-04.1: the cap reserves the frame-envelope allowance).
102
- // `>` (not `>=`) — exactly-at-budget still fits (REQ-CCL-02.3).
103
- //
104
- // REQ-CCL-02.4: `options` is run through the SAME shared `encodeOptions` (fit-39's one
105
- // other sanctioned call site) real `create()` emission applies, so the measure and the
106
- // emitted directive can never disagree on the options' wire form.
107
- const prospectiveDirective = {
108
- op: "create",
109
- create: { pathTemplate: destPath, template: content, options: encodeOptions(options), ...forceEntry(force) },
110
- };
111
- const directiveSize = serializedBatchSize([prospectiveDirective]);
112
- if (directiveSize > EMIT_BATCH_BUDGET_BYTES) {
113
- if (renderFail) {
114
- throw invalidInput(renderFail.oversized);
115
- }
116
- return { verdict: "by-reference" };
117
- }
118
- return { verdict: "by-value", content };
119
- }