@n24q02m/mnemo-plugin 1.3.0 → 1.4.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.
- package/bin/cli.mjs +147 -9
- package/build/src/core/memory-service.d.ts +63 -0
- package/build/src/core/memory-service.d.ts.map +1 -0
- package/build/src/core/memory-service.js +151 -0
- package/build/src/core/memory-service.js.map +1 -0
- package/build/src/hooks/auto-capture.d.ts +1 -0
- package/build/src/hooks/auto-capture.d.ts.map +1 -1
- package/build/src/hooks/auto-capture.js +17 -34
- package/build/src/hooks/auto-capture.js.map +1 -1
- package/build/src/hooks/compaction.d.ts +8 -0
- package/build/src/hooks/compaction.d.ts.map +1 -1
- package/build/src/hooks/compaction.js +7 -19
- package/build/src/hooks/compaction.js.map +1 -1
- package/build/src/hooks/system-prompt.d.ts +1 -2
- package/build/src/hooks/system-prompt.d.ts.map +1 -1
- package/build/src/hooks/system-prompt.js +12 -59
- package/build/src/hooks/system-prompt.js.map +1 -1
- package/build/src/index.d.ts +8 -7
- package/build/src/index.d.ts.map +1 -1
- package/build/src/index.js +6 -46
- package/build/src/index.js.map +1 -1
- package/build/src/platforms/omp/index.d.ts +24 -0
- package/build/src/platforms/omp/index.d.ts.map +1 -0
- package/build/src/platforms/omp/index.js +74 -0
- package/build/src/platforms/omp/index.js.map +1 -0
- package/build/src/platforms/opencode/index.d.ts +11 -0
- package/build/src/platforms/opencode/index.d.ts.map +1 -0
- package/build/src/platforms/opencode/index.js +50 -0
- package/build/src/platforms/opencode/index.js.map +1 -0
- package/build/src/tools/memory.d.ts.map +1 -1
- package/build/src/tools/memory.js +1 -6
- package/build/src/tools/memory.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -2
|
@@ -1,36 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* System Prompt Hook
|
|
3
|
+
*
|
|
4
|
+
* Injects relevant memories into the system prompt using adaptive budget
|
|
5
|
+
* based on the model's context window. Delegates core logic to memory-service.
|
|
6
|
+
*/
|
|
2
7
|
import { MnemoBridge } from '../bridge.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/** Budget bounds in characters */
|
|
6
|
-
const MIN_BUDGET = 600;
|
|
7
|
-
const MAX_BUDGET = 8000;
|
|
8
|
-
/** Self-awareness block always injected (tells agent about available memory tools) */
|
|
9
|
-
const SELF_AWARENESS = `You have persistent memory via the Mnemo system. You can use:
|
|
10
|
-
- mnemo_search: Search stored memories, facts, preferences, decisions
|
|
11
|
-
- mnemo_remember: Permanently store new facts, rules, preferences
|
|
12
|
-
- mnemo_forget: Delete outdated or incorrect memories
|
|
13
|
-
Proactively search memory when entering a new codebase or when the user asks about past decisions.`;
|
|
14
|
-
/** Extract project name from directory path */
|
|
15
|
-
function getProjectName(directory) {
|
|
16
|
-
const cleanDir = directory.replace(/\\/g, '/');
|
|
17
|
-
const parts = cleanDir.split('/');
|
|
18
|
-
return parts[parts.length - 1] || 'unknown';
|
|
19
|
-
}
|
|
20
|
-
/** Compute injection budget based on model context limit */
|
|
21
|
-
function computeBudget(model) {
|
|
22
|
-
const contextLimit = model?.limit?.context;
|
|
23
|
-
if (!contextLimit || contextLimit <= 0)
|
|
24
|
-
return MIN_BUDGET;
|
|
25
|
-
const budget = Math.floor(contextLimit * BUDGET_PERCENT * 4); // ~4 chars per token
|
|
26
|
-
return Math.max(MIN_BUDGET, Math.min(MAX_BUDGET, budget));
|
|
27
|
-
}
|
|
28
|
-
/** Truncate text to fit within character budget */
|
|
29
|
-
function truncateToFit(text, budget) {
|
|
30
|
-
if (text.length <= budget)
|
|
31
|
-
return text;
|
|
32
|
-
return `${text.slice(0, budget - 3)}...`;
|
|
33
|
-
}
|
|
8
|
+
import { buildMemoryContext, computeBudget, getProjectName, SELF_AWARENESS } from '../core/memory-service.js';
|
|
9
|
+
import { logger } from '../logger.js';
|
|
34
10
|
export const systemPromptHook = async (input, output, directory) => {
|
|
35
11
|
try {
|
|
36
12
|
const bridge = MnemoBridge.getInstance();
|
|
@@ -40,33 +16,10 @@ export const systemPromptHook = async (input, output, directory) => {
|
|
|
40
16
|
if (!bridge.isAvailable())
|
|
41
17
|
return;
|
|
42
18
|
const projectName = getProjectName(directory);
|
|
43
|
-
const budget = computeBudget(input.model);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
query: projectName,
|
|
48
|
-
limit: 10
|
|
49
|
-
});
|
|
50
|
-
if (!searchRes || !searchRes.count || searchRes.count === 0)
|
|
51
|
-
return;
|
|
52
|
-
const results = searchRes.results;
|
|
53
|
-
// Build memory injection with budget constraint
|
|
54
|
-
let injection = `[Mnemo Context for "${projectName}"]\n`;
|
|
55
|
-
let usedBudget = injection.length;
|
|
56
|
-
for (const mem of results) {
|
|
57
|
-
const line = `- [${mem.category}] ${mem.content}\n`;
|
|
58
|
-
if (usedBudget + line.length > budget) {
|
|
59
|
-
// Try to fit a truncated version
|
|
60
|
-
const remaining = budget - usedBudget;
|
|
61
|
-
if (remaining > 20) {
|
|
62
|
-
injection += truncateToFit(line, remaining);
|
|
63
|
-
}
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
injection += line;
|
|
67
|
-
usedBudget += line.length;
|
|
68
|
-
}
|
|
69
|
-
output.system.push(injection);
|
|
19
|
+
const budget = computeBudget(input.model?.limit?.context);
|
|
20
|
+
const injection = await buildMemoryContext(bridge, projectName, budget);
|
|
21
|
+
if (injection)
|
|
22
|
+
output.system.push(injection);
|
|
70
23
|
}
|
|
71
24
|
catch (error) {
|
|
72
25
|
logger.error(`[Mnemo] Error injecting system prompt: ${error}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"system-prompt.js","sourceRoot":"","sources":["../../../src/hooks/system-prompt.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"system-prompt.js","sourceRoot":"","sources":["../../../src/hooks/system-prompt.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC7G,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAErC,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,EACnC,KAA2C,EAC3C,MAA4B,EAC5B,SAAiB,EACjB,EAAE;IACF,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,WAAW,CAAC,WAAW,EAAE,CAAA;QAExC,sDAAsD;QACtD,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;QAElC,wEAAwE;QACxE,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE;YAAE,OAAM;QAEjC,MAAM,WAAW,GAAG,cAAc,CAAC,SAAS,CAAC,CAAA;QAC7C,MAAM,MAAM,GAAG,aAAa,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,CAAA;QAEzD,MAAM,SAAS,GAAG,MAAM,kBAAkB,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,CAAA;QACvE,IAAI,SAAS;YAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IAC9C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,0CAA0C,KAAK,EAAE,CAAC,CAAA;IACjE,CAAC;AACH,CAAC,CAAA"}
|
package/build/src/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* mnemo-plugin - Universal Memory Plugin
|
|
2
|
+
* mnemo-plugin - Universal Memory Plugin
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* persistent memory capabilities across coding sessions.
|
|
4
|
+
* Default export: OpenCode platform adapter (backward-compatible).
|
|
5
|
+
* Named exports: Platform adapters and core service for other runtimes.
|
|
7
6
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export
|
|
7
|
+
export type { MemoryResult } from './core/memory-service.js';
|
|
8
|
+
export { buildMemoryContext, captureConstraint, computeBudget, exportMemoriesAsMarkdown, fetchCompactionMemories, getProjectName, hashContent, SELF_AWARENESS } from './core/memory-service.js';
|
|
9
|
+
export type { OmpContext, OmpPlugin } from './platforms/omp/index.js';
|
|
10
|
+
export { register as registerOmp } from './platforms/omp/index.js';
|
|
11
|
+
export { default } from './platforms/opencode/index.js';
|
|
11
12
|
//# sourceMappingURL=index.d.ts.map
|
package/build/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,YAAY,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,EACb,wBAAwB,EACxB,uBAAuB,EACvB,cAAc,EACd,WAAW,EACX,cAAc,EACf,MAAM,0BAA0B,CAAA;AACjC,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACrE,OAAO,EAAE,QAAQ,IAAI,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAA"}
|
package/build/src/index.js
CHANGED
|
@@ -1,50 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* mnemo-plugin - Universal Memory Plugin
|
|
2
|
+
* mnemo-plugin - Universal Memory Plugin
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* persistent memory capabilities across coding sessions.
|
|
4
|
+
* Default export: OpenCode platform adapter (backward-compatible).
|
|
5
|
+
* Named exports: Platform adapters and core service for other runtimes.
|
|
7
6
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import { systemPromptHook } from './hooks/system-prompt.js';
|
|
12
|
-
import { mnemoForget, mnemoRemember, mnemoSearch } from './tools/memory.js';
|
|
13
|
-
const plugin = async (input) => {
|
|
14
|
-
const bridge = MnemoBridge.getInstance();
|
|
15
|
-
// Start bridge connection in background (non-blocking).
|
|
16
|
-
// If this fails, the circuit breaker in MnemoBridge will prevent repeated
|
|
17
|
-
// connection attempts from hooks, avoiding log noise.
|
|
18
|
-
setTimeout(async () => {
|
|
19
|
-
try {
|
|
20
|
-
await bridge.connect();
|
|
21
|
-
}
|
|
22
|
-
catch {
|
|
23
|
-
// Silently handled -- circuit breaker will prevent further attempts.
|
|
24
|
-
// Hooks check bridge.isAvailable() before calling, so no cascading errors.
|
|
25
|
-
}
|
|
26
|
-
}, 100);
|
|
27
|
-
return {
|
|
28
|
-
// Tools
|
|
29
|
-
tool: {
|
|
30
|
-
mnemo_search: mnemoSearch,
|
|
31
|
-
mnemo_remember: mnemoRemember,
|
|
32
|
-
mnemo_forget: mnemoForget
|
|
33
|
-
},
|
|
34
|
-
// Hooks
|
|
35
|
-
'experimental.chat.system.transform': async (inParams, outParams) => {
|
|
36
|
-
await systemPromptHook(inParams, outParams, input.directory);
|
|
37
|
-
},
|
|
38
|
-
'chat.message': async (inParams, outParams) => {
|
|
39
|
-
await messageHook(inParams, outParams);
|
|
40
|
-
},
|
|
41
|
-
event: async (inParams) => {
|
|
42
|
-
await autoCaptureHook(inParams, input.directory);
|
|
43
|
-
},
|
|
44
|
-
'experimental.session.compacting': async (inParams, outParams) => {
|
|
45
|
-
await compactionHook(inParams, outParams);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
export default plugin;
|
|
7
|
+
export { buildMemoryContext, captureConstraint, computeBudget, exportMemoriesAsMarkdown, fetchCompactionMemories, getProjectName, hashContent, SELF_AWARENESS } from './core/memory-service.js';
|
|
8
|
+
export { register as registerOmp } from './platforms/omp/index.js';
|
|
9
|
+
export { default } from './platforms/opencode/index.js';
|
|
50
10
|
//# sourceMappingURL=index.js.map
|
package/build/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,EACb,wBAAwB,EACxB,uBAAuB,EACvB,cAAc,EACd,WAAW,EACX,cAAc,EACf,MAAM,0BAA0B,CAAA;AAEjC,OAAO,EAAE,QAAQ,IAAI,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* oh-my-pi (OMP) Platform Adapter
|
|
3
|
+
*
|
|
4
|
+
* Registers mnemo memory hooks using the pi.on() event paradigm.
|
|
5
|
+
* Provides the same memory capabilities as the OpenCode adapter
|
|
6
|
+
* but through OMP's event-driven plugin interface.
|
|
7
|
+
*/
|
|
8
|
+
/** Context object passed to OMP event handlers */
|
|
9
|
+
export interface OmpContext {
|
|
10
|
+
directory: string;
|
|
11
|
+
model?: {
|
|
12
|
+
contextLimit?: number;
|
|
13
|
+
};
|
|
14
|
+
system?: string[];
|
|
15
|
+
content?: string;
|
|
16
|
+
context?: string[];
|
|
17
|
+
}
|
|
18
|
+
/** OMP plugin interface using the pi.on() paradigm */
|
|
19
|
+
export interface OmpPlugin {
|
|
20
|
+
on(event: string, handler: (ctx: OmpContext) => Promise<void>): void;
|
|
21
|
+
}
|
|
22
|
+
/** Register mnemo hooks with an OMP plugin instance */
|
|
23
|
+
export declare function register(pi: OmpPlugin): void;
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/platforms/omp/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAeH,kDAAkD;AAClD,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE;QAAE,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;IACjC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;CACnB;AAED,sDAAsD;AACtD,MAAM,WAAW,SAAS;IACxB,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,EAAE,UAAU,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;CACrE;AAKD,uDAAuD;AACvD,wBAAgB,QAAQ,CAAC,EAAE,EAAE,SAAS,GAAG,IAAI,CA6D5C"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* oh-my-pi (OMP) Platform Adapter
|
|
3
|
+
*
|
|
4
|
+
* Registers mnemo memory hooks using the pi.on() event paradigm.
|
|
5
|
+
* Provides the same memory capabilities as the OpenCode adapter
|
|
6
|
+
* but through OMP's event-driven plugin interface.
|
|
7
|
+
*/
|
|
8
|
+
import { MnemoBridge } from '../../bridge.js';
|
|
9
|
+
import { buildMemoryContext, COMPACTION_INSTRUCTION, captureConstraint, computeBudget, fetchCompactionMemories, getProjectName, hashContent, SELF_AWARENESS } from '../../core/memory-service.js';
|
|
10
|
+
import { logger } from '../../logger.js';
|
|
11
|
+
/** Dedup set for auto-capture (per-process lifetime) */
|
|
12
|
+
const capturedHashes = new Set();
|
|
13
|
+
/** Register mnemo hooks with an OMP plugin instance */
|
|
14
|
+
export function register(pi) {
|
|
15
|
+
const bridge = MnemoBridge.getInstance();
|
|
16
|
+
// Background connect (non-blocking)
|
|
17
|
+
setTimeout(async () => {
|
|
18
|
+
try {
|
|
19
|
+
await bridge.connect();
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
// Circuit breaker handles repeated failures
|
|
23
|
+
}
|
|
24
|
+
}, 100);
|
|
25
|
+
pi.on('system-prompt', async (ctx) => {
|
|
26
|
+
try {
|
|
27
|
+
ctx.system = ctx.system ?? [];
|
|
28
|
+
ctx.system.push(SELF_AWARENESS);
|
|
29
|
+
if (!bridge.isAvailable())
|
|
30
|
+
return;
|
|
31
|
+
const projectName = getProjectName(ctx.directory);
|
|
32
|
+
const budget = computeBudget(ctx.model?.contextLimit);
|
|
33
|
+
const injection = await buildMemoryContext(bridge, projectName, budget);
|
|
34
|
+
if (injection)
|
|
35
|
+
ctx.system.push(injection);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
logger.error(`[Mnemo/OMP] Error in system-prompt: ${error}`);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
pi.on('message', async (ctx) => {
|
|
42
|
+
if (!ctx.content || !bridge.isAvailable())
|
|
43
|
+
return;
|
|
44
|
+
try {
|
|
45
|
+
const projectName = getProjectName(ctx.directory);
|
|
46
|
+
const hash = hashContent(ctx.content);
|
|
47
|
+
if (capturedHashes.has(hash))
|
|
48
|
+
return;
|
|
49
|
+
const captured = await captureConstraint(bridge, ctx.content, projectName);
|
|
50
|
+
if (captured) {
|
|
51
|
+
capturedHashes.add(hash);
|
|
52
|
+
logger.info(`[Mnemo/OMP] Auto-captured a new rule for ${projectName}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
logger.error(`[Mnemo/OMP] Error in message capture: ${error}`);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
pi.on('compact', async (ctx) => {
|
|
60
|
+
try {
|
|
61
|
+
if (!bridge.isAvailable())
|
|
62
|
+
return;
|
|
63
|
+
ctx.context = ctx.context ?? [];
|
|
64
|
+
const memoryContext = await fetchCompactionMemories(bridge);
|
|
65
|
+
if (memoryContext)
|
|
66
|
+
ctx.context.push(memoryContext);
|
|
67
|
+
ctx.context.push(COMPACTION_INSTRUCTION);
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
logger.error(`[Mnemo/OMP] Error in compaction: ${error}`);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/platforms/omp/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACtB,iBAAiB,EACjB,aAAa,EACb,uBAAuB,EACvB,cAAc,EACd,WAAW,EACX,cAAc,EACf,MAAM,8BAA8B,CAAA;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAgBxC,wDAAwD;AACxD,MAAM,cAAc,GAAG,IAAI,GAAG,EAAU,CAAA;AAExC,uDAAuD;AACvD,MAAM,UAAU,QAAQ,CAAC,EAAa;IACpC,MAAM,MAAM,GAAG,WAAW,CAAC,WAAW,EAAE,CAAA;IAExC,oCAAoC;IACpC,UAAU,CAAC,KAAK,IAAI,EAAE;QACpB,IAAI,CAAC;YACH,MAAM,MAAM,CAAC,OAAO,EAAE,CAAA;QACxB,CAAC;QAAC,MAAM,CAAC;YACP,4CAA4C;QAC9C,CAAC;IACH,CAAC,EAAE,GAAG,CAAC,CAAA;IAEP,EAAE,CAAC,EAAE,CAAC,eAAe,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;QACnC,IAAI,CAAC;YACH,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,IAAI,EAAE,CAAA;YAC7B,G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f,MAAM,CAAC,KAAK,CAAC,yCAAyC,KAAK,EAAE,CAAC,CAAA;QAChE,CAAC;IACH,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,EAAE,CAAC,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;QAC7B,IAAI,CAAC;YACH,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE;gBAAE,OAAM;YAEjC,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,IAAI,EAAE,CAAA;YAE/B,MAAM,aAAa,GAAG,MAAM,uBAAuB,CAAC,MAAM,CAAC,CAAA;YAC3D,IAAI,aAAa;gBAAE,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAA;YAElD,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAA;QAC1C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,oCAAoC,KAAK,EAAE,CAAC,CAAA;QAC3D,CAAC;IACH,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenCode Platform Adapter
|
|
3
|
+
*
|
|
4
|
+
* Plugin entrypoint that registers tools and hooks with the OpenCode runtime.
|
|
5
|
+
* Connects to mnemo-mcp (Python MCP server) via stdio transport to provide
|
|
6
|
+
* persistent memory capabilities across coding sessions.
|
|
7
|
+
*/
|
|
8
|
+
import type { Plugin } from '@opencode-ai/plugin';
|
|
9
|
+
declare const plugin: Plugin;
|
|
10
|
+
export default plugin;
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/platforms/opencode/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAOjD,QAAA,MAAM,MAAM,EAAE,MAwCb,CAAA;AAED,eAAe,MAAM,CAAA"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenCode Platform Adapter
|
|
3
|
+
*
|
|
4
|
+
* Plugin entrypoint that registers tools and hooks with the OpenCode runtime.
|
|
5
|
+
* Connects to mnemo-mcp (Python MCP server) via stdio transport to provide
|
|
6
|
+
* persistent memory capabilities across coding sessions.
|
|
7
|
+
*/
|
|
8
|
+
import { MnemoBridge } from '../../bridge.js';
|
|
9
|
+
import { autoCaptureHook, messageHook } from '../../hooks/auto-capture.js';
|
|
10
|
+
import { compactionHook } from '../../hooks/compaction.js';
|
|
11
|
+
import { systemPromptHook } from '../../hooks/system-prompt.js';
|
|
12
|
+
import { mnemoForget, mnemoRemember, mnemoSearch } from '../../tools/memory.js';
|
|
13
|
+
const plugin = async (input) => {
|
|
14
|
+
const bridge = MnemoBridge.getInstance();
|
|
15
|
+
// Start bridge connection in background (non-blocking).
|
|
16
|
+
// If this fails, the circuit breaker in MnemoBridge will prevent repeated
|
|
17
|
+
// connection attempts from hooks, avoiding log noise.
|
|
18
|
+
setTimeout(async () => {
|
|
19
|
+
try {
|
|
20
|
+
await bridge.connect();
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
// Silently handled -- circuit breaker will prevent further attempts.
|
|
24
|
+
// Hooks check bridge.isAvailable() before calling, so no cascading errors.
|
|
25
|
+
}
|
|
26
|
+
}, 100);
|
|
27
|
+
return {
|
|
28
|
+
// Tools
|
|
29
|
+
tool: {
|
|
30
|
+
mnemo_search: mnemoSearch,
|
|
31
|
+
mnemo_remember: mnemoRemember,
|
|
32
|
+
mnemo_forget: mnemoForget
|
|
33
|
+
},
|
|
34
|
+
// Hooks
|
|
35
|
+
'experimental.chat.system.transform': async (inParams, outParams) => {
|
|
36
|
+
await systemPromptHook(inParams, outParams, input.directory);
|
|
37
|
+
},
|
|
38
|
+
'chat.message': async (inParams, outParams) => {
|
|
39
|
+
await messageHook(inParams, outParams);
|
|
40
|
+
},
|
|
41
|
+
event: async (inParams) => {
|
|
42
|
+
await autoCaptureHook(inParams, input.directory);
|
|
43
|
+
},
|
|
44
|
+
'experimental.session.compacting': async (inParams, outParams) => {
|
|
45
|
+
await compactionHook(inParams, outParams);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
export default plugin;
|
|
50
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/platforms/opencode/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAE/E,MAAM,MAAM,GAAW,KAAK,EAAE,KAAK,EAAE,EAAE;IACrC,MAAM,MAAM,GAAG,WAAW,CAAC,WAAW,EAAE,CAAA;IAExC,wDAAwD;IACxD,0EAA0E;IAC1E,sDAAsD;IACtD,UAAU,CAAC,KAAK,IAAI,EAAE;QACpB,IAAI,CAAC;YACH,MAAM,MAAM,CAAC,OAAO,EAAE,CAAA;QACxB,CAAC;QAAC,MAAM,CAAC;YACP,qEAAqE;YACrE,2EAA2E;QAC7E,CAAC;IACH,CAAC,EAAE,GAAG,CAAC,CAAA;IAEP,OAAO;QACL,QAAQ;QACR,IAAI,EAAE;YACJ,YAAY,EAAE,WAAW;YACzB,cAAc,EAAE,aAAa;YAC7B,YAAY,EAAE,WAAW;SAC1B;QAED,QAAQ;QACR,oCAAoC,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE;YAClE,MAAM,gBAAgB,CAAC,QAAQ,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,CAAA;QAC9D,CAAC;QAED,cAAc,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE;YAC5C,MAAM,WAAW,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA;QACxC,CAAC;QAED,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE;YACxB,MAAM,eAAe,CAAC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,CAAA;QAClD,CAAC;QAED,iCAAiC,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE;YAC/D,MAAM,cAAc,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA;QAC3C,CAAC;KACF,CAAA;AACH,CAAC,CAAA;AAED,eAAe,MAAM,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../src/tools/memory.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,KAAK,cAAc,EAAQ,MAAM,0BAA0B,CAAA;
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../src/tools/memory.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,KAAK,cAAc,EAAQ,MAAM,0BAA0B,CAAA;AAMpE,eAAO,MAAM,WAAW,EAAE,cAwCxB,CAAA;AAEF,eAAO,MAAM,aAAa,EAAE,cAsC1B,CAAA;AAEF,eAAO,MAAM,WAAW,EAAE,cAuBxB,CAAA"}
|
|
@@ -8,12 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { tool } from '@opencode-ai/plugin/tool';
|
|
10
10
|
import { MnemoBridge } from '../bridge.js';
|
|
11
|
-
|
|
12
|
-
function getProjectName(directory) {
|
|
13
|
-
const cleanDir = directory.replace(/\\/g, '/');
|
|
14
|
-
const parts = cleanDir.split('/');
|
|
15
|
-
return parts[parts.length - 1] || 'unknown';
|
|
16
|
-
}
|
|
11
|
+
import { getProjectName } from '../core/memory-service.js';
|
|
17
12
|
export const mnemoSearch = tool({
|
|
18
13
|
description: 'Search the persistent memory system (mnemo) for project rules, facts, preferences, or context. Use this proactively when entering a new codebase or when the user asks about past decisions.',
|
|
19
14
|
args: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../../../src/tools/memory.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAuB,IAAI,EAAE,MAAM,0BAA0B,CAAA;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../../../src/tools/memory.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAuB,IAAI,EAAE,MAAM,0BAA0B,CAAA;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAG1C,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAE1D,MAAM,CAAC,MAAM,WAAW,GAAmB,IAAI,CAAC;IAC9C,WAAW,EACT,8LAA8L;IAChM,IAAI,EAAE;QACJ,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,wEAAwE,CAAC;QAC9G,QAAQ,EAAE,IAAI,CAAC,MAAM;aAClB,MAAM,EAAE;aACR,QAAQ,EAAE;aACV,QAAQ,CAAC,2EAA2E,CAAC;QACxF,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,uBAAuB,CAAC;KACxF;IACD,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO;QACz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