feat(cli): superset schema, completion and config check

Merged
AV
2mo ago
+2171-27

Lands the three self-describing/DX commands from #7103 as their own PR, rebuilt on today's main. The terminal primitives (wait, wait-output, send-keys) are a sibling PR; attach, resume-all and explain stay on #7103.

What is here

  • superset completion <bash|zsh> prints a completion script generated from the command tree: command names at every level (an alias already typed is walked through), each command's flags and aliases, enum values for flags (--flag=value too) and positionals, and the globals. The script is printed byte for byte in every output mode (agent auto-JSON, --json, --quiet).
  • superset schema prints the whole command tree as JSON, sorted and with absent fields omitted, so two versions diff cleanly. Internal-only and sandbox-hidden commands are left out, exactly as --help leaves them out.
  • superset config check validates config.json: JSON syntax, the shape of auth, apiKey and organizationId, token expiry, and keys this version does not read. Exits 1 on an error, 0 on warnings or when there is no file.
  • Docs: three sections in the CLI reference, and a "Shell & tooling" section in superset --help.

Changed from #7103

  • introspectCli() is built from the audience- and sandbox-filtered tree the runner already routed on, so it cannot list a command the run cannot execute (CodeRabbit), and the slot is cleared when run() returns (CodeRabbit). It returns CliDescription ({ name, version, root }) and both generators take that directly.
  • The framework gains { raw: string } command results: printed verbatim under --json, --quiet and agent mode, with no trailing newline added. completion returns one instead of writing to process.stdout itself, and --json no longer wraps the script in { shell, script }.
  • The runner enforces .enum() on positional arguments (superset completion fish → Valid values: bash, zsh). That replaces the command-level lookup CodeRabbit flagged for prototype-chain keys. No existing command declares an enum positional.
  • config-check keys are a { [K in keyof SupersetConfig]-?: check } record: a field added to SupersetConfig does not compile until it has a check, and a check for a removed field is an excess key. Reading moved into checkConfigFile, which reports an unreadable file as an error instead of throwing (CodeRabbit). The expired-token warning says whether the next command will refresh. config check sets exit code 1 when the file is invalid.
  • Schema: adds version, int/min/max, a separate SchemaArg shape, options sorted by name with a locale-independent comparator; enumVals→enum, envVar→env, isVariadic→variadic.
  • Completion: the word walk is one generator shared by the bash and zsh scripts; visibleChildren is shared with help.ts.
  • The runner exits quietly on EPIPE. superset schema | head printed Error: EPIPE: broken pipe, write; this was true of every command and is only more visible with document-sized output.
  • packages/cli-framework gets a test script. It had none, so turbo and CI never ran its tests (the existing router, output, runner and interactive-help tests included).
  • Tests: the bash script runs in a real bash with COMPREPLY assertions; the zsh script is parse-checked with zsh -n; introspectCli is exercised through run(); checkConfigFile is tested against a missing file and a directory.
  • Not carried over: the herdr submodule pointer, the two HTML reports, and the orchestrate SKILL.md changes.

Verified

Each shell was driven by expect in a scratch session with this worktree's build first on PATH. In every one, superset term<TAB> completed to superset terminals , superset terminals read --<TAB> listed --workspace through --json, superset ws cr<TAB> completed to superset ws create , and superset completion <TAB> offered bash zsh.

ShellLoaded with
zsh 5.9source <(superset completion zsh)
zsh 5.9_superset on fpath, autoloaded by compinit
bash 5.3source <(superset completion bash)
bash 3.2 (macOS /bin/bash)eval "$(superset completion bash)"

bash 3.2 cannot source a process substitution at all (it reads zero bytes, even for source <(echo …)), so the docs give the eval form for bash.

  • superset schema --json is byte-identical across runs; SUPERSET_CLI_AUDIENCE=internal adds exactly the internal groups.
  • superset config check against a valid, invalid, expired, missing and unreadable (directory) file: exit codes 0, 1, 0, 0, 1, with the human and --json output.
  • superset completion zsh under CLAUDE_CODE=1, --json and --quiet is the same script; superset schema prints JSON in every mode.
  • /ci-check: lint:fix (no warnings), sherif, typecheck and check:i18n are clean. bun run test passes 22 of 25 turbo tasks from this worktree; the three that fail touch no file on this branch: trpc (7 deriveSandboxCredentials tests, a JWT signing error from an empty secret in the local env), host-service (5 here, 8 on a pristine origin/main checkout in the same session), desktop (34 git-helper tests that follow the directory, not the code: the same HEAD checked out at another path passes 7758 with the one known env-sensitive failure, as does origin/main).
  • Each of the five commits typechecks and passes the framework tests on its own.
  • Screenshots of every session, plus the schema and config check output: https://app.superset.sh/page/superset-schema-completion-and-config-check-1f42qt

