# Briefing Document: UCXL Browser with Temporal Navigation and Markdown Context Storage\n\nPhase 2B has completed. This briefing outlines a design for a browser that:\n- implements temporal navigation techniques native to the UCXL protocol\n- supports submitting Markdown content as context and storing it in the DHT\n- boots first in a local subnet with BZZZ software\n- considers a self-healing mechanism (whether implemented today or how to add it)\n\nThe document is written for the development team and product stakeholders. It emphasizes architecture, data models, workflows, security, testing, and deployment.\n\n---\n\n## 1. Executive Summary\n\n- Objective: Build a browser client that can:\n  - navigate document state over time using UCXL temporal capabilities\n  - publish Markdown context to the DHT with versioned metadata\n  - store and retrieve content efficiently and deterministically (content-addressable storage)\n  - run first on a local subnet using the BZZZ software gateway and self-healing concepts\n- Success metrics:\n  - Latency to fetch a historical state under 2 seconds on a typical local subnet\n  - 99.9% successful storage and retrieval of Markdown contexts in a pilot\n  - Intuitive temporal navigation UX (timeline/versions) with accurate state reconstruction\n  - Clear API surface for frontend and extensible backend modules\n\n---\n\n## 2. Scope\n\n- In Scope:\n  - Frontend browser UI for temporal navigation (timeline scrubber, version compare, diff view)\n  - UCXL temporal engine integration (state at a given time/version)\n  - Markdown submission pipeline (markdown -> context blob -> DHT storage)\n  - DHT integration (put/get, content addressing, version metadata)\n  - Local subnet bootstrap with BZZZ software (gateway/bridge to UCXL and DHT)\n  - Self-healing design concepts (anti-entropy, replication, repair hooks)\n  - Developer-facing API and data models\n- Out of Scope:\n  - Production-grade global routing beyond the local subnet\n  - Non-UCXL protocol features not required for debugging\n  - Advanced UI themes/branding beyond core usability\n\n---\n\n## 3. Reference Architecture\n\n- UI/Frontend\n  - Lightweight browser app (Electron/Chromium extension or web app) with:\n    - Timeline/Version Navigator\n    - Markdown editor + preview\n    - Context submission flow\n    - Version diff and compare UI\n- UCXL Temporal Engine\n  - Core logic to query, assemble, and render document state at a given time/version\n  - Traverses UCXL-backed DAGs of state changes\n- DHT Layer\n  - Content-addressable storage layer\n  - Put/get operations with metadata\n  - Versioned pointers (handles to previous versions)\n- BZZZ Gateway/Node\n  - Local gateway operating on the subnet\n  - Interfaces with UCXL and DHT\n  - Provides predictable, low-latency access for development\n- Context Store\n  - Markdown content stored as context blobs\n  - Metadata: title, author, timestamp, version, content hash, parent hash\n  - Optional front matter for additional metadata\n- Self-Healing Module (design/optional)\n  - Checksums, anti-entropy, background repair, replication policy\n  - Health dashboard and repair triggers\n\n---\n\n## 4. Temporal Navigation for UCXL\n\n### 4.1 Concept\nTemporal navigation enables debugging by allowing users to:\n- view document state as it existed at a given time\n- traverse a version DAG (branching/merging)\n- replay sequences of edits to reconstruct the state\n\n### 4.2 Data Model (Temporal)\n- DocumentRoot\n  - doc_id: string\n  - version: string (semantic version or UUID)\n  - timestamp: ISO8601 string\n  - parent_version: string|null\n  - state_pointer: multihash or DHT key for the serialized state\n  - metadata: { author, source, tags, ... }\n- StateDelta / Block\n  - Each change to the document is a delta/rooted change\n  - state_pointer may reference a blob or linked list of blocks\n- Timeline\n  - A directed acyclic graph (DAG) of versions\n  - Each node stores: version_id, timestamp, parent_ids, metadata\n  - UI renders as a chronological timeline with branches\n\n### 4.3 Workflow\n- To view state at time T:\n  - Query UCXL for the latest state up to T\n  - Traverse the version DAG to reconstruct the state\n- To compare two versions:\n  - Retrieve both state pointers\n  - Compute diff at the Markdown/text level (or at AST level)\n- To navigate branches:\n  - Expose branch/merge UI; allow selecting a branch head\n  - Resolve merges using a defined policy (e.g., last-writer-wins, CRDT-based merge hints)\n\n### 4.4 API Sketch\n- UCXL Temporal API (high level)\n  - GET /ucxl/state?doc_id=&at_time=\n  - GET /ucxl/state?doc_id=&version_id=\n  - GET /ucxl/diff?doc_id=&from_version=&to_version=\n- Internal data format accepted by the UI\n  - A normalized JSON state: { doc_id, version, timestamp, content: \"<markdown or AST>\", metadata }\n\n---\n\n## 5. Markdown Context Submission to the DHT\n\n### 5.1 Ingestion Pipeline\n1. Editor collects Markdown content from the user.\n2. Optional front matter is parsed/validated (title, author, date, tags).\n3. Markdown content is sanitized (to remove script tags and unsafe constructs if user-provided).\n4. The content is converted into a stable blob or a set of chunks (chunking strategy optional but recommended for large docs).\n5. Compute a content hash (e.g., SHA-256) for the blob(s).\n6. Create a Context Blob that stores:\n   - content_hash, size, chunk metadata (if chunked)\n   - metadata: doc_id, version, author, timestamp, parent_version, source_uri\n   - optional signature for authenticity\n7. Publish to DHT:\n   - Put the Context Blob with a key derived from its content_hash\n   - Store pointers to parent version(s) and to the document root/version\n8. Return to UI:\n   - New version_id, content_hash, and DHT keys\n\n### 5.2 Data Model\n- MarkdownContextBlob\n  - blob_id: string (content_hash)\n  - doc_id: string\n  - version: string\n  - timestamp: ISO8601\n  - parent_version: string|null\n  - content_hashes: [string] // if chunked\n  - content_size: int\n  - mime_type: \"text/markdown\"\n  - metadata: { author, source, title, tags }\n  - signature: string|null\n\n- DocumentRootVersion\n  - doc_id\n  - version\n  - state_pointer: string (reference to ContextBlob or a root pointer)\n  - timestamp\n  - parent_versions: [string]\n\n### 5.3 Security Considerations\n- Signatures: optional digital signatures on content blobs for authenticity\n- Integrity: content-addressable storage ensures content cannot be altered after publish\n- Access control: DHT read access can be public; consider encrypted blobs if sensitive\n- Sanitization: ensure Markdown rendering in UI cannot execute scripts\n\n---\n\n## 6. DHT and Content Addressing\n\n### 6.1 Storage Model\n- Content-addressable: each blob is stored under a key derived from its hash\n- Metadata pointers: doc_id, version, parent_version, and state_pointer\n- Version DAG: each version node contains pointers to parent versions\n\n### 6.2 Write Path\n- User submits Markdown context\n- System computes hash, stores blob, writes metadata and version pointers\n- Returns version_id and blob_id to the UI\n\n### 6.3 Read Path\n- User requests a specific document version\n- System follows pointers to fetch the ContextBlob\n- Reconstruct state: combine content blob(s) with metadata to render\n\n### 6.4 Indexing and Discovery\n- Optional: lightweight local index to map doc_id -> latest_version\n- For cross-node discovery in the local subnet, maintain a small, sparse index replicated by BZZZ\n\n---\n\n## 7. BZZZ Software Plan (Local Subnet Bootstrapping)\n\n### 7.1 What BZZZ Does\n- Acts as a gateway/node on the local subnet for:\n  - UCXL protocol interactions\n  - DHT put/get operations\n  - Local content caching and retrieval\n  - Bridging the frontend to the UCXL network with predictable latency\n\n### 7.2 Deployment Model\n- Run BZZZ as a daemon on a dev machine or a small server within the subnet\n- Expose a local API (REST/gRPC) consumed by the browser app\n- Use mDNS or static DNS within the subnet for discovery\n\n### 7.3 Local Subnet Rollout\n- Phase 1: Stand up a single BZZZ node, ensure basic put/get works\n- Phase 2: Add a second BZZZ node for redundancy; test replication\n- Phase 3: Test network partition scenarios and latency budgets\n\n### 7.4 Interfaces\n- API surface for the browser:\n  - POST /store/context\n  - GET /fetch/context?blob_id=\n  - POST /store/document_version\n  - GET /state?doc_id=&at_time=\n- Security: mutual TLS or token-based auth for internal use only\n\n---\n\n## 8. Self-Healing Mechanism\n\n### 8.1 Concept\n- Self-healing refers to autonomously detecting and repairing data loss or corruption, and maintaining consistent state across nodes.\n\n### 8.2 Implementation Options\n- Anti-Entropy Protocol\n  - Periodically compare checksums of replicas and repair mismatches\n- Background Repair\n  - Auto-replicate popular/important blobs to additional nodes\n- Versioned Integrity\n  - Use content hashes and version DAG to detect orphaned or missing blocks\n- On-Demand Repair\n  - Trigger repair when a read detects a missing piece\n\n### 8.3 Has It Been Implemented?\n- Current UCXL baseline: often not automatically self-healing in all stacks\n- Recommendation: implement a SelfHealingModule as an optional pluggable component\n  - Provides API hooks:\n    - startRepair(doc_id, version)\n    - reportMissingBlob(blob_id)\n    - healthStatus()\n  - With a pilot on local subnet for a subset of critical docs\n- Deliverables if implemented:\n  - Repair scheduler\n  - Integrity verifier (checksum validation)\n  - Redundancy policy (lower latency, higher replication factor for frequently accessed docs)\n\n### 8.4 Migration Path\n- If not implemented in phase 2B, plan a dedicated sprint to add SelfHealingModule with test coverage and telemetry\n\n---\n\n## 9. Security and Compliance\n\n- Data in DHT: consider encryption for sensitive content or use public, read-only public blobs with signed metadata\n- Integrity: all content blobs are content-addressed; verify hash on retrieval\n- Authentication: internal APIs (BZZZ) should require strong authentication and encryption\n- Code signing: sign the browser extension/desktop app to ensure integrity\n- Logging: avoid leaking sensitive content in logs; redact metadata where appropriate\n\n---\n\n## 10. UX and UI Considerations\n\n- Temporal Navigator\n  - Timeline with zoom levels (hour/day/week/month)\n  - Version markers and branch indicators\n  - “Jump to state” action with a single click\n  - Diff view between two selected versions\n- Markdown Editor\n  - Live preview\n  - Front matter editor (optional)\n  - Validation messages for content readiness (e.g., title presence)\n- Context Submission\n  - Clear success/failure feedback\n  - Display of new version_id and blob_id\n- Status Dashboard\n  - Local subnet health, BZZZ connectivity, replication status\n  - Self-healing activity log (if enabled)\n\n---\n\n## 11. API Design (High Level)\n\n- UCXL Temporal Engine\n  - GET /ucxl/state?doc_id=&at_time=\n  - GET /ucxl/state?doc_id=&version_id=\n  - GET /ucxl/diff?doc_id=&from_version=&to_version=\n- Markdown Context Submission\n  - POST /store/context\n    - Body: { doc_id, markdown, author, title, timestamp, parent_version, [front_matter] }\n    - Response: { version_id, blob_id, state_pointer }\n  - POST /store/document_version\n    - Body: { doc_id, version, parent_versions, state_pointer, metadata }\n    - Response: { success: true, version_id }\n- DHT Fetch\n  - GET /fetch/context?blob_id=\n  - GET /fetch/document?doc_id=&version_id=\n- BZZZ Gateway\n  - Internal API endpoints are used by the frontend; documented in internal API spec\n\n---\n\n## 12. Testing and Quality Assurance\n\n- Unit tests for:\n  - Markdown ingestion and sanitization\n  - DHT blob serialization/deserialization\n  - Version/DAG logic\n- Integration tests:\n  - End-to-end: submit MD, publish version, retrieve state at time t\n  - Temporal navigation: navigate across versions and branches\n  - Local subnet routing with BZZZ\n- Performance tests:\n  - Latency budgets for fetch/store under varying network conditions\n  - Stress test with large markdown documents\n- Chaos testing:\n  - Simulate node outages and network partitions to validate self-healing behavior (if enabled)\n\n---\n\n## 13. Deployment Roadmap\n\n- Phase 0 (Immediate)\n  - Define data models and API surface\n  - Set up local BZZZ skeleton on the subnet\n  - Establish a minimal UI with temporal navigation scaffolding\n- Phase 1\n  - Implement Markdown ingestion and DHT storage (single node)\n  - Implement basic temporal engine to reconstruct state at given time\n  - Basic self-healing hooks (watch for missing blocks)\n- Phase 2\n  - Multi-node BZZZ with replication tests\n  - Full self-healing module in place (anti-entropy, repair)\n  - Timeline UI polish, diff view\n- Phase 3\n  - Pilot with a broader set of docs, performance tuning\n  - Security hardening and access control\n  - Documentation for developers and operators\n\n---\n\n## 14. Deliverables to Create\n\n- Architecture and API design documents (this briefing can be a living doc)\n- Data models (JSON schemas or TypeScript interfaces)\n- UI wireframes or a minimal prototype\n- A runnable local subnet setup guide (with BZZZ, UCXL, and DHT)\n- Self-healing module design/spec (and a plan for MVP)\n- Test plans and CI benchmarks\n\n---\n\n## 15. Risks and Mitigations\n\n- Risk: Temporal state reconstruction latency\n  - Mitigation: caching of frequently accessed states; prefetch of probable next states; efficient delta application\n- Risk: DHT data loss on subnet partition\n  - Mitigation: replicate critical blobs; implement self-healing repair\n- Risk: Complex version DAG leading to user confusion\n  - Mitigation: intuitive UI; guided tours; simplified diff/merge presets\n- Risk: Security exposure of Markdown payloads\n  - Mitigation: sanitization, signing, optional encryption, access control\n\n---\n\n## 16. Next Steps\n\n- Schedule a design review with frontend, backend, and DevOps to validate data models and API contracts\n- Create a minimal viable product (MVP) plan with milestones for:\n  - Markdown ingestion to DHT\n  - Temporal state retrieval\n  - Local BZZZ deployment\n  - Basic self-healing hooks\n- Prepare test datasets (sample Markdown docs with versions)\n\n---\n\nIf you’d like, I can tailor this briefing into a concrete project plan with:\n- a detailed data dictionary (JSON schemas)\n- a starter API spec with concrete endpoint definitions\n- sample UI wireframes or user stories for the temporal navigator\n\nWould you prefer a lighter or more detailed version for your dev kickoff?
