@vodmal/vdx-cli 0.16.0 → 0.17.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 (3) hide show
  1. package/README.md +8 -3
  2. package/package.json +1 -1
  3. package/src/index.ts +138 -50
package/README.md CHANGED
@@ -49,7 +49,9 @@ vdx doctor [--format=ansi|markdown|json]
49
49
 
50
50
  # Start your agent in a project per your profile (~/.vdx-environment.yaml or $VDX_ENVIRONMENT)
51
51
  vdx ai[@host] [project-path] [--new] [--restart] [--detach] [--dry-run] # default: cwd; @host: over ssh, in tmux there
52
- vdx ai --help # flags, where launch flags live, exit codes
52
+
53
+ # What a command does and takes; nothing runs (ai: also where launch flags live)
54
+ vdx <command> --help
53
55
 
54
56
  # Print the installed version
55
57
  vdx --version
@@ -88,8 +90,11 @@ name. `vdx ai@<host>` runs the same command on `<host>` over ssh — that machin
88
90
  profile and tmux, the path taken under its home directory; `--detach` only
89
91
  starts it. The machine's own label (`$VDX_HOST`) runs here. Where git knows no
90
92
  commit author, `vdx ai` proposes one (Enter writes it into `.git/config`).
91
- `vdx ai --help` (`-h`) prints the help; an unknown option or a second path is
92
- refused with exit 2, and nothing starts.
93
+
94
+ Every command takes `--help` (`-h`) and runs nothing with it. An unknown option,
95
+ a stray argument or a value flag without its value is refused with exit 2
96
+ before anything runs. In 0.16.0 and earlier the commands other than `vdx ai`
97
+ dropped such arguments, and `vdx init --help` wrote `mise.toml`.
93
98
 
94
99
  By default the bundled `rubric/vdx-rubric.yaml` is used (a mirror of canonical
95
100
  [vdx-rubric-vodmal](https://github.com/VoDmAl/vdx-rubric-vodmal) at the time of
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vodmal/vdx-cli",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "description": "vdx — unified lifecycle interface (up/down/build/test/check/fix) + versioned maturity audit with drift detection. Pairs with the vdx Claude Code plugin.",
5
5
  "keywords": [
6
6
  "vdx",
package/src/index.ts CHANGED
@@ -33,27 +33,36 @@ import { runAi, runAiRemote, defaultDeps, hostLabel, REMOTE_HOST_RE } from './ai
33
33
 
34
34
  const DEFAULT_RUBRIC = resolveDefaultRubric();
35
35
 
36
- function usage(): never {
37
- process.stderr.write(
38
- `Usage:
36
+ const USAGE = `Usage:
39
37
  vdx <up|down|build|test|check|fix> run lifecycle verb (via mise run <verb>)
40
38
  vdx audit [project_path] [--rubric <path>] [--stack <stack>] [--format=ansi|markdown|json] [--json] (default: cwd)
41
39
  vdx init [project_path] [--stack <id>] [--baseline <ref>] [--dry-run] [--force] (default: cwd)
42
40
  vdx publish <patch|minor|major> [--dry-run] [--force]
43
41
  vdx doctor [--format=ansi|markdown|json] [--json]
44
42
  vdx ai[@host] [project_path] [--new] [--restart] [--detach] [--dry-run] (default: cwd; @host: over ssh, in tmux there)
45
- vdx ai --help (launch flags, profile, exit codes)
43
+ vdx <command> --help what the command does; an unknown option is refused (exit 2)
46
44
  vdx --version
47
- `,
48
- );
45
+ `;
46
+
47
+ function usage(): never {
48
+ process.stderr.write(USAGE);
49
49
  process.exit(1);
50
50
  }
51
51
 
52
- const AI_USAGE_LINE = 'Usage: vdx ai[@host] [project_path] [--new] [--restart] [--detach] [--dry-run]';
53
-
54
- const AI_HELP = `${AI_USAGE_LINE}
52
+ /** What a command reads from its arguments; the rest is refused. */
53
+ interface CommandSpec {
54
+ usage: string;
55
+ /** Printed under the usage line by `--help`. */
56
+ help: string;
57
+ /** Flags that take no value. */
58
+ bools?: string[];
59
+ /** Flags that take one (`--stack node`, `--format=json`). */
60
+ values?: string[];
61
+ /** How many positional arguments the command takes. */
62
+ positionals: number;
63
+ }
55
64
 
56
- Starts your agent in the project, or attaches to the one already running there.
65
+ const AI_HELP = `Starts your agent in the project, or attaches to the one already running there.
57
66
  Which agent, its flags and whether it runs in tmux come from your profile:
58
67
  $VDX_ENVIRONMENT, else ~/.vdx-environment.yaml, else a plain claude/codex.
59
68
 
@@ -75,12 +84,65 @@ was not confirmed.
75
84
  Profile format: https://github.com/VoDmAl/vdx/blob/main/docs/specs/environment-format.md
76
85
  `;
77
86
 
78
- const AI_FLAGS = ['new', 'restart', 'resume', 'detach', 'dry-run', 'help'];
79
-
80
- function aiUsageError(message: string): never {
81
- process.stderr.write(`vdx ai: ${message}\n${AI_USAGE_LINE}\nMore: vdx ai --help\n`);
82
- process.exit(2);
83
- }
87
+ const COMMANDS: Record<string, CommandSpec> = {
88
+ audit: {
89
+ usage: 'vdx audit [project_path] [--rubric <path>] [--stack <stack>] [--format=ansi|markdown|json] [--json]',
90
+ help: `Scores the project (default: cwd) against the rubric and prints the report.
91
+ Reads only. The rubric is the bundled one unless --rubric or $VDX_RUBRIC names another.
92
+ `,
93
+ bools: ['json'],
94
+ values: ['rubric', 'stack', 'format'],
95
+ positionals: 1,
96
+ },
97
+ init: {
98
+ usage: 'vdx init [project_path] [--stack <id>] [--baseline <ref>] [--dry-run] [--force]',
99
+ help: `Writes mise.toml for the project (default: cwd): the lifecycle verbs mapped to
100
+ the project's own scripts. --dry-run prints it and writes nothing; an existing
101
+ mise.toml is overwritten only with --force.
102
+ `,
103
+ bools: ['dry-run', 'force'],
104
+ values: ['stack', 'baseline'],
105
+ positionals: 1,
106
+ },
107
+ publish: {
108
+ usage: 'vdx publish <patch|minor|major> [--dry-run] [--force]',
109
+ help: `Releases the library in the current directory: pre-flight checks, version bump,
110
+ npm publish (npm asks for an OTP), git commit and tag. Does not push.
111
+ --dry-run runs the pre-flight and prints the plan; --force goes on past a failed pre-flight.
112
+ `,
113
+ bools: ['dry-run', 'force'],
114
+ positionals: 1,
115
+ },
116
+ doctor: {
117
+ usage: 'vdx doctor [--format=ansi|markdown|json] [--json]',
118
+ help: `Checks this machine for what vdx needs (Node, git, mise, npm auth, docker, the
119
+ Claude Code plugin) and, inside a project, its commit author. Reads only.
120
+ Exit 2 when something is missing.
121
+ `,
122
+ bools: ['json'],
123
+ values: ['format'],
124
+ positionals: 0,
125
+ },
126
+ ai: {
127
+ usage: 'vdx ai[@host] [project_path] [--new] [--restart] [--detach] [--dry-run]',
128
+ help: AI_HELP,
129
+ // `--resume` asked to continue in 0.12; continuing is the default now.
130
+ bools: ['new', 'restart', 'resume', 'detach', 'dry-run'],
131
+ positionals: 1,
132
+ },
133
+ ...Object.fromEntries(
134
+ LIFECYCLE_VERBS.map((verb) => [
135
+ verb,
136
+ {
137
+ usage: `vdx ${verb}`,
138
+ help: `Runs \`mise run ${verb}\` in the current directory — the project's own ${verb}
139
+ command, as mise.toml maps it. Takes no arguments.
140
+ `,
141
+ positionals: 0,
142
+ },
143
+ ]),
144
+ ),
145
+ };
84
146
 
