Greeting Card
The whole Loop. The card from the Quick Start, finished. Code, System One, System Two and a person each write part of it.
What it shows
The whole Loop in one small app. A birthday card where the code gives the defaults, System One judges the tone, System Two writes the words, and a person decides, previews the alternatives and approves any reprogramming of the card itself. It is the Quick Start's last step, as one app; the Quick Start builds it up one step at a time.
| You will see | What does it |
|---|---|
| The tone is picked for you, and changes when you tell it the occasion | System One: question, ask, sentences told with intent.tell |
| When System One is not sure, the card asks you | <World minMargin={0.5}>, ask: ['model', 'human'] |
| The message inside is written for each tone and joke | System Two: useGenerate, kept for its uses |
| Only a funny card asks which joke | A choice read only on the branch that needs it |
| The other tones, drawn small beside the card | <World as>: previews that write nothing |
| Make it a card the whole family signs, then Accept or Reject | intent.reprogram, review(p).accept(): the program is reprogrammed only with a person's yes |
| The card is a React component; the buttons above it are the app's own | reintentView, the root's input, useReintent in its children |
Learn more: Quick start, Making choices, Generating, Reprogramming, Showing an intent.
Where it fits: generative UI and content apps where a model drafts and a person decides; personalization that stays editable; apps whose very structure can be reprogrammed on request, behind a review.
Make the card
Grandma turns 90. System One picks a tone; tell it She loves a good joke. and it judges again. Press a tone to decide it yourself, or no preference to hand it back. When none of the tones will do, ask System Two for a card the whole family signs, and accept or reject what it writes.
/** @jsxImportSource @reintent/dom */
import { action, choices, useChoiceStatus, useGenerate, World, type Content } from '@reintent/core';
/** Who the card is for, and from: the root's input, the props App.tsx gives it. */
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 JOKES = ['pun', 'tease'] as const;
export type Joke = (typeof JOKES)[number];
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, joke?: Joke) {
if (tone === 'formal') return `Many happy returns, ${p.to}.`;
if (tone === 'warm') return `Happy ${p.age}th birthday, ${p.to}!`;
return joke === 'tease'
? `${p.to}, you don’t look a day over ${p.age - 1}!`
: `${p.age} laps around the sun, ${p.to}!`;
}
/** What Sam asked for, in Sam's words: the question about the tone carries it to System One. */
export const SAID = 'A birthday card for Grandma. She’s turning 90.';
/** The card's tone, and which layer it came from: System One weighs it; a person's decision is above its judgment. */
export function useToneStatus() {
return useChoiceStatus(choices<Tone>(...TONES), {
of: 'card',
name: 'tone',
defaultValue: 'warm',
question: `Sam asked: “${SAID}” Which tone suits the card?`,
ask: ['model', 'human'],
});
}
export function useTone() {
return useToneStatus().value;
}
/** Which joke: a question only a funny card has. */
export function useJokeStatus(tone: Tone) {
return tone === 'funny'
? useChoiceStatus(choices<Joke>(...JOKES), {
of: 'card',
name: 'joke',
defaultValue: 'pun',
ask: ['human'],
})
: undefined;
}
export function useJoke(tone: Tone) {
return useJokeStatus(tone)?.value;
}
export function Front(p: Person) {
const tone = useTone();
const joke = useJoke(tone);
// The words nobody listed: System Two writes them, once for each set of inputs.
const message = useGenerate<string>({
of: 'card',
name: 'message',
instruction:
'Write the message inside a birthday card: two short sentences in this tone, no greeting and no signature.',
uses: { to: p.to, age: p.age, tone, joke },
});
return (
<div
style={{
maxWidth: 380,
padding: '1.5em',
borderRadius: 12,
background: LOOK[tone].background,
color: '#3a2a1c',
}}
>
<h1 style={{ color: LOOK[tone].accent }}>{title(p, tone, joke)}</h1>
<p>{message.value ?? '…'}</p>
<p style={{ textAlign: 'right', fontStyle: 'italic' }}>— {p.from}</p>
</div>
);
}
export function Buttons() {
const tone = useToneStatus();
const joke = useJokeStatus(tone.value);
const row = <T extends string>(name: string, values: readonly T[], now: { value: T; source: string }) => (
<div className="card-row">
{values.map((v) => (
// A person's decision is pressed; a value the card took on its own is only marked.
<button
key={v}
disabled={now.source === 'decision' && v === now.value}
className={now.source !== 'decision' && v === now.value ? 'card-marked' : undefined}
onClick={action.decide({ of: 'card', name }, v)}
>
{v}
</button>
))}
{/* The person's way of not deciding: forget the decision, and the card picks again. */}
<button
className="card-none"
disabled={now.source !== 'decision'}
onClick={action.forget({ of: 'card', name })}
>
no preference
</button>
</div>
);
// Left to a person and not answered yet: the card asks.
const asking = tone.status === 'unresolved';
return (
<div className="card-buttons">
{asking && <p className="card-asking">Not sure which tone suits her. Which would you like?</p>}
{row('tone', TONES, tone)}
{joke && row('joke', JOKES, joke)}
</div>
);
}
/** The card as each other tone would make it: previews write nothing and decide nothing. */
export function Others(p: Person) {
const tone = useTone();
return (
<div className="card-others">
{TONES.filter((t) => t !== tone).map((t) => (
<World key={t} as={{ 'card#tone': t }}>
<Front {...p} />
</World>
))}
</div>
);
}
/** The card Sam makes, for whoever the props say: a function of its input. */
export default function Card(p: Person & { children?: Content }) {
// Take System One's judgment only when it leads the next by 0.5; otherwise, ask.
return (
<World minMargin={0.5}>
<div className="card-app">
{/* Whatever the app puts in the card's children: Sam's own controls. */}
{p.children}
{/* The card and its previews scroll between the app's bars; the buttons stay below. */}
<div className="card-body">
<Front {...p} />
<Others {...p} />
</div>
<Buttons />
</div>
</World>
);
}
Starting…
Starting…
Nothing logged.
Why Reintent
The card is one intent program. Each open question in it is a choice with an identity, and each answer is kept in the layer of whoever gave it: the code's default, System One's belief, a person's decision. System Two writes values nobody listed, and when asked, a new program; it replaces the old one only after a person accepts it, and the choices already made carry over. Every answer of the models here is recorded, so the page calls no model.
Last updated on
Edit on GitHub