Reintent

Autopilot

A self-driving car plans a trip. The code times each road, System One reads the radio and the passenger, the car asks when the reports disagree, and one Go makes the plan the passenger's. A fictional simulation.

What it shows

Who decides the route, layer by layer, until it is real. A self-driving car takes its passenger to the airport. The code times each road from its length and speed, and its prior favours the fastest. System One reads what the code cannot: the radio's reports and what the passenger says. When the reports disagree and System One is not sure enough, the car asks the passenger, who can override it at any time. Until Go, every road and departure time is a hypothesis the map can show without deciding anything; Go writes the plan as the passenger's decision in one step, and the trip is real.

Why this scenario. There is no answer key: the right road depends on whether the passenger is in a hurry and wants to see the sea, which only they know. The passenger answers for the outcome, since it is their trip and their flight. The model adds what code can't, reading a police report against a listener's call-in. Its uncertainty is real, so asking is natural. And it ends in something that happens: the car leaves. The car plans only at the level of the trip, which road and when to leave; it never steers or sets the speed, where asking a model or a person each moment would be far too slow.

A fictional simulation

The town, its roads, the radio and the car are made up and drawn by the example. This is not a navigation system, and nothing here is a statement about the safety of real vehicles.

You will seeWhat does it
At first the A1 glows, prior, 72% on its bubblechoices with weights from each road's time: the code's prior
The radio's signs pulse while System One… reads themuseChoiceStatus with a question, and uses for the times and reports
The two A1 reports disagree: every road turns grey, the bubbles ring amber, Which way?, Go is off<World minMargin={0.45}> and ask: ['model', 'human']; intent.questions() lists it
Say you'd love to see the sea: Shore Road glows, beliefWhat was said is part of every judgment's inputs
Tap a road, a bubble or a name: decision; Auto gives it backintent.decide and intent.forget, above every other layer
Each grey bubble's weight<World each={ROUTE}>: a possible world per road, with its probability
Hover a road or Later: a dashed route and card, the 17:50 radio, the fogintent.preview: nothing decided, nothing to undo
Go: the route and departure become yours, the car drives; one Undo takes it backOne intent.commit that decides the route, the departure and the phase, whichever layer led

Learn more: The code's expectation: a prior, Asking System One, What was said, The margin, What to ask, A decision and where it came from, Several things, one step, Every possible card, A possible card from code.

Where it fits: planning that a person answers for and a model can read for, a step above any control loop: travel and logistics (which route, when to leave, which carrier), dispatch, scheduling, choosing between plans whose inputs are partly written in prose.

Plan a trip

The car leaves home at 17:20. For a moment it plans with the code alone, then System One reads the radio: a police report says a lorry has overturned on the A1, a listener says it is moving freely. System One leans to the A1, but not by enough, so the car asks. Say “I’m not in a hurry, and I’d love to see the sea.”: System One is sure now, and Shore Road glows. Hover Later to see the trip at 17:50, when the A1 has reopened and fog has come in from the sea. Then press Go.

/** @jsxImportSource ./drive */
import { choices, useChoose, useChoiceStatus, World, type HostNode, type Realization } from '@reintent/core';
import { LEAVES, PHASES, ROUTES, type Leg, type Report, type Trip } from './catalog';

export { LEAVES, PHASES, ROUTES, type Leg, type Report, type Trip };
export type Route = (typeof ROUTES)[number];
export type Leave = (typeof LEAVES)[number];

export const ROUTE = { of: 'trip', name: 'route' };
export const LEAVE = { of: 'trip', name: 'leave' };
export const PHASE = { of: 'trip', name: 'phase' };

/** Each road's length and average speed: all the code knows about it. */
export const ROADS: Record<Route, { km: number; kmh: number }> = {
  motorway: { km: 40, kmh: 80 },
  city: { km: 22, kmh: 32 },
  coast: { km: 38, kmh: 45 },
};
export const minutesOf = (r: Route) => Math.round((ROADS[r].km / ROADS[r].kmh) * 60);

/** When the car leaves, in minutes after midnight. */
export const DEPARTS: Record<Leave, number> = { now: 17 * 60 + 20, later: 17 * 60 + 50 };
export const clock = (m: number) => `${Math.floor(m / 60)}:${String(m % 60).padStart(2, '0')}`;

