@kurvball/rehearse 0.0.0-stage → 1.2.1

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 (266) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +102 -2
  3. package/dist/affected/affected.d.ts +22 -0
  4. package/dist/affected/affected.js +162 -0
  5. package/dist/affected/index.d.ts +1 -0
  6. package/dist/affected/index.js +1 -0
  7. package/dist/args.d.ts +12 -0
  8. package/dist/args.js +42 -0
  9. package/dist/cli.d.ts +4 -0
  10. package/dist/cli.js +100 -0
  11. package/dist/commands/check.d.ts +2 -0
  12. package/dist/commands/check.js +42 -0
  13. package/dist/commands/clean.d.ts +2 -0
  14. package/dist/commands/clean.js +37 -0
  15. package/dist/commands/command.d.ts +29 -0
  16. package/dist/commands/command.js +29 -0
  17. package/dist/commands/compare.d.ts +4 -0
  18. package/dist/commands/compare.js +84 -0
  19. package/dist/commands/drive.d.ts +2 -0
  20. package/dist/commands/drive.js +244 -0
  21. package/dist/commands/index.d.ts +3 -0
  22. package/dist/commands/index.js +32 -0
  23. package/dist/commands/init.d.ts +2 -0
  24. package/dist/commands/init.js +19 -0
  25. package/dist/commands/list.d.ts +2 -0
  26. package/dist/commands/list.js +69 -0
  27. package/dist/commands/open.d.ts +2 -0
  28. package/dist/commands/open.js +60 -0
  29. package/dist/commands/people.d.ts +2 -0
  30. package/dist/commands/people.js +49 -0
  31. package/dist/commands/run.d.ts +4 -0
  32. package/dist/commands/run.js +82 -0
  33. package/dist/commands/services.d.ts +28 -0
  34. package/dist/commands/services.js +51 -0
  35. package/dist/commands/stage.d.ts +7 -0
  36. package/dist/commands/stage.js +49 -0
  37. package/dist/commands/up.d.ts +3 -0
  38. package/dist/commands/up.js +77 -0
  39. package/dist/commands/validate.d.ts +2 -0
  40. package/dist/commands/validate.js +35 -0
  41. package/dist/commands/worlds.d.ts +2 -0
  42. package/dist/commands/worlds.js +15 -0
  43. package/dist/compare/announce.d.ts +6 -0
  44. package/dist/compare/announce.js +27 -0
  45. package/dist/compare/compare.d.ts +82 -0
  46. package/dist/compare/compare.js +310 -0
  47. package/dist/compare/diff.d.ts +15 -0
  48. package/dist/compare/diff.js +105 -0
  49. package/dist/compare/index.d.ts +4 -0
  50. package/dist/compare/index.js +4 -0
  51. package/dist/compare/setaside.d.ts +29 -0
  52. package/dist/compare/setaside.js +121 -0
  53. package/dist/compare/verdict.d.ts +21 -0
  54. package/dist/compare/verdict.js +30 -0
  55. package/dist/drive/aria.d.ts +8 -0
  56. package/dist/drive/aria.js +12 -0
  57. package/dist/drive/browser.d.ts +34 -0
  58. package/dist/drive/browser.js +216 -0
  59. package/dist/drive/daemon.d.ts +1 -0
  60. package/dist/drive/daemon.js +171 -0
  61. package/dist/drive/grammar.d.ts +93 -0
  62. package/dist/drive/grammar.js +303 -0
  63. package/dist/drive/index.d.ts +4 -0
  64. package/dist/drive/index.js +4 -0
  65. package/dist/drive/names.d.ts +24 -0
  66. package/dist/drive/names.js +97 -0
  67. package/dist/drive/state.d.ts +13 -0
  68. package/dist/drive/state.js +28 -0
  69. package/dist/errors.d.ts +26 -0
  70. package/dist/errors.js +32 -0
  71. package/dist/exec.d.ts +16 -0
  72. package/dist/exec.js +43 -0
  73. package/dist/git/checkout.d.ts +11 -0
  74. package/dist/git/checkout.js +84 -0
  75. package/dist/git/git.d.ts +7 -0
  76. package/dist/git/git.js +27 -0
  77. package/dist/git/index.d.ts +2 -0
  78. package/dist/git/index.js +2 -0
  79. package/dist/index.d.ts +18 -0
  80. package/dist/index.js +15 -0
  81. package/dist/kinds/all.d.ts +4 -0
  82. package/dist/kinds/all.js +4 -0
  83. package/dist/kinds/call/check.d.ts +29 -0
  84. package/dist/kinds/call/check.js +187 -0
  85. package/dist/kinds/call/definition.d.ts +16 -0
  86. package/dist/kinds/call/definition.js +33 -0
  87. package/dist/kinds/call/hurl.d.ts +65 -0
  88. package/dist/kinds/call/hurl.js +333 -0
  89. package/dist/kinds/call/kind.d.ts +8 -0
  90. package/dist/kinds/call/kind.js +122 -0
  91. package/dist/kinds/call/send.d.ts +32 -0
  92. package/dist/kinds/call/send.js +152 -0
  93. package/dist/kinds/call/words.d.ts +22 -0
  94. package/dist/kinds/call/words.js +24 -0
  95. package/dist/kinds/file/kind.d.ts +44 -0
  96. package/dist/kinds/file/kind.js +331 -0
  97. package/dist/kinds/file/layouts.d.ts +14 -0
  98. package/dist/kinds/file/layouts.js +103 -0
  99. package/dist/kinds/flow/kind.d.ts +21 -0
  100. package/dist/kinds/flow/kind.js +401 -0
  101. package/dist/kinds/flow/literal.d.ts +8 -0
  102. package/dist/kinds/flow/literal.js +148 -0
  103. package/dist/kinds/index.d.ts +10 -0
  104. package/dist/kinds/index.js +8 -0
  105. package/dist/kinds/kind.d.ts +57 -0
  106. package/dist/kinds/kind.js +21 -0
  107. package/dist/kinds/piece/canvas.d.ts +18 -0
  108. package/dist/kinds/piece/canvas.js +165 -0
  109. package/dist/kinds/piece/conventions.d.ts +12 -0
  110. package/dist/kinds/piece/conventions.js +101 -0
  111. package/dist/kinds/piece/csf.d.ts +10 -0
  112. package/dist/kinds/piece/csf.js +304 -0
  113. package/dist/kinds/piece/kind.d.ts +12 -0
  114. package/dist/kinds/piece/kind.js +297 -0
  115. package/dist/kinds/piece/server.d.ts +23 -0
  116. package/dist/kinds/piece/server.js +236 -0
  117. package/dist/manifest/fill.d.ts +4 -0
  118. package/dist/manifest/fill.js +7 -0
  119. package/dist/manifest/index.d.ts +5 -0
  120. package/dist/manifest/index.js +5 -0
  121. package/dist/manifest/init.d.ts +1 -0
  122. package/dist/manifest/init.js +47 -0
  123. package/dist/manifest/load.d.ts +7 -0
  124. package/dist/manifest/load.js +244 -0
  125. package/dist/manifest/types.d.ts +253 -0
  126. package/dist/manifest/types.js +7 -0
  127. package/dist/manifest/yaml.d.ts +5 -0
  128. package/dist/manifest/yaml.js +47 -0
  129. package/dist/people/index.d.ts +1 -0
  130. package/dist/people/index.js +1 -0
  131. package/dist/people/people.d.ts +39 -0
  132. package/dist/people/people.js +139 -0
  133. package/dist/run/cache.d.ts +20 -0
  134. package/dist/run/cache.js +98 -0
  135. package/dist/run/index.d.ts +4 -0
  136. package/dist/run/index.js +3 -0
  137. package/dist/run/observation.d.ts +27 -0
  138. package/dist/run/observation.js +1 -0
  139. package/dist/run/session.d.ts +32 -0
  140. package/dist/run/session.js +258 -0
  141. package/dist/run/vars.d.ts +3 -0
  142. package/dist/run/vars.js +13 -0
  143. package/dist/scenarios/area.d.ts +6 -0
  144. package/dist/scenarios/area.js +37 -0
  145. package/dist/scenarios/files.d.ts +9 -0
  146. package/dist/scenarios/files.js +26 -0
  147. package/dist/scenarios/glob.d.ts +6 -0
  148. package/dist/scenarios/glob.js +106 -0
  149. package/dist/scenarios/index.d.ts +4 -0
  150. package/dist/scenarios/index.js +4 -0
  151. package/dist/scenarios/read.d.ts +18 -0
  152. package/dist/scenarios/read.js +54 -0
  153. package/dist/scenarios/scenario.d.ts +34 -0
  154. package/dist/scenarios/scenario.js +10 -0
  155. package/dist/schema.d.ts +14 -0
  156. package/dist/schema.js +122 -0
  157. package/dist/services/index.d.ts +2 -0
  158. package/dist/services/index.js +2 -0
  159. package/dist/services/registry.d.ts +23 -0
  160. package/dist/services/registry.js +49 -0
  161. package/dist/services/service.d.ts +22 -0
  162. package/dist/services/service.js +284 -0
  163. package/dist/stage/api.d.ts +28 -0
  164. package/dist/stage/api.js +206 -0
  165. package/dist/stage/client/client/api.js +11 -0
  166. package/dist/stage/client/client/index.js +1 -0
  167. package/dist/stage/client/features/canvas/call.js +65 -0
  168. package/dist/stage/client/features/canvas/context.js +1 -0
  169. package/dist/stage/client/features/canvas/file.js +36 -0
  170. package/dist/stage/client/features/canvas/flow.js +59 -0
  171. package/dist/stage/client/features/canvas/index.js +1 -0
  172. package/dist/stage/client/features/canvas/observed.js +8 -0
  173. package/dist/stage/client/features/canvas/parts.js +24 -0
  174. package/dist/stage/client/features/canvas/piece.js +31 -0
  175. package/dist/stage/client/features/canvas/reach.js +6 -0
  176. package/dist/stage/client/features/canvas/views.js +16 -0
  177. package/dist/stage/client/features/list/index.js +1 -0
  178. package/dist/stage/client/features/list/list.js +53 -0
  179. package/dist/stage/client/features/list/reach.js +10 -0
  180. package/dist/stage/client/features/scenario/heading.js +14 -0
  181. package/dist/stage/client/features/scenario/index.js +1 -0
  182. package/dist/stage/client/features/scenario/reach.js +9 -0
  183. package/dist/stage/client/features/scenario/scenario.js +145 -0
  184. package/dist/stage/client/features/try/index.js +1 -0
  185. package/dist/stage/client/features/try/reach.js +12 -0
  186. package/dist/stage/client/features/try/try.js +65 -0
  187. package/dist/stage/client/index.html +16 -0
  188. package/dist/stage/client/main.js +24 -0
  189. package/dist/stage/client/primitives/busy.js +6 -0
  190. package/dist/stage/client/primitives/focus.js +21 -0
  191. package/dist/stage/client/primitives/h.js +25 -0
  192. package/dist/stage/client/primitives/index.js +6 -0
  193. package/dist/stage/client/primitives/keyed.js +16 -0
  194. package/dist/stage/client/primitives/say.js +6 -0
  195. package/dist/stage/client/primitives/state.js +21 -0
  196. package/dist/stage/client/primitives/types.js +1 -0
  197. package/dist/stage/client/primitives/verdicts.js +8 -0
  198. package/dist/stage/client/stage.css +652 -0
  199. package/dist/stage/compared.d.ts +20 -0
  200. package/dist/stage/compared.js +58 -0
  201. package/dist/stage/files.d.ts +4 -0
  202. package/dist/stage/files.js +59 -0
  203. package/dist/stage/guard.d.ts +3 -0
  204. package/dist/stage/guard.js +20 -0
  205. package/dist/stage/http.d.ts +12 -0
  206. package/dist/stage/http.js +34 -0
  207. package/dist/stage/index.d.ts +1 -0
  208. package/dist/stage/index.js +1 -0
  209. package/dist/stage/sending.d.ts +18 -0
  210. package/dist/stage/sending.js +66 -0
  211. package/dist/stage/server.d.ts +31 -0
  212. package/dist/stage/server.js +250 -0
  213. package/dist/version.d.ts +2 -0
  214. package/dist/version.js +5 -0
  215. package/dist/worlds/define.d.ts +16 -0
  216. package/dist/worlds/define.js +45 -0
  217. package/dist/worlds/index.d.ts +2 -0
  218. package/dist/worlds/index.js +2 -0
  219. package/dist/worlds/worlds.d.ts +15 -0
  220. package/dist/worlds/worlds.js +46 -0
  221. package/llms.txt +46 -0
  222. package/package.json +84 -3
  223. package/schema/v1/announce.schema.json +28 -0
  224. package/schema/v1/check.schema.json +67 -0
  225. package/schema/v1/clean.schema.json +19 -0
  226. package/schema/v1/common.schema.json +210 -0
  227. package/schema/v1/comparison.schema.json +298 -0
  228. package/schema/v1/dependents.schema.json +30 -0
  229. package/schema/v1/drive.schema.json +112 -0
  230. package/schema/v1/error.schema.json +26 -0
  231. package/schema/v1/file-scenario.schema.json +175 -0
  232. package/schema/v1/flow.schema.json +216 -0
  233. package/schema/v1/init.schema.json +20 -0
  234. package/schema/v1/list.schema.json +70 -0
  235. package/schema/v1/manifest.schema.json +430 -0
  236. package/schema/v1/observation.schema.json +388 -0
  237. package/schema/v1/open.schema.json +14 -0
  238. package/schema/v1/people.schema.json +88 -0
  239. package/schema/v1/samples/announce.yaml +5 -0
  240. package/schema/v1/samples/check.json +13 -0
  241. package/schema/v1/samples/clean.json +1 -0
  242. package/schema/v1/samples/comparison.json +83 -0
  243. package/schema/v1/samples/dependents.json +7 -0
  244. package/schema/v1/samples/drive.json +10 -0
  245. package/schema/v1/samples/error.json +10 -0
  246. package/schema/v1/samples/file-scenario.yaml +13 -0
  247. package/schema/v1/samples/flow.yaml +13 -0
  248. package/schema/v1/samples/init.json +1 -0
  249. package/schema/v1/samples/list.json +24 -0
  250. package/schema/v1/samples/manifest.yaml +55 -0
  251. package/schema/v1/samples/observation.json +49 -0
  252. package/schema/v1/samples/open.json +6 -0
  253. package/schema/v1/samples/people.json +11 -0
  254. package/schema/v1/samples/services.json +27 -0
  255. package/schema/v1/samples/stage.json +6 -0
  256. package/schema/v1/samples/try.json +13 -0
  257. package/schema/v1/samples/up.json +16 -0
  258. package/schema/v1/samples/validate.json +7 -0
  259. package/schema/v1/samples/worlds.json +21 -0
  260. package/schema/v1/services.schema.json +72 -0
  261. package/schema/v1/stage.schema.json +14 -0
  262. package/schema/v1/try.schema.json +56 -0
  263. package/schema/v1/up.schema.json +55 -0
  264. package/schema/v1/validate.schema.json +40 -0
  265. package/schema/v1/worlds.schema.json +33 -0
  266. package/skill/rehearse/SKILL.md +148 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kurvball
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 CHANGED
@@ -1,3 +1,103 @@
1
- # Temporary Holding Version
1
+ # Rehearse
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Rehearse a change before it ships.
4
+
5
+ [Docs](https://rehearse.kurvball.ca/) · [Contributing](CONTRIBUTING.md) · [Security](SECURITY.md) ·
6
+ [Changelog](CHANGELOG.md)
7
+
8
+ Rehearse sits beside any repository. It brings the product up, signs in as named people, starts from named worlds
9
+ with stand-ins for what can't run, runs scenarios on a baseline and on the head, and compares them. A person tries any
10
+ scenario on one page, the stage. An agent does the same through commands that print JSON.
11
+
12
+ ```bash
13
+ rehearse compare --base main
14
+ ```
15
+
16
+ ```text
17
+ 11 as on the base · 1 new · 1 changed and said so · 4 changed without saying so · 1 fails on the head
18
+ ```
19
+
20
+ ## What a repository declares
21
+
22
+ One file, `rehearse.yaml`. Every block is optional: a repository declares what it has.
23
+
24
+ ```yaml
25
+ base: main
26
+ services:
27
+ api:
28
+ up: pnpm --filter api serve --port {{port}}
29
+ port: auto
30
+ ready: http://127.0.0.1:{{port}}/health
31
+ signIn: 'node scripts/people.mjs --api {{api_url}}'
32
+ people:
33
+ owner: { default: true }
34
+ worlds:
35
+ one-org: { add: 'node scripts/seed.mjs --api {{api_url}}', default: true }
36
+ scenarios:
37
+ pieces: ['packages/ui/src/**/*.stories.tsx']
38
+ calls: ['apps/api/src/**/*.hurl']
39
+ files: ['**/*.rehearse.yaml']
40
+ flows: ['**/*.flow.yaml']
41
+ ```
42
+
43
+ Scenarios use formats agents already write:
44
+
45
+ | Kind | Format | What is compared |
46
+ | ----- | ------------------------------------- | ---------------------------------------------- |
47
+ | piece | Storybook's CSF, beside the component | the accessibility tree, errors, axe violations |
48
+ | flow | steps by accessible name | the accessibility tree after each step |
49
+ | call | Hurl's plain part, beside the handler | status and body, with ids and times set aside |
50
+ | file | `*.rehearse.yaml`: input, run, output | the output's fields, by column |
51
+
52
+ ## Commands
53
+
54
+ | Command | What it does |
55
+ | ------------------------------------------- | ------------------------------------------------- |
56
+ | `rehearse init` | Writes a starter `rehearse.yaml` |
57
+ | `rehearse check` | Reads the manifest and every scenario file |
58
+ | `rehearse services`, `people`, `worlds` | What can come up, who you can be, where you start |
59
+ | `rehearse list [--affected <file>…]` | The scenarios, or those a change reaches, and why |
60
+ | `rehearse up`, `rehearse down` | Brings services up with a world, and stops them |
61
+ | `rehearse run <scenario> [--on <checkout>]` | One observation of one scenario |
62
+ | `rehearse compare [--base <ref>]` | Every scenario on the base and the head, compared |
63
+ | `rehearse drive <step>` | One step for an agent: click, fill, snapshot… |
64
+ | `rehearse clean` | Removes old base checkouts, runs and comparisons |
65
+ | `rehearse validate <schema> [file]` | Checks a file or stdin against a schema in v1 |
66
+
67
+ Every command takes `--json` and prints one object described by a schema in [`schema/v1/`](schema/v1/). Within v1 an
68
+ output only gains optional fields and new values in open fields, so a reader ignores what it doesn't know.
69
+
70
+ ```bash
71
+ rehearse services --json | rehearse validate services
72
+ ```
73
+
74
+ ## Examples
75
+
76
+ Rehearse runs on [Kurvball](https://www.kurvball.ca) from a scratch clone, with every kind of scenario compared. See
77
+ [examples/kurvball](examples/kurvball/): its `prove.sh` makes the whole proof again.
78
+
79
+ ## Status
80
+
81
+ Rehearse 1.0 is built on [the decisions in its design](docs/plans/v1.md). [CHANGELOG.md](CHANGELOG.md) says what each version
82
+ changed, and [RELEASING.md](RELEASING.md) how a change gets its changeset and how a release and a hotfix go. Each
83
+ release is a tag and a [GitHub Release](https://github.com/kurvball/rehearse/releases) with the package's tarball.
84
+
85
+ It runs on its own. Other tools read it only through its JSON commands, and [Ashlar](https://github.com/kurvball/ashlar), when present, lends it an import
86
+ graph. Neither is required.
87
+
88
+ ## Name
89
+
90
+ The package is `@kurvball/rehearse`; its command is `rehearse`. The bare name `rehearse` is taken on npm and on PyPI by
91
+ unrelated projects. It isn't on npm yet: each release is a tarball on its GitHub Release.
92
+
93
+ ## Licence
94
+
95
+ MIT, [Copyright (c) 2026 Kurvball](LICENSE). The licence covers the code, not the names: Kurvball, Rehearse and Ashlar
96
+ are Kurvball's, and a fork that changes the code should go by another name.
97
+
98
+ ## Contributing
99
+
100
+ Ask a question or propose an idea in [Discussions](https://github.com/kurvball/rehearse/discussions); report a bug with
101
+ the [bug form](https://github.com/kurvball/rehearse/issues/new/choose). [CONTRIBUTING.md](CONTRIBUTING.md) says what is
102
+ likely to be accepted, [AI_POLICY.md](AI_POLICY.md) how to contribute with AI tools, and [SECURITY.md](SECURITY.md) how
103
+ to report a security problem privately.
@@ -0,0 +1,22 @@
1
+ import type { Manifest } from '../manifest/index.ts';
2
+ import { type Scenario } from '../scenarios/index.ts';
3
+ interface Pkg {
4
+ dir: string;
5
+ name: string;
6
+ deps: string[];
7
+ }
8
+ export declare function workspaceOf(root: string): Pkg[];
9
+ export interface Reached {
10
+ scenario: Scenario;
11
+ reachedBy: string[];
12
+ }
13
+ export interface Affected {
14
+ by: 'all' | 'graph' | 'packages';
15
+ graph: string | null;
16
+ files: string[];
17
+ said: string | null;
18
+ reached: Reached[];
19
+ }
20
+ export declare function graphCommand(m: Manifest, checkout: string): string | null;
21
+ export declare function affected(m: Manifest, checkout: string, given: readonly string[], scenarios: readonly Scenario[]): Promise<Affected>;
22
+ export {};
@@ -0,0 +1,162 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import path from 'node:path';
3
+ import { parse } from 'yaml';
4
+ import { sh, tail } from '../exec.js';
5
+ import { packageDirOf, packageNameOf, findFiles, matches, toPosix, } from '../scenarios/index.js';
6
+ import { validate } from '../schema.js';
7
+ export function workspaceOf(root) {
8
+ let globs = [];
9
+ try {
10
+ const ws = parse(readFileSync(path.join(root, 'pnpm-workspace.yaml'), 'utf8'));
11
+ globs = ws?.packages ?? [];
12
+ }
13
+ catch {
14
+ try {
15
+ const pkg = JSON.parse(readFileSync(path.join(root, 'package.json'), 'utf8'));
16
+ globs = Array.isArray(pkg.workspaces) ? pkg.workspaces : (pkg.workspaces?.packages ?? []);
17
+ }
18
+ catch {
19
+ globs = [];
20
+ }
21
+ }
22
+ const dirs = findFiles(root, globs.filter((g) => !g.startsWith('!')).map((g) => `${g.replace(/\/+$/, '')}/package.json`)).map((f) => path.dirname(f));
23
+ return dirs.map((dir) => {
24
+ const pkg = JSON.parse(readFileSync(path.join(root, dir, 'package.json'), 'utf8'));
25
+ const deps = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'].flatMap((k) => Object.keys(pkg[k] ?? {}));
26
+ return { dir, name: typeof pkg.name === 'string' ? pkg.name : dir, deps };
27
+ });
28
+ }
29
+ function dependentsDirectlyOrNotOf(pkgs, name) {
30
+ const out = new Set();
31
+ const queue = [name];
32
+ while (queue.length) {
33
+ const at = queue.shift();
34
+ for (const p of pkgs)
35
+ if (p.deps.includes(at) && !out.has(p.name)) {
36
+ out.add(p.name);
37
+ queue.push(p.name);
38
+ }
39
+ }
40
+ return out;
41
+ }
42
+ export function graphCommand(m, checkout) {
43
+ if (m.affected.graph)
44
+ return m.affected.graph;
45
+ const config = ['ts', 'mts', 'js', 'mjs', 'json'].some((ext) => existsSync(path.join(checkout, `ashlar.config.${ext}`)));
46
+ if (!config)
47
+ return null;
48
+ const local = path.join(checkout, 'node_modules', '.bin', 'ashlar');
49
+ if (existsSync(local))
50
+ return `${JSON.stringify(local)} dependents`;
51
+ const onPath = (process.env.PATH ?? '')
52
+ .split(path.delimiter)
53
+ .filter(Boolean)
54
+ .some((dir) => existsSync(path.join(dir, 'ashlar')));
55
+ return onPath ? 'ashlar dependents' : null;
56
+ }
57
+ const quote = (s) => `'${s.replace(/'/g, `'\\''`)}'`;
58
+ async function dependentsFromGraph(command, checkout, files) {
59
+ const ran = await sh(`${command} ${files.map(quote).join(' ')} --json`, {
60
+ cwd: checkout,
61
+ timeoutMs: 120_000,
62
+ });
63
+ if (ran.code !== 0)
64
+ return `\`${command}\` failed (exit ${ran.code}${ran.stderr ? `: ${tail(ran.stderr)}` : ''})`;
65
+ let out;
66
+ try {
67
+ out = JSON.parse(ran.stdout);
68
+ }
69
+ catch {
70
+ return `\`${command}\` didn't print JSON`;
71
+ }
72
+ const invalid = validate('dependents', out);
73
+ if (invalid.length)
74
+ return `\`${command}\` printed something other than schema/v1/dependents: ${invalid[0].says}`;
75
+ const read = out;
76
+ return { dependents: read.dependents, unknown: read.unknown ?? [] };
77
+ }
78
+ export async function affected(m, checkout, given, scenarios) {
79
+ const files = [
80
+ ...new Set(given.map((f) => toPosix(path.relative(checkout, path.resolve(checkout, f))))),
81
+ ].sort();
82
+ const pkgs = workspaceOf(checkout);
83
+ const graph = graphCommand(m, checkout);
84
+ let said = null;
85
+ let graphRead = null;
86
+ if (graph) {
87
+ const read = await dependentsFromGraph(graph, checkout, files);
88
+ if (typeof read === 'string')
89
+ said = `${read}, so Rehearse took the touched packages and the packages that depend on them.`;
90
+ else
91
+ graphRead = read;
92
+ }
93
+ else
94
+ said =
95
+ 'No import graph is here (no Ashlar, no affected.graph), so Rehearse took the touched packages and the packages that depend on them.';
96
+ const jsOnly = pkgs.length === 0
97
+ ? 'No JavaScript workspace is here, and v1 reads workspace links for JavaScript packages only.'
98
+ : 'v1 reads workspace links for JavaScript packages only: other languages’ packages count as folders.';
99
+ const pkgOf = (file) => {
100
+ const dir = packageDirOf(checkout, file);
101
+ if (!dir || path.resolve(dir) === path.resolve(checkout))
102
+ return null;
103
+ const rel = toPosix(path.relative(checkout, dir));
104
+ return { dir: rel, name: packageNameOf(dir) ?? rel };
105
+ };
106
+ const reached = [];
107
+ for (const s of scenarios) {
108
+ const why = new Set();
109
+ const own = s.from === 'checkout' ? pkgOf(s.file) : null;
110
+ const serviceCwd = s.service ? m.services[s.service]?.cwd : null;
111
+ const servicePkg = serviceCwd ? pkgOf(`${serviceCwd}/package.json`) : null;
112
+ if (s.from === 'manifest' && s.covers.length === 0)
113
+ why.add('it is read beside the manifest and says nothing of what it covers');
114
+ const applyCoveringRule = (r, through, withDependents, graphHolds = false) => {
115
+ const via = through && through !== r ? `, which depends on ${through}` : '';
116
+ if (s.from === 'checkout' && r === s.file)
117
+ why.add(through && through !== r ? `it depends on ${through}, directly or not` : 'its own file changed');
118
+ if (s.covers.length && matches(r, s.covers))
119
+ why.add(`it covers ${r}${via}`);
120
+ const p = pkgOf(r);
121
+ if (!p) {
122
+ if (!graphHolds && (!through || through === r))
123
+ why.add(`${r} is outside every package, so it reaches every scenario`);
124
+ return;
125
+ }
126
+ for (const [mine, label] of [
127
+ [own, 'it is'],
128
+ [servicePkg, 'its service is'],
129
+ ]) {
130
+ if (!mine)
131
+ continue;
132
+ if (mine.dir === p.dir)
133
+ why.add(`${label} in ${p.name}, which the change ${via ? `reaches (${r}${via})` : 'touches'}`);
134
+ else if (withDependents && dependentsDirectlyOrNotOf(pkgs, p.name).has(mine.name))
135
+ why.add(`${label} in ${mine.name}, which depends on ${p.name}`);
136
+ }
137
+ };
138
+ for (const f of files) {
139
+ if (graphRead && !graphRead.unknown.includes(f) && f in graphRead.dependents) {
140
+ applyCoveringRule(f, null, false, true);
141
+ for (const r of graphRead.dependents[f] ?? [])
142
+ applyCoveringRule(r, f, false, true);
143
+ }
144
+ else
145
+ applyCoveringRule(f, null, true);
146
+ }
147
+ if (why.size)
148
+ reached.push({ scenario: s, reachedBy: [...why] });
149
+ }
150
+ const unknown = graphRead?.unknown.filter((f) => files.includes(f)) ?? [];
151
+ return {
152
+ by: graphRead ? 'graph' : 'packages',
153
+ graph: graphRead ? graph : null,
154
+ files,
155
+ said: graphRead
156
+ ? unknown.length
157
+ ? `The graph doesn't hold ${unknown.join(', ')}: for ${unknown.length === 1 ? 'it' : 'those'}, Rehearse took the package and the packages that depend on it.`
158
+ : null
159
+ : [said, jsOnly].filter(Boolean).join(' ') || null,
160
+ reached,
161
+ };
162
+ }
@@ -0,0 +1 @@
1
+ export { affected } from './affected.ts';
@@ -0,0 +1 @@
1
+ export { affected } from './affected.js';
package/dist/args.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ export interface Args {
2
+ positional: string[];
3
+ values: Map<string, string[]>;
4
+ flags: Set<string>;
5
+ }
6
+ export interface ArgSpec {
7
+ valued: readonly string[];
8
+ bare: readonly string[];
9
+ }
10
+ export declare function parseArgs(argv: readonly string[], spec: ArgSpec, command: string): Args;
11
+ export declare const one: (args: Args, name: string) => string | null;
12
+ export declare const many: (args: Args, name: string) => string[];
package/dist/args.js ADDED
@@ -0,0 +1,42 @@
1
+ import { usage } from './errors.js';
2
+ export function parseArgs(argv, spec, command) {
3
+ const positional = [];
4
+ const values = new Map();
5
+ const flags = new Set();
6
+ for (let i = 0; i < argv.length; i += 1) {
7
+ const arg = argv[i];
8
+ if (arg === '--') {
9
+ positional.push(...argv.slice(i + 1));
10
+ break;
11
+ }
12
+ if (!arg.startsWith('--') || arg === '--') {
13
+ positional.push(arg);
14
+ continue;
15
+ }
16
+ const equals = arg.indexOf('=');
17
+ const name = arg.slice(2, equals === -1 ? undefined : equals);
18
+ if (spec.bare.includes(name)) {
19
+ if (equals !== -1)
20
+ throw usage(`\`--${name}\` takes no value.`);
21
+ flags.add(name);
22
+ continue;
23
+ }
24
+ if (!spec.valued.includes(name)) {
25
+ const known = [...spec.valued, ...spec.bare].map((f) => `--${f}`);
26
+ throw usage(`rehearse ${command} takes no \`--${name}\`.${known.length ? ` It takes ${known.join(', ')}.` : ''}`);
27
+ }
28
+ let value;
29
+ if (equals !== -1)
30
+ value = arg.slice(equals + 1);
31
+ else {
32
+ i += 1;
33
+ value = argv[i];
34
+ }
35
+ if (value === undefined || value === '' || (equals === -1 && value.startsWith('--')))
36
+ throw usage(`Give \`--${name}\` a value.`);
37
+ values.set(name, [...(values.get(name) ?? []), value]);
38
+ }
39
+ return { positional, values, flags };
40
+ }
41
+ export const one = (args, name) => args.values.get(name)?.at(-1) ?? null;
42
+ export const many = (args, name) => args.values.get(name) ?? [];
package/dist/cli.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { type Context, type Said } from './commands/index.ts';
3
+ export declare const USAGE: string;
4
+ export declare function main(argv: readonly string[], ctx: Omit<Context, 'manifest' | 'json'>): Promise<Said>;
package/dist/cli.js ADDED
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/env node
2
+ import { parseArgs } from './args.js';
3
+ import { columns, GLOBAL_BARE, GLOBAL_VALUED, COMMANDS } from './commands/index.js';
4
+ import { errorJson, RehearseError, usage } from './errors.js';
5
+ import { VERSION } from './version.js';
6
+ export const USAGE = `Rehearse ${VERSION}: rehearse a change before it ships.
7
+
8
+ Usage: rehearse <command> [options]
9
+
10
+ Commands:
11
+ ${columns(COMMANDS.map((c) => [c.name, c.summary]))}
12
+
13
+ Every command takes:
14
+ --json Prints one JSON object (schema/v1/<command>.schema.json), and nothing else on stdout.
15
+ --manifest <file> The rehearse.yaml to read. Default: $REHEARSE_MANIFEST, then rehearse.yaml here or above.
16
+ --help Says how to use the command.
17
+
18
+ rehearse --version prints the version.
19
+ `;
20
+ function helpOf(name) {
21
+ const c = COMMANDS.find((x) => x.name === name);
22
+ if (!c)
23
+ return USAGE;
24
+ return `${c.summary}\n\nUsage: ${c.usage}\n`;
25
+ }
26
+ export async function main(argv, ctx) {
27
+ const json = argv.includes('--json');
28
+ const words = argv.filter((a) => a !== '--json');
29
+ const name = words[0];
30
+ const rest = json ? [...words.slice(1), '--json'] : words.slice(1);
31
+ try {
32
+ if (name === undefined || name === '--help' || name === 'help')
33
+ return { json: { v: 1, usage: USAGE }, text: USAGE, code: 0 };
34
+ if (name === '--version' || name === 'version')
35
+ return { json: { v: 1, version: VERSION }, text: `${VERSION}\n`, code: 0 };
36
+ const command = COMMANDS.find((c) => c.name === name);
37
+ if (!command)
38
+ throw usage(`Rehearse has no command “${name}”. It has ${COMMANDS.map((c) => c.name).join(', ')}.`);
39
+ if (command.ownGrammar) {
40
+ const given = [];
41
+ let manifest = null;
42
+ for (let i = 0; i < rest.length; i += 1) {
43
+ if (rest[i] === '--manifest')
44
+ manifest = rest[++i] ?? null;
45
+ else if (rest[i].startsWith('--manifest='))
46
+ manifest = rest[i].slice('--manifest='.length);
47
+ else if (rest[i] === '--help')
48
+ return { json: { v: 1, usage: helpOf(command.name) }, text: helpOf(command.name), code: 0 };
49
+ else
50
+ given.push(rest[i]);
51
+ }
52
+ return await command.run({ positional: given, values: new Map(), flags: new Set() }, { ...ctx, manifest, json });
53
+ }
54
+ const args = parseArgs(rest, { valued: [...command.spec.valued, ...GLOBAL_VALUED], bare: [...command.spec.bare, ...GLOBAL_BARE] }, command.name);
55
+ if (args.flags.has('help'))
56
+ return { json: { v: 1, usage: helpOf(command.name) }, text: helpOf(command.name), code: 0 };
57
+ return await command.run(args, { ...ctx, manifest: args.values.get('manifest')?.at(-1) ?? null, json });
58
+ }
59
+ catch (error) {
60
+ const out = errorJson(error);
61
+ const code = error instanceof RehearseError ? error.exit : 1;
62
+ const text = `${out.error.says}\n${code === 2 && name ? `\n${helpOf(name)}` : ''}`;
63
+ if (!(error instanceof RehearseError) &&
64
+ error instanceof Error &&
65
+ error.stack &&
66
+ process.env.REHEARSE_DEBUG)
67
+ return { json: out, text: `${text}${error.stack}\n`, code, refused: true };
68
+ return { json: out, text, code, refused: true };
69
+ }
70
+ }
71
+ const written = (stream, text) => new Promise((resolve) => stream.write(text, () => resolve()));
72
+ async function cli() {
73
+ const argv = process.argv.slice(2);
74
+ const out = await main(argv, {
75
+ cwd: process.cwd(),
76
+ env: process.env,
77
+ progress: (line) => void process.stderr.write(`${line}\n`),
78
+ });
79
+ const printedItsOwnJsonAsItWent = out.json === null;
80
+ if (argv.includes('--json') && !printedItsOwnJsonAsItWent)
81
+ await written(process.stdout, `${JSON.stringify(out.json)}\n`);
82
+ else if (out.text)
83
+ await written(out.refused ? process.stderr : process.stdout, out.text);
84
+ process.exitCode = out.code;
85
+ }
86
+ function stopWhatItBroughtUpOn(signal, code) {
87
+ process.once(signal, () => {
88
+ process.stderr.write(`Stopping what Rehearse brought up (${signal}).\n`);
89
+ void import('./services/index.js').then((s) => s.downStartedHere()).finally(() => process.exit(code));
90
+ });
91
+ }
92
+ const invoked = process.argv[1]
93
+ ? await import('node:fs').then((fs) => fs.realpathSync(process.argv[1]))
94
+ : '';
95
+ const here = await import('node:url').then((u) => u.fileURLToPath(import.meta.url));
96
+ if (invoked === here) {
97
+ stopWhatItBroughtUpOn('SIGINT', 130);
98
+ stopWhatItBroughtUpOn('SIGTERM', 143);
99
+ await cli();
100
+ }
@@ -0,0 +1,2 @@
1
+ import type { Command } from './command.ts';
2
+ export declare const check: Command;
@@ -0,0 +1,42 @@
1
+ import { checkoutOf, columns, manifestOf, said } from './command.js';
2
+ import { one } from '../args.js';
3
+ import { KINDS } from '../manifest/index.js';
4
+ import { readScenarios } from '../scenarios/index.js';
5
+ export const check = {
6
+ name: 'check',
7
+ summary: "Checks rehearse.yaml and reads every scenario file, saying what it can't read and where.",
8
+ usage: 'rehearse check [--on <checkout>] [--json]',
9
+ spec: { valued: ['on'], bare: [] },
10
+ async run(args, ctx) {
11
+ const m = manifestOf(ctx);
12
+ const checkout = checkoutOf(m, one(args, 'on'), ctx.cwd);
13
+ const read = await readScenarios(m, checkout);
14
+ const counts = Object.fromEntries(KINDS.map((k) => [k, read.scenarios.filter((s) => s.kind === k).length]));
15
+ const out = {
16
+ v: 1,
17
+ ok: read.refused.length === 0,
18
+ manifest: m.file,
19
+ checkout,
20
+ base: m.base,
21
+ services: Object.keys(m.services).length,
22
+ people: Object.keys(m.people).length,
23
+ worlds: Object.keys(m.worlds).length,
24
+ standins: Object.keys(m.standins).length,
25
+ scenarios: counts,
26
+ refused: read.refused,
27
+ };
28
+ const text = [
29
+ `${m.file} reads well.`,
30
+ columns([
31
+ ['base', m.base],
32
+ ['services', String(out.services)],
33
+ ['people', String(out.people)],
34
+ ['worlds', String(out.worlds)],
35
+ ['stand-ins', String(out.standins)],
36
+ ...KINDS.map((k) => [`${k}s`, String(counts[k])]),
37
+ ]),
38
+ ...read.refused.map((r) => `✗ ${r.file}${r.line ? `:${r.line}` : ''}: ${r.says}`),
39
+ ].join('\n');
40
+ return said(out, `${text}\n`, out.ok ? 0 : 1);
41
+ },
42
+ };
@@ -0,0 +1,2 @@
1
+ import type { Command } from './command.ts';
2
+ export declare const clean: Command;
@@ -0,0 +1,37 @@
1
+ import { existsSync, readdirSync, rmSync, statSync } from 'node:fs';
2
+ import path from 'node:path';
3
+ import { checkoutOf, manifestOf, said } from './command.js';
4
+ import { evict } from '../git/index.js';
5
+ import { stateDir } from '../services/index.js';
6
+ const DAY = 24 * 60 * 60 * 1000;
7
+ export const clean = {
8
+ name: 'clean',
9
+ summary: 'Removes base checkouts beyond the budget, and runs and comparisons older than a week. Keeps the cache.',
10
+ usage: 'rehearse clean [--all] [--json]\n\n--all also removes every base checkout and the baseline cache.',
11
+ spec: { valued: [], bare: ['all'] },
12
+ async run(args, ctx) {
13
+ const m = manifestOf(ctx);
14
+ const repo = checkoutOf(m, null, ctx.cwd);
15
+ const all = args.flags.has('all');
16
+ const removed = all
17
+ ? evict({ ...m, budget: { ...m.budget, checkouts: 0 } }, repo)
18
+ : evict(m, repo);
19
+ for (const folder of ['runs', 'compare', ...(all ? ['cache'] : [])]) {
20
+ const dir = path.join(stateDir(m.dir), folder);
21
+ if (!existsSync(dir))
22
+ continue;
23
+ for (const entry of readdirSync(dir)) {
24
+ const at = path.join(dir, entry);
25
+ if (entry === 'latest.json' || entry === 'latest-partial.json')
26
+ continue;
27
+ if (all || Date.now() - statSync(at).mtimeMs > 7 * DAY) {
28
+ rmSync(at, { recursive: true, force: true });
29
+ removed.push(at);
30
+ }
31
+ }
32
+ }
33
+ return said({ v: 1, removed }, removed.length
34
+ ? `Removed ${removed.length}:\n${removed.map((r) => ` ${r}`).join('\n')}\n`
35
+ : 'Nothing to remove.\n');
36
+ },
37
+ };
@@ -0,0 +1,29 @@
1
+ import type { Args, ArgSpec } from '../args.ts';
2
+ import { type Manifest } from '../manifest/index.ts';
3
+ export interface Context {
4
+ cwd: string;
5
+ env: NodeJS.ProcessEnv;
6
+ manifest: string | null;
7
+ json: boolean;
8
+ progress(line: string): void;
9
+ }
10
+ export interface Said {
11
+ json: unknown;
12
+ text: string;
13
+ code: number;
14
+ refused?: boolean;
15
+ }
16
+ export interface Command {
17
+ name: string;
18
+ summary: string;
19
+ usage: string;
20
+ spec: ArgSpec;
21
+ ownGrammar?: boolean;
22
+ run(args: Args, ctx: Context): Promise<Said>;
23
+ }
24
+ export declare const GLOBAL_VALUED: readonly ['manifest'];
25
+ export declare const GLOBAL_BARE: readonly ['json', 'help'];
26
+ export declare const said: (json: unknown, text: string, code?: number) => Said;
27
+ export declare function manifestOf(ctx: Context): Manifest;
28
+ export declare function checkoutOf(m: Manifest, given: string | null, cwd: string): string;
29
+ export declare function columns(rows: readonly (readonly [string, string])[], indent?: string): string;
@@ -0,0 +1,29 @@
1
+ import path from 'node:path';
2
+ import { findManifest, loadManifest } from '../manifest/index.js';
3
+ import { topOf } from '../git/index.js';
4
+ import { RehearseError } from '../errors.js';
5
+ import { existsSync, statSync } from 'node:fs';
6
+ export const GLOBAL_VALUED = ['manifest'];
7
+ export const GLOBAL_BARE = ['json', 'help'];
8
+ export const said = (json, text, code = 0) => ({ json, text, code });
9
+ export function manifestOf(ctx) {
10
+ return loadManifest(findManifest(ctx.cwd, ctx.manifest, ctx.env));
11
+ }
12
+ export function checkoutOf(m, given, cwd) {
13
+ if (given) {
14
+ const dir = path.resolve(cwd, given);
15
+ if (!existsSync(dir) || !statSync(dir).isDirectory())
16
+ throw new RehearseError('no_checkout', `There is no checkout at ${dir}.`);
17
+ return dir;
18
+ }
19
+ if (m.checkout) {
20
+ if (!existsSync(m.checkout))
21
+ throw new RehearseError('no_checkout', `The manifest's checkout ${m.checkout} isn't there. Name one with --on.`);
22
+ return m.checkout;
23
+ }
24
+ return topOf(m.dir) ?? m.dir;
25
+ }
26
+ export function columns(rows, indent = ' ') {
27
+ const width = Math.min(32, Math.max(0, ...rows.map(([a]) => a.length)));
28
+ return rows.map(([a, b]) => `${indent}${a.padEnd(width)} ${b}`.trimEnd()).join('\n');
29
+ }
@@ -0,0 +1,4 @@
1
+ import type { Command } from './command.ts';
2
+ import { type Comparison } from '../compare/index.ts';
3
+ export declare function comparisonText(c: Comparison): string;
4
+ export declare const compare: Command;