85
147
  interface ParsedArgs {
86
148
  cmd: string;
@@ -116,6 +178,48 @@ function parseArgs(argv: string[]): ParsedArgs {
116
178
  return { cmd, positionals, flags };
117
179
  }
118
180
 
181
+ /**
182
+ * Keeps what the command reads and refuses the rest, before anything runs: a
183
+ * misread argument must not run the command. `vdx ai --help` started an agent,
184
+ * `vdx init --help` wrote mise.toml, `vdx down --help` ran `mise run down`.
185
+ */
186
+ function checkArgs(name: string, opts: ParsedArgs): ParsedArgs {
187
+ const spec = COMMANDS[name]!;
188
+ const bools = [...(spec.bools ?? []), 'help'];
189
+ const values = spec.values ?? [];
190
+ // parseArgs hands the token after a bare flag to that flag as its value; a
191
+ // flag that takes none gives it back — it is the path (or `-h`).
192
+ const positionals = [...opts.positionals];
193
+ const flags: Record<string, string | boolean> = {};
194
+ for (const [flag, value] of Object.entries(opts.flags)) {
195
+ if (bools.includes(flag) && typeof value === 'string') {
196
+ positionals.push(value);
197
+ flags[flag] = true;
198
+ } else {
199
+ flags[flag] = value;
200
+ }
201
+ }
202
+ if (flags.help || positionals.includes('-h')) {
203
+ process.stdout.write(`Usage: ${spec.usage}\n\n${spec.help}`);
204
+ process.exit(0);
205
+ }
206
+ const fail = (message: string): never => {
207
+ process.stderr.write(`vdx ${name}: ${message}\nUsage: ${spec.usage}\nMore: vdx ${name} --help\n`);
208
+ process.exit(2);
209
+ };
210
+ const unknown = [
211
+ ...Object.keys(flags).filter((f) => !bools.includes(f) && !values.includes(f)).map((f) => `--${f}`),
212
+ ...positionals.filter((p) => p.startsWith('-')),
213
+ ];
214
+ if (unknown.length > 0) fail(`unknown option ${unknown.join(', ')}`);
215
+ const bare = values.filter((f) => flags[f] === true).map((f) => `--${f}`);
216
+ if (bare.length > 0) fail(`${bare.join(', ')} needs a value`);
217
+ if (positionals.length > spec.positionals) {
218
+ fail(`unexpected argument ${positionals.slice(spec.positionals).join(' ')}`);
219
+ }
220
+ return { cmd: opts.cmd, positionals, flags };
221
+ }
222
+
119
223
  function cmdAudit(opts: ParsedArgs): void {
120
224
  const projectArg = opts.positionals[0] ?? '.';
121
225
  const projectRoot = path.resolve(projectArg);
@@ -297,34 +401,13 @@ function cmdDoctor(opts: ParsedArgs): void {
297
401
  }
298
402
 
299
403
  function cmdAi(opts: ParsedArgs): void {
300
- // parseArgs hands the token after a bare flag to that flag as its value;
301
- // these flags take none, so such a token is the project path (or `-h`).
302
- const positionals = [...opts.positionals];
303
- const bool = (name: string): boolean => {
304
- const v = opts.flags[name];
305
- if (typeof v === 'string') positionals.push(v);
306
- return v !== undefined;
404
+ const options = {
405
+ path: opts.positionals[0] ?? '.',
406
+ restart: opts.flags.restart === true,
407
+ fresh: opts.flags.new === true,
408
+ detach: opts.flags.detach === true,
409
+ dryRun: opts.flags['dry-run'] === true,
307
410
  };
308
- const restart = bool('restart');
309
- const fresh = bool('new');
310
- // `--resume` asked to continue in 0.12; continuing is the default now.
311
- // Still read, so the path after it is not taken for its value.
312
- bool('resume');
313
- const detach = bool('detach');
314
- const dryRun = bool('dry-run');
315
- // `vdx ai` starts an agent, so a misread argument must not run it: an agent
316
- // that tried `vdx ai --help` got a launch in the current directory.
317
- if (bool('help') || positionals.includes('-h')) {
318
- process.stdout.write(AI_HELP);
319
- process.exit(0);
320
- }
321
- const unknown = [
322
- ...Object.keys(opts.flags).filter((f) => !AI_FLAGS.includes(f)).map((f) => `--${f}`),
323
- ...positionals.filter((p) => p.startsWith('-')),
324
- ];
325
- if (unknown.length > 0) aiUsageError(`unknown option ${unknown.join(', ')}`);
326
- if (positionals.length > 1) aiUsageError(`unexpected argument ${positionals.slice(1).join(' ')}`);
327
- const options = { path: positionals[0] ?? '.', restart, fresh, detach, dryRun };
328
411
  // `ai@m3`: the same command on another machine. Its own label runs here.
329
412
  const host = opts.cmd.startsWith('ai@') ? opts.cmd.slice(3) : null;
330
413
  if (host !== null) {
@@ -341,11 +424,16 @@ function cmdAi(opts: ParsedArgs): void {
341
424
 
342
425
  const parsed = parseArgs(process.argv);
343
426
  if (parsed.cmd === '--version') process.stdout.write(readCliVersion() + '\n');
344
- else if (parsed.cmd === 'audit') cmdAudit(parsed);
345
- else if (parsed.cmd === 'init') cmdInit(parsed);
346
- else if (parsed.cmd === 'publish') cmdPublish(parsed);
347
- else if (parsed.cmd === 'doctor') cmdDoctor(parsed);
348
- else if (parsed.cmd === 'ai' || parsed.cmd.startsWith('ai@')) cmdAi(parsed);
349
- else if ((LIFECYCLE_VERBS as readonly string[]).includes(parsed.cmd))
427
+ else if (['--help', '-h', 'help'].includes(parsed.cmd)) process.stdout.write(USAGE);
428
+ else if (parsed.cmd === 'audit') cmdAudit(checkArgs('audit', parsed));
429
+ else if (parsed.cmd === 'init') cmdInit(checkArgs('init', parsed));
430
+ else if (parsed.cmd === 'publish') cmdPublish(checkArgs('publish', parsed));
431
+ else if (parsed.cmd === 'doctor') cmdDoctor(checkArgs('doctor', parsed));
432
+ else if (parsed.cmd === 'ai' || parsed.cmd.startsWith('ai@')) cmdAi(checkArgs('ai', parsed));
433
+ else if ((LIFECYCLE_VERBS as readonly string[]).includes(parsed.cmd)) {
434
+ checkArgs(parsed.cmd, parsed);
350
435
  cmdRun(parsed.cmd as LifecycleVerb);
351
- else usage();
436
+ } else {
437
+ if (parsed.cmd !== '') process.stderr.write(`vdx: unknown command "${parsed.cmd}"\n`);
438
+ usage();
439
+ }