@kurvball/rehearse 0.0.0-stage → 1.3.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 (270) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +107 -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 +30 -0
  16. package/dist/commands/command.js +38 -0
  17. package/dist/commands/compare.d.ts +4 -0
  18. package/dist/commands/compare.js +89 -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 +84 -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 +53 -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 +83 -0
  46. package/dist/compare/compare.js +335 -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 +5 -0
  50. package/dist/compare/index.js +5 -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 +90 -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/git/seed.d.ts +3 -0
  80. package/dist/git/seed.js +115 -0
  81. package/dist/index.d.ts +18 -0
  82. package/dist/index.js +15 -0
  83. package/dist/kinds/all.d.ts +4 -0
  84. package/dist/kinds/all.js +4 -0
  85. package/dist/kinds/call/check.d.ts +29 -0
  86. package/dist/kinds/call/check.js +187 -0
  87. package/dist/kinds/call/definition.d.ts +16 -0
  88. package/dist/kinds/call/definition.js +33 -0
  89. package/dist/kinds/call/hurl.d.ts +65 -0
  90. package/dist/kinds/call/hurl.js +333 -0
  91. package/dist/kinds/call/kind.d.ts +8 -0
  92. package/dist/kinds/call/kind.js +122 -0
  93. package/dist/kinds/call/send.d.ts +32 -0
  94. package/dist/kinds/call/send.js +152 -0
  95. package/dist/kinds/call/words.d.ts +22 -0
  96. package/dist/kinds/call/words.js +24 -0
  97. package/dist/kinds/file/kind.d.ts +44 -0
  98. package/dist/kinds/file/kind.js +331 -0
  99. package/dist/kinds/file/layouts.d.ts +14 -0
  100. package/dist/kinds/file/layouts.js +103 -0
  101. package/dist/kinds/flow/kind.d.ts +21 -0
  102. package/dist/kinds/flow/kind.js +412 -0
  103. package/dist/kinds/flow/literal.d.ts +8 -0
  104. package/dist/kinds/flow/literal.js +148 -0
  105. package/dist/kinds/index.d.ts +10 -0
  106. package/dist/kinds/index.js +8 -0
  107. package/dist/kinds/kind.d.ts +63 -0
  108. package/dist/kinds/kind.js +21 -0
  109. package/dist/kinds/piece/canvas.d.ts +18 -0
  110. package/dist/kinds/piece/canvas.js +165 -0
  111. package/dist/kinds/piece/conventions.d.ts +12 -0
  112. package/dist/kinds/piece/conventions.js +101 -0
  113. package/dist/kinds/piece/csf.d.ts +10 -0
  114. package/dist/kinds/piece/csf.js +304 -0
  115. package/dist/kinds/piece/kind.d.ts +12 -0
  116. package/dist/kinds/piece/kind.js +297 -0
  117. package/dist/kinds/piece/server.d.ts +23 -0
  118. package/dist/kinds/piece/server.js +236 -0
  119. package/dist/manifest/fill.d.ts +4 -0
  120. package/dist/manifest/fill.js +7 -0
  121. package/dist/manifest/index.d.ts +5 -0
  122. package/dist/manifest/index.js +5 -0
  123. package/dist/manifest/init.d.ts +1 -0
  124. package/dist/manifest/init.js +47 -0
  125. package/dist/manifest/load.d.ts +7 -0
  126. package/dist/manifest/load.js +245 -0
  127. package/dist/manifest/types.d.ts +255 -0
  128. package/dist/manifest/types.js +7 -0
  129. package/dist/manifest/yaml.d.ts +5 -0
  130. package/dist/manifest/yaml.js +47 -0
  131. package/dist/people/index.d.ts +1 -0
  132. package/dist/people/index.js +1 -0
  133. package/dist/people/people.d.ts +39 -0
  134. package/dist/people/people.js +139 -0
  135. package/dist/run/cache.d.ts +20 -0
  136. package/dist/run/cache.js +98 -0
  137. package/dist/run/index.d.ts +5 -0
  138. package/dist/run/index.js +4 -0
  139. package/dist/run/observation.d.ts +27 -0
  140. package/dist/run/observation.js +1 -0
  141. package/dist/run/parallel.d.ts +28 -0
  142. package/dist/run/parallel.js +140 -0
  143. package/dist/run/session.d.ts +35 -0
  144. package/dist/run/session.js +399 -0
  145. package/dist/run/vars.d.ts +3 -0
  146. package/dist/run/vars.js +13 -0
  147. package/dist/scenarios/area.d.ts +6 -0
  148. package/dist/scenarios/area.js +37 -0
  149. package/dist/scenarios/files.d.ts +9 -0
  150. package/dist/scenarios/files.js +26 -0
  151. package/dist/scenarios/glob.d.ts +6 -0
  152. package/dist/scenarios/glob.js +106 -0
  153. package/dist/scenarios/index.d.ts +4 -0
  154. package/dist/scenarios/index.js +4 -0
  155. package/dist/scenarios/read.d.ts +18 -0
  156. package/dist/scenarios/read.js +54 -0
  157. package/dist/scenarios/scenario.d.ts +34 -0
  158. package/dist/scenarios/scenario.js +10 -0
  159. package/dist/schema.d.ts +14 -0
  160. package/dist/schema.js +122 -0
  161. package/dist/services/index.d.ts +2 -0
  162. package/dist/services/index.js +2 -0
  163. package/dist/services/registry.d.ts +23 -0
  164. package/dist/services/registry.js +49 -0
  165. package/dist/services/service.d.ts +23 -0
  166. package/dist/services/service.js +313 -0
  167. package/dist/stage/api.d.ts +30 -0
  168. package/dist/stage/api.js +206 -0
  169. package/dist/stage/client/client/api.js +11 -0
  170. package/dist/stage/client/client/index.js +1 -0
  171. package/dist/stage/client/features/canvas/call.js +65 -0
  172. package/dist/stage/client/features/canvas/context.js +1 -0
  173. package/dist/stage/client/features/canvas/file.js +36 -0
  174. package/dist/stage/client/features/canvas/flow.js +59 -0
  175. package/dist/stage/client/features/canvas/index.js +1 -0
  176. package/dist/stage/client/features/canvas/observed.js +8 -0
  177. package/dist/stage/client/features/canvas/parts.js +24 -0
  178. package/dist/stage/client/features/canvas/piece.js +31 -0
  179. package/dist/stage/client/features/canvas/reach.js +6 -0
  180. package/dist/stage/client/features/canvas/views.js +16 -0
  181. package/dist/stage/client/features/list/index.js +1 -0
  182. package/dist/stage/client/features/list/list.js +53 -0
  183. package/dist/stage/client/features/list/reach.js +10 -0
  184. package/dist/stage/client/features/scenario/heading.js +14 -0
  185. package/dist/stage/client/features/scenario/index.js +1 -0
  186. package/dist/stage/client/features/scenario/reach.js +9 -0
  187. package/dist/stage/client/features/scenario/scenario.js +145 -0
  188. package/dist/stage/client/features/try/index.js +1 -0
  189. package/dist/stage/client/features/try/reach.js +12 -0
  190. package/dist/stage/client/features/try/try.js +65 -0
  191. package/dist/stage/client/index.html +16 -0
  192. package/dist/stage/client/main.js +24 -0
  193. package/dist/stage/client/primitives/busy.js +6 -0
  194. package/dist/stage/client/primitives/focus.js +21 -0
  195. package/dist/stage/client/primitives/h.js +25 -0
  196. package/dist/stage/client/primitives/index.js +6 -0
  197. package/dist/stage/client/primitives/keyed.js +16 -0
  198. package/dist/stage/client/primitives/say.js +6 -0
  199. package/dist/stage/client/primitives/state.js +21 -0
  200. package/dist/stage/client/primitives/types.js +1 -0
  201. package/dist/stage/client/primitives/verdicts.js +8 -0
  202. package/dist/stage/client/stage.css +652 -0
  203. package/dist/stage/compared.d.ts +20 -0
  204. package/dist/stage/compared.js +58 -0
  205. package/dist/stage/files.d.ts +4 -0
  206. package/dist/stage/files.js +59 -0
  207. package/dist/stage/guard.d.ts +3 -0
  208. package/dist/stage/guard.js +20 -0
  209. package/dist/stage/http.d.ts +12 -0
  210. package/dist/stage/http.js +34 -0
  211. package/dist/stage/index.d.ts +1 -0
  212. package/dist/stage/index.js +1 -0
  213. package/dist/stage/sending.d.ts +18 -0
  214. package/dist/stage/sending.js +66 -0
  215. package/dist/stage/server.d.ts +33 -0
  216. package/dist/stage/server.js +253 -0
  217. package/dist/version.d.ts +2 -0
  218. package/dist/version.js +5 -0
  219. package/dist/worlds/define.d.ts +16 -0
  220. package/dist/worlds/define.js +45 -0
  221. package/dist/worlds/index.d.ts +2 -0
  222. package/dist/worlds/index.js +2 -0
  223. package/dist/worlds/worlds.d.ts +15 -0
  224. package/dist/worlds/worlds.js +46 -0
  225. package/llms.txt +46 -0
  226. package/package.json +84 -3
  227. package/schema/v1/announce.schema.json +28 -0
  228. package/schema/v1/check.schema.json +67 -0
  229. package/schema/v1/clean.schema.json +19 -0
  230. package/schema/v1/common.schema.json +210 -0
  231. package/schema/v1/comparison.schema.json +298 -0
  232. package/schema/v1/dependents.schema.json +30 -0
  233. package/schema/v1/drive.schema.json +112 -0
  234. package/schema/v1/error.schema.json +26 -0
  235. package/schema/v1/file-scenario.schema.json +175 -0
  236. package/schema/v1/flow.schema.json +216 -0
  237. package/schema/v1/init.schema.json +20 -0
  238. package/schema/v1/list.schema.json +70 -0
  239. package/schema/v1/manifest.schema.json +434 -0
  240. package/schema/v1/observation.schema.json +388 -0
  241. package/schema/v1/open.schema.json +14 -0
  242. package/schema/v1/people.schema.json +88 -0
  243. package/schema/v1/samples/announce.yaml +5 -0
  244. package/schema/v1/samples/check.json +13 -0
  245. package/schema/v1/samples/clean.json +1 -0
  246. package/schema/v1/samples/comparison.json +83 -0
  247. package/schema/v1/samples/dependents.json +7 -0
  248. package/schema/v1/samples/drive.json +10 -0
  249. package/schema/v1/samples/error.json +10 -0
  250. package/schema/v1/samples/file-scenario.yaml +13 -0
  251. package/schema/v1/samples/flow.yaml +13 -0
  252. package/schema/v1/samples/init.json +1 -0
  253. package/schema/v1/samples/list.json +24 -0
  254. package/schema/v1/samples/manifest.yaml +55 -0
  255. package/schema/v1/samples/observation.json +49 -0
  256. package/schema/v1/samples/open.json +6 -0
  257. package/schema/v1/samples/people.json +11 -0
  258. package/schema/v1/samples/services.json +27 -0
  259. package/schema/v1/samples/stage.json +6 -0
  260. package/schema/v1/samples/try.json +13 -0
  261. package/schema/v1/samples/up.json +16 -0
  262. package/schema/v1/samples/validate.json +7 -0
  263. package/schema/v1/samples/worlds.json +21 -0
  264. package/schema/v1/services.schema.json +72 -0
  265. package/schema/v1/stage.schema.json +14 -0
  266. package/schema/v1/try.schema.json +56 -0
  267. package/schema/v1/up.schema.json +55 -0
  268. package/schema/v1/validate.schema.json +40 -0
  269. package/schema/v1/worlds.schema.json +33 -0
  270. package/skill/rehearse/SKILL.md +148 -0
