opencode-claude-memory 1.7.0 → 1.7.1

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.
Files changed (2) hide show
  1. package/dist/index.js +19 -8
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { tool } from "@opencode-ai/plugin";
2
+ import { parse, resolve } from "path";
2
3
  import { buildMemorySystemPrompt } from "./prompt.js";
3
4
  import { formatRecalledMemories, recallSelectedMemories } from "./recall.js";
4
5
  import { assertSupportedRecallSelectorClient, selectRelevantMemoryFilenames } from "./recallSelector.js";
@@ -117,6 +118,15 @@ function getRecallModel() {
117
118
  modelID: raw.slice(slashIdx + 1),
118
119
  };
119
120
  }
121
+ function isRootPath(path) {
122
+ const resolved = resolve(path);
123
+ return resolved === parse(resolved).root;
124
+ }
125
+ function resolveMemoryRoot(worktree, directory) {
126
+ if (isRootPath(worktree) && !isRootPath(directory))
127
+ return directory;
128
+ return worktree;
129
+ }
120
130
  function isUsefulRecallQuery(query) {
121
131
  const trimmed = query?.trim();
122
132
  if (!trimmed)
@@ -225,7 +235,8 @@ function getCallID(ctx) {
225
235
  }
226
236
  export const MemoryPlugin = async ({ worktree, directory, client }) => {
227
237
  directory ??= worktree;
228
- getMemoryDir(worktree);
238
+ const memoryRoot = resolveMemoryRoot(worktree, directory);
239
+ getMemoryDir(memoryRoot);
229
240
  return {
230
241
  config: async (config) => {
231
242
  const agentName = getRecallAgent();
@@ -285,7 +296,7 @@ export const MemoryPlugin = async ({ worktree, directory, client }) => {
285
296
  : startRecallPrefetch({
286
297
  client: client,
287
298
  directory,
288
- worktree,
299
+ worktree: memoryRoot,
289
300
  parentSessionID: sessionID,
290
301
  turnID,
291
302
  query,
@@ -321,7 +332,7 @@ export const MemoryPlugin = async ({ worktree, directory, client }) => {
321
332
  const ignoreMemoryContext = process.env.OPENCODE_MEMORY_IGNORE === "1" || shouldIgnoreMemoryContext(query);
322
333
  const recalled = ignoreMemoryContext ? [] : consumeRecallPrefetch(ctx);
323
334
  const recalledSection = formatRecalledMemories(recalled);
324
- const memoryPrompt = buildMemorySystemPrompt(worktree, recalledSection, {
335
+ const memoryPrompt = buildMemorySystemPrompt(memoryRoot, recalledSection, {
325
336
  includeIndex: !ignoreMemoryContext,
326
337
  });
327
338
  output.system.push(memoryPrompt);
@@ -350,7 +361,7 @@ export const MemoryPlugin = async ({ worktree, directory, client }) => {
350
361
  .describe("Memory content. For feedback/project types, structure as: rule/fact, then **Why:** and **How to apply:** lines"),
351
362
  },
352
363
  async execute(args, _ctx) {
353
- const filePath = saveMemory(worktree, args.file_name, args.name, args.description, args.type, args.content);
364
+ const filePath = saveMemory(memoryRoot, args.file_name, args.name, args.description, args.type, args.content);
354
365
  return `Memory saved to ${filePath}`;
355
366
  },
356
367
  }),
@@ -360,7 +371,7 @@ export const MemoryPlugin = async ({ worktree, directory, client }) => {
360
371
  file_name: tool.schema.string().describe("File name of the memory to delete (with or without .md extension)"),
361
372
  },
362
373
  async execute(args, _ctx) {
363
- const deleted = deleteMemory(worktree, args.file_name);
374
+ const deleted = deleteMemory(memoryRoot, args.file_name);
364
375
  return deleted ? `Memory "${args.file_name}" deleted.` : `Memory "${args.file_name}" not found.`;
365
376
  },
366
377
  }),
@@ -370,7 +381,7 @@ export const MemoryPlugin = async ({ worktree, directory, client }) => {
370
381
  "or when you need to recall what's been stored.",
371
382
  args: {},
372
383
  async execute(_args, ctx) {
373
- const entries = listMemories(worktree);
384
+ const entries = listMemories(memoryRoot);
374
385
  const callID = getCallID(ctx);
375
386
  if (callID)
376
387
  memoryListCountByCallID.set(callID, entries.length);
@@ -388,7 +399,7 @@ export const MemoryPlugin = async ({ worktree, directory, client }) => {
388
399
  query: tool.schema.string().describe("Search query — searches across name, description, and content"),
389
400
  },
390
401
  async execute(args, ctx) {
391
- const results = searchMemories(worktree, args.query);
402
+ const results = searchMemories(memoryRoot, args.query);
392
403
  const callID = getCallID(ctx);
393
404
  if (callID)
394
405
  memorySearchCountByCallID.set(callID, results.length);
@@ -405,7 +416,7 @@ export const MemoryPlugin = async ({ worktree, directory, client }) => {
405
416
  file_name: tool.schema.string().describe("File name of the memory to read (with or without .md extension)"),
406
417
  },
407
418
  async execute(args, _ctx) {
408
- const entry = readMemory(worktree, args.file_name);
419
+ const entry = readMemory(memoryRoot, args.file_name);
409
420
  if (!entry) {
410
421
  return `Memory "${args.file_name}" not found.`;
411
422
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-claude-memory",
3
- "version": "1.7.0",
3
+ "version": "1.7.1",
4
4
  "type": "module",
5
5
  "description": "Claude Code-compatible memory compatibility layer for OpenCode — zero config, local-first, no migration",
6
6
  "main": "dist/index.js",