import type { Finding, FindingPath } from "../schema/findings.js"; import type { WorkNode, Workspec } from "../schema/workspec.js"; import type { NodeAddress, NodeContractAssembly, PlanReceipt } from "../plan/index.js"; import type { ObservedNodeVerificationRecord, ObservedVerificationCacheUpdate, ObservedVerificationResult, TreeIdentity, VerificationFailure } from "../verify/index.js"; export type { NodeAddress } from "../plan/index.js"; export type { TreeIdentity } from "../verify/index.js"; export type LifecycleState = "done" | "ready" | "blocked" | "needs-decision"; export type VerificationState = "verified-this-session" | "failed-this-session" | "observed-green-not-verified-this-session" | "observed-failure-not-verified-this-session" | "stale-observation" | "conflicting-observation" | "unverified"; export type ReviewState = "not-configured" | "required-not-reviewed" | "approved-this-session" | "rejected-this-session" | "observed-approval-not-authoritative" | "observed-rejection-not-authoritative"; export type StatusBlocker = { readonly code: "dependency"; readonly addresses: readonly NodeAddress[]; } | { readonly code: "children"; readonly addresses: readonly NodeAddress[]; } | { readonly code: "completion-contract"; readonly reason: "no-execution-evidence" | "positive-floor-missing" | "checklist-incomplete"; } | { readonly code: "open-decision"; readonly ids: readonly string[]; }; /** Findings are deliberately separate from schema findings: cache data is not authored input. */ export type StatusFinding = { readonly code: "invalid-status-input"; readonly message: string; } | { readonly code: "spec-read-error"; readonly message: string; readonly path: FindingPath; } | { readonly code: "spec-path-escape"; readonly message: string; readonly path: FindingPath; } | { readonly code: "tree-identity-error"; readonly message: string; } | { readonly code: "duplicate-node-address"; readonly address: NodeAddress; readonly message: string; } | { readonly code: "missing-node-address"; readonly address: NodeAddress; readonly message: string; } | { readonly code: "ambiguous-node-id"; readonly nodeId: string; readonly addresses: readonly NodeAddress[]; readonly message: string; } | { readonly code: "duplicate-checklist-address"; readonly address: NodeAddress; readonly message: string; } | { readonly code: "invalid-checklist-report"; readonly address: NodeAddress; readonly message: string; } | { readonly code: "positive-floor-missing"; readonly address: NodeAddress; readonly criterionId: string; readonly message: string; } | { readonly code: "cache-read-error"; readonly path: string; readonly message: string; } | { readonly code: "cache-parse-error"; readonly path: string; readonly message: string; } | { readonly code: "unsupported-cache-version"; readonly path: string; readonly version: unknown; readonly message: string; } | { readonly code: "malformed-cache"; readonly path: string; readonly message: string; } | { readonly code: "malformed-cache-entry"; readonly address?: NodeAddress; readonly message: string; } | { readonly code: "cache-source-mismatch"; readonly expected: string; readonly actual: string; readonly message: string; } | { readonly code: "cache-address-mismatch"; readonly address: NodeAddress; readonly nodeId: string; readonly message: string; } | { readonly code: "cache-unknown-address"; readonly address: NodeAddress; readonly message: string; } | { readonly code: "cache-duplicate-address"; readonly address: NodeAddress; readonly message: string; } | { readonly code: "cache-duplicate-run-id"; readonly runId: string; readonly message: string; } | { readonly code: "cache-dispatch-node-mismatch"; readonly address: NodeAddress; readonly nodeId: string; readonly message: string; } | { readonly code: "cache-dispatch-target-mismatch"; readonly runId: string; readonly expected: string; readonly actual: string; readonly message: string; } | { readonly code: "stale-cache-observation"; readonly address: NodeAddress; readonly message: string; } | { readonly code: "cache-source-conflict"; readonly address: NodeAddress; readonly message: string; } | { readonly code: "cache-write-error"; readonly path: string; readonly message: string; } | { readonly code: "refresh-authority-unavailable"; readonly message: string; } | { readonly code: "refresh-address-required"; readonly message: string; } | { readonly code: "refresh-address-ambiguous"; readonly nodeId: string; readonly addresses: readonly NodeAddress[]; readonly message: string; }; export interface StatusCacheVerificationEntry { readonly address: NodeAddress; readonly update: ObservedVerificationCacheUpdate; } export interface ObservedReviewRecord { readonly address: NodeAddress; readonly verdict: "approved" | "rejected"; readonly tree: TreeIdentity; readonly source: string; readonly recordedAt: string; } export interface StatusCacheDispatchInputDigest { readonly kind: "task" | "read" | "checklist" | "focus"; readonly name: string; readonly algorithm: "sha256"; readonly digest: string; } /** The runtime-reported slot fields are optional where pi-delegate cannot resolve them at receipt time. */ export interface StatusCacheDispatchSlot { readonly agent: string; readonly workerCwd?: string; readonly branch?: string; readonly maxRounds: number; readonly cloneMode?: string; readonly collapseMode?: string; readonly confineWrites?: boolean; readonly readOnly?: boolean; readonly requestedModel?: string; readonly resolvedModel?: string; readonly skills?: readonly string[]; readonly inputDigests: readonly StatusCacheDispatchInputDigest[]; } export interface StatusCacheDispatchEntry { readonly runId: string; readonly forkName: string; readonly nodeId: string; readonly address: NodeAddress; readonly createdAt: string; readonly worktreePath: string; readonly headCommit: string; readonly branch: string; readonly briefPath: string; readonly briefSha256: string; readonly slot: StatusCacheDispatchSlot; readonly receiptPath: string; readonly resultPath: string; } /** Run-id-keyed history. It is an untrusted reporting hint and never lifecycle authority. */ export type StatusCacheDispatchSection = Readonly>; export interface StatusCacheV1 { readonly kind: "pi-work-status-cache"; readonly version: 1; readonly specPath: string; readonly verification: Readonly>; readonly review: Readonly>; readonly dispatch: StatusCacheDispatchSection; } export type StatusCacheDispatchWriteResult = { readonly status: "written"; readonly path: string; readonly attempts: number; readonly residualRace: "readback-may-precede-later-overwrite"; } | { readonly status: "contended"; readonly path: string; readonly attempts: number; readonly residualRace: "readback-may-precede-later-overwrite"; readonly message: string; } | { readonly status: "failed"; readonly path: string; readonly attempts: number; readonly reason: "cache-read-error" | "malformed-cache" | "cache-source-mismatch" | "run-id-conflict" | "cache-write-error"; readonly message: string; }; export type StatusCacheVerificationWriteResult = { readonly status: "written"; readonly path: string; readonly attempts: number; readonly residualRace: "readback-may-precede-later-overwrite"; } | { readonly status: "contended"; readonly path: string; readonly attempts: number; readonly residualRace: "readback-may-precede-later-overwrite"; readonly message: string; } | { readonly status: "failed"; readonly path: string; readonly attempts: number; readonly reason: "cache-read-error" | "malformed-cache" | "cache-source-mismatch" | "cache-write-error"; readonly message: string; }; export interface StatusCacheDecode { readonly cache?: StatusCacheV1; readonly findings: readonly StatusFinding[]; } export type ObservationReport = { readonly state: "observed-green-not-verified-this-session"; readonly update: ObservedVerificationCacheUpdate; } | { readonly state: "observed-failure-not-verified-this-session"; readonly update: ObservedVerificationCacheUpdate; } | { readonly state: "stale-observation"; readonly update: ObservedVerificationCacheUpdate; } | { readonly state: "conflicting-observation"; readonly update: ObservedVerificationCacheUpdate; } | { readonly state: "unverified"; }; /** Containment used by command evidence in an authority-verified pass. */ export interface VerificationContainment { readonly method: "systemd-scope" | "process-group" | "unknown"; } export interface NodeStatusReport { readonly address: NodeAddress; readonly nodeId: string; readonly task: string; readonly lifecycle: LifecycleState; readonly verification: VerificationState; readonly containment: readonly VerificationContainment[]; readonly verificationObservation?: ObservedVerificationResult; readonly review: ReviewState; readonly reviewText: string; readonly dispatches: readonly StatusCacheDispatchEntry[]; readonly blockers: readonly StatusBlocker[]; readonly findings: readonly StatusFinding[]; readonly lifecycleText: string; readonly verificationText: string; } export interface WorkStatusDetails { readonly path: string; readonly cachePath: string; readonly currentTree?: TreeIdentity; readonly specState: "done" | "not-done"; readonly valid: boolean; readonly findings: readonly (Finding | StatusFinding | VerificationFailure)[]; readonly nodes: readonly NodeStatusReport[]; readonly unresolvedDecisions: readonly string[]; readonly dispatch: StatusCacheDispatchSection; readonly refresh: RefreshResult; readonly refreshed: boolean; readonly truncated: boolean; } export interface WorkStatusResult { readonly ok: boolean; readonly details: WorkStatusDetails; } export interface ChecklistReportInput { readonly index: number; readonly done: boolean; } export interface ChecklistReportsByAddress { readonly nodeAddress: NodeAddress; readonly reports: readonly ChecklistReportInput[]; } export interface RefreshRequest { readonly nodeAddresses?: readonly NodeAddress[] | undefined; readonly checklists?: readonly ChecklistReportsByAddress[] | undefined; } export interface StatusRequest { readonly path: string; readonly worktreePath: string; readonly expectedCommit: string; readonly refresh?: RefreshRequest | undefined; readonly signal?: AbortSignal | undefined; } export interface DeriveStatusInput { readonly source: string; readonly specPath: string; readonly tree: TreeIdentity; readonly cache?: unknown; } export interface RefreshBlocked { readonly status: "blocked"; readonly ran: false; readonly code: "refresh-authority-unavailable"; readonly message: string; readonly requires: readonly [ "a public production-authority verification entry point", "a trusted current-session result bound to the selected NodeAddress and TreeIdentity", "a serializable Observed* cache update produced after that run" ]; } export type RefreshResult = RefreshBlocked; export interface StatusGraph { readonly assemblies: readonly NodeContractAssembly[]; readonly byAddress: ReadonlyMap; readonly children: ReadonlyMap; readonly dependencies: ReadonlyMap; readonly ancestorDependencies: ReadonlyMap; } export interface StatusGraphBuild { readonly graph: StatusGraph; readonly findings: readonly StatusFinding[]; } export interface ValidatedStatusInput { readonly spec: Workspec; readonly source: string; readonly specPath: string; readonly tree: TreeIdentity; } export interface DerivedStatusContext { readonly graph: StatusGraph; readonly observations: ReadonlyMap; readonly trusted: ReadonlyMap; readonly review: ReadonlyMap; readonly dispatch: StatusCacheDispatchSection; readonly findings: readonly StatusFinding[]; } export type StatusNodeInput = { readonly node: WorkNode; readonly address: NodeAddress; }; export type { Finding, FindingPath, NodeContractAssembly, PlanReceipt, WorkNode, Workspec }; export declare const LIFECYCLE_TEXT: Readonly>; export declare const VERIFICATION_TEXT: Readonly>; export declare const REVIEW_TEXT: Readonly>; export declare const REFRESH_BLOCKED_MESSAGE = "refresh is not run by work_status; use work_verify to run the node's evidence and record the result"; export declare function lifecycleText(state: LifecycleState, values?: { readonly blockers?: string | undefined; readonly decisions?: string | undefined; }): string; export declare function verificationText(state: VerificationState, values?: { readonly sha?: string | undefined; readonly old?: string | undefined; readonly current?: string | undefined; }): string; export declare function reviewText(state: ReviewState): string; export declare function containmentQualification(containment: readonly VerificationContainment[]): string; export declare function refreshBlocked(): RefreshBlocked; export declare function isObservedGreen(observation: ObservationReport | undefined): observation is Extract; export declare function isObservedNodePassed(value: ObservedVerificationResult | undefined): value is ObservedNodeVerificationRecord;