@pbuilder/sdk 0.1.0 → 0.2.2

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.
@@ -5,19 +5,23 @@
5
5
  // the repo carries no glob library and none may be added) and intra-scaffold
6
6
  // destination-collision detection (REQ-FSC-08). Zero I/O — pure string transforms over
7
7
  // already-enumerated `walk.ts` entries.
8
+ import { posix } from "node:path";
8
9
  import { invalidInput } from "../core/authoring-error.js";
9
10
  const TEMPLATE_SUFFIX = ".template";
10
11
  const TOKEN_PATTERN = /__([A-Za-z_][A-Za-z0-9_]*(?:@[A-Za-z_][A-Za-z0-9_]*)*)__/g;
11
12
  /**
12
13
  * Translates on-disk filename tokens to the wire `pathTemplate` syntax the ENGINE
13
14
  * substitutes (obs #915 ruling 4) — the SDK never renders these itself, only rewrites the
14
- * marker syntax. `__name@dasherize__` → `{= name | dasherize =}`; a bare `__name__`
15
- * (no `@pipe`) → `{= name =}`.
15
+ * marker syntax. `__name@dasherize__` → `{= .name | dasherize =}`; a bare `__name__`
16
+ * (no `@pipe`) → `{= .name =}`. The dotted field reference is REQUIRED by the engine's
17
+ * templating (bare `{= name =}` was migrated away — docs/templating/migration-note.md in
18
+ * the engine repo); emitting the bare form makes every tokenized filename fail
19
+ * path-render at ingest (`path-render-failed`, exit 2).
16
20
  */
17
21
  export function translateTokens(path) {
18
22
  return path.replace(TOKEN_PATTERN, (_match, inner) => {
19
23
  const [field, ...pipes] = inner.split("@");
20
- return pipes.length > 0 ? `{= ${field} | ${pipes.join(" | ")} =}` : `{= ${field} =}`;
24
+ return pipes.length > 0 ? `{= .${field} | ${pipes.join(" | ")} =}` : `{= .${field} =}`;
21
25
  });
22
26
  }
23
27
  /** REQ-FSC-05 step (3): strips a `.template` suffix from the (post-translation) path. */
