CANONICAL MULTIMODAL SCHEMA · LAB EXPERIMENT

One Action Schema, Two Native Interfaces

Every mutation on this page is declared once in ACTION_DEFINITIONS (public/lib/canonical-schema.js). From that single frozen object, the runtime projects ARIA-accessible HTML <form> controls with declarative WebMCP attributes on the left and imperative registerTool() JSON schemas on the right, both executing through the same pure reducer and 64-bit FNV-1a state hash.

Problem & Hypothesis

Separate HTML forms and JSON tool schemas drift when enums, required fields, or length rules change. Generating both from one ACTION_DEFINITIONS map removes that divergence.

Confirm Signal

Dispatching an identical action through the HTML form UI or the headless WebMCP console runs the same shared reducer and produces byte-identical fnv1a64 state hashes and validation errors.

Falsify Signal

Multi-field cross-validation, conditional sub-fields, or visual layout constraints force UI-only overrides that break single-schema generation and split validation behavior.

Run Parity Verification

Execute steps 1 through 3 in order to test DOM-to-WebMCP state convergence and identical schema rejection.

MODALITY A · HUMAN UI

Declarative HTML Forms & Board

Active Action Schema Metadata

Live Task Board

0 active 0 archived

    MODALITY B · MACHINE TOOL API

    Headless WebMCP Tool Console

    Checking WebMCP…
    State Parity Counter INITIALIZED
    DOM State Hash fnv1a64:0000000000000000
    ===
    Tool State Hash fnv1a64:0000000000000000
    DOM mutations: 0 WebMCP calls: 0 Verified matches: 0 Rejection parity: n/a
    Validated against the identical validateActionArgs() contract used by HTML forms. Edge verification tests against the stateless seed state createInitialState().

    Action Trace Feed

    0 events

      Live Schema, Generated DOM & HTTP Wire Inspector

      Zero-duplication single source
      Derived WebMCP Tools & Draft 2020-12 JSON Schema (GET /api/schema)
      Generated Declarative <form> Markup & Dual-Track State Snapshot
      Edge Worker HTTP Wire Log (GET /api/schema & POST /api/validate-action)
      How This Is Set Up

      Single-Source Schema Architecture

      Each state transition is defined once in ACTION_DEFINITIONS (public/lib/canonical-schema.js). The browser runtime and Cloudflare Worker both import the exact same module to build semantic HTML forms, Draft 2020-12 JSON Schema, WebMCP tool descriptors, and stateless edge validation.

      Split definitions (drift risk)
      // Separate form markup, UI validator, and tool schema diverge over time
      function TaskForm() {
        return createEl("form", { onSubmit: validateHumanForm }, [titleInput, prioritySelect]);
      }
      
      const toolSchema = {
        name: "add_item",
        parameters: {
          type: "object",
          properties: { title: { type: "string" }, priority: { type: "string" } },
          required: ["title", "priority"], // Must be edited manually when form fields change
        },
        execute: (args) => legacyRestCall(args), // Parallel validator and state mutator
      };
      Single-source declaration (this lab)
      // public/lib/canonical-schema.js — shared by DOM forms, WebMCP tools, and Worker API
      export const ACTION_DEFINITIONS = Object.freeze({
        add_item: Object.freeze({
          name: "add_item",
          toolautosubmit: true,
          annotations: Object.freeze({ readOnlyHint: false, destructiveHint: false, idempotentHint: false }),
          fields: Object.freeze([
            Object.freeze({ name: "title", label: "Task Title", type: "string", required: true, minLength: 3, maxLength: 120 }),
            Object.freeze({ name: "priority", label: "Priority", type: "string", required: true, enum: ["low", "medium", "high", "critical"] }),
            Object.freeze({ name: "owner", label: "Owner Handle", type: "string", required: true, minLength: 2, maxLength: 32, default: "unassigned" }),
          ]),
        }),
      });
      // Runtime generates <form toolname="add_item"> and registers WebMCP tools from this map
      Complete Page Setup: Verbatim Schema, HTML Mount Points & Runtime Wiring

      Declarative Invoker Command triggers in public/index.html, verbatim add_item and update_priority definitions from public/lib/canonical-schema.js, and dual-track execution in public/app.js and src/worker.ts.

      <!-- 1. Page HTML Setup (public/index.html) -->
      <button type="button" class="btn btn-secondary" commandfor="reset-board-dialog" command="show-modal">
        Reset Board
      </button>
      <button type="button" id="schema-popover-trigger" commandfor="schema-popover" command="toggle-popover">
        Action Schema Rules
      </button>
      <div id="schema-popover" popover class="schema-popover">...</div>
      <div class="action-tabs" role="tablist" id="human-action-tabs"></div>
      <div id="human-form-stage" class="form-stage" aria-live="polite"></div>
      <select id="webmcp-tool-select"></select>
      <textarea id="webmcp-args-editor"></textarea>
      <dialog id="reset-board-dialog" class="modal-dialog">...</dialog>
      <script type="module" src="/app.js"></script>
      
      // 2. Complete ACTION_DEFINITIONS Entries (verbatim from public/lib/canonical-schema.js)
      export const ACTION_DEFINITIONS = Object.freeze({
        add_item: Object.freeze({
          name: "add_item",
          label: "Add Task Item",
          submitLabel: "Add Item",
          description: "Create a new task item in the board state with title, priority, and owner.",
          toolautosubmit: true,
          annotations: Object.freeze({
            readOnlyHint: false,
            destructiveHint: false,
            idempotentHint: false,
          }),
          exampleArgs: Object.freeze({
            title: "Audit WebMCP form parity",
            priority: "high",
            owner: "alex",
          }),
          fields: Object.freeze([
            Object.freeze({
              name: "title",
              label: "Task Title",
              type: "string",
              required: true,
              minLength: 3,
              maxLength: 120,
              default: "",
              placeholder: "e.g. Audit WebMCP form parity",
              description: "Summary of the work item (minimum 3 characters).",
            }),
            Object.freeze({
              name: "priority",
              label: "Priority",
              type: "string",
              required: true,
              enum: Object.freeze(["low", "medium", "high", "critical"]),
              default: "medium",
              description: "Triage severity level: low, medium, high, or critical.",
            }),
            Object.freeze({
              name: "owner",
              label: "Owner Handle",
              type: "string",
              required: true,
              minLength: 2,
              maxLength: 32,
              default: "unassigned",
              placeholder: "e.g. alex",
              description: "Assignee handle (minimum 2 characters, e.g. alex, sam, unassigned).",
            }),
          ]),
        }),
      
        update_priority: Object.freeze({
          name: "update_priority",
          label: "Update Priority",
          submitLabel: "Update Priority",
          description: "Update the priority level and optional workflow status of an existing task by ID.",
          toolautosubmit: true,
          annotations: Object.freeze({
            readOnlyHint: false,
            destructiveHint: false,
            idempotentHint: true,
          }),
          exampleArgs: Object.freeze({
            id: "TASK-001",
            priority: "critical",
            status: "in_progress",
          }),
          fields: Object.freeze([
            Object.freeze({
              name: "id",
              label: "Task ID",
              type: "string",
              required: true,
              minLength: 4,
              maxLength: 16,
              pattern: "^TASK-\\d{3,}$",
              default: "TASK-001",
              placeholder: "TASK-001",
              description: "Target task identifier matching TASK-NNN (e.g. TASK-001).",
            }),
            Object.freeze({
              name: "priority",
              label: "New Priority",
              type: "string",
              required: true,
              enum: Object.freeze(["low", "medium", "high", "critical"]),
              default: "high",
              description: "Updated priority level: low, medium, high, or critical.",
            }),
            Object.freeze({
              name: "status",
              label: "Workflow Status",
              type: "string",
              required: false,
              enum: Object.freeze(["open", "in_progress", "done"]),
              default: "",
              description: "Optional workflow status transition (open, in_progress, or done).",
            }),
          ]),
        }),
      });
      
      // 3. Page Bootstrap & Edge Wiring (public/app.js + src/worker.ts)
      import {
        ACTION_DEFINITIONS, coerceFormData, createInitialState,
        deriveJsonSchema, deriveWebMcpTools, executeAction, hashState, validateActionArgs,
      } from "/lib/canonical-schema.js";
      
      // Project <form toolname="..."> controls into #human-form-stage
      const form = createEl("form", {
        id: `human-form-${action.name}`, method: "post", action: "/api/validate-action",
        toolname: action.name, tooldescription: action.description, toolautosubmit: action.toolautosubmit,
      });
      // Derive Draft 2020-12 JSON Schema & register WebMCP tools on navigator.modelContext
      const jsonSchema = deriveJsonSchema();
      for (const toolMeta of deriveWebMcpTools()) {
        const toolDescriptor = { ...toolMeta, execute: (args) => handleWebMcpExecution(toolMeta.name, args) };
        polyfillContext.registerTool(toolDescriptor, { signal: appState.toolAbortController.signal });
        nativeContext?.registerTool?.(toolDescriptor, { signal: appState.toolAbortController.signal });
      }
      // Shared reducer + FNV-1a parity hash across DOM FormData, WebMCP JSON, and Worker API
      const domOutcome = executeAction(appState.domState, actionName, coerceFormData(actionName, new FormData(form)));
      const toolOutcome = executeAction(appState.toolState, toolName, rawArgs);
      const parityOk = hashState(domOutcome.state) === hashState(toolOutcome.state);
      // src/worker.ts: POST /api/validate-action returns { ok, valid, errors, nextStateHash: outcome.hash }
      Browser + Edge Parity Contract (FormData Coercion, WebMCP Fallback & FNV-1a Hashing)
      // public/app.js + src/worker.ts — shared reducer, FNV-1a parity hash, and WebMCP fallback
      for (const field of action.fields) {
        input.setAttribute("aria-describedby", hintId);
        input.setAttribute("toolparamdescription", field.description);
      }
      for (const toolMeta of deriveWebMcpTools()) {
        const tool = { ...toolMeta, execute: (args) => handleWebMcpExecution(toolMeta.name, args) };
        nativeContext?.registerTool?.(tool, { signal: appState.toolAbortController.signal });
      }
      // Human FormData and JSON tool payloads pass through coerceFormData() -> executeAction()
      const outcome = executeAction(state, actionName, coerceFormData(actionName, formData));
      // hashState(outcome.state) returns fnv1a64:<16-hex> parity across client & POST /api/validate-action
      Eliminated duplication

      Separate form validators, hand-maintained JSON Schema copies for automated tool callers, and mismatched client/server input rules are replaced by one shared module.

      Explicit wire contract

      Declarative HTML tool attributes (toolname, tooldescription, toolparamdescription, toolautosubmit), tool annotations, and deterministic fnv1a64 hashes make state equivalence testable.

      Platform gaps remaining

      Native navigator.modelContext.registerTool() and Invoker Commands (commandfor/command) remain behind preview flags or partial support, requiring a feature-detected CommandEvent and registry fallback in public/app.js.

      Runtime Boundary & Parity Flow

      public/lib/canonical-schema.js
      Canonical Multimodal Schema Architecture ACTION_DEFINITIONS branches symmetrically into Human HTML FormData controls on the left and WebMCP JSON tools on the right, merging back into validateActionArgs, reduceState, and FNV-1a hashState. ACTION_DEFINITIONS (Single Source) add_item · update_priority · assign_owner · archive_completed Human Modality: Semantic HTML Forms <form toolname="..."> + ARIA + :user-invalid + commandfor SubmitEvent → new FormData(form) → coerceFormData() Machine Modality: WebMCP JSON Tools deriveJsonSchema() + deriveWebMcpTools() → registerTool() Tool Invocation → structured JSON args → execute(args) validateActionArgs() → reduceState(state, action, args) → hashState() Parity Guarantee: hashState(domState) === hashState(toolState)

      Reset Both State Tracks?

      Restores both the Human DOM Track and the Headless WebMCP Track to createInitialState() so both hashes return to the baseline seed state.