Review follow-ups

  • CodeRabbit: the generated zsh function declared local path, which zsh ties to PATH, so it ran with an empty PATH. Renamed to cmdpath in both shells; a test asserts no path local is ever generated.
  • Greptile: an expired token with no refresh token was reported as logged in. config check now reports loggedIn: false with a warning naming the coming "Session expired", and uses the same five-minute leeway as resolveAuth (one constant in config.ts, read by both).
  • Greptile: --priority=ur<Tab> completes to --priority=urgent in both shells, including bash's split of the word at =.
  • Greptile: enum values are validated for variadic positionals too.
  • Greptile: a raw result is one that carries only raw; { raw, data } is data again, and the type forbids the combination.
  • Greptile, alias completion: kept as is. Candidates are canonical names on purpose (ws, t, term, auto, org beside their full names would be noise); an alias already typed is walked through. The sentence in the docs that promised more was reworded.

After these: the four shell sessions were re-run on the rebuilt binary (every check passes), plus --priority=u<Tab> in zsh and bash and a check that zsh's PATH is intact after completing.

Second round (cubic and CodeRabbit on the first follow-ups)

  • Completion: the walk honours -- (everything after is positional, dispatch offers only the positional enum or files), skips a boolean's explicit true/false, and skips both words of readline's split --flag = value; a free-form value attached with = falls back to filename completion in both shells.
  • Runner: empty output prints nothing again (the raw-result change had made it print a bare newline).
  • Schema: conflicts lists an option's conflictsWith as flag names.
  • Config check: whitespace-only credentials are errors (as resolveAuth treats them), expiresAt must be finite (1e400 parses to Infinity), and unknown keys inside auth get the same warning as top-level ones, with the key set tied to the type.
  • Tests: the completion fixture's enum values no longer appear in the scripts' boilerplate; the introspection teardown test runs the CLI itself; the path guard matches any local naming path.
  • Declined, with replies on the threads: --no-<flag> candidates (not advertised by --help either) and alias candidates (canonical names on purpose).

Every shell check was re-run on the rebuilt binary after this round, plus new live checks for --, boolean values and --workspace=<Tab> filenames in zsh and bash.

Third round

  • A boolean given as --json=false lost the command context in bash, which splits it into --json, =, false: the walk now skips both split words, and --json=<Tab> offers false/true. Driving the real binary in bash 3.2 showed it hands over the unsplit word while readline still replaces only the text after =, so the --flag= prefix is added only when = is not in COMP_WORDBREAKS. The bash tests cover both modes in a temp fixture directory (cubic's cwd finding).
  • Verified live in zsh 5.9, bash 5.3 and bash 3.2: superset --json=false completion <Tab> and superset completion --json=false <Tab> list bash zsh, superset --json=<Tab> lists false true, and every earlier shell check still passes.
  • bash 3.2 offered no filenames for a free-form value after a space, because the fallback relied on compopt -o default, which that bash lacks. Without compopt the script now registers with complete -o default, so readline completes filenames itself whenever the function offers nothing. Driven live in bash 3.2 and 5.3: --workspace <Tab> lists files and directories, a directory completes with a trailing slash, my file.json comes back quoted, and command completion still ends with a space.

Summary by CodeRabbit

  • New Features
    • Added Bash and Zsh shell completion scripts for CLI commands, options, and values.
    • Added superset schema to output sorted JSON metadata about visible CLI commands and options.
    • Added superset config check to validate local configuration and report errors and warnings.
  • Bug Fixes
    • Positional arguments with configured choices are now validated.
    • Raw command output no longer receives an extra newline, and broken-pipe errors are ignored.