Parent
Chat Interface — Design Spec (docs/superpowers/specs/2026-06-19-chat-interface-design.md)
App Security Baseline — Design Spec (docs/superpowers/specs/2026-06-19-app-security-baseline-design.md)
What to build
The RAG grounding layer: retrieve relevant items from the ShadowBrain SQLite
and inject them as context, toggleable per thread and per send. When off, the
chat is plain general chat (no knowledge-base context). The retrieval respects
the two-level visibility model: is_hidden items are AI-OK by default;
is_private items are excluded unless the current thread has opted in via a
per-thread "Include private in AI" control.
lib/chat/retrieval.ts — given the latest user message, run FTS retrieval
reusing the Phase 1 search helper / sanitizeFts5Query, with tag/type
filters. Default behavior: include is_hidden = 1 items (they are AI-OK);
exclude is_private = 1 items unless the thread has
include_private_in_ai = 1. Return top-K items (CHAT_RAG_TOP_K, default
8). Render a ## Retrieved context block (title, type, snippet, tags).
- Wire into
/api/chat: when grounded is true, prepend the context block as
a system message before forwarding to the provider.
grounded comes from the thread default (chat_threads.grounded) and is
overridable per send.
- The "Include private in AI" toggle: a new column
chat_threads.include_private_in_ai INTEGER NOT NULL DEFAULT 0 (per-thread
setting, off by default) plus a per-send override in the chat UI. When on,
the RAG layer calls the read helpers with includePrivate = true for that
thread / message.
- Config:
CHAT_RAG_TOP_K.
Acceptance criteria
Blocked by
References
- docs/superpowers/specs/2026-06-19-chat-interface-design.md — §Components (
retrieval.ts), §Architecture, §Configuration, §Data Model, §Security
- docs/superpowers/specs/2026-06-19-app-security-baseline-design.md — §2 (two-level visibility)
Parent
Chat Interface — Design Spec (docs/superpowers/specs/2026-06-19-chat-interface-design.md)
App Security Baseline — Design Spec (docs/superpowers/specs/2026-06-19-app-security-baseline-design.md)
What to build
The RAG grounding layer: retrieve relevant items from the ShadowBrain SQLite
and inject them as context, toggleable per thread and per send. When off, the
chat is plain general chat (no knowledge-base context). The retrieval respects
the two-level visibility model:
is_hiddenitems are AI-OK by default;is_privateitems are excluded unless the current thread has opted in via aper-thread "Include private in AI" control.
lib/chat/retrieval.ts— given the latest user message, run FTS retrievalreusing the Phase 1 search helper /
sanitizeFts5Query, with tag/typefilters. Default behavior: include
is_hidden = 1items (they are AI-OK);exclude
is_private = 1items unless the thread hasinclude_private_in_ai = 1. Return top-K items (CHAT_RAG_TOP_K, default8). Render a
## Retrieved contextblock (title, type, snippet, tags)./api/chat: whengroundedis true, prepend the context block asa system message before forwarding to the provider.
groundedcomes from the thread default (chat_threads.grounded) and isoverridable per send.
chat_threads.include_private_in_ai INTEGER NOT NULL DEFAULT 0(per-threadsetting, off by default) plus a per-send override in the chat UI. When on,
the RAG layer calls the read helpers with
includePrivate = truefor thatthread / message.
CHAT_RAG_TOP_K.Acceptance criteria
retrieval.tsreturns top-K items via FTSis_hidden = 1items are included in RAG context (AI-OK)is_private = 1items are excluded from RAG contextinclude_private_in_ai = 1(per-thread or per-send override),is_privateitems are includedgrounded=trueinjects a## Retrieved contextsystem block;grounded=falseis plain chatinclude_private_in_aitoggle is persisted on the thread and overridable per sendopencode-goandhermestargets (context injection is provider-agnostic)Blocked by
includeHidden/includePrivateread-helper options)References
retrieval.ts), §Architecture, §Configuration, §Data Model, §Security