// data.jsx — Correx scenario fixture
// Session: implementing CAS-based storage for segments (Kafka-style) of domain data.
// The kernel ("Correx") is the orchestration harness; the model is a stateless worker.

const SESSION = {
  id: "01J9-CAS-SEG-7F2A",
  name: "cas-segment-storage",
  project: "correx/segment-store",
  branch: "feat/cas-segments",
  state: "awaiting_approval",
  started: "14:02:11",
  model: "qwen_coder_14b",
  provider: "local",
};

// Stage / transition graph. current = implementation.
const STAGES = [
  { id: "intake",         role: "router",    status: "done",     enter: "14:02", note: "parsed request → plan" },
  { id: "planning",       role: "architect", status: "done",     enter: "14:04", note: "segment layout + CAS index" },
  { id: "implementation", role: "coder",     status: "active",   enter: "14:11", note: "writing SegmentStore.kt" },
  { id: "validation",     role: "reviewer",  status: "pending",  enter: "—",     note: "schema + semantic checks" },
  { id: "integration",    role: "coder",     status: "pending",  enter: "—",     note: "wire into DomainLog" },
  { id: "done",           role: "—",         status: "pending",  enter: "—",     note: "" },
];

const TRANSITIONS = [
  { when: 'artifact.status == "success"', goto: "validation" },
  { when: "retries > 3",                  goto: "failed" },
  { when: 'semantic.contradiction',       goto: "retry" },
];

// Router conversation. The last assistant turn is mid-stream.
const CONVERSATION = [
  { role: "user", t: "14:02", text: "Implement CAS-based storage for segments, Kafka-style. Domain data lands as an append-only log; segments should be content-addressed so dedup is free." },
  { role: "kernel", t: "14:02", kind: "route", text: "Routed → planning (role: architect). Synthesized Context Pack [4 sources, 6.1k tok]." },
  { role: "assistant", t: "14:05", text: "Plan: each segment is an immutable, size-bounded run of records keyed by SHA-256 of its bytes. A SegmentIndex maps logical offset ranges → CAS keys. Compaction rewrites overlapping segments; identical segments collapse to one object. Writing SegmentStore.kt, CasKey.kt, SegmentIndex.kt." },
  { role: "kernel", t: "14:11", kind: "route", text: "Transition planning → implementation (role: coder). Tools: filesystem, git, shell." },
  { role: "assistant", t: "14:12", streaming: true, text: "SegmentStore.append() now hashes the framed buffer with a streaming SHA-256 and writes <key>.seg under .correx/cas/. To pull zstd compression for cold segments I need com.github.luben:zstd-jni — resolving it touches the network, so I've raised a T3 approval before running gradle" },
];

// Live event stream (newest at bottom). category drives color + filter.
const EVENTS = [
  { id: "e41", t: "14:11:02", cat: "Lifecycle",   type: "stage.enter",        text: "implementation (role=coder)" },
  { id: "e42", t: "14:11:02", cat: "Context",     type: "pack.synthesized",   text: "4 sources · 6,120 tok · dedup −38%" },
  { id: "e43", t: "14:11:03", cat: "Inference",   type: "infer.start",        text: "qwen_coder_14b · t=0.2 · ctx 6.1k/32k" },
  { id: "e44", t: "14:11:19", cat: "Tool",        type: "fs.write",           text: "SegmentStore.kt (+212)" },
  { id: "e45", t: "14:11:20", cat: "Tool",        type: "fs.write",           text: "CasKey.kt (+47)" },
  { id: "e46", t: "14:11:24", cat: "Domain",      type: "artifact.partial",   text: "ImplementationArtifact draft" },
  { id: "e47", t: "14:11:31", cat: "Tool",        type: "shell.exec",         text: "./gradlew compileKotlin → OK (3.2s)" },
  { id: "e48", t: "14:11:48", cat: "Inference",   type: "infer.token",        text: "streaming … 1,204 tok" },
  { id: "e49", t: "14:12:02", cat: "Approval",    type: "approval.raised",    text: "T3 · gradle network resolve", pending: true },
];

