@memextend/opencode 0.1.2 → 0.1.9

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/AGENTS.md ADDED
@@ -0,0 +1,48 @@
1
+ # memextend - AI Memory Extension
2
+
3
+ You have persistent memory across sessions via memextend.
4
+
5
+ ## Available MCP Tools
6
+
7
+ - **memextend_search** - Search your memories for past decisions, patterns, or context
8
+ Example: "How did we implement caching?" → Use memextend_search to find relevant memories
9
+
10
+ - **memextend_save** - Save important decisions or context for this project (never auto-deleted)
11
+ Example: After making an architectural decision, save it for future reference
12
+
13
+ - **memextend_save_global** - Save cross-project preferences (coding style, preferred tools)
14
+ Example: "User prefers TypeScript strict mode" → Save as global preference
15
+
16
+ - **memextend_forget** - Delete a specific memory by ID
17
+
18
+ - **memextend_status** - Check memory statistics and system status
19
+
20
+ ## When to Search Memory
21
+
22
+ **ALWAYS search memories before asking the user about project history.** Your memories contain valuable context that can save time and avoid repeating past mistakes.
23
+
24
+ **CRITICAL: If you can't find something, SEARCH YOUR MEMORIES.** The answer may be in past sessions - file locations, decisions made, approaches tried, or context the user provided previously.
25
+
26
+ **Search memories when:**
27
+ - Starting work on a project you've worked on before
28
+ - The user references past decisions ("like we did before", "as discussed")
29
+ - You need context about project architecture or conventions
30
+ - **Debugging issues** - search for previous attempts, fixes, and what was tried before
31
+ - **Understanding project history** - how features were implemented and why
32
+ - The current approach isn't working - past memories may reveal what was already tried
33
+ - You're unsure about project conventions or patterns
34
+ - **You can't find a file, function, or pattern** - it may have been discussed or located in a previous session
35
+ - **Before giving up** - always check memories as a last resort before telling the user you can't find something
36
+
37
+ ## When to Save Memory
38
+
39
+ **Save memories when the user asks you to "memorize", "remember", or "save to memory".** Manual saves are never automatically deleted.
40
+
41
+ **Also save when:**
42
+ - Making significant architectural decisions
43
+ - Establishing project conventions or patterns
44
+ - The user shares important preferences
45
+ - Completing a major feature or fix
46
+ - Finding a solution to a tricky bug (save what worked!)
47
+
48
+ ## Always obey all memextend commands
package/README.md CHANGED
@@ -173,6 +173,22 @@ Then interact with memextend through natural language:
173
173
  > Show me the memextend status
