opencode-memoir 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of opencode-memoir might be problematic. Click here for more details.
- package/dist/index.js +835 -422
- package/dist/index.js.map +7 -1
- package/package.json +6 -2
- package/dist/capture.js +0 -232
- package/dist/capture.js.map +0 -1
- package/dist/debug.js +0 -11
- package/dist/debug.js.map +0 -1
- package/dist/recall-gate.js +0 -65
- package/dist/recall-gate.js.map +0 -1
- package/dist/store.js +0 -304
- package/dist/store.js.map +0 -1
package/dist/index.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAA4B,IAAI,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,eAAe,EAAE,WAAW,EAAE,cAAc,EAAE,gBAAgB,EAAE,SAAS,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACrK,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,eAAe,EAAE,UAAU,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACzH,OAAO,EAAE,yBAAyB,EAAE,2BAA2B,EAAE,aAAa,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC9I,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AA6BtC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"}
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.ts", "../src/store.ts", "../src/debug.ts", "../src/capture.ts", "../src/recall-gate.ts"],
|
|
4
|
+
"sourcesContent": ["import { spawn } from 'node:child_process';\nimport { createHash } from 'node:crypto';\nimport { mkdir, readFile, rm, writeFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { homedir } from 'node:os';\nimport { type Config, type Plugin, tool } from '@opencode-ai/plugin';\nimport { autoMatchMemoirBranch, codeGitBranch, deriveStorePath, ensureStore, memoirResolved, memoirSpawnSpecs, runMemoir, setPluginStoreOverride } from './store.js';\nimport { EDIT_TOOLS, flushCapture, getCachedBranch, recordEdit, recordToolMetrics, setCachedBranch } from './capture.js';\nimport { DEFAULT_RECALL_NAMESPACES, isSecretSanitizationEnabled, pendingRecall, SECRET_PATTERN, shouldTriggerRecall } from './recall-gate.js';\nimport { debugLog } from './debug.js';\n\ntype CommandOutput = {\n parts: unknown[];\n};\n\ntype OpenCodeConfig = Config & {\n command?: Config['command'];\n};\n\ntype MemoirRememberArgs = {\n content: string;\n path?: string | string[];\n namespace?: string;\n replace?: boolean;\n};\n\ntype MemoirRecallArgs = {\n query?: string;\n namespace?: string;\n namespaces?: string[];\n includeMetrics?: boolean;\n};\n\ntype MemoirGetArgs = {\n keys: string[];\n namespace?: string;\n};\n\nasync function statusJson(store: string): Promise<string> {\n await ensureStore(store);\n const raw = await runMemoir(['--json', '-s', store, 'status'], { cwd: store });\n try {\n const data = JSON.parse(raw);\n const branch = await codeGitBranch();\n data.opencode = { store, project_git_root: process.cwd(), project_git_branch: branch };\n return JSON.stringify(data, null, 2);\n } catch (e) {\n debugLog('statusJson: failed to parse JSON:', e instanceof Error ? e.message : String(e));\n return raw;\n }\n}\n\nasync function launchUi(store: string): Promise<string> {\n await ensureStore(store);\n const pidDir = join(homedir(), '.memoir', 'ui-servers');\n await mkdir(pidDir, { recursive: true });\n const hash = createHash('sha256').update(store).digest('hex').slice(0, 8);\n const pidfile = join(pidDir, `${hash}.json`);\n\n try {\n const existing = JSON.parse(await readFile(pidfile, 'utf8'));\n if (existing?.pid && existing?.url) {\n try {\n process.kill(Number(existing.pid), 0); // check if alive\n return JSON.stringify({ ...existing, reused: true }, null, 2);\n } catch (e) {\n debugLog('launchUi: process dead, relaunching:', e instanceof Error ? e.message : String(e));\n // process is dead \u2014 fall through to relaunch\n }\n }\n } catch (e) {\n debugLog('launchUi: failed to read pidfile:', e instanceof Error ? e.message : String(e));\n await rm(pidfile, { force: true }).catch(() => undefined);\n }\n\n let lastError = '';\n const uiSpecs = memoirSpawnSpecs(['ui', store]);\n // Reorder: put cached memoir resolver first, same as runMemoir\n if (memoirResolved) {\n const idx = uiSpecs.findIndex(s => s.label === memoirResolved);\n if (idx > 0) {\n const [cached] = uiSpecs.splice(idx, 1);\n uiSpecs.unshift(cached);\n }\n }\n for (const spec of uiSpecs) {\n const child = spawn(spec.command, spec.args, {\n detached: true,\n stdio: ['ignore', 'pipe', 'pipe'],\n env: process.env,\n });\n\n let output = '';\n child.stdout?.on('data', chunk => { output += String(chunk); });\n child.stderr?.on('data', chunk => { output += String(chunk); });\n\n const spawnFailed = new Promise<string | null>(resolve => {\n child.once('error', error => resolve(String(error.message || error)));\n child.once('spawn', () => resolve(null));\n });\n const error = await spawnFailed;\n if (error) {\n lastError = `${spec.label}: ${error}`;\n continue;\n }\n\n child.unref();\n\n const urlPattern = /https?:\\/\\/(?:localhost|127\\.0\\.0\\.1):\\d+\\S*/;\n const deadline = Date.now() + 5000;\n while (Date.now() < deadline) {\n const match = output.match(urlPattern);\n if (match) {\n const url = match[0];\n const data = { pid: child.pid, url, store, command: spec.label, started: new Date().toISOString(), reused: false };\n await writeFile(pidfile, JSON.stringify(data, null, 2));\n return JSON.stringify(data, null, 2);\n }\n await new Promise(resolve => setTimeout(resolve, 100));\n }\n\n return `Memoir UI started with ${spec.label} (pid ${child.pid ?? 'unknown'}), but URL was not detected yet.\\n${output.trim()}`.trim();\n }\n\n return `Memoir UI failed to start: ${lastError || 'no launcher succeeded'}`;\n}\n\nexport function coercePaths(path: string | string[] | undefined): string[] {\n if (!path) return [];\n return Array.isArray(path) ? path.filter(Boolean) : [path];\n}\n\nfunction pushText(output: CommandOutput, text: string): void {\n output.parts.length = 0;\n output.parts.push({ type: 'text', text });\n}\n\n/** Format JSON string with 2-space indentation. Passes non-JSON through unchanged. */\nexport function tryPrettyJson(text: string): string {\n try {\n return JSON.stringify(JSON.parse(text), null, 2);\n } catch {\n return text;\n }\n}\n\n/** Cached session init context (taxonomy overview). Fetched once, injected per-session. */\nlet initContext: string | null = null;\nlet initContextFetched = false;\n/**\n * Tracks sessions that have received initial context injection.\n * Uses a Map with timestamp so stale entries can be evicted.\n * Cleaned on dispose. Sessions older than 1 hour are considered stale.\n */\nconst SESSION_CONTEXT_TTL_MS = 60 * 60 * 1000;\nconst sessionsWithContext = new Map<string, number>();\n\n/** Check if a session has received context (and prune stale entries opportunistically). */\nfunction hasSessionContext(sessionID: string): boolean {\n const ts = sessionsWithContext.get(sessionID);\n if (ts === undefined) return false;\n if (Date.now() - ts > SESSION_CONTEXT_TTL_MS) {\n sessionsWithContext.delete(sessionID);\n return false;\n }\n return true;\n}\n\n/** Mark a session as having received context. */\nfunction markSessionContext(sessionID: string): void {\n sessionsWithContext.set(sessionID, Date.now());\n}\n\n/** Prune all stale session entries. */\nfunction pruneStaleSessions(): void {\n const now = Date.now();\n for (const [id, ts] of sessionsWithContext) {\n if (now - ts > SESSION_CONTEXT_TTL_MS) sessionsWithContext.delete(id);\n }\n}\n\nfunction registerCommands(config: OpenCodeConfig): void {\n config.command = config.command ?? {};\n\n config.command['memoir:status'] = {\n description: 'Show Memoir status for the current OpenCode project',\n template: 'Show Memoir status for this OpenCode project.',\n };\n\n config.command['memoir:ui'] = {\n description: 'Launch or reopen the Memoir web UI for this project store',\n template: 'Launch or reopen the Memoir UI for this project.',\n };\n\n config.command['memoir:remember'] = {\n description: 'Save a durable fact, preference, rule, or decision to Memoir',\n template: `Use Memoir to save this durable memory now.\\n\\nUSER REQUEST:\\n$ARGUMENTS\\n\\nExtract the memory content, choose a semantic path if none is supplied, then call the memoir_remember tool. Never save secrets.`,\n };\n\n config.command['memoir:recall'] = {\n description: 'Recall relevant facts from Memoir before answering',\n template: `Recall relevant Memoir memories for this request.\\n\\nUSER REQUEST:\\n$ARGUMENTS\\n\\nUse memoir_recall first. It checks default plus onboard namespaces unless a namespace is specified. Then call memoir_get with the matching namespace for exact values before answering.`,\n };\n\n config.command['memoir:onboard'] = {\n description: 'Populate or refresh Memoir onboarding for this project',\n template: `Populate or refresh Memoir onboarding for the CURRENT OpenCode project only.\\n\\nUSER REQUEST:\\n$ARGUMENTS\\n\\nWorkflow:\\n- Stay inside the current project/worktree. Do not inspect parent directories.\\n- First obtain a project file tree to understand structure.\\n- Start studying from project documentation.\\n- Continue only based on what the tree and documentation show.\\n\\nMemory rules:\\n- Record only verified facts from files/docs/code or explicit user statements.\\n- Do not write inferred user thoughts, intentions, preferences, or opinions.\\n- Do not use preferences.* paths unless the user explicitly stated a preference.\\n- If a fact is your interpretation, do not save it; report it as uncertain instead.\\n\\nThen call memoir_remember with replace=true for durable onboarding facts. Use namespace codebase:onboard in git repositories and project:onboard outside git. Do not install or invoke separate skills/scripts.`,\n };\n\n config.command['memoir:unmerged'] = {\n description: 'List memoir branches with changes not yet merged into main',\n template: 'List memoir branches that have diverged from main.',\n };\n}\n\nconst memoirStatus = tool({\n description: 'Show Memoir status for the current OpenCode project store.',\n args: {},\n execute: async () => statusJson(deriveStorePath()),\n});\n\nconst memoirRemember = tool({\n description: 'Explicitly save a durable memory to Memoir at one or more semantic taxonomy paths.',\n args: {\n content: tool.schema.string().describe('Memory content to save. Do not include secrets.'),\n path: tool.schema.string().optional().describe('Semantic taxonomy path, e.g. preferences.coding.style.'),\n namespace: tool.schema.string().optional().describe('Memoir namespace. Defaults to default.'),\n replace: tool.schema.boolean().optional().describe('Replace existing value at the path.'),\n },\n execute: async (args: MemoirRememberArgs) => {\n const content = args.content?.trim();\n if (!content) return 'Memoir memory was not saved: content is empty.';\n if (isSecretSanitizationEnabled() && SECRET_PATTERN.test(content)) {\n return 'Memoir memory was not saved: the content looks like a secret or credential. Save a redacted rule instead.';\n }\n const paths = coercePaths(args.path);\n if (paths.length === 0) {\n return 'Memoir memory was not saved: provide a semantic path, e.g. preferences.coding.style.';\n }\n\n const store = deriveStorePath();\n try {\n await ensureStore(store);\n } catch (error) {\n return String((error as Error).message || error);\n }\n\n const cliArgs = ['--json', '-s', store, 'remember', content];\n for (const p of paths) cliArgs.push('-p', p);\n cliArgs.push('-n', args.namespace ?? 'default');\n if (args.replace) cliArgs.push('--replace');\n return tryPrettyJson(await runMemoir(cliArgs, { cwd: store }));\n },\n});\n\nconst memoirRecall = tool({\n description: 'List Memoir memory keys across relevant namespaces for relevance picking. Never calls legacy memoir recall.',\n args: {\n query: tool.schema.string().optional().describe('User query or topic to recall for.'),\n namespace: tool.schema.string().optional().describe('Single Memoir namespace to inspect. If omitted, checks default + onboard namespaces.'),\n namespaces: tool.schema.array(tool.schema.string()).optional().describe('Namespaces to inspect. Defaults to default, project:onboard, codebase:onboard.'),\n includeMetrics: tool.schema.boolean().optional().describe('Include metrics.* memories in the listing.'),\n },\n execute: async (args: MemoirRecallArgs) => {\n const store = deriveStorePath();\n try {\n await ensureStore(store);\n } catch (error) {\n return String((error as Error).message || error);\n }\n\n const namespaces = args.namespace\n ? [args.namespace]\n : (args.namespaces && args.namespaces.length > 0 ? args.namespaces : DEFAULT_RECALL_NAMESPACES);\n const sections: string[] = [];\n for (const namespace of namespaces) {\n const output = tryPrettyJson(await runMemoir(['--json', '-s', store, 'summarize', '--depth', '3', '-n', namespace], { cwd: store }));\n sections.push(`## namespace: ${namespace}\\n${output}`);\n }\n const note = args.includeMetrics\n ? 'Metrics were included by request.'\n : 'Ignore metrics.* and taxonomy:v1:* entries unless explicitly needed. If default is empty or only metrics, inspect project:onboard/codebase:onboard before concluding there is no memory.';\n const query = args.query ? `Query: ${args.query}\\n` : '';\n return `${query}${note}\\nPick at most 5-7 relevant exact keys across namespaces, then call memoir_get with the matching namespace if values are needed.\\n${sections.join('\\n\\n')}`;\n },\n});\n\n/** Max keys memoir_get accepts to avoid hitting OS arg-length limits. */\nexport const MEMOIR_GET_MAX_KEYS = 20;\n\nconst memoirGet = tool({\n description: 'Fetch exact Memoir memory keys after selecting them from memoir_recall output.',\n args: {\n keys: tool.schema.array(tool.schema.string()).describe('Exact memory keys to fetch.'),\n namespace: tool.schema.string().optional().describe('Memoir namespace. Defaults to default.'),\n },\n execute: async (args: MemoirGetArgs) => {\n const keys = args.keys?.map((key) => key.trim()).filter(Boolean) ?? [];\n if (keys.length === 0) return 'No Memoir keys were provided.';\n if (keys.length > MEMOIR_GET_MAX_KEYS) {\n return `Error: Too many keys requested (max ${MEMOIR_GET_MAX_KEYS}, got ${keys.length}). Narrow your selection from memoir_recall output.`;\n }\n\n const store = deriveStorePath();\n try {\n await ensureStore(store);\n } catch (error) {\n return String((error as Error).message || error);\n }\n\n return tryPrettyJson(await runMemoir(['--json', '-s', store, 'get', ...keys, '-n', args.namespace ?? 'default'], { cwd: store }));\n },\n});\n\nconst MemoirOpenCode: Plugin = async (_input, rawOptions) => {\n const opts = (rawOptions ?? {}) as { store?: string };\n if (opts.store) setPluginStoreOverride(opts.store);\n\n // Resolve store path once at init so shell.env doesn't call execFileSync\n // on every shell command (mirrors Claude Code's MEMOIR_STORE_PATH caching).\n const storeRoot = deriveStorePath();\n\n return ({\n name: 'memoir',\n tool: {\n memoir_status: memoirStatus,\n memoir_remember: memoirRemember,\n memoir_recall: memoirRecall,\n memoir_get: memoirGet,\n },\n config: async (opencodeConfig: OpenCodeConfig) => {\n registerCommands(opencodeConfig);\n },\n 'command.execute.before': async (input: { command?: string }, output: CommandOutput) => {\n try {\n if (input.command === 'memoir:status') {\n pushText(output, await statusJson(deriveStorePath()));\n }\n if (input.command === 'memoir:ui') {\n pushText(output, await launchUi(deriveStorePath()));\n }\n if (input.command === 'memoir:unmerged') {\n const store = deriveStorePath();\n await ensureStore(store);\n const raw = await runMemoir(['--json', '-s', store, 'branch'], { cwd: store });\n const data = JSON.parse(raw);\n const branches: string[] = data?.branches ?? [];\n const unmerged: string[] = [];\n for (const branch of branches) {\n if (branch === 'main') continue;\n const diffOut = await runMemoir(['-s', store, 'diff', branch, 'main', '--stat'], { cwd: store }).catch(() => '');\n if (diffOut.trim()) {\n unmerged.push(branch);\n }\n }\n pushText(output,\n unmerged.length > 0\n ? `Unmerged branches:\\n${unmerged.join('\\n')}`\n : 'All branches are merged into main.'\n );\n }\n } catch (error) {\n pushText(output, `Memoir command failed: ${String((error as Error).message || error)}`);\n }\n },\n\n /**\n * Inject MEMOIR_STORE into every shell command's environment so any memoir\n * invocation automatically targets the right store without manual -s flags.\n * Uses the cached value resolved at init time (avoiding execFileSync overhead\n * on every shell command).\n */\n 'shell.env': async (_input, output) => {\n try {\n output.env.MEMOIR_STORE = storeRoot;\n } catch (e) {\n debugLog('shell.env: failed:', e instanceof Error ? e.message : String(e));\n }\n },\n\n /**\n * Observe every tool execution for metrics and code-change tracking.\n * Mirrors the observation phase of Claude Code's Stop hook.\n * Never modifies the tool output.\n */\n 'tool.execute.after': async (input, output) => {\n try {\n // Per-session state key\n const sid = input.sessionID ?? 'default';\n\n // Accumulate per-tool metrics (cf. collect-metrics.sh).\n // Skipped when MEMOIR_NO_CAPTURE or MEMOIR_NO_METRICS is set.\n if (process.env.MEMOIR_NO_CAPTURE !== '1' && process.env.MEMOIR_NO_METRICS !== '1') {\n const calls = 1;\n const errors = (output.metadata?.error || output.output?.startsWith('Error:')) ? 1 : 0;\n recordToolMetrics(sid, input.tool, { calls, errors });\n }\n\n // Track file edits (cf. collect-edits.sh).\n // Skipped when MEMOIR_NO_CAPTURE or MEMOIR_NO_CODE_SUMMARY is set.\n if (process.env.MEMOIR_NO_CAPTURE !== '1' && process.env.MEMOIR_NO_CODE_SUMMARY !== '1' && EDIT_TOOLS.has(input.tool)) {\n const filePath =\n typeof input.args?.filePath === 'string' ? input.args.filePath\n : typeof input.args?.path === 'string' ? input.args.path\n : '';\n if (filePath) {\n recordEdit(sid, { tool: input.tool, filePath, snippet: '', timestamp: Date.now() });\n }\n }\n } catch (e) {\n debugLog('tool.execute.after: failed:', e instanceof Error ? e.message : String(e));\n }\n },\n\n /**\n * Fires on every incoming user message.\n *\n * 1. Auto-match memoir branch to current git branch\n * (cf. UserPromptSubmit's auto_match_memoir_branch in Claude Code plugin).\n * 2. Flush pending edits from the previous assistant turn\n * (cf. Stop hook code change audit, run after each turn).\n * 3. Run the recall gate (cf. UserPromptSubmit).\n *\n * Steps 1\u20132 are skipped when MEMOIR_NO_CAPTURE=1.\n */\n 'chat.message': async (input, output) => {\n try {\n const sid = input.sessionID ?? 'default';\n\n // C4: run recall gate BEFORE any await \u2014 otherwise system.transform\n // could fire before pendingRecall is set.\n const text = output.parts\n .filter((p): p is typeof p & { type: 'text'; text: string } => p.type === 'text')\n .map(p => p.text)\n .join(' ');\n if (shouldTriggerRecall(text)) {\n pendingRecall.add(sid);\n }\n\n // Snapshot previous branch BEFORE switching \u2014 edits from the last turn\n // belong to the OLD branch. (C2 fix: prevents misattribution when the\n // user switches git branch between turns.)\n const prevBranch = getCachedBranch(sid) === 'unknown' ? undefined : getCachedBranch(sid);\n setCachedBranch(sid, await autoMatchMemoirBranch(storeRoot));\n\n // Skip capture flush when MEMOIR_NO_CAPTURE is set.\n // Flush under the PREVIOUS branch (the one edits were made on).\n if (process.env.MEMOIR_NO_CAPTURE !== '1') {\n await flushCapture(storeRoot, prevBranch, sid);\n }\n } catch (e) {\n debugLog('chat.message: failed:', e instanceof Error ? e.message : String(e));\n }\n },\n\n /**\n * Fires on SDK events. On session.created, kick off a background fetch of\n * the taxonomy overview so it's ready before the first LLM call.\n * Mirrors Claude Code's SessionStart context injection.\n */\n event: async ({ event: evt }: { event: { type: string } }) => {\n if (evt.type === 'session.created' && !initContextFetched) {\n initContextFetched = true;\n (async () => {\n try {\n const taxonomy = await runMemoir(\n ['--json', '-s', storeRoot, 'summarize', '--depth', '3', '-n', 'default'],\n { cwd: storeRoot }\n );\n if (taxonomy.startsWith('Memoir command failed')) {\n throw new Error(taxonomy);\n }\n const pretty = tryPrettyJson(taxonomy);\n initContext = `[memoir] Available taxonomy paths:\\n${pretty}`;\n } catch (e: unknown) {\n debugLog('event: taxonomy fetch failed, will retry on next session:', e instanceof Error ? e.message : String(e));\n // Allow a later session to retry \u2014 the store may not have been ready yet.\n initContextFetched = false;\n }\n })();\n }\n },\n\n /**\n * Fires before every LLM call.\n *\n * 1. Injects the memoir taxonomy context for this session (once per session).\n * 2. If a recall is pending for this session, injects a brief instruction\n * telling the model to use memoir tools (one-shot per trigger).\n */\n 'experimental.chat.system.transform': async (input, output) => {\n try {\n // Inject initial context on the first LLM call of each session\n if (input.sessionID && !hasSessionContext(input.sessionID)) {\n markSessionContext(input.sessionID);\n if (initContext) {\n output.system.unshift(initContext);\n }\n }\n\n // Inject recall instruction (one-shot per trigger)\n if (input.sessionID && pendingRecall.has(input.sessionID)) {\n pendingRecall.delete(input.sessionID);\n output.system.push(\n '\\n[memoir] The user may have relevant context in Memoir. Run memoir_recall to list available memories across default and onboard namespaces, then memoir_get with the matching namespace to fetch exact values.'\n );\n }\n } catch (e) {\n debugLog('system.transform: failed:', e instanceof Error ? e.message : String(e));\n }\n },\n\n /**\n * Fires when the plugin is shut down. Flushes any remaining code changes\n * and metrics (cf. SessionEnd heartbeat cleanup + final metrics flush).\n */\n dispose: async () => {\n // No sessionID \u2192 flushCapture flushes ALL sessions\n await flushCapture(storeRoot);\n pruneStaleSessions();\n sessionsWithContext.clear();\n },\n});\n};\n\nexport default MemoirOpenCode;\n", "import { execFile, execFileSync } from 'node:child_process';\nimport { access, mkdir, rm } from 'node:fs/promises';\nimport { join, resolve } from 'node:path';\nimport { homedir, tmpdir } from 'node:os';\nimport { promisify } from 'node:util';\nimport { debugLog } from './debug.js';\n\nconst execFileAsync = promisify(execFile);\n\nexport const MEMOIR_PACKAGE = 'memoir-ai';\n\n/**\n * Pinned memoir-ai version for uvx/uv fallbacks.\n * Mirrors plugins/claude-code/scripts/resolve-memoir-cli.sh.\n * Bump deliberately after verifying the new release works with this plugin.\n */\nexport const MEMOIR_AI_PIN = '0.2.2';\n\nexport type SpawnSpec = { command: string; args: string[]; label: string };\n\n/**\n * Cache of cwds confirmed to be outside a git repo.\n * Avoids redundant ~200ms failing `git rev-parse` calls on non-git directories.\n */\nexport const _noGitCache = new Set<string>();\n\n/**\n * Resolve the main worktree root path for a git repository.\n * Mirrors _main_worktree_root from plugins/claude-code/scripts/derive-store-path.sh.\n *\n * @returns The main worktree path, or empty string if not in a git repo.\n */\nexport function _main_worktree_root(cwd: string): string {\n if (_noGitCache.has(cwd)) return '';\n try {\n // Fast path: check if --git-dir and --git-common-dir resolve to the same path\n const gitDir = execFileSync('git', ['rev-parse', '--git-dir'], { cwd, encoding: 'utf8', timeout: 3000 }).trim();\n const gitCommonDir = execFileSync('git', ['rev-parse', '--git-common-dir'], { cwd, encoding: 'utf8', timeout: 3000 }).trim();\n\n // Resolve to absolute paths\n const resolvePath = (path: string): string => {\n if (path.startsWith('/')) return path;\n return join(cwd, path);\n };\n const gitDirAbs = resolvePath(gitDir);\n const gitCommonDirAbs = resolvePath(gitCommonDir);\n\n if (gitDirAbs === gitCommonDirAbs) {\n // Main worktree or non-worktree repo\n return execFileSync('git', ['rev-parse', '--show-toplevel'], { cwd, encoding: 'utf8', timeout: 3000 }).trim();\n }\n\n // Slow path: parse `git worktree list --porcelain` for the main worktree\n const worktreeList = execFileSync('git', ['worktree', 'list', '--porcelain'], { cwd, encoding: 'utf8', timeout: 3000 });\n const firstLine = worktreeList.split('\\n')[0];\n if (firstLine.startsWith('worktree ')) {\n const mainWorktree = firstLine.substring('worktree '.length).trim();\n if (mainWorktree && mainWorktree !== '(bare)') {\n return mainWorktree;\n }\n }\n\n // Fallback: try --show-toplevel (bare repo or older git)\n return execFileSync('git', ['rev-parse', '--show-toplevel'], { cwd, encoding: 'utf8', timeout: 3000 }).trim();\n } catch (e) {\n debugLog('_main_worktree_root: not a git repo or git error:', e instanceof Error ? e.message : String(e));\n _noGitCache.add(cwd);\n return '';\n }\n}\n\n/**\n * Derive `~/.memoir/<slug>` from cwd.\n * Override via `store` plugin option or `MEMOIR_STORE` env var.\n *\n * Resolution order (mirrors plugins/claude-code/scripts/derive-store-path.sh):\n * 1. Plugin option override\n * 2. MEMOIR_STORE env var\n * 3. Git root (realpath) \u2014 all worktrees of a repo share one store\n * 4. `path.resolve()` of cwd \u2014 normalized deterministic slug for non-git folders\n * 5. Raw cwd fallback\n */\nexport function deriveStorePath(cwd: string = process.cwd()): string {\n if (pluginStoreOverride) return pluginStoreOverride;\n const configured = process.env.MEMOIR_STORE;\n if (configured) return configured;\n\n // Prefer git root so all subdirectories and worktrees share one store\n let projectDir: string;\n try {\n const gitRoot = _main_worktree_root(cwd);\n if (gitRoot) {\n projectDir = gitRoot;\n } else {\n // Not in git \u2014 normalize to deterministic absolute path\n projectDir = resolve(cwd);\n }\n } catch (e) {\n debugLog('deriveStorePath: unexpected error:', e instanceof Error ? e.message : String(e));\n // Fallback to raw cwd if everything else fails\n projectDir = cwd;\n }\n\n // Slug = absolute path with '/' and '.' replaced by '-'\n // Matches Claude Code's own ~/.claude/projects/ naming convention\n const slug = projectDir.replace(/[/.]/g, '-');\n return join(homedir(), '.memoir', slug);\n}\n\n/** Set by plugin options (`store` key). */\nexport let pluginStoreOverride: string | undefined;\n\n/** Set `pluginStoreOverride` from plugin init. Exported as a function\n * because ES module imports are read-only bindings (direct assignment\n * from another module is a TS2632 error). */\nexport function setPluginStoreOverride(store: string | undefined): void {\n pluginStoreOverride = store;\n}\n\n/** Cache of stores already verified or created \u2014 avoids redundant access() + CLI calls. */\nexport const ensuredStores = new Set<string>();\n\n/**\n * Stores currently being created \u2014 prevents concurrent `memoir new` on\n * the same path (C5 fix).\n */\nconst storeCreations = new Map<string, Promise<void>>();\n\nexport async function ensureStore(store: string): Promise<void> {\n if (ensuredStores.has(store)) return;\n\n // If another caller is already creating this store, await it\n const inFlight = storeCreations.get(store);\n if (inFlight) {\n await inFlight;\n return;\n }\n\n try {\n await access(join(store, '.git'));\n ensuredStores.add(store);\n return; // already exists\n } catch {\n // ensure parent dir exists (memoir new doesn't create intermediate dirs)\n await mkdir(join(store, '..'), { recursive: true }).catch((e: unknown) => debugLog('ensureStore: mkdir failed:', e instanceof Error ? e.message : String(e)));\n }\n\n // Register this creation so concurrent callers coallesce\n const creationPromise = (async () => {\n const tmpDir = join(tmpdir(), `memoir-scratch-${Date.now()}`);\n try {\n await mkdir(tmpDir, { recursive: true });\n await execFileAsync('git', ['init', '-q', tmpDir], { timeout: 5000 });\n const result = await runMemoir(['new', store, '--taxonomy-builtin'], { cwd: tmpDir });\n if (result.startsWith('Memoir command failed')) {\n throw new Error(result);\n }\n ensuredStores.add(store);\n } finally {\n rm(tmpDir, { recursive: true, force: true }).catch(() => undefined);\n }\n })();\n storeCreations.set(store, creationPromise);\n try {\n await creationPromise;\n } finally {\n storeCreations.delete(store);\n }\n}\n\n/** Which CLI launcher successfully resolved memoir. Cached to avoid redundant fallback probing. */\nexport let memoirResolved: string | null = null;\n\nexport async function runMemoir(args: string[], options: { cwd?: string } = {}): Promise<string> {\n const specs = memoirSpawnSpecs(args);\n\n // Put cached resolver first so we skip redundant fallback probing\n if (memoirResolved) {\n const idx = specs.findIndex(s => s.label === memoirResolved);\n if (idx > 0) {\n const [cached] = specs.splice(idx, 1);\n specs.unshift(cached);\n }\n }\n\n for (const spec of specs) {\n try {\n const { stdout } = await execFileAsync(spec.command, spec.args, {\n cwd: options.cwd ?? process.cwd(),\n env: process.env,\n maxBuffer: 1024 * 1024,\n timeout: 15_000, // prevent hang if memoir CLI stalls\n });\n memoirResolved = spec.label;\n return stdout.trim();\n } catch (e) {\n debugLog('runMemoir: fallback', spec.label, 'failed:', e instanceof Error ? e.message : String(e));\n // Invalidate cache so we don't keep trying a broken resolver on next call\n if (memoirResolved === spec.label) memoirResolved = null;\n }\n }\n\n // Build a fallback-free attempt at memoir direct for the error message\n try {\n const { stdout } = await execFileAsync('memoir', args, {\n cwd: options.cwd ?? process.cwd(),\n env: process.env,\n maxBuffer: 1024 * 1024,\n timeout: 15_000,\n });\n return stdout.trim(); // shouldn't get here since all specs failed, but defensive\n } catch (memoirError) {\n const err = memoirError as Error & { stdout?: string; stderr?: string; code?: number };\n const detail = (err.stderr || err.stdout || err.message).trim();\n return `Memoir command failed${err.code ? ` (${err.code})` : ''}: ${detail}`;\n }\n}\n\nexport function memoirSpawnSpecs(args: string[]): SpawnSpec[] {\n return [\n { command: 'memoir', args, label: 'memoir' },\n { command: 'uvx', args: ['--from', `${MEMOIR_PACKAGE}==${MEMOIR_AI_PIN}`, 'memoir', ...args], label: 'uvx' },\n { command: 'uv', args: ['tool', 'run', '--from', `${MEMOIR_PACKAGE}==${MEMOIR_AI_PIN}`, 'memoir', ...args], label: 'uv tool run' },\n ];\n}\n\n/** Read the current memoir branch name for use in storage keys. */\nexport async function getCurrentBranch(store: string): Promise<string> {\n try {\n const raw = await runMemoir(['--json', '-s', store, 'status'], { cwd: store });\n const data = JSON.parse(raw);\n return data.branch || 'unknown';\n } catch (e) {\n debugLog('getCurrentBranch: failed:', e instanceof Error ? e.message : String(e));\n return 'unknown';\n }\n}\n\n/**\n * Return the current git branch of the user's project (from cwd).\n * Empty string if not in a git repo or detached HEAD.\n * Mirrors code_git_branch from plugins/claude-code/hooks/common.sh.\n */\nexport async function codeGitBranch(): Promise<string> {\n try {\n const { stdout } = await execFileAsync('git', ['branch', '--show-current'], { encoding: 'utf8', timeout: 3000 });\n return stdout.trim();\n } catch (e) {\n debugLog('codeGitBranch: failed:', e instanceof Error ? e.message : String(e));\n return '';\n }\n}\n\n/**\n * Check whether a branch exists in the memoir store.\n * Mirrors branch_exists_in_memoir from plugins/claude-code/hooks/common.sh.\n */\nexport async function branchExistsInMemoir(store: string, name: string): Promise<boolean> {\n if (!name) return false;\n try {\n const raw = await runMemoir(['--json', '-s', store, 'branch'], { cwd: store });\n const data = JSON.parse(raw);\n const branches: string[] = data?.branches ?? [];\n return branches.includes(name);\n } catch (e) {\n debugLog('branchExistsInMemoir: failed:', e instanceof Error ? e.message : String(e));\n return false;\n }\n}\n\n/**\n * Auto-match memoir branch to the current code git branch.\n * If the code branch differs from the memoir branch, creates the memoir branch\n * (forked from main) if needed and checks it out.\n * Mirrors auto_match_memoir_branch from plugins/claude-code/hooks/common.sh.\n */\nexport async function autoMatchMemoirBranch(store: string): Promise<string> {\n const codeBranch = await codeGitBranch();\n if (!codeBranch) {\n return getCurrentBranch(store); // detached or non-git \u2014 just report current\n }\n\n const current = await getCurrentBranch(store);\n if (current === codeBranch) return current; // already matched\n\n // Create the branch from main if it doesn't exist yet\n if (!(await branchExistsInMemoir(store, codeBranch))) {\n const result = await runMemoir(['-s', store, 'branch', codeBranch, '--from', 'main'], { cwd: store });\n if (result.startsWith('Memoir command failed')) {\n debugLog('autoMatchMemoirBranch: create branch failed:', result);\n return getCurrentBranch(store);\n }\n }\n // Checkout the branch\n const result = await runMemoir(['-s', store, 'checkout', codeBranch], { cwd: store });\n if (result.startsWith('Memoir command failed')) {\n debugLog('autoMatchMemoirBranch: checkout failed:', result);\n return getCurrentBranch(store);\n }\n return codeBranch;\n}\n\n/**\n * Read the content of a single memoir key (first item found).\n * Returns empty string if key doesn't exist or on error.\n */\nexport async function readMemoirValue(store: string, key: string, namespace: string = 'default'): Promise<string> {\n try {\n const raw = await runMemoir(['--json', '-s', store, 'get', key, '-n', namespace], { cwd: store });\n const parsed = JSON.parse(raw);\n const items = parsed?.items ?? [];\n const value = items[0]?.value?.content;\n return typeof value === 'string' ? value : '';\n } catch (e) {\n debugLog('readMemoirValue: failed:', e instanceof Error ? e.message : String(e));\n return '';\n }\n}\n", "/**\n * Debug logger writing to stderr. Prefixes with [memoir] for easy filtering.\n * Only writes when MEMOIR_DEBUG=1 is set.\n */\nexport function debugLog(...args: unknown[]): void {\n if (process.env.MEMOIR_DEBUG !== '1') return;\n const ts = new Date().toISOString();\n process.stderr.write(`[memoir ${ts}] ${args.map(a => String(a)).join(' ')}\\n`);\n}\n", "import { deriveStorePath, ensureStore, getCurrentBranch, readMemoirValue, runMemoir } from './store.js';\nimport { debugLog } from './debug.js';\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport const EDIT_TOOLS = new Set(['Edit', 'Write', 'MultiEdit', 'NotebookEdit', 'apply_patch', 'ApplyPatch', 'MultiFileEdit']);\n\nexport interface EditRecord {\n tool: string;\n filePath: string;\n snippet: string;\n timestamp: number;\n}\n\nexport interface ToolMetrics {\n calls: number;\n errors: number;\n}\n\n/**\n * Maximum entries retained in metrics.code.<branch>.\n * Mirrors MEMOIR_METRICS_CODE_MAX from plugins/claude-code/hooks/stop.sh.\n */\nexport const METRICS_CODE_MAX = 1000;\n\n// ---------------------------------------------------------------------------\n// Per-session state\n// ---------------------------------------------------------------------------\n\nconst pendingEditsBySession = new Map<string, EditRecord[]>();\nconst toolMetricsBySession = new Map<string, Map<string, ToolMetrics>>();\nconst cachedBranchBySession = new Map<string, string>();\n\nexport function getCachedBranch(sessionID: string): string {\n return cachedBranchBySession.get(sessionID) ?? 'unknown';\n}\n\nexport function setCachedBranch(sessionID: string, branch: string): void {\n cachedBranchBySession.set(sessionID, branch);\n}\n\n/** Record an edit for a specific session. */\nexport function recordEdit(sessionID: string, edit: EditRecord): void {\n let edits = pendingEditsBySession.get(sessionID);\n if (!edits) { edits = []; pendingEditsBySession.set(sessionID, edits); }\n edits.push(edit);\n}\n\n/** Accumulate tool metrics for a specific session (adds to previous values). */\nexport function recordToolMetrics(sessionID: string, tool: string, metrics: ToolMetrics): void {\n let sessionMetrics = toolMetricsBySession.get(sessionID);\n if (!sessionMetrics) { sessionMetrics = new Map(); toolMetricsBySession.set(sessionID, sessionMetrics); }\n const prev = sessionMetrics.get(tool) ?? { calls: 0, errors: 0 };\n sessionMetrics.set(tool, {\n calls: prev.calls + metrics.calls,\n errors: prev.errors + metrics.errors,\n });\n}\n\n/** Peek at a session's pending edits (test helper, read-only). */\nexport function getPendingEdits(sessionID: string): readonly EditRecord[] {\n return pendingEditsBySession.get(sessionID) ?? [];\n}\n\n/** Peek at a session's tool metrics (test helper, read-only). */\nexport function getToolMetrics(sessionID: string): ReadonlyMap<string, ToolMetrics> {\n return toolMetricsBySession.get(sessionID) ?? new Map();\n}\n\n/** Clear all state for a session (test helper). */\nexport function clearSession(sessionID: string): void {\n pendingEditsBySession.delete(sessionID);\n toolMetricsBySession.delete(sessionID);\n cachedBranchBySession.delete(sessionID);\n}\n\n// ---------------------------------------------------------------------------\n// parse / serialize\n// ---------------------------------------------------------------------------\n\nexport function parseTurnMetrics(text: string): Map<string, ToolMetrics> {\n const result = new Map<string, ToolMetrics>();\n if (!text) return result;\n const parts = text.split('|');\n for (const part of parts) {\n const trimmed = part.trim();\n if (!trimmed) continue;\n const [tool, callsStr, errorsStr] = trimmed.split(':');\n if (!tool) continue;\n result.set(tool, {\n calls: parseInt(callsStr, 10) || 0,\n errors: parseInt(errorsStr, 10) || 0,\n });\n }\n return result;\n}\n\nexport function serializeTurnMetrics(map: Map<string, ToolMetrics>): string {\n return [...map.entries()]\n .map(([tool, m]) => `${tool}:${m.calls}:${m.errors}`)\n .join(' | ');\n}\n\n// ---------------------------------------------------------------------------\n// Per-store mutex\n// ---------------------------------------------------------------------------\n\nconst flushQueues = new Map<string, Promise<void>>();\n\nasync function acquireFlushLock(store: string): Promise<() => void> {\n const prev = flushQueues.get(store) ?? Promise.resolve();\n let release: () => void;\n const next = new Promise<void>(resolve => { release = resolve; });\n flushQueues.set(store, next);\n await prev;\n return () => {\n release();\n if (flushQueues.get(store) === next) flushQueues.delete(store);\n };\n}\n\n// ---------------------------------------------------------------------------\n// ---------------------------------------------------------------------------\n// flushCapture \u2014 flushes one session, or all if no sessionID\n// ---------------------------------------------------------------------------\n\nexport async function flushCapture(store?: string, branch?: string, sessionID?: string): Promise<void> {\n // Determine which sessions to flush\n const targets: string[] = sessionID\n ? [sessionID]\n : [...pendingEditsBySession.keys()]; // dispose: flush all sessions\n if (targets.length === 0) return;\n\n try {\n store = store ?? deriveStorePath();\n if (!store) return;\n await ensureStore(store);\n\n // Acquire store-level mutex before touching per-session state.\n // Prevents C1 (cross-session interleave) and C2-RACE (data arriving\n // between snapshot and drain).\n const releaseLock = await acquireFlushLock(store);\n try {\n // Atomic swap: grab current data and replace with empty containers.\n // Any recordEdit/recordToolMetrics call during the subsequent I/O\n // goes into the fresh empty containers and is safe.\n interface SessionData { edits: EditRecord[]; metrics: Map<string, ToolMetrics>; sessionBranch: string; }\n const perSession: SessionData[] = [];\n const swappedSids = new Map<string, number>(); // sid \u2192 index in perSession for rollback\n for (const sid of targets) {\n const idx = perSession.length;\n const edits = pendingEditsBySession.get(sid) ?? [];\n pendingEditsBySession.set(sid, []);\n const metrics = toolMetricsBySession.get(sid) ?? new Map();\n toolMetricsBySession.set(sid, new Map());\n const sb = branch ?? cachedBranchBySession.get(sid);\n perSession.push({ edits, metrics, sessionBranch: sb ?? 'unknown' });\n swappedSids.set(sid, idx);\n }\n\n // Skip if nothing to flush\n if (!perSession.some(p => p.edits.length > 0 || p.metrics.size > 0)) return;\n\n // Wrap I/O in inner try \u2014 if it fails, restore swapped data before\n // propagating the error so the next flush retries it.\n try {\n // Resolve 'unknown' branches (read-only I/O, safe inside lock \u2014\n // the lock serializes per-store CLI access)\n for (const p of perSession) {\n if (p.sessionBranch === 'unknown' || !p.sessionBranch) {\n p.sessionBranch = await getCurrentBranch(store);\n }\n }\n\n // For each session, read-merge-write sequentially.\n for (const p of perSession) {\n const { edits, metrics, sessionBranch: branchKey } = p;\n if (edits.length === 0 && metrics.size === 0) continue;\n\n const [prevCodeRaw, prevTurnRaw] = await Promise.all([\n edits.length > 0 ? readMemoirValue(store, `metrics.code.${branchKey}`) : Promise.resolve(''),\n metrics.size > 0 ? readMemoirValue(store, `metrics.turn.${branchKey}`) : Promise.resolve(''),\n ]);\n\n let codeWrite: Promise<string> | undefined;\n if (edits.length > 0) {\n const files = [...new Set(edits.map(e => e.filePath))];\n const entry = {\n timestamp: Date.now() / 1000,\n summary: `Changed ${edits.length} block(s) across ${files.length} file(s): ${files.join(', ')}`,\n files,\n };\n\n let acc: { schema_version: number; entries: Array<Record<string, unknown>> } = {\n schema_version: 2, entries: [],\n };\n if (prevCodeRaw) {\n try {\n const parsed = JSON.parse(prevCodeRaw);\n if (parsed?.entries && Array.isArray(parsed.entries)) {\n acc = parsed;\n if (acc.schema_version < 2) acc.schema_version = 2;\n }\n } catch (e) {\n debugLog('flushCapture: failed to parse existing code metrics, starting fresh:', e instanceof Error ? e.message : String(e));\n }\n }\n acc.entries.push(entry as unknown as Record<string, unknown>);\n if (acc.entries.length > METRICS_CODE_MAX) acc.entries = acc.entries.slice(-METRICS_CODE_MAX);\n codeWrite = runMemoir(['-s', store, 'remember', '--replace', JSON.stringify(acc), '-p', `metrics.code.${branchKey}`], { cwd: store });\n }\n\n let turnWrite: Promise<string> | undefined;\n if (metrics.size > 0) {\n const existing = parseTurnMetrics(prevTurnRaw);\n for (const [tool, current] of metrics) {\n const prev = existing.get(tool) ?? { calls: 0, errors: 0 };\n existing.set(tool, { calls: prev.calls + current.calls, errors: prev.errors + current.errors });\n }\n turnWrite = runMemoir(['-s', store, 'remember', '--replace', serializeTurnMetrics(existing), '-p', `metrics.turn.${branchKey}`], { cwd: store });\n }\n\n // Check writes for this session's pair\n const results = await Promise.all([codeWrite, turnWrite].filter(Boolean));\n for (const result of results) {\n if (typeof result === 'string' && result.startsWith('Memoir command failed')) {\n throw new Error(`Memoir write failed: ${result}`);\n }\n }\n }\n } catch (e) {\n // Restore swapped data into pending maps so the next flush retries it.\n // Entries accumulated during I/O by concurrent recordEdit/recordToolMetrics\n // are preserved: we prepend the original entries, so ordering is maintained.\n for (const [sid, idx] of swappedSids) {\n const p = perSession[idx];\n const currentEdits = pendingEditsBySession.get(sid) ?? [];\n pendingEditsBySession.set(sid, [...p.edits, ...currentEdits]);\n\n const merged = toolMetricsBySession.get(sid) ?? new Map();\n for (const [tool, m] of p.metrics) {\n const prev = merged.get(tool) ?? { calls: 0, errors: 0 };\n merged.set(tool, { calls: prev.calls + m.calls, errors: prev.errors + m.errors });\n }\n toolMetricsBySession.set(sid, merged);\n }\n // Re-throw so the outer catch logs it\n throw e;\n }\n } finally {\n releaseLock();\n }\n } catch (e) {\n debugLog('flushCapture: failed:', e instanceof Error ? e.message : String(e));\n }\n}\n", "export const SECRET_PATTERN = /(api[_-]?key|auth_token|access_token|\\btoken\\b|\\bsecret\\b|\\bpassword\\b|\\bpasswd\\b|private[_-]?key|-----BEGIN [A-Z ]*PRIVATE KEY-----)/i;\n\n/** Whether secret sanitization is enabled. Default on. Set MEMOIR_SANITIZE_SECRETS=0 to disable. */\nexport function isSecretSanitizationEnabled(): boolean {\n return process.env.MEMOIR_SANITIZE_SECRETS !== '0';\n}\n\n/**\n * Sessions waiting for a recall instruction (one-shot, consumed by\n * experimental.chat.system.transform on the next LLM call).\n */\nexport const pendingRecall = new Set<string>();\n\n/** Short acknowledgements that never trigger recall. */\nconst ACK_PATTERN = /^(ok|thanks|thank you|sounds good|got it|\uD83D\uDC4D|\uD83D\uDE4F|perfect|great|cool|nice|awesome|understood|makes sense|agree|right|sure|yes|no|done|nvm|never mind|lgtm|looks good|proceed|continue|good|fine)\\b/i;\n\n/** Explicit memoir commands always trigger recall regardless of length. */\nconst EXPLICIT_RECALL_PATTERN = /\\b(memoir:recall|memoir:remember|memoir-recall|memoir-remember)\\b|(\\/recall|\\/remember)\\b/i;\n\n/** Positive-list patterns \u2014 identical to the Claude Code UserPromptSubmit gate. */\nconst RECALL_TRIGGER_PATTERNS = [\n // Action verbs and domain nouns\n /\\b(add|build|implement|refactor|redesign|design|create|write|set( |-)up|wire( |-)up|integrate|migrate|rewrite|extract|extend|plumb|hook( |-)up|ship|scaffold|optimize|fix|debug|review|architect|model|schema|API|service|feature|module|system|pipeline|workflow|make|move|replace|convert|swap|remove|clean( |-)up|transform|investigate|explore|figure( |-)out|plan|decide|choose|pick|compare|walk( |-)?me( |-)?through|take( |-)?a( |-)?stab|help( |-)?me|harness|hook|prompt|test)\\b/i,\n // Question starts (how/why/what/where/when/should/can/could/would/is it/are we/do I/does it)\n /^(how|why|what|where|when|should|can|could|would|is it|are we|do I|does it)\\b.*\\?/im,\n // Code blocks (triple backticks)\n /```/,\n // Code definitions\n /\\b(def|function|class|import|export)\\s+/,\n // Memoir/recall keywords\n /\\b(memoir|recall|remember|memory)\\b/i,\n // File extensions\n /\\b\\w+\\.(py|js|ts|tsx|scala|java|go|rs|rb|md|json|yaml|yml|toml|sh|bash|css|html|kt|swift|c|cpp|h|hpp)\\b/i,\n // File paths (slash-containing tokens)\n /\\w+\\/\\w+/,\n];\n\nexport function isAcknowledgement(text: string): boolean {\n const trimmed = text.trim().toLowerCase();\n const words = trimmed.split(/\\s+/);\n return words.length <= 5 && ACK_PATTERN.test(trimmed);\n}\n\n/**\n * Decide whether a user message should trigger a recall instruction.\n * Identical gate logic to the Claude Code UserPromptSubmit hook:\n *\n * 1. Empty text \u2192 skip\n * 2. Explicit `/recall` / `memoir:recall` commands \u2192 always fire\n * 3. < 10 chars \u2192 skip (empty or noise)\n * 4. Acknowledgements (ok/thanks/\u2026) \u2192 skip\n * 5. < 40 chars without explicit command \u2192 skip (too short for intent)\n * 6. \u2265 40 chars + any trigger pattern \u2192 fire\n */\nexport function shouldTriggerRecall(text: string): boolean {\n const trimmed = text.trim();\n if (!trimmed) return false;\n // Explicit memoir commands fire regardless of length\n if (EXPLICIT_RECALL_PATTERN.test(trimmed)) return true;\n if (trimmed.length < 10) return false;\n if (isAcknowledgement(trimmed)) return false;\n // Gate: \u2265 40 chars + any trigger\n if (trimmed.length >= 40 && RECALL_TRIGGER_PATTERNS.some(p => p.test(trimmed))) return true;\n return false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AK,UAAU;AAAA,YACnB;AACA,gBAAI,SAAS,WAAW,uBAAuB,GAAG;AAChD,oBAAM,IAAI,MAAM,QAAQ;AAAA,YAC1B;AACA,kBAAM,SAAS,cAAc,QAAQ;AACrC,0BAAc;AAAA,EAAuC,MAAM;AAAA,UAC7D,SAAS,GAAY;AACnB,qBAAS,6DAA6D,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC,CAAC;AAEhH,iCAAqB;AAAA,UACvB;AAAA,QACF,GAAG;AAAA,MACL;AAAA,IACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IASA,sCAAsC,OAAO,OAAO,WAAW;AAC7D,UAAI;AAEF,YAAI,MAAM,aAAa,CAAC,kBAAkB,MAAM,SAAS,GAAG;AAC1D,6BAAmB,MAAM,SAAS;AAClC,cAAI,aAAa;AACf,mBAAO,OAAO,QAAQ,WAAW;AAAA,UACnC;AAAA,QACF;AAGA,YAAI,MAAM,aAAa,cAAc,IAAI,MAAM,SAAS,GAAG;AACzD,wBAAc,OAAO,MAAM,SAAS;AACpC,iBAAO,OAAO;AAAA,YACZ;AAAA,UACF;AAAA,QACF;AAAA,MACF,SAAS,GAAG;AACV,iBAAS,6BAA6B,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC,CAAC;AAAA,MAClF;AAAA,IACF;AAAA;AAAA;AAAA;AAAA;AAAA,IAMA,SAAS,YAAY;AAEnB,YAAM,aAAa,SAAS;AAC5B,yBAAmB;AACnB,0BAAoB,MAAM;AAAA,IAC5B;AAAA,EACF;AACA;AAEA,IAAO,gBAAQ;",
|
|
6
|
+
"names": ["mkdir", "rm", "join", "homedir", "result", "tool", "tool", "resolve", "join", "homedir", "mkdir", "rm", "resolve", "error", "_input"]
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-memoir",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "Memoir memory plugin for OpenCode — Git-versioned, taxonomy-structured AI memory.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"README.md"
|
|
17
17
|
],
|
|
18
18
|
"scripts": {
|
|
19
|
-
"build": "tsc -p tsconfig.json",
|
|
19
|
+
"build": "tsc -p tsconfig.json --declaration --emitDeclarationOnly && esbuild src/index.ts --bundle --platform=node --format=esm --outfile=dist/index.js --external:node:* --external:@opencode-ai/plugin --sourcemap",
|
|
20
20
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
21
21
|
"test": "tsx --test tests/*.test.ts",
|
|
22
22
|
"prepack": "npm run build",
|
|
@@ -45,10 +45,14 @@
|
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/node": "^22.0.0",
|
|
48
|
+
"esbuild": "^0.28.0",
|
|
48
49
|
"tsx": "^4.22.4",
|
|
49
50
|
"typescript": "^5.7.0"
|
|
50
51
|
},
|
|
51
52
|
"engines": {
|
|
52
53
|
"node": ">=20"
|
|
54
|
+
},
|
|
55
|
+
"allowScripts": {
|
|
56
|
+
"esbuild@0.28.0": true
|
|
53
57
|
}
|
|
54
58
|
}
|
package/dist/capture.js
DELETED
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
import { deriveStorePath, ensureStore, getCurrentBranch, readMemoirValue, runMemoir } from './store.js';
|
|
2
|
-
import { debugLog } from './debug.js';
|
|
3
|
-
// ---------------------------------------------------------------------------
|
|
4
|
-
// Types
|
|
5
|
-
// ---------------------------------------------------------------------------
|
|
6
|
-
export const EDIT_TOOLS = new Set(['Edit', 'Write', 'MultiEdit', 'NotebookEdit', 'apply_patch', 'ApplyPatch', 'MultiFileEdit']);
|
|
7
|
-
/**
|
|
8
|
-
* Maximum entries retained in metrics.code.<branch>.
|
|
9
|
-
* Mirrors MEMOIR_METRICS_CODE_MAX from plugins/claude-code/hooks/stop.sh.
|
|
10
|
-
*/
|
|
11
|
-
export const METRICS_CODE_MAX = 1000;
|
|
12
|
-
// ---------------------------------------------------------------------------
|
|
13
|
-
// Per-session state
|
|
14
|
-
// ---------------------------------------------------------------------------
|
|
15
|
-
const pendingEditsBySession = new Map();
|
|
16
|
-
const toolMetricsBySession = new Map();
|
|
17
|
-
const cachedBranchBySession = new Map();
|
|
18
|
-
export function getCachedBranch(sessionID) {
|
|
19
|
-
return cachedBranchBySession.get(sessionID) ?? 'unknown';
|
|
20
|
-
}
|
|
21
|
-
export function setCachedBranch(sessionID, branch) {
|
|
22
|
-
cachedBranchBySession.set(sessionID, branch);
|
|
23
|
-
}
|
|
24
|
-
/** Record an edit for a specific session. */
|
|
25
|
-
export function recordEdit(sessionID, edit) {
|
|
26
|
-
let edits = pendingEditsBySession.get(sessionID);
|
|
27
|
-
if (!edits) {
|
|
28
|
-
edits = [];
|
|
29
|
-
pendingEditsBySession.set(sessionID, edits);
|
|
30
|
-
}
|
|
31
|
-
edits.push(edit);
|
|
32
|
-
}
|
|
33
|
-
/** Accumulate tool metrics for a specific session (adds to previous values). */
|
|
34
|
-
export function recordToolMetrics(sessionID, tool, metrics) {
|
|
35
|
-
let sessionMetrics = toolMetricsBySession.get(sessionID);
|
|
36
|
-
if (!sessionMetrics) {
|
|
37
|
-
sessionMetrics = new Map();
|
|
38
|
-
toolMetricsBySession.set(sessionID, sessionMetrics);
|
|
39
|
-
}
|
|
40
|
-
const prev = sessionMetrics.get(tool) ?? { calls: 0, errors: 0 };
|
|
41
|
-
sessionMetrics.set(tool, {
|
|
42
|
-
calls: prev.calls + metrics.calls,
|
|
43
|
-
errors: prev.errors + metrics.errors,
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
/** Peek at a session's pending edits (test helper, read-only). */
|
|
47
|
-
export function getPendingEdits(sessionID) {
|
|
48
|
-
return pendingEditsBySession.get(sessionID) ?? [];
|
|
49
|
-
}
|
|
50
|
-
/** Peek at a session's tool metrics (test helper, read-only). */
|
|
51
|
-
export function getToolMetrics(sessionID) {
|
|
52
|
-
return toolMetricsBySession.get(sessionID) ?? new Map();
|
|
53
|
-
}
|
|
54
|
-
/** Clear all state for a session (test helper). */
|
|
55
|
-
export function clearSession(sessionID) {
|
|
56
|
-
pendingEditsBySession.delete(sessionID);
|
|
57
|
-
toolMetricsBySession.delete(sessionID);
|
|
58
|
-
cachedBranchBySession.delete(sessionID);
|
|
59
|
-
}
|
|
60
|
-
// ---------------------------------------------------------------------------
|
|
61
|
-
// parse / serialize
|
|
62
|
-
// ---------------------------------------------------------------------------
|
|
63
|
-
export function parseTurnMetrics(text) {
|
|
64
|
-
const result = new Map();
|
|
65
|
-
if (!text)
|
|
66
|
-
return result;
|
|
67
|
-
const parts = text.split('|');
|
|
68
|
-
for (const part of parts) {
|
|
69
|
-
const trimmed = part.trim();
|
|
70
|
-
if (!trimmed)
|
|
71
|
-
continue;
|
|
72
|
-
const [tool, callsStr, errorsStr] = trimmed.split(':');
|
|
73
|
-
if (!tool)
|
|
74
|
-
continue;
|
|
75
|
-
result.set(tool, {
|
|
76
|
-
calls: parseInt(callsStr, 10) || 0,
|
|
77
|
-
errors: parseInt(errorsStr, 10) || 0,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
return result;
|
|
81
|
-
}
|
|
82
|
-
export function serializeTurnMetrics(map) {
|
|
83
|
-
return [...map.entries()]
|
|
84
|
-
.map(([tool, m]) => `${tool}:${m.calls}:${m.errors}`)
|
|
85
|
-
.join(' | ');
|
|
86
|
-
}
|
|
87
|
-
// ---------------------------------------------------------------------------
|
|
88
|
-
// Per-store mutex
|
|
89
|
-
// ---------------------------------------------------------------------------
|
|
90
|
-
const flushQueues = new Map();
|
|
91
|
-
async function acquireFlushLock(store) {
|
|
92
|
-
const prev = flushQueues.get(store) ?? Promise.resolve();
|
|
93
|
-
let release;
|
|
94
|
-
const next = new Promise(resolve => { release = resolve; });
|
|
95
|
-
flushQueues.set(store, next);
|
|
96
|
-
await prev;
|
|
97
|
-
return () => {
|
|
98
|
-
release();
|
|
99
|
-
if (flushQueues.get(store) === next)
|
|
100
|
-
flushQueues.delete(store);
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
// ---------------------------------------------------------------------------
|
|
104
|
-
// ---------------------------------------------------------------------------
|
|
105
|
-
// flushCapture — flushes one session, or all if no sessionID
|
|
106
|
-
// ---------------------------------------------------------------------------
|
|
107
|
-
export async function flushCapture(store, branch, sessionID) {
|
|
108
|
-
// Determine which sessions to flush
|
|
109
|
-
const targets = sessionID
|
|
110
|
-
? [sessionID]
|
|
111
|
-
: [...pendingEditsBySession.keys()]; // dispose: flush all sessions
|
|
112
|
-
if (targets.length === 0)
|
|
113
|
-
return;
|
|
114
|
-
try {
|
|
115
|
-
store = store ?? deriveStorePath();
|
|
116
|
-
if (!store)
|
|
117
|
-
return;
|
|
118
|
-
await ensureStore(store);
|
|
119
|
-
// Acquire store-level mutex before touching per-session state.
|
|
120
|
-
// Prevents C1 (cross-session interleave) and C2-RACE (data arriving
|
|
121
|
-
// between snapshot and drain).
|
|
122
|
-
const releaseLock = await acquireFlushLock(store);
|
|
123
|
-
try {
|
|
124
|
-
const perSession = [];
|
|
125
|
-
const swappedSids = new Map(); // sid → index in perSession for rollback
|
|
126
|
-
for (const sid of targets) {
|
|
127
|
-
const idx = perSession.length;
|
|
128
|
-
const edits = pendingEditsBySession.get(sid) ?? [];
|
|
129
|
-
pendingEditsBySession.set(sid, []);
|
|
130
|
-
const metrics = toolMetricsBySession.get(sid) ?? new Map();
|
|
131
|
-
toolMetricsBySession.set(sid, new Map());
|
|
132
|
-
const sb = branch ?? cachedBranchBySession.get(sid);
|
|
133
|
-
perSession.push({ edits, metrics, sessionBranch: sb ?? 'unknown' });
|
|
134
|
-
swappedSids.set(sid, idx);
|
|
135
|
-
}
|
|
136
|
-
// Skip if nothing to flush
|
|
137
|
-
if (!perSession.some(p => p.edits.length > 0 || p.metrics.size > 0))
|
|
138
|
-
return;
|
|
139
|
-
// Wrap I/O in inner try — if it fails, restore swapped data before
|
|
140
|
-
// propagating the error so the next flush retries it.
|
|
141
|
-
try {
|
|
142
|
-
// Resolve 'unknown' branches (read-only I/O, safe inside lock —
|
|
143
|
-
// the lock serializes per-store CLI access)
|
|
144
|
-
for (const p of perSession) {
|
|
145
|
-
if (p.sessionBranch === 'unknown' || !p.sessionBranch) {
|
|
146
|
-
p.sessionBranch = await getCurrentBranch(store);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
// For each session, read-merge-write sequentially.
|
|
150
|
-
for (const p of perSession) {
|
|
151
|
-
const { edits, metrics, sessionBranch: branchKey } = p;
|
|
152
|
-
if (edits.length === 0 && metrics.size === 0)
|
|
153
|
-
continue;
|
|
154
|
-
const [prevCodeRaw, prevTurnRaw] = await Promise.all([
|
|
155
|
-
edits.length > 0 ? readMemoirValue(store, `metrics.code.${branchKey}`) : Promise.resolve(''),
|
|
156
|
-
metrics.size > 0 ? readMemoirValue(store, `metrics.turn.${branchKey}`) : Promise.resolve(''),
|
|
157
|
-
]);
|
|
158
|
-
let codeWrite;
|
|
159
|
-
if (edits.length > 0) {
|
|
160
|
-
const files = [...new Set(edits.map(e => e.filePath))];
|
|
161
|
-
const entry = {
|
|
162
|
-
timestamp: Date.now() / 1000,
|
|
163
|
-
summary: `Changed ${edits.length} block(s) across ${files.length} file(s): ${files.join(', ')}`,
|
|
164
|
-
files,
|
|
165
|
-
};
|
|
166
|
-
let acc = {
|
|
167
|
-
schema_version: 2, entries: [],
|
|
168
|
-
};
|
|
169
|
-
if (prevCodeRaw) {
|
|
170
|
-
try {
|
|
171
|
-
const parsed = JSON.parse(prevCodeRaw);
|
|
172
|
-
if (parsed?.entries && Array.isArray(parsed.entries)) {
|
|
173
|
-
acc = parsed;
|
|
174
|
-
if (acc.schema_version < 2)
|
|
175
|
-
acc.schema_version = 2;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
catch (e) {
|
|
179
|
-
debugLog('flushCapture: failed to parse existing code metrics, starting fresh:', e instanceof Error ? e.message : String(e));
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
acc.entries.push(entry);
|
|
183
|
-
if (acc.entries.length > METRICS_CODE_MAX)
|
|
184
|
-
acc.entries = acc.entries.slice(-METRICS_CODE_MAX);
|
|
185
|
-
codeWrite = runMemoir(['-s', store, 'remember', '--replace', JSON.stringify(acc), '-p', `metrics.code.${branchKey}`], { cwd: store });
|
|
186
|
-
}
|
|
187
|
-
let turnWrite;
|
|
188
|
-
if (metrics.size > 0) {
|
|
189
|
-
const existing = parseTurnMetrics(prevTurnRaw);
|
|
190
|
-
for (const [tool, current] of metrics) {
|
|
191
|
-
const prev = existing.get(tool) ?? { calls: 0, errors: 0 };
|
|
192
|
-
existing.set(tool, { calls: prev.calls + current.calls, errors: prev.errors + current.errors });
|
|
193
|
-
}
|
|
194
|
-
turnWrite = runMemoir(['-s', store, 'remember', '--replace', serializeTurnMetrics(existing), '-p', `metrics.turn.${branchKey}`], { cwd: store });
|
|
195
|
-
}
|
|
196
|
-
// Check writes for this session's pair
|
|
197
|
-
const results = await Promise.all([codeWrite, turnWrite].filter(Boolean));
|
|
198
|
-
for (const result of results) {
|
|
199
|
-
if (typeof result === 'string' && result.startsWith('Memoir command failed')) {
|
|
200
|
-
throw new Error(`Memoir write failed: ${result}`);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
catch (e) {
|
|
206
|
-
// Restore swapped data into pending maps so the next flush retries it.
|
|
207
|
-
// Entries accumulated during I/O by concurrent recordEdit/recordToolMetrics
|
|
208
|
-
// are preserved: we prepend the original entries, so ordering is maintained.
|
|
209
|
-
for (const [sid, idx] of swappedSids) {
|
|
210
|
-
const p = perSession[idx];
|
|
211
|
-
const currentEdits = pendingEditsBySession.get(sid) ?? [];
|
|
212
|
-
pendingEditsBySession.set(sid, [...p.edits, ...currentEdits]);
|
|
213
|
-
const merged = toolMetricsBySession.get(sid) ?? new Map();
|
|
214
|
-
for (const [tool, m] of p.metrics) {
|
|
215
|
-
const prev = merged.get(tool) ?? { calls: 0, errors: 0 };
|
|
216
|
-
merged.set(tool, { calls: prev.calls + m.calls, errors: prev.errors + m.errors });
|
|
217
|
-
}
|
|
218
|
-
toolMetricsBySession.set(sid, merged);
|
|
219
|
-
}
|
|
220
|
-
// Re-throw so the outer catch logs it
|
|
221
|
-
throw e;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
finally {
|
|
225
|
-
releaseLock();
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
catch (e) {
|
|
229
|
-
debugLog('flushCapture: failed:', e instanceof Error ? e.message : String(e));
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
//# sourceMappingURL=capture.js.map
|
package/dist/capture.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"capture.js","sourceRoot":"","sources":["../src/capture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,gBAAgB,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACxG,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,8EAA8E;AAC9E,QAAQ;AACR,8EAA8E;AAE9E,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,YAAY,EAAE,eAAe,CAAC,CAAC,CAAC;AAchI;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAErC,8EAA8E;AAC9E,oBAAoB;AACpB,8EAA8E;AAE9E,MAAM,qBAAqB,GAAG,IAAI,GAAG,EAAwB,CAAC;AAC9D,MAAM,oBAAoB,GAAG,IAAI,GAAG,EAAoC,CAAC;AACzE,MAAM,qBAAqB,GAAG,IAAI,GAAG,EAAkB,CAAC;AAExD,MAAM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CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAChF,CAAC;AACH,CAAC"}
|
package/dist/debug.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Debug logger writing to stderr. Prefixes with [memoir] for easy filtering.
|
|
3
|
-
* Only writes when MEMOIR_DEBUG=1 is set.
|
|
4
|
-
*/
|
|
5
|
-
export function debugLog(...args) {
|
|
6
|
-
if (process.env.MEMOIR_DEBUG !== '1')
|
|
7
|
-
return;
|
|
8
|
-
const ts = new Date().toISOString();
|
|
9
|
-
process.stderr.write(`[memoir ${ts}] ${args.map(a => String(a)).join(' ')}\n`);
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=debug.js.map
|
package/dist/debug.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"debug.js","sourceRoot":"","sources":["../src/debug.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAG,IAAe;IACzC,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY,KAAK,GAAG;QAAE,OAAO;IAC7C,MAAM,EAAE,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACpC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACjF,CAAC"}
|
package/dist/recall-gate.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
export const SECRET_PATTERN = /(api[_-]?key|auth_token|access_token|\btoken\b|\bsecret\b|\bpassword\b|\bpasswd\b|private[_-]?key|-----BEGIN [A-Z ]*PRIVATE KEY-----)/i;
|
|
2
|
-
/** Whether secret sanitization is enabled. Default on. Set MEMOIR_SANITIZE_SECRETS=0 to disable. */
|
|
3
|
-
export function isSecretSanitizationEnabled() {
|
|
4
|
-
return process.env.MEMOIR_SANITIZE_SECRETS !== '0';
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Sessions waiting for a recall instruction (one-shot, consumed by
|
|
8
|
-
* experimental.chat.system.transform on the next LLM call).
|
|
9
|
-
*/
|
|
10
|
-
export const pendingRecall = new Set();
|
|
11
|
-
/** Short acknowledgements that never trigger recall. */
|
|
12
|
-
const ACK_PATTERN = /^(ok|thanks|thank you|sounds good|got it|👍|🙏|perfect|great|cool|nice|awesome|understood|makes sense|agree|right|sure|yes|no|done|nvm|never mind|lgtm|looks good|proceed|continue|good|fine)\b/i;
|
|
13
|
-
/** Explicit memoir commands always trigger recall regardless of length. */
|
|
14
|
-
const EXPLICIT_RECALL_PATTERN = /\b(memoir:recall|memoir:remember|memoir-recall|memoir-remember)\b|(\/recall|\/remember)\b/i;
|
|
15
|
-
/** Positive-list patterns — identical to the Claude Code UserPromptSubmit gate. */
|
|
16
|
-
const RECALL_TRIGGER_PATTERNS = [
|
|
17
|
-
// Action verbs and domain nouns
|
|
18
|
-
/\b(add|build|implement|refactor|redesign|design|create|write|set( |-)up|wire( |-)up|integrate|migrate|rewrite|extract|extend|plumb|hook( |-)up|ship|scaffold|optimize|fix|debug|review|architect|model|schema|API|service|feature|module|system|pipeline|workflow|make|move|replace|convert|swap|remove|clean( |-)up|transform|investigate|explore|figure( |-)out|plan|decide|choose|pick|compare|walk( |-)?me( |-)?through|take( |-)?a( |-)?stab|help( |-)?me|harness|hook|prompt|test)\b/i,
|
|
19
|
-
// Question starts (how/why/what/where/when/should/can/could/would/is it/are we/do I/does it)
|
|
20
|
-
/^(how|why|what|where|when|should|can|could|would|is it|are we|do I|does it)\b.*\?/im,
|
|
21
|
-
// Code blocks (triple backticks)
|
|
22
|
-
/```/,
|
|
23
|
-
// Code definitions
|
|
24
|
-
/\b(def|function|class|import|export)\s+/,
|
|
25
|
-
// Memoir/recall keywords
|
|
26
|
-
/\b(memoir|recall|remember|memory)\b/i,
|
|
27
|
-
// File extensions
|
|
28
|
-
/\b\w+\.(py|js|ts|tsx|scala|java|go|rs|rb|md|json|yaml|yml|toml|sh|bash|css|html|kt|swift|c|cpp|h|hpp)\b/i,
|
|
29
|
-
// File paths (slash-containing tokens)
|
|
30
|
-
/\w+\/\w+/,
|
|
31
|
-
];
|
|
32
|
-
export function isAcknowledgement(text) {
|
|
33
|
-
const trimmed = text.trim().toLowerCase();
|
|
34
|
-
const words = trimmed.split(/\s+/);
|
|
35
|
-
return words.length <= 5 && ACK_PATTERN.test(trimmed);
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Decide whether a user message should trigger a recall instruction.
|
|
39
|
-
* Identical gate logic to the Claude Code UserPromptSubmit hook:
|
|
40
|
-
*
|
|
41
|
-
* 1. Empty text → skip
|
|
42
|
-
* 2. Explicit `/recall` / `memoir:recall` commands → always fire
|
|
43
|
-
* 3. < 10 chars → skip (empty or noise)
|
|
44
|
-
* 4. Acknowledgements (ok/thanks/…) → skip
|
|
45
|
-
* 5. < 40 chars without explicit command → skip (too short for intent)
|
|
46
|
-
* 6. ≥ 40 chars + any trigger pattern → fire
|
|
47
|
-
*/
|
|
48
|
-
export function shouldTriggerRecall(text) {
|
|
49
|
-
const trimmed = text.trim();
|
|
50
|
-
if (!trimmed)
|
|
51
|
-
return false;
|
|
52
|
-
// Explicit memoir commands fire regardless of length
|
|
53
|
-
if (EXPLICIT_RECALL_PATTERN.test(trimmed))
|
|
54
|
-
return true;
|
|
55
|
-
if (trimmed.length < 10)
|
|
56
|
-
return false;
|
|
57
|
-
if (isAcknowledgement(trimmed))
|
|
58
|
-
return false;
|
|
59
|
-
// Gate: ≥ 40 chars + any trigger
|
|
60
|
-
if (trimmed.length >= 40 && RECALL_TRIGGER_PATTERNS.some(p => p.test(trimmed)))
|
|
61
|
-
return true;
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
export const DEFAULT_RECALL_NAMESPACES = ['default', 'project:onboard', 'codebase:onboard'];
|
|
65
|
-
//# sourceMappingURL=recall-gate.js.map
|
package/dist/recall-gate.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"recall-gate.js","sourceRoot":"","sources":["../src/recall-gate.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG,wIAAwI,CAAC;AAEvK,oGAAoG;AACpG,MAAM,UAAU,2BAA2B;IACzC,OAAO,OAAO,CAAC,GAAG,CAAC,uBAAuB,KAAK,GAAG,CAAC;AACrD,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,GAAG,EAAU,CAAC;AAE/C,wDAAwD;AACxD,MAAM,WAAW,GAAG,kMAAkM,CAAC;AAEvN,2EAA2E;AAC3E,MAAM,uBAAuB,GAAG,4FAA4F,CAAC;AAE7H,mFAAmF;AACnF,MAAM,uBAAuB,GAAG;IAC9B,gCAAgC;IAChC,6dAA6d;IAC7d,6FAA6F;IAC7F,qFAAqF;IACrF,iCAAiC;IACjC,KAAK;IACL,mBAAmB;IACnB,yCAAyC;IACzC,yBAAyB;IACzB,sCAAsC;IACtC,kBAAkB;IAClB,0GAA0G;IAC1G,uCAAuC;IACvC,UAAU;CACX,CAAC;AAEF,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAC1C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACnC,OAAO,KAAK,CAAC,MAAM,IAAI,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACxD,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC9C,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;IAC5B,IAAI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