Skip to content

Schemas for the CLI's JSON output - #395

Open
agorischek wants to merge 8 commits into
mainfrom
schemas/cli-json-output
Open

agorischek wants to merge 8 commits into
mainfrom
schemas/cli-json-output

Conversation

@agorischek

@agorischek agorischek commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator

What changed

Finding 2 of the December code quality review: every document the CLI prints with --json, or writes with --output, now has a published JSON Schema, and a CLI test validates the real output against it, so a document's shape can't change unless its schema changes with it.

Schemas. The TypeBox sources are in packages/schemas/src/typebox/cli.ts (with cli-common.ts, cli-explore.ts, cli-environment.ts and cli-viewer.ts), beside the existing ones. They're generated as draft 2020-12 under the existing host (https://schemas.projections.githubnext.com/cli/<name>/v0.json), using the cli/ prefix the way vocabularies/ is used, so names like list, error and check don't collide with future schemas. Reference pages are in docs/reference/schemas/cli-*.md. Objects are closed (additionalProperties: false), as the existing schemas are.

Command Document (format, version 0) Schema
explore --list --json projections.explore cli/explore/v0.json
explore --sweep --json projections.sweep cli/sweep/v0.json
adopt --json projections.adopt (new: format/version added) cli/adopt/v0.json
check --json projections.check cli/check/v0.json
doctor --json projections.doctor cli/doctor/v0.json
prepare --json projections.prepare cli/prepare/v0.json
workspace list --json projections.workspaces cli/workspaces/v0.json
workspace clean --json projections.workspace-clean (new: format/version added) cli/workspace-clean/v0.json
list --json projections.list cli/list/v0.json
show --all, compare --all, bookmark run (--json/--output) projections.batch cli/batch/v0.json
pr --json projections.pull-request cli/pull-request/v0.json
extractor list --json projections.extractors (new: format/version added) cli/extractors/v0.json
extractor view --json projections.extractor (new: format/version added) cli/extractor/v0.json
validate --json (none, see below) cli/validation/v0.json
view show, view current, view refresh (--json) projections.view (new: format/version added) cli/view/v0.json
view screenshot --json projections.screenshot (new: format/version added) cli/screenshot/v0.json
any command's failure with --json/--output projections.error cli/error/v0.json
show --json, compare --json, bookmark list --json unchanged existing extraction-document, comparison-document, bookmarks

The only behaviour change is additive. Six outputs that had no kind now carry format and version (marked "new" above). They're added only where the CLI prints the document, so MCP and serve --stdio structured results and the runner API are unchanged.

