What a person says
Decide, forget, undo, rule out, lean and tell, each one a commit in the intent's history.
Sam types “Sign it with hugs.” in the app, and the card signs off with Hugs. A week before the dinner, Sam's father says no jokes, Sam would like the card a little warmer without picking a tone, and Sam's mother asks why the card says Hugs. Each of these is something a person says to the intent, and each needs its own word.
You will learn
- How to decide, keep where a decision came from, forget and undo
- How to commit several words as one step of the history
- How to rule possibilities out and lean toward one, short of deciding
- How to say something about the whole card, and where every word is kept
A decision and where it came from
Sam's app reads the sentence with a rule of its own, and decides the sign-off:
/** @jsxImportSource @reintent/core */
import { action, choices, host, useChoose, type Id } from '@reintent/core';
export const SIGNOFFS = ['With love', 'Hugs'] as const;
export type Signoff = (typeof SIGNOFFS)[number];
export const SIGNOFF: Id = { of: 'card', name: 'signoff' };
/** What Sam's app does for the card: the intent gives it to every evaluation (index.intent.tsx). */
export default function App() {
const signoff = useChoose(choices<Signoff>(...SIGNOFFS), { ...SIGNOFF, defaultValue: 'With love' });
return host('div', {
children: [
host('div', {
style: { maxWidth: 380, padding: 24, borderRadius: 12, background: '#fdebd3', color: '#3a2a1c' },
children: [
host('h1', { style: { color: '#b5562b' }, children: 'Happy 90th birthday, Grandma!' }),
host('p', { children: 'Wishing you a wonderful day.' }),
host('p', { style: { textAlign: 'right', fontStyle: 'italic' }, children: `${signoff}, Sam` }),
],
}),
host('p', {
children: [
...SIGNOFFS.map((v) =>
host('button', { disabled: v === signoff, onClick: action.decide(SIGNOFF, v), children: v }),
),
host('button', {
onClick: { event: 'say', args: ['Sign it with hugs.'] },
style: { marginLeft: 12, fontStyle: 'italic' },
children: '“Sign it with hugs.”',
}),
],
}),
],
});
}
Starting…
Starting…
Nothing logged.
intent.decide(id, value) writes a person's decision, the top layer (Who answers a choice). Its third argument can say where the decision came from: said is the sentence, kept word for word, and via is the Actor who read it as this decision: 'code', 'model' or 'human', the same words as ask. ACTORS lists the three, and actorOf(source) says which one wrote a value read from a layer: a decision is Human's, a belief a Model's, a prior Code's. Together they are a DecisionOrigin. note is the line the history keeps for the commit.
The read of the choice gives the origin back as origin, and undo brings it back with the decision. Press With love, and the button's decision carries no origin. The origin changes nothing in the card. It is kept for whoever asks why.
Undo, redo and starting over
Every word a person says is a commit, and intent.history walks them:
/** @jsxImportSource @reintent/core */
import { action, choices, createContext, host, useChoose, type Id } 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}!`;
}
/** What the buttons do: the intent gives them to every evaluation (index.intent.tsx). */
export const Decide = createContext<(id: Id, value: unknown) => void>('Decide', { key: () => undefined });
export const Forget = createContext<(id: Id) => void>('Forget', { key: () => undefined });
export function useTone() {
return useChoose(choices<Tone>(...TONES), { of: 'card', name: 'tone', defaultValue: 'warm' });
}
export function Card({ p, tone }: { p: Person; tone: Tone }) {
return 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(p, tone) }),
host('p', { children: 'Wishing you a wonderful day.' }),
host('p', { style: { textAlign: 'right', fontStyle: 'italic' }, children: `— ${p.from}` }),
],
});
}
export function Buttons({ tone }: { tone: Tone }) {
const id = { of: 'card', name: 'tone' };
return host('p', {
children: [
...TONES.map((v) =>
host('button', { disabled: v === tone, onClick: action.decide(id, v), children: v }),
),
host('button', {
onClick: action.forget(id),
style: { marginLeft: 12, borderStyle: 'dashed', background: 'transparent', fontStyle: 'italic' },
children: 'no preference',
}),
],
});
}
export default function App() {
const tone = useTone();
return host('div', { children: [<Card p={GRANDMA} tone={tone} />, <Buttons tone={tone} />] });
}
Starting…
Starting…
Nothing logged.
intent.history.undo() and intent.history.redo() move one commit at a time, and canUndo and canRedo say whether there is one to move to. entries lists the commits so far, oldest first, each a Commit with its note, and the state a person committed before and after it (a read-only Committed). reset() goes back to before the first commit and empties the history, so there is nothing to redo either. The panel's undo and redo buttons call the same methods.
no preference calls intent.forget(id), which takes the decision back. Forgetting is a commit too, and undo brings the decision back.
Several things, one step
A joke card makes the tone funny and the joke a tease, and one undo should take back both:
/** @jsxImportSource @reintent/core */
import { action, choices, host, useChoose, 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 JOKE: Id = { of: 'card', name: 'joke' };
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 Sam's app does for the card: the intent gives it to every evaluation (index.intent.tsx). */
export default function App() {
const tone = useChoose(choices<Tone>(...TONES), { ...TONE, defaultValue: 'warm' });
// A question only a funny card has.
const joke =
tone === 'funny' ? useChoose(choices<Joke>(...JOKES), { ...JOKE, defaultValue: 'pun' }) : undefined;
const row = <T extends string>(id: Id, values: readonly T[], now: T) =>
host('p', {
children: values.map((v) =>
host('button', { disabled: v === now, onClick: action.decide(id, v), children: v }),
),
});
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' }),
],
}),
row(TONE, TONES, tone),
joke && row(JOKE, JOKES, joke),
host('p', {
children: [host('button', { onClick: { event: 'jokeCard', args: [] }, children: 'A joke card' })],
}),
],
});
}
Starting…
Starting…
Nothing logged.
intent.commit(note, (tx) => …) writes everything inside as one commit, here two decisions under the note 'A joke card'. The tx it gives is a Tx, with a method for every word: decide, forget, constrain, unconstrain, prefer, unprefer, tell and untell. intent.decide and the others on the intent are each a commit of one word.
Ruling out
Grandma loves a good joke, so System One leans funny. Sam's father says no jokes at this dinner, and Sam still does not know between warm and formal. Say “She loves a good joke.” in the panel, then press Not funny:
/** @jsxImportSource @reintent/core */
import {
action,
choices,
createContext,
host,
useChoiceStatus,
type Constraint,
type Id,
} from '@reintent/core';
export const TONES = ['warm', 'funny', 'formal'] as const;
export type Tone = (typeof TONES)[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) {
if (tone === 'formal') return 'Many happy returns, Grandma.';
if (tone === 'warm') return 'Happy 90th birthday, Grandma!';
return '90 laps around the sun, Grandma!';
}
export function Card({ tone }: { tone: Tone }) {
return 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) }),
host('p', { children: 'Wishing you a wonderful day.' }),
host('p', { style: { textAlign: 'right', fontStyle: 'italic' }, children: '— Sam' }),
],
});
}
/** What Sam's app does for the card: the intent gives it to every evaluation (index.intent.tsx). */
export const Actions = createContext<{
decide: (id: Id, value: string) => void;
constrain: (id: Id, c: Constraint) => void;
unconstrain: (id: Id) => void;
}>('Actions', { key: () => undefined });
export default function App() {
const tone = useChoiceStatus(choices<Tone>(...TONES), {
...TONE,
defaultValue: 'warm',
question: 'Which tone suits a birthday card for Grandma, turning 90?',
ask: ['model'],
});
return host('div', {
children: [
<Card tone={tone.value} />,
host('p', {
children: [
...TONES.map((v) =>
host('button', {
disabled: tone.source === 'decision' && v === tone.value,
onClick: action.decide(TONE, v),
children: v,
}),
),
host('small', { style: { marginLeft: 12 }, children: `from: ${tone.source}` }),
],
}),
// What Sam rules out, short of choosing.
host('p', {
children: [
host('button', { onClick: action.constrain(TONE, { not: ['funny'] }), children: 'Not funny' }),
host('button', { onClick: action.constrain(TONE, { only: ['formal'] }), children: 'Only formal' }),
host('button', {
onClick: action.unconstrain(TONE),
style: { marginLeft: 12, borderStyle: 'dashed', fontStyle: 'italic' },
children: 'Any tone',
}),
],
}),
],
});
}
Starting…
Starting…
Nothing logged.
intent.constrain(id, { not: ['funny'] }) rules funny out. System One's answer stays as it was, and the constraint takes funny out of it: warm 0.30 and formal 0.07 become 0.81 and 0.19, so the card is warm, still from System One's belief. Another not adds to the ones before. { only: ['formal'] } keeps only what it lists. Press Only formal: one possibility is left, and that settles it as a person's word, with the source 'constraint' and the status 'decided'. Both forms are a Constraint.
Any tone calls intent.unconstrain(id), which takes back every constraint on the choice.
The first argument is a Target: an identity { of, name } for one choice, or { name } alone for every choice with that name, on this card and on any other. A choice's own decision is above its name's constraints.
The later word counts
Rule funny out, then press funny: the decision clears the constraint it contradicts. Decide funny, then rule it out, and the constraint clears the decision.
When nothing is left
Rule out all three tones, and no possibility is left for any policy to take. The card uses its default, and the choice is unresolved with reason: 'none', which goes to the host unless a <World> around it says otherwise (When no possibility fits).
Leaning
After “It is for a formal family dinner.” System One judges formal, 0.60 to warm 0.30. Sam would like the card a little warmer, and would go along with formal if System One were sure. Say the sentence in the panel, then press A bit warmer:
/** @jsxImportSource @reintent/core */
import { action, choices, host, useChoiceStatus, type Id } from '@reintent/core';
export const TONES = ['warm', 'funny', 'formal'] as const;
export type Tone = (typeof TONES)[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) {
if (tone === 'formal') return 'Many happy returns, Grandma.';
if (tone === 'warm') return 'Happy 90th birthday, Grandma!';
return '90 laps around the sun, Grandma!';
}
export function Card({ tone }: { tone: Tone }) {
return 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) }),
host('p', { children: 'Wishing you a wonderful day.' }),
host('p', { style: { textAlign: 'right', fontStyle: 'italic' }, children: '— Sam' }),
],
});
}
/** What Sam's app does for the card: the intent gives it to every evaluation (index.intent.tsx). */
export default function App() {
const tone = useChoiceStatus(choices<Tone>(...TONES), {
...TONE,
defaultValue: 'warm',
question: 'Which tone suits a birthday card for Grandma, turning 90?',
ask: ['model'],
});
// How Sam leans, short of choosing.
return host('div', {
children: [
<Card tone={tone.value} />,
host('p', {
children: [
host('button', { onClick: action.prefer(TONE, 'warm'), children: 'A bit warmer' }),
host('button', { onClick: action.prefer(TONE, 'funny'), children: 'A bit funnier' }),
host('button', {
onClick: { event: 'unprefer', args: [TONE] },
style: { marginLeft: 12, borderStyle: 'dashed', fontStyle: 'italic' },
children: 'No lean',
}),
host('small', { style: { marginLeft: 12 }, children: `from: ${tone.source}, ${tone.status}` }),
],
}),
],
});
}
Starting…
Starting…
Nothing logged.
intent.prefer(id, 'warm') multiplies warm's weight by 6, or by the factor given as the third argument, and the weights are normalized again. Warm becomes 0.72 and formal 0.24, so warm leads by enough and the card is warm, still from System One's belief. The lean is kept as a Preference, { toward: 'warm', factor: 6 }. Leaning toward the same possibility again replaces its factor, and leaning toward another adds a second lean.
A lean only moves weights. Press No lean, take the sentence back, and press A bit funnier: funny becomes 0.51 and warm 0.46, neither leads by 0.2, and the card shows its default. When Sam knows the answer, a decision says it. On a choice with no prior and no judgment, though, a lean alone can settle it, with the source 'preference'.
The intent has no unprefer of its own. No lean commits it: intent.commit('no lean', (tx) => tx.unprefer(id)).
Something about the whole card
Quick start tells System One about the occasion with intent.tell. Sam's card says one sentence at a time, and takes it back:
/** @jsxImportSource @reintent/core */
import { choices, host, useChoose, type Id } from '@reintent/core';
export const TONES = ['warm', 'funny', 'formal'] as const;
export type Tone = (typeof TONES)[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) {
if (tone === 'formal') return 'Many happy returns, Grandma.';
if (tone === 'warm') return 'Happy 90th birthday, Grandma!';
return '90 laps around the sun, Grandma!';
}
export function Card({ tone }: { tone: Tone }) {
return 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) }),
host('p', { children: 'Wishing you a wonderful day.' }),
host('p', { style: { textAlign: 'right', fontStyle: 'italic' }, children: '— Sam' }),
],
});
}
export const SENTENCES = ['She loves a good joke.', 'It is for a formal family dinner.'];
/** What Sam's app does for the card: the intent gives it to every evaluation (index.intent.tsx). */
export default function App() {
const tone = useChoose(choices<Tone>(...TONES), {
...TONE,
defaultValue: 'warm',
question: 'Which tone suits a birthday card for Grandma, turning 90?',
ask: ['model'],
});
// What Sam says about the occasion: one sentence at a time.
return host('div', {
children: [
<Card tone={tone} />,
host('p', {
children: [
...SENTENCES.map((s) =>
host('button', { onClick: { event: 'say', args: [s] }, children: `“${s}”` }),
),
host('button', {
onClick: { event: 'unsay', args: [] },
style: { marginLeft: 12, borderStyle: 'dashed', fontStyle: 'italic' },
children: 'Take it back',
}),
],
}),
],
});
}
Starting…
Starting…
Nothing logged.
intent.tell(sentence) says something about the whole program, so every judgment reads it (Asking System One). intent.untell(sentence) takes it back, and System One's earlier answer holds again. A new sentence replaces the old one in a single commit, tx.untell the old and tx.tell the new, so one undo brings the old sentence back.
Where the words are kept
Everything said about the choices is one value, intent.layers, a Layers:
/** @jsxImportSource @reintent/core */
import {
action,
choices,
createContext,
host,
useChoiceStatus,
type Constraint,
type Id,
} from '@reintent/core';
export const TONES = ['warm', 'funny', 'formal'] as const;
export type Tone = (typeof TONES)[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) {
if (tone === 'formal') return 'Many happy returns, Grandma.';
if (tone === 'warm') return 'Happy 90th birthday, Grandma!';
return '90 laps around the sun, Grandma!';
}
export function Card({ tone }: { tone: Tone }) {
return 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) }),
host('p', { children: 'Wishing you a wonderful day.' }),
host('p', { style: { textAlign: 'right', fontStyle: 'italic' }, children: '— Sam' }),
],
});
}
/** What Sam's app does for the card: the intent gives it to every evaluation (index.intent.tsx). */
export const Actions = createContext<{
decide: (id: Id, value: string) => void;
constrain: (id: Id, c: Constraint) => void;
unconstrain: (id: Id) => void;
}>('Actions', { key: () => undefined });
export default function App() {
const tone = useChoiceStatus(choices<Tone>(...TONES), {
...TONE,
defaultValue: 'warm',
question: 'Which tone suits a birthday card for Grandma, turning 90?',
ask: ['model'],
});
return host('div', {
children: [
<Card tone={tone.value} />,
host('p', {
children: [
...TONES.map((v) =>
host('button', {
disabled: tone.source === 'decision' && v === tone.value,
onClick: action.decide(TONE, v),
children: v,
}),
),
host('small', { style: { marginLeft: 12 }, children: `from: ${tone.source}` }),
],
}),
// What Sam rules out, short of choosing.
host('p', {
children: [
host('button', { onClick: action.constrain(TONE, { not: ['funny'] }), children: 'Not funny' }),
host('button', { onClick: action.constrain(TONE, { only: ['formal'] }), children: 'Only formal' }),
host('button', {
onClick: action.unconstrain(TONE),
style: { marginLeft: 12, borderStyle: 'dashed', fontStyle: 'italic' },
children: 'Any tone',
}),
],
}),
],
});
}
Starting…
Starting…
Nothing logged.
layers.choices['card#tone'] holds what was said of the tone: its decision with its origin, its constraints and preferences, and System One's beliefs, each answer kept with the inputs it was given for. layers.named.tone holds the words about every choice named tone, here a lean toward warm. layers.facts holds the sentences told.
intent.history.reset() takes back everything people said, an accepted reprogram included, and keeps System One's answers. To keep the layers between visits, see Saving and restoring.
Recap
intent.decide(id, value, { said, via, note })decides and keeps where the decision came from;intent.forgettakes it back.intent.historyundoes, redoes, lists the commits and starts over.intent.commit(note, (tx) => …)writes several words as one step.intent.constrain(target, { not } | { only })rules possibilities out;intent.unconstraintakes the constraints back.intent.prefer(target, toward, factor?)leans; it only moves weights.intent.tellandintent.untellsay and take back something about the whole card.intent.layersholds every word, by choice, by name and for the whole.
Last updated on
Edit on GitHub