import type { GoalTodoNode } from "../core/types.js"; import type { GoalTodoClaimSettlementRecord, GoalTodoClaimValidationRecord, GoalTodoDelegationAttemptRecord, GoalTodoReturnedClaim } from "../core/claims.js"; import type { GoalMutationReceipt } from "../core/cas.js"; export declare const GOAL_STREAM_SCHEMA = "pi-goals.goal.v1"; export declare const TODOS_STREAM_SCHEMA = "pi-goals.todos.v1"; export declare const CLAIMS_STREAM_SCHEMA = "pi-goals.claims.v1"; export declare const RECEIPT_STREAM_SCHEMA = "pi-goals.receipt.v1"; export declare const PI_GOAL_STREAM_SCHEMAS: readonly string[]; export declare const GOAL_ID_PATTERN: RegExp; export declare function isCanonicalGoalId(value: unknown): value is string; export type PiGoalStatus = "active" | "ready_for_oracle" | "oracle_failed" | "paused" | "blocked" | "budget_limited" | "complete"; export declare const PI_GOAL_STATUSES: readonly PiGoalStatus[]; /** Persisted goal record (Phase 4 runtime owns transitions; the store owns shape). */ export interface GoalRecord { goalId: string; objective: string; status: PiGoalStatus; /** Embedded stream revision; must equal the envelope revision (restore-checked). */ revision: number; createdAt: number; updatedAt: number; } /** Tree policy mirrored from core (pure data; core stays unimported for policy logic). */ export interface TodoTreePolicyRecord { maxDepth: number; maxFanout: number; maxBatch: number; } export interface GoalSetEventData { goal: GoalRecord; } export interface GoalClearEventData { goalId: string; } export interface StreamBaselineEventData { snapshotFile: string; } export interface GoalSetEvent { schema: typeof GOAL_STREAM_SCHEMA; kind: "goal_set"; revision: number; at: number; data: GoalSetEventData; } export interface GoalClearEvent { schema: typeof GOAL_STREAM_SCHEMA; kind: "goal_clear"; revision: number; at: number; data: GoalClearEventData; } export interface GoalBaselineEvent { schema: typeof GOAL_STREAM_SCHEMA; kind: "baseline"; revision: number; at: number; data: StreamBaselineEventData; } export type GoalStreamEvent = GoalSetEvent | GoalClearEvent | GoalBaselineEvent; /** Write-side appends never emit baseline markers; compaction owns those. */ export type GoalStreamAppendEvent = GoalSetEvent | GoalClearEvent; export interface TodosSnapshotEventData { goalId: string; nodes: GoalTodoNode[]; policy?: TodoTreePolicyRecord; } export interface TodoNodeEventData { goalId: string; node: GoalTodoNode; } export interface TodoRemovedEventData { goalId: string; todoId: string; } export interface TodosClearedEventData { goalId: string; } export interface TodosSnapshotEvent { schema: typeof TODOS_STREAM_SCHEMA; kind: "todos_snapshot"; revision: number; at: number; data: TodosSnapshotEventData; } export interface TodoAddedEvent { schema: typeof TODOS_STREAM_SCHEMA; kind: "todo_added"; revision: number; at: number; data: TodoNodeEventData; } export interface TodoUpdatedEvent { schema: typeof TODOS_STREAM_SCHEMA; kind: "todo_updated"; revision: number; at: number; data: TodoNodeEventData; } export interface TodoRemovedEvent { schema: typeof TODOS_STREAM_SCHEMA; kind: "todo_removed"; revision: number; at: number; data: TodoRemovedEventData; } export interface TodosClearedEvent { schema: typeof TODOS_STREAM_SCHEMA; kind: "todos_cleared"; revision: number; at: number; data: TodosClearedEventData; } export interface TodosBaselineEvent { schema: typeof TODOS_STREAM_SCHEMA; kind: "baseline"; revision: number; at: number; data: StreamBaselineEventData; } export type TodosStreamEvent = TodosSnapshotEvent | TodoAddedEvent | TodoUpdatedEvent | TodoRemovedEvent | TodosClearedEvent | TodosBaselineEvent; export type TodosStreamAppendEvent = Exclude; export interface ClaimsAttemptEventData { goalId: string; attempt: GoalTodoDelegationAttemptRecord; } export interface ClaimReturnedEventData { goalId: string; claim: GoalTodoReturnedClaim; } export interface ClaimValidatedEventData { goalId: string; validation: GoalTodoClaimValidationRecord; } export interface ClaimSettlementEventData { goalId: string; settlement: GoalTodoClaimSettlementRecord; } export interface ClaimsDelegationAttemptLaunchedEvent { schema: typeof CLAIMS_STREAM_SCHEMA; kind: "delegation_attempt_launched"; at: number; data: ClaimsAttemptEventData; } export interface ClaimReturnedEvent { schema: typeof CLAIMS_STREAM_SCHEMA; kind: "claim_returned"; at: number; data: ClaimReturnedEventData; } export interface ClaimValidatedEvent { schema: typeof CLAIMS_STREAM_SCHEMA; kind: "claim_validated"; at: number; data: ClaimValidatedEventData; } export interface ClaimAcceptedEvent { schema: typeof CLAIMS_STREAM_SCHEMA; kind: "claim_accepted"; at: number; data: ClaimSettlementEventData; } export interface ClaimRejectedEvent { schema: typeof CLAIMS_STREAM_SCHEMA; kind: "claim_rejected"; at: number; data: ClaimSettlementEventData; } export interface ClaimsBaselineEvent { schema: typeof CLAIMS_STREAM_SCHEMA; kind: "baseline"; at: number; data: StreamBaselineEventData; } export type ClaimsStreamEvent = ClaimsDelegationAttemptLaunchedEvent | ClaimReturnedEvent | ClaimValidatedEvent | ClaimAcceptedEvent | ClaimRejectedEvent | ClaimsBaselineEvent; export type ClaimsStreamAppendEvent = Exclude; export interface MutationReceiptEventData { receipt: GoalMutationReceipt; } export interface MutationReceiptEvent { schema: typeof RECEIPT_STREAM_SCHEMA; kind: "mutation_receipt"; at: number; data: MutationReceiptEventData; } export type ReceiptStreamEvent = MutationReceiptEvent; export type StreamEventParseCode = "unknown_schema" | "malformed_event"; export interface StreamEventParseFailure { ok: false; code: StreamEventParseCode; message: string; } export type ParsedStreamEvent = { stream: "goal"; event: GoalStreamEvent; } | { stream: "todos"; event: TodosStreamEvent; } | { stream: "claims"; event: ClaimsStreamEvent; } | { stream: "receipts"; event: ReceiptStreamEvent; }; export type StreamEventParseResult = { ok: true; parsed: ParsedStreamEvent; } | StreamEventParseFailure; export declare function parseGoalRecord(value: unknown): GoalRecord | undefined; export declare function parseGoalTodoNodeRecord(value: unknown): GoalTodoNode | undefined; export declare function parseTodoTreePolicyRecord(value: unknown): TodoTreePolicyRecord | undefined; export declare function parseDelegationAttemptRecord(value: unknown): GoalTodoDelegationAttemptRecord | undefined; export declare function parseReturnedClaimRecord(value: unknown): GoalTodoReturnedClaim | undefined; /** * Canonical claim-validation record parser. * * BUG-1 fix: optional provenance keys `agent`/`runId` (metadata-safe, * length-capped) are accepted — v0.1.x lines without them keep parsing. * BUG-4 fix: the canonical shape persists blocking issues HASH-ONLY * (blockingIssuesHash + blockingIssuesCount); legacy v0.1.x cleartext * `blockingIssues` lines still parse and convert to the hash+count form. */ export declare function parseClaimValidationRecord(value: unknown): GoalTodoClaimValidationRecord | undefined; export declare function parseClaimSettlementRecord(value: unknown): GoalTodoClaimSettlementRecord | undefined; export declare function parseMutationReceiptRecord(value: unknown): GoalMutationReceipt | undefined; export declare function parseGoalStreamEvent(value: unknown): StreamEventParseResult; export declare function parseTodosStreamEvent(value: unknown): StreamEventParseResult; export declare function parseClaimsStreamEvent(value: unknown): StreamEventParseResult; export declare function parseReceiptStreamEvent(value: unknown): StreamEventParseResult; /** Dispatch on the schema field: unknown schemas fail with `unknown_schema` (R1). */ export declare function parseStreamLine(value: unknown): StreamEventParseResult; /** Deterministic single-line JSON with a fixed canonical key order. */ export declare function serializeStreamEvent(event: GoalStreamEvent | TodosStreamEvent | ClaimsStreamEvent | ReceiptStreamEvent): string;