@pbuilder/sdk 0.13.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 +16 -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 +11 -1
  37. package/dist/{scaffold → bounded-contexts/authoring/domain/services}/filename-pipeline.js +94 -3
  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
@@ -0,0 +1,5 @@
1
+ import { type AuthoringOrigin } from "../../../domain/valueobjects/authoring-error.ts";
2
+ /** The origin of an Authoring rejection, or `undefined` for any other error. */
3
+ export declare function authoringOrigin(err: unknown): AuthoringOrigin | undefined;
4
+ /** Where `raw`, already rejected by `JSON.parse`, breaks: "(line L, column C)" or "(position unknown)". */
5
+ export declare function describeJsonSyntaxError(raw: string): string;
@@ -0,0 +1,15 @@
1
+ // What a driving adapter in another context needs from the run-factory use case besides
2
+ // defineFactory: it reaches Authoring through this application layer, never its domain
3
+ // (CODE-LAYOUT:131).
4
+ import { AuthoringError } from "../../../domain/valueobjects/authoring-error.js";
5
+ import { locateFirstJsonSyntaxError } from "../../../domain/services/schema/schema-locate.js";
6
+ import { formatLocator } from "../../../domain/services/schema/schema-parse.js";
7
+ /** The origin of an Authoring rejection, or `undefined` for any other error. */
8
+ export function authoringOrigin(err) {
9
+ return err instanceof AuthoringError ? err.origin : undefined;
10
+ }
11
+ /** Where `raw`, already rejected by `JSON.parse`, breaks: "(line L, column C)" or "(position unknown)". */
12
+ export function describeJsonSyntaxError(raw) {
13
+ const locator = locateFirstJsonSyntaxError(raw);
14
+ return formatLocator(locator?.line, locator?.column);
15
+ }
@@ -0,0 +1,51 @@
1
+ import type { JsonValue } from "../../../domain/valueobjects/wire.ts";
2
+ import type { PackageFiles } from "../../../domain/ports/package-files.ts";
3
+ export type ClassificationVerdict = "by-value" | "by-reference";
4
+ export type ClassifyResult = {
5
+ verdict: "by-value"; /** The file's decoded UTF-8 content. */
6
+ content: string;
7
+ } | {
8
+ verdict: "by-reference";
9
+ };
10
+ export declare function decodeSniffableText(buf: Uint8Array): string | null;
11
+ export declare function isSniffableText(buf: Uint8Array): boolean;
12
+ interface ClassifyParams {
13
+ files: PackageFiles;
14
+ packageDir: string;
15
+ relPath: string;
16
+ isTemplateMarked: boolean;
17
+ /** The author listed this source in scaffold's `binary` option: it is copied, never read. */
18
+ declaredBinary?: boolean;
19
+ /** The pattern a not-text rejection suggests for `binary`: the path inside the walked folder. */
20
+ binaryPattern?: string;
21
+ /**
22
+ * The `pathTemplate`/`options`/`force` the caller puts on the `create` directive, so the
23
+ * frame check measures the directive the emit authority will measure, options included.
24
+ */
25
+ destPath: string;
26
+ options: JsonValue;
27
+ force?: boolean;
28
+ /** Render-request mode (`create({templateFile})`, REQ-FEH-02): the caller's own message texts. */
29
+ failMessages?: {
30
+ binary: string;
31
+ oversized: string;
32
+ };
33
+ }
34
+ /**
35
+ * Classifies ONE package-local source. A source declared binary goes by reference, after the
36
+ * IO hygiene check and without any content read. Every other source renders: it must be
37
+ * whole-file valid UTF-8 with no null byte, and its `create` directive must fit one emit frame.
38
+ * A source that fails either rejects naming it, never degrading to a copy (#163): size and
39
+ * options never decide render vs copy.
40
+ */
41
+ export declare function classifyTransport(params: ClassifyParams & {
42
+ failMessages: {
43
+ binary: string;
44
+ oversized: string;
45
+ };
46
+ }): {
47
+ verdict: "by-value";
48
+ content: string;
49
+ };
50
+ export declare function classifyTransport(params: ClassifyParams): ClassifyResult;
51
+ export {};
@@ -0,0 +1,105 @@
1
+ // Scaffold's by-value/by-reference classifier (ADR-0044, #163): the author's `binary`
2
+ // declaration decides; every undeclared source renders, and one that cannot (not text, or too
3
+ // large for one emit frame) rejects rather than being copied. `create({templateFile})` render
4
+ // requests share the same gates through `failMessages` (REQ-FEH-02).
5
+ //
6
+ // ADR-0077: delegates to `path-guards.ts`'s `statSourceForRead` — IO hygiene (regular-file
7
+ // allow-list), no containment ceiling. Runs BEFORE any of this module's own stat/sniff/
8
+ // budget checks; the size it already obtained is reused here for the CCL-06 size gate
9
+ // rather than stat'ing the path a second time. Both reads go through the package-files
10
+ // port. A `readBytes` failure AFTER hygiene has
11
+ // already proven a regular file (e.g. a permission/I/O error between stat and read)
12
+ // classifies `source-unreadable` (REQ-AEC-10) — distinct from a CONTENT-level classify
13
+ // failure (binary/oversized), which is `invalid-input`.
14
+ import { invalidInput } from "../../../domain/valueobjects/authoring-error.js";
15
+ import { serializedBatchSize } from "../../../domain/valueobjects/wire.js";
16
+ import { EMIT_BATCH_BUDGET_BYTES } from "../../../../../shared-kernel/batch-cap.js";
17
+ import { encodeOptions, forceEntry } from "../../../domain/services/directive-factory.js";
18
+ import { sourceRejection, statSourceForRead } from "./path-guards.js";
19
+ // REQ-CCL-01's whole-file sniff, scoped to what a render REQUEST needs (S-000): valid UTF-8
20
+ // across the ENTIRE buffer (never a prefix sample — REQ-CCL-03) and no null byte anywhere.
21
+ // Lives here (the classify leaf) so the module graph stays acyclic — `index.ts` re-exports
22
+ // the boolean form for the historical `scaffold/index.ts` surface. A render request has no
23
+ // by-reference fallback (REQ-FEH-02), it fails loud. `ignoreBOM: true` is REQUIRED (judgment-
24
+ // day iteration 2 fix, REQ-FEH-01.1): `TextDecoder` defaults to stripping a leading UTF-8 BOM
25
+ // (`ignoreBOM: false`), which would silently drop bytes from a file's exact content — this
26
+ // decoded string becomes the `create` directive's `template` (both the by-value scaffold path
27
+ // and `readTemplateFile`), so a BOM-prefixed source must decode BOM-preserving to honor "exact
28
+ // content" (REQ-FEH-01.1). `ignoreBOM: true` still fatal-validates the whole buffer in one pass
29
+ // — no second decode at the caller.
30
+ export function decodeSniffableText(buf) {
31
+ if (buf.includes(0))
32
+ return null;
33
+ try {
34
+ return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(buf);
35
+ }
36
+ catch {
37
+ return null;
38
+ }
39
+ }
40
+ export function isSniffableText(buf) {
41
+ return decodeSniffableText(buf) !== null;
42
+ }
43
+ function templateSniffFailMessage(relPath, problem) {
44
+ return (`invalid input: source "${relPath}" is marked .template but ${problem} — ` +
45
+ "render requests never silently fall back to a copy");
46
+ }
47
+ function notTextMessage(relPath, binaryPattern) {
48
+ return (`invalid input: source "${relPath}" is not valid text, so it cannot be rendered — ` +
49
+ `declare it in scaffold's binary option (binary: [${JSON.stringify(binaryPattern)}]) to copy it byte for byte`);
50
+ }
51
+ function tooLargeMessage(relPath, size) {
52
+ return (`invalid input: source "${relPath}" (${size} bytes) does not fit in one emit frame once rendered ` +
53
+ `(the limit is ${EMIT_BATCH_BUDGET_BYTES} bytes) — make it smaller, or declare it in scaffold's binary option ` +
54
+ "to copy it byte for byte");
55
+ }
56
+ function binaryTemplateMessage(relPath) {
57
+ return (`invalid input: source "${relPath}" is marked .template, which asks for rendering, and declared binary, ` +
58
+ "which asks for a byte-for-byte copy — remove one of the two");
59
+ }
60
+ export function classifyTransport(params) {
61
+ const { files, packageDir, relPath, isTemplateMarked, declaredBinary, destPath, options, force, failMessages } = params;
62
+ if (declaredBinary === true) {
63
+ if (isTemplateMarked)
64
+ throw invalidInput(binaryTemplateMessage(relPath));
65
+ statSourceForRead({ files, packageDir, relPath });
66
+ return { verdict: "by-reference" };
67
+ }
68
+ // IO hygiene completes BEFORE any content read and throws one of the `source-*` reasons.
69
+ const { size } = statSourceForRead({ files, packageDir, relPath });
70
+ const tooLarge = () => {
71
+ throw invalidInput(failMessages?.oversized ??
72
+ (isTemplateMarked
73
+ ? templateSniffFailMessage(relPath, "is too large to render inline (over the 4 MiB limit)")
74
+ : tooLargeMessage(relPath, size)));
75
+ };
76
+ // Size gate before any content read: an over-budget file is never read.
77
+ if (size > EMIT_BATCH_BUDGET_BYTES)
78
+ tooLarge();
79
+ let buf;
80
+ try {
81
+ buf = files.readBytes(packageDir, relPath);
82
+ }
83
+ catch {
84
+ // Hygiene already proved a readable regular file, so a failure this late is a genuine
85
+ // read-path failure (permission or I/O), reported with its category (REQ-AEC-11.1).
86
+ throw sourceRejection("source-unreadable", relPath, "permission or I/O error");
87
+ }
88
+ const content = decodeSniffableText(buf);
89
+ if (content === null) {
90
+ throw invalidInput(failMessages?.binary ??
91
+ (isTemplateMarked
92
+ ? templateSniffFailMessage(relPath, "is not valid text (binary content)")
93
+ : notTextMessage(relPath, params.binaryPattern ?? relPath)));
94
+ }
95
+ // Measured against the PROSPECTIVE `create` directive, envelope and options included, with
96
+ // the same `serializedBatchSize` the emit authority applies; `>` so exactly-at-budget fits.
97
+ // `options` goes through the same `encodeOptions` real emission applies.
98
+ const prospectiveDirective = {
99
+ op: "create",
100
+ create: { pathTemplate: destPath, template: content, options: encodeOptions(options, destPath), ...forceEntry(force) },
101
+ };
102
+ if (serializedBatchSize([prospectiveDirective]) > EMIT_BATCH_BUDGET_BYTES)
103
+ tooLarge();
104
+ return { verdict: "by-value", content };
105
+ }
@@ -1,4 +1,4 @@
1
- import type { JsonValue } from "../core/wire.ts";
1
+ import type { JsonValue } from "../../../domain/valueobjects/wire.ts";
2
2
  /**
3
3
  * Argument shape for the `scaffold` author verb (REQ-FSC-01). `from`/`to` are mandatory;
4
4
  * every other field defaults per REQ-FSC-01: `options` → `{}`, `include` → match
@@ -12,6 +12,7 @@ export interface ScaffoldArgs {
12
12
  exclude?: string[];
13
13
  rename?: Record<string, string>;
14
14
  force?: boolean;
15
+ binary?: string[];
15
16
  }
16
17
  /**
17
18
  * Walks a package-local folder and mirrors it into the target tree (REQ-FSC-01..09):
@@ -26,12 +26,13 @@
26
26
  // underlying `#tree` every chunk staged into: run-level all-or-nothing (REQ-05) holds with
27
27
  // NO new atomicity mechanism, exactly as the design promises.
28
28
  import { posix, join } from "node:path";
29
- import { currentContext, requirePackageAnchors } from "../core/context.js";
30
- import { invalidInput } from "../core/authoring-error.js";
31
- import { forceEntry } from "../core/directive-factory.js";
32
- import { EMIT_BATCH_BUDGET_BYTES, serializedBatchSize } from "../core/wire.js";
29
+ import { currentContext, requirePackageAnchors } from "../run-factory/context.js";
30
+ import { invalidInput } from "../../../domain/valueobjects/authoring-error.js";
31
+ import { forceEntry } from "../../../domain/services/directive-factory.js";
32
+ import { serializedBatchSize } from "../../../domain/valueobjects/wire.js";
33
+ import { EMIT_BATCH_BUDGET_BYTES } from "../../../../../shared-kernel/batch-cap.js";
33
34
  import { walkFolder } from "./walk.js";
34
- import { runFilenamePipeline, isIncluded, detectDestinationCollisions, translateTokens } from "./filename-pipeline.js";
35
+ import { runFilenamePipeline, isIncluded, detectDestinationCollisions, translateTokens, checkDestinationNames, checkSourceNames, } from "../../../domain/services/filename-pipeline.js";
35
36
  import { classifyTransport } from "./classify-transport.js";
36
37
  import { validateDestinationLexical, validateSourceLexical } from "./path-guards.js";
37
38
  function noResolutionAnchorMessage() {
@@ -112,7 +113,7 @@ export function runScaffold(args) {
112
113
  }
113
114
  const ctx = currentContext();
114
115
  const { session, factory } = ctx;
115
- const { packageDir } = requirePackageAnchors(noResolutionAnchorMessage());
116
+ const { packageDir, files } = requirePackageAnchors(noResolutionAnchorMessage());
116
117
  // judgment-day round 3 fix (F4): destination validated AFTER context resolution (`ctx`/
117
118
  // `packageDir` above), not before it — round 2 placed this call at the very top of the
118
119
  // function, ABOVE `currentContext()`, so an escaping `to` called OUTSIDE any run reported
@@ -132,6 +133,7 @@ export function runScaffold(args) {
132
133
  // reaches `isIncluded` (see `validateFilterOptionShape`'s own comment above).
133
134
  validateFilterOptionShape("include", args.include);
134
135
  validateFilterOptionShape("exclude", args.exclude);
136
+ validateFilterOptionShape("binary", args.binary);
135
137
  // Screen call site 2 (REQ-IPF-01): the walk ROOT itself must be lexically screened
136
138
  // BEFORE `walkFolder` ever enumerates it — otherwise an escaping `from` (e.g.
137
139
  // `../secrets`) would readdirSync/lstatSync the whole tree (bounded by `walk.ts`'s
@@ -139,10 +141,14 @@ export function runScaffold(args) {
139
141
  // preserved verbatim (design §4).
140
142
  validateSourceLexical(args.from);
141
143
  const fromAbs = join(packageDir, args.from);
142
- const walked = walkFolder(fromAbs, undefined, args.from);
144
+ const walked = walkFolder(files, fromAbs, undefined, args.from);
143
145
  if (walked.length === 0) {
144
146
  return; // REQ-FSC-04.1: a truly-empty source folder is a silent no-op.
145
147
  }
148
+ // A-17 covers every name under the source folder, excluded ones included: an excluded
149
+ // `con.ts` still cannot be checked out on Windows.
150
+ checkSourceNames(walked.map((entry) => entry.relPath));
151
+ checkDestinationNames(args.to, args.rename);
146
152
  const filtered = walked.filter((entry) => isIncluded(entry.relPath, args.include, args.exclude));
147
153
  if (filtered.length === 0) {
148
154
  throw invalidInput(filtersEliminatedEverythingMessage(args.include, args.exclude));
@@ -178,9 +184,12 @@ export function runScaffold(args) {
178
184
  // pathTemplate/options/force this loop will put on that directive below.
179
185
  const destPath = posix.join(toPrefix, result.destRelPath);
180
186
  const verdict = classifyTransport({
187
+ files,
181
188
  packageDir,
182
189
  relPath: sourceRelPath,
183
190
  isTemplateMarked: result.isTemplateMarked,
191
+ declaredBinary: args.binary !== undefined && isIncluded(result.sourceRelPath, args.binary, undefined),
192
+ binaryPattern: result.sourceRelPath,
184
193
  destPath,
185
194
  options: args.options ?? {},
186
195
  force: args.force,
@@ -1,4 +1,4 @@
1
- import type { JsonValue } from "../core/wire.ts";
1
+ import type { JsonValue } from "../../../domain/valueobjects/wire.ts";
2
2
  export { runScaffold } from "./expander.ts";
3
3
  export type { ScaffoldArgs } from "./expander.ts";
4
4
  export { isSniffableText } from "./classify-transport.ts";
@@ -3,9 +3,9 @@
3
3
  // leaf folder is the ONE place that does (FIT-01: `commons -> ../scaffold -> node:fs` is
4
4
  // compliant by the fitness rule's own terms — it bans bare external PACKAGES, not `node:`
5
5
  // builtins).
6
- import { currentContext, requirePackageAnchors } from "../core/context.js";
7
- import { invalidInput } from "../core/authoring-error.js";
8
- import { forceEntry } from "../core/directive-factory.js";
6
+ import { currentContext, requirePackageAnchors } from "../run-factory/context.js";
7
+ import { invalidInput } from "../../../domain/valueobjects/authoring-error.js";
8
+ import { forceEntry } from "../../../domain/services/directive-factory.js";
9
9
  import { validateSourceLexical, statSourceForRead, validateDestinationLexical } from "./path-guards.js";
10
10
  import { classifyTransport } from "./classify-transport.js";
11
11
  // S-001: the folder-scaffold orchestrator lives in expander.ts (the single owner of the
@@ -50,9 +50,10 @@ export { isSniffableText } from "./classify-transport.js";
50
50
  * never the template content alone.
51
51
  */
