From 97d7917a3607aae181d49585ff4df9fbdaf8ee4f Mon Sep 17 00:00:00 2001 From: lex00 <121451605+lex00@users.noreply.github.com> Date: Fri, 16 Oct 2026 18:31:24 -0600 Subject: [PATCH 1/2] feat(workspace): one run-event contract for Op, component and pipeline runs (#4019) run-event.schema.json (contract 1, floor chant 0.124.28) covers run, wave, component, phase and step start and settle, gate-waiting and gate-resolved, with run-settle as the verdict. Every event carries runId, kind, name, gitSha, runtime (local, steward, ci) and runOrigin, the RunOrigin shape a release record carries. Step settle statuses are ok, failed, skipped (with skip: receipt, resumed, refused, not-run or null), cached, gated and waiting. @intentius/chant exports the types and the one writer (createRunEventWriter, writeRunEvent, buildRunEvent, serializeRunEvent), plus runEventOfProgress and runEventsOfStepRecord, which map the older RunProgressEvent and StepRecord lines onto the contract. Those two shapes are deprecated for new readers; the emitted JSON is unchanged until #4041 moves the emitters. The read-contract page lists the schema. --- docs/src/content/docs/cli/run.mdx | 2 +- .../reference/workspace-read-contract.mdx | 45 +- packages/core/src/components/run-progress.ts | 7 + packages/core/src/index.ts | 2 + packages/core/src/op/local-executor.ts | 10 + packages/core/src/run-event.test.ts | 277 ++++++++++++ packages/core/src/run-event.ts | 415 ++++++++++++++++++ .../core/src/workspace/run-event.schema.json | 283 ++++++++++++ 8 files changed, 1039 insertions(+), 2 deletions(-) create mode 100644 packages/core/src/run-event.test.ts create mode 100644 packages/core/src/run-event.ts create mode 100644 packages/core/src/workspace/run-event.schema.json diff --git a/docs/src/content/docs/cli/run.mdx b/docs/src/content/docs/cli/run.mdx index 68cf5d8978..e9c33ced67 100644 --- a/docs/src/content/docs/cli/run.mdx +++ b/docs/src/content/docs/cli/run.mdx @@ -298,7 +298,7 @@ chant components promote --from staging --to prod --digest "$(cat search-service #### Streaming progress: `--progress-json` -`--progress-json` streams one NDJSON record per line to stdout while the run executes, so a consumer can render live progress instead of tailing logs. On the component path each line is a `RunProgressEvent` (wave, component, phase, step). On `chant run ` each line is a `StepRecord` for a settled step, fed by whatever runtime is hosting the run. Run semantics, ordering and exit code are unchanged. +`--progress-json` streams one NDJSON record per line to stdout while the run executes, so a consumer can render live progress instead of tailing logs. On the component path each line is a `RunProgressEvent` (wave, component, phase, step). On `chant run ` each line is a `StepRecord` for a settled step, fed by whatever runtime is hosting the run. Run semantics, ordering and exit code are unchanged. Both shapes are deprecated for new readers. They give way to the [run-event stream](/chant/reference/workspace-read-contract/#run-events), whose every line names its run. The `--progress-json` output moves to it with [#4041](https://github.com/INTENTIUS/chant/issues/4041). On a successful run, `chant run --components` auto-emits one immutable release record per component that published a digest-bearing artifact, `(component, env, digest, gitSha, runId, timestamp, actor)`, appended to the same [release ledger](/chant/components/observability/) the standalone [`chant components release`](/chant/cli/components/) command writes to. It is a CLI step after the run, outside the composition, and runs only when the deploy succeeds. See [Auto-recorded releases](#auto-recorded-releases) below. diff --git a/docs/src/content/docs/reference/workspace-read-contract.mdx b/docs/src/content/docs/reference/workspace-read-contract.mdx index 0b8a12317e..cbb9ec230d 100644 --- a/docs/src/content/docs/reference/workspace-read-contract.mdx +++ b/docs/src/content/docs/reference/workspace-read-contract.mdx @@ -10,7 +10,7 @@ Tools that show a workspace read it through one contract ([#2536](https://github | Contract | chant floor | Declaration | Output schemas | |---|---|---|---| -| 1 | 0.81.0 | schema 1 | `ls`, `graph`, `check`, `status`, `records`, `records-since`, `intent`, `intent-record`, `composites`, `points`, `changes`, `patch`, `work-history`, `agent`, `runs`, `wip`, `change-set`, `plan-summary`, `pr-report`, `run-statement`, `ci-last-green` and `ci-list`, each at `v1` | +| 1 | 0.81.0 | schema 1 | `ls`, `graph`, `check`, `status`, `records`, `records-since`, `intent`, `intent-record`, `composites`, `points`, `changes`, `patch`, `work-history`, `agent`, `runs`, `wip`, `change-set`, `plan-summary`, `pr-report`, `run-statement`, `ci-last-green`, `ci-list` and `run-event`, each at `v1` | Every document carries `contract`, the version it follows, and `$schema`, its schema's `$id`. Most also carry `chant`, the version of the chant that wrote it. A reader that knows contract 1 refuses a document with any other `contract` value. Given a chant older than the floor, the reader can say so and name the version to install, since that chant doesn't write the contract at all. @@ -47,6 +47,7 @@ Each schema ships in `@intentius/chant` at `src/workspace/.schema.json` | [`chant workspace evidence verify`](/chant/cli/workspace-evidence/#output) | `--json` | `https://intentius.io/chant/schemas/workspace/evidence/v1/evidence.schema.json` | | [`chant ci last-green`](/chant/cli/ci/#ci-last-green) | `--json` | `https://intentius.io/chant/schemas/workspace/ci-last-green/v1/ci-last-green.schema.json` | | [`chant ci list`](/chant/cli/ci/#ci-list) | `--json` | `https://intentius.io/chant/schemas/workspace/ci-list/v1/ci-list.schema.json` | +| [a run's event stream](#run-events), one event per line | as each event happens | `https://intentius.io/chant/schemas/workspace/run-event/v1/run-event.schema.json` | Each schema is a `oneOf` of a result and a failure. The `records` schema has a third branch for the set it prints without `--kind` ([#2680](https://github.com/INTENTIUS/chant/issues/2680)). The set holds a result or a failure for each record kind the declaration names. A failure has `error: { code, message }`, plus `location` for the commands that read the declaration, and exits 1. A result may still hold entries that couldn't be read, each with a `reason: { code, message }`. Only `check` fails on those ([ws-020](https://github.com/INTENTIUS/chant/blob/main/docs/design/decisions/ws-020-unreadable.md)). In `check`, a declaration that can't be read is the finding `WSP001` with the same `code`, not a failure. @@ -462,6 +463,48 @@ A work lease is written by [`chant workspace work claim|renew|release`](/chant/c `totals` holds `all`, `byUnit`, `byDecision` and `byPrincipal`, each with `runs`, `running`, `tokens`, `cost` (one sum per currency), `unpriced`, the runs that report no cost, and `unreported`, the runs that report no usage. A run without a cost is listed, never counted as zero. A metering reader sums `cost` per currency and shows `unpriced` beside it, and a reader that trusts only signed figures counts the runs whose `attestation.status` is `signed`. `trust` names the base the statements were judged at (`--base`, else `origin/HEAD`, `main` or `master`), the runner principals listed there with their class, and any `problems` reading it, in which case nothing is signed. `reasons` holds `runs-no-ledger`, `runs-ledger-malformed`, `kind-unreadable` when a work kind can't be read to find what its items implement, and `squash-unfollowed` when `--follow-squash` can't read a pull request's ref. `chant serve mcp` serves the document as `workspace-runs`. +## Run events + +An Op run, a component run and a CI pipeline run all report progress as one stream of events, one JSON object per line ([#4019](https://github.com/INTENTIUS/chant/issues/4019)). Each line follows `run-event.schema.json`, whose contract version 1 is written by chant `0.124.28` and newer. behold, terragucci and a CI log read the same fields wherever the run happened, and a step's state is in the event, so nobody parses log text for it. + +`@intentius/chant` exports the types (`RunEvent` and one type per event) and the one writer. `createRunEventWriter({ run, write })` keeps a run's identity and its sequence, and each `emit(body)` writes the next line. `writeRunEvent` and `buildRunEvent` do the same for a single event. The commands start printing this stream with [#4041](https://github.com/INTENTIUS/chant/issues/4041), and replay and `--follow` arrive with [#4042](https://github.com/INTENTIUS/chant/issues/4042). + +Every event carries the fields in this table. + +| Field | Holds | +|---|---| +| `$schema`, `contract`, `chant` | the schema's `$id`, `1`, and the version of the chant that wrote it | +| `seq`, `at` | the event's place in the stream, `0` for `run-start`, and when it happened | +| `runId`, `runOrigin` | the run's id and its locator, the `RunOrigin` shape a release record carries: `forge` (`github`, `gitlab`, `op` or `local`; Forgejo spells itself `github`), and `repo` and `url` when known | +| `kind`, `name` | `op`, `component` or `pipeline`, and the Op's name, the component selection as given, or the pipeline's name | +| `gitSha` | the commit the run built from, `null` outside a git checkout | +| `runtime` | `local`, `steward` or `ci` | + +The `type` field names the event. A stream opens with `run-start` and ends with `run-settle`, whose `status` is the run's verdict. + +| `type` | Adds | +|---|---| +| `run-start` | `waves`, the component waves in a component run, `null` otherwise | +| `wave-start`, `wave-settle` | `wave`, counted from 1, and `components` or `status` | +| `component-start`, `component-settle` | `wave`, `component`, and `status` on settle | +| `phase-start`, `phase-settle` | `component` (`null` outside a component run), `phase`, and `status` on settle | +| `step-start`, `step-settle` | `component`, `phase`, `step`; on settle `status`, `durationMs`, and `skip`, `error` or `message` when they apply | +| `gate-waiting` | `component`, `phase`, `step`, `op` (what `chant approve` takes), `gate` and `point`, the answer record id of an open question | +| `gate-resolved` | `component`, `phase`, `step`, `op`, `gate`, `resolvedBy`, `resolvedAt`, `via` and `url` | +| `run-settle` | `status`, `durationMs`, and `error` on a failed run | + +A run, wave, component or phase settles `ok`, `failed`, `gated` or `waiting`. `gated` stops at a gate nobody has approved, and `waiting` stops at a decision point nobody has answered. Neither is a failure. A step settles `ok`, `failed`, `skipped`, `cached`, `gated` or `waiting`. `cached` is for a cache hit standing in for the step ([#4015](https://github.com/INTENTIUS/chant/issues/4015)). In a pipeline run a stage is a phase and a job is a step. A skipped step says why in `skip`. + +| `skip` | The step | +|---|---| +| `receipt` | is an effect whose receipt matched, so it had already applied | +| `resumed` | ran in an earlier run, which this run resumed from at a later gate | +| `refused` | declined to go on, and `message` says why | +| `not-run` | never ran, because an earlier step stopped the run | +| `null` | was skipped for a reason the writer can't tell | + +The two older streams keep their shape until #4041 moves them. `runEventOfProgress` maps a `RunProgressEvent`, a line of `chant run --components --progress-json`, onto a run-event body. `runEventsOfStepRecord` maps a `StepRecord` line of `chant run --progress-json` onto a `step-settle`. When the record holds a gate, a `gate-resolved` or `gate-waiting` comes before it. The executor writes one bare skipped `StepRecord` for several of these cases, so such a record maps to `skip: null`. New readers should read the run-event stream rather than either older shape. + ## Decision points A record kind with an `answers` block is an answer kind ([ws-058](https://github.com/INTENTIUS/chant/issues/2739)). Its `answers.points` names a JSON points file, validated against `decision-points.schema.json`, which `@intentius/chant` exports as `@intentius/chant/workspace/decision-points.schema.json`. Each input a point reads is named for one of this contract's outputs, optionally followed by dotted field names. diff --git a/packages/core/src/components/run-progress.ts b/packages/core/src/components/run-progress.ts index cde79a6628..abe340b385 100644 --- a/packages/core/src/components/run-progress.ts +++ b/packages/core/src/components/run-progress.ts @@ -90,6 +90,13 @@ export interface RunDoneEvent { status: RunProgressStatus; } +/** + * @deprecated Read `RunEvent` (`../run-event.ts`, exported from + * `@intentius/chant`) instead: one contract for Op, component and pipeline + * runs, with the run id, commit and runtime on every event (#4019). + * `runEventOfProgress` maps each of these onto it. `--progress-json` keeps + * printing this shape until #4041 moves it to the run-event stream. + */ export type RunProgressEvent = | RunStartEvent | WaveStartEvent diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 1e6d38704a..af20249c00 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -153,6 +153,8 @@ export type { SymbolDeclaration, SymbolResolver } from "./workspace/symbols"; export * from "./lsp/lexicon-providers"; export * from "./mcp/types"; export * from "./lifecycle/index"; +// The run-event contract (#4019): the types and the one writer of a run's stream. +export * from "./run-event"; // Op builders — use explicit exports to avoid collision with the core `build` function export { Op, phase, activity, gate, kubectlApply, helmInstall, waitForStack, gitlabPipeline, lifecycleSnapshot, shell, teardown, OpResource } from "./op/index"; diff --git a/packages/core/src/op/local-executor.ts b/packages/core/src/op/local-executor.ts index 693edfb509..514b7eebf2 100644 --- a/packages/core/src/op/local-executor.ts +++ b/packages/core/src/op/local-executor.ts @@ -64,6 +64,16 @@ export { parseDuration } from "./duration"; // ── Records ───────────────────────────────────────────────────────────────── +/** + * One settled step of an Op run, as `OpRunResult.records` holds it. + * + * As a `chant run --progress-json` line it is deprecated: read + * `RunEvent` (`../run-event.ts`, exported from `@intentius/chant`) + * instead, whose `step-settle` carries the run id, commit and runtime too, + * and whose step statuses are `ok`, `failed`, `skipped`, `cached`, `gated` + * and `waiting` (#4019). `runEventsOfStepRecord` maps a record onto it. + * `--progress-json` keeps printing records until #4041 moves it. + */ export interface StepRecord { phase: string; fn: string; diff --git a/packages/core/src/run-event.test.ts b/packages/core/src/run-event.test.ts new file mode 100644 index 0000000000..4b602fd3a1 --- /dev/null +++ b/packages/core/src/run-event.test.ts @@ -0,0 +1,277 @@ +/** + * #4019: the run-event contract. One schema for Op, component and pipeline + * runs, the one writer, and the two older streams mapped onto it. Every + * line the writer prints is checked against `run-event.schema.json`. + */ + +import { describe, expect, test } from "vitest"; +import type { RunProgressEvent } from "./components/run-progress"; +import type { StepRecord } from "./op/local-executor"; +import { contract, validSchema } from "./workspace/__fixtures__/contract-repo"; +import { READ_CONTRACT_FLOOR, READ_CONTRACT_VERSION } from "./workspace/reason-codes"; +import { + buildRunEvent, + createRunEventWriter, + RUN_EVENT_CONTRACT_VERSION, + RUN_EVENT_FLOOR, + RUN_EVENT_SCHEMA_ID, + RUN_EVENT_TYPES, + runEventOfProgress, + runEventsOfStepRecord, + serializeRunEvent, + type RunEvent, + type RunEventBody, + type RunEventRun, +} from "./run-event"; +import schema from "./workspace/run-event.schema.json"; + +const { validate, expectValid } = contract(schema); + +const SHA = "0123456789abcdef0123456789abcdef01234567"; + +const OP_RUN: RunEventRun = { + runId: "6f1c2d4e-0000-4000-8000-000000000001", + kind: "op", + name: "deploy-api", + gitSha: SHA, + runtime: "local", + runOrigin: { forge: "local" }, +}; + +/** A writer that keeps its lines, on a clock that ticks a second per event. */ +function capture(run: RunEventRun) { + const lines: string[] = []; + let t = Date.parse("2026-10-16T12:00:00.000Z"); + const writer = createRunEventWriter({ run, write: (l) => lines.push(l), now: () => new Date((t += 1000)), chant: "0.124.28" }); + const events = () => lines.map((l) => JSON.parse(l) as RunEvent); + return { writer, lines, events }; +} + +describe("the run-event schema", () => { + test("is a valid draft 2020-12 document at the contract version, naming its floor and the read contract's", () => { + expect(validSchema(schema)).toBe(true); + expect(schema.$id).toBe(RUN_EVENT_SCHEMA_ID); + expect(RUN_EVENT_SCHEMA_ID).toBe(`https://intentius.io/chant/schemas/workspace/run-event/v${READ_CONTRACT_VERSION}/run-event.schema.json`); + const envelope = schema.$defs.envelope.properties; + expect(envelope.contract).toEqual({ const: RUN_EVENT_CONTRACT_VERSION }); + expect(envelope.$schema).toEqual({ const: RUN_EVENT_SCHEMA_ID }); + expect(schema.description).toContain(`written by chant ${RUN_EVENT_FLOOR} and newer`); + expect(schema.description).toContain(`chant ${READ_CONTRACT_FLOOR} and newer`); + }); + + test("names exactly the event types the code does, and every one requires the envelope", () => { + const defs = schema.$defs as Record }>; + const refs = schema.oneOf.map((o) => o.$ref.replace("#/$defs/", "")); + expect([...refs].sort()).toEqual([...RUN_EVENT_TYPES].sort()); + for (const t of RUN_EVENT_TYPES) { + const parts = defs[t].allOf!; + expect(parts[0].$ref, t).toBe("#/$defs/envelope"); + expect(parts[1].properties!.type!.const, t).toBe(t); + } + }); + + test("keeps the step statuses closed, with skipped and room for cached", () => { + const status = schema.$defs["step-settle"].allOf[1].properties!.status as { enum: string[] }; + expect(status.enum).toEqual(["ok", "failed", "skipped", "cached", "gated", "waiting"]); + const one = buildRunEvent({ type: "step-settle", component: null, phase: "p", step: "s", status: "ok", durationMs: 1 }, { run: OP_RUN, seq: 3 }); + expectValid(one); + for (const bad of ["fail", "running", "done"]) expect(validate({ ...one, status: bad }), bad).toBe(false); + expect(validate({ ...one, status: "skipped", skip: "receipt" })).toBe(true); + expect(validate({ ...one, status: "skipped", skip: "because" })).toBe(false); + }); + + test("refuses an event missing the run, the commit or the runtime, or at another contract", () => { + const one = buildRunEvent({ type: "run-start", waves: null }, { run: OP_RUN, seq: 0 }); + expectValid(one); + for (const field of ["runId", "kind", "name", "gitSha", "runtime", "runOrigin", "seq", "at", "chant"] as const) { + const copy: Record = { ...one }; + delete copy[field]; + expect(validate(copy), field).toBe(false); + } + expect(validate({ ...one, gitSha: "main" })).toBe(false); + expect(validate({ ...one, gitSha: null })).toBe(true); + expect(validate({ ...one, runtime: "cloud" })).toBe(false); + expect(validate({ ...one, runOrigin: { forge: "jenkins" } })).toBe(false); + expect(validate({ ...one, contract: 2 })).toBe(false); + expect(validate({ ...one, type: "run-done" })).toBe(false); + }); + + test("lets a reader ignore fields it does not know", () => { + expectValid({ ...buildRunEvent({ type: "run-start", waves: null }, { run: OP_RUN, seq: 0 }), later: true }); + }); +}); + +describe("the one writer", () => { + test("writes an Op run as one line per event, each valid, with the run on every line and seq counting from 0", () => { + const { writer, lines, events } = capture(OP_RUN); + const bodies: RunEventBody[] = [ + { type: "run-start", waves: null }, + { type: "phase-start", component: null, phase: "build" }, + { type: "step-start", component: null, phase: "build", step: "shell" }, + { type: "step-settle", component: null, phase: "build", step: "shell", status: "ok", durationMs: 412 }, + { type: "step-start", component: null, phase: "build", step: "effect:schema" }, + { type: "step-settle", component: null, phase: "build", step: "effect:schema", status: "skipped", skip: "receipt", durationMs: 3 }, + { type: "step-settle", component: null, phase: "build", step: "cache-restore", status: "cached", durationMs: 0 }, + { type: "phase-settle", component: null, phase: "build", status: "ok" }, + { type: "phase-start", component: null, phase: "release" }, + { type: "step-start", component: null, phase: "release", step: "gate:prod" }, + { type: "gate-waiting", component: null, phase: "release", step: "gate:prod", op: "deploy-api", gate: "prod", point: null }, + { type: "step-settle", component: null, phase: "release", step: "gate:prod", status: "gated", durationMs: 20 }, + { type: "phase-settle", component: null, phase: "release", status: "gated" }, + { type: "run-settle", status: "gated", durationMs: 1500 }, + ]; + for (const b of bodies) writer.emit(b); + expect(writer.next).toBe(bodies.length); + expect(lines.every((l) => l.endsWith("\n") && !l.slice(0, -1).includes("\n"))).toBe(true); + const evs = events(); + evs.forEach((e, i) => { + expectValid(e); + expect(e.seq).toBe(i); + expect(e).toMatchObject({ $schema: RUN_EVENT_SCHEMA_ID, contract: 1, chant: "0.124.28", runId: OP_RUN.runId, kind: "op", name: "deploy-api", gitSha: SHA, runtime: "local", runOrigin: { forge: "local" } }); + expect(e.type).toBe(bodies[i].type); + }); + expect(evs[0].at).toBe("2026-10-16T12:00:01.000Z"); + expect(Object.keys(evs[0]).slice(0, 5)).toEqual(["$schema", "contract", "chant", "seq", "at"]); + expect(evs.at(-1)).toMatchObject({ type: "run-settle", status: "gated" }); + }); + + test("writes a pipeline run in forge CI, its stages as phases and its jobs as steps, with the CI locator", () => { + const { writer, events } = capture({ + runId: "8812345", + kind: "pipeline", + name: "main", + gitSha: SHA, + runtime: "ci", + runOrigin: { forge: "gitlab", repo: "acme/api", url: "https://gitlab.example.com/acme/api/-/pipelines/8812345" }, + }); + writer.emit({ type: "run-start", waves: null }); + writer.emit({ type: "phase-start", component: null, phase: "test" }); + writer.emit({ type: "step-start", component: null, phase: "test", step: "unit" }); + writer.emit({ type: "step-settle", component: null, phase: "test", step: "unit", status: "failed", durationMs: 9000, error: "exit 1" }); + writer.emit({ type: "phase-settle", component: null, phase: "test", status: "failed" }); + writer.emit({ type: "run-settle", status: "failed", durationMs: 9100, error: "job unit failed" }); + for (const e of events()) expectValid(e); + }); + + test("writes a steward run with its approval and an open decision point", () => { + const { writer, events } = capture({ ...OP_RUN, runtime: "steward", runOrigin: { forge: "op", url: "https://fountain.example.com/threads/t-1" } }); + writer.emit({ type: "gate-resolved", component: null, phase: "release", step: "gate:prod", op: "deploy-api", gate: "prod", resolvedBy: "alice", resolvedAt: "2026-10-16T11:00:00.000Z", via: "quorum" }); + writer.emit({ type: "gate-waiting", component: null, phase: "release", step: "pick-region", op: "deploy-api", gate: null, point: "A-0042" }); + writer.emit({ type: "step-settle", component: null, phase: "release", step: "pick-region", status: "waiting", durationMs: 5, message: "region?" }); + writer.emit({ type: "run-settle", status: "waiting", durationMs: 40 }); + for (const e of events()) expectValid(e); + }); + + test("serializes one event as one JSON line", () => { + const e = buildRunEvent({ type: "run-start", waves: [["a"], ["b", "c"]] }, { run: OP_RUN, seq: 0, at: "2026-10-16T12:00:00.000Z", chant: "1.0.0" }); + expect(serializeRunEvent(e)).toBe(JSON.stringify(e) + "\n"); + expect(e.at).toBe("2026-10-16T12:00:00.000Z"); + }); + + test("is exported from @intentius/chant", async () => { + const root = await import("./index"); + expect(root.createRunEventWriter).toBe(createRunEventWriter); + expect(root.RUN_EVENT_SCHEMA_ID).toBe(RUN_EVENT_SCHEMA_ID); + }, 60_000); +}); + +describe("RunProgressEvent in terms of the run-event contract", () => { + const progress: RunProgressEvent[] = [ + { type: "run-start", waves: [["db"], ["api", "web"]] }, + { type: "wave-start", wave: 1, components: ["db"] }, + { type: "component-start", wave: 1, component: "db" }, + { type: "phase-start", component: "db", phase: "deploy" }, + { type: "step", component: "db", phase: "deploy", step: "apply", status: "running" }, + { type: "step", component: "db", phase: "deploy", step: "apply", status: "failed", error: "boom" }, + { type: "step", component: "db", phase: "deploy", step: "verify", status: "ok" }, + { type: "phase-done", component: "db", phase: "deploy", status: "failed" }, + { type: "component-done", wave: 1, component: "db", status: "gated" }, + { type: "wave-done", wave: 1, status: "failed" }, + { type: "run-done", status: "failed" }, + ]; + + test("maps every variant to a valid event that keeps its fields", () => { + const { writer, events } = capture({ ...OP_RUN, kind: "component", name: "db,api,web" }); + for (const p of progress) writer.emit(runEventOfProgress(p)); + const evs = events(); + for (const e of evs) expectValid(e); + expect(evs.map((e) => e.type)).toEqual([ + "run-start", + "wave-start", + "component-start", + "phase-start", + "step-start", + "step-settle", + "step-settle", + "phase-settle", + "component-settle", + "wave-settle", + "run-settle", + ]); + expect(evs[0]).toMatchObject({ waves: [["db"], ["api", "web"]] }); + expect(evs[5]).toMatchObject({ component: "db", step: "apply", status: "failed", error: "boom", durationMs: null }); + expect(evs[8]).toMatchObject({ component: "db", status: "gated" }); + }); +}); + +describe("StepRecord in terms of the run-event contract", () => { + const ctx = { op: "deploy-api" }; + const base = { phase: "release", args: {}, durationMs: 12 } as const; + const types = (r: StepRecord) => runEventsOfStepRecord(r, ctx).map((b) => b.type); + const settle = (r: StepRecord) => runEventsOfStepRecord(r, ctx).at(-1)!; + + test("ok and fail settle ok and failed, with the error", () => { + expect(settle({ ...base, fn: "shell", status: "ok" })).toEqual({ type: "step-settle", component: null, phase: "release", step: "shell", status: "ok", durationMs: 12 }); + expect(settle({ ...base, fn: "shell", status: "fail", error: "exit 2" })).toMatchObject({ status: "failed", error: "exit 2" }); + }); + + test("an approved gate resolves before its step settles ok", () => { + const r: StepRecord = { ...base, fn: "gate:prod", status: "ok", approval: { gate: "prod", resolvedBy: "alice", timestamp: "2026-10-16T11:00:00.000Z", via: "policy", url: "https://x" } }; + expect(types(r)).toEqual(["gate-resolved", "step-settle"]); + expect(runEventsOfStepRecord(r, ctx)[0]).toEqual({ type: "gate-resolved", component: null, phase: "release", step: "gate:prod", op: "deploy-api", gate: "prod", resolvedBy: "alice", resolvedAt: "2026-10-16T11:00:00.000Z", via: "policy", url: "https://x" }); + }); + + test("a step waiting on a gate or a decision point settles gated or waiting, after gate-waiting", () => { + const own: StepRecord = { ...base, fn: "workspace-upgrade", status: "skipped", gate: { op: "workspace-upgrade", gate: "all" } }; + expect(types(own)).toEqual(["gate-waiting", "step-settle"]); + expect(runEventsOfStepRecord(own, ctx)[0]).toMatchObject({ op: "workspace-upgrade", gate: "all", point: null }); + expect(settle(own)).toMatchObject({ status: "gated" }); + + const point: StepRecord = { ...base, fn: "pick", status: "skipped", point: { id: "A-1", point: "region", state: "escalated", path: "answers/A-1.md", subject: null, steward: null } }; + expect(runEventsOfStepRecord(point, ctx)[0]).toMatchObject({ type: "gate-waiting", gate: null, point: "A-1" }); + expect(settle(point)).toMatchObject({ status: "waiting" }); + + const pointGate: StepRecord = { ...point, fn: "gate:prod" }; + expect(runEventsOfStepRecord(pointGate, ctx)[0]).toMatchObject({ gate: "prod", point: "A-1" }); + + const mismatch: StepRecord = { ...base, fn: "gate:prod", status: "skipped", refusal: "approved for another plan" }; + expect(runEventsOfStepRecord(mismatch, ctx)[0]).toMatchObject({ type: "gate-waiting", gate: "prod", message: "approved for another plan" }); + expect(settle(mismatch)).toMatchObject({ status: "gated", message: "approved for another plan" }); + }); + + test("skips say why when the record does, and null when it does not", () => { + expect(settle({ ...base, fn: "build", status: "skipped", resumed: { run: "r-1", gate: "prod" } })).toMatchObject({ status: "skipped", skip: "resumed" }); + expect(settle({ ...base, fn: "workLease:claim", status: "skipped", refusal: "no item ready" })).toMatchObject({ status: "skipped", skip: "refused", message: "no item ready" }); + expect(settle({ ...base, fn: "gate:prod", status: "skipped" })).toMatchObject({ status: "skipped", skip: null }); + expect(settle({ ...base, fn: "migrate", status: "skipped", durationMs: 0 })).toMatchObject({ status: "skipped", skip: null, durationMs: 0 }); + }); + + test("every mapped record writes valid events", () => { + const { writer, events } = capture(OP_RUN); + const records: StepRecord[] = [ + { ...base, fn: "shell", status: "ok" }, + { ...base, fn: "shell", status: "fail", error: "x" }, + { ...base, fn: "gate:prod", status: "ok", approval: { gate: "prod", resolvedBy: "a", timestamp: "2026-10-16T11:00:00.000Z" } }, + { ...base, fn: "gate:prod", status: "skipped", refusal: "r" }, + { ...base, fn: "build", status: "skipped", resumed: { run: "r-1", gate: "prod" } }, + { ...base, fn: "migrate", status: "skipped" }, + ]; + for (const r of records) for (const b of runEventsOfStepRecord(r, { ...ctx, component: "api" })) writer.emit(b); + const evs = events(); + expect(evs.length).toBe(8); + for (const e of evs) { + expectValid(e); + expect(e).toMatchObject({ component: "api" }); + } + }); +}); diff --git a/packages/core/src/run-event.ts b/packages/core/src/run-event.ts new file mode 100644 index 0000000000..ff96142c55 --- /dev/null +++ b/packages/core/src/run-event.ts @@ -0,0 +1,415 @@ +/** + * The run-event contract (#4019, behold #678): one stream of events for Op + * runs, component runs and pipeline runs, so anything that shows a run reads + * the same fields wherever the run happened. + * + * `workspace/run-event.schema.json` is the contract. These types + * mirror it, and {@link createRunEventWriter} and {@link writeRunEvent} are + * the one writer: every emitter hands a writer the type-specific body and + * the writer stamps the run's identity, the sequence number, the time and the + * contract fields on it, then writes one JSON line. The emitters themselves + * are #4041's work; replay and `--follow` are #4042's. + * + * Two older streams predate this one and keep their shape until #4041 moves + * them: `RunProgressEvent` (`./components/run-progress.ts`, from `chant run + * --components --progress-json`) and the Op path's `StepRecord` lines + * (`./op/local-executor.ts`, from `chant run --progress-json`). + * {@link runEventOfProgress} and {@link runEventsOfStepRecord} say how each + * maps onto this contract. + * + * This module imports no runtime code beyond the chant version, so a consumer + * can import the types and the writer without loading the rest of chant. It + * lives outside `workspace/` so that a level-0 import of `@intentius/chant` + * loads no workspace module (#2526). + */ + +import type { RunProgressEvent } from "./components/run-progress"; +import type { RunOrigin } from "./lifecycle/release-ledger"; +import type { StepRecord } from "./op/local-executor"; +import { CHANT_VERSION } from "./cli/version"; + +/** The schema's `$id`, which every event carries as `$schema`. */ +export const RUN_EVENT_SCHEMA_ID = "https://intentius.io/chant/schemas/workspace/run-event/v1/run-event.schema.json"; + +/** The contract version every event carries as `contract`. */ +export const RUN_EVENT_CONTRACT_VERSION = 1; + +/** The first chant that writes contract version 1 of the run-event stream. */ +export const RUN_EVENT_FLOOR = "0.124.28"; + +/** What ran: an Op, a component selection (`chant run --components`), or a CI pipeline. */ +export type RunEventKind = "op" | "component" | "pipeline"; + +/** Where the run happened: in the process that started it, on a steward, or in a forge's CI. */ +export type RunEventRuntime = "local" | "steward" | "ci"; + +/** How a run, wave, component or phase settled. `gated` and `waiting` wait on a person and are not failures. */ +export type RunEventSettleStatus = "ok" | "failed" | "gated" | "waiting"; + +/** + * How a step settled. `skipped` says why in {@link RunEventStepSettle.skip}; + * `cached` is for a cache hit standing in for the step (#4015). + */ +export type RunEventStepStatus = "ok" | "failed" | "skipped" | "cached" | "gated" | "waiting"; + +/** Why a step was skipped. */ +export type RunEventSkipReason = "receipt" | "resumed" | "refused" | "not-run"; + +/** How a gate's approval passed, when it was more than one person's approval of that gate. */ +export type RunEventGateVia = "quorum" | "policy" | "point" | "alias"; + +/** The run every event of a stream names: the same on every line. */ +export interface RunEventRun { + /** The run's id, in the id space `runOrigin.forge` names. */ + runId: string; + kind: RunEventKind; + /** The Op's name, the component selection as given, or the pipeline's name. */ + name: string; + /** The commit the run built from, or null when it did not start in a git checkout. */ + gitSha: string | null; + runtime: RunEventRuntime; + /** The locator: the shape a release record's `runOrigin` has. */ + runOrigin: RunOrigin; +} + +/** What every event carries besides its body. */ +export interface RunEventEnvelope extends RunEventRun { + $schema: typeof RUN_EVENT_SCHEMA_ID; + contract: typeof RUN_EVENT_CONTRACT_VERSION; + /** The version of the chant that wrote the event. */ + chant: string; + /** The event's place in its run's stream, from 0 at `run-start`. */ + seq: number; + /** When it happened, ISO-8601. */ + at: string; +} + +export interface RunEventRunStart { + type: "run-start"; + /** In a component run, the waves the run will attempt, in order. Null in an Op or pipeline run. */ + waves: string[][] | null; +} + +/** The last event of a stream. Its `status` is the run's verdict. */ +export interface RunEventRunSettle { + type: "run-settle"; + status: RunEventSettleStatus; + durationMs: number | null; + error?: string; +} + +export interface RunEventWaveStart { + type: "wave-start"; + /** 1-based, into `run-start`'s `waves`. */ + wave: number; + components: string[]; +} + +export interface RunEventWaveSettle { + type: "wave-settle"; + wave: number; + status: RunEventSettleStatus; +} + +export interface RunEventComponentStart { + type: "component-start"; + wave: number; + component: string; +} + +export interface RunEventComponentSettle { + type: "component-settle"; + wave: number; + component: string; + status: RunEventSettleStatus; +} + +/** An Op's phase, a component composition's phase, or a pipeline's stage. `component` is null outside a component run. */ +export interface RunEventPhaseStart { + type: "phase-start"; + component: string | null; + phase: string; +} + +export interface RunEventPhaseSettle { + type: "phase-settle"; + component: string | null; + phase: string; + status: RunEventSettleStatus; +} + +/** An Op or composition step, or a pipeline's job. */ +export interface RunEventStepStart { + type: "step-start"; + component: string | null; + phase: string; + /** The activity, `gate:`, `effect:`, or the job's name. */ + step: string; +} + +export interface RunEventStepSettle { + type: "step-settle"; + component: string | null; + phase: string; + step: string; + status: RunEventStepStatus; + /** With `skipped`: why, or null when the writer does not know. */ + skip?: RunEventSkipReason | null; + durationMs: number | null; + /** With `failed`: what failed. */ + error?: string; + /** Why the step skipped, gated or waited, for a person. */ + message?: string; +} + +/** The run stopped at a gate nobody has approved, or a decision point nobody has answered. */ +export interface RunEventGateWaiting { + type: "gate-waiting"; + component: string | null; + phase: string; + step: string; + /** The op the gate is recorded under, which `chant approve` takes. */ + op: string; + /** The gate's name, or null when the step waits on a decision point alone. */ + gate: string | null; + /** The open question's answer record id, or null. */ + point: string | null; + message?: string; +} + +export interface RunEventGateResolved { + type: "gate-resolved"; + component: string | null; + phase: string; + step: string; + op: string; + gate: string; + resolvedBy: string; + resolvedAt: string; + via: RunEventGateVia | null; + url?: string; +} + +/** The type-specific part of an event: what an emitter hands the writer. */ +export type RunEventBody = + | RunEventRunStart + | RunEventRunSettle + | RunEventWaveStart + | RunEventWaveSettle + | RunEventComponentStart + | RunEventComponentSettle + | RunEventPhaseStart + | RunEventPhaseSettle + | RunEventStepStart + | RunEventStepSettle + | RunEventGateWaiting + | RunEventGateResolved; + +export type RunEventType = RunEventBody["type"]; + +/** Every event type, in the order a reader meets them. Closed: part of the contract. */ +export const RUN_EVENT_TYPES = [ + "run-start", + "wave-start", + "component-start", + "phase-start", + "step-start", + "gate-waiting", + "gate-resolved", + "step-settle", + "phase-settle", + "component-settle", + "wave-settle", + "run-settle", +] as const satisfies readonly RunEventType[]; + +/** One line of a run's stream. */ +export type RunEvent = RunEventBody extends infer B ? (B extends RunEventBody ? RunEventEnvelope & B : never) : never; + +/** One event as its line: JSON with the envelope first, then the body, and a newline. */ +export function serializeRunEvent(event: RunEvent): string { + return JSON.stringify(event) + "\n"; +} + +/** What {@link writeRunEvent} and {@link createRunEventWriter} need besides the body. */ +export interface RunEventStamp { + run: RunEventRun; + seq: number; + /** When it happened. Defaults to now. */ + at?: Date | string; + /** Defaults to this chant's version. */ + chant?: string; +} + +/** + * Build one event from its body and the run it belongs to. The envelope's + * fields come first, so every line reads the same way. No body names an + * envelope field, so neither overrides the other. + */ +export function buildRunEvent(body: RunEventBody, stamp: RunEventStamp): RunEvent { + const at = stamp.at === undefined ? new Date().toISOString() : typeof stamp.at === "string" ? stamp.at : stamp.at.toISOString(); + const { runId, kind, name, gitSha, runtime, runOrigin } = stamp.run; + const envelope: RunEventEnvelope = { + $schema: RUN_EVENT_SCHEMA_ID, + contract: RUN_EVENT_CONTRACT_VERSION, + chant: stamp.chant ?? CHANT_VERSION, + seq: stamp.seq, + at, + runId, + kind, + name, + gitSha, + runtime, + runOrigin, + }; + return { ...envelope, ...body } as RunEvent; +} + +/** Build one event and hand its line to `write`. Returns the event written. */ +export function writeRunEvent(body: RunEventBody, stamp: RunEventStamp, write: (line: string) => void): RunEvent { + const event = buildRunEvent(body, stamp); + write(serializeRunEvent(event)); + return event; +} + +/** A run's writer: it keeps the run and the sequence, so an emitter hands it bodies only. */ +export interface RunEventWriter { + /** Write the next event of the run and return it. */ + emit(body: RunEventBody): RunEvent; + /** The `seq` the next event gets. */ + readonly next: number; +} + +export interface RunEventWriterOptions { + run: RunEventRun; + /** Where each line goes. Defaults to standard output. */ + write?: (line: string) => void; + /** The clock. Defaults to `new Date()`. */ + now?: () => Date; + /** The `seq` of the first event, for a writer that carries on a stream. Defaults to 0. */ + seq?: number; + /** Defaults to this chant's version. */ + chant?: string; +} + +/** The one writer of a run's stream (#4019). Each `emit` writes one line and moves the sequence on. */ +export function createRunEventWriter(opts: RunEventWriterOptions): RunEventWriter { + const write = opts.write ?? ((line: string) => void process.stdout.write(line)); + const now = opts.now ?? (() => new Date()); + let seq = opts.seq ?? 0; + return { + emit(body) { + return writeRunEvent(body, { run: opts.run, seq: seq++, at: now(), chant: opts.chant }, write); + }, + get next() { + return seq; + }, + }; +} + +// ── The older streams, in terms of this one ───────────────────────────────── + +/** + * A `RunProgressEvent` (`chant run --components --progress-json`) as a + * run-event body. The older stream has no step timings, so `durationMs` is + * null on the settles it maps to. + */ +export function runEventOfProgress(event: RunProgressEvent): RunEventBody { + switch (event.type) { + case "run-start": + return { type: "run-start", waves: event.waves }; + case "wave-start": + return { type: "wave-start", wave: event.wave, components: event.components }; + case "component-start": + return { type: "component-start", wave: event.wave, component: event.component }; + case "phase-start": + return { type: "phase-start", component: event.component, phase: event.phase }; + case "step": + if (event.status === "running") return { type: "step-start", component: event.component, phase: event.phase, step: event.step }; + return { + type: "step-settle", + component: event.component, + phase: event.phase, + step: event.step, + status: event.status, + durationMs: null, + ...(event.error !== undefined ? { error: event.error } : {}), + }; + case "phase-done": + return { type: "phase-settle", component: event.component, phase: event.phase, status: event.status }; + case "component-done": + return { type: "component-settle", wave: event.wave, component: event.component, status: event.status }; + case "wave-done": + return { type: "wave-settle", wave: event.wave, status: event.status }; + case "run-done": + return { type: "run-settle", status: event.status, durationMs: null }; + } +} + +const GATE_PREFIX = "gate:"; + +/** + * A settled `StepRecord` (`chant run --progress-json`) as run-event + * bodies: a gate's `gate-resolved` or `gate-waiting` when the record carries + * one, then the `step-settle`. `op` is the run's Op, which a gate is recorded + * under unless the record names another. + * + * A record skipped with nothing to say why maps to `skip: null`. The local + * executor writes the same record for a gate nobody has approved, for a step + * of an effect whose receipt matched and for a step an earlier failure + * stopped, so only an emitter that knows which (#4041) can say `gated`, + * `receipt` or `not-run`. The run's own status still says `gated`. + */ +export function runEventsOfStepRecord(record: StepRecord, ctx: { op: string; component?: string | null }): RunEventBody[] { + const component = ctx.component ?? null; + const at = { component, phase: record.phase, step: record.fn }; + const out: RunEventBody[] = []; + const settle = (status: RunEventStepStatus, extra: Partial = {}): RunEventStepSettle => ({ + type: "step-settle", + ...at, + status, + durationMs: record.durationMs, + ...extra, + }); + const gateOfFn = record.fn.startsWith(GATE_PREFIX) ? record.fn.slice(GATE_PREFIX.length) : null; + + if (record.approval) { + const a = record.approval; + out.push({ + type: "gate-resolved", + ...at, + op: ctx.op, + gate: a.gate, + resolvedBy: a.resolvedBy, + resolvedAt: a.timestamp, + via: a.via ?? null, + ...(a.url !== undefined ? { url: a.url } : {}), + }); + } + if (record.status === "ok") { + out.push(settle("ok")); + return out; + } + if (record.status === "fail") { + out.push(settle("failed", record.error !== undefined ? { error: record.error } : {})); + return out; + } + const message = record.refusal !== undefined ? { message: record.refusal } : {}; + if (record.point) { + out.push({ type: "gate-waiting", ...at, op: ctx.op, gate: gateOfFn, point: record.point.id, ...message }); + out.push(settle("waiting", message)); + } else if (record.gate) { + out.push({ type: "gate-waiting", ...at, op: record.gate.op, gate: record.gate.gate, point: null, ...message }); + out.push(settle("gated", message)); + } else if (gateOfFn !== null && record.refusal !== undefined) { + out.push({ type: "gate-waiting", ...at, op: ctx.op, gate: gateOfFn, point: null, ...message }); + out.push(settle("gated", message)); + } else if (record.resumed) { + out.push(settle("skipped", { skip: "resumed", message: `resumed at gate ${record.resumed.gate} from run ${record.resumed.run}` })); + } else if (record.refusal !== undefined) { + out.push(settle("skipped", { skip: "refused", ...message })); + } else { + out.push(settle("skipped", { skip: null })); + } + return out; +} diff --git a/packages/core/src/workspace/run-event.schema.json b/packages/core/src/workspace/run-event.schema.json new file mode 100644 index 0000000000..adf9045bee --- /dev/null +++ b/packages/core/src/workspace/run-event.schema.json @@ -0,0 +1,283 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://intentius.io/chant/schemas/workspace/run-event/v1/run-event.schema.json", + "title": "chant run event", + "description": "One event of a run's stream (#4019, behold #678): one JSON object per line, written by writeRunEvent and createRunEventWriter in src/run-event.ts. It covers Op runs, component runs and pipeline runs alike. Every event names the run, what it ran, the commit it built from and the runtime it ran on, so a reader shows a run the same way wherever it happened. A run's stream opens with run-start and ends with run-settle, whose status is the run's verdict; seq counts the events from 0. Version 1 of the read contract. Readers ignore fields they do not know; a field is only ever added within a version. The status sets are closed. Contract version 1 of this document is written by chant 0.124.28 and newer; the read contract as a whole by chant 0.81.0 and newer.", + "oneOf": [ + { "$ref": "#/$defs/run-start" }, + { "$ref": "#/$defs/run-settle" }, + { "$ref": "#/$defs/wave-start" }, + { "$ref": "#/$defs/wave-settle" }, + { "$ref": "#/$defs/component-start" }, + { "$ref": "#/$defs/component-settle" }, + { "$ref": "#/$defs/phase-start" }, + { "$ref": "#/$defs/phase-settle" }, + { "$ref": "#/$defs/step-start" }, + { "$ref": "#/$defs/step-settle" }, + { "$ref": "#/$defs/gate-waiting" }, + { "$ref": "#/$defs/gate-resolved" } + ], + "$defs": { + "envelope": { + "type": "object", + "description": "What every event carries.", + "required": ["$schema", "contract", "chant", "seq", "at", "type", "runId", "kind", "name", "gitSha", "runtime", "runOrigin"], + "properties": { + "$schema": { "const": "https://intentius.io/chant/schemas/workspace/run-event/v1/run-event.schema.json" }, + "contract": { "const": 1 }, + "chant": { "type": "string", "description": "The version of the chant that wrote the event." }, + "seq": { "type": "integer", "minimum": 0, "description": "The event's place in its run's stream: 0 for run-start, one more for each event after it." }, + "at": { "type": "string", "description": "When the event happened, ISO-8601." }, + "type": { "type": "string" }, + "runId": { "type": "string", "minLength": 1, "description": "The run's id, in the id space runOrigin.forge names: the Op run id, the GitHub or Forgejo run id, the GitLab pipeline id, or one minted locally." }, + "kind": { "enum": ["op", "component", "pipeline"], "description": "What ran: an Op, a component selection (chant run --components), or a CI pipeline." }, + "name": { "type": "string", "description": "The Op's name, the component selection as given, or the pipeline's name." }, + "gitSha": { + "type": ["string", "null"], + "pattern": "^[0-9a-f]{40,64}$", + "description": "The commit the run built from, the same field a release record carries. Null when the run did not start in a git checkout." + }, + "runtime": { + "enum": ["local", "steward", "ci"], + "description": "Where the run happened: in the process that started it, on a steward, or in a forge's CI." + }, + "runOrigin": { "$ref": "#/$defs/runOrigin" } + } + }, + "runOrigin": { + "type": "object", + "description": "The id space runId lives in and how to reach the run: RunOrigin from lifecycle/release-ledger.ts, the shape a release record's runOrigin has.", + "required": ["forge"], + "properties": { + "forge": { + "enum": ["github", "gitlab", "op", "local"], + "description": "github: a GitHub Actions run id, also the spelling Forgejo Actions uses. gitlab: a CI pipeline id. op: an Op run id, which a steward's run carries. local: minted on the machine that ran it." + }, + "repo": { "type": "string", "description": "The repository or project slug on the forge, when the environment named one." }, + "url": { "type": "string", "description": "A link to the run, when the environment gave enough to build one." } + } + }, + "settleStatus": { + "enum": ["ok", "failed", "gated", "waiting"], + "description": "How a run, wave, component or phase settled. gated: it stopped at a gate nobody has approved. waiting: it stopped at a decision point nobody has answered. Neither is a failure." + }, + "component": { + "type": ["string", "null"], + "description": "The component whose composition the phase or step belongs to in a component run, and null in an Op or pipeline run." + }, + "run-start": { + "allOf": [ + { "$ref": "#/$defs/envelope" }, + { + "type": "object", + "description": "The run is about to start.", + "required": ["type", "waves"], + "properties": { + "type": { "const": "run-start" }, + "waves": { + "type": ["array", "null"], + "items": { "type": "array", "items": { "type": "string" } }, + "description": "In a component run, the waves of components the run will attempt, in order; wave numbers in later events count from 1 into this list. Null in an Op or pipeline run." + } + } + } + ] + }, + "run-settle": { + "allOf": [ + { "$ref": "#/$defs/envelope" }, + { + "type": "object", + "description": "The run settled. The last event of the stream, and its verdict.", + "required": ["type", "status", "durationMs"], + "properties": { + "type": { "const": "run-settle" }, + "status": { "$ref": "#/$defs/settleStatus" }, + "durationMs": { "type": ["integer", "null"], "minimum": 0, "description": "From run-start to now, or null when the writer did not time it." }, + "error": { "type": "string", "description": "With status failed, what failed, when the writer knows." } + } + } + ] + }, + "wave-start": { + "allOf": [ + { "$ref": "#/$defs/envelope" }, + { + "type": "object", + "description": "A wave of a component run is about to start. Its components may run at the same time.", + "required": ["type", "wave", "components"], + "properties": { + "type": { "const": "wave-start" }, + "wave": { "type": "integer", "minimum": 1 }, + "components": { "type": "array", "items": { "type": "string" } } + } + } + ] + }, + "wave-settle": { + "allOf": [ + { "$ref": "#/$defs/envelope" }, + { + "type": "object", + "description": "A wave settled. failed if any component in it failed, which stops the run before the next wave.", + "required": ["type", "wave", "status"], + "properties": { + "type": { "const": "wave-settle" }, + "wave": { "type": "integer", "minimum": 1 }, + "status": { "$ref": "#/$defs/settleStatus" } + } + } + ] + }, + "component-start": { + "allOf": [ + { "$ref": "#/$defs/envelope" }, + { + "type": "object", + "description": "A component in a wave is about to start its deploy composition.", + "required": ["type", "wave", "component"], + "properties": { + "type": { "const": "component-start" }, + "wave": { "type": "integer", "minimum": 1 }, + "component": { "type": "string" } + } + } + ] + }, + "component-settle": { + "allOf": [ + { "$ref": "#/$defs/envelope" }, + { + "type": "object", + "description": "A component's composition settled, after any rollback the run did for it.", + "required": ["type", "wave", "component", "status"], + "properties": { + "type": { "const": "component-settle" }, + "wave": { "type": "integer", "minimum": 1 }, + "component": { "type": "string" }, + "status": { "$ref": "#/$defs/settleStatus" } + } + } + ] + }, + "phase-start": { + "allOf": [ + { "$ref": "#/$defs/envelope" }, + { + "type": "object", + "description": "A phase is about to run its steps: an Op's phase, a component composition's phase, or a pipeline's stage.", + "required": ["type", "component", "phase"], + "properties": { + "type": { "const": "phase-start" }, + "component": { "$ref": "#/$defs/component" }, + "phase": { "type": "string" } + } + } + ] + }, + "phase-settle": { + "allOf": [ + { "$ref": "#/$defs/envelope" }, + { + "type": "object", + "description": "A phase settled: ok when every step in it settled ok, skipped or cached.", + "required": ["type", "component", "phase", "status"], + "properties": { + "type": { "const": "phase-settle" }, + "component": { "$ref": "#/$defs/component" }, + "phase": { "type": "string" }, + "status": { "$ref": "#/$defs/settleStatus" } + } + } + ] + }, + "step-start": { + "allOf": [ + { "$ref": "#/$defs/envelope" }, + { + "type": "object", + "description": "A step is about to run: an Op or composition step, or a pipeline's job.", + "required": ["type", "component", "phase", "step"], + "properties": { + "type": { "const": "step-start" }, + "component": { "$ref": "#/$defs/component" }, + "phase": { "type": "string" }, + "step": { "type": "string", "description": "The step's activity, gate: for a gate, effect: for an effect, or the job's name." } + } + } + ] + }, + "step-settle": { + "allOf": [ + { "$ref": "#/$defs/envelope" }, + { + "type": "object", + "description": "A step settled.", + "required": ["type", "component", "phase", "step", "status", "durationMs"], + "properties": { + "type": { "const": "step-settle" }, + "component": { "$ref": "#/$defs/component" }, + "phase": { "type": "string" }, + "step": { "type": "string" }, + "status": { + "enum": ["ok", "failed", "skipped", "cached", "gated", "waiting"], + "description": "ok: it ran and succeeded. failed: it ran and failed. skipped: it did not run, and skip says why. cached: a cache hit stood in for running it (#4015). gated: it stopped the run at a gate nobody has approved. waiting: it stopped the run at a decision point nobody has answered." + }, + "skip": { + "enum": ["receipt", "resumed", "refused", "not-run", null], + "description": "With status skipped. receipt: the effect's receipt matched, so it had already applied. resumed: the run resumed at a later gate and carried this step's output from an earlier run. refused: it declined to go on, and message says why. not-run: an earlier step failed or stopped the run. Null when the writer does not know." + }, + "durationMs": { "type": ["integer", "null"], "minimum": 0, "description": "How long it ran, or null when the writer did not time it." }, + "error": { "type": "string", "description": "With status failed, what failed." }, + "message": { "type": "string", "description": "Why a step skipped, gated or waited, for a person." } + } + } + ] + }, + "gate-waiting": { + "allOf": [ + { "$ref": "#/$defs/envelope" }, + { + "type": "object", + "description": "The run stopped and waits on a person: a gate nobody has approved, or a decision point nobody has answered. The step settles gated or waiting next.", + "required": ["type", "component", "phase", "step", "op", "gate", "point"], + "properties": { + "type": { "const": "gate-waiting" }, + "component": { "$ref": "#/$defs/component" }, + "phase": { "type": "string" }, + "step": { "type": "string" }, + "op": { "type": "string", "description": "The op the gate is recorded under, which chant approve takes. It differs from name when a step's command stopped at a gate of its own." }, + "gate": { "type": ["string", "null"], "description": "The gate's name, or null when the step waits on a decision point alone." }, + "point": { "type": ["string", "null"], "description": "The answer record id of the open question, which points answer takes, or null." }, + "message": { "type": "string", "description": "Why the gate did not pass, such as an approval for a different plan." } + } + } + ] + }, + "gate-resolved": { + "allOf": [ + { "$ref": "#/$defs/envelope" }, + { + "type": "object", + "description": "A gate the run reached was approved, so its step goes on.", + "required": ["type", "component", "phase", "step", "op", "gate", "resolvedBy", "resolvedAt", "via"], + "properties": { + "type": { "const": "gate-resolved" }, + "component": { "$ref": "#/$defs/component" }, + "phase": { "type": "string" }, + "step": { "type": "string" }, + "op": { "type": "string" }, + "gate": { "type": "string" }, + "resolvedBy": { "type": "string", "description": "Who approved it." }, + "resolvedAt": { "type": "string", "description": "When the approval was recorded, ISO-8601." }, + "via": { + "enum": ["quorum", "policy", "point", "alias", null], + "description": "How the approval passed when it was more than one person's approval of this gate: a quorum, a policy permit, a decision point's answer, or an approval recorded under one of the gate's aliases." + }, + "url": { "type": "string", "description": "Where the approval was made, when known." } + } + } + ] + } + } +} From a0ca5158e0730ac43c8a2f4cb212ad3dbfafa9a3 Mon Sep 17 00:00:00 2001 From: lex00 <121451605+lex00@users.noreply.github.com> Date: Fri, 16 Oct 2026 18:33:44 -0600 Subject: [PATCH 2/2] docs: ratchet the prose baseline down after #4019 --- scripts/docs-sentences-baseline.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/docs-sentences-baseline.json b/scripts/docs-sentences-baseline.json index 68d348a0c8..486fae91b8 100644 --- a/scripts/docs-sentences-baseline.json +++ b/scripts/docs-sentences-baseline.json @@ -193,8 +193,7 @@ }, "docs/src/content/docs/cli/run.mdx": { "claude/colon-reveal": 3, - "tricolon/comma-series": 3, - "anaphora/repeated-opening": 1 + "tricolon/comma-series": 3 }, "docs/src/content/docs/cli/scenario.mdx": { "formatting/em-dash-density": 5,