Elnor Repo Reader

DOC20_Q_BROWSER_INTAKE_ARCHITECTURE.md

Current Specs/DOC20/DOC20_Q_BROWSER_INTAKE_ARCHITECTURE.md

Short text page 31f4e4cf01fc. Generated 2026-06-09T01:23:58.539Z from commit dbaa25962edc11ab30e8d4ca1715f9ae5bf77331. Worktree: clean.

Open readable HTML page · Open raw txt · Open path URL

ELNOR REPO READER TEXT MIRROR
Original path: Current Specs/DOC20/DOC20_Q_BROWSER_INTAKE_ARCHITECTURE.md
Source repo: /Users/OpenClaw1/Elnor/Elnor Specs
Git branch: main
Git commit: dbaa25962edc11ab30e8d4ca1715f9ae5bf77331
Generated: 2026-06-09T01:23:58.539Z

---

# DOC20 §6.19 Addition — Q Browser Knowledge Intake Architecture

**Source:** Architectural discussion, 2026-04-03
**Target:** DOC20 §6.19 (Q Browser), with cross-doc implications for DOC72 §20A, DOC16 Entry 16.7, DOC3 R11.3, DOC8
**Status:** Proposed addition — needs integration into DOC20 R2.3+ and cross-doc review

---

## 1. Overview

The Q Browser is not just a web viewer — it is a knowledge intake surface. When the user browses in Q Browser, the system captures browsing metadata, extracts knowledge from significant pages during idle processing, and provides enhanced intake for Microsoft 365 web applications. All capture is subject to user-controlled toggles and an incognito mode.

Three interaction modes coexist in the Q Browser, all available by default without activation buttons:

- **Passive ambient capture** — automatic metadata and idle-time entity extraction (this document)
- **User-initiated interaction** — comments, highlights, Ask Elnor, Save as Artifact/Note (DOC20 §6.19.7, always available)
- **Demonstration mode** — "watch how I do this" for learning web-based procedures (DOC3 R11.3 §4, activated on demand)

---

## 2. Two-Tier Intake Pipeline

### 2.1 Tier 1 — Deterministic metadata capture (immediate, no LLM, always on)

On every page load in Q Browser, EC captures lightweight metadata automatically:

```ts
export const BrowserPageVisitSchema = z.object({
  visit_id: z.string().max(120),
  url: z.string().max(2000),
  url_hash: z.string().max(64),
  title: z.string().max(500),
  domain: z.string().max(200),
  visited_at: z.string().datetime(),
  dwell_start_at: z.string().datetime(),
  dwell_end_at: z.string().datetime().optional(),       // Updated on navigation away
  dwell_seconds: z.number().nonnegative().default(0),   // Computed on navigation away
  project_id: z.string().max(120).optional(),            // Auto-associated if domain matches known matter
  is_m365_surface: z.boolean().default(false),
  m365_metadata: M365PageMetadataSchema.optional(),      // Enhanced extraction for M365 pages
  user_interactions: z.object({
    highlighted: z.boolean().default(false),
    commented: z.boolean().default(false),
    asked_elnor: z.boolean().default(false),
    saved_as_artifact: z.boolean().default(false),
    saved_as_note: z.boolean().default(false),
    demonstration_mode_used: z.boolean().default(false),
  }).default({}),
  intake_state: z.enum(["metadata_only", "queued_for_extraction", "extracted", "skipped", "incognito"]).default("metadata_only"),
  schema_version: z.literal(1),
});
```

**M365 enhanced metadata — DOM extraction, no LLM:**

```ts
export const M365PageMetadataSchema = z.object({
  surface_type: z.enum(["word_online", "outlook_web", "onedrive", "sharepoint", "excel_online", "powerpoint_online", "teams_web", "other_m365"]),
  document_id: z.string().max(240).optional(),
  sharepoint_path: z.string().max(500).optional(),
  direct_url: z.string().max(2000).optional(),           // Deep link to reopen this exact document
  file_name: z.string().max(300).optional(),
  last_modified_at: z.string().datetime().optional(),
  last_modified_by: z.string().max(200).optional(),
  content_type: z.string().max(100).optional(),           // Document, email, folder listing, etc.
  schema_version: z.literal(1),
});
```

**Cost:** Zero API calls. Pure URL parsing + DOM scraping for M365 pages. Runs synchronously on page load. Sub-100ms.

**Storage:** `ELNOR_MEMORY/browser/visits.jsonl` — append-only log. Retained per retention policy (default 90 days). The most recent 500 entries also maintained in `ELNOR_MEMORY/browser/history_current.json` for fast Q Browser start page search.

### 2.2 Tier 2 — LLM-assisted entity extraction (idle background, significant pages only)

An idle background process scans the visit log and runs extraction on pages that cross a significance threshold. This is NOT a DOC8 nightly job — it runs opportunistically during idle periods throughout the day using the same idle detection infrastructure as the Satisfaction Matrix background job.

**Significance filtering — which pages get extracted:**