52
52
  export function readTemplateFile(relPath, destPath, options, force) {
53
- const { packageDir } = requirePackageAnchors(noResolutionAnchorMessage(relPath));
53
+ const { packageDir, files } = requirePackageAnchors(noResolutionAnchorMessage(relPath));
54
54
  validateSourceLexical(relPath);
55
55
  return classifyTransport({
56
+ files,
56
57
  packageDir,
57
58
  relPath,
58
59
  isTemplateMarked: false,
@@ -93,11 +94,11 @@ export function runCopyIn(args) {
93
94
  throw invalidInput(missingCopyInArgMessage("to"));
94
95
  }
95
96
  const { session, factory } = currentContext();
96
- const { packageDir } = requirePackageAnchors(noResolutionAnchorForCopyInMessage());
97
+ const { packageDir, files } = requirePackageAnchors(noResolutionAnchorForCopyInMessage());
97
98
  // design §4 Q2 — pinned statement order: destination BEFORE source. A both-escape
98
99
  // fixture must yield the DESTINATION template, never the source one (REQ-AEC-11.2).
99
100
  validateDestinationLexical(args.to);
100
101
  validateSourceLexical(args.from);
101
- statSourceForRead({ packageDir, relPath: args.from });
102
+ statSourceForRead({ files, packageDir, relPath: args.from });
102
103
  session.buffer(factory.copyIn({ from: args.from, to: args.to, ...forceEntry(args.force) }));
103
104
  }
@@ -1,5 +1,5 @@
1
- import { type Stats } from "node:fs";
2
- import { AuthoringError } from "../core/authoring-error.ts";
1
+ import { AuthoringError } from "../../../domain/valueobjects/authoring-error.ts";
2
+ import type { PackageFiles, PackageSource } from "../../../domain/ports/package-files.ts";
3
3
  /**
4
4
  * Ruling-5 lexical screen (REQ-IPF-01). Segment-aware over `/` and `\`; ANY segment
5
5
  * === ".." or an absolute path (POSIX `/` or Windows drive) → `invalid-input`. Zero fs
@@ -7,21 +7,22 @@ import { AuthoringError } from "../core/authoring-error.ts";
7
7
  * ROOT `from`), `runCopyIn` (`from`).
8
8
  */
9
9
  export declare function validateSourceLexical(relPath: string): void;
10
- type RejectionDetail = "directory" | "permission or I/O error" | "symlink cycle" | "path contains an invalid character";
10
+ type RejectionDetail = "directory" | Extract<PackageSource, {
11
+ kind: "unreadable";
12
+ }>["detail"];
11
13
  export declare function sourceRejection(reason: "source-not-found" | "source-not-regular-file" | "source-unreadable", relPath: string, detail?: RejectionDetail): AuthoringError;
12
14
  /**
13
- * IO hygiene, TOTAL guard (`package-source-io-hygiene` REQ-PSH-01/02/03). `absPath =
14
- * resolve(join(packageDir, relPath))` — LEXICAL, never disk-canonicalized. `statSync` (follows
15
- * symlinks) → allow-list `isFile()`. The returned `stat` is reused by
16
- * `classify-transport.ts` for the CCL-06 size gate. The `try` wraps BOTH the path
17
- * computation AND the `statSync` call — no raw Node error ever escapes.
15
+ * IO hygiene, TOTAL guard (`package-source-io-hygiene` REQ-PSH-01/02/03): the source must be a
16
+ * readable regular file. The port resolves the path lexically and follows symlinks; this maps
17
+ * what it found to the author-facing rejection. Returns the size `classify-transport.ts` reuses
18
+ * for the CCL-06 gate.
18
19
  */
19
20
  export declare function statSourceForRead(params: {
21
+ files: PackageFiles;
20
22
  packageDir: string;
21
23
  relPath: string;
22
24
  }): {
23
- absPath: string;
24
- stat: Stats;
25
+ size: number;
25
26
  };
26
27
  /**
27
28
  * Validates a FINAL, SDK-computed DESTINATION path (`scaffold`'s computed `to`, or
@@ -1,4 +1,4 @@
1
- // src/scaffold/path-guards.ts (ADR-0077): replaces containment.ts. The SDK no longer
1
+ // Scaffold's source and destination guards (ADR-0077): replaces containment.ts. The SDK no longer
2
2
  // enforces a containment ceiling — `package-root-containment` is retired wholesale. The
3
3
  // SDK's remaining obligation for package-local sources is IO HYGIENE (does this resolve to
4
4
  // a readable regular file?) and IR WELL-FORMEDNESS (is the literal path shape emittable?) —
@@ -7,14 +7,11 @@
7
7
  // 1. `validateSourceLexical` — segment-aware `../`/absolute screen for a SOURCE path
8
8
  // (`ir-path-well-formedness` REQ-IPF-01). Zero fs calls. Called at EXACTLY three sites.
9
9
  // 2. `statSourceForRead` — IO hygiene, TOTAL guard (`package-source-io-hygiene`
10
- // REQ-PSH-01/02/03). LEXICAL resolution only — no disk-canonicalization pass, no
11
- // ceiling.
10
+ // REQ-PSH-01/02/03), over the package-files port's `statSource`. LEXICAL resolution
11
+ // only — no disk-canonicalization pass, no ceiling.
12
12
  // 3. `validateDestinationLexical` — lexical-only guard for a `to` destination
13
13
  // (`ir-path-well-formedness` REQ-IPF-02). Reuses the EXISTING `invalid-input` reason.
14
- import { statSync } from "node:fs";
15
- import { join, resolve } from "node:path";
16
- import { AuthoringError, invalidInput } from "../core/authoring-error.js";
17
- import { isErrnoException } from "../core/fs-errors.js";
14
+ import { AuthoringError, invalidInput } from "../../../domain/valueobjects/authoring-error.js";
18
15
  // Lexical `../`/absolute screen shared by BOTH the source guard (REQ-IPF-01) and the
19
16
  // destination guard (REQ-IPF-02, symmetric by design): a literal ".." segment or an
20
17
  // absolute-looking path (POSIX leading `/` or a Windows drive letter) is rejected
@@ -74,50 +71,26 @@ export function sourceRejection(reason, relPath, detail) {
74
71
  });
75
72
  }
76
73
  /**
77
- * IO hygiene, TOTAL guard (`package-source-io-hygiene` REQ-PSH-01/02/03). `absPath =
78
- * resolve(join(packageDir, relPath))` — LEXICAL, never disk-canonicalized. `statSync` (follows
79
- * symlinks) → allow-list `isFile()`. The returned `stat` is reused by
80
- * `classify-transport.ts` for the CCL-06 size gate. The `try` wraps BOTH the path
81
- * computation AND the `statSync` call — no raw Node error ever escapes.
74
+ * IO hygiene, TOTAL guard (`package-source-io-hygiene` REQ-PSH-01/02/03): the source must be a
75
+ * readable regular file. The port resolves the path lexically and follows symlinks; this maps
76
+ * what it found to the author-facing rejection. Returns the size `classify-transport.ts` reuses
77
+ * for the CCL-06 gate.
82
78
  */
83
79
  export function statSourceForRead(params) {
84
- const { packageDir, relPath } = params;
85
- let absPath;
86
- let stat;
87
- try {
88
- absPath = resolve(join(packageDir, relPath));
89
- stat = statSync(absPath);
80
+ const { files, packageDir, relPath } = params;
81
+ const source = files.statSource(packageDir, relPath);
82
+ switch (source.kind) {
83
+ case "file":
84
+ return { size: source.size };
85
+ case "missing":
86
+ throw sourceRejection("source-not-found", relPath);
87
+ case "directory":
88
+ throw sourceRejection("source-not-regular-file", relPath, "directory");
89
+ case "other":
90
+ throw sourceRejection("source-not-regular-file", relPath);
91
+ case "unreadable":
92
+ throw sourceRejection("source-unreadable", relPath, source.detail);
90
93
  }
91
- catch (err) {
92
- if (isErrnoException(err)) {
93
- // ENOTDIR/ENAMETOOLONG (judgment-day G4(ii)): both mean the path, AS GIVEN, does not
94
- // exist — a segment along the way turned out to be a regular file, or the resolved
95
- // string exceeded the filesystem's name-length limit. Neither is a permission/IO
96
- // failure on an existing path; `source-not-found` is the honest category (the spec's
97
- // own table scopes it to "does not exist"), same as a plain ENOENT.
98
- if (err.code === "ENOENT" || err.code === "ENOTDIR" || err.code === "ENAMETOOLONG") {
99
- throw sourceRejection("source-not-found", relPath);
100
- }
101
- if (err.code === "ELOOP") {
102
- throw sourceRejection("source-unreadable", relPath, "symlink cycle");
103
- }
104
- if (err.code === "ERR_INVALID_ARG_VALUE") {
105
- throw sourceRejection("source-unreadable", relPath, "path contains an invalid character");
106
- }
107
- // EACCES/EPERM/EMFILE/ENFILE/EINTR/… — deliberately never interpolates the errno.
108
- throw sourceRejection("source-unreadable", relPath, "permission or I/O error");
109
- }
110
- // No `.code` at all — an unclassifiable failure. Safest generic category, never a
111
- // raw error message.
112
- throw sourceRejection("source-unreadable", relPath, "permission or I/O error");
113
- }
114
- if (stat.isDirectory()) {
115
- throw sourceRejection("source-not-regular-file", relPath, "directory");
116
- }
117
- if (!stat.isFile()) {
118
- throw sourceRejection("source-not-regular-file", relPath);
119
- }
120
- return { absPath, stat };
121
94
  }
122
95
  function destinationEscapeMessage(relPath) {
123
96
  return (`invalid input: destination "${relPath}" escapes the workspace tree ` +
@@ -1,9 +1,8 @@
1
+ import type { PackageFiles } from "../../../domain/ports/package-files.ts";
1
2
  export declare const DEFAULT_WALK_ENTRY_BOUND = 10000;
2
3
  export interface WalkEntry {
3
4
  /** Source-relative path, posix-separated, relative to the walked `from` root. */
4
5
  relPath: string;
5
- /** Absolute filesystem path — `join(fromAbs, relPath)`. */
6
- absPath: string;
7
6
  }
8
7
  /**
9
8
  * Enumerates every file under `fromAbs`, mirroring nested directory structure into
@@ -24,4 +23,4 @@ export interface WalkEntry {
24
23
  * own doc-comment); a nested entry if a recursive `readdirSync`/`lstatSync` fails mid-walk
25
24
  * (the entry vanished, or an EACCES mid-tree, REQ-FSC-10.4).
26
25
  */
27
- export declare function walkFolder(fromAbs: string, bound?: number, rootRelPath?: string): WalkEntry[];
26
+ export declare function walkFolder(files: PackageFiles, fromAbs: string, bound?: number, rootRelPath?: string): WalkEntry[];
@@ -1,11 +1,10 @@
1
- // src/scaffold/walk.ts (ADR-0044): folder enumeration for `scaffold` — lstat-based
1
+ // Scaffold's folder walk (ADR-0044): enumeration for `scaffold` — lstat-based
2
2
  // symlinked-directory non-descent (REQ-FSC-09.1) and a 10 000-entry bound (REQ-FSC-09.2).
3
3
  // Pure enumeration only: source/destination eligibility and the by-value/by-reference
4
- // verdict are NOT this module's concern (classify-transport.ts + path-guards.ts).
5
- import { lstatSync, readdirSync, statSync } from "node:fs";
4
+ // verdict are NOT this module's concern (classify-transport.ts + path-guards.ts). Every
5
+ // read goes through the package-files port.
6
6
  import { join, posix, resolve } from "node:path";
7
- import { invalidInput } from "../core/authoring-error.js";
8
- import { isErrnoException } from "../core/fs-errors.js";
7
+ import { invalidInput } from "../../../domain/valueobjects/authoring-error.js";
9
8
  export const DEFAULT_WALK_ENTRY_BOUND = 10_000;
10
9
  function boundExceededMessage(bound) {
11
10
  return `invalid input: scaffold walk exceeded the ${bound}-entry bound`;
@@ -49,17 +48,16 @@ function rootUnreadableMessage(rootRelPath) {
49
48
  function rootIsSymlinkMessage(rootRelPath) {
50
49
  return withOptionalLocator(rootRelPath, "invalid input: scaffold \"from\" must not be a symlinked directory", (relPath) => `invalid input: scaffold "from" (${relPath}) must not be a symlinked directory`);
51
50
  }
52
- // Never re-throws the raw Node error (no-echo, REQ-AEC-05/FIT-11 posture already held by
53
- // every other scaffold-family rejection): ENOTDIR (the root resolves to a non-directory —
54
- // most commonly a regular file) and ENOENT (the root doesn't exist) each mint their own
55
- // `AuthoringError` naming ONLY the package-relative `rootRelPath`; any other errno (e.g.
56
- // EACCES) still fails closed the same way — a generic "could not be read" — rather than ever
57
- // leaking `err.message`'s absolute path.
58
- function rootReadFailure(err, rootRelPath) {
59
- if (isErrnoException(err) && err.code === "ENOTDIR") {
51
+ // Never echoes a raw Node error (no-echo, REQ-AEC-05/FIT-11 posture already held by every
52
+ // other scaffold-family rejection): a root that is not a folder (most commonly a regular
53
+ // file) and a missing root each mint their own `AuthoringError` naming ONLY the
54
+ // package-relative `rootRelPath`; any other failure (e.g. a permission error) still fails
55
+ // closed the same way — a generic "could not be read".
56
+ function rootReadFailure(failure, rootRelPath) {
57
+ if (failure === "not-a-directory") {
60
58
  return invalidInput(rootNotDirectoryMessage(rootRelPath));
61
59
  }
62
- if (isErrnoException(err) && err.code === "ENOENT") {
60
+ if (failure === "missing") {
63
61
  return invalidInput(rootNotFoundMessage(rootRelPath));
64
62
  }
65
63
  return invalidInput(rootUnreadableMessage(rootRelPath));
@@ -80,24 +78,12 @@ function entryUnreadableMessage(entryRelPath) {
80
78
  function entryDisappearedMessage(entryRelPath) {
81
79
  return withOptionalLocator(entryRelPath, "invalid input: scaffold entry disappeared during the walk", (relPath) => `invalid input: scaffold entry (${relPath}) disappeared during the walk`);
82
80
  }
83
- function entryReadFailure(err, entryRelPath) {
84
- if (isErrnoException(err) && err.code === "ENOENT") {
81
+ function entryReadFailure(failure, entryRelPath) {
82
+ if (failure === "missing") {
85
83
  return invalidInput(entryDisappearedMessage(entryRelPath));
86
84
  }
87
85
  return invalidInput(entryUnreadableMessage(entryRelPath));
88
86
  }
89
- // A symlink's OWN type (lstat) is always "symbolic link" — this asks what the link's
90
- // TARGET is, via `statSync` (follows the link), ONLY to decide non-descent (REQ-FSC-09.1).
91
- // NOT a containment check: a broken symlink (target absent) is treated as a
92
- // (later-failing) file candidate rather than silently vanishing from the walk.
93
- function symlinkTargetIsDirectory(absPath) {
94
- try {
95
- return statSync(absPath).isDirectory();
96
- }
97
- catch {
98
- return false;
99
- }
100
- }
101
87
  /**
102
88
  * Enumerates every file under `fromAbs`, mirroring nested directory structure into
103
89
  * posix-separated `relPath`s (sorted for deterministic output). A NESTED symlinked
@@ -117,7 +103,7 @@ function symlinkTargetIsDirectory(absPath) {
117
103
  * own doc-comment); a nested entry if a recursive `readdirSync`/`lstatSync` fails mid-walk
118
104
  * (the entry vanished, or an EACCES mid-tree, REQ-FSC-10.4).
119
105
  */
120
- export function walkFolder(fromAbs, bound = DEFAULT_WALK_ENTRY_BOUND, rootRelPath) {
106
+ export function walkFolder(files, fromAbs, bound = DEFAULT_WALK_ENTRY_BOUND, rootRelPath) {
121
107
  // judgment-day round 2 fix (F1): POSIX `lstat` FOLLOWS the final symlink when the path
122
108
  // ends with a separator — an un-normalized `fromAbs` (trailing slash, doubled trailing
123
109
  // slash, or a literal "./" segment) would resolve THROUGH a symlinked root before the
@@ -146,31 +132,26 @@ export function walkFolder(fromAbs, bound = DEFAULT_WALK_ENTRY_BOUND, rootRelPat
146
132
  // missing/non-directory root still reaches `rootReadFailure` unchanged (lstat fails
147
133
  // with the identical errno readdir would have), and a symlinked root rejects
148
134
  // explicitly instead of either being followed or silently skipped.
149
- let rootLst;
150
- try {
151
- rootLst = lstatSync(absDir);
152
- }
153
- catch (err) {
154
- throw rootReadFailure(err, rootRelPath);
135
+ const rootEntry = files.entryAt(absDir);
136
+ if ("failure" in rootEntry) {
137
+ throw rootReadFailure(rootEntry.failure, rootRelPath);
155
138
  }
156
- if (rootLst.isSymbolicLink()) {
139
+ if (rootEntry.kind === "symlink") {
157
140
  throw invalidInput(rootIsSymlinkMessage(rootRelPath));
158
141
  }
159
- try {
160
- names = readdirSync(absDir).sort();
161
- }
162
- catch (err) {
163
- throw rootReadFailure(err, rootRelPath);
142
+ const listed = files.namesIn(absDir);
143
+ if (!Array.isArray(listed)) {
144
+ throw rootReadFailure(listed.failure, rootRelPath);
164
145
  }
146
+ names = listed.sort();
165
147
  }
166
148
  else {
167
- try {
168
- names = readdirSync(absDir).sort();
169
- }
170
- catch (err) {
149
+ const listed = files.namesIn(absDir);
150
+ if (!Array.isArray(listed)) {
171
151
  const entryX = rootRelPath === undefined ? undefined : posix.join(rootRelPath, relDir);
172
- throw entryReadFailure(err, entryX);
152
+ throw entryReadFailure(listed.failure, entryX);
173
153
  }
154
+ names = listed.sort();
174
155
  }
175
156
  for (const name of names) {
176
157
  // F6: incremented for EVERY name `readdirSync` returned, before this entry is
@@ -182,25 +163,25 @@ export function walkFolder(fromAbs, bound = DEFAULT_WALK_ENTRY_BOUND, rootRelPat
182
163
  }
183
164
  const relPath = relDir === "" ? name : `${relDir}/${name}`;
184
165
  const absPath = join(absDir, name);
185
- let lst;
186
- try {
187
- lst = lstatSync(absPath);
188
- }
189
- catch (err) {
166
+ const entry = files.entryAt(absPath);
167
+ if ("failure" in entry) {
190
168
  const entryX = rootRelPath === undefined ? undefined : posix.join(rootRelPath, relPath);
191
- throw entryReadFailure(err, entryX);
169
+ throw entryReadFailure(entry.failure, entryX);
192
170
  }
193
- if (lst.isSymbolicLink()) {
194
- if (symlinkTargetIsDirectory(absPath)) {
171
+ if (entry.kind === "symlink") {
172
+ // Asks what the link's TARGET is, only to decide non-descent (REQ-FSC-09.1). Not a
173
+ // containment check: a broken symlink is a (later-failing) file candidate rather than
174
+ // silently vanishing from the walk.
175
+ if (files.isFolder(absPath)) {
195
176
  continue; // REQ-FSC-09.1: never descended, no error for the skip
196
177
  }
197
178
  // symlinked file (or broken symlink): walkable entry, eligibility deferred.
198
179
  }
199
- else if (lst.isDirectory()) {
180
+ else if (entry.kind === "directory") {
200
181
  dirStack.push(relPath);
201
182
  continue;
202
183
  }
203
- entries.push({ relPath, absPath });
184
+ entries.push({ relPath });
204
185
  }
205
186
  }
206
187
  return entries;
@@ -1,5 +1,5 @@
1
- import type { EngineClient } from "./engine-client.ts";
2
- import type { Directive } from "./wire.ts";
1
+ import type { EngineClient } from "../../ports/engine-client.ts";
2
+ import type { Directive } from "../../valueobjects/wire.ts";
3
3
  export declare class Session {
4
4
  #private;
5
5
  constructor(client: EngineClient);
@@ -7,7 +7,7 @@
7
7
  // but v1's author surface exposes only op-level `force`; this field is hard-coded false
8
8
  // here because the author API has no run-wide force concept yet. The fake's Row-3 test
9
9
  // (FAKE-04) is intentional engine-contract coverage, not dead-code coverage.
10
- import { toAuthoringError } from "./authoring-error.js";
10
+ import { toAuthoringError } from "../../valueobjects/authoring-error.js";
11
11
  export class Session {
12
12
  #client;
13
13
  #pending = [];