@pbuilder/sdk 0.19.0 → 0.21.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 (68) hide show
  1. package/README.md +81 -38
  2. package/dist/acl/irwire/stdio-engine-client.d.ts +1 -0
  3. package/dist/acl/irwire/stdio-engine-client.js +9 -0
  4. package/dist/bin/pbuilder-codegen.js +90 -18
  5. package/dist/bounded-contexts/authoring/application/usecases/authoring-verbs/index.d.ts +15 -0
  6. package/dist/bounded-contexts/authoring/application/usecases/authoring-verbs/index.js +17 -0
  7. package/dist/bounded-contexts/authoring/application/usecases/run-factory/context.d.ts +16 -3
  8. package/dist/bounded-contexts/authoring/application/usecases/run-factory/context.js +45 -11
  9. package/dist/bounded-contexts/authoring/domain/aggregates/session/session.d.ts +3 -1
  10. package/dist/bounded-contexts/authoring/domain/aggregates/session/session.js +10 -1
  11. package/dist/bounded-contexts/authoring/domain/ports/engine-client.d.ts +1 -0
  12. package/dist/bounded-contexts/authoring/domain/services/define-dialect.d.ts +28 -1
  13. package/dist/bounded-contexts/authoring/domain/services/define-dialect.js +27 -3
  14. package/dist/bounded-contexts/authoring/domain/services/evaluation.d.ts +29 -0
  15. package/dist/bounded-contexts/authoring/domain/services/evaluation.js +43 -0
  16. package/dist/bounded-contexts/authoring/domain/services/glob-match.d.ts +4 -0
  17. package/dist/bounded-contexts/authoring/domain/services/glob-match.js +81 -0
  18. package/dist/bounded-contexts/authoring/domain/services/schema/input-rejection.d.ts +1 -0
  19. package/dist/bounded-contexts/authoring/domain/services/schema/input-rejection.js +4 -0
  20. package/dist/bounded-contexts/authoring/domain/services/schema/schema-validate.d.ts +2 -1
  21. package/dist/bounded-contexts/authoring/domain/services/schema/schema-validate.js +6 -2
  22. package/dist/bounded-contexts/authoring/domain/valueobjects/findings.d.ts +12 -0
  23. package/dist/bounded-contexts/authoring/domain/valueobjects/findings.js +57 -0
  24. package/dist/bounded-contexts/authoring/domain/valueobjects/schema-model.d.ts +2 -0
  25. package/dist/bounded-contexts/authoring/infrastructure/in/codegen/cli.d.ts +7 -2
  26. package/dist/bounded-contexts/authoring/infrastructure/in/codegen/cli.js +28 -7
  27. package/dist/bounded-contexts/authoring/infrastructure/in/codegen/emit-type.d.ts +6 -2
  28. package/dist/bounded-contexts/authoring/infrastructure/in/codegen/emit-type.js +23 -13
  29. package/dist/bounded-contexts/authoring/infrastructure/in/codegen/project-codegen.d.ts +1 -0
  30. package/dist/bounded-contexts/authoring/infrastructure/in/codegen/project-codegen.js +5 -2
  31. package/dist/bounded-contexts/authoring/infrastructure/in/commons/index.d.ts +2 -1
  32. package/dist/bounded-contexts/authoring/infrastructure/in/commons/index.js +1 -1
  33. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/angular/index.d.ts +14 -1
  34. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/angular/index.js +15 -0
  35. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/aspnet/index.d.ts +14 -1
  36. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/aspnet/index.js +15 -0
  37. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/csharp/index.d.ts +14 -1
  38. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/csharp/index.js +15 -0
  39. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/css/index.d.ts +14 -1
  40. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/css/index.js +15 -0
  41. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/json/index.d.ts +14 -1
  42. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/json/index.js +15 -0
  43. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/msbuild/index.d.ts +14 -1
  44. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/msbuild/index.js +15 -0
  45. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/nestjs/index.d.ts +14 -1
  46. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/nestjs/index.js +15 -0
  47. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/index.d.ts +14 -1
  48. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/index.js +15 -0
  49. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/typescript/index.d.ts +14 -1
  50. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/typescript/index.js +15 -0
  51. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/yaml/index.d.ts +14 -1
  52. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/yaml/index.js +15 -0
  53. package/dist/bounded-contexts/authoring/testing/contract-fake.d.ts +1 -0
  54. package/dist/bounded-contexts/authoring/testing/contract-fake.js +8 -0
  55. package/dist/bounded-contexts/authoring/testing/glob-pattern.d.ts +5 -0
  56. package/dist/bounded-contexts/authoring/testing/glob-pattern.js +20 -0
  57. package/dist/bounded-contexts/authoring/testing/harness/index.d.ts +8 -0
  58. package/dist/bounded-contexts/authoring/testing/harness/index.js +12 -1
  59. package/dist/bounded-contexts/authoring/testing/run-vehicle.d.ts +1 -0
  60. package/dist/bounded-contexts/authoring/testing/run-vehicle.js +4 -0
  61. package/dist/bounded-contexts/runner-hosting/infrastructure/in/bootstrap-bridge.d.ts +3 -0
  62. package/dist/bounded-contexts/runner-hosting/infrastructure/in/bootstrap-bridge.js +4 -0
  63. package/dist/bounded-contexts/runner-hosting/infrastructure/in/runner.js +15 -3
  64. package/dist/runner-manifest.json +33 -9
  65. package/dist/shared-kernel/wire-protocol.d.ts +1 -1
  66. package/dist/shared-kernel/wire-protocol.js +1 -1
  67. package/package.json +1 -1
  68. package/schemas/project-builder.schema.json +75 -2