@@ -34,7 +38,23 @@ export function stripTemplateSuffix(path) {
34
38
  * (the marker must survive translation to be recognized).
35
39
  */
36
40
  export function runFilenamePipeline(relPath, rename) {
37
- const renamed = rename?.[relPath] ?? relPath;
41
+ // judgment-day round 2 fix (F2): a non-string rename value used to reach `translateTokens`
42
+ // as a raw, unbranded TypeError (`.replace is not a function`) — type-checked at the
43
+ // FIRST point of consumption, same posture as every other scaffold-family author-misuse
44
+ // rejection (`invalid-input`, never a raw Node/JS error).
45
+ //
46
+ // judgment-day round 3 fix (F3): `rename?.[relPath]` on a PLAIN object walks the
47
+ // prototype chain — a walked entry literally named `__proto__`/`toString`/`constructor`
48
+ // (no author rename rule at all) resolved to an inherited `Object.prototype` value,
49
+ // minting a nonsense "must be a string" rejection for ANY rename table, on ANY entry
50
+ // sharing that name. `Object.hasOwn` gates the lookup to the table's OWN keys only —
51
+ // an entry with no OWN rename rule pipelines through unchanged, exactly as if `rename`
52
+ // were absent for it.
53
+ const renameValue = rename !== undefined && Object.hasOwn(rename, relPath) ? rename[relPath] : undefined;
54
+ if (renameValue !== undefined && typeof renameValue !== "string") {
55
+ throw invalidInput(`invalid input: scaffold rename value for "${relPath}" must be a string`);
56
+ }
57
+ const renamed = renameValue ?? relPath;
38
58
  const translated = translateTokens(renamed);
39
59
  const { stripped, wasTemplate } = stripTemplateSuffix(translated);
40
60
  return { sourceRelPath: relPath, destRelPath: stripped, isTemplateMarked: wasTemplate };
@@ -103,16 +123,24 @@ function collisionMessage(collisions) {
103
123
  * destination (after the filename pipeline collapses their names), reject fail-loud,
104
124
  * deterministically, naming ALL offending source paths — never last-writer-wins, never
105
125
  * dependent on walk order.
126
+ *
127
+ * judgment-day round 3 fix (F5): keyed on `posix.normalize(destRelPath)`, not the raw
128
+ * string — a `rename` value like `"./b.ts"` and a sibling literal `"b.ts"` are the SAME
129
+ * destination post-normalization (the expander's own `posix.join` would collapse them
130
+ * identically) but previously formed two distinct map keys, so the collision went
131
+ * undetected here and surfaced later as whatever error family the SECOND write happened
132
+ * to hit, instead of this REQ's deterministic, both-offenders-named rejection.
106
133
  */
107
134
  export function detectDestinationCollisions(results) {
108
135
  const byDest = new Map();
109
136
  for (const r of results) {
110
- const existing = byDest.get(r.destRelPath);
137
+ const key = posix.normalize(r.destRelPath);
138
+ const existing = byDest.get(key);
111
139
  if (existing) {
112
140
  existing.push(r.sourceRelPath);
113
141
  }
114
142
  else {
115
- byDest.set(r.destRelPath, [r.sourceRelPath]);
143
+ byDest.set(key, [r.sourceRelPath]);
116
144
  }
117
145
  }
118
146
  const collisions = [...byDest.entries()]
@@ -6,13 +6,13 @@ export { isSniffableText } from "./classify-transport.ts";
6
6
  * Reads a package-local file (relative to the active run's `packageDir`) and returns its
7
7
  * content as the string to use for a `create({ templateFile })` render request.
8
8
  *
9
- * Containment (S-005, verify-in-loop-4 Deviation #1 ruling): the path is validated through
10
- * the SAME `validateSourceContainment` machinery `scaffold`/`copyIn` already use
11
- * (`package-root-containment` REQ-PRC-01..08) BEFORE any content read — a missing/
12
- * outside-package/non-regular/unreadable source surfaces the matching neutral `source-*`
13
- * `AuthoringReason` (REQ-AEC-10/11), never a parallel templateFile-only check. The whole
14
- * containment → stat-size (REQ-CCL-06 posture) → read → sniff (REQ-CCL-01/03) → budget
15
- * (REQ-CCL-02) chain is `classifyTransport`'s — ONE gate engine for both callers. A
9
+ * ADR-0077: the path is screened lexically (`validateSourceLexical`, `ir-path-well-formedness`
10
+ * REQ-IPF-01) then hygiene-checked through the SAME `statSourceForRead` machinery
11
+ * `scaffold`/`copyIn` already use (`package-source-io-hygiene` REQ-PSH-01..03) BEFORE any
12
+ * content read — a missing/non-regular/unreadable source surfaces the matching neutral
13
+ * `source-*` `AuthoringReason` (REQ-AEC-10/11), never a parallel templateFile-only check.
14
+ * The whole hygiene → stat-size (REQ-CCL-06 posture) → read → sniff (REQ-CCL-01/03) →
15
+ * budget (REQ-CCL-02) chain is `classifyTransport`'s — ONE gate engine for both callers. A
16
16
  * `templateFile` REQUESTS a render — unlike `scaffold`'s by-value/by-reference
17
17
  * classification of unmarked files, there is no silent by-reference fallback here
18
18
  * (REQ-FEH-02): invalid UTF-8, a null byte, or an over-budget file all fail loud with
@@ -32,11 +32,12 @@ export declare function readTemplateFile(relPath: string, destPath: string, opti
32
32
  * rendered: a text asset containing `{= =}`-like sequences travels verbatim, the documented
33
33
  * escape from `scaffold`'s by-value classification (`content-classification` REQ-CCL-04).
34
34
  * `from`/`to` are mandatory; a missing one rejects fail-loud before any emission
35
- * (REQ-FEH-04.1/.2). Source containment (existence, in-ceiling, regular-file) is validated
36
- * SDK-side against real disk BEFORE any directive is emitted — a missing/outside-package/
37
- * non-regular source surfaces the matching `source-*` reason
38
- * (`package-root-containment` REQ-PRC-04, `by-reference-copy-wire` REQ-BRC-06); content is
39
- * never read (`copyIn` never classifies, REQ-FEH-03).
35
+ * (REQ-FEH-04.1/.2). The destination is screened lexically FIRST (design §4 Q2 — a
36
+ * both-escape fixture must yield the destination template), then the source is screened
37
+ * lexically and hygiene-checked against real disk BEFORE any directive is emitted — a
38
+ * missing/non-regular source surfaces the matching `source-*` reason
39
+ * (`package-source-io-hygiene` REQ-PSH-01/02, `by-reference-copy-wire` REQ-BRC-06);
40
+ * content is never read (`copyIn` never classifies, REQ-FEH-03).
40
41
  */
41
42
  export declare function runCopyIn(args: {
42
43
  from: string | undefined;
@@ -6,7 +6,7 @@
6
6
  import { currentContext, requirePackageAnchors } from "../core/context.js";
7
7
  import { invalidInput } from "../core/authoring-error.js";
8
8
  import { forceEntry } from "../core/directive-factory.js";
9
- import { validateSourceContainment, validateDestinationLexical } from "./containment.js";
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
12
12
  // walk → filename-pipeline → classify → emit fan-out, ADR-0044); re-exported here so
@@ -30,13 +30,13 @@ export { isSniffableText } from "./classify-transport.js";
30
30
  * Reads a package-local file (relative to the active run's `packageDir`) and returns its
31
31
  * content as the string to use for a `create({ templateFile })` render request.
32
32
  *
33
- * Containment (S-005, verify-in-loop-4 Deviation #1 ruling): the path is validated through
34
- * the SAME `validateSourceContainment` machinery `scaffold`/`copyIn` already use
35
- * (`package-root-containment` REQ-PRC-01..08) BEFORE any content read — a missing/
36
- * outside-package/non-regular/unreadable source surfaces the matching neutral `source-*`
37
- * `AuthoringReason` (REQ-AEC-10/11), never a parallel templateFile-only check. The whole
38
- * containment → stat-size (REQ-CCL-06 posture) → read → sniff (REQ-CCL-01/03) → budget
39
- * (REQ-CCL-02) chain is `classifyTransport`'s — ONE gate engine for both callers. A
33
+ * ADR-0077: the path is screened lexically (`validateSourceLexical`, `ir-path-well-formedness`
34
+ * REQ-IPF-01) then hygiene-checked through the SAME `statSourceForRead` machinery
35
+ * `scaffold`/`copyIn` already use (`package-source-io-hygiene` REQ-PSH-01..03) BEFORE any
36
+ * content read — a missing/non-regular/unreadable source surfaces the matching neutral
37
+ * `source-*` `AuthoringReason` (REQ-AEC-10/11), never a parallel templateFile-only check.
38
+ * The whole hygiene → stat-size (REQ-CCL-06 posture) → read → sniff (REQ-CCL-01/03) →
39
+ * budget (REQ-CCL-02) chain is `classifyTransport`'s — ONE gate engine for both callers. A
40
40
  * `templateFile` REQUESTS a render — unlike `scaffold`'s by-value/by-reference
41
41
  * classification of unmarked files, there is no silent by-reference fallback here
42
42
  * (REQ-FEH-02): invalid UTF-8, a null byte, or an over-budget file all fail loud with
@@ -50,10 +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, packageRoot } = requirePackageAnchors(noResolutionAnchorMessage(relPath));
53
+ const { packageDir } = requirePackageAnchors(noResolutionAnchorMessage(relPath));
54
+ validateSourceLexical(relPath);
54
55
  return classifyTransport({
55
56
  packageDir,
56
- packageRoot,
57
57
  relPath,
58
58
  isTemplateMarked: false,
59
59
  destPath,
@@ -78,11 +78,12 @@ function noResolutionAnchorForCopyInMessage() {
78
78
  * rendered: a text asset containing `{= =}`-like sequences travels verbatim, the documented
79
79
  * escape from `scaffold`'s by-value classification (`content-classification` REQ-CCL-04).
80
80
  * `from`/`to` are mandatory; a missing one rejects fail-loud before any emission
81
- * (REQ-FEH-04.1/.2). Source containment (existence, in-ceiling, regular-file) is validated
82
- * SDK-side against real disk BEFORE any directive is emitted — a missing/outside-package/
83
- * non-regular source surfaces the matching `source-*` reason
84
- * (`package-root-containment` REQ-PRC-04, `by-reference-copy-wire` REQ-BRC-06); content is
85
- * never read (`copyIn` never classifies, REQ-FEH-03).
81
+ * (REQ-FEH-04.1/.2). The destination is screened lexically FIRST (design §4 Q2 — a
82
+ * both-escape fixture must yield the destination template), then the source is screened
83
+ * lexically and hygiene-checked against real disk BEFORE any directive is emitted — a
84
+ * missing/non-regular source surfaces the matching `source-*` reason
85
+ * (`package-source-io-hygiene` REQ-PSH-01/02, `by-reference-copy-wire` REQ-BRC-06);
86
+ * content is never read (`copyIn` never classifies, REQ-FEH-03).
86
87
  */
87
88
  export function runCopyIn(args) {
88
89
  if (args.from === undefined) {
@@ -92,8 +93,11 @@ export function runCopyIn(args) {
92
93
  throw invalidInput(missingCopyInArgMessage("to"));
93
94
  }
94
95
  const { session, factory } = currentContext();
95
- const { packageDir, packageRoot } = requirePackageAnchors(noResolutionAnchorForCopyInMessage());
96
- validateSourceContainment({ packageDir, packageRoot, relPath: args.from });
96
+ const { packageDir } = requirePackageAnchors(noResolutionAnchorForCopyInMessage());
97
+ // design §4 Q2 — pinned statement order: destination BEFORE source. A both-escape
98
+ // fixture must yield the DESTINATION template, never the source one (REQ-AEC-11.2).
97
99
  validateDestinationLexical(args.to);
100
+ validateSourceLexical(args.from);
101
+ statSourceForRead({ packageDir, relPath: args.from });
98
102
  session.buffer(factory.copyIn({ from: args.from, to: args.to, ...forceEntry(args.force) }));
99
103
  }
@@ -0,0 +1,34 @@
1
+ import { type Stats } from "node:fs";
2
+ import { AuthoringError } from "../core/authoring-error.ts";
3
+ /**
4
+ * Ruling-5 lexical screen (REQ-IPF-01). Segment-aware over `/` and `\`; ANY segment
5
+ * === ".." or an absolute path (POSIX `/` or Windows drive) → `invalid-input`. Zero fs
6
+ * calls. Called at EXACTLY three sites: `readTemplateFile`, `runScaffold` (the walk
7
+ * ROOT `from`), `runCopyIn` (`from`).
8
+ */
9
+ export declare function validateSourceLexical(relPath: string): void;
10
+ type RejectionDetail = "directory" | "permission or I/O error" | "symlink cycle" | "path contains an invalid character";
11
+ export declare function sourceRejection(reason: "source-not-found" | "source-not-regular-file" | "source-unreadable", relPath: string, detail?: RejectionDetail): AuthoringError;
12
+ /**
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.
18
+ */
19
+ export declare function statSourceForRead(params: {
20
+ packageDir: string;
21
+ relPath: string;
22
+ }): {
23
+ absPath: string;
24
+ stat: Stats;
25
+ };
26
+ /**
27
+ * Validates a FINAL, SDK-computed DESTINATION path (`scaffold`'s computed `to`, or
28
+ * `copyIn`'s `to`) — LEXICAL ONLY, never disk-canonicalized (the destination may not exist yet,
29
+ * `ir-path-well-formedness` REQ-IPF-02). Applied post-rename, post-token-translation,
30
+ * immediately pre-emit. Rejects with the EXISTING `invalid-input` reason (scaffold-family
31
+ * author misuse) — never a `source-*` reason, which is reserved for source READS.
32
+ */
33
+ export declare function validateDestinationLexical(relPath: string): void;
34
+ export {};
@@ -0,0 +1,140 @@
1
+ // src/scaffold/path-guards.ts (ADR-0077): replaces containment.ts. The SDK no longer
2
+ // enforces a containment ceiling — `package-root-containment` is retired wholesale. The
3
+ // SDK's remaining obligation for package-local sources is IO HYGIENE (does this resolve to
4
+ // a readable regular file?) and IR WELL-FORMEDNESS (is the literal path shape emittable?) —
5
+ // never a boundary. Three guards live here (ADR-0077 §G, one shared predicate, ruling 5):
6
+ //
7
+ // 1. `validateSourceLexical` — segment-aware `../`/absolute screen for a SOURCE path
8
+ // (`ir-path-well-formedness` REQ-IPF-01). Zero fs calls. Called at EXACTLY three sites.
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.
12
+ // 3. `validateDestinationLexical` — lexical-only guard for a `to` destination
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";
18
+ // Lexical `../`/absolute screen shared by BOTH the source guard (REQ-IPF-01) and the
19
+ // destination guard (REQ-IPF-02, symmetric by design): a literal ".." segment or an
20
+ // absolute-looking path (POSIX leading `/` or a Windows drive letter) is rejected
21
+ // lexically — no filesystem touch needed.
22
+ function isLexicallyEscaping(relPath) {
23
+ const isAbsolute = relPath.startsWith("/") || /^[A-Za-z]:[\\/]/.test(relPath);
24
+ const segments = relPath.split(/[\\/]+/);
25
+ return isAbsolute || segments.includes("..");
26
+ }
27
+ function sourceLexicalRejectionMessage(relPath) {
28
+ return (`source path invalid: ${relPath} must not contain a '..' segment or be absolute — ` +
29
+ "everything a schematic reads lives inside its package (packageDir)");
30
+ }
31
+ /**
32
+ * Ruling-5 lexical screen (REQ-IPF-01). Segment-aware over `/` and `\`; ANY segment
33
+ * === ".." or an absolute path (POSIX `/` or Windows drive) → `invalid-input`. Zero fs
34
+ * calls. Called at EXACTLY three sites: `readTemplateFile`, `runScaffold` (the walk
35
+ * ROOT `from`), `runCopyIn` (`from`).
36
+ */
37
+ export function validateSourceLexical(relPath) {
38
+ if (typeof relPath !== "string") {
39
+ throw invalidInput("invalid input: source path must be a string");
40
+ }
41
+ if (isLexicallyEscaping(relPath)) {
42
+ throw invalidInput(sourceLexicalRejectionMessage(relPath));
43
+ }
44
+ }
45
+ const UNPRINTABLE_SOURCE_PATH_PLACEHOLDER = "<unprintable source path>";
46
+ function sourceRejectionMessage(reason, displayPath, detail) {
47
+ switch (reason) {
48
+ case "source-not-found":
49
+ return `source file not found: ${displayPath} does not exist in the package`;
50
+ case "source-not-regular-file":
51
+ return detail === "directory"
52
+ ? `source file invalid: ${displayPath} is a directory, not a regular file — use scaffold() to copy a folder`
53
+ : `source file invalid: ${displayPath} is not a regular file`;
54
+ case "source-unreadable":
55
+ return `source file unreadable: ${displayPath} could not be read (${detail})`;
56
+ }
57
+ }
58
+ // REQ-PSH-02.3: when `relPath` is unrepresentable (embedded NUL), the fixed placeholder
59
+ // substitutes for the WHOLE `{path}` slot in the message — never the literal (possibly
60
+ // unprintable) bytes. The `.path` field on the error still carries the real `relPath`
61
+ // (programmatic access, not the human-readable surface). Exported (judgment-day G4(i)):
62
+ // `classify-transport.ts`'s own post-hygiene read failure mints through this SAME helper
63
+ // rather than constructing a bare, category-less `AuthoringError` — the ONE place a
64
+ // `source-unreadable` message is built, so the failure category (REQ-AEC-11.1) can never
65
+ // be silently dropped at a second call site.
66
+ export function sourceRejection(reason, relPath, detail) {
67
+ const displayPath = detail === "path contains an invalid character" ? UNPRINTABLE_SOURCE_PATH_PLACEHOLDER : relPath;
68
+ return new AuthoringError({
69
+ verb: undefined,
70
+ path: relPath,
71
+ reason,
72
+ appliedCount: 0,
73
+ message: sourceRejectionMessage(reason, displayPath, detail),
74
+ });
75
+ }
76
+ /**
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.
82
+ */
83
+ 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);
90
+ }
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
+ }
122
+ function destinationEscapeMessage(relPath) {
123
+ return (`invalid input: destination "${relPath}" escapes the workspace tree ` +
124
+ '(literal ".." segment or absolute path)');
125
+ }
126
+ /**
127
+ * Validates a FINAL, SDK-computed DESTINATION path (`scaffold`'s computed `to`, or
128
+ * `copyIn`'s `to`) — LEXICAL ONLY, never disk-canonicalized (the destination may not exist yet,
129
+ * `ir-path-well-formedness` REQ-IPF-02). Applied post-rename, post-token-translation,
130
+ * immediately pre-emit. Rejects with the EXISTING `invalid-input` reason (scaffold-family
131
+ * author misuse) — never a `source-*` reason, which is reserved for source READS.
132
+ */
133
+ export function validateDestinationLexical(relPath) {
134
+ if (typeof relPath !== "string") {
135
+ throw invalidInput("invalid input: destination path must be a string");
136
+ }
137
+ if (isLexicallyEscaping(relPath)) {
138
+ throw invalidInput(destinationEscapeMessage(relPath));
139
+ }
140
+ }
@@ -7,19 +7,21 @@ export interface WalkEntry {
7
7
  }
8
8
  /**
9
9
  * Enumerates every file under `fromAbs`, mirroring nested directory structure into
10
- * posix-separated `relPath`s (sorted for deterministic output). Symlinked directories are
11
- * NEVER descended — even when their target resolves inside the containment ceiling
12
- * (REQ-FSC-09.1) — skipped silently, no error. Fails loud, naming the bound, once the
13
- * enumerated entry count exceeds `bound` (REQ-FSC-09.2); `bound` is injectable so a test
14
- * can drive the branch without materializing 10,001 real files.
10
+ * posix-separated `relPath`s (sorted for deterministic output). A NESTED symlinked
11
+ * directory is NEVER descended — even when its target resolves inside the package
12
+ * (REQ-FSC-09.1) — skipped silently, no error. The ROOT is held to a stricter standard
13
+ * (owner ruling 16): a symlinked `from` itself is REJECTED (`AuthoringError`,
14
+ * `invalid-input`) rather than followed or silently skipped — a bare no-op would hide a
15
+ * root that resolves to a real, populated directory. Fails loud, naming the bound, once
16
+ * the enumerated entry count exceeds `bound` (REQ-FSC-09.2); `bound` is injectable so a
17
+ * test can drive the branch without materializing 10,001 real files.
15
18
  *
16
- * `rootRelPath` (judgment-day iteration 2 fix, package-root-containment REQ-PRC-10.3
17
- * amendment): the author-facing, package-relative `from` — threaded through SOLELY to name
18
- * the ROOT in an `AuthoringError` message if the root itself is not a readable directory (a
19
- * regular file, or missing — `runScaffold`'s `validateSourceRootContainment` proves the root
20
- * is in-ceiling but deliberately leaves existence/type to this function, see its own
21
- * doc-comment). Recursive sub-directory reads below are NOT re-guarded — every one of them
22
- * enumerates a directory this walk already lstat'd as a directory, so their behavior for a
23
- * valid tree is unchanged.
19
+ * `rootRelPath` (judgment-day iteration 2 fix, extended by ruling 8 / REQ-FSC-10.4): the
20
+ * author-facing, package-relative `from` — threaded through to name BOTH the ROOT and any
21
+ * RECURSIVE entry in an `AuthoringError` message: the root if it itself is not a readable
22
+ * directory (a regular file, or missing — `runScaffold`'s `validateSourceLexical` only
23
+ * screens the root lexically, deliberately leaving existence/type to this function, see its
24
+ * own doc-comment); a nested entry if a recursive `readdirSync`/`lstatSync` fails mid-walk
25
+ * (the entry vanished, or an EACCES mid-tree, REQ-FSC-10.4).
24
26
  */
25
27
  export declare function walkFolder(fromAbs: string, bound?: number, rootRelPath?: string): WalkEntry[];