@kurvball/rehearse 1.3.0 → 1.5.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.
- package/README.md +5 -2
- package/dist/cli.js +4 -1
- package/dist/commands/announce.d.ts +16 -0
- package/dist/commands/announce.js +77 -0
- package/dist/commands/clean.js +2 -2
- package/dist/commands/command.d.ts +1 -0
- package/dist/commands/command.js +8 -0
- package/dist/commands/compare.d.ts +4 -2
- package/dist/commands/compare.js +25 -22
- package/dist/commands/index.d.ts +4 -0
- package/dist/commands/index.js +8 -0
- package/dist/commands/mcp.d.ts +4 -0
- package/dist/commands/mcp.js +44 -0
- package/dist/commands/stage.js +4 -3
- package/dist/commands/synopsis.d.ts +19 -0
- package/dist/commands/synopsis.js +26 -0
- package/dist/commands/tools.d.ts +11 -0
- package/dist/commands/tools.js +118 -0
- package/dist/compare/announce.d.ts +14 -0
- package/dist/compare/announce.js +19 -1
- package/dist/compare/changesets.d.ts +9 -0
- package/dist/compare/changesets.js +105 -0
- package/dist/compare/compare.d.ts +1 -0
- package/dist/compare/compare.js +8 -13
- package/dist/compare/index.d.ts +2 -1
- package/dist/compare/index.js +2 -1
- package/dist/drive/daemon.js +2 -1
- package/dist/drive/grammar.d.ts +2 -0
- package/dist/drive/grammar.js +14 -4
- package/dist/drive/index.d.ts +1 -1
- package/dist/drive/index.js +1 -1
- package/dist/git/checkout.d.ts +7 -0
- package/dist/git/checkout.js +9 -2
- package/dist/git/index.d.ts +1 -1
- package/dist/git/index.js +1 -1
- package/dist/kinds/flow/kind.js +2 -1
- package/dist/kinds/piece/conventions.d.ts +1 -1
- package/dist/kinds/piece/conventions.js +1 -2
- package/dist/kinds/piece/kind.js +2 -0
- package/dist/kinds/piece/server.d.ts +1 -0
- package/dist/kinds/piece/server.js +1 -1
- package/dist/mcp/call.d.ts +13 -0
- package/dist/mcp/call.js +53 -0
- package/dist/mcp/index.d.ts +4 -0
- package/dist/mcp/index.js +3 -0
- package/dist/mcp/output.d.ts +3 -0
- package/dist/mcp/output.js +43 -0
- package/dist/mcp/server.d.ts +16 -0
- package/dist/mcp/server.js +152 -0
- package/dist/mcp/tool.d.ts +19 -0
- package/dist/mcp/tool.js +1 -0
- package/dist/services/service.js +11 -2
- package/dist/stage/api.d.ts +1 -0
- package/dist/stage/api.js +1 -0
- package/dist/stage/server.d.ts +1 -0
- package/dist/stage/server.js +2 -1
- package/llms.txt +5 -3
- package/package.json +4 -2
- package/skill/rehearse/SKILL.md +56 -2
package/README.md
CHANGED
|
@@ -65,9 +65,11 @@ Scenarios use formats agents already write:
|
|
|
65
65
|
| `rehearse up`, `rehearse down` | Brings services up with a world, and stops them |
|
|
66
66
|
| `rehearse run <scenario> [--on <checkout>]` | One observation of one scenario |
|
|
67
67
|
| `rehearse compare [--base <ref>]` | Every scenario on the base and the head, compared |
|
|
68
|
+
| `rehearse announce [--draft]` | What the change announces, or a draft to rewrite |
|
|
68
69
|
| `rehearse drive <step>` | One step for an agent: click, fill, snapshot… |
|
|
69
70
|
| `rehearse clean` | Removes old base checkouts, runs and comparisons |
|
|
70
71
|
| `rehearse validate <schema> [file]` | Checks a file or stdin against a schema in v1 |
|
|
72
|
+
| `rehearse mcp` | Serves list, compare, drive, announce over MCP |
|
|
71
73
|
|
|
72
74
|
Every command takes `--json` and prints one object described by a schema in [`schema/v1/`](schema/v1/). Within v1 an
|
|
73
75
|
output only gains optional fields and new values in open fields, so a reader ignores what it doesn't know.
|
|
@@ -85,7 +87,8 @@ Rehearse runs on [Kurvball](https://www.kurvball.ca) from a scratch clone, with
|
|
|
85
87
|
|
|
86
88
|
Rehearse 1.0 is built on [the decisions in its design](docs/plans/v1.md). [CHANGELOG.md](CHANGELOG.md) says what each version
|
|
87
89
|
changed, and [RELEASING.md](RELEASING.md) how a change gets its changeset and how a release and a hotfix go. Each
|
|
88
|
-
release is a tag
|
|
90
|
+
release is a tag, a version on [npm](https://www.npmjs.com/package/@kurvball/rehearse) published with provenance, and a
|
|
91
|
+
[GitHub Release](https://github.com/kurvball/rehearse/releases) with the package's tarball.
|
|
89
92
|
|
|
90
93
|
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
|
|
91
94
|
graph. Neither is required.
|
|
@@ -93,7 +96,7 @@ graph. Neither is required.
|
|
|
93
96
|
## Name
|
|
94
97
|
|
|
95
98
|
The package is `@kurvball/rehearse`; its command is `rehearse`. The bare name `rehearse` is taken on npm and on PyPI by
|
|
96
|
-
unrelated projects.
|
|
99
|
+
unrelated projects. Install it with `pnpm add -D @kurvball/rehearse`.
|
|
97
100
|
|
|
98
101
|
## Licence
|
|
99
102
|
|
package/dist/cli.js
CHANGED
|
@@ -27,7 +27,10 @@ export async function main(argv, ctx) {
|
|
|
27
27
|
const json = argv.includes('--json');
|
|
28
28
|
const words = argv.filter((a) => a !== '--json');
|
|
29
29
|
const name = words[0];
|
|
30
|
-
const rest =
|
|
30
|
+
const rest = words.slice(1);
|
|
31
|
+
const endOfFlags = rest.indexOf('--');
|
|
32
|
+
if (json)
|
|
33
|
+
rest.splice(endOfFlags === -1 ? rest.length : endOfFlags, 0, '--json');
|
|
31
34
|
try {
|
|
32
35
|
if (name === undefined || name === '--help' || name === 'help')
|
|
33
36
|
return { json: { v: 1, usage: USAGE }, text: USAGE, code: 0 };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Command } from './command.ts';
|
|
2
|
+
import { type Difference } from '../compare/index.ts';
|
|
3
|
+
export interface Announcement {
|
|
4
|
+
v: 1;
|
|
5
|
+
changes: {
|
|
6
|
+
scenario: string;
|
|
7
|
+
why: string;
|
|
8
|
+
}[];
|
|
9
|
+
}
|
|
10
|
+
declare const FORMATS: readonly ['yaml', 'changeset'];
|
|
11
|
+
type Format = (typeof FORMATS)[number];
|
|
12
|
+
export declare const NOT_COMPARED = "not_compared";
|
|
13
|
+
export declare const oneLine: (d: Difference) => string;
|
|
14
|
+
export declare function announcementText(a: Announcement, format: Format): string;
|
|
15
|
+
export declare const announce: Command;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { stringify } from 'yaml';
|
|
2
|
+
import { checkoutOf, manifestOf, said } from './command.js';
|
|
3
|
+
import { compare, compareOptionsOf } from './compare.js';
|
|
4
|
+
import { many, one } from '../args.js';
|
|
5
|
+
import { announcedBy, compare as compareSides, } from '../compare/index.js';
|
|
6
|
+
import { RehearseError, usage } from '../errors.js';
|
|
7
|
+
import { locate, topOf } from '../git/index.js';
|
|
8
|
+
const FORMATS = ['yaml', 'changeset'];
|
|
9
|
+
export const NOT_COMPARED = 'not_compared';
|
|
10
|
+
const ONLY_WITH_A_DRAFT = {
|
|
11
|
+
bare: ['affected', 'fresh'],
|
|
12
|
+
valued: ['world', 'as', 'real', 'parallel'],
|
|
13
|
+
};
|
|
14
|
+
function formatOf(args) {
|
|
15
|
+
const given = one(args, 'format') ?? 'yaml';
|
|
16
|
+
if (!FORMATS.includes(given))
|
|
17
|
+
throw usage(`--format takes ${FORMATS.join(' or ')}, not “${given}”.`);
|
|
18
|
+
return given;
|
|
19
|
+
}
|
|
20
|
+
const inWords = (items) => items.length < 2 ? items.join('') : `${items.slice(0, -1).join(', ')} and ${items.at(-1)}`;
|
|
21
|
+
function refuseWhatOnlyADraftTakes(args) {
|
|
22
|
+
const given = [
|
|
23
|
+
...(args.positional.length ? ['Scenario ids'] : []),
|
|
24
|
+
...ONLY_WITH_A_DRAFT.valued.filter((f) => many(args, f).length > 0).map((f) => `--${f}`),
|
|
25
|
+
...ONLY_WITH_A_DRAFT.bare.filter((f) => args.flags.has(f)).map((f) => `--${f}`),
|
|
26
|
+
];
|
|
27
|
+
if (given.length)
|
|
28
|
+
throw usage(`${inWords(given)} ${given.length === 1 ? 'needs' : 'need'} --draft: only a draft compares.`);
|
|
29
|
+
}
|
|
30
|
+
export const oneLine = (d) => `${d.path}: ${d.base} → ${d.head}`.replace(/\s*\n\s*/g, ' ');
|
|
31
|
+
const proposalOf = (s) => ({ scenario: s.scenario.id, why: oneLine(s.differences[0]) });
|
|
32
|
+
async function drafted(m, args, ctx) {
|
|
33
|
+
const c = await compareSides(m, compareOptionsOf(args, ctx, checkoutOf(m, null, ctx.cwd)));
|
|
34
|
+
if (!c.base.ok)
|
|
35
|
+
throw new RehearseError(NOT_COMPARED, c.line);
|
|
36
|
+
if (!c.head.ok)
|
|
37
|
+
throw new RehearseError(NOT_COMPARED, `The head didn't come up (${c.head.step}): ${c.head.says}`);
|
|
38
|
+
return c.scenarios.filter((s) => s.verdict === 'unsaid').map(proposalOf);
|
|
39
|
+
}
|
|
40
|
+
function announcedNow(m, args, ctx) {
|
|
41
|
+
const o = compareOptionsOf(args, ctx, checkoutOf(m, null, ctx.cwd));
|
|
42
|
+
const sides = () => {
|
|
43
|
+
const head = o.head ? locate(o.repo, o.head, ctx.cwd) : { folder: topOf(o.repo) ?? o.repo };
|
|
44
|
+
const base = locate('folder' in head ? head.folder : head.repo, o.base ?? m.base, ctx.cwd);
|
|
45
|
+
return { base, head };
|
|
46
|
+
};
|
|
47
|
+
return announcedBy(m, o, sides).map(({ scenario, why }) => ({ scenario, why }));
|
|
48
|
+
}
|
|
49
|
+
export function announcementText(a, format) {
|
|
50
|
+
if (format === 'changeset')
|
|
51
|
+
return ['```announce', ...a.changes.map((c) => `rehearse: ${c.scenario} — ${c.why}`), '```', ''].join('\n');
|
|
52
|
+
return stringify({ changes: a.changes }, { lineWidth: 0 });
|
|
53
|
+
}
|
|
54
|
+
export const announce = {
|
|
55
|
+
name: 'announce',
|
|
56
|
+
summary: 'Prints what the change announces, or, with --draft, proposes an announcement for each scenario that changed without saying so.',
|
|
57
|
+
usage: `rehearse announce [<scenario>…] [--draft] [--affected] [--base <ref|checkout>] [--head <ref|checkout>] [--announce <file>] [--announce-from changesets] [--said <scenario>]… [--world <name>] [--as <person>] [--real <stand-in>]… [--fresh] [--parallel <n>] [--format yaml|changeset] [--json]
|
|
58
|
+
|
|
59
|
+
Without --draft it reads what rehearse compare would read: the announcement file, each --said, and with
|
|
60
|
+
--announce-from changesets the changesets the change adds. With --draft it compares as rehearse compare does, and
|
|
61
|
+
proposes one entry per scenario that changed without saying so, its why the first thing that changed: rewrite it.
|
|
62
|
+
--format changeset prints an announce block for a changeset instead of YAML. It writes no file.`,
|
|
63
|
+
spec: {
|
|
64
|
+
valued: [...compare.spec.valued, 'format'],
|
|
65
|
+
bare: [...compare.spec.bare, 'draft'],
|
|
66
|
+
},
|
|
67
|
+
async run(args, ctx) {
|
|
68
|
+
const format = formatOf(args);
|
|
69
|
+
const draft = args.flags.has('draft');
|
|
70
|
+
if (!draft)
|
|
71
|
+
refuseWhatOnlyADraftTakes(args);
|
|
72
|
+
const m = manifestOf(ctx);
|
|
73
|
+
const changes = draft ? await drafted(m, args, ctx) : announcedNow(m, args, ctx);
|
|
74
|
+
const out = { v: 1, changes };
|
|
75
|
+
return said(out, announcementText(out, format));
|
|
76
|
+
},
|
|
77
|
+
};
|
package/dist/commands/clean.js
CHANGED
|
@@ -6,7 +6,7 @@ import { stateDir } from '../services/index.js';
|
|
|
6
6
|
const DAY = 24 * 60 * 60 * 1000;
|
|
7
7
|
export const clean = {
|
|
8
8
|
name: 'clean',
|
|
9
|
-
summary:
|
|
9
|
+
summary: "Removes base checkouts beyond the budget, and runs, comparisons and pieces' Vite caches older than a week. Keeps the cache.",
|
|
10
10
|
usage: 'rehearse clean [--all] [--json]\n\n--all also removes every base checkout and the baseline cache.',
|
|
11
11
|
spec: { valued: [], bare: ['all'] },
|
|
12
12
|
async run(args, ctx) {
|
|
@@ -16,7 +16,7 @@ export const clean = {
|
|
|
16
16
|
const removed = all
|
|
17
17
|
? evict({ ...m, budget: { ...m.budget, checkouts: 0 } }, repo)
|
|
18
18
|
: evict(m, repo);
|
|
19
|
-
for (const folder of ['runs', 'compare', ...(all ? ['cache'] : [])]) {
|
|
19
|
+
for (const folder of ['runs', 'compare', 'pieces', ...(all ? ['cache'] : [])]) {
|
|
20
20
|
const dir = path.join(stateDir(m.dir), folder);
|
|
21
21
|
if (!existsSync(dir))
|
|
22
22
|
continue;
|
|
@@ -28,3 +28,4 @@ export declare function manifestOf(ctx: Context): Manifest;
|
|
|
28
28
|
export declare function checkoutOf(m: Manifest, given: string | null, cwd: string): string;
|
|
29
29
|
export declare function columns(rows: readonly (readonly [string, string])[], indent?: string): string;
|
|
30
30
|
export declare function parallelOf(args: Args): number;
|
|
31
|
+
export declare function announceFromOf(args: Args): 'changesets' | null;
|
package/dist/commands/command.js
CHANGED
|
@@ -36,3 +36,11 @@ export function parallelOf(args) {
|
|
|
36
36
|
throw usage(`--parallel takes a whole number, 1 or more, not “${given}”.`);
|
|
37
37
|
return Number(given);
|
|
38
38
|
}
|
|
39
|
+
export function announceFromOf(args) {
|
|
40
|
+
const given = one(args, 'announce-from');
|
|
41
|
+
if (given === null)
|
|
42
|
+
return null;
|
|
43
|
+
if (given !== 'changesets')
|
|
44
|
+
throw usage(`--announce-from takes changesets, not “${given}”.`);
|
|
45
|
+
return given;
|
|
46
|
+
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type { Command } from './command.ts';
|
|
2
|
-
import { type
|
|
1
|
+
import type { Command, Context } from './command.ts';
|
|
2
|
+
import { type Args } from '../args.ts';
|
|
3
|
+
import { type CompareOptions, type Comparison } from '../compare/index.ts';
|
|
3
4
|
export declare function comparisonText(c: Comparison): string;
|
|
5
|
+
export declare function compareOptionsOf(args: Args, ctx: Context, repo: string): CompareOptions;
|
|
4
6
|
export declare const compare: Command;
|
package/dist/commands/compare.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import { checkoutOf, manifestOf, parallelOf, said } from './command.js';
|
|
2
|
+
import { announceFromOf, checkoutOf, manifestOf, parallelOf, said } from './command.js';
|
|
3
3
|
import { many, one } from '../args.js';
|
|
4
4
|
import { compare as compareSides } from '../compare/index.js';
|
|
5
5
|
const VERDICT_WORDS = {
|
|
@@ -55,35 +55,38 @@ export function comparisonText(c) {
|
|
|
55
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
56
|
return `${lines.join('\n')}\n`;
|
|
57
57
|
}
|
|
58
|
+
export function compareOptionsOf(args, ctx, repo) {
|
|
59
|
+
const announce = one(args, 'announce');
|
|
60
|
+
const parallel = parallelOf(args);
|
|
61
|
+
return {
|
|
62
|
+
repo,
|
|
63
|
+
cwd: ctx.cwd,
|
|
64
|
+
head: one(args, 'head'),
|
|
65
|
+
base: one(args, 'base'),
|
|
66
|
+
ids: args.positional,
|
|
67
|
+
affected: args.flags.has('affected'),
|
|
68
|
+
announce: announce ? path.resolve(ctx.cwd, announce) : null,
|
|
69
|
+
announceFrom: announceFromOf(args),
|
|
70
|
+
said: many(args, 'said'),
|
|
71
|
+
fresh: args.flags.has('fresh'),
|
|
72
|
+
world: one(args, 'world'),
|
|
73
|
+
as: one(args, 'as'),
|
|
74
|
+
real: new Set(many(args, 'real')),
|
|
75
|
+
progress: ctx.progress,
|
|
76
|
+
parallel,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
58
79
|
export const compare = {
|
|
59
80
|
name: 'compare',
|
|
60
81
|
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.",
|
|
82
|
+
usage: "rehearse compare [<scenario>…] [--affected] [--base <ref|checkout>] [--head <ref|checkout>] [--announce <file>] [--announce-from changesets] [--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
83
|
spec: {
|
|
63
|
-
valued: ['base', 'head', 'announce', 'said', 'world', 'as', 'real', 'parallel'],
|
|
84
|
+
valued: ['base', 'head', 'announce', 'announce-from', 'said', 'world', 'as', 'real', 'parallel'],
|
|
64
85
|
bare: ['affected', 'fresh'],
|
|
65
86
|
},
|
|
66
87
|
async run(args, ctx) {
|
|
67
88
|
const m = manifestOf(ctx);
|
|
68
|
-
const
|
|
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
|
-
});
|
|
89
|
+
const c = await compareSides(m, compareOptionsOf(args, ctx, checkoutOf(m, null, ctx.cwd)));
|
|
87
90
|
return said(c, comparisonText(c), c.ok ? 0 : 1);
|
|
88
91
|
},
|
|
89
92
|
};
|
package/dist/commands/index.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import type { Command } from './command.ts';
|
|
2
2
|
export { columns, GLOBAL_BARE, GLOBAL_VALUED, type Context, type Said } from './command.ts';
|
|
3
|
+
export { announcementText, NOT_COMPARED, oneLine, type Announcement } from './announce.ts';
|
|
4
|
+
export { TOOLS } from './mcp.ts';
|
|
5
|
+
export { synopsis, synopsisOf, type Flag, type Word } from './synopsis.ts';
|
|
6
|
+
export { camelCase } from './tools.ts';
|
|
3
7
|
export declare const COMMANDS: readonly Command[];
|
package/dist/commands/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { announce } from './announce.js';
|
|
1
2
|
import { check } from './check.js';
|
|
2
3
|
import { clean } from './clean.js';
|
|
3
4
|
import { compare } from './compare.js';
|
|
4
5
|
import { drive } from './drive.js';
|
|
5
6
|
import { list } from './list.js';
|
|
7
|
+
import { mcp } from './mcp.js';
|
|
6
8
|
import { open } from './open.js';
|
|
7
9
|
import { run } from './run.js';
|
|
8
10
|
import { down, up } from './up.js';
|
|
@@ -13,6 +15,10 @@ import { stage } from './stage.js';
|
|
|
13
15
|
import { validate } from './validate.js';
|
|
14
16
|
import { worlds } from './worlds.js';
|
|
15
17
|
export { columns, GLOBAL_BARE, GLOBAL_VALUED } from './command.js';
|
|
18
|
+
export { announcementText, NOT_COMPARED, oneLine } from './announce.js';
|
|
19
|
+
export { TOOLS } from './mcp.js';
|
|
20
|
+
export { synopsis, synopsisOf } from './synopsis.js';
|
|
21
|
+
export { camelCase } from './tools.js';
|
|
16
22
|
export const COMMANDS = [
|
|
17
23
|
init,
|
|
18
24
|
check,
|
|
@@ -24,9 +30,11 @@ export const COMMANDS = [
|
|
|
24
30
|
down,
|
|
25
31
|
run,
|
|
26
32
|
compare,
|
|
33
|
+
announce,
|
|
27
34
|
drive,
|
|
28
35
|
stage,
|
|
29
36
|
open,
|
|
30
37
|
clean,
|
|
31
38
|
validate,
|
|
39
|
+
mcp,
|
|
32
40
|
];
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { said } from './command.js';
|
|
3
|
+
import { announce } from './announce.js';
|
|
4
|
+
import { compare } from './compare.js';
|
|
5
|
+
import { drive } from './drive.js';
|
|
6
|
+
import { list } from './list.js';
|
|
7
|
+
import { stepsToolOf, toolOf } from './tools.js';
|
|
8
|
+
import { usage } from '../errors.js';
|
|
9
|
+
import { serveOnStdio } from '../mcp/index.js';
|
|
10
|
+
export const TOOLS = [
|
|
11
|
+
toolOf(list, { output: 'list', annotations: { readOnlyHint: true, idempotentHint: true } }),
|
|
12
|
+
toolOf(compare, {
|
|
13
|
+
output: 'comparison',
|
|
14
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true },
|
|
15
|
+
}),
|
|
16
|
+
stepsToolOf(drive, { output: 'drive', annotations: { readOnlyHint: false, idempotentHint: false } }),
|
|
17
|
+
toolOf(announce, {
|
|
18
|
+
output: 'announce',
|
|
19
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true },
|
|
20
|
+
forPeopleOnly: ['format'],
|
|
21
|
+
}),
|
|
22
|
+
];
|
|
23
|
+
const inWords = (names) => names.length < 2 ? names.join('') : `${names.slice(0, -1).join(', ')} and ${names.at(-1)}`;
|
|
24
|
+
export const mcp = {
|
|
25
|
+
name: 'mcp',
|
|
26
|
+
summary: `Serves ${inWords(TOOLS.map((t) => t.name))} as MCP tools on stdio, each answering with its command's --json object.`,
|
|
27
|
+
usage: `rehearse mcp
|
|
28
|
+
|
|
29
|
+
An MCP client starts it, talks to it over stdin and stdout, and stops it: it opens no port.
|
|
30
|
+
Each call runs the command in this folder, as \`rehearse <command> --json\` would.`,
|
|
31
|
+
spec: { valued: [], bare: [] },
|
|
32
|
+
async run(args, ctx) {
|
|
33
|
+
if (ctx.json)
|
|
34
|
+
throw usage('rehearse mcp speaks MCP on stdout, so it takes no --json.');
|
|
35
|
+
if (args.positional.length)
|
|
36
|
+
throw usage(`rehearse mcp takes no words, not “${args.positional[0]}”.`);
|
|
37
|
+
await serveOnStdio(TOOLS, {
|
|
38
|
+
cwd: ctx.cwd,
|
|
39
|
+
env: ctx.manifest ? { ...ctx.env, REHEARSE_MANIFEST: path.resolve(ctx.cwd, ctx.manifest) } : ctx.env,
|
|
40
|
+
log: ctx.progress,
|
|
41
|
+
});
|
|
42
|
+
return said(null, '', 0);
|
|
43
|
+
},
|
|
44
|
+
};
|
package/dist/commands/stage.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import { checkoutOf, manifestOf, said } from './command.js';
|
|
2
|
+
import { announceFromOf, checkoutOf, manifestOf, said } from './command.js';
|
|
3
3
|
import { many, one } from '../args.js';
|
|
4
4
|
import { errorText, usage } from '../errors.js';
|
|
5
5
|
import { startStage } from '../stage/index.js';
|
|
@@ -15,8 +15,8 @@ export function portOf(given) {
|
|
|
15
15
|
export const stage = {
|
|
16
16
|
name: 'stage',
|
|
17
17
|
summary: "Serves the stage: every scenario on one page, in Base, Head and Diff, with Works, Doesn't and a note.",
|
|
18
|
-
usage: 'rehearse stage [--base <ref|checkout>] [--head <ref|checkout>] [--port <port>] [--announce <file>] [--said <scenario>]…\n\nIt runs until you stop it (Ctrl-C), and stops the services it brought up.\nCompare on the stage reads the announcement as rehearse compare does.',
|
|
19
|
-
spec: { valued: ['base', 'head', 'port', 'announce', 'said'], bare: [] },
|
|
18
|
+
usage: 'rehearse stage [--base <ref|checkout>] [--head <ref|checkout>] [--port <port>] [--announce <file>] [--announce-from changesets] [--said <scenario>]…\n\nIt runs until you stop it (Ctrl-C), and stops the services it brought up.\nCompare on the stage reads the announcement as rehearse compare does.',
|
|
19
|
+
spec: { valued: ['base', 'head', 'port', 'announce', 'announce-from', 'said'], bare: [] },
|
|
20
20
|
async run(args, ctx) {
|
|
21
21
|
const m = manifestOf(ctx);
|
|
22
22
|
const { port, anyPort } = portOf(one(args, 'port'));
|
|
@@ -30,6 +30,7 @@ export const stage = {
|
|
|
30
30
|
port,
|
|
31
31
|
anyPort,
|
|
32
32
|
announce: announce ? path.resolve(ctx.cwd, announce) : null,
|
|
33
|
+
announceFrom: announceFromOf(args),
|
|
33
34
|
said: many(args, 'said'),
|
|
34
35
|
progress: ctx.progress,
|
|
35
36
|
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface Flag {
|
|
2
|
+
name: string;
|
|
3
|
+
value: string | null;
|
|
4
|
+
repeatable: boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface Word {
|
|
7
|
+
name: string;
|
|
8
|
+
shown: string;
|
|
9
|
+
optional: boolean;
|
|
10
|
+
repeating: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare function synopsis(line: string, valued: (flag: string) => boolean): {
|
|
13
|
+
flags: Flag[];
|
|
14
|
+
words: Word[];
|
|
15
|
+
};
|
|
16
|
+
export declare const synopsisOf: (usage: string, valued: readonly string[]) => {
|
|
17
|
+
flags: Flag[];
|
|
18
|
+
words: Word[];
|
|
19
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const VALUE = /^[ =](<[^>]+>|[a-z]+(?:\|[a-z]+)*)/;
|
|
2
|
+
const REPEATS = /^\]?…/;
|
|
3
|
+
export function synopsis(line, valued) {
|
|
4
|
+
const flags = [];
|
|
5
|
+
const words = [];
|
|
6
|
+
const token = /--([a-z][a-z-]*)|<([^>]+)>/g;
|
|
7
|
+
for (let m = token.exec(line); m; m = token.exec(line)) {
|
|
8
|
+
const before = line.slice(0, m.index);
|
|
9
|
+
const depth = (before.match(/\[/g)?.length ?? 0) - (before.match(/\]/g)?.length ?? 0);
|
|
10
|
+
if (m[1]) {
|
|
11
|
+
const value = VALUE.exec(line.slice(token.lastIndex));
|
|
12
|
+
const takes = value && valued(m[1]) ? value[1] : null;
|
|
13
|
+
if (takes)
|
|
14
|
+
token.lastIndex += value[0].length;
|
|
15
|
+
const repeatable = REPEATS.test(line.slice(token.lastIndex));
|
|
16
|
+
if (!flags.some((f) => f.name === m[1]))
|
|
17
|
+
flags.push({ name: m[1], value: takes, repeatable });
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
const repeating = REPEATS.test(line.slice(token.lastIndex));
|
|
21
|
+
words.push({ name: m[2], shown: `<${m[2]}>${repeating ? '…' : ''}`, optional: depth > 0, repeating });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return { flags, words };
|
|
25
|
+
}
|
|
26
|
+
export const synopsisOf = (usage, valued) => synopsis(usage.split('\n')[0], (flag) => valued.includes(flag));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Command } from './command.ts';
|
|
2
|
+
import type { Annotations, Tool } from '../mcp/index.ts';
|
|
3
|
+
import type { SchemaName } from '../schema.ts';
|
|
4
|
+
export declare const camelCase: (name: string) => string;
|
|
5
|
+
export interface ToolChoices {
|
|
6
|
+
output: SchemaName;
|
|
7
|
+
annotations: Annotations;
|
|
8
|
+
forPeopleOnly?: readonly string[];
|
|
9
|
+
}
|
|
10
|
+
export declare function toolOf(command: Command, choices: ToolChoices): Tool;
|
|
11
|
+
export declare function stepsToolOf(command: Command, choices: ToolChoices): Tool;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { GLOBAL_VALUED } from './command.js';
|
|
2
|
+
import { synopsis, synopsisOf } from './synopsis.js';
|
|
3
|
+
import { STEP_FLAGS, STEP_WORDS, VERBS } from '../drive/index.js';
|
|
4
|
+
export const camelCase = (name) => name.replace(/[^a-z0-9]+([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
5
|
+
const GLOBAL_FLAGS = {
|
|
6
|
+
manifest: { name: 'manifest', value: '<file>', repeatable: false },
|
|
7
|
+
};
|
|
8
|
+
const fallbackOf = (name) => GLOBAL_FLAGS[name] ?? { name, value: null, repeatable: false };
|
|
9
|
+
function valueOf(value) {
|
|
10
|
+
if (value === '<n>')
|
|
11
|
+
return { type: 'integer' };
|
|
12
|
+
if (value && !value.startsWith('<'))
|
|
13
|
+
return { enum: value.split('|') };
|
|
14
|
+
return { type: 'string', minLength: 1 };
|
|
15
|
+
}
|
|
16
|
+
function optionOf(flag, valued, description) {
|
|
17
|
+
const one = valueOf(flag.value);
|
|
18
|
+
const schema = !valued ? { type: 'boolean' } : flag.repeatable ? { type: 'array', items: one } : one;
|
|
19
|
+
return { key: camelCase(flag.name), flag: flag.name, bare: !valued, schema: { ...schema, description } };
|
|
20
|
+
}
|
|
21
|
+
const shownOf = (flag, valued) => `--${flag.name}${valued ? ` ${flag.value ?? '<value>'}` : ''}${flag.repeatable ? ', repeatable' : ''}`;
|
|
22
|
+
function inputSchemaOf(options, words) {
|
|
23
|
+
const properties = {};
|
|
24
|
+
for (const x of [...words, ...options]) {
|
|
25
|
+
if (x.key in properties)
|
|
26
|
+
throw new Error(`Two arguments would be named ${x.key}.`);
|
|
27
|
+
properties[x.key] = x.schema;
|
|
28
|
+
}
|
|
29
|
+
const required = words.filter((w) => w.required).map((w) => w.key);
|
|
30
|
+
return { type: 'object', properties, ...(required.length && { required }), additionalProperties: false };
|
|
31
|
+
}
|
|
32
|
+
function flagsOf(options, args) {
|
|
33
|
+
return options.flatMap((o) => {
|
|
34
|
+
const given = args[o.key];
|
|
35
|
+
if (given === undefined || given === false)
|
|
36
|
+
return [];
|
|
37
|
+
if (o.bare)
|
|
38
|
+
return [`--${o.flag}`];
|
|
39
|
+
return [given].flat().map((value) => `--${o.flag}=${String(value)}`);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
const describedAs = (command, output) => `${command.summary} It answers with what \`rehearse ${command.name} --json\` prints: the ${output} object of schema/v1/${output}.schema.json.`;
|
|
43
|
+
export function toolOf(command, choices) {
|
|
44
|
+
const { flags, words } = synopsisOf(command.usage, command.spec.valued);
|
|
45
|
+
const valued = [...command.spec.valued, ...GLOBAL_VALUED];
|
|
46
|
+
const options = [...command.spec.valued, ...command.spec.bare, ...GLOBAL_VALUED]
|
|
47
|
+
.filter((name) => !choices.forPeopleOnly?.includes(name))
|
|
48
|
+
.map((name) => {
|
|
49
|
+
const flag = flags.find((f) => f.name === name) ?? fallbackOf(name);
|
|
50
|
+
return optionOf(flag, valued.includes(name), shownOf(flag, valued.includes(name)));
|
|
51
|
+
});
|
|
52
|
+
const positional = words.map((w) => ({
|
|
53
|
+
key: camelCase(w.name),
|
|
54
|
+
required: !w.optional,
|
|
55
|
+
schema: w.repeating
|
|
56
|
+
? { type: 'array', items: { type: 'string', minLength: 1 }, description: w.shown }
|
|
57
|
+
: { type: 'string', minLength: 1, description: w.shown },
|
|
58
|
+
}));
|
|
59
|
+
return {
|
|
60
|
+
name: command.name,
|
|
61
|
+
description: describedAs(command, choices.output),
|
|
62
|
+
inputSchema: inputSchemaOf(options, positional),
|
|
63
|
+
output: choices.output,
|
|
64
|
+
annotations: choices.annotations,
|
|
65
|
+
failsWhenNotOk: false,
|
|
66
|
+
argvOf(args) {
|
|
67
|
+
const given = positional.flatMap((p) => (args[p.key] === undefined ? [] : [args[p.key]].flat()));
|
|
68
|
+
return [
|
|
69
|
+
command.name,
|
|
70
|
+
...flagsOf(options, args),
|
|
71
|
+
'--json',
|
|
72
|
+
...(given.length ? ['--', ...given.map(String)] : []),
|
|
73
|
+
];
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
export function stepsToolOf(command, choices) {
|
|
78
|
+
const shapes = command.usage
|
|
79
|
+
.split('\n')
|
|
80
|
+
.filter((line) => new RegExp(`^\\s+rehearse ${command.name} [a-z]`).test(line))
|
|
81
|
+
.flatMap((line) => synopsis(line.trim().replace(/\s{2,}.*$/, ''), () => true).flags);
|
|
82
|
+
const takenBy = (pick) => VERBS.filter(pick)
|
|
83
|
+
.map((v) => `\`${v}\``)
|
|
84
|
+
.join(', ');
|
|
85
|
+
const options = [...new Set([...VERBS.flatMap((v) => STEP_FLAGS[v]), ...GLOBAL_VALUED])].map((name) => {
|
|
86
|
+
const flag = shapes.find((f) => f.name === name) ?? fallbackOf(name);
|
|
87
|
+
const steps = takenBy((v) => STEP_FLAGS[v].includes(name));
|
|
88
|
+
return optionOf(flag, true, `${shownOf(flag, true)}${steps ? `, for ${steps}` : ''}`);
|
|
89
|
+
});
|
|
90
|
+
const wordNames = [...new Set(VERBS.map((v) => STEP_WORDS[v]).filter((w) => w !== null))];
|
|
91
|
+
const positional = [
|
|
92
|
+
{
|
|
93
|
+
key: 'step',
|
|
94
|
+
required: true,
|
|
95
|
+
schema: { enum: [...VERBS], description: `The step, as in rehearse ${command.name} <step>.` },
|
|
96
|
+
},
|
|
97
|
+
...wordNames.map((word) => ({
|
|
98
|
+
key: camelCase(word),
|
|
99
|
+
required: false,
|
|
100
|
+
schema: {
|
|
101
|
+
type: 'string',
|
|
102
|
+
description: `<${word}>, for ${takenBy((v) => STEP_WORDS[v] === word)}`,
|
|
103
|
+
},
|
|
104
|
+
})),
|
|
105
|
+
];
|
|
106
|
+
return {
|
|
107
|
+
name: command.name,
|
|
108
|
+
description: describedAs(command, choices.output),
|
|
109
|
+
inputSchema: inputSchemaOf(options, positional),
|
|
110
|
+
output: choices.output,
|
|
111
|
+
annotations: choices.annotations,
|
|
112
|
+
failsWhenNotOk: true,
|
|
113
|
+
argvOf(args) {
|
|
114
|
+
const words = wordNames.flatMap((w) => args[camelCase(w)] === undefined ? [] : [String(args[camelCase(w)])]);
|
|
115
|
+
return [command.name, String(args.step), ...words, ...flagsOf(options, args), '--json'];
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
}
|
|
@@ -1,6 +1,20 @@
|
|
|
1
|
+
import type { Tree } from '../git/index.ts';
|
|
2
|
+
import { type Manifest } from '../manifest/index.ts';
|
|
1
3
|
export interface Announced {
|
|
2
4
|
scenario: string;
|
|
3
5
|
why: string;
|
|
6
|
+
from?: string;
|
|
4
7
|
}
|
|
5
8
|
export declare function readAnnouncement(file: string): Announced[];
|
|
6
9
|
export declare function announcementFor(id: string, announced: readonly Announced[]): Announced | null;
|
|
10
|
+
export interface AnnouncedFrom {
|
|
11
|
+
repo: string;
|
|
12
|
+
announce: string | null;
|
|
13
|
+
announceFrom?: 'changesets' | null;
|
|
14
|
+
said: readonly string[];
|
|
15
|
+
}
|
|
16
|
+
export declare const SAID_ON_THE_COMMAND_LINE = "Said on the command line.";
|
|
17
|
+
export declare function announcedBy(m: Manifest, o: AnnouncedFrom, sides: () => {
|
|
18
|
+
base: Tree;
|
|
19
|
+
head: Tree;
|
|
20
|
+
}): Announced[];
|
package/dist/compare/announce.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs';
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
2
3
|
import { RehearseError } from '../errors.js';
|
|
3
4
|
import { readYaml } from '../manifest/index.js';
|
|
4
5
|
import { globToRegExp } from '../scenarios/index.js';
|
|
5
6
|
import { validate } from '../schema.js';
|
|
7
|
+
import { stateDir } from '../services/index.js';
|
|
8
|
+
import { announcedByChangesets } from './changesets.js';
|
|
6
9
|
export function readAnnouncement(file) {
|
|
7
10
|
let text;
|
|
8
11
|
try {
|
|
@@ -25,3 +28,18 @@ export function readAnnouncement(file) {
|
|
|
25
28
|
export function announcementFor(id, announced) {
|
|
26
29
|
return (announced.find((a) => a.scenario === id || (/[*?{[]/.test(a.scenario) && globToRegExp(a.scenario).test(id))) ?? null);
|
|
27
30
|
}
|
|
31
|
+
export const SAID_ON_THE_COMMAND_LINE = 'Said on the command line.';
|
|
32
|
+
export function announcedBy(m, o, sides) {
|
|
33
|
+
const announced = [];
|
|
34
|
+
const kept = path.join(stateDir(m.dir), 'announce.yaml');
|
|
35
|
+
const file = o.announce ?? (existsSync(kept) ? kept : null);
|
|
36
|
+
if (file)
|
|
37
|
+
announced.push(...readAnnouncement(path.resolve(o.repo, file)).map((a) => ({ ...a, from: file })));
|
|
38
|
+
if (o.announceFrom === 'changesets') {
|
|
39
|
+
const { base, head } = sides();
|
|
40
|
+
announced.push(...announcedByChangesets(base, head).map((a) => ({ scenario: a.scenario, why: a.why, from: a.file })));
|
|
41
|
+
}
|
|
42
|
+
for (const id of o.said)
|
|
43
|
+
announced.push({ scenario: id, why: SAID_ON_THE_COMMAND_LINE, from: '--said' });
|
|
44
|
+
return announced;
|
|
45
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Tree } from '../git/index.ts';
|
|
2
|
+
import type { Announced } from './announce.ts';
|
|
3
|
+
export interface ChangesetAnnounced extends Announced {
|
|
4
|
+
file: string;
|
|
5
|
+
line: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function addedChangesets(base: string | Tree, head: string | Tree): string[];
|
|
8
|
+
export declare function announcedIn(text: string, file: string): ChangesetAnnounced[];
|
|
9
|
+
export declare function announcedByChangesets(base: string | Tree, head: string | Tree): ChangesetAnnounced[];
|