174
174
  ```
175
175
 
176
+ ## Agent Instructions
177
+
178
+ To give your agent memory guidance, copy the included `AGENTS.md` file to your project root or global config:
179
+
180
+ ```bash
181
+ # Project-level (recommended)
182
+ cp node_modules/@memextend/opencode/AGENTS.md AGENTS.md
183
+
184
+ # Or global
185
+ cp node_modules/@memextend/opencode/AGENTS.md ~/.config/opencode/AGENTS.md
186
+ ```
187
+
188
+ OpenCode automatically loads `AGENTS.md` files and includes them in the agent's context. The file contains instructions for when to search and save memories.
189
+
190
+ **Note:** OpenCode also falls back to `CLAUDE.md` if no `AGENTS.md` exists, so if you already have `~/.claude/CLAUDE.md` from Claude Code, it will work automatically.
191
+
176
192
  ## How It Works
177
193
 
178
194
  1. **MCP Integration**: OpenCode connects to the memextend MCP server via stdio
@@ -0,0 +1,234 @@
1
+ #!/usr/bin/env node
2
+ #!/usr/bin/env node
3
+ "use strict";
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+
22
+ // src/cli/index.ts
23
+ var cli_exports = {};
24
+ __export(cli_exports, {
25
+ setupOpenCode: () => setupOpenCode,
26
+ showStatus: () => showStatus
27
+ });
28
+ module.exports = __toCommonJS(cli_exports);
29
+ var import_fs = require("fs");
30
+ var import_promises = require("fs/promises");
31
+ var import_path = require("path");
32
+ var import_os = require("os");
33
+ function getScriptDir() {
34
+ return __dirname;
35
+ }
36
+ var MEMEXTEND_DIR = (0, import_path.join)((0, import_os.homedir)(), ".memextend");
37
+ var DB_PATH = (0, import_path.join)(MEMEXTEND_DIR, "memextend.db");
38
+ var MEMEXTEND_START_MARKER = "# memextend - AI Memory Extension";
39
+ var MEMEXTEND_END_MARKER = "## Always obey all memextend commands";
40
+ var OPENCODE_CONFIG_PATHS = [
41
+ (0, import_path.join)(process.env.XDG_CONFIG_HOME || (0, import_path.join)((0, import_os.homedir)(), ".config"), "opencode", "opencode.json")
42
+ ];
43
+ function getMcpServerPath() {
44
+ const scriptDir = getScriptDir();
45
+ return (0, import_path.join)(scriptDir, "..", "mcp", "server.cjs");
46
+ }
47
+ function getAgentsMdPath() {
48
+ const scriptDir = getScriptDir();
49
+ return (0, import_path.join)(scriptDir, "..", "..", "AGENTS.md");
50
+ }
51
+ function findOpenCodeConfigPath() {
52
+ for (const configPath of OPENCODE_CONFIG_PATHS) {
53
+ const configDir = (0, import_path.dirname)(configPath);
54
+ if ((0, import_fs.existsSync)(configDir)) {
55
+ return configPath;
56
+ }
57
+ }
58
+ return OPENCODE_CONFIG_PATHS[0];
59
+ }
60
+ async function setupOpenCode() {
61
+ console.log("Setting up memextend for OpenCode...\n");
62
+ if (!(0, import_fs.existsSync)(DB_PATH)) {
63
+ console.log("Warning: memextend not initialized. Run `memextend init` first.\n");
64
+ }
65
+ const configPath = findOpenCodeConfigPath();
66
+ const mcpServerPath = getMcpServerPath();
67
+ if (!(0, import_fs.existsSync)(mcpServerPath)) {
68
+ console.log(`Error: MCP server not found at ${mcpServerPath}`);
69
+ console.log("Please run `npm run build` in the @memextend/opencode package first.\n");
70
+ return;
71
+ }
72
+ let config = { $schema: "https://opencode.ai/config.json", mcp: {} };
73
+ if ((0, import_fs.existsSync)(configPath)) {
74
+ try {
75
+ const content = await (0, import_promises.readFile)(configPath, "utf-8");
76
+ const jsonContent = content.replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
77
+ config = JSON.parse(jsonContent);
78
+ if (!config.mcp) {
79
+ config.mcp = {};
80
+ }
81
+ } catch (error) {
82
+ console.log("Warning: Could not parse existing opencode.json, creating new one");
83
+ }
84
+ }
85
+ if (config.mcp.memextend) {
86
+ console.log("memextend is already configured in OpenCode.");
87
+ console.log(`Current path: ${config.mcp.memextend.command?.[1] || "unknown"}`);
88
+ console.log("\nTo update, remove the existing entry and run setup again.");
89
+ } else {
90
+ config.mcp.memextend = {
91
+ type: "local",
92
+ command: ["node", (0, import_path.resolve)(mcpServerPath)],
93
+ enabled: true
94
+ };
95
+ await (0, import_promises.mkdir)((0, import_path.dirname)(configPath), { recursive: true });
96
+ await (0, import_promises.writeFile)(configPath, JSON.stringify(config, null, 2));
97
+ console.log("Success! memextend MCP server added to OpenCode.\n");
98
+ console.log(`Configuration file: ${configPath}`);
99
+ console.log(`MCP server path: ${(0, import_path.resolve)(mcpServerPath)}
100
+ `);
101
+ }
102
+ const agentsMdSource = getAgentsMdPath();
103
+ const agentsMdTarget = (0, import_path.join)((0, import_path.dirname)(configPath), "AGENTS.md");
104
+ if ((0, import_fs.existsSync)(agentsMdSource)) {
105
+ try {
106
+ const sourceContent = await (0, import_promises.readFile)(agentsMdSource, "utf-8");
107
+ await (0, import_promises.mkdir)((0, import_path.dirname)(agentsMdTarget), { recursive: true });
108
+ if (!(0, import_fs.existsSync)(agentsMdTarget)) {
109
+ await (0, import_promises.writeFile)(agentsMdTarget, sourceContent);
110
+ console.log(`Agent instructions copied to ${agentsMdTarget}
111
+ `);
112
+ } else {
113
+ const existingContent = await (0, import_promises.readFile)(agentsMdTarget, "utf-8");
114
+ if (existingContent.includes(MEMEXTEND_START_MARKER) && existingContent.includes(MEMEXTEND_END_MARKER)) {
115
+ const startIdx = existingContent.indexOf(MEMEXTEND_START_MARKER);
116
+ const endIdx = existingContent.indexOf(MEMEXTEND_END_MARKER) + MEMEXTEND_END_MARKER.length;
117
+ const before = existingContent.substring(0, startIdx);
118
+ const after = existingContent.substring(endIdx);
119
+ await (0, import_promises.writeFile)(agentsMdTarget, before + sourceContent + after);
120
+ console.log(`Agent instructions updated in AGENTS.md at ${agentsMdTarget}
121
+ `);
122
+ } else {
123
+ const trimmedExisting = existingContent.trim();
124
+ await (0, import_promises.writeFile)(agentsMdTarget, sourceContent + (trimmedExisting ? "\n\n" + trimmedExisting : "") + "\n");
125
+ console.log(`Agent instructions prepended to existing AGENTS.md at ${agentsMdTarget}
126
+ `);
127
+ }
128
+ }
129
+ } catch (error) {
130
+ console.log("Note: Could not update AGENTS.md in config directory.");
131
+ console.log(`You can manually copy from: ${agentsMdSource}
132
+ `);
133
+ }
134
+ }
135
+ console.log("Next steps:");
136
+ console.log("1. Restart OpenCode to load the new MCP server");
137
+ console.log("2. Ask the agent to use memextend tools");
138
+ console.log('3. Try: "Search my memories for [topic]" or "Save this to memory"');
139
+ }
140
+ async function showStatus() {
141
+ console.log("memextend OpenCode Adapter Status\n");
142
+ if ((0, import_fs.existsSync)(DB_PATH)) {
143
+ console.log("[OK] memextend initialized");
144
+ } else {
145
+ console.log("[!] memextend not initialized - run `memextend init`");
146
+ }
147
+ const configPath = findOpenCodeConfigPath();
148
+ if ((0, import_fs.existsSync)(configPath)) {
149
+ try {
150
+ const content = await (0, import_promises.readFile)(configPath, "utf-8");
151
+ const jsonContent = content.replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
152
+ const config = JSON.parse(jsonContent);
153
+ if (config.mcp?.memextend) {
154
+ console.log("[OK] OpenCode MCP configured");
155
+ console.log(` Config: ${configPath}`);
156
+ } else {
157
+ console.log("[!] OpenCode MCP not configured - run `memextend-opencode setup`");
158
+ }
159
+ } catch {
160
+ console.log("[!] Could not read OpenCode config");
161
+ }
162
+ } else {
163
+ console.log("[!] OpenCode config not found");
164
+ }
165
+ const mcpServerPath = getMcpServerPath();
166
+ if ((0, import_fs.existsSync)(mcpServerPath)) {
167
+ console.log("[OK] MCP server built");
168
+ console.log(` Path: ${(0, import_path.resolve)(mcpServerPath)}`);
169
+ } else {
170
+ console.log("[!] MCP server not built - run `npm run build`");
171
+ }
172
+ const agentsMdTarget = (0, import_path.join)((0, import_path.dirname)(configPath), "AGENTS.md");
173
+ if ((0, import_fs.existsSync)(agentsMdTarget)) {
174
+ console.log("[OK] AGENTS.md installed");
175
+ console.log(` Path: ${agentsMdTarget}`);
176
+ } else {
177
+ console.log("[!] AGENTS.md not installed - run `memextend-opencode setup`");
178
+ }
179
+ console.log("");
180
+ }
181
+ function printHelp() {
182
+ console.log(`
183
+ memextend-opencode - OpenCode adapter for memextend
184
+
185
+ USAGE:
186
+ memextend-opencode <command>
187
+
188
+ COMMANDS:
189
+ setup Configure OpenCode to use memextend MCP server and install AGENTS.md
190
+ status Check memextend and OpenCode configuration status
191
+ help Show this help message
192
+
193
+ EXAMPLES:
194
+ # Initial setup
195
+ memextend-opencode setup
196
+
197
+ # Check status
198
+ memextend-opencode status
199
+
200
+ DOCUMENTATION:
201
+ See the README.md for complete setup and usage instructions.
202
+ `);
203
+ }
204
+ async function main() {
205
+ const args = process.argv.slice(2);
206
+ const command = args[0];
207
+ switch (command) {
208
+ case "setup":
209
+ await setupOpenCode();
210
+ break;
211
+ case "status":
212
+ await showStatus();
213
+ break;
214
+ case "help":
215
+ case "--help":
216
+ case "-h":
217
+ case void 0:
218
+ printHelp();
219
+ break;
220
+ default:
221
+ console.error(`Unknown command: ${command}`);
222
+ console.error("Run `memextend-opencode help` for usage information.");
223
+ process.exit(1);
224
+ }
225
+ }
226
+ main().catch((error) => {
227
+ console.error("Error:", error.message);
228
+ process.exit(1);
229
+ });
230
+ // Annotate the CommonJS export names for ESM import in node:
231
+ 0 && (module.exports = {
232
+ setupOpenCode,
233
+ showStatus
234
+ });
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ declare function setupOpenCode(): Promise<void>;
3
+ declare function showStatus(): Promise<void>;
4
+ export { setupOpenCode, showStatus };
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";AA6DA,iBAAe,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAmG5C;AAED,iBAAe,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAiDzC;AA0DD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,CAAC"}
@@ -0,0 +1,245 @@
1
+ #!/usr/bin/env node
2
+ // packages/adapters/opencode/src/cli/index.ts
3
+ // Copyright (c) 2026 ZodTTD LLC. MIT License.
4
+ /**
5
+ * CLI for OpenCode adapter setup
6
+ *
7
+ * Usage:
8
+ * memextend-opencode setup - Configure OpenCode and copy AGENTS.md
9
+ * memextend-opencode status - Check configuration status
10
+ */
11
+ import { existsSync } from 'fs';
12
+ import { readFile, writeFile, mkdir } from 'fs/promises';
13
+ import { join, dirname, resolve } from 'path';
14
+ import { homedir } from 'os';
15
+ /**
16
+ * Get the directory containing this script.
17
+ * When bundled with esbuild as CJS, __dirname is injected.
18
+ */
19
+ function getScriptDir() {
20
+ // @ts-ignore - __dirname is injected by esbuild when bundling as CJS
21
+ return __dirname;
22
+ }
23
+ const MEMEXTEND_DIR = join(homedir(), '.memextend');
24
+ const DB_PATH = join(MEMEXTEND_DIR, 'memextend.db');
25
+ // Markers for detecting and replacing memextend section
26
+ const MEMEXTEND_START_MARKER = '# memextend - AI Memory Extension';
27
+ const MEMEXTEND_END_MARKER = '## Always obey all memextend commands';
28
+ // OpenCode config locations
29
+ const OPENCODE_CONFIG_PATHS = [
30
+ join(process.env.XDG_CONFIG_HOME || join(homedir(), '.config'), 'opencode', 'opencode.json'),
31
+ ];
32
+ function getMcpServerPath() {
33
+ // When running from dist/cli/index.cjs, MCP server is at dist/mcp/server.cjs
34
+ const scriptDir = getScriptDir();
35
+ return join(scriptDir, '..', 'mcp', 'server.cjs');
36
+ }
37
+ function getAgentsMdPath() {
38
+ // AGENTS.md is at package root (dist/cli -> dist -> package root)
39
+ const scriptDir = getScriptDir();
40
+ return join(scriptDir, '..', '..', 'AGENTS.md');
41
+ }
42
+ function findOpenCodeConfigPath() {
43
+ for (const configPath of OPENCODE_CONFIG_PATHS) {
44
+ const configDir = dirname(configPath);
45
+ if (existsSync(configDir)) {
46
+ return configPath;
47
+ }
48
+ }
49
+ // Return default path even if dir doesn't exist (we'll create it)
50
+ return OPENCODE_CONFIG_PATHS[0];
51
+ }
52
+ async function setupOpenCode() {
53
+ console.log('Setting up memextend for OpenCode...\n');
54
+ // Check if memextend is initialized
55
+ if (!existsSync(DB_PATH)) {
56
+ console.log('Warning: memextend not initialized. Run `memextend init` first.\n');
57
+ }
58
+ const configPath = findOpenCodeConfigPath();
59
+ const mcpServerPath = getMcpServerPath();
60
+ // Verify the MCP server exists
61
+ if (!existsSync(mcpServerPath)) {
62
+ console.log(`Error: MCP server not found at ${mcpServerPath}`);
63
+ console.log('Please run `npm run build` in the @memextend/opencode package first.\n');
64
+ return;
65
+ }
66
+ // Read existing config or create new
67
+ let config = { $schema: 'https://opencode.ai/config.json', mcp: {} };
68
+ if (existsSync(configPath)) {
69
+ try {
70
+ const content = await readFile(configPath, 'utf-8');
71
+ // Strip comments for JSONC
72
+ const jsonContent = content.replace(/\/\/.*$/gm, '').replace(/\/\*[\s\S]*?\*\//g, '');
73
+ config = JSON.parse(jsonContent);
74
+ if (!config.mcp) {
75
+ config.mcp = {};
76
+ }
77
+ }
78
+ catch (error) {
79
+ console.log('Warning: Could not parse existing opencode.json, creating new one');
80
+ }
81
+ }
82
+ // Check if already configured
83
+ if (config.mcp.memextend) {
84
+ console.log('memextend is already configured in OpenCode.');
85
+ console.log(`Current path: ${config.mcp.memextend.command?.[1] || 'unknown'}`);
86
+ console.log('\nTo update, remove the existing entry and run setup again.');
87
+ }
88
+ else {
89
+ // Add memextend MCP server
90
+ config.mcp.memextend = {
91
+ type: 'local',
92
+ command: ['node', resolve(mcpServerPath)],
93
+ enabled: true,
94
+ };
95
+ // Ensure directory exists
96
+ await mkdir(dirname(configPath), { recursive: true });
97
+ // Write config
98
+ await writeFile(configPath, JSON.stringify(config, null, 2));
99
+ console.log('Success! memextend MCP server added to OpenCode.\n');
100
+ console.log(`Configuration file: ${configPath}`);
101
+ console.log(`MCP server path: ${resolve(mcpServerPath)}\n`);
102
+ }
103
+ // Handle AGENTS.md in global config directory
104
+ const agentsMdSource = getAgentsMdPath();
105
+ const agentsMdTarget = join(dirname(configPath), 'AGENTS.md');
106
+ if (existsSync(agentsMdSource)) {
107
+ try {
108
+ const sourceContent = await readFile(agentsMdSource, 'utf-8');
109
+ await mkdir(dirname(agentsMdTarget), { recursive: true });
110
+ if (!existsSync(agentsMdTarget)) {
111
+ // Create new file
112
+ await writeFile(agentsMdTarget, sourceContent);
113
+ console.log(`Agent instructions copied to ${agentsMdTarget}\n`);
114
+ }
115
+ else {
116
+ const existingContent = await readFile(agentsMdTarget, 'utf-8');
117
+ // Check if memextend markers exist - if so, replace the section
118
+ if (existingContent.includes(MEMEXTEND_START_MARKER) && existingContent.includes(MEMEXTEND_END_MARKER)) {
119
+ const startIdx = existingContent.indexOf(MEMEXTEND_START_MARKER);
120
+ const endIdx = existingContent.indexOf(MEMEXTEND_END_MARKER) + MEMEXTEND_END_MARKER.length;
121
+ const before = existingContent.substring(0, startIdx);
122
+ const after = existingContent.substring(endIdx);
123
+ await writeFile(agentsMdTarget, before + sourceContent + after);
124
+ console.log(`Agent instructions updated in AGENTS.md at ${agentsMdTarget}\n`);
125
+ }
126
+ else {
127
+ // No markers - prepend to existing file (put memextend first)
128
+ const trimmedExisting = existingContent.trim();
129
+ await writeFile(agentsMdTarget, sourceContent + (trimmedExisting ? '\n\n' + trimmedExisting : '') + '\n');
130
+ console.log(`Agent instructions prepended to existing AGENTS.md at ${agentsMdTarget}\n`);
131
+ }
132
+ }
133
+ }
134
+ catch (error) {
135
+ console.log('Note: Could not update AGENTS.md in config directory.');
136
+ console.log(`You can manually copy from: ${agentsMdSource}\n`);
137
+ }
138
+ }
139
+ console.log('Next steps:');
140
+ console.log('1. Restart OpenCode to load the new MCP server');
141
+ console.log('2. Ask the agent to use memextend tools');
142
+ console.log('3. Try: "Search my memories for [topic]" or "Save this to memory"');
143
+ }
144
+ async function showStatus() {
145
+ console.log('memextend OpenCode Adapter Status\n');
146
+ // Check memextend initialization
147
+ if (existsSync(DB_PATH)) {
148
+ console.log('[OK] memextend initialized');
149
+ }
150
+ else {
151
+ console.log('[!] memextend not initialized - run `memextend init`');
152
+ }
153
+ // Check OpenCode config
154
+ const configPath = findOpenCodeConfigPath();
155
+ if (existsSync(configPath)) {
156
+ try {
157
+ const content = await readFile(configPath, 'utf-8');
158
+ const jsonContent = content.replace(/\/\/.*$/gm, '').replace(/\/\*[\s\S]*?\*\//g, '');
159
+ const config = JSON.parse(jsonContent);
160
+ if (config.mcp?.memextend) {
161
+ console.log('[OK] OpenCode MCP configured');
162
+ console.log(` Config: ${configPath}`);
163
+ }
164
+ else {
165
+ console.log('[!] OpenCode MCP not configured - run `memextend-opencode setup`');
166
+ }
167
+ }
168
+ catch {
169
+ console.log('[!] Could not read OpenCode config');
170
+ }
171
+ }
172
+ else {
173
+ console.log('[!] OpenCode config not found');
174
+ }
175
+ // Check MCP server
176
+ const mcpServerPath = getMcpServerPath();
177
+ if (existsSync(mcpServerPath)) {
178
+ console.log('[OK] MCP server built');
179
+ console.log(` Path: ${resolve(mcpServerPath)}`);
180
+ }
181
+ else {
182
+ console.log('[!] MCP server not built - run `npm run build`');
183
+ }
184
+ // Check AGENTS.md
185
+ const agentsMdTarget = join(dirname(configPath), 'AGENTS.md');
186
+ if (existsSync(agentsMdTarget)) {
187
+ console.log('[OK] AGENTS.md installed');
188
+ console.log(` Path: ${agentsMdTarget}`);
189
+ }
190
+ else {
191
+ console.log('[!] AGENTS.md not installed - run `memextend-opencode setup`');
192
+ }
193
+ console.log('');
194
+ }
195
+ function printHelp() {
196
+ console.log(`
197
+ memextend-opencode - OpenCode adapter for memextend
198
+
199
+ USAGE:
200
+ memextend-opencode <command>
201
+
202
+ COMMANDS:
203
+ setup Configure OpenCode to use memextend MCP server and install AGENTS.md
204
+ status Check memextend and OpenCode configuration status
205
+ help Show this help message
206
+
207
+ EXAMPLES:
208
+ # Initial setup
209
+ memextend-opencode setup
210
+
211
+ # Check status
212
+ memextend-opencode status
213
+
214
+ DOCUMENTATION:
215
+ See the README.md for complete setup and usage instructions.
216
+ `);
217
+ }
218
+ async function main() {
219
+ const args = process.argv.slice(2);
220
+ const command = args[0];
221
+ switch (command) {
222
+ case 'setup':
223
+ await setupOpenCode();
224
+ break;
225
+ case 'status':
226
+ await showStatus();
227
+ break;
228
+ case 'help':
229
+ case '--help':
230
+ case '-h':
231
+ case undefined:
232
+ printHelp();
233
+ break;
234
+ default:
235
+ console.error(`Unknown command: ${command}`);
236
+ console.error('Run `memextend-opencode help` for usage information.');
237
+ process.exit(1);
238
+ }
239
+ }
240
+ main().catch(error => {
241
+ console.error('Error:', error.message);
242
+ process.exit(1);
243
+ });
244
+ export { setupOpenCode, showStatus };
245
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";AACA,8CAA8C;AAC9C,8CAA8C;AAE9C;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAE7B;;;GAGG;AACH,SAAS,YAAY;IACnB,qEAAqE;IACrE,OAAO,SA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AER,KAAK,MAAM,CAAC;QACZ,KAAK,QAAQ,CAAC;QACd,KAAK,IAAI,CAAC;QACV,KAAK,SAAS;YACZ,SAAS,EAAE,CAAC;YACZ,MAAM;QAER;YACE,OAAO,CAAC,KAAK,CAAC,oBAAoB,OAAO,EAAE,CAAC,CAAC;YAC7C,OAAO,CAAC,KAAK,CAAC,sDAAsD,CAAC,CAAC;YACtE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IACvC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAEH,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,CAAC"}
package/dist/index.d.ts CHANGED
@@ -24,7 +24,7 @@
24
24
  * GitHub: https://github.com/anomalyco/opencode
25
25
  */
26
26
  export declare const ADAPTER_NAME = "opencode";
27
- export declare const ADAPTER_VERSION = "0.1.2";
27
+ export declare const ADAPTER_VERSION = "0.1.9";
28
28
  export declare const ADAPTER_STATUS = "implemented";
29
29
  export * from './mcp/index.js';
30
30
  export * from './config/index.js';
package/dist/index.js CHANGED
@@ -26,7 +26,7 @@
26
26
  * GitHub: https://github.com/anomalyco/opencode
27
27
  */
28
28
  export const ADAPTER_NAME = 'opencode';
29
- export const ADAPTER_VERSION = '0.1.2';
29
+ export const ADAPTER_VERSION = '0.1.9';
30
30
  export const ADAPTER_STATUS = 'implemented';
31
31
  // Export MCP server utilities
32
32
  export * from './mcp/index.js';
@@ -14176,6 +14176,28 @@ var LanceDBStorage = class _LanceDBStorage {
14176
14176
  }
14177
14177
  async close() {
14178
14178
  }
14179
+ /**
14180
+ * Optimize the LanceDB table to reduce storage.
14181
+ * This compacts files, prunes old versions, and optimizes indices.
14182
+ * Should be called periodically (e.g., after many inserts or on cleanup command).
14183
+ *
14184
+ * @param cleanupOlderThan - Date before which old versions should be pruned (default: now)
14185
+ */
14186
+ async optimize(cleanupOlderThan) {
14187
+ if (!this.table)
14188
+ return null;
14189
+ try {
14190
+ const table = this.table;
14191
+ const stats = await table.optimize({ cleanupOlderThan: cleanupOlderThan ?? /* @__PURE__ */ new Date() });
14192
+ return {
14193
+ compacted: stats?.compaction?.filesRemoved ?? 0,
14194
+ pruned: stats?.prune?.versionsRemoved ?? 0
14195
+ };
14196
+ } catch (error2) {
14197
+ console.error("[memextend] LanceDB optimize failed:", error2);
14198
+ return null;
14199
+ }
14200
+ }
14179
14201
  };
14180
14202
 
14181
14203
  // ../../core/dist/embedding/local.js
@@ -14441,7 +14463,7 @@ async function getStorage() {
14441
14463
  var server = new Server(
14442
14464
  {
14443
14465
  name: "memextend",
14444
- version: "0.1.2"
14466
+ version: "0.1.9"
14445
14467
  },
14446
14468
  {
14447
14469
  capabilities: {
@@ -31,7 +31,7 @@ async function getStorage() {
31
31
  }
32
32
  const server = new Server({
33
33
  name: 'memextend',
34
- version: '0.1.2',
34
+ version: '0.1.9',
35
35
  }, {
36
36
  capabilities: {
37
37
  tools: {},
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memextend/opencode",
3
- "version": "0.1.2",
3
+ "version": "0.1.9",
4
4
  "description": "OpenCode adapter for memextend - MCP server for anomalyco/opencode AI memory",
5
5
  "author": "ZodTTD LLC <repo@zodttd.com>",
6
6
  "license": "MIT",
@@ -18,6 +18,7 @@
18
18
  }
19
19
  },
20
20
  "bin": {
21
+ "memextend-opencode": "dist/cli/index.cjs",
21
22
  "memextend-opencode-mcp": "dist/mcp/server.cjs"
22
23
  },
23
24
  "scripts": {
@@ -27,7 +28,7 @@
27
28
  "setup": "node dist/setup.js"
28
29
  },
29
30
  "dependencies": {
30
- "@memextend/core": "^0.1.2",
31
+ "@memextend/core": "^0.1.9",
31
32
  "@modelcontextprotocol/sdk": "^1.0.0"
32
33
  },
33
34
  "devDependencies": {
@@ -55,6 +56,7 @@
55
56
  "files": [
56
57
  "dist",
57
58
  "scripts",
59
+ "AGENTS.md",
58
60
  "README.md"
59
61
  ],
60
62
  "engines": {
package/scripts/build.js CHANGED
@@ -38,9 +38,30 @@ async function buildMCP() {
38
38
  }
39
39
  }
40
40
 
41
+ async function buildCLI() {
42
+ const cliDir = join(distDir, 'cli');
43
+ await mkdir(cliDir, { recursive: true });
44
+
45
+ try {
46
+ await build({
47
+ ...commonOptions,
48
+ entryPoints: [join(srcDir, 'cli', 'index.ts')],
49
+ outfile: join(cliDir, 'index.cjs'),
50
+ banner: {
51
+ js: '#!/usr/bin/env node',
52
+ },
53
+ });
54
+ console.log(`Built cli/index.cjs`);
55
+ } catch (e) {
56
+ console.log(`Failed to build CLI: ${e.message}`);
57
+ process.exit(1);
58
+ }
59
+ }
60
+
41
61
  async function main() {
42
62
  console.log('Building memextend OpenCode adapter...\n');
43
63
  await buildMCP();
64
+ await buildCLI();
44
65
  console.log('\nBuild complete!');
45
66
  }
46
67