// Pending approval (modal interrupt).
const APPROVAL = {
  tier: "T3",
  tierLabel: "external / network",
  tool: "shell",
  intent: "Resolve a new dependency over the network",
  command: "./gradlew :segment-store:dependencies --refresh-dependencies",
  detail: "Adds com.github.luben:zstd-jni:1.5.6-3 for cold-segment compression. Touches Maven Central (network egress).",
  reversible: false,
  policy: "stages.implementation.approvals.tool_tier_3 = required",
  risks: [
    "Network egress to repo1.maven.org",
    "Mutates gradle.lockfile",
    "New transitive: org.lz4? (none detected)",
  ],
};

// Context Pack — what the model actually receives. Layered L0..L4.
const CONTEXT_PACK = {
  budget: 32768,
  used: 6120,
  layers: [
    { id: "L0", name: "live execution",      tok: 1840, mode: "verbatim",        items: ["current diff: SegmentStore.kt", "last tool result: compileKotlin OK"] },
    { id: "L1", name: "stage-local",          tok: 1310, mode: "verbatim",        items: ["stage=implementation", "role=coder card", "allowed tools (3)"] },
    { id: "L2", name: "compressed session",   tok: 1490, mode: "semantic_summary", items: ["plan summary", "CasKey design decision", "rejected: per-record hashing"] },
    { id: "L3", name: "project memory",       tok: 980,  mode: "ranked",          items: ["DomainLog.kt interface", "build conventions", "ADR-014 immutability"] },
    { id: "L4", name: "archival",             tok: 500,  mode: "latest_only",     items: ["prior CAS spike (summary)"] },
  ],
  dropped: ["12 stale tool logs (summarized)", "router chit-chat (excluded)", "duplicate file reads (deduped)"],
};

// Model registry.
const MODELS = [
  { id: "qwen_coder_14b", provider: "local",  active: true,  caps: ["coding", "tool_calling", "reasoning"], ctx: 32768, temp: 0.2, gpu: "48 layers · q8_0 kv", status: "warm", parallel: "1/2" },
  { id: "qwen_coder_32b", provider: "local",  active: false, caps: ["coding", "tool_calling", "reasoning"], ctx: 32768, temp: 0.2, gpu: "unloaded", status: "cold", parallel: "0/1" },
  { id: "gpt-oss-120b",   provider: "remote", active: false, caps: ["coding", "reasoning"],                 ctx: 131072, temp: 0.3, gpu: "—", status: "ready", parallel: "0/8" },
  { id: "claude-sonnet",  provider: "remote", active: false, caps: ["coding", "tool_calling", "reasoning"], ctx: 200000, temp: 0.2, gpu: "—", status: "ready", parallel: "0/8" },
];

// Tool palette.
const TOOLS = [
  { id: "filesystem", tier: "T2", enabled: true,  mode: "auto",   desc: "read/write workspace files" },
  { id: "git",        tier: "T2", enabled: true,  mode: "auto",   desc: "stage, commit, branch" },
  { id: "shell",      tier: "T2", enabled: true,  mode: "prompt", desc: "run bounded commands" },
  { id: "gradle",     tier: "T3", enabled: true,  mode: "prompt", desc: "build · may resolve deps (network)" },
  { id: "curl",       tier: "T3", enabled: false, mode: "deny",   desc: "raw network egress" },
  { id: "rm",         tier: "T4", enabled: false, mode: "deny",   desc: "destructive delete" },
];

// Command palette entries — id maps to an overlay/action in app.jsx.
const COMMANDS = [
  { id: "events",   label: "Inspect event stream",      hint: "filter · drill payload", key: "e" },
  { id: "context",  label: "Inspect Context Pack",      hint: "what the model sees",     key: "c" },
  { id: "graph",    label: "Stage / transition graph",  hint: "workflow DAG",            key: "g" },
  { id: "models",   label: "Model registry",            hint: "switch provider/model",   key: "m" },
  { id: "tools",    label: "Tool palette",              hint: "enable · tiers · approvals", key: "t" },
  { id: "approval", label: "Review pending approval",   hint: "T3 gate",                 key: "a" },
  { id: "appearance", label: "Cycle aesthetic direction", hint: "Boxed · Soft · Bare",   key: "F2" },
];

window.CORREX = { SESSION, STAGES, TRANSITIONS, CONVERSATION, EVENTS, APPROVAL, CONTEXT_PACK, MODELS, TOOLS, COMMANDS };
