diff --git a/docs/roadmap/preflight-command.md b/docs/roadmap/preflight-command.md new file mode 100644 index 0000000..78ed612 --- /dev/null +++ b/docs/roadmap/preflight-command.md @@ -0,0 +1,246 @@ +# Dedicated Preflight Command + +Status: Core design agreed; quiet-mode destination semantics remain open. +Implementation has not begun. + +## Purpose and Targeted End State + +Provide `audita preflight` so operators and orchestration applications such as +Narratio can check a proposed processing invocation without executing its +correction pipeline. The existing execution command is `audita process`; this +feature does not rename it or introduce a `run` alias. + +Preflight accepts the same transcript argument and processing options, including +configuration, overlay, runtime glossary files, profile and collection selections, +and intended output/report/debug settings. It adds a boolean `--smoke` option, +enabled by default: + +```sh +audita preflight --config audita.yml --overlay selected \ + --glossary-file session-glossaries.yml --output polished.json transcript.json + +audita preflight --smoke=false --config audita.yml \ + --output polished.json transcript.json +``` + +These are target commands, not implemented interfaces. Default preflight runs +shared local preparation followed by native PromptKit structured-output smoke +diagnostics for the selected profiles. `--smoke=false` runs local checks only. +CommandKit reports which scope was checked and the outcome. No persistent +preflight report format is required for this feature; callers can use exit status. + +Ordinary `process` reuses shared preparation and proceeds to execution without +adding smoke requests to every processing run. Native configuration inspection +and individual PromptKit diagnostic commands remain available for their existing +purposes. + +## Current Baseline + +Reviewed at Audita commit `8411a69`. Runtime glossary inputs and collection +instructions are implemented. Dependencies include ConfigKit v1.4.0, PromptKit +v0.25.0, CommandKit v0.8.0, ckconfig v0.11.0, and ckprompt v0.12.0. + +- `internal/cli/loadProcessInputs` acquires combined configuration and runtime + glossary inputs, constructs the PromptKit runtime, reads/parses the transcript, + and collects source paths for collision checks. It also enforces the current + quiet-processing destination rule. +- `internal/framework/preflight.ProcessingPlan` checks glossary-stage content, + proposal and validation profiles, and repair profiles when repair is enabled. + It resolves stage specifications and prepares shared glossary context. +- `preflight.Prepare`, called through CLI preparation, then selects and prepares + an output session, initializes reports, and may create debug artifacts. Calling + this whole function from the new command would perform unwanted output work. +- Normalization currently occurs later in `runProcess`; chunking occurs in the + runner. A standalone readiness check needs these deterministic preparation + steps without executing proposal, validation, repair, or correction application. +- PromptKit already exposes `Engine.SmokeTest` with a structured-output diagnostic + and native observations. A nil Go error means the diagnostic concluded, not + that its observations establish success. + +The [CLI contract](../cli.md), [operations guide](../operations.md), +[pipeline internals](../internal/pipeline.md), and +[configuration/CLI guide](../internal/cli-config.md) describe current behavior. +PromptKit's [v0.25.0 consumer guide](https://forge.maximumdirect.net/base-layer/promptkit/src/tag/v0.25.0/docs/consumers/pkg-promptkit.md#run-explicit-smoke-diagnostics) +owns the diagnostic API and its native semantics. + +## Shared Preparation and Execution Boundaries + +Refactor as needed for correctness and clear ownership, including substantial +changes where warranted. Minimizing the diff or preserving current helper/package +boundaries is not a design objective. Keep the resulting design proportionate; +this feature needs a shared preparation path, not a new workflow framework. + +### 1. Shared Local Preparation + +Both commands use the same argument bindings and acquisition path, retaining +ConfigKit's source composition, configured secrets bootstrap, CLI precedence, +and runtime glossary handling. Do not duplicate configuration interpretation in +the preflight command. + +Prepare an invocation-local execution plan containing the data needed for actual +processing: resolved settings and stages, prepared glossary context, normalized +transcript and normalization summary, fixed chunks, selected profile references, +and intended destination information. Exact Go types and package placement belong +to implementation planning. Retain an expressly named preflight package for +Audita's domain readiness orchestration. + +Perform existing transcript, glossary, profile, normalization, chunking-feasibility, +and destination checks in their appropriate owners. For example, an infeasible +requested section count should fail before smoke testing or model processing. +Reuse stage/profile inspection and prepared context rather than doing the same +work separately for each command. Preserve collection instructions and all +existing protection and role-fallback rules. + +Processing consumes this plan rather than normalizing, chunking, or resolving +stage selections independently again. This is shared code and invocation-local +data, not a persisted plan, cross-process cache, or a promise that a subsequent +invocation reuses the same configuration snapshot. + +### 2. Provider Verification + +After local readiness succeeds, default standalone preflight calls PromptKit's +native structured-output smoke diagnostic once per distinct selected profile ID. +Include proposal, validation, and enabled correction-repair profiles from the +resolved plan. Repeated uses of one profile share a check; two profiles on the +same backend remain distinct targets because their models or settings can differ. +Do not inspect the whole bundled catalog to invent additional smoke targets. +An empty pipeline has no model profiles to smoke-test and remains valid. + +Use the existing captured PromptKit engine and native effective profile settings. +Keep transport, credentials, diagnostic request construction, retries, admission, +and observations in PromptKit. Do not substitute a custom miniature Audita prompt +or execute production transcript requests. Reachability, authentication, and +text-only diagnostics remain accessible through existing native commands; this +command does not automatically run the entire diagnostic inventory. + +Audita owns the small outcome adaptation: when smoke is enabled, every selected +profile needs a positive structured-output result. Evaluate the native report's +completion, support/applicability, execution failure, and generation/schema +observations; a nil error or completed report alone is insufficient. Negative, +unsupported, or inconclusive results do not establish successful preflight and +must be identified distinctly in diagnostics. Do not require unrelated HTTP-only +facts to be present for an inference diagnostic. Preserve native errors and +available partial observations, especially on cancellation. + +`--smoke=false` skips this provider-verification phase, not local profile selection +or ordinary configuration/credential resolution. It does not introduce a new +credential-relaxation mode or alter ConfigKit bootstrap behavior. Use upstream +defaults for diagnostic execution controls unless an existing applicable setting +must be passed through; add no new retry loop, aggregate budget, or timeout policy. + +### 3. Output Resources and Processing + +Standalone preflight checks intended output paths and the existing collision and +placement rules without creating or truncating transcript/report files, initializing +processing reports, or retaining processing debug artifacts. Reporting and debug +flags remain accepted, describing the intended invocation; they do not initiate +the output lifecycle. CommandKit's diagnostic reporting still applies. + +Separate destination selection and non-writing checks from acquisition and +publication of output resources. Preserve existing in-place transcript support, +inactive-destination handling, and optional-debug failure severity. Do not open +pipes/devices for delivery or introduce permission-bit simulations, write probes, +or stronger filesystem guarantees to make preflight approximate publication. +Required output parents retain their existing requirements. Output preparation +and actual writes remain execution-time checks owned by the output session. + +Processing performs local preparation, then acquires output resources, initializes +its reports/debug evidence, and executes the prepared stages and chunks. Preserve +cleanup, cancellation, publication, and partial-failure semantics at that boundary. +Moving normalization/chunking before output initialization intentionally means +those early failures need not leave processing reports; document that lifecycle +change rather than fabricating an execution session during readiness checking. + +## Reporting and Command Semantics + +Use CommandKit's reporter and outcome handling for progress, summaries, errors, +and quiet mode. Progress can identify local preparation and each profile being +checked. The completion summary identifies local-only versus local-plus-smoke +scope, including when there were no profiles to test. Preserve native usage +reporting integration where applicable rather than adding local accounting. + +Use existing exit categories: success is `0`, invalid usage/input is `2`, and +operational failure is `1`. Continue native configuration diagnostic classification. +An unsuccessful or inconclusive provider verification is an operational failure; +missing required profile selections remain input failures. No new exit-code family, +machine-report schema, or mandatory retained artifacts are selected. + +Destination flags describe the would-be processing outputs; standalone preflight +does not emit a corrected transcript. Quiet-mode handling of an omitted destination +is the open decision below. Help/version continue to avoid configuration loading. +Do not turn the command into a general side-effect-free guarantee: ordinary +configured secrets bootstrap still applies, and provider verification is enabled +by default. Link upstream documentation for standard diagnostic behavior rather +than maintaining an Audita copy of the smoke-test reference. + +## Work to Reach the Target + +1. Refactor shared acquisition and local preparation. Extract destination checking + from output-session preparation, move normalization and chunk planning to the + shared path, and have processing consume the resulting plan. Remove obsolete + duplicate preparation and adjust error ownership with the new boundaries. +2. Add `preflight` using shared processing argument definitions and the default-on + `--smoke` flag. Wire it to local preparation without starting output sessions. + Resolve the quiet-destination decision before finalizing CLI behavior. +3. Add the native smoke adapter and selected-profile orchestration. Reuse the + existing PromptKit runtime and CommandKit reporting; preserve cancellation and + classify native observations correctly. Keep domain preparation independent + of provider-specific transport types wherever practical. +4. Validate behavior at the boundaries described below. Refactor existing tests + to protect the target behavior rather than preserving outdated call order. +5. Update canonical CLI, operations, subprocess integration, and internal pipeline, + preflight, and output-lifecycle documentation as the implementation lands. + Provide a small domain-neutral example. Narratio can adopt the readiness command + independently; no D&D-specific processing rules belong in Audita. + +## Validation + +Follow the [testing policy](../policy/testing.md). Use real local collaborators +and controlled provider responses; default tests remain offline and require no +real credentials. Focus coverage on: + +- Argument/configuration parity, including overlays, runtime glossaries, stage + overrides, profile fallback, and the selected quiet-mode rule. +- Shared normalized transcript/chunk/stage preparation, including an infeasible + chunk count, and processing consumption of the prepared plan. +- Local failures stopping before smoke calls; `--smoke=false` making none; default + smoke selecting distinct used profiles and omitting disabled repair roles. +- Positive and negative structured-output facts, nil-error negative reports, + unknown/unsupported outcomes, provider errors, and cancellation. +- Preflight preserving existing transcript/report files and avoiding output/debug + initialization, while still detecting existing destination collisions. +- Processing retaining its output publication and cleanup behavior after the + refactor, without automatically performing smoke tests. +- CommandKit completion, progress, quiet, and exit behavior at representative CLI + boundaries, without freezing incidental presentation or upstream report layouts. + +Reuse existing coverage for unchanged domain logic and upstream behavior. Run +focused tests during implementation and the repository's normal full suite and +build before completion. This documentation pass does not execute provider tests +or implement the command. + +## Open Decisions + +### Should quiet preflight require a transcript output destination? + +**Context:** Processing currently rejects quiet mode without `--output` because +it would suppress the only corrected transcript destination. That check lives in +the acquisition helper proposed for sharing. Standalone preflight does useful +readiness work even when its optional summary is suppressed, but accepting the +same arguments would then not imply that quiet processing accepts that exact +destination choice. + +**Recommendation:** Allow `preflight --quiet` without `--output`. Quiet controls +the readiness command's own reporting; no corrected transcript is being discarded. +Keep the destination requirement in the processing command, while sharing actual +destination selection and collision checks. This supports simple orchestration +using exit status without requiring a placeholder output path. The tradeoff is +that preflight's quiet/output combination is intentionally different from process. + +**Alternative:** Enforce processing's destination requirement during preflight as +well. This gives closer argument-level equivalence for callers switching the +command name and catches a future quiet-processing invocation with no destination. +It requires a destination or `/dev/null` even when the caller only wants a silent +readiness check. Both approaches preserve processing's current rule; choose the +standalone command's meaning explicitly rather than inheriting it accidentally +from a shared helper.