PersonafileSpecification
On this page1. Design Goal & Terminology2. Deterministic Rendering & Runtime Pipeline3. PFDOM Schema (Single Document Only)4. PersonaBrowser Runtime Schema, Subsystems & Rules5. End-to-End Walkthrough (Book #42 → borrow() → Loan #1 → go_back())

Personafile Renderer, PFDOM & PersonaBrowser Specification

Status: Proposed specification — Working Draft 0.1
Maturity: Experimental; client-side runtime companion to Personafile Format specification
Informed by: HTML_DOM_to_PFOM_Comparison.md (US-090, updated by US-091, US-092) and Agentic_MVC_Personafile_View_Conformance_0.1.md
Scope: Deterministic client-side rendering of a validated PERSONAFILE/1.0 document into PFDOM (Personafile Document Object Model), plus the PersonaBrowser runtime shell (tabs, history_stack, open_persona, go_back, trail, runTools, ResourceLoader, CookieJar, VirtualConsole, and safe re-fetch rules)—without modifying PFS 1.0 wire syntax.


1. Design Goal & Terminology

Core Invariant: Raw PERSONAFILE/1.0 parsing, validation, and <pf:embed> composition MUST be performed deterministically by personafile-core before Personafile Renderer constructs a PFDOM. An LLM MUST NOT be used as the raw security/syntax parser.


2. Deterministic Rendering & Runtime Pipeline

  1. Fetch (PersonaBrowser.resourceLoader + cookieJar): ResourceLoader retrieves bytes from a URI (following redirects to establish canonical_uri, honoring Cache-Control/Vary, and keeping cookies, CSRF tokens, and API credentials in CookieJar outside PFDOM and LLM context).
  2. Parse & Compose (personafile-core): Validates the PERSONAFILE/1.0 envelope, resolves the post-redirect canonical URI in Provenance, and composes any <pf:embed> blocks under ResourceLoader cycle/depth/SSRF limits.
  3. Project (Personafile Renderer → PFDOM):
    • Identity & Prose → PFDOM.context_text: Emits Persona-ID, Name, canonical uri, trust="untrusted", and clean tag-free prose (replacing <pf:a> inline labels with readable link references and omitting raw <pf:form> XML boilerplate).
    • <pf:a pref="..."> → PFDOM.links: Resolves relative pref targets against the host document's Provenance.canonical_uri—except inside <pf:embed>, where relative <pf:a pref="..."> targets MUST resolve against the embedded document's own Provenance.canonical_uri.
    • <pf:form> (top-level only) → PFDOM.document_tools: Compiles each declared <pf:form> into a typed callable Tool bound to (method, resolved_action, params). Embedded <pf:form> and <pf:api> elements inside <pf:embed> MUST NOT enter PFDOM.document_tools and are logged to VirtualConsole.
  4. Mount & Inject (PersonaBrowser):
    • Places the new PFDOM into active_tab.active_pfdom and assigns a fresh active_tab.mount_id.
    • Applies the runTools policy ("none" | "confirm" | "auto") to compute mounted_tools = runtime.navigation_tools + gated(active_tab.active_pfdom.document_tools, runTools).
    • Passes [System Rules] + [active_tab.active_pfdom.context_text] + [runtime.trail] and tools = mounted_tools to the LLM. Document-derived prose (context_text), document_tools descriptions, and trail summaries MUST all be treated as untrusted model input, never promoted to System Rules.

3. PFDOM Schema (Single Document Only)

A PFDOM instance represents one rendered PERSONAFILE/1.0 document and has no browsing or history fields:

{
  "uri": "string (canonical post-redirect URI)",
  "persona_id": "string",
  "name": "string",
  "trust": "untrusted",
  "cache_policy": "string | null",
  "context_text": "string",
  "links": [
    { "label": "string", "url": "string" }
  ],
  "document_tools": [
    {
      "name": "string",
      "description": "string",
      "method": "GET | POST | LOCAL",
      "action": "string | null",
      "params": {}
    }
  ]
}

4. PersonaBrowser Runtime Schema, Subsystems & Rules

PersonaBrowser wraps PFDOM with browsing, tab, history, execution policy, and session state:

{
  "session_id": "string",
  "run_tools": "none | confirm | auto",
  "active_tab_id": "string",
  "tabs": {
    "tab-1": {
      "mount_id": "string",
      "history_stack": ["string"],
      "active_pfdom": "<PFDOM>"
    }
  },
  "navigation_tools": ["open_persona(url)", "go_back()"],
  "trail": ["string"]
}

4.1 PersonaBrowser Subsystems (jsdom-Inspired)

4.2 Navigation, Snapshot & Conflict Rules

  1. Single-Tab Baseline & Optional Multi-Tab Mode:
    • Single-tab mode (tabs containing one default tab, e.g. "tab-1") is the required baseline so LLM context stays focused.
    • A Runtime MAY support multiple tabs and active_tab_id. When multi-tab mode is active, ONLY tabs[active_tab_id].active_pfdom.document_tools (plus navigation_tools) MUST be mounted for the LLM so background tabs cannot be triggered unintentionally.
  2. SPA-Style In-Place Replacement & Mount-Bound Dispatch:
    • Every open_persona(url) or <pf:form> mutation response MUST replace tabs[active_tab_id].active_pfdom in place, mint a new mount_id, and recompute mounted_tools from scratch, unmounting all document_tools from the previous document.
    • Every pending tool call MUST bind to its originating (tab_id, mount_id). Both (tab_id, mount_id) MUST be rechecked after confirmation and immediately before dispatch; if either changed (e.g., navigation occurred while confirmation was open), the call MUST be aborted with no HTTP request sent. If an in-flight response arrives after mount_id has changed, it MUST be discarded and MUST NOT replace the newer active_pfdom.
    • runtime.trail retains compact user/assistant/action summaries (marked untrusted) and MUST NOT retain old PERSONAFILE/1.0 bodies or old unmounted tool schemas.
  3. Atomic History Commits, go_back(), and 304 Revalidation:
    • History mutations (push on navigation, pop on go_back()) MUST commit atomically with the newly rendered PFDOM.
    • Calling go_back() MUST fetch and validate the previous URI before popping tabs[active_tab_id].history_stack; if fetch or validation fails, history_stack remains unchanged.
    • ResourceLoader MAY send conditional revalidation (If-None-Match / If-Modified-Since) and accept 304 Not Modified on go_back() only when PersonaBrowser holds the validated cached response for that URI (and MUST still re-run Personafile Renderer / re-mount from scratch).
  4. Snapshots & Resume (.pfnav.json / Session Snapshot):
    • A Runtime MAY serialize session state (session_id, active_tab_id, history_stack, trail) to a snapshot file for pause/resume and auditability.
    • Snapshot files MUST NOT store session cookies, CSRF tokens, or credentials (HttpOnly-equivalent separation).
    • On resume, PersonaBrowser MUST fetch a fresh 200 response body from the server (304 is not permitted without an in-memory validated cache) and render a fresh PFDOM before mounting any tools.
  5. Error & Conflict View Updates (401 / 403 / 409):
    • On 401 or 403, active_pfdom MUST NOT disclose private state or mount privileged document_tools.
    • On 409 Conflict (e.g., stale borrow or renewal blocked by a waiting reservation), the Runtime replaces tabs[active_tab_id].active_pfdom with a newly rendered PFDOM containing the server's explanation and any recovery links (such as returning to the current entity view).

5. End-to-End Walkthrough (Book #42 → borrow() → Loan #1 → go_back())

Step 1 — open_persona("/books/42/")

Step 2 — borrow() (POST /books/42/borrow/ → 201 Created, Location: /loans/1/ → GET /loans/1/)

Step 3 — go_back() (fetches & validates "/books/42/" before popping "/loans/1/")

5.1 Conformance Test — Stale Confirmation After Navigation

  1. Under runTools: "confirm", request borrow() on Book #42 (tab-1, mount_id: "m-1").
  2. While the confirmation prompt is open, navigate away (open_persona("/library/")), advancing tab-1 to mount_id: "m-2".
  3. Approve the pending borrow() confirmation.
  4. Expected: PersonaBrowser detects m-1 != m-2 before dispatch, aborts the call, and sends no POST /books/42/borrow/.