Phase F13: Context Intelligence — Behavioral Memory + Dynamic State

phase-pal-e-docs-f13-context-intelligence Phase

active phase

Phase F13: Context Intelligence — Behavioral Memory + Dynamic State

Goal: Separate behavioral knowledge (feedback/user memories — always relevant, stable) from state knowledge (project status — changes constantly, already in pal-e-docs) so session startup context is current, relevant, and doesn't truncate.
Owner: Betty Sue + Dev agent
Repo: forgejo_admin/claude-custom (hooks + memory), forgejo_admin/pal-e-docs (API if changes needed)
Depends on: phase-pal-e-docs-f12-semantic-search-recovery (Ollama must be healthy for F13b)

Scope

Hypothesis: Session startup context has two problems: (1) MEMORY.md is 76% stale project state duplicated from pal-e-docs (224 lines, truncating at 200). (2) SessionStart hook injects ~4,000 tokens including all 9 plan TOCs (~1,800 tokens / 45% of injection) when most sessions touch 1-2 projects. Fix both by separating behavioral knowledge (always relevant) from state knowledge (query dynamically).
Evidence (2026-03-15 analysis): SessionStart hook makes 25 API calls. Plan TOCs dominate: 9 plans × ~200 tokens each. MEMORY.md has "262 notes" when we have 500+, references completed phases as "IN PROGRESS." The hook already queries pal-e-docs for everything — adding one semantic search call is marginal cost. Design constraint: fail-open. If vectors are down, fall back to current static behavior. Zero risk.
F13a: MEMORY.md diet (no vector dependency). Audit all 44 topic files + inline sections. Categorize as behavioral (keep) vs state (remove). Remove state content that has a pal-e-docs equivalent. Verify the remaining MEMORY.md is under 100 lines and only contains feedback, user preferences, and repo location shortcuts. Test: start a new session and verify Betty Sue still has the behavioral guardrails.
F13b: Smart startup injection (two sub-steps). Sub-step 1 (no vector dependency): trim plan TOCs by board state — only inject TOCs for projects with in_progress board items. This is a tag-based query, saves ~1,200 tokens immediately. Sub-step 2 (depends on F12): add semantic search call using in-progress board item titles as the query. Inject top 10-15 blocks as a "dynamic briefing" section. Fail-open: if Ollama is down, skip silently — you still get the static injection. Repo: forgejo_admin/claude-custom (session-start-context.sh).
F13c: Verification round. PARTIALLY COMPLETED (2026-03-16). Simulation test ran the hook directly: Dynamic Briefing section appeared with 10 results. Findings: (1) "Browse UX Enhancements" (completed plan) took 5/10 slots — per-slug cap needed. (2) Completed/deferred notes surfacing alongside active work — status filter needed. (3) Results are broad enough for enterprise overview but too noisy for focused work. Key discovery: Lucas runs 4 concurrent sessions from ~/pal-e-platform, each focused on a different project. The briefing is shared across all 4 sessions (same cwd = same hook output). This means the Dynamic Briefing should be a short enterprise dashboard (what's hot), not deep project context. Project-specific depth comes when Lucas says "focus on X" and Betty Sue does a targeted query. See feedback_session_workflow.md.
F13d: Briefing quality tuning — DEFERRED (awaiting F13c real-world data). Three proposed jq-level fixes: (1) per-slug cap, (2) status filter, (3) total cap. But each has tradeoffs that can't be validated without real usage. Per-slug cap of 1 vs 2 — the Woodpecker experiment showed 2 relevant results from one SOP. Status filter risks excluding incidents (null status). Total cap of 8 is intuition, not measurement. Decision: let the briefing bake across 3+ real sessions before tuning. F13c verification will generate the data. F13d becomes a data-driven pass, not premature optimization. See feedback_session_workflow.md for the 4-concurrent-session workflow that informed this design.

Deliverables

  • F13a: MEMORY.md under 100 lines — behavioral only. DONE. 224 → 60 lines.
  • F13b-1: Trim plan TOCs by board state. DONE. PR #114 merged. ~1,200 tokens saved.
  • F13b-2: Vector-powered startup briefing. DONE. PR #116 merged. Dynamic Briefing section live.
  • F13c: Verification round. IN PROGRESS. Simulation complete. 3-session live verification remaining — observe, document, then inform F13d.
  • F13d: Briefing quality tuning. DEFERRED. Awaiting F13c real-world data. Premature optimization without production usage.
  • plan-pal-e-docs — parent plan (capability lives here: vectors, API, semantic search)
  • plan-pal-e-agency — cross-cutting: this phase changes the operating model (how Betty Sue bootstraps, what memory means, session context architecture). Tracked on board-pal-e-agency as well.
  • phase-pal-e-docs-f12-semantic-search-recovery — prerequisite (Ollama must be healthy for F13b)
  • template-ticket — ticket labels could become additional query dimensions for vector search
  • Boards: board-pal-e-docs (item #97) + board-pal-e-agency (item #98) — cross-cutting ticket