@pbuilder/sdk 0.1.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 (121) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +202 -0
  3. package/dist/bin/pbuilder-codegen.js +506 -0
  4. package/dist/bin/pbuilder-runner.d.ts +1 -0
  5. package/dist/bin/pbuilder-runner.js +47 -0
  6. package/dist/commons/classify-content.d.ts +40 -0
  7. package/dist/commons/classify-content.js +32 -0
  8. package/dist/commons/index.d.ts +271 -0
  9. package/dist/commons/index.js +276 -0
  10. package/dist/conformance/index.d.ts +115 -0
  11. package/dist/conformance/index.js +218 -0
  12. package/dist/conformance/run-vehicle.d.ts +19 -0
  13. package/dist/conformance/run-vehicle.js +104 -0
  14. package/dist/core/authoring-error.d.ts +116 -0
  15. package/dist/core/authoring-error.js +205 -0
  16. package/dist/core/base-handle.d.ts +17 -0
  17. package/dist/core/base-handle.js +4 -0
  18. package/dist/core/context.d.ts +85 -0
  19. package/dist/core/context.js +356 -0
  20. package/dist/core/deep-equal.d.ts +1 -0
  21. package/dist/core/deep-equal.js +29 -0
  22. package/dist/core/define-dialect.d.ts +94 -0
  23. package/dist/core/define-dialect.js +121 -0
  24. package/dist/core/dialect-error.d.ts +8 -0
  25. package/dist/core/dialect-error.js +26 -0
  26. package/dist/core/dialect-handle.d.ts +21 -0
  27. package/dist/core/dialect-handle.js +382 -0
  28. package/dist/core/directive-factory.d.ts +47 -0
  29. package/dist/core/directive-factory.js +154 -0
  30. package/dist/core/emit-rejection.d.ts +19 -0
  31. package/dist/core/emit-rejection.js +31 -0
  32. package/dist/core/engine-client.d.ts +7 -0
  33. package/dist/core/engine-client.js +5 -0
  34. package/dist/core/fs-errors.d.ts +1 -0
  35. package/dist/core/fs-errors.js +5 -0
  36. package/dist/core/handle-state.d.ts +24 -0
  37. package/dist/core/handle-state.js +4 -0
  38. package/dist/core/index.d.ts +10 -0
  39. package/dist/core/index.js +6 -0
  40. package/dist/core/jsx-name-validator.d.ts +19 -0
  41. package/dist/core/jsx-name-validator.js +104 -0
  42. package/dist/core/reject-tail.d.ts +23 -0
  43. package/dist/core/reject-tail.js +63 -0
  44. package/dist/core/schema/input-rejection.d.ts +4 -0
  45. package/dist/core/schema/input-rejection.js +32 -0
  46. package/dist/core/schema/schema-digest.d.ts +1 -0
  47. package/dist/core/schema/schema-digest.js +7 -0
  48. package/dist/core/schema/schema-discovery.d.ts +13 -0
  49. package/dist/core/schema/schema-discovery.js +51 -0
  50. package/dist/core/schema/schema-locate.d.ts +10 -0
  51. package/dist/core/schema/schema-locate.js +192 -0
  52. package/dist/core/schema/schema-model.d.ts +18 -0
  53. package/dist/core/schema/schema-model.js +15 -0
  54. package/dist/core/schema/schema-parse.d.ts +20 -0
  55. package/dist/core/schema/schema-parse.js +80 -0
  56. package/dist/core/schema/schema-sufficiency.d.ts +17 -0
  57. package/dist/core/schema/schema-sufficiency.js +54 -0
  58. package/dist/core/schema/schema-validate.d.ts +14 -0
  59. package/dist/core/schema/schema-validate.js +64 -0
  60. package/dist/core/session.d.ts +13 -0
  61. package/dist/core/session.js +72 -0
  62. package/dist/core/wire.d.ts +87 -0
  63. package/dist/core/wire.js +49 -0
  64. package/dist/dialects/react/ast.d.ts +25 -0
  65. package/dist/dialects/react/ast.js +80 -0
  66. package/dist/dialects/react/index.d.ts +39 -0
  67. package/dist/dialects/react/index.js +71 -0
  68. package/dist/dialects/react/ops.d.ts +56 -0
  69. package/dist/dialects/react/ops.js +186 -0
  70. package/dist/dialects/typescript/ast.d.ts +42 -0
  71. package/dist/dialects/typescript/ast.js +93 -0
  72. package/dist/dialects/typescript/index.d.ts +32 -0
  73. package/dist/dialects/typescript/index.js +40 -0
  74. package/dist/dialects/typescript/ops.d.ts +123 -0
  75. package/dist/dialects/typescript/ops.js +365 -0
  76. package/dist/dry-run/index.d.ts +2 -0
  77. package/dist/dry-run/index.js +1 -0
  78. package/dist/dry-run/plan.d.ts +69 -0
  79. package/dist/dry-run/plan.js +44 -0
  80. package/dist/index.d.ts +1 -0
  81. package/dist/index.js +3 -0
  82. package/dist/runner-manifest.json +104 -0
  83. package/dist/scaffold/classify-transport.d.ts +57 -0
  84. package/dist/scaffold/classify-transport.js +123 -0
  85. package/dist/scaffold/containment.d.ts +54 -0
  86. package/dist/scaffold/containment.js +242 -0
  87. package/dist/scaffold/expander.d.ts +30 -0
  88. package/dist/scaffold/expander.js +161 -0
  89. package/dist/scaffold/filename-pipeline.d.ts +39 -0
  90. package/dist/scaffold/filename-pipeline.js +125 -0
  91. package/dist/scaffold/index.d.ts +45 -0
  92. package/dist/scaffold/index.js +99 -0
  93. package/dist/scaffold/walk.d.ts +25 -0
  94. package/dist/scaffold/walk.js +124 -0
  95. package/dist/testing/contract-fake.d.ts +17 -0
  96. package/dist/testing/contract-fake.js +221 -0
  97. package/dist/testing/index.d.ts +84 -0
  98. package/dist/testing/index.js +82 -0
  99. package/dist/testing/rejection-messages.d.ts +7 -0
  100. package/dist/testing/rejection-messages.js +12 -0
  101. package/dist/transport/bootstrap-bridge.d.ts +33 -0
  102. package/dist/transport/bootstrap-bridge.js +65 -0
  103. package/dist/transport/error-text.d.ts +8 -0
  104. package/dist/transport/error-text.js +44 -0
  105. package/dist/transport/exit-codes.d.ts +2 -0
  106. package/dist/transport/exit-codes.js +35 -0
  107. package/dist/transport/factory-pointer.d.ts +32 -0
  108. package/dist/transport/factory-pointer.js +63 -0
  109. package/dist/transport/frame-reader.d.ts +10 -0
  110. package/dist/transport/frame-reader.js +81 -0
  111. package/dist/transport/framing.d.ts +20 -0
  112. package/dist/transport/framing.js +98 -0
  113. package/dist/transport/runner.d.ts +25 -0
  114. package/dist/transport/runner.js +308 -0
  115. package/dist/transport/single-instance-probe.d.ts +23 -0
  116. package/dist/transport/single-instance-probe.js +119 -0
  117. package/dist/transport/stdio-engine-client.d.ts +27 -0
  118. package/dist/transport/stdio-engine-client.js +243 -0
  119. package/dist/transport/wire-protocol.d.ts +33 -0
  120. package/dist/transport/wire-protocol.js +22 -0
  121. package/package.json +93 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Project Builder Schematics
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,202 @@
1
+ # @pbuilder/sdk
2
+
3
+ > The public TypeScript/Bun authoring layer for [Project Builder](https://github.com/Project-Builder-Schematics) schematics.
4
+
5
+ **Status: early development.** Not yet published to a registry — see the
6
+ [quickstart](./docs/quickstart.md) for the local-install path (`bun link` or a packed
7
+ tarball). APIs are unstable and will change.
8
+
9
+ Start with the [quickstart](./docs/quickstart.md), or the [full doc index](./docs/README.md)
10
+ for the reference set — verbs, error contract, dry-run, and
11
+ [authoring a dialect](./docs/authoring-a-dialect.md) (structured, AST-aware mutation for one
12
+ file type, e.g. `@pbuilder/sdk/typescript`, `@pbuilder/sdk/react`).
13
+
14
+ ## What it is
15
+
16
+ `@pbuilder/sdk` is the developer-facing library for authoring Project Builder **schematics** —
17
+ programmable file mutations (create, remove, move, rename, copy, replaceContent) plus
18
+ package-local reads (`scaffold`, `copyIn`, `create({ templateFile })`). The SDK never touches
19
+ the disk:
20
+ it translates what you author into an **IR** (instruction record) and hands it to the Project Builder
21
+ engine, which owns execution and is the only component that writes to disk.
22
+
23
+ It's a conversation, not a one-shot: while a schematic runs, the SDK queries the engine for file
24
+ contents and emits mutations; the engine applies them to a staging tree and answers back. The SDK
25
+ proposes; the engine disposes.
26
+
27
+ ## Anatomy of a schematic
28
+
29
+ ```
30
+ collection
31
+ ├── schema.json # typed inputs (the contract with the user)
32
+ └── factory.ts # the authoring logic (written against @pbuilder/sdk)
33
+ ```
34
+
35
+ ## Scaffolding a folder
36
+
37
+ A schematic's own `collection` folder can hold static/templated files alongside
38
+ `schema.json`/`factory.ts` — `scaffold` walks one of those folders and mirrors it into the
39
+ target tree, without you writing a `create()` call per file:
40
+
41
+ ```ts
42
+ import { scaffold } from "@pbuilder/sdk/commons";
43
+
44
+ export const run = (input: { name: string }) => {
45
+ scaffold({ from: "files", to: "src/generated", options: { name: input.name } });
46
+ };
47
+ ```
48
+
49
+ Each source file is classified automatically — never author-declared: valid, in-budget text
50
+ renders by-value (through the same IR `create()` uses, `{= =}` tokens included); anything
51
+ else (binary content, or a file over the size budget) travels by-reference instead, verbatim.
52
+
53
+ `scaffold`, `copyIn`, and `create({ templateFile })` all resolve package-local files, so the
54
+ call that runs this factory needs `packageDir` passed to it — without it, these verbs have
55
+ no package to resolve against.
56
+
57
+ Two escape hatches handle the single-file cases `scaffold` doesn't:
58
+
59
+ - **`create(path, { templateFile })`** — an explicit RENDER request for one package-local
60
+ file; a binary or over-budget file rejects fail-loud (never silently falls back to a copy).
61
+ - **`copyIn(from, to, { force? })`** — an explicit NEVER-RENDER copy of one package-local
62
+ file, verbatim — the escape for a text asset that would otherwise be classified by-value
63
+ (e.g. one containing `{= =}`-like sequences that must survive untouched).
64
+
65
+ Two things worth knowing before you rely on `scaffold`:
66
+
67
+ - **Packaging caveat**: an empty `from` folder scaffolds as a silent no-op — but npm tarball
68
+ packaging commonly drops empty directories, so an empty folder may not even survive
69
+ `npm publish`. Ship a placeholder file if the folder's presence matters.
70
+ - **Symlinked directories are never traversed** (even when their target resolves inside the
71
+ package), and a single `scaffold` call is capped at 10,000 enumerated entries.
72
+
73
+ ## Design at a glance
74
+
75
+ - **Surface ≠ contract** — the SDK gives you rich authoring verbs; they lower to a small, stable IR.
76
+ - **AST-agnostic engine** — AST tooling (ts-morph, postcss, cheerio) lives in SDK dialect modules,
77
+ never in the engine. New file types are new packages, not engine releases.
78
+ - **Bun-native** — TypeScript runs directly, no transpile step.
79
+ - **`dist/core/**` ships, documented, not stripped** — the published tarball intentionally
80
+ includes `dist/core/**`, because `./testing`'s runtime code imports `../core/context.ts`
81
+ at runtime and needs it physically present on disk. `@pbuilder/sdk/core` still stays
82
+ unreachable via `package.json#exports` regardless — the boundary is advisory-by-convention
83
+ (no import path resolves it), not enforced by tarball exclusion.
84
+
85
+ ## Testing your factory
86
+
87
+ `@pbuilder/sdk/testing` is the third audience surface — `author-testing` (ADR-0033) — the
88
+ supported way to test a factory you're authoring, in-memory, without a running engine. It
89
+ ships `0.x`, semver-exempt (mirroring the kit) until real use validates the result shape.
90
+
91
+ This is distinct from `./conformance`: `./testing` tests **your own factory's** behaviour;
92
+ `./conformance` conformance-tests a **dialect or op-pack** implementation (parse/print
93
+ fidelity), not a factory.
94
+
95
+ Import `runFactoryForTest` from `@pbuilder/sdk/testing`, pass it a bare
96
+ `(input) => void | Promise<void>` factory function, and assert on the result. Templates are
97
+ stored **verbatim** — `{{...}}` interpolation is the engine's job, not the harness's:
98
+
99
+ ```ts
100
+ import { runFactoryForTest } from "@pbuilder/sdk/testing";
101
+ import { create } from "@pbuilder/sdk/commons";
102
+ import { expect, test } from "bun:test";
103
+
104
+ test("factory writes a greeting file", async () => {
105
+ const run = (input: { name: string }) => {
106
+ create("src/greeting.ts", {
107
+ template: `export const greeting = '${input.name}';`,
108
+ options: {},
109
+ });
110
+ };
111
+
112
+ const result = await runFactoryForTest(run, { name: "world" });
113
+
114
+ expect(result.error).toBeUndefined();
115
+ expect(result.tree.get("src/greeting.ts")).toEqual("export const greeting = 'world';");
116
+ });
117
+ ```
118
+
119
+ `runFactoryForTest`'s third parameter is an options bag — `seed` pre-populates the
120
+ in-memory tree so your factory can read existing files back before writing new ones:
121
+
122
+ ```ts
123
+ import { runFactoryForTest } from "@pbuilder/sdk/testing";
124
+ import { find, create } from "@pbuilder/sdk/commons";
125
+ import { expect, test } from "bun:test";
126
+
127
+ test("factory derives a file from a seeded config", async () => {
128
+ const run = async () => {
129
+ const raw = await find("config.json").read();
130
+ const { name } = JSON.parse(raw ?? "{}") as { name: string };
131
+ create("src/greeting.ts", { template: `export const greeting = '${name}';`, options: {} });
132
+ };
133
+
134
+ const seed = { "config.json": JSON.stringify({ name: "seeded" }) };
135
+ const result = await runFactoryForTest(run, undefined, { seed });
136
+
137
+ expect(result.error).toBeUndefined();
138
+ expect(result.tree.get("src/greeting.ts")).toEqual("export const greeting = 'seeded';");
139
+ // the seed itself is readable but never appears in the committed tree
140
+ expect(result.tree.has("config.json")).toBe(false);
141
+ });
142
+ ```
143
+
144
+ `packageDir` is the options bag's other field — pass `import.meta.dir` to opt a factory into
145
+ schema-derived run-boundary validation against an adjacent `schema.json`. It's more than a
146
+ validation toggle, though: it's also the mandatory resolution anchor for the package-local
147
+ verb family (`scaffold`, `copyIn`, `create({ templateFile })`) — omit it and you keep the
148
+ untyped, unvalidated escape hatch shown above, but those verbs have nothing to resolve
149
+ against.
150
+
151
+ ## Development
152
+
153
+ ```sh
154
+ bun install
155
+ bun test
156
+ bun run typecheck
157
+ ```
158
+
159
+ `conformance/` — SDK↔engine live conformance corpus, consumed by `project-builder-engine` as a
160
+ pinned git submodule; see `conformance/README.md` and `CONFORMANCE-CORPUS-HANDOFF.md`.
161
+
162
+ ### Local registry (Verdaccio)
163
+
164
+ Test real publishes — tarball, `files`, `exports`, `bin` — before anything reaches npmjs.
165
+ Unlike `bun link`, this exercises the actual packaging step, so dist/packaging bugs surface
166
+ locally instead of on first contact with a consumer.
167
+
168
+ ```sh
169
+ # terminal 1 — start the registry (runs in foreground)
170
+ bun run registry:up
171
+
172
+ # terminal 2 — build + publish a local prerelease (0.0.0-local.<timestamp>, dist-tag `local`)
173
+ bun run publish:local
174
+ ```
175
+
176
+ Consume from another repo (e.g. `project-builder-engine`) by pointing only the `@pbuilder`
177
+ scope at the local registry:
178
+
179
+ ```toml
180
+ # bunfig.toml
181
+ [install.scopes]
182
+ "@pbuilder" = "http://localhost:4873"
183
+ ```
184
+
185
+ ```sh
186
+ bun add @pbuilder/sdk@local # always resolves the latest local publish
187
+ ```
188
+
189
+ With npm, use `@pbuilder:registry=http://localhost:4873` in the consumer's `.npmrc` instead.
190
+
191
+ Notes:
192
+
193
+ - The `@pbuilder/*` scope is local-authoritative (no npmjs proxy) — a local publish can never
194
+ be shadowed by the public package. Everything else proxies through to npmjs with caching.
195
+ - `publish:local` restores `package.json` via `git checkout` afterwards — run it with a clean
196
+ `package.json`, or uncommitted changes to it will be lost.
197
+ - To reset the registry, stop it and delete `tools/verdaccio/storage/` (git-ignored).
198
+ - Registry config lives in `tools/verdaccio/config.yaml`.
199
+
200
+ ## License
201
+
202
+ [MIT](./LICENSE)