nomi-opencode 2.0.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.
- package/LICENSE +21 -0
- package/README.md +140 -0
- package/README.zh-CN.md +140 -0
- package/dist/cli/install.d.ts +3 -0
- package/dist/cli/install.d.ts.map +1 -0
- package/dist/cli/install.js +296 -0
- package/dist/cli/install.js.map +1 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +9 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/memory/store.d.ts +31 -0
- package/dist/src/memory/store.d.ts.map +1 -0
- package/dist/src/memory/store.js +387 -0
- package/dist/src/memory/store.js.map +1 -0
- package/dist/src/memory/types.d.ts +42 -0
- package/dist/src/memory/types.d.ts.map +1 -0
- package/dist/src/memory/types.js +2 -0
- package/dist/src/memory/types.js.map +1 -0
- package/dist/src/plugins/nomi-memory.d.ts +3 -0
- package/dist/src/plugins/nomi-memory.d.ts.map +1 -0
- package/dist/src/plugins/nomi-memory.js +165 -0
- package/dist/src/plugins/nomi-memory.js.map +1 -0
- package/dist/src/tools/recall.d.ts +22 -0
- package/dist/src/tools/recall.d.ts.map +1 -0
- package/dist/src/tools/recall.js +33 -0
- package/dist/src/tools/recall.js.map +1 -0
- package/dist/src/tools/remember.d.ts +28 -0
- package/dist/src/tools/remember.d.ts.map +1 -0
- package/dist/src/tools/remember.js +38 -0
- package/dist/src/tools/remember.js.map +1 -0
- package/package.json +64 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { formatMemoriesForInjection, projectFromDirectory, rememberMemory, selectMemoriesForInjection } from '../memory/store.js';
|
|
2
|
+
import { recall } from '../tools/recall.js';
|
|
3
|
+
import { remember } from '../tools/remember.js';
|
|
4
|
+
const sessionBlocks = new Map();
|
|
5
|
+
const capturedMessagesBySession = new Map();
|
|
6
|
+
const explicitCaptureMatchers = [
|
|
7
|
+
/^\s*(?:顺便|另外|还有|对了)?\s*(?:帮我|请)?记住(?:这个)?[::,,\s-]*(.+)$/u,
|
|
8
|
+
/^\s*(?:顺便|另外|还有|对了)?\s*记一下(?:这个)?[::,,\s-]*(.+)$/u,
|
|
9
|
+
/^\s*(?:顺便|另外|还有|对了)?\s*别忘了[::,,\s-]*(.+)$/u,
|
|
10
|
+
/^\s*(?:顺便|另外|还有|对了)?\s*以后都这样[::,,\s-]*(.+)$/u,
|
|
11
|
+
/^\s*(?:also\s+)?please remember[,:\s-]*(.+)$/iu,
|
|
12
|
+
/^\s*(?:also\s+)?remember this[,:\s-]*(.+)$/iu,
|
|
13
|
+
/^\s*(?:also\s+)?keep this in mind[,:\s-]*(.+)$/iu,
|
|
14
|
+
];
|
|
15
|
+
function normalizeWhitespace(value) {
|
|
16
|
+
return value.replace(/\s+/gu, ' ').trim();
|
|
17
|
+
}
|
|
18
|
+
function extractMessageText(parts) {
|
|
19
|
+
return normalizeWhitespace(parts
|
|
20
|
+
.filter((part) => part.type === 'text' && typeof part.text === 'string' && !part.synthetic && !part.ignored)
|
|
21
|
+
.map((part) => part.text)
|
|
22
|
+
.join('\n'));
|
|
23
|
+
}
|
|
24
|
+
function inferMemoryCategory(content) {
|
|
25
|
+
const haystack = content.toLowerCase();
|
|
26
|
+
if (/决定|定为|统一|采用|选用|技术选型|方案|decision|decide|adopt|choose/u.test(haystack)) {
|
|
27
|
+
return 'decision';
|
|
28
|
+
}
|
|
29
|
+
if (/流程|步骤|模式|写法|结构|模板|按这个方式|按这个流程|pattern|workflow|template|structure/u.test(haystack)) {
|
|
30
|
+
return 'pattern';
|
|
31
|
+
}
|
|
32
|
+
if (/不要|别再|避免|注意|教训|坑|报错|失败|lesson|avoid|warning|pitfall|error/u.test(haystack)) {
|
|
33
|
+
return 'lesson';
|
|
34
|
+
}
|
|
35
|
+
if (/默认|偏好|风格|语气|格式|简洁|简短|总是|优先|回答时|default|prefer|always|tone|format/u.test(haystack)) {
|
|
36
|
+
return 'preference';
|
|
37
|
+
}
|
|
38
|
+
return 'context';
|
|
39
|
+
}
|
|
40
|
+
function shouldScopeMemoryToProject(content, category, project) {
|
|
41
|
+
if (!project) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
if (/这个项目|当前项目|本项目|项目里|项目内|for this project|in this project|this project/iu.test(content)) {
|
|
45
|
+
return project;
|
|
46
|
+
}
|
|
47
|
+
if (/全局|通用|所有项目|跨项目|global|generally|across projects|for every project/iu.test(content)) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
if (category === 'preference') {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
if (/dto|schema|commit|repo|repository|module|service|api|migration|lint|build|测试|接口|模块|服务|提交信息|代码风格|数据库|脚本|工作流/u.test(content)) {
|
|
54
|
+
return project;
|
|
55
|
+
}
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
function extractAutoMemory(text, project) {
|
|
59
|
+
const normalized = normalizeWhitespace(text);
|
|
60
|
+
if (!normalized) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
for (const matcher of explicitCaptureMatchers) {
|
|
64
|
+
const matched = normalized.match(matcher);
|
|
65
|
+
const captured = normalizeWhitespace(matched?.[1] ?? '');
|
|
66
|
+
if (captured) {
|
|
67
|
+
const category = inferMemoryCategory(captured);
|
|
68
|
+
return {
|
|
69
|
+
category,
|
|
70
|
+
content: captured,
|
|
71
|
+
project: shouldScopeMemoryToProject(captured, category, project),
|
|
72
|
+
source: 'auto',
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
function hasCapturedMessage(sessionID, messageID) {
|
|
79
|
+
const captured = capturedMessagesBySession.get(sessionID);
|
|
80
|
+
return captured?.has(messageID) ?? false;
|
|
81
|
+
}
|
|
82
|
+
function markCapturedMessage(sessionID, messageID) {
|
|
83
|
+
const captured = capturedMessagesBySession.get(sessionID);
|
|
84
|
+
const next = captured ?? new Set();
|
|
85
|
+
next.add(messageID);
|
|
86
|
+
capturedMessagesBySession.set(sessionID, next);
|
|
87
|
+
}
|
|
88
|
+
function isMemorySystemBlock(value) {
|
|
89
|
+
return value.startsWith('Nomi long-term memory:') || value === 'Nomi memory: no stored memories matched this context.';
|
|
90
|
+
}
|
|
91
|
+
async function buildInjectionBlock(directory, prioritized = []) {
|
|
92
|
+
const prioritizedIds = new Set(prioritized.map((memory) => memory.id));
|
|
93
|
+
const memories = await selectMemoriesForInjection({ directory, limit: Math.max(15 - prioritized.length, 1) }, process.env.NOMI_MEMORY_PATH);
|
|
94
|
+
const ordered = [...prioritized, ...memories.filter((memory) => !prioritizedIds.has(memory.id))].slice(0, 15);
|
|
95
|
+
return formatMemoriesForInjection(ordered);
|
|
96
|
+
}
|
|
97
|
+
export const NomiMemoryPlugin = async ({ directory }) => {
|
|
98
|
+
const project = projectFromDirectory(directory);
|
|
99
|
+
return {
|
|
100
|
+
tool: {
|
|
101
|
+
remember,
|
|
102
|
+
recall,
|
|
103
|
+
},
|
|
104
|
+
event: async ({ event }) => {
|
|
105
|
+
if (event.type === 'session.created') {
|
|
106
|
+
const sessionID = event.properties.info.id;
|
|
107
|
+
capturedMessagesBySession.set(sessionID, new Set());
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (event.type === 'session.deleted') {
|
|
111
|
+
const sessionID = event.properties.info.id;
|
|
112
|
+
sessionBlocks.delete(sessionID);
|
|
113
|
+
capturedMessagesBySession.delete(sessionID);
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
'chat.message': async (_input, output) => {
|
|
117
|
+
if (output.message.role !== 'user') {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const messageID = output.message.id;
|
|
121
|
+
const sessionID = output.message.sessionID;
|
|
122
|
+
if (hasCapturedMessage(sessionID, messageID)) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const text = extractMessageText(output.parts);
|
|
126
|
+
const memory = extractAutoMemory(text, project);
|
|
127
|
+
if (!memory) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
const result = await rememberMemory(memory, process.env.NOMI_MEMORY_PATH);
|
|
132
|
+
markCapturedMessage(sessionID, messageID);
|
|
133
|
+
sessionBlocks.set(sessionID, await buildInjectionBlock(directory, [result.memory]));
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
console.error('Nomi auto-capture failed.', {
|
|
137
|
+
error,
|
|
138
|
+
messageID,
|
|
139
|
+
sessionID,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
'experimental.chat.system.transform': async (input, output) => {
|
|
144
|
+
if (!input.sessionID) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (output.system.some(isMemorySystemBlock)) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const block = sessionBlocks.get(input.sessionID) ?? (await buildInjectionBlock(directory));
|
|
151
|
+
output.system.splice(Math.min(1, output.system.length), 0, block);
|
|
152
|
+
if (sessionBlocks.has(input.sessionID)) {
|
|
153
|
+
sessionBlocks.delete(input.sessionID);
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
'experimental.session.compacting': async (_input, output) => {
|
|
157
|
+
const project = projectFromDirectory(directory);
|
|
158
|
+
const memories = await selectMemoriesForInjection({ directory, limit: 15 }, process.env.NOMI_MEMORY_PATH);
|
|
159
|
+
const block = formatMemoriesForInjection(memories);
|
|
160
|
+
output.context.push(project ? `Current project: ${project}` : 'Current project: 通用');
|
|
161
|
+
output.context.push(block);
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
//# sourceMappingURL=nomi-memory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nomi-memory.js","sourceRoot":"","sources":["../../../src/plugins/nomi-memory.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,0BA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,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAA;YAEjE,IAAI,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;gBACvC,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;YACvC,CAAC;QACH,CAAC;QACD,iCAAiC,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;YAC1D,MAAM,OAAO,GAAG,oBAAoB,CAAC,SAAS,CAAC,CAAA;YAC/C,MAAM,QAAQ,GAAG,MAAM,0BAA0B,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAA;YACzG,MAAM,KAAK,GAAG,0BAA0B,CAAC,QAAQ,CAAC,CAAA;YAClD,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,oBAAoB,OAAO,EAAE,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAA;YACpF,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QAC5B,CAAC;KACF,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare const recall: {
|
|
2
|
+
description: string;
|
|
3
|
+
args: {
|
|
4
|
+
query: import("zod").ZodOptional<import("zod").ZodString>;
|
|
5
|
+
category: import("zod").ZodOptional<import("zod").ZodEnum<{
|
|
6
|
+
preference: "preference";
|
|
7
|
+
decision: "decision";
|
|
8
|
+
pattern: "pattern";
|
|
9
|
+
lesson: "lesson";
|
|
10
|
+
context: "context";
|
|
11
|
+
}>>;
|
|
12
|
+
project: import("zod").ZodOptional<import("zod").ZodString>;
|
|
13
|
+
limit: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
14
|
+
};
|
|
15
|
+
execute(args: {
|
|
16
|
+
query?: string | undefined;
|
|
17
|
+
category?: "preference" | "decision" | "pattern" | "lesson" | "context" | undefined;
|
|
18
|
+
project?: string | undefined;
|
|
19
|
+
limit?: number | undefined;
|
|
20
|
+
}, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=recall.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recall.d.ts","sourceRoot":"","sources":["../../../src/tools/recall.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;CAkCjB,CAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { tool } from '@opencode-ai/plugin';
|
|
2
|
+
import { formatMemoriesForInjection, recallMemories } from '../memory/store.js';
|
|
3
|
+
export const recall = tool({
|
|
4
|
+
description: 'Search Nomi long-term memory for relevant preferences, decisions, patterns, lessons, or context.',
|
|
5
|
+
args: {
|
|
6
|
+
query: tool.schema.string().optional().describe('Search query for memory content, tags, or project.'),
|
|
7
|
+
category: tool.schema.enum(['preference', 'decision', 'pattern', 'lesson', 'context']).optional(),
|
|
8
|
+
project: tool.schema.string().optional().describe('Project name to filter by. Omit for all projects.'),
|
|
9
|
+
limit: tool.schema.number().int().min(1).max(50).optional(),
|
|
10
|
+
},
|
|
11
|
+
async execute(args, context) {
|
|
12
|
+
const memories = await recallMemories({
|
|
13
|
+
query: args.query,
|
|
14
|
+
category: args.category,
|
|
15
|
+
project: args.project,
|
|
16
|
+
limit: args.limit,
|
|
17
|
+
}, process.env.NOMI_MEMORY_PATH);
|
|
18
|
+
context.metadata({
|
|
19
|
+
title: memories.length > 0 ? `Recalled ${memories.length} memories` : 'No memories found',
|
|
20
|
+
metadata: {
|
|
21
|
+
count: memories.length,
|
|
22
|
+
project: args.project ?? 'all',
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
return {
|
|
26
|
+
output: formatMemoriesForInjection(memories),
|
|
27
|
+
metadata: {
|
|
28
|
+
memories,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
//# sourceMappingURL=recall.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recall.js","sourceRoot":"","sources":["../../../src/tools/recall.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAA;AAE1C,OAAO,EAAE,0BAA0B,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAE/E,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,CAAC;IACzB,WAAW,EAAE,kGAAkG;IAC/G,IAAI,EAAE;QACJ,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,oDAAoD,CAAC;QACrG,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,QAAQ,EAAE;QACjG,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,mDAAmD,CAAC;QACtG,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,QAAQ,EAAE;KAC5D;IACD,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO;QACzB,MAAM,QAAQ,GAAG,MAAM,cAAc,CACnC;YACE,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,KAAK,EAAE,IAAI,CAAC,KAAK;SAClB,EACD,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAC7B,CAAA;QAED,OAAO,CAAC,QAAQ,CAAC;YACf,KAAK,EAAE,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,QAAQ,CAAC,MAAM,WAAW,CAAC,CAAC,CAAC,mBAAmB;YACzF,QAAQ,EAAE;gBACR,KAAK,EAAE,QAAQ,CAAC,MAAM;gBACtB,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI,KAAK;aAC/B;SACF,CAAC,CAAA;QAEF,OAAO;YACL,MAAM,EAAE,0BAA0B,CAAC,QAAQ,CAAC;YAC5C,QAAQ,EAAE;gBACR,QAAQ;aACT;SACF,CAAA;IACH,CAAC;CACF,CAAC,CAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare const remember: {
|
|
2
|
+
description: string;
|
|
3
|
+
args: {
|
|
4
|
+
category: import("zod").ZodEnum<{
|
|
5
|
+
preference: "preference";
|
|
6
|
+
decision: "decision";
|
|
7
|
+
pattern: "pattern";
|
|
8
|
+
lesson: "lesson";
|
|
9
|
+
context: "context";
|
|
10
|
+
}>;
|
|
11
|
+
content: import("zod").ZodString;
|
|
12
|
+
tags: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
|
|
13
|
+
project: import("zod").ZodOptional<import("zod").ZodString>;
|
|
14
|
+
source: import("zod").ZodOptional<import("zod").ZodEnum<{
|
|
15
|
+
user: "user";
|
|
16
|
+
auto: "auto";
|
|
17
|
+
agent: "agent";
|
|
18
|
+
}>>;
|
|
19
|
+
};
|
|
20
|
+
execute(args: {
|
|
21
|
+
category: "preference" | "decision" | "pattern" | "lesson" | "context";
|
|
22
|
+
content: string;
|
|
23
|
+
tags?: string[] | undefined;
|
|
24
|
+
project?: string | undefined;
|
|
25
|
+
source?: "user" | "auto" | "agent" | undefined;
|
|
26
|
+
}, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=remember.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remember.d.ts","sourceRoot":"","sources":["../../../src/tools/remember.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;CAuCnB,CAAA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { tool } from '@opencode-ai/plugin';
|
|
2
|
+
import { rememberMemory } from '../memory/store.js';
|
|
3
|
+
export const remember = tool({
|
|
4
|
+
description: 'Save a long-term memory into Nomi memory storage.',
|
|
5
|
+
args: {
|
|
6
|
+
category: tool.schema.enum(['preference', 'decision', 'pattern', 'lesson', 'context']),
|
|
7
|
+
content: tool.schema.string().min(1).describe('Memory content to preserve.'),
|
|
8
|
+
tags: tool.schema.array(tool.schema.string()).optional().describe('Optional search tags.'),
|
|
9
|
+
project: tool.schema.string().optional().describe('Optional project name. Omit for global memory.'),
|
|
10
|
+
source: tool.schema.enum(['user', 'auto', 'agent']).optional(),
|
|
11
|
+
},
|
|
12
|
+
async execute(args, context) {
|
|
13
|
+
const result = await rememberMemory({
|
|
14
|
+
...args,
|
|
15
|
+
project: args.project,
|
|
16
|
+
source: args.source,
|
|
17
|
+
}, process.env.NOMI_MEMORY_PATH);
|
|
18
|
+
context.metadata({
|
|
19
|
+
title: result.deduped ? 'Updated memory' : 'Saved memory',
|
|
20
|
+
metadata: {
|
|
21
|
+
id: result.memory.id,
|
|
22
|
+
category: result.memory.category,
|
|
23
|
+
project: result.memory.project ?? '通用',
|
|
24
|
+
deduped: result.deduped,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
return {
|
|
28
|
+
output: result.deduped
|
|
29
|
+
? `Updated existing ${result.memory.category} memory: ${result.memory.content}`
|
|
30
|
+
: `Saved new ${result.memory.category} memory: ${result.memory.content}`,
|
|
31
|
+
metadata: {
|
|
32
|
+
memory: result.memory,
|
|
33
|
+
deduped: result.deduped,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CAAC,gBAAgB,CAC7B,CAAA;QAED,OAAO,CAAC,QAAQ,CAAC;YACf,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,cAAc;YACzD,QAAQ,EAAE;gBACR,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE;gBACpB,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ;gBAChC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,IAAI,IAAI;gBACtC,OAAO,EAAE,MAAM,CAAC,OAAO;aACxB;SACF,CAAC,CAAA;QAEF,OAAO;YACL,MAAM,EAAE,MAAM,CAAC,OAAO;gBACpB,CAAC,CAAC,oBAAoB,MAAM,CAAC,MAAM,CAAC,QAAQ,YAAY,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE;gBAC/E,CAAC,CAAC,aAAa,MAAM,CAAC,MAAM,CAAC,QAAQ,YAAY,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE;YAC1E,QAAQ,EAAE;gBACR,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,OAAO,EAAE,MAAM,CAAC,OAAO;aACxB;SACF,CAAA;IACH,CAAC;CACF,CAAC,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nomi-opencode",
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"description": "Long-term memory plugin for OpenCode AI editor — remember preferences, decisions, patterns and lessons across sessions.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/src/index.js",
|
|
7
|
+
"types": "dist/src/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/src/index.d.ts",
|
|
11
|
+
"import": "./dist/src/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"bin": {
|
|
15
|
+
"nomi-opencode": "dist/cli/install.js"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"LICENSE",
|
|
20
|
+
"README.md",
|
|
21
|
+
"README.zh-CN.md"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"check": "tsc -p tsconfig.json",
|
|
25
|
+
"build": "tsc -p tsconfig.build.json",
|
|
26
|
+
"prepublishOnly": "npm run build",
|
|
27
|
+
"test": "echo \"No root tests configured\""
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"opencode",
|
|
31
|
+
"memory",
|
|
32
|
+
"ai",
|
|
33
|
+
"plugin",
|
|
34
|
+
"long-term-memory",
|
|
35
|
+
"agent",
|
|
36
|
+
"remember",
|
|
37
|
+
"recall"
|
|
38
|
+
],
|
|
39
|
+
"author": "Nomi Contributors",
|
|
40
|
+
"license": "MIT",
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "git+https://github.com/Zengxiaoer991214/nomi-agent.git"
|
|
44
|
+
},
|
|
45
|
+
"homepage": "https://github.com/Zengxiaoer991214/nomi-agent#readme",
|
|
46
|
+
"bugs": {
|
|
47
|
+
"url": "https://github.com/Zengxiaoer991214/nomi-agent/issues"
|
|
48
|
+
},
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
51
|
+
},
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"@opencode-ai/plugin": ">=1.14.0"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@opencode-ai/plugin": "^1.14.40",
|
|
57
|
+
"@types/node": "^25.6.0",
|
|
58
|
+
"tsx": "^4.21.0",
|
|
59
|
+
"typescript": "^6.0.3"
|
|
60
|
+
},
|
|
61
|
+
"engines": {
|
|
62
|
+
"node": ">=20"
|
|
63
|
+
}
|
|
64
|
+
}
|