harn-stdlib 0.8.39

Embedded Harn standard library source catalog
Documentation
/*
 * std/corrections - Replay-for-teaching correction records.
 *
 * Import with: `import "std/corrections"`.
 */
import "std/triggers"

type CorrectionId = string

type CorrectionScope = "this_run" | "this_persona" | "all"

type CorrectionDecision = {
  actor_id?: string,
  actor?: string,
  agent?: string,
  action?: string,
  event_kind?: string,
  outcome?: string,
  reason?: string,
  metadata?: dict,
  raw?: dict,
}

type CorrectionEvidenceRef = {
  kind: string,
  event_id?: string,
  trace_id?: string,
  uri?: string,
  path?: string,
  line?: int,
  summary?: string,
  raw?: dict,
}

type CorrectionRecord = {
  schema: string,
  correction_id: string,
  from_decision: CorrectionDecision,
  to_decision: CorrectionDecision,
  reason: string,
  applied_by: string,
  scope: CorrectionScope,
  timestamp: string,
  actor_id: string?,
  action: string?,
  trace_id: string?,
  step: string?,
  evidence_refs: list<CorrectionEvidenceRef>,
  metadata: dict,
}

type CorrectionInput = {
  from_decision: CorrectionDecision,
  to_decision: CorrectionDecision,
  reason: string,
  applied_by: string,
  scope?: CorrectionScope,
  actor_id?: string,
  actor?: string,
  agent?: string,
  action?: string,
  trace_id?: string,
  step?: string,
  evidence_refs?: list<CorrectionEvidenceRef>,
  metadata?: dict,
}

type CorrectionQueryFilters = {
  actor?: string,
  actor_id?: string,
  agent?: string,
  action?: string,
  scope?: CorrectionScope,
  since?: string,
  until?: string,
  limit?: int,
}

/**
 * record appends a typed replay correction and returns its CorrectionId.
 *
 * @effects: []
 * @allocation: heap
 * @errors: []
 * @api_stability: stable
 * @example: record(correction)
 */
pub fn record(correction: CorrectionInput) -> CorrectionId {
  return corrections.record(correction)
}

/**
 * query returns recorded replay corrections.
 *
 * @effects: []
 * @allocation: heap
 * @errors: []
 * @api_stability: stable
 * @example: query(filters)
 */
pub fn query(filters: CorrectionQueryFilters = {}) -> list<CorrectionRecord> {
  return corrections.query(filters)
}