@@ -0,0 +1,89 @@
1
+ import path from 'node:path';
2
+ import { checkoutOf, manifestOf, parallelOf, said } from './command.js';
3
+ import { many, one } from '../args.js';
4
+ import { compare as compareSides } from '../compare/index.js';
5
+ const VERDICT_WORDS = {
6
+ fails: 'fails on the head',
7
+ new: 'new',
8
+ unsaid: 'changed without saying so',
9
+ said: 'changed and said so',
10
+ same: 'as on the base',
11
+ };
12
+ export function comparisonText(c) {
13
+ const lines = [c.line];
14
+ if (!c.base.ok)
15
+ return `${lines.join('\n')}\n`;
16
+ for (const verdict of ['unsaid', 'fails', 'said', 'new']) {
17
+ const these = c.scenarios.filter((s) => s.verdict === verdict);
18
+ if (!these.length)
19
+ continue;
20
+ lines.push('', `${VERDICT_WORDS[verdict]}:`);
21
+ for (const s of these) {
22
+ const where = `${s.scenario.file}${s.scenario.line ? `:${s.scenario.line}` : ''}`;
23
+ lines.push(` ${s.scenario.name} (${where})${s.said === 'announced' && s.why ? ` — announced: ${s.why}` : s.said === 'edited' ? ' — its definition was edited' : ''}`);
24
+ for (const d of s.differences.slice(0, 4))
25
+ lines.push(` ${d.path}: ${d.base} → ${d.head}${d.count > 1 ? ` (${d.count} places)` : ''}`);
26
+ if (s.differences.length > 4)
27
+ lines.push(` … ${s.differences.length - 4} more`);
28
+ if (verdict === 'fails') {
29
+ if (s.failsOnBase)
30
+ lines.push(" fails on the base too: not this change's doing");
31
+ for (const f of s.failures.slice(0, 4))
32
+ lines.push(` ${f.line ? `line ${f.line}: ` : f.step ? `step ${f.step}: ` : ''}${f.text} · expected ${f.expected ?? '—'}, got ${f.got ?? '—'}`);
33
+ }
34
+ }
35
+ }
36
+ if (c.byChange.length) {
37
+ lines.push('', 'unannounced, by what changed:');
38
+ for (const b of c.byChange)
39
+ lines.push(` ${b.path} — in ${b.scenarios.length} scenario${b.scenarios.length === 1 ? '' : 's'}`);
40
+ }
41
+ if (c.gone.length)
42
+ lines.push('', 'gone from the head:', ...c.gone.map((g) => ` ${g.name} (${g.file})`));
43
+ if (c.notRun.length)
44
+ lines.push('', 'not run:', ...c.notRun.map((n) => ` ${n.scenario.name} on the ${n.side} (${n.step}): ${n.says}`));
45
+ if (c.announcedUnchanged.length)
46
+ lines.push('', 'announced, but as on the base:', ...c.announcedUnchanged.map((a) => ` ${a.scenario} — ${a.why}`));
47
+ if (c.refused.length)
48
+ lines.push('', 'not read:', ...c.refused.map((r) => ` ${r.file}${r.line ? `:${r.line}` : ''} (${r.side}): ${r.says}`));
49
+ const aside = c.scenarios.reduce((n, s) => n + Object.values(s.setAside).reduce((a, b) => a + (b ?? 0), 0), 0);
50
+ if (aside)
51
+ lines.push('', `${aside} ${aside === 1 ? 'id, time or opaque value was' : 'ids, times and opaque values were'} set aside before comparing.`);
52
+ if (c.standins.length)
53
+ lines.push(`Stand-ins: ${c.standins.map((s) => `${s.name}${s.real ? ' (real)' : ` (${s.fidelity}, for ${s.replaces})`}`).join(', ')}.`);
54
+ if (c.base.cached)
55
+ lines.push(`${c.base.cached} base observation${c.base.cached === 1 ? '' : 's'} came from the cache (${c.base.checkout.commit?.slice(0, 12)}).`);
56
+ return `${lines.join('\n')}\n`;
57
+ }
58
+ export const compare = {
59
+ name: 'compare',
60
+ summary: 'Runs scenarios on the base and on the head, compares them, and sorts each into a verdict.',
61
+ usage: "rehearse compare [<scenario>…] [--affected] [--base <ref|checkout>] [--head <ref|checkout>] [--announce <file>] [--said <scenario>]… [--world <name>] [--as <person>] [--real <stand-in>]… [--fresh] [--parallel <n>] [--json]\n\nThe base defaults to the manifest's base branch; the head to this checkout as it is now.\nScenario ids may be globs: 'apps/api/**'. It exits 0 when nothing fails on the head or changed without saying so.",
62
+ spec: {
63
+ valued: ['base', 'head', 'announce', 'said', 'world', 'as', 'real', 'parallel'],
64
+ bare: ['affected', 'fresh'],
65
+ },
66
+ async run(args, ctx) {
67
+ const m = manifestOf(ctx);
68
+ const repo = checkoutOf(m, null, ctx.cwd);
69
+ const announce = one(args, 'announce');
70
+ const parallel = parallelOf(args);
71
+ const c = await compareSides(m, {
72
+ repo,
73
+ cwd: ctx.cwd,
74
+ head: one(args, 'head'),
75
+ base: one(args, 'base'),
76
+ ids: args.positional,
77
+ affected: args.flags.has('affected'),
78
+ announce: announce ? path.resolve(ctx.cwd, announce) : null,
79
+ said: many(args, 'said'),
80
+ fresh: args.flags.has('fresh'),
81
+ world: one(args, 'world'),
82
+ as: one(args, 'as'),
83
+ real: new Set(many(args, 'real')),
84
+ progress: ctx.progress,
85
+ parallel,
86
+ });
87
+ return said(c, comparisonText(c), c.ok ? 0 : 1);
88
+ },
89
+ };
@@ -0,0 +1,2 @@
1
+ import type { Command } from './command.ts';
2
+ export declare const drive: Command;
@@ -0,0 +1,244 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { closeSync, mkdirSync, openSync, readFileSync } from 'node:fs';
3
+ import path from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+ import { checkoutOf, manifestOf, said } from './command.js';
6
+ import { failed, driveArgv, exitOf, parseDrive, resultText, VERBS, forgetDriving, readDriving, writeDriving, } from '../drive/index.js';
7
+ import { sh, tail } from '../exec.js';
8
+ import { fillEnv } from '../manifest/index.js';
9
+ import { applyWorld, baseVars } from '../run/index.js';
10
+ import { alive, runningServices, stateDir, bringDown, bringUp, release } from '../services/index.js';
11
+ const quote = (s) => `'${s.replace(/'/g, `'\\''`)}'`;
12
+ const here = fileURLToPath(import.meta.url);
13
+ const daemonFile = path.join(path.dirname(here), '..', 'drive', `daemon${path.extname(here)}`);
14
+ const answer = (r) => said(r, resultText(r), exitOf(r));
15
+ function endIfStillThere(pid) {
16
+ try {
17
+ process.kill(pid, 'SIGTERM');
18
+ return true;
19
+ }
20
+ catch {
21
+ return false;
22
+ }
23
+ }
24
+ async function untilTheDaemonHasClosedWhatItBroughtUp(pid) {
25
+ if (!pid)
26
+ return;
27
+ const begun = Date.now();
28
+ while (alive(pid) && Date.now() - begun < 30_000)
29
+ await new Promise((resolve) => setTimeout(resolve, 100));
30
+ }
31
+ export const drive = {
32
+ name: 'drive',
33
+ summary: 'Drives the product one step at a time for an agent: click, type, key, fill, snapshot, screenshot, stop.',
34
+ usage: `rehearse drive <step> [--json]
35
+
36
+ rehearse drive start [--service <name> | --piece <id>] [--world <name>] [--as <person>] [--on <checkout>] [--start <path>] [--scheme light|dark]
37
+ Brings the service up and opens it, signed in as the person; it stays up until stop.
38
+ A service with its own driver (drive: in rehearse.yaml) is driven through it.
39
+ rehearse drive click --name <name> [--role <role>]
40
+ rehearse drive fill --name <name> [--role <role>] --with <text>
41
+ rehearse drive type <text>
42
+ rehearse drive key <key> Enter, Escape, Meta+k, ControlOrMeta+j…
43
+ rehearse drive snapshot [--name <name> [--role <role>]]
44
+ rehearse drive screenshot <file.png>
45
+ rehearse drive stop
46
+
47
+ Each answers in the drive result shape (schema/v1/drive.schema.json): 0 done, 1 failed, 2 usage.`,
48
+ spec: { valued: [], bare: [] },
49
+ ownGrammar: true,
50
+ async run(args, ctx) {
51
+ const at = Date.now();
52
+ const parsed = parseDrive(args.positional);
53
+ if (!parsed.ok) {
54
+ const verb = args.positional[0];
55
+ const commandItWas = verb !== undefined && VERBS.includes(verb) ? verb : null;
56
+ return answer(failed(commandItWas, at, 'usage', parsed.says, null));
57
+ }
58
+ const { command, options } = parsed;
59
+ const m = manifestOf(ctx);
60
+ const driving = readDriving(m.dir);
61
+ if (command.command === 'start') {
62
+ if (driving)
63
+ return answer(failed('start', at, 'usage', `Rehearse is already driving ${driving.service ?? 'a page'} in ${driving.checkout}: \`rehearse drive stop\` first.`, driving.driver));
64
+ const checkout = checkoutOf(m, options.on ?? null, ctx.cwd);
65
+ const name = options.service ?? m.scenarios.flows.service ?? m.defaults.service;
66
+ const svc = name ? m.services[name] : undefined;
67
+ if (!options.piece && svc?.drive) {
68
+ const world = options.world ?? m.defaults.world;
69
+ let running = runningServices(m.dir).filter((r) => path.resolve(r.checkout) === path.resolve(checkout));
70
+ const already = running.some((r) => r.name === svc.name);
71
+ if (!already) {
72
+ if (world)
73
+ await applyWorld(m, world, 'before', checkout, baseVars(m, checkout, running));
74
+ const r = await bringUp(m, svc, checkout, {
75
+ world,
76
+ real: new Set(),
77
+ vars: baseVars(m, checkout, running),
78
+ progress: ctx.progress,
79
+ });
80
+ release(r);
81
+ running = [...running, r];
82
+ if (world)
83
+ await applyWorld(m, world, 'add', checkout, baseVars(m, checkout, running));
84
+ }
85
+ writeDriving(m.dir, {
86
+ driver: 'service',
87
+ service: svc.name,
88
+ checkout,
89
+ started: !already,
90
+ since: new Date().toISOString(),
91
+ });
92
+ const person = options.as ?? null;
93
+ return answer({
94
+ v: 1,
95
+ ok: true,
96
+ command: 'start',
97
+ ms: Date.now() - at,
98
+ file: null,
99
+ tree: null,
100
+ driver: 'service',
101
+ said: person ? `${svc.name}'s driver signs in as no one, so it isn't ${person}.` : null,
102
+ });
103
+ }
104
+ const logDir = path.join(stateDir(m.dir), 'logs');
105
+ mkdirSync(logDir, { recursive: true });
106
+ const log = path.join(logDir, 'drive.log');
107
+ const out = openSync(log, 'w');
108
+ const argv = [daemonFile, '--manifest', m.file, '--on', checkout];
109
+ for (const key of ['service', 'piece', 'world', 'as', 'start'])
110
+ if (options[key])
111
+ argv.push(`--${key}`, options[key]);
112
+ const scheme = options.scheme ?? ctx.env.DRIVE_SCHEME;
113
+ if (scheme === 'light' || scheme === 'dark')
114
+ argv.push('--scheme', scheme);
115
+ const child = spawn(process.execPath, argv, {
116
+ cwd: checkout,
117
+ detached: true,
118
+ stdio: ['ignore', 'pipe', out],
119
+ });
120
+ closeSync(out);
121
+ const answeredInTime = await new Promise((resolve) => {
122
+ let text = '';
123
+ const timer = setTimeout(() => resolve(false), 120_000);
124
+ child.stdout.setEncoding('utf8').on('data', (d) => {
125
+ text += d;
126
+ if (/^ready \d+/m.test(text)) {
127
+ clearTimeout(timer);
128
+ resolve(true);
129
+ }
130
+ });
131
+ child.on('exit', () => {
132
+ clearTimeout(timer);
133
+ resolve(false);
134
+ });
135
+ });
136
+ child.stdout.destroy();
137
+ child.unref();
138
+ if (!answeredInTime) {
139
+ if (child.pid)
140
+ endIfStillThere(-child.pid);
141
+ let said2 = '';
142
+ try {
143
+ said2 = tail(readFileSync(log, 'utf8'));
144
+ }
145
+ catch {
146
+ said2 = '';
147
+ }
148
+ return answer(failed('start', at, 'crashed', `The browser didn't start${said2 ? `: ${said2}` : '.'}`));
149
+ }
150
+ return answer({
151
+ v: 1,
152
+ ok: true,
153
+ command: 'start',
154
+ ms: Date.now() - at,
155
+ file: null,
156
+ tree: null,
157
+ driver: 'browser',
158
+ said: null,
159
+ });
160
+ }
161
+ if (!driving && command.command === 'stop')
162
+ return answer({
163
+ v: 1,
164
+ ok: true,
165
+ command: 'stop',
166
+ ms: Date.now() - at,
167
+ file: null,
168
+ tree: null,
169
+ driver: null,
170
+ said: null,
171
+ });
172
+ if (!driving)
173
+ return answer(failed(command.command, at, 'not_running', 'Nothing is being driven: start with `rehearse drive start`.', null));
174
+ if (driving.driver === 'service') {
175
+ const svc = m.services[driving.service];
176
+ const running = runningServices(m.dir).find((r) => r.name === svc.name && path.resolve(r.checkout) === path.resolve(driving.checkout));
177
+ if (command.command === 'stop') {
178
+ if (running && driving.started)
179
+ await bringDown(m, running, ctx.progress);
180
+ forgetDriving(m.dir);
181
+ return answer({
182
+ v: 1,
183
+ ok: true,
184
+ command: 'stop',
185
+ ms: Date.now() - at,
186
+ file: null,
187
+ tree: null,
188
+ driver: 'service',
189
+ said: null,
190
+ });
191
+ }
192
+ if (command.command === 'fill')
193
+ return answer(failed('fill', at, 'usage', `${svc.name}'s driver takes no fill step: click the field, then type.`, 'service'));
194
+ const cwd = svc.cwd ? path.resolve(driving.checkout, svc.cwd) : driving.checkout;
195
+ const env = running?.env ?? {
196
+ ...fillEnv(svc.env, {}),
197
+ ...(svc.isolate && running?.scratch && { [svc.isolate.env]: running.scratch }),
198
+ };
199
+ const ran = await sh(`${svc.drive} ${driveArgv(command).map(quote).join(' ')} --json`, {
200
+ cwd,
201
+ env,
202
+ timeoutMs: 120_000,
203
+ });
204
+ try {
205
+ const r = JSON.parse(ran.stdout.trim().split('\n').at(-1) ?? '');
206
+ return answer({ v: 1, driver: 'service', ...r });
207
+ }
208
+ catch {
209
+ return answer(failed(command.command, at, 'crashed', `\`${svc.drive}\` answered with no JSON: ${tail(ran.stderr || ran.stdout) || `exit ${ran.code}`}`, 'service'));
210
+ }
211
+ }
212
+ const headers = { 'x-rehearse-drive': driving.secret ?? '' };
213
+ const sent = command.command === 'screenshot' || command.command === 'record'
214
+ ? { ...command, file: path.resolve(ctx.cwd, command.file) }
215
+ : command;
216
+ try {
217
+ if (command.command === 'stop') {
218
+ const r = await fetch(`http://127.0.0.1:${driving.port}/`, {
219
+ method: 'POST',
220
+ headers,
221
+ body: JSON.stringify(sent),
222
+ signal: AbortSignal.timeout(30_000),
223
+ });
224
+ const result = (await r.json());
225
+ await untilTheDaemonHasClosedWhatItBroughtUp(driving.pid);
226
+ forgetDriving(m.dir);
227
+ return answer(result);
228
+ }
229
+ const r = await fetch(`http://127.0.0.1:${driving.port}/`, {
230
+ method: 'POST',
231
+ headers,
232
+ body: JSON.stringify(sent),
233
+ signal: AbortSignal.timeout(120_000),
234
+ });
235
+ return answer((await r.json()));
236
+ }
237
+ catch (error) {
238
+ if (driving.pid && alive(driving.pid))
239
+ endIfStillThere(driving.pid);
240
+ forgetDriving(m.dir);
241
+ return answer(failed(command.command, at, 'crashed', `The browser Rehearse was driving stopped answering: ${error.message}`));
242
+ }
243
+ },
244
+ };
@@ -0,0 +1,3 @@
1
+ import type { Command } from './command.ts';
2
+ export { columns, GLOBAL_BARE, GLOBAL_VALUED, type Context, type Said } from './command.ts';
3
+ export declare const COMMANDS: readonly Command[];
@@ -0,0 +1,32 @@
1
+ import { check } from './check.js';
2
+ import { clean } from './clean.js';
3
+ import { compare } from './compare.js';
4
+ import { drive } from './drive.js';
5
+ import { list } from './list.js';
6
+ import { open } from './open.js';
7
+ import { run } from './run.js';
8
+ import { down, up } from './up.js';
9
+ import { init } from './init.js';
10
+ import { people } from './people.js';
11
+ import { services } from './services.js';
12
+ import { stage } from './stage.js';
13
+ import { validate } from './validate.js';
14
+ import { worlds } from './worlds.js';
15
+ export { columns, GLOBAL_BARE, GLOBAL_VALUED } from './command.js';
16
+ export const COMMANDS = [
17
+ init,
18
+ check,
19
+ services,
20
+ people,
21
+ worlds,
22
+ list,
23
+ up,
24
+ down,
25
+ run,
26
+ compare,
27
+ drive,
28
+ stage,
29
+ open,
30
+ clean,
31
+ validate,
32
+ ];
@@ -0,0 +1,2 @@
1
+ import type { Command } from './command.ts';
2
+ export declare const init: Command;
@@ -0,0 +1,19 @@
1
+ import { existsSync, writeFileSync } from 'node:fs';
2
+ import path from 'node:path';
3
+ import { said } from './command.js';
4
+ import { MANIFEST_FILE, STARTER } from '../manifest/index.js';
5
+ import { RehearseError } from '../errors.js';
6
+ export const init = {
7
+ name: 'init',
8
+ summary: 'Writes a starter rehearse.yaml in this folder, every block commented.',
9
+ usage: 'rehearse init [--force] [--json]',
10
+ spec: { valued: [], bare: ['force'] },
11
+ async run(args, ctx) {
12
+ const file = path.join(ctx.cwd, MANIFEST_FILE);
13
+ const there = existsSync(file);
14
+ if (there && !args.flags.has('force'))
15
+ throw new RehearseError('exists', `${file} is already there. Give --force to replace it.`);
16
+ writeFileSync(file, STARTER);
17
+ return said({ v: 1, file, replaced: there }, `Wrote ${file}.\nKeep the blocks this repository has, then run \`rehearse check\`.\n`);
18
+ },
19
+ };
@@ -0,0 +1,2 @@
1
+ import type { Command } from './command.ts';
2
+ export declare const list: Command;
@@ -0,0 +1,69 @@
1
+ import { checkoutOf, manifestOf, said } from './command.js';
2
+ import { one } from '../args.js';
3
+ import { readScenarios, refOf } from '../scenarios/index.js';
4
+ import { affected } from '../affected/index.js';
5
+ import { changedFiles } from '../compare/index.js';
6
+ import { commitOf } from '../git/index.js';
7
+ import { RehearseError, usage } from '../errors.js';
8
+ export const list = {
9
+ name: 'list',
10
+ summary: 'Lists the scenarios, or, with --affected, those a change reaches and why.',
11
+ usage: 'rehearse list [--affected <file>… | --since <ref>] [--on <checkout>] [--json]',
12
+ spec: { valued: ['on', 'since'], bare: ['affected'] },
13
+ async run(args, ctx) {
14
+ const m = manifestOf(ctx);
15
+ const checkout = checkoutOf(m, one(args, 'on'), ctx.cwd);
16
+ const read = await readScenarios(m, checkout);
17
+ const since = one(args, 'since');
18
+ const isAffected = args.flags.has('affected') || since !== null;
19
+ if (args.positional.length && !isAffected)
20
+ throw usage('Name files only with --affected.');
21
+ const row = (s, reachedBy) => ({
22
+ ...refOf(s),
23
+ world: s.world,
24
+ person: s.person,
25
+ service: s.service,
26
+ ...(reachedBy && { reachedBy }),
27
+ });
28
+ if (!isAffected) {
29
+ const out = {
30
+ v: 1,
31
+ by: 'all',
32
+ graph: null,
33
+ said: null,
34
+ scenarios: read.scenarios.map((s) => row(s)),
35
+ refused: read.refused,
36
+ };
37
+ const byArea = new Map();
38
+ for (const s of read.scenarios)
39
+ byArea.set(s.area, [...(byArea.get(s.area) ?? []), ` ${s.kind.padEnd(5)} ${s.id}`]);
40
+ const text = [...byArea].map(([area, lines]) => `${area}\n${lines.join('\n')}`).join('\n\n');
41
+ return said(out, `${text || 'No scenarios yet.'}${read.refused.length ? `\n\nnot read:\n${read.refused.map((r) => ` ${r.file}${r.line ? `:${r.line}` : ''}: ${r.says}`).join('\n')}` : ''}\n`);
42
+ }
43
+ let files = args.positional;
44
+ if (since) {
45
+ const commit = commitOf(checkout, since);
46
+ if (!commit)
47
+ throw new RehearseError('git', `Rehearse can't find ${since} in ${checkout}.`);
48
+ files = [...files, ...changedFiles(checkout, commit)];
49
+ }
50
+ if (files.length === 0)
51
+ throw usage('Name the files the change touches, or give --since <ref>.');
52
+ const reach = await affected(m, checkout, files, read.scenarios);
53
+ const out = {
54
+ v: 1,
55
+ by: reach.by,
56
+ graph: reach.graph,
57
+ files: reach.files,
58
+ said: reach.said,
59
+ scenarios: reach.reached.map((r) => row(r.scenario, r.reachedBy)),
60
+ refused: read.refused,
61
+ };
62
+ const text = [
63
+ `${reach.reached.length} of ${read.scenarios.length} scenarios are reached by ${reach.files.length} file${reach.files.length === 1 ? '' : 's'}${reach.by === 'graph' ? ` (import graph: ${reach.graph})` : ''}.`,
64
+ ...(reach.said ? [reach.said] : []),
65
+ ...reach.reached.map((r) => ` ${r.scenario.kind.padEnd(5)} ${r.scenario.id}\n ${r.reachedBy.join('; ')}`),
66
+ ].join('\n');
67
+ return said(out, `${text}\n`);
68
+ },
69
+ };
@@ -0,0 +1,2 @@
1
+ import type { Command } from './command.ts';
2
+ export declare const open: Command;
@@ -0,0 +1,60 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { closeSync, mkdirSync, openSync, readFileSync } from 'node:fs';
3
+ import path from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+ import { manifestOf, said } from './command.js';
6
+ import { one } from '../args.js';
7
+ import { RehearseError, usage } from '../errors.js';
8
+ import { readScenarios } from '../scenarios/index.js';
9
+ import { stateDir } from '../services/index.js';
10
+ import { runningStage } from '../stage/index.js';
11
+ import { checkoutOf } from './command.js';
12
+ import { tail } from '../exec.js';
13
+ import { portOf } from './stage.js';
14
+ const cliFile = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', `cli${path.extname(fileURLToPath(import.meta.url))}`);
15
+ export const open = {
16
+ name: 'open',
17
+ summary: "Prints the stage's address for a scenario, starting the stage when none is running.",
18
+ usage: 'rehearse open <scenario> [--no-start] [--port <port>] [--json]\n\nThe address is the link a pull request carries.',
19
+ spec: { valued: ['port'], bare: ['no-start'] },
20
+ async run(args, ctx) {
21
+ const id = args.positional[0];
22
+ if (!id)
23
+ throw usage('Name the scenario to open: rehearse list shows their ids.');
24
+ const m = manifestOf(ctx);
25
+ const given = one(args, 'port');
26
+ const { port, anyPort } = portOf(given);
27
+ const checkout = checkoutOf(m, null, ctx.cwd);
28
+ const read = await readScenarios(m, checkout);
29
+ if (!read.scenarios.some((s) => s.id === id))
30
+ throw new RehearseError('no_scenario', `There is no scenario “${id}”. rehearse list shows them.`);
31
+ let running = await runningStage(m);
32
+ let started = false;
33
+ if (!running && args.flags.has('no-start'))
34
+ throw new RehearseError('stage', 'No stage is running for this repository: run rehearse stage, or open without --no-start.');
35
+ if (!running) {
36
+ mkdirSync(path.join(stateDir(m.dir), 'logs'), { recursive: true });
37
+ const log = path.join(stateDir(m.dir), 'logs', 'stage.log');
38
+ const out = openSync(log, 'w');
39
+ const child = spawn(process.execPath, [cliFile, 'stage', ...(anyPort ? [] : ['--port', String(port)]), '--manifest', m.file], {
40
+ cwd: ctx.cwd,
41
+ detached: true,
42
+ stdio: ['ignore', out, out],
43
+ });
44
+ closeSync(out);
45
+ child.unref();
46
+ const begun = Date.now();
47
+ while (!running && Date.now() - begun < 60_000) {
48
+ await new Promise((resolve) => setTimeout(resolve, 200));
49
+ running = await runningStage(m);
50
+ if (child.exitCode !== null)
51
+ break;
52
+ }
53
+ if (!running)
54
+ throw new RehearseError('stage', `The stage didn't start: ${tail(readFileSync(log, 'utf8')) || 'it said nothing'}`);
55
+ started = true;
56
+ }
57
+ const url = `${running.url}?s=${encodeURIComponent(id)}`;
58
+ return said({ v: 1, url, scenario: id, started }, `${url}\n${started ? `The stage started for it; stop it with kill ${running.pid}.\n` : ''}`);
59
+ },
60
+ };
@@ -0,0 +1,2 @@
1
+ import type { Command } from './command.ts';
2
+ export declare const people: Command;
@@ -0,0 +1,49 @@
1
+ import { checkoutOf, manifestOf, said } from './command.js';
2
+ import { one } from '../args.js';
3
+ import { peopleOut, signIn } from '../people/index.js';
4
+ import { liveServices } from '../services/index.js';
5
+ import { baseVars } from '../run/index.js';
6
+ import { fill } from '../manifest/index.js';
7
+ import { RehearseError } from '../errors.js';
8
+ export const people = {
9
+ name: 'people',
10
+ summary: 'Who you can sign in as, and how real each person is. Tokens are printed only with --json.',
11
+ usage: 'rehearse people [--on <checkout>] [--json]',
12
+ spec: { valued: ['on'], bare: [] },
13
+ async run(args, ctx) {
14
+ const m = manifestOf(ctx);
15
+ const checkout = checkoutOf(m, one(args, 'on'), ctx.cwd);
16
+ const running = await liveServices(m, checkout);
17
+ const needs = m.signIn?.service ?? null;
18
+ let signed = null;
19
+ let note = null;
20
+ const hasTokens = m.signIn !== null || Object.values(m.people).some((p) => p.token !== null);
21
+ if (needs && !running.some((r) => r.name === needs))
22
+ note = `The sign-in needs the service ${needs} up in ${checkout}: \`rehearse up ${needs}\`.`;
23
+ else if (hasTokens) {
24
+ const vars = baseVars(m, checkout, running);
25
+ try {
26
+ signed = await signIn(m, { cwd: checkout, env: {}, fill: (t) => fill(t, vars) });
27
+ }
28
+ catch (error) {
29
+ if (!(error instanceof RehearseError))
30
+ throw error;
31
+ note = error.says;
32
+ }
33
+ }
34
+ else
35
+ note = 'No sign-in is declared, so no one has a token.';
36
+ const out = peopleOut(m, signed, ctx.json, note);
37
+ const names = Object.keys(out.about);
38
+ if (names.length === 0)
39
+ return said(out, `No people are declared.${note ? ` ${note}` : ''}\n`);
40
+ const lines = names.map((name) => {
41
+ const p = out.about[name];
42
+ const token = signed?.tokens[name];
43
+ const has = token ? ` · token (${token.length} characters, hidden; --json prints it)` : '';
44
+ return `${name}${p.default ? ' (default)' : ''} — ${p.real}${p.describe ? `: ${p.describe}` : ''}${has}`;
45
+ });
46
+ const vars = Object.keys(out.variables);
47
+ return said(out, `${lines.join('\n')}${vars.length ? `\nvariables: ${vars.join(', ')}` : ''}${note ? `\n${note}` : ''}\n`);
48
+ },
49
+ };
@@ -0,0 +1,4 @@
1
+ import type { Command } from './command.ts';
2
+ import { type Observation } from '../run/index.ts';
3
+ export declare function observationText(o: Observation): string;
4
+ export declare const run: Command;