/** What the radio says about the roads, by when the car leaves: sentences the code cannot read. */
export const RADIO: Record<Leave, Report[]> = {
  now: [
    {
      road: 'motorway',
      at: 0.42,
      kind: 'crash',
      time: '17:08',
      text: 'Police: a lorry has overturned on the A1 northbound at junction 7; one lane is closed, with long delays.',
    },
    {
      road: 'motorway',
      at: 0.6,
      kind: 'clear',
      time: '17:14',
      text: 'A listener calls in: the A1 northbound is moving freely past junction 7.',
    },
    {
      road: 'city',
      at: 0.45,
      kind: 'works',
      time: '17:05',
      text: 'Roadworks on Harbour Street: temporary lights, short queues.',
    },
    {
      road: 'coast',
      at: 0.68,
      kind: 'sun',
      time: '17:10',
      text: 'Shore Road is clear; sunset over the bay at 18:05.',
    },
  ],
  later: [
    {
      road: 'motorway',
      at: 0.42,
      kind: 'clear',
      time: '17:41',
      text: 'The A1 northbound has fully reopened; traffic is normal.',
    },
    {
      road: 'city',
      at: 0.45,
      kind: 'works',
      time: '17:05',
      text: 'Roadworks on Harbour Street: temporary lights, short queues.',
    },
    {
      road: 'coast',
      at: 0.68,
      kind: 'fog',
      time: '17:44',
      text: 'Sea fog on Shore Road; visibility under 100 metres.',
    },
  ],
};

/** What System One is asked. */
export const PLANNER =
  'A self-driving car takes its passenger from home to the airport. Which route should it take? The minutes are the code’s estimate from each road’s length and speed; the radio reports are what has been said about each road, with the time.';

/** What the passenger can say, one sentence at a time (prompts.json, App.tsx). */
export const SAYINGS = [
  'I’m not in a hurry, and I’d love to see the sea.',
  'My flight boards at 18:40.',
] as const;

/** The code's prior: the faster a road usually is, the likelier. */
const PRIOR = (() => {
  const w = ROUTES.map((r) => Math.exp(-minutesOf(r) / 9));
  const total = w.reduce((a, b) => a + b, 0);
  return choices<Route>(
    ROUTES.map((value, i) => ({ value, weight: Math.round((w[i] / total) * 100) / 100 })),
  );
})();

/** The route: the code's prior, System One reading the radio and the passenger, the passenger's decision. */
export function useRoute(leave: Leave) {
  return useChoiceStatus(PRIOR, {
    ...ROUTE,
    defaultValue: 'motorway',
    question: PLANNER,
    // System One first; when it is not sure enough, the passenger is asked.
    ask: ['model', 'human'],
    uses: {
      departs: clock(DEPARTS[leave]),
      routes: Object.fromEntries(
        ROUTES.map((r) => [
          r,
          {
            minutes: minutesOf(r),
            radio: RADIO[leave].filter((x) => x.road === r).map((x) => `${x.time} ${x.text}`),
          },
        ]),
      ),
    },
  });
}

/** One road, as a possible world takes it. */
function Way(p: { leave: Leave }) {
  return <leg route={useRoute(p.leave).value} />;
}

function Plan() {
  // Leaving now is likelier; the passenger can choose later.
  const leave = useChoiceStatus(
    choices<Leave>([
      { value: 'now', weight: 0.8 },
      { value: 'later', weight: 0.2 },
    ]),
    { ...LEAVE, defaultValue: 'now' },
  );
  const route = useRoute(leave.value);
  // Until the passenger says go, everything is a plan.
  const phase = useChoose(choices(...PHASES), { ...PHASE, defaultValue: 'planning' });
  const departs = DEPARTS[leave.value];
  const legs: Leg[] = ROUTES.map((r) => ({
    route: r,
    km: ROADS[r].km,
    minutes: minutesOf(r),
    arrives: clock(departs + minutesOf(r)),
  }));
  return (
    <trip
      route={route.value}
      source={route.source}
      stale={!!route.stale}
      leave={leave.value}
      leaveSource={leave.source}
      departs={clock(departs)}
      phase={phase}
      legs={legs}
      radio={RADIO[leave.value]}
    >
      {/* The roads side by side: one possible world each, with its weight. Nothing is decided. */}
      <World each={ROUTE}>
        <Way leave={leave.value} />
      </World>
    </trip>
  );
}

