A panel on the intent
Show what the intent holds in one snapshot, the choices with their weights, the decisions, the questions and the model calls.
Sam's app has a side panel next to the card. It shows the tone with System One's weights, what Sam decided, what is still worth asking, the model calls on their way, and the history. The panel renders often, and each render should read the intent once, without asking any model.
You will learn
- How
inspectiongathers what an intent holds into one object - How
useSyncExternalStoreonintent.storekeeps a React panel up to date - How
readOffinds one choice, and howatandcontextspick where to look
One snapshot
The panel:
import { useSyncExternalStore } from 'react';
import { inspection, readOf } from '@reintent/lib/inspect';
import { card } from './card.intent';
import { intent } from './store';
function Panel() {
const now = useSyncExternalStore(intent.store.subscribe, () => inspection(intent));
const tone = readOf(now, card.tone());
return (
<aside>
<p>
Tone: {String(tone?.value)} {JSON.stringify(tone?.dist)}
</p>
<p>Decided: {now.decided.join(', ') || 'nothing'}</p>
<p>Questions: {now.questions.length}</p>
<p>Waiting for a model: {now.pending.length}</p>
<ol>
{now.history.map((note, i) => (
<li key={i}>{note}</li>
))}
</ol>
</aside>
);
}inspection(intent, opts) returns an Inspection:
realization: λ, asintent.store.getSnapshotgives it;reads: one per choice read, in order, each aChoiceView, the read with its distributiondistfromintent.explain;decided: the keys Sam decided;questions: what to ask Sam where the answer changes the card, worked out with no new judge calls;requests: every model call, each aRequestView, andpending, the ones not completed, running or failed;facts,history(the commit notes, oldest first),canUndo,canRedo, and the program'srevisionandversion.
Nothing is sent. The object stays the same until the intent changes: a decision, a model's answer, a new program, a call that failed. That makes inspection(intent) the snapshot React's useSyncExternalStore reads from intent.store, which renders the panel again only when the object changes. It is not a selector for useReintent: a call that failed changes it and leaves the intent's state as it was. A view, a debugging panel or a DevTools extension can call it on every render.
readOf(now, card.tone()) finds one choice in reads by its identity. A handle such as card.tone() is one.
Where to look
On the dinner tablet the card reads the Screen context (Along an axis). The panel for that screen passes it:
const tablet = useSyncExternalStore(intent.store.subscribe, () =>
inspection(intent, { at: [[Screen, { id: 'tablet', width: 1024 }]] }),
);InspectOptions has at, the context to read in, and contexts, the contexts questions are asked in (default [at]). A panel for every screen passes them all in contexts, and a question that matters on any screen is listed. The context is matched by its values, so the snapshot written inline above still gets the same object on the next render.
Recap
inspection(intent)gathers λ, the reads with their weights, the decisions, the questions, the model calls and the history, and sends nothing.- It is the same object until the intent changes, so
useSyncExternalStore(intent.store.subscribe, () => inspection(intent))keeps a panel up to date. readOf(now, id)finds one choice;atandcontextspick the context to read in and the ones to ask in.
Last updated on
Edit on GitHub