opencode-memoir 1.0.0
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/LICENSE +201 -0
- package/README.md +175 -0
- package/dist/capture.d.ts +32 -0
- package/dist/capture.d.ts.map +1 -0
- package/dist/capture.js +232 -0
- package/dist/capture.js.map +1 -0
- package/dist/debug.d.ts +6 -0
- package/dist/debug.d.ts.map +1 -0
- package/dist/debug.js +11 -0
- package/dist/debug.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +464 -0
- package/dist/index.js.map +1 -0
- package/dist/recall-gate.d.ts +23 -0
- package/dist/recall-gate.d.ts.map +1 -0
- package/dist/recall-gate.js +65 -0
- package/dist/recall-gate.js.map +1 -0
- package/dist/store.d.ts +77 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +304 -0
- package/dist/store.js.map +1 -0
- package/package.json +54 -0
package/dist/debug.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../src/debug.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAIjD"}
|
package/dist/debug.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Plugin } from '@opencode-ai/plugin';
|
|
2
|
+
export declare function coercePaths(path: string | string[] | undefined): string[];
|
|
3
|
+
/** Format JSON string with 2-space indentation. Passes non-JSON through unchanged. */
|
|
4
|
+
export declare function tryPrettyJson(text: string): string;
|
|
5
|
+
/** Max keys memoir_get accepts to avoid hitting OS arg-length limits. */
|
|
6
|
+
export declare const MEMOIR_GET_MAX_KEYS = 20;
|
|
7
|
+
declare const MemoirOpenCode: Plugin;
|
|
8
|
+
export default MemoirOpenCode;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAe,KAAK,MAAM,EAAQ,MAAM,qBAAqB,CAAC;AA0HrE,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,GAAG,MAAM,EAAE,CAGzE;AAOD,sFAAsF;AACtF,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAMlD;AA+ID,yEAAyE;AACzE,eAAO,MAAM,mBAAmB,KAAK,CAAC;AA0BtC,QAAA,MAAM,cAAc,EAAE,MAiNrB,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { mkdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { homedir } from 'node:os';
|
|
6
|
+
import { tool } from '@opencode-ai/plugin';
|
|
7
|
+
import { autoMatchMemoirBranch, codeGitBranch, deriveStorePath, ensureStore, memoirResolved, memoirSpawnSpecs, runMemoir, setPluginStoreOverride } from './store.js';
|
|
8
|
+
import { EDIT_TOOLS, flushCapture, getCachedBranch, recordEdit, recordToolMetrics, setCachedBranch } from './capture.js';
|
|
9
|
+
import { DEFAULT_RECALL_NAMESPACES, isSecretSanitizationEnabled, pendingRecall, SECRET_PATTERN, shouldTriggerRecall } from './recall-gate.js';
|
|
10
|
+
import { debugLog } from './debug.js';
|
|
11
|
+
async function statusJson(store) {
|
|
12
|
+
await ensureStore(store);
|
|
13
|
+
const raw = await runMemoir(['--json', '-s', store, 'status'], { cwd: store });
|
|
14
|
+
try {
|
|
15
|
+
const data = JSON.parse(raw);
|
|
16
|
+
const branch = await codeGitBranch();
|
|
17
|
+
data.opencode = { store, project_git_root: process.cwd(), project_git_branch: branch };
|
|
18
|
+
return JSON.stringify(data, null, 2);
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
debugLog('statusJson: failed to parse JSON:', e instanceof Error ? e.message : String(e));
|
|
22
|
+
return raw;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async function launchUi(store) {
|
|
26
|
+
await ensureStore(store);
|
|
27
|
+
const pidDir = join(homedir(), '.memoir', 'ui-servers');
|
|
28
|
+
await mkdir(pidDir, { recursive: true });
|
|
29
|
+
const hash = createHash('sha256').update(store).digest('hex').slice(0, 8);
|
|
30
|
+
const pidfile = join(pidDir, `${hash}.json`);
|
|
31
|
+
try {
|
|
32
|
+
const existing = JSON.parse(await readFile(pidfile, 'utf8'));
|
|
33
|
+
if (existing?.pid && existing?.url) {
|
|
34
|
+
try {
|
|
35
|
+
process.kill(Number(existing.pid), 0); // check if alive
|
|
36
|
+
return JSON.stringify({ ...existing, reused: true }, null, 2);
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
debugLog('launchUi: process dead, relaunching:', e instanceof Error ? e.message : String(e));
|
|
40
|
+
// process is dead — fall through to relaunch
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
debugLog('launchUi: failed to read pidfile:', e instanceof Error ? e.message : String(e));
|
|
46
|
+
await rm(pidfile, { force: true }).catch(() => undefined);
|
|
47
|
+
}
|
|
48
|
+
let lastError = '';
|
|
49
|
+
const uiSpecs = memoirSpawnSpecs(['ui', store]);
|
|
50
|
+
// Reorder: put cached memoir resolver first, same as runMemoir
|
|
51
|
+
if (memoirResolved) {
|
|
52
|
+
const idx = uiSpecs.findIndex(s => s.label === memoirResolved);
|
|
53
|
+
if (idx > 0) {
|
|
54
|
+
const [cached] = uiSpecs.splice(idx, 1);
|
|
55
|
+
uiSpecs.unshift(cached);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
for (const spec of uiSpecs) {
|
|
59
|
+
const child = spawn(spec.command, spec.args, {
|
|
60
|
+
detached: true,
|
|
61
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
62
|
+
env: process.env,
|
|
63
|
+
});
|
|
64
|
+
let output = '';
|
|
65
|
+
child.stdout?.on('data', chunk => { output += String(chunk); });
|
|
66
|
+
child.stderr?.on('data', chunk => { output += String(chunk); });
|
|
67
|
+
const spawnFailed = new Promise(resolve => {
|
|
68
|
+
child.once('error', error => resolve(String(error.message || error)));
|
|
69
|
+
child.once('spawn', () => resolve(null));
|
|
70
|
+
});
|
|
71
|
+
const error = await spawnFailed;
|
|
72
|
+
if (error) {
|
|
73
|
+
lastError = `${spec.label}: ${error}`;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
child.unref();
|
|
77
|
+
const urlPattern = /https?:\/\/(?:localhost|127\.0\.0\.1):\d+\S*/;
|
|
78
|
+
const deadline = Date.now() + 5000;
|
|
79
|
+
while (Date.now() < deadline) {
|
|
80
|
+
const match = output.match(urlPattern);
|
|
81
|
+
if (match) {
|
|
82
|
+
const url = match[0];
|
|
83
|
+
const data = { pid: child.pid, url, store, command: spec.label, started: new Date().toISOString(), reused: false };
|
|
84
|
+
await writeFile(pidfile, JSON.stringify(data, null, 2));
|
|
85
|
+
return JSON.stringify(data, null, 2);
|
|
86
|
+
}
|
|
87
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
88
|
+
}
|
|
89
|
+
return `Memoir UI started with ${spec.label} (pid ${child.pid ?? 'unknown'}), but URL was not detected yet.\n${output.trim()}`.trim();
|
|
90
|
+
}
|
|
91
|
+
return `Memoir UI failed to start: ${lastError || 'no launcher succeeded'}`;
|
|
92
|
+
}
|
|
93
|
+
export function coercePaths(path) {
|
|
94
|
+
if (!path)
|
|
95
|
+
return [];
|
|
96
|
+
return Array.isArray(path) ? path.filter(Boolean) : [path];
|
|
97
|
+
}
|
|
98
|
+
function pushText(output, text) {
|
|
99
|
+
output.parts.length = 0;
|
|
100
|
+
output.parts.push({ type: 'text', text });
|
|
101
|
+
}
|
|
102
|
+
/** Format JSON string with 2-space indentation. Passes non-JSON through unchanged. */
|
|
103
|
+
export function tryPrettyJson(text) {
|
|
104
|
+
try {
|
|
105
|
+
return JSON.stringify(JSON.parse(text), null, 2);
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return text;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/** Cached session init context (taxonomy overview). Fetched once, injected per-session. */
|
|
112
|
+
let initContext = null;
|
|
113
|
+
let initContextFetched = false;
|
|
114
|
+
/**
|
|
115
|
+
* Tracks sessions that have received initial context injection.
|
|
116
|
+
* Uses a Map with timestamp so stale entries can be evicted.
|
|
117
|
+
* Cleaned on dispose. Sessions older than 1 hour are considered stale.
|
|
118
|
+
*/
|
|
119
|
+
const SESSION_CONTEXT_TTL_MS = 60 * 60 * 1000;
|
|
120
|
+
const sessionsWithContext = new Map();
|
|
121
|
+
/** Check if a session has received context (and prune stale entries opportunistically). */
|
|
122
|
+
function hasSessionContext(sessionID) {
|
|
123
|
+
const ts = sessionsWithContext.get(sessionID);
|
|
124
|
+
if (ts === undefined)
|
|
125
|
+
return false;
|
|
126
|
+
if (Date.now() - ts > SESSION_CONTEXT_TTL_MS) {
|
|
127
|
+
sessionsWithContext.delete(sessionID);
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
/** Mark a session as having received context. */
|
|
133
|
+
function markSessionContext(sessionID) {
|
|
134
|
+
sessionsWithContext.set(sessionID, Date.now());
|
|
135
|
+
}
|
|
136
|
+
/** Prune all stale session entries. */
|
|
137
|
+
function pruneStaleSessions() {
|
|
138
|
+
const now = Date.now();
|
|
139
|
+
for (const [id, ts] of sessionsWithContext) {
|
|
140
|
+
if (now - ts > SESSION_CONTEXT_TTL_MS)
|
|
141
|
+
sessionsWithContext.delete(id);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function registerCommands(config) {
|
|
145
|
+
config.command = config.command ?? {};
|
|
146
|
+
config.command['memoir:status'] = {
|
|
147
|
+
description: 'Show Memoir status for the current OpenCode project',
|
|
148
|
+
template: 'Show Memoir status for this OpenCode project.',
|
|
149
|
+
};
|
|
150
|
+
config.command['memoir:ui'] = {
|
|
151
|
+
description: 'Launch or reopen the Memoir web UI for this project store',
|
|
152
|
+
template: 'Launch or reopen the Memoir UI for this project.',
|
|
153
|
+
};
|
|
154
|
+
config.command['memoir:remember'] = {
|
|
155
|
+
description: 'Save a durable fact, preference, rule, or decision to Memoir',
|
|
156
|
+
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.`,
|
|
157
|
+
};
|
|
158
|
+
config.command['memoir:recall'] = {
|
|
159
|
+
description: 'Recall relevant facts from Memoir before answering',
|
|
160
|
+
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.`,
|
|
161
|
+
};
|
|
162
|
+
config.command['memoir:onboard'] = {
|
|
163
|
+
description: 'Populate or refresh Memoir onboarding for this project',
|
|
164
|
+
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.`,
|
|
165
|
+
};
|
|
166
|
+
config.command['memoir:unmerged'] = {
|
|
167
|
+
description: 'List memoir branches with changes not yet merged into main',
|
|
168
|
+
template: 'List memoir branches that have diverged from main.',
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
const memoirStatus = tool({
|
|
172
|
+
description: 'Show Memoir status for the current OpenCode project store.',
|
|
173
|
+
args: {},
|
|
174
|
+
execute: async () => statusJson(deriveStorePath()),
|
|
175
|
+
});
|
|
176
|
+
const memoirRemember = tool({
|
|
177
|
+
description: 'Explicitly save a durable memory to Memoir at one or more semantic taxonomy paths.',
|
|
178
|
+
args: {
|
|
179
|
+
content: tool.schema.string().describe('Memory content to save. Do not include secrets.'),
|
|
180
|
+
path: tool.schema.string().optional().describe('Semantic taxonomy path, e.g. preferences.coding.style.'),
|
|
181
|
+
namespace: tool.schema.string().optional().describe('Memoir namespace. Defaults to default.'),
|
|
182
|
+
replace: tool.schema.boolean().optional().describe('Replace existing value at the path.'),
|
|
183
|
+
},
|
|
184
|
+
execute: async (args) => {
|
|
185
|
+
const content = args.content?.trim();
|
|
186
|
+
if (!content)
|
|
187
|
+
return 'Memoir memory was not saved: content is empty.';
|
|
188
|
+
if (isSecretSanitizationEnabled() && SECRET_PATTERN.test(content)) {
|
|
189
|
+
return 'Memoir memory was not saved: the content looks like a secret or credential. Save a redacted rule instead.';
|
|
190
|
+
}
|
|
191
|
+
const paths = coercePaths(args.path);
|
|
192
|
+
if (paths.length === 0) {
|
|
193
|
+
return 'Memoir memory was not saved: provide a semantic path, e.g. preferences.coding.style.';
|
|
194
|
+
}
|
|
195
|
+
const store = deriveStorePath();
|
|
196
|
+
try {
|
|
197
|
+
await ensureStore(store);
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
return String(error.message || error);
|
|
201
|
+
}
|
|
202
|
+
const cliArgs = ['--json', '-s', store, 'remember', content];
|
|
203
|
+
for (const p of paths)
|
|
204
|
+
cliArgs.push('-p', p);
|
|
205
|
+
cliArgs.push('-n', args.namespace ?? 'default');
|
|
206
|
+
if (args.replace)
|
|
207
|
+
cliArgs.push('--replace');
|
|
208
|
+
return tryPrettyJson(await runMemoir(cliArgs, { cwd: store }));
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
const memoirRecall = tool({
|
|
212
|
+
description: 'List Memoir memory keys across relevant namespaces for relevance picking. Never calls legacy memoir recall.',
|
|
213
|
+
args: {
|
|
214
|
+
query: tool.schema.string().optional().describe('User query or topic to recall for.'),
|
|
215
|
+
namespace: tool.schema.string().optional().describe('Single Memoir namespace to inspect. If omitted, checks default + onboard namespaces.'),
|
|
216
|
+
namespaces: tool.schema.array(tool.schema.string()).optional().describe('Namespaces to inspect. Defaults to default, project:onboard, codebase:onboard.'),
|
|
217
|
+
includeMetrics: tool.schema.boolean().optional().describe('Include metrics.* memories in the listing.'),
|
|
218
|
+
},
|
|
219
|
+
execute: async (args) => {
|
|
220
|
+
const store = deriveStorePath();
|
|
221
|
+
try {
|
|
222
|
+
await ensureStore(store);
|
|
223
|
+
}
|
|
224
|
+
catch (error) {
|
|
225
|
+
return String(error.message || error);
|
|
226
|
+
}
|
|
227
|
+
const namespaces = args.namespace
|
|
228
|
+
? [args.namespace]
|
|
229
|
+
: (args.namespaces && args.namespaces.length > 0 ? args.namespaces : DEFAULT_RECALL_NAMESPACES);
|
|
230
|
+
const sections = [];
|
|
231
|
+
for (const namespace of namespaces) {
|
|
232
|
+
const output = tryPrettyJson(await runMemoir(['--json', '-s', store, 'summarize', '--depth', '3', '-n', namespace], { cwd: store }));
|
|
233
|
+
sections.push(`## namespace: ${namespace}\n${output}`);
|
|
234
|
+
}
|
|
235
|
+
const note = args.includeMetrics
|
|
236
|
+
? 'Metrics were included by request.'
|
|
237
|
+
: '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.';
|
|
238
|
+
const query = args.query ? `Query: ${args.query}\n` : '';
|
|
239
|
+
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')}`;
|
|
240
|
+
},
|
|
241
|
+
});
|
|
242
|
+
/** Max keys memoir_get accepts to avoid hitting OS arg-length limits. */
|
|
243
|
+
export const MEMOIR_GET_MAX_KEYS = 20;
|
|
244
|
+
const memoirGet = tool({
|
|
245
|
+
description: 'Fetch exact Memoir memory keys after selecting them from memoir_recall output.',
|
|
246
|
+
args: {
|
|
247
|
+
keys: tool.schema.array(tool.schema.string()).describe('Exact memory keys to fetch.'),
|
|
248
|
+
namespace: tool.schema.string().optional().describe('Memoir namespace. Defaults to default.'),
|
|
249
|
+
},
|
|
250
|
+
execute: async (args) => {
|
|
251
|
+
const keys = args.keys?.map((key) => key.trim()).filter(Boolean) ?? [];
|
|
252
|
+
if (keys.length === 0)
|
|
253
|
+
return 'No Memoir keys were provided.';
|
|
254
|
+
if (keys.length > MEMOIR_GET_MAX_KEYS) {
|
|
255
|
+
return `Error: Too many keys requested (max ${MEMOIR_GET_MAX_KEYS}, got ${keys.length}). Narrow your selection from memoir_recall output.`;
|
|
256
|
+
}
|
|
257
|
+
const store = deriveStorePath();
|
|
258
|
+
try {
|
|
259
|
+
await ensureStore(store);
|
|
260
|
+
}
|
|
261
|
+
catch (error) {
|
|
262
|
+
return String(error.message || error);
|
|
263
|
+
}
|
|
264
|
+
return tryPrettyJson(await runMemoir(['--json', '-s', store, 'get', ...keys, '-n', args.namespace ?? 'default'], { cwd: store }));
|
|
265
|
+
},
|
|
266
|
+
});
|
|
267
|
+
const MemoirOpenCode = async (_input, rawOptions) => {
|
|
268
|
+
const opts = (rawOptions ?? {});
|
|
269
|
+
if (opts.store)
|
|
270
|
+
setPluginStoreOverride(opts.store);
|
|
271
|
+
// Resolve store path once at init so shell.env doesn't call execFileSync
|
|
272
|
+
// on every shell command (mirrors Claude Code's MEMOIR_STORE_PATH caching).
|
|
273
|
+
const storeRoot = deriveStorePath();
|
|
274
|
+
return ({
|
|
275
|
+
name: 'memoir',
|
|
276
|
+
tool: {
|
|
277
|
+
memoir_status: memoirStatus,
|
|
278
|
+
memoir_remember: memoirRemember,
|
|
279
|
+
memoir_recall: memoirRecall,
|
|
280
|
+
memoir_get: memoirGet,
|
|
281
|
+
},
|
|
282
|
+
config: async (opencodeConfig) => {
|
|
283
|
+
registerCommands(opencodeConfig);
|
|
284
|
+
},
|
|
285
|
+
'command.execute.before': async (input, output) => {
|
|
286
|
+
try {
|
|
287
|
+
if (input.command === 'memoir:status') {
|
|
288
|
+
pushText(output, await statusJson(deriveStorePath()));
|
|
289
|
+
}
|
|
290
|
+
if (input.command === 'memoir:ui') {
|
|
291
|
+
pushText(output, await launchUi(deriveStorePath()));
|
|
292
|
+
}
|
|
293
|
+
if (input.command === 'memoir:unmerged') {
|
|
294
|
+
const store = deriveStorePath();
|
|
295
|
+
await ensureStore(store);
|
|
296
|
+
const raw = await runMemoir(['--json', '-s', store, 'branch'], { cwd: store });
|
|
297
|
+
const data = JSON.parse(raw);
|
|
298
|
+
const branches = data?.branches ?? [];
|
|
299
|
+
const unmerged = [];
|
|
300
|
+
for (const branch of branches) {
|
|
301
|
+
if (branch === 'main')
|
|
302
|
+
continue;
|
|
303
|
+
const diffOut = await runMemoir(['-s', store, 'diff', branch, 'main', '--stat'], { cwd: store }).catch(() => '');
|
|
304
|
+
if (diffOut.trim()) {
|
|
305
|
+
unmerged.push(branch);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
pushText(output, unmerged.length > 0
|
|
309
|
+
? `Unmerged branches:\n${unmerged.join('\n')}`
|
|
310
|
+
: 'All branches are merged into main.');
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
catch (error) {
|
|
314
|
+
pushText(output, `Memoir command failed: ${String(error.message || error)}`);
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
/**
|
|
318
|
+
* Inject MEMOIR_STORE into every shell command's environment so any memoir
|
|
319
|
+
* invocation automatically targets the right store without manual -s flags.
|
|
320
|
+
* Uses the cached value resolved at init time (avoiding execFileSync overhead
|
|
321
|
+
* on every shell command).
|
|
322
|
+
*/
|
|
323
|
+
'shell.env': async (_input, output) => {
|
|
324
|
+
try {
|
|
325
|
+
output.env.MEMOIR_STORE = storeRoot;
|
|
326
|
+
}
|
|
327
|
+
catch (e) {
|
|
328
|
+
debugLog('shell.env: failed:', e instanceof Error ? e.message : String(e));
|
|
329
|
+
}
|
|
330
|
+
},
|
|
331
|
+
/**
|
|
332
|
+
* Observe every tool execution for metrics and code-change tracking.
|
|
333
|
+
* Mirrors the observation phase of Claude Code's Stop hook.
|
|
334
|
+
* Never modifies the tool output.
|
|
335
|
+
*/
|
|
336
|
+
'tool.execute.after': async (input, output) => {
|
|
337
|
+
try {
|
|
338
|
+
// Per-session state key
|
|
339
|
+
const sid = input.sessionID ?? 'default';
|
|
340
|
+
// Accumulate per-tool metrics (cf. collect-metrics.sh).
|
|
341
|
+
// Skipped when MEMOIR_NO_CAPTURE or MEMOIR_NO_METRICS is set.
|
|
342
|
+
if (process.env.MEMOIR_NO_CAPTURE !== '1' && process.env.MEMOIR_NO_METRICS !== '1') {
|
|
343
|
+
const calls = 1;
|
|
344
|
+
const errors = (output.metadata?.error || output.output?.startsWith('Error:')) ? 1 : 0;
|
|
345
|
+
recordToolMetrics(sid, input.tool, { calls, errors });
|
|
346
|
+
}
|
|
347
|
+
// Track file edits (cf. collect-edits.sh).
|
|
348
|
+
// Skipped when MEMOIR_NO_CAPTURE or MEMOIR_NO_CODE_SUMMARY is set.
|
|
349
|
+
if (process.env.MEMOIR_NO_CAPTURE !== '1' && process.env.MEMOIR_NO_CODE_SUMMARY !== '1' && EDIT_TOOLS.has(input.tool)) {
|
|
350
|
+
const filePath = typeof input.args?.filePath === 'string' ? input.args.filePath
|
|
351
|
+
: typeof input.args?.path === 'string' ? input.args.path
|
|
352
|
+
: '';
|
|
353
|
+
if (filePath) {
|
|
354
|
+
recordEdit(sid, { tool: input.tool, filePath, snippet: '', timestamp: Date.now() });
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
catch (e) {
|
|
359
|
+
debugLog('tool.execute.after: failed:', e instanceof Error ? e.message : String(e));
|
|
360
|
+
}
|
|
361
|
+
},
|
|
362
|
+
/**
|
|
363
|
+
* Fires on every incoming user message.
|
|
364
|
+
*
|
|
365
|
+
* 1. Auto-match memoir branch to current git branch
|
|
366
|
+
* (cf. UserPromptSubmit's auto_match_memoir_branch in Claude Code plugin).
|
|
367
|
+
* 2. Flush pending edits from the previous assistant turn
|
|
368
|
+
* (cf. Stop hook code change audit, run after each turn).
|
|
369
|
+
* 3. Run the recall gate (cf. UserPromptSubmit).
|
|
370
|
+
*
|
|
371
|
+
* Steps 1–2 are skipped when MEMOIR_NO_CAPTURE=1.
|
|
372
|
+
*/
|
|
373
|
+
'chat.message': async (input, output) => {
|
|
374
|
+
try {
|
|
375
|
+
const sid = input.sessionID ?? 'default';
|
|
376
|
+
// C4: run recall gate BEFORE any await — otherwise system.transform
|
|
377
|
+
// could fire before pendingRecall is set.
|
|
378
|
+
const text = output.parts
|
|
379
|
+
.filter((p) => p.type === 'text')
|
|
380
|
+
.map(p => p.text)
|
|
381
|
+
.join(' ');
|
|
382
|
+
if (shouldTriggerRecall(text)) {
|
|
383
|
+
pendingRecall.add(sid);
|
|
384
|
+
}
|
|
385
|
+
// Snapshot previous branch BEFORE switching — edits from the last turn
|
|
386
|
+
// belong to the OLD branch. (C2 fix: prevents misattribution when the
|
|
387
|
+
// user switches git branch between turns.)
|
|
388
|
+
const prevBranch = getCachedBranch(sid) === 'unknown' ? undefined : getCachedBranch(sid);
|
|
389
|
+
setCachedBranch(sid, await autoMatchMemoirBranch(storeRoot));
|
|
390
|
+
// Skip capture flush when MEMOIR_NO_CAPTURE is set.
|
|
391
|
+
// Flush under the PREVIOUS branch (the one edits were made on).
|
|
392
|
+
if (process.env.MEMOIR_NO_CAPTURE !== '1') {
|
|
393
|
+
await flushCapture(storeRoot, prevBranch, sid);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
catch (e) {
|
|
397
|
+
debugLog('chat.message: failed:', e instanceof Error ? e.message : String(e));
|
|
398
|
+
}
|
|
399
|
+
},
|
|
400
|
+
/**
|
|
401
|
+
* Fires on SDK events. On session.created, kick off a background fetch of
|
|
402
|
+
* the taxonomy overview so it's ready before the first LLM call.
|
|
403
|
+
* Mirrors Claude Code's SessionStart context injection.
|
|
404
|
+
*/
|
|
405
|
+
event: async ({ event: evt }) => {
|
|
406
|
+
if (evt.type === 'session.created' && !initContextFetched) {
|
|
407
|
+
initContextFetched = true;
|
|
408
|
+
(async () => {
|
|
409
|
+
try {
|
|
410
|
+
const taxonomy = await runMemoir(['--json', '-s', storeRoot, 'summarize', '--depth', '3', '-n', 'default'], { cwd: storeRoot });
|
|
411
|
+
if (taxonomy.startsWith('Memoir command failed')) {
|
|
412
|
+
throw new Error(taxonomy);
|
|
413
|
+
}
|
|
414
|
+
const pretty = tryPrettyJson(taxonomy);
|
|
415
|
+
initContext = `[memoir] Available taxonomy paths:\n${pretty}`;
|
|
416
|
+
}
|
|
417
|
+
catch (e) {
|
|
418
|
+
debugLog('event: taxonomy fetch failed, will retry on next session:', e instanceof Error ? e.message : String(e));
|
|
419
|
+
// Allow a later session to retry — the store may not have been ready yet.
|
|
420
|
+
initContextFetched = false;
|
|
421
|
+
}
|
|
422
|
+
})();
|
|
423
|
+
}
|
|
424
|
+
},
|
|
425
|
+
/**
|
|
426
|
+
* Fires before every LLM call.
|
|
427
|
+
*
|
|
428
|
+
* 1. Injects the memoir taxonomy context for this session (once per session).
|
|
429
|
+
* 2. If a recall is pending for this session, injects a brief instruction
|
|
430
|
+
* telling the model to use memoir tools (one-shot per trigger).
|
|
431
|
+
*/
|
|
432
|
+
'experimental.chat.system.transform': async (input, output) => {
|
|
433
|
+
try {
|
|
434
|
+
// Inject initial context on the first LLM call of each session
|
|
435
|
+
if (input.sessionID && !hasSessionContext(input.sessionID)) {
|
|
436
|
+
markSessionContext(input.sessionID);
|
|
437
|
+
if (initContext) {
|
|
438
|
+
output.system.unshift(initContext);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
// Inject recall instruction (one-shot per trigger)
|
|
442
|
+
if (input.sessionID && pendingRecall.has(input.sessionID)) {
|
|
443
|
+
pendingRecall.delete(input.sessionID);
|
|
444
|
+
output.system.push('\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.');
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
catch (e) {
|
|
448
|
+
debugLog('system.transform: failed:', e instanceof Error ? e.message : String(e));
|
|
449
|
+
}
|
|
450
|
+
},
|
|
451
|
+
/**
|
|
452
|
+
* Fires when the plugin is shut down. Flushes any remaining code changes
|
|
453
|
+
* and metrics (cf. SessionEnd heartbeat cleanup + final metrics flush).
|
|
454
|
+
*/
|
|
455
|
+
dispose: async () => {
|
|
456
|
+
// No sessionID → flushCapture flushes ALL sessions
|
|
457
|
+
await flushCapture(storeRoot);
|
|
458
|
+
pruneStaleSessions();
|
|
459
|
+
sessionsWithContext.clear();
|
|
460
|
+
},
|
|
461
|
+
});
|
|
462
|
+
};
|
|
463
|
+
export default MemoirOpenCode;
|
|
464
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,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B,EAAE,CAAC;YACrB,mBAAmB,CAAC,KAAK,EAAE,CAAC;QAC9B,CAAC;KACF,CAAC,CAAC;AACH,CAAC,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare const SECRET_PATTERN: RegExp;
|
|
2
|
+
/** Whether secret sanitization is enabled. Default on. Set MEMOIR_SANITIZE_SECRETS=0 to disable. */
|
|
3
|
+
export declare function isSecretSanitizationEnabled(): boolean;
|
|
4
|
+
/**
|
|
5
|
+
* Sessions waiting for a recall instruction (one-shot, consumed by
|
|
6
|
+
* experimental.chat.system.transform on the next LLM call).
|
|
7
|
+
*/
|
|
8
|
+
export declare const pendingRecall: Set<string>;
|
|
9
|
+
export declare function isAcknowledgement(text: string): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Decide whether a user message should trigger a recall instruction.
|
|
12
|
+
* Identical gate logic to the Claude Code UserPromptSubmit hook:
|
|
13
|
+
*
|
|
14
|
+
* 1. Empty text → skip
|
|
15
|
+
* 2. Explicit `/recall` / `memoir:recall` commands → always fire
|
|
16
|
+
* 3. < 10 chars → skip (empty or noise)
|
|
17
|
+
* 4. Acknowledgements (ok/thanks/…) → skip
|
|
18
|
+
* 5. < 40 chars without explicit command → skip (too short for intent)
|
|
19
|
+
* 6. ≥ 40 chars + any trigger pattern → fire
|
|
20
|
+
*/
|
|
21
|
+
export declare function shouldTriggerRecall(text: string): boolean;
|
|
22
|
+
export declare const DEFAULT_RECALL_NAMESPACES: string[];
|
|
23
|
+
//# sourceMappingURL=recall-gate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recall-gate.d.ts","sourceRoot":"","sources":["../src/recall-gate.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,QAA2I,CAAC;AAEvK,oGAAoG;AACpG,wBAAgB,2BAA2B,IAAI,OAAO,CAErD;AAED;;;GAGG;AACH,eAAO,MAAM,aAAa,aAAoB,CAAC;AA0B/C,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAIvD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAUzD;AAED,eAAO,MAAM,yBAAyB,UAAqD,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,iBAA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