/** The trip in a realization: the root's first node. */
const tripNode = (r: Realization) => (r.tree as HostNode).children[0] as HostNode;
export const tripOf = (r: Realization) => tripNode(r).props as Trip;
/** The weight of each road, from the possible worlds beside the trip: empty while one is decided. */
export const weightsOf = (r: Realization): Partial<Record<Route, number>> => {
  const worlds = tripNode(r).children[0] as HostNode;
  const each = worlds.children as HostNode[];
  if (each.length < 2) return {};
  return Object.fromEntries(
    each.map((w) => [((w.children[0] as HostNode).props as { route: Route }).route, w.props.p as number]),
  );
};

/** The trip the car plans. It plans the trip, never the steering or the speed. */
export default function App() {
  // System One's route when it leads the next by 0.45; otherwise, the passenger's to answer.
  return (
    <World minMargin={0.45}>
      <div>
        <Plan />
      </div>
    </World>
  );
}
ChoicesC

Starting…

Realizationλ

Starting…

What happened

Nothing logged.

Four writers of one route

The route is one choice, trip#route, and four writers can answer it:

  • The code. ROADS gives each road a length and a speed, and the prior weighs each road by its time: the A1 30 minutes, Harbour Street 41, Shore Road 51, so 0.72, 0.21 and 0.07. With no model, the A1 is taken, from prior.
  • System One. The choice has a question, and uses carries what it reads: when the car leaves, each road's minutes, and the radio's reports with their times. What the passenger said reaches it too. Its weights are a belief, kept for exactly those inputs: leaving later, or saying something else, asks again, and going back finds the earlier answer. The app's model answers after 0.9 seconds, so you can watch the car think.
  • The passenger, when System One isn't sure. <World minMargin={0.45}> takes System One's answer only when it leads by 0.45. At 17:20 it gives the A1 0.6 and the others 0.2, so the choice is unresolved, and ask: ['model', 'human'] makes it a question for the passenger. The app asks intent.questions(), greys every road and turns off Go until the passenger picks one.
  • The passenger, at any time. A tap is intent.decide, a decision above every other layer, and Auto forgets it.

Before anything is sent

Around the trip, <World each={ROUTE}> evaluates the route once per road: λ holds a worlds node with a world for each, its at the road it assumes and its p the road's probability. The bubbles' percentages are those ps, the code's or System One's. A decided route is not enumerated, so the node holds one world whose at is {}: the catalog's world kind makes the trip#route key optional, or the frame would be refused. The entry checks the frame after Go with checkFrame.

Hovering a road, a bubble or a departure time calls intent.preview({ 'trip#route': … }) or intent.preview({ 'trip#leave': 'later' }): the trip as it would be, drawn dashed, with that time's radio on the map. A preview asks nobody, so a preview of 17:50 shows the code's choice until the passenger has chosen to leave then and System One has read that radio. Nothing is written, and Undo has nothing to take back.

Go

Go is one intent.commit that decides the route, the departure and trip#phase as driving. It writes the route that is showing, whichever layer it came from: the code's, System One's or the passenger's. From then on the plan does not move when the radio or the passenger changes their mind, the car drives the route, and the card says decision. One Undo takes back all three.

Why Reintent

The difference from a navigation app is that the route here has several writers, and each one's answer stays visible as its own layer. Code supplies what can be computed, System One what has to be read, and the passenger what only they know, and the passenger is asked only when the others can't settle it. Hypotheses stay apart from reality until a person makes them real.

The realization is data: a trip node with every road's time and the radio, beside the possible worlds of its route, in the example's own catalog. The map, the car and the card are drawn by the React host in App.tsx with SVG, with no map tiles and no outside images.

This example follows design notes 0005 (choices and previews), 0012 (sandbox) and 0062 §6. The editable entry checks the code's prior, the question, the weights, a preview, the passenger's sentence, an override, Go and the frame after it. System One's answers are recorded, so the page calls no model.

Last updated on

Edit on GitHub