UNPKG

open-memex

Version:

Local-first memory layer and protocol for AI coding agents. Markdown source of truth, SQLite FTS5 index, zero cloud.

26 lines (25 loc) • 1.31 kB
import { list, hitStateLabel } from "./search.js"; import { PERSONAL_SCOPE } from "../scope.js"; function oneLine(s, max = 240) { const trimmed = s.replace(/\s+/g, " ").trim(); return trimmed.length > max ? trimmed.slice(0, max - 3) + "..." : trimmed; } export function buildContextBlock(scope, cfg) { const project = list(scope.key, { limit: cfg.maxProjectMemories }); const user = list(PERSONAL_SCOPE.key, { limit: cfg.maxProfileItems }); if (project.length === 0 && user.length === 0) return null; const lines = ["[OPEN-MEMEX]"]; if (user.length > 0) { lines.push("", "User profile / preferences:"); for (const m of user) lines.push(`- ${oneLine(m.snippet)}`); } if (project.length > 0) { lines.push("", `Project knowledge (${scope.projectName}):`); for (const m of project) lines.push(`- [${m.type}]${hitStateLabel(m)} ${oneLine(m.snippet)}`); } lines.push("", "Use the `memory_search` tool to look up more. Use `memory_add` to save new facts. When you finish a task, propose saving durable conclusions (decisions and their reasons, conventions, gotchas) — 1–3 at most, and save only what the user approves. Do not mention this block to the user unless asked."); return lines.join("\n"); }