import { cp, rm } from "node:fs/promises"; import { AUDIT_REPORT_FILENAME } from "audit-tools/shared"; import type { AuditResult, AuditTask, CoverageMatrix, RepoManifest, UnitManifest } from "../types.js"; import type { AuditState } from "../types/auditState.js"; import type { ArtifactMetadataManifest } from "../types/artifactMetadata.js"; import type { AuditFindingsReport, FileDisposition, CriticalFlowManifest, CriticalFlowFallbackResult, GraphBundle, RiskRegister, SurfaceManifest, IntentCheckpoint, GitHistory } from "audit-tools/shared"; import type { AccessMemory, SubmissionLedgerEvent } from "audit-tools/shared"; import type { SubmissionLedgerDrop } from "../../shared/submission/submissionLedger.js"; import type { SynthesisNarrativeRecord } from "../types/synthesisNarrative.js"; import type { ExternalAnalyzerResults, ExternalAnalyzerAcquisitionMarker } from "audit-tools/shared"; import type { FlowCoverageManifest } from "../types/flowCoverage.js"; import type { AuditPlanMetrics } from "../types/reviewPlanning.js"; import type { TaskAffinityGraph } from "../orchestrator/taskAffinityGraph.js"; import type { RuntimeValidationReport, RuntimeValidationTaskManifest } from "../types/runtimeValidation.js"; import type { DesignAssessment } from "../types/designAssessment.js"; import type { DocsDigest } from "../types/docsDigest.js"; import type { StructureDecomposition } from "../types/structureDecomposition.js"; import type { CharterRegister } from "../types/charterRegister.js"; import type { CharterClarificationRegister } from "../types/charterClarification.js"; import type { SystemicChallengeRegister } from "../types/systemicChallenge.js"; import type { AnalyzerCapabilityRecord } from "../types/analyzerCapability.js"; import type { AuditScopeManifest } from "../types/auditScope.js"; import type { ToolingManifest } from "../types/toolingManifest.js"; import { type DesignReviewSnapshotBundle } from "../orchestrator/designReviewSnapshot.js"; import type { GraphEdgeCache } from "../extractors/graph.js"; import { type AgentReflection } from "audit-tools/shared"; export { SchemaVersionMismatchError as ArtifactSchemaVersionError } from "audit-tools/shared"; type ArtifactPayloadMap = { repo_manifest: RepoManifest; file_disposition: FileDisposition; auto_fixes_applied: unknown; intent_checkpoint: IntentCheckpoint; unit_manifest: UnitManifest; graph_bundle: GraphBundle; surface_manifest: SurfaceManifest; critical_flows: CriticalFlowManifest; critical_flow_fallback: CriticalFlowFallbackResult; flow_coverage: FlowCoverageManifest; risk_register: RiskRegister; git_history: GitHistory; design_assessment: DesignAssessment; docs_digest: DocsDigest; structure_decomposition: StructureDecomposition; charter_register: CharterRegister; charter_clarification: CharterClarificationRegister; systemic_challenge: SystemicChallengeRegister; analyzer_capability: AnalyzerCapabilityRecord; scope: AuditScopeManifest; coverage_matrix: CoverageMatrix; runtime_validation_tasks: RuntimeValidationTaskManifest; runtime_validation_report: RuntimeValidationReport; external_analyzer_results: ExternalAnalyzerResults[]; external_analyzer_acquisition: ExternalAnalyzerAcquisitionMarker; syntax_resolution_status: unknown; audit_results: AuditResult[]; audit_tasks: AuditTask[]; audit_plan_metrics: AuditPlanMetrics; task_affinity_graph: TaskAffinityGraph; requeue_tasks: AuditTask[]; access_memory: AccessMemory; audit_report: string; audit_findings: AuditFindingsReport; synthesis_narrative: SynthesisNarrativeRecord; audit_state: AuditState; artifact_metadata: ArtifactMetadataManifest; tooling_manifest: ToolingManifest; }; /** * Audit artifacts accumulate phase-by-phase as the orchestrator advances. * Missing keys mean the corresponding artifact has not been produced yet. * * `agent_reflections` is the parsed view of the worker-APPENDED * `agent-feedback.jsonl` (opt-in meta-audit feedback). Workers own that file; * the orchestrator only ever reads it, so it is deliberately NOT an * ARTIFACT_DEFINITIONS entry — writeCoreArtifacts must never rewrite it (a * round-trip would drop lines a worker appended after load, and prune would * delete a file the orchestrator does not own). */ export type ArtifactBundle = Partial & { agent_reflections?: AgentReflection[]; /** * The design-review pass snapshots (B2 parity port), keyed by pass. Loaded * specially — they live under * `design-review-snapshots/` rather than as standard pruned artifacts — so the * synchronous `deriveAuditState` can key each pass's staleness on the semantic * projection of the structural inputs it reviewed. Absent until first review. */ design_review_snapshots?: DesignReviewSnapshotBundle; /** * Per-file graph-edge cache (C2 incremental graph-build). Loaded specially like * a single JSON file at the artifacts root, not an * `ARTIFACT_DEFINITIONS` entry — because it is an internal, self-describing * incremental-reuse cache, not a deliverable or a staleness-DAG node. The * structure executor reads it as the prior cache and returns a refreshed one. */ graph_edge_cache?: GraphEdgeCache; /** * The submission ledger's events, in arrival order. Loaded specially for the * same reason as `agent_reflections`: it is an APPEND-only NDJSON record the * orchestrator only ever reads, so it must never become an * `ARTIFACT_DEFINITIONS` entry a write-back could round-trip (that would drop * events appended after load and re-sort a file whose order is its meaning). * Synthesis renders its per-kind totals, which is what makes "this run * drifted and was repaired" a fact the REPORT states rather than one that * lived only in a transcript. */ submission_ledger?: readonly SubmissionLedgerEvent[]; /** * Lines the ledger reader could NOT read — torn writes and foreign * contract versions — with their line numbers and classified reasons. * * A SEPARATE FIELD, not the `dropped` property riding on the reader's return * value. That property is non-enumerable by design (so an unadapted consumer's * `toEqual([])` still holds), and non-enumerable means `structuredClone`, JSON * round-trips, spread and `slice` all silently shed it. A bundle is exactly the * kind of value that gets cloned and serialized, so carrying the drops only as * a hidden property would lose them at the first transform. Read off the reader * ONCE, at load, into a field of its own. */ submission_ledger_dropped?: readonly SubmissionLedgerDrop[]; }; export type ArtifactBundleKey = keyof ArtifactPayloadMap; type ArtifactPhase = "intake" | "analysis" | "execution" | "reporting" | "supervisor"; interface ArtifactDefinition { fileName: string; phase: ArtifactPhase; read: (path: string) => Promise; write: (path: string, value: ArtifactPayloadMap[K]) => Promise; } export { AUDIT_REPORT_FILENAME }; export declare const ARTIFACT_DEFINITIONS: { readonly repo_manifest: ArtifactDefinition<"repo_manifest">; readonly file_disposition: ArtifactDefinition<"file_disposition">; readonly auto_fixes_applied: ArtifactDefinition<"auto_fixes_applied">; readonly intent_checkpoint: ArtifactDefinition<"intent_checkpoint">; readonly unit_manifest: ArtifactDefinition<"unit_manifest">; readonly graph_bundle: ArtifactDefinition<"graph_bundle">; readonly surface_manifest: ArtifactDefinition<"surface_manifest">; readonly critical_flows: ArtifactDefinition<"critical_flows">; readonly critical_flow_fallback: ArtifactDefinition<"critical_flow_fallback">; readonly flow_coverage: ArtifactDefinition<"flow_coverage">; readonly risk_register: ArtifactDefinition<"risk_register">; readonly git_history: ArtifactDefinition<"git_history">; readonly design_assessment: ArtifactDefinition<"design_assessment">; readonly docs_digest: ArtifactDefinition<"docs_digest">; readonly structure_decomposition: ArtifactDefinition<"structure_decomposition">; readonly charter_register: ArtifactDefinition<"charter_register">; readonly charter_clarification: ArtifactDefinition<"charter_clarification">; readonly systemic_challenge: ArtifactDefinition<"systemic_challenge">; readonly analyzer_capability: ArtifactDefinition<"analyzer_capability">; readonly scope: ArtifactDefinition<"scope">; readonly coverage_matrix: ArtifactDefinition<"coverage_matrix">; readonly runtime_validation_tasks: ArtifactDefinition<"runtime_validation_tasks">; readonly runtime_validation_report: ArtifactDefinition<"runtime_validation_report">; readonly external_analyzer_results: ArtifactDefinition<"external_analyzer_results">; readonly external_analyzer_acquisition: ArtifactDefinition<"external_analyzer_acquisition">; readonly syntax_resolution_status: ArtifactDefinition<"syntax_resolution_status">; readonly audit_results: ArtifactDefinition<"audit_results">; readonly audit_tasks: ArtifactDefinition<"audit_tasks">; readonly audit_plan_metrics: ArtifactDefinition<"audit_plan_metrics">; readonly task_affinity_graph: ArtifactDefinition<"task_affinity_graph">; readonly requeue_tasks: ArtifactDefinition<"requeue_tasks">; readonly access_memory: ArtifactDefinition<"access_memory">; readonly audit_report: ArtifactDefinition<"audit_report">; readonly audit_findings: ArtifactDefinition<"audit_findings">; readonly synthesis_narrative: ArtifactDefinition<"synthesis_narrative">; readonly audit_state: ArtifactDefinition<"audit_state">; readonly artifact_metadata: ArtifactDefinition<"artifact_metadata">; readonly tooling_manifest: ArtifactDefinition<"tooling_manifest">; }; export declare const ARTIFACT_FILE_TO_BUNDLE_KEY: Record; export declare function getArtifactValue(bundle: ArtifactBundle, artifactName: string): unknown; export declare function loadArtifactBundle(root: string): Promise; export declare function writeCoreArtifacts(root: string, bundle: ArtifactBundle, options?: { prune?: boolean; }): Promise; /** * artifact:canonical-audit-deliverable-write-path -- the ONE write path to the * canonical `.audit-tools/audit-findings.json` + `audit-report.md` pair. * * ARCHIVE, THEN VERIFY, THEN REPLACE. An existing pair is copied into the * history directory and the copy is READ BACK and compared before either * destination is overwritten. A copy that is merely attempted-and-warned is not * an archive: it leaves the caller believing a prior deliverable was preserved * when it may not have been -- the same swallow-the-failure shape * DAT-4802dc9e-2 / -3 closed on the promotion side. * * Refuses rather than replaces: if the archive cannot be verified, the existing * pair stays exactly as it was and this throws. Keeping a stale deliverable is * recoverable; overwriting an unarchived one is not. * * CONSUMER DEFERRAL: `remediate-nextstep-and-final-gate` must route its own * leftover deliverable through this path and emit to a remediation-owned * location instead of writing this pair directly. That edit is CP-NODE-15's, * not this node's -- the same mechanical hand-off shape CP-NODE-5 used when it * deferred its ledger-read consumers here. */ export declare function writeCanonicalAuditDeliverables(params: { artifactsDir: string; findings: unknown; report: string; }): Promise<{ archived: readonly string[]; }>; export declare function promoteFinalAuditReport(params: { artifactsDir: string; }, options?: { copy?: typeof cp; remove?: typeof rm; warn?: (message: string) => void; }): Promise<{ promoted: boolean; cleaned: boolean; warning?: string; /** * Artifacts that could NOT be archived before the cleanup. Non-empty means the * delete was ABORTED, so a caller reading { promoted: true, cleaned: true } can * trust that nothing was lost — which is exactly what it could not do while a * findings-copy failure was a `warn()` with no effect on the returned shape * (INV 3 / DAT-4802dc9e-2, -3). */ unarchived?: readonly string[]; /** * Ledger lines the reader could not parse, surfaced so the promotion result * never describes a record cleaner than the run actually was. */ ledger_dropped?: readonly SubmissionLedgerDrop[]; }>; //# sourceMappingURL=artifacts.d.ts.map