Reintent

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 inspection gathers what an intent holds into one object
  • How useSyncExternalStore on intent.store keeps a React panel up to date
  • How readOf finds one choice, and how at and contexts pick 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: λ, as intent.store.getSnapshot gives it;
  • reads: one per choice read, in order, each a ChoiceView, the read with its distribution dist from intent.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 a RequestView, and pending, the ones not completed, running or failed;
  • facts, history (the commit notes, oldest first), canUndo, canRedo, and the program's revision and version.

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; at and contexts pick the context to read in and the ones to ask in.

Last updated on

Edit on GitHub