@pbuilder/sdk 0.3.0 → 0.4.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.
- package/README.md +15 -15
- package/dist/commons/index.d.ts +22 -22
- package/dist/commons/index.js +20 -20
- package/dist/core/authoring-error.d.ts +3 -3
- package/dist/core/authoring-error.js +5 -5
- package/dist/core/context.d.ts +6 -6
- package/dist/core/context.js +18 -18
- package/dist/core/define-dialect.d.ts +1 -1
- package/dist/core/define-dialect.js +1 -1
- package/dist/core/dialect-handle.js +8 -8
- package/dist/core/index.d.ts +1 -1
- package/dist/core/session.d.ts +1 -1
- package/dist/core/session.js +2 -2
- package/dist/dialects/react/index.d.ts +1 -1
- package/dist/dialects/react/index.js +1 -1
- package/dist/dialects/typescript/index.d.ts +2 -2
- package/dist/dialects/typescript/index.js +2 -2
- package/dist/dialects/typescript/ops.js +1 -1
- package/dist/pending-directives/index.d.ts +2 -0
- package/dist/pending-directives/index.js +1 -0
- package/dist/{dry-run/plan.d.ts → pending-directives/render.d.ts} +8 -33
- package/dist/{dry-run/plan.js → pending-directives/render.js} +5 -5
- package/dist/runner-manifest.json +5 -5
- package/dist/scaffold/expander.js +3 -3
- package/dist/scaffold/index.d.ts +1 -1
- package/dist/scaffold/index.js +1 -1
- package/package.json +2 -1
- package/dist/dry-run/index.d.ts +0 -2
- package/dist/dry-run/index.js +0 -1
package/README.md
CHANGED
|
@@ -21,14 +21,14 @@ sequenceDiagram
|
|
|
21
21
|
CLI->>E: start engine
|
|
22
22
|
E->>E: raise staging tree
|
|
23
23
|
E->>F: start Bun sidecar, run factory
|
|
24
|
-
loop
|
|
24
|
+
loop Stage — the SDK ↔ engine conversation
|
|
25
25
|
F->>E: read a file (find().read())
|
|
26
26
|
E-->>F: content, answered from the staging tree
|
|
27
27
|
F->>E: IR directives (create, replaceContent, …)
|
|
28
|
-
E->>E:
|
|
28
|
+
E->>E: stage the Instruction on the staging tree
|
|
29
29
|
end
|
|
30
30
|
F-->>E: factory returns
|
|
31
|
-
E->>E:
|
|
31
|
+
E->>E: Commit — the Plan is written to disk
|
|
32
32
|
E-->>CLI: result
|
|
33
33
|
CLI-->>U: ✓ done
|
|
34
34
|
```
|
|
@@ -41,10 +41,10 @@ sequenceDiagram
|
|
|
41
41
|
testing harness — and lowers everything you author into a small, stable **IR**
|
|
42
42
|
(instruction records). It holds a conversation with the engine over framed stdio: reads
|
|
43
43
|
come back from the staging tree, directives go out as IR. It never writes to disk.
|
|
44
|
-
- The **engine** owns execution, in two
|
|
44
|
+
- The **engine** owns execution, in two steps. During the Run, it **stages**:
|
|
45
45
|
it raises the staging tree, starts the Bun sidecar that runs your factory, answers its
|
|
46
|
-
read-backs, and
|
|
47
|
-
factory returns does
|
|
46
|
+
read-backs, and stages every incoming IR Instruction on the staging tree. Only after the
|
|
47
|
+
factory returns does it **commit**: the staged result is written to disk.
|
|
48
48
|
The engine is the only component that ever writes — and a failed run writes nothing.
|
|
49
49
|
|
|
50
50
|
That staging tree is what makes a schematic a conversation rather than a one-shot: while
|
|
@@ -304,7 +304,7 @@ Everything a factory can do to the tree is one of seven mutation verbs, all impo
|
|
|
304
304
|
| [`rename(path, newName)`](./docs/authoring-verbs.md#rename) | A basename-only rename in place. |
|
|
305
305
|
| [`move(path, toDir)`](./docs/authoring-verbs.md#move) | A move to a different directory. |
|
|
306
306
|
| [`copy(from, to)`](./docs/authoring-verbs.md#copy) | A tree-to-tree copy, chainable via the returned handle. |
|
|
307
|
-
| [`copyIn(from, to)`](./docs/authoring-verbs.md#copyin) | A package-local file copied into the tree **verbatim** —
|
|
307
|
+
| [`copyIn(from, to)`](./docs/authoring-verbs.md#copyin) | A package-local file copied into the tree **verbatim** — never rendered. |
|
|
308
308
|
|
|
309
309
|
The verbs that write to a new path — `create`, `rename`, `move`, `copy`, `copyIn`, and
|
|
310
310
|
`scaffold` — are fail-closed on collision and accept `{ force: true }` for a deliberate
|
|
@@ -318,7 +318,7 @@ Three companions round out the surface:
|
|
|
318
318
|
- [`scaffold({ from, to, options })`](./docs/authoring-verbs.md#scaffold) — mirror an
|
|
319
319
|
entire package-local folder into the tree, with dynamic file names. The workhorse for
|
|
320
320
|
multi-file generators — see [Scaffolding a folder of templates](#scaffolding-a-folder-of-templates).
|
|
321
|
-
- [`
|
|
321
|
+
- [`pendingDirectives()`](./docs/pending-directives.md) — inspect the directives still **pending**. A `read()`
|
|
322
322
|
drains the buffer, so call it before reading if you want the full picture.
|
|
323
323
|
|
|
324
324
|
### What to keep in mind
|
|
@@ -337,9 +337,9 @@ Rules that save you real debugging time — each one is a mistake we've watched
|
|
|
337
337
|
example shows the read-back mechanics — a production factory would also skip the append
|
|
338
338
|
when the name is already listed.
|
|
339
339
|
- **Nothing touches disk while your factory runs.** Verbs *schedule* directives; during the
|
|
340
|
-
|
|
341
|
-
created earlier in the same run sees the staged content). Disk writes happen
|
|
342
|
-
|
|
340
|
+
Run the engine stages them on the staging tree only (that's why reading a path you
|
|
341
|
+
created earlier in the same run sees the staged content). Disk writes happen at Commit,
|
|
342
|
+
after the factory returns — a thrown error before return means nothing is written
|
|
343
343
|
at all.
|
|
344
344
|
- **Errors are structured.** A rejected run surfaces an `AuthoringError` with
|
|
345
345
|
`verb`/`path`/`reason` fields telling you which directive failed and why (one label
|
|
@@ -409,7 +409,7 @@ Two traps worth knowing before they bite: **empty arrays and objects are falsy**
|
|
|
409
409
|
the numeric type** they're compared against (option numbers are decimals: `eq .count 2.0`,
|
|
410
410
|
never `eq .count 2`).
|
|
411
411
|
|
|
412
|
-
If templating gets in your way,
|
|
412
|
+
If templating gets in your way, there is always a way out: build the final
|
|
413
413
|
strings in TypeScript and pass a token-free template — it renders verbatim. For the full
|
|
414
414
|
language — `with`, variables, whitespace rules, output-path templating, sandbox limits, and
|
|
415
415
|
the error taxonomy — see [Authoring `create` templates](./docs/create-templates.md).
|
|
@@ -596,7 +596,7 @@ untrusted input is the author's responsibility to sanitize.
|
|
|
596
596
|
|
|
597
597
|
Mutates `.tsx` files — `find()` requires the explicit `.tsx` extension (extensionless and
|
|
598
598
|
`.jsx` paths are rejected, never normalized). The v1 op-pack — a dialect's bundle of named
|
|
599
|
-
ops — is deliberately minimal: two
|
|
599
|
+
ops — is deliberately minimal: two named ops, with `.modify(fn)` as the escape hatch
|
|
600
600
|
for everything else:
|
|
601
601
|
|
|
602
602
|
```ts
|
|
@@ -625,7 +625,7 @@ a trailing `{...spread}`, so it **wins** at runtime under React's later-position
|
|
|
625
625
|
Every dialect handle carries one universal op alongside its named ops: `.modify(ast => …)`.
|
|
626
626
|
Your callback receives the **same live AST instance the named ops mutate** — a ts-morph
|
|
627
627
|
`SourceFile` — so anything a named op could do, `.modify()` can do too, without waiting for
|
|
628
|
-
a
|
|
628
|
+
a named op to exist:
|
|
629
629
|
|
|
630
630
|
```ts
|
|
631
631
|
import * as ts from "@pbuilder/sdk/typescript";
|
|
@@ -673,7 +673,7 @@ The full reading path lives in [`docs/`](./docs/README.md):
|
|
|
673
673
|
2. [Authoring verbs](./docs/authoring-verbs.md) — the seven verbs + `find().read()` in full.
|
|
674
674
|
3. [Authoring `create` templates](./docs/create-templates.md) — the template language.
|
|
675
675
|
4. [Error contract](./docs/authoring-errors.md) — `AuthoringError` and recovery.
|
|
676
|
-
5. [
|
|
676
|
+
5. [Pending Directives](./docs/pending-directives.md) — previewing pending changes.
|
|
677
677
|
6. [Authoring a dialect](./docs/authoring-a-dialect.md) — AST-aware mutation per file type.
|
|
678
678
|
|
|
679
679
|
## Design at a glance
|
package/dist/commons/index.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export interface CreateOptions {
|
|
|
25
25
|
/**
|
|
26
26
|
* Options for the `create({ templateFile })` render request — an explicit, package-local
|
|
27
27
|
* alternative to an inline `template` string (REQ-FEH-01). `templateFile` is a
|
|
28
|
-
* package-relative path (resolved against the active
|
|
28
|
+
* package-relative path (resolved against the active Session's `packageDir`), read at
|
|
29
29
|
* emission time; its content becomes the `create` directive's `template` field —
|
|
30
30
|
* the existing `create` IR, zero wire change. `templateFile` REQUESTS a render: a binary
|
|
31
31
|
* or oversized source fails loud (`invalid-input`), it never silently falls back to a
|
|
@@ -69,12 +69,12 @@ export declare function find(path: string): FoundHandle;
|
|
|
69
69
|
*
|
|
70
70
|
* Creating over an existing file is rejected at the engine seam unless
|
|
71
71
|
* `{ force: true }` is passed (overwrite-on-collision, ADR-0017 fail-closed) — a
|
|
72
|
-
* rejected
|
|
72
|
+
* rejected Session throws `AuthoringError`.
|
|
73
73
|
*
|
|
74
74
|
* `templateFile` is a THIRD overload (REQ-FEH-01): pass a package-local path instead of an
|
|
75
75
|
* inline `template` string — its content is read at emission time and becomes the
|
|
76
76
|
* directive's `template` field. `template` and `templateFile` are mutually exclusive forms;
|
|
77
|
-
* only usable inside a factory
|
|
77
|
+
* only usable inside a factory invocation started with packageDir (there is no resolution anchor
|
|
78
78
|
* to read a package-local file against otherwise — `invalid-input`, never a cwd fallback).
|
|
79
79
|
* `templateFile`'s VALUE is a literal package-relative path, read verbatim by CONTENT —
|
|
80
80
|
* it is NOT run through `scaffold`'s filename pipeline (no rename remap, no `__x__` token
|
|
@@ -121,7 +121,7 @@ export declare function create(path: string, opts: CreateFromTemplateFileOptions
|
|
|
121
121
|
*/
|
|
122
122
|
export type ScaffoldOptions = ScaffoldArgs;
|
|
123
123
|
/**
|
|
124
|
-
* Walks a package-local folder (`from`, resolved against the active
|
|
124
|
+
* Walks a package-local folder (`from`, resolved against the active Session's `packageDir`)
|
|
125
125
|
* and mirrors every entry into `to`, applying the rename → filename-token-translation →
|
|
126
126
|
* `.template`-strip pipeline (REQ-FSC-05) and include/exclude glob filtering (REQ-FSC-03,
|
|
127
127
|
* `exclude` wins on overlap). Each source classifies by-value or by-reference
|
|
@@ -132,7 +132,7 @@ export type ScaffoldOptions = ScaffoldArgs;
|
|
|
132
132
|
* `false`) passes through unchanged to every emitted directive, no per-file override
|
|
133
133
|
* (REQ-FSC-06). Two or more sources collapsing to the same destination reject fail-loud,
|
|
134
134
|
* naming every offending source (REQ-FSC-08). Only usable inside a
|
|
135
|
-
* factory
|
|
135
|
+
* factory invocation started with packageDir — there is no resolution anchor to walk a
|
|
136
136
|
* package-local folder against otherwise (`invalid-input`, never a cwd fallback).
|
|
137
137
|
*
|
|
138
138
|
* `rename` is a static REMAP TABLE (`Record<originalSourceRelativePath,
|
|
@@ -176,7 +176,7 @@ export declare function scaffold(args: ScaffoldOptions): void;
|
|
|
176
176
|
* `from`/`to` are mandatory; `force` defaults `false`. A missing `from`/`to` rejects
|
|
177
177
|
* fail-loud before any emission (REQ-FEH-04.1/.2). Collision without `force` rejects;
|
|
178
178
|
* `force: true` overwrites (`by-reference-copy-wire` REQ-BRC-05). Only usable inside a
|
|
179
|
-
* factory
|
|
179
|
+
* factory invocation started with packageDir — there is no resolution anchor to read a
|
|
180
180
|
* package-local file against otherwise (`invalid-input`, never a cwd fallback).
|
|
181
181
|
*
|
|
182
182
|
* Returns `void` (REQ-FEH-04.3) — NOT a `WritableHandle`, unlike `copy`: a by-reference
|
|
@@ -193,7 +193,7 @@ export declare function copyIn(from: string, to: string, opts?: {
|
|
|
193
193
|
}): void;
|
|
194
194
|
/**
|
|
195
195
|
* Schedules an in-place content replacement for an existing file and returns a `WritableHandle`.
|
|
196
|
-
* A rejected
|
|
196
|
+
* A rejected Session (e.g. the target does not exist) throws `AuthoringError`.
|
|
197
197
|
*
|
|
198
198
|
* @example
|
|
199
199
|
* replaceContent("src/config.json", '{ "version": "2.0.0" }');
|
|
@@ -210,7 +210,7 @@ export declare function remove(path: string): void;
|
|
|
210
210
|
* Schedules a file rename (basename only) and returns a `WritableHandle` for the new path.
|
|
211
211
|
* Renaming onto an existing path is rejected at the engine seam unless
|
|
212
212
|
* `{ force: true }` is passed (overwrite-on-collision, ADR-0017 fail-closed) — a
|
|
213
|
-
* rejected
|
|
213
|
+
* rejected Session throws `AuthoringError`.
|
|
214
214
|
*
|
|
215
215
|
* @example
|
|
216
216
|
* rename("src/foo.ts", "bar.ts");
|
|
@@ -222,7 +222,7 @@ export declare function rename(path: string, newName: string, opts?: {
|
|
|
222
222
|
* Schedules a file move to a different directory and returns a `WritableHandle`.
|
|
223
223
|
* Moving onto an existing destination is rejected at the engine seam unless
|
|
224
224
|
* `{ force: true }` is passed (overwrite-on-collision, ADR-0017 fail-closed) — a
|
|
225
|
-
* rejected
|
|
225
|
+
* rejected Session throws `AuthoringError`.
|
|
226
226
|
* A move whose destination equals its source is a no-op, never a collision
|
|
227
227
|
* (ADR-0017 self-move amendment).
|
|
228
228
|
*
|
|
@@ -236,7 +236,7 @@ export declare function move(path: string, toDir: string, opts?: {
|
|
|
236
236
|
* Schedules a file copy to a new path and returns a `WritableHandle` for the destination.
|
|
237
237
|
* Copying onto an existing destination is rejected at the engine seam unless
|
|
238
238
|
* `{ force: true }` is passed (overwrite-on-collision, ADR-0017 fail-closed) — a
|
|
239
|
-
* rejected
|
|
239
|
+
* rejected Session throws `AuthoringError`.
|
|
240
240
|
*
|
|
241
241
|
* @example
|
|
242
242
|
* copy("src/template.ts", "src/generated/output.ts");
|
|
@@ -244,15 +244,15 @@ export declare function move(path: string, toDir: string, opts?: {
|
|
|
244
244
|
export declare function copy(from: string, to: string, opts?: {
|
|
245
245
|
force?: boolean;
|
|
246
246
|
}): WritableHandle;
|
|
247
|
-
import type {
|
|
248
|
-
export type {
|
|
247
|
+
import type { PendingDirective } from "../pending-directives/render.ts";
|
|
248
|
+
export type { PendingDirective };
|
|
249
249
|
/**
|
|
250
|
-
* Returns the
|
|
251
|
-
*
|
|
250
|
+
* Returns the Directives still pending in the active Session's buffer, rendered in
|
|
251
|
+
* author vocabulary.
|
|
252
252
|
*
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
*
|
|
253
|
+
* Only what is still pending appears — the honest answer to "what will this Session
|
|
254
|
+
* still emit", not "what has this Session emitted in total." A `read()` (or any flush)
|
|
255
|
+
* drains the pending buffer, so Directives already sent no longer appear.
|
|
256
256
|
*
|
|
257
257
|
* Entries carry verb and path — no content or byte preview — plus an optional `kind`
|
|
258
258
|
* (`"rendered" | "copied"`) present only on the package-local-read verbs whose transport
|
|
@@ -260,19 +260,19 @@ export type { DryRunEntry, DryRunVerb };
|
|
|
260
260
|
* (`kind: "copied"`). The tree→tree `copy` verb also materializes content but predates
|
|
261
261
|
* this axis and is never package-local-read/classified, so it carries no `kind`.
|
|
262
262
|
*
|
|
263
|
-
* Call it inside an active factory
|
|
263
|
+
* Call it inside an active factory invocation, like every other `./commons` verb.
|
|
264
264
|
*
|
|
265
265
|
* @example
|
|
266
266
|
* const run = () => {
|
|
267
267
|
* create("src/index.ts", { template: "export const version = '1.0.0';", options: {} });
|
|
268
268
|
* find("src/legacy.ts").remove();
|
|
269
|
-
* for (const entry of
|
|
269
|
+
* for (const entry of pendingDirectives()) {
|
|
270
270
|
* console.log(entry.verb, entry.path); // "create src/index.ts", then "remove src/legacy.ts"
|
|
271
271
|
* }
|
|
272
272
|
* };
|
|
273
273
|
*
|
|
274
|
-
* @throws When called outside an active factory
|
|
274
|
+
* @throws When called outside an active factory invocation, propagates the standard
|
|
275
275
|
* error — authoring verbs "can only be used while a schematic is running" (ADR-0026: the
|
|
276
|
-
* message no longer enumerates individual verbs, so it covers `
|
|
276
|
+
* message no longer enumerates individual verbs, so it covers `pendingDirectives` too).
|
|
277
277
|
*/
|
|
278
|
-
export declare function
|
|
278
|
+
export declare function pendingDirectives(): PendingDirective[];
|
package/dist/commons/index.js
CHANGED
|
@@ -108,7 +108,7 @@ export function create(path, opts) {
|
|
|
108
108
|
return buildWritableHandle(path);
|
|
109
109
|
}
|
|
110
110
|
/**
|
|
111
|
-
* Walks a package-local folder (`from`, resolved against the active
|
|
111
|
+
* Walks a package-local folder (`from`, resolved against the active Session's `packageDir`)
|
|
112
112
|
* and mirrors every entry into `to`, applying the rename → filename-token-translation →
|
|
113
113
|
* `.template`-strip pipeline (REQ-FSC-05) and include/exclude glob filtering (REQ-FSC-03,
|
|
114
114
|
* `exclude` wins on overlap). Each source classifies by-value or by-reference
|
|
@@ -119,7 +119,7 @@ export function create(path, opts) {
|
|
|
119
119
|
* `false`) passes through unchanged to every emitted directive, no per-file override
|
|
120
120
|
* (REQ-FSC-06). Two or more sources collapsing to the same destination reject fail-loud,
|
|
121
121
|
* naming every offending source (REQ-FSC-08). Only usable inside a
|
|
122
|
-
* factory
|
|
122
|
+
* factory invocation started with packageDir — there is no resolution anchor to walk a
|
|
123
123
|
* package-local folder against otherwise (`invalid-input`, never a cwd fallback).
|
|
124
124
|
*
|
|
125
125
|
* `rename` is a static REMAP TABLE (`Record<originalSourceRelativePath,
|
|
@@ -165,7 +165,7 @@ export function scaffold(args) {
|
|
|
165
165
|
* `from`/`to` are mandatory; `force` defaults `false`. A missing `from`/`to` rejects
|
|
166
166
|
* fail-loud before any emission (REQ-FEH-04.1/.2). Collision without `force` rejects;
|
|
167
167
|
* `force: true` overwrites (`by-reference-copy-wire` REQ-BRC-05). Only usable inside a
|
|
168
|
-
* factory
|
|
168
|
+
* factory invocation started with packageDir — there is no resolution anchor to read a
|
|
169
169
|
* package-local file against otherwise (`invalid-input`, never a cwd fallback).
|
|
170
170
|
*
|
|
171
171
|
* Returns `void` (REQ-FEH-04.3) — NOT a `WritableHandle`, unlike `copy`: a by-reference
|
|
@@ -182,7 +182,7 @@ export function copyIn(from, to, opts) {
|
|
|
182
182
|
}
|
|
183
183
|
/**
|
|
184
184
|
* Schedules an in-place content replacement for an existing file and returns a `WritableHandle`.
|
|
185
|
-
* A rejected
|
|
185
|
+
* A rejected Session (e.g. the target does not exist) throws `AuthoringError`.
|
|
186
186
|
*
|
|
187
187
|
* @example
|
|
188
188
|
* replaceContent("src/config.json", '{ "version": "2.0.0" }');
|
|
@@ -206,7 +206,7 @@ export function remove(path) {
|
|
|
206
206
|
* Schedules a file rename (basename only) and returns a `WritableHandle` for the new path.
|
|
207
207
|
* Renaming onto an existing path is rejected at the engine seam unless
|
|
208
208
|
* `{ force: true }` is passed (overwrite-on-collision, ADR-0017 fail-closed) — a
|
|
209
|
-
* rejected
|
|
209
|
+
* rejected Session throws `AuthoringError`.
|
|
210
210
|
*
|
|
211
211
|
* @example
|
|
212
212
|
* rename("src/foo.ts", "bar.ts");
|
|
@@ -221,7 +221,7 @@ export function rename(path, newName, opts) {
|
|
|
221
221
|
* Schedules a file move to a different directory and returns a `WritableHandle`.
|
|
222
222
|
* Moving onto an existing destination is rejected at the engine seam unless
|
|
223
223
|
* `{ force: true }` is passed (overwrite-on-collision, ADR-0017 fail-closed) — a
|
|
224
|
-
* rejected
|
|
224
|
+
* rejected Session throws `AuthoringError`.
|
|
225
225
|
* A move whose destination equals its source is a no-op, never a collision
|
|
226
226
|
* (ADR-0017 self-move amendment).
|
|
227
227
|
*
|
|
@@ -237,7 +237,7 @@ export function move(path, toDir, opts) {
|
|
|
237
237
|
* Schedules a file copy to a new path and returns a `WritableHandle` for the destination.
|
|
238
238
|
* Copying onto an existing destination is rejected at the engine seam unless
|
|
239
239
|
* `{ force: true }` is passed (overwrite-on-collision, ADR-0017 fail-closed) — a
|
|
240
|
-
* rejected
|
|
240
|
+
* rejected Session throws `AuthoringError`.
|
|
241
241
|
*
|
|
242
242
|
* @example
|
|
243
243
|
* copy("src/template.ts", "src/generated/output.ts");
|
|
@@ -247,15 +247,15 @@ export function copy(from, to, opts) {
|
|
|
247
247
|
session.buffer(factory.copy({ from, to, ...forceEntry(opts?.force) }));
|
|
248
248
|
return buildWritableHandle(to);
|
|
249
249
|
}
|
|
250
|
-
// --- Stage 3:
|
|
251
|
-
import {
|
|
250
|
+
// --- Stage 3: pending Directives exposure (REQ-DRE-01..04) ---
|
|
251
|
+
import { renderPendingDirectives } from "../pending-directives/index.js";
|
|
252
252
|
/**
|
|
253
|
-
* Returns the
|
|
254
|
-
*
|
|
253
|
+
* Returns the Directives still pending in the active Session's buffer, rendered in
|
|
254
|
+
* author vocabulary.
|
|
255
255
|
*
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
*
|
|
256
|
+
* Only what is still pending appears — the honest answer to "what will this Session
|
|
257
|
+
* still emit", not "what has this Session emitted in total." A `read()` (or any flush)
|
|
258
|
+
* drains the pending buffer, so Directives already sent no longer appear.
|
|
259
259
|
*
|
|
260
260
|
* Entries carry verb and path — no content or byte preview — plus an optional `kind`
|
|
261
261
|
* (`"rendered" | "copied"`) present only on the package-local-read verbs whose transport
|
|
@@ -263,21 +263,21 @@ import { dryRunPlan } from "../dry-run/index.js";
|
|
|
263
263
|
* (`kind: "copied"`). The tree→tree `copy` verb also materializes content but predates
|
|
264
264
|
* this axis and is never package-local-read/classified, so it carries no `kind`.
|
|
265
265
|
*
|
|
266
|
-
* Call it inside an active factory
|
|
266
|
+
* Call it inside an active factory invocation, like every other `./commons` verb.
|
|
267
267
|
*
|
|
268
268
|
* @example
|
|
269
269
|
* const run = () => {
|
|
270
270
|
* create("src/index.ts", { template: "export const version = '1.0.0';", options: {} });
|
|
271
271
|
* find("src/legacy.ts").remove();
|
|
272
|
-
* for (const entry of
|
|
272
|
+
* for (const entry of pendingDirectives()) {
|
|
273
273
|
* console.log(entry.verb, entry.path); // "create src/index.ts", then "remove src/legacy.ts"
|
|
274
274
|
* }
|
|
275
275
|
* };
|
|
276
276
|
*
|
|
277
|
-
* @throws When called outside an active factory
|
|
277
|
+
* @throws When called outside an active factory invocation, propagates the standard
|
|
278
278
|
* error — authoring verbs "can only be used while a schematic is running" (ADR-0026: the
|
|
279
|
-
* message no longer enumerates individual verbs, so it covers `
|
|
279
|
+
* message no longer enumerates individual verbs, so it covers `pendingDirectives` too).
|
|
280
280
|
*/
|
|
281
|
-
export function
|
|
282
|
-
return
|
|
281
|
+
export function pendingDirectives() {
|
|
282
|
+
return renderPendingDirectives(currentContext().session.pendingDirectives());
|
|
283
283
|
}
|
|
@@ -45,7 +45,7 @@ export type AuthoringVerb = "create" | "modify" | "remove" | "rename" | "move" |
|
|
|
45
45
|
* case "path-not-found":
|
|
46
46
|
* case "unrepresentable-content":
|
|
47
47
|
* case "changes-too-large":
|
|
48
|
-
* case "outside-
|
|
48
|
+
* case "outside-session":
|
|
49
49
|
* case "unknown":
|
|
50
50
|
* case "invalid-input":
|
|
51
51
|
* case "reserved-name":
|
|
@@ -56,7 +56,7 @@ export type AuthoringVerb = "create" | "modify" | "remove" | "rename" | "move" |
|
|
|
56
56
|
* break;
|
|
57
57
|
* }
|
|
58
58
|
*/
|
|
59
|
-
export type AuthoringReason = "path-collision" | "path-not-found" | "unrepresentable-content" | "changes-too-large" | "outside-
|
|
59
|
+
export type AuthoringReason = "path-collision" | "path-not-found" | "unrepresentable-content" | "changes-too-large" | "outside-session" | "unknown" | "invalid-input" | "reserved-name" | "source-not-found" | "source-not-regular-file" | "source-unreadable";
|
|
60
60
|
/**
|
|
61
61
|
* Distinguishes an engine-refused write from an SDK-side misuse (2.4, ADR-0021) —
|
|
62
62
|
* DERIVED from `reason`, never producer-set.
|
|
@@ -95,7 +95,7 @@ export declare class AuthoringError extends Error {
|
|
|
95
95
|
readonly origin: AuthoringOrigin;
|
|
96
96
|
/**
|
|
97
97
|
* Counts directives applied within the failing flush before the offender — a
|
|
98
|
-
* diagnostic for locating progress, NOT a persistence promise (a rejected
|
|
98
|
+
* diagnostic for locating progress, NOT a persistence promise (a rejected Session
|
|
99
99
|
* discards everything, ADR-0015).
|
|
100
100
|
*/
|
|
101
101
|
readonly appliedCount: number;
|
|
@@ -16,7 +16,7 @@ import { EmitRejection } from "./emit-rejection.js";
|
|
|
16
16
|
// an unclassifiable rejection necessarily arrived through the emit/write seam (the only
|
|
17
17
|
// place toAuthoringError runs), so the write side is the honest attribution (spec
|
|
18
18
|
// cross-cutting note 7). `invalid-input`/`reserved-name` (V2 → V3 amendment, REQ-AEC-07/08)
|
|
19
|
-
// are ALWAYS "authoring-rejected" — same rationale as outside-
|
|
19
|
+
// are ALWAYS "authoring-rejected" — same rationale as outside-session: an SDK-side misuse
|
|
20
20
|
// detection, not an engine round-trip refusal. The three surviving `source-*` reasons
|
|
21
21
|
// (`schematic-local-files` S-002, REQ-AEC-10; `source-outside-package` retired by
|
|
22
22
|
// `inline-collection-marker` S-002, ADR-0077) are likewise ALWAYS "authoring-rejected" —
|
|
@@ -30,7 +30,7 @@ function originFor(reason) {
|
|
|
30
30
|
case "changes-too-large":
|
|
31
31
|
case "unknown":
|
|
32
32
|
return "write-rejected";
|
|
33
|
-
case "outside-
|
|
33
|
+
case "outside-session":
|
|
34
34
|
case "invalid-input":
|
|
35
35
|
case "reserved-name":
|
|
36
36
|
case "source-not-found":
|
|
@@ -81,7 +81,7 @@ function primaryPath(directive) {
|
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
// REQ-AEC-06: message templates selected BY REASON, three-way — never by verb/path
|
|
84
|
-
// presence. `outside-
|
|
84
|
+
// presence. `outside-session` also has verb/path undefined but must NOT get the batch
|
|
85
85
|
// template (the context.test.ts:12 substring pin would break).
|
|
86
86
|
//
|
|
87
87
|
// REQ-AEC-09 (V2 → V3 amendment) adds two MORE families (invalid-input's two variants,
|
|
@@ -105,7 +105,7 @@ function messageFor(reason, verb, path) {
|
|
|
105
105
|
case "path-collision":
|
|
106
106
|
case "path-not-found":
|
|
107
107
|
return `${verb} failed at ${path}: ${reason}`;
|
|
108
|
-
case "outside-
|
|
108
|
+
case "outside-session":
|
|
109
109
|
return ("@pbuilder/sdk: authoring verbs can only be used while a schematic is running — " +
|
|
110
110
|
"call them inside your factory function, not at module load time.");
|
|
111
111
|
case "unrepresentable-content":
|
|
@@ -159,7 +159,7 @@ export class AuthoringError extends Error {
|
|
|
159
159
|
origin;
|
|
160
160
|
/**
|
|
161
161
|
* Counts directives applied within the failing flush before the offender — a
|
|
162
|
-
* diagnostic for locating progress, NOT a persistence promise (a rejected
|
|
162
|
+
* diagnostic for locating progress, NOT a persistence promise (a rejected Session
|
|
163
163
|
* discards everything, ADR-0015).
|
|
164
164
|
*/
|
|
165
165
|
appliedCount;
|
package/dist/core/context.d.ts
CHANGED
|
@@ -8,26 +8,26 @@ export interface DialectRegistry {
|
|
|
8
8
|
}): void;
|
|
9
9
|
drain(): Promise<void>;
|
|
10
10
|
}
|
|
11
|
-
export interface
|
|
11
|
+
export interface SessionContext {
|
|
12
12
|
session: Session;
|
|
13
13
|
factory: DirectiveFactory;
|
|
14
14
|
dialects: DialectRegistry;
|
|
15
|
-
|
|
15
|
+
sessionFailure?: {
|
|
16
16
|
reason: unknown;
|
|
17
17
|
};
|
|
18
18
|
packageAnchors?: {
|
|
19
19
|
packageDir: string;
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
-
export declare const
|
|
23
|
-
export declare function
|
|
22
|
+
export declare const SESSION_ALS_REGISTRY_KEY = "@pbuilder/sdk:core/context#session-als";
|
|
23
|
+
export declare function resolveSessionAls(slotValue: unknown): AsyncLocalStorage<SessionContext>;
|
|
24
24
|
export declare function isDefineFactoryWrapped(value: unknown): boolean;
|
|
25
|
-
export declare function currentContext():
|
|
25
|
+
export declare function currentContext(): SessionContext;
|
|
26
26
|
export declare function requirePackageAnchors(missingAnchorMessage: string): {
|
|
27
27
|
packageDir: string;
|
|
28
28
|
};
|
|
29
29
|
/**
|
|
30
|
-
* Builds a
|
|
30
|
+
* Builds a SessionContext and runs the factory inside it, flushing buffered
|
|
31
31
|
* directives at run end (REQ-KIT-05) — a write-only factory still emits.
|
|
32
32
|
*
|
|
33
33
|
* All-or-nothing contract (ADR-01): on success the full directive batch is committed;
|
package/dist/core/context.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// KIT-05: Ambient
|
|
1
|
+
// KIT-05: Ambient SessionContext via AsyncLocalStorage.
|
|
2
2
|
// defineFactory returns a runner that builds the context and runs fn inside the ALS.
|
|
3
3
|
// The EngineClient is injected by the caller (test passes the fake) — no module global.
|
|
4
4
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
@@ -33,11 +33,11 @@ class DialectRegistryImpl {
|
|
|
33
33
|
}
|
|
34
34
|
// context-singleton-fix (REQ-MIS-01/02, design §4.3): a module-scope `als` is realm-local —
|
|
35
35
|
// when `dist/bin/pbuilder-runner.js` and a src-relative `.ts` factory co-execute in one Bun
|
|
36
|
-
// process, each resolves its OWN copy of this module and its OWN `als`, so a
|
|
36
|
+
// process, each resolves its OWN copy of this module and its OWN `als`, so a Session entered in
|
|
37
37
|
// one realm is invisible to `currentContext()` in the other. The store is therefore parked at
|
|
38
|
-
// `globalThis[Symbol.for(
|
|
38
|
+
// `globalThis[Symbol.for(SESSION_ALS_REGISTRY_KEY)]` — a process-singleton every realm resolving
|
|
39
39
|
// this file reaches via the SAME well-known key — lazily installed on first access.
|
|
40
|
-
export const
|
|
40
|
+
export const SESSION_ALS_REGISTRY_KEY = "@pbuilder/sdk:core/context#session-als";
|
|
41
41
|
function isAsyncLocalStorageLike(value) {
|
|
42
42
|
return (typeof value === "object" &&
|
|
43
43
|
value !== null &&
|
|
@@ -51,25 +51,25 @@ function isAsyncLocalStorageLike(value) {
|
|
|
51
51
|
// trusted or silently clobbered. Plain `Error` (NOT AuthoringError) — this is
|
|
52
52
|
// environment/integration corruption, not author-input misuse; the closed reason enum has no
|
|
53
53
|
// member for it (mirrors `validateAtRunBoundary`'s read-path posture).
|
|
54
|
-
export function
|
|
54
|
+
export function resolveSessionAls(slotValue) {
|
|
55
55
|
if (slotValue === undefined) {
|
|
56
56
|
return new AsyncLocalStorage();
|
|
57
57
|
}
|
|
58
58
|
if (isAsyncLocalStorageLike(slotValue)) {
|
|
59
59
|
return slotValue;
|
|
60
60
|
}
|
|
61
|
-
throw new Error(`[pbuilder] run-context registry slot Symbol.for("${
|
|
61
|
+
throw new Error(`[pbuilder] run-context registry slot Symbol.for("${SESSION_ALS_REGISTRY_KEY}") is occupied by an ` +
|
|
62
62
|
`incompatible value (expected an AsyncLocalStorage, got ${typeof slotValue}) — another module ` +
|
|
63
63
|
"may have polluted globalThis");
|
|
64
64
|
}
|
|
65
65
|
// IMPURE thin shell: reads the shared slot, delegates the 3-state decision to the pure
|
|
66
|
-
// `
|
|
66
|
+
// `resolveSessionAls`, and installs the resolved ALS ONLY when the slot was absent — a frozen
|
|
67
67
|
// descriptor (non-enumerable, non-configurable, non-writable) so REQ-MIS-01.2's no-pollution
|
|
68
68
|
// guarantee holds and the slot can never be silently reassigned after first install.
|
|
69
|
-
function
|
|
70
|
-
const registryKey = Symbol.for(
|
|
69
|
+
function getSessionAls() {
|
|
70
|
+
const registryKey = Symbol.for(SESSION_ALS_REGISTRY_KEY);
|
|
71
71
|
const slot = globalThis[registryKey];
|
|
72
|
-
const resolved =
|
|
72
|
+
const resolved = resolveSessionAls(slot);
|
|
73
73
|
if (slot === undefined) {
|
|
74
74
|
Object.defineProperty(globalThis, registryKey, {
|
|
75
75
|
value: resolved,
|
|
@@ -90,17 +90,17 @@ const DEFINE_FACTORY_BRAND = Symbol("pbuilder.defineFactory.wrapped");
|
|
|
90
90
|
export function isDefineFactoryWrapped(value) {
|
|
91
91
|
return typeof value === "function" && Reflect.get(value, DEFINE_FACTORY_BRAND) === true;
|
|
92
92
|
}
|
|
93
|
-
// REQ-AEC-02.1 (2.4): a verb called outside any defineFactory
|
|
94
|
-
// independent of any engine round-trip — an AuthoringError{authoring-rejected,outside-
|
|
95
|
-
// not a plain Error. The prose lives in authoring-error.ts's outside-
|
|
93
|
+
// REQ-AEC-02.1 (2.4): a verb called outside any defineFactory Session is SDK-side misuse,
|
|
94
|
+
// independent of any engine round-trip — an AuthoringError{authoring-rejected,outside-session},
|
|
95
|
+
// not a plain Error. The prose lives in authoring-error.ts's outside-session message template
|
|
96
96
|
// (the third template, REQ-AEC-06); this is the one call site that reaches it.
|
|
97
97
|
export function currentContext() {
|
|
98
|
-
const ctx =
|
|
98
|
+
const ctx = getSessionAls().getStore();
|
|
99
99
|
if (ctx === undefined) {
|
|
100
100
|
throw new AuthoringError({
|
|
101
101
|
verb: undefined,
|
|
102
102
|
path: undefined,
|
|
103
|
-
reason: "outside-
|
|
103
|
+
reason: "outside-session",
|
|
104
104
|
appliedCount: 0,
|
|
105
105
|
});
|
|
106
106
|
}
|
|
@@ -153,7 +153,7 @@ function emptySchemaWarning(packageDir) {
|
|
|
153
153
|
return `[pbuilder] factory at ${relativeDir(packageDir)}: schema.json declares zero properties — no input validation performed`;
|
|
154
154
|
}
|
|
155
155
|
// Pre-`als.run` schema-conformance check (ADR-0029, REQ-RBV-01/03/05): validates BEFORE
|
|
156
|
-
//
|
|
156
|
+
// SessionContext is built, so a rejection throws with nothing buffered — all-or-nothing holds
|
|
157
157
|
// trivially and the rejection never reaches the emit seam. Bare `defineFactory(fn)` (no
|
|
158
158
|
// `options`) skips this entirely — the untyped opt-out (REQ-TFO-02) stays byte-for-byte
|
|
159
159
|
// unchanged. Read-path posture (SEC-3, constraint 4): ONLY ENOENT maps to the opt-out;
|
|
@@ -213,7 +213,7 @@ function checkReservedNames(packageDir) {
|
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
215
|
/**
|
|
216
|
-
* Builds a
|
|
216
|
+
* Builds a SessionContext and runs the factory inside it, flushing buffered
|
|
217
217
|
* directives at run end (REQ-KIT-05) — a write-only factory still emits.
|
|
218
218
|
*
|
|
219
219
|
* All-or-nothing contract (ADR-01): on success the full directive batch is committed;
|
|
@@ -288,7 +288,7 @@ export function defineFactory(fn, options) {
|
|
|
288
288
|
// rejection (an unawaited chain that threw) routes through the SAME catch below as a
|
|
289
289
|
// flush rejection already does.
|
|
290
290
|
try {
|
|
291
|
-
await
|
|
291
|
+
await getSessionAls().run(ctx, () => fn(o));
|
|
292
292
|
await ctx.dialects.drain();
|
|
293
293
|
await ctx.session.flush();
|
|
294
294
|
await ctx.session.commit();
|
|
@@ -53,7 +53,7 @@ export interface Dialect<Ast = any, Ops extends OpPack<Ast> = OpPack<Ast>> {
|
|
|
53
53
|
export declare function defineOpPack<Ast, Ops extends OpPack<Ast>>(ops: Ops): Ops;
|
|
54
54
|
/**
|
|
55
55
|
* Assembles a `Dialect` from its frozen descriptor (extensions, an AST parse/print pair,
|
|
56
|
-
* and an op-pack). `find` is the dialect's ONLY entry verb into a
|
|
56
|
+
* and an op-pack). `find` is the dialect's ONLY entry verb into a Session (REQ-DG-01.2) — it
|
|
57
57
|
* returns an open, coalescing `Handle`.
|
|
58
58
|
*
|
|
59
59
|
* @example
|
|
@@ -27,7 +27,7 @@ export function defineOpPack(ops) {
|
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* Assembles a `Dialect` from its frozen descriptor (extensions, an AST parse/print pair,
|
|
30
|
-
* and an op-pack). `find` is the dialect's ONLY entry verb into a
|
|
30
|
+
* and an op-pack). `find` is the dialect's ONLY entry verb into a Session (REQ-DG-01.2) — it
|
|
31
31
|
* returns an open, coalescing `Handle`.
|
|
32
32
|
*
|
|
33
33
|
* @example
|
|
@@ -38,7 +38,7 @@ export function handlePathFor(ast) {
|
|
|
38
38
|
}
|
|
39
39
|
// A getter-backed modify directive: `content` resolves lazily, exactly once, memoized — at
|
|
40
40
|
// whichever flush first `JSON.stringify`s the batch (ADR-0006's "serialize once at flush").
|
|
41
|
-
// `
|
|
41
|
+
// `pendingDirectives()` never triggers this: `renderPendingDirectives` reads only `verb`/`path` (REQ-MC-05).
|
|
42
42
|
//
|
|
43
43
|
// Row-145: `resolve` is nulled out immediately after its one use (rather than a separate
|
|
44
44
|
// `resolved` boolean) — the memoized getter's closure retained the ts-morph `Project` (via
|
|
@@ -101,23 +101,23 @@ class DialectHandleController {
|
|
|
101
101
|
// `#tail` already skips `guardedStep` via ordinary promise-chain semantics, no flag
|
|
102
102
|
// needed. The flag exists for the CROSS-handle case: a different handle's `#tail` is
|
|
103
103
|
// independent, so without this check its step WOULD run (mutate/buffer) even though
|
|
104
|
-
// nothing ever commits. `ctx.
|
|
105
|
-
// fresh operation) and set FIRST-WINS on catch (the earliest rejection in the
|
|
104
|
+
// nothing ever commits. `ctx.sessionFailure` is consulted at step entry (never attempted as a
|
|
105
|
+
// fresh operation) and set FIRST-WINS on catch (the earliest rejection in the Session is the
|
|
106
106
|
// one every later op/read surfaces, unchanged).
|
|
107
107
|
#chain(step) {
|
|
108
108
|
const guardedStep = async () => {
|
|
109
109
|
const ctx = currentContext();
|
|
110
|
-
if (ctx.
|
|
111
|
-
throw ctx.
|
|
110
|
+
if (ctx.sessionFailure !== undefined) {
|
|
111
|
+
throw ctx.sessionFailure.reason;
|
|
112
112
|
}
|
|
113
113
|
try {
|
|
114
114
|
return await step();
|
|
115
115
|
}
|
|
116
116
|
catch (err) {
|
|
117
|
-
if (ctx.
|
|
118
|
-
ctx.
|
|
117
|
+
if (ctx.sessionFailure === undefined) {
|
|
118
|
+
ctx.sessionFailure = { reason: err };
|
|
119
119
|
}
|
|
120
|
-
throw ctx.
|
|
120
|
+
throw ctx.sessionFailure.reason;
|
|
121
121
|
}
|
|
122
122
|
};
|
|
123
123
|
const result = this.#tail.then(guardedStep);
|
package/dist/core/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export type { EngineClient } from "./engine-client.ts";
|
|
|
2
2
|
export type { Batch, Directive, JsonValue } from "./wire.ts";
|
|
3
3
|
export { Session } from "./session.ts";
|
|
4
4
|
export { DirectiveFactory } from "./directive-factory.ts";
|
|
5
|
-
export type {
|
|
5
|
+
export type { SessionContext } from "./context.ts";
|
|
6
6
|
export { defineFactory, currentContext } from "./context.ts";
|
|
7
7
|
export type { ReadOps, WriteOps, WritableHandleRef } from "./base-handle.ts";
|
|
8
8
|
export type { FoundHandle, WritableHandle } from "./handle-state.ts";
|
package/dist/core/session.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export declare class Session {
|
|
|
4
4
|
#private;
|
|
5
5
|
constructor(client: EngineClient);
|
|
6
6
|
buffer(directive: Directive): void;
|
|
7
|
-
|
|
7
|
+
pendingDirectives(): readonly Directive[];
|
|
8
8
|
isPending(directive: Directive): boolean;
|
|
9
9
|
read(path: string): Promise<string | undefined>;
|
|
10
10
|
commit(): Promise<void>;
|
package/dist/core/session.js
CHANGED
|
@@ -17,9 +17,9 @@ export class Session {
|
|
|
17
17
|
buffer(directive) {
|
|
18
18
|
this.#pending.push(directive);
|
|
19
19
|
}
|
|
20
|
-
// SEAM-02 (REQ-03): a defensive copy of the pending buffer for the
|
|
20
|
+
// SEAM-02 (REQ-03): a defensive copy of the pending buffer for the pending Directives renderer.
|
|
21
21
|
// Later mutations to #pending must NOT affect a snapshot taken earlier.
|
|
22
|
-
|
|
22
|
+
pendingDirectives() {
|
|
23
23
|
return this.#pending.slice();
|
|
24
24
|
}
|
|
25
25
|
// Row-141 kept-half: an identity membership check against the LIVE buffer (no defensive
|
|
@@ -6,7 +6,7 @@ type ReactOps = {
|
|
|
6
6
|
addImport: (ast: SourceFile, name: string, from: string) => void;
|
|
7
7
|
};
|
|
8
8
|
/**
|
|
9
|
-
* Opens a `.tsx` file for React-dialect-aware editing — the dialect's entry verb into a
|
|
9
|
+
* Opens a `.tsx` file for React-dialect-aware editing — the dialect's entry verb into a Session
|
|
10
10
|
* (REQ-DG-01.2). `path` MUST end in `.tsx`: the gate below runs SYNCHRONOUSLY, before any op
|
|
11
11
|
* is chained and before any run flush, so a rejected path throws on the bare `find()` call
|
|
12
12
|
* itself. `.ts` files are TypeScript, not this dialect — use `@pbuilder/sdk/typescript`.
|
|
@@ -18,7 +18,7 @@ const baseDialect = defineDialect({
|
|
|
18
18
|
});
|
|
19
19
|
const reactDialect = withOps(baseDialect, opsPack);
|
|
20
20
|
/**
|
|
21
|
-
* Opens a `.tsx` file for React-dialect-aware editing — the dialect's entry verb into a
|
|
21
|
+
* Opens a `.tsx` file for React-dialect-aware editing — the dialect's entry verb into a Session
|
|
22
22
|
* (REQ-DG-01.2). `path` MUST end in `.tsx`: the gate below runs SYNCHRONOUSLY, before any op
|
|
23
23
|
* is chained and before any run flush, so a rejected path throws on the bare `find()` call
|
|
24
24
|
* itself. `.ts` files are TypeScript, not this dialect — use `@pbuilder/sdk/typescript`.
|
|
@@ -16,9 +16,9 @@ type TypeScriptOps = {
|
|
|
16
16
|
removeImport: (ast: SourceFile, name: string, from: string) => void;
|
|
17
17
|
};
|
|
18
18
|
/**
|
|
19
|
-
* Opens a TypeScript file for dialect-aware editing — the dialect's entry verb into a
|
|
19
|
+
* Opens a TypeScript file for dialect-aware editing — the dialect's entry verb into a Session
|
|
20
20
|
* (REQ-DG-01.2). Returns an awaitable, chainable `Handle` exposing the universal `.modify()`
|
|
21
|
-
* escape hatch plus the dialect's
|
|
21
|
+
* escape hatch plus the dialect's named ops (`addImport`, `addFunction`, `addVariable`,
|
|
22
22
|
* `addClass`, `removeImport`). Reads route through `Session.read` only (REQ-MC-03); edits
|
|
23
23
|
* coalesce into a single `modify` at flush (REQ-MC-01/02).
|
|
24
24
|
*
|
|
@@ -23,9 +23,9 @@ const baseDialect = defineDialect({
|
|
|
23
23
|
});
|
|
24
24
|
const typescriptDialect = withOps(baseDialect, opsPack);
|
|
25
25
|
/**
|
|
26
|
-
* Opens a TypeScript file for dialect-aware editing — the dialect's entry verb into a
|
|
26
|
+
* Opens a TypeScript file for dialect-aware editing — the dialect's entry verb into a Session
|
|
27
27
|
* (REQ-DG-01.2). Returns an awaitable, chainable `Handle` exposing the universal `.modify()`
|
|
28
|
-
* escape hatch plus the dialect's
|
|
28
|
+
* escape hatch plus the dialect's named ops (`addImport`, `addFunction`, `addVariable`,
|
|
29
29
|
* `addClass`, `removeImport`). Reads route through `Session.read` only (REQ-MC-03); edits
|
|
30
30
|
* coalesce into a single `modify` at flush (REQ-MC-01/02).
|
|
31
31
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// S-002: the `addImport`
|
|
1
|
+
// S-002: the `addImport` named op (REQ-TSD-01, frozen call signature
|
|
2
2
|
// `addImport(name: string, from: string)`, design §4.4).
|
|
3
3
|
//
|
|
4
4
|
// S-001: `addFunction` (REQ-TSD-09) + the shared `assertNoCollision` predicate it (and
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { renderPendingDirectives } from "./render.js";
|
|
@@ -1,31 +1,7 @@
|
|
|
1
1
|
import type { Directive } from "../core/wire.ts";
|
|
2
|
+
import type { AuthoringVerb } from "../core/authoring-error.ts";
|
|
2
3
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* Frozen at exactly these seven members — adding a member is a MAJOR event (ADR-0025).
|
|
6
|
-
* `schematic-local-files` S-003 (ADR-0025 amendment): grew from six to seven — `copyIn`
|
|
7
|
-
* added, 1:1 with the `copyIn` wire op (ADR-0043).
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* function label(verb: DryRunVerb): string {
|
|
11
|
-
* switch (verb) {
|
|
12
|
-
* case "create": return "creates";
|
|
13
|
-
* case "modify": return "modifies";
|
|
14
|
-
* case "remove": return "removes";
|
|
15
|
-
* case "rename": return "renames";
|
|
16
|
-
* case "move": return "moves";
|
|
17
|
-
* case "copy": return "copies";
|
|
18
|
-
* case "copyIn": return "copies in";
|
|
19
|
-
* default: {
|
|
20
|
-
* const exhaustive: never = verb;
|
|
21
|
-
* return exhaustive;
|
|
22
|
-
* }
|
|
23
|
-
* }
|
|
24
|
-
* }
|
|
25
|
-
*/
|
|
26
|
-
export type DryRunVerb = "create" | "modify" | "remove" | "rename" | "move" | "copy" | "copyIn";
|
|
27
|
-
/**
|
|
28
|
-
* One entry of a rendered dry-run plan: the author verb and the primary path the
|
|
4
|
+
* One pending Directive rendered in author vocabulary: the author verb and the primary path the
|
|
29
5
|
* operation targets. Carries no content or byte preview.
|
|
30
6
|
*
|
|
31
7
|
* `kind` is present ONLY on the package-local-READ verbs whose transport is CLASSIFIED
|
|
@@ -42,19 +18,18 @@ export type DryRunVerb = "create" | "modify" | "remove" | "rename" | "move" | "c
|
|
|
42
18
|
* about its own behavior).
|
|
43
19
|
*
|
|
44
20
|
* @example
|
|
45
|
-
* const
|
|
46
|
-
* for (const entry of plan) {
|
|
21
|
+
* for (const entry of pendingDirectives()) { // from "@pbuilder/sdk/commons"
|
|
47
22
|
* console.log(entry.verb, entry.path, entry.kind);
|
|
48
23
|
* }
|
|
49
24
|
*/
|
|
50
|
-
export interface
|
|
51
|
-
verb:
|
|
25
|
+
export interface PendingDirective {
|
|
26
|
+
verb: AuthoringVerb;
|
|
52
27
|
path: string;
|
|
53
28
|
kind?: "rendered" | "copied";
|
|
54
29
|
}
|
|
55
|
-
export declare const WIRE_TO_AUTHOR_VERB: Readonly<Record<Directive["op"],
|
|
30
|
+
export declare const WIRE_TO_AUTHOR_VERB: Readonly<Record<Directive["op"], AuthoringVerb>>;
|
|
56
31
|
/**
|
|
57
|
-
* Renders
|
|
32
|
+
* Renders pending Directives in author vocabulary.
|
|
58
33
|
*
|
|
59
34
|
* Each entry carries the author verb (per the frozen `WIRE_TO_AUTHOR_VERB` table above)
|
|
60
35
|
* and the primary source path of the operation:
|
|
@@ -66,4 +41,4 @@ export declare const WIRE_TO_AUTHOR_VERB: Readonly<Record<Directive["op"], DryRu
|
|
|
66
41
|
* copy → copy.from (primary source path)
|
|
67
42
|
* copyIn → copyIn.from (primary source path, REQ-BRC-07 package-relative)
|
|
68
43
|
*/
|
|
69
|
-
export declare function
|
|
44
|
+
export declare function renderPendingDirectives(directives: readonly Directive[]): PendingDirective[];
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Frozen seven-row wire→author verb map — delete→remove, identity elsewhere (including
|
|
2
2
|
// copyIn→copyIn). EXPORTED for the D3 consistency test (test-only reach, §4.6b): NOT
|
|
3
|
-
// re-exported by src/
|
|
3
|
+
// re-exported by src/pending-directives/index.ts or ./commons. The Record<Directive["op"], AuthoringVerb>
|
|
4
4
|
// annotation itself compile-enforces totality over wire ops and value-membership in
|
|
5
|
-
//
|
|
5
|
+
// AuthoringVerb; Object.freeze makes the "frozen" claim literal at runtime.
|
|
6
6
|
export const WIRE_TO_AUTHOR_VERB = Object.freeze({
|
|
7
7
|
create: "create",
|
|
8
8
|
modify: "modify",
|
|
@@ -13,7 +13,7 @@ export const WIRE_TO_AUTHOR_VERB = Object.freeze({
|
|
|
13
13
|
copyIn: "copyIn",
|
|
14
14
|
});
|
|
15
15
|
/**
|
|
16
|
-
* Renders
|
|
16
|
+
* Renders pending Directives in author vocabulary.
|
|
17
17
|
*
|
|
18
18
|
* Each entry carries the author verb (per the frozen `WIRE_TO_AUTHOR_VERB` table above)
|
|
19
19
|
* and the primary source path of the operation:
|
|
@@ -25,8 +25,8 @@ export const WIRE_TO_AUTHOR_VERB = Object.freeze({
|
|
|
25
25
|
* copy → copy.from (primary source path)
|
|
26
26
|
* copyIn → copyIn.from (primary source path, REQ-BRC-07 package-relative)
|
|
27
27
|
*/
|
|
28
|
-
export function
|
|
29
|
-
return
|
|
28
|
+
export function renderPendingDirectives(directives) {
|
|
29
|
+
return directives.map((d) => {
|
|
30
30
|
const verb = WIRE_TO_AUTHOR_VERB[d.op];
|
|
31
31
|
switch (d.op) {
|
|
32
32
|
// "rendered" — every `create` IS a render request, inline `template` or
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"manifestVersion": 1,
|
|
3
3
|
"algorithm": "sha256",
|
|
4
4
|
"entry": "dist/bin/pbuilder-runner.js",
|
|
5
|
-
"packageVersion": "0.
|
|
5
|
+
"packageVersion": "0.4.0",
|
|
6
6
|
"files": [
|
|
7
7
|
{
|
|
8
8
|
"path": "dist/bin/pbuilder-runner.js",
|
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
},
|
|
11
11
|
{
|
|
12
12
|
"path": "dist/core/authoring-error.js",
|
|
13
|
-
"sha256": "
|
|
13
|
+
"sha256": "e7ac92bcd689f78911230841da74dc458ca0281ef69734ca1f8a42ac77a20576"
|
|
14
14
|
},
|
|
15
15
|
{
|
|
16
16
|
"path": "dist/core/context.js",
|
|
17
|
-
"sha256": "
|
|
17
|
+
"sha256": "e5bc7098b04a42487d0632f847efbbf88e66628d0b8241345ad16f178ae78e30"
|
|
18
18
|
},
|
|
19
19
|
{
|
|
20
20
|
"path": "dist/core/directive-factory.js",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
},
|
|
55
55
|
{
|
|
56
56
|
"path": "dist/core/session.js",
|
|
57
|
-
"sha256": "
|
|
57
|
+
"sha256": "bdb3c5cd7fe86028818d9de766c14b67070fea0fc3866f7e1fb5310f1605056e"
|
|
58
58
|
},
|
|
59
59
|
{
|
|
60
60
|
"path": "dist/core/wire.js",
|
|
@@ -98,7 +98,7 @@
|
|
|
98
98
|
},
|
|
99
99
|
{
|
|
100
100
|
"path": "package.json",
|
|
101
|
-
"sha256": "
|
|
101
|
+
"sha256": "757269c8ffe0c40e8add5ec3167b5dee329d36f9cb936bf6b37b6ba4e5e01b60"
|
|
102
102
|
}
|
|
103
103
|
]
|
|
104
104
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/scaffold/expander.ts (ADR-0044): the SINGLE owner of the scaffold fan-out — drives
|
|
2
2
|
// `walk.ts` → `filename-pipeline.ts` → `classify-transport.ts` → emits `factory.create(...)`/
|
|
3
|
-
// `factory.copyIn(...)` directives via the
|
|
3
|
+
// `factory.copyIn(...)` directives via the Session (Executor Context §18).
|
|
4
4
|
// `classify-transport.ts` stays a PURE per-file decision; a by-reference VERDICT is handled
|
|
5
5
|
// HERE, not there. S-003: the by-reference verdict now emits a real `copyIn` directive
|
|
6
6
|
// (`from` package-relative, REQ-BRC-07) instead of S-001/S-002's fail-loud placeholder throw.
|
|
@@ -118,7 +118,7 @@ export function runScaffold(args) {
|
|
|
118
118
|
// function, ABOVE `currentContext()`, so an escaping `to` called OUTSIDE any run reported
|
|
119
119
|
// `invalid-input` where `copyIn` (whose own version of this same guard already runs
|
|
120
120
|
// AFTER its `currentContext()`/`requirePackageAnchors` calls, see `index.ts`'s
|
|
121
|
-
// `runCopyIn`) reports `outside-
|
|
121
|
+
// `runCopyIn`) reports `outside-session` — the two package-local verbs disagreed on which
|
|
122
122
|
// failure wins when BOTH apply. `runScaffold` now mirrors `runCopyIn`'s exact ordering:
|
|
123
123
|
// ctx → packageDir → destination guard → (new F7/F1 screens below) → source guard. The
|
|
124
124
|
// existing post-rename/post-token-translation validation of the FINAL `destPath` inside
|
|
@@ -155,7 +155,7 @@ export function runScaffold(args) {
|
|
|
155
155
|
// and maintained incrementally. Byte-identical to re-serializing the whole batch per
|
|
156
156
|
// append: JSON array bytes are additive — each extra element contributes exactly its own
|
|
157
157
|
// `JSON.stringify` bytes plus one comma when it is not the first.
|
|
158
|
-
const seedPending = session.
|
|
158
|
+
const seedPending = session.pendingDirectives();
|
|
159
159
|
let pendingCount = seedPending.length;
|
|
160
160
|
let pendingSize = serializedBatchSize(seedPending);
|
|
161
161
|
for (const result of pipelineResults) {
|
package/dist/scaffold/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { runScaffold } from "./expander.ts";
|
|
|
3
3
|
export type { ScaffoldArgs } from "./expander.ts";
|
|
4
4
|
export { isSniffableText } from "./classify-transport.ts";
|
|
5
5
|
/**
|
|
6
|
-
* Reads a package-local file (relative to the active
|
|
6
|
+
* Reads a package-local file (relative to the active Session's `packageDir`) and returns its
|
|
7
7
|
* content as the string to use for a `create({ templateFile })` render request.
|
|
8
8
|
*
|
|
9
9
|
* ADR-0077: the path is screened lexically (`validateSourceLexical`, `ir-path-well-formedness`
|
package/dist/scaffold/index.js
CHANGED
|
@@ -27,7 +27,7 @@ function templateFileOversizedMessage(relPath) {
|
|
|
27
27
|
// so this module's surface is unchanged.
|
|
28
28
|
export { isSniffableText } from "./classify-transport.js";
|
|
29
29
|
/**
|
|
30
|
-
* Reads a package-local file (relative to the active
|
|
30
|
+
* Reads a package-local file (relative to the active Session's `packageDir`) and returns its
|
|
31
31
|
* content as the string to use for a `create({ templateFile })` render request.
|
|
32
32
|
*
|
|
33
33
|
* ADR-0077: the path is screened lexically (`validateSourceLexical`, `ir-path-well-formedness`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pbuilder/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.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",
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"bin": {
|
|
36
36
|
"pbuilder-codegen": "dist/bin/pbuilder-codegen.js"
|
|
37
37
|
},
|
|
38
|
+
"main": "./dist/index.js",
|
|
38
39
|
"exports": {
|
|
39
40
|
".": {
|
|
40
41
|
"types": "./dist/index.d.ts",
|
package/dist/dry-run/index.d.ts
DELETED
package/dist/dry-run/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { dryRunPlan } from "./plan.js";
|