```ts
export const BrowserExtractionSignificancePolicy = {
  // Any ONE of these conditions qualifies a page for extraction
  conditions: [
    { type: "dwell_time", min_seconds: 30 },
    { type: "user_interaction", any_of: ["highlighted", "commented", "asked_elnor", "saved_as_artifact", "saved_as_note"] },
    { type: "m365_surface", surface_types: ["word_online", "outlook_web", "excel_online", "powerpoint_online"] },
    { type: "domain_match", match_against: "known_matter_domains" },  // Domains associated with active matters
    { type: "return_visit", min_visits: 2, within_hours: 24 },
  ],
  // Pages below ALL conditions are skipped
};
```

**Processing priority queue:**

1. M365 document pages (Word Online, Excel Online) — highest priority, richest extraction
2. Pages with user interactions (commented, highlighted, asked Elnor)
3. Long-dwell pages (> 2 minutes)
4. Matter-associated domain pages
5. Return visits
6. Everything else that qualifies

**Extraction model and prompt:**

Uses the configured cheap extraction model (default: Gemini Flash, per DOC24 §7 `ExtractionModelConfigSchema`). The prompt is targeted:

```
Extract structured knowledge from this web page content.

Page URL: {url}
Page title: {title}
Domain: {domain}
User's active matters: {active_matter_names}

Extract:
- Named entities (people, organizations, courts, case names, case numbers)
- Dates and deadlines mentioned
- Key facts or holdings
- Document references (filings, motions, orders) with any identifiers
- Any information related to the user's active matters

For M365 documents, additionally extract:
- Document purpose/type (brief, motion, letter, memo, etc.)
- Key content summary (2-3 sentences)
- Parties/entities referenced in the document

Output as structured JSON candidates. Mark confidence based on extraction clarity.
Do NOT extract navigation elements, ads, boilerplate, or UI chrome.
```

**Cost:** One cheap LLM call per significant page. For 10-15 significant pages per day, approximately 2-3 minutes of processing total.

**Output:** Entity candidates feed into DOC72's standard promotion pipeline — same as conversation mining candidates. Entity linking, dedup, confidence assignment, and promotion rules all apply.

### 2.3 M365 Word Online — enhanced "god mode" intake

When the user visits a Word Online document in Q Browser, the system has direct DOM access to the document content. This enables significantly richer intake than a generic web page:

- **Full document text extraction** via DOM (the document content is rendered in the browser)
- **Document structure** (headings, sections, paragraph count)
- **Document metadata** from the SharePoint/OneDrive API (file path, version history, sharing permissions)
- **Direct link** for reopening the exact document
- **Matter association** via entity resolution on document title, content entities, and file path

The extraction creates or updates a `work_product` node in DOC72 with:
- Document name, type, and location (SharePoint URL + direct link)
- Matter association (linked via entity edges)
- Content summary
- Key entities mentioned in the document
- Last accessed timestamp

This means Elnor automatically learns "the Henderson MTD draft is at this SharePoint URL" without the user explicitly telling it. When the user later says "pull up the Henderson MTD," Elnor knows where it is and can open it in the Q Browser or link to it.

**M365 intake runs at tier 1 priority** — metadata is captured immediately on page load, and the page is automatically queued at the top of the tier 2 extraction priority queue.

---

## 3. Idle Background Processing

### 3.1 Shared idle infrastructure

