Reintent

How sure is sure enough

A World turns System One's weights into one value, and says what to do when they are not clear enough.

System One answers with weights; the card shows one tone. After “It is for a formal family dinner.” formal leads warm 0.60 to 0.30. That may be enough for Sam's quick draft, and too little for the card the whole family reads, so each needs its own rule.

You will learn

  • How minMargin says how far the likeliest must lead
  • How the same card gets different rules from the <World> around it
  • Each way to go on when the lead is short: 'fallback', a person, steps, 'forward'
  • How each choice says who is asked about it

The margin

The same card twice, under two rules:

/** @jsxImportSource @reintent/core */
import { choices, host, useChoose, World } from '@reintent/core';

export type Person = { to: string; age: number; from: string };
export const TONES = ['warm', 'funny', 'formal'] as const;
export type Tone = (typeof TONES)[number];

export const GRANDMA: Person = { to: 'Grandma', age: 90, from: 'Sam' };

export const LOOK: Record<Tone, { background: string; accent: string }> = {
  warm: { background: '#fdebd3', accent: '#b5562b' },
  funny: { background: '#fff2a8', accent: '#7a4fd6' },
  formal: { background: '#f1eee8', accent: '#2b2b2b' },
};

export function title(p: Person, tone: Tone) {
  if (tone === 'formal') return `Many happy returns, ${p.to}.`;
  if (tone === 'warm') return `Happy ${p.age}th birthday, ${p.to}!`;
  return `${p.age} laps around the sun, ${p.to}!`;
}

export function useTone() {
  return useChoose(choices<Tone>(...TONES), {
    of: 'card',
    name: 'tone',
    defaultValue: 'warm',
    question: 'Which tone suits a birthday card for Grandma, turning 90?',
    ask: ['model', 'human'],
  });
}

/** A small card, with a label: the policy it is under. */
export function Card({ label }: { label: string }) {
  const tone = useTone();
  return host('div', {
    style: {
      padding: 12,
      borderRadius: 10,
      background: LOOK[tone].background,
      color: '#3a2a1c',
      fontSize: 13,
    },
    children: [
      host('small', { children: label }),
      host('h3', { style: { color: LOOK[tone].accent, margin: '4px 0 0' }, children: title(GRANDMA, tone) }),
    ],
  });
}

export default function App() {
  return host('div', {
    style: { display: 'grid', gap: 8 },
    children: [
      // The card Sam sends: System One's tone only when it leads the next by 0.5.
      <World minMargin={0.5}>
        <Card label="the card · minMargin 0.5" />
      </World>,
      // Sam's quick draft: any lead will do.
      <World minMargin={0}>
        <Card label="the draft · minMargin 0" />
      </World>,
    ],
  });
}
ChoicesC

Starting…

Realizationλ

Starting…

What happened

Nothing logged.

<World minMargin> is a handler: the likeliest possibility is taken when it leads the next by at least minMargin. With nothing said, warm leads by 0.65, and both cards are warm. Say “It is for a formal family dinner.”: formal leads by 0.30. The draft (minMargin={0}) turns formal; the card (minMargin={0.5}) stays warm and waits for you: Choices marks its tone asks you. Card itself has no say in how sure is sure enough. The rule lives in the handler around it, so one component can sit under different rules.

With no <World> around it, a choice has the root's rule: minMargin: 0.2, and a choice that is not sure enough takes its default. That is the rule of Quick start's steps 4 to 7.

When the lead is short: onUnresolved

The same margin, 0.5, with two ways to go on when the lead falls short:

/** @jsxImportSource @reintent/core */
import { choices, host, useChoose, World } from '@reintent/core';

export type Person = { to: string; age: number; from: string };
export const TONES = ['warm', 'funny', 'formal'] as const;
export type Tone = (typeof TONES)[number];

export const GRANDMA: Person = { to: 'Grandma', age: 90, from: 'Sam' };

export const LOOK: Record<Tone, { background: string; accent: string }> = {
  warm: { background: '#fdebd3', accent: '#b5562b' },
  funny: { background: '#fff2a8', accent: '#7a4fd6' },
  formal: { background: '#f1eee8', accent: '#2b2b2b' },
};

export function title(p: Person, tone: Tone) {
  if (tone === 'formal') return `Many happy returns, ${p.to}.`;
  if (tone === 'warm') return `Happy ${p.age}th birthday, ${p.to}!`;
  return `${p.age} laps around the sun, ${p.to}!`;
}

export function useTone(ask: readonly ('model' | 'human')[]) {
  return useChoose(choices<Tone>(...TONES), {
    of: 'card',
    name: 'tone',
    defaultValue: 'warm',
    question: 'Which tone suits a birthday card for Grandma, turning 90?',
    ask,
  });
}

/** A small card, with a label: what it does when System One is not sure enough. */
export function Card({ label, ask = ['model'] }: { label: string; ask?: readonly ('model' | 'human')[] }) {
  const tone = useTone(ask);
  return host('div', {
    style: {
      padding: 12,
      borderRadius: 10,
      background: LOOK[tone].background,
      color: '#3a2a1c',
      fontSize: 13,
    },
    children: [
      host('small', { children: label }),
      host('h3', { style: { color: LOOK[tone].accent, margin: '4px 0 0' }, children: title(GRANDMA, tone) }),
    ],
  });
}

