@@ -2,10 +2,7 @@ import type { Plugin, PluginInput } from "@opencode-ai/plugin";
22import type { Part } from "@opencode-ai/sdk" ;
33import { tool } from "@opencode-ai/plugin" ;
44
5- import {
6- PROJECT_ENTITY_CONTEXT ,
7- USER_ENTITY_CONTEXT ,
8- } from "./services/entity-context.js" ;
5+ import { AGENT_ENTITY_CONTEXT } from "./services/entity-context.js" ;
96import { supermemoryClient } from "./services/client.js" ;
107import { formatContextForPrompt } from "./services/context.js" ;
118import { getTags } from "./services/tags.js" ;
@@ -27,7 +24,7 @@ The user wants you to remember something. You MUST use the \`supermemory\` tool
2724
2825Extract the key information the user wants remembered and save it as a concise, searchable memory.
2926- Use \`scope: "project"\` for project-specific preferences (e.g., "run lint with tests")
30- - Use \`scope: "user"\` for cross-project preferences (e.g., "prefers concise responses")
27+ - Use \`scope: "user"\` for personal preferences in this project (e.g., "prefers concise responses")
3128- Choose an appropriate \`type\`: "preference", "project-config", "learned-pattern", etc.
3229
3330DO NOT skip this step. The user explicitly asked you to remember.` ;
@@ -146,9 +143,24 @@ export const SupermemoryPlugin: Plugin = async (ctx: PluginInput) => {
146143
147144 if ( CONFIG . autoRecallEveryPrompt ) {
148145 const [ profileResult , userMemoriesResult , projectMemoriesListResult ] = await Promise . all ( [
149- supermemoryClient . getProfile ( tags . user , userMessage ) ,
150- supermemoryClient . searchMemories ( userMessage , tags . user ) ,
151- supermemoryClient . listMemories ( tags . project , CONFIG . maxProjectMemories ) ,
146+ supermemoryClient . getProfileScoped (
147+ tags . canonical ,
148+ tags . personalReads ,
149+ "personal" ,
150+ userMessage ,
151+ ) ,
152+ supermemoryClient . searchMemoriesScoped (
153+ userMessage ,
154+ tags . canonical ,
155+ tags . personalReads ,
156+ "personal" ,
157+ ) ,
158+ supermemoryClient . listMemoriesScoped (
159+ tags . canonical ,
160+ tags . projectReads ,
161+ "project" ,
162+ CONFIG . maxProjectMemories ,
163+ ) ,
152164 ] ) ;
153165
154166 const profile = profileResult . success ? profileResult : null ;
@@ -173,7 +185,11 @@ export const SupermemoryPlugin: Plugin = async (ctx: PluginInput) => {
173185 projectMemories
174186 ) ;
175187 } else {
176- const profileResult = await supermemoryClient . getProfile ( tags . user ) ;
188+ const profileResult = await supermemoryClient . getProfileScoped (
189+ tags . canonical ,
190+ tags . personalReads ,
191+ "personal" ,
192+ ) ;
177193 const profile = profileResult . success ? profileResult : null ;
178194 memoryContext = formatContextForPrompt ( profile , { results : [ ] } , { results : [ ] } ) ;
179195 }
@@ -283,7 +299,7 @@ export const SupermemoryPlugin: Plugin = async (ctx: PluginInput) => {
283299 } ,
284300 ] ,
285301 scopes : {
286- user : "Cross-project preferences and knowledge" ,
302+ user : "Personal preferences and knowledge for this project " ,
287303 project : "Project-specific knowledge (default)" ,
288304 } ,
289305 types : [
@@ -314,16 +330,20 @@ export const SupermemoryPlugin: Plugin = async (ctx: PluginInput) => {
314330 }
315331
316332 const scope = args . scope || "project" ;
317- const containerTag =
318- scope === "user" ? tags . user : tags . project ;
319- const entityContext =
320- scope === "user" ? USER_ENTITY_CONTEXT : PROJECT_ENTITY_CONTEXT ;
333+ const internalScope =
334+ scope === "user" ? "personal" : "project" ;
321335
322336 const result = await supermemoryClient . addMemory (
323337 sanitizedContent ,
324- containerTag ,
325- { type : args . type } ,
326- { entityContext }
338+ tags . canonical ,
339+ {
340+ type : args . type ,
341+ project : tags . projectName ,
342+ sm_project_id : tags . projectId ,
343+ sm_scope : internalScope ,
344+ sm_capture_mode : "tool" ,
345+ } ,
346+ { entityContext : AGENT_ENTITY_CONTEXT }
327347 ) ;
328348
329349 if ( ! result . success ) {
@@ -353,9 +373,11 @@ export const SupermemoryPlugin: Plugin = async (ctx: PluginInput) => {
353373 const scope = args . scope ;
354374
355375 if ( scope === "user" ) {
356- const result = await supermemoryClient . searchMemories (
376+ const result = await supermemoryClient . searchMemoriesScoped (
357377 args . query ,
358- tags . user
378+ tags . canonical ,
379+ tags . personalReads ,
380+ "personal" ,
359381 ) ;
360382 if ( ! result . success ) {
361383 return JSON . stringify ( {
@@ -367,9 +389,11 @@ export const SupermemoryPlugin: Plugin = async (ctx: PluginInput) => {
367389 }
368390
369391 if ( scope === "project" ) {
370- const result = await supermemoryClient . searchMemories (
392+ const result = await supermemoryClient . searchMemoriesScoped (
371393 args . query ,
372- tags . project
394+ tags . canonical ,
395+ tags . projectReads ,
396+ "project" ,
373397 ) ;
374398 if ( ! result . success ) {
375399 return JSON . stringify ( {
@@ -380,46 +404,30 @@ export const SupermemoryPlugin: Plugin = async (ctx: PluginInput) => {
380404 return formatSearchResults ( args . query , scope , result , args . limit ) ;
381405 }
382406
383- const [ userResult , projectResult ] = await Promise . all ( [
384- supermemoryClient . searchMemories ( args . query , tags . user ) ,
385- supermemoryClient . searchMemories ( args . query , tags . project ) ,
386- ] ) ;
387-
388- if ( ! userResult . success || ! projectResult . success ) {
407+ const result = await supermemoryClient . searchMemoriesMany (
408+ args . query ,
409+ tags . allReads ,
410+ ) ;
411+ if ( ! result . success ) {
389412 return JSON . stringify ( {
390413 success : false ,
391- error : userResult . error || projectResult . error || "Failed to search memories" ,
414+ error : result . error || "Failed to search memories" ,
392415 } ) ;
393416 }
394-
395- const combined = [
396- ...( userResult . results || [ ] ) . map ( ( r ) => ( {
397- ...r ,
398- scope : "user" as const ,
399- } ) ) ,
400- ...( projectResult . results || [ ] ) . map ( ( r ) => ( {
401- ...r ,
402- scope : "project" as const ,
403- } ) ) ,
404- ] . sort ( ( a , b ) => ( b . similarity ?? 0 ) - ( a . similarity ?? 0 ) ) ;
405-
406- return JSON . stringify ( {
407- success : true ,
408- query : args . query ,
409- count : combined . length ,
410- results : combined . slice ( 0 , args . limit || 10 ) . map ( ( r ) => ( {
411- id : r . id ,
412- content : r . memory || r . chunk ,
413- similarity : Math . round ( ( r . similarity ?? 0 ) * 100 ) ,
414- scope : r . scope ,
415- } ) ) ,
416- } ) ;
417+ return formatSearchResults (
418+ args . query ,
419+ undefined ,
420+ result ,
421+ args . limit ,
422+ ) ;
417423 }
418424
419425 case "profile" : {
420- const result = await supermemoryClient . getProfile (
421- tags . user ,
422- args . query
426+ const result = await supermemoryClient . getProfileScoped (
427+ tags . canonical ,
428+ tags . personalReads ,
429+ "personal" ,
430+ args . query ,
423431 ) ;
424432
425433 if ( ! result . success ) {
@@ -441,12 +449,16 @@ export const SupermemoryPlugin: Plugin = async (ctx: PluginInput) => {
441449 case "list" : {
442450 const scope = args . scope || "project" ;
443451 const limit = args . limit || 20 ;
444- const containerTag =
445- scope === "user" ? tags . user : tags . project ;
446-
447- const result = await supermemoryClient . listMemories (
448- containerTag ,
449- limit
452+ const internalScope =
453+ scope === "user" ? "personal" : "project" ;
454+ const readTags =
455+ scope === "user" ? tags . personalReads : tags . projectReads ;
456+
457+ const result = await supermemoryClient . listMemoriesScoped (
458+ tags . canonical ,
459+ readTags ,
460+ internalScope ,
461+ limit ,
450462 ) ;
451463
452464 if ( ! result . success ) {
@@ -524,7 +536,7 @@ export const SupermemoryPlugin: Plugin = async (ctx: PluginInput) => {
524536function formatSearchResults (
525537 query : string ,
526538 scope : string | undefined ,
527- results : { results ?: Array < { id : string ; memory ?: string ; chunk ?: string ; similarity ?: number } > } ,
539+ results : { results ?: Array < { id ? : string ; memory ?: string ; chunk ?: string ; similarity ?: number } > } ,
528540 limit ?: number
529541) : string {
530542 const memoryResults = results . results || [ ] ;
0 commit comments