@ai-matrx/content-ir-react 0.25.2 → 0.25.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["../directives.ts","../directives/directive-host.tsx","../directives/registry.ts","../directives/ApplyDirectiveButton.tsx","../directives/item-changes.ts","../directives/record-values.ts","../directives/failure-words.ts","../directives/icons.tsx","../directives/SideEffectDirectiveCard.tsx","../directives/DirectiveFallbackCard.tsx","../directives/DirectiveProvisionalCard.tsx","../directives/DirectiveRender.tsx"],"sourcesContent":["/**\n * `@ai-matrx/content-ir-react/directives` — the Kind Directives render tier:\n * the host seams (`DirectiveHostProvider`), the renderer registry with THE\n * PREFIX TIER, the side-effect card, the fallback floor, the Apply control, and\n * `DirectiveRender` — THE renderer every UI draws a directive through. Client\n * entry (stamped \"use client\").\n */\nexport * from \"./directives/directive-host\";\nexport * from \"./directives/registry\";\nexport * from \"./directives/ApplyDirectiveButton\";\nexport * from \"./directives/SideEffectDirectiveCard\";\nexport * from \"./directives/DirectiveFallbackCard\";\nexport * from \"./directives/DirectiveProvisionalCard\";\nexport * from \"./directives/DirectiveRender\";\nexport * from \"./directives/item-changes\";\nexport * from \"./directives/failure-words\";\nexport * from \"./directives/record-values\";\n","\"use client\";\n\n/**\n * THE DIRECTIVE HOST CONTRACT — what the directive tier refuses to decide.\n *\n * The package owns the DECISIONS (decode → renderer → card → floor, the\n * position law, never-null rendering) and the card itself. Four things stay\n * host property and enter through named seams:\n *\n * 1. APPLYING a side-effect directive — `POST /directives/confirm` as the\n * user, with the host's auth and base URL. Absent → the Apply control is\n * ABSENT (honest), never a dead button.\n * 2. OPENING an item to read it before approving — a window panel, a dialog,\n * a route. Absent → items are not clickable.\n * 3. COPY controls — host chrome (matrx-frontend's CopyButtons). Absent → none.\n * 4. The NOUN catalog + item-kind lookup — server-derived tables the host\n * mirrors (or reads from its kind catalog's `items` edges).\n * 5. ASKING (`ask`), NAMING a record (`renderRecord`), and READING the ledger\n * (`applyState`) — the consequence before the click, the doors, and the\n * state that survives a reload.\n *\n * A host that has adopted `ContentIrRenderProvider` passes `directives` on its\n * ContentIrHost; a host that has NOT (Workflow Studio, 2026-09-08) mounts\n * `DirectiveHostProvider` alone — the directive tier never requires the full\n * render host, because a chat bubble must be able to draw a directive card\n * identically everywhere, today.\n */\n\nimport { createContext, useContext, type ReactNode } from \"react\";\nimport type {\n DecodedDirective,\n DirectiveItemKindLookup,\n DirectiveNounCatalog,\n} from \"@ai-matrx/content-ir\";\n\nexport interface DirectiveApplyResult {\n applied: number;\n failed: number;\n /**\n * The server's own receipt sentence (\"Deleted task “Ship it”.\"), shown in\n * place of a bare count. Never composed client-side.\n */\n message?: string | null;\n /**\n * The records the apply created or changed, so the tally is a way IN to them\n * (no dead ends). Rendered through `renderRecord`; absent → the sentence alone.\n */\n records?: DirectiveRecordRef[];\n /**\n * For an UPDATE: what each item's fields held just BEFORE the write, by item\n * index (`null` for an item the server did not record). The card draws the\n * applied change from this record — never from a live re-read, which after the\n * apply answers the NEW value (G6A review, 2026-10-02: \"(no change)\" for a\n * change that happened).\n */\n before?: ReadonlyArray<Record<string, unknown> | null>;\n}\n\n/**\n * What the server's action ledger says about ONE block, read on mount so a\n * reloaded page never offers \"Apply\" for work that already ran (reviewer\n * defect 5, 2026-10-02).\n *\n * - `not_applied` — still to do (or partly done: the batch re-applies, and the\n * server replays the members it already holds). The card offers Apply.\n * - `in_flight` — another request is applying it right now. The card says it\n * is finishing and asks again shortly; it offers neither Apply nor a tally.\n * - `applied` — the ledger holds every item. The card shows the tally exactly\n * as a fresh apply would: the ledger's own sentence and the records, as doors.\n */\nexport interface DirectiveApplyState {\n state: \"not_applied\" | \"in_flight\" | \"applied\";\n /** The ledger row's sentence (\"Created task.\"), never composed client-side. */\n message?: string | null;\n /**\n * The records the LATEST apply wrote — the tally's doors. After \"Run again\"\n * that is the newest copy, never the first.\n */\n records?: DirectiveRecordRef[];\n /**\n * How many times the ledger holds this block as applied: 1 for the original,\n * one more for every \"Run again\". Absent → 1. A create that ran twice made\n * two records, and the card says so (reviewer, 2026-10-02).\n */\n copies?: number;\n /**\n * For an applied UPDATE: each item's replaced values, by item index, from the\n * ledger row (`null` where the ledger has none — a row from before 2026-10-02).\n * Absent → the card says only what each field was set to.\n */\n before?: ReadonlyArray<Record<string, unknown> | null>;\n}\n\n/** One record a directive names: the noun it is, and its id. */\nexport interface DirectiveRecordRef {\n noun: string;\n id: string;\n}\n\nexport interface DirectiveRecordProps extends DirectiveRecordRef {\n /**\n * What to show until (or unless) the host resolves the live name —\n * \"Task 1a2b3c4d\". Never blank, never \"Item\".\n */\n fallback: string;\n /** Where it is drawn: an item row, the confirm dialog, or the applied tally. */\n context: \"row\" | \"dialog\" | \"applied\";\n /**\n * True when the record is (about to be) in the trash — the host may still\n * name it but should not promise it opens as a live record.\n */\n trashed?: boolean;\n}\n\n/** What the person is being asked to approve — everything the card knows. */\nexport interface DirectiveAskRequest {\n directive: DecodedDirective;\n /** The items, exactly as they will be sent. */\n items: Record<string, unknown>[];\n /** The noun's human label (\"Task\"), from the host's catalog when it has one. */\n nounLabel: string;\n /**\n * True for \"Run again\": the ledger already holds this block, and a yes runs\n * it a SECOND time (`force`) — another copy for a create, the same fields\n * written again for an update, another delete for a restored record. The\n * question must say so.\n */\n again?: boolean;\n}\n\n/**\n * The shell a card hands its host — the two keys, plus WHERE it sits.\n *\n * `conversationId` is the conversation the card renders in (a chat message),\n * absent in a person's own content (a note). It is the idempotency NAMESPACE:\n * a card in an agent's message must apply under the SAME key as that\n * proposal's Approve button, or the one action could run twice.\n */\nexport interface DirectiveShell {\n __kind: string;\n items: Record<string, unknown>[];\n conversationId?: string;\n /** \"Run again\": skip the ledger's dedup and apply a second time. */\n force?: boolean;\n}\n\nexport interface DirectiveOpenItemOptions {\n /** The item, `__kind`-stamped when the shape has an item kind. */\n item: Record<string, unknown>;\n /** The content-IR kind this item IS, or null when the shape has none. */\n itemKind: string | null;\n /** What the item is called — the same title the card shows. */\n title: string;\n /** \"Run Create agent definition · item 1 of 1\". */\n subtitle: string | null;\n directive: DecodedDirective;\n index: number;\n total: number;\n}\n\nexport interface DirectiveCopyProps {\n /**\n * What the control is called to a screen reader. Never an id: for a record it\n * is type-generic (\"this task\"); a host with the record's live name replaces\n * it through `record`.\n */\n label: string;\n /** The existing record this control copies, when it copies one — to name it. */\n record?: DirectiveRecordRef;\n /** The value to copy — the whole shell or one item. */\n value: unknown;\n /** The item's kind, when copying an item. */\n kind?: string | null;\n size: \"icon\" | \"xs\";\n}\n\nexport interface DirectiveHost {\n /**\n * Apply a side-effect directive as the user (the server re-validates every\n * item against the registered model and runs the ONE handler; idempotent).\n * Reject with an Error whose message is safe to show.\n */\n confirm?: (shell: DirectiveShell) => Promise<DirectiveApplyResult>;\n /**\n * Ask the person BEFORE anything runs, naming the consequence (the records,\n * what changes). Resolve `true` to go ahead, `false` to leave the card as it\n * was. The Apply control stays idle while this is open — nothing reads as\n * \"applying\" until the person has said yes. Absent → `confirm` is called\n * directly (a host that asks inside `confirm` keeps working, but its card\n * will read \"Applying…\" while its dialog is up).\n */\n ask?: (request: DirectiveAskRequest) => Promise<boolean>;\n /**\n * Has this exact block already been applied? Read ONCE when the card mounts\n * (and again while the answer is `in_flight`), so the card survives a reload:\n * the server ledger, not component state, is what knows. The identity is the\n * server's (it hashes the validated items in the same namespace `confirm`\n * applies in), so a host asks — it never computes. Batch on the host side if\n * a page carries many cards. Reject with an Error when the ledger cannot be\n * read: the card reports it and offers Apply, which is safe because `confirm`\n * is idempotent. Absent → the card starts at Apply, as before.\n */\n applyState?: (shell: DirectiveShell) => Promise<DirectiveApplyState>;\n /**\n * Read the CURRENT values of ONE existing record, so an update says what it\n * replaces — \"Status open → done\", never just \"→ done\" (reviewer,\n * 2026-10-02). Resolve `null` when the record cannot be read (no access, no\n * such record, a noun the host cannot read); reject only for a real failure.\n * Absent → an update row shows the new values alone, as before.\n */\n readRecord?: (ref: DirectiveRecordRef) => Promise<Record<string, unknown> | null>;\n /**\n * Draw ONE existing record by its live name, as a way to open it. Used on\n * update/delete rows (the record that will change), in the host's own ask\n * dialog if it likes, and on the applied tally (what was written). Absent →\n * the fallback text, unlinked.\n */\n renderRecord?: (props: DirectiveRecordProps) => ReactNode;\n /** Open ONE item to read it properly before approving the write. */\n openItem?: (options: DirectiveOpenItemOptions) => void;\n /** Host copy controls. */\n renderCopy?: (props: DirectiveCopyProps) => ReactNode;\n /**\n * The app's word for one stored value of one pick-list field — the SAME word\n * the record's own screens and the write forms show (\"incomplete\" on a task\n * reads \"Inbox\"). One value, one display word everywhere (G8A review,\n * 2026-10-02: the card said \"Status incomplete → completed\"). Return null for\n * a field that is not a pick-list: its value is shown as written. Absent →\n * every value is shown as stored.\n */\n valueLabel?: (ref: DirectiveValueRef) => string | null;\n /** The mirrored noun catalog (label / family / title column). */\n nouns?: DirectiveNounCatalog;\n /** slug → the kind ONE item is (THE DIRECTIVE⇄KIND SEAM), or null. */\n itemKind?: DirectiveItemKindLookup;\n /** Where a decode failure or an unhonourable shell is reported. Default: console.error. */\n reportError?: (message: string) => void;\n /**\n * Plain words for a failed apply the host recognises (\"This button can't\n * create a task yet.\" + \"Create it from Tasks instead.\"). The card never shows\n * the server's raw text as its sentence: it shows these words — or its own\n * verb-aware default — and keeps the raw text behind \"Details\". Return null\n * to use the default.\n */\n explainFailure?: (failure: DirectiveFailure) => DirectiveFailureWords | null;\n}\n\n/** One stored value of one field of one record type. */\nexport interface DirectiveValueRef {\n noun: string;\n field: string;\n value: string;\n}\n\n/** One failed apply, as the card knows it. */\nexport interface DirectiveFailure {\n /** The server's / host's own text — technical; shown only behind Details. */\n raw: string;\n directiveClass: string;\n noun: string;\n /** The noun's display label (\"Task\"). */\n nounLabel: string;\n /** Items that failed, when some applied and some did not. */\n failed?: number;\n /** Items in the block. */\n total?: number;\n}\n\n/** What failed and what to do — each one short sentence. */\nexport interface DirectiveFailureWords {\n what: string;\n next: string;\n /**\n * The text behind \"Details\", when the host words it (e.g. the server's field\n * names read as the form labels them — \"Title is required\", never\n * \"name is required\"). Absent → the raw text.\n */\n details?: string;\n}\n\nconst DirectiveHostContext = createContext<DirectiveHost | null>(null);\n\n/** Where a directive renders — today, the conversation it sits in (if any). */\nexport interface DirectiveScope {\n conversationId?: string | null;\n}\n\nconst DirectiveScopeContext = createContext<DirectiveScope>({});\n\n/**\n * Tell every card below WHERE it renders. A host draws a chat message's\n * directives inside one of these (or passes `conversationId` to\n * `DirectiveRender`), so the card applies in that conversation's namespace —\n * the same key the agent's proposal approves under. A note mounts none.\n */\nexport function DirectiveScopeProvider({\n conversationId,\n children,\n}: DirectiveScope & { children: ReactNode }) {\n return (\n <DirectiveScopeContext.Provider value={{ conversationId: conversationId ?? null }}>\n {children}\n </DirectiveScopeContext.Provider>\n );\n}\n\nexport function useDirectiveScope(): DirectiveScope {\n return useContext(DirectiveScopeContext);\n}\n\nexport interface DirectiveHostProviderProps {\n host: DirectiveHost;\n children: ReactNode;\n}\n\nexport function DirectiveHostProvider({ host, children }: DirectiveHostProviderProps) {\n return <DirectiveHostContext.Provider value={host}>{children}</DirectiveHostContext.Provider>;\n}\n\nconst EMPTY_HOST: DirectiveHost = {};\n\n/**\n * The wired directive host. Unlike the render host this does NOT throw when\n * unwired: a directive still renders (named, itemised, copy-less, apply-less)\n * — degrading the chrome is honest, hiding the content is not.\n */\nexport function useDirectiveHost(): DirectiveHost {\n return useContext(DirectiveHostContext) ?? EMPTY_HOST;\n}\n","/**\n * Kind Directives — the renderer registry, and THE PREFIX TIER.\n *\n * A directive IS a kind instance, so the renderer for one is resolved from its\n * SLUG, in the same shape the kind component resolver uses:\n *\n * getDirectiveRenderer(directive)\n * → an exact-slug renderer (directive_v1_action_plan_tree)\n * → else the CLASS prefix rule (every directive_v1_reference_*)\n * → else null (DirectiveRender's own tier: the\n * side-effect card, then the floor)\n *\n * THE PREFIX RULE is Arman's routing-language ruling made real: registering\n * `reference` once gives EVERY enrolled noun a renderer for free; a custom\n * renderer for one slug overrides it; a brand-new server noun renders with\n * ZERO client edits. Hosts register their bespoke renderers (reference chips,\n * plan trees) here; the package supplies the side-effect card and the floor.\n */\n\nimport type { ComponentType } from \"react\";\nimport {\n type DecodedDirective,\n type DirectiveClass,\n buildDirectiveSlug,\n} from \"@ai-matrx/content-ir\";\n\nexport interface DirectiveRendererProps {\n /** The decoded two-key shell — slug, class, noun, items, position law. */\n directive: DecodedDirective;\n}\n\nexport type DirectiveRenderer = ComponentType<DirectiveRendererProps>;\n\n// REGISTRY ON A globalThis SLOT — never module-level Maps. With `splitting:\n// false` dual ESM/CJS output this module is duplicated into the root bundle and\n// the `./directives` bundle, and a host registering a renderer through one\n// graph must be visible to a card rendering through the other.\nconst REGISTRY_SLOT = Symbol.for(\"ai-matrx.content-ir-react.directive-renderers\");\ninterface Registry {\n bySlug: Map<string, DirectiveRenderer>;\n byClass: Map<DirectiveClass, DirectiveRenderer>;\n}\ntype RegistryHolder = typeof globalThis & { [REGISTRY_SLOT]?: Registry };\nconst registry: Registry = ((globalThis as RegistryHolder)[REGISTRY_SLOT] ??= {\n bySlug: new Map(),\n byClass: new Map(),\n});\n\n/**\n * Register a renderer for a whole CLASS (the prefix rule), or for one exact\n * `(class, noun)` pair, which wins. `noun` is passed as a noun, never a\n * hand-typed slug: the slug is BUILT by the grammar, so a registration whose\n * slug could not be parsed back is unconstructable rather than unreachable.\n */\nexport function registerDirectiveRenderer(\n directiveClass: DirectiveClass,\n renderer: DirectiveRenderer,\n noun?: string,\n): void {\n if (noun) registry.bySlug.set(buildDirectiveSlug(directiveClass, noun), renderer);\n else registry.byClass.set(directiveClass, renderer);\n}\n\n/** The renderer for a slug: exact → class prefix rule → null. */\nexport function getDirectiveRenderer(\n directive: Pick<DecodedDirective, \"slug\" | \"directiveClass\">,\n): DirectiveRenderer | null {\n return (\n registry.bySlug.get(directive.slug) ?? registry.byClass.get(directive.directiveClass) ?? null\n );\n}\n\n/** Tests only. */\nexport function resetDirectiveRenderers(): void {\n registry.bySlug.clear();\n registry.byClass.clear();\n}\n","\"use client\";\n\n/**\n * \"Apply\" for a side-effect Kind Directive that arrived as CONTENT.\n *\n * THE POSITION RULE, honoured exactly: a directive inside content NEVER\n * auto-executes — that is the guard against untrusted content mutating things.\n * But \"does not auto-execute\" was never \"is inert\": the user seeing it must be\n * able to say yes. This button IS that yes, through the host's `confirm` seam\n * (`POST /directives/confirm`, re-validated server-side, run as the user).\n *\n * No `confirm` seam → NO button. A control that cannot do its job is absent,\n * never dead. Only a side-effect class is applicable at all (`parsed.executes`).\n */\n\nimport { useEffect, useRef, useState, useSyncExternalStore } from \"react\";\nimport { nounLabel, type DecodedDirective } from \"@ai-matrx/content-ir\";\nimport {\n useDirectiveHost,\n useDirectiveScope,\n type DirectiveRecordRef,\n type DirectiveShell,\n} from \"./directive-host\";\nimport { TARGETING_CLASSES, itemRecordId, recordFallbackName } from \"./item-changes\";\nimport { noteRecordChanged } from \"./record-values\";\nimport { failureWords } from \"./failure-words\";\nimport { AlertIcon, CheckCircleIcon, LoaderIcon, PlayIcon, RotateCcwIcon } from \"./icons\";\n\n/** The records an update/delete names — re-read wherever they are shown once it ran. */\nfunction announceChangedRecords(directive: DecodedDirective, items: Record<string, unknown>[]): void {\n if (!TARGETING_CLASSES.has(directive.directiveClass)) return;\n for (const item of items) {\n const id = itemRecordId(item);\n if (id) noteRecordChanged(id);\n }\n}\n\ntype ApplyState =\n // Reading the server ledger on mount: has this block already run? Nothing\n // offers a write until it answers (reviewer defect 5, 2026-10-02).\n | { status: \"checking\" }\n // The ledger has a claim but no result: another request is applying it now.\n | { status: \"finishing\" }\n | { status: \"idle\" }\n // The host's `ask` dialog is up. NOTHING is applying yet, so nothing says so.\n | { status: \"asking\" }\n | { status: \"applying\"; startedAt: number }\n | {\n status: \"applied\";\n applied: number;\n failed: number;\n message: string | null;\n /** The LATEST apply's records — after \"Run again\", the newest copy. */\n records: DirectiveRecordRef[];\n /** How many times this block has applied (1 + every \"Run again\"). */\n copies: number;\n /** An update's replaced values, by item index — the record of the change. */\n before: ReadonlyArray<Record<string, unknown> | null> | null;\n }\n | { status: \"error\"; message: string };\n\n/**\n * 🚨 AN APPLY BELONGS TO THE BLOCK, NOT TO THE COMPONENT (G6A review,\n * 2026-10-02). A note re-renders its blocks while a confirm dialog is open, so\n * the card that asked was unmounted and a fresh one mounted in its place. The\n * apply still ran — but its result was handed to the card that was gone, and\n * the new card, which had read the ledger BEFORE the write landed, offered\n * \"Apply\" for an update that had already run.\n *\n * So once a person says yes, the apply's progress and outcome are kept HERE,\n * per apply authority — the host's `confirm` function, which ran it (a host\n * object may be rebuilt on every render; its `confirm` is the stable seam) — keyed by the block's identity (slug + items + where it renders — the\n * same namespace the ledger keys in), and every card drawing that block shows\n * them, whenever it mounted. Component state keeps only what is the instance's own:\n * the ledger read and the open question.\n */\ntype ApplyOutcome = Extract<ApplyState, { status: \"applying\" | \"applied\" | \"error\" }>;\nconst applyOutcomes = new WeakMap<object, Map<string, ApplyOutcome>>();\n/** The key when a host has no `confirm`: nothing can apply, so nothing is ever held. */\nconst EMPTY_AUTHORITY = {};\nconst outcomeListeners = new Set<() => void>();\n\nfunction outcomesOf(host: object): Map<string, ApplyOutcome> {\n let held = applyOutcomes.get(host);\n if (!held) {\n held = new Map();\n applyOutcomes.set(host, held);\n }\n return held;\n}\n\nfunction publishOutcome(host: object, identity: string, outcome: ApplyOutcome): void {\n outcomesOf(host).set(identity, outcome);\n for (const listener of outcomeListeners) listener();\n}\n\nfunction subscribeOutcomes(listener: () => void): () => void {\n outcomeListeners.add(listener);\n return () => {\n outcomeListeners.delete(listener);\n };\n}\n\n/** The outcome this page holds for a block, or null. */\nfunction useApplyOutcome(host: object, identity: string): ApplyOutcome | null {\n return useSyncExternalStore(\n subscribeOutcomes,\n () => applyOutcomes.get(host)?.get(identity) ?? null,\n () => null,\n );\n}\n\n/** How often a card re-reads a block another request is mid-applying. */\nconst FINISH_POLL_MS = 2_000;\n/** ~1 minute (the server's own claim wait is 45 s), then Apply is offered — idempotent. */\nconst FINISH_POLLS_MAX = 30;\n\n/**\n * What the Apply control knows about its block, for the rest of the card:\n * - `pending` — the ledger has not answered yet;\n * - `open` — nothing applied: rows compare against the record as it is now;\n * - `applied` — the change happened: rows draw it from `before` (the server's\n * record of what it replaced), never from a live re-read, which\n * now holds the NEW value.\n */\nexport type DirectiveApplyPhase =\n | { phase: \"pending\" }\n | { phase: \"open\" }\n | { phase: \"applied\"; before: ReadonlyArray<Record<string, unknown> | null> | null };\n\n/** Does this card read the ledger before offering Apply? (One rule, card and control.) */\nexport function readsApplyLedger(\n host: { applyState?: unknown; confirm?: unknown },\n directive: DecodedDirective,\n): boolean {\n return !!host.applyState && !!host.confirm && directive.parsed.executes && directive.items.length > 0;\n}\n\nexport interface ApplyDirectiveButtonProps {\n directive: DecodedDirective;\n label?: string;\n /** How many things this will write — shown during the wait so a long apply reads as work, not a frozen spinner. */\n itemCount?: number;\n onApplied?: () => void;\n /** Told whenever what the control knows about its block changes. */\n onPhase?: (phase: DirectiveApplyPhase) => void;\n /**\n * The block would change nothing (an update that sets no field). Apply stays\n * — validation offers, never blocks — but muted, with the reason beside it.\n */\n nothingToChange?: boolean;\n}\n\nexport function ApplyDirectiveButton({\n directive,\n label = \"Apply\",\n itemCount,\n onApplied,\n onPhase,\n nothingToChange = false,\n}: ApplyDirectiveButtonProps) {\n const host = useDirectiveHost();\n const scope = useDirectiveScope();\n // WHERE the card sits is the namespace its apply keys in: a chat message's\n // conversation (the SAME key the agent proposal's Approve uses — never two\n // applies of one action), else the person's own content.\n const conversationId = scope.conversationId || undefined;\n const items = directive.items;\n // The ledger read runs only where an apply could: a side effect, a confirm\n // seam, something to write. Everything else starts (and stays) where it was.\n const readsLedger = readsApplyLedger(host, directive);\n const initial: ApplyState = readsLedger ? { status: \"checking\" } : { status: \"idle\" };\n const [state, setState] = useState<ApplyState>(initial);\n const [elapsed, setElapsed] = useState(0);\n // \"Run again\" asks from the tally; the tally stays on screen while it asks\n // (only its own button goes quiet), never swapped for a disabled Apply.\n const [askingAgain, setAskingAgain] = useState(false);\n const startedAt = useRef<number | null>(null);\n\n // 🚨 THE STATE BELONGS TO THE BLOCK, NOT TO THE SLOT (reviewer, 2026-10-02).\n // A host that keys its blocks by POSITION hands this same instance a\n // DIFFERENT directive when a block is inserted above it. The state used to\n // stay: an applied Update card flipped back to \"Apply\" (the instance that\n // had been an idle card now held the Update, and the ledger's \"applied\"\n // answer was ignored because the state was not \"checking\"), and the\n // opposite — one card's tally drawn on another block — was one insert away.\n // When the block this instance draws changes, everything it knew resets and\n // the ledger is asked again about the block it now holds.\n const identity = JSON.stringify([directive.slug, items, conversationId ?? null]);\n const [stateFor, setStateFor] = useState(identity);\n if (stateFor !== identity) {\n setStateFor(identity);\n setState(initial);\n setAskingAgain(false);\n setElapsed(0);\n }\n // What this page knows about the block's apply wins over this instance's own\n // ledger read — except while this instance is asking its own question.\n const shared = useApplyOutcome(host.confirm ?? EMPTY_AUTHORITY, identity);\n const view: ApplyState = state.status === \"asking\" || !shared ? state : shared;\n // An apply that finishes after its block left this slot must not land here.\n const currentIdentity = useRef(identity);\n useEffect(() => {\n currentIdentity.current = identity;\n }, [identity]);\n const nounText = nounLabel(directive.noun, host.nouns);\n\n // THE CARD SURVIVES A RELOAD. Component state dies with the page; the\n // server's action ledger does not. Ask it once on mount — and every\n // FINISH_POLL_MS while another request is mid-apply — and render exactly\n // what a fresh apply would have left on screen.\n const shellKey = readsLedger ? JSON.stringify([directive.slug, items, conversationId ?? null]) : \"\";\n const read = host.applyState;\n const report = host.reportError;\n useEffect(() => {\n if (!shellKey || !read) return;\n // Parsed back from the key so the effect depends on the shell's CONTENT,\n // never on the per-render identity of `directive.items`.\n const [slug, shellItems, inConversation] = JSON.parse(shellKey) as [\n string,\n Record<string, unknown>[],\n string | null,\n ];\n const shell: DirectiveShell = { __kind: slug, items: shellItems };\n if (inConversation) shell.conversationId = inConversation;\n let live = true;\n let polls = 0;\n let timer: ReturnType<typeof setTimeout> | null = null;\n const ask = () => {\n read(shell)\n .then((answer) => {\n if (!live) return;\n if (answer.state === \"applied\") {\n setState((prev) =>\n prev.status === \"checking\" || prev.status === \"finishing\"\n ? {\n status: \"applied\",\n applied: shellItems.length,\n failed: 0,\n message: answer.message?.trim() ? answer.message.trim() : null,\n records: answer.records ?? [],\n copies: Math.max(1, answer.copies ?? 1),\n before: answer.before ?? null,\n }\n : prev,\n );\n } else if (answer.state === \"in_flight\" && polls < FINISH_POLLS_MAX) {\n polls += 1;\n setState((prev) => (prev.status === \"checking\" || prev.status === \"finishing\" ? { status: \"finishing\" } : prev));\n timer = setTimeout(ask, FINISH_POLL_MS);\n } else {\n // Not applied — or still \"in flight\" after a minute, when Apply is\n // the honest offer: confirm is idempotent and replays the receipt.\n setState((prev) => (prev.status === \"checking\" || prev.status === \"finishing\" ? { status: \"idle\" } : prev));\n }\n })\n .catch((error: unknown) => {\n if (!live) return;\n const why = error instanceof Error && error.message ? error.message : String(error);\n (report ?? console.error)(\n `[kind-directives] Could not read whether ${slug} was already applied: ${why}`,\n );\n setState((prev) => (prev.status === \"checking\" || prev.status === \"finishing\" ? { status: \"idle\" } : prev));\n });\n };\n ask();\n return () => {\n live = false;\n if (timer) clearTimeout(timer);\n };\n }, [shellKey, read, report]);\n\n // The rest of the card draws its rows from what this control knows.\n const appliedClean = view.status === \"applied\" && view.failed === 0 ? view : null;\n const appliedBefore = appliedClean ? appliedClean.before : null;\n const phaseKey =\n view.status === \"checking\" || view.status === \"finishing\"\n ? \"pending\"\n : appliedClean\n ? `applied:${JSON.stringify(appliedBefore)}`\n : \"open\";\n useEffect(() => {\n if (!onPhase) return;\n if (phaseKey === \"pending\") onPhase({ phase: \"pending\" });\n else if (phaseKey === \"open\") onPhase({ phase: \"open\" });\n else onPhase({ phase: \"applied\", before: appliedBefore });\n }, [phaseKey, onPhase, appliedBefore]);\n\n // An honest clock beats a fake progress bar — counted from when the apply\n // started, so a card mounted mid-apply shows the true elapsed time.\n const applyingSince = view.status === \"applying\" ? view.startedAt : null;\n useEffect(() => {\n if (applyingSince === null) return;\n startedAt.current = applyingSince;\n const id = setInterval(\n () => setElapsed(Math.round((Date.now() - (startedAt.current ?? 0)) / 1000)),\n 1000,\n );\n return () => clearInterval(id);\n }, [applyingSince]);\n\n if (!directive.parsed.executes) return null;\n const confirm = host.confirm;\n if (!confirm) return null;\n\n /**\n * `again` = \"Run again\": the ledger already holds this block, so a plain\n * confirm would only replay its receipt. The person is asked in words that\n * say it runs a SECOND time, and a yes sends `force`.\n */\n async function handleApply(again = false) {\n if (!confirm) return;\n // A \"no\" to Run again leaves the tally exactly where it was.\n const prior = view;\n const askedFor = identity;\n const stillHere = () => currentIdentity.current === askedFor;\n const priorCopies = view.status === \"applied\" ? view.copies : 0;\n // THE STATUS TELLS THE TRUTH (reviewer, 2026-09-30): the card used to read\n // \"Applying 1 item…\" while the confirm dialog was still asking. Ask first,\n // idle; only a yes moves the control to \"applying\".\n if (host.ask) {\n if (again) setAskingAgain(true);\n else setState({ status: \"asking\" });\n let ok = false;\n try {\n ok = await host.ask({\n directive,\n items,\n nounLabel: nounText,\n ...(again ? { again: true } : {}),\n });\n } catch (error) {\n if (!stillHere()) return;\n setAskingAgain(false);\n setState({\n status: \"error\",\n message:\n error instanceof Error && error.message\n ? error.message\n : \"We could not ask you to confirm this, so nothing was done.\",\n });\n return;\n }\n if (!stillHere()) return;\n setAskingAgain(false);\n if (!ok) {\n // Declining is not an error: the card is exactly as it was.\n setState(again ? prior : { status: \"idle\" });\n return;\n }\n }\n setElapsed(0);\n // The question is answered: this instance stops asking.\n setState((prev) => (prev.status === \"asking\" ? { status: \"idle\" } : prev));\n // From the yes on, the apply is the BLOCK's: published by identity, so a\n // card that re-mounts mid-apply (or after it) shows the true outcome.\n publishOutcome(confirm, askedFor, { status: \"applying\", startedAt: Date.now() });\n try {\n const shell: DirectiveShell = { __kind: directive.slug, items };\n if (conversationId) shell.conversationId = conversationId;\n if (again) shell.force = true;\n let result: Awaited<ReturnType<typeof confirm>>;\n try {\n result = await confirm(shell);\n } finally {\n // Every record this apply may have touched is re-read wherever it is\n // shown — even a failed apply may have written some items.\n announceChangedRecords(directive, items);\n }\n for (const record of result.records ?? []) noteRecordChanged(record.id);\n publishOutcome(confirm, askedFor, {\n status: \"applied\",\n applied: result.applied,\n failed: result.failed,\n message: result.message?.trim() ? result.message.trim() : null,\n records: result.records ?? [],\n // \"Run again\" made one more; a first apply (or a replay of one) is one.\n copies: again ? Math.max(1, priorCopies) + 1 : Math.max(1, priorCopies),\n // \"Run again\" wrote the same values over themselves; what the FIRST\n // apply replaced is still the change this block made.\n before:\n again && prior.status === \"applied\" && prior.before\n ? prior.before\n : (result.before ?? null),\n });\n if (stillHere()) onApplied?.();\n } catch (error) {\n publishOutcome(confirm, askedFor, {\n status: \"error\",\n message:\n error instanceof Error && error.message\n ? error.message\n : \"That couldn't be applied just now. Please try again.\",\n });\n }\n }\n\n if (view.status === \"applied\") {\n const bad = view.failed > 0;\n const trashed = directive.directiveClass === \"delete\";\n const label = nounText;\n // THE TALLY IS A DOOR (no dead ends): the records the apply wrote, each by\n // name and each opening, beside the server's own sentence when it sent one.\n const records = host.renderRecord ? view.records : [];\n return (\n <span\n className={`flex min-w-0 flex-wrap items-center gap-x-2 gap-y-0.5 text-xs ${bad ? \"text-destructive\" : \"text-primary\"}`}\n data-apply-state=\"applied\"\n >\n {/* The glyph rides WITH the sentence: a long server sentence wraps\n beside it, never leaving the icon alone on a line (phone width). */}\n <span className=\"inline-flex min-w-0 items-start gap-1\">\n {bad ? (\n <AlertIcon className=\"mt-px h-3.5 w-3.5 shrink-0\" />\n ) : (\n <CheckCircleIcon className=\"mt-px h-3.5 w-3.5 shrink-0\" />\n )}\n {bad ? (\n <FailureNotice\n words={failureWords(\n {\n raw: view.message ?? `${view.failed} failed`,\n directiveClass: directive.directiveClass,\n noun: directive.noun,\n nounLabel: nounText,\n failed: view.failed,\n total: view.applied + view.failed,\n },\n host.explainFailure,\n )}\n raw={view.message}\n />\n ) : (\n <span className=\"min-w-0\">{view.message ?? `Applied ${view.applied}`}</span>\n )}\n </span>\n {view.copies > 1 ? (\n <span\n className=\"shrink-0 text-muted-foreground\"\n data-apply-copies={view.copies}\n title={\n records.length > 0\n ? directive.directiveClass === \"create\"\n ? \"Links to the latest copy.\"\n : \"Links to the latest run.\"\n : undefined\n }\n >\n {directive.directiveClass === \"create\" ? `${view.copies} copies` : `Ran ${view.copies} times`}\n </span>\n ) : null}\n {records.map((record) => (\n <span key={`${record.noun}:${record.id}`} className=\"inline-flex min-w-0 items-center\">\n {host.renderRecord?.({\n ...record,\n fallback: recordFallbackName(label),\n context: \"applied\",\n trashed,\n })}\n </span>\n ))}\n {/* A failed item was never ledgered, so a plain re-apply retries only\n it. A clean tally offers \"Run again\" — the one way past the\n ledger's dedup, asked in words that say it runs a second time. */}\n <button\n type=\"button\"\n disabled={askingAgain}\n onClick={() => void handleApply(!bad)}\n className=\"inline-flex shrink-0 items-center gap-1 whitespace-nowrap rounded px-1 py-0.5 text-muted-foreground hover:bg-accent hover:text-accent-foreground disabled:opacity-50\"\n data-apply-action={bad ? \"retry\" : \"run-again\"}\n >\n <RotateCcwIcon className=\"h-3 w-3\" />\n {bad ? \"Retry\" : \"Run again\"}\n </button>\n </span>\n );\n }\n\n if (view.status === \"checking\") {\n return (\n <span\n className=\"inline-flex h-6 w-6 items-center justify-center text-muted-foreground\"\n role=\"status\"\n aria-label=\"Checking whether this already ran\"\n data-apply-state=\"checking\"\n >\n <LoaderIcon className=\"h-3.5 w-3.5 animate-spin\" />\n </span>\n );\n }\n\n if (view.status === \"finishing\") {\n return (\n <span\n className=\"inline-flex items-center gap-1 text-xs text-muted-foreground\"\n role=\"status\"\n data-apply-state=\"finishing\"\n >\n <LoaderIcon className=\"h-3.5 w-3.5 animate-spin\" />\n Finishing…\n </span>\n );\n }\n\n // THE CONFIRM OPENS WITH THE RECORD IN HAND (G10B review, 2026-10-02: the\n // first update confirm of a session took ~2 s). An update/delete's confirm\n // reads the records it names; pointing at (or focusing) Apply starts that\n // read through the host's `readRecord`, so a host that keeps a recent read\n // hands the confirm the record instead of a second round trip.\n const warm = () => {\n const read = host.readRecord;\n if (!read || !TARGETING_CLASSES.has(directive.directiveClass)) return;\n for (const item of items) {\n const id = itemRecordId(item);\n if (id) void read({ noun: directive.noun, id }).catch(() => null);\n }\n };\n\n // A delete LOOKS like one before the click, not only inside the confirm\n // (reviewer, 2026-10-02: the Delete card's Apply was the same neutral grey\n // as a create's).\n const destructive = directive.directiveClass === \"delete\";\n // NOTHING TO CHANGE, SHOWN BEFORE THE CLICK (G6A review, 2026-10-02): an\n // update that sets no field still offered a full-weight \"Update\". The control\n // stays live — validation offers, never blocks — but reads muted, with why.\n const muted = nothingToChange && view.status === \"idle\";\n return (\n <span className=\"flex min-w-0 flex-wrap items-center justify-end gap-x-2 gap-y-1\">\n {/* A button never wraps its label: the REASON wraps, the button holds. */}\n {muted ? (\n <span className=\"min-w-0 text-xs text-muted-foreground\" data-apply-nothing=\"\">\n Nothing to change\n </span>\n ) : null}\n <button\n type=\"button\"\n onClick={() => void handleApply()}\n onPointerEnter={warm}\n onFocus={warm}\n disabled={view.status === \"applying\" || view.status === \"asking\" || items.length === 0}\n data-apply-tone={muted ? \"muted\" : destructive ? \"destructive\" : \"default\"}\n title={muted ? \"Applying it changes nothing.\" : undefined}\n className={`inline-flex shrink-0 items-center gap-1 whitespace-nowrap rounded-md border px-2 py-1 text-xs font-medium disabled:opacity-50 ${\n muted\n ? \"border-border/60 bg-background text-muted-foreground hover:bg-accent\"\n : destructive\n ? \"border-destructive/50 bg-background text-destructive hover:bg-destructive/10\"\n : \"border-border bg-background hover:bg-accent\"\n }`}\n >\n {view.status === \"applying\" ? (\n <LoaderIcon className=\"h-3.5 w-3.5 animate-spin\" />\n ) : (\n <PlayIcon className=\"h-3.5 w-3.5\" />\n )}\n {view.status === \"applying\"\n ? `Applying${itemCount ? ` ${itemCount} ${itemCount === 1 ? \"item\" : \"items\"}` : \"\"}…${elapsed ? ` ${elapsed}s` : \"\"}`\n : label}\n </button>\n {view.status === \"error\" ? (\n <span\n className=\"inline-flex max-w-sm items-start gap-1 text-xs text-destructive\"\n data-apply-state=\"error\"\n >\n <AlertIcon className=\"mt-0.5 h-3.5 w-3.5 shrink-0\" />\n <FailureNotice\n words={failureWords(\n {\n raw: view.message,\n directiveClass: directive.directiveClass,\n noun: directive.noun,\n nounLabel: nounText,\n },\n host.explainFailure,\n )}\n raw={view.message}\n />\n </span>\n ) : null}\n </span>\n );\n}\n\n/**\n * What failed and what to do, in plain words — and the technical text behind\n * \"Details\" for whoever debugs it. Never the raw text as the sentence.\n */\nfunction FailureNotice({\n words,\n raw,\n}: {\n words: { what: string; next: string; details?: string };\n raw: string | null;\n}) {\n const [open, setOpen] = useState(false);\n // The host's worded details replace the raw text only when there IS raw text.\n const detail = raw?.trim() ? (words.details?.trim() || raw.trim()) : \"\";\n return (\n <span className=\"flex min-w-0 flex-col gap-0.5\" data-apply-failure>\n <span className=\"min-w-0\">\n {words.what} {words.next}\n {detail ? (\n <button\n type=\"button\"\n onClick={() => setOpen((v) => !v)}\n aria-expanded={open}\n className=\"ml-1 whitespace-nowrap underline underline-offset-2 hover:no-underline\"\n data-apply-failure-details-toggle\n >\n {open ? \"Hide details\" : \"Details\"}\n </button>\n ) : null}\n </span>\n {open && detail ? (\n <span\n className=\"block max-w-sm select-text break-words font-mono text-[11px] text-muted-foreground\"\n data-apply-failure-details\n >\n {detail}\n </span>\n ) : null}\n </span>\n );\n}\n\nexport default ApplyDirectiveButton;\n","/**\n * WHAT A DIRECTIVE ITEM WILL DO TO AN EXISTING RECORD — for the card, the\n * confirm dialog, and anything else that must say it before the click.\n *\n * WHY (reviewer, 2026-09-30): an Update card and a Delete card showed each item\n * as \"Item\" — they never named the record they would change, and an Update card\n * never said what it would change. The item-summary helpers name a thing to be\n * CREATED from its own fields; an update or delete item carries the TARGET's id\n * and, for an update, the NEW values — so its \"title\" field is the new title,\n * not the name of the record being changed. Naming the target is the host's\n * live lookup (`DirectiveHost.renderRecord`); what changes is right here.\n *\n * Law: common-docs/policies/no-dead-ends.md — the sentence\n * names what changes.\n */\n\nimport { humanizeIdentifier } from \"@ai-matrx/kit/text-case\";\nimport { itemTitle } from \"@ai-matrx/content-ir\";\n\n/** Classes whose items point at an EXISTING record by `id`. */\nexport const TARGETING_CLASSES: ReadonlySet<string> = new Set([\"update\", \"delete\"]);\n\n/** Never a change: identity and plumbing. */\nconst NOT_A_CHANGE = new Set<string>([\"__kind\", \"id\"]);\n\n/**\n * How long a changed value may read before it is shortened. A value someone\n * must judge — a title, a status, a date — is always whole (G8A review: a 60\n * cap plus CSS truncation cut \"Review4 tasks…\" on a phone); only a body of\n * prose longer than this is shortened, whole on hover and in View/Copy.\n */\nexport const CHANGE_VALUE_MAX = 280;\n\n/** The id of the existing record an update/delete item targets, or null. */\nexport function itemRecordId(item: Record<string, unknown>): string | null {\n const id = item.id;\n if (typeof id === \"string\" && id.trim()) return id.trim();\n if (typeof id === \"number\") return String(id);\n return null;\n}\n\n/** \"due_date\" → \"Due Date\" — THE humanizer; underscores read as developer output. */\nexport function fieldLabel(key: string): string {\n return humanizeIdentifier(key) || key;\n}\n\n/**\n * THE ONE FIELD-LABEL RULE for a directive — card rows, card facts and the\n * host's confirm: the noun's title column reads \"Title\" whatever it is stored\n * as (a workbook's `workbook_name`, a note's `label`), every other field reads\n * through THE humanizer. A new workbook card said \"workbook name\" while its\n * confirm said \"Title\" (G8A review, 2026-10-02).\n */\nexport function directiveFieldLabel(key: string, titleColumn: string | null | undefined): string {\n return titleColumn && key === titleColumn ? \"Title\" : fieldLabel(key);\n}\n\n/**\n * The app's word for ONE stored value of ONE field — \"incomplete\" on a task\n * reads \"Inbox\", \"high\" reads \"High\". The host answers it for its pick-list\n * fields; null → the value as stored.\n */\nexport type DirectiveValueWord = (field: string, value: string) => string | null;\n\n/**\n * The name a NEW item carries, or null when it has none — the one rule the card\n * and a host's confirm share. `itemTitle`'s last resort (\"Item\", \"Item 2 of 3\")\n * is a placeholder, never a name: a create with an empty title used to ask\n * \"Create project Item?\" and its card row read \"Item\" (G10B review, 2026-10-02).\n */\nexport function itemOwnName(item: Record<string, unknown>, titleColumn: string | null): string | null {\n // With two items the last resort is exactly \"Item 1 of 2\"; a real name wins first.\n const probe = itemTitle(item, titleColumn, 0, 2);\n return probe === \"Item 1 of 2\" ? null : probe;\n}\n\n/** What a nameless new item is called — said as such, never a placeholder name. */\nexport const NO_TITLE_WORD = \"No title\";\n\n/** How an empty value reads — before or after, on the card and in the confirm. */\nexport const EMPTY_VALUE_WORD = \"None\";\n\n\n/**\n * What a record is called when its name cannot be read: its TYPE (\"Task\").\n * Never its id, in any slot — text, tooltip or screen-reader label. It used to\n * be \"Task a8a00001\", and a link to a record that no longer exists hovered\n * \"Open Task a8a00001\" (G10B review, 2026-10-02). The host says WHY the name is\n * missing (not found, no access) beside it.\n */\nexport function recordFallbackName(nounLabel: string): string {\n return nounLabel.trim() || \"Record\";\n}\n\n/** One value as a row reads it: shortened, the whole of it, and whether it is empty. */\nexport interface ChangeValue {\n value: string;\n full: string;\n clears: boolean;\n}\n\nexport interface ItemChange extends ChangeValue {\n key: string;\n /** \"Due date\". */\n label: string;\n /**\n * What the field holds NOW, when the host could read the record — so an\n * update reads \"old → new\", never just the new value (reviewer, 2026-10-02).\n * Absent when the current record is unknown.\n */\n before?: ChangeValue;\n /** True when the record already holds exactly this value — nothing changes. */\n same?: boolean;\n}\n\n/** One value, described for a change row (`value` shortened, `full` whole). */\nexport function describeChangeValue(value: unknown, word?: (value: string) => string | null): ChangeValue {\n return describeValue(value, word);\n}\n\nconst EMPTY: ChangeValue = { value: EMPTY_VALUE_WORD, full: EMPTY_VALUE_WORD, clears: true };\n\nfunction describeValue(value: unknown, word?: (value: string) => string | null): ChangeValue {\n if (value === null || value === undefined) return EMPTY;\n if (typeof value === \"string\") {\n const trimmed = value.trim();\n if (!trimmed) return EMPTY;\n // ONE VALUE, ONE WORD (G8A review, 2026-10-02: \"Status incomplete →\n // completed\"). A value of a pick-list field reads as the app's word for it\n // — the host knows which fields are pick-lists and their words; anything\n // else (free text, a slug) is shown exactly as written.\n const named = word?.(trimmed) ?? null;\n if (named) return { value: named, full: named, clears: false };\n const oneLine = trimmed.replace(/\\s+/g, \" \");\n const shown = oneLine.length > CHANGE_VALUE_MAX ? `${oneLine.slice(0, CHANGE_VALUE_MAX - 1)}…` : oneLine;\n return { value: shown, full: trimmed, clears: false };\n }\n if (typeof value === \"number\" || typeof value === \"boolean\") {\n return { value: String(value), full: String(value), clears: false };\n }\n if (Array.isArray(value)) {\n const n = value.length;\n const text = n === 0 ? EMPTY_VALUE_WORD : `${n} ${n === 1 ? \"entry\" : \"entries\"}`;\n return { value: text, full: safeJson(value), clears: n === 0 };\n }\n const n = Object.keys(value as object).length;\n const text = n === 0 ? EMPTY_VALUE_WORD : `${n} ${n === 1 ? \"field\" : \"fields\"}`;\n return { value: text, full: safeJson(value), clears: n === 0 };\n}\n\nfunction safeJson(value: unknown): string {\n try {\n return JSON.stringify(value, null, 2);\n } catch {\n return String(value);\n }\n}\n\nfunction sameValue(a: unknown, b: unknown): boolean {\n if (a === b) return true;\n if (a === null || a === undefined || b === null || b === undefined) {\n // An empty string and a missing value both read \"None\".\n const emptyA = a === null || a === undefined || a === \"\";\n const emptyB = b === null || b === undefined || b === \"\";\n return emptyA && emptyB;\n }\n if (typeof a === \"object\" || typeof b === \"object\") return safeJson(a) === safeJson(b);\n return false;\n}\n\n/**\n * Every field an UPDATE item sets, in the order the item carries them — ALL of\n * them, never a sample: a person approving an overwrite sees the whole of it.\n *\n * Pass `current` — the record as it is now (`DirectiveHost.readRecord`) — and\n * each change also carries what it REPLACES (`before`) and whether it changes\n * anything at all (`same`). A field the record does not carry gets no `before`.\n */\nexport interface ItemChangesOptions {\n /**\n * The noun's title column (catalog `title_column` — `nounTitleColumn`). It is\n * labelled \"Title\" whatever it is called: a note's title is stored in\n * `label`, and the confirm said \"Label\" while the form said \"Title\"\n * (reviewer, 2026-10-02). The same rule the directive builder's form uses.\n */\n titleColumn?: string | null;\n /** The app's word for a stored value (`DirectiveHost.valueLabel`, bound to the noun). */\n valueWord?: DirectiveValueWord | null;\n}\n\nexport function itemChanges(\n item: Record<string, unknown>,\n current?: Record<string, unknown> | null,\n options: ItemChangesOptions = {},\n): ItemChange[] {\n const out: ItemChange[] = [];\n const titleColumn = options.titleColumn ?? null;\n for (const [key, raw] of Object.entries(item)) {\n if (NOT_A_CHANGE.has(key)) continue;\n const label = directiveFieldLabel(key, titleColumn);\n // The title is a name, never a token to translate.\n const valueWord = options.valueWord;\n const word =\n key === titleColumn || !valueWord ? undefined : (v: string) => valueWord(key, v);\n const change: ItemChange = { key, label, ...describeValue(raw, word) };\n if (current && Object.prototype.hasOwnProperty.call(current, key)) {\n change.before = describeValue(current[key], word);\n change.same = sameValue(current[key], raw);\n }\n out.push(change);\n }\n return out;\n}\n\n/**\n * 🚨 AN UPDATE THAT WOULD CHANGE NOTHING SAYS SO (G11B review, 2026-10-07: the\n * confirm listed every field \"(no change)\", Apply stayed full-weight, and the\n * run ended \"Updated task. Ran 2 times\"). True when the item sets no field, or\n * when the record was read and EVERY field already holds its new value. A field\n * whose current value is unknown counts as a change — doubt never mutes Apply.\n * ONE rule for the card and the host's confirm.\n */\nexport function changesNothing(changes: ReadonlyArray<ItemChange>): boolean {\n return changes.every((change) => change.same === true);\n}\n","\"use client\";\n\n/**\n * THE RECORD AS IT IS NOW — read through the host's `readRecord` seam, so an\n * update row (and the host's own confirm) can say what each field REPLACES.\n *\n * 🚨 RE-READ WHENEVER THE RECORD CHANGES (G7, 2026-10-02). It used to be read\n * ONCE per `noun:id`: after Update card A applied, Update card B naming the same\n * record — its row, and a confirm whose body stayed mounted between questions —\n * still said A's OLD value was the old value (\"G6A renamed target\" while the\n * database held \"G6A second rename\"). Every apply now announces the records it\n * touched (`noteRecordChanged`, also the host's door for its own writers) and\n * every read keyed on that record's revision runs again. A host reader that\n * shares in-flight reads keys them by `recordRevision(id)` too, so a read\n * started before the write is never handed to a reader asking after it.\n *\n * A pure hook over a reader FUNCTION rather than the directive-host context:\n * the confirm dialog renders in the host's global dialog layer, outside every\n * `DirectiveHostProvider`, and must read the same values the card does.\n */\n\nimport { useEffect, useState, useSyncExternalStore } from \"react\";\nimport type { DirectiveRecordRef } from \"./directive-host\";\n\nexport type RecordValuesStatus = \"idle\" | \"loading\" | \"ready\" | \"unavailable\";\n\nexport interface RecordValues {\n /** The record's fields now, or null until (or unless) they are read. */\n values: Record<string, unknown> | null;\n status: RecordValuesStatus;\n}\n\nexport type RecordReader = (ref: DirectiveRecordRef) => Promise<Record<string, unknown> | null>;\n\n/**\n * One change counter per record id — bumped by every write this page makes.\n * ONE store per page, not per bundle: every entry of this package (`.`,\n * `./directives`, …) is built self-contained, so module state would be a\n * SEPARATE counter per entry — an apply announced through one entry was never\n * seen by a reader imported through another (found adopting 0.19.0). The store\n * lives in a `Symbol.for` slot on `globalThis`, shared by every copy.\n */\ninterface RevisionStore {\n revisions: Map<string, number>;\n listeners: Set<() => void>;\n}\nconst STORE_SLOT = Symbol.for(\"@ai-matrx/content-ir-react/record-revisions\");\nfunction revisionStore(): RevisionStore {\n const slots = globalThis as unknown as Record<symbol, RevisionStore | undefined>;\n let store = slots[STORE_SLOT];\n if (!store) {\n store = { revisions: new Map(), listeners: new Set() };\n slots[STORE_SLOT] = store;\n }\n return store;\n}\nconst { revisions, listeners } = revisionStore();\n\n/** How many times this page has changed record `id` (0 = never). */\nexport function recordRevision(id: string): number {\n return revisions.get(id) ?? 0;\n}\n\n/**\n * Record `id` just changed (an apply wrote it, or any other writer on the page).\n * Every `useRecordValues` naming it reads it again.\n */\nexport function noteRecordChanged(id: string): void {\n if (!id) return;\n revisions.set(id, recordRevision(id) + 1);\n for (const listener of listeners) listener();\n}\n\nfunction subscribeRevisions(listener: () => void): () => void {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n}\n\n/** The live revision of record `id`, re-rendering when it changes. */\nexport function useRecordRevision(id: string): number {\n return useSyncExternalStore(\n subscribeRevisions,\n () => recordRevision(id),\n () => 0,\n );\n}\n\nexport function useRecordValues(\n read: RecordReader | undefined,\n ref: DirectiveRecordRef | null,\n): RecordValues {\n const revision = useRecordRevision(ref?.id ?? \"\");\n // The revision is part of the key: a change to the record is a fresh read,\n // and nothing read before it is shown as \"now\" while the new read runs.\n const key = ref && read ? `${ref.noun}:${ref.id}#${revision}` : \"\";\n const [result, setResult] = useState<{ key: string } & RecordValues>({\n key: \"\",\n values: null,\n status: \"idle\",\n });\n\n useEffect(() => {\n if (!key || !read) return;\n const split = key.indexOf(\":\");\n const target: DirectiveRecordRef = {\n noun: key.slice(0, split),\n id: key.slice(split + 1, key.lastIndexOf(\"#\")),\n };\n let live = true;\n setResult({ key, values: null, status: \"loading\" });\n read(target)\n .then((values) => {\n if (!live) return;\n setResult({ key, values, status: values ? \"ready\" : \"unavailable\" });\n })\n .catch(() => {\n if (!live) return;\n // Not knowing the old value is not an error the person must handle:\n // the row says only what changes, exactly as it did before this seam.\n setResult({ key, values: null, status: \"unavailable\" });\n });\n return () => {\n live = false;\n };\n }, [key, read]);\n\n if (!key) return { values: null, status: \"idle\" };\n if (result.key !== key) return { values: null, status: \"loading\" };\n return { values: result.values, status: result.status };\n}\n","/**\n * THE WORDS A FAILED APPLY SHOWS A PERSON.\n *\n * A card used to print the server's text as its sentence — e.g.\n * \"unknown / non-writable noun 'task'. Writable: [...]\" (G5 review,\n * 2026-10-02). A person needs WHAT failed and WHAT TO DO, in plain words; the\n * technical text is for whoever debugs it, behind a Details toggle. The host\n * may name a failure it recognises (`DirectiveHost.explainFailure`); otherwise\n * these verb-aware defaults answer.\n */\nimport type { DirectiveFailure, DirectiveFailureWords } from \"./directive-host\";\n\nconst PAST: Record<string, string> = {\n create: \"created\",\n update: \"updated\",\n delete: \"deleted\",\n};\n\n/** The card's own words for a failure the host did not name. */\nexport function defaultFailureWords(failure: DirectiveFailure): DirectiveFailureWords {\n const verbed = PAST[failure.directiveClass] ?? \"applied\";\n const noun = failure.nounLabel.trim().toLowerCase() || \"item\";\n if (failure.failed && failure.total && failure.total > 1) {\n return {\n what: `${failure.failed} of ${failure.total} weren't ${verbed}.`,\n next: \"Retry to try those again.\",\n };\n }\n return {\n what: `The ${noun} wasn't ${verbed}.`,\n next: \"Try again in a moment.\",\n };\n}\n\n/** The host's words when it names this failure, else the default. */\nexport function failureWords(\n failure: DirectiveFailure,\n explain?: (failure: DirectiveFailure) => DirectiveFailureWords | null,\n): DirectiveFailureWords {\n return explain?.(failure) ?? defaultFailureWords(failure);\n}\n","/**\n * The handful of glyphs the directive cards need, as inline SVG. This package\n * depends on no icon library (see the FEATURE boundary); the paths are the\n * Lucide set's (ISC), so the cards look identical to a Lucide-using host.\n */\n\nimport type { ReactElement, SVGProps } from \"react\";\n\ntype IconProps = SVGProps<SVGSVGElement>;\n\nfunction Svg({ children, ...props }: IconProps) {\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth={2}\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n {...props}\n >\n {children}\n </svg>\n );\n}\n\nexport const FilePlusIcon = (p: IconProps) => (\n <Svg {...p}>\n <path d=\"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4\" />\n <path d=\"M14 2v4a2 2 0 0 0 2 2h4\" />\n <path d=\"M3 15h6\" />\n <path d=\"M6 12v6\" />\n </Svg>\n);\nexport const PencilIcon = (p: IconProps) => (\n <Svg {...p}>\n <path d=\"M12 20h9\" />\n <path d=\"M16.376 3.622a1 1 0 0 1 3.002 3.002L7.368 18.635a2 2 0 0 1-.855.506l-2.872.838a.5.5 0 0 1-.62-.62l.838-2.872a2 2 0 0 1 .506-.854z\" />\n </Svg>\n);\nexport const TrashIcon = (p: IconProps) => (\n <Svg {...p}>\n <path d=\"M3 6h18\" />\n <path d=\"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6\" />\n <path d=\"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2\" />\n <line x1=\"10\" x2=\"10\" y1=\"11\" y2=\"17\" />\n <line x1=\"14\" x2=\"14\" y1=\"11\" y2=\"17\" />\n </Svg>\n);\nexport const PlayIcon = (p: IconProps) => (\n <Svg {...p}>\n <polygon points=\"6 3 20 12 6 21 6 3\" />\n </Svg>\n);\nexport const WebhookIcon = (p: IconProps) => (\n <Svg {...p}>\n <path d=\"M18 16.98h-5.99c-1.1 0-1.95.94-2.48 1.9A4 4 0 0 1 2 17c.01-.7.2-1.4.57-2\" />\n <path d=\"m6 17 3.13-5.78c.53-.97.1-2.01-.4-2.96A4 4 0 0 1 14 5.5c.63.42 1.13 1 1.44 1.66\" />\n <path d=\"m12 6 3.13 5.73C15.66 12.7 16.9 13 18 13a4 4 0 0 1 0 8\" />\n </Svg>\n);\nexport const BoxesIcon = (p: IconProps) => (\n <Svg {...p}>\n <path d=\"M2.97 12.92A2 2 0 0 0 2 14.63v3.24a2 2 0 0 0 .97 1.71l3 1.8a2 2 0 0 0 2.06 0L12 19v-5.5l-5-3-4.03 2.42Z\" />\n <path d=\"m7 16.5-4.74-2.85\" />\n <path d=\"m7 16.5 5-3\" />\n <path d=\"M7 16.5v5.17\" />\n <path d=\"M12 13.5V19l3.97 2.38a2 2 0 0 0 2.06 0l3-1.8a2 2 0 0 0 .97-1.71v-3.24a2 2 0 0 0-.97-1.71L17 10.5l-5 3Z\" />\n <path d=\"m17 16.5-5-3\" />\n <path d=\"m17 16.5 4.74-2.85\" />\n <path d=\"M17 16.5v5.17\" />\n <path d=\"M7.97 4.42A2 2 0 0 0 7 6.13v4.37l5 3 5-3V6.13a2 2 0 0 0-.97-1.71l-3-1.8a2 2 0 0 0-2.06 0l-3 1.8Z\" />\n <path d=\"M12 8 7.26 5.15\" />\n <path d=\"m12 8 4.74-2.85\" />\n <path d=\"M12 13.5V8\" />\n </Svg>\n);\nexport const ChevronDownIcon = (p: IconProps) => (\n <Svg {...p}>\n <path d=\"m6 9 6 6 6-6\" />\n </Svg>\n);\nexport const ChevronRightIcon = (p: IconProps) => (\n <Svg {...p}>\n <path d=\"m9 18 6-6-6-6\" />\n </Svg>\n);\nexport const MaximizeIcon = (p: IconProps) => (\n <Svg {...p}>\n <polyline points=\"15 3 21 3 21 9\" />\n <polyline points=\"9 21 3 21 3 15\" />\n <line x1=\"21\" x2=\"14\" y1=\"3\" y2=\"10\" />\n <line x1=\"3\" x2=\"10\" y1=\"21\" y2=\"14\" />\n </Svg>\n);\nexport const LoaderIcon = (p: IconProps) => (\n <Svg {...p}>\n <path d=\"M21 12a9 9 0 1 1-6.219-8.56\" />\n </Svg>\n);\n/** Lucide `rotate-ccw` — \"Run again\". */\nexport const RotateCcwIcon = (p: IconProps) => (\n <Svg {...p}>\n <path d=\"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8\" />\n <path d=\"M3 3v5h5\" />\n </Svg>\n);\nexport const CheckCircleIcon = (p: IconProps) => (\n <Svg {...p}>\n <circle cx=\"12\" cy=\"12\" r=\"10\" />\n <path d=\"m9 12 2 2 4-4\" />\n </Svg>\n);\nexport const AlertIcon = (p: IconProps) => (\n <Svg {...p}>\n <path d=\"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3\" />\n <path d=\"M12 9v4\" />\n <path d=\"M12 17h.01\" />\n </Svg>\n);\n\n/**\n * The icon for a side-effect directive card. THE CLASS LEADS: on a card whose\n * job is \"authorize this write\", the first thing to see is whether this\n * CREATES, CHANGES, or DELETES. A noun override exists only where the platform\n * has a settled visual identity for the thing — agents are a Webhook.\n */\nconst AGENT_NOUNS = new Set([\"create_agent\", \"create_agent_definition\", \"agent\"]);\n\nexport function classIcon(directiveClass: string, noun: string): (p: IconProps) => ReactElement {\n if (directiveClass === \"action\" && AGENT_NOUNS.has(noun)) return WebhookIcon;\n switch (directiveClass) {\n case \"create\":\n return FilePlusIcon;\n case \"update\":\n return PencilIcon;\n case \"delete\":\n return TrashIcon;\n default:\n return PlayIcon;\n }\n}\n","\"use client\";\n\n/**\n * The card for a SIDE-EFFECT directive in content — create / update / delete /\n * action. One card for every shape the server can register, so a person is\n * never asked to approve a write they cannot identify.\n *\n * WHY IT EXISTS (Arman, 2026-08-26): the floor it replaced gave \"a name and\n * then an apply button, which essentially tells the user to click apply and\n * conduct a potentially destructive action without any clue as to what this\n * thing is.\"\n *\n * THE DESIGN:\n * - Say what it IS, from authority — the catalog's own words for the title,\n * the noun's title column for each item, never a guess.\n * - Facts, not prose — a few scalar chips; nesting goes to the panel.\n * - Read before you approve — `View` opens the item through the host's seam,\n * which wraps the item's OWN kind component (THE DIRECTIVE⇄KIND SEAM).\n * - Copy is table stakes, at the batch and at the item (host chrome).\n * - Apply stays exactly where it was — the host's confirm seam.\n *\n * NEVER RETURNS NULL — a shape with no items degrades to a stated line.\n */\n\nimport { useEffect, useState } from \"react\";\nimport {\n asKindInstance,\n directiveDisplay,\n itemFacts,\n itemSubtitle,\n nounLabel,\n nounTitleColumn,\n type DecodedDirective,\n} from \"@ai-matrx/content-ir\";\nimport {\n ApplyDirectiveButton,\n readsApplyLedger,\n type DirectiveApplyPhase,\n} from \"./ApplyDirectiveButton\";\nimport {\n TARGETING_CLASSES,\n changesNothing,\n directiveFieldLabel,\n itemChanges,\n itemOwnName,\n itemRecordId,\n NO_TITLE_WORD,\n recordFallbackName,\n type DirectiveValueWord,\n type ItemChange,\n} from \"./item-changes\";\nimport { useRecordValues } from \"./record-values\";\nimport { useDirectiveHost, type DirectiveHost } from \"./directive-host\";\nimport { ChevronDownIcon, ChevronRightIcon, MaximizeIcon, classIcon } from \"./icons\";\n\nexport interface SideEffectDirectiveCardProps {\n directive: DecodedDirective;\n}\n\n/** The host's value words for one record type, or null when it has none. */\nexport function directiveValueWord(\n host: Pick<DirectiveHost, \"valueLabel\">,\n noun: string,\n): DirectiveValueWord | null {\n const valueLabel = host.valueLabel;\n return valueLabel ? (field, value) => valueLabel({ noun, field, value }) : null;\n}\n\nfunction omitKey(item: Record<string, unknown>, key: string): Record<string, unknown> {\n const { [key]: _omitted, ...rest } = item;\n return rest;\n}\n\n/** How many items render as rows before the rest collapse behind a toggle. */\nconst ROWS_BEFORE_FOLD = 3;\n\nfunction ItemRow({\n directive,\n item,\n index,\n total,\n phase,\n onNothing,\n}: {\n directive: DecodedDirective;\n item: Record<string, unknown>;\n index: number;\n total: number;\n phase: DirectiveApplyPhase;\n onNothing?: ((index: number, nothing: boolean) => void) | undefined;\n}) {\n const host = useDirectiveHost();\n // An update/delete item points at a record that ALREADY EXISTS: name THAT\n // record (its live name, through the host), never the item's own fields —\n // an update's `title` is the NEW title — and never \"Item\".\n const recordId = TARGETING_CLASSES.has(directive.directiveClass) ? itemRecordId(item) : null;\n if (recordId) {\n return (\n <TargetRow\n directive={directive}\n item={item}\n recordId={recordId}\n index={index}\n phase={phase}\n onNothing={onNothing}\n />\n );\n }\n const titleColumn = nounTitleColumn(directive.noun, host.nouns);\n // A nameless item SAYS it has no title — never \"Item\" posing as its name.\n const ownName = itemOwnName(item, titleColumn);\n const title = ownName ?? NO_TITLE_WORD;\n const subtitle = itemSubtitle(item);\n // The title column IS the title — never repeated as a fact — and every\n // fact is labelled and worded exactly as the confirm and the forms do.\n const valueWord = directiveValueWord(host, directive.noun);\n const facts = itemFacts(titleColumn ? omitKey(item, titleColumn) : item).map((fact) => ({\n ...fact,\n label: directiveFieldLabel(fact.key, titleColumn),\n value: valueWord?.(fact.key, fact.value) ?? fact.value,\n }));\n const kind = host.itemKind?.(directive.slug) ?? null;\n const display = directiveDisplay(directive.directiveClass, directive.noun, host.nouns);\n const openItem = host.openItem;\n\n const body = (\n <>\n {/* THE IDENTITY WINS THE SPACE: the title keeps its intrinsic width and the facts give way; on a phone (no facts) it wraps to two lines, never cut to one (G11B). */}\n <span\n className={`min-w-0 line-clamp-2 font-medium [overflow-wrap:anywhere] sm:shrink-0 sm:truncate ${ownName ? \"text-foreground\" : \"italic text-muted-foreground\"}`}\n data-item-name=\"\"\n data-item-untitled={ownName ? undefined : \"\"}\n >\n {title}\n </span>\n <span className=\"hidden min-w-0 flex-1 items-baseline gap-2 overflow-hidden sm:flex\">\n {facts.map((fact) => (\n <span key={fact.key} className=\"truncate text-[11px] text-muted-foreground\" data-item-fact={fact.key}>\n {fact.label} <span className=\"text-foreground/80\">{fact.value}</span>\n </span>\n ))}\n </span>\n {subtitle && facts.length === 0 ? (\n <span className=\"hidden truncate text-[11px] text-muted-foreground sm:inline\">{subtitle}</span>\n ) : null}\n {openItem ? (\n <MaximizeIcon className=\"ml-auto h-3 w-3 shrink-0 text-muted-foreground\" />\n ) : null}\n </>\n );\n\n return (\n <div className=\"flex items-center gap-2 py-1 text-xs\">\n {openItem ? (\n <button\n type=\"button\"\n onClick={() =>\n openItem({\n // Stamped so the panel's kind pipeline types it from its own first key.\n item: asKindInstance(item, kind) ?? item,\n itemKind: kind,\n title,\n subtitle: `${display.title} · item ${index + 1} of ${total}`,\n directive,\n index,\n total,\n })\n }\n className=\"flex min-w-0 flex-1 items-center gap-2 rounded px-1 py-0.5 text-left hover:bg-accent hover:text-accent-foreground\"\n title=\"Open to read it\"\n >\n {body}\n </button>\n ) : (\n <span className=\"flex min-w-0 flex-1 items-center gap-2 px-1 py-0.5\">{body}</span>\n )}\n {host.renderCopy?.({\n label: ownName ?? `this ${nounLabel(directive.noun, host.nouns)}`,\n value: item,\n kind,\n size: \"xs\",\n })}\n </div>\n );\n}\n\n/**\n * THE CHANGE LIST — every field an update sets, as \"Label old → new\" when the\n * record's current value is known, \"Label → new\" when it is not. ONE component\n * for the card row and the host's confirm dialog, so the two can never read\n * differently (reviewer, 2026-10-02: the confirm showed only the new value).\n *\n * 🚨 A VALUE SOMEONE MUST JUDGE IS NEVER CUT (G8A review, 2026-10-02): on a\n * phone the card is ~230px and the row read \"Title Review… → Review4 tas…\".\n * Values wrap; below a 20rem container the label, the old value and the new\n * value stack, one per line. Measured on the list's own width (a container\n * query), so a narrow window panel on a desktop gets the same stacking.\n */\nexport function DirectiveChangeList({\n changes,\n className,\n}: {\n changes: ItemChange[];\n className?: string;\n}) {\n if (changes.length === 0) {\n return (\n <p className={`text-[11px] text-muted-foreground${className ? ` ${className}` : \"\"}`}>\n Sets no fields — nothing would change.\n </p>\n );\n }\n return (\n <ul className={`@container space-y-1${className ? ` ${className}` : \"\"}`} data-directive-changes=\"\">\n {changes.map((change) => {\n const before = change.before && !change.same ? change.before : null;\n return (\n <li\n key={change.key}\n className=\"flex min-w-0 flex-col text-[11px] @xs:flex-row @xs:flex-wrap @xs:items-baseline @xs:gap-x-1.5\"\n title={\n before\n ? `${change.label}: ${before.full} → ${change.full}`\n : `${change.label} → ${change.full}`\n }\n data-change-key={change.key}\n >\n <span className=\"shrink-0 text-muted-foreground\">{change.label}</span>\n {before ? (\n <span\n className=\"min-w-0 text-muted-foreground line-through [overflow-wrap:anywhere]\"\n data-change-before=\"\"\n >\n {before.value}\n </span>\n ) : null}\n <span className=\"flex min-w-0 items-baseline gap-1.5\">\n <span aria-hidden className=\"shrink-0 text-muted-foreground\">\n →\n </span>\n <span\n className={`min-w-0 [overflow-wrap:anywhere] ${change.clears ? \"italic text-muted-foreground\" : \"text-foreground\"}`}\n data-change-after=\"\"\n >\n {change.value}\n </span>\n {change.same ? <span className=\"shrink-0 text-muted-foreground\">(no change)</span> : null}\n </span>\n </li>\n );\n })}\n </ul>\n );\n}\n\n/**\n * ONE row for an item that changes an EXISTING record: the record by its live\n * name (a way to open it, through `renderRecord`), then — for an update —\n * every field it sets, \"Due date 2026-10-01 → 2026-10-15\" (the old value read\n * through `readRecord` when the host can).\n */\nfunction TargetRow({\n directive,\n item,\n recordId,\n index,\n phase,\n onNothing,\n}: {\n directive: DecodedDirective;\n item: Record<string, unknown>;\n recordId: string;\n index: number;\n phase: DirectiveApplyPhase;\n onNothing?: ((index: number, nothing: boolean) => void) | undefined;\n}) {\n const host = useDirectiveHost();\n const fallback = recordFallbackName(nounLabel(directive.noun, host.nouns));\n const isUpdate = directive.directiveClass === \"update\";\n // 🚨 THE OLD VALUE OF A CHANGE THAT HAPPENED COMES FROM THE RECORD OF THE\n // CHANGE (G6A review, 2026-10-02). A live read after the apply answers the NEW\n // value, so an applied card said \"Title → X (no change)\". Live values are read\n // only while the block is still open; once applied, the server's `before` is\n // the old value — and without it the row says only what each field was set to.\n // Until the ledger answers, neither: no comparison is better than a wrong one.\n const readsLive = isUpdate && phase.phase === \"open\";\n const live = useRecordValues(\n readsLive ? host.readRecord : undefined,\n readsLive ? { noun: directive.noun, id: recordId } : null,\n );\n const compareTo =\n phase.phase === \"applied\" ? (phase.before?.[index] ?? null) : readsLive ? live.values : null;\n const changes = isUpdate\n ? itemChanges(item, compareTo, {\n titleColumn: nounTitleColumn(directive.noun, host.nouns),\n valueWord: directiveValueWord(host, directive.noun),\n })\n : [];\n // The card mutes Apply when every row would change nothing — known only once\n // the record is read and the block is still open.\n const nothing = readsLive && live.values !== null && changesNothing(changes);\n useEffect(() => {\n onNothing?.(index, nothing);\n }, [onNothing, index, nothing]);\n const name = host.renderRecord ? (\n host.renderRecord({ noun: directive.noun, id: recordId, fallback, context: \"row\" })\n ) : (\n <span className=\"line-clamp-2 min-w-0 font-medium text-foreground [overflow-wrap:anywhere]\">{fallback}</span>\n );\n\n return (\n <div className=\"py-1 text-xs\" data-directive-target={recordId}>\n <div className=\"flex min-w-0 items-center gap-2\">\n <span className=\"flex min-w-0 flex-1 items-center gap-1 px-1\">{name}</span>\n {/* THE LABEL NEVER NAMES AN ID (G9): \"this task\" until the host reads the name. */}\n {host.renderCopy?.({\n label: `this ${nounLabel(directive.noun, host.nouns).toLowerCase()}`,\n value: item,\n size: \"xs\",\n record: { noun: directive.noun, id: recordId },\n })}\n </div>\n {isUpdate ? <DirectiveChangeList changes={changes} className=\"mt-0.5 px-1\" /> : null}\n </div>\n );\n}\n\nexport function SideEffectDirectiveCard({ directive }: SideEffectDirectiveCardProps) {\n const host = useDirectiveHost();\n const [expanded, setExpanded] = useState(false);\n const items = directive.items;\n const total = items.length;\n const display = directiveDisplay(directive.directiveClass, directive.noun, host.nouns);\n const Icon = classIcon(directive.directiveClass, directive.noun);\n\n // What the Apply control knows about this block — the rows draw an applied\n // change from its record, never from a live re-read.\n const [phase, setPhase] = useState<DirectiveApplyPhase>(() =>\n readsApplyLedger(host, directive) ? { phase: \"pending\" } : { phase: \"open\" },\n );\n // An update that changes nothing — it sets no field, or the record already\n // holds every value (read by its row) — says so before the click (G11B).\n const [nothingAt, setNothingAt] = useState<Readonly<Record<number, boolean>>>({});\n const noteNothing = (index: number, nothing: boolean) =>\n setNothingAt((prev) => (prev[index] === nothing ? prev : { ...prev, [index]: nothing }));\n const nothingToChange =\n directive.directiveClass === \"update\" &&\n total > 0 &&\n items.every((item, index) => itemChanges(item).length === 0 || nothingAt[index] === true);\n\n const shown = expanded ? items : items.slice(0, ROWS_BEFORE_FOLD);\n const hidden = total - shown.length;\n\n return (\n <div className=\"my-3 rounded-md border border-border bg-card px-2.5 py-1.5\" data-directive={directive.slug}>\n <div className=\"flex flex-wrap items-center gap-x-2 gap-y-1\">\n <Icon className=\"h-3.5 w-3.5 shrink-0 text-muted-foreground\" />\n <span className=\"text-sm font-medium text-foreground\">{display.title}</span>\n {display.family ? <span className=\"text-xs text-muted-foreground\">{display.family}</span> : null}\n <span className=\"text-xs tabular-nums text-muted-foreground\">\n {total} {total === 1 ? \"item\" : \"items\"}\n </span>\n <div className=\"ml-auto flex min-w-0 flex-wrap items-center justify-end gap-1\">\n {host.renderCopy?.({ label: display.title, value: directive.shell, size: \"icon\" })}\n <ApplyDirectiveButton\n directive={directive}\n itemCount={total}\n onPhase={setPhase}\n nothingToChange={nothingToChange}\n />\n </div>\n </div>\n\n {total === 0 ? (\n // Stated, never silent: an empty batch is a real (and suspicious) state.\n <p className=\"mt-1 text-xs text-muted-foreground\">No items — nothing would be written.</p>\n ) : (\n <div className=\"mt-0.5 divide-y divide-border/60\">\n {shown.map((item, i) => (\n <ItemRow\n key={i}\n directive={directive}\n item={item}\n index={i}\n total={total}\n phase={phase}\n onNothing={noteNothing}\n />\n ))}\n </div>\n )}\n\n {hidden > 0 || expanded ? (\n <button\n type=\"button\"\n onClick={() => setExpanded((v) => !v)}\n className=\"mt-0.5 inline-flex items-center gap-1 whitespace-nowrap rounded px-1 py-0.5 text-[11px] text-muted-foreground hover:text-foreground\"\n >\n {expanded ? <ChevronDownIcon className=\"h-3 w-3\" /> : <ChevronRightIcon className=\"h-3 w-3\" />}\n {expanded ? \"Show less\" : `Show ${hidden} more`}\n </button>\n ) : null}\n </div>\n );\n}\n\nexport default SideEffectDirectiveCard;\n","\"use client\";\n\n/**\n * The neutral \"we could not render this, but we will NEVER hide it\" card —\n * THE PREFIX FLOOR of the Kind Directives route.\n *\n * THE RULE THIS ENFORCES: a registered directive renderer must never return\n * `null`. `DirectiveRender` renders a renderer's output verbatim, so a `null`\n * deletes the assistant's whole message block (2026-07-26: a 70KB content plan\n * vanished exactly that way). When a renderer cannot draw its rich view, it\n * renders THIS instead: named by class and noun, itemised by count, with Apply\n * when the class is a side effect and the host can apply.\n */\n\nimport { directiveDisplay, type DecodedDirective } from \"@ai-matrx/content-ir\";\nimport { ApplyDirectiveButton } from \"./ApplyDirectiveButton\";\nimport { useDirectiveHost } from \"./directive-host\";\nimport { BoxesIcon } from \"./icons\";\n\nexport interface DirectiveFallbackCardProps {\n directive: DecodedDirective;\n /** Short, human explanation of why the rich renderer degraded. */\n reason?: string;\n}\n\nexport function DirectiveFallbackCard({ directive, reason }: DirectiveFallbackCardProps) {\n const host = useDirectiveHost();\n const count = directive.items.length;\n const display = directiveDisplay(directive.directiveClass, directive.noun, host.nouns);\n return (\n <div className=\"my-3 inline-flex flex-wrap items-center gap-2 rounded-md border border-border bg-muted px-2.5 py-1 text-sm\">\n <BoxesIcon className=\"h-3.5 w-3.5 shrink-0 text-muted-foreground\" />\n <span className=\"text-foreground\">{display.title}</span>\n {display.family ? <span className=\"text-muted-foreground\">· {display.family}</span> : null}\n <span className=\"text-muted-foreground\">\n · {count} {count === 1 ? \"item\" : \"items\"}\n </span>\n {reason ? <span className=\"text-muted-foreground\">· {reason}</span> : null}\n <ApplyDirectiveButton directive={directive} />\n </div>\n );\n}\n\nexport default DirectiveFallbackCard;\n","\"use client\";\n\n/**\n * The card for a directive whose JSON has NOT finished arriving — the\n * provisional tier of `DirectiveRender`.\n *\n * WHY IT EXISTS (found live 2026-09-25, the agent builder's\n * `directive_v1_action_create_agent_definition` in the agent run window): an\n * agent streams a directive as one JSON document, `__kind` first. Every splitter\n * already types the block as a directive from its first bytes\n * (`looksLikeDirectiveHead`), but the decoder can only honour a COMPLETE shell,\n * so for the whole stream `DirectiveRender` fell to its raw `<pre>` — the person\n * watched a wall of JSON grow and then snap into a card at the last byte.\n *\n * The head already says what this is (class + noun), so the card says it from\n * the first bytes, from the same catalog words the finished card uses:\n *\n * - STREAMING — \"Create agent definition · writing…\". No Apply: nothing is\n * applicable until the shell is whole.\n * - NOT STREAMING, still undecodable — the document was cut off (a model hit\n * its output limit, a stream died). Said plainly, never dressed as\n * \"writing…\" forever, with what did arrive one click away.\n *\n * NEVER RETURNS NULL.\n */\n\nimport { directiveDisplay, parseDirectiveSlug } from \"@ai-matrx/content-ir\";\nimport { useDirectiveHost } from \"./directive-host\";\nimport { BoxesIcon, classIcon } from \"./icons\";\n\n/** A head whose slug has fully arrived: `{\"__kind\":\"directive_v1_…\"` + closing quote. */\nconst COMPLETE_SLUG_RE = /^\\{\\s*\"__kind\"\\s*:\\s*\"([^\"]+)\"/;\n\n/** The directive slug of a partial document, once its closing quote has arrived. */\nexport function provisionalDirectiveSlug(content: string): string | null {\n const match = content.trimStart().match(COMPLETE_SLUG_RE);\n return match?.[1] ?? null;\n}\n\nexport interface DirectiveProvisionalCardProps {\n /** The partial fence body as received so far. */\n content: string;\n /**\n * Whether the document may still be arriving. `false` means the stream is\n * over and the document never completed — the card says it was cut off.\n */\n streaming: boolean;\n className?: string | undefined;\n}\n\nexport function DirectiveProvisionalCard({ content, streaming, className }: DirectiveProvisionalCardProps) {\n const host = useDirectiveHost();\n const slug = provisionalDirectiveSlug(content);\n const known = slug ? parseDirectiveSlug(slug) : null;\n const display = known ? directiveDisplay(known.directiveClass, known.noun, host.nouns) : null;\n const Icon = known ? classIcon(known.directiveClass, known.noun) : BoxesIcon;\n const title = display?.title ?? \"Structured action\";\n\n return (\n <div\n className={`my-3 rounded-md border border-border bg-card px-2.5 py-1.5${className ? ` ${className}` : \"\"}`}\n data-directive={slug ?? undefined}\n data-directive-state={streaming ? \"streaming\" : \"incomplete\"}\n >\n <div className=\"flex flex-wrap items-center gap-x-2 gap-y-1\">\n <Icon className=\"h-3.5 w-3.5 shrink-0 text-muted-foreground\" />\n <span className=\"text-sm font-medium text-foreground\">{title}</span>\n {display?.family ? <span className=\"text-xs text-muted-foreground\">{display.family}</span> : null}\n {streaming ? (\n <span className=\"inline-flex items-center gap-1.5 text-xs text-muted-foreground\" role=\"status\">\n <span className=\"h-1.5 w-1.5 animate-pulse rounded-full bg-primary\" aria-hidden />\n Writing…\n </span>\n ) : (\n <span className=\"text-xs text-destructive\" role=\"status\">\n Cut off before it finished — nothing can be applied.\n </span>\n )}\n </div>\n {streaming ? null : (\n <details className=\"mt-1 text-xs text-muted-foreground\">\n <summary className=\"cursor-pointer select-none hover:text-foreground\">Show what arrived</summary>\n <pre className=\"mt-1 max-h-64 overflow-auto whitespace-pre-wrap break-all rounded bg-muted px-2 py-1 text-[11px]\">\n {content}\n </pre>\n </details>\n )}\n </div>\n );\n}\n\nexport default DirectiveProvisionalCard;\n","\"use client\";\n\n/**\n * DirectiveRender — THE renderer for anything whose `__kind` is a reserved\n * directive slug, on every AI Matrx UI.\n *\n * Pipeline (one pipeline, mirroring the backend):\n * 0. THE PROVISIONAL TIER — a head that names a directive but does not\n * decode yet renders `DirectiveProvisionalCard` (\"writing…\" while\n * streaming, \"cut off\" once the host says the stream ended).\n * 1. `tryDecodeDirectiveContent` → the two-key shell (a stored 4-key fence is\n * translated inside the decoder). Not a directive (bad JSON / no reserved\n * `__kind`) → raw <pre>, never throws. An unhonourable shell is REPORTED\n * through the host and falls to raw — a render seam must not take a whole\n * message block down over one fence, and must never go silent.\n * 2. `getDirectiveRenderer` → exact slug, else the CLASS prefix rule (the\n * host's registrations). Found → render it.\n * 3. THE SIDE-EFFECT TIER — every create / update / delete / action shape\n * renders the side-effect card, so a person is never asked to approve a\n * write they cannot identify.\n * 4. THE FLOOR — a class nothing registers still shows the fallback card.\n * Never null, never silent.\n *\n * Position decides capability: in content only `reference`/`secret` resolve;\n * a side-effect directive in prose is a card with an explicit Apply, never\n * executed on sight.\n */\n\nimport { looksLikeDirectiveHead, tryDecodeDirectiveContent } from \"@ai-matrx/content-ir\";\nimport { DirectiveScopeProvider, useDirectiveHost } from \"./directive-host\";\nimport { DirectiveFallbackCard } from \"./DirectiveFallbackCard\";\nimport { DirectiveProvisionalCard } from \"./DirectiveProvisionalCard\";\nimport { getDirectiveRenderer } from \"./registry\";\nimport { SideEffectDirectiveCard } from \"./SideEffectDirectiveCard\";\n\nexport interface DirectiveRenderProps {\n /** The fence body (JSON string) or an already-parsed shell / value. */\n content: unknown;\n className?: string;\n /**\n * Whether the document may still be arriving. A host that knows its stream\n * has ended passes `false`, so an undecodable directive head is shown as CUT\n * OFF rather than \"writing…\" forever. Omitted = it may still be arriving.\n */\n streaming?: boolean;\n /**\n * The conversation this directive renders in (a chat message). Applies and\n * ledger reads key on it — the same namespace an agent proposal's Approve\n * uses — so one action can never apply twice through two doors. Omit in a\n * person's own content. Overrides any enclosing `DirectiveScopeProvider`.\n */\n conversationId?: string | null;\n}\n\n/**\n * A document that parses is WHOLE: if it still does not decode, it is a\n * malformed directive (already reported by the decoder), never one \"still\n * arriving\" — only a genuinely unfinished document gets the provisional tier.\n */\nfunction isWholeJson(content: string): boolean {\n try {\n JSON.parse(content);\n return true;\n } catch {\n return false;\n }\n}\n\nexport function DirectiveRender({ conversationId, ...props }: DirectiveRenderProps) {\n if (conversationId === undefined) return <DirectiveRenderInner {...props} />;\n return (\n <DirectiveScopeProvider conversationId={conversationId}>\n <DirectiveRenderInner {...props} />\n </DirectiveScopeProvider>\n );\n}\n\nfunction DirectiveRenderInner({ content, className, streaming }: Omit<DirectiveRenderProps, \"conversationId\">) {\n const host = useDirectiveHost();\n const directive = tryDecodeDirectiveContent(content, (message) => {\n const line = `[kind-directives] ${message}`;\n if (host.reportError) host.reportError(line);\n else console.error(line);\n });\n\n if (!directive) {\n // THE PROVISIONAL TIER: the head already names a directive but the shell is\n // not whole yet (mid-stream) or never became whole (cut off). The class and\n // noun are known from the first bytes — say what it is, never show the\n // growing JSON as if it were the answer.\n if (typeof content === \"string\" && looksLikeDirectiveHead(content) && !isWholeJson(content)) {\n return (\n <DirectiveProvisionalCard content={content} streaming={streaming !== false} className={className} />\n );\n }\n const raw = typeof content === \"string\" ? content : JSON.stringify(content, null, 2);\n return (\n <pre\n className={`my-3 overflow-x-auto rounded-md border border-border bg-muted px-3 py-2 text-xs text-muted-foreground${className ? ` ${className}` : \"\"}`}\n >\n {raw}\n </pre>\n );\n }\n\n const Renderer = getDirectiveRenderer(directive);\n if (Renderer) return <Renderer directive={directive} />;\n if (directive.parsed.executes) return <SideEffectDirectiveCard directive={directive} />;\n return <DirectiveFallbackCard directive={directive} />;\n}\n\nexport default DirectiveRender;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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AAS,CAAC,YAAY;AAChE,UAAM,OAAO,qBAAqB,OAAO;AACzC,QAAI,KAAK,YAAa,MAAK,YAAY,IAAI;AAAA,QACtC,SAAQ,MAAM,IAAI;AAAA,EACzB,CAAC;AAED,MAAI,CAAC,WAAW;AAKd,QAAI,OAAO,YAAY,gBAAY,2CAAuB,OAAO,KAAK,CAAC,YAAY,OAAO,GAAG;AAC3F,aACE,6CAAC,4BAAyB,SAAkB,WAAW,cAAc,OAAO,WAAsB;AAAA,IAEtG;AACA,UAAM,MAAM,OAAO,YAAY,WAAW,UAAU,KAAK,UAAU,SAAS,MAAM,CAAC;AACnF,WACE;AAAA,MAAC;AAAA;AAAA,QACC,WAAW,wGAAwG,YAAY,IAAI,SAAS,KAAK,EAAE;AAAA,QAElJ;AAAA;AAAA,IACH;AAAA,EAEJ;AAEA,QAAM,WAAW,qBAAqB,SAAS;AAC/C,MAAI,SAAU,QAAO,6CAAC,YAAS,WAAsB;AACrD,MAAI,UAAU,OAAO,SAAU,QAAO,6CAAC,2BAAwB,WAAsB;AACrF,SAAO,6CAAC,yBAAsB,WAAsB;AACtD;","names":["import_react","import_content_ir","import_content_ir","nounLabel","n","text","import_react","import_jsx_runtime","import_jsx_runtime","label","read","import_react","import_content_ir","import_jsx_runtime","import_content_ir","import_jsx_runtime","import_content_ir","import_jsx_runtime","import_content_ir","import_jsx_runtime"]}
1
+ {"version":3,"sources":["../directives.ts","../directives/directive-host.tsx","../directives/registry.ts","../directives/ApplyDirectiveButton.tsx","../directives/item-changes.ts","../directives/record-values.ts","../directives/failure-words.ts","../directives/icons.tsx","../directives/SideEffectDirectiveCard.tsx","../directives/DirectiveFallbackCard.tsx","../directives/DirectiveProvisionalCard.tsx","../directives/DirectiveRender.tsx"],"sourcesContent":["/**\n * `@ai-matrx/content-ir-react/directives` — the Kind Directives render tier:\n * the host seams (`DirectiveHostProvider`), the renderer registry with THE\n * PREFIX TIER, the side-effect card, the fallback floor, the Apply control, and\n * `DirectiveRender` — THE renderer every UI draws a directive through. Client\n * entry (stamped \"use client\").\n */\nexport * from \"./directives/directive-host\";\nexport * from \"./directives/registry\";\nexport * from \"./directives/ApplyDirectiveButton\";\nexport * from \"./directives/SideEffectDirectiveCard\";\nexport * from \"./directives/DirectiveFallbackCard\";\nexport * from \"./directives/DirectiveProvisionalCard\";\nexport * from \"./directives/DirectiveRender\";\nexport * from \"./directives/item-changes\";\nexport * from \"./directives/failure-words\";\nexport * from \"./directives/record-values\";\n","\"use client\";\n\n/**\n * THE DIRECTIVE HOST CONTRACT — what the directive tier refuses to decide.\n *\n * The package owns the DECISIONS (decode → renderer → card → floor, the\n * position law, never-null rendering) and the card itself. Four things stay\n * host property and enter through named seams:\n *\n * 1. APPLYING a side-effect directive — `POST /directives/confirm` as the\n * user, with the host's auth and base URL. Absent → the Apply control is\n * ABSENT (honest), never a dead button.\n * 2. OPENING an item to read it before approving — a window panel, a dialog,\n * a route. Absent → items are not clickable.\n * 3. COPY controls — host chrome (matrx-frontend's CopyButtons). Absent → none.\n * 4. The NOUN catalog + item-kind lookup — server-derived tables the host\n * mirrors (or reads from its kind catalog's `items` edges).\n * 5. ASKING (`ask`), NAMING a record (`renderRecord`), and READING the ledger\n * (`applyState`) — the consequence before the click, the doors, and the\n * state that survives a reload.\n *\n * A host that has adopted `ContentIrRenderProvider` passes `directives` on its\n * ContentIrHost; a host that has NOT (Workflow Studio, 2026-09-08) mounts\n * `DirectiveHostProvider` alone — the directive tier never requires the full\n * render host, because a chat bubble must be able to draw a directive card\n * identically everywhere, today.\n */\n\nimport { createContext, useContext, type ReactNode } from \"react\";\nimport type {\n DecodedDirective,\n DirectiveItemKindLookup,\n DirectiveNounCatalog,\n} from \"@ai-matrx/content-ir\";\n\nexport interface DirectiveApplyResult {\n applied: number;\n failed: number;\n /**\n * The server's own receipt sentence (\"Deleted task “Ship it”.\"), shown in\n * place of a bare count. Never composed client-side.\n */\n message?: string | null;\n /**\n * The records the apply created or changed, so the tally is a way IN to them\n * (no dead ends). Rendered through `renderRecord`; absent → the sentence alone.\n */\n records?: DirectiveRecordRef[];\n /**\n * For an UPDATE: what each item's fields held just BEFORE the write, by item\n * index (`null` for an item the server did not record). The card draws the\n * applied change from this record — never from a live re-read, which after the\n * apply answers the NEW value (G6A review, 2026-10-02: \"(no change)\" for a\n * change that happened).\n */\n before?: ReadonlyArray<Record<string, unknown> | null>;\n}\n\n/**\n * What the server's action ledger says about ONE block, read on mount so a\n * reloaded page never offers \"Apply\" for work that already ran (reviewer\n * defect 5, 2026-10-02).\n *\n * - `not_applied` — still to do (or partly done: the batch re-applies, and the\n * server replays the members it already holds). The card offers Apply.\n * - `in_flight` — another request is applying it right now. The card says it\n * is finishing and asks again shortly; it offers neither Apply nor a tally.\n * - `applied` — the ledger holds every item. The card shows the tally exactly\n * as a fresh apply would: the ledger's own sentence and the records, as doors.\n */\nexport interface DirectiveApplyState {\n state: \"not_applied\" | \"in_flight\" | \"applied\";\n /** The ledger row's sentence (\"Created task.\"), never composed client-side. */\n message?: string | null;\n /**\n * The records the LATEST apply wrote — the tally's doors. After \"Run again\"\n * that is the newest copy, never the first.\n */\n records?: DirectiveRecordRef[];\n /**\n * How many times the ledger holds this block as applied: 1 for the original,\n * one more for every \"Run again\". Absent → 1. A create that ran twice made\n * two records, and the card says so (reviewer, 2026-10-02).\n */\n copies?: number;\n /**\n * For an applied UPDATE: each item's replaced values, by item index, from the\n * ledger row (`null` where the ledger has none — a row from before 2026-10-02).\n * Absent → the card says only what each field was set to.\n */\n before?: ReadonlyArray<Record<string, unknown> | null>;\n}\n\n/** One record a directive names: the noun it is, and its id. */\nexport interface DirectiveRecordRef {\n noun: string;\n id: string;\n}\n\nexport interface DirectiveRecordProps extends DirectiveRecordRef {\n /**\n * What to show until (or unless) the host resolves the live name —\n * \"Task 1a2b3c4d\". Never blank, never \"Item\".\n */\n fallback: string;\n /** Where it is drawn: an item row, the confirm dialog, or the applied tally. */\n context: \"row\" | \"dialog\" | \"applied\";\n /**\n * True when the record is (about to be) in the trash — the host may still\n * name it but should not promise it opens as a live record.\n */\n trashed?: boolean;\n}\n\n/** What the person is being asked to approve — everything the card knows. */\nexport interface DirectiveAskRequest {\n directive: DecodedDirective;\n /** The items, exactly as they will be sent. */\n items: Record<string, unknown>[];\n /** The noun's human label (\"Task\"), from the host's catalog when it has one. */\n nounLabel: string;\n /**\n * True for \"Run again\": the ledger already holds this block, and a yes runs\n * it a SECOND time (`force`) — another copy for a create, the same fields\n * written again for an update, another delete for a restored record. The\n * question must say so.\n */\n again?: boolean;\n}\n\n/**\n * The shell a card hands its host — the two keys, plus WHERE it sits.\n *\n * `conversationId` is the conversation the card renders in (a chat message),\n * absent in a person's own content (a note). It is the idempotency NAMESPACE:\n * a card in an agent's message must apply under the SAME key as that\n * proposal's Approve button, or the one action could run twice.\n */\nexport interface DirectiveShell {\n __kind: string;\n items: Record<string, unknown>[];\n conversationId?: string;\n /** \"Run again\": skip the ledger's dedup and apply a second time. */\n force?: boolean;\n}\n\nexport interface DirectiveOpenItemOptions {\n /** The item, `__kind`-stamped when the shape has an item kind. */\n item: Record<string, unknown>;\n /** The content-IR kind this item IS, or null when the shape has none. */\n itemKind: string | null;\n /** What the item is called — the same title the card shows. */\n title: string;\n /** \"Run Create agent definition · item 1 of 1\". */\n subtitle: string | null;\n directive: DecodedDirective;\n index: number;\n total: number;\n}\n\nexport interface DirectiveCopyProps {\n /**\n * What the control is called to a screen reader. Never an id: for a record it\n * is type-generic (\"this task\"); a host with the record's live name replaces\n * it through `record`.\n */\n label: string;\n /** The existing record this control copies, when it copies one — to name it. */\n record?: DirectiveRecordRef;\n /** The value to copy — the whole shell or one item. */\n value: unknown;\n /** The item's kind, when copying an item. */\n kind?: string | null;\n size: \"icon\" | \"xs\";\n}\n\nexport interface DirectiveHost {\n /**\n * Apply a side-effect directive as the user (the server re-validates every\n * item against the registered model and runs the ONE handler; idempotent).\n * Reject with an Error whose message is safe to show.\n */\n confirm?: (shell: DirectiveShell) => Promise<DirectiveApplyResult>;\n /**\n * Ask the person BEFORE anything runs, naming the consequence (the records,\n * what changes). Resolve `true` to go ahead, `false` to leave the card as it\n * was. The Apply control stays idle while this is open — nothing reads as\n * \"applying\" until the person has said yes. Absent → `confirm` is called\n * directly (a host that asks inside `confirm` keeps working, but its card\n * will read \"Applying…\" while its dialog is up).\n */\n ask?: (request: DirectiveAskRequest) => Promise<boolean>;\n /**\n * Has this exact block already been applied? Read ONCE when the card mounts\n * (and again while the answer is `in_flight`), so the card survives a reload:\n * the server ledger, not component state, is what knows. The identity is the\n * server's (it hashes the validated items in the same namespace `confirm`\n * applies in), so a host asks — it never computes. Batch on the host side if\n * a page carries many cards. Reject with an Error when the ledger cannot be\n * read: the card reports it and offers Apply, which is safe because `confirm`\n * is idempotent. Absent → the card starts at Apply, as before.\n */\n applyState?: (shell: DirectiveShell) => Promise<DirectiveApplyState>;\n /**\n * Read the CURRENT values of ONE existing record, so an update says what it\n * replaces — \"Status open → done\", never just \"→ done\" (reviewer,\n * 2026-10-02). Resolve `null` when the record cannot be read (no access, no\n * such record, a noun the host cannot read); reject only for a real failure.\n * Absent → an update row shows the new values alone, as before.\n */\n readRecord?: (ref: DirectiveRecordRef) => Promise<Record<string, unknown> | null>;\n /**\n * Draw ONE existing record by its live name, as a way to open it. Used on\n * update/delete rows (the record that will change), in the host's own ask\n * dialog if it likes, and on the applied tally (what was written). Absent →\n * the fallback text, unlinked.\n */\n renderRecord?: (props: DirectiveRecordProps) => ReactNode;\n /** Open ONE item to read it properly before approving the write. */\n openItem?: (options: DirectiveOpenItemOptions) => void;\n /** Host copy controls. */\n renderCopy?: (props: DirectiveCopyProps) => ReactNode;\n /**\n * The app's word for one stored value of one pick-list field — the SAME word\n * the record's own screens and the write forms show (\"incomplete\" on a task\n * reads \"Inbox\"). One value, one display word everywhere (G8A review,\n * 2026-10-02: the card said \"Status incomplete → completed\"). Return null for\n * a field that is not a pick-list: its value is shown as written. Absent →\n * every value is shown as stored.\n */\n valueLabel?: (ref: DirectiveValueRef) => string | null;\n /** The mirrored noun catalog (label / family / title column). */\n nouns?: DirectiveNounCatalog;\n /** slug → the kind ONE item is (THE DIRECTIVE⇄KIND SEAM), or null. */\n itemKind?: DirectiveItemKindLookup;\n /** Where a decode failure or an unhonourable shell is reported. Default: console.error. */\n reportError?: (message: string) => void;\n /**\n * Plain words for a failed apply the host recognises (\"This button can't\n * create a task yet.\" + \"Create it from Tasks instead.\"). The card never shows\n * the server's raw text as its sentence: it shows these words — or its own\n * verb-aware default — and keeps the raw text behind \"Details\". Return null\n * to use the default.\n */\n explainFailure?: (failure: DirectiveFailure) => DirectiveFailureWords | null;\n}\n\n/** One stored value of one field of one record type. */\nexport interface DirectiveValueRef {\n noun: string;\n field: string;\n value: string;\n}\n\n/** One failed apply, as the card knows it. */\nexport interface DirectiveFailure {\n /** The server's / host's own text — technical; shown only behind Details. */\n raw: string;\n directiveClass: string;\n noun: string;\n /** The noun's display label (\"Task\"). */\n nounLabel: string;\n /** Items that failed, when some applied and some did not. */\n failed?: number;\n /** Items in the block. */\n total?: number;\n}\n\n/** What failed and what to do — each one short sentence. */\nexport interface DirectiveFailureWords {\n what: string;\n next: string;\n /**\n * The text behind \"Details\", when the host words it (e.g. the server's field\n * names read as the form labels them — \"Title is required\", never\n * \"name is required\"). Absent → the raw text.\n */\n details?: string;\n}\n\nconst DirectiveHostContext = createContext<DirectiveHost | null>(null);\n\n/** Where a directive renders — today, the conversation it sits in (if any). */\nexport interface DirectiveScope {\n conversationId?: string | null;\n}\n\nconst DirectiveScopeContext = createContext<DirectiveScope>({});\n\n/**\n * Tell every card below WHERE it renders. A host draws a chat message's\n * directives inside one of these (or passes `conversationId` to\n * `DirectiveRender`), so the card applies in that conversation's namespace —\n * the same key the agent's proposal approves under. A note mounts none.\n */\nexport function DirectiveScopeProvider({\n conversationId,\n children,\n}: DirectiveScope & { children: ReactNode }) {\n return (\n <DirectiveScopeContext.Provider value={{ conversationId: conversationId ?? null }}>\n {children}\n </DirectiveScopeContext.Provider>\n );\n}\n\nexport function useDirectiveScope(): DirectiveScope {\n return useContext(DirectiveScopeContext);\n}\n\nexport interface DirectiveHostProviderProps {\n host: DirectiveHost;\n children: ReactNode;\n}\n\nexport function DirectiveHostProvider({ host, children }: DirectiveHostProviderProps) {\n return <DirectiveHostContext.Provider value={host}>{children}</DirectiveHostContext.Provider>;\n}\n\nconst EMPTY_HOST: DirectiveHost = {};\n\n/**\n * The wired directive host. Unlike the render host this does NOT throw when\n * unwired: a directive still renders (named, itemised, copy-less, apply-less)\n * — degrading the chrome is honest, hiding the content is not.\n */\nexport function useDirectiveHost(): DirectiveHost {\n return useContext(DirectiveHostContext) ?? EMPTY_HOST;\n}\n","/**\n * Kind Directives — the renderer registry, and THE PREFIX TIER.\n *\n * A directive IS a kind instance, so the renderer for one is resolved from its\n * SLUG, in the same shape the kind component resolver uses:\n *\n * getDirectiveRenderer(directive)\n * → an exact-slug renderer (directive_v1_action_plan_tree)\n * → else the CLASS prefix rule (every directive_v1_reference_*)\n * → else null (DirectiveRender's own tier: the\n * side-effect card, then the floor)\n *\n * THE PREFIX RULE is Arman's routing-language ruling made real: registering\n * `reference` once gives EVERY enrolled noun a renderer for free; a custom\n * renderer for one slug overrides it; a brand-new server noun renders with\n * ZERO client edits. Hosts register their bespoke renderers (reference chips,\n * plan trees) here; the package supplies the side-effect card and the floor.\n */\n\nimport type { ComponentType } from \"react\";\nimport {\n type DecodedDirective,\n type DirectiveClass,\n buildDirectiveSlug,\n} from \"@ai-matrx/content-ir\";\n\nexport interface DirectiveRendererProps {\n /** The decoded two-key shell — slug, class, noun, items, position law. */\n directive: DecodedDirective;\n}\n\nexport type DirectiveRenderer = ComponentType<DirectiveRendererProps>;\n\n// REGISTRY ON A globalThis SLOT — never module-level Maps. With `splitting:\n// false` dual ESM/CJS output this module is duplicated into the root bundle and\n// the `./directives` bundle, and a host registering a renderer through one\n// graph must be visible to a card rendering through the other.\nconst REGISTRY_SLOT = Symbol.for(\"ai-matrx.content-ir-react.directive-renderers\");\ninterface Registry {\n bySlug: Map<string, DirectiveRenderer>;\n byClass: Map<DirectiveClass, DirectiveRenderer>;\n}\ntype RegistryHolder = typeof globalThis & { [REGISTRY_SLOT]?: Registry };\nconst registry: Registry = ((globalThis as RegistryHolder)[REGISTRY_SLOT] ??= {\n bySlug: new Map(),\n byClass: new Map(),\n});\n\n/**\n * Register a renderer for a whole CLASS (the prefix rule), or for one exact\n * `(class, noun)` pair, which wins. `noun` is passed as a noun, never a\n * hand-typed slug: the slug is BUILT by the grammar, so a registration whose\n * slug could not be parsed back is unconstructable rather than unreachable.\n */\nexport function registerDirectiveRenderer(\n directiveClass: DirectiveClass,\n renderer: DirectiveRenderer,\n noun?: string,\n): void {\n if (noun) registry.bySlug.set(buildDirectiveSlug(directiveClass, noun), renderer);\n else registry.byClass.set(directiveClass, renderer);\n}\n\n/** The renderer for a slug: exact → class prefix rule → null. */\nexport function getDirectiveRenderer(\n directive: Pick<DecodedDirective, \"slug\" | \"directiveClass\">,\n): DirectiveRenderer | null {\n return (\n registry.bySlug.get(directive.slug) ?? registry.byClass.get(directive.directiveClass) ?? null\n );\n}\n\n/** Tests only. */\nexport function resetDirectiveRenderers(): void {\n registry.bySlug.clear();\n registry.byClass.clear();\n}\n","\"use client\";\n\n/**\n * \"Apply\" for a side-effect Kind Directive that arrived as CONTENT.\n *\n * THE POSITION RULE, honoured exactly: a directive inside content NEVER\n * auto-executes — that is the guard against untrusted content mutating things.\n * But \"does not auto-execute\" was never \"is inert\": the user seeing it must be\n * able to say yes. This button IS that yes, through the host's `confirm` seam\n * (`POST /directives/confirm`, re-validated server-side, run as the user).\n *\n * No `confirm` seam → NO button. A control that cannot do its job is absent,\n * never dead. Only a side-effect class is applicable at all (`parsed.executes`).\n */\n\nimport { useEffect, useRef, useState, useSyncExternalStore } from \"react\";\nimport { nounLabel, type DecodedDirective } from \"@ai-matrx/content-ir\";\nimport {\n useDirectiveHost,\n useDirectiveScope,\n type DirectiveRecordRef,\n type DirectiveShell,\n} from \"./directive-host\";\nimport { TARGETING_CLASSES, itemRecordId, recordFallbackName } from \"./item-changes\";\nimport { noteRecordChanged } from \"./record-values\";\nimport { failureWords } from \"./failure-words\";\nimport { AlertIcon, CheckCircleIcon, LoaderIcon, PlayIcon, RotateCcwIcon } from \"./icons\";\n\n/** The records an update/delete names — re-read wherever they are shown once it ran. */\nfunction announceChangedRecords(directive: DecodedDirective, items: Record<string, unknown>[]): void {\n if (!TARGETING_CLASSES.has(directive.directiveClass)) return;\n for (const item of items) {\n const id = itemRecordId(item);\n if (id) noteRecordChanged(id);\n }\n}\n\ntype ApplyState =\n // Reading the server ledger on mount: has this block already run? Nothing\n // offers a write until it answers (reviewer defect 5, 2026-10-02).\n | { status: \"checking\" }\n // The ledger has a claim but no result: another request is applying it now.\n | { status: \"finishing\" }\n | { status: \"idle\" }\n // The host's `ask` dialog is up. NOTHING is applying yet, so nothing says so.\n | { status: \"asking\" }\n | { status: \"applying\"; startedAt: number }\n | {\n status: \"applied\";\n applied: number;\n failed: number;\n message: string | null;\n /** The LATEST apply's records — after \"Run again\", the newest copy. */\n records: DirectiveRecordRef[];\n /** How many times this block has applied (1 + every \"Run again\"). */\n copies: number;\n /** An update's replaced values, by item index — the record of the change. */\n before: ReadonlyArray<Record<string, unknown> | null> | null;\n }\n | { status: \"error\"; message: string };\n\n/**\n * 🚨 AN APPLY BELONGS TO THE BLOCK, NOT TO THE COMPONENT (G6A review,\n * 2026-10-02). A note re-renders its blocks while a confirm dialog is open, so\n * the card that asked was unmounted and a fresh one mounted in its place. The\n * apply still ran — but its result was handed to the card that was gone, and\n * the new card, which had read the ledger BEFORE the write landed, offered\n * \"Apply\" for an update that had already run.\n *\n * So once a person says yes, the apply's progress and outcome are kept HERE,\n * per apply authority — the host's `confirm` function, which ran it (a host\n * object may be rebuilt on every render; its `confirm` is the stable seam) — keyed by the block's identity (slug + items + where it renders — the\n * same namespace the ledger keys in), and every card drawing that block shows\n * them, whenever it mounted. Component state keeps only what is the instance's own:\n * the ledger read and the open question.\n */\ntype ApplyOutcome = Extract<ApplyState, { status: \"applying\" | \"applied\" | \"error\" }>;\nconst applyOutcomes = new WeakMap<object, Map<string, ApplyOutcome>>();\n/** The key when a host has no `confirm`: nothing can apply, so nothing is ever held. */\nconst EMPTY_AUTHORITY = {};\nconst outcomeListeners = new Set<() => void>();\n\nfunction outcomesOf(host: object): Map<string, ApplyOutcome> {\n let held = applyOutcomes.get(host);\n if (!held) {\n held = new Map();\n applyOutcomes.set(host, held);\n }\n return held;\n}\n\nfunction publishOutcome(host: object, identity: string, outcome: ApplyOutcome): void {\n outcomesOf(host).set(identity, outcome);\n for (const listener of outcomeListeners) listener();\n}\n\nfunction subscribeOutcomes(listener: () => void): () => void {\n outcomeListeners.add(listener);\n return () => {\n outcomeListeners.delete(listener);\n };\n}\n\n/** The outcome this page holds for a block, or null. */\nfunction useApplyOutcome(host: object, identity: string): ApplyOutcome | null {\n return useSyncExternalStore(\n subscribeOutcomes,\n () => applyOutcomes.get(host)?.get(identity) ?? null,\n () => null,\n );\n}\n\n/** How often a card re-reads a block another request is mid-applying. */\nconst FINISH_POLL_MS = 2_000;\n/** ~1 minute (the server's own claim wait is 45 s), then Apply is offered — idempotent. */\nconst FINISH_POLLS_MAX = 30;\n\n/**\n * What the Apply control knows about its block, for the rest of the card:\n * - `pending` — the ledger has not answered yet;\n * - `open` — nothing applied: rows compare against the record as it is now;\n * - `applied` — the change happened: rows draw it from `before` (the server's\n * record of what it replaced), never from a live re-read, which\n * now holds the NEW value.\n */\nexport type DirectiveApplyPhase =\n | { phase: \"pending\" }\n | { phase: \"open\" }\n | { phase: \"applied\"; before: ReadonlyArray<Record<string, unknown> | null> | null };\n\n/** Does this card read the ledger before offering Apply? (One rule, card and control.) */\nexport function readsApplyLedger(\n host: { applyState?: unknown; confirm?: unknown },\n directive: DecodedDirective,\n): boolean {\n return !!host.applyState && !!host.confirm && directive.parsed.executes && directive.items.length > 0;\n}\n\nexport interface ApplyDirectiveButtonProps {\n directive: DecodedDirective;\n label?: string;\n /** How many things this will write — shown during the wait so a long apply reads as work, not a frozen spinner. */\n itemCount?: number;\n onApplied?: () => void;\n /** Told whenever what the control knows about its block changes. */\n onPhase?: (phase: DirectiveApplyPhase) => void;\n /**\n * The block would change nothing (an update that sets no field). Apply stays\n * — validation offers, never blocks — but muted, with the reason beside it.\n */\n nothingToChange?: boolean;\n}\n\nexport function ApplyDirectiveButton({\n directive,\n label = \"Apply\",\n itemCount,\n onApplied,\n onPhase,\n nothingToChange = false,\n}: ApplyDirectiveButtonProps) {\n const host = useDirectiveHost();\n const scope = useDirectiveScope();\n // WHERE the card sits is the namespace its apply keys in: a chat message's\n // conversation (the SAME key the agent proposal's Approve uses — never two\n // applies of one action), else the person's own content.\n const conversationId = scope.conversationId || undefined;\n const items = directive.items;\n // The ledger read runs only where an apply could: a side effect, a confirm\n // seam, something to write. Everything else starts (and stays) where it was.\n const readsLedger = readsApplyLedger(host, directive);\n const initial: ApplyState = readsLedger ? { status: \"checking\" } : { status: \"idle\" };\n const [state, setState] = useState<ApplyState>(initial);\n const [elapsed, setElapsed] = useState(0);\n // \"Run again\" asks from the tally; the tally stays on screen while it asks\n // (only its own button goes quiet), never swapped for a disabled Apply.\n const [askingAgain, setAskingAgain] = useState(false);\n const startedAt = useRef<number | null>(null);\n\n // 🚨 THE STATE BELONGS TO THE BLOCK, NOT TO THE SLOT (reviewer, 2026-10-02).\n // A host that keys its blocks by POSITION hands this same instance a\n // DIFFERENT directive when a block is inserted above it. The state used to\n // stay: an applied Update card flipped back to \"Apply\" (the instance that\n // had been an idle card now held the Update, and the ledger's \"applied\"\n // answer was ignored because the state was not \"checking\"), and the\n // opposite — one card's tally drawn on another block — was one insert away.\n // When the block this instance draws changes, everything it knew resets and\n // the ledger is asked again about the block it now holds.\n const identity = JSON.stringify([directive.slug, items, conversationId ?? null]);\n const [stateFor, setStateFor] = useState(identity);\n if (stateFor !== identity) {\n setStateFor(identity);\n setState(initial);\n setAskingAgain(false);\n setElapsed(0);\n }\n // What this page knows about the block's apply wins over this instance's own\n // ledger read — except while this instance is asking its own question.\n const shared = useApplyOutcome(host.confirm ?? EMPTY_AUTHORITY, identity);\n const view: ApplyState = state.status === \"asking\" || !shared ? state : shared;\n // An apply that finishes after its block left this slot must not land here.\n const currentIdentity = useRef(identity);\n useEffect(() => {\n currentIdentity.current = identity;\n }, [identity]);\n const nounText = nounLabel(directive.noun, host.nouns);\n\n // THE CARD SURVIVES A RELOAD. Component state dies with the page; the\n // server's action ledger does not. Ask it once on mount — and every\n // FINISH_POLL_MS while another request is mid-apply — and render exactly\n // what a fresh apply would have left on screen.\n const shellKey = readsLedger ? JSON.stringify([directive.slug, items, conversationId ?? null]) : \"\";\n const read = host.applyState;\n const report = host.reportError;\n useEffect(() => {\n if (!shellKey || !read) return;\n // Parsed back from the key so the effect depends on the shell's CONTENT,\n // never on the per-render identity of `directive.items`.\n const [slug, shellItems, inConversation] = JSON.parse(shellKey) as [\n string,\n Record<string, unknown>[],\n string | null,\n ];\n const shell: DirectiveShell = { __kind: slug, items: shellItems };\n if (inConversation) shell.conversationId = inConversation;\n let live = true;\n let polls = 0;\n let timer: ReturnType<typeof setTimeout> | null = null;\n const ask = () => {\n read(shell)\n .then((answer) => {\n if (!live) return;\n if (answer.state === \"applied\") {\n setState((prev) =>\n prev.status === \"checking\" || prev.status === \"finishing\"\n ? {\n status: \"applied\",\n applied: shellItems.length,\n failed: 0,\n message: answer.message?.trim() ? answer.message.trim() : null,\n records: answer.records ?? [],\n copies: Math.max(1, answer.copies ?? 1),\n before: answer.before ?? null,\n }\n : prev,\n );\n } else if (answer.state === \"in_flight\" && polls < FINISH_POLLS_MAX) {\n polls += 1;\n setState((prev) => (prev.status === \"checking\" || prev.status === \"finishing\" ? { status: \"finishing\" } : prev));\n timer = setTimeout(ask, FINISH_POLL_MS);\n } else {\n // Not applied — or still \"in flight\" after a minute, when Apply is\n // the honest offer: confirm is idempotent and replays the receipt.\n setState((prev) => (prev.status === \"checking\" || prev.status === \"finishing\" ? { status: \"idle\" } : prev));\n }\n })\n .catch((error: unknown) => {\n if (!live) return;\n const why = error instanceof Error && error.message ? error.message : String(error);\n (report ?? console.error)(\n `[kind-directives] Could not read whether ${slug} was already applied: ${why}`,\n );\n setState((prev) => (prev.status === \"checking\" || prev.status === \"finishing\" ? { status: \"idle\" } : prev));\n });\n };\n ask();\n return () => {\n live = false;\n if (timer) clearTimeout(timer);\n };\n }, [shellKey, read, report]);\n\n // The rest of the card draws its rows from what this control knows.\n const appliedClean = view.status === \"applied\" && view.failed === 0 ? view : null;\n const appliedBefore = appliedClean ? appliedClean.before : null;\n const phaseKey =\n view.status === \"checking\" || view.status === \"finishing\"\n ? \"pending\"\n : appliedClean\n ? `applied:${JSON.stringify(appliedBefore)}`\n : \"open\";\n useEffect(() => {\n if (!onPhase) return;\n if (phaseKey === \"pending\") onPhase({ phase: \"pending\" });\n else if (phaseKey === \"open\") onPhase({ phase: \"open\" });\n else onPhase({ phase: \"applied\", before: appliedBefore });\n }, [phaseKey, onPhase, appliedBefore]);\n\n // An honest clock beats a fake progress bar — counted from when the apply\n // started, so a card mounted mid-apply shows the true elapsed time.\n const applyingSince = view.status === \"applying\" ? view.startedAt : null;\n useEffect(() => {\n if (applyingSince === null) return;\n startedAt.current = applyingSince;\n const id = setInterval(\n () => setElapsed(Math.round((Date.now() - (startedAt.current ?? 0)) / 1000)),\n 1000,\n );\n return () => clearInterval(id);\n }, [applyingSince]);\n\n if (!directive.parsed.executes) return null;\n const confirm = host.confirm;\n if (!confirm) return null;\n\n /**\n * `again` = \"Run again\": the ledger already holds this block, so a plain\n * confirm would only replay its receipt. The person is asked in words that\n * say it runs a SECOND time, and a yes sends `force`.\n */\n async function handleApply(again = false) {\n if (!confirm) return;\n // A \"no\" to Run again leaves the tally exactly where it was.\n const prior = view;\n const askedFor = identity;\n const stillHere = () => currentIdentity.current === askedFor;\n const priorCopies = view.status === \"applied\" ? view.copies : 0;\n // THE STATUS TELLS THE TRUTH (reviewer, 2026-09-30): the card used to read\n // \"Applying 1 item…\" while the confirm dialog was still asking. Ask first,\n // idle; only a yes moves the control to \"applying\".\n if (host.ask) {\n if (again) setAskingAgain(true);\n else setState({ status: \"asking\" });\n let ok = false;\n try {\n ok = await host.ask({\n directive,\n items,\n nounLabel: nounText,\n ...(again ? { again: true } : {}),\n });\n } catch (error) {\n if (!stillHere()) return;\n setAskingAgain(false);\n setState({\n status: \"error\",\n message:\n error instanceof Error && error.message\n ? error.message\n : \"We could not ask you to confirm this, so nothing was done.\",\n });\n return;\n }\n if (!stillHere()) return;\n setAskingAgain(false);\n if (!ok) {\n // Declining is not an error: the card is exactly as it was.\n setState(again ? prior : { status: \"idle\" });\n return;\n }\n }\n setElapsed(0);\n // The question is answered: this instance stops asking.\n setState((prev) => (prev.status === \"asking\" ? { status: \"idle\" } : prev));\n // From the yes on, the apply is the BLOCK's: published by identity, so a\n // card that re-mounts mid-apply (or after it) shows the true outcome.\n publishOutcome(confirm, askedFor, { status: \"applying\", startedAt: Date.now() });\n try {\n const shell: DirectiveShell = { __kind: directive.slug, items };\n if (conversationId) shell.conversationId = conversationId;\n if (again) shell.force = true;\n let result: Awaited<ReturnType<typeof confirm>>;\n try {\n result = await confirm(shell);\n } finally {\n // Every record this apply may have touched is re-read wherever it is\n // shown — even a failed apply may have written some items.\n announceChangedRecords(directive, items);\n }\n for (const record of result.records ?? []) noteRecordChanged(record.id);\n publishOutcome(confirm, askedFor, {\n status: \"applied\",\n applied: result.applied,\n failed: result.failed,\n message: result.message?.trim() ? result.message.trim() : null,\n records: result.records ?? [],\n // \"Run again\" made one more; a first apply (or a replay of one) is one.\n copies: again ? Math.max(1, priorCopies) + 1 : Math.max(1, priorCopies),\n // \"Run again\" wrote the same values over themselves; what the FIRST\n // apply replaced is still the change this block made.\n before:\n again && prior.status === \"applied\" && prior.before\n ? prior.before\n : (result.before ?? null),\n });\n if (stillHere()) onApplied?.();\n } catch (error) {\n publishOutcome(confirm, askedFor, {\n status: \"error\",\n message:\n error instanceof Error && error.message\n ? error.message\n : \"That couldn't be applied just now. Please try again.\",\n });\n }\n }\n\n if (view.status === \"applied\") {\n const bad = view.failed > 0;\n const trashed = directive.directiveClass === \"delete\";\n const label = nounText;\n // THE TALLY IS A DOOR (no dead ends): the records the apply wrote, each by\n // name and each opening, beside the server's own sentence when it sent one.\n const records = host.renderRecord ? view.records : [];\n return (\n <span\n className={`flex min-w-0 flex-wrap items-center gap-x-2 gap-y-0.5 text-xs ${bad ? \"text-destructive\" : \"text-primary\"}`}\n data-apply-state=\"applied\"\n >\n {/* The glyph rides WITH the sentence: a long server sentence wraps\n beside it, never leaving the icon alone on a line (phone width). */}\n <span className=\"inline-flex min-w-0 items-start gap-1\">\n {bad ? (\n <AlertIcon className=\"mt-px h-3.5 w-3.5 shrink-0\" />\n ) : (\n <CheckCircleIcon className=\"mt-px h-3.5 w-3.5 shrink-0\" />\n )}\n {bad ? (\n <FailureNotice\n words={failureWords(\n {\n raw: view.message ?? `${view.failed} failed`,\n directiveClass: directive.directiveClass,\n noun: directive.noun,\n nounLabel: nounText,\n failed: view.failed,\n total: view.applied + view.failed,\n },\n host.explainFailure,\n )}\n raw={view.message}\n />\n ) : (\n <span className=\"min-w-0\">{view.message ?? `Applied ${view.applied}`}</span>\n )}\n </span>\n {view.copies > 1 ? (\n <span\n className=\"shrink-0 text-muted-foreground\"\n data-apply-copies={view.copies}\n title={\n records.length > 0\n ? directive.directiveClass === \"create\"\n ? \"Links to the latest copy.\"\n : \"Links to the latest run.\"\n : undefined\n }\n >\n {directive.directiveClass === \"create\" ? `${view.copies} copies` : `Ran ${view.copies} times`}\n </span>\n ) : null}\n {records.map((record) => (\n <span key={`${record.noun}:${record.id}`} className=\"inline-flex min-w-0 items-center\">\n {host.renderRecord?.({\n ...record,\n fallback: recordFallbackName(label),\n context: \"applied\",\n trashed,\n })}\n </span>\n ))}\n {/* A failed item was never ledgered, so a plain re-apply retries only\n it. A clean tally offers \"Run again\" — the one way past the\n ledger's dedup, asked in words that say it runs a second time. */}\n <button\n type=\"button\"\n disabled={askingAgain}\n onClick={() => void handleApply(!bad)}\n className=\"inline-flex shrink-0 items-center gap-1 whitespace-nowrap rounded px-1 py-0.5 text-muted-foreground hover:bg-accent hover:text-accent-foreground disabled:opacity-50\"\n data-apply-action={bad ? \"retry\" : \"run-again\"}\n >\n <RotateCcwIcon className=\"h-3 w-3\" />\n {bad ? \"Retry\" : \"Run again\"}\n </button>\n </span>\n );\n }\n\n if (view.status === \"checking\") {\n return (\n <span\n className=\"inline-flex h-6 w-6 items-center justify-center text-muted-foreground\"\n role=\"status\"\n aria-label=\"Checking whether this already ran\"\n data-apply-state=\"checking\"\n >\n <LoaderIcon className=\"h-3.5 w-3.5 animate-spin\" />\n </span>\n );\n }\n\n if (view.status === \"finishing\") {\n return (\n <span\n className=\"inline-flex items-center gap-1 text-xs text-muted-foreground\"\n role=\"status\"\n data-apply-state=\"finishing\"\n >\n <LoaderIcon className=\"h-3.5 w-3.5 animate-spin\" />\n Finishing…\n </span>\n );\n }\n\n // THE CONFIRM OPENS WITH THE RECORD IN HAND (G10B review, 2026-10-02: the\n // first update confirm of a session took ~2 s). An update/delete's confirm\n // reads the records it names; pointing at (or focusing) Apply starts that\n // read through the host's `readRecord`, so a host that keeps a recent read\n // hands the confirm the record instead of a second round trip.\n const warm = () => {\n const read = host.readRecord;\n if (!read || !TARGETING_CLASSES.has(directive.directiveClass)) return;\n for (const item of items) {\n const id = itemRecordId(item);\n if (id) void read({ noun: directive.noun, id }).catch(() => null);\n }\n };\n\n // A delete LOOKS like one before the click, not only inside the confirm\n // (reviewer, 2026-10-02: the Delete card's Apply was the same neutral grey\n // as a create's).\n const destructive = directive.directiveClass === \"delete\";\n // NOTHING TO CHANGE, SHOWN BEFORE THE CLICK (G6A review, 2026-10-02): an\n // update that sets no field still offered a full-weight \"Update\". The control\n // stays live — validation offers, never blocks — but reads muted, with why.\n const muted = nothingToChange && view.status === \"idle\";\n return (\n <span className=\"flex min-w-0 flex-wrap items-center justify-end gap-x-2 gap-y-1\">\n {/* A button never wraps its label: the REASON wraps, the button holds. */}\n {muted ? (\n <span className=\"min-w-0 text-xs text-muted-foreground\" data-apply-nothing=\"\">\n Nothing to change\n </span>\n ) : null}\n <button\n type=\"button\"\n onClick={() => void handleApply()}\n onPointerEnter={warm}\n onFocus={warm}\n disabled={view.status === \"applying\" || view.status === \"asking\" || items.length === 0}\n data-apply-tone={muted ? \"muted\" : destructive ? \"destructive\" : \"default\"}\n title={muted ? \"Applying it changes nothing.\" : undefined}\n className={`inline-flex shrink-0 items-center gap-1 whitespace-nowrap rounded-md border px-2 py-1 text-xs font-medium disabled:opacity-50 ${\n muted\n ? \"border-border/60 bg-background text-muted-foreground hover:bg-accent\"\n : destructive\n ? \"border-destructive/50 bg-background text-destructive hover:bg-destructive/10\"\n : \"border-border bg-background hover:bg-accent\"\n }`}\n >\n {view.status === \"applying\" ? (\n <LoaderIcon className=\"h-3.5 w-3.5 animate-spin\" />\n ) : (\n <PlayIcon className=\"h-3.5 w-3.5\" />\n )}\n {view.status === \"applying\"\n ? `Applying${itemCount ? ` ${itemCount} ${itemCount === 1 ? \"item\" : \"items\"}` : \"\"}…${elapsed ? ` ${elapsed}s` : \"\"}`\n : label}\n </button>\n {view.status === \"error\" ? (\n <span\n className=\"inline-flex max-w-sm items-start gap-1 text-xs text-destructive\"\n data-apply-state=\"error\"\n >\n <AlertIcon className=\"mt-0.5 h-3.5 w-3.5 shrink-0\" />\n <FailureNotice\n words={failureWords(\n {\n raw: view.message,\n directiveClass: directive.directiveClass,\n noun: directive.noun,\n nounLabel: nounText,\n },\n host.explainFailure,\n )}\n raw={view.message}\n />\n </span>\n ) : null}\n </span>\n );\n}\n\n/**\n * What failed and what to do, in plain words — and the technical text behind\n * \"Details\" for whoever debugs it. Never the raw text as the sentence.\n */\nfunction FailureNotice({\n words,\n raw,\n}: {\n words: { what: string; next: string; details?: string };\n raw: string | null;\n}) {\n const [open, setOpen] = useState(false);\n // The host's worded details replace the raw text only when there IS raw text.\n const detail = raw?.trim() ? (words.details?.trim() || raw.trim()) : \"\";\n return (\n <span className=\"flex min-w-0 flex-col gap-0.5\" data-apply-failure>\n <span className=\"min-w-0\">\n {words.what} {words.next}\n {detail ? (\n <button\n type=\"button\"\n onClick={() => setOpen((v) => !v)}\n aria-expanded={open}\n className=\"ml-1 whitespace-nowrap underline underline-offset-2 hover:no-underline\"\n data-apply-failure-details-toggle\n >\n {open ? \"Hide details\" : \"Details\"}\n </button>\n ) : null}\n </span>\n {open && detail ? (\n <span\n className=\"block max-w-sm select-text break-words font-mono text-[11px] text-muted-foreground\"\n data-apply-failure-details\n >\n {detail}\n </span>\n ) : null}\n </span>\n );\n}\n\nexport default ApplyDirectiveButton;\n","/**\n * WHAT A DIRECTIVE ITEM WILL DO TO AN EXISTING RECORD — for the card, the\n * confirm dialog, and anything else that must say it before the click.\n *\n * WHY (reviewer, 2026-09-30): an Update card and a Delete card showed each item\n * as \"Item\" — they never named the record they would change, and an Update card\n * never said what it would change. The item-summary helpers name a thing to be\n * CREATED from its own fields; an update or delete item carries the TARGET's id\n * and, for an update, the NEW values — so its \"title\" field is the new title,\n * not the name of the record being changed. Naming the target is the host's\n * live lookup (`DirectiveHost.renderRecord`); what changes is right here.\n *\n * Law: common-docs/policies/no-dead-ends.md — the sentence\n * names what changes.\n */\n\nimport { humanizeIdentifier } from \"@ai-matrx/kit/text-case\";\nimport { itemTitle } from \"@ai-matrx/content-ir\";\n\n/** Classes whose items point at an EXISTING record by `id`. */\nexport const TARGETING_CLASSES: ReadonlySet<string> = new Set([\"update\", \"delete\"]);\n\n/** Never a change: identity and plumbing. */\nconst NOT_A_CHANGE = new Set<string>([\"__kind\", \"id\"]);\n\n/**\n * How long a changed value may read before it is shortened. A value someone\n * must judge — a title, a status, a date — is always whole (G8A review: a 60\n * cap plus CSS truncation cut \"Review4 tasks…\" on a phone); only a body of\n * prose longer than this is shortened, whole on hover and in View/Copy.\n */\nexport const CHANGE_VALUE_MAX = 280;\n\n/** The id of the existing record an update/delete item targets, or null. */\nexport function itemRecordId(item: Record<string, unknown>): string | null {\n const id = item.id;\n if (typeof id === \"string\" && id.trim()) return id.trim();\n if (typeof id === \"number\") return String(id);\n return null;\n}\n\n/** \"due_date\" → \"Due Date\" — THE humanizer; underscores read as developer output. */\nexport function fieldLabel(key: string): string {\n return humanizeIdentifier(key) || key;\n}\n\n/**\n * THE ONE FIELD-LABEL RULE for a directive — card rows, card facts and the\n * host's confirm: the noun's title column reads \"Title\" whatever it is stored\n * as (a workbook's `workbook_name`, a note's `label`), every other field reads\n * through THE humanizer. A new workbook card said \"workbook name\" while its\n * confirm said \"Title\" (G8A review, 2026-10-02).\n */\nexport function directiveFieldLabel(key: string, titleColumn: string | null | undefined): string {\n return titleColumn && key === titleColumn ? \"Title\" : fieldLabel(key);\n}\n\n/**\n * The app's word for ONE stored value of ONE field — \"incomplete\" on a task\n * reads \"Inbox\", \"high\" reads \"High\". The host answers it for its pick-list\n * fields; null → the value as stored.\n */\nexport type DirectiveValueWord = (field: string, value: string) => string | null;\n\n/**\n * The name a NEW item carries, or null when it has none — the one rule the card\n * and a host's confirm share. `itemTitle`'s last resort (\"Item\", \"Item 2 of 3\")\n * is a placeholder, never a name: a create with an empty title used to ask\n * \"Create project Item?\" and its card row read \"Item\" (G10B review, 2026-10-02).\n */\nexport function itemOwnName(item: Record<string, unknown>, titleColumn: string | null): string | null {\n // With two items the last resort is exactly \"Item 1 of 2\"; a real name wins first.\n const probe = itemTitle(item, titleColumn, 0, 2);\n return probe === \"Item 1 of 2\" ? null : probe;\n}\n\n/** What a nameless new item is called — said as such, never a placeholder name. */\nexport const NO_TITLE_WORD = \"No title\";\n\n/** How an empty value reads — before or after, on the card and in the confirm. */\nexport const EMPTY_VALUE_WORD = \"None\";\n\n\n/**\n * What a record is called when its name cannot be read: its TYPE (\"Task\").\n * Never its id, in any slot — text, tooltip or screen-reader label. It used to\n * be \"Task a8a00001\", and a link to a record that no longer exists hovered\n * \"Open Task a8a00001\" (G10B review, 2026-10-02). The host says WHY the name is\n * missing (not found, no access) beside it.\n */\nexport function recordFallbackName(nounLabel: string): string {\n return nounLabel.trim() || \"Record\";\n}\n\n/** One value as a row reads it: shortened, the whole of it, and whether it is empty. */\nexport interface ChangeValue {\n value: string;\n full: string;\n clears: boolean;\n}\n\nexport interface ItemChange extends ChangeValue {\n key: string;\n /** \"Due date\". */\n label: string;\n /**\n * What the field holds NOW, when the host could read the record — so an\n * update reads \"old → new\", never just the new value (reviewer, 2026-10-02).\n * Absent when the current record is unknown.\n */\n before?: ChangeValue;\n /** True when the record already holds exactly this value — nothing changes. */\n same?: boolean;\n}\n\n/** One value, described for a change row (`value` shortened, `full` whole). */\nexport function describeChangeValue(value: unknown, word?: (value: string) => string | null): ChangeValue {\n return describeValue(value, word);\n}\n\nconst EMPTY: ChangeValue = { value: EMPTY_VALUE_WORD, full: EMPTY_VALUE_WORD, clears: true };\n\nfunction describeValue(value: unknown, word?: (value: string) => string | null): ChangeValue {\n if (value === null || value === undefined) return EMPTY;\n if (typeof value === \"string\") {\n const trimmed = value.trim();\n if (!trimmed) return EMPTY;\n // ONE VALUE, ONE WORD (G8A review, 2026-10-02: \"Status incomplete →\n // completed\"). A value of a pick-list field reads as the app's word for it\n // — the host knows which fields are pick-lists and their words; anything\n // else (free text, a slug) is shown exactly as written.\n const named = word?.(trimmed) ?? null;\n if (named) return { value: named, full: named, clears: false };\n const oneLine = trimmed.replace(/\\s+/g, \" \");\n const shown = oneLine.length > CHANGE_VALUE_MAX ? `${oneLine.slice(0, CHANGE_VALUE_MAX - 1)}…` : oneLine;\n return { value: shown, full: trimmed, clears: false };\n }\n if (typeof value === \"number\" || typeof value === \"boolean\") {\n return { value: String(value), full: String(value), clears: false };\n }\n if (Array.isArray(value)) {\n const n = value.length;\n const text = n === 0 ? EMPTY_VALUE_WORD : `${n} ${n === 1 ? \"entry\" : \"entries\"}`;\n return { value: text, full: safeJson(value), clears: n === 0 };\n }\n const n = Object.keys(value as object).length;\n const text = n === 0 ? EMPTY_VALUE_WORD : `${n} ${n === 1 ? \"field\" : \"fields\"}`;\n return { value: text, full: safeJson(value), clears: n === 0 };\n}\n\nfunction safeJson(value: unknown): string {\n try {\n return JSON.stringify(value, null, 2);\n } catch {\n return String(value);\n }\n}\n\nfunction sameValue(a: unknown, b: unknown): boolean {\n if (a === b) return true;\n if (a === null || a === undefined || b === null || b === undefined) {\n // An empty string and a missing value both read \"None\".\n const emptyA = a === null || a === undefined || a === \"\";\n const emptyB = b === null || b === undefined || b === \"\";\n return emptyA && emptyB;\n }\n if (typeof a === \"object\" || typeof b === \"object\") return safeJson(a) === safeJson(b);\n return false;\n}\n\n/**\n * Every field an UPDATE item sets, in the order the item carries them — ALL of\n * them, never a sample: a person approving an overwrite sees the whole of it.\n *\n * Pass `current` — the record as it is now (`DirectiveHost.readRecord`) — and\n * each change also carries what it REPLACES (`before`) and whether it changes\n * anything at all (`same`). A field the record does not carry gets no `before`.\n */\nexport interface ItemChangesOptions {\n /**\n * The noun's title column (catalog `title_column` — `nounTitleColumn`). It is\n * labelled \"Title\" whatever it is called: a note's title is stored in\n * `label`, and the confirm said \"Label\" while the form said \"Title\"\n * (reviewer, 2026-10-02). The same rule the directive builder's form uses.\n */\n titleColumn?: string | null;\n /** The app's word for a stored value (`DirectiveHost.valueLabel`, bound to the noun). */\n valueWord?: DirectiveValueWord | null;\n}\n\nexport function itemChanges(\n item: Record<string, unknown>,\n current?: Record<string, unknown> | null,\n options: ItemChangesOptions = {},\n): ItemChange[] {\n const out: ItemChange[] = [];\n const titleColumn = options.titleColumn ?? null;\n for (const [key, raw] of Object.entries(item)) {\n if (NOT_A_CHANGE.has(key)) continue;\n const label = directiveFieldLabel(key, titleColumn);\n // The title is a name, never a token to translate.\n const valueWord = options.valueWord;\n const word =\n key === titleColumn || !valueWord ? undefined : (v: string) => valueWord(key, v);\n const change: ItemChange = { key, label, ...describeValue(raw, word) };\n if (current && Object.prototype.hasOwnProperty.call(current, key)) {\n change.before = describeValue(current[key], word);\n change.same = sameValue(current[key], raw);\n }\n out.push(change);\n }\n return out;\n}\n\n/**\n * 🚨 AN UPDATE THAT WOULD CHANGE NOTHING SAYS SO (G11B review, 2026-10-07: the\n * confirm listed every field \"(no change)\", Apply stayed full-weight, and the\n * run ended \"Updated task. Ran 2 times\"). True when the item sets no field, or\n * when the record was read and EVERY field already holds its new value. A field\n * whose current value is unknown counts as a change — doubt never mutes Apply.\n * ONE rule for the card and the host's confirm.\n */\nexport function changesNothing(changes: ReadonlyArray<ItemChange>): boolean {\n return changes.every((change) => change.same === true);\n}\n","\"use client\";\n\n/**\n * THE RECORD AS IT IS NOW — read through the host's `readRecord` seam, so an\n * update row (and the host's own confirm) can say what each field REPLACES.\n *\n * 🚨 RE-READ WHENEVER THE RECORD CHANGES (G7, 2026-10-02). It used to be read\n * ONCE per `noun:id`: after Update card A applied, Update card B naming the same\n * record — its row, and a confirm whose body stayed mounted between questions —\n * still said A's OLD value was the old value (\"G6A renamed target\" while the\n * database held \"G6A second rename\"). Every apply now announces the records it\n * touched (`noteRecordChanged`, also the host's door for its own writers) and\n * every read keyed on that record's revision runs again. A host reader that\n * shares in-flight reads keys them by `recordRevision(id)` too, so a read\n * started before the write is never handed to a reader asking after it.\n *\n * A pure hook over a reader FUNCTION rather than the directive-host context:\n * the confirm dialog renders in the host's global dialog layer, outside every\n * `DirectiveHostProvider`, and must read the same values the card does.\n */\n\nimport { useEffect, useState, useSyncExternalStore } from \"react\";\nimport type { DirectiveRecordRef } from \"./directive-host\";\n\nexport type RecordValuesStatus = \"idle\" | \"loading\" | \"ready\" | \"unavailable\";\n\nexport interface RecordValues {\n /** The record's fields now, or null until (or unless) they are read. */\n values: Record<string, unknown> | null;\n status: RecordValuesStatus;\n}\n\nexport type RecordReader = (ref: DirectiveRecordRef) => Promise<Record<string, unknown> | null>;\n\n/**\n * One change counter per record id — bumped by every write this page makes.\n * ONE store per page, not per bundle: every entry of this package (`.`,\n * `./directives`, …) is built self-contained, so module state would be a\n * SEPARATE counter per entry — an apply announced through one entry was never\n * seen by a reader imported through another (found adopting 0.19.0). The store\n * lives in a `Symbol.for` slot on `globalThis`, shared by every copy.\n */\ninterface RevisionStore {\n revisions: Map<string, number>;\n listeners: Set<() => void>;\n}\nconst STORE_SLOT = Symbol.for(\"@ai-matrx/content-ir-react/record-revisions\");\nfunction revisionStore(): RevisionStore {\n const slots = globalThis as unknown as Record<symbol, RevisionStore | undefined>;\n let store = slots[STORE_SLOT];\n if (!store) {\n store = { revisions: new Map(), listeners: new Set() };\n slots[STORE_SLOT] = store;\n }\n return store;\n}\nconst { revisions, listeners } = revisionStore();\n\n/** How many times this page has changed record `id` (0 = never). */\nexport function recordRevision(id: string): number {\n return revisions.get(id) ?? 0;\n}\n\n/**\n * Record `id` just changed (an apply wrote it, or any other writer on the page).\n * Every `useRecordValues` naming it reads it again.\n */\nexport function noteRecordChanged(id: string): void {\n if (!id) return;\n revisions.set(id, recordRevision(id) + 1);\n for (const listener of listeners) listener();\n}\n\nfunction subscribeRevisions(listener: () => void): () => void {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n}\n\n/** The live revision of record `id`, re-rendering when it changes. */\nexport function useRecordRevision(id: string): number {\n return useSyncExternalStore(\n subscribeRevisions,\n () => recordRevision(id),\n () => 0,\n );\n}\n\nexport function useRecordValues(\n read: RecordReader | undefined,\n ref: DirectiveRecordRef | null,\n): RecordValues {\n const revision = useRecordRevision(ref?.id ?? \"\");\n // The revision is part of the key: a change to the record is a fresh read,\n // and nothing read before it is shown as \"now\" while the new read runs.\n const key = ref && read ? `${ref.noun}:${ref.id}#${revision}` : \"\";\n const [result, setResult] = useState<{ key: string } & RecordValues>({\n key: \"\",\n values: null,\n status: \"idle\",\n });\n\n useEffect(() => {\n if (!key || !read) return;\n const split = key.indexOf(\":\");\n const target: DirectiveRecordRef = {\n noun: key.slice(0, split),\n id: key.slice(split + 1, key.lastIndexOf(\"#\")),\n };\n let live = true;\n setResult({ key, values: null, status: \"loading\" });\n read(target)\n .then((values) => {\n if (!live) return;\n setResult({ key, values, status: values ? \"ready\" : \"unavailable\" });\n })\n .catch(() => {\n if (!live) return;\n // Not knowing the old value is not an error the person must handle:\n // the row says only what changes, exactly as it did before this seam.\n setResult({ key, values: null, status: \"unavailable\" });\n });\n return () => {\n live = false;\n };\n }, [key, read]);\n\n if (!key) return { values: null, status: \"idle\" };\n if (result.key !== key) return { values: null, status: \"loading\" };\n return { values: result.values, status: result.status };\n}\n","/**\n * THE WORDS A FAILED APPLY SHOWS A PERSON.\n *\n * A card used to print the server's text as its sentence — e.g.\n * \"unknown / non-writable noun 'task'. Writable: [...]\" (G5 review,\n * 2026-10-02). A person needs WHAT failed and WHAT TO DO, in plain words; the\n * technical text is for whoever debugs it, behind a Details toggle. The host\n * may name a failure it recognises (`DirectiveHost.explainFailure`); otherwise\n * these verb-aware defaults answer.\n */\nimport type { DirectiveFailure, DirectiveFailureWords } from \"./directive-host\";\n\nconst PAST: Record<string, string> = {\n create: \"created\",\n update: \"updated\",\n delete: \"deleted\",\n};\n\n/** The card's own words for a failure the host did not name. */\nexport function defaultFailureWords(failure: DirectiveFailure): DirectiveFailureWords {\n const verbed = PAST[failure.directiveClass] ?? \"applied\";\n const noun = failure.nounLabel.trim().toLowerCase() || \"item\";\n if (failure.failed && failure.total && failure.total > 1) {\n return {\n what: `${failure.failed} of ${failure.total} weren't ${verbed}.`,\n next: \"Retry to try those again.\",\n };\n }\n return {\n what: `The ${noun} wasn't ${verbed}.`,\n next: \"Try again in a moment.\",\n };\n}\n\n/** The host's words when it names this failure, else the default. */\nexport function failureWords(\n failure: DirectiveFailure,\n explain?: (failure: DirectiveFailure) => DirectiveFailureWords | null,\n): DirectiveFailureWords {\n return explain?.(failure) ?? defaultFailureWords(failure);\n}\n","/**\n * The handful of glyphs the directive cards need, as inline SVG. This package\n * depends on no icon library (see the FEATURE boundary); the paths are the\n * Lucide set's (ISC), so the cards look identical to a Lucide-using host.\n */\n\nimport type { ReactElement, SVGProps } from \"react\";\n\ntype IconProps = SVGProps<SVGSVGElement>;\n\nfunction Svg({ children, ...props }: IconProps) {\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth={2}\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n {...props}\n >\n {children}\n </svg>\n );\n}\n\nexport const FilePlusIcon = (p: IconProps) => (\n <Svg {...p}>\n <path d=\"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4\" />\n <path d=\"M14 2v4a2 2 0 0 0 2 2h4\" />\n <path d=\"M3 15h6\" />\n <path d=\"M6 12v6\" />\n </Svg>\n);\nexport const PencilIcon = (p: IconProps) => (\n <Svg {...p}>\n <path d=\"M12 20h9\" />\n <path d=\"M16.376 3.622a1 1 0 0 1 3.002 3.002L7.368 18.635a2 2 0 0 1-.855.506l-2.872.838a.5.5 0 0 1-.62-.62l.838-2.872a2 2 0 0 1 .506-.854z\" />\n </Svg>\n);\nexport const TrashIcon = (p: IconProps) => (\n <Svg {...p}>\n <path d=\"M3 6h18\" />\n <path d=\"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6\" />\n <path d=\"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2\" />\n <line x1=\"10\" x2=\"10\" y1=\"11\" y2=\"17\" />\n <line x1=\"14\" x2=\"14\" y1=\"11\" y2=\"17\" />\n </Svg>\n);\nexport const PlayIcon = (p: IconProps) => (\n <Svg {...p}>\n <polygon points=\"6 3 20 12 6 21 6 3\" />\n </Svg>\n);\nexport const WebhookIcon = (p: IconProps) => (\n <Svg {...p}>\n <path d=\"M18 16.98h-5.99c-1.1 0-1.95.94-2.48 1.9A4 4 0 0 1 2 17c.01-.7.2-1.4.57-2\" />\n <path d=\"m6 17 3.13-5.78c.53-.97.1-2.01-.4-2.96A4 4 0 0 1 14 5.5c.63.42 1.13 1 1.44 1.66\" />\n <path d=\"m12 6 3.13 5.73C15.66 12.7 16.9 13 18 13a4 4 0 0 1 0 8\" />\n </Svg>\n);\nexport const BoxesIcon = (p: IconProps) => (\n <Svg {...p}>\n <path d=\"M2.97 12.92A2 2 0 0 0 2 14.63v3.24a2 2 0 0 0 .97 1.71l3 1.8a2 2 0 0 0 2.06 0L12 19v-5.5l-5-3-4.03 2.42Z\" />\n <path d=\"m7 16.5-4.74-2.85\" />\n <path d=\"m7 16.5 5-3\" />\n <path d=\"M7 16.5v5.17\" />\n <path d=\"M12 13.5V19l3.97 2.38a2 2 0 0 0 2.06 0l3-1.8a2 2 0 0 0 .97-1.71v-3.24a2 2 0 0 0-.97-1.71L17 10.5l-5 3Z\" />\n <path d=\"m17 16.5-5-3\" />\n <path d=\"m17 16.5 4.74-2.85\" />\n <path d=\"M17 16.5v5.17\" />\n <path d=\"M7.97 4.42A2 2 0 0 0 7 6.13v4.37l5 3 5-3V6.13a2 2 0 0 0-.97-1.71l-3-1.8a2 2 0 0 0-2.06 0l-3 1.8Z\" />\n <path d=\"M12 8 7.26 5.15\" />\n <path d=\"m12 8 4.74-2.85\" />\n <path d=\"M12 13.5V8\" />\n </Svg>\n);\nexport const ChevronDownIcon = (p: IconProps) => (\n <Svg {...p}>\n <path d=\"m6 9 6 6 6-6\" />\n </Svg>\n);\nexport const ChevronRightIcon = (p: IconProps) => (\n <Svg {...p}>\n <path d=\"m9 18 6-6-6-6\" />\n </Svg>\n);\nexport const MaximizeIcon = (p: IconProps) => (\n <Svg {...p}>\n <polyline points=\"15 3 21 3 21 9\" />\n <polyline points=\"9 21 3 21 3 15\" />\n <line x1=\"21\" x2=\"14\" y1=\"3\" y2=\"10\" />\n <line x1=\"3\" x2=\"10\" y1=\"21\" y2=\"14\" />\n </Svg>\n);\nexport const LoaderIcon = (p: IconProps) => (\n <Svg {...p}>\n <path d=\"M21 12a9 9 0 1 1-6.219-8.56\" />\n </Svg>\n);\n/** Lucide `rotate-ccw` — \"Run again\". */\nexport const RotateCcwIcon = (p: IconProps) => (\n <Svg {...p}>\n <path d=\"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8\" />\n <path d=\"M3 3v5h5\" />\n </Svg>\n);\nexport const CheckCircleIcon = (p: IconProps) => (\n <Svg {...p}>\n <circle cx=\"12\" cy=\"12\" r=\"10\" />\n <path d=\"m9 12 2 2 4-4\" />\n </Svg>\n);\nexport const AlertIcon = (p: IconProps) => (\n <Svg {...p}>\n <path d=\"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3\" />\n <path d=\"M12 9v4\" />\n <path d=\"M12 17h.01\" />\n </Svg>\n);\n\n/**\n * The icon for a side-effect directive card. THE CLASS LEADS: on a card whose\n * job is \"authorize this write\", the first thing to see is whether this\n * CREATES, CHANGES, or DELETES. A noun override exists only where the platform\n * has a settled visual identity for the thing — agents are a Webhook.\n */\nconst AGENT_NOUNS = new Set([\"create_agent\", \"create_agent_definition\", \"agent\"]);\n\nexport function classIcon(directiveClass: string, noun: string): (p: IconProps) => ReactElement {\n if (directiveClass === \"action\" && AGENT_NOUNS.has(noun)) return WebhookIcon;\n switch (directiveClass) {\n case \"create\":\n return FilePlusIcon;\n case \"update\":\n return PencilIcon;\n case \"delete\":\n return TrashIcon;\n default:\n return PlayIcon;\n }\n}\n","\"use client\";\n\n/**\n * The card for a SIDE-EFFECT directive in content — create / update / delete /\n * action. One card for every shape the server can register, so a person is\n * never asked to approve a write they cannot identify.\n *\n * WHY IT EXISTS (Arman, 2026-08-26): the floor it replaced gave \"a name and\n * then an apply button, which essentially tells the user to click apply and\n * conduct a potentially destructive action without any clue as to what this\n * thing is.\"\n *\n * THE DESIGN:\n * - Say what it IS, from authority — the catalog's own words for the title,\n * the noun's title column for each item, never a guess.\n * - Facts, not prose — a few scalar chips; nesting goes to the panel.\n * - Read before you approve — `View` opens the item through the host's seam,\n * which wraps the item's OWN kind component (THE DIRECTIVE⇄KIND SEAM).\n * - Copy is table stakes, at the batch and at the item (host chrome).\n * - Apply stays exactly where it was — the host's confirm seam.\n *\n * NEVER RETURNS NULL — a shape with no items degrades to a stated line.\n */\n\nimport { useEffect, useState } from \"react\";\nimport {\n asKindInstance,\n directiveDisplay,\n itemFacts,\n itemSubtitle,\n nounLabel,\n nounTitleColumn,\n type DecodedDirective,\n} from \"@ai-matrx/content-ir\";\nimport {\n ApplyDirectiveButton,\n readsApplyLedger,\n type DirectiveApplyPhase,\n} from \"./ApplyDirectiveButton\";\nimport {\n TARGETING_CLASSES,\n changesNothing,\n directiveFieldLabel,\n itemChanges,\n itemOwnName,\n itemRecordId,\n NO_TITLE_WORD,\n recordFallbackName,\n type DirectiveValueWord,\n type ItemChange,\n} from \"./item-changes\";\nimport { useRecordValues } from \"./record-values\";\nimport { useDirectiveHost, type DirectiveHost } from \"./directive-host\";\nimport { ChevronDownIcon, ChevronRightIcon, MaximizeIcon, classIcon } from \"./icons\";\n\nexport interface SideEffectDirectiveCardProps {\n directive: DecodedDirective;\n}\n\n/** The host's value words for one record type, or null when it has none. */\nexport function directiveValueWord(\n host: Pick<DirectiveHost, \"valueLabel\">,\n noun: string,\n): DirectiveValueWord | null {\n const valueLabel = host.valueLabel;\n return valueLabel ? (field, value) => valueLabel({ noun, field, value }) : null;\n}\n\nfunction omitKey(item: Record<string, unknown>, key: string): Record<string, unknown> {\n const { [key]: _omitted, ...rest } = item;\n return rest;\n}\n\n/** How many items render as rows before the rest collapse behind a toggle. */\nconst ROWS_BEFORE_FOLD = 3;\n\nfunction ItemRow({\n directive,\n item,\n index,\n total,\n phase,\n onNothing,\n}: {\n directive: DecodedDirective;\n item: Record<string, unknown>;\n index: number;\n total: number;\n phase: DirectiveApplyPhase;\n onNothing?: ((index: number, nothing: boolean) => void) | undefined;\n}) {\n const host = useDirectiveHost();\n // An update/delete item points at a record that ALREADY EXISTS: name THAT\n // record (its live name, through the host), never the item's own fields —\n // an update's `title` is the NEW title — and never \"Item\".\n const recordId = TARGETING_CLASSES.has(directive.directiveClass) ? itemRecordId(item) : null;\n if (recordId) {\n return (\n <TargetRow\n directive={directive}\n item={item}\n recordId={recordId}\n index={index}\n phase={phase}\n onNothing={onNothing}\n />\n );\n }\n const titleColumn = nounTitleColumn(directive.noun, host.nouns);\n // A nameless item SAYS it has no title — never \"Item\" posing as its name.\n const ownName = itemOwnName(item, titleColumn);\n const title = ownName ?? NO_TITLE_WORD;\n const subtitle = itemSubtitle(item);\n // The title column IS the title — never repeated as a fact — and every\n // fact is labelled and worded exactly as the confirm and the forms do.\n const valueWord = directiveValueWord(host, directive.noun);\n const facts = itemFacts(titleColumn ? omitKey(item, titleColumn) : item).map((fact) => ({\n ...fact,\n label: directiveFieldLabel(fact.key, titleColumn),\n value: valueWord?.(fact.key, fact.value) ?? fact.value,\n }));\n const kind = host.itemKind?.(directive.slug) ?? null;\n const display = directiveDisplay(directive.directiveClass, directive.noun, host.nouns);\n const openItem = host.openItem;\n\n const body = (\n <>\n {/* THE IDENTITY WINS THE SPACE: the title keeps its intrinsic width and the facts give way; on a phone (no facts) it wraps to two lines, never cut to one (G11B). */}\n <span\n className={`min-w-0 line-clamp-2 font-medium [overflow-wrap:anywhere] sm:shrink-0 sm:truncate ${ownName ? \"text-foreground\" : \"italic text-muted-foreground\"}`}\n data-item-name=\"\"\n data-item-untitled={ownName ? undefined : \"\"}\n >\n {title}\n </span>\n <span className=\"hidden min-w-0 flex-1 items-baseline gap-2 overflow-hidden sm:flex\">\n {facts.map((fact) => (\n <span key={fact.key} className=\"truncate text-[11px] text-muted-foreground\" data-item-fact={fact.key}>\n {fact.label} <span className=\"text-foreground/80\">{fact.value}</span>\n </span>\n ))}\n </span>\n {subtitle && facts.length === 0 ? (\n <span className=\"hidden truncate text-[11px] text-muted-foreground sm:inline\">{subtitle}</span>\n ) : null}\n {openItem ? (\n <MaximizeIcon className=\"ml-auto h-3 w-3 shrink-0 text-muted-foreground\" />\n ) : null}\n </>\n );\n\n return (\n <div className=\"flex items-center gap-2 py-1 text-xs\">\n {openItem ? (\n <button\n type=\"button\"\n onClick={() =>\n openItem({\n // Stamped so the panel's kind pipeline types it from its own first key.\n item: asKindInstance(item, kind) ?? item,\n itemKind: kind,\n title,\n subtitle: `${display.title} · item ${index + 1} of ${total}`,\n directive,\n index,\n total,\n })\n }\n className=\"flex min-w-0 flex-1 items-center gap-2 rounded px-1 py-0.5 text-left hover:bg-accent hover:text-accent-foreground\"\n title=\"Open to read it\"\n >\n {body}\n </button>\n ) : (\n <span className=\"flex min-w-0 flex-1 items-center gap-2 px-1 py-0.5\">{body}</span>\n )}\n {host.renderCopy?.({\n label: ownName ?? `this ${nounLabel(directive.noun, host.nouns)}`,\n value: item,\n kind,\n size: \"xs\",\n })}\n </div>\n );\n}\n\n/**\n * THE CHANGE LIST — every field an update sets, as \"Label old → new\" when the\n * record's current value is known, \"Label → new\" when it is not. ONE component\n * for the card row and the host's confirm dialog, so the two can never read\n * differently (reviewer, 2026-10-02: the confirm showed only the new value).\n *\n * 🚨 A VALUE SOMEONE MUST JUDGE IS NEVER CUT (G8A review, 2026-10-02): on a\n * phone the card is ~230px and the row read \"Title Review… → Review4 tas…\".\n * Values wrap; below a 20rem container the label, the old value and the new\n * value stack, one per line. Measured on the list's own width (a container\n * query), so a narrow window panel on a desktop gets the same stacking.\n */\nexport function DirectiveChangeList({\n changes,\n className,\n}: {\n changes: ItemChange[];\n className?: string;\n}) {\n if (changes.length === 0) {\n return (\n <p className={`text-[11px] text-muted-foreground${className ? ` ${className}` : \"\"}`}>\n Sets no fields — nothing would change.\n </p>\n );\n }\n return (\n <ul className={`@container space-y-1${className ? ` ${className}` : \"\"}`} data-directive-changes=\"\">\n {changes.map((change) => {\n const before = change.before && !change.same ? change.before : null;\n return (\n <li\n key={change.key}\n className=\"flex min-w-0 flex-col text-[11px] @xs:flex-row @xs:flex-wrap @xs:items-baseline @xs:gap-x-1.5\"\n title={\n before\n ? `${change.label}: ${before.full} → ${change.full}`\n : `${change.label} → ${change.full}`\n }\n data-change-key={change.key}\n >\n <span className=\"shrink-0 text-muted-foreground\">{change.label}</span>\n {before ? (\n <span\n className=\"min-w-0 text-muted-foreground line-through [overflow-wrap:anywhere]\"\n data-change-before=\"\"\n >\n {before.value}\n </span>\n ) : null}\n <span className=\"flex min-w-0 items-baseline gap-1.5\">\n <span aria-hidden className=\"shrink-0 text-muted-foreground\">\n →\n </span>\n <span\n className={`min-w-0 [overflow-wrap:anywhere] ${change.clears ? \"italic text-muted-foreground\" : \"text-foreground\"}`}\n data-change-after=\"\"\n >\n {change.value}\n </span>\n {change.same ? <span className=\"shrink-0 text-muted-foreground\">(no change)</span> : null}\n </span>\n </li>\n );\n })}\n </ul>\n );\n}\n\n/**\n * ONE row for an item that changes an EXISTING record: the record by its live\n * name (a way to open it, through `renderRecord`), then — for an update —\n * every field it sets, \"Due date 2026-10-01 → 2026-10-15\" (the old value read\n * through `readRecord` when the host can).\n */\nfunction TargetRow({\n directive,\n item,\n recordId,\n index,\n phase,\n onNothing,\n}: {\n directive: DecodedDirective;\n item: Record<string, unknown>;\n recordId: string;\n index: number;\n phase: DirectiveApplyPhase;\n onNothing?: ((index: number, nothing: boolean) => void) | undefined;\n}) {\n const host = useDirectiveHost();\n const fallback = recordFallbackName(nounLabel(directive.noun, host.nouns));\n const isUpdate = directive.directiveClass === \"update\";\n // 🚨 THE OLD VALUE OF A CHANGE THAT HAPPENED COMES FROM THE RECORD OF THE\n // CHANGE (G6A review, 2026-10-02). A live read after the apply answers the NEW\n // value, so an applied card said \"Title → X (no change)\". Live values are read\n // only while the block is still open; once applied, the server's `before` is\n // the old value — and without it the row says only what each field was set to.\n // Until the ledger answers, neither: no comparison is better than a wrong one.\n const readsLive = isUpdate && phase.phase === \"open\";\n const live = useRecordValues(\n readsLive ? host.readRecord : undefined,\n readsLive ? { noun: directive.noun, id: recordId } : null,\n );\n const compareTo =\n phase.phase === \"applied\" ? (phase.before?.[index] ?? null) : readsLive ? live.values : null;\n const changes = isUpdate\n ? itemChanges(item, compareTo, {\n titleColumn: nounTitleColumn(directive.noun, host.nouns),\n valueWord: directiveValueWord(host, directive.noun),\n })\n : [];\n // The card mutes Apply when every row would change nothing — known only once\n // the record is read and the block is still open.\n const nothing = readsLive && live.values !== null && changesNothing(changes);\n useEffect(() => {\n onNothing?.(index, nothing);\n }, [onNothing, index, nothing]);\n const name = host.renderRecord ? (\n host.renderRecord({ noun: directive.noun, id: recordId, fallback, context: \"row\" })\n ) : (\n <span className=\"line-clamp-2 min-w-0 font-medium text-foreground [overflow-wrap:anywhere]\">{fallback}</span>\n );\n\n return (\n <div className=\"py-1 text-xs\" data-directive-target={recordId}>\n <div className=\"flex min-w-0 items-center gap-2\">\n <span className=\"flex min-w-0 flex-1 items-center gap-1 px-1\">{name}</span>\n {/* THE LABEL NEVER NAMES AN ID (G9): \"this task\" until the host reads the name. */}\n {host.renderCopy?.({\n label: `this ${nounLabel(directive.noun, host.nouns).toLowerCase()}`,\n value: item,\n size: \"xs\",\n record: { noun: directive.noun, id: recordId },\n })}\n </div>\n {isUpdate ? <DirectiveChangeList changes={changes} className=\"mt-0.5 px-1\" /> : null}\n </div>\n );\n}\n\nexport function SideEffectDirectiveCard({ directive }: SideEffectDirectiveCardProps) {\n const host = useDirectiveHost();\n const [expanded, setExpanded] = useState(false);\n const items = directive.items;\n const total = items.length;\n const display = directiveDisplay(directive.directiveClass, directive.noun, host.nouns);\n const Icon = classIcon(directive.directiveClass, directive.noun);\n\n // What the Apply control knows about this block — the rows draw an applied\n // change from its record, never from a live re-read.\n const [phase, setPhase] = useState<DirectiveApplyPhase>(() =>\n readsApplyLedger(host, directive) ? { phase: \"pending\" } : { phase: \"open\" },\n );\n // An update that changes nothing — it sets no field, or the record already\n // holds every value (read by its row) — says so before the click (G11B).\n const [nothingAt, setNothingAt] = useState<Readonly<Record<number, boolean>>>({});\n const noteNothing = (index: number, nothing: boolean) =>\n setNothingAt((prev) => (prev[index] === nothing ? prev : { ...prev, [index]: nothing }));\n const nothingToChange =\n directive.directiveClass === \"update\" &&\n total > 0 &&\n items.every((item, index) => itemChanges(item).length === 0 || nothingAt[index] === true);\n\n const shown = expanded ? items : items.slice(0, ROWS_BEFORE_FOLD);\n const hidden = total - shown.length;\n\n return (\n <div className=\"my-3 rounded-md border border-border bg-card px-2.5 py-1.5\" data-directive={directive.slug}>\n <div className=\"flex flex-wrap items-center gap-x-2 gap-y-1\">\n <Icon className=\"h-3.5 w-3.5 shrink-0 text-muted-foreground\" />\n <span className=\"text-sm font-medium text-foreground\">{display.title}</span>\n {display.family ? <span className=\"text-xs text-muted-foreground\">{display.family}</span> : null}\n <span className=\"text-xs tabular-nums text-muted-foreground\">\n {total} {total === 1 ? \"item\" : \"items\"}\n </span>\n {/* Copy and Apply share ONE row that never wraps: after a run the tally\n wraps inside itself, so the copy icon never sits alone (G18). */}\n <div className=\"ml-auto flex min-w-0 max-w-full items-start justify-end gap-1\" data-directive-actions=\"\">\n {host.renderCopy?.({ label: display.title, value: directive.shell, size: \"icon\" })}\n <ApplyDirectiveButton\n directive={directive}\n itemCount={total}\n onPhase={setPhase}\n nothingToChange={nothingToChange}\n />\n </div>\n </div>\n\n {total === 0 ? (\n // Stated, never silent: an empty batch is a real (and suspicious) state.\n <p className=\"mt-1 text-xs text-muted-foreground\">No items — nothing would be written.</p>\n ) : (\n <div className=\"mt-0.5 divide-y divide-border/60\">\n {shown.map((item, i) => (\n <ItemRow\n key={i}\n directive={directive}\n item={item}\n index={i}\n total={total}\n phase={phase}\n onNothing={noteNothing}\n />\n ))}\n </div>\n )}\n\n {hidden > 0 || expanded ? (\n <button\n type=\"button\"\n onClick={() => setExpanded((v) => !v)}\n className=\"mt-0.5 inline-flex items-center gap-1 whitespace-nowrap rounded px-1 py-0.5 text-[11px] text-muted-foreground hover:text-foreground\"\n >\n {expanded ? <ChevronDownIcon className=\"h-3 w-3\" /> : <ChevronRightIcon className=\"h-3 w-3\" />}\n {expanded ? \"Show less\" : `Show ${hidden} more`}\n </button>\n ) : null}\n </div>\n );\n}\n\nexport default SideEffectDirectiveCard;\n","\"use client\";\n\n/**\n * The neutral \"we could not render this, but we will NEVER hide it\" card —\n * THE PREFIX FLOOR of the Kind Directives route.\n *\n * THE RULE THIS ENFORCES: a registered directive renderer must never return\n * `null`. `DirectiveRender` renders a renderer's output verbatim, so a `null`\n * deletes the assistant's whole message block (2026-07-26: a 70KB content plan\n * vanished exactly that way). When a renderer cannot draw its rich view, it\n * renders THIS instead: named by class and noun, itemised by count, with Apply\n * when the class is a side effect and the host can apply.\n */\n\nimport { directiveDisplay, type DecodedDirective } from \"@ai-matrx/content-ir\";\nimport { ApplyDirectiveButton } from \"./ApplyDirectiveButton\";\nimport { useDirectiveHost } from \"./directive-host\";\nimport { BoxesIcon } from \"./icons\";\n\nexport interface DirectiveFallbackCardProps {\n directive: DecodedDirective;\n /** Short, human explanation of why the rich renderer degraded. */\n reason?: string;\n}\n\nexport function DirectiveFallbackCard({ directive, reason }: DirectiveFallbackCardProps) {\n const host = useDirectiveHost();\n const count = directive.items.length;\n const display = directiveDisplay(directive.directiveClass, directive.noun, host.nouns);\n return (\n <div className=\"my-3 inline-flex flex-wrap items-center gap-2 rounded-md border border-border bg-muted px-2.5 py-1 text-sm\">\n <BoxesIcon className=\"h-3.5 w-3.5 shrink-0 text-muted-foreground\" />\n <span className=\"text-foreground\">{display.title}</span>\n {display.family ? <span className=\"text-muted-foreground\">· {display.family}</span> : null}\n <span className=\"text-muted-foreground\">\n · {count} {count === 1 ? \"item\" : \"items\"}\n </span>\n {reason ? <span className=\"text-muted-foreground\">· {reason}</span> : null}\n <ApplyDirectiveButton directive={directive} />\n </div>\n );\n}\n\nexport default DirectiveFallbackCard;\n","\"use client\";\n\n/**\n * The card for a directive whose JSON has NOT finished arriving — the\n * provisional tier of `DirectiveRender`.\n *\n * WHY IT EXISTS (found live 2026-09-25, the agent builder's\n * `directive_v1_action_create_agent_definition` in the agent run window): an\n * agent streams a directive as one JSON document, `__kind` first. Every splitter\n * already types the block as a directive from its first bytes\n * (`looksLikeDirectiveHead`), but the decoder can only honour a COMPLETE shell,\n * so for the whole stream `DirectiveRender` fell to its raw `<pre>` — the person\n * watched a wall of JSON grow and then snap into a card at the last byte.\n *\n * The head already says what this is (class + noun), so the card says it from\n * the first bytes, from the same catalog words the finished card uses:\n *\n * - STREAMING — \"Create agent definition · writing…\". No Apply: nothing is\n * applicable until the shell is whole.\n * - NOT STREAMING, still undecodable — the document was cut off (a model hit\n * its output limit, a stream died). Said plainly, never dressed as\n * \"writing…\" forever, with what did arrive one click away.\n *\n * NEVER RETURNS NULL.\n */\n\nimport { directiveDisplay, parseDirectiveSlug } from \"@ai-matrx/content-ir\";\nimport { useDirectiveHost } from \"./directive-host\";\nimport { BoxesIcon, classIcon } from \"./icons\";\n\n/** A head whose slug has fully arrived: `{\"__kind\":\"directive_v1_…\"` + closing quote. */\nconst COMPLETE_SLUG_RE = /^\\{\\s*\"__kind\"\\s*:\\s*\"([^\"]+)\"/;\n\n/** The directive slug of a partial document, once its closing quote has arrived. */\nexport function provisionalDirectiveSlug(content: string): string | null {\n const match = content.trimStart().match(COMPLETE_SLUG_RE);\n return match?.[1] ?? null;\n}\n\nexport interface DirectiveProvisionalCardProps {\n /** The partial fence body as received so far. */\n content: string;\n /**\n * Whether the document may still be arriving. `false` means the stream is\n * over and the document never completed — the card says it was cut off.\n */\n streaming: boolean;\n className?: string | undefined;\n}\n\nexport function DirectiveProvisionalCard({ content, streaming, className }: DirectiveProvisionalCardProps) {\n const host = useDirectiveHost();\n const slug = provisionalDirectiveSlug(content);\n const known = slug ? parseDirectiveSlug(slug) : null;\n const display = known ? directiveDisplay(known.directiveClass, known.noun, host.nouns) : null;\n const Icon = known ? classIcon(known.directiveClass, known.noun) : BoxesIcon;\n const title = display?.title ?? \"Structured action\";\n\n return (\n <div\n className={`my-3 rounded-md border border-border bg-card px-2.5 py-1.5${className ? ` ${className}` : \"\"}`}\n data-directive={slug ?? undefined}\n data-directive-state={streaming ? \"streaming\" : \"incomplete\"}\n >\n <div className=\"flex flex-wrap items-center gap-x-2 gap-y-1\">\n <Icon className=\"h-3.5 w-3.5 shrink-0 text-muted-foreground\" />\n <span className=\"text-sm font-medium text-foreground\">{title}</span>\n {display?.family ? <span className=\"text-xs text-muted-foreground\">{display.family}</span> : null}\n {streaming ? (\n <span className=\"inline-flex items-center gap-1.5 text-xs text-muted-foreground\" role=\"status\">\n <span className=\"h-1.5 w-1.5 animate-pulse rounded-full bg-primary\" aria-hidden />\n Writing…\n </span>\n ) : (\n <span className=\"text-xs text-destructive\" role=\"status\">\n Cut off before it finished — nothing can be applied.\n </span>\n )}\n </div>\n {streaming ? null : (\n <details className=\"mt-1 text-xs text-muted-foreground\">\n <summary className=\"cursor-pointer select-none hover:text-foreground\">Show what arrived</summary>\n <pre className=\"mt-1 max-h-64 overflow-auto whitespace-pre-wrap break-all rounded bg-muted px-2 py-1 text-[11px]\">\n {content}\n </pre>\n </details>\n )}\n </div>\n );\n}\n\nexport default DirectiveProvisionalCard;\n","\"use client\";\n\n/**\n * DirectiveRender — THE renderer for anything whose `__kind` is a reserved\n * directive slug, on every AI Matrx UI.\n *\n * Pipeline (one pipeline, mirroring the backend):\n * 0. THE PROVISIONAL TIER — a head that names a directive but does not\n * decode yet renders `DirectiveProvisionalCard` (\"writing…\" while\n * streaming, \"cut off\" once the host says the stream ended).\n * 1. `tryDecodeDirectiveContent` → the two-key shell (a stored 4-key fence is\n * translated inside the decoder). Not a directive (bad JSON / no reserved\n * `__kind`) → raw <pre>, never throws. An unhonourable shell is REPORTED\n * through the host and falls to raw — a render seam must not take a whole\n * message block down over one fence, and must never go silent.\n * 2. `getDirectiveRenderer` → exact slug, else the CLASS prefix rule (the\n * host's registrations). Found → render it.\n * 3. THE SIDE-EFFECT TIER — every create / update / delete / action shape\n * renders the side-effect card, so a person is never asked to approve a\n * write they cannot identify.\n * 4. THE FLOOR — a class nothing registers still shows the fallback card.\n * Never null, never silent.\n *\n * Position decides capability: in content only `reference`/`secret` resolve;\n * a side-effect directive in prose is a card with an explicit Apply, never\n * executed on sight.\n */\n\nimport { looksLikeDirectiveHead, tryDecodeDirectiveContent } from \"@ai-matrx/content-ir\";\nimport { DirectiveScopeProvider, useDirectiveHost } from \"./directive-host\";\nimport { DirectiveFallbackCard } from \"./DirectiveFallbackCard\";\nimport { DirectiveProvisionalCard } from \"./DirectiveProvisionalCard\";\nimport { getDirectiveRenderer } from \"./registry\";\nimport { SideEffectDirectiveCard } from \"./SideEffectDirectiveCard\";\n\nexport interface DirectiveRenderProps {\n /** The fence body (JSON string) or an already-parsed shell / value. */\n content: unknown;\n className?: string;\n /**\n * Whether the document may still be arriving. A host that knows its stream\n * has ended passes `false`, so an undecodable directive head is shown as CUT\n * OFF rather than \"writing…\" forever. Omitted = it may still be arriving.\n */\n streaming?: boolean;\n /**\n * The conversation this directive renders in (a chat message). Applies and\n * ledger reads key on it — the same namespace an agent proposal's Approve\n * uses — so one action can never apply twice through two doors. Omit in a\n * person's own content. Overrides any enclosing `DirectiveScopeProvider`.\n */\n conversationId?: string | null;\n}\n\n/**\n * A document that parses is WHOLE: if it still does not decode, it is a\n * malformed directive (already reported by the decoder), never one \"still\n * arriving\" — only a genuinely unfinished document gets the provisional tier.\n */\nfunction isWholeJson(content: string): boolean {\n try {\n JSON.parse(content);\n return true;\n } catch {\n return false;\n }\n}\n\nexport function DirectiveRender({ conversationId, ...props }: DirectiveRenderProps) {\n if (conversationId === undefined) return <DirectiveRenderInner {...props} />;\n return (\n <DirectiveScopeProvider conversationId={conversationId}>\n <DirectiveRenderInner {...props} />\n </DirectiveScopeProvider>\n );\n}\n\nfunction DirectiveRenderInner({ content, className, streaming }: Omit<DirectiveRenderProps, \"conversationId\">) {\n const host = useDirectiveHost();\n const directive = tryDecodeDirectiveContent(content, (message) => {\n const line = `[kind-directives] ${message}`;\n if (host.reportError) host.reportError(line);\n else console.error(line);\n });\n\n if (!directive) {\n // THE PROVISIONAL TIER: the head already names a directive but the shell is\n // not whole yet (mid-stream) or never became whole (cut off). The class and\n // noun are known from the first bytes — say what it is, never show the\n // growing JSON as if it were the answer.\n if (typeof content === \"string\" && looksLikeDirectiveHead(content) && !isWholeJson(content)) {\n return (\n <DirectiveProvisionalCard content={content} streaming={streaming !== false} className={className} />\n );\n }\n const raw = typeof content === \"string\" ? content : JSON.stringify(content, null, 2);\n return (\n <pre\n className={`my-3 overflow-x-auto rounded-md border border-border bg-muted px-3 py-2 text-xs text-muted-foreground${className ? ` ${className}` : \"\"}`}\n >\n {raw}\n </pre>\n );\n }\n\n const Renderer = getDirectiveRenderer(directive);\n if (Renderer) return <Renderer directive={directive} />;\n if (directive.parsed.executes) return <SideEffectDirectiveCard directive={directive} />;\n return <DirectiveFallbackCard directive={directive} />;\n}\n\nexport default DirectiveRender;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC4BA,mBAA0D;AAgRtD;AApBJ,IAAM,2BAAuB,4BAAoC,IAAI;AAOrE,IAAM,4BAAwB,4BAA8B,CAAC,CAAC;AAQvD,SAAS,uBAAuB;AAAA,EACrC;AAAA,EACA;AACF,GAA6C;AAC3C,SACE,4CAAC,sBAAsB,UAAtB,EAA+B,OAAO,EAAE,gBAAgB,kBAAkB,KAAK,GAC7E,UACH;AAEJ;AAEO,SAAS,oBAAoC;AAClD,aAAO,yBAAW,qBAAqB;AACzC;AAOO,SAAS,sBAAsB,EAAE,MAAM,SAAS,GAA+B;AACpF,SAAO,4CAAC,qBAAqB,UAArB,EAA8B,OAAO,MAAO,UAAS;AAC/D;AAEA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AAA,QACC,WAAW,wGAAwG,YAAY,IAAI,SAAS,KAAK,EAAE;AAAA,QAElJ;AAAA;AAAA,IACH;AAAA,EAEJ;AAEA,QAAM,WAAW,qBAAqB,SAAS;AAC/C,MAAI,SAAU,QAAO,6CAAC,YAAS,WAAsB;AACrD,MAAI,UAAU,OAAO,SAAU,QAAO,6CAAC,2BAAwB,WAAsB;AACrF,SAAO,6CAAC,yBAAsB,WAAsB;AACtD;","names":["import_react","import_content_ir","import_content_ir","nounLabel","n","text","import_react","import_jsx_runtime","import_jsx_runtime","label","read","import_react","import_content_ir","import_jsx_runtime","import_content_ir","import_jsx_runtime","import_content_ir","import_jsx_runtime","import_content_ir","import_jsx_runtime"]}