The browser extraction background job uses the same idle detection infrastructure as the Satisfaction Matrix background job (DOC24 Addendum A §22):
- Starts when system idle ≥ 10 minutes (configurable)
- CPU < 20%
- Screen off or locked (configurable)
- Polls every 15 minutes (more frequent than the Satisfaction Matrix's 30-minute poll)

### 3.2 Incremental and interruptible

The job processes the extraction queue in priority order. After each page extraction, it writes the result and updates `intake_state` on the visit record. If the user resumes activity, the job pauses at the next page boundary (not mid-extraction) and resumes on the next idle window.

No checkpointing needed beyond the per-page intake_state update — each page is an independent unit of work.

### 3.3 Same-day recall

Because the job runs opportunistically during idle periods throughout the day (not just at night), most significant pages will be extracted within 1-2 hours of visiting them. If you browse a Henderson filing at 10 AM, go to a meeting at 10:30, the extraction runs during the meeting, and by 11 AM when you ask "what was in that Henderson filing I read this morning," the entities are in the graph and the page URL is in history.

For tier 1 metadata (URL, title, dwell time), recall is IMMEDIATE — no processing delay. "Pull up that Nike page from this morning" works instantly from history search. Tier 2 extraction adds entity-level recall ("what cases were cited on the page I was reading").

---

## 4. User Controls

### 4.1 Q Browser incognito mode

Toggle in the Q Browser toolbar (lock icon or similar).

When active:
- No history entries created
- No tier 1 metadata captured
- No tier 2 extraction queued
- No comments persisted
- Ask Elnor still works (the query is processed but the page context is not durably stored)
- Demonstration mode is unavailable
- Persistent visual indicator (toolbar badge, subtle banner) confirming incognito is active

When deactivated: normal capture resumes for subsequent page visits. Previously incognito pages are not retroactively captured.

```ts
export const BrowserIncognitoSettingsSchema = z.object({
  incognito_active: z.boolean().default(false),
  schema_version: z.literal(1),
});
// Storage: in-memory only while active. NOT persisted. Default is off on browser launch.
```

### 4.2 Disable automatic browser intake

Setting in Settings > Knowledge & Feedback.

When active:
- Tier 1 metadata still captures (history works normally — you can search and revisit pages)
- Tier 2 LLM extraction is disabled (no idle background processing of browsing history)
- User-initiated features still work: comments, highlights, Ask Elnor, Save as Artifact/Note, demonstration mode
- Only the automatic background extraction stops

This is for users who want a normal browser with history but don't want the system automatically extracting knowledge from browsed content.

```ts
export const BrowserIntakeSettingsSchema = z.object({
  automatic_extraction_enabled: z.boolean().default(true),
  m365_enhanced_intake_enabled: z.boolean().default(true),
  extraction_idle_minutes: z.number().int().positive().default(10),
  extraction_poll_interval_minutes: z.number().int().positive().default(15),
  schema_version: z.literal(1),
});
// Storage: ELNOR_MEMORY/system/browser_intake_settings.json
// EC-only write via browser_intake.update_settings command
```

### 4.3 Relationship to other toggles

- **Q Browser incognito** — browser-specific, suppresses ALL capture for that browsing session
- **Disable automatic browser intake** — browser-specific, suppresses only tier 2 background extraction
- **Global "pause learning" toggle** (DOC72 §20.10) — stops ALL ambient learning across all surfaces including browser
- **Satisfaction Matrix `gather_matrix_data`** — independent, controls Matrix feedback capture, NOT browser knowledge intake

These are independent toggles. Incognito is the most aggressive (no capture at all). Disable automatic intake is moderate (history works, extraction doesn't). Global pause learning is the nuclear option across all surfaces.

---

## 5. DOC3 Demonstration Mode Cross-Reference

The Q Browser supports DOC3's demonstration mode for learning web-based procedures. When the user activates "watch how I do this" while browsing in Q Browser, the browser's Electron webview provides observation infrastructure through two channels:

- **Chrome DevTools Protocol (CDP)** — DOC3's `browser_cdp` adapter source. Provides structured DOM events, network requests, and page state. Higher fidelity than the macOS Accessibility API for web content.
- **Accessibility bridge** — DOC3's `accessibility_bridge` adapter source. Available as fallback for web content that doesn't expose clean DOM structure.

CDP is the preferred observation mechanism for Q Browser demonstrations because it provides richer, more structured data than AX events for web-based workflows. DOC3 R11.3 §4.1 already lists `browser_cdp` as an adapter source.

The full demonstration capture, interpretation, and knowledge promotion pipeline is specified in DOC3 R11.3 §§4-9. DOC20 provides the webview infrastructure; DOC3 provides the learning pipeline.

**Example use case:** The user navigates to CM/ECF, demonstrates how to file a motion, narrates "I always check the case number first, then select the motion type, then upload the PDF." DOC3's pipeline observes via CDP, interprets the workflow, and produces a `ProcedureKnowledgeContract` for "File a motion on CM/ECF" stored in DOC72 and injectable through DOC24.

---

## 6. Cross-Doc Obligations

| Target Doc | Obligation | Priority |
|---|---|---|
| **DOC20** | Add §6.19.9 (or similar) for browser intake architecture: two-tier pipeline, significance filtering, M365 enhanced intake, incognito mode, intake settings | High |
| **DOC72 §20A** | Add `intake.browser.page_visited` surface-specific intake contract with extraction prompt, candidate output schema, and promotion rules | High |
| **DOC72 §20A** | Add `intake.browser.m365_document` enhanced intake contract for Word Online / SharePoint documents | High |
| **DOC16** | Cross-reference M365 web app intake with DOC16 Entry 16.7 M365 integration. Ensure document IDs and SharePoint paths align between web intake and API-based intake | Medium |
| **DOC8** | Browser extraction background job uses shared idle infrastructure. Job scheduling, checkpoint, and pause/resume follow the same patterns as the Satisfaction Matrix background job | Medium |
| **DOC3** | Cross-reference Q Browser as a demonstration mode target with CDP as preferred observation mechanism | Low |
| **DOC21/22** | Register Q Browser incognito toggle, intake settings, and extraction status indicator as UI components | Medium |

---

## 7. What This Does NOT Cover

- **Chrome extension / external browser integration** — this is Q Browser (Electron webview) only. External browser capture is a separate feature not currently specified.
- **Full document indexing** — DOC18 (LlamaIndex sidecar) handles deep document indexing. Browser intake creates entity candidates and work product references, not full document indexes.
- **Real-time page monitoring** — the system captures on page visit and extracts during idle time. It does not continuously monitor page content changes. If a page updates after you've left it, the system has the snapshot from your visit.
- **Cross-device sync** — browser history and intake data are local to the machine running Q. The Chrome-based version of Q (for mobile) does not have browser intake capability.