From 3c1e77afed29944c1d59987b9f1424f72108e433 Mon Sep 17 00:00:00 2001 From: agorischek <6295280+agorischek@users.noreply.github.com> Date: Fri, 4 Dec 2026 20:58:36 +0000 Subject: [PATCH 1/6] Schemas for the CLI's JSON output (WIP) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> --- packages/cli/src/commands/authoring.rs | 10 +- packages/cli/src/commands/environment.rs | 6 +- packages/cli/src/commands/explore.rs | 7 +- packages/cli/src/commands/view.rs | 11 +- packages/cli/src/commands/view_page.rs | 2 +- packages/schemas/schemas/cli/adopt/v0.json | 57 ++ packages/schemas/schemas/cli/batch/v0.json | 64 ++ packages/schemas/schemas/cli/check/v0.json | 86 ++ packages/schemas/schemas/cli/doctor/v0.json | 112 +++ packages/schemas/schemas/cli/error/v0.json | 45 + packages/schemas/schemas/cli/explore/v0.json | 75 ++ .../schemas/schemas/cli/extractor/v0.json | 52 ++ .../schemas/schemas/cli/extractors/v0.json | 48 ++ packages/schemas/schemas/cli/list/v0.json | 74 ++ packages/schemas/schemas/cli/prepare/v0.json | 48 ++ .../schemas/schemas/cli/pull-request/v0.json | 49 ++ .../schemas/schemas/cli/screenshot/v0.json | 68 ++ packages/schemas/schemas/cli/sweep/v0.json | 98 +++ .../schemas/schemas/cli/validation/v0.json | 27 + packages/schemas/schemas/cli/view/v0.json | 145 ++++ .../schemas/cli/workspace-clean/v0.json | 18 + .../schemas/schemas/cli/workspaces/v0.json | 44 + packages/schemas/src/typebox/cli.ts | 771 ++++++++++++++++++ packages/schemas/src/typebox/index.ts | 3 + packages/schemas/test/schemas.test.mjs | 17 + 25 files changed, 1929 insertions(+), 8 deletions(-) create mode 100644 packages/schemas/schemas/cli/adopt/v0.json create mode 100644 packages/schemas/schemas/cli/batch/v0.json create mode 100644 packages/schemas/schemas/cli/check/v0.json create mode 100644 packages/schemas/schemas/cli/doctor/v0.json create mode 100644 packages/schemas/schemas/cli/error/v0.json create mode 100644 packages/schemas/schemas/cli/explore/v0.json create mode 100644 packages/schemas/schemas/cli/extractor/v0.json create mode 100644 packages/schemas/schemas/cli/extractors/v0.json create mode 100644 packages/schemas/schemas/cli/list/v0.json create mode 100644 packages/schemas/schemas/cli/prepare/v0.json create mode 100644 packages/schemas/schemas/cli/pull-request/v0.json create mode 100644 packages/schemas/schemas/cli/screenshot/v0.json create mode 100644 packages/schemas/schemas/cli/sweep/v0.json create mode 100644 packages/schemas/schemas/cli/validation/v0.json create mode 100644 packages/schemas/schemas/cli/view/v0.json create mode 100644 packages/schemas/schemas/cli/workspace-clean/v0.json create mode 100644 packages/schemas/schemas/cli/workspaces/v0.json create mode 100644 packages/schemas/src/typebox/cli.ts diff --git a/packages/cli/src/commands/authoring.rs b/packages/cli/src/commands/authoring.rs index cd1d8e3ff..350ef796b 100644 --- a/packages/cli/src/commands/authoring.rs +++ b/packages/cli/src/commands/authoring.rs @@ -353,7 +353,11 @@ pub fn extractor(command: Extractor) -> Result<()> { match command { Extractor::List { json } => { if json { - return output(&catalog, None, 32 * 1024 * 1024); + return output( + &json!({"format": "projections.extractors", "version": 0, "extractors": extractors}), + None, + 32 * 1024 * 1024, + ); } let width = extractors .iter() @@ -384,7 +388,9 @@ pub fn extractor(command: Extractor) -> Result<()> { .find(|descriptor| descriptor["id"] == id.as_str()) .with_context(|| format!("No built-in extractor {id}; projections extractor list shows them"))?; if json { - return output(descriptor, None, 1024 * 1024); + let mut document = json!({"format": "projections.extractor", "version": 0}); + document.as_object_mut().unwrap().extend(descriptor.as_object().cloned().unwrap_or_default()); + return output(&document, None, 1024 * 1024); } let mut text = format!( "{} [{id}]\n{}\n\nSchema: {}\nRenderer: {}\nRuns repository code: {}\nNeeds: {}\n", diff --git a/packages/cli/src/commands/environment.rs b/packages/cli/src/commands/environment.rs index 7b7443cb1..9ac259c15 100644 --- a/packages/cli/src/commands/environment.rs +++ b/packages/cli/src/commands/environment.rs @@ -171,7 +171,11 @@ pub fn workspace(directory: &Path, command: Workspace) -> Result<()> { Workspace::Clean { json } => { let removed = crate::workspaces::clean(&runner)?; if json { - return output(&json!({"removed": removed}), None, 1024 * 1024); + return output( + &json!({"format": "projections.workspace-clean", "version": 0, "removed": removed}), + None, + 1024 * 1024, + ); } println!( "Removed {} workspace{}{}", diff --git a/packages/cli/src/commands/explore.rs b/packages/cli/src/commands/explore.rs index 98dff31d4..cb72b12e4 100644 --- a/packages/cli/src/commands/explore.rs +++ b/packages/cli/src/commands/explore.rs @@ -184,9 +184,10 @@ pub fn adopt(directory: &Path, args: Adopt) -> Result<()> { } let result = onboard::adopt(&root, &candidates, &args.projections, &highlights, None, args.dry_run)?; if args.json { - let mut result = result; - result["notes"] = json!(notes); - return output(&result, None, 32 * 1024 * 1024); + let mut document = json!({"format": "projections.adopt", "version": 0}); + document.as_object_mut().unwrap().extend(result.as_object().cloned().unwrap_or_default()); + document["notes"] = json!(notes); + return output(&document, None, 32 * 1024 * 1024); } let mut text = onboard::text(&result, args.dry_run); for note in notes { diff --git a/packages/cli/src/commands/view.rs b/packages/cli/src/commands/view.rs index e4a877e84..c2ef501d6 100644 --- a/packages/cli/src/commands/view.rs +++ b/packages/cli/src/commands/view.rs @@ -391,7 +391,16 @@ async fn view_tool(root: &Path, command: ViewCommand) -> Result<()> { eprintln!("Wrote {}", out.display()); } if json_output { - println!("{}", serde_json::to_string(&outcome.structured)?); + // A result is a projections.view or projections.screenshot document; a refusal stays `{"error": …}`. + let structured = if outcome.error { + outcome.structured.clone() + } else { + let format = if name == "screenshot" { "projections.screenshot" } else { "projections.view" }; + let mut document = json!({"format": format, "version": 0}); + document.as_object_mut().unwrap().extend(outcome.structured.as_object().cloned().unwrap_or_default()); + document + }; + println!("{}", serde_json::to_string(&structured)?); } else { print!("{}", outcome.text); } diff --git a/packages/cli/src/commands/view_page.rs b/packages/cli/src/commands/view_page.rs index cacd9a899..a2c266e30 100644 --- a/packages/cli/src/commands/view_page.rs +++ b/packages/cli/src/commands/view_page.rs @@ -62,7 +62,7 @@ pub async fn screenshot( eprintln!("Wrote {}", out.display()); let projection = defaults["projection"].as_str().unwrap_or_default(); if json_output { - let result = json!({"page": true, "viewer": name, "projection": projection, "theme": theme.name(), + let result = json!({"format": "projections.screenshot", "version": 0, "page": true, "viewer": name, "projection": projection, "theme": theme.name(), "width": width, "height": height, "notices": shot.notices, "bytes": shot.png.len()}); println!("{result}"); } else { diff --git a/packages/schemas/schemas/cli/adopt/v0.json b/packages/schemas/schemas/cli/adopt/v0.json new file mode 100644 index 000000000..5f77ad0a9 --- /dev/null +++ b/packages/schemas/schemas/cli/adopt/v0.json @@ -0,0 +1,57 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://schemas.projections.githubnext.com/cli/adopt/v0.json", + "title": "CLI adopt", + "description": "The definitions and bookmarks adopting projections writes (`projections adopt --json`).", + "type": "object", + "additionalProperties": false, + "required": ["format", "version", "files", "digest", "written", "adopted", "bookmarked", "notes"], + "properties": { + "format": {"type": "string", "const": "projections.adopt"}, + "version": {"type": "number", "const": 0}, + "files": { + "description": "The definitions and the bookmarks file it writes, or would write.", + "type": "array", + "items": { + "type": "object", + "additionalProperties": false, + "required": ["path", "before", "after", "created", "changed"], + "properties": { + "path": {"type": "string"}, + "before": { + "description": "Its current content; `null` when it is absent.", + "anyOf": [{"type": "string"}, {"type": "null"}] + }, + "after": {"type": "string"}, + "created": {"type": "boolean"}, + "changed": {"type": "boolean"} + } + } + }, + "digest": { + "description": "The files' contents before, which a write must still find.", + "type": "string", + "pattern": "^sha256:[0-9a-f]{64}$" + }, + "written": {"description": "`false` for `--dry-run`.", "type": "boolean"}, + "adopted": { + "type": "array", + "items": {"$ref": "https://schemas.projections.githubnext.com/definition/v0.json#/$defs/identifier"} + }, + "bookmarked": { + "type": "array", + "items": { + "type": "object", + "additionalProperties": false, + "required": ["id", "projection", "change"], + "properties": { + "id": {"$ref": "https://schemas.projections.githubnext.com/definition/v0.json#/$defs/identifier"}, + "projection": {"$ref": "https://schemas.projections.githubnext.com/definition/v0.json#/$defs/identifier"}, + "change": {"$ref": "https://schemas.projections.githubnext.com/cli/sweep/v0.json#/$defs/change"} + } + } + }, + "notes": {"type": "array", "items": {"$ref": "#/$defs/note"}} + }, + "$defs": {"note": {"type": "string"}} +} diff --git a/packages/schemas/schemas/cli/batch/v0.json b/packages/schemas/schemas/cli/batch/v0.json new file mode 100644 index 000000000..0e3b234ce --- /dev/null +++ b/packages/schemas/schemas/cli/batch/v0.json @@ -0,0 +1,64 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://schemas.projections.githubnext.com/cli/batch/v0.json", + "title": "CLI batch", + "description": "Every projection (or bookmark) at once: `show --all`, `compare --all` and `bookmark run` with `--json` or `--output`.", + "type": "object", + "additionalProperties": false, + "required": ["format", "version", "operation", "results", "failed"], + "properties": { + "format": {"type": "string", "const": "projections.batch"}, + "version": {"type": "number", "const": 0}, + "operation": {"enum": ["show", "compare", "bookmarks"]}, + "results": {"description": "Ordered by ID.", "type": "array", "items": {"$ref": "#/$defs/result"}}, + "failed": { + "description": "Results whose status is `error`.", + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + } + }, + "$defs": { + "result": { + "description": "One projection's (or bookmark's) result: its document, or why it failed.", + "type": "object", + "additionalProperties": false, + "required": ["id", "status"], + "properties": { + "id": {"$ref": "https://schemas.projections.githubnext.com/definition/v0.json#/$defs/identifier"}, + "status": { + "description": "`extracted` (show), `changed` or `unchanged` (compared), `head-only` or `base-only` (one revision defines it, shown alone), or `error`.", + "enum": ["extracted", "changed", "unchanged", "head-only", "base-only", "error"] + }, + "projectionId": { + "$ref": "https://schemas.projections.githubnext.com/definition/v0.json#/$defs/identifier", + "description": "A bookmark's projection, for `bookmark run`, whose `id` is the bookmark's." + }, + "extraction": {"$ref": "https://schemas.projections.githubnext.com/extraction-document/v0.json"}, + "comparison": {"$ref": "https://schemas.projections.githubnext.com/comparison-document/v0.json"}, + "notices": {"type": "array", "items": {"type": "string"}}, + "review": { + "description": "The engine's review counts of a comparison.", + "type": "object", + "additionalProperties": false, + "required": ["reviewable", "content", "identity", "variation"], + "properties": { + "reviewable": {"type": "integer", "minimum": 0, "maximum": 9007199254740991}, + "content": {"type": "integer", "minimum": 0, "maximum": 9007199254740991}, + "identity": {"type": "integer", "minimum": 0, "maximum": 9007199254740991}, + "variation": {"type": "integer", "minimum": 0, "maximum": 9007199254740991} + } + }, + "diagnostics": { + "description": "Why it failed, for `error`.", + "type": "array", + "items": {"$ref": "https://schemas.projections.githubnext.com/cli/error/v0.json#/$defs/diagnostic"} + }, + "definition": { + "$ref": "https://schemas.projections.githubnext.com/definition/v0.json", + "description": "Its definition, for `error` once it resolved." + } + } + } + } +} diff --git a/packages/schemas/schemas/cli/check/v0.json b/packages/schemas/schemas/cli/check/v0.json new file mode 100644 index 000000000..4800ef3d3 --- /dev/null +++ b/packages/schemas/schemas/cli/check/v0.json @@ -0,0 +1,86 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://schemas.projections.githubnext.com/cli/check/v0.json", + "title": "CLI check", + "description": "Projections verified end to end: extraction, comparison and renderer checks (`projections check --json`).", + "type": "object", + "additionalProperties": false, + "required": ["format", "version", "ok", "projections"], + "properties": { + "format": {"type": "string", "const": "projections.check"}, + "version": {"type": "number", "const": 0}, + "ok": {"type": "boolean"}, + "projections": { + "type": "array", + "items": { + "anyOf": [ + { + "type": "object", + "additionalProperties": false, + "required": ["id", "title", "ok", "steps"], + "properties": { + "id": { + "$ref": "https://schemas.projections.githubnext.com/definition/v0.json#/$defs/identifier" + }, + "title": {"type": "string"}, + "ok": {"type": "boolean"}, + "steps": {"type": "array", "items": {"$ref": "#/$defs/step"}} + } + }, + { + "description": "A definition file that failed to load.", + "type": "object", + "additionalProperties": false, + "required": ["id", "title", "path", "ok", "steps", "diagnostics"], + "properties": { + "id": {"type": "string"}, + "title": {"type": "string"}, + "path": {"type": "string"}, + "ok": {"type": "boolean", "const": false}, + "steps": {"type": "array", "items": {"$ref": "#/$defs/step"}}, + "diagnostics": { + "type": "array", + "items": { + "$ref": "https://schemas.projections.githubnext.com/cli/list/v0.json#/$defs/definitionDiagnostic" + } + } + } + } + ] + } + } + }, + "$defs": { + "rendererCheck": { + "type": "object", + "additionalProperties": false, + "required": ["id", "title", "status", "details", "durationMs"], + "properties": { + "id": {"type": "string"}, + "title": {"type": "string"}, + "status": {"enum": ["pass", "fail", "skip", "advice"]}, + "details": {"type": "array", "items": {"type": "string"}}, + "durationMs": {"type": "number", "minimum": 0} + } + }, + "step": { + "type": "object", + "additionalProperties": false, + "required": ["id", "title", "status", "message"], + "properties": { + "id": {"type": "string"}, + "title": {"type": "string"}, + "status": {"enum": ["pass", "fail", "warn", "skip"]}, + "message": {"type": "string"}, + "error": {"$ref": "https://schemas.projections.githubnext.com/cli/error/v0.json#/$defs/report"}, + "details": {"type": "array", "items": {"type": "string"}}, + "rerun": {"description": "The command that runs the failed renderer checks again.", "type": "string"}, + "checks": { + "description": "Every renderer check, on a renderer step.", + "type": "array", + "items": {"$ref": "#/$defs/rendererCheck"} + } + } + } + } +} diff --git a/packages/schemas/schemas/cli/doctor/v0.json b/packages/schemas/schemas/cli/doctor/v0.json new file mode 100644 index 000000000..1df652237 --- /dev/null +++ b/packages/schemas/schemas/cli/doctor/v0.json @@ -0,0 +1,112 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://schemas.projections.githubnext.com/cli/doctor/v0.json", + "title": "CLI doctor", + "description": "What the checkout needs to run its projections, found without running anything (`projections doctor --json`).", + "type": "object", + "additionalProperties": false, + "required": ["format", "version", "ok", "items", "projections"], + "properties": { + "format": {"type": "string", "const": "projections.doctor"}, + "version": {"type": "number", "const": 0}, + "ok": {"type": "boolean"}, + "items": {"type": "array", "items": {"$ref": "#/$defs/item"}}, + "projections": { + "type": "array", + "items": { + "type": "object", + "additionalProperties": false, + "required": ["id", "title", "ok", "items"], + "properties": { + "id": {"$ref": "https://schemas.projections.githubnext.com/definition/v0.json#/$defs/identifier"}, + "title": {"type": "string"}, + "ok": {"type": "boolean"}, + "items": {"type": "array", "items": {"$ref": "#/$defs/item"}} + } + } + }, + "environment": {"$ref": "#/$defs/environment"} + }, + "$defs": { + "environment": { + "type": "object", + "additionalProperties": false, + "required": ["workspace"], + "properties": { + "workspace": { + "anyOf": [ + { + "type": "object", + "additionalProperties": false, + "required": ["strategy", "source", "reason"], + "properties": { + "strategy": {"enum": ["fresh", "worktree", "clone", "sparse", "none"]}, + "source": {"enum": ["flag", "config", "environment", "automatic"]}, + "reason": {"type": "string"} + } + }, + { + "type": "object", + "additionalProperties": false, + "required": ["error"], + "properties": {"error": {"type": "string"}} + } + ] + }, + "workspaces": { + "type": "array", + "items": { + "$ref": "https://schemas.projections.githubnext.com/cli/workspaces/v0.json#/$defs/workspace" + } + }, + "workspacesError": {"type": "string"}, + "declared": { + "description": "The environment file, or `null` when none is declared.", + "anyOf": [{"type": "string"}, {"type": "null"}] + }, + "error": {"type": "string"}, + "prepare": { + "type": "array", + "items": { + "type": "object", + "additionalProperties": false, + "required": ["id", "run", "directory", "key", "state"], + "properties": { + "id": {"type": "string"}, + "run": {"type": "array", "items": {"type": "string"}}, + "directory": {"type": "string"}, + "key": {"type": "string"}, + "state": {"enum": ["current", "stale", "failed", "never"]}, + "last": { + "type": "object", + "additionalProperties": false, + "required": ["key", "at", "durationMs", "log", "status"], + "properties": { + "key": {"type": "string"}, + "at": {"type": "string"}, + "durationMs": {"type": "integer", "minimum": 0, "maximum": 9007199254740991}, + "log": {"type": "string"}, + "status": {"enum": ["succeeded", "failed"]}, + "error": {"type": "string"} + } + } + } + } + }, + "toolchain": {"type": "array", "items": {"type": "array", "items": {"type": "string"}}}, + "devcontainer": {"anyOf": [{"type": "string"}, {"type": "null"}]}, + "missing": {"type": "array", "items": {"type": "string"}} + } + }, + "item": { + "type": "object", + "additionalProperties": false, + "required": ["status", "title", "message"], + "properties": { + "status": {"enum": ["pass", "warn", "fail"]}, + "title": {"type": "string"}, + "message": {"type": "string"} + } + } + } +} diff --git a/packages/schemas/schemas/cli/error/v0.json b/packages/schemas/schemas/cli/error/v0.json new file mode 100644 index 000000000..d13bab111 --- /dev/null +++ b/packages/schemas/schemas/cli/error/v0.json @@ -0,0 +1,45 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://schemas.projections.githubnext.com/cli/error/v0.json", + "title": "CLI error", + "description": "What a command run with `--json` or `--output` prints to stdout when it fails, besides its message on stderr.", + "type": "object", + "additionalProperties": false, + "required": ["format", "version", "error"], + "properties": { + "format": {"type": "string", "const": "projections.error"}, + "version": {"type": "number", "const": 0}, + "error": {"$ref": "#/$defs/report"} + }, + "$defs": { + "diagnostic": { + "description": "One problem the engine or runner found.", + "type": "object", + "additionalProperties": false, + "required": ["severity", "code", "path", "message"], + "properties": { + "severity": {"enum": ["error", "warning"]}, + "code": {"type": "string"}, + "path": {"description": "A JSON pointer into the extraction, or empty.", "type": "string"}, + "message": {"type": "string"}, + "entityId": {"description": "The entity the problem is about, when there is one.", "type": "string"} + } + }, + "report": { + "description": "What failed (a stable code), where, the evidence and what to do next.", + "type": "object", + "additionalProperties": false, + "required": ["code", "message", "diagnostics"], + "properties": { + "code": {"enum": ["TRUST_REQUIRED", "EXTRACTOR_FAILED", "INVALID_EXTRACTION", "INVALID_INPUT", "ERROR"]}, + "message": {"type": "string"}, + "hint": {"description": "What to do next.", "type": "string"}, + "diagnostics": {"type": "array", "items": {"$ref": "#/$defs/diagnostic"}}, + "stderr": { + "description": "A failed extractor's standard error, for `EXTRACTOR_FAILED`.", + "type": "string" + } + } + } + } +} diff --git a/packages/schemas/schemas/cli/explore/v0.json b/packages/schemas/schemas/cli/explore/v0.json new file mode 100644 index 000000000..423a7d5b1 --- /dev/null +++ b/packages/schemas/schemas/cli/explore/v0.json @@ -0,0 +1,75 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://schemas.projections.githubnext.com/cli/explore/v0.json", + "title": "CLI explore candidates", + "description": "The built-in projections that apply to the repository (`projections explore --list --json`).", + "type": "object", + "additionalProperties": false, + "required": ["format", "version", "candidates"], + "properties": { + "format": {"type": "string", "const": "projections.explore"}, + "version": {"type": "number", "const": 0}, + "candidates": {"type": "array", "items": {"$ref": "#/$defs/candidate"}} + }, + "$defs": { + "need": { + "type": "object", + "additionalProperties": false, + "required": ["kind", "message"], + "properties": {"kind": {"enum": ["configuration", "install"]}, "message": {"type": "string"}} + }, + "candidate": { + "description": "A built-in projection that applies to the repository, as a trial definition.", + "type": "object", + "additionalProperties": false, + "required": ["id", "title", "description", "extractor", "schema", "renderer", "requiresTrust", "basis", "adopted", "definition"], + "properties": { + "id": {"$ref": "https://schemas.projections.githubnext.com/definition/v0.json#/$defs/identifier"}, + "title": {"type": "string"}, + "description": {"type": "string"}, + "extractor": {"$ref": "https://schemas.projections.githubnext.com/definition/v0.json#/$defs/identifier"}, + "schema": {"description": "The domain schema its extractions use, such as `graph/v0`.", "type": "string"}, + "renderer": {"type": "string"}, + "requiresTrust": {"type": "boolean"}, + "basis": { + "description": "Why it was proposed: the detection pattern that matched, how many files and the first few.", + "type": "object", + "additionalProperties": false, + "required": ["count", "examples"], + "properties": { + "pattern": { + "description": "The detection pattern that matched; absent for a candidate named by ID.", + "type": "string" + }, + "named": { + "description": "`adopt` named the built-in extractor; explore did not propose it.", + "type": "boolean", + "const": true + }, + "count": {"type": "integer", "minimum": 0, "maximum": 9007199254740991}, + "examples": {"type": "array", "items": {"type": "string"}}, + "file": {"description": "The one file or manifest a per-file candidate reads.", "type": "string"}, + "skipped": { + "description": "Files `.gitattributes` marks vendored or generated.", + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "crates": { + "description": "The Rust workspace's crates.", + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + } + } + }, + "adopted": { + "description": "The authored definition that already uses it, if any.", + "anyOf": [{"type": "string"}, {"type": "null"}] + }, + "definition": {"$ref": "https://schemas.projections.githubnext.com/definition/v0.json"}, + "needs": {"type": "array", "items": {"$ref": "#/$defs/need"}} + } + } + } +} diff --git a/packages/schemas/schemas/cli/extractor/v0.json b/packages/schemas/schemas/cli/extractor/v0.json new file mode 100644 index 000000000..0132c197e --- /dev/null +++ b/packages/schemas/schemas/cli/extractor/v0.json @@ -0,0 +1,52 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://schemas.projections.githubnext.com/cli/extractor/v0.json", + "title": "CLI extractor", + "description": "One built-in extractor: its inputs, schema, renderer and definition template (`projections extractor view --json`).", + "type": "object", + "additionalProperties": false, + "required": [ + "format", + "version", + "id", + "title", + "description", + "schema", + "renderer", + "trust", + "access", + "determinism", + "inputs", + "template", + "detects" + ], + "properties": { + "format": {"type": "string", "const": "projections.extractor"}, + "version": {"type": "number", "const": 0}, + "id": {"$ref": "https://schemas.projections.githubnext.com/definition/v0.json#/$defs/identifier"}, + "title": {"type": "string"}, + "description": {"type": "string"}, + "schema": {"description": "The domain schema its extractions use, such as `graph/v0`.", "type": "string"}, + "renderer": {"description": "The built-in renderer its definition template uses.", "type": "string"}, + "trust": { + "description": "Whether it runs repository code (anything but `none`).", + "enum": ["none", "when-executing-tools"] + }, + "access": {"description": "File reads only, or a checkout.", "enum": ["files", "checkout"]}, + "determinism": {"enum": ["pure", "environmental", "observed"]}, + "inputs": { + "description": "Its inputs, each with what it means.", + "type": "object", + "additionalProperties": {"type": "string"} + }, + "template": { + "$ref": "https://schemas.projections.githubnext.com/definition/v0.json", + "description": "The definition `projections init --extractor` writes." + }, + "detects": { + "description": "The file patterns that mean it may apply.", + "type": "array", + "items": {"type": "string"} + } + } +} diff --git a/packages/schemas/schemas/cli/extractors/v0.json b/packages/schemas/schemas/cli/extractors/v0.json new file mode 100644 index 000000000..08212f696 --- /dev/null +++ b/packages/schemas/schemas/cli/extractors/v0.json @@ -0,0 +1,48 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://schemas.projections.githubnext.com/cli/extractors/v0.json", + "title": "CLI extractor list", + "description": "The built-in extractors (`projections extractor list --json`).", + "type": "object", + "additionalProperties": false, + "required": ["format", "version", "extractors"], + "properties": { + "format": {"type": "string", "const": "projections.extractors"}, + "version": {"type": "number", "const": 0}, + "extractors": {"type": "array", "items": {"$ref": "#/$defs/extractor"}} + }, + "$defs": { + "extractor": { + "type": "object", + "additionalProperties": false, + "required": ["id", "title", "description", "schema", "renderer", "trust", "access", "determinism", "inputs", "template", "detects"], + "properties": { + "id": {"$ref": "https://schemas.projections.githubnext.com/definition/v0.json#/$defs/identifier"}, + "title": {"type": "string"}, + "description": {"type": "string"}, + "schema": {"description": "The domain schema its extractions use, such as `graph/v0`.", "type": "string"}, + "renderer": {"description": "The built-in renderer its definition template uses.", "type": "string"}, + "trust": { + "description": "Whether it runs repository code (anything but `none`).", + "enum": ["none", "when-executing-tools"] + }, + "access": {"description": "File reads only, or a checkout.", "enum": ["files", "checkout"]}, + "determinism": {"enum": ["pure", "environmental", "observed"]}, + "inputs": { + "description": "Its inputs, each with what it means.", + "type": "object", + "additionalProperties": {"type": "string"} + }, + "template": { + "$ref": "https://schemas.projections.githubnext.com/definition/v0.json", + "description": "The definition `projections init --extractor` writes." + }, + "detects": { + "description": "The file patterns that mean it may apply.", + "type": "array", + "items": {"type": "string"} + } + } + } + } +} diff --git a/packages/schemas/schemas/cli/list/v0.json b/packages/schemas/schemas/cli/list/v0.json new file mode 100644 index 000000000..1da3de225 --- /dev/null +++ b/packages/schemas/schemas/cli/list/v0.json @@ -0,0 +1,74 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://schemas.projections.githubnext.com/cli/list/v0.json", + "title": "CLI list", + "description": "The projections a revision defines, read without running anything (`projections list --json`).", + "type": "object", + "additionalProperties": false, + "required": ["format", "version", "revision", "projections", "invalid"], + "properties": { + "format": {"type": "string", "const": "projections.list"}, + "version": {"type": "number", "const": 0}, + "revision": { + "$ref": "https://schemas.projections.githubnext.com/extraction-document/v0.json#/$defs/revision", + "description": "The revision whose definitions are listed." + }, + "projections": { + "type": "array", + "items": { + "type": "object", + "additionalProperties": false, + "required": ["id", "title", "renderer", "requiresTrust", "rendererRequiresTrust", "definition"], + "properties": { + "id": {"$ref": "https://schemas.projections.githubnext.com/definition/v0.json#/$defs/identifier"}, + "title": {"type": "string"}, + "renderer": {"$ref": "https://schemas.projections.githubnext.com/definition/v0.json#/$defs/renderer"}, + "requiresTrust": {"description": "Whether its extractor runs repository code.", "type": "boolean"}, + "rendererRequiresTrust": {"description": "Whether its custom renderer needs explicit trust.", "type": "boolean"}, + "definition": {"$ref": "https://schemas.projections.githubnext.com/definition/v0.json"} + } + } + }, + "invalid": {"type": "array", "items": {"$ref": "#/$defs/invalidDefinition"}} + }, + "$defs": { + "definitionDiagnostic": { + "type": "object", + "additionalProperties": false, + "required": ["code", "severity", "message", "path", "location"], + "properties": { + "code": {"type": "string"}, + "severity": {"enum": ["error", "warning"]}, + "message": {"type": "string"}, + "path": {"description": "The definition file, relative to the repository.", "type": "string"}, + "location": { + "type": "object", + "additionalProperties": false, + "required": ["path", "line", "column"], + "properties": { + "path": {"type": "string"}, + "line": {"type": "integer", "minimum": 0, "maximum": 9007199254740991}, + "column": {"type": "integer", "minimum": 0, "maximum": 9007199254740991} + } + }, + "pointer": { + "description": "A JSON pointer to the invalid value, when the error names one.", + "type": "string" + } + } + }, + "invalidDefinition": { + "type": "object", + "additionalProperties": false, + "required": ["id", "path", "diagnostics"], + "properties": { + "id": { + "description": "The file's `id`, when it has a readable one.", + "anyOf": [{"type": "string"}, {"type": "null"}] + }, + "path": {"type": "string"}, + "diagnostics": {"type": "array", "items": {"$ref": "#/$defs/definitionDiagnostic"}} + } + } + } +} diff --git a/packages/schemas/schemas/cli/prepare/v0.json b/packages/schemas/schemas/cli/prepare/v0.json new file mode 100644 index 000000000..ea2b2c384 --- /dev/null +++ b/packages/schemas/schemas/cli/prepare/v0.json @@ -0,0 +1,48 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://schemas.projections.githubnext.com/cli/prepare/v0.json", + "title": "CLI prepare", + "description": "The environment's prepare steps, run in the working tree or a commit's workspace (`projections prepare --json`).", + "type": "object", + "additionalProperties": false, + "required": ["format", "version", "target", "environment", "root", "steps"], + "properties": { + "format": {"type": "string", "const": "projections.prepare"}, + "version": {"type": "number", "const": 0}, + "target": {"description": "`working-tree`, or the commit whose workspace was prepared.", "type": "string"}, + "environment": {"description": "The environment file.", "type": "string"}, + "root": {"description": "Where the steps ran.", "type": "string"}, + "strategy": {"description": "The workspace's strategy, for a commit.", "enum": ["worktree", "clone", "sparse"]}, + "notes": {"type": "array", "items": {"type": "string"}}, + "steps": { + "type": "array", + "items": { + "anyOf": [ + { + "description": "Unchanged keys: not run.", + "type": "object", + "additionalProperties": false, + "required": ["id", "key", "status"], + "properties": { + "id": {"type": "string"}, + "key": {"type": "string"}, + "status": {"type": "string", "const": "current"} + } + }, + { + "type": "object", + "additionalProperties": false, + "required": ["id", "key", "status", "durationMs", "log"], + "properties": { + "id": {"type": "string"}, + "key": {"type": "string"}, + "status": {"type": "string", "const": "succeeded"}, + "durationMs": {"type": "integer", "minimum": 0, "maximum": 9007199254740991}, + "log": {"type": "string"} + } + } + ] + } + } + } +} diff --git a/packages/schemas/schemas/cli/pull-request/v0.json b/packages/schemas/schemas/cli/pull-request/v0.json new file mode 100644 index 000000000..188c6fe3b --- /dev/null +++ b/packages/schemas/schemas/cli/pull-request/v0.json @@ -0,0 +1,49 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://schemas.projections.githubnext.com/cli/pull-request/v0.json", + "title": "CLI pull request review", + "description": "A pull request reviewed without running its code, with the base's definitions (`projections pr --json`).", + "type": "object", + "additionalProperties": false, + "required": [ + "format", + "version", + "repository", + "number", + "url", + "base", + "head", + "mergeBase", + "fork", + "execution", + "definition", + "changedProjections", + "comparisons" + ], + "properties": { + "format": {"type": "string", "const": "projections.pull-request"}, + "version": {"type": "number", "const": 0}, + "repository": {"description": "`owner/name`.", "type": "string"}, + "number": {"type": "integer", "minimum": 0, "maximum": 9007199254740991}, + "url": {"type": "string"}, + "base": {"type": "string"}, + "head": {"type": "string"}, + "mergeBase": {"type": "string"}, + "fork": {"type": "boolean"}, + "execution": {"type": "string", "const": "untrusted"}, + "definition": {"type": "string", "const": "base"}, + "changedProjections": { + "type": "array", + "items": { + "type": "object", + "additionalProperties": false, + "required": ["id", "notices"], + "properties": { + "id": {"$ref": "https://schemas.projections.githubnext.com/definition/v0.json#/$defs/identifier"}, + "notices": {"type": "array", "items": {"type": "string"}} + } + } + }, + "comparisons": {"$ref": "https://schemas.projections.githubnext.com/cli/batch/v0.json"} + } +} diff --git a/packages/schemas/schemas/cli/screenshot/v0.json b/packages/schemas/schemas/cli/screenshot/v0.json new file mode 100644 index 000000000..4bbb04327 --- /dev/null +++ b/packages/schemas/schemas/cli/screenshot/v0.json @@ -0,0 +1,68 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://schemas.projections.githubnext.com/cli/screenshot/v0.json", + "title": "CLI viewer screenshot", + "description": "The PNG `projections view screenshot --json` wrote, and what it shows.", + "anyOf": [ + { + "description": "A projection rendered by its renderer.", + "type": "object", + "additionalProperties": false, + "required": [ + "format", + "version", + "projection", + "scenario", + "before", + "after", + "mode", + "progress", + "theme", + "width", + "height", + "notices", + "bytes" + ], + "properties": { + "format": {"type": "string", "const": "projections.screenshot"}, + "version": {"type": "number", "const": 0}, + "projection": {"description": "The projection drawn."}, + "scenario": {"description": "The scenario drawn, or `null`."}, + "before": {"description": "The revision before, or `null`."}, + "after": {"description": "The revision after, or `null` for a scenario."}, + "mode": {"anyOf": [{"type": "string"}, {"type": "null"}]}, + "progress": {"description": "The comparison progress drawn."}, + "theme": {"type": "string"}, + "width": {"type": "integer", "minimum": 0, "maximum": 9007199254740991}, + "height": {"type": "integer", "minimum": 0, "maximum": 9007199254740991}, + "notices": {"type": "array", "items": {"type": "string"}}, + "bytes": {"type": "integer", "minimum": 0, "maximum": 9007199254740991} + } + }, + { + "description": "The viewer's page, captured with `--page`.", + "type": "object", + "additionalProperties": false, + "required": ["format", "version", "page", "viewer", "projection", "theme", "width", "height", "notices", "bytes"], + "properties": { + "format": {"type": "string", "const": "projections.screenshot"}, + "version": {"type": "number", "const": 0}, + "page": {"type": "boolean", "const": true}, + "viewer": {"type": "string"}, + "projection": {"type": "string"}, + "theme": {"type": "string"}, + "width": {"type": "integer", "minimum": 0, "maximum": 9007199254740991}, + "height": {"type": "integer", "minimum": 0, "maximum": 9007199254740991}, + "notices": {"type": "array", "items": {"type": "string"}}, + "bytes": {"type": "integer", "minimum": 0, "maximum": 9007199254740991} + } + }, + { + "description": "The viewer refused; the command fails. It has no `format`.", + "type": "object", + "additionalProperties": false, + "required": ["error"], + "properties": {"error": {"type": "string"}} + } + ] +} diff --git a/packages/schemas/schemas/cli/sweep/v0.json b/packages/schemas/schemas/cli/sweep/v0.json new file mode 100644 index 000000000..c706472a7 --- /dev/null +++ b/packages/schemas/schemas/cli/sweep/v0.json @@ -0,0 +1,98 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://schemas.projections.githubnext.com/cli/sweep/v0.json", + "title": "CLI sweep", + "description": "Each candidate and adopted projection tried on recent changes (`projections explore --sweep --json`).", + "type": "object", + "additionalProperties": false, + "required": ["format", "version", "changes", "projections", "cells", "notes"], + "properties": { + "format": {"type": "string", "const": "projections.sweep"}, + "version": {"type": "number", "const": 0}, + "changes": {"type": "array", "items": {"$ref": "#/$defs/change"}}, + "projections": {"type": "array", "items": {"$ref": "#/$defs/projection"}}, + "cells": {"type": "array", "items": {"$ref": "#/$defs/cell"}}, + "notes": {"type": "array", "items": {"$ref": "#/$defs/note"}} + }, + "$defs": { + "change": { + "type": "object", + "additionalProperties": false, + "required": ["before", "after", "title", "number", "kind", "date"], + "properties": { + "before": {"type": "string"}, + "after": {"type": "string"}, + "title": {"type": "string"}, + "number": { + "description": "The pull request number its message names, if any.", + "anyOf": [{"type": "integer", "minimum": 0, "maximum": 9007199254740991}, {"type": "null"}] + }, + "kind": {"description": "A merge commit, or a first-parent commit.", "enum": ["merge", "commit"]}, + "date": {"description": "The commit's date, ISO 8601.", "type": "string"} + } + }, + "projectionStatus": {"enum": ["ready", "trust", "failed"]}, + "projection": { + "description": "One projection of the sweep, and its tally over the swept changes.", + "type": "object", + "additionalProperties": false, + "required": ["projection", "status"], + "properties": { + "projection": {"$ref": "https://schemas.projections.githubnext.com/definition/v0.json#/$defs/identifier"}, + "status": {"$ref": "#/$defs/projectionStatus"}, + "requiresTrust": {"type": "boolean"}, + "error": {"description": "Why it was skipped or failed.", "type": "string"}, + "signal": { + "description": "How useful its changes look, for a ready projection.", + "enum": ["rare", "steady", "unknown", "noisy", "quiet"] + }, + "changed": { + "description": "Changes it showed a change on, besides version-only ones.", + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "versionOnly": { + "description": "Changes where only version strings moved.", + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "failed": { + "description": "Changes it failed on.", + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + } + } + }, + "cellStatus": {"enum": ["changed", "unchanged", "failed"]}, + "cell": { + "description": "One projection on one change: its comparison counts, or why it failed.", + "type": "object", + "additionalProperties": false, + "required": ["projection", "before", "after", "status"], + "properties": { + "projection": {"$ref": "https://schemas.projections.githubnext.com/definition/v0.json#/$defs/identifier"}, + "before": {"type": "string"}, + "after": {"type": "string"}, + "status": {"$ref": "#/$defs/cellStatus"}, + "changes": {"type": "integer", "minimum": 0, "maximum": 9007199254740991}, + "steps": {"type": "integer", "minimum": 0, "maximum": 9007199254740991}, + "counts": { + "description": "Changes by status (`added`, `removed`, `modified`, …).", + "type": "object", + "additionalProperties": {"type": "integer", "minimum": 0, "maximum": 9007199254740991} + }, + "versionOnly": { + "description": "Changed, but only version strings moved (a dependency or action bump).", + "type": "boolean", + "const": true + }, + "error": {"type": "string"}, + "stderr": {"description": "The end of a failed extractor's stderr.", "type": "string"} + } + }, + "note": {"type": "string"} + } +} diff --git a/packages/schemas/schemas/cli/validation/v0.json b/packages/schemas/schemas/cli/validation/v0.json new file mode 100644 index 000000000..93d70706c --- /dev/null +++ b/packages/schemas/schemas/cli/validation/v0.json @@ -0,0 +1,27 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://schemas.projections.githubnext.com/cli/validation/v0.json", + "title": "CLI validation", + "description": "A valid saved extraction, comparison or scenarios document (`projections validate --json`).", + "type": "object", + "additionalProperties": false, + "required": ["valid", "format"], + "properties": { + "valid": {"type": "boolean", "const": true}, + "format": { + "description": "What was validated: a saved extraction, a saved comparison, scenarios, or a bare extraction.", + "enum": ["projections.extraction", "projections.comparison", "projections.scenarios", "extraction"] + }, + "scenarios": { + "description": "The scenarios, for `projections.scenarios`.", + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "reproduced": { + "description": "A comparison by a custom comparator, which wasn't recomputed without `--comparator`.", + "type": "boolean", + "const": false + } + } +} diff --git a/packages/schemas/schemas/cli/view/v0.json b/packages/schemas/schemas/cli/view/v0.json new file mode 100644 index 000000000..fd67c7060 --- /dev/null +++ b/packages/schemas/schemas/cli/view/v0.json @@ -0,0 +1,145 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://schemas.projections.githubnext.com/cli/view/v0.json", + "title": "CLI viewer", + "description": "What the viewer shows and what the person selected (`projections view show|current|refresh --json`).", + "anyOf": [ + { + "description": "Nothing is shown yet.", + "type": "object", + "additionalProperties": false, + "required": ["format", "version", "shown", "viewer", "url", "viewers"], + "properties": { + "format": {"type": "string", "const": "projections.view"}, + "version": {"type": "number", "const": 0}, + "shown": {"type": "boolean", "const": false}, + "viewer": {"description": "The viewer."}, + "url": {"description": "The viewer's page."}, + "viewers": {"description": "The other viewers running."} + } + }, + { + "description": "What the viewer shows.", + "type": "object", + "additionalProperties": false, + "required": [ + "format", + "version", + "shown", + "surface", + "viewer", + "url", + "chosenBy", + "viewers", + "pages", + "seen", + "projection", + "title", + "choice", + "compared", + "before", + "after", + "scenario", + "mode", + "selection", + "page", + "failures", + "document", + "rendererBuild" + ], + "properties": { + "format": {"type": "string", "const": "projections.view"}, + "version": {"type": "number", "const": 0}, + "shown": {"type": "boolean", "const": true}, + "surface": {"type": "string", "const": "viewer"}, + "viewer": {"description": "The viewer."}, + "url": {"description": "The viewer's page."}, + "chosenBy": {"description": "Who chose the projection: the agent, or the person from the page."}, + "viewers": {"description": "The other viewers running."}, + "pages": {"type": "integer", "minimum": 0, "maximum": 9007199254740991}, + "seen": {"description": "What the open pages saw."}, + "projection": {"type": "string"}, + "title": {"type": "string"}, + "choice": {"description": "How the revisions were chosen."}, + "compared": {"type": "string"}, + "before": { + "anyOf": [ + { + "type": "object", + "additionalProperties": false, + "required": ["ref", "commit"], + "properties": {"ref": {"type": "string"}, "commit": {"anyOf": [{"type": "string"}, {"type": "null"}]}} + }, + {"type": "null"} + ] + }, + "after": { + "type": "object", + "additionalProperties": false, + "required": ["ref", "commit"], + "properties": {"ref": {"type": "string"}, "commit": {"anyOf": [{"type": "string"}, {"type": "null"}]}} + }, + "scenario": {"description": "The scenario shown, for fixtures."}, + "mode": {"description": "The comparison mode."}, + "selection": {"description": "What the person selected, from the current page."}, + "page": {"description": "The current page's view."}, + "failures": {"description": "The current page's failures."}, + "document": { + "description": "The saved document shown, instead of the repository.", + "anyOf": [ + { + "type": "object", + "additionalProperties": false, + "required": ["path", "format", "renderer"], + "properties": { + "path": {"type": "string"}, + "format": {"description": "The document's format."}, + "renderer": { + "anyOf": [ + { + "type": "object", + "additionalProperties": false, + "required": ["builtIn"], + "properties": {"builtIn": {"description": "The built-in renderer."}} + }, + { + "type": "object", + "additionalProperties": false, + "required": ["bundle"], + "properties": {"bundle": {"type": "string"}} + } + ] + } + } + }, + {"type": "null"} + ] + }, + "rendererBuild": { + "anyOf": [ + { + "type": "object", + "additionalProperties": false, + "required": ["phase", "error", "script", "package", "bundled"], + "properties": { + "phase": {"type": "string"}, + "error": {"description": "Why the build failed."}, + "script": {"description": "The build script."}, + "package": {"description": "The renderer's package."}, + "bundled": {"type": "boolean"} + } + }, + {"type": "null"} + ] + } + } + }, + { + "description": "The viewer refused; the command fails. It has no `format`.", + "type": "object", + "additionalProperties": false, + "required": ["error"], + "properties": {"error": {"type": "string"}} + } + ] +} diff --git a/packages/schemas/schemas/cli/workspace-clean/v0.json b/packages/schemas/schemas/cli/workspace-clean/v0.json new file mode 100644 index 000000000..675b9d1fe --- /dev/null +++ b/packages/schemas/schemas/cli/workspace-clean/v0.json @@ -0,0 +1,18 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://schemas.projections.githubnext.com/cli/workspace-clean/v0.json", + "title": "CLI workspace clean", + "description": "The workspaces `projections workspace clean --json` removed.", + "type": "object", + "additionalProperties": false, + "required": ["format", "version", "removed"], + "properties": { + "format": {"type": "string", "const": "projections.workspace-clean"}, + "version": {"type": "number", "const": 0}, + "removed": { + "description": "The workspaces removed; busy ones are kept.", + "type": "array", + "items": {"type": "string"} + } + } +} diff --git a/packages/schemas/schemas/cli/workspaces/v0.json b/packages/schemas/schemas/cli/workspaces/v0.json new file mode 100644 index 000000000..9f73339f2 --- /dev/null +++ b/packages/schemas/schemas/cli/workspaces/v0.json @@ -0,0 +1,44 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://schemas.projections.githubnext.com/cli/workspaces/v0.json", + "title": "CLI workspace list", + "description": "The workspaces Projections keeps for the repository (`projections workspace list --json`).", + "type": "object", + "additionalProperties": false, + "required": ["format", "version", "directory", "workspaces"], + "properties": { + "format": {"type": "string", "const": "projections.workspaces"}, + "version": {"type": "number", "const": 0}, + "directory": {"type": "string"}, + "workspaces": {"type": "array", "items": {"$ref": "#/$defs/workspace"}} + }, + "$defs": { + "workspace": { + "type": "object", + "additionalProperties": false, + "required": ["name", "strategy", "commit", "at", "scope", "path", "busy", "prepared"], + "properties": { + "name": {"type": "string"}, + "strategy": {"anyOf": [{"enum": ["fresh", "worktree", "clone", "sparse", "none"]}, {"type": "null"}]}, + "commit": {"anyOf": [{"type": "string"}, {"type": "null"}]}, + "at": {"anyOf": [{"type": "string"}, {"type": "null"}]}, + "scope": {"description": "The scope it holds, for a sparse workspace; `null` otherwise."}, + "path": {"type": "string"}, + "busy": {"description": "Whether a run is using it.", "type": "boolean"}, + "prepared": { + "type": "array", + "items": { + "type": "object", + "additionalProperties": false, + "required": ["id", "status", "at"], + "properties": { + "id": {"type": "string"}, + "status": {"anyOf": [{"type": "string"}, {"type": "null"}]}, + "at": {"anyOf": [{"type": "string"}, {"type": "null"}]} + } + } + } + } + } + } +} diff --git a/packages/schemas/src/typebox/cli.ts b/packages/schemas/src/typebox/cli.ts new file mode 100644 index 000000000..dfcb54f6d --- /dev/null +++ b/packages/schemas/src/typebox/cli.ts @@ -0,0 +1,771 @@ +// The documents the CLI prints with `--json` (or writes with `--output`), each published as `cli//v0.json`. +// Every document but `validate`'s carries `format` (its kind) and `version`. Objects are closed, so a field the CLI +// adds fails `packages/cli/test/json-output.test.mjs` until it is declared here. +// +// Extension points: a shape another change will grow is its own `$defs` entry, so that change edits one place: +// a sweep cell's status (`cli/sweep#/$defs/cellStatus`), a swept projection with its tally (`cli/sweep#/$defs/projection`, +// which is also what a streamed sweep prints per projection), the sweep's notes (`cli/sweep#/$defs/note`) and +// adopt's notes (`cli/adopt#/$defs/note`). +import Type, {type Static, type TProperties, type TSchema} from 'typebox' +import {DefinitionSchema, Identifier, RendererReference} from './definition.js' +import {ComparisonDocumentSchema, ExtractionDocumentSchema, RevisionSchema} from './documents.js' +import {annotated, Closed, define, Dictionary} from './support.js' + +const Count = Type.Integer({minimum: 0, maximum: Number.MAX_SAFE_INTEGER}) +const Nullable = (schema: T, options: {description?: string} = {}) => Type.Union([schema, Type.Null()], options) +const Sha256Digest = Type.String({pattern: '^sha256:[0-9a-f]{64}$'}) +/** A value the CLI passes through from another component without shaping it here. */ +const Passed = (description: string) => Type.Unknown({description}) + +/** A CLI document's kind and version: `format` names it, `version` is its major version. */ +function Document(format: F, properties: P, options: {description: string}) { + return Closed({format: Type.Literal(format), version: Type.Literal(0), ...properties}, options) +} + +// Errors --------------------------------------------------------------------------------------------------------- + +/** One problem the engine or runner found: where (`path`, a JSON pointer or file), and what. */ +export const CliDiagnosticSchema = define( + 'cli/error', + 'diagnostic', + Closed( + { + severity: Type.Enum(['error', 'warning']), + code: Type.String(), + path: Type.String({description: 'A JSON pointer into the extraction, or empty.'}), + message: Type.String(), + entityId: Type.Optional(Type.String({description: 'The entity the problem is about, when there is one.'})), + }, + {description: 'One problem the engine or runner found.'}, + ), +) + +/** The JSON Schema of a failure report, `cli/error#/$defs/report`: a `projections.error` document's `error`, and a failed `check` step's. */ +export const CliErrorReportSchema = define( + 'cli/error', + 'report', + Closed( + { + code: Type.Enum(['TRUST_REQUIRED', 'EXTRACTOR_FAILED', 'INVALID_EXTRACTION', 'INVALID_INPUT', 'ERROR']), + message: Type.String(), + hint: Type.Optional(Type.String({description: 'What to do next.'})), + diagnostics: Type.Array(CliDiagnosticSchema), + stderr: Type.Optional(Type.String({description: "A failed extractor's standard error, for `EXTRACTOR_FAILED`."})), + }, + {description: 'What failed (a stable code), where, the evidence and what to do next.'}, + ), +) + +/** The JSON Schema of `projections.error`, what a command run with `--json` or `--output` prints when it fails. */ +export const CliErrorSchema = define( + 'cli/error', + undefined, + Document( + 'projections.error', + {error: CliErrorReportSchema}, + {description: 'What a command run with `--json` or `--output` prints to stdout when it fails, besides its message on stderr.'}, + ), +) + +// Definitions ---------------------------------------------------------------------------------------------------- + +/** An invalid definition file's diagnostic: its code, the file and the line and column of the problem. */ +export const DefinitionDiagnosticSchema = define( + 'cli/list', + 'definitionDiagnostic', + Closed({ + code: Type.String(), + severity: Type.Enum(['error', 'warning']), + message: Type.String(), + path: Type.String({description: 'The definition file, relative to the repository.'}), + location: Closed({path: Type.String(), line: Count, column: Count}), + pointer: Type.Optional(Type.String({description: 'A JSON pointer to the invalid value, when the error names one.'})), + }), +) + +/** A definition file that doesn't load: its ID when it has a readable one, its path and why. */ +export const InvalidDefinitionSchema = define( + 'cli/list', + 'invalidDefinition', + Closed({ + id: Nullable(Type.String(), {description: "The file's `id`, when it has a readable one."}), + path: Type.String(), + diagnostics: Type.Array(DefinitionDiagnosticSchema), + }), +) + +/** The JSON Schema of `projections.list`, what `projections list --json` prints. */ +export const CliListSchema = define( + 'cli/list', + undefined, + Document( + 'projections.list', + { + revision: annotated(RevisionSchema, {description: 'The revision whose definitions are listed.'}), + projections: Type.Array( + Closed({ + id: Identifier, + title: Type.String(), + renderer: RendererReference, + requiresTrust: Type.Boolean({description: 'Whether its extractor runs repository code.'}), + rendererRequiresTrust: Type.Boolean({description: 'Whether its custom renderer needs explicit trust.'}), + definition: DefinitionSchema, + }), + ), + invalid: Type.Array(InvalidDefinitionSchema), + }, + {description: 'The projections a revision defines, read without running anything (`projections list --json`).'}, + ), +) + +// Explore -------------------------------------------------------------------------------------------------------- + +/** Something a candidate needs before it can run, such as an install. */ +export const CandidateNeedSchema = define( + 'cli/explore', + 'need', + Closed({kind: Type.Enum(['configuration', 'install']), message: Type.String()}), +) + +/** The JSON Schema of one explore candidate, `cli/explore#/$defs/candidate`: a built-in projection that applies, as a trial definition. */ +export const CandidateSchema = define( + 'cli/explore', + 'candidate', + Closed( + { + id: Identifier, + title: Type.String(), + description: Type.String(), + extractor: Identifier, + schema: Type.String({description: 'The domain schema its extractions use, such as `graph/v0`.'}), + renderer: Type.String(), + requiresTrust: Type.Boolean(), + basis: Closed( + { + pattern: Type.Optional(Type.String({description: 'The detection pattern that matched; absent for a candidate named by ID.'})), + named: Type.Optional(Type.Literal(true, {description: '`adopt` named the built-in extractor; explore did not propose it.'})), + count: Count, + examples: Type.Array(Type.String()), + file: Type.Optional(Type.String({description: 'The one file or manifest a per-file candidate reads.'})), + skipped: Type.Optional(annotated(Count, {description: 'Files `.gitattributes` marks vendored or generated.'})), + crates: Type.Optional(annotated(Count, {description: "The Rust workspace's crates."})), + }, + {description: 'Why it was proposed: the detection pattern that matched, how many files and the first few.'}, + ), + adopted: Nullable(Type.String(), {description: 'The authored definition that already uses it, if any.'}), + definition: DefinitionSchema, + needs: Type.Optional(Type.Array(CandidateNeedSchema)), + }, + {description: 'A built-in projection that applies to the repository, as a trial definition.'}, + ), +) + +/** The JSON Schema of `projections.explore`, what `projections explore --list --json` prints. */ +export const CliExploreSchema = define( + 'cli/explore', + undefined, + Document( + 'projections.explore', + {candidates: Type.Array(CandidateSchema)}, + {description: 'The built-in projections that apply to the repository (`projections explore --list --json`).'}, + ), +) + +// Sweep ---------------------------------------------------------------------------------------------------------- + +/** The JSON Schema of a swept change, `cli/sweep#/$defs/change`: a revision compared with the one before it. */ +export const SweepChangeSchema = define( + 'cli/sweep', + 'change', + Closed({ + before: Type.String(), + after: Type.String(), + title: Type.String(), + number: Nullable(Count, {description: 'The pull request number its message names, if any.'}), + kind: Type.Enum(['merge', 'commit'], {description: 'A merge commit, or a first-parent commit.'}), + date: Type.String({description: "The commit's date, ISO 8601."}), + }), +) + +/** Whether a projection could be swept: `ready`, skipped because it needs `--trust`, or failed to prepare. */ +export const SweepProjectionStatusSchema = define('cli/sweep', 'projectionStatus', Type.Enum(['ready', 'trust', 'failed'])) + +/** + * The JSON Schema of one swept projection, `cli/sweep#/$defs/projection`: its status and, once ready, its tally over + * the cells. Rows are ranked best signal first. A streamed sweep prints one of these per projection. + */ +export const SweepProjectionSchema = define( + 'cli/sweep', + 'projection', + Closed( + { + projection: Identifier, + status: SweepProjectionStatusSchema, + requiresTrust: Type.Optional(Type.Boolean()), + error: Type.Optional(Type.String({description: 'Why it was skipped or failed.'})), + signal: Type.Optional( + Type.Enum(['rare', 'steady', 'unknown', 'noisy', 'quiet'], {description: 'How useful its changes look, for a ready projection.'}), + ), + changed: Type.Optional(annotated(Count, {description: 'Changes it showed a change on, besides version-only ones.'})), + versionOnly: Type.Optional(annotated(Count, {description: 'Changes where only version strings moved.'})), + failed: Type.Optional(annotated(Count, {description: 'Changes it failed on.'})), + }, + {description: 'One projection of the sweep, and its tally over the swept changes.'}, + ), +) + +/** A sweep cell's outcome. */ +export const SweepCellStatusSchema = define('cli/sweep', 'cellStatus', Type.Enum(['changed', 'unchanged', 'failed'])) + +/** The JSON Schema of one sweep cell, `cli/sweep#/$defs/cell`: one projection on one change. */ +export const SweepCellSchema = define( + 'cli/sweep', + 'cell', + Closed( + { + projection: Identifier, + before: Type.String(), + after: Type.String(), + status: SweepCellStatusSchema, + changes: Type.Optional(Count), + steps: Type.Optional(Count), + counts: Type.Optional(Dictionary(Count, {description: 'Changes by status (`added`, `removed`, `modified`, …).'})), + versionOnly: Type.Optional(Type.Literal(true, {description: 'Changed, but only version strings moved (a dependency or action bump).'})), + error: Type.Optional(Type.String()), + stderr: Type.Optional(Type.String({description: "The end of a failed extractor's stderr."})), + }, + {description: 'One projection on one change: its comparison counts, or why it failed.'}, + ), +) + +/** Something about the sweep as a whole, such as a shallow clone's missing history. */ +export const SweepNoteSchema = define('cli/sweep', 'note', Type.String()) + +/** The JSON Schema of `projections.sweep`, what `projections explore --sweep --json` prints. */ +export const CliSweepSchema = define( + 'cli/sweep', + undefined, + Document( + 'projections.sweep', + { + changes: Type.Array(SweepChangeSchema), + projections: Type.Array(SweepProjectionSchema), + cells: Type.Array(SweepCellSchema), + notes: Type.Array(SweepNoteSchema), + }, + {description: 'Each candidate and adopted projection tried on recent changes (`projections explore --sweep --json`).'}, + ), +) + +// Adopt ---------------------------------------------------------------------------------------------------------- + +/** Something about how adopt chose bookmarks, or why a projection has none. */ +export const AdoptNoteSchema = define('cli/adopt', 'note', Type.String()) + +/** The JSON Schema of `projections.adopt`, what `projections adopt --json` prints. */ +export const CliAdoptSchema = define( + 'cli/adopt', + undefined, + Document( + 'projections.adopt', + { + files: Type.Array( + Closed({ + path: Type.String(), + before: Nullable(Type.String(), {description: 'Its current content; `null` when it is absent.'}), + after: Type.String(), + created: Type.Boolean(), + changed: Type.Boolean(), + }), + {description: 'The definitions and the bookmarks file it writes, or would write.'}, + ), + digest: annotated(Sha256Digest, {description: "The files' contents before, which a write must still find."}), + written: Type.Boolean({description: '`false` for `--dry-run`.'}), + adopted: Type.Array(Identifier), + bookmarked: Type.Array(Closed({id: Identifier, projection: Identifier, change: SweepChangeSchema})), + notes: Type.Array(AdoptNoteSchema), + }, + {description: 'The definitions and bookmarks adopting projections writes (`projections adopt --json`).'}, + ), +) + +// Check ---------------------------------------------------------------------------------------------------------- + +const CheckStatus = Type.Enum(['pass', 'fail', 'warn', 'skip']) + +/** One renderer check's outcome, as the renderer checks report it. */ +export const RendererCheckSchema = define( + 'cli/check', + 'rendererCheck', + Closed({ + id: Type.String(), + title: Type.String(), + status: Type.Enum(['pass', 'fail', 'skip', 'advice']), + details: Type.Array(Type.String()), + durationMs: Type.Number({minimum: 0}), + }), +) + +/** The JSON Schema of one check step, `cli/check#/$defs/step`. */ +export const CheckStepSchema = define( + 'cli/check', + 'step', + Closed({ + id: Type.String(), + title: Type.String(), + status: CheckStatus, + message: Type.String(), + error: Type.Optional(CliErrorReportSchema), + details: Type.Optional(Type.Array(Type.String())), + rerun: Type.Optional(Type.String({description: 'The command that runs the failed renderer checks again.'})), + checks: Type.Optional(Type.Array(RendererCheckSchema, {description: 'Every renderer check, on a renderer step.'})), + }), +) + +/** The JSON Schema of `projections.check`, what `projections check --json` prints. */ +export const CliCheckSchema = define( + 'cli/check', + undefined, + Document( + 'projections.check', + { + ok: Type.Boolean(), + projections: Type.Array( + Type.Union([ + Closed({id: Identifier, title: Type.String(), ok: Type.Boolean(), steps: Type.Array(CheckStepSchema)}), + Closed( + { + id: Type.String(), + title: Type.String(), + path: Type.String(), + ok: Type.Literal(false), + steps: Type.Array(CheckStepSchema), + diagnostics: Type.Array(DefinitionDiagnosticSchema), + }, + {description: 'A definition file that failed to load.'}, + ), + ]), + ), + }, + {description: 'Projections verified end to end: extraction, comparison and renderer checks (`projections check --json`).'}, + ), +) + +// Environment ---------------------------------------------------------------------------------------------------- + +const Strategy = Type.Enum(['fresh', 'worktree', 'clone', 'sparse', 'none']) + +/** The JSON Schema of a workspace, `cli/workspaces#/$defs/workspace`. Its recorded state is `null` when unreadable. */ +export const WorkspaceSchema = define( + 'cli/workspaces', + 'workspace', + Closed({ + name: Type.String(), + strategy: Nullable(Strategy), + commit: Nullable(Type.String()), + at: Nullable(Type.String()), + scope: Type.Unknown({description: 'The scope it holds, for a sparse workspace; `null` otherwise.'}), + path: Type.String(), + busy: Type.Boolean({description: 'Whether a run is using it.'}), + prepared: Type.Array(Closed({id: Type.String(), status: Nullable(Type.String()), at: Nullable(Type.String())})), + }), +) + +/** The JSON Schema of `projections.workspaces`, what `projections workspace list --json` prints. */ +export const CliWorkspacesSchema = define( + 'cli/workspaces', + undefined, + Document( + 'projections.workspaces', + {directory: Type.String(), workspaces: Type.Array(WorkspaceSchema)}, + {description: 'The workspaces Projections keeps for the repository (`projections workspace list --json`).'}, + ), +) + +/** The JSON Schema of `projections.workspace-clean`, what `projections workspace clean --json` prints. */ +export const CliWorkspaceCleanSchema = define( + 'cli/workspace-clean', + undefined, + Document( + 'projections.workspace-clean', + {removed: Type.Array(Type.String(), {description: 'The workspaces removed; busy ones are kept.'})}, + {description: 'The workspaces `projections workspace clean --json` removed.'}, + ), +) + +/** A prepare step's last run in the working tree. */ +const LastRun = Closed({ + key: Type.String(), + at: Type.String(), + durationMs: Count, + log: Type.String(), + status: Type.Enum(['succeeded', 'failed']), + error: Type.Optional(Type.String()), +}) + +/** The JSON Schema of the environment report, `cli/doctor#/$defs/environment`. */ +export const EnvironmentReportSchema = define( + 'cli/doctor', + 'environment', + Closed({ + workspace: Type.Union([ + Closed({strategy: Strategy, source: Type.Enum(['flag', 'config', 'environment', 'automatic']), reason: Type.String()}), + Closed({error: Type.String()}), + ]), + workspaces: Type.Optional(Type.Array(WorkspaceSchema)), + workspacesError: Type.Optional(Type.String()), + declared: Type.Optional(Nullable(Type.String(), {description: 'The environment file, or `null` when none is declared.'})), + error: Type.Optional(Type.String()), + prepare: Type.Optional( + Type.Array( + Closed({ + id: Type.String(), + run: Type.Array(Type.String()), + directory: Type.String(), + key: Type.String(), + state: Type.Enum(['current', 'stale', 'failed', 'never']), + last: Type.Optional(LastRun), + }), + ), + ), + toolchain: Type.Optional(Type.Array(Type.Array(Type.String()))), + devcontainer: Type.Optional(Nullable(Type.String())), + missing: Type.Optional(Type.Array(Type.String())), + }), +) + +/** A doctor finding. */ +export const DoctorItemSchema = define( + 'cli/doctor', + 'item', + Closed({status: Type.Enum(['pass', 'warn', 'fail']), title: Type.String(), message: Type.String()}), +) + +/** The JSON Schema of `projections.doctor`, what `projections doctor --json` prints. */ +export const CliDoctorSchema = define( + 'cli/doctor', + undefined, + Document( + 'projections.doctor', + { + ok: Type.Boolean(), + items: Type.Array(DoctorItemSchema), + projections: Type.Array(Closed({id: Identifier, title: Type.String(), ok: Type.Boolean(), items: Type.Array(DoctorItemSchema)})), + environment: Type.Optional(EnvironmentReportSchema), + }, + {description: 'What the checkout needs to run its projections, found without running anything (`projections doctor --json`).'}, + ), +) + +/** The JSON Schema of `projections.prepare`, what `projections prepare --json` prints. */ +export const CliPrepareSchema = define( + 'cli/prepare', + undefined, + Document( + 'projections.prepare', + { + target: Type.String({description: '`working-tree`, or the commit whose workspace was prepared.'}), + environment: Type.String({description: 'The environment file.'}), + root: Type.String({description: 'Where the steps ran.'}), + strategy: Type.Optional(Type.Enum(['worktree', 'clone', 'sparse'], {description: "The workspace's strategy, for a commit."})), + notes: Type.Optional(Type.Array(Type.String())), + steps: Type.Array( + Type.Union([ + Closed({id: Type.String(), key: Type.String(), status: Type.Literal('current')}, {description: 'Unchanged keys: not run.'}), + Closed({id: Type.String(), key: Type.String(), status: Type.Literal('succeeded'), durationMs: Count, log: Type.String()}), + ]), + ), + }, + {description: "The environment's prepare steps, run in the working tree or a commit's workspace (`projections prepare --json`)."}, + ), +) + +// Batches -------------------------------------------------------------------------------------------------------- + +/** The JSON Schema of one batch result, `cli/batch#/$defs/result`. */ +export const BatchResultSchema = define( + 'cli/batch', + 'result', + Closed( + { + id: Identifier, + status: Type.Enum(['extracted', 'changed', 'unchanged', 'head-only', 'base-only', 'error'], { + description: + '`extracted` (show), `changed` or `unchanged` (compared), `head-only` or `base-only` (one revision defines it, shown alone), or `error`.', + }), + projectionId: Type.Optional(annotated(Identifier, {description: "A bookmark's projection, for `bookmark run`, whose `id` is the bookmark's."})), + extraction: Type.Optional(ExtractionDocumentSchema), + comparison: Type.Optional(ComparisonDocumentSchema), + notices: Type.Optional(Type.Array(Type.String())), + review: Type.Optional( + Closed( + {reviewable: Count, content: Count, identity: Count, variation: Count}, + {description: "The engine's review counts of a comparison."}, + ), + ), + diagnostics: Type.Optional(Type.Array(CliDiagnosticSchema, {description: 'Why it failed, for `error`.'})), + definition: Type.Optional(annotated(DefinitionSchema, {description: 'Its definition, for `error` once it resolved.'})), + }, + {description: "One projection's (or bookmark's) result: its document, or why it failed."}, + ), +) + +/** The JSON Schema of `projections.batch`, what `show --all`, `compare --all` and `bookmark run` print with `--json` or write with `--output`. */ +export const CliBatchSchema = define( + 'cli/batch', + undefined, + Document( + 'projections.batch', + { + operation: Type.Enum(['show', 'compare', 'bookmarks']), + results: Type.Array(BatchResultSchema, {description: 'Ordered by ID.'}), + failed: annotated(Count, {description: 'Results whose status is `error`.'}), + }, + {description: 'Every projection (or bookmark) at once: `show --all`, `compare --all` and `bookmark run` with `--json` or `--output`.'}, + ), +) + +/** The JSON Schema of `projections.pull-request`, what `projections pr --json` prints. */ +export const CliPullRequestSchema = define( + 'cli/pull-request', + undefined, + Document( + 'projections.pull-request', + { + repository: Type.String({description: '`owner/name`.'}), + number: Count, + url: Type.String(), + base: Type.String(), + head: Type.String(), + mergeBase: Type.String(), + fork: Type.Boolean(), + execution: Type.Literal('untrusted'), + definition: Type.Literal('base'), + changedProjections: Type.Array(Closed({id: Identifier, notices: Type.Array(Type.String())})), + comparisons: CliBatchSchema, + }, + {description: "A pull request reviewed without running its code, with the base's definitions (`projections pr --json`)."}, + ), +) + +// Extractors ----------------------------------------------------------------------------------------------------- + +const ExtractorProperties = { + id: Identifier, + title: Type.String(), + description: Type.String(), + schema: Type.String({description: 'The domain schema its extractions use, such as `graph/v0`.'}), + renderer: Type.String({description: 'The built-in renderer its definition template uses.'}), + trust: Type.Enum(['none', 'when-executing-tools'], {description: 'Whether it runs repository code (anything but `none`).'}), + access: Type.Enum(['files', 'checkout'], {description: 'File reads only, or a checkout.'}), + determinism: Type.Enum(['pure', 'environmental', 'observed']), + inputs: Dictionary(Type.String(), {description: 'Its inputs, each with what it means.'}), + template: annotated(DefinitionSchema, {description: 'The definition `projections init --extractor` writes.'}), + detects: Type.Array(Type.String(), {description: 'The file patterns that mean it may apply.'}), +} + +/** The JSON Schema of a built-in extractor, `cli/extractors#/$defs/extractor`. */ +export const ExtractorDescriptorSchema = define('cli/extractors', 'extractor', Closed(ExtractorProperties)) + +/** The JSON Schema of `projections.extractors`, what `projections extractor list --json` prints. */ +export const CliExtractorsSchema = define( + 'cli/extractors', + undefined, + Document( + 'projections.extractors', + {extractors: Type.Array(ExtractorDescriptorSchema)}, + {description: 'The built-in extractors (`projections extractor list --json`).'}, + ), +) + +/** The JSON Schema of `projections.extractor`, what `projections extractor view --json` prints. */ +export const CliExtractorSchema = define( + 'cli/extractor', + undefined, + Document('projections.extractor', ExtractorProperties, { + description: 'One built-in extractor: its inputs, schema, renderer and definition template (`projections extractor view --json`).', + }), +) + +// Validate ------------------------------------------------------------------------------------------------------- + +/** The JSON Schema of what `projections validate --json` prints. Its `format` is the validated document's, so it has no kind of its own. */ +export const CliValidationSchema = define( + 'cli/validation', + undefined, + Closed( + { + valid: Type.Literal(true), + format: Type.Enum(['projections.extraction', 'projections.comparison', 'projections.scenarios', 'extraction'], { + description: 'What was validated: a saved extraction, a saved comparison, scenarios, or a bare extraction.', + }), + scenarios: Type.Optional(annotated(Count, {description: 'The scenarios, for `projections.scenarios`.'})), + reproduced: Type.Optional( + Type.Literal(false, {description: "A comparison by a custom comparator, which wasn't recomputed without `--comparator`."}), + ), + }, + {description: 'A valid saved extraction, comparison or scenarios document (`projections validate --json`).'}, + ), +) + +// Viewer --------------------------------------------------------------------------------------------------------- + +const Side = Closed({ref: Type.String(), commit: Nullable(Type.String())}) + +/** The JSON Schema of `projections.view`, what `projections view show`, `view current` and `view refresh` print with `--json`. */ +export const CliViewSchema = define( + 'cli/view', + undefined, + Type.Union( + [ + Document( + 'projections.view', + { + shown: Type.Literal(false), + viewer: Passed('The viewer.'), + url: Passed("The viewer's page."), + viewers: Passed('The other viewers running.'), + }, + {description: 'Nothing is shown yet.'}, + ), + Document( + 'projections.view', + { + shown: Type.Literal(true), + surface: Type.Literal('viewer'), + viewer: Passed('The viewer.'), + url: Passed("The viewer's page."), + chosenBy: Passed('Who chose the projection: the agent, or the person from the page.'), + viewers: Passed('The other viewers running.'), + pages: Count, + seen: Passed('What the open pages saw.'), + projection: Type.String(), + title: Type.String(), + choice: Passed('How the revisions were chosen.'), + compared: Type.String(), + before: Nullable(Side), + after: Side, + scenario: Passed('The scenario shown, for fixtures.'), + mode: Passed('The comparison mode.'), + selection: Passed('What the person selected, from the current page.'), + page: Passed("The current page's view."), + failures: Passed("The current page's failures."), + document: Nullable( + Closed({ + path: Type.String(), + format: Passed("The document's format."), + renderer: Type.Union([Closed({builtIn: Passed('The built-in renderer.')}), Closed({bundle: Type.String()})]), + }), + {description: 'The saved document shown, instead of the repository.'}, + ), + rendererBuild: Nullable( + Closed({ + phase: Type.String(), + error: Passed('Why the build failed.'), + script: Passed('The build script.'), + package: Passed("The renderer's package."), + bundled: Type.Boolean(), + }), + ), + }, + {description: 'What the viewer shows.'}, + ), + Closed({error: Type.String()}, {description: 'The viewer refused; the command fails. It has no `format`.'}), + ], + {description: 'What the viewer shows and what the person selected (`projections view show|current|refresh --json`).'}, + ), +) + +/** The JSON Schema of `projections.screenshot`, what `projections view screenshot --json` prints. */ +export const CliScreenshotSchema = define( + 'cli/screenshot', + undefined, + Type.Union( + [ + Document( + 'projections.screenshot', + { + projection: Passed('The projection drawn.'), + scenario: Passed('The scenario drawn, or `null`.'), + before: Passed('The revision before, or `null`.'), + after: Passed('The revision after, or `null` for a scenario.'), + mode: Nullable(Type.String()), + progress: Passed('The comparison progress drawn.'), + theme: Type.String(), + width: Count, + height: Count, + notices: Type.Array(Type.String()), + bytes: Count, + }, + {description: 'A projection rendered by its renderer.'}, + ), + Document( + 'projections.screenshot', + { + page: Type.Literal(true), + viewer: Type.String(), + projection: Type.String(), + theme: Type.String(), + width: Count, + height: Count, + notices: Type.Array(Type.String()), + bytes: Count, + }, + {description: "The viewer's page, captured with `--page`."}, + ), + Closed({error: Type.String()}, {description: 'The viewer refused; the command fails. It has no `format`.'}), + ], + {description: 'The PNG `projections view screenshot --json` wrote, and what it shows.'}, + ), +) + +/** Every CLI document, by schema name; `packages/cli/test/json-output.test.mjs` validates the CLI's output against them. */ +export const cliSchemaDocuments = [ + {name: 'cli/adopt', title: 'CLI adopt', schema: CliAdoptSchema}, + {name: 'cli/batch', title: 'CLI batch', schema: CliBatchSchema}, + {name: 'cli/check', title: 'CLI check', schema: CliCheckSchema}, + {name: 'cli/doctor', title: 'CLI doctor', schema: CliDoctorSchema}, + {name: 'cli/error', title: 'CLI error', schema: CliErrorSchema}, + {name: 'cli/explore', title: 'CLI explore candidates', schema: CliExploreSchema}, + {name: 'cli/extractor', title: 'CLI extractor', schema: CliExtractorSchema}, + {name: 'cli/extractors', title: 'CLI extractor list', schema: CliExtractorsSchema}, + {name: 'cli/list', title: 'CLI list', schema: CliListSchema}, + {name: 'cli/prepare', title: 'CLI prepare', schema: CliPrepareSchema}, + {name: 'cli/pull-request', title: 'CLI pull request review', schema: CliPullRequestSchema}, + {name: 'cli/screenshot', title: 'CLI viewer screenshot', schema: CliScreenshotSchema}, + {name: 'cli/sweep', title: 'CLI sweep', schema: CliSweepSchema}, + {name: 'cli/validation', title: 'CLI validation', schema: CliValidationSchema}, + {name: 'cli/view', title: 'CLI viewer', schema: CliViewSchema}, + {name: 'cli/workspace-clean', title: 'CLI workspace clean', schema: CliWorkspaceCleanSchema}, + {name: 'cli/workspaces', title: 'CLI workspace list', schema: CliWorkspacesSchema}, +] + +export type CliError = Static +export type CliErrorReport = Static +export type CliDiagnostic = Static +export type CliList = Static +export type InvalidDefinition = Static +export type Candidate = Static +export type CliExplore = Static +export type SweepChange = Static +export type SweepProjection = Static +export type SweepCell = Static +export type CliSweep = Static +export type CliAdopt = Static +export type CheckStep = Static +export type CliCheck = Static +export type Workspace = Static +export type CliWorkspaces = Static +export type CliWorkspaceClean = Static +export type EnvironmentReport = Static +export type CliDoctor = Static +export type CliPrepare = Static +export type BatchResult = Static +export type CliBatch = Static +export type CliPullRequest = Static +export type ExtractorDescriptor = Static +export type CliExtractors = Static +export type CliExtractor = Static +export type CliValidation = Static +export type CliView = Static +export type CliScreenshot = Static diff --git a/packages/schemas/src/typebox/index.ts b/packages/schemas/src/typebox/index.ts index fadf14d4b..9a11435bc 100644 --- a/packages/schemas/src/typebox/index.ts +++ b/packages/schemas/src/typebox/index.ts @@ -1,5 +1,6 @@ import type {TSchema} from 'typebox' import * as bookmarks from './bookmarks.js' +import {cliSchemaDocuments} from './cli.js' import * as comparison from './comparison.js' import * as comparatorFile from './comparator.js' import * as comparatorTests from './comparator-tests.js' @@ -12,6 +13,7 @@ import * as renderer from './renderer.js' import * as scenarios from './scenarios.js' export * from './bookmarks.js' +export * from './cli.js' export * from './comparison.js' export * from './comparator.js' export * from './comparator-tests.js' @@ -48,4 +50,5 @@ export const schemaDocuments: SchemaDocument[] = [ {name: 'bookmarks', title: 'Projections bookmarks', schema: bookmarks.BookmarksSchema}, {name: 'renderer', title: 'Projections renderer manifest', schema: renderer.RendererManifestSchema}, ...domainSchemaDocuments, + ...cliSchemaDocuments, ] diff --git a/packages/schemas/test/schemas.test.mjs b/packages/schemas/test/schemas.test.mjs index d3a719fa8..e5943e517 100644 --- a/packages/schemas/test/schemas.test.mjs +++ b/packages/schemas/test/schemas.test.mjs @@ -41,6 +41,23 @@ test('every published schema is draft 2020-12 at its URL, compiles strictly and 'architecture', 'artifact', 'bookmarks', + 'cli/adopt', + 'cli/batch', + 'cli/check', + 'cli/doctor', + 'cli/error', + 'cli/explore', + 'cli/extractor', + 'cli/extractors', + 'cli/list', + 'cli/prepare', + 'cli/pull-request', + 'cli/screenshot', + 'cli/sweep', + 'cli/validation', + 'cli/view', + 'cli/workspace-clean', + 'cli/workspaces', 'comparator', 'comparator-tests', 'comparison', From e45fbbc85a61c7215f81e91dc66c5424ca16c745 Mon Sep 17 00:00:00 2001 From: agorischek <6295280+agorischek@users.noreply.github.com> Date: Fri, 4 Dec 2026 21:31:31 +0000 Subject: [PATCH 2/6] CLI JSON schemas: tests, typed Action decoder, docs Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> --- docs/contracts.md | 6 +- docs/runner/batches.md | 5 +- docs/runner/commands.md | 19 +- package-lock.json | 1 + packages/cli/package.json | 1 + packages/cli/src/commands/authoring.rs | 5 +- packages/cli/src/commands/explore.rs | 5 +- packages/cli/src/commands/view.rs | 11 +- packages/cli/test/json-output.test.mjs | 202 ++++++++++++++++++ .../integrations/github-action/package.json | 3 +- .../integrations/github-action/src/lib.mjs | 33 ++- .../integrations/github-action/tsconfig.json | 11 + packages/schemas/schemas/cli/list/v0.json | 8 +- packages/schemas/src/index.ts | 36 ++++ packages/schemas/src/typebox/cli.ts | 40 +++- 15 files changed, 365 insertions(+), 21 deletions(-) create mode 100644 packages/cli/test/json-output.test.mjs create mode 100644 packages/integrations/github-action/tsconfig.json diff --git a/docs/contracts.md b/docs/contracts.md index 68730cd62..1866e5c45 100644 --- a/docs/contracts.md +++ b/docs/contracts.md @@ -121,7 +121,11 @@ the runtime validator together, so a hand-written type never stands in for a checked one. - **Published contracts** (`src/typebox`): the versioned documents listed above, - along with their `$id`s and reference pages. + along with their `$id`s and reference pages. They include every document the + CLI prints with `--json` or writes with `--output` (`cli//v0.json`, such + as `cli/sweep/v0.json` for `projections.sweep`), and + `packages/cli/test/json-output.test.mjs` validates the CLI's real output + against them, so a document's shape changes only with its schema. - **The local runner's API** (`src/runner`, exported as `@githubnext/projections-schemas/runner`): the responses from the Inspector service (`projections view` and [`serve --stdio`](runner/stdio-backend.md)) diff --git a/docs/runner/batches.md b/docs/runner/batches.md index 59c950fca..e0766ee66 100644 --- a/docs/runner/batches.md +++ b/docs/runner/batches.md @@ -35,7 +35,10 @@ single operations follow the same explicit trust rules. To inspect what a revision defines without running any extractors, run `list [--revision REF] [--json]`. It reads only the definition directories and prints -`{"format": "projections.list", "version": 0, "revision", "projections": [{"id", "title", "renderer", "requiresTrust", "rendererRequiresTrust", "definition"}]}`. +`{"format": "projections.list", "version": 0, "revision", "projections": [{"id", "title", "renderer", "requiresTrust", "rendererRequiresTrust", "definition"}], "invalid", "defaults"}` +([schema](../reference/schemas/cli-list.md)): `invalid` lists the definition +files that don't load, with their diagnostics, and `defaults` says whether the +projections are the built-in defaults because the working tree defines none. Here `requiresTrust` indicates that the extractor runs repository code, while `rendererRequiresTrust` means the custom renderer differs from the bundle at the revision's merge base with the default branch (`refs/remotes/origin/HEAD`), or diff --git a/docs/runner/commands.md b/docs/runner/commands.md index c551cba80..60ded76ae 100644 --- a/docs/runner/commands.md +++ b/docs/runner/commands.md @@ -298,12 +298,19 @@ counts, and each step in order with its changes (`Added`, `Removed`, `Changed`, Pass `--json` to print the structured document instead: `projections.extraction` (version 0), `projections.comparison` (version 0), or—for `--all` and -`bookmark run`—`projections.batch` (version 0). Pass `--output FILE` to write -that JSON to a new file (never overwriting an existing one), pretty-printed with -two-space indentation (falling back to compact JSON only if needed to fit the -size limits) and printing nothing to stdout. Comparison documents include -definition notices in `notices` (omitted when empty), as do batch items; in JSON -modes, notices are also echoed to stderr as `projections: note: ...`. +`bookmark run`—`projections.batch` (version 0). Every command's `--json` +document names its kind in `format` and its version in `version`, and has a +published schema: the saved documents' and, for the rest, +`https://schemas.projections.githubnext.com/cli//v0.json` (see +[the schema reference](../reference/schemas/README.md)). The exceptions are +`validate --json`, whose `format` names the validated document, and a `view` +command the viewer refused, which prints `{"error": …}`. Pass `--output FILE` to +write that JSON to a new file (never overwriting an existing one), +pretty-printed with two-space indentation (falling back to compact JSON only if +needed to fit the size limits) and printing nothing to stdout. Comparison +documents include definition notices in `notices` (omitted when empty), as do +batch items; in JSON modes, notices are also echoed to stderr as +`projections: note: ...`. If a declared input (a file, folder, or glob named in a built-in's `inputs`) does not exist at a revision, the built-in produces an empty extraction and diff --git a/package-lock.json b/package-lock.json index fc4108988..447d43a73 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10554,6 +10554,7 @@ "@githubnext/projections-renderer-testing": "0.3.2", "@githubnext/projections-typescript-support": "0.3.2", "@playwright/test": "^1.55.0", + "ajv": "^8.17.1", "yaml": "^2.8.0" } }, diff --git a/packages/cli/package.json b/packages/cli/package.json index 53c4ff008..f341a4869 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -22,6 +22,7 @@ "@githubnext/projections-renderer-testing": "0.3.2", "@githubnext/projections-typescript-support": "0.3.2", "@playwright/test": "^1.55.0", + "ajv": "^8.17.1", "yaml": "^2.8.0" } } diff --git a/packages/cli/src/commands/authoring.rs b/packages/cli/src/commands/authoring.rs index 350ef796b..d4b53dc01 100644 --- a/packages/cli/src/commands/authoring.rs +++ b/packages/cli/src/commands/authoring.rs @@ -389,7 +389,10 @@ pub fn extractor(command: Extractor) -> Result<()> { .with_context(|| format!("No built-in extractor {id}; projections extractor list shows them"))?; if json { let mut document = json!({"format": "projections.extractor", "version": 0}); - document.as_object_mut().unwrap().extend(descriptor.as_object().cloned().unwrap_or_default()); + document + .as_object_mut() + .unwrap() + .extend(descriptor.as_object().cloned().unwrap_or_default()); return output(&document, None, 1024 * 1024); } let mut text = format!( diff --git a/packages/cli/src/commands/explore.rs b/packages/cli/src/commands/explore.rs index cb72b12e4..6ce8bae46 100644 --- a/packages/cli/src/commands/explore.rs +++ b/packages/cli/src/commands/explore.rs @@ -185,7 +185,10 @@ pub fn adopt(directory: &Path, args: Adopt) -> Result<()> { let result = onboard::adopt(&root, &candidates, &args.projections, &highlights, None, args.dry_run)?; if args.json { let mut document = json!({"format": "projections.adopt", "version": 0}); - document.as_object_mut().unwrap().extend(result.as_object().cloned().unwrap_or_default()); + document + .as_object_mut() + .unwrap() + .extend(result.as_object().cloned().unwrap_or_default()); document["notes"] = json!(notes); return output(&document, None, 32 * 1024 * 1024); } diff --git a/packages/cli/src/commands/view.rs b/packages/cli/src/commands/view.rs index c2ef501d6..754cf1e92 100644 --- a/packages/cli/src/commands/view.rs +++ b/packages/cli/src/commands/view.rs @@ -395,9 +395,16 @@ async fn view_tool(root: &Path, command: ViewCommand) -> Result<()> { let structured = if outcome.error { outcome.structured.clone() } else { - let format = if name == "screenshot" { "projections.screenshot" } else { "projections.view" }; + let format = if name == "screenshot" { + "projections.screenshot" + } else { + "projections.view" + }; let mut document = json!({"format": format, "version": 0}); - document.as_object_mut().unwrap().extend(outcome.structured.as_object().cloned().unwrap_or_default()); + document + .as_object_mut() + .unwrap() + .extend(outcome.structured.as_object().cloned().unwrap_or_default()); document }; println!("{}", serde_json::to_string(&structured)?); diff --git a/packages/cli/test/json-output.test.mjs b/packages/cli/test/json-output.test.mjs new file mode 100644 index 000000000..c11105cef --- /dev/null +++ b/packages/cli/test/json-output.test.mjs @@ -0,0 +1,202 @@ +// Every document the CLI prints with --json, or writes with --output, matches its published schema +// (packages/schemas/schemas/cli/*, and the saved-document and bookmarks schemas). A change to a document's shape fails +// here until its TypeBox source (packages/schemas/src/typebox/cli.ts) changes with it. +import assert from 'node:assert/strict' +import {execFileSync} from 'node:child_process' +import {mkdir, mkdtemp, readdir, readFile, realpath, rm, writeFile} from 'node:fs/promises' +import {tmpdir} from 'node:os' +import path from 'node:path' +import test, {after} from 'node:test' +import {fileURLToPath} from 'node:url' +import Ajv2020 from 'ajv/dist/2020.js' +import {executionEnvironment, pullRequestTools, runBounded} from './process.mjs' +import {commit, fixture} from './repository.mjs' + +const executable = fileURLToPath(new URL(`../dist/projections${process.platform === 'win32' ? '.exe' : ''}`, import.meta.url)) +const schemas = fileURLToPath(new URL('../../schemas/schemas/', import.meta.url)) +const host = 'https://schemas.projections.githubnext.com/' + +const ajv = new Ajv2020({allErrors: true, strictTuples: false}) +for (const file of await readdir(schemas, {recursive: true})) { + if (file.endsWith('v0.json')) ajv.addSchema(JSON.parse(await readFile(path.join(schemas, file), 'utf8'))) +} +const cliSchemas = (await readdir(path.join(schemas, 'cli'))).map(name => `cli/${name}`) +/** The schemas a document was checked against, so the last test can tell which went untested. */ +const checked = new Set() + +/** Asserts that `text`, what the CLI printed, is one JSON document `name`'s schema accepts; returns the document. */ +function conforms(name, text) { + const document = JSON.parse(text) + const validate = ajv.getSchema(`${host}${name}/v0.json`) + assert.ok(validate, `no schema ${name}`) + const errors = validate(document) + ? [] + : validate.errors.map(error => `${error.instancePath || '/'} ${error.message} ${JSON.stringify(error.params)}`) + assert.deepEqual(errors, [], `${name}: the CLI's output doesn't match packages/schemas/schemas/${name}/v0.json`) + checked.add(name) + return document +} + +// The CLI's own cache, as the environment has no HOME; a build without the Inspector's browser assets runs the viewer +// with PROJECTIONS_INSPECTOR_ASSETS instead. +const cache = await mkdtemp(path.join(tmpdir(), 'projections-json-cache-')) +after(() => rm(cache, {recursive: true, force: true})) +const environment = () => ({ + ...executionEnvironment(process.env, ['PROJECTIONS_INSPECTOR_ASSETS']), + PROJECTIONS_CACHE_DIR: cache, +}) + +/** Runs the CLI; resolves its stdout whether it succeeds or fails, and whether it failed. */ +async function run(cwd, args, env = environment()) { + try { + const {stdout} = await runBounded(executable, args, {label: 'Projections CLI', cwd, env, timeoutMs: 120_000}) + return {stdout, failed: false} + } catch (error) { + if (!error.output) throw error + return {stdout: error.output.stdout, stderr: error.output.stderr, failed: true} + } +} +const ok = async (cwd, args, env) => { + const result = await run(cwd, args, env) + assert.equal(result.failed, false, `projections ${args.join(' ')} failed: ${result.stderr}`) + return result.stdout +} + +const workflow = `name: CI +on: push +jobs: + test: + runs-on: ubuntu-latest + steps: + - run: echo test +` +const environmentFile = { + format: 'projections.environment', + version: 0, + prepare: [{id: 'noop', run: ['node', '-e', ''], key: ['services.json']}], +} + +/** The polyglot example, with a workflow, an environment, a built-in projection, bookmarks and two more commits. */ +async function repository() { + const {root, before} = await fixture() + await mkdir(path.join(root, '.github', 'workflows'), {recursive: true}) + await writeFile(path.join(root, '.github', 'workflows', 'ci.yml'), workflow) + await writeFile(path.join(root, '.github', 'projections', 'environment.json'), JSON.stringify(environmentFile)) + await ok(root, ['init', 'files', '--extractor', 'repository-map', '--no-skill']) + await writeFile( + path.join(root, '.projections-bookmarks.json'), + JSON.stringify({ + format: 'projections.bookmarks', + version: 0, + bookmarks: [{id: 'working', title: 'Working', projectionId: 'files', before: 'HEAD'}], + }), + ) + const middle = commit(root) + await writeFile(path.join(root, 'new.txt'), 'changed') + const head = commit(root) + return {root, before, middle, head} +} + +test('explore, sweep and adopt print their documents', async () => { + const {root} = await repository() + const explored = conforms('cli/explore', await ok(root, ['explore', '--list', '--json'])) + assert.ok(explored.candidates.length > 0) + const swept = conforms('cli/sweep', (await run(root, ['explore', '--sweep', '--json', '--last', '2', '--trust'])).stdout) + assert.ok(swept.cells.length > 0) + const candidate = explored.candidates.find(item => item.adopted === null && !item.requiresTrust) + assert.ok(candidate, 'a candidate to adopt') + conforms('cli/adopt', await ok(root, ['adopt', candidate.id, '--dry-run', '--json', '--bookmarks', '1', '--last', '2'])) + conforms('cli/adopt', await ok(root, ['adopt', candidate.id, '--json', '--bookmarks', '0'])) +}) + +test('check, doctor, prepare and the workspaces print their documents', async () => { + const {root, middle} = await repository() + const report = conforms('cli/check', (await run(root, ['check', '--json', '--no-render', '--trust'])).stdout) + assert.ok(report.projections.length > 0) + // Doctor exits nonzero when something is missing, such as a browser. + conforms('cli/doctor', (await run(root, ['doctor', '--json'])).stdout) + conforms('cli/prepare', await ok(root, ['prepare', '--json', '--trust'])) + conforms('cli/prepare', await ok(root, ['prepare', '--json', '--trust', '--revision', middle, '--workspace', 'worktree'])) + conforms('cli/workspaces', await ok(root, ['workspace', 'list', '--json'])) + conforms('cli/doctor', (await run(root, ['doctor', '--json'])).stdout) + conforms('cli/workspace-clean', await ok(root, ['workspace', 'clean', '--json'])) + // An invalid definition file is its own entry. + await writeFile(path.join(root, '.github', 'projections', 'broken.json'), '{"id": "broken"}') + const broken = conforms('cli/check', (await run(root, ['check', '--json', '--no-render', '-p', 'broken'])).stdout) + assert.equal(broken.ok, false) +}) + +test('list, batches, bookmarks, saved documents, validate, extractors and errors print their documents', async () => { + const {root, before, middle, head} = await repository() + conforms('cli/list', await ok(root, ['list', '--json'])) + conforms('cli/batch', await ok(root, ['show', '--all', '--json', '--trust'])) + conforms('cli/batch', (await run(root, ['show', '--all', '--json'])).stdout) + conforms('cli/batch', await ok(root, ['compare', `${before}..${head}`, '--all', '--json', '--trust'])) + conforms('bookmarks', await ok(root, ['bookmark', 'list', '--json'])) + conforms('cli/batch', await ok(root, ['bookmark', 'run', '--json', '--trust'])) + conforms('extraction-document', await ok(root, ['show', head, '-p', 'files', '--json'])) + const comparison = conforms('comparison-document', await ok(root, ['compare', `${middle}..${head}`, '-p', 'files', '--json'])) + const saved = path.join(root, 'saved.json') + await writeFile(saved, JSON.stringify(comparison)) + conforms('cli/validation', await ok(root, ['validate', saved, '--json'])) + const extractors = conforms('cli/extractors', await ok(root, ['extractor', 'list', '--json'])) + for (const {id} of extractors.extractors) conforms('cli/extractor', await ok(root, ['extractor', 'view', id, '--json'])) + const failure = await run(root, ['show', '-p', 'nope', '--json']) + assert.equal(failure.failed, true) + conforms('cli/error', failure.stdout) + // A projection whose definition file is invalid. + await writeFile(path.join(root, '.github', 'projections', 'broken.json'), '{"id": "broken"}') + const listed = conforms('cli/list', (await run(root, ['list', '--json'])).stdout) + assert.equal(listed.invalid.length, 1) +}) + +test( + 'pr prints its document', + // On Windows the CLI runs gh.exe and git.exe, which /bin/sh stand-ins can't replace. + {skip: process.platform === 'win32' && 'Stands in for gh and git with /bin/sh scripts'}, + async t => { + const {root, middle: base, head} = await repository() + const tools = path.join(root, '..', `pr-tools-${path.basename(root)}`) + await mkdir(tools) + t.after(() => rm(tools, {recursive: true, force: true})) + await pullRequestTools(tools, { + gitPath: await realpath(execFileSync('which', ['git'], {encoding: 'utf8'}).trim()), + repository: root, + base, + head, + metadata: { + html_url: 'https://github.com/example/tiny/pull/42', + base: {sha: base, repo: {id: 1, full_name: 'example/tiny'}}, + head: {sha: head, repo: {id: 2, full_name: 'example/fork'}}, + }, + }) + const env = {...environment(), PATH: `${tools}${path.delimiter}${process.env.PATH}`} + const pullRequests = path.join(tools, 'cache') + await mkdir(pullRequests) + const args = ['pr', '42', '-R', 'example/tiny', '--cache', pullRequests, '--id', 'files', '--id', 'services-node', '--json'] + conforms('cli/pull-request', (await run(root, args, env)).stdout) + }, +) + +test('the viewer commands print their documents', async t => { + const {root} = await repository() + t.after(() => run(root, ['view', 'stop'])) + conforms('cli/view', await ok(root, ['view', 'show', '-p', 'files', '--json'])) + conforms('cli/view', await ok(root, ['view', 'current', '--json'])) + conforms('cli/view', await ok(root, ['view', 'refresh', '--json'])) + // Where no browser can run (Chrome refuses to as root), the renderer's screenshot prints the refusal its schema + // allows and the page's prints nothing. + for (const page of [[], ['--page']]) { + const image = path.join(root, '..', `screenshot-${path.basename(root)}-${page.length}.png`) + t.after(() => rm(image, {force: true})) + const {stdout, failed} = await run(root, ['view', 'screenshot', '--out', image, ...page, '--json']) + if (stdout || !failed) conforms('cli/screenshot', stdout) + } +}) + +test('every CLI schema was checked against the CLI', {skip: process.platform === 'win32' && 'pr is skipped'}, () => { + assert.deepEqual( + cliSchemas.filter(name => !checked.has(name)), + [], + ) +}) diff --git a/packages/integrations/github-action/package.json b/packages/integrations/github-action/package.json index caccd60b2..e557ef3cd 100644 --- a/packages/integrations/github-action/package.json +++ b/packages/integrations/github-action/package.json @@ -6,7 +6,8 @@ "license": "MIT", "description": "The Projections GitHub Action's dependency-free scripts (action.yml is at the repository root)", "scripts": { - "test": "node --test test/*.test.mjs" + "test": "node --test test/*.test.mjs", + "typecheck": "tsc -p tsconfig.json" }, "devDependencies": { "@githubnext/projections-cli": "0.3.2", diff --git a/packages/integrations/github-action/src/lib.mjs b/packages/integrations/github-action/src/lib.mjs index 737427879..6ffd5ccd2 100644 --- a/packages/integrations/github-action/src/lib.mjs +++ b/packages/integrations/github-action/src/lib.mjs @@ -77,15 +77,31 @@ function notices(values) { return list.length ? {notices: list} : {} } +/** @typedef {import('@githubnext/projections-schemas').CliBatch} CliBatch */ + /** - * Splits a CLI batch document into one file per projection plus the artifact - * manifest. Returns the files to write, relative to the artifact root. + * The CLI's `projections.batch` document for `operation` (`cli/batch/v0.json`), typed once its envelope checks out. + * `splitBatch` checks each result again as it splits it. + * @param {unknown} value + * @param {CliBatch['operation']} operation + * @returns {CliBatch} */ -export function splitBatch(batch, {subject, repository, run, cli, action, trust}) { - const operation = subject.kind === 'pull-request' ? 'compare' : 'show' +function decodeBatch(value, operation) { + const batch = /** @type {Partial | null} */ (value) if (batch?.format !== 'projections.batch' || batch.version !== 0 || batch.operation !== operation || !Array.isArray(batch.results)) { throw new Error(`The CLI did not produce a ${operation} batch document`) } + return /** @type {CliBatch} */ (batch) +} + +/** + * Splits a CLI batch document into one file per projection plus the artifact + * manifest. Returns the files to write, relative to the artifact root. + * @param {unknown} parsed The batch document the CLI wrote, parsed. + */ +export function splitBatch(parsed, {subject, repository, run, cli, action, trust}) { + const operation = subject.kind === 'pull-request' ? 'compare' : 'show' + const batch = decodeBatch(parsed, operation) if (batch.results.length > maxProjections) { throw new Error(`At most ${maxProjections} projections fit in one artifact; this run produced ${batch.results.length}`) } @@ -290,6 +306,11 @@ export function hostedLink(manifest, hostedUrl) { * `documents` maps each projection ID to its document from the artifact. Details that don't fit `limit` bytes * are left out, with a note. */ +/** + * @param {any} manifest + * @param {Map} documents + * @param {{hostedUrl?: string, artifactName?: string, snapshots?: any, limit?: number}} [options] + */ export function summaryMarkdown(manifest, documents, {hostedUrl, artifactName = 'projections', snapshots, limit = summaryLimit} = {}) { const {subject} = manifest const counts = new Map() @@ -466,6 +487,10 @@ function picture(light, dark, alt) { * The comment's snapshot section: before and after thumbnails where their * images were published, else a link to the snapshots artifact. */ +/** + * @param {any} index + * @param {{images?: any, artifactUrl?: string}} [options] + */ export function snapshotSection(index, {images, artifactUrl} = {}) { const files = index?.snapshots ?? [] const ids = [...new Set(files.map(file => file.id))] diff --git a/packages/integrations/github-action/tsconfig.json b/packages/integrations/github-action/tsconfig.json new file mode 100644 index 000000000..1fdd92df7 --- /dev/null +++ b/packages/integrations/github-action/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "../../../tsconfig.base.json", + "compilerOptions": { + "noEmit": true, + "allowJs": true, + "checkJs": true, + "noImplicitAny": false, + "types": ["node"] + }, + "include": ["src/lib.mjs"] +} diff --git a/packages/schemas/schemas/cli/list/v0.json b/packages/schemas/schemas/cli/list/v0.json index 1da3de225..e3f08d147 100644 --- a/packages/schemas/schemas/cli/list/v0.json +++ b/packages/schemas/schemas/cli/list/v0.json @@ -5,7 +5,7 @@ "description": "The projections a revision defines, read without running anything (`projections list --json`).", "type": "object", "additionalProperties": false, - "required": ["format", "version", "revision", "projections", "invalid"], + "required": ["format", "version", "revision", "projections", "invalid", "defaults"], "properties": { "format": {"type": "string", "const": "projections.list"}, "version": {"type": "number", "const": 0}, @@ -29,7 +29,11 @@ } } }, - "invalid": {"type": "array", "items": {"$ref": "#/$defs/invalidDefinition"}} + "invalid": {"type": "array", "items": {"$ref": "#/$defs/invalidDefinition"}}, + "defaults": { + "description": "Whether the projections are the built-in defaults, because the working tree defines none of its own.", + "type": "boolean" + } }, "$defs": { "definitionDiagnostic": { diff --git a/packages/schemas/src/index.ts b/packages/schemas/src/index.ts index 03270539f..9cca4bfbd 100644 --- a/packages/schemas/src/index.ts +++ b/packages/schemas/src/index.ts @@ -543,3 +543,39 @@ export function escapeProse(text: string): string { export function codeSpan(text: string): string { return `\`${escapeProse(text)}\`` } + +/** + * The documents the CLI prints with `--json` (or writes with `--output`), as their published schemas + * (`cli//v0.json`) type them. + */ +export type { + BatchResult, + Candidate, + CheckStep, + CliAdopt, + CliBatch, + CliCheck, + CliDiagnostic, + CliDoctor, + CliError, + CliErrorReport, + CliExplore, + CliExtractor, + CliExtractors, + CliList, + CliPrepare, + CliPullRequest, + CliScreenshot, + CliSweep, + CliValidation, + CliView, + CliWorkspaceClean, + CliWorkspaces, + EnvironmentReport, + ExtractorDescriptor, + InvalidDefinition, + SweepCell, + SweepChange, + SweepProjection, + Workspace, +} from './typebox/cli.js' diff --git a/packages/schemas/src/typebox/cli.ts b/packages/schemas/src/typebox/cli.ts index dfcb54f6d..516fdae23 100644 --- a/packages/schemas/src/typebox/cli.ts +++ b/packages/schemas/src/typebox/cli.ts @@ -113,6 +113,9 @@ export const CliListSchema = define( }), ), invalid: Type.Array(InvalidDefinitionSchema), + defaults: Type.Boolean({ + description: 'Whether the projections are the built-in defaults, because the working tree defines none of its own.', + }), }, {description: 'The projections a revision defines, read without running anything (`projections list --json`).'}, ), @@ -230,7 +233,9 @@ export const SweepCellSchema = define( changes: Type.Optional(Count), steps: Type.Optional(Count), counts: Type.Optional(Dictionary(Count, {description: 'Changes by status (`added`, `removed`, `modified`, …).'})), - versionOnly: Type.Optional(Type.Literal(true, {description: 'Changed, but only version strings moved (a dependency or action bump).'})), + versionOnly: Type.Optional( + Type.Literal(true, {description: 'Changed, but only version strings moved (a dependency or action bump).'}), + ), error: Type.Optional(Type.String()), stderr: Type.Optional(Type.String({description: "The end of a failed extractor's stderr."})), }, @@ -493,7 +498,9 @@ export const BatchResultSchema = define( description: '`extracted` (show), `changed` or `unchanged` (compared), `head-only` or `base-only` (one revision defines it, shown alone), or `error`.', }), - projectionId: Type.Optional(annotated(Identifier, {description: "A bookmark's projection, for `bookmark run`, whose `id` is the bookmark's."})), + projectionId: Type.Optional( + annotated(Identifier, {description: "A bookmark's projection, for `bookmark run`, whose `id` is the bookmark's."}), + ), extraction: Type.Optional(ExtractionDocumentSchema), comparison: Type.Optional(ComparisonDocumentSchema), notices: Type.Optional(Type.Array(Type.String())), @@ -740,32 +747,61 @@ export const cliSchemaDocuments = [ {name: 'cli/workspaces', title: 'CLI workspace list', schema: CliWorkspacesSchema}, ] +/** A `projections.error` document: what a command run with `--json` or `--output` prints when it fails. */ export type CliError = Static +/** A failure report: a stable code, the message, diagnostics, and optionally a hint and an extractor's stderr. */ export type CliErrorReport = Static +/** One problem the engine or runner found, in a failure report or a batch result. */ export type CliDiagnostic = Static +/** The `projections.list` document `projections list --json` prints. */ export type CliList = Static +/** A definition file that doesn't load, as `projections list --json` lists it. */ export type InvalidDefinition = Static +/** A built-in projection `projections explore` proposes, as a trial definition. */ export type Candidate = Static +/** The `projections.explore` document `projections explore --list --json` prints. */ export type CliExplore = Static +/** A change a sweep tries: a revision compared with the one before it. */ export type SweepChange = Static +/** One swept projection: its status and, once ready, its tally over the swept changes. */ export type SweepProjection = Static +/** One projection on one swept change: its comparison counts, or why it failed. */ export type SweepCell = Static +/** The `projections.sweep` document `projections explore --sweep --json` prints. */ export type CliSweep = Static +/** The `projections.adopt` document `projections adopt --json` prints. */ export type CliAdopt = Static +/** One step of a projection's check: its status and message, and any error, details or renderer checks. */ export type CheckStep = Static +/** The `projections.check` document `projections check --json` prints. */ export type CliCheck = Static +/** A workspace Projections keeps for the repository, as `projections workspace list --json` lists it. */ export type Workspace = Static +/** The `projections.workspaces` document `projections workspace list --json` prints. */ export type CliWorkspaces = Static +/** The `projections.workspace-clean` document `projections workspace clean --json` prints. */ export type CliWorkspaceClean = Static +/** The environment a `projections.doctor` document reports: declared, prepared and missing, and the workspace strategy. */ export type EnvironmentReport = Static +/** The `projections.doctor` document `projections doctor --json` prints. */ export type CliDoctor = Static +/** The `projections.prepare` document `projections prepare --json` prints. */ export type CliPrepare = Static +/** One projection's (or bookmark's) result in a `projections.batch` document. */ export type BatchResult = Static +/** The `projections.batch` document `show --all`, `compare --all` and `bookmark run` print with `--json` or write with `--output`. */ export type CliBatch = Static +/** The `projections.pull-request` document `projections pr --json` prints. */ export type CliPullRequest = Static +/** A built-in extractor, as `projections extractor list --json` lists it. */ export type ExtractorDescriptor = Static +/** The `projections.extractors` document `projections extractor list --json` prints. */ export type CliExtractors = Static +/** The `projections.extractor` document `projections extractor view --json` prints. */ export type CliExtractor = Static +/** What `projections validate --json` prints for a valid document. */ export type CliValidation = Static +/** The `projections.view` document `projections view show`, `current` and `refresh` print with `--json`, or the viewer's refusal. */ export type CliView = Static +/** The `projections.screenshot` document `projections view screenshot --json` prints, or the viewer's refusal. */ export type CliScreenshot = Static From 5f1fe21026d6208a6133a148d277d6e4139ae036 Mon Sep 17 00:00:00 2001 From: agorischek <6295280+agorischek@users.noreply.github.com> Date: Fri, 4 Dec 2026 21:50:01 +0000 Subject: [PATCH 3/6] Reference pages for the CLI's JSON schemas Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> --- docs/reference/schemas/README.md | 17 ++++ docs/reference/schemas/cli-adopt.md | 27 ++++++ docs/reference/schemas/cli-batch.md | 42 ++++++++++ docs/reference/schemas/cli-check.md | 46 +++++++++++ docs/reference/schemas/cli-doctor.md | 47 +++++++++++ docs/reference/schemas/cli-error.md | 46 +++++++++++ docs/reference/schemas/cli-explore.md | 54 ++++++++++++ docs/reference/schemas/cli-extractor.md | 26 ++++++ docs/reference/schemas/cli-extractors.md | 36 ++++++++ docs/reference/schemas/cli-list.md | 47 +++++++++++ docs/reference/schemas/cli-prepare.md | 21 +++++ docs/reference/schemas/cli-pull-request.md | 26 ++++++ docs/reference/schemas/cli-screenshot.md | 10 +++ docs/reference/schemas/cli-sweep.md | 82 +++++++++++++++++++ docs/reference/schemas/cli-validation.md | 17 ++++ docs/reference/schemas/cli-view.md | 10 +++ docs/reference/schemas/cli-workspace-clean.md | 16 ++++ docs/reference/schemas/cli-workspaces.md | 34 ++++++++ 18 files changed, 604 insertions(+) create mode 100644 docs/reference/schemas/cli-adopt.md create mode 100644 docs/reference/schemas/cli-batch.md create mode 100644 docs/reference/schemas/cli-check.md create mode 100644 docs/reference/schemas/cli-doctor.md create mode 100644 docs/reference/schemas/cli-error.md create mode 100644 docs/reference/schemas/cli-explore.md create mode 100644 docs/reference/schemas/cli-extractor.md create mode 100644 docs/reference/schemas/cli-extractors.md create mode 100644 docs/reference/schemas/cli-list.md create mode 100644 docs/reference/schemas/cli-prepare.md create mode 100644 docs/reference/schemas/cli-pull-request.md create mode 100644 docs/reference/schemas/cli-screenshot.md create mode 100644 docs/reference/schemas/cli-sweep.md create mode 100644 docs/reference/schemas/cli-validation.md create mode 100644 docs/reference/schemas/cli-view.md create mode 100644 docs/reference/schemas/cli-workspace-clean.md create mode 100644 docs/reference/schemas/cli-workspaces.md diff --git a/docs/reference/schemas/README.md b/docs/reference/schemas/README.md index b03bf929b..310c7f858 100644 --- a/docs/reference/schemas/README.md +++ b/docs/reference/schemas/README.md @@ -14,6 +14,23 @@ domain schemas an extraction's `schema` field selects. | [Domain schema architecture/v0](architecture.md) | `https://schemas.projections.githubnext.com/architecture/v0.json` | Components and their connections, as `graph/v0`, for architecture and infrastructure. | | [CI artifact manifest](artifact.md) | `https://schemas.projections.githubnext.com/artifact/v0.json` | projections.artifact.json at the root of the `projections` Actions artifact: what one workflow run extracted or compared, and the full-byte SHA-256 of every document it uploaded. | | [Bookmarks](bookmarks.md) | `https://schemas.projections.githubnext.com/bookmarks/v0.json` | `.projections-bookmarks.json` at the repository root: saved comparisons to revisit, each a projection and two revisions. `projections bookmark` reads it; bookmark IDs are unique within the file. | +| [CLI adopt](cli-adopt.md) | `https://schemas.projections.githubnext.com/cli/adopt/v0.json` | The definitions and bookmarks adopting projections writes (`projections adopt --json`). | +| [CLI batch](cli-batch.md) | `https://schemas.projections.githubnext.com/cli/batch/v0.json` | Every projection (or bookmark) at once: `show --all`, `compare --all` and `bookmark run` with `--json` or `--output`. | +| [CLI check](cli-check.md) | `https://schemas.projections.githubnext.com/cli/check/v0.json` | Projections verified end to end: extraction, comparison and renderer checks (`projections check --json`). | +| [CLI doctor](cli-doctor.md) | `https://schemas.projections.githubnext.com/cli/doctor/v0.json` | What the checkout needs to run its projections, found without running anything (`projections doctor --json`). | +| [CLI error](cli-error.md) | `https://schemas.projections.githubnext.com/cli/error/v0.json` | What a command run with `--json` or `--output` prints to stdout when it fails, besides its message on stderr. | +| [CLI explore candidates](cli-explore.md) | `https://schemas.projections.githubnext.com/cli/explore/v0.json` | The built-in projections that apply to the repository (`projections explore --list --json`). | +| [CLI extractor](cli-extractor.md) | `https://schemas.projections.githubnext.com/cli/extractor/v0.json` | One built-in extractor: its inputs, schema, renderer and definition template (`projections extractor view --json`). | +| [CLI extractor list](cli-extractors.md) | `https://schemas.projections.githubnext.com/cli/extractors/v0.json` | The built-in extractors (`projections extractor list --json`). | +| [CLI list](cli-list.md) | `https://schemas.projections.githubnext.com/cli/list/v0.json` | The projections a revision defines, read without running anything (`projections list --json`). | +| [CLI prepare](cli-prepare.md) | `https://schemas.projections.githubnext.com/cli/prepare/v0.json` | The environment's prepare steps, run in the working tree or a commit's workspace (`projections prepare --json`). | +| [CLI pull request review](cli-pull-request.md) | `https://schemas.projections.githubnext.com/cli/pull-request/v0.json` | A pull request reviewed without running its code, with the base's definitions (`projections pr --json`). | +| [CLI viewer screenshot](cli-screenshot.md) | `https://schemas.projections.githubnext.com/cli/screenshot/v0.json` | The PNG `projections view screenshot --json` wrote, and what it shows. | +| [CLI sweep](cli-sweep.md) | `https://schemas.projections.githubnext.com/cli/sweep/v0.json` | Each candidate and adopted projection tried on recent changes (`projections explore --sweep --json`). | +| [CLI validation](cli-validation.md) | `https://schemas.projections.githubnext.com/cli/validation/v0.json` | A valid saved extraction, comparison or scenarios document (`projections validate --json`). | +| [CLI viewer](cli-view.md) | `https://schemas.projections.githubnext.com/cli/view/v0.json` | What the viewer shows and what the person selected (`projections view show\|current\|refresh --json`). | +| [CLI workspace clean](cli-workspace-clean.md) | `https://schemas.projections.githubnext.com/cli/workspace-clean/v0.json` | The workspaces `projections workspace clean --json` removed. | +| [CLI workspace list](cli-workspaces.md) | `https://schemas.projections.githubnext.com/cli/workspaces/v0.json` | The workspaces Projections keeps for the repository (`projections workspace list --json`). | | [Comparator tests](comparator-tests.md) | `https://schemas.projections.githubnext.com/comparator-tests/v0.json` | Tests for a custom comparator, in the file beside its comparator file (`X.comparator.test.yaml` for `X.comparator.yaml`), never part of the comparator or its digest. Each case gives two extractions and states what the comparator must make of them: partial expectations (step order, steps, changes, counts, metadata, or the error the comparator must fail with) and an optional snapshot of the whole comparison. `projections check` runs them. See docs/contracts.md, "Comparator tests". | | [Comparator file](comparator.md) | `https://schemas.projections.githubnext.com/comparator/v0.json` | A custom comparator file (`.comparator.yaml`): YAML declarations the rules interpreter runs over the default comparator, sandboxed. Identity passes add correspondences; comparator rules, CEL expressions checked against declared types when the file loads, classify changes, order them into steps and add metadata. See the guide's "Write a custom comparator" and docs/design/declarative-comparators.md. | | [Saved comparison](comparison-document.md) | `https://schemas.projections.githubnext.com/comparison-document/v0.json` | Two saved extractions and the comparison between them, with the comparator that produced it. | diff --git a/docs/reference/schemas/cli-adopt.md b/docs/reference/schemas/cli-adopt.md new file mode 100644 index 000000000..c621a15de --- /dev/null +++ b/docs/reference/schemas/cli-adopt.md @@ -0,0 +1,27 @@ + + +# CLI adopt + +The definitions and bookmarks adopting projections writes (`projections adopt --json`). The schema is published at its ID, `https://schemas.projections.githubnext.com/cli/adopt/v0.json`; it is generated from TypeBox +definitions into [`packages/schemas/schemas/cli/adopt/v0.json`](../../../packages/schemas/schemas/cli/adopt/v0.json). + +## Document + +| Property | Type | Required | Description | +|---|---|---|---| +| `format` | `"projections.adopt"` | Yes | | +| `version` | `0` | Yes | | +| `files` | array of object | Yes | The definitions and the bookmarks file it writes, or would write. | +| `digest` | string | Yes | The files' contents before, which a write must still find. Pattern `^sha256:[0-9a-f]{64}$`. | +| `written` | boolean | Yes | `false` for `--dry-run`. | +| `adopted` | array of [`identifier`](definition.md#identifier) | Yes | | +| `bookmarked` | array of object | Yes | | +| `notes` | array of [`note`](#note) | Yes | | + +No other properties are allowed. + +## Definitions + +### `note` + +Type: string. diff --git a/docs/reference/schemas/cli-batch.md b/docs/reference/schemas/cli-batch.md new file mode 100644 index 000000000..5798842bd --- /dev/null +++ b/docs/reference/schemas/cli-batch.md @@ -0,0 +1,42 @@ + + +# CLI batch + +Every projection (or bookmark) at once: `show --all`, `compare --all` and `bookmark run` with `--json` or `--output`. The schema is published at its ID, `https://schemas.projections.githubnext.com/cli/batch/v0.json`; it is generated from TypeBox +definitions into [`packages/schemas/schemas/cli/batch/v0.json`](../../../packages/schemas/schemas/cli/batch/v0.json). + +## Document + +| Property | Type | Required | Description | +|---|---|---|---| +| `format` | `"projections.batch"` | Yes | | +| `version` | `0` | Yes | | +| `operation` | `"show"` or `"compare"` or `"bookmarks"` | Yes | | +| `results` | array of [`result`](#result) | Yes | Ordered by ID. | +| `failed` | integer | Yes | Results whose status is `error`. At least 0. At most 9007199254740991. | + +No other properties are allowed. + +## Definitions + +### `result` + +One projection's (or bookmark's) result: its document, or why it failed. + +| Property | Type | Required | Description | +|---|---|---|---| +| `id` | [`identifier`](definition.md#identifier) | Yes | | +| `status` | `"extracted"` or `"changed"` or `"unchanged"` or `"head-only"` or `"base-only"` or `"error"` | Yes | `extracted` (show), `changed` or `unchanged` (compared), `head-only` or `base-only` (one revision defines it, shown alone), or `error`. | +| `projectionId` | [`identifier`](definition.md#identifier) | | A bookmark's projection, for `bookmark run`, whose `id` is the bookmark's. | +| `extraction` | [Saved extraction](extraction-document.md) | | | +| `comparison` | [Saved comparison](comparison-document.md) | | | +| `notices` | array of string | | | +| `review` | object | | The engine's review counts of a comparison. | +| `review.reviewable` | integer | Yes | At least 0. At most 9007199254740991. | +| `review.content` | integer | Yes | At least 0. At most 9007199254740991. | +| `review.identity` | integer | Yes | At least 0. At most 9007199254740991. | +| `review.variation` | integer | Yes | At least 0. At most 9007199254740991. | +| `diagnostics` | array of [`diagnostic`](cli-error.md#diagnostic) | | Why it failed, for `error`. | +| `definition` | [Projection definition](definition.md) | | Its definition, for `error` once it resolved. | + +No other properties are allowed. diff --git a/docs/reference/schemas/cli-check.md b/docs/reference/schemas/cli-check.md new file mode 100644 index 000000000..4d649e1e6 --- /dev/null +++ b/docs/reference/schemas/cli-check.md @@ -0,0 +1,46 @@ + + +# CLI check + +Projections verified end to end: extraction, comparison and renderer checks (`projections check --json`). The schema is published at its ID, `https://schemas.projections.githubnext.com/cli/check/v0.json`; it is generated from TypeBox +definitions into [`packages/schemas/schemas/cli/check/v0.json`](../../../packages/schemas/schemas/cli/check/v0.json). + +## Document + +| Property | Type | Required | Description | +|---|---|---|---| +| `format` | `"projections.check"` | Yes | | +| `version` | `0` | Yes | | +| `ok` | boolean | Yes | | +| `projections` | array of object or object | Yes | | + +No other properties are allowed. + +## Definitions + +### `rendererCheck` + +| Property | Type | Required | Description | +|---|---|---|---| +| `id` | string | Yes | | +| `title` | string | Yes | | +| `status` | `"pass"` or `"fail"` or `"skip"` or `"advice"` | Yes | | +| `details` | array of string | Yes | | +| `durationMs` | number | Yes | At least 0. | + +No other properties are allowed. + +### `step` + +| Property | Type | Required | Description | +|---|---|---|---| +| `id` | string | Yes | | +| `title` | string | Yes | | +| `status` | `"pass"` or `"fail"` or `"warn"` or `"skip"` | Yes | | +| `message` | string | Yes | | +| `error` | [`report`](cli-error.md#report) | | | +| `details` | array of string | | | +| `rerun` | string | | The command that runs the failed renderer checks again. | +| `checks` | array of [`rendererCheck`](#renderercheck) | | Every renderer check, on a renderer step. | + +No other properties are allowed. diff --git a/docs/reference/schemas/cli-doctor.md b/docs/reference/schemas/cli-doctor.md new file mode 100644 index 000000000..1c1a4227e --- /dev/null +++ b/docs/reference/schemas/cli-doctor.md @@ -0,0 +1,47 @@ + + +# CLI doctor + +What the checkout needs to run its projections, found without running anything (`projections doctor --json`). The schema is published at its ID, `https://schemas.projections.githubnext.com/cli/doctor/v0.json`; it is generated from TypeBox +definitions into [`packages/schemas/schemas/cli/doctor/v0.json`](../../../packages/schemas/schemas/cli/doctor/v0.json). + +## Document + +| Property | Type | Required | Description | +|---|---|---|---| +| `format` | `"projections.doctor"` | Yes | | +| `version` | `0` | Yes | | +| `ok` | boolean | Yes | | +| `items` | array of [`item`](#item) | Yes | | +| `projections` | array of object | Yes | | +| `environment` | [`environment`](#environment) | | | + +No other properties are allowed. + +## Definitions + +### `environment` + +| Property | Type | Required | Description | +|---|---|---|---| +| `workspace` | object or object | Yes | | +| `workspaces` | array of [`workspace`](cli-workspaces.md#workspace) | | | +| `workspacesError` | string | | | +| `declared` | string or null | | The environment file, or `null` when none is declared. | +| `error` | string | | | +| `prepare` | array of object | | | +| `toolchain` | array of array of string | | | +| `devcontainer` | string or null | | | +| `missing` | array of string | | | + +No other properties are allowed. + +### `item` + +| Property | Type | Required | Description | +|---|---|---|---| +| `status` | `"pass"` or `"warn"` or `"fail"` | Yes | | +| `title` | string | Yes | | +| `message` | string | Yes | | + +No other properties are allowed. diff --git a/docs/reference/schemas/cli-error.md b/docs/reference/schemas/cli-error.md new file mode 100644 index 000000000..d9205c36b --- /dev/null +++ b/docs/reference/schemas/cli-error.md @@ -0,0 +1,46 @@ + + +# CLI error + +What a command run with `--json` or `--output` prints to stdout when it fails, besides its message on stderr. The schema is published at its ID, `https://schemas.projections.githubnext.com/cli/error/v0.json`; it is generated from TypeBox +definitions into [`packages/schemas/schemas/cli/error/v0.json`](../../../packages/schemas/schemas/cli/error/v0.json). + +## Document + +| Property | Type | Required | Description | +|---|---|---|---| +| `format` | `"projections.error"` | Yes | | +| `version` | `0` | Yes | | +| `error` | [`report`](#report) | Yes | | + +No other properties are allowed. + +## Definitions + +### `diagnostic` + +One problem the engine or runner found. + +| Property | Type | Required | Description | +|---|---|---|---| +| `severity` | `"error"` or `"warning"` | Yes | | +| `code` | string | Yes | | +| `path` | string | Yes | A JSON pointer into the extraction, or empty. | +| `message` | string | Yes | | +| `entityId` | string | | The entity the problem is about, when there is one. | + +No other properties are allowed. + +### `report` + +What failed (a stable code), where, the evidence and what to do next. + +| Property | Type | Required | Description | +|---|---|---|---| +| `code` | `"TRUST_REQUIRED"` or `"EXTRACTOR_FAILED"` or `"INVALID_EXTRACTION"` or `"INVALID_INPUT"` or `"ERROR"` | Yes | | +| `message` | string | Yes | | +| `hint` | string | | What to do next. | +| `diagnostics` | array of [`diagnostic`](#diagnostic) | Yes | | +| `stderr` | string | | A failed extractor's standard error, for `EXTRACTOR_FAILED`. | + +No other properties are allowed. diff --git a/docs/reference/schemas/cli-explore.md b/docs/reference/schemas/cli-explore.md new file mode 100644 index 000000000..2c5b586ab --- /dev/null +++ b/docs/reference/schemas/cli-explore.md @@ -0,0 +1,54 @@ + + +# CLI explore candidates + +The built-in projections that apply to the repository (`projections explore --list --json`). The schema is published at its ID, `https://schemas.projections.githubnext.com/cli/explore/v0.json`; it is generated from TypeBox +definitions into [`packages/schemas/schemas/cli/explore/v0.json`](../../../packages/schemas/schemas/cli/explore/v0.json). + +## Document + +| Property | Type | Required | Description | +|---|---|---|---| +| `format` | `"projections.explore"` | Yes | | +| `version` | `0` | Yes | | +| `candidates` | array of [`candidate`](#candidate) | Yes | | + +No other properties are allowed. + +## Definitions + +### `need` + +| Property | Type | Required | Description | +|---|---|---|---| +| `kind` | `"configuration"` or `"install"` | Yes | | +| `message` | string | Yes | | + +No other properties are allowed. + +### `candidate` + +A built-in projection that applies to the repository, as a trial definition. + +| Property | Type | Required | Description | +|---|---|---|---| +| `id` | [`identifier`](definition.md#identifier) | Yes | | +| `title` | string | Yes | | +| `description` | string | Yes | | +| `extractor` | [`identifier`](definition.md#identifier) | Yes | | +| `schema` | string | Yes | The domain schema its extractions use, such as `graph/v0`. | +| `renderer` | string | Yes | | +| `requiresTrust` | boolean | Yes | | +| `basis` | object | Yes | Why it was proposed: the detection pattern that matched, how many files and the first few. | +| `basis.pattern` | string | | The detection pattern that matched; absent for a candidate named by ID. | +| `basis.named` | `true` | | `adopt` named the built-in extractor; explore did not propose it. | +| `basis.count` | integer | Yes | At least 0. At most 9007199254740991. | +| `basis.examples` | array of string | Yes | | +| `basis.file` | string | | The one file or manifest a per-file candidate reads. | +| `basis.skipped` | integer | | Files `.gitattributes` marks vendored or generated. At least 0. At most 9007199254740991. | +| `basis.crates` | integer | | The Rust workspace's crates. At least 0. At most 9007199254740991. | +| `adopted` | string or null | Yes | The authored definition that already uses it, if any. | +| `definition` | [Projection definition](definition.md) | Yes | | +| `needs` | array of [`need`](#need) | | | + +No other properties are allowed. diff --git a/docs/reference/schemas/cli-extractor.md b/docs/reference/schemas/cli-extractor.md new file mode 100644 index 000000000..1e9b720af --- /dev/null +++ b/docs/reference/schemas/cli-extractor.md @@ -0,0 +1,26 @@ + + +# CLI extractor + +One built-in extractor: its inputs, schema, renderer and definition template (`projections extractor view --json`). The schema is published at its ID, `https://schemas.projections.githubnext.com/cli/extractor/v0.json`; it is generated from TypeBox +definitions into [`packages/schemas/schemas/cli/extractor/v0.json`](../../../packages/schemas/schemas/cli/extractor/v0.json). + +## Document + +| Property | Type | Required | Description | +|---|---|---|---| +| `format` | `"projections.extractor"` | Yes | | +| `version` | `0` | Yes | | +| `id` | [`identifier`](definition.md#identifier) | Yes | | +| `title` | string | Yes | | +| `description` | string | Yes | | +| `schema` | string | Yes | The domain schema its extractions use, such as `graph/v0`. | +| `renderer` | string | Yes | The built-in renderer its definition template uses. | +| `trust` | `"none"` or `"when-executing-tools"` | Yes | Whether it runs repository code (anything but `none`). | +| `access` | `"files"` or `"checkout"` | Yes | File reads only, or a checkout. | +| `determinism` | `"pure"` or `"environmental"` or `"observed"` | Yes | | +| `inputs` | map of string | Yes | Its inputs, each with what it means. | +| `template` | [Projection definition](definition.md) | Yes | The definition `projections init --extractor` writes. | +| `detects` | array of string | Yes | The file patterns that mean it may apply. | + +No other properties are allowed. diff --git a/docs/reference/schemas/cli-extractors.md b/docs/reference/schemas/cli-extractors.md new file mode 100644 index 000000000..06a7bba74 --- /dev/null +++ b/docs/reference/schemas/cli-extractors.md @@ -0,0 +1,36 @@ + + +# CLI extractor list + +The built-in extractors (`projections extractor list --json`). The schema is published at its ID, `https://schemas.projections.githubnext.com/cli/extractors/v0.json`; it is generated from TypeBox +definitions into [`packages/schemas/schemas/cli/extractors/v0.json`](../../../packages/schemas/schemas/cli/extractors/v0.json). + +## Document + +| Property | Type | Required | Description | +|---|---|---|---| +| `format` | `"projections.extractors"` | Yes | | +| `version` | `0` | Yes | | +| `extractors` | array of [`extractor`](#extractor) | Yes | | + +No other properties are allowed. + +## Definitions + +### `extractor` + +| Property | Type | Required | Description | +|---|---|---|---| +| `id` | [`identifier`](definition.md#identifier) | Yes | | +| `title` | string | Yes | | +| `description` | string | Yes | | +| `schema` | string | Yes | The domain schema its extractions use, such as `graph/v0`. | +| `renderer` | string | Yes | The built-in renderer its definition template uses. | +| `trust` | `"none"` or `"when-executing-tools"` | Yes | Whether it runs repository code (anything but `none`). | +| `access` | `"files"` or `"checkout"` | Yes | File reads only, or a checkout. | +| `determinism` | `"pure"` or `"environmental"` or `"observed"` | Yes | | +| `inputs` | map of string | Yes | Its inputs, each with what it means. | +| `template` | [Projection definition](definition.md) | Yes | The definition `projections init --extractor` writes. | +| `detects` | array of string | Yes | The file patterns that mean it may apply. | + +No other properties are allowed. diff --git a/docs/reference/schemas/cli-list.md b/docs/reference/schemas/cli-list.md new file mode 100644 index 000000000..61dac460b --- /dev/null +++ b/docs/reference/schemas/cli-list.md @@ -0,0 +1,47 @@ + + +# CLI list + +The projections a revision defines, read without running anything (`projections list --json`). The schema is published at its ID, `https://schemas.projections.githubnext.com/cli/list/v0.json`; it is generated from TypeBox +definitions into [`packages/schemas/schemas/cli/list/v0.json`](../../../packages/schemas/schemas/cli/list/v0.json). + +## Document + +| Property | Type | Required | Description | +|---|---|---|---| +| `format` | `"projections.list"` | Yes | | +| `version` | `0` | Yes | | +| `revision` | [`revision`](extraction-document.md#revision) | Yes | The revision whose definitions are listed. | +| `projections` | array of object | Yes | | +| `invalid` | array of [`invalidDefinition`](#invaliddefinition) | Yes | | +| `defaults` | boolean | Yes | Whether the projections are the built-in defaults, because the working tree defines none of its own. | + +No other properties are allowed. + +## Definitions + +### `definitionDiagnostic` + +| Property | Type | Required | Description | +|---|---|---|---| +| `code` | string | Yes | | +| `severity` | `"error"` or `"warning"` | Yes | | +| `message` | string | Yes | | +| `path` | string | Yes | The definition file, relative to the repository. | +| `location` | object | Yes | | +| `location.path` | string | Yes | | +| `location.line` | integer | Yes | At least 0. At most 9007199254740991. | +| `location.column` | integer | Yes | At least 0. At most 9007199254740991. | +| `pointer` | string | | A JSON pointer to the invalid value, when the error names one. | + +No other properties are allowed. + +### `invalidDefinition` + +| Property | Type | Required | Description | +|---|---|---|---| +| `id` | string or null | Yes | The file's `id`, when it has a readable one. | +| `path` | string | Yes | | +| `diagnostics` | array of [`definitionDiagnostic`](#definitiondiagnostic) | Yes | | + +No other properties are allowed. diff --git a/docs/reference/schemas/cli-prepare.md b/docs/reference/schemas/cli-prepare.md new file mode 100644 index 000000000..117838e04 --- /dev/null +++ b/docs/reference/schemas/cli-prepare.md @@ -0,0 +1,21 @@ + + +# CLI prepare + +The environment's prepare steps, run in the working tree or a commit's workspace (`projections prepare --json`). The schema is published at its ID, `https://schemas.projections.githubnext.com/cli/prepare/v0.json`; it is generated from TypeBox +definitions into [`packages/schemas/schemas/cli/prepare/v0.json`](../../../packages/schemas/schemas/cli/prepare/v0.json). + +## Document + +| Property | Type | Required | Description | +|---|---|---|---| +| `format` | `"projections.prepare"` | Yes | | +| `version` | `0` | Yes | | +| `target` | string | Yes | `working-tree`, or the commit whose workspace was prepared. | +| `environment` | string | Yes | The environment file. | +| `root` | string | Yes | Where the steps ran. | +| `strategy` | `"worktree"` or `"clone"` or `"sparse"` | | The workspace's strategy, for a commit. | +| `notes` | array of string | | | +| `steps` | array of object or object | Yes | | + +No other properties are allowed. diff --git a/docs/reference/schemas/cli-pull-request.md b/docs/reference/schemas/cli-pull-request.md new file mode 100644 index 000000000..3cb1c3043 --- /dev/null +++ b/docs/reference/schemas/cli-pull-request.md @@ -0,0 +1,26 @@ + + +# CLI pull request review + +A pull request reviewed without running its code, with the base's definitions (`projections pr --json`). The schema is published at its ID, `https://schemas.projections.githubnext.com/cli/pull-request/v0.json`; it is generated from TypeBox +definitions into [`packages/schemas/schemas/cli/pull-request/v0.json`](../../../packages/schemas/schemas/cli/pull-request/v0.json). + +## Document + +| Property | Type | Required | Description | +|---|---|---|---| +| `format` | `"projections.pull-request"` | Yes | | +| `version` | `0` | Yes | | +| `repository` | string | Yes | `owner/name`. | +| `number` | integer | Yes | At least 0. At most 9007199254740991. | +| `url` | string | Yes | | +| `base` | string | Yes | | +| `head` | string | Yes | | +| `mergeBase` | string | Yes | | +| `fork` | boolean | Yes | | +| `execution` | `"untrusted"` | Yes | | +| `definition` | `"base"` | Yes | | +| `changedProjections` | array of object | Yes | | +| `comparisons` | [CLI batch](cli-batch.md) | Yes | | + +No other properties are allowed. diff --git a/docs/reference/schemas/cli-screenshot.md b/docs/reference/schemas/cli-screenshot.md new file mode 100644 index 000000000..c39db5351 --- /dev/null +++ b/docs/reference/schemas/cli-screenshot.md @@ -0,0 +1,10 @@ + + +# CLI viewer screenshot + +The PNG `projections view screenshot --json` wrote, and what it shows. The schema is published at its ID, `https://schemas.projections.githubnext.com/cli/screenshot/v0.json`; it is generated from TypeBox +definitions into [`packages/schemas/schemas/cli/screenshot/v0.json`](../../../packages/schemas/schemas/cli/screenshot/v0.json). + +## Document + +Type: object or object or object. diff --git a/docs/reference/schemas/cli-sweep.md b/docs/reference/schemas/cli-sweep.md new file mode 100644 index 000000000..bb1958eac --- /dev/null +++ b/docs/reference/schemas/cli-sweep.md @@ -0,0 +1,82 @@ + + +# CLI sweep + +Each candidate and adopted projection tried on recent changes (`projections explore --sweep --json`). The schema is published at its ID, `https://schemas.projections.githubnext.com/cli/sweep/v0.json`; it is generated from TypeBox +definitions into [`packages/schemas/schemas/cli/sweep/v0.json`](../../../packages/schemas/schemas/cli/sweep/v0.json). + +## Document + +| Property | Type | Required | Description | +|---|---|---|---| +| `format` | `"projections.sweep"` | Yes | | +| `version` | `0` | Yes | | +| `changes` | array of [`change`](#change) | Yes | | +| `projections` | array of [`projection`](#projection) | Yes | | +| `cells` | array of [`cell`](#cell) | Yes | | +| `notes` | array of [`note`](#note) | Yes | | + +No other properties are allowed. + +## Definitions + +### `change` + +| Property | Type | Required | Description | +|---|---|---|---| +| `before` | string | Yes | | +| `after` | string | Yes | | +| `title` | string | Yes | | +| `number` | integer or null | Yes | The pull request number its message names, if any. | +| `kind` | `"merge"` or `"commit"` | Yes | A merge commit, or a first-parent commit. | +| `date` | string | Yes | The commit's date, ISO 8601. | + +No other properties are allowed. + +### `projectionStatus` + +Type: `"ready"` or `"trust"` or `"failed"`. + +### `projection` + +One projection of the sweep, and its tally over the swept changes. + +| Property | Type | Required | Description | +|---|---|---|---| +| `projection` | [`identifier`](definition.md#identifier) | Yes | | +| `status` | [`projectionStatus`](#projectionstatus) | Yes | | +| `requiresTrust` | boolean | | | +| `error` | string | | Why it was skipped or failed. | +| `signal` | `"rare"` or `"steady"` or `"unknown"` or `"noisy"` or `"quiet"` | | How useful its changes look, for a ready projection. | +| `changed` | integer | | Changes it showed a change on, besides version-only ones. At least 0. At most 9007199254740991. | +| `versionOnly` | integer | | Changes where only version strings moved. At least 0. At most 9007199254740991. | +| `failed` | integer | | Changes it failed on. At least 0. At most 9007199254740991. | + +No other properties are allowed. + +### `cellStatus` + +Type: `"changed"` or `"unchanged"` or `"failed"`. + +### `cell` + +One projection on one change: its comparison counts, or why it failed. + +| Property | Type | Required | Description | +|---|---|---|---| +| `projection` | [`identifier`](definition.md#identifier) | Yes | | +| `before` | string | Yes | | +| `after` | string | Yes | | +| `status` | [`cellStatus`](#cellstatus) | Yes | | +| `changes` | integer | | At least 0. At most 9007199254740991. | +| `steps` | integer | | At least 0. At most 9007199254740991. | +| `counts` | map of integer | | Changes by status (`added`, `removed`, `modified`, …). | +| `versionOnly` | `true` | | Changed, but only version strings moved (a dependency or action bump). | +| `error` | string | | | +| `stderr` | string | | The end of a failed extractor's stderr. | + +No other properties are allowed. + +### `note` + +Type: string. diff --git a/docs/reference/schemas/cli-validation.md b/docs/reference/schemas/cli-validation.md new file mode 100644 index 000000000..84f13b459 --- /dev/null +++ b/docs/reference/schemas/cli-validation.md @@ -0,0 +1,17 @@ + + +# CLI validation + +A valid saved extraction, comparison or scenarios document (`projections validate --json`). The schema is published at its ID, `https://schemas.projections.githubnext.com/cli/validation/v0.json`; it is generated from TypeBox +definitions into [`packages/schemas/schemas/cli/validation/v0.json`](../../../packages/schemas/schemas/cli/validation/v0.json). + +## Document + +| Property | Type | Required | Description | +|---|---|---|---| +| `valid` | `true` | Yes | | +| `format` | `"projections.extraction"` or `"projections.comparison"` or `"projections.scenarios"` or `"extraction"` | Yes | What was validated: a saved extraction, a saved comparison, scenarios, or a bare extraction. | +| `scenarios` | integer | | The scenarios, for `projections.scenarios`. At least 0. At most 9007199254740991. | +| `reproduced` | `false` | | A comparison by a custom comparator, which wasn't recomputed without `--comparator`. | + +No other properties are allowed. diff --git a/docs/reference/schemas/cli-view.md b/docs/reference/schemas/cli-view.md new file mode 100644 index 000000000..3e56d3603 --- /dev/null +++ b/docs/reference/schemas/cli-view.md @@ -0,0 +1,10 @@ + + +# CLI viewer + +What the viewer shows and what the person selected (`projections view show|current|refresh --json`). The schema is published at its ID, `https://schemas.projections.githubnext.com/cli/view/v0.json`; it is generated from TypeBox +definitions into [`packages/schemas/schemas/cli/view/v0.json`](../../../packages/schemas/schemas/cli/view/v0.json). + +## Document + +Type: object or object or object. diff --git a/docs/reference/schemas/cli-workspace-clean.md b/docs/reference/schemas/cli-workspace-clean.md new file mode 100644 index 000000000..8bc9d46d1 --- /dev/null +++ b/docs/reference/schemas/cli-workspace-clean.md @@ -0,0 +1,16 @@ + + +# CLI workspace clean + +The workspaces `projections workspace clean --json` removed. The schema is published at its ID, `https://schemas.projections.githubnext.com/cli/workspace-clean/v0.json`; it is generated from TypeBox +definitions into [`packages/schemas/schemas/cli/workspace-clean/v0.json`](../../../packages/schemas/schemas/cli/workspace-clean/v0.json). + +## Document + +| Property | Type | Required | Description | +|---|---|---|---| +| `format` | `"projections.workspace-clean"` | Yes | | +| `version` | `0` | Yes | | +| `removed` | array of string | Yes | The workspaces removed; busy ones are kept. | + +No other properties are allowed. diff --git a/docs/reference/schemas/cli-workspaces.md b/docs/reference/schemas/cli-workspaces.md new file mode 100644 index 000000000..592b7fe9b --- /dev/null +++ b/docs/reference/schemas/cli-workspaces.md @@ -0,0 +1,34 @@ + + +# CLI workspace list + +The workspaces Projections keeps for the repository (`projections workspace list --json`). The schema is published at its ID, `https://schemas.projections.githubnext.com/cli/workspaces/v0.json`; it is generated from TypeBox +definitions into [`packages/schemas/schemas/cli/workspaces/v0.json`](../../../packages/schemas/schemas/cli/workspaces/v0.json). + +## Document + +| Property | Type | Required | Description | +|---|---|---|---| +| `format` | `"projections.workspaces"` | Yes | | +| `version` | `0` | Yes | | +| `directory` | string | Yes | | +| `workspaces` | array of [`workspace`](#workspace) | Yes | | + +No other properties are allowed. + +## Definitions + +### `workspace` + +| Property | Type | Required | Description | +|---|---|---|---| +| `name` | string | Yes | | +| `strategy` | `"fresh"` or `"worktree"` or `"clone"` or `"sparse"` or `"none"` or null | Yes | | +| `commit` | string or null | Yes | | +| `at` | string or null | Yes | | +| `scope` | any | Yes | The scope it holds, for a sparse workspace; `null` otherwise. | +| `path` | string | Yes | | +| `busy` | boolean | Yes | Whether a run is using it. | +| `prepared` | array of object | Yes | | + +No other properties are allowed. From fc8dc72af1d56b8733b1cacfb8c7402290d445fb Mon Sep 17 00:00:00 2001 From: agorischek <6295280+agorischek@users.noreply.github.com> Date: Fri, 4 Dec 2026 21:51:02 +0000 Subject: [PATCH 4/6] Changelog for #395 Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> --- changelog.d/395.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 changelog.d/395.md diff --git a/changelog.d/395.md b/changelog.d/395.md new file mode 100644 index 000000000..ed24aa68b --- /dev/null +++ b/changelog.d/395.md @@ -0,0 +1,6 @@ +--- +section: authoring +--- + +- **Every `--json` document has a published schema** (#395). The documents the CLI prints with `--json`, or writes with `--output`, now have JSON Schemas at `https://schemas.projections.githubnext.com/cli//v0.json`, such as `cli/sweep/v0.json` for `explore --sweep`, `cli/check/v0.json` for `check` and `cli/batch/v0.json` for `show --all`, `compare --all` and `bookmark run` (see [the schema reference](docs/reference/schemas/README.md)). The CLI's tests validate its output against them. Their TypeScript types are exported from `@githubnext/projections/schemas`, for example `CliSweep` and `CliBatch`. +- **More `--json` documents name their kind** (#395). The JSON from `adopt`, `extractor list`, `extractor view`, `workspace clean`, `view show`, `view current`, `view refresh` and `view screenshot` now starts with `format` (`projections.adopt`, `projections.extractors`, `projections.extractor`, `projections.workspace-clean`, `projections.view` and `projections.screenshot`) and `version` (`0`), as the other documents do. The other fields are unchanged. From 610ee130504380ffb6b774f888f527d688a321fe Mon Sep 17 00:00:00 2001 From: agorischek <6295280+agorischek@users.noreply.github.com> Date: Fri, 4 Dec 2026 23:10:13 +0000 Subject: [PATCH 5/6] CLI schemas: comparator test steps, unvalidated IDs, screenshot defaults 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> --- docs/reference/schemas/cli-batch.md | 2 +- docs/reference/schemas/cli-check.md | 77 ++- docs/reference/schemas/cli-doctor.md | 24 +- docs/reference/schemas/cli-prepare.md | 30 +- docs/reference/schemas/cli-screenshot.md | 56 +- docs/reference/schemas/cli-sweep.md | 2 +- docs/reference/schemas/cli-view.md | 63 +- packages/cli/test/json-output.test.mjs | 39 +- packages/schemas/schemas/cli/batch/v0.json | 5 +- packages/schemas/schemas/cli/check/v0.json | 213 +++++-- packages/schemas/schemas/cli/doctor/v0.json | 39 +- packages/schemas/schemas/cli/prepare/v0.json | 49 +- .../schemas/schemas/cli/screenshot/v0.json | 17 +- packages/schemas/schemas/cli/sweep/v0.json | 5 +- packages/schemas/schemas/cli/view/v0.json | 11 +- packages/schemas/src/typebox/cli-common.ts | 89 +++ .../schemas/src/typebox/cli-environment.ts | 294 +++++++++ packages/schemas/src/typebox/cli-explore.ts | 178 ++++++ packages/schemas/src/typebox/cli-viewer.ts | 140 +++++ packages/schemas/src/typebox/cli.ts | 584 +----------------- 20 files changed, 1251 insertions(+), 666 deletions(-) create mode 100644 packages/schemas/src/typebox/cli-common.ts create mode 100644 packages/schemas/src/typebox/cli-environment.ts create mode 100644 packages/schemas/src/typebox/cli-explore.ts create mode 100644 packages/schemas/src/typebox/cli-viewer.ts diff --git a/docs/reference/schemas/cli-batch.md b/docs/reference/schemas/cli-batch.md index 5798842bd..ba3fabf8a 100644 --- a/docs/reference/schemas/cli-batch.md +++ b/docs/reference/schemas/cli-batch.md @@ -25,7 +25,7 @@ One projection's (or bookmark's) result: its document, or why it failed. | Property | Type | Required | Description | |---|---|---|---| -| `id` | [`identifier`](definition.md#identifier) | Yes | | +| `id` | string | Yes | The projection or bookmark, as requested: an error keeps an ID that names neither. | | `status` | `"extracted"` or `"changed"` or `"unchanged"` or `"head-only"` or `"base-only"` or `"error"` | Yes | `extracted` (show), `changed` or `unchanged` (compared), `head-only` or `base-only` (one revision defines it, shown alone), or `error`. | | `projectionId` | [`identifier`](definition.md#identifier) | | A bookmark's projection, for `bookmark run`, whose `id` is the bookmark's. | | `extraction` | [Saved extraction](extraction-document.md) | | | diff --git a/docs/reference/schemas/cli-check.md b/docs/reference/schemas/cli-check.md index 4d649e1e6..b2ec3c0ce 100644 --- a/docs/reference/schemas/cli-check.md +++ b/docs/reference/schemas/cli-check.md @@ -12,7 +12,7 @@ definitions into [`packages/schemas/schemas/cli/check/v0.json`](../../../package | `format` | `"projections.check"` | Yes | | | `version` | `0` | Yes | | | `ok` | boolean | Yes | | -| `projections` | array of object or object | Yes | | +| `projections` | array of [`projection`](#projection) or [`invalidProjection`](#invalidprojection) | Yes | | No other properties are allowed. @@ -30,6 +30,48 @@ No other properties are allowed. No other properties are allowed. +### `comparatorTestDiagnostic` + +| Property | Type | Required | Description | +|---|---|---|---| +| `pointer` | string | Yes | | +| `message` | string | Yes | | +| `location` | object | Yes | | +| `location.path` | string | Yes | | +| `location.line` | integer | Yes | At least 0. At most 9007199254740991. | +| `location.column` | integer | Yes | At least 0. At most 9007199254740991. | + +No other properties are allowed. + +### `comparatorTestCase` + +| Property | Type | Required | Description | +|---|---|---|---| +| `id` | string | Yes | | +| `name` | string | Yes | | +| `status` | `"pass"` or `"fail"` or `"skip"` | Yes | | +| `location` | object | Yes | | +| `location.path` | string | Yes | | +| `location.line` | integer | Yes | At least 0. At most 9007199254740991. | +| `location.column` | integer | Yes | At least 0. At most 9007199254740991. | +| `failures` | array of object | Yes | | +| `message` | string | | Why it failed or was skipped. | +| `durationMs` | integer | Yes | At least 0. At most 9007199254740991. | + +No other properties are allowed. + +### `comparatorCoverage` + +| Property | Type | Required | Description | +|---|---|---|---| +| `comparator` | string | Yes | The comparator file. | +| `summary` | map of object or null | Yes | Covered of total, by category (functions, expressions, branches); `null` when nothing ran. | +| `uncovered` | array of object | | | +| `excluded` | array of object | | | +| `entries` | any | | The rules interpreter's raw coverage. | + +No other properties are allowed. + ### `step` | Property | Type | Required | Description | @@ -42,5 +84,38 @@ No other properties are allowed. | `details` | array of string | | | | `rerun` | string | | The command that runs the failed renderer checks again. | | `checks` | array of [`rendererCheck`](#renderercheck) | | Every renderer check, on a renderer step. | +| `file` | string | | The comparator test file, on a comparator tests step, whether or not it exists. | +| `cases` | array of [`comparatorTestCase`](#comparatortestcase) | | | +| `diagnostics` | array of [`comparatorTestDiagnostic`](#comparatortestdiagnostic) | | Why the comparator test file is invalid. | +| `written` | array of string | | The snapshots `--update` wrote. | +| `coverage` | [`comparatorCoverage`](#comparatorcoverage) | | | + +No other properties are allowed. + +### `projection` + +A projection checked: each step of its check. + +| Property | Type | Required | Description | +|---|---|---|---| +| `id` | [`identifier`](definition.md#identifier) | Yes | | +| `title` | string | Yes | | +| `ok` | boolean | Yes | | +| `steps` | array of [`step`](#step) | Yes | | + +No other properties are allowed. + +### `invalidProjection` + +A definition file that failed to load. + +| Property | Type | Required | Description | +|---|---|---|---| +| `id` | string | Yes | | +| `title` | string | Yes | | +| `path` | string | Yes | | +| `ok` | `false` | Yes | | +| `steps` | array of [`step`](#step) | Yes | | +| `diagnostics` | array of [`definitionDiagnostic`](cli-list.md#definitiondiagnostic) | Yes | | No other properties are allowed. diff --git a/docs/reference/schemas/cli-doctor.md b/docs/reference/schemas/cli-doctor.md index 1c1a4227e..076aa085c 100644 --- a/docs/reference/schemas/cli-doctor.md +++ b/docs/reference/schemas/cli-doctor.md @@ -20,11 +20,33 @@ No other properties are allowed. ## Definitions +### `workspaceStrategy` + +The workspace strategy in effect, where it was set, and why. + +| Property | Type | Required | Description | +|---|---|---|---| +| `strategy` | `"fresh"` or `"worktree"` or `"clone"` or `"sparse"` or `"none"` | Yes | | +| `source` | `"flag"` or `"config"` or `"environment"` or `"automatic"` | Yes | | +| `reason` | string | Yes | | + +No other properties are allowed. + +### `workspaceError` + +Why the workspace strategy couldn't be chosen. + +| Property | Type | Required | Description | +|---|---|---|---| +| `error` | string | Yes | | + +No other properties are allowed. + ### `environment` | Property | Type | Required | Description | |---|---|---|---| -| `workspace` | object or object | Yes | | +| `workspace` | [`workspaceStrategy`](#workspacestrategy) or [`workspaceError`](#workspaceerror) | Yes | | | `workspaces` | array of [`workspace`](cli-workspaces.md#workspace) | | | | `workspacesError` | string | | | | `declared` | string or null | | The environment file, or `null` when none is declared. | diff --git a/docs/reference/schemas/cli-prepare.md b/docs/reference/schemas/cli-prepare.md index 117838e04..a8da55200 100644 --- a/docs/reference/schemas/cli-prepare.md +++ b/docs/reference/schemas/cli-prepare.md @@ -16,6 +16,34 @@ definitions into [`packages/schemas/schemas/cli/prepare/v0.json`](../../../packa | `root` | string | Yes | Where the steps ran. | | `strategy` | `"worktree"` or `"clone"` or `"sparse"` | | The workspace's strategy, for a commit. | | `notes` | array of string | | | -| `steps` | array of object or object | Yes | | +| `steps` | array of [`currentStep`](#currentstep) or [`ranStep`](#ranstep) | Yes | | + +No other properties are allowed. + +## Definitions + +### `currentStep` + +Unchanged keys: not run. + +| Property | Type | Required | Description | +|---|---|---|---| +| `id` | string | Yes | | +| `key` | string | Yes | | +| `status` | `"current"` | Yes | | + +No other properties are allowed. + +### `ranStep` + +A step that ran and succeeded; a failed step fails the command. + +| Property | Type | Required | Description | +|---|---|---|---| +| `id` | string | Yes | | +| `key` | string | Yes | | +| `status` | `"succeeded"` | Yes | | +| `durationMs` | integer | Yes | At least 0. At most 9007199254740991. | +| `log` | string | Yes | | No other properties are allowed. diff --git a/docs/reference/schemas/cli-screenshot.md b/docs/reference/schemas/cli-screenshot.md index c39db5351..dab9950ae 100644 --- a/docs/reference/schemas/cli-screenshot.md +++ b/docs/reference/schemas/cli-screenshot.md @@ -7,4 +7,58 @@ definitions into [`packages/schemas/schemas/cli/screenshot/v0.json`](../../../pa ## Document -Type: object or object or object. +Type: [`rendered`](#rendered) or [`page`](#page) or [`refusal`](#refusal). + +## Definitions + +### `rendered` + +A projection rendered by its renderer. + +| Property | Type | Required | Description | +|---|---|---|---| +| `format` | `"projections.screenshot"` | Yes | | +| `version` | `0` | Yes | | +| `projection` | any | Yes | The projection drawn. | +| `scenario` | any | Yes | The scenario drawn, or `null`. | +| `before` | any | Yes | The revision before, or `null`. | +| `after` | any | Yes | The revision after, or `null` for a scenario. | +| `mode` | string or null | Yes | | +| `progress` | any | Yes | The comparison progress drawn. | +| `theme` | string | Yes | | +| `width` | integer | Yes | At least 0. At most 9007199254740991. | +| `height` | integer | Yes | At least 0. At most 9007199254740991. | +| `notices` | array of string | Yes | | +| `bytes` | integer | Yes | At least 0. At most 9007199254740991. | +| `defaults` | string | | Which of the projection and revisions came from what the viewer shows. | + +No other properties are allowed. + +### `page` + +The viewer's page, captured with `--page`. + +| Property | Type | Required | Description | +|---|---|---|---| +| `format` | `"projections.screenshot"` | Yes | | +| `version` | `0` | Yes | | +| `page` | `true` | Yes | | +| `viewer` | string | Yes | | +| `projection` | string | Yes | | +| `theme` | string | Yes | | +| `width` | integer | Yes | At least 0. At most 9007199254740991. | +| `height` | integer | Yes | At least 0. At most 9007199254740991. | +| `notices` | array of string | Yes | | +| `bytes` | integer | Yes | At least 0. At most 9007199254740991. | + +No other properties are allowed. + +### `refusal` + +The viewer refused; the command fails. It has no `format`. + +| Property | Type | Required | Description | +|---|---|---|---| +| `error` | string | Yes | | + +No other properties are allowed. diff --git a/docs/reference/schemas/cli-sweep.md b/docs/reference/schemas/cli-sweep.md index bb1958eac..a28d4d165 100644 --- a/docs/reference/schemas/cli-sweep.md +++ b/docs/reference/schemas/cli-sweep.md @@ -43,7 +43,7 @@ One projection of the sweep, and its tally over the swept changes. | Property | Type | Required | Description | |---|---|---|---| -| `projection` | [`identifier`](definition.md#identifier) | Yes | | +| `projection` | string | Yes | The projection, as given: a failed row keeps an ID that names no definition. | | `status` | [`projectionStatus`](#projectionstatus) | Yes | | | `requiresTrust` | boolean | | | | `error` | string | | Why it was skipped or failed. | diff --git a/docs/reference/schemas/cli-view.md b/docs/reference/schemas/cli-view.md index 3e56d3603..c760ec169 100644 --- a/docs/reference/schemas/cli-view.md +++ b/docs/reference/schemas/cli-view.md @@ -7,4 +7,65 @@ definitions into [`packages/schemas/schemas/cli/view/v0.json`](../../../packages ## Document -Type: object or object or object. +Type: [`nothingShown`](#nothingshown) or [`shown`](#shown) or [`refusal`](#refusal). + +## Definitions + +### `nothingShown` + +Nothing is shown yet. + +| Property | Type | Required | Description | +|---|---|---|---| +| `format` | `"projections.view"` | Yes | | +| `version` | `0` | Yes | | +| `shown` | `false` | Yes | | +| `viewer` | any | Yes | The viewer. | +| `url` | any | Yes | The viewer's page. | +| `viewers` | any | Yes | The other viewers running. | + +No other properties are allowed. + +### `shown` + +What the viewer shows. + +| Property | Type | Required | Description | +|---|---|---|---| +| `format` | `"projections.view"` | Yes | | +| `version` | `0` | Yes | | +| `shown` | `true` | Yes | | +| `surface` | `"viewer"` | Yes | | +| `viewer` | any | Yes | The viewer. | +| `url` | any | Yes | The viewer's page. | +| `chosenBy` | any | Yes | Who chose the projection: the agent, or the person from the page. | +| `viewers` | any | Yes | The other viewers running. | +| `pages` | integer | Yes | At least 0. At most 9007199254740991. | +| `seen` | any | Yes | What the open pages saw. | +| `projection` | string | Yes | | +| `title` | string | Yes | | +| `choice` | any | Yes | How the revisions were chosen. | +| `compared` | string | Yes | | +| `before` | object or null | Yes | | +| `after` | object | Yes | | +| `after.ref` | string | Yes | | +| `after.commit` | string or null | Yes | | +| `scenario` | any | Yes | The scenario shown, for fixtures. | +| `mode` | any | Yes | The comparison mode. | +| `selection` | any | Yes | What the person selected, from the current page. | +| `page` | any | Yes | The current page's view. | +| `failures` | any | Yes | The current page's failures. | +| `document` | object or null | Yes | The saved document shown, instead of the repository. | +| `rendererBuild` | object or null | Yes | | + +No other properties are allowed. + +### `refusal` + +The viewer refused; the command fails. It has no `format`. + +| Property | Type | Required | Description | +|---|---|---|---| +| `error` | string | Yes | | + +No other properties are allowed. diff --git a/packages/cli/test/json-output.test.mjs b/packages/cli/test/json-output.test.mjs index c11105cef..9971066d1 100644 --- a/packages/cli/test/json-output.test.mjs +++ b/packages/cli/test/json-output.test.mjs @@ -3,7 +3,7 @@ // here until its TypeBox source (packages/schemas/src/typebox/cli.ts) changes with it. import assert from 'node:assert/strict' import {execFileSync} from 'node:child_process' -import {mkdir, mkdtemp, readdir, readFile, realpath, rm, writeFile} from 'node:fs/promises' +import {cp, mkdir, mkdtemp, readdir, readFile, realpath, rm, writeFile} from 'node:fs/promises' import {tmpdir} from 'node:os' import path from 'node:path' import test, {after} from 'node:test' @@ -14,6 +14,7 @@ import {commit, fixture} from './repository.mjs' const executable = fileURLToPath(new URL(`../dist/projections${process.platform === 'win32' ? '.exe' : ''}`, import.meta.url)) const schemas = fileURLToPath(new URL('../../schemas/schemas/', import.meta.url)) +const priorityOrder = fileURLToPath(new URL('../../../examples/comparators/priority-order/', import.meta.url)) const host = 'https://schemas.projections.githubnext.com/' const ajv = new Ajv2020({allErrors: true, strictTuples: false}) @@ -107,6 +108,9 @@ test('explore, sweep and adopt print their documents', async () => { assert.ok(candidate, 'a candidate to adopt') conforms('cli/adopt', await ok(root, ['adopt', candidate.id, '--dry-run', '--json', '--bookmarks', '1', '--last', '2'])) conforms('cli/adopt', await ok(root, ['adopt', candidate.id, '--json', '--bookmarks', '0'])) + // A requested ID that names no projection is a failed row that keeps it. + const unknown = conforms('cli/sweep', (await run(root, ['explore', '--sweep', '-p', 'bad/id', '--json', '--last', '2'])).stdout) + assert.equal(unknown.projections[0].status, 'failed') }) test('check, doctor, prepare and the workspaces print their documents', async () => { @@ -120,6 +124,22 @@ test('check, doctor, prepare and the workspaces print their documents', async () conforms('cli/workspaces', await ok(root, ['workspace', 'list', '--json'])) conforms('cli/doctor', (await run(root, ['doctor', '--json'])).stdout) conforms('cli/workspace-clean', await ok(root, ['workspace', 'clean', '--json'])) + // A custom comparator's tests: their cases, coverage and the snapshot --update writes, and a comparator without tests. + const projections = path.join(root, '.github', 'projections') + await cp(priorityOrder, projections, {recursive: true, filter: source => !source.endsWith('README.md')}) + await rm(path.join(projections, 'snapshots'), {recursive: true}) + await cp(path.join(projections, 'priority-order.comparator.yaml'), path.join(projections, 'untested.comparator.yaml')) + const comparator = file => ({file: `.github/projections/${file}`, options: {priority: ['package:@acme/core']}}) + const definition = (id, file) => ({id, extractor: 'repository-map', renderer: 'graph', comparator: comparator(file)}) + await writeFile(path.join(projections, 'ordered.json'), JSON.stringify(definition('ordered', 'priority-order.comparator.yaml'))) + await writeFile(path.join(projections, 'untested.json'), JSON.stringify(definition('untested', 'untested.comparator.yaml'))) + const tested = conforms( + 'cli/check', + (await run(root, ['check', '--json', '--no-render', '--update', '--coverage', '-p', 'ordered', '-p', 'untested'])).stdout, + ) + const steps = tested.projections.flatMap(projection => projection.steps).filter(step => step.file) + assert.ok(steps.some(step => step.cases?.length && step.coverage && step.written)) + assert.ok(steps.some(step => step.status === 'warn')) // An invalid definition file is its own entry. await writeFile(path.join(root, '.github', 'projections', 'broken.json'), '{"id": "broken"}') const broken = conforms('cli/check', (await run(root, ['check', '--json', '--no-render', '-p', 'broken'])).stdout) @@ -134,6 +154,9 @@ test('list, batches, bookmarks, saved documents, validate, extractors and errors conforms('cli/batch', await ok(root, ['compare', `${before}..${head}`, '--all', '--json', '--trust'])) conforms('bookmarks', await ok(root, ['bookmark', 'list', '--json'])) conforms('cli/batch', await ok(root, ['bookmark', 'run', '--json', '--trust'])) + // A requested bookmark that doesn't exist is an error result that keeps its name. + const missing = conforms('cli/batch', (await run(root, ['bookmark', 'run', 'bad/id', '--json'])).stdout) + assert.equal(missing.results[0].status, 'error') conforms('extraction-document', await ok(root, ['show', head, '-p', 'files', '--json'])) const comparison = conforms('comparison-document', await ok(root, ['compare', `${middle}..${head}`, '-p', 'files', '--json'])) const saved = path.join(root, 'saved.json') @@ -184,13 +207,19 @@ test('the viewer commands print their documents', async t => { conforms('cli/view', await ok(root, ['view', 'show', '-p', 'files', '--json'])) conforms('cli/view', await ok(root, ['view', 'current', '--json'])) conforms('cli/view', await ok(root, ['view', 'refresh', '--json'])) - // Where no browser can run (Chrome refuses to as root), the renderer's screenshot prints the refusal its schema - // allows and the page's prints nothing. + // Both captures must succeed wherever a browser can run. Only where none can (none is installed, or Chrome refuses + // to run as root) may they fail: the renderer's then prints the refusal its schema allows, the page's nothing. + const unavailable = /No Chrome, Chromium or Edge|Chrome won't run as root/u for (const page of [[], ['--page']]) { const image = path.join(root, '..', `screenshot-${path.basename(root)}-${page.length}.png`) t.after(() => rm(image, {force: true})) - const {stdout, failed} = await run(root, ['view', 'screenshot', '--out', image, ...page, '--json']) - if (stdout || !failed) conforms('cli/screenshot', stdout) + const {stdout, stderr, failed} = await run(root, ['view', 'screenshot', '--out', image, ...page, '--json']) + if (!failed) { + assert.equal(conforms('cli/screenshot', stdout).format, 'projections.screenshot') + continue + } + assert.match(`${stdout}${stderr}`, unavailable, `view screenshot ${page.join(' ')} failed with a browser available`) + if (stdout) conforms('cli/screenshot', stdout) } }) diff --git a/packages/schemas/schemas/cli/batch/v0.json b/packages/schemas/schemas/cli/batch/v0.json index 0e3b234ce..307c6b504 100644 --- a/packages/schemas/schemas/cli/batch/v0.json +++ b/packages/schemas/schemas/cli/batch/v0.json @@ -25,7 +25,10 @@ "additionalProperties": false, "required": ["id", "status"], "properties": { - "id": {"$ref": "https://schemas.projections.githubnext.com/definition/v0.json#/$defs/identifier"}, + "id": { + "description": "The projection or bookmark, as requested: an error keeps an ID that names neither.", + "type": "string" + }, "status": { "description": "`extracted` (show), `changed` or `unchanged` (compared), `head-only` or `base-only` (one revision defines it, shown alone), or `error`.", "enum": ["extracted", "changed", "unchanged", "head-only", "base-only", "error"] diff --git a/packages/schemas/schemas/cli/check/v0.json b/packages/schemas/schemas/cli/check/v0.json index 4800ef3d3..4b3828f51 100644 --- a/packages/schemas/schemas/cli/check/v0.json +++ b/packages/schemas/schemas/cli/check/v0.json @@ -12,42 +12,7 @@ "ok": {"type": "boolean"}, "projections": { "type": "array", - "items": { - "anyOf": [ - { - "type": "object", - "additionalProperties": false, - "required": ["id", "title", "ok", "steps"], - "properties": { - "id": { - "$ref": "https://schemas.projections.githubnext.com/definition/v0.json#/$defs/identifier" - }, - "title": {"type": "string"}, - "ok": {"type": "boolean"}, - "steps": {"type": "array", "items": {"$ref": "#/$defs/step"}} - } - }, - { - "description": "A definition file that failed to load.", - "type": "object", - "additionalProperties": false, - "required": ["id", "title", "path", "ok", "steps", "diagnostics"], - "properties": { - "id": {"type": "string"}, - "title": {"type": "string"}, - "path": {"type": "string"}, - "ok": {"type": "boolean", "const": false}, - "steps": {"type": "array", "items": {"$ref": "#/$defs/step"}}, - "diagnostics": { - "type": "array", - "items": { - "$ref": "https://schemas.projections.githubnext.com/cli/list/v0.json#/$defs/definitionDiagnostic" - } - } - } - } - ] - } + "items": {"anyOf": [{"$ref": "#/$defs/projection"}, {"$ref": "#/$defs/invalidProjection"}]} } }, "$defs": { @@ -63,6 +28,139 @@ "durationMs": {"type": "number", "minimum": 0} } }, + "comparatorTestDiagnostic": { + "type": "object", + "additionalProperties": false, + "required": ["pointer", "message", "location"], + "properties": { + "pointer": {"type": "string"}, + "message": {"type": "string"}, + "location": { + "type": "object", + "additionalProperties": false, + "required": ["path", "line", "column"], + "properties": { + "path": {"type": "string"}, + "line": {"type": "integer", "minimum": 0, "maximum": 9007199254740991}, + "column": {"type": "integer", "minimum": 0, "maximum": 9007199254740991} + } + } + } + }, + "comparatorTestCase": { + "type": "object", + "additionalProperties": false, + "required": ["id", "name", "status", "location", "failures", "durationMs"], + "properties": { + "id": {"type": "string"}, + "name": {"type": "string"}, + "status": {"enum": ["pass", "fail", "skip"]}, + "location": { + "type": "object", + "additionalProperties": false, + "required": ["path", "line", "column"], + "properties": { + "path": {"type": "string"}, + "line": {"type": "integer", "minimum": 0, "maximum": 9007199254740991}, + "column": {"type": "integer", "minimum": 0, "maximum": 9007199254740991} + } + }, + "failures": { + "type": "array", + "items": { + "type": "object", + "additionalProperties": false, + "required": ["expectation", "message", "location"], + "properties": { + "expectation": {"description": "The JSON pointer of the expectation that failed.", "type": "string"}, + "message": {"type": "string"}, + "location": { + "type": "object", + "additionalProperties": false, + "required": ["path", "line", "column"], + "properties": { + "path": {"type": "string"}, + "line": {"type": "integer", "minimum": 0, "maximum": 9007199254740991}, + "column": {"type": "integer", "minimum": 0, "maximum": 9007199254740991} + } + }, + "expected": {"description": "What the case expected."}, + "actual": {"description": "What the comparator produced."}, + "diff": {"type": "string"} + } + } + }, + "message": {"description": "Why it failed or was skipped.", "type": "string"}, + "durationMs": {"type": "integer", "minimum": 0, "maximum": 9007199254740991} + } + }, + "comparatorCoverage": { + "type": "object", + "additionalProperties": false, + "required": ["comparator", "summary"], + "properties": { + "comparator": {"description": "The comparator file.", "type": "string"}, + "summary": { + "description": "Covered of total, by category (functions, expressions, branches); `null` when nothing ran.", + "anyOf": [ + { + "type": "object", + "additionalProperties": { + "type": "object", + "additionalProperties": false, + "required": ["covered", "total", "excluded", "percent"], + "properties": { + "covered": {"type": "integer", "minimum": 0, "maximum": 9007199254740991}, + "total": {"type": "integer", "minimum": 0, "maximum": 9007199254740991}, + "excluded": {"type": "integer", "minimum": 0, "maximum": 9007199254740991}, + "percent": {"type": "number", "minimum": 0, "maximum": 100} + } + } + }, + {"type": "null"} + ] + }, + "uncovered": { + "type": "array", + "items": { + "type": "object", + "additionalProperties": false, + "required": ["category", "path", "line", "column", "message"], + "properties": { + "category": {"type": "string"}, + "path": {"type": "string"}, + "line": {"type": "integer", "minimum": 0, "maximum": 9007199254740991}, + "column": {"type": "integer", "minimum": 0, "maximum": 9007199254740991}, + "message": {"type": "string"}, + "excluded": { + "description": "Why it is excluded from coverage (its `coverage-ignore:` reason).", + "type": "string" + } + } + } + }, + "excluded": { + "type": "array", + "items": { + "type": "object", + "additionalProperties": false, + "required": ["category", "path", "line", "column", "message"], + "properties": { + "category": {"type": "string"}, + "path": {"type": "string"}, + "line": {"type": "integer", "minimum": 0, "maximum": 9007199254740991}, + "column": {"type": "integer", "minimum": 0, "maximum": 9007199254740991}, + "message": {"type": "string"}, + "excluded": { + "description": "Why it is excluded from coverage (its `coverage-ignore:` reason).", + "type": "string" + } + } + } + }, + "entries": {"description": "The rules interpreter's raw coverage."} + } + }, "step": { "type": "object", "additionalProperties": false, @@ -79,6 +177,49 @@ "description": "Every renderer check, on a renderer step.", "type": "array", "items": {"$ref": "#/$defs/rendererCheck"} + }, + "file": { + "description": "The comparator test file, on a comparator tests step, whether or not it exists.", + "type": "string" + }, + "cases": {"type": "array", "items": {"$ref": "#/$defs/comparatorTestCase"}}, + "diagnostics": { + "description": "Why the comparator test file is invalid.", + "type": "array", + "items": {"$ref": "#/$defs/comparatorTestDiagnostic"} + }, + "written": {"description": "The snapshots `--update` wrote.", "type": "array", "items": {"type": "string"}}, + "coverage": {"$ref": "#/$defs/comparatorCoverage"} + } + }, + "projection": { + "description": "A projection checked: each step of its check.", + "type": "object", + "additionalProperties": false, + "required": ["id", "title", "ok", "steps"], + "properties": { + "id": {"$ref": "https://schemas.projections.githubnext.com/definition/v0.json#/$defs/identifier"}, + "title": {"type": "string"}, + "ok": {"type": "boolean"}, + "steps": {"type": "array", "items": {"$ref": "#/$defs/step"}} + } + }, + "invalidProjection": { + "description": "A definition file that failed to load.", + "type": "object", + "additionalProperties": false, + "required": ["id", "title", "path", "ok", "steps", "diagnostics"], + "properties": { + "id": {"type": "string"}, + "title": {"type": "string"}, + "path": {"type": "string"}, + "ok": {"type": "boolean", "const": false}, + "steps": {"type": "array", "items": {"$ref": "#/$defs/step"}}, + "diagnostics": { + "type": "array", + "items": { + "$ref": "https://schemas.projections.githubnext.com/cli/list/v0.json#/$defs/definitionDiagnostic" + } } } } diff --git a/packages/schemas/schemas/cli/doctor/v0.json b/packages/schemas/schemas/cli/doctor/v0.json index 1df652237..e3e22f86c 100644 --- a/packages/schemas/schemas/cli/doctor/v0.json +++ b/packages/schemas/schemas/cli/doctor/v0.json @@ -28,31 +28,30 @@ "environment": {"$ref": "#/$defs/environment"} }, "$defs": { + "workspaceStrategy": { + "description": "The workspace strategy in effect, where it was set, and why.", + "type": "object", + "additionalProperties": false, + "required": ["strategy", "source", "reason"], + "properties": { + "strategy": {"enum": ["fresh", "worktree", "clone", "sparse", "none"]}, + "source": {"enum": ["flag", "config", "environment", "automatic"]}, + "reason": {"type": "string"} + } + }, + "workspaceError": { + "description": "Why the workspace strategy couldn't be chosen.", + "type": "object", + "additionalProperties": false, + "required": ["error"], + "properties": {"error": {"type": "string"}} + }, "environment": { "type": "object", "additionalProperties": false, "required": ["workspace"], "properties": { - "workspace": { - "anyOf": [ - { - "type": "object", - "additionalProperties": false, - "required": ["strategy", "source", "reason"], - "properties": { - "strategy": {"enum": ["fresh", "worktree", "clone", "sparse", "none"]}, - "source": {"enum": ["flag", "config", "environment", "automatic"]}, - "reason": {"type": "string"} - } - }, - { - "type": "object", - "additionalProperties": false, - "required": ["error"], - "properties": {"error": {"type": "string"}} - } - ] - }, + "workspace": {"anyOf": [{"$ref": "#/$defs/workspaceStrategy"}, {"$ref": "#/$defs/workspaceError"}]}, "workspaces": { "type": "array", "items": { diff --git a/packages/schemas/schemas/cli/prepare/v0.json b/packages/schemas/schemas/cli/prepare/v0.json index ea2b2c384..b4f268f0a 100644 --- a/packages/schemas/schemas/cli/prepare/v0.json +++ b/packages/schemas/schemas/cli/prepare/v0.json @@ -14,34 +14,27 @@ "root": {"description": "Where the steps ran.", "type": "string"}, "strategy": {"description": "The workspace's strategy, for a commit.", "enum": ["worktree", "clone", "sparse"]}, "notes": {"type": "array", "items": {"type": "string"}}, - "steps": { - "type": "array", - "items": { - "anyOf": [ - { - "description": "Unchanged keys: not run.", - "type": "object", - "additionalProperties": false, - "required": ["id", "key", "status"], - "properties": { - "id": {"type": "string"}, - "key": {"type": "string"}, - "status": {"type": "string", "const": "current"} - } - }, - { - "type": "object", - "additionalProperties": false, - "required": ["id", "key", "status", "durationMs", "log"], - "properties": { - "id": {"type": "string"}, - "key": {"type": "string"}, - "status": {"type": "string", "const": "succeeded"}, - "durationMs": {"type": "integer", "minimum": 0, "maximum": 9007199254740991}, - "log": {"type": "string"} - } - } - ] + "steps": {"type": "array", "items": {"anyOf": [{"$ref": "#/$defs/currentStep"}, {"$ref": "#/$defs/ranStep"}]}} + }, + "$defs": { + "currentStep": { + "description": "Unchanged keys: not run.", + "type": "object", + "additionalProperties": false, + "required": ["id", "key", "status"], + "properties": {"id": {"type": "string"}, "key": {"type": "string"}, "status": {"type": "string", "const": "current"}} + }, + "ranStep": { + "description": "A step that ran and succeeded; a failed step fails the command.", + "type": "object", + "additionalProperties": false, + "required": ["id", "key", "status", "durationMs", "log"], + "properties": { + "id": {"type": "string"}, + "key": {"type": "string"}, + "status": {"type": "string", "const": "succeeded"}, + "durationMs": {"type": "integer", "minimum": 0, "maximum": 9007199254740991}, + "log": {"type": "string"} } } } diff --git a/packages/schemas/schemas/cli/screenshot/v0.json b/packages/schemas/schemas/cli/screenshot/v0.json index 4bbb04327..100223247 100644 --- a/packages/schemas/schemas/cli/screenshot/v0.json +++ b/packages/schemas/schemas/cli/screenshot/v0.json @@ -3,8 +3,9 @@ "$id": "https://schemas.projections.githubnext.com/cli/screenshot/v0.json", "title": "CLI viewer screenshot", "description": "The PNG `projections view screenshot --json` wrote, and what it shows.", - "anyOf": [ - { + "anyOf": [{"$ref": "#/$defs/rendered"}, {"$ref": "#/$defs/page"}, {"$ref": "#/$defs/refusal"}], + "$defs": { + "rendered": { "description": "A projection rendered by its renderer.", "type": "object", "additionalProperties": false, @@ -36,10 +37,14 @@ "width": {"type": "integer", "minimum": 0, "maximum": 9007199254740991}, "height": {"type": "integer", "minimum": 0, "maximum": 9007199254740991}, "notices": {"type": "array", "items": {"type": "string"}}, - "bytes": {"type": "integer", "minimum": 0, "maximum": 9007199254740991} + "bytes": {"type": "integer", "minimum": 0, "maximum": 9007199254740991}, + "defaults": { + "description": "Which of the projection and revisions came from what the viewer shows.", + "type": "string" + } } }, - { + "page": { "description": "The viewer's page, captured with `--page`.", "type": "object", "additionalProperties": false, @@ -57,12 +62,12 @@ "bytes": {"type": "integer", "minimum": 0, "maximum": 9007199254740991} } }, - { + "refusal": { "description": "The viewer refused; the command fails. It has no `format`.", "type": "object", "additionalProperties": false, "required": ["error"], "properties": {"error": {"type": "string"}} } - ] + } } diff --git a/packages/schemas/schemas/cli/sweep/v0.json b/packages/schemas/schemas/cli/sweep/v0.json index c706472a7..30c3ade59 100644 --- a/packages/schemas/schemas/cli/sweep/v0.json +++ b/packages/schemas/schemas/cli/sweep/v0.json @@ -38,7 +38,10 @@ "additionalProperties": false, "required": ["projection", "status"], "properties": { - "projection": {"$ref": "https://schemas.projections.githubnext.com/definition/v0.json#/$defs/identifier"}, + "projection": { + "description": "The projection, as given: a failed row keeps an ID that names no definition.", + "type": "string" + }, "status": {"$ref": "#/$defs/projectionStatus"}, "requiresTrust": {"type": "boolean"}, "error": {"description": "Why it was skipped or failed.", "type": "string"}, diff --git a/packages/schemas/schemas/cli/view/v0.json b/packages/schemas/schemas/cli/view/v0.json index fd67c7060..6046210d3 100644 --- a/packages/schemas/schemas/cli/view/v0.json +++ b/packages/schemas/schemas/cli/view/v0.json @@ -3,8 +3,9 @@ "$id": "https://schemas.projections.githubnext.com/cli/view/v0.json", "title": "CLI viewer", "description": "What the viewer shows and what the person selected (`projections view show|current|refresh --json`).", - "anyOf": [ - { + "anyOf": [{"$ref": "#/$defs/nothingShown"}, {"$ref": "#/$defs/shown"}, {"$ref": "#/$defs/refusal"}], + "$defs": { + "nothingShown": { "description": "Nothing is shown yet.", "type": "object", "additionalProperties": false, @@ -18,7 +19,7 @@ "viewers": {"description": "The other viewers running."} } }, - { + "shown": { "description": "What the viewer shows.", "type": "object", "additionalProperties": false, @@ -134,12 +135,12 @@ } } }, - { + "refusal": { "description": "The viewer refused; the command fails. It has no `format`.", "type": "object", "additionalProperties": false, "required": ["error"], "properties": {"error": {"type": "string"}} } - ] + } } diff --git a/packages/schemas/src/typebox/cli-common.ts b/packages/schemas/src/typebox/cli-common.ts new file mode 100644 index 000000000..736430d75 --- /dev/null +++ b/packages/schemas/src/typebox/cli-common.ts @@ -0,0 +1,89 @@ +// What every CLI document shares: its kind and version, and the failure reports and diagnostics several carry. +import Type, {type TProperties, type TSchema} from 'typebox' +import {Closed, define} from './support.js' + +/** A non-negative safe integer. */ +export const Count = Type.Integer({minimum: 0, maximum: Number.MAX_SAFE_INTEGER}) +/** `schema`, or `null`. */ +export const Nullable = (schema: T, options: {description?: string} = {}) => Type.Union([schema, Type.Null()], options) +/** A `sha256:` digest. */ +export const Sha256Digest = Type.String({pattern: '^sha256:[0-9a-f]{64}$'}) +/** A value the CLI passes through from another component without shaping it here. */ +export const Passed = (description: string) => Type.Unknown({description}) + +/** A CLI document's kind and version: `format` names it, `version` is its major version. */ +export function Document(format: F, properties: P, options: {description: string}) { + return Closed({format: Type.Literal(format), version: Type.Literal(0), ...properties}, options) +} + +// Errors --------------------------------------------------------------------------------------------------------- + +/** One problem the engine or runner found: where (`path`, a JSON pointer or file), and what. */ +export const CliDiagnosticSchema = define( + 'cli/error', + 'diagnostic', + Closed( + { + severity: Type.Enum(['error', 'warning']), + code: Type.String(), + path: Type.String({description: 'A JSON pointer into the extraction, or empty.'}), + message: Type.String(), + entityId: Type.Optional(Type.String({description: 'The entity the problem is about, when there is one.'})), + }, + {description: 'One problem the engine or runner found.'}, + ), +) + +/** The JSON Schema of a failure report, `cli/error#/$defs/report`: a `projections.error` document's `error`, and a failed `check` step's. */ +export const CliErrorReportSchema = define( + 'cli/error', + 'report', + Closed( + { + code: Type.Enum(['TRUST_REQUIRED', 'EXTRACTOR_FAILED', 'INVALID_EXTRACTION', 'INVALID_INPUT', 'ERROR']), + message: Type.String(), + hint: Type.Optional(Type.String({description: 'What to do next.'})), + diagnostics: Type.Array(CliDiagnosticSchema), + stderr: Type.Optional(Type.String({description: "A failed extractor's standard error, for `EXTRACTOR_FAILED`."})), + }, + {description: 'What failed (a stable code), where, the evidence and what to do next.'}, + ), +) + +/** The JSON Schema of `projections.error`, what a command run with `--json` or `--output` prints when it fails. */ +export const CliErrorSchema = define( + 'cli/error', + undefined, + Document( + 'projections.error', + {error: CliErrorReportSchema}, + {description: 'What a command run with `--json` or `--output` prints to stdout when it fails, besides its message on stderr.'}, + ), +) + +// Definitions ---------------------------------------------------------------------------------------------------- + +/** An invalid definition file's diagnostic: its code, the file and the line and column of the problem. */ +export const DefinitionDiagnosticSchema = define( + 'cli/list', + 'definitionDiagnostic', + Closed({ + code: Type.String(), + severity: Type.Enum(['error', 'warning']), + message: Type.String(), + path: Type.String({description: 'The definition file, relative to the repository.'}), + location: Closed({path: Type.String(), line: Count, column: Count}), + pointer: Type.Optional(Type.String({description: 'A JSON pointer to the invalid value, when the error names one.'})), + }), +) + +/** A definition file that doesn't load: its ID when it has a readable one, its path and why. */ +export const InvalidDefinitionSchema = define( + 'cli/list', + 'invalidDefinition', + Closed({ + id: Nullable(Type.String(), {description: "The file's `id`, when it has a readable one."}), + path: Type.String(), + diagnostics: Type.Array(DefinitionDiagnosticSchema), + }), +) diff --git a/packages/schemas/src/typebox/cli-environment.ts b/packages/schemas/src/typebox/cli-environment.ts new file mode 100644 index 000000000..7e7f3e581 --- /dev/null +++ b/packages/schemas/src/typebox/cli-environment.ts @@ -0,0 +1,294 @@ +// The documents `check`, `doctor`, `prepare` and `workspace` print. +import Type from 'typebox' +import {CliErrorReportSchema, Count, DefinitionDiagnosticSchema, Document, Nullable, Passed} from './cli-common.js' +import {Identifier} from './definition.js' +import {Closed, define, Dictionary} from './support.js' + +// Check ---------------------------------------------------------------------------------------------------------- + +const CheckStatus = Type.Enum(['pass', 'fail', 'warn', 'skip']) + +/** One renderer check's outcome, as the renderer checks report it. */ +export const RendererCheckSchema = define( + 'cli/check', + 'rendererCheck', + Closed({ + id: Type.String(), + title: Type.String(), + status: Type.Enum(['pass', 'fail', 'skip', 'advice']), + details: Type.Array(Type.String()), + durationMs: Type.Number({minimum: 0}), + }), +) + +/** Where in a comparator test file: its path, line and column. */ +const TestLocation = Closed({path: Type.String(), line: Count, column: Count}) + +/** A comparator test file's problem: the JSON pointer of what is wrong, and why. */ +export const ComparatorTestDiagnosticSchema = define( + 'cli/check', + 'comparatorTestDiagnostic', + Closed({pointer: Type.String(), message: Type.String(), location: TestLocation}), +) + +/** The JSON Schema of one comparator test case's outcome, `cli/check#/$defs/comparatorTestCase`. */ +export const ComparatorTestCaseSchema = define( + 'cli/check', + 'comparatorTestCase', + Closed({ + id: Type.String(), + name: Type.String(), + status: Type.Enum(['pass', 'fail', 'skip']), + location: TestLocation, + failures: Type.Array( + Closed({ + expectation: Type.String({description: 'The JSON pointer of the expectation that failed.'}), + message: Type.String(), + location: TestLocation, + expected: Type.Optional(Passed('What the case expected.')), + actual: Type.Optional(Passed('What the comparator produced.')), + diff: Type.Optional(Type.String()), + }), + ), + message: Type.Optional(Type.String({description: 'Why it failed or was skipped.'})), + durationMs: Count, + }), +) + +/** One rules entry a coverage report lists, uncovered or excluded. */ +const CoverageEntry = Closed({ + category: Type.String(), + path: Type.String(), + line: Count, + column: Count, + message: Type.String(), + excluded: Type.Optional(Type.String({description: 'Why it is excluded from coverage (its `coverage-ignore:` reason).'})), +}) + +/** The JSON Schema of a comparator test file's rule coverage, `cli/check#/$defs/comparatorCoverage` (`check --coverage`). */ +export const ComparatorCoverageSchema = define( + 'cli/check', + 'comparatorCoverage', + Closed({ + comparator: Type.String({description: 'The comparator file.'}), + summary: Type.Union( + [Dictionary(Closed({covered: Count, total: Count, excluded: Count, percent: Type.Number({minimum: 0, maximum: 100})})), Type.Null()], + {description: 'Covered of total, by category (functions, expressions, branches); `null` when nothing ran.'}, + ), + uncovered: Type.Optional(Type.Array(CoverageEntry)), + excluded: Type.Optional(Type.Array(CoverageEntry)), + entries: Type.Optional(Passed("The rules interpreter's raw coverage.")), + }), +) + +/** The JSON Schema of one check step, `cli/check#/$defs/step`. */ +export const CheckStepSchema = define( + 'cli/check', + 'step', + Closed({ + id: Type.String(), + title: Type.String(), + status: CheckStatus, + message: Type.String(), + error: Type.Optional(CliErrorReportSchema), + details: Type.Optional(Type.Array(Type.String())), + rerun: Type.Optional(Type.String({description: 'The command that runs the failed renderer checks again.'})), + checks: Type.Optional(Type.Array(RendererCheckSchema, {description: 'Every renderer check, on a renderer step.'})), + file: Type.Optional(Type.String({description: 'The comparator test file, on a comparator tests step, whether or not it exists.'})), + cases: Type.Optional(Type.Array(ComparatorTestCaseSchema)), + diagnostics: Type.Optional(Type.Array(ComparatorTestDiagnosticSchema, {description: 'Why the comparator test file is invalid.'})), + written: Type.Optional(Type.Array(Type.String(), {description: 'The snapshots `--update` wrote.'})), + coverage: Type.Optional(ComparatorCoverageSchema), + }), +) + +/** The JSON Schema of `projections.check`, what `projections check --json` prints. */ +export const CliCheckSchema = define( + 'cli/check', + undefined, + Document( + 'projections.check', + { + ok: Type.Boolean(), + projections: Type.Array( + Type.Union([ + define( + 'cli/check', + 'projection', + Closed( + {id: Identifier, title: Type.String(), ok: Type.Boolean(), steps: Type.Array(CheckStepSchema)}, + {description: 'A projection checked: each step of its check.'}, + ), + ), + define( + 'cli/check', + 'invalidProjection', + Closed( + { + id: Type.String(), + title: Type.String(), + path: Type.String(), + ok: Type.Literal(false), + steps: Type.Array(CheckStepSchema), + diagnostics: Type.Array(DefinitionDiagnosticSchema), + }, + {description: 'A definition file that failed to load.'}, + ), + ), + ]), + ), + }, + {description: 'Projections verified end to end: extraction, comparison and renderer checks (`projections check --json`).'}, + ), +) + +// Environment ---------------------------------------------------------------------------------------------------- + +const Strategy = Type.Enum(['fresh', 'worktree', 'clone', 'sparse', 'none']) + +/** The JSON Schema of a workspace, `cli/workspaces#/$defs/workspace`. Its recorded state is `null` when unreadable. */ +export const WorkspaceSchema = define( + 'cli/workspaces', + 'workspace', + Closed({ + name: Type.String(), + strategy: Nullable(Strategy), + commit: Nullable(Type.String()), + at: Nullable(Type.String()), + scope: Type.Unknown({description: 'The scope it holds, for a sparse workspace; `null` otherwise.'}), + path: Type.String(), + busy: Type.Boolean({description: 'Whether a run is using it.'}), + prepared: Type.Array(Closed({id: Type.String(), status: Nullable(Type.String()), at: Nullable(Type.String())})), + }), +) + +/** The JSON Schema of `projections.workspaces`, what `projections workspace list --json` prints. */ +export const CliWorkspacesSchema = define( + 'cli/workspaces', + undefined, + Document( + 'projections.workspaces', + {directory: Type.String(), workspaces: Type.Array(WorkspaceSchema)}, + {description: 'The workspaces Projections keeps for the repository (`projections workspace list --json`).'}, + ), +) + +/** The JSON Schema of `projections.workspace-clean`, what `projections workspace clean --json` prints. */ +export const CliWorkspaceCleanSchema = define( + 'cli/workspace-clean', + undefined, + Document( + 'projections.workspace-clean', + {removed: Type.Array(Type.String(), {description: 'The workspaces removed; busy ones are kept.'})}, + {description: 'The workspaces `projections workspace clean --json` removed.'}, + ), +) + +/** A prepare step's last run in the working tree. */ +const LastRun = Closed({ + key: Type.String(), + at: Type.String(), + durationMs: Count, + log: Type.String(), + status: Type.Enum(['succeeded', 'failed']), + error: Type.Optional(Type.String()), +}) + +/** The JSON Schema of the environment report, `cli/doctor#/$defs/environment`. */ +export const EnvironmentReportSchema = define( + 'cli/doctor', + 'environment', + Closed({ + workspace: Type.Union([ + define( + 'cli/doctor', + 'workspaceStrategy', + Closed( + {strategy: Strategy, source: Type.Enum(['flag', 'config', 'environment', 'automatic']), reason: Type.String()}, + {description: 'The workspace strategy in effect, where it was set, and why.'}, + ), + ), + define( + 'cli/doctor', + 'workspaceError', + Closed({error: Type.String()}, {description: "Why the workspace strategy couldn't be chosen."}), + ), + ]), + workspaces: Type.Optional(Type.Array(WorkspaceSchema)), + workspacesError: Type.Optional(Type.String()), + declared: Type.Optional(Nullable(Type.String(), {description: 'The environment file, or `null` when none is declared.'})), + error: Type.Optional(Type.String()), + prepare: Type.Optional( + Type.Array( + Closed({ + id: Type.String(), + run: Type.Array(Type.String()), + directory: Type.String(), + key: Type.String(), + state: Type.Enum(['current', 'stale', 'failed', 'never']), + last: Type.Optional(LastRun), + }), + ), + ), + toolchain: Type.Optional(Type.Array(Type.Array(Type.String()))), + devcontainer: Type.Optional(Nullable(Type.String())), + missing: Type.Optional(Type.Array(Type.String())), + }), +) + +/** A doctor finding. */ +export const DoctorItemSchema = define( + 'cli/doctor', + 'item', + Closed({status: Type.Enum(['pass', 'warn', 'fail']), title: Type.String(), message: Type.String()}), +) + +/** The JSON Schema of `projections.doctor`, what `projections doctor --json` prints. */ +export const CliDoctorSchema = define( + 'cli/doctor', + undefined, + Document( + 'projections.doctor', + { + ok: Type.Boolean(), + items: Type.Array(DoctorItemSchema), + projections: Type.Array(Closed({id: Identifier, title: Type.String(), ok: Type.Boolean(), items: Type.Array(DoctorItemSchema)})), + environment: Type.Optional(EnvironmentReportSchema), + }, + {description: 'What the checkout needs to run its projections, found without running anything (`projections doctor --json`).'}, + ), +) + +/** The JSON Schema of `projections.prepare`, what `projections prepare --json` prints. */ +export const CliPrepareSchema = define( + 'cli/prepare', + undefined, + Document( + 'projections.prepare', + { + target: Type.String({description: '`working-tree`, or the commit whose workspace was prepared.'}), + environment: Type.String({description: 'The environment file.'}), + root: Type.String({description: 'Where the steps ran.'}), + strategy: Type.Optional(Type.Enum(['worktree', 'clone', 'sparse'], {description: "The workspace's strategy, for a commit."})), + notes: Type.Optional(Type.Array(Type.String())), + steps: Type.Array( + Type.Union([ + define( + 'cli/prepare', + 'currentStep', + Closed({id: Type.String(), key: Type.String(), status: Type.Literal('current')}, {description: 'Unchanged keys: not run.'}), + ), + define( + 'cli/prepare', + 'ranStep', + Closed( + {id: Type.String(), key: Type.String(), status: Type.Literal('succeeded'), durationMs: Count, log: Type.String()}, + {description: 'A step that ran and succeeded; a failed step fails the command.'}, + ), + ), + ]), + ), + }, + {description: "The environment's prepare steps, run in the working tree or a commit's workspace (`projections prepare --json`)."}, + ), +) diff --git a/packages/schemas/src/typebox/cli-explore.ts b/packages/schemas/src/typebox/cli-explore.ts new file mode 100644 index 000000000..fdcb67867 --- /dev/null +++ b/packages/schemas/src/typebox/cli-explore.ts @@ -0,0 +1,178 @@ +// The documents `projections explore` and `projections adopt` print: candidates, sweeps and what adopt writes. +import Type from 'typebox' +import {Count, Document, Nullable, Sha256Digest} from './cli-common.js' +import {DefinitionSchema, Identifier} from './definition.js' +import {annotated, Closed, define, Dictionary} from './support.js' + +// Explore -------------------------------------------------------------------------------------------------------- + +/** Something a candidate needs before it can run, such as an install. */ +export const CandidateNeedSchema = define( + 'cli/explore', + 'need', + Closed({kind: Type.Enum(['configuration', 'install']), message: Type.String()}), +) + +/** The JSON Schema of one explore candidate, `cli/explore#/$defs/candidate`: a built-in projection that applies, as a trial definition. */ +export const CandidateSchema = define( + 'cli/explore', + 'candidate', + Closed( + { + id: Identifier, + title: Type.String(), + description: Type.String(), + extractor: Identifier, + schema: Type.String({description: 'The domain schema its extractions use, such as `graph/v0`.'}), + renderer: Type.String(), + requiresTrust: Type.Boolean(), + basis: Closed( + { + pattern: Type.Optional(Type.String({description: 'The detection pattern that matched; absent for a candidate named by ID.'})), + named: Type.Optional(Type.Literal(true, {description: '`adopt` named the built-in extractor; explore did not propose it.'})), + count: Count, + examples: Type.Array(Type.String()), + file: Type.Optional(Type.String({description: 'The one file or manifest a per-file candidate reads.'})), + skipped: Type.Optional(annotated(Count, {description: 'Files `.gitattributes` marks vendored or generated.'})), + crates: Type.Optional(annotated(Count, {description: "The Rust workspace's crates."})), + }, + {description: 'Why it was proposed: the detection pattern that matched, how many files and the first few.'}, + ), + adopted: Nullable(Type.String(), {description: 'The authored definition that already uses it, if any.'}), + definition: DefinitionSchema, + needs: Type.Optional(Type.Array(CandidateNeedSchema)), + }, + {description: 'A built-in projection that applies to the repository, as a trial definition.'}, + ), +) + +/** The JSON Schema of `projections.explore`, what `projections explore --list --json` prints. */ +export const CliExploreSchema = define( + 'cli/explore', + undefined, + Document( + 'projections.explore', + {candidates: Type.Array(CandidateSchema)}, + {description: 'The built-in projections that apply to the repository (`projections explore --list --json`).'}, + ), +) + +// Sweep ---------------------------------------------------------------------------------------------------------- + +/** The JSON Schema of a swept change, `cli/sweep#/$defs/change`: a revision compared with the one before it. */ +export const SweepChangeSchema = define( + 'cli/sweep', + 'change', + Closed({ + before: Type.String(), + after: Type.String(), + title: Type.String(), + number: Nullable(Count, {description: 'The pull request number its message names, if any.'}), + kind: Type.Enum(['merge', 'commit'], {description: 'A merge commit, or a first-parent commit.'}), + date: Type.String({description: "The commit's date, ISO 8601."}), + }), +) + +/** Whether a projection could be swept: `ready`, skipped because it needs `--trust`, or failed to prepare. */ +export const SweepProjectionStatusSchema = define('cli/sweep', 'projectionStatus', Type.Enum(['ready', 'trust', 'failed'])) + +/** + * The JSON Schema of one swept projection, `cli/sweep#/$defs/projection`: its status and, once ready, its tally over + * the cells. Rows are ranked best signal first. A streamed sweep prints one of these per projection. + */ +export const SweepProjectionSchema = define( + 'cli/sweep', + 'projection', + Closed( + { + projection: Type.String({description: 'The projection, as given: a failed row keeps an ID that names no definition.'}), + status: SweepProjectionStatusSchema, + requiresTrust: Type.Optional(Type.Boolean()), + error: Type.Optional(Type.String({description: 'Why it was skipped or failed.'})), + signal: Type.Optional( + Type.Enum(['rare', 'steady', 'unknown', 'noisy', 'quiet'], {description: 'How useful its changes look, for a ready projection.'}), + ), + changed: Type.Optional(annotated(Count, {description: 'Changes it showed a change on, besides version-only ones.'})), + versionOnly: Type.Optional(annotated(Count, {description: 'Changes where only version strings moved.'})), + failed: Type.Optional(annotated(Count, {description: 'Changes it failed on.'})), + }, + {description: 'One projection of the sweep, and its tally over the swept changes.'}, + ), +) + +/** A sweep cell's outcome. */ +export const SweepCellStatusSchema = define('cli/sweep', 'cellStatus', Type.Enum(['changed', 'unchanged', 'failed'])) + +/** The JSON Schema of one sweep cell, `cli/sweep#/$defs/cell`: one projection on one change. */ +export const SweepCellSchema = define( + 'cli/sweep', + 'cell', + Closed( + { + projection: Identifier, + before: Type.String(), + after: Type.String(), + status: SweepCellStatusSchema, + changes: Type.Optional(Count), + steps: Type.Optional(Count), + counts: Type.Optional(Dictionary(Count, {description: 'Changes by status (`added`, `removed`, `modified`, …).'})), + versionOnly: Type.Optional( + Type.Literal(true, {description: 'Changed, but only version strings moved (a dependency or action bump).'}), + ), + error: Type.Optional(Type.String()), + stderr: Type.Optional(Type.String({description: "The end of a failed extractor's stderr."})), + }, + {description: 'One projection on one change: its comparison counts, or why it failed.'}, + ), +) + +/** Something about the sweep as a whole, such as a shallow clone's missing history. */ +export const SweepNoteSchema = define('cli/sweep', 'note', Type.String()) + +/** The JSON Schema of `projections.sweep`, what `projections explore --sweep --json` prints. */ +export const CliSweepSchema = define( + 'cli/sweep', + undefined, + Document( + 'projections.sweep', + { + changes: Type.Array(SweepChangeSchema), + projections: Type.Array(SweepProjectionSchema), + cells: Type.Array(SweepCellSchema), + notes: Type.Array(SweepNoteSchema), + }, + {description: 'Each candidate and adopted projection tried on recent changes (`projections explore --sweep --json`).'}, + ), +) + +// Adopt ---------------------------------------------------------------------------------------------------------- + +/** Something about how adopt chose bookmarks, or why a projection has none. */ +export const AdoptNoteSchema = define('cli/adopt', 'note', Type.String()) + +/** The JSON Schema of `projections.adopt`, what `projections adopt --json` prints. */ +export const CliAdoptSchema = define( + 'cli/adopt', + undefined, + Document( + 'projections.adopt', + { + files: Type.Array( + Closed({ + path: Type.String(), + before: Nullable(Type.String(), {description: 'Its current content; `null` when it is absent.'}), + after: Type.String(), + created: Type.Boolean(), + changed: Type.Boolean(), + }), + {description: 'The definitions and the bookmarks file it writes, or would write.'}, + ), + digest: annotated(Sha256Digest, {description: "The files' contents before, which a write must still find."}), + written: Type.Boolean({description: '`false` for `--dry-run`.'}), + adopted: Type.Array(Identifier), + bookmarked: Type.Array(Closed({id: Identifier, projection: Identifier, change: SweepChangeSchema})), + notes: Type.Array(AdoptNoteSchema), + }, + {description: 'The definitions and bookmarks adopting projections writes (`projections adopt --json`).'}, + ), +) diff --git a/packages/schemas/src/typebox/cli-viewer.ts b/packages/schemas/src/typebox/cli-viewer.ts new file mode 100644 index 000000000..e7a8d88c2 --- /dev/null +++ b/packages/schemas/src/typebox/cli-viewer.ts @@ -0,0 +1,140 @@ +// The documents the viewer commands print: `view show`, `current`, `refresh` and `screenshot`. +import Type from 'typebox' +import {Count, Document, Nullable, Passed} from './cli-common.js' +import {Closed, define} from './support.js' + +// Viewer --------------------------------------------------------------------------------------------------------- + +const Side = Closed({ref: Type.String(), commit: Nullable(Type.String())}) + +/** The JSON Schema of `projections.view`, what `projections view show`, `view current` and `view refresh` print with `--json`. */ +export const CliViewSchema = define( + 'cli/view', + undefined, + Type.Union( + [ + define( + 'cli/view', + 'nothingShown', + Document( + 'projections.view', + { + shown: Type.Literal(false), + viewer: Passed('The viewer.'), + url: Passed("The viewer's page."), + viewers: Passed('The other viewers running.'), + }, + {description: 'Nothing is shown yet.'}, + ), + ), + define( + 'cli/view', + 'shown', + Document( + 'projections.view', + { + shown: Type.Literal(true), + surface: Type.Literal('viewer'), + viewer: Passed('The viewer.'), + url: Passed("The viewer's page."), + chosenBy: Passed('Who chose the projection: the agent, or the person from the page.'), + viewers: Passed('The other viewers running.'), + pages: Count, + seen: Passed('What the open pages saw.'), + projection: Type.String(), + title: Type.String(), + choice: Passed('How the revisions were chosen.'), + compared: Type.String(), + before: Nullable(Side), + after: Side, + scenario: Passed('The scenario shown, for fixtures.'), + mode: Passed('The comparison mode.'), + selection: Passed('What the person selected, from the current page.'), + page: Passed("The current page's view."), + failures: Passed("The current page's failures."), + document: Nullable( + Closed({ + path: Type.String(), + format: Passed("The document's format."), + renderer: Type.Union([Closed({builtIn: Passed('The built-in renderer.')}), Closed({bundle: Type.String()})]), + }), + {description: 'The saved document shown, instead of the repository.'}, + ), + rendererBuild: Nullable( + Closed({ + phase: Type.String(), + error: Passed('Why the build failed.'), + script: Passed('The build script.'), + package: Passed("The renderer's package."), + bundled: Type.Boolean(), + }), + ), + }, + {description: 'What the viewer shows.'}, + ), + ), + define( + 'cli/view', + 'refusal', + Closed({error: Type.String()}, {description: 'The viewer refused; the command fails. It has no `format`.'}), + ), + ], + {description: 'What the viewer shows and what the person selected (`projections view show|current|refresh --json`).'}, + ), +) + +/** The JSON Schema of `projections.screenshot`, what `projections view screenshot --json` prints. */ +export const CliScreenshotSchema = define( + 'cli/screenshot', + undefined, + Type.Union( + [ + define( + 'cli/screenshot', + 'rendered', + Document( + 'projections.screenshot', + { + projection: Passed('The projection drawn.'), + scenario: Passed('The scenario drawn, or `null`.'), + before: Passed('The revision before, or `null`.'), + after: Passed('The revision after, or `null` for a scenario.'), + mode: Nullable(Type.String()), + progress: Passed('The comparison progress drawn.'), + theme: Type.String(), + width: Count, + height: Count, + notices: Type.Array(Type.String()), + bytes: Count, + defaults: Type.Optional(Type.String({description: 'Which of the projection and revisions came from what the viewer shows.'})), + }, + {description: 'A projection rendered by its renderer.'}, + ), + ), + define( + 'cli/screenshot', + 'page', + Document( + 'projections.screenshot', + { + page: Type.Literal(true), + viewer: Type.String(), + projection: Type.String(), + theme: Type.String(), + width: Count, + height: Count, + notices: Type.Array(Type.String()), + bytes: Count, + }, + {description: "The viewer's page, captured with `--page`."}, + ), + ), + define( + 'cli/screenshot', + 'refusal', + Closed({error: Type.String()}, {description: 'The viewer refused; the command fails. It has no `format`.'}), + ), + ], + {description: 'The PNG `projections view screenshot --json` wrote, and what it shows.'}, + ), +) diff --git a/packages/schemas/src/typebox/cli.ts b/packages/schemas/src/typebox/cli.ts index 516fdae23..9cd18bc0b 100644 --- a/packages/schemas/src/typebox/cli.ts +++ b/packages/schemas/src/typebox/cli.ts @@ -6,94 +6,39 @@ // a sweep cell's status (`cli/sweep#/$defs/cellStatus`), a swept projection with its tally (`cli/sweep#/$defs/projection`, // which is also what a streamed sweep prints per projection), the sweep's notes (`cli/sweep#/$defs/note`) and // adopt's notes (`cli/adopt#/$defs/note`). -import Type, {type Static, type TProperties, type TSchema} from 'typebox' +import Type, {type Static} from 'typebox' +import {CliDiagnosticSchema, type CliErrorReportSchema, CliErrorSchema, Count, Document, InvalidDefinitionSchema} from './cli-common.js' +import { + type CandidateSchema, + CliAdoptSchema, + CliExploreSchema, + CliSweepSchema, + type SweepCellSchema, + type SweepChangeSchema, + type SweepProjectionSchema, +} from './cli-explore.js' +import { + type CheckStepSchema, + CliCheckSchema, + CliDoctorSchema, + CliPrepareSchema, + CliWorkspaceCleanSchema, + CliWorkspacesSchema, + type EnvironmentReportSchema, + type WorkspaceSchema, +} from './cli-environment.js' +import {CliScreenshotSchema, CliViewSchema} from './cli-viewer.js' import {DefinitionSchema, Identifier, RendererReference} from './definition.js' import {ComparisonDocumentSchema, ExtractionDocumentSchema, RevisionSchema} from './documents.js' import {annotated, Closed, define, Dictionary} from './support.js' -const Count = Type.Integer({minimum: 0, maximum: Number.MAX_SAFE_INTEGER}) -const Nullable = (schema: T, options: {description?: string} = {}) => Type.Union([schema, Type.Null()], options) -const Sha256Digest = Type.String({pattern: '^sha256:[0-9a-f]{64}$'}) -/** A value the CLI passes through from another component without shaping it here. */ -const Passed = (description: string) => Type.Unknown({description}) - -/** A CLI document's kind and version: `format` names it, `version` is its major version. */ -function Document(format: F, properties: P, options: {description: string}) { - return Closed({format: Type.Literal(format), version: Type.Literal(0), ...properties}, options) -} - -// Errors --------------------------------------------------------------------------------------------------------- - -/** One problem the engine or runner found: where (`path`, a JSON pointer or file), and what. */ -export const CliDiagnosticSchema = define( - 'cli/error', - 'diagnostic', - Closed( - { - severity: Type.Enum(['error', 'warning']), - code: Type.String(), - path: Type.String({description: 'A JSON pointer into the extraction, or empty.'}), - message: Type.String(), - entityId: Type.Optional(Type.String({description: 'The entity the problem is about, when there is one.'})), - }, - {description: 'One problem the engine or runner found.'}, - ), -) - -/** The JSON Schema of a failure report, `cli/error#/$defs/report`: a `projections.error` document's `error`, and a failed `check` step's. */ -export const CliErrorReportSchema = define( - 'cli/error', - 'report', - Closed( - { - code: Type.Enum(['TRUST_REQUIRED', 'EXTRACTOR_FAILED', 'INVALID_EXTRACTION', 'INVALID_INPUT', 'ERROR']), - message: Type.String(), - hint: Type.Optional(Type.String({description: 'What to do next.'})), - diagnostics: Type.Array(CliDiagnosticSchema), - stderr: Type.Optional(Type.String({description: "A failed extractor's standard error, for `EXTRACTOR_FAILED`."})), - }, - {description: 'What failed (a stable code), where, the evidence and what to do next.'}, - ), -) - -/** The JSON Schema of `projections.error`, what a command run with `--json` or `--output` prints when it fails. */ -export const CliErrorSchema = define( - 'cli/error', - undefined, - Document( - 'projections.error', - {error: CliErrorReportSchema}, - {description: 'What a command run with `--json` or `--output` prints to stdout when it fails, besides its message on stderr.'}, - ), -) +export * from './cli-common.js' +export * from './cli-environment.js' +export * from './cli-explore.js' +export * from './cli-viewer.js' // Definitions ---------------------------------------------------------------------------------------------------- -/** An invalid definition file's diagnostic: its code, the file and the line and column of the problem. */ -export const DefinitionDiagnosticSchema = define( - 'cli/list', - 'definitionDiagnostic', - Closed({ - code: Type.String(), - severity: Type.Enum(['error', 'warning']), - message: Type.String(), - path: Type.String({description: 'The definition file, relative to the repository.'}), - location: Closed({path: Type.String(), line: Count, column: Count}), - pointer: Type.Optional(Type.String({description: 'A JSON pointer to the invalid value, when the error names one.'})), - }), -) - -/** A definition file that doesn't load: its ID when it has a readable one, its path and why. */ -export const InvalidDefinitionSchema = define( - 'cli/list', - 'invalidDefinition', - Closed({ - id: Nullable(Type.String(), {description: "The file's `id`, when it has a readable one."}), - path: Type.String(), - diagnostics: Type.Array(DefinitionDiagnosticSchema), - }), -) - /** The JSON Schema of `projections.list`, what `projections list --json` prints. */ export const CliListSchema = define( 'cli/list', @@ -121,370 +66,6 @@ export const CliListSchema = define( ), ) -// Explore -------------------------------------------------------------------------------------------------------- - -/** Something a candidate needs before it can run, such as an install. */ -export const CandidateNeedSchema = define( - 'cli/explore', - 'need', - Closed({kind: Type.Enum(['configuration', 'install']), message: Type.String()}), -) - -/** The JSON Schema of one explore candidate, `cli/explore#/$defs/candidate`: a built-in projection that applies, as a trial definition. */ -export const CandidateSchema = define( - 'cli/explore', - 'candidate', - Closed( - { - id: Identifier, - title: Type.String(), - description: Type.String(), - extractor: Identifier, - schema: Type.String({description: 'The domain schema its extractions use, such as `graph/v0`.'}), - renderer: Type.String(), - requiresTrust: Type.Boolean(), - basis: Closed( - { - pattern: Type.Optional(Type.String({description: 'The detection pattern that matched; absent for a candidate named by ID.'})), - named: Type.Optional(Type.Literal(true, {description: '`adopt` named the built-in extractor; explore did not propose it.'})), - count: Count, - examples: Type.Array(Type.String()), - file: Type.Optional(Type.String({description: 'The one file or manifest a per-file candidate reads.'})), - skipped: Type.Optional(annotated(Count, {description: 'Files `.gitattributes` marks vendored or generated.'})), - crates: Type.Optional(annotated(Count, {description: "The Rust workspace's crates."})), - }, - {description: 'Why it was proposed: the detection pattern that matched, how many files and the first few.'}, - ), - adopted: Nullable(Type.String(), {description: 'The authored definition that already uses it, if any.'}), - definition: DefinitionSchema, - needs: Type.Optional(Type.Array(CandidateNeedSchema)), - }, - {description: 'A built-in projection that applies to the repository, as a trial definition.'}, - ), -) - -/** The JSON Schema of `projections.explore`, what `projections explore --list --json` prints. */ -export const CliExploreSchema = define( - 'cli/explore', - undefined, - Document( - 'projections.explore', - {candidates: Type.Array(CandidateSchema)}, - {description: 'The built-in projections that apply to the repository (`projections explore --list --json`).'}, - ), -) - -// Sweep ---------------------------------------------------------------------------------------------------------- - -/** The JSON Schema of a swept change, `cli/sweep#/$defs/change`: a revision compared with the one before it. */ -export const SweepChangeSchema = define( - 'cli/sweep', - 'change', - Closed({ - before: Type.String(), - after: Type.String(), - title: Type.String(), - number: Nullable(Count, {description: 'The pull request number its message names, if any.'}), - kind: Type.Enum(['merge', 'commit'], {description: 'A merge commit, or a first-parent commit.'}), - date: Type.String({description: "The commit's date, ISO 8601."}), - }), -) - -/** Whether a projection could be swept: `ready`, skipped because it needs `--trust`, or failed to prepare. */ -export const SweepProjectionStatusSchema = define('cli/sweep', 'projectionStatus', Type.Enum(['ready', 'trust', 'failed'])) - -/** - * The JSON Schema of one swept projection, `cli/sweep#/$defs/projection`: its status and, once ready, its tally over - * the cells. Rows are ranked best signal first. A streamed sweep prints one of these per projection. - */ -export const SweepProjectionSchema = define( - 'cli/sweep', - 'projection', - Closed( - { - projection: Identifier, - status: SweepProjectionStatusSchema, - requiresTrust: Type.Optional(Type.Boolean()), - error: Type.Optional(Type.String({description: 'Why it was skipped or failed.'})), - signal: Type.Optional( - Type.Enum(['rare', 'steady', 'unknown', 'noisy', 'quiet'], {description: 'How useful its changes look, for a ready projection.'}), - ), - changed: Type.Optional(annotated(Count, {description: 'Changes it showed a change on, besides version-only ones.'})), - versionOnly: Type.Optional(annotated(Count, {description: 'Changes where only version strings moved.'})), - failed: Type.Optional(annotated(Count, {description: 'Changes it failed on.'})), - }, - {description: 'One projection of the sweep, and its tally over the swept changes.'}, - ), -) - -/** A sweep cell's outcome. */ -export const SweepCellStatusSchema = define('cli/sweep', 'cellStatus', Type.Enum(['changed', 'unchanged', 'failed'])) - -/** The JSON Schema of one sweep cell, `cli/sweep#/$defs/cell`: one projection on one change. */ -export const SweepCellSchema = define( - 'cli/sweep', - 'cell', - Closed( - { - projection: Identifier, - before: Type.String(), - after: Type.String(), - status: SweepCellStatusSchema, - changes: Type.Optional(Count), - steps: Type.Optional(Count), - counts: Type.Optional(Dictionary(Count, {description: 'Changes by status (`added`, `removed`, `modified`, …).'})), - versionOnly: Type.Optional( - Type.Literal(true, {description: 'Changed, but only version strings moved (a dependency or action bump).'}), - ), - error: Type.Optional(Type.String()), - stderr: Type.Optional(Type.String({description: "The end of a failed extractor's stderr."})), - }, - {description: 'One projection on one change: its comparison counts, or why it failed.'}, - ), -) - -/** Something about the sweep as a whole, such as a shallow clone's missing history. */ -export const SweepNoteSchema = define('cli/sweep', 'note', Type.String()) - -/** The JSON Schema of `projections.sweep`, what `projections explore --sweep --json` prints. */ -export const CliSweepSchema = define( - 'cli/sweep', - undefined, - Document( - 'projections.sweep', - { - changes: Type.Array(SweepChangeSchema), - projections: Type.Array(SweepProjectionSchema), - cells: Type.Array(SweepCellSchema), - notes: Type.Array(SweepNoteSchema), - }, - {description: 'Each candidate and adopted projection tried on recent changes (`projections explore --sweep --json`).'}, - ), -) - -// Adopt ---------------------------------------------------------------------------------------------------------- - -/** Something about how adopt chose bookmarks, or why a projection has none. */ -export const AdoptNoteSchema = define('cli/adopt', 'note', Type.String()) - -/** The JSON Schema of `projections.adopt`, what `projections adopt --json` prints. */ -export const CliAdoptSchema = define( - 'cli/adopt', - undefined, - Document( - 'projections.adopt', - { - files: Type.Array( - Closed({ - path: Type.String(), - before: Nullable(Type.String(), {description: 'Its current content; `null` when it is absent.'}), - after: Type.String(), - created: Type.Boolean(), - changed: Type.Boolean(), - }), - {description: 'The definitions and the bookmarks file it writes, or would write.'}, - ), - digest: annotated(Sha256Digest, {description: "The files' contents before, which a write must still find."}), - written: Type.Boolean({description: '`false` for `--dry-run`.'}), - adopted: Type.Array(Identifier), - bookmarked: Type.Array(Closed({id: Identifier, projection: Identifier, change: SweepChangeSchema})), - notes: Type.Array(AdoptNoteSchema), - }, - {description: 'The definitions and bookmarks adopting projections writes (`projections adopt --json`).'}, - ), -) - -// Check ---------------------------------------------------------------------------------------------------------- - -const CheckStatus = Type.Enum(['pass', 'fail', 'warn', 'skip']) - -/** One renderer check's outcome, as the renderer checks report it. */ -export const RendererCheckSchema = define( - 'cli/check', - 'rendererCheck', - Closed({ - id: Type.String(), - title: Type.String(), - status: Type.Enum(['pass', 'fail', 'skip', 'advice']), - details: Type.Array(Type.String()), - durationMs: Type.Number({minimum: 0}), - }), -) - -/** The JSON Schema of one check step, `cli/check#/$defs/step`. */ -export const CheckStepSchema = define( - 'cli/check', - 'step', - Closed({ - id: Type.String(), - title: Type.String(), - status: CheckStatus, - message: Type.String(), - error: Type.Optional(CliErrorReportSchema), - details: Type.Optional(Type.Array(Type.String())), - rerun: Type.Optional(Type.String({description: 'The command that runs the failed renderer checks again.'})), - checks: Type.Optional(Type.Array(RendererCheckSchema, {description: 'Every renderer check, on a renderer step.'})), - }), -) - -/** The JSON Schema of `projections.check`, what `projections check --json` prints. */ -export const CliCheckSchema = define( - 'cli/check', - undefined, - Document( - 'projections.check', - { - ok: Type.Boolean(), - projections: Type.Array( - Type.Union([ - Closed({id: Identifier, title: Type.String(), ok: Type.Boolean(), steps: Type.Array(CheckStepSchema)}), - Closed( - { - id: Type.String(), - title: Type.String(), - path: Type.String(), - ok: Type.Literal(false), - steps: Type.Array(CheckStepSchema), - diagnostics: Type.Array(DefinitionDiagnosticSchema), - }, - {description: 'A definition file that failed to load.'}, - ), - ]), - ), - }, - {description: 'Projections verified end to end: extraction, comparison and renderer checks (`projections check --json`).'}, - ), -) - -// Environment ---------------------------------------------------------------------------------------------------- - -const Strategy = Type.Enum(['fresh', 'worktree', 'clone', 'sparse', 'none']) - -/** The JSON Schema of a workspace, `cli/workspaces#/$defs/workspace`. Its recorded state is `null` when unreadable. */ -export const WorkspaceSchema = define( - 'cli/workspaces', - 'workspace', - Closed({ - name: Type.String(), - strategy: Nullable(Strategy), - commit: Nullable(Type.String()), - at: Nullable(Type.String()), - scope: Type.Unknown({description: 'The scope it holds, for a sparse workspace; `null` otherwise.'}), - path: Type.String(), - busy: Type.Boolean({description: 'Whether a run is using it.'}), - prepared: Type.Array(Closed({id: Type.String(), status: Nullable(Type.String()), at: Nullable(Type.String())})), - }), -) - -/** The JSON Schema of `projections.workspaces`, what `projections workspace list --json` prints. */ -export const CliWorkspacesSchema = define( - 'cli/workspaces', - undefined, - Document( - 'projections.workspaces', - {directory: Type.String(), workspaces: Type.Array(WorkspaceSchema)}, - {description: 'The workspaces Projections keeps for the repository (`projections workspace list --json`).'}, - ), -) - -/** The JSON Schema of `projections.workspace-clean`, what `projections workspace clean --json` prints. */ -export const CliWorkspaceCleanSchema = define( - 'cli/workspace-clean', - undefined, - Document( - 'projections.workspace-clean', - {removed: Type.Array(Type.String(), {description: 'The workspaces removed; busy ones are kept.'})}, - {description: 'The workspaces `projections workspace clean --json` removed.'}, - ), -) - -/** A prepare step's last run in the working tree. */ -const LastRun = Closed({ - key: Type.String(), - at: Type.String(), - durationMs: Count, - log: Type.String(), - status: Type.Enum(['succeeded', 'failed']), - error: Type.Optional(Type.String()), -}) - -/** The JSON Schema of the environment report, `cli/doctor#/$defs/environment`. */ -export const EnvironmentReportSchema = define( - 'cli/doctor', - 'environment', - Closed({ - workspace: Type.Union([ - Closed({strategy: Strategy, source: Type.Enum(['flag', 'config', 'environment', 'automatic']), reason: Type.String()}), - Closed({error: Type.String()}), - ]), - workspaces: Type.Optional(Type.Array(WorkspaceSchema)), - workspacesError: Type.Optional(Type.String()), - declared: Type.Optional(Nullable(Type.String(), {description: 'The environment file, or `null` when none is declared.'})), - error: Type.Optional(Type.String()), - prepare: Type.Optional( - Type.Array( - Closed({ - id: Type.String(), - run: Type.Array(Type.String()), - directory: Type.String(), - key: Type.String(), - state: Type.Enum(['current', 'stale', 'failed', 'never']), - last: Type.Optional(LastRun), - }), - ), - ), - toolchain: Type.Optional(Type.Array(Type.Array(Type.String()))), - devcontainer: Type.Optional(Nullable(Type.String())), - missing: Type.Optional(Type.Array(Type.String())), - }), -) - -/** A doctor finding. */ -export const DoctorItemSchema = define( - 'cli/doctor', - 'item', - Closed({status: Type.Enum(['pass', 'warn', 'fail']), title: Type.String(), message: Type.String()}), -) - -/** The JSON Schema of `projections.doctor`, what `projections doctor --json` prints. */ -export const CliDoctorSchema = define( - 'cli/doctor', - undefined, - Document( - 'projections.doctor', - { - ok: Type.Boolean(), - items: Type.Array(DoctorItemSchema), - projections: Type.Array(Closed({id: Identifier, title: Type.String(), ok: Type.Boolean(), items: Type.Array(DoctorItemSchema)})), - environment: Type.Optional(EnvironmentReportSchema), - }, - {description: 'What the checkout needs to run its projections, found without running anything (`projections doctor --json`).'}, - ), -) - -/** The JSON Schema of `projections.prepare`, what `projections prepare --json` prints. */ -export const CliPrepareSchema = define( - 'cli/prepare', - undefined, - Document( - 'projections.prepare', - { - target: Type.String({description: '`working-tree`, or the commit whose workspace was prepared.'}), - environment: Type.String({description: 'The environment file.'}), - root: Type.String({description: 'Where the steps ran.'}), - strategy: Type.Optional(Type.Enum(['worktree', 'clone', 'sparse'], {description: "The workspace's strategy, for a commit."})), - notes: Type.Optional(Type.Array(Type.String())), - steps: Type.Array( - Type.Union([ - Closed({id: Type.String(), key: Type.String(), status: Type.Literal('current')}, {description: 'Unchanged keys: not run.'}), - Closed({id: Type.String(), key: Type.String(), status: Type.Literal('succeeded'), durationMs: Count, log: Type.String()}), - ]), - ), - }, - {description: "The environment's prepare steps, run in the working tree or a commit's workspace (`projections prepare --json`)."}, - ), -) - // Batches -------------------------------------------------------------------------------------------------------- /** The JSON Schema of one batch result, `cli/batch#/$defs/result`. */ @@ -493,7 +74,7 @@ export const BatchResultSchema = define( 'result', Closed( { - id: Identifier, + id: Type.String({description: 'The projection or bookmark, as requested: an error keeps an ID that names neither.'}), status: Type.Enum(['extracted', 'changed', 'unchanged', 'head-only', 'base-only', 'error'], { description: '`extracted` (show), `changed` or `unchanged` (compared), `head-only` or `base-only` (one revision defines it, shown alone), or `error`.', @@ -615,117 +196,6 @@ export const CliValidationSchema = define( ), ) -// Viewer --------------------------------------------------------------------------------------------------------- - -const Side = Closed({ref: Type.String(), commit: Nullable(Type.String())}) - -/** The JSON Schema of `projections.view`, what `projections view show`, `view current` and `view refresh` print with `--json`. */ -export const CliViewSchema = define( - 'cli/view', - undefined, - Type.Union( - [ - Document( - 'projections.view', - { - shown: Type.Literal(false), - viewer: Passed('The viewer.'), - url: Passed("The viewer's page."), - viewers: Passed('The other viewers running.'), - }, - {description: 'Nothing is shown yet.'}, - ), - Document( - 'projections.view', - { - shown: Type.Literal(true), - surface: Type.Literal('viewer'), - viewer: Passed('The viewer.'), - url: Passed("The viewer's page."), - chosenBy: Passed('Who chose the projection: the agent, or the person from the page.'), - viewers: Passed('The other viewers running.'), - pages: Count, - seen: Passed('What the open pages saw.'), - projection: Type.String(), - title: Type.String(), - choice: Passed('How the revisions were chosen.'), - compared: Type.String(), - before: Nullable(Side), - after: Side, - scenario: Passed('The scenario shown, for fixtures.'), - mode: Passed('The comparison mode.'), - selection: Passed('What the person selected, from the current page.'), - page: Passed("The current page's view."), - failures: Passed("The current page's failures."), - document: Nullable( - Closed({ - path: Type.String(), - format: Passed("The document's format."), - renderer: Type.Union([Closed({builtIn: Passed('The built-in renderer.')}), Closed({bundle: Type.String()})]), - }), - {description: 'The saved document shown, instead of the repository.'}, - ), - rendererBuild: Nullable( - Closed({ - phase: Type.String(), - error: Passed('Why the build failed.'), - script: Passed('The build script.'), - package: Passed("The renderer's package."), - bundled: Type.Boolean(), - }), - ), - }, - {description: 'What the viewer shows.'}, - ), - Closed({error: Type.String()}, {description: 'The viewer refused; the command fails. It has no `format`.'}), - ], - {description: 'What the viewer shows and what the person selected (`projections view show|current|refresh --json`).'}, - ), -) - -/** The JSON Schema of `projections.screenshot`, what `projections view screenshot --json` prints. */ -export const CliScreenshotSchema = define( - 'cli/screenshot', - undefined, - Type.Union( - [ - Document( - 'projections.screenshot', - { - projection: Passed('The projection drawn.'), - scenario: Passed('The scenario drawn, or `null`.'), - before: Passed('The revision before, or `null`.'), - after: Passed('The revision after, or `null` for a scenario.'), - mode: Nullable(Type.String()), - progress: Passed('The comparison progress drawn.'), - theme: Type.String(), - width: Count, - height: Count, - notices: Type.Array(Type.String()), - bytes: Count, - }, - {description: 'A projection rendered by its renderer.'}, - ), - Document( - 'projections.screenshot', - { - page: Type.Literal(true), - viewer: Type.String(), - projection: Type.String(), - theme: Type.String(), - width: Count, - height: Count, - notices: Type.Array(Type.String()), - bytes: Count, - }, - {description: "The viewer's page, captured with `--page`."}, - ), - Closed({error: Type.String()}, {description: 'The viewer refused; the command fails. It has no `format`.'}), - ], - {description: 'The PNG `projections view screenshot --json` wrote, and what it shows.'}, - ), -) - /** Every CLI document, by schema name; `packages/cli/test/json-output.test.mjs` validates the CLI's output against them. */ export const cliSchemaDocuments = [ {name: 'cli/adopt', title: 'CLI adopt', schema: CliAdoptSchema}, From fdbd0114da6035d0a855f847c207a8ae39d61cab Mon Sep 17 00:00:00 2001 From: agorischek <6295280+agorischek@users.noreply.github.com> Date: Sat, 5 Dec 2026 04:14:25 +0000 Subject: [PATCH 6/6] json-output test: ask the CLI's doctor whether a browser can run 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> --- packages/cli/test/json-output.test.mjs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/cli/test/json-output.test.mjs b/packages/cli/test/json-output.test.mjs index 9971066d1..553c2adcf 100644 --- a/packages/cli/test/json-output.test.mjs +++ b/packages/cli/test/json-output.test.mjs @@ -207,18 +207,20 @@ test('the viewer commands print their documents', async t => { conforms('cli/view', await ok(root, ['view', 'show', '-p', 'files', '--json'])) conforms('cli/view', await ok(root, ['view', 'current', '--json'])) conforms('cli/view', await ok(root, ['view', 'refresh', '--json'])) - // Both captures must succeed wherever a browser can run. Only where none can (none is installed, or Chrome refuses - // to run as root) may they fail: the renderer's then prints the refusal its schema allows, the page's nothing. - const unavailable = /No Chrome, Chromium or Edge|Chrome won't run as root/u + // Both captures must succeed wherever the CLI can run a browser, which its doctor reports with the same discovery + // (`pass`; `warn` when none is found or Chrome would run as root). Where it can't, they may fail: the renderer's + // capture then prints the refusal its schema allows, the page's nothing. + const doctor = JSON.parse((await run(root, ['doctor', '--json'])).stdout) + const browser = doctor.items.find(item => item.title === 'Browser')?.status === 'pass' for (const page of [[], ['--page']]) { const image = path.join(root, '..', `screenshot-${path.basename(root)}-${page.length}.png`) t.after(() => rm(image, {force: true})) - const {stdout, stderr, failed} = await run(root, ['view', 'screenshot', '--out', image, ...page, '--json']) + const {stdout, failed} = await run(root, ['view', 'screenshot', '--out', image, ...page, '--json']) if (!failed) { assert.equal(conforms('cli/screenshot', stdout).format, 'projections.screenshot') continue } - assert.match(`${stdout}${stderr}`, unavailable, `view screenshot ${page.join(' ')} failed with a browser available`) + assert.equal(browser, false, `view screenshot ${page.join(' ')} failed though the CLI found a browser`) if (stdout) conforms('cli/screenshot', stdout) } })