Tests. packages/cli/test/json-output.test.mjs runs the built CLI on a fixture repository through every command above, including failure, invalid-definition, unknown-ID (explore --sweep -p bad/id, bookmark run bad/id), custom-comparator tests (check --update --coverage, and a comparator without tests), --dry-run, revision and --page variants. Screenshots must succeed wherever a browser can run; they may fail only when none can (none installed, or Chrome as root). It validates each printed document with Ajv against the published schemas. A final test fails if any cli/* schema was never checked. It already caught one undocumented field (list's defaults), now in the schema.

Types. These are the repository's existing generation: the TypeBox Static types, exported from @githubnext/projections-schemas (and so from @githubnext/projections-sdk/schemas) as CliSweep, CliBatch, CliCheck, SweepCell and others.

Consumer switched. The GitHub Action's splitBatch (packages/integrations/github-action/src/lib.mjs) used to hand-check the batch document. It now decodes it at the boundary with decodeBatch, which returns the generated CliBatch type, and each result is still checked as it's split. The Action's scripts stay dependency-free at run time because the types are a JSDoc type import, erased at run time. lib.mjs is now type-checked (tsconfig.json with checkJs, and a typecheck script). That needed JSDoc on two existing helpers whose option defaults TypeScript couldn't infer.

Extension points for the in-flight work (#380, #383, #389, #399, which extend these schemas after this merges). Each shape another change will grow is its own $defs entry:

  • NDJSON sweep lines (sweep/ndjson-stream): a line per candidate is cli/sweep#/$defs/projection (the ranked row with its tally); $defs/cell and $defs/change are reusable too. A line schema can $ref them.
  • A "timed out" candidate status (sweep/timeout-skip): add the value to cli/sweep#/$defs/cellStatus (and $defs/projectionStatus if a whole projection can time out).
  • Adopt's "reused" notes (adopt/reuse-sweep): cli/adopt#/$defs/note (a string today).
  • Bot-update counts in the sweep summary (sweep/bot-and-version-only-ranking): the tally lives on cli/sweep#/$defs/projection (changed, versionOnly, failed), and sweep-wide notes on cli/sweep#/$defs/note.

Inconsistencies found (recorded, not changed)

  • The kind field is format, not kind, in every document; kept.
  • validate --json has no kind or version. Its format names the validated document (projections.extraction, …, or extraction), so a kind can't be added there without a breaking change.
  • Viewer failures. A refused view command prints {"error": "…"} (no format) and exits 1. view commands aren't in the CLI's wants_json list, so a failure before the viewer answers, such as view screenshot --page without a browser, prints nothing to stdout, unlike every other command, which prints projections.error.
  • Viewer documents pass state through unshaped. viewer, url, viewers, seen, page, selection, failures, mode, scenario, choice, chosenBy and some screenshot fields are copied from viewer state. The schema documents them but allows any JSON value.
  • Two diagnostic shapes. Engine and runner diagnostics are {severity, code, path, message, entityId?}, while invalid-definition diagnostics (in list and check) are {code, severity, message, path, location, pointer?}.
  • An invalid definition's id is null when unreadable in list, but "" in check.
  • versionOnly has two types: true on a sweep cell, a count on a sweep projection row.
  • Prepare state names differ: prepare steps use status (current, succeeded), and doctor's environment report uses state (current, stale, failed, never) with last.status.
  • Doctor's environment.workspace is either {strategy, source, reason} or {error}, while list failures elsewhere use a sibling …Error field (workspacesError).
  • list --json was under-documented: docs/runner/batches.md omitted invalid and defaults. Fixed in the docs.
  • The runner API's internal schemas (src/runner/api.ts) model the same sweep, explore and adopt shapes separately and less completely (no candidate needs, basis named/crates, or adopt notes; the change kind adds pair). They're left as they are; unifying them would mean teaching the Rust conformance checker $ref and the string keywords.

Evidence

  • node --test packages/cli/test/json-output.test.mjs with the CLI built by npm run tools -- build packages/cli: passed (6/6), after the review fixes too.

  • node tools/scripts/considered.mjs check: no violations, after splitting the TypeBox sources. Run locally as root: Chrome refuses to start, so view screenshot printed its refusal. That refusal is validated, but the success shapes of cli/screenshot are validated only where a browser runs, as in CI.

  • npm test --workspace @githubnext/projections-schemas (generate --check and the schema tests, including strict compilation of every schema): passed (24/24).

  • node --test packages/cli/test/cli.test.mjs packages/cli/test/canvas-extension.test.mjs packages/cli/test/mcp.test.mjs: 10 passed. 1 failed for the environment only: the MCP screenshot needs Chrome, which won't run as root.

  • npm run typecheck --workspace @githubnext/projections-action: passed. node --test packages/integrations/github-action/test/*.test.mjs: 15 passed. 1 failed for the environment only (the snapshot test needs Chrome, which won't run as root); it fails the same way without this change.

  • npm run tools -- check --fast: cargo check, cargo fmt, format, lint, versions and the repository rules pass.

  • npm run format:check: passed.

  • node tools/scripts/reference-docs.mjs --only agents,cli,action,schemas,tokens,renderers,extractors,renderer-sdk,builtins,tsdoc: generated and committed. rust-sdk was skipped because it needs the pinned nightly, and this change doesn't touch it.

  • Not run locally: the Rust test suites (cargo test -p projections-cli). The machine was below the disk floor for a debug build. The Rust changes are the additive format/version fields above, and the JSON test exercises them through the built binary.

  • Documentation that this change affects is updated, and generated reference
    pages are regenerated (npm run docs:generate).

  • Fixes include a regression test.

  • A changelog fragment at changelog.d/<this PR's number>.md describes what
    users will notice, or the PR has the no changelog label (see
    changelog.d/README.md).

  • No credentials, private source or machine-specific paths are included.

agorischek and others added 4 commits December 4, 2026 20:58
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The schemas reject existing custom-comparator, sweep-error, bookmark-error, and screenshot outputs, while screenshot tests can pass without validating successful captures.

5 open issues
What changed in this PR

Publishes CLI JSON output contracts through the existing schema package, with generated types, reference documentation, and conformance tests.

Changes:

  • Adds 17 CLI schemas and validates real command output against them.
  • Adds format and version fields to previously untagged outputs.
  • Uses generated batch types in the GitHub Action and enables JavaScript type-checking.
File Description
packages/​schemas/​test/​schemas.test.mjs Registers CLI schemas for validation.
packages/​schemas/​src/​typebox/​index.ts Registers and exports CLI schemas.
packages/​schemas/​src/​typebox/​cli.ts Defines CLI output contracts and types.
packages/​schemas/​src/​index.ts Exports CLI types publicly.
packages/​schemas/​schemas/​cli/​workspaces/​v0.json Workspace-list schema.
packages/​schemas/​schemas/​cli/​workspace-clean/​v0.json Workspace-clean schema.
packages/​schemas/​schemas/​cli/​view/​v0.json Viewer-state schema.
packages/​schemas/​schemas/​cli/​validation/​v0.json Validation-result schema.
packages/​schemas/​schemas/​cli/​sweep/​v0.json Sweep-result schema.
packages/​schemas/​schemas/​cli/​screenshot/​v0.json Screenshot-result schema.
packages/​schemas/​schemas/​cli/​pull-request/​v0.json Pull-request report schema.
packages/​schemas/​schemas/​cli/​prepare/​v0.json Environment-preparation schema.
packages/​schemas/​schemas/​cli/​list/​v0.json Projection-list schema.
packages/​schemas/​schemas/​cli/​extractors/​v0.json Extractor-catalog schema.
packages/​schemas/​schemas/​cli/​extractor/​v0.json Extractor-detail schema.
packages/​schemas/​schemas/​cli/​explore/​v0.json Exploration-candidate schema.
packages/​schemas/​schemas/​cli/​error/​v0.json CLI error schema.
packages/​schemas/​schemas/​cli/​doctor/​v0.json Diagnostic-report schema.
packages/​schemas/​schemas/​cli/​check/​v0.json Projection-check schema.
packages/​schemas/​schemas/​cli/​batch/​v0.json Batch-result schema.
packages/​schemas/​schemas/​cli/​adopt/​v0.json Adoption-result schema.
packages/​integrations/​github-action/​tsconfig.json Enables JavaScript type-checking.
packages/​integrations/​github-action/​src/​lib.mjs Adds typed batch decoding and annotations.
packages/​integrations/​github-action/​package.json Adds the typecheck script.
packages/​cli/​test/​json-output.test.mjs Tests output against published schemas.
packages/​cli/​src/​commands/​view.rs Tags viewer and screenshot output.
packages/​cli/​src/​commands/​view_page.rs Tags page-screenshot output.
packages/​cli/​src/​commands/​explore.rs Tags adoption output.
packages/​cli/​src/​commands/​environment.rs Tags workspace-clean output.
packages/​cli/​src/​commands/​authoring.rs Tags extractor output.
packages/​cli/​package.json Adds Ajv for conformance tests.
package-lock.json Records the test dependency.
docs/​runner/​commands.md Documents JSON contracts and exceptions.
docs/​runner/​batches.md Documents list diagnostics and defaults.
docs/​reference/​schemas/​README.md Indexes the CLI schemas.
docs/​reference/​schemas/​cli-workspaces.md Workspace-list reference.
docs/​reference/​schemas/​cli-workspace-clean.md Workspace-clean reference.
docs/​reference/​schemas/​cli-view.md Viewer-state reference.
docs/​reference/​schemas/​cli-validation.md Validation-result reference.
docs/​reference/​schemas/​cli-sweep.md Sweep-result reference.
docs/​reference/​schemas/​cli-screenshot.md Screenshot-result reference.
docs/​reference/​schemas/​cli-pull-request.md Pull-request report reference.
docs/​reference/​schemas/​cli-prepare.md Preparation-result reference.
docs/​reference/​schemas/​cli-list.md Projection-list reference.
docs/​reference/​schemas/​cli-extractors.md Extractor-catalog reference.
docs/​reference/​schemas/​cli-extractor.md Extractor-detail reference.
docs/​reference/​schemas/​cli-explore.md Exploration-candidate reference.
docs/​reference/​schemas/​cli-error.md CLI error reference.
docs/​reference/​schemas/​cli-doctor.md Diagnostic-report reference.
docs/​reference/​schemas/​cli-check.md Projection-check reference.
docs/​reference/​schemas/​cli-batch.md Batch-result reference.
docs/​reference/​schemas/​cli-adopt.md Adoption-result reference.
docs/​contracts.md Documents CLI contract conformance testing.
changelog.d/​395.md Announces schemas, types, and output tags.

Review effort: Balanced

Comment thread packages/cli/test/json-output.test.mjs Resolved
Comment thread packages/schemas/src/typebox/cli.ts Resolved
Comment thread packages/schemas/src/typebox/cli.ts Resolved
Comment thread packages/schemas/src/typebox/cli.ts Resolved
Comment thread packages/schemas/src/typebox/cli.ts Resolved
agorischek and others added 2 commits December 4, 2026 22:54
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Splits the TypeBox sources into four files under the size limit, names the
alternatives of every union so the reference documents them, and makes the
screenshot conformance test require both captures where a browser can run.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
agorischek and others added 2 commits December 5, 2026 04:14
Windows reports a missing browser as "No Chrome, Chromium or Microsoft Edge",
which the test's own pattern missed; the doctor's Browser item uses the same
discovery as the screenshot.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Adopt's new `skipped` and a sweep cell's `items` (#390) are declared in the
CLI schemas, and the changelog names the renamed SDK package (#394).

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants