@kurvball/rehearse 1.9.0 → 1.10.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 (41) hide show
  1. package/README.md +3 -2
  2. package/dist/commands/init.js +52 -7
  3. package/dist/detect/detect.d.ts +6 -0
  4. package/dist/detect/detect.js +48 -0
  5. package/dist/detect/finding.d.ts +18 -0
  6. package/dist/detect/finding.js +4 -0
  7. package/dist/detect/globs.d.ts +10 -0
  8. package/dist/detect/globs.js +43 -0
  9. package/dist/detect/index.d.ts +2 -0
  10. package/dist/detect/index.js +2 -0
  11. package/dist/detect/lockfiles.d.ts +15 -0
  12. package/dist/detect/lockfiles.js +64 -0
  13. package/dist/detect/paths.d.ts +5 -0
  14. package/dist/detect/paths.js +39 -0
  15. package/dist/detect/pieces.d.ts +14 -0
  16. package/dist/detect/pieces.js +119 -0
  17. package/dist/detect/prepare.d.ts +14 -0
  18. package/dist/detect/prepare.js +78 -0
  19. package/dist/detect/repository.d.ts +33 -0
  20. package/dist/detect/repository.js +166 -0
  21. package/dist/detect/scenarios.d.ts +26 -0
  22. package/dist/detect/scenarios.js +170 -0
  23. package/dist/detect/scripts.d.ts +46 -0
  24. package/dist/detect/scripts.js +233 -0
  25. package/dist/detect/services.d.ts +16 -0
  26. package/dist/detect/services.js +171 -0
  27. package/dist/detect/write.d.ts +18 -0
  28. package/dist/detect/write.js +115 -0
  29. package/dist/manifest/index.d.ts +1 -1
  30. package/dist/manifest/index.js +1 -1
  31. package/dist/manifest/init.d.ts +47 -1
  32. package/dist/manifest/init.js +19 -16
  33. package/dist/scenarios/glob.d.ts +1 -0
  34. package/dist/scenarios/glob.js +10 -3
  35. package/dist/scenarios/index.d.ts +1 -1
  36. package/dist/scenarios/index.js +1 -1
  37. package/llms.txt +1 -1
  38. package/package.json +1 -1
  39. package/schema/v1/init.schema.json +69 -1
  40. package/schema/v1/samples/init.json +46 -1
  41. package/skill/rehearse/SKILL.md +5 -0
