@kurvball/rehearse 1.4.0 → 1.6.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 +2 -0
- package/dist/cli.js +4 -1
- package/dist/commands/announce.d.ts +16 -0
- package/dist/commands/announce.js +77 -0
- package/dist/commands/compare.d.ts +4 -2
- package/dist/commands/compare.js +22 -20
- 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/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 +13 -0
- package/dist/compare/announce.js +19 -1
- package/dist/compare/changesets.d.ts +3 -2
- package/dist/compare/changesets.js +22 -8
- package/dist/compare/compare.js +6 -18
- package/dist/compare/index.d.ts +1 -1
- package/dist/compare/index.js +1 -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/file/kind.d.ts +1 -0
- package/dist/kinds/file/kind.js +1 -0
- 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/llms.txt +3 -1
- package/package.json +4 -2
- package/schema/v1/file-scenario.schema.json +7 -0
- package/skill/rehearse/SKILL.md +52 -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.
|
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
|
+
};
|
|
@@ -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
|
@@ -55,6 +55,27 @@ 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.',
|
|
@@ -65,26 +86,7 @@ export const compare = {
|
|
|
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
|
-
announceFrom: announceFromOf(args),
|
|
80
|
-
said: many(args, 'said'),
|
|
81
|
-
fresh: args.flags.has('fresh'),
|
|
82
|
-
world: one(args, 'world'),
|
|
83
|
-
as: one(args, 'as'),
|
|
84
|
-
real: new Set(many(args, 'real')),
|
|
85
|
-
progress: ctx.progress,
|
|
86
|
-
parallel,
|
|
87
|
-
});
|
|
89
|
+
const c = await compareSides(m, compareOptionsOf(args, ctx, checkoutOf(m, null, ctx.cwd)));
|
|
88
90
|
return said(c, comparisonText(c), c.ok ? 0 : 1);
|
|
89
91
|
},
|
|
90
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
|
+
};
|
|
@@ -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,3 +1,5 @@
|
|
|
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;
|
|
@@ -5,3 +7,14 @@ export interface Announced {
|
|
|
5
7
|
}
|
|
6
8
|
export declare function readAnnouncement(file: string): Announced[];
|
|
7
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
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { type Tree } from '../git/index.ts';
|
|
1
2
|
import type { Announced } from './announce.ts';
|
|
2
3
|
export interface ChangesetAnnounced extends Announced {
|
|
3
4
|
file: string;
|
|
4
5
|
line: number;
|
|
5
6
|
}
|
|
6
|
-
export declare function addedChangesets(base: string, head: string): string[];
|
|
7
|
+
export declare function addedChangesets(base: string | Tree, head: string | Tree): string[];
|
|
7
8
|
export declare function announcedIn(text: string, file: string): ChangesetAnnounced[];
|
|
8
|
-
export declare function announcedByChangesets(base: string, head: string): ChangesetAnnounced[];
|
|
9
|
+
export declare function announcedByChangesets(base: string | Tree, head: string | Tree): ChangesetAnnounced[];
|
|
@@ -1,20 +1,34 @@
|
|
|
1
1
|
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { RehearseError } from '../errors.js';
|
|
4
|
+
import { gitOr } from '../git/index.js';
|
|
4
5
|
const CHANGESETS = '.changeset';
|
|
5
6
|
const NOT_A_CHANGESET = new Set(['README.md']);
|
|
6
7
|
const FENCE = /^(`{3,}|~{3,})\s*([^\s`~]*)/;
|
|
7
8
|
const TARGET = /^([a-z][a-z0-9-]*):\s*(.*)$/;
|
|
8
9
|
const OWN_WHY = /^(.*?)\s+—(?:\s+(.*))?$/;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const treeOf = (side) => (typeof side === 'string' ? { folder: side } : side);
|
|
11
|
+
const isAChangeset = (name) => name.endsWith('.md') && !NOT_A_CHANGESET.has(name);
|
|
12
|
+
function namesIn(tree) {
|
|
13
|
+
if ('folder' in tree) {
|
|
14
|
+
const folder = path.join(tree.folder, CHANGESETS);
|
|
15
|
+
return existsSync(folder) ? readdirSync(folder) : [];
|
|
16
|
+
}
|
|
17
|
+
const listed = gitOr(tree.repo, ['ls-tree', '--name-only', tree.commit, `${CHANGESETS}/`]) ?? '';
|
|
18
|
+
return listed
|
|
19
|
+
.split('\n')
|
|
20
|
+
.filter(Boolean)
|
|
21
|
+
.map((file) => path.posix.basename(file));
|
|
22
|
+
}
|
|
23
|
+
const changesetsIn = (tree) => new Set(namesIn(tree).filter(isAChangeset));
|
|
24
|
+
function textIn(tree, file) {
|
|
25
|
+
if ('folder' in tree)
|
|
26
|
+
return readFileSync(path.join(tree.folder, file), 'utf8');
|
|
27
|
+
return gitOr(tree.repo, ['show', `${tree.commit}:${file}`]) ?? '';
|
|
14
28
|
}
|
|
15
29
|
export function addedChangesets(base, head) {
|
|
16
|
-
const onBase = changesetsIn(base);
|
|
17
|
-
return [...changesetsIn(head)]
|
|
30
|
+
const onBase = changesetsIn(treeOf(base));
|
|
31
|
+
return [...changesetsIn(treeOf(head))]
|
|
18
32
|
.filter((name) => !onBase.has(name))
|
|
19
33
|
.sort()
|
|
20
34
|
.map((name) => `${CHANGESETS}/${name}`);
|
|
@@ -87,5 +101,5 @@ export function announcedIn(text, file) {
|
|
|
87
101
|
return announced;
|
|
88
102
|
}
|
|
89
103
|
export function announcedByChangesets(base, head) {
|
|
90
|
-
return addedChangesets(base, head).flatMap((file) => announcedIn(
|
|
104
|
+
return addedChangesets(base, head).flatMap((file) => announcedIn(textIn(treeOf(head), file), file));
|
|
91
105
|
}
|
package/dist/compare/compare.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
-
import {
|
|
2
|
+
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { affected } from '../affected/index.js';
|
|
5
5
|
import { RehearseError, errorText } from '../errors.js';
|
|
@@ -8,8 +8,7 @@ import { runnerOf } from '../kinds/index.js';
|
|
|
8
8
|
import { cached, cacheKeyOf, groupsOf, keep, runSideSharing, slotsFor, } from '../run/index.js';
|
|
9
9
|
import { readScenarios, refOf, globToRegExp, } from '../scenarios/index.js';
|
|
10
10
|
import { runningServices, stateDir } from '../services/index.js';
|
|
11
|
-
import {
|
|
12
|
-
import { announcedByChangesets } from './changesets.js';
|
|
11
|
+
import { announcedBy, announcementFor } from './announce.js';
|
|
13
12
|
import { nonZeroCounts, noCounts, rulesOf } from './setaside.js';
|
|
14
13
|
import { lineOf, verdictOf } from './verdict.js';
|
|
15
14
|
const emptyCounts = () => ({
|
|
@@ -113,21 +112,10 @@ export async function compare(m, o) {
|
|
|
113
112
|
}
|
|
114
113
|
if (path.resolve(base.path) === path.resolve(head.path))
|
|
115
114
|
throw new RehearseError('usage', `The base and the head are the same checkout (${head.path}): name a base ref, or another folder.`, { exit: 2 });
|
|
116
|
-
const announced =
|
|
117
|
-
|
|
118
|
-
(
|
|
119
|
-
|
|
120
|
-
: null);
|
|
121
|
-
if (announceFile)
|
|
122
|
-
announced.push(...readAnnouncement(path.resolve(o.repo, announceFile)).map((a) => ({ ...a, from: announceFile })));
|
|
123
|
-
if (o.announceFrom === 'changesets')
|
|
124
|
-
announced.push(...announcedByChangesets(topOf(base.path) ?? base.path, topOf(head.path) ?? head.path).map((a) => ({
|
|
125
|
-
scenario: a.scenario,
|
|
126
|
-
why: a.why,
|
|
127
|
-
from: a.file,
|
|
128
|
-
})));
|
|
129
|
-
for (const id of o.said)
|
|
130
|
-
announced.push({ scenario: id, why: 'Said on the command line.', from: '--said' });
|
|
115
|
+
const announced = announcedBy(m, o, () => ({
|
|
116
|
+
base: { folder: topOf(base.path) ?? base.path },
|
|
117
|
+
head: { folder: topOf(head.path) ?? head.path },
|
|
118
|
+
}));
|
|
131
119
|
const headRead = await readScenarios(m, head.path);
|
|
132
120
|
const baseRead = await readScenarios(m, base.path);
|
|
133
121
|
let headScenarios = select(headRead.scenarios, o.ids);
|
package/dist/compare/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { readAnnouncement } from './announce.ts';
|
|
1
|
+
export { announcedBy, readAnnouncement, SAID_ON_THE_COMMAND_LINE, type Announced, type AnnouncedFrom, } from './announce.ts';
|
|
2
2
|
export { addedChangesets, announcedByChangesets, announcedIn, type ChangesetAnnounced, } from './changesets.ts';
|
|
3
3
|
export { changedFiles, compare, type CompareOptions, type Compared, type Comparison } from './compare.ts';
|
|
4
4
|
export { clip, jsonDifferences, lineHunks, textDifferences, type Difference } from './diff.ts';
|
package/dist/compare/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { readAnnouncement } from './announce.js';
|
|
1
|
+
export { announcedBy, readAnnouncement, SAID_ON_THE_COMMAND_LINE, } from './announce.js';
|
|
2
2
|
export { addedChangesets, announcedByChangesets, announcedIn, } from './changesets.js';
|
|
3
3
|
export { changedFiles, compare } from './compare.js';
|
|
4
4
|
export { clip, jsonDifferences, lineHunks, textDifferences } from './diff.js';
|
package/dist/drive/grammar.d.ts
CHANGED
|
@@ -79,6 +79,8 @@ export declare const exitOf: (r: DriveResult) => number;
|
|
|
79
79
|
export declare function stepCommand(step: Step): Command;
|
|
80
80
|
export declare function stepWords(step: Step): string;
|
|
81
81
|
export declare function stepOf(v: unknown, n: number): Step;
|
|
82
|
+
export declare const STEP_FLAGS: Readonly<Record<Verb, readonly string[]>>;
|
|
83
|
+
export declare const STEP_WORDS: Readonly<Record<Verb, string | null>>;
|
|
82
84
|
export type Parsed = {
|
|
83
85
|
ok: true;
|
|
84
86
|
command: Command;
|