agentleFS
indianicindianic/parelay/.claude/skills/widget-component/SKILL.md

widget-component

Skill2 starsChanged 4 months agoMITView on GitHub

Use when building any UI piece inside packages/widget — the embeddable vanilla-JS chat widget. Establishes the Shadow-DOM + tokens.css contract and bundle-size guardrails that keep the embed safe to drop on any host page.

The file

We split this skill into the rules it gives an agent

10 rules. About 0 are common, 4 are distinctive, and 6 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 6

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Import design tokens from @indianic/shared/design/tokens.css and inject the stylesheet into the Shadow root with <link> or constructable …

    line 21
  2. Very specific:

    Keep all state in a single store object (plain TS object behind a small getState/setState/subscribe API).

    line 22
  3. Distinctive:

    Use event delegation on the Shadow root for clicks.

    line 23
  4. Distinctive:

    Don't render outside Shadow DOM.

    line 31
  5. Very specific:

    Don't use innerHTML / insertAdjacentHTML with anything that touched a network payload, the host page, or visitor input.

    line 32
  6. Distinctive:

    Don't import React, lit-html, or any UI framework.

    line 33
  7. Very specific:

    Don't read or write localStorage for anything other than the visitor UUID.

    line 34
  8. Very specific:

    Don't bind global event listeners on window/document outside the widget's mount lifecycle — and always remove them in unmount().

    line 35
  9. Very specific:

    Don't console.log past Phase 0.

    line 36
  10. Distinctive:

    Don't load fonts from a third-party CDN at runtime.

    line 37

≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

widget-component

The widget is loaded via <script src="…widget.iife.js"> on host pages we don't control (indianic.com, careers, etc.). Anything that leaks from the widget — global names, styles, focus traps, console noise — is a bug. Defensive defaults beat clever ones here.

When to use

  • Touching any file in packages/widget/src/
  • Adding a new visitor-facing UI piece (bubble, panel, pre-chat form, chat scroller, video tile, file-share UI)
  • Wiring widget state, host-page integration, or any DOM observation

Skip for code that is purely shared (event types, design tokens) — that lives in packages/shared.

Do

  • Mount everything inside a single Shadow DOM root attached to a host <div> the widget injects into document.body. The Shadow host is the widget's only contact with the host page.
  • Import design tokens from @indianic/shared/design/tokens.css and inject the stylesheet into the Shadow root with <link> or constructable stylesheets. Reference tokens as CSS custom properties (var(--inic-paper) etc.).
  • Keep all state in a single store object (plain TS object behind a small getState/setState/subscribe API). No external state libs — they cost bytes and the widget should ship under 100KB gzipped.
  • Use event delegation on the Shadow root for clicks; do not attach a listener per button.
  • Persist only the visitor UUID to localStorage (key: indianic.visitor.id). Everything else is in-memory.
  • Build DOM with document.createElement + textContent + append. The host page is untrusted; user-supplied strings (visitor name, geo, messages) must never reach innerHTML.
  • Bundle to a single IIFE (vite build) that self-mounts on load. The IIFE entry creates window.IndianicWidget (read-only handle for the host page).
  • Honor prefers-reduced-motion — already routed through the token CSS layer; don't override.

Don't

  • Don't render outside Shadow DOM. Light-DOM injection will collide with host CSS.
  • Don't use innerHTML / insertAdjacentHTML with anything that touched a network payload, the host page, or visitor input. XSS vector.
  • Don't import React, lit-html, or any UI framework. Vanilla JS + small helpers only. If a pattern feels like it needs React, write it as a Web Component.
  • Don't read or write localStorage for anything other than the visitor UUID. Use the in-memory store.
  • Don't bind global event listeners on window/document outside the widget's mount lifecycle — and always remove them in unmount().
  • Don't console.log past Phase 0. Use a widgetLog() helper that is silenced in production builds.
  • Don't load fonts from a third-party CDN at runtime. Host fonts ourselves once Phase 5 ships; until then accept the system fallback.

One short example

// packages/widget/src/mount.ts
import tokensCss from '@indianic/shared/design/tokens.css?inline';

export function mount(host: HTMLElement = document.body) {
  const shadowHost = document.createElement('div');
  shadowHost.setAttribute('data-indianic-widget', '');
  host.appendChild(shadowHost);
  const root = shadowHost.attachShadow({ mode: 'open' });

  const style = new CSSStyleSheet();
  style.replaceSync(tokensCss);
  root.adoptedStyleSheets = [style];

  const bubble = document.createElement('button');
  bubble.type = 'button';
  bubble.className = 'bubble';
  bubble.setAttribute('aria-label', 'Open chat');
  bubble.textContent = '●';
  bubble.addEventListener('click', () => openPanel(root));
  root.append(bubble);
}

Reference

  • Aesthetic + tokens: packages/shared/src/design/README.md
  • Event schema (what to emit): packages/shared/src/events/schema.ts
  • Phase doc: dev-docs/phase-1-widget-mockup.md

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.