@@ -0,0 +1,171 @@
1
+ import path from 'node:path';
2
+ import { isFile, joined, readText, within, } from './repository.js';
3
+ import { FILE_LIKE, quoted, readScript } from './scripts.js';
4
+ const SCRIPTS = ['dev', 'start', 'serve', 'develop'];
5
+ const RUN = {
6
+ pnpm: (s, a) => `pnpm run ${quoted(s)}${a ? ` ${a}` : ''}`,
7
+ npm: (s, a) => `npm run ${quoted(s)}${a ? ` -- ${a}` : ''}`,
8
+ yarn: (s, a) => `yarn run ${quoted(s)}${a ? ` ${a}` : ''}`,
9
+ bun: (s, a) => `bun run ${quoted(s)}${a ? ` ${a}` : ''}`,
10
+ };
11
+ const NAMES = { vite: 'Vite', next: 'Next', astro: 'Astro' };
12
+ const READS_PORT = /process\.env\.PORT\b|process\.env\[\s*['"`]PORT['"`]\s*\]|\{[^}]*\bPORT\b[^}]*\}\s*=\s*process\.env\b|(?:Bun|import\.meta)\.env\.PORT\b|Deno\.env\.get\(\s*['"`]PORT['"`]/;
13
+ const HEALTH = /['"`](\/(?:api\/)?(?:healthz?|livez|readyz|ping))['"`]/;
14
+ const RELATIVE_IMPORT = /(?:\bfrom\s*|\bimport\s*\(\s*|\brequire\s*\(\s*)['"](\.{1,2}\/[^'"]+)['"]/g;
15
+ const EXTENSIONS = ['', '.js', '.mjs', '.cjs', '.ts', '.mts', '.cts', '/index.js', '/index.mjs', '/index.ts'];
16
+ const SOURCES_READ = 200;
17
+ const BY_HAND = 'Write its service by hand: an up command with {{port}} where the port goes, and port: auto.';
18
+ function resolveFile(repo, from, spec) {
19
+ const base = joined(from, spec);
20
+ const tried = [...EXTENSIONS.map((e) => base + e), base.replace(/\.([cm]?)js$/, '.$1ts')];
21
+ return tried.find((f) => !f.startsWith('..') && isFile(path.join(repo.root, f))) ?? null;
22
+ }
23
+ function sourcesFrom(repo, entry) {
24
+ const text = readText(path.join(repo.root, entry));
25
+ if (text === null)
26
+ return [];
27
+ const out = [{ file: entry, text }];
28
+ for (const m of text.matchAll(RELATIVE_IMPORT)) {
29
+ if (out.length > 20)
30
+ break;
31
+ const file = resolveFile(repo, path.posix.dirname(entry), m[1]);
32
+ const more = file && !out.some((o) => o.file === file) ? readText(path.join(repo.root, file)) : null;
33
+ if (file && more !== null)
34
+ out.push({ file, text: more });
35
+ }
36
+ return out;
37
+ }
38
+ function sourcesIn(repo, dir) {
39
+ return repo.files
40
+ .filter((f) => within(joined(dir, 'src'), f) && FILE_LIKE.test(f))
41
+ .slice(0, SOURCES_READ)
42
+ .flatMap((file) => {
43
+ const text = readText(path.join(repo.root, file));
44
+ return text === null ? [] : [{ file, text }];
45
+ });
46
+ }
47
+ function nodeServer(repo, pkg, read) {
48
+ const its = `its ${read.script} script`;
49
+ if (!read.entry)
50
+ return { why: `${its} runs ${read.tool} without a file Rehearse can read.`, next: BY_HAND };
51
+ const entry = resolveFile(repo, pkg.dir, read.entry);
52
+ const built = entry === null || repo.ignored(entry);
53
+ const canBuild = pkg.scripts.build !== undefined;
54
+ const sources = built ? (canBuild ? sourcesIn(repo, pkg.dir) : []) : sourcesFrom(repo, entry);
55
+ const reading = sources.find((s) => READS_PORT.test(s.text));
56
+ if (!reading)
57
+ return {
58
+ why: built
59
+ ? `${its} runs ${read.entry}, which is built, and ${canBuild ? 'no file in src/ reads PORT' : 'there is no build script'}, so Rehearse can't give it a free port.`
60
+ : `${its} runs ${read.entry}, which doesn't read PORT, so Rehearse can't give it a free port.`,
61
+ next: 'Make it listen on process.env.PORT, or write its service by hand with {{port}} where the port goes.',
62
+ };
63
+ const health = [reading, ...sources].map((s) => HEALTH.exec(s.text)?.[1]).find(Boolean) ?? '/';
64
+ const manager = repo.managerOf(pkg.dir);
65
+ return {
66
+ service: {
67
+ pkg,
68
+ server: 'node',
69
+ up: RUN[manager](read.script, ''),
70
+ env: { PORT: '{{port}}' },
71
+ ready: `http://127.0.0.1:{{port}}${health}`,
72
+ built: built ? joined(pkg.dir, read.entry) : null,
73
+ },
74
+ what: `a Node server that reads PORT${built ? ', built first' : ''}, on a free port`,
75
+ };
76
+ }
77
+ function frameworkServer(repo, pkg, read) {
78
+ const { framework, script, words } = read;
79
+ const manager = repo.managerOf(pkg.dir);
80
+ const more = [
81
+ ...(framework === 'vite' && !words.includes('--strictPort') ? ['--strictPort'] : []),
82
+ ...(framework !== 'next' && !words.some((w) => w === '--host' || w.startsWith('--host='))
83
+ ? ['--host', '127.0.0.1']
84
+ : []),
85
+ ];
86
+ const up = RUN[manager](script, [framework === 'next' ? '-p' : '--port', '{{port}}', ...more].join(' '));
87
+ return {
88
+ service: { pkg, server: framework, up, env: {}, ready: 'http://127.0.0.1:{{port}}/', built: null },
89
+ what: `${NAMES[framework]}'s dev server, on a free port`,
90
+ };
91
+ }
92
+ function left(read) {
93
+ const its = `its ${read.script} script`;
94
+ switch (read.as) {
95
+ case 'others':
96
+ return {
97
+ why: `${its} runs ${read.tool}, which starts other packages' scripts; Rehearse brings each app up as a service of its own.`,
98
+ };
99
+ case 'unknown':
100
+ return {
101
+ why: `${its} runs ${read.tool}, and Rehearse can't tell how that takes a port.`,
102
+ next: BY_HAND,
103
+ };
104
+ case 'fixed':
105
+ return {
106
+ why: `${its} fixes its port (${read.port}), so Rehearse can't give it a free one without running something else.`,
107
+ next: 'Take the port out of the script, since Rehearse gives it one, or write its service by hand.',
108
+ };
109
+ case 'together':
110
+ return {
111
+ why: read.how === '&'
112
+ ? `${its} runs commands side by side (&), and a service is one server Rehearse gives one port.`
113
+ : `${its} pipes the server's output into another command (|), so the port Rehearse adds wouldn't reach the server.`,
114
+ next: BY_HAND,
115
+ };
116
+ case 'handover':
117
+ return {
118
+ why: `${its} hands over to ${read.via}, which doesn't pass on the port Rehearse adds.`,
119
+ next: `End that call with --, as in ${read.via} --, or write its service by hand.`,
120
+ };
121
+ }
122
+ }
123
+ function seen(repo, pkg) {
124
+ for (const script of SCRIPTS.filter((s) => s in pkg.scripts)) {
125
+ const read = readScript(pkg.scripts, script);
126
+ if (read.as === 'framework')
127
+ return frameworkServer(repo, pkg, read);
128
+ if (read.as === 'node')
129
+ return nodeServer(repo, pkg, read);
130
+ if (read.as !== 'tool')
131
+ return left(read);
132
+ }
133
+ return null;
134
+ }
135
+ const safe = (word) => (word ?? '')
136
+ .replace(/^@[^/]+\//, '')
137
+ .replace(/[^A-Za-z0-9_-]+/g, '-')
138
+ .replace(/^[^A-Za-z_]+|-+$/g, '');
139
+ function nameOf(pkg, server, taken) {
140
+ const byKind = server === 'node' ? 'api' : 'web';
141
+ const tried = (pkg.dir ? [safe(path.posix.basename(pkg.dir)), safe(pkg.name), byKind] : [byKind]).filter(Boolean);
142
+ const free = tried.find((name) => !taken.has(name));
143
+ if (free)
144
+ return free;
145
+ for (let n = 2;; n += 1)
146
+ if (!taken.has(`${tried[0]}-${n}`))
147
+ return `${tried[0]}-${n}`;
148
+ }
149
+ export function servicesOf(repo) {
150
+ const services = [];
151
+ const findings = [];
152
+ for (const pkg of repo.packages) {
153
+ const found = seen(repo, pkg);
154
+ if (!found)
155
+ continue;
156
+ if ('service' in found) {
157
+ const name = nameOf(pkg, found.service.server, new Set(services.map((s) => s.name)));
158
+ services.push({ name, ...found.service });
159
+ findings.push({ kind: 'service', name, from: pkg.file, written: true, why: found.what });
160
+ }
161
+ else
162
+ findings.push({
163
+ kind: 'service',
164
+ from: pkg.file,
165
+ written: false,
166
+ why: found.why,
167
+ ...(found.next !== undefined && { next: found.next }),
168
+ });
169
+ }
170
+ return { services, findings };
171
+ }
@@ -0,0 +1,18 @@
1
+ import type { Blocks } from './scenarios.ts';
2
+ import type { Service } from './services.ts';
3
+ export interface Plan {
4
+ base: {
5
+ branch: string;
6
+ from: string;
7
+ } | null;
8
+ prepare: {
9
+ command: string;
10
+ from: string[];
11
+ } | null;
12
+ services: readonly Service[];
13
+ blocks: Blocks;
14
+ prefix: string;
15
+ }
16
+ export declare function scalar(value: string): string;
17
+ export declare const commented: (block: string) => string;
18
+ export declare function manifestText(plan: Plan): string;
@@ -0,0 +1,115 @@
1
+ import { STARTER_BLOCKS } from '../manifest/index.js';
2
+ import { escapeGlob } from '../scenarios/index.js';
3
+ import { counted, hasControl, printable } from './finding.js';
4
+ import { joined } from './repository.js';
5
+ const HEAD = `# rehearse.yaml: what this repository has, so a change can be rehearsed before it ships.
6
+ # rehearse init --detect wrote the blocks it found, each saying what from, and left the rest commented.
7
+ # Every block is optional. Reference: the docs' rehearse.yaml page.
8
+ version: 1
9
+ `;
10
+ const WHAT = {
11
+ vite: "Vite's dev server",
12
+ next: "Next's dev server",
13
+ astro: "Astro's dev server",
14
+ node: 'a Node server that reads PORT',
15
+ };
16
+ const SPECIAL = /^(?:true|false|yes|no|on|off|y|n|null|~)$/i;
17
+ const NUMBER = /^[-+]?(?:\d[\d_]*(?:\.\d*)?|\.\d+)(?:e[-+]?\d+)?$|^0x[\da-f]+$|^0o[0-7]+$|^[-+]?\.(?:inf|nan)$/i;
18
+ const doubleQuoted = (value) => JSON.stringify(value).replace(/[\u2028\u2029]/g, (c) => `\\u${c.charCodeAt(0).toString(16)}`);
19
+ const singleQuoted = (value) => hasControl(value) ? doubleQuoted(value) : `'${value.replace(/'/g, "''")}'`;
20
+ export function scalar(value) {
21
+ if (hasControl(value))
22
+ return doubleQuoted(value);
23
+ const plain = /^[A-Za-z0-9_./(]/.test(value) &&
24
+ !/[\n\t]|: | #|:$|\s$/.test(value) &&
25
+ !SPECIAL.test(value) &&
26
+ !NUMBER.test(value);
27
+ return plain ? value : `'${value.replace(/'/g, "''")}'`;
28
+ }
29
+ const list = (values) => `[${values.map(singleQuoted).join(', ')}]`;
30
+ const and = (items) => items.length <= 1 ? (items[0] ?? '') : `${items.slice(0, -1).join(', ')} and ${items.at(-1)}`;
31
+ const explanation = (block) => block.split('\n')[0];
32
+ function commentedLine(line) {
33
+ if (line === '')
34
+ return line;
35
+ const indented = /^(\s+)#\s?(.*)$/.exec(line);
36
+ if (indented)
37
+ return `# ${indented[1]}${indented[2]}`;
38
+ return line.startsWith('#') ? line : `# ${line}`;
39
+ }
40
+ export const commented = (block) => block.split('\n').map(commentedLine).join('\n');
41
+ function base(plan) {
42
+ if (!plan.base)
43
+ return STARTER_BLOCKS.base;
44
+ return `${explanation(STARTER_BLOCKS.base)}\n# Detected from ${printable(plan.base.from)}.\nbase: ${scalar(plan.base.branch)}\n`;
45
+ }
46
+ function prepare(plan) {
47
+ if (!plan.prepare)
48
+ return STARTER_BLOCKS.prepare;
49
+ return `${explanation(STARTER_BLOCKS.prepare)}\n# Detected from ${printable(and(plan.prepare.from))}.\nprepare: ${scalar(plan.prepare.command)}\n`;
50
+ }
51
+ function services(plan) {
52
+ if (plan.services.length === 0)
53
+ return commented(STARTER_BLOCKS.services);
54
+ const lines = [explanation(STARTER_BLOCKS.services), 'services:'];
55
+ for (const s of plan.services) {
56
+ const cwd = joined(plan.prefix, s.pkg.dir);
57
+ const env = Object.entries(s.env);
58
+ lines.push(` # Detected from ${printable(s.pkg.file)}: ${WHAT[s.server]}${s.built ? ', built first' : ''}.`, ` ${s.name}:`, ` up: ${scalar(s.up)}`, ...(cwd ? [` cwd: ${scalar(cwd)}`] : []), ' port: auto', ` ready: ${scalar(s.ready)}`, ...(env.length ? [' env:', ...env.map(([k, v]) => ` ${k}: ${scalar(v)}`)] : []));
59
+ }
60
+ return `${lines.join('\n')}\n`;
61
+ }
62
+ function scenarios(plan) {
63
+ const b = plan.blocks;
64
+ if (!b.pieces && !b.flows && !b.calls && !b.files)
65
+ return commented(STARTER_BLOCKS.scenarios);
66
+ const starter = new Map(STARTER_BLOCKS.scenarios
67
+ .split('\n')
68
+ .map((line) => /^ {2}(\w+):/.exec(line))
69
+ .filter((m) => m !== null)
70
+ .map((m) => [m[1], m.input.trim()]));
71
+ const block = (kind, from, paths, settings) => {
72
+ const set = settings.filter((s) => s[1] !== null);
73
+ const globs = list(paths.map((p) => joined(escapeGlob(plan.prefix), p)));
74
+ return [
75
+ ` # Detected from ${printable(from)}.`,
76
+ ...(set.length
77
+ ? [` ${kind}:`, ` paths: ${globs}`, ...set.map(([k, v]) => ` ${k}: ${scalar(v)}`)]
78
+ : [` ${kind}: ${globs}`]),
79
+ ];
80
+ };
81
+ const left = (kind) => [` # ${starter.get(kind)}`];
82
+ const lines = [
83
+ explanation(STARTER_BLOCKS.scenarios),
84
+ 'scenarios:',
85
+ ...(b.pieces
86
+ ? block('pieces', `${counted(b.pieces.count, 'story file', 'story files')}${b.pieces.previewFile ? ` and ${b.pieces.previewFile}` : ''}`, b.pieces.paths, [['preview', b.pieces.preview]])
87
+ : left('pieces')),
88
+ ...(b.flows
89
+ ? block('flows', counted(b.flows.count, 'flow file', 'flow files'), b.flows.paths, [
90
+ ['service', b.flows.service],
91
+ ])
92
+ : left('flows')),
93
+ ...(b.calls
94
+ ? block('calls', counted(b.calls.count, '.hurl file', '.hurl files'), b.calls.paths, [
95
+ ['service', b.calls.service],
96
+ ])
97
+ : left('calls')),
98
+ ...(b.files
99
+ ? block('files', counted(b.files.count, 'file scenario', 'file scenarios'), b.files.paths, [])
100
+ : left('files')),
101
+ ];
102
+ return `${lines.join('\n')}\n`;
103
+ }
104
+ export function manifestText(plan) {
105
+ return [
106
+ HEAD,
107
+ base(plan),
108
+ prepare(plan),
109
+ services(plan),
110
+ commented(STARTER_BLOCKS.people),
111
+ commented(STARTER_BLOCKS.worlds),
112
+ commented(STARTER_BLOCKS.standins),
113
+ scenarios(plan),
114
+ ].join('\n');
115
+ }
@@ -1,5 +1,5 @@
1
1
  export { fill, fillEnv } from './fill.ts';
2
- export { STARTER } from './init.ts';
2
+ export { STARTER, STARTER_BLOCKS, STARTER_HEAD } from './init.ts';
3
3
  export { findManifest, hashOf, loadManifest, MANIFEST_FILE, manifestFrom } from './load.ts';
4
4
  export { KIND_BLOCK, KINDS, type Kind, type Manifest, type PathEntry, type Person, type Real, type Service, type Standin, type World, } from './types.ts';
5
5
  export { readYaml } from './yaml.ts';
@@ -1,5 +1,5 @@
1
1
  export { fill, fillEnv } from './fill.js';
2
- export { STARTER } from './init.js';
2
+ export { STARTER, STARTER_BLOCKS, STARTER_HEAD } from './init.js';
3
3
  export { findManifest, hashOf, loadManifest, MANIFEST_FILE, manifestFrom } from './load.js';
4
4
  export { KIND_BLOCK, KINDS, } from './types.js';
5
5
  export { readYaml } from './yaml.js';
@@ -1 +1,47 @@
1
- export declare const STARTER = "# rehearse.yaml: what this repository has, so a change can be rehearsed before it ships.\n# Every block is optional. Delete what you don't have. Reference: the docs' rehearse.yaml page.\nversion: 1\n\n# The branch production runs. Comparisons use it as the base.\nbase: main\n\n# Run once in a fresh checkout of a base commit, before anything else.\n# prepare: pnpm install --frozen-lockfile --offline\n\n# What can come up. {{port}} is filled with the port; port: auto picks a free one.\nservices:\n web:\n up: pnpm dev --port {{port}}\n port: auto\n ready: http://127.0.0.1:{{port}}/\n\n# Who you can sign in as. A sign-in command prints {\"people\": {\"name\": \"token\"}}.\n# signIn: node scripts/people.mjs\npeople:\n owner:\n describe: The organisation's owner\n default: true\n\n# Named starting states. A world extends another and adds to it.\nworlds:\n empty:\n describe: Nothing but the schema\n default: true\n # one-org:\n # extends: empty\n # add: node scripts/seed.mjs one-org --url {{web_url}}\n\n# Fakes for what can't run locally, named in every result.\n# standins:\n# ai:\n# replaces: The model provider\n# by: test/fixtures/ai-fake.ts\n# env: { AI_PROVIDER: fake }\n\n# Where the scenarios are. A path starting with ./ is read beside this file; any other, from each checkout.\nscenarios:\n pieces: ['src/**/*.stories.tsx']\n flows: ['**/*.flow.yaml']\n calls: ['**/*.hurl']\n files: ['**/*.rehearse.yaml']\n";
1
+ export declare const STARTER_HEAD = "# rehearse.yaml: what this repository has, so a change can be rehearsed before it ships.\n# Every block is optional. Delete what you don't have. Reference: the docs' rehearse.yaml page.\nversion: 1\n";
2
+ export declare const STARTER_BLOCKS: {
3
+ readonly base: `# The branch production runs. Comparisons use it as the base.
4
+ base: main
5
+ `;
6
+ readonly prepare: `# Run once in a fresh checkout of a base commit, before anything else.
7
+ # prepare: pnpm install --frozen-lockfile --offline
8
+ `;
9
+ readonly services: `# What can come up. {{port}} is filled with the port; port: auto picks a free one.
10
+ services:
11
+ web:
12
+ up: pnpm dev --port {{port}}
13
+ port: auto
14
+ ready: http://127.0.0.1:{{port}}/
15
+ `;
16
+ readonly people: `# Who you can sign in as. A sign-in command prints {"people": {"name": "token"}}.
17
+ # signIn: node scripts/people.mjs
18
+ people:
19
+ owner:
20
+ describe: The organisation's owner
21
+ default: true
22
+ `;
23
+ readonly worlds: `# Named starting states. A world extends another and adds to it.
24
+ worlds:
25
+ empty:
26
+ describe: Nothing but the schema
27
+ default: true
28
+ # one-org:
29
+ # extends: empty
30
+ # add: node scripts/seed.mjs one-org --url {{web_url}}
31
+ `;
32
+ readonly standins: `# Fakes for what can't run locally, named in every result.
33
+ # standins:
34
+ # ai:
35
+ # replaces: The model provider
36
+ # by: test/fixtures/ai-fake.ts
37
+ # env: { AI_PROVIDER: fake }
38
+ `;
39
+ readonly scenarios: `# Where the scenarios are. A path starting with ./ is read beside this file; any other, from each checkout.
40
+ scenarios:
41
+ pieces: ['src/**/*.stories.tsx']
42
+ flows: ['**/*.flow.yaml']
43
+ calls: ['**/*.hurl']
44
+ files: ['**/*.rehearse.yaml']
45
+ `;
46
+ };
47
+ export declare const STARTER: string;
@@ -1,28 +1,29 @@
1
- export const STARTER = `# rehearse.yaml: what this repository has, so a change can be rehearsed before it ships.
1
+ export const STARTER_HEAD = `# rehearse.yaml: what this repository has, so a change can be rehearsed before it ships.
2
2
  # Every block is optional. Delete what you don't have. Reference: the docs' rehearse.yaml page.
3
3
  version: 1
4
-
5
- # The branch production runs. Comparisons use it as the base.
4
+ `;
5
+ export const STARTER_BLOCKS = {
6
+ base: `# The branch production runs. Comparisons use it as the base.
6
7
  base: main
7
-
8
- # Run once in a fresh checkout of a base commit, before anything else.
8
+ `,
9
+ prepare: `# Run once in a fresh checkout of a base commit, before anything else.
9
10
  # prepare: pnpm install --frozen-lockfile --offline
10
-
11
- # What can come up. {{port}} is filled with the port; port: auto picks a free one.
11
+ `,
12
+ services: `# What can come up. {{port}} is filled with the port; port: auto picks a free one.
12
13
  services:
13
14
  web:
14
15
  up: pnpm dev --port {{port}}
15
16
  port: auto
16
17
  ready: http://127.0.0.1:{{port}}/
17
-
18
- # Who you can sign in as. A sign-in command prints {"people": {"name": "token"}}.
18
+ `,
19
+ people: `# Who you can sign in as. A sign-in command prints {"people": {"name": "token"}}.
19
20
  # signIn: node scripts/people.mjs
20
21
  people:
21
22
  owner:
22
23
  describe: The organisation's owner
23
24
  default: true
24
-
25
- # Named starting states. A world extends another and adds to it.
25
+ `,
26
+ worlds: `# Named starting states. A world extends another and adds to it.
26
27
  worlds:
27
28
  empty:
28
29
  describe: Nothing but the schema
@@ -30,18 +31,20 @@ worlds:
30
31
  # one-org:
31
32
  # extends: empty
32
33
  # add: node scripts/seed.mjs one-org --url {{web_url}}
33
-
34
- # Fakes for what can't run locally, named in every result.
34
+ `,
35
+ standins: `# Fakes for what can't run locally, named in every result.
35
36
  # standins:
36
37
  # ai:
37
38
  # replaces: The model provider
38
39
  # by: test/fixtures/ai-fake.ts
39
40
  # env: { AI_PROVIDER: fake }
40
-
41
- # Where the scenarios are. A path starting with ./ is read beside this file; any other, from each checkout.
41
+ `,
42
+ scenarios: `# Where the scenarios are. A path starting with ./ is read beside this file; any other, from each checkout.
42
43
  scenarios:
43
44
  pieces: ['src/**/*.stories.tsx']
44
45
  flows: ['**/*.flow.yaml']
45
46
  calls: ['**/*.hurl']
46
47
  files: ['**/*.rehearse.yaml']
47
- `;
48
+ `,
49
+ };
50
+ export const STARTER = [STARTER_HEAD, ...Object.values(STARTER_BLOCKS)].join('\n');
@@ -1,4 +1,5 @@
1
1
  export declare const NEVER_WALKED: Set<string>;
2
+ export declare const escapeGlob: (text: string) => string;
2
3
  export declare function globToRegExp(glob: string): RegExp;
3
4
  export declare function globRoot(glob: string): string;
4
5
  export declare const toPosix: (p: string) => string;
@@ -16,12 +16,19 @@ export const NEVER_WALKED = new Set([
16
16
  '.venv',
17
17
  ]);
18
18
  const escape = (c) => c.replace(/[.+^$()|\\]/g, '\\$&');
19
+ const literal = (c) => c.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&');
20
+ export const escapeGlob = (text) => text.replace(/[*?[\]{}\\]/g, '\\$&');
19
21
  export function globToRegExp(glob) {
20
22
  let out = '';
21
23
  let i = 0;
22
24
  let braces = 0;
23
25
  while (i < glob.length) {
24
26
  const c = glob[i];
27
+ if (c === '\\' && i + 1 < glob.length) {
28
+ out += literal(glob[i + 1]);
29
+ i += 2;
30
+ continue;
31
+ }
25
32
  if (c === '*') {
26
33
  if (glob[i + 1] === '*') {
27
34
  const slashAfter = glob[i + 2] === '/';
@@ -59,15 +66,15 @@ export function globToRegExp(glob) {
59
66
  out += escape(c);
60
67
  i += 1;
61
68
  }
62
- return new RegExp(`^${out}$`);
69
+ return new RegExp(`^${out}$`, 's');
63
70
  }
64
71
  export function globRoot(glob) {
65
72
  const parts = glob.split('/');
66
73
  const fixed = [];
67
74
  for (const part of parts.slice(0, -1)) {
68
- if (/[*?{[]/.test(part))
75
+ if (/[*?{[]/.test(part.replace(/\\[\s\S]/g, '')))
69
76
  break;
70
- fixed.push(part);
77
+ fixed.push(part.replace(/\\([\s\S])/g, '$1'));
71
78
  }
72
79
  return fixed.join('/');
73
80
  }
@@ -1,4 +1,4 @@
1
1
  export { packageDirOf, packageNameOf } from './area.ts';
2
- export { findFiles, globRoot, globToRegExp, matches, toPosix } from './glob.ts';
2
+ export { escapeGlob, findFiles, globRoot, globToRegExp, matches, NEVER_WALKED, toPosix } from './glob.ts';
3
3
  export { readScenarios, registerReader } from './read.ts';
4
4
  export { refOf, type Refused, type Scenario, type ScenarioRef } from './scenario.ts';
@@ -1,4 +1,4 @@
1
1
  export { packageDirOf, packageNameOf } from './area.js';
2
- export { findFiles, globRoot, globToRegExp, matches, toPosix } from './glob.js';
2
+ export { escapeGlob, findFiles, globRoot, globToRegExp, matches, NEVER_WALKED, toPosix } from './glob.js';
3
3
  export { readScenarios, registerReader } from './read.js';
4
4
  export { refOf } from './scenario.js';
package/llms.txt CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  ## Commands
6
6
 
7
- - `rehearse init`: writes a starter rehearse.yaml, every block commented.
7
+ - `rehearse init [--detect] [--force] [--json]`: writes a starter rehearse.yaml, every block commented. With --detect it fills in what the repository has (base from origin/HEAD, prepare from the lockfile, a service per app whose dev script runs Vite, Next, Astro or a Node server reading PORT, and globs for stories, flows, .hurl and *.rehearse.yaml), each block commented with what it was detected from; --json adds `detected` {base, findings: [{kind, name?, from, count?, written, why, next?}], next} (schema init), naming what it found but couldn't write (OpenAPI, Playwright, a dev server it can't give a port). It writes only rehearse.yaml.
8
8
  - `rehearse check [--json]`: reads the manifest and every scenario file; says what it can't read and where (schema check).
9
9
  - `rehearse services | people | worlds [--json]`: what can come up; who you can sign in as (people: the sign-in shape {name: {token, …}}, everyone described in about; tokens only with --json); the named starting states.
10
10
  - `rehearse list [--affected <file>… | --since <ref>] [--json]`: the scenarios, or those a change reaches, each with reachedBy (schema list).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kurvball/rehearse",
3
- "version": "1.9.0",
3
+ "version": "1.10.0",
4
4
  "description": "Rehearse a change before it ships: bring the product up, sign in as named people, start from named worlds, and compare any scenario on the base and on the head.",
5
5
  "homepage": "https://rehearse.kurvball.ca/",
6
6
  "repository": {
@@ -2,7 +2,7 @@
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "$id": "https://rehearse.kurvball.ca/schema/v1/init.schema.json",
4
4
  "title": "Rehearse v1: rehearse init --json",
5
- "description": "Where the starter manifest was written.",
5
+ "description": "Where the starter manifest was written, and with --detect, what it found in the repository.",
6
6
  "type": "object",
7
7
  "required": ["v", "file", "replaced"],
8
8
  "properties": {
@@ -15,6 +15,74 @@
15
15
  "replaced": {
16
16
  "description": "Whether it replaced a manifest (--force).",
17
17
  "type": "boolean"
18
+ },
19
+ "detected": {
20
+ "description": "With --detect: what it found, and whether each finding is in the manifest.",
21
+ "type": "object",
22
+ "required": ["base", "findings", "next"],
23
+ "properties": {
24
+ "base": {
25
+ "description": "The base branch it wrote: the repository's default branch, or main when it found none.",
26
+ "type": "string"
27
+ },
28
+ "findings": {
29
+ "description": "Each thing it found, written or not, in the order of the manifest's blocks.",
30
+ "type": "array",
31
+ "items": {
32
+ "type": "object",
33
+ "required": ["kind", "from", "written", "why"],
34
+ "properties": {
35
+ "kind": {
36
+ "description": "What it found.",
37
+ "type": "string",
38
+ "examples": [
39
+ "base",
40
+ "prepare",
41
+ "build",
42
+ "service",
43
+ "pieces",
44
+ "flows",
45
+ "calls",
46
+ "files",
47
+ "openapi",
48
+ "playwright",
49
+ "gitignore"
50
+ ]
51
+ },
52
+ "name": {
53
+ "description": "The service's name in the manifest, for a service it wrote.",
54
+ "type": "string"
55
+ },
56
+ "from": {
57
+ "description": "Where it found it, relative to the manifest's folder: a file, a glob, or a git ref.",
58
+ "type": "string"
59
+ },
60
+ "count": {
61
+ "description": "How many scenario files the glob holds.",
62
+ "type": "integer",
63
+ "minimum": 0
64
+ },
65
+ "written": {
66
+ "description": "Whether it is in the manifest.",
67
+ "type": "boolean"
68
+ },
69
+ "why": {
70
+ "description": "What it wrote, or why it didn't, in one line.",
71
+ "type": "string"
72
+ },
73
+ "next": {
74
+ "description": "What to do next, when something is left to do.",
75
+ "type": "string"
76
+ }
77
+ }
78
+ }
79
+ },
80
+ "next": {
81
+ "description": "The commands to run next: check, list, then compare with the base.",
82
+ "type": "array",
83
+ "items": { "type": "string" }
84
+ }
85
+ }
18
86
  }
19
87
  }
20
88
  }
@@ -1 +1,46 @@
1
- { "v": 1, "file": "/work/acme/rehearse.yaml", "replaced": false }
1
+ {
2
+ "v": 1,
3
+ "file": "/work/acme/rehearse.yaml",
4
+ "replaced": false,
5
+ "detected": {
6
+ "base": "main",
7
+ "findings": [
8
+ { "kind": "base", "from": "origin/HEAD", "written": true, "why": "main, the default branch" },
9
+ {
10
+ "kind": "prepare",
11
+ "from": "pnpm-lock.yaml",
12
+ "written": true,
13
+ "why": "pnpm install --frozen-lockfile --prefer-offline"
14
+ },
15
+ {
16
+ "kind": "service",
17
+ "name": "web",
18
+ "from": "apps/web/package.json",
19
+ "written": true,
20
+ "why": "Vite's dev server, on a free port"
21
+ },
22
+ {
23
+ "kind": "service",
24
+ "name": "api",
25
+ "from": "apps/api/package.json",
26
+ "written": true,
27
+ "why": "a Node server that reads PORT, on a free port"
28
+ },
29
+ {
30
+ "kind": "calls",
31
+ "from": "apps/api/**/*.hurl",
32
+ "count": 4,
33
+ "written": true,
34
+ "why": "4 .hurl files, sent to api"
35
+ },
36
+ {
37
+ "kind": "openapi",
38
+ "from": "apps/api/openapi.yaml",
39
+ "written": false,
40
+ "why": "Rehearse compares calls written in Hurl, and doesn't read an OpenAPI description.",
41
+ "next": "Write a .hurl file beside the handlers, one call for each answer that matters: https://rehearse.kurvball.ca/guides/calls/"
42
+ }
43
+ ],
44
+ "next": ["rehearse check", "rehearse list", "rehearse compare --base main"]
45
+ }
46
+ }