import { useState } from "preact/hooks"; import { DAY, MIN, STATS } from "../app/config.ts"; import { copyText, setAge } from "../app/debug.ts"; import { writeDiary } from "../app/diary.ts"; import { editState, petEngine } from "../app/engine.ts"; import { age, dayNum, worldState } from "../app/simulation.ts"; import { brain, store, ui, view } from "../app/store.ts"; import { header, offerThing, stageAges, wakeChance } from "../core.ts"; import type { Disturbance } from "../types.ts"; import { canRunLocally, isRemote } from "../app/hosting.ts"; export function Debug() { const s = store.state, pet = s.pet; const [days, setDays] = useState(() => (age() / DAY).toFixed(2)); const n = petEngine().disturbancesAt(Date.now()) + 1; return (
{isRemote() && (

This is the server's last synchronized state. Switch to local mode to use body debug controls.

)}

Pet

{pet ? ( <>

{`brain ${brain.id || "none"} · ${pet.stage}, day ${dayNum()} (${(age() / DAY).toFixed(2)} days old) · offer open: ${s.offer ? offerThing(s.offer) : "none"}`}

{stageAges() .reverse() .map(([stage, ms]) => ( ))}
setDays(e.currentTarget.value)} />
{STATS.map((k) => (
{ const value = +e.currentTarget.value; editState((state) => { state.stats[k] = value; }); }} /> {Math.round(s.stats[k])}
))}

{`${s.asleep ? "Asleep" : "Awake"} · next disturbance #${n}: `} {(["talk", "touch", "light"] as Disturbance[]) .map((k) => `${k} ${Math.round(wakeChance(s.stats.energy, k, n) * 100)}%`) .join(" · ")}

Write today's page using the log so far, even if it is short. An early page skips bedtime writing; rewrite it later to include new events.

) : (

No pet yet.

)}

Context

The last prompts sent to the brain, newest first; what it wrote is highlighted. Only kept until the page reloads.

{ui.debugLog .slice() .reverse() .map((d) => (
{`${d.at.toLocaleTimeString()} · ${d.mode} · ${d.promptTokens} prompt tokens · stopped: ${d.reason}`}
              {d.prompt}
              {d.text}
            
))}
); }