package/README.md CHANGED
@@ -183,7 +183,7 @@ export default async (input: Input) => {
183
183
  The engine invokes the module's **default export** — that's the factory. (This one builds
184
184
  its output strings in TypeScript; the template language below is the declarative
185
185
  alternative. And if your editor flags the `.ts`-extension import or `bun:test`, that's
186
- just missing tsconfig settings — the [quickstart](./docs/guides/quickstart.md) ships one; Bun
186
+ just missing tsconfig settings — the [quickstart](https://github.com/Project-Builder-Schematics/project-builder-sdk/blob/main/docs/guides/quickstart.md) ships one; Bun
187
187
  itself runs fine without it.)
188
188
 
189
189
  **6. Execute it** — `default:hello` is `<collection>:<schematic>` as registered in
@@ -214,9 +214,9 @@ as it was.
214
214
  **7. Test it** without the CLI or a running engine — see
215
215
  [Testing your factory](#testing-your-factory) below.
216
216
 
217
- From here: [Authoring verbs](./docs/guides/authoring-verbs.md) is the full reference for
217
+ From here: [Authoring verbs](https://github.com/Project-Builder-Schematics/project-builder-sdk/blob/main/docs/guides/authoring-verbs.md) is the full reference for
218
218
  everything you can do inside a factory, and the
219
- [quickstart](./docs/guides/quickstart.md) covers the standalone-package setup (tsconfig
219
+ [quickstart](https://github.com/Project-Builder-Schematics/project-builder-sdk/blob/main/docs/guides/quickstart.md) covers the standalone-package setup (tsconfig
220
220
  included) in more depth.
221
221
 
222
222
  ## Returning a Result
@@ -258,6 +258,41 @@ cycles, `undefined` or non-finite numbers. Its JSON encoding may take at most 1
258
258
  fails, the run fails with an `AuthoringError` whose reason is `invalid-result`, and nothing
259
259
  is written. A declared `null` is a Result and is returned as `null`.
260
260
 
261
+ ## Evaluation schematics
262
+
263
+ A schematic whose Collection definition entry declares `"role": "evaluation"` reads the
264
+ workspace and returns `Findings`, which the role fixes as its Result (A-120). It declares no
265
+ `result` in `schema.json`, and no input named `include` or `exclude`; codegen refuses either.
266
+ Codegen reads the role only in project mode (`pbuilder-codegen` or `--project`), since a single
267
+ directory has no Collection definition entry. For an evaluation schematic it emits `Findings`
268
+ as the `Result` type, and adds the scope inputs `include` and `exclude`, arrays of globs, to
269
+ `Input` (A-122):
270
+
271
+ ```ts
272
+ import type { Input, Result } from "./schema.generated.ts";
273
+ import { glob } from "@pbuilder/sdk/commons";
274
+
275
+ export default async (input: Input): Promise<Result> => {
276
+ const routes = await glob("src/**/route.ts");
277
+ return {
278
+ items: routes.length > 0 ? [] : [{ rule: "route-missing", message: "no route file", severity: "error" }],
279
+ };
280
+ };
281
+ ```
282
+
283
+ A finding has `rule`, `message` and `severity` (`error` or `warning`), and may have a
284
+ workspace-relative `path`, a 1-based `range` (`{ start: { line, column }, end? }`) and a `fix`
285
+ (`{ schematic: "collection:schematic", inputs? }`). The SDK checks the returned value against
286
+ that shape as it checks any Result, then sets each finding's `source` to the schematic's
287
+ qualified name. A finding that sets `source` itself fails the run with `invalid-result` (A-121).
288
+
289
+ The scope is what `include` names, less what `exclude` names; `exclude` alone keeps every file
290
+ it does not name, and with neither nothing is narrowed. Every `glob` result, from commons or a
291
+ Dialect, is narrowed to the scope (A-123), and a finding whose `path` falls outside it is dropped
292
+ before the Result leaves the schematic (A-124). A finding without `path` is always kept. `find`
293
+ is not narrowed, so a check can read the files it compares against (A-125). Every verb a
294
+ generator has is offered as well; the engine discards an evaluation Frame's edits (A-126).
295
+
261
296
  ## Project-wide type generation
262
297
 
263
298
  ```sh
@@ -277,7 +312,7 @@ Two registration forms are supported:
277
312
  ```json
278
313
  {
279
314
  "collections": {
280
- "local": { "hello": { "path": "./schematics/hello" } },
315
+ "local": { "hello": { "path": "./schematics/hello" }, "check": { "path": "./schematics/check", "role": "evaluation" } },
281
316
  "shared": { "path": "./schematics/collection.json" }
282
317
  }
283
318
  }
@@ -339,27 +374,30 @@ Everything a factory can do to the tree is one of seven mutation verbs, all impo
339
374
 
340
375
  | Verb | What it schedules |
341
376
  |---|---|
342
- | [`create(path, opts)`](./docs/guides/authoring-verbs.md#create) | A new file. `path` and `template` are template strings rendered against one `options` object; the `templateFile` overload renders a package-local file instead. |
343
- | [`replaceContent(path, content)`](./docs/guides/authoring-verbs.md#replacecontent) | Wholesale replacement of an existing file's content. |
344
- | [`remove(path)`](./docs/guides/authoring-verbs.md#remove) | A deletion. Idempotent on an absent path. |
345
- | [`rename(path, newName)`](./docs/guides/authoring-verbs.md#rename) | A basename-only rename in place. |
346
- | [`move(path, toDir)`](./docs/guides/authoring-verbs.md#move) | A move to a different directory. |
347
- | [`copy(from, to)`](./docs/guides/authoring-verbs.md#copy) | A tree-to-tree copy, chainable via the returned handle. |
348
- | [`copyIn(from, to)`](./docs/guides/authoring-verbs.md#copyin) | A package-local file copied into the tree **verbatim** — never rendered. |
377
+ | [`create(path, opts)`](https://github.com/Project-Builder-Schematics/project-builder-sdk/blob/main/docs/guides/authoring-verbs.md#create) | A new file. `path` and `template` are template strings rendered against one `options` object; the `templateFile` overload renders a package-local file instead. |
378
+ | [`replaceContent(path, content)`](https://github.com/Project-Builder-Schematics/project-builder-sdk/blob/main/docs/guides/authoring-verbs.md#replacecontent) | Wholesale replacement of an existing file's content. |
379
+ | [`remove(path)`](https://github.com/Project-Builder-Schematics/project-builder-sdk/blob/main/docs/guides/authoring-verbs.md#remove) | A deletion. Idempotent on an absent path. |
380
+ | [`rename(path, newName)`](https://github.com/Project-Builder-Schematics/project-builder-sdk/blob/main/docs/guides/authoring-verbs.md#rename) | A basename-only rename in place. |
381
+ | [`move(path, toDir)`](https://github.com/Project-Builder-Schematics/project-builder-sdk/blob/main/docs/guides/authoring-verbs.md#move) | A move to a different directory. |
382
+ | [`copy(from, to)`](https://github.com/Project-Builder-Schematics/project-builder-sdk/blob/main/docs/guides/authoring-verbs.md#copy) | A tree-to-tree copy, chainable via the returned handle. |
383
+ | [`copyIn(from, to)`](https://github.com/Project-Builder-Schematics/project-builder-sdk/blob/main/docs/guides/authoring-verbs.md#copyin) | A package-local file copied into the tree **verbatim** — never rendered. |
349
384
 
350
385
  The verbs that write to a new path — `create`, `rename`, `move`, `copy`, `copyIn`, and
351
386
  `scaffold` — are fail-closed on collision and accept `{ force: true }` for a deliberate
352
387
  overwrite: `create` and `scaffold` inside their options/args object, the rest as a
353
388
  trailing argument.
354
389
 
355
- Three companions round out the surface:
390
+ Four companions round out the surface:
356
391
 
357
- - [`find(path).read()`](./docs/guides/authoring-verbs.md#the-read-trichotomy-findpathread) — read
392
+ - [`find(path).read()`](https://github.com/Project-Builder-Schematics/project-builder-sdk/blob/main/docs/guides/authoring-verbs.md#the-read-trichotomy-findpathread) — read
358
393
  a file back from the staging tree.
359
- - [`scaffold({ from, to, options })`](./docs/guides/authoring-verbs.md#scaffold) — mirror an
394
+ - [`glob(pattern, { ignore })`](https://github.com/Project-Builder-Schematics/project-builder-sdk/blob/main/docs/guides/authoring-verbs.md#many-files-at-once-globpattern--ignore-)
395
+ resolves a handle for every file the pattern matches, ordered by path, or `[]` when none
396
+ does. Every dialect has its own `glob`, which keeps the files of the extensions it declares.
397
+ - [`scaffold({ from, to, options })`](https://github.com/Project-Builder-Schematics/project-builder-sdk/blob/main/docs/guides/authoring-verbs.md#scaffold) — mirror an
360
398
  entire package-local folder into the tree, with dynamic file names. The workhorse for
361
399
  multi-file generators — see [Scaffolding a folder of templates](#scaffolding-a-folder-of-templates).
362
- - [`pendingDirectives()`](./docs/guides/pending-directives.md) — inspect the directives still **pending**. A `read()`
400
+ - [`pendingDirectives()`](https://github.com/Project-Builder-Schematics/project-builder-sdk/blob/main/docs/guides/pending-directives.md) — inspect the directives still **pending**. A `read()`
363
401
  drains the buffer, so call it before reading if you want the full picture.
364
402
 
365
403
  ### What to keep in mind
@@ -385,7 +423,7 @@ Rules that save you real debugging time — each one is a mistake we've watched
385
423
  - **Errors are structured.** A rejected run surfaces an `AuthoringError` with
386
424
  `verb`/`path`/`reason` fields telling you which directive failed and why (one label
387
425
  quirk: content replacement reports `verb: "modify"` — including plain
388
- `replaceContent()`) — see the [error contract](./docs/guides/authoring-errors.md).
426
+ `replaceContent()`) — see the [error contract](https://github.com/Project-Builder-Schematics/project-builder-sdk/blob/main/docs/guides/authoring-errors.md).
389
427
 
390
428
  ## How templates work
391
429
 
@@ -453,7 +491,7 @@ never `eq .count 2`).
453
491
  If templating gets in your way, there is always a way out: build the final
454
492
  strings in TypeScript and pass a token-free template — it renders verbatim. For the full
455
493
  language — `with`, variables, whitespace rules, output-path templating, sandbox limits, and
456
- the error taxonomy — see [Authoring `create` templates](./docs/guides/create-templates.md).
494
+ the error taxonomy — see [Authoring `create` templates](https://github.com/Project-Builder-Schematics/project-builder-sdk/blob/main/docs/guides/create-templates.md).
457
495
 
458
496
  ## Scaffolding a folder of templates
459
497
 
@@ -523,7 +561,7 @@ placeholder if the folder's presence matters) while `include`/`exclude` filters
523
561
  eliminate every entry reject loudly, nested symlinked directories are skipped
524
562
  silently while a symlinked `from` root rejects outright, and a single call caps at 10,000
525
563
  entries. Full edge-and-error semantics:
526
- [`scaffold` in Authoring verbs](./docs/guides/authoring-verbs.md#scaffold).
564
+ [`scaffold` in Authoring verbs](https://github.com/Project-Builder-Schematics/project-builder-sdk/blob/main/docs/guides/authoring-verbs.md#scaffold).
527
565
 
528
566
  `scaffold`, `copyIn`, and `create({ templateFile })` resolve **package-local** files
529
567
  (relative to your schematic's folder), so the run must know where that package is — the CLI
@@ -597,6 +635,10 @@ Three things to know:
597
635
  against the `result` its `schema.json` declares (see [Returning a Result](#returning-a-result)).
598
636
  It is `undefined` when the factory declares none or the run failed.
599
637
 
638
+ - `role: "evaluation"` with `name: "collection:schematic"` runs the factory as an
639
+ [evaluation schematic](#evaluation-schematics): `result.result` holds its Findings with their
640
+ `source`, narrowed to the scope of the `include` and `exclude` inputs.
641
+
600
642
  - `result.reads` counts the reads the engine served for each path, so a test can check
601
643
  that the factory reads a file once however many ops it chains on it. A path the factory
602
644
  never read is absent.
@@ -617,15 +659,16 @@ as the engine will once it nets such writes out. Until then, write each file onc
617
659
 
618
660
  When string-level mutation isn't enough — "add an import to this module", "set a prop on
619
661
  this JSX element" — **dialects** provide structured, AST-aware operations for one file
620
- type: see [authoring a dialect](./docs/guides/authoring-a-dialect.md) for the full story. Seven
621
- ship today: `@pbuilder/sdk/typescript`, `@pbuilder/sdk/react`, `@pbuilder/sdk/nestjs`,
662
+ type: see [authoring a dialect](https://github.com/Project-Builder-Schematics/project-builder-sdk/blob/main/docs/guides/authoring-a-dialect.md) for the full story. The SDK
663
+ ships these: `@pbuilder/sdk/typescript`, `@pbuilder/sdk/react`, `@pbuilder/sdk/nestjs`,
622
664
  `@pbuilder/sdk/angular`, `@pbuilder/sdk/json`, `@pbuilder/sdk/yaml`, `@pbuilder/sdk/css`,
623
665
  `@pbuilder/sdk/csharp`, `@pbuilder/sdk/aspnet`, and `@pbuilder/sdk/msbuild`.
624
666
 
625
667
  A dialect's entry point is its own `find(path)`: it opens a **coalescing, awaitable
626
668
  handle**. Every op you chain mutates the same live AST, and the handle serializes to
627
669
  exactly **one** `replaceContent`-style directive when it flushes — chaining three ops does
628
- not produce three writes.
670
+ not produce three writes. Its `glob(pattern, { ignore })` opens every matching file of the
671
+ dialect's extensions the same way.
629
672
 
630
673
  ### `@pbuilder/sdk/typescript`
631
674
 
@@ -717,7 +760,7 @@ await json
717
760
  Named ops: `setValue`, `addKey`, `removeKey`, `renameKey`, `insertItem`, `appendItem`,
718
761
  `removeItem`, `removeValue`, `replaceItem`, `moveItem`, `merge`, `updateValue`, `moveValue`,
719
762
  `copyValue`, `sortKeys`. `.modify(fn)` exposes [jsonc-parser](https://github.com/microsoft/node-jsonc-parser).
720
- See [the JSON dialect guide](./docs/guides/json-dialect.md).
763
+ See [the JSON dialect guide](https://github.com/Project-Builder-Schematics/project-builder-sdk/blob/main/docs/guides/json-dialect.md).
721
764
 
722
765
  ### `@pbuilder/sdk/yaml`
723
766
 
@@ -736,7 +779,7 @@ await yaml
736
779
 
737
780
  Extra named ops: `setComment`, `removeComment`, `setAnchor`, `removeAnchor`, `setAlias`,
738
781
  `addMergeKey`, `setStyle`, `setTag`, `addDocument`, `removeDocument`. `.modify(fn)` exposes
739
- [yaml](https://eemeli.org/yaml/). See [the YAML dialect guide](./docs/guides/yaml-dialect.md).
782
+ [yaml](https://eemeli.org/yaml/). See [the YAML dialect guide](https://github.com/Project-Builder-Schematics/project-builder-sdk/blob/main/docs/guides/yaml-dialect.md).
740
783
 
741
784
  ### `@pbuilder/sdk/css`
742
785
 
@@ -756,7 +799,7 @@ await css
756
799
  Named ops: `setDeclaration`, `removeDeclaration`, and the query `getDeclaration(target, property)`,
757
800
  which ends the chain and resolves to `{ value, important }` (also exported as
758
801
  `getDeclaration(root, target, property)` for use inside `.modify(fn)`). `.modify(fn)` exposes
759
- [postcss](https://postcss.org/). See [the CSS dialect guide](./docs/guides/css-dialect.md).
802
+ [postcss](https://postcss.org/). See [the CSS dialect guide](https://github.com/Project-Builder-Schematics/project-builder-sdk/blob/main/docs/guides/css-dialect.md).
760
803
 
761
804
  ### `@pbuilder/sdk/csharp`
762
805
 
@@ -774,7 +817,7 @@ await csharp
774
817
 
775
818
  Named ops: `addUsing`, `addBaseType`, `addMember`, `addConstructorParameter`. `.modify(fn)` exposes
776
819
  [web-tree-sitter](https://github.com/tree-sitter/tree-sitter/tree/master/lib/binding_web) and the
777
- C# `language`. See [the C# dialect guide](./docs/guides/csharp-dialect.md).
820
+ C# `language`. See [the C# dialect guide](https://github.com/Project-Builder-Schematics/project-builder-sdk/blob/main/docs/guides/csharp-dialect.md).
778
821
 
779
822
  ### `@pbuilder/sdk/aspnet`
780
823
 
@@ -790,7 +833,7 @@ await aspnet
790
833
  .addService("Scoped", "IOrders", "SqlOrders", { serviceFrom: "Shop.Application.Ports", implementationFrom: "Shop.Infrastructure" });
791
834
  ```
792
835
 
793
- See [the ASP.NET dialect guide](./docs/guides/aspnet-dialect.md).
836
+ See [the ASP.NET dialect guide](https://github.com/Project-Builder-Schematics/project-builder-sdk/blob/main/docs/guides/aspnet-dialect.md).
794
837
 
795
838
  ### `@pbuilder/sdk/msbuild`
796
839
 
@@ -808,7 +851,7 @@ await msbuild.find("Shop.slnx").addProject("src/Shop.Api/Shop.Api.csproj", { fol
808
851
  ```
809
852
 
810
853
  Named ops: `addProjectReference`, `addProject`. `.modify(fn)` exposes [saxes](https://github.com/lddubeau/saxes).
811
- See [the MSBuild dialect guide](./docs/guides/msbuild-dialect.md).
854
+ See [the MSBuild dialect guide](https://github.com/Project-Builder-Schematics/project-builder-sdk/blob/main/docs/guides/msbuild-dialect.md).
812
855
 
813
856
  ### `@pbuilder/sdk/nestjs`
814
857
 
@@ -825,7 +868,7 @@ await nestjs
825
868
  ```
826
869
 
827
870
  Extra named ops: `addProvider`, `addController`, `addModuleImport`, `addExport`. `.modify(fn)`
828
- exposes ts-morph. See [the NestJS dialect guide](./docs/guides/nestjs-dialect.md).
871
+ exposes ts-morph. See [the NestJS dialect guide](https://github.com/Project-Builder-Schematics/project-builder-sdk/blob/main/docs/guides/nestjs-dialect.md).
829
872
 
830
873
  ### `@pbuilder/sdk/angular`
831
874
 
@@ -847,7 +890,7 @@ Extra named ops: `addComponentImport`, `addComponentProvider`, `addRootProvider`
847
890
  `addLazyRoute`, `addInjection`, `addInput`, `addModel`, `addOutput`, `addSignal`, `addComputed`,
848
891
  `addNgModuleImport`, `addDeclaration`, `addNgModuleProvider`, `addNgModuleExport`, `addBootstrap`.
849
892
  `.modify(fn)` exposes ts-morph. See
850
- [the Angular dialect guide](./docs/guides/angular-dialect.md).
893
+ [the Angular dialect guide](https://github.com/Project-Builder-Schematics/project-builder-sdk/blob/main/docs/guides/angular-dialect.md).
851
894
 
852
895
  ### `.modify()` — the universal escape hatch
853
896
 
@@ -881,7 +924,7 @@ still flushes as a **single** write. Two things to respect:
881
924
  boundary.
882
925
  - **`.modify()` runs with full process privilege — it is not a sandbox.** Your own
883
926
  callbacks are your own trust; before importing a *third-party* dialect or op-pack built
884
- on it, read [SECURITY.md](./SECURITY.md).
927
+ on it, read [SECURITY.md](https://github.com/Project-Builder-Schematics/project-builder-sdk/blob/main/SECURITY.md).
885
928
 
886
929
  ### `.inspect()` — reading the AST back
887
930
 
@@ -906,7 +949,7 @@ a node you keep goes stale after the next edit.
906
949
  ### Going deeper
907
950
 
908
951
  Everything dialect-related lives in one reference page —
909
- [Authoring a dialect](./docs/guides/authoring-a-dialect.md): the complete method-by-method
952
+ [Authoring a dialect](https://github.com/Project-Builder-Schematics/project-builder-sdk/blob/main/docs/guides/authoring-a-dialect.md): the complete method-by-method
910
953
  contracts of both shipped dialects (collision rules, idempotency, rejection semantics),
911
954
  how coalescing turns chained edits into one directive, async usage, and building a dialect
912
955
  of your own with `defineDialect`/`defineOpPack`, validated by the conformance kit (the
@@ -916,14 +959,14 @@ is written down.
916
959
 
917
960
  ## Documentation
918
961
 
919
- The full reading path lives in [`docs/guides/`](./docs/guides/README.md):
962
+ The full reading path lives in [`docs/guides/`](https://github.com/Project-Builder-Schematics/project-builder-sdk/blob/main/docs/guides/README.md):
920
963
 
921
- 1. [Quickstart](./docs/guides/quickstart.md) — standalone factory package, tsconfig, codegen, test.
922
- 2. [Authoring verbs](./docs/guides/authoring-verbs.md) — the seven verbs + `find().read()` in full.
923
- 3. [Authoring `create` templates](./docs/guides/create-templates.md) — the template language.
924
- 4. [Error contract](./docs/guides/authoring-errors.md) — `AuthoringError` and recovery.
925
- 5. [Pending Directives](./docs/guides/pending-directives.md) — previewing pending changes.
926
- 6. [Authoring a dialect](./docs/guides/authoring-a-dialect.md) — AST-aware mutation per file type.
964
+ 1. [Quickstart](https://github.com/Project-Builder-Schematics/project-builder-sdk/blob/main/docs/guides/quickstart.md) — standalone factory package, tsconfig, codegen, test.
965
+ 2. [Authoring verbs](https://github.com/Project-Builder-Schematics/project-builder-sdk/blob/main/docs/guides/authoring-verbs.md) — the seven verbs + `find().read()` in full.
966
+ 3. [Authoring `create` templates](https://github.com/Project-Builder-Schematics/project-builder-sdk/blob/main/docs/guides/create-templates.md) — the template language.
967
+ 4. [Error contract](https://github.com/Project-Builder-Schematics/project-builder-sdk/blob/main/docs/guides/authoring-errors.md) — `AuthoringError` and recovery.
968
+ 5. [Pending Directives](https://github.com/Project-Builder-Schematics/project-builder-sdk/blob/main/docs/guides/pending-directives.md) — previewing pending changes.
969
+ 6. [Authoring a dialect](https://github.com/Project-Builder-Schematics/project-builder-sdk/blob/main/docs/guides/authoring-a-dialect.md) — AST-aware mutation per file type.
927
970
 
928
971
  ## Design at a glance
929
972
 
@@ -22,6 +22,7 @@ export declare class StdioEngineClient implements EngineClient {
22
22
  });
23
23
  emit(batch: Batch): Promise<void>;
24
24
  read(path: string): Promise<string | undefined>;
25
+ list(pattern: string, ignore?: readonly string[]): Promise<readonly string[]>;
25
26
  commit(result?: unknown): Promise<void>;
26
27
  discard(): Promise<void>;
27
28
  }
@@ -228,6 +228,15 @@ export class StdioEngineClient {
228
228
  return undefined;
229
229
  return result.content;
230
230
  }
231
+ // ADR-0070 (engine): `ignore` is optional on the wire, so it is sent only when given. A host
232
+ // rejection, such as a pattern that escapes the workspace, throws as a read's does.
233
+ async list(pattern, ignore) {
234
+ const response = await this.#call("tree.list", ignore === undefined ? { pattern } : { pattern, ignore });
235
+ if (response.error !== undefined) {
236
+ throw new IntentRejectedError(response.error.message);
237
+ }
238
+ return response.result.paths;
239
+ }
231
240
  // A-14: the Result rides in the ir.commit params, the key present only when one is declared.
232
241
  async commit(result) {
233
242
  const response = await this.#call("ir.commit", result === undefined ? {} : { result });
@@ -351,6 +351,57 @@ function isErrnoException(err) {
351
351
  return err instanceof Error && "code" in err;
352
352
  }
353
353
 
354
+ // src/bounded-contexts/authoring/domain/valueobjects/findings.ts
355
+ var SCOPE_INPUTS = ["include", "exclude"];
356
+ var STRING = { types: ["string"] };
357
+ var NUMBER = { types: ["number"] };
358
+ var POSITION = {
359
+ types: ["object"],
360
+ properties: [
361
+ { key: "line", schema: NUMBER },
362
+ { key: "column", schema: NUMBER }
363
+ ],
364
+ required: ["line", "column"]
365
+ };
366
+ function findingsWith(extra) {
367
+ const finding = {
368
+ types: ["object"],
369
+ properties: [
370
+ { key: "rule", schema: STRING },
371
+ { key: "message", schema: STRING },
372
+ { key: "severity", schema: { types: ["string"], choices: ["error", "warning"] } },
373
+ { key: "path", schema: STRING },
374
+ {
375
+ key: "range",
376
+ schema: {
377
+ types: ["object"],
378
+ properties: [
379
+ { key: "start", schema: POSITION },
380
+ { key: "end", schema: POSITION }
381
+ ],
382
+ required: ["start"]
383
+ }
384
+ },
385
+ {
386
+ key: "fix",
387
+ schema: {
388
+ types: ["object"],
389
+ properties: [
390
+ { key: "schematic", schema: STRING },
391
+ { key: "inputs", schema: { types: ["object"] } }
392
+ ],
393
+ required: ["schematic"]
394
+ }
395
+ },
396
+ ...extra
397
+ ],
398
+ required: ["rule", "message", "severity"]
399
+ };
400
+ return { types: ["object"], properties: [{ key: "items", schema: { types: ["array"], items: finding } }], required: ["items"] };
401
+ }
402
+ var FINDINGS = findingsWith([]);
403
+ var SOURCED_FINDINGS = findingsWith([{ key: "source", schema: STRING }]);
404
+
354
405
  // src/bounded-contexts/authoring/infrastructure/in/codegen/emit-type.ts
355
406
  var GENERATED_HEADER = "// AUTO-GENERATED by pbuilder-codegen — do not edit. Regenerate: pbuilder-codegen <package-dir>";
356
407
  var IDENTIFIER_RE = /^[A-Za-z_$][\w$]*$/;
@@ -399,24 +450,24 @@ function emitResult(result) {
399
450
  const members = result.properties.map(({ key, schema }) => `${emitPropertyKey(key)}${required.has(key) ? "" : "?"}: ${emitResult(schema)}`);
400
451
  return members.length === 0 ? "Record<string, never>" : `{ ${members.join("; ")} }`;
401
452
  }
453
+ case "string":
454
+ return result.choices === undefined ? kind : result.choices.map((choice) => JSON.stringify(choice)).join(" | ");
402
455
  default:
403
456
  return kind;
404
457
  }
405
458
  }).join(" | ");
406
459
  }
407
- function emitInputType(schema, digest) {
408
- const members = schema.properties.map(emitProperty).join(`
460
+ var SCOPE_MEMBERS = [
461
+ " /** Globs or literal paths to check */",
462
+ " include?: string[];",
463
+ " /** Globs or literal paths to skip */",
464
+ " exclude?: string[];"
465
+ ];
466
+ function emitInputType(schema, digest, evaluation = false) {
467
+ const members = [...schema.properties.map(emitProperty), ...evaluation ? SCOPE_MEMBERS : []].join(`
409
468
  `);
410
- return [
411
- GENERATED_HEADER,
412
- `// @schema-digest sha256:${digest}`,
413
- "",
414
- "export type Input = {",
415
- members,
416
- "};",
417
- ...schema.result === undefined ? [] : ["", `export type Result = ${emitResult(schema.result)};`],
418
- ""
419
- ].join(`
469
+ const result = evaluation ? ["", `export type Findings = ${emitResult(FINDINGS)};`, "", "export type Result = Findings;"] : schema.result === undefined ? [] : ["", `export type Result = ${emitResult(schema.result)};`];
470
+ return [GENERATED_HEADER, `// @schema-digest sha256:${digest}`, "", "export type Input = {", members, "};", ...result, ""].join(`
420
471
  `);
421
472
  }
422
473
 
@@ -431,6 +482,9 @@ function readObject(path) {
431
482
  throw new Error("invalid object");
432
483
  return value;
433
484
  }
485
+ function isEvaluation(registration) {
486
+ return isPlainObject(registration) && registration.role === "evaluation";
487
+ }
434
488
  function discoverProject(directory) {
435
489
  let selected = resolve(directory ?? process.cwd());
436
490
  if (directory === undefined) {
@@ -494,7 +548,7 @@ function discoverProject(directory) {
494
548
  try {
495
549
  if (!statSync(module).isFile())
496
550
  throw new Error("nonregular module");
497
- entries.push({ kind: "target", label, directory: dirname(realpathSync(module)) });
551
+ entries.push({ kind: "target", label, directory: dirname(realpathSync(module)), evaluation: isEvaluation(registration) });
498
552
  } catch {
499
553
  entries.push({ kind: "failure", label, diagnostic: `cannot resolve factory module ${JSON.stringify(module)}` });
500
554
  }
@@ -535,7 +589,7 @@ function discoverProject(directory) {
535
589
  }
536
590
  if (factories !== 1)
537
591
  throw new Error("ambiguous or missing factory");
538
- entries.push({ kind: "target", label, directory: realpathSync(path) });
592
+ entries.push({ kind: "target", label, directory: realpathSync(path), evaluation: isEvaluation(registration) });
539
593
  } catch {
540
594
  entries.push({ kind: "failure", label, diagnostic: `directory requires exactly one regular factory.ts or factory.js: ${JSON.stringify(path)}` });
541
595
  }
@@ -563,6 +617,22 @@ class SchemaSufficiencyFailure extends Error {
563
617
  }
564
618
  }
565
619
 
620
+ class RoleContractFailure extends Error {
621
+ constructor(problem) {
622
+ super(problem);
623
+ this.name = "RoleContractFailure";
624
+ }
625
+ }
626
+ function checkEvaluationSchema(schema) {
627
+ if (schema.result !== undefined) {
628
+ throw new RoleContractFailure("an evaluation schematic declares a Result, which the role fixes as Findings");
629
+ }
630
+ const imposed = schema.properties.find((property) => SCOPE_INPUTS.includes(property.key));
631
+ if (imposed !== undefined) {
632
+ throw new RoleContractFailure(`an evaluation schematic declares the input ${JSON.stringify(imposed.key)}, which the role imposes`);
633
+ }
634
+ }
635
+
566
636
  class OutputWriteFailure extends Error {
567
637
  constructor(outputPath, cause, reason) {
568
638
  const code = isErrnoException(cause) ? cause.code : undefined;
@@ -585,7 +655,7 @@ function assertOutputLeaf(outputPath) {
585
655
  throw err instanceof OutputWriteFailure ? err : new OutputWriteFailure(outputPath, err);
586
656
  }
587
657
  }
588
- function generateSchema(packageDir) {
658
+ function generateSchema(packageDir, evaluation = false) {
589
659
  const schemaPath = schemaPathFor(packageDir);
590
660
  const raw = readFileSync2(schemaPath, "utf-8");
591
661
  const schema = parseSchema(raw);
@@ -593,8 +663,10 @@ function generateSchema(packageDir) {
593
663
  if (sufficiencyFindings.length > 0) {
594
664
  throw new SchemaSufficiencyFailure(sufficiencyFindings);
595
665
  }
666
+ if (evaluation)
667
+ checkEvaluationSchema(schema);
596
668
  const digest = computeSchemaDigest(raw);
597
- const output = emitInputType(schema, digest);
669
+ const output = emitInputType(schema, digest, evaluation);
598
670
  const outputPath = join3(packageDir, GENERATED_FILENAME);
599
671
  try {
600
672
  if (process.platform === "linux" || process.platform === "darwin") {
@@ -777,11 +849,11 @@ function runProject(directory) {
777
849
  seen.add(output);
778
850
  if (!statSync2(schemaPath).isFile())
779
851
  throw new Error("nonregular schema");
780
- generateSchema(entry.directory);
852
+ generateSchema(entry.directory, entry.evaluation);
781
853
  generated++;
782
854
  } catch (error) {
783
855
  failed++;
784
- const diagnostic = error instanceof SchemaParseFailure ? formatParseError(schemaPath, error) : error instanceof SchemaSufficiencyFailure ? formatSufficiencyError(schemaPath, error) : error instanceof WriteContainmentRefusal ? "refusing to write outside the selected project root" : error instanceof OutputWriteFailure ? "cannot write a regular, non-symbolic-link output" : "cannot read or generate schema.json";
856
+ const diagnostic = error instanceof SchemaParseFailure ? formatParseError(schemaPath, error) : error instanceof SchemaSufficiencyFailure ? formatSufficiencyError(schemaPath, error) : error instanceof RoleContractFailure ? `pbuilder-codegen: ${schemaPath}: ${error.message}` : error instanceof WriteContainmentRefusal ? "refusing to write outside the selected project root" : error instanceof OutputWriteFailure ? "cannot write a regular, non-symbolic-link output" : "cannot read or generate schema.json";
785
857
  console.error(`pbuilder-codegen: ${JSON.stringify(entry.label)} (${JSON.stringify(entry.directory)}): ${JSON.stringify(diagnostic)}`);
786
858
  }
787
859
  }
@@ -1,6 +1,7 @@
1
1
  import type { JsonValue } from "../../../domain/valueobjects/wire.ts";
2
2
  import type { FoundHandle, WritableHandle } from "../../../domain/entities/handle-state.ts";
3
3
  import type { PendingDirective } from "../pending-directives/render.ts";
4
+ import type { GlobOptions } from "../../../domain/services/define-dialect.ts";
4
5
  /**
5
6
  * Locates an existing file and returns a `FoundHandle` for reading or removing it.
6
7
  *
@@ -17,6 +18,20 @@ import type { PendingDirective } from "../pending-directives/render.ts";
17
18
  * else replaceContent("src/config.ts", patch(c));
18
19
  */
19
20
  export declare function find(path: string): FoundHandle;
21
+ /**
22
+ * Opens every file `pattern` matches as a `FoundHandle`, ordered by path, leaving out every file
23
+ * an `ignore` pattern matches; resolves `[]` when none matches (A-130). `*` matches within one
24
+ * path segment, `?` one character, `**` any number of segments and `{a,b}` either alternative;
25
+ * every other character is literal, so `ignore` is the only way to leave files out. It sees the
26
+ * run (A-131): a file created earlier is listed, one removed earlier is not. Unlike `find`, it
27
+ * is asynchronous, because it lists files first.
28
+ *
29
+ * @example
30
+ * for (const file of await glob("src/domain/**", { ignore: ["**\/*.test.ts"] })) {
31
+ * const content = await file.read();
32
+ * }
33
+ */
34
+ export declare function glob(pattern: string, options?: GlobOptions): Promise<FoundHandle[]>;
20
35
  export declare function create(path: string, opts: {
21
36
  options: JsonValue | undefined;
22
37
  force?: boolean;
@@ -86,6 +86,23 @@ function buildFoundHandle(path) {
86
86
  export function find(path) {
87
87
  return buildFoundHandle(path);
88
88
  }
89
+ /**
90
+ * Opens every file `pattern` matches as a `FoundHandle`, ordered by path, leaving out every file
91
+ * an `ignore` pattern matches; resolves `[]` when none matches (A-130). `*` matches within one
92
+ * path segment, `?` one character, `**` any number of segments and `{a,b}` either alternative;
93
+ * every other character is literal, so `ignore` is the only way to leave files out. It sees the
94
+ * run (A-131): a file created earlier is listed, one removed earlier is not. Unlike `find`, it
95
+ * is asynchronous, because it lists files first.
96
+ *
97
+ * @example
98
+ * for (const file of await glob("src/domain/**", { ignore: ["**\/*.test.ts"] })) {
99
+ * const content = await file.read();
100
+ * }
101
+ */
102
+ export async function glob(pattern, options) {
103
+ const paths = await currentContext().session.list(pattern, options?.ignore);
104
+ return paths.map(buildFoundHandle);
105
+ }
89
106
  // `template` receives the defaulted options and runs after the active run is resolved, so a
90
107
  // call outside a run fails before any template file is read.
91
108
  export function create(path, opts, template) {
@@ -27,6 +27,14 @@ export declare function requirePackageAnchors(missingAnchorMessage: string): {
27
27
  packageDir: string;
28
28
  files: PackageFiles;
29
29
  };
30
+ /** What a run of a wrapped factory receives besides its input. */
31
+ export interface RunDeps {
32
+ client: EngineClient;
33
+ /** The role of the schematic (CA-14), as the runner received it; only `evaluation` changes the run. */
34
+ role?: string;
35
+ /** The qualified name `collection:schematic` of the schematic, as the runner received it. */
36
+ name?: string;
37
+ }
30
38
  /**
31
39
  * Builds a SessionContext and runs the factory inside it, flushing buffered
32
40
  * directives at run end (REQ-KIT-05) — a write-only factory still emits.
@@ -81,6 +89,13 @@ export declare function requirePackageAnchors(missingAnchorMessage: string): {
81
89
  *
82
90
  * const runner = defineFactory<Input>(bareFactory, { packageDir: import.meta.dir });
83
91
  * await runner(input, { client });
92
+ *
93
+ * The returned runner takes, besides the client, the `role` and the qualified `name` of the
94
+ * schematic it runs, as the caller received them (CA-19). With the role `evaluation`, `fn`
95
+ * returns its Findings, checked against the shape the role imposes, each finding's `source` is
96
+ * set to `name`, and `fn` receives the scope inputs `include` and `exclude`; every `glob` result
97
+ * is narrowed to the scope and so is every finding with a path (A-120 to A-124). Any other role,
98
+ * or none, runs as a generator.
84
99
  */
85
100
  export declare function defineFactory<O, R = void>(fn: (o: O) => R | Promise<R>, options?: ({
86
101
  packageDir: string | URL;
@@ -90,6 +105,4 @@ export declare function defineFactory<O, R = void>(fn: (o: O) => R | Promise<R>,
90
105
  packageFiles?: undefined;
91
106
  }) & {
92
107
  declaredDialects?: readonly string[];
93
- }): (o: O, deps: {
94
- client: EngineClient;
95
- }) => Promise<R>;
108
+ }): (o: O, deps: RunDeps) => Promise<R>;