How enu3379/kibitzer works
Purpose and execution surface
Kibitzer is a Manifest-based Chrome extension that observes non-incognito browsing during a user-defined focus session, estimates distraction accumulation, and displays non-blocking coaching plus a session summary. The extension package and build boundary are apps/extension/manifest.json, apps/extension/build.mjs, and apps/extension/src/background.ts. User-facing entry points are the popup, options, onboarding, replay viewer, and local-PDF prompt pages.
Extension orchestration and browser observation
The background service worker is the control-plane owner: it receives Chrome lifecycle/navigation/activity signals, maintains session state, schedules dwell processing, updates UI/badge state, and coordinates persistence and judgments. Page-context collection is intentionally separated into content scripts: apps/extension/src/content/pageExcerpt.ts extracts bounded page text only when needed, while apps/extension/src/content/toastOverlay.ts renders coaching on the current page. apps/extension/src/offscreen.ts provides an offscreen runtime boundary for work unsuitable for the service worker.
Session, event, and durable state
A session records the goal, browsing events, judgment outcomes, intervention state, and aggregate reporting data. Core state is persisted locally in browser storage/IndexedDB through apps/extension/src/lib/db.ts; event definitions and history/session reconstruction live in apps/extension/src/lib/events.ts, apps/extension/src/lib/session.ts, and apps/extension/src/lib/sessionRestore.ts. This local-first boundary supports service-worker restarts and the replay capability; no application backend is present.
Attention measurement and intervention state machine
Browsing dwell and presence signals are converted into attention evidence by apps/extension/src/lib/dwell.ts, apps/extension/src/lib/dwellScheduler.ts, and apps/extension/src/lib/presence.ts. The focus “gauge” is a distinct deterministic reducer/state-machine layer in apps/extension/src/core/gauge/reducer.ts, with its contract/types/config in apps/extension/src/core/gauge/types.ts and apps/extension/src/core/gauge/config.ts. Gauge tiers, cooldown/snooze/refund behavior, and runtime transitions determine whether the extension stays quiet, requests judgment, or emits a nag.
Tiered relevance judgment
Judgment is staged to minimize data sharing and latency. A local Tier 0 semantic classifier uses the bundled Korean/English ONNX embedding model via apps/extension/src/providers/tier0Wasm.ts and apps/extension/assets/models/koen-e5-tiny/model-manifest.json; relevance policy/orchestration resides in apps/extension/src/lib/relevance.ts and apps/extension/src/lib/tier0.ts. Higher tiers can use an opted-in LLM for fast or detailed assessment; detailed requests add a page excerpt capped by product policy. Sensitive and user-excluded domains are filtered before observation through apps/extension/src/lib/domainFilter.ts and configs/sensitive_domains.json.
AI-provider and persona boundary
Provider-neutral request formation, prompting, parsing, and failure handling are concentrated in apps/extension/src/providers/chatTransport.ts, apps/extension/src/providers/payloads.ts, and apps/extension/src/providers/judgeParsing.ts. Implementations include OpenAI-compatible/OpenAI, Claude, and Ollama paths in apps/extension/src/providers/openaiChat.ts, apps/extension/src/providers/claudeChat.ts, and apps/extension/src/providers/ollamaChat.ts; configured services include Ollama Cloud, OpenRouter, Gemini, Deepseek, and Kimi. Persona configuration drives coaching voice and fallback copy via apps/extension/src/lib/personas.ts, configs/personas.yaml, and configs/personas/.
UI, reporting, and operational tooling
The popup starts/controls sessions and exposes immediate status (apps/extension/src/popup/popup.ts); settings cover AI, privacy, and local data (apps/extension/src/options/options.ts); onboarding initializes user choices (apps/extension/src/onboarding/onboarding.ts). End-of-session aggregation and generated commentary are handled by apps/extension/src/lib/sessionSummary.ts, apps/extension/src/lib/sessionReport.ts, and apps/extension/src/lib/reportCards.ts. Recorded events can be replayed through apps/extension/src/replay/replay.ts and the CLI apps/extension/tools/replay.ts, creating a deterministic debugging/audit boundary around the core loop.
Main entry points: background.ts Background control plane · relevance.ts Relevance orchestration · session.ts Session history · reducer.ts Focus gauge reducer
Components 21
Extension runtime
- Background control plane · Owns session orchestration, badge state, and runtime coordination.
apps/extension/src/background.ts - Local durable store · Local-first session, event, and judgment persistence.
apps/extension/src/lib/db.ts - Session restoration
apps/extension/src/lib/sessionRestore.ts - Page excerpt collector · Extracts bounded text only for detailed assessment.
apps/extension/src/content/pageExcerpt.ts - Coaching overlay · Renders non-blocking coaching in the current page.
apps/extension/src/content/toastOverlay.ts - Offscreen runtime · Hosts work unsuitable for the service worker.
apps/extension/src/offscreen.ts
Attention & session core
- Dwell & presence evidence
apps/extension/src/lib/dwellScheduler.ts - Focus gauge reducer · Applies tiers, cooldowns, snoozes, refunds, and intervention transitions.
apps/extension/src/core/gauge/reducer.ts - Session history · Reconstructs goals, events, judgments, and aggregates.
apps/extension/src/lib/session.ts
Relevance & AI
- Domain privacy filter · Excludes sensitive and user-filtered domains before observation.
apps/extension/src/lib/domainFilter.ts - Relevance orchestration · Selects local or opted-in higher-tier relevance assessment.
apps/extension/src/lib/relevance.ts - Local semantic classifier · Korean/English Tier 0 relevance classification.
apps/extension/src/providers/tier0Wasm.ts - Bundled embedding model
apps/extension/assets/models/koen-e5-tiny/model-manifest.json - Provider-neutral AI transport · Forms prompts, parses responses, and handles provider failures.
apps/extension/src/providers/chatTransport.ts - Opted-in LLM providers · OpenAI-compatible, Claude, and Ollama provider paths.
apps/extension/src/providers/openaiChat.ts - Persona configuration · Controls coaching voice and fallback copy.
apps/extension/src/lib/personas.ts
User surfaces & reporting
- Popup controls · Starts and controls focus sessions.
apps/extension/src/popup/popup.ts - Options & onboarding · Configures AI, privacy, local data, and initial choices.
apps/extension/src/options/options.ts - Session reports · Builds end-of-session summaries and report cards.
apps/extension/src/lib/sessionReport.ts - Replay viewer & CLI · Replays recorded events for debugging and audit.
apps/extension/src/replay/replay.ts
Other components
- Chrome signals · Lifecycle, navigation, and activity signals.
Connections 22
- Chrome signals → Background control plane: browser events
- Background control plane → Domain privacy filter: filter before observe
- Background control plane → Dwell & presence evidence: schedule dwell
- Dwell & presence evidence → Focus gauge reducer: attention evidence
- Background control plane → Relevance orchestration: request judgment
- Relevance orchestration → Local semantic classifier: Tier 0
- Bundled embedding model → Local semantic classifier: embeddings
- Relevance orchestration → Page excerpt collector: detailed-only excerpt
- Relevance orchestration → Provider-neutral AI transport: higher tiers
- Provider-neutral AI transport → Opted-in LLM providers: provider request
- Relevance orchestration → Focus gauge reducer: judgment outcome
- Persona configuration → Coaching overlay: coaching voice
- Focus gauge reducer → Coaching overlay: emit coaching
- Background control plane → Session history: record state
- Session history → Local durable store: persist locally
- Local durable store → Session restoration: reload after restart
- Session restoration → Background control plane: restore session
- Popup controls → Background control plane: session controls
- Options & onboarding → Background control plane: preferences
- Session history → Session reports: aggregate session
- Session history → Replay viewer & CLI: recorded events
- Background control plane → Offscreen runtime: delegate runtime work