Skip to content

Commit fa537a1

Browse files
authored
feat: configurable keywords (#15)
* feat: configurable keyword detection patterns * readme * validate regex
1 parent 9232b0f commit fa537a1

3 files changed

Lines changed: 41 additions & 3 deletions

File tree

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ You: "Remember that this project uses bun"
145145
Agent: [saves to project memory]
146146
```
147147

148+
Add custom triggers via `keywordPatterns` config.
149+
148150
### Codebase Indexing
149151

150152
Run `/supermemory-init` to explore and memorize your codebase structure, patterns, and conventions.
@@ -214,7 +216,10 @@ Create `~/.config/opencode/supermemory.jsonc`:
214216
"injectProfile": true,
215217

216218
// Prefix for container tags
217-
"containerTagPrefix": "opencode"
219+
"containerTagPrefix": "opencode",
220+
221+
// Extra keyword patterns for memory detection (regex)
222+
"keywordPatterns": ["log\\s+this", "write\\s+down"]
218223
}
219224
```
220225

src/config.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,28 @@ interface SupermemoryConfig {
1818
injectProfile?: boolean;
1919
containerTagPrefix?: string;
2020
filterPrompt?: string;
21+
keywordPatterns?: string[];
2122
}
2223

24+
const DEFAULT_KEYWORD_PATTERNS = [
25+
"remember",
26+
"memorize",
27+
"save\\s+this",
28+
"note\\s+this",
29+
"keep\\s+in\\s+mind",
30+
"don'?t\\s+forget",
31+
"learn\\s+this",
32+
"store\\s+this",
33+
"record\\s+this",
34+
"make\\s+a\\s+note",
35+
"take\\s+note",
36+
"jot\\s+down",
37+
"commit\\s+to\\s+memory",
38+
"remember\\s+that",
39+
"never\\s+forget",
40+
"always\\s+remember",
41+
];
42+
2343
const DEFAULTS: Required<Omit<SupermemoryConfig, "apiKey">> = {
2444
similarityThreshold: 0.6,
2545
maxMemories: 5,
@@ -28,8 +48,18 @@ const DEFAULTS: Required<Omit<SupermemoryConfig, "apiKey">> = {
2848
injectProfile: true,
2949
containerTagPrefix: "opencode",
3050
filterPrompt: "You are a stateful coding agent. Remember all the information, including but not limited to user's coding preferences, tech stack, behaviours, workflows, and any other relevant details.",
51+
keywordPatterns: [],
3152
};
3253

54+
function isValidRegex(pattern: string): boolean {
55+
try {
56+
new RegExp(pattern);
57+
return true;
58+
} catch {
59+
return false;
60+
}
61+
}
62+
3363
function loadConfig(): SupermemoryConfig {
3464
for (const path of CONFIG_FILES) {
3565
if (existsSync(path)) {
@@ -57,6 +87,10 @@ export const CONFIG = {
5787
injectProfile: fileConfig.injectProfile ?? DEFAULTS.injectProfile,
5888
containerTagPrefix: fileConfig.containerTagPrefix ?? DEFAULTS.containerTagPrefix,
5989
filterPrompt: fileConfig.filterPrompt ?? DEFAULTS.filterPrompt,
90+
keywordPatterns: [
91+
...DEFAULT_KEYWORD_PATTERNS,
92+
...(fileConfig.keywordPatterns ?? []).filter(isValidRegex),
93+
],
6094
};
6195

6296
export function isConfigured(): boolean {

src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ import type { MemoryScope, MemoryType } from "./types/index.js";
1515
const CODE_BLOCK_PATTERN = /```[\s\S]*?```/g;
1616
const INLINE_CODE_PATTERN = /`[^`]+`/g;
1717

18-
const MEMORY_KEYWORD_PATTERN =
19-
/\b(remember|memorize|save\s+this|note\s+this|keep\s+in\s+mind|don'?t\s+forget|learn\s+this|store\s+this|record\s+this|make\s+a\s+note|take\s+note|jot\s+down|commit\s+to\s+memory|remember\s+that|never\s+forget|always\s+remember)\b/i;
18+
const MEMORY_KEYWORD_PATTERN = new RegExp(`\\b(${CONFIG.keywordPatterns.join("|")})\\b`, "i");
2019

2120
const MEMORY_NUDGE_MESSAGE = `[MEMORY TRIGGER DETECTED]
2221
The user wants you to remember something. You MUST use the \`supermemory\` tool with \`mode: "add"\` to save this information.

0 commit comments

Comments
 (0)