export default function App() {
  // One margin, 0.5; two ways to go on when System One does not reach it.
  return host('div', {
    style: { display: 'grid', gap: 8 },
    children: [
      <World minMargin={0.5} onUnresolved="fallback">
        <Card label='onUnresolved="fallback"' />
      </World>,
      <World minMargin={0.5}>
        <Card label="ask: ['model', 'human']" ask={['model', 'human']} />
      </World>,
    ],
  });
}
ChoicesC

Starting…

Realizationλ

Starting…

What happened

Nothing logged.

Say the sentence again. The first card falls back to its defaultValue, warm. The second card's tone asks a person, after System One, and intent.questions() lists it. Every way to go on:

Whatthe card
onUnresolved="fallback"uses defaultValue: warm. A choice with no defaultValue takes the likeliest
ask: ['model', 'human'] on the choiceuses its default meanwhile, and intent.questions() lists it for a person (Asking a person)
onUnresolved={rejudge({ goal })} and moretakes steps, one each time (When no possibility fits)
onUnresolved="forward"goes up to the next <World> out, and from the top to the host (When no possibility fits)

onUnresolved takes one Strategy for every reason, or one per reason: { unsure: 'fallback', none: reprogram({ goal }) }. The Reason is 'unsure' when the lead is short, 'none' when every possibility is ruled out, and 'unmet' when K does not hold what is wanted: a person decided something it does not hold, or (cause: 'judged') System One judged none of it is what was asked for, its share outside K, BEYOND, leading the likeliest possibility by minMargin. A reason the World leaves out is the next World's to say.

A choice's own way

A World covers a subtree, and who is asked is each choice's own. The card asks Sam about its tone, and nobody about the joke:

/** @jsxImportSource @reintent/core */
import { action, choices, createContext, host, useChoose, World, type Id } from '@reintent/core';

export const TONES = ['warm', 'funny', 'formal'] as const;
export type Tone = (typeof TONES)[number];
export const JOKES = ['pun', 'tease'] as const;
export type Joke = (typeof JOKES)[number];
export const TONE: Id = { of: 'card', name: 'tone' };

export const LOOK: Record<Tone, { background: string; accent: string }> = {
  warm: { background: '#fdebd3', accent: '#b5562b' },
  funny: { background: '#fff2a8', accent: '#7a4fd6' },
  formal: { background: '#f1eee8', accent: '#2b2b2b' },
};

export function title(tone: Tone, joke?: Joke) {
  if (tone === 'formal') return 'Many happy returns, Grandma.';
  if (tone === 'warm') return 'Happy 90th birthday, Grandma!';
  return joke === 'tease' ? 'Grandma, you don’t look a day over 89!' : '90 laps around the sun, Grandma!';
}

/** What a button does: the intent gives it to every evaluation (index.intent.tsx). */
export const Decide = createContext<(id: Id, value: string) => void>('Decide', { key: () => undefined });

export function Card() {
  const tone = useChoose(choices<Tone>(...TONES), {
    ...TONE,
    defaultValue: 'warm',
    question: 'Which tone suits a birthday card for Grandma, turning 90?',
    ask: ['model', 'human'],
  });
  // Nobody is asked about the joke: until someone answers, it is a pun.
  const joke =
    tone === 'funny'
      ? useChoose(choices<Joke>(...JOKES), {
          of: 'card',
          name: 'joke',
          defaultValue: 'pun',
        })
      : undefined;
  return host('div', {
    children: [
      host('div', {
        style: {
          maxWidth: 380,
          padding: 24,
          borderRadius: 12,
          background: LOOK[tone].background,
          color: '#3a2a1c',
        },
        children: [
          host('h1', { style: { color: LOOK[tone].accent }, children: title(tone, joke) }),
          host('p', { style: { textAlign: 'right', fontStyle: 'italic' }, children: '— Sam' }),
        ],
      }),
      host('p', {
        children: TONES.map((v) => host('button', { onClick: action.decide(TONE, v), children: v })),
      }),
    ],
  });
}

export default function App() {
  return (
    <World minMargin={0.5}>
      <Card />
    </World>
  );
}
ChoicesC

Starting…

Realizationλ

Starting…

What happened

Nothing logged.

Say “She loves a good joke.”: funny leads warm by 0.33, short of 0.5, so the tone asks. Press funny, and the joke is read. It has no prior, no judgment and no ask, so it is a pun until someone answers, under the same World that has the tone ask. Give it ask: ['human'], and Choices marks the joke asks you as well.

Recap

  • <World minMargin onUnresolved> is a rule for a subtree; with none, it is minMargin: 0.2, and a choice falls back when unsure.
  • The likeliest is taken when it leads the next by at least minMargin.
  • Short of it, onUnresolved decides, by reason: 'fallback', steps, or 'forward'.
  • Who is asked is the choice's ask: System One, then a person.

Last updated on

Edit on GitHub