# declarative <ai-prompt> cells & pinning studio

- Status: `experiment`
- Track: [reactive prompt architectures](https://aifoc.us/labs/reactive-prompts/)
- Layer: 5. Local Compute, Wasm & Zero-Framework UI
- Updated: 1 December 2026
- Live demo: https://reactive-prompt-cells.kinlan-test.workers.dev
- Source: https://github.com/PaulKinlan/reactive-prompt-cells

## Inspired by

- [the projects behind my ai focus posts](https://aifoc.us/projects/)
- [web components are packaging for ai-generated ui](https://aifoc.us/elements/)

## Hypothesis

- **Claim:** Encoding prompt dependencies and execution gates (`auto`, `debounce`, `manual`, `frozen`, `switch`/`exhaust`) as `<ai-prompt>` custom elements eliminates listener leaks, exposes topology in DevTools, and protects manual human edits.
- **Confirms it:** Detaching an `<ai-prompt>` node aborts active fetches via `disconnectedCallback()`, identical prompt+config hashes hit content-addressed cache, and upstream changes enter `conflict` instead of overwriting pinned cells.
- **Falsifies or bounds it:** HTML attribute bindings become unwieldy for nested object schemas or deeply branching array rows compared to keyed JS IVM collections.

> **Why this exists:** Imperative `effect()` subscriptions hide dependency edges inside JavaScript closures, leak listeners across re-renders, trigger unwanted token spend on every keystroke, and silently overwrite manual human edits when an upstream input changes. Treating every prompt as a spreadsheet cell encoded in HTML custom-element attributes makes the graph DevTools-inspectable, scopes cost policies (`auto`, `debounce`, `manual`, `frozen`), and preserves user edits via a `conflict` resolution state.


## What this lab tests

[Declarative Prompt Cells](https://reactive-prompt-cells.kinlan-test.workers.dev) ([GitHub](https://github.com/PaulKinlan/reactive-prompt-cells)) implements `<ai-prompt>` Custom Elements wired with content-addressed caching (`hash(promptText, config)`), `disconnectedCallback()` `AbortController` teardown, human pin/conflict/merge controls, and keyed Collection IVM feature tables.

```html
<ai-prompt id="cell-brief" watch="#product, #audience" mode="auto" policy="switch">
  Draft an executive brief for ${#product} aimed at ${#audience}.
</ai-prompt>
<ai-prompt id="cell-faq" watch="#cell-brief" mode="manual" policy="exhaust">
  Generate customer FAQs from ${#cell-brief}.
</ai-prompt>
```


## Open questions to iterate on

- What HTML element API (`ElementInternals`, form participation, `shadowRoot`) makes `<ai-prompt>` drop cleanly into existing `<form>` flows?
- What three-way merge UX works best when an upstream input changes underneath a human-pinned cell?

## Iteration log

- **2026-12-01:** Implemented `<ai-prompt>` Web Component runtime, content-addressed cache, keep/accept/merge conflict states, and keyed Collection IVM table.
- **2026-12-01:** Moved the live `<ai-prompt>` workbench ahead of setup docs, added CSP-safe DOM syntax highlighting across setup snippets, live DOM snapshots, and wire/cache/scrubber inspectors, hardened 700px embed wrapping, and enforced no-cache headers across HTML, CSS, and JS assets.

## Primitives tested

- `Custom Elements (<ai-prompt>)`
- `Content-Addressed Cache`
- `Human Override Pinning`
- `Keyed Collection IVM`

## Connected labs in other tracks

- [canonical multimodal ui](https://aifoc.us/labs/hypermedia-and-islands/canonical-multimodal-ui/) — Explores declarative HTML custom elements and `FormData` contracts for both humans and tools.

---
Canonical: https://aifoc.us/labs/reactive-prompts/reactive-prompt-cells/
