# Obelisk Query Patterns These are copyable CodeAct patterns for `runtime.mjs --query` scripts plus `--attune` memory mutation patterns. They are not new APIs. Adapt them to the user's scope and return compact evidence. Read this before the first query for broad synthesis, progress summaries, design history, weekly/monthly reviews, or questions that ask what the user did, learned, decided, tried, or abandoned. Start with a helper-first pass; use raw `sql()` only when the helper surface cannot express the needed join or aggregation. ## First Pass: Overview + Recall + Evidence Use this for broad synthesis before writing custom SQL. It gives the agent a map, prior notes, and raw session evidence in one bounded result. Then run a faceted detail pass if the first pass reveals useful projects, sessions, files, or terms. ```js const topic = 'English topic terms translated from the user request'; const map = overview({ limit: 6 }); const project = map.current.project?.project; const scoped = project ? { project } : {}; return { query_plan: { mode: 'first_pass', topic, project: project || null, limits: { sessions: 6, memories: 5, search: 8 }, }, orientation: map.current_project && { project: map.current_project.project, session_total: map.current_project.session_total, sessions: map.current_project.sessions.map(s => ({ id: s.id, title: s.title, branch: s.git_branch, ended_at: s.ended_at, })), memory_total: map.current_project.memory_total, memories: map.current_project.memories.map(m => ({ id: m.id, path: m.path, anchors: m.anchors, summary: m.summary?.slice(0, 240), })), }, prior_memories: memories({ ...scoped, query: topic, limit: 5 }).map(m => ({ id: m.id, path: m.path, anchors: m.anchors, session_id: m.session_id, created_at: m.created_at, rank: m.rank, summary: m.summary?.slice(0, 260), })), session_evidence: search(topic.replace(/[-_]/g, ' '), { ...scoped, limit: 8 }) .slice(0, 6) .map(h => ({ session_id: h.session.id, session_title: h.session.title, uuid: h.message.uuid, timestamp: h.message.timestamp, snippet: h.message.text?.slice(0, 220), })), }; ``` ## Orient Before Retrieval Use `overview()` when the current project or available scopes are unclear. Treat the result as a map, not evidence; follow up with `memories()`, `search()`, helpers, or `sql()` for facts. ```js const map = overview({ limit: 6 }); return { current: map.current, current_project: map.current_project && { project: map.current_project.project, session_total: map.current_project.session_total, sessions: map.current_project.sessions.map(s => ({ id: s.id, title: s.title, branch: s.git_branch, ended_at: s.ended_at, })), memory_total: map.current_project.memory_total, memories: map.current_project.memories.map(m => ({ id: m.id, path: m.path, anchors: m.anchors, summary: m.summary?.slice(0, 240), })), }, projects: map.projects.slice(0, 8), totals: map.totals, }; ``` ## Bounded Search To Context Use `search()` to locate candidates, then expand only the strongest hits. ```js const hits = search('"runtime query"', { project: '%quiet-zero%', limit: 8 }); return hits.slice(0, 5).map(h => { const c = context(h.message.uuid); return { session_id: h.session.id, session_title: h.session.title, uuid: h.message.uuid, timestamp: h.message.timestamp, snippet: h.message.text?.slice(0, 240), parentChain: (c?.parentChain || []).slice(-3).map(m => ({ uuid: m.uuid, role: m.role, snippet: m.text?.slice(0, 120), })), }; }); ``` ## Memory Plus Session Evidence Use this when prior conclusions may exist but the answer still depends on raw session evidence. Keep memory as prior notes, not final authority; compare it with session evidence in your final answer when correctness matters. Memory query terms are English even when the user asks in another language. ```js const project = '%quiet-zero%'; const topic = 'markdown memory layer'; const ftsTopic = topic.replace(/[-_]/g, ' '); const prior_memories = memories({ project, query: topic, limit: 5, }).map(m => ({ id: m.id, path: m.path, anchors: m.anchors, session_id: m.session_id, message_start: m.message_start, message_end: m.message_end, created_at: m.created_at, summary: m.summary?.slice(0, 260), rank: m.rank, })); const session_evidence = search(ftsTopic, { project, limit: 8 }) .slice(0, 6) .map(h => ({ session_id: h.session.id, session_title: h.session.title, uuid: h.message.uuid, timestamp: h.message.timestamp, snippet: h.message.text?.slice(0, 220), })); return { query_plan: { project, topic, memory_limit: 5, session_limit: 8, }, prior_memories, session_evidence, }; ``` ## Attune Approved Memory Use this only after the user approves writing memory and the markdown file already exists. `remember()` validates the file and stores a normalized absolute path, so keep the script small and return the registered record. Run this script with `runtime.mjs --attune