Documentation

AI Agent Authoring Guide

Explicit contract and hard rules for AI coding agents scaffolding custom TypeDock themes and sandboxed plugins.

TypeDock is designed so coding agents can build custom client themes and small extensions safely against an explicit contract — without risking server compromise or brittle runtime hacks.

Give this guide (along with themes/kinari/theme.json or plugins/social/plugin.js) as context when asking an AI coding agent to scaffold a TypeDock theme or plugin.


Building a Custom Theme with an AI Agent

Hard Rules (Contract)

  1. No server-side code: Only create theme.json, Pongo2 HTML templates under layouts/, partials/, and components/, and static assets under assets/.
  2. Declare every configurable token in theme.json: Expose brand colors, typography, and layout switches under settings.<group>.fields.<field> and reference them in CSS via var(--td-<group>-<field>).
  3. Use slots for composable regions: Declare named slots in theme.json (slots.<name>) instead of hardcoding sidebar/footer widgets so site editors can reorder components from Admin.
  4. Preserve base path compatibility: Always route theme asset URLs and links through the theme context helpers (so sites work identically at domain root / and subdirectories like /blog/).
  5. Keep markup accessible and fast: Prefer semantic HTML and clean CSS over heavy client-side JS bundles.

Suggested Starting Point

  • Inspect themes/default/ for the complete set of layout templates (base.html, archive.html, single.html, page.html, author.html, search.html, 404.html).
  • Inspect themes/kinari/ for a full example of theme.json settings, CSS variables, and slot-driven header/footer layouts.

Building a Drop-in JS Plugin with an AI Agent

Hard Rules (Contract)

  1. Sandbox-compatible ES only: Plugins execute in goja with strict timeouts. Do not rely on Node.js built-ins (fs, process, require of npm packages) or browser DOM globals.
  2. Use ctx.* host APIs exclusively: Use ctx.getOption / ctx.setOption for plugin settings, ctx.db for guarded queries, ctx.http for external API calls, and ctx.escapeHtml when returning HTML fragments.
  3. Declare capabilities explicitly: If replacing a shared contract (such as mail or captcha), declare "provides": ["..."] in plugin.json.
  4. Isolate admin UI: Register admin screens via ctx.registerAdminRoute + ctx.registerAdminMenu; set admin_csp in plugin.json if the iframe needs external script/frame origins.
  5. Fail gracefully: Always validate inputs and return structured error objects rather than throwing uncaught exceptions.

Suggested Reference Plugins

  • Editorial components & slots: plugins/social/ and plugins/advanced-blocks/
  • Forms & submissions storage: plugins/form/
  • URL redirect resolver: plugins/redirect/
  • Capability provider (provides: ["captcha"]): plugins/turnstile-captcha/
  • Custom mail transport (provides: ["mail"]): see docs/plugins/mail-provider.md