opencode-memory-pro 1.3.0

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.
@@ -0,0 +1,112 @@
1
+ import { tool } from "@opencode-ai/plugin";
2
+ import { deriveProjectScope, buildScopeFilter } from "../scope.js";
3
+ import { generateId } from "../utils.js";
4
+ function unavailableMessage(provider) {
5
+ return `Memory store unavailable (${provider} embedding may be offline). Will retry automatically.`;
6
+ }
7
+ export function createFeedbackTools(state) {
8
+ return {
9
+ memory_feedback_missing: tool({
10
+ description: "Record feedback for memory that should have been stored",
11
+ args: {
12
+ text: tool.schema.string().min(1),
13
+ labels: tool.schema.array(tool.schema.string().min(1)).default([]),
14
+ scope: tool.schema.string().optional(),
15
+ },
16
+ execute: async (args, context) => {
17
+ await state.ensureInitialized();
18
+ if (!state.initialized)
19
+ return unavailableMessage(state.config.embedding.provider);
20
+ const scope = args.scope ?? deriveProjectScope(context.directory || context.worktree);
21
+ await state.store.putEvent({
22
+ id: generateId(),
23
+ type: "feedback",
24
+ feedbackType: "missing",
25
+ scope,
26
+ sessionID: context.sessionID,
27
+ timestamp: Date.now(),
28
+ text: args.text,
29
+ labels: args.labels ?? [],
30
+ metadataJson: JSON.stringify({ source: "memory_feedback_missing" }),
31
+ });
32
+ return "Recorded missing-memory feedback.";
33
+ },
34
+ }),
35
+ memory_feedback_wrong: tool({
36
+ description: "Record feedback for memory that should not be stored",
37
+ args: {
38
+ id: tool.schema.string().min(8),
39
+ reason: tool.schema.string().optional(),
40
+ scope: tool.schema.string().optional(),
41
+ },
42
+ execute: async (args, context) => {
43
+ await state.ensureInitialized();
44
+ if (!state.initialized)
45
+ return unavailableMessage(state.config.embedding.provider);
46
+ const scope = args.scope ?? deriveProjectScope(context.directory || context.worktree);
47
+ const scopes = buildScopeFilter(scope, state.config.includeGlobalScope);
48
+ const exists = await state.store.hasMemory(args.id, scopes);
49
+ if (!exists) {
50
+ return `Memory ${args.id} not found in current scope.`;
51
+ }
52
+ await state.store.putEvent({
53
+ id: generateId(),
54
+ type: "feedback",
55
+ feedbackType: "wrong",
56
+ scope,
57
+ sessionID: context.sessionID,
58
+ timestamp: Date.now(),
59
+ memoryId: args.id,
60
+ reason: args.reason,
61
+ metadataJson: JSON.stringify({ source: "memory_feedback_wrong" }),
62
+ });
63
+ return `Recorded wrong-memory feedback for ${args.id}.`;
64
+ },
65
+ }),
66
+ memory_feedback_useful: tool({
67
+ description: "Record whether a recalled memory was helpful",
68
+ args: {
69
+ id: tool.schema.string().min(8),
70
+ helpful: tool.schema.boolean(),
71
+ scope: tool.schema.string().optional(),
72
+ },
73
+ execute: async (args, context) => {
74
+ await state.ensureInitialized();
75
+ if (!state.initialized)
76
+ return unavailableMessage(state.config.embedding.provider);
77
+ const scope = args.scope ?? deriveProjectScope(context.directory || context.worktree);
78
+ const scopes = buildScopeFilter(scope, state.config.includeGlobalScope);
79
+ const exists = await state.store.hasMemory(args.id, scopes);
80
+ if (!exists) {
81
+ return `Memory ${args.id} not found in current scope.`;
82
+ }
83
+ await state.store.putEvent({
84
+ id: generateId(),
85
+ type: "feedback",
86
+ feedbackType: "useful",
87
+ scope,
88
+ sessionID: context.sessionID,
89
+ timestamp: Date.now(),
90
+ memoryId: args.id,
91
+ helpful: args.helpful,
92
+ metadataJson: JSON.stringify({ source: "memory_feedback_useful" }),
93
+ });
94
+ return `Recorded recall usefulness feedback for ${args.id}.`;
95
+ },
96
+ }),
97
+ memory_effectiveness: tool({
98
+ description: "Show effectiveness metrics for capture recall and feedback",
99
+ args: {
100
+ scope: tool.schema.string().optional(),
101
+ },
102
+ execute: async (args, context) => {
103
+ await state.ensureInitialized();
104
+ if (!state.initialized)
105
+ return unavailableMessage(state.config.embedding.provider);
106
+ const scope = args.scope ?? deriveProjectScope(context.directory || context.worktree);
107
+ const summary = await state.store.summarizeEvents(scope, state.config.includeGlobalScope);
108
+ return JSON.stringify(summary, null, 2);
109
+ },
110
+ }),
111
+ };
112
+ }
@@ -0,0 +1,3 @@
1
+ export { createMemoryTools, type ToolRuntimeState, type ToolContext } from "./memory.js";
2
+ export { createFeedbackTools } from "./feedback.js";
3
+ export { createEpisodicTools } from "./episodic.js";
@@ -0,0 +1,3 @@
1
+ export { createMemoryTools } from "./memory.js";
2
+ export { createFeedbackTools } from "./feedback.js";
3
+ export { createEpisodicTools } from "./episodic.js";
@@ -0,0 +1,293 @@
1
+ import { type Embedder } from "../embedder.js";
2
+ import type { MemoryStore } from "../store.js";
3
+ import type { MemoryRuntimeConfig, CitationStatus } from "../types.js";
4
+ export interface ToolRuntimeState {
5
+ config: MemoryRuntimeConfig;
6
+ embedder: Embedder;
7
+ store: MemoryStore;
8
+ defaultScope: string;
9
+ initialized: boolean;
10
+ lastRecall: {
11
+ timestamp: number;
12
+ query: string;
13
+ results: {
14
+ memoryId: string;
15
+ score: number;
16
+ factors: {
17
+ relevance: {
18
+ overall: number;
19
+ vectorScore: number;
20
+ bm25Score: number;
21
+ };
22
+ recency: {
23
+ timestamp: number;
24
+ ageHours: number;
25
+ withinHalfLife: boolean;
26
+ decayFactor: number;
27
+ };
28
+ citation?: {
29
+ source: string;
30
+ status: CitationStatus;
31
+ };
32
+ importance: number;
33
+ scope: {
34
+ memoryScope: string;
35
+ matchesCurrentScope: boolean;
36
+ isGlobal: boolean;
37
+ };
38
+ };
39
+ }[];
40
+ } | null;
41
+ consolidationInProgress: Map<string, boolean>;
42
+ ensureInitialized: () => Promise<void>;
43
+ }
44
+ export type ToolContext = {
45
+ worktree: string;
46
+ sessionID: string;
47
+ };
48
+ export declare function createMemoryTools(state: ToolRuntimeState): {
49
+ memory_search: {
50
+ description: string;
51
+ args: {
52
+ query: import("zod").ZodString;
53
+ limit: import("zod").ZodDefault<import("zod").ZodNumber>;
54
+ scope: import("zod").ZodOptional<import("zod").ZodString>;
55
+ };
56
+ execute(args: {
57
+ query: string;
58
+ limit: number;
59
+ scope?: string | undefined;
60
+ }, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
61
+ };
62
+ memory_delete: {
63
+ description: string;
64
+ args: {
65
+ id: import("zod").ZodString;
66
+ scope: import("zod").ZodOptional<import("zod").ZodString>;
67
+ confirm: import("zod").ZodDefault<import("zod").ZodBoolean>;
68
+ };
69
+ execute(args: {
70
+ id: string;
71
+ confirm: boolean;
72
+ scope?: string | undefined;
73
+ }, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
74
+ };
75
+ memory_clear: {
76
+ description: string;
77
+ args: {
78
+ scope: import("zod").ZodString;
79
+ confirm: import("zod").ZodDefault<import("zod").ZodBoolean>;
80
+ };
81
+ execute(args: {
82
+ scope: string;
83
+ confirm: boolean;
84
+ }, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
85
+ };
86
+ memory_stats: {
87
+ description: string;
88
+ args: {
89
+ scope: import("zod").ZodOptional<import("zod").ZodString>;
90
+ };
91
+ execute(args: {
92
+ scope?: string | undefined;
93
+ }, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
94
+ };
95
+ memory_event_cleanup: {
96
+ description: string;
97
+ args: {
98
+ scope: import("zod").ZodOptional<import("zod").ZodString>;
99
+ dryRun: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodBoolean>>;
100
+ archivePath: import("zod").ZodOptional<import("zod").ZodString>;
101
+ };
102
+ execute(args: {
103
+ dryRun: boolean;
104
+ scope?: string | undefined;
105
+ archivePath?: string | undefined;
106
+ }, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
107
+ };
108
+ memory_remember: {
109
+ description: string;
110
+ args: {
111
+ text: import("zod").ZodString;
112
+ category: import("zod").ZodOptional<import("zod").ZodString>;
113
+ scope: import("zod").ZodOptional<import("zod").ZodString>;
114
+ };
115
+ execute(args: {
116
+ text: string;
117
+ category?: string | undefined;
118
+ scope?: string | undefined;
119
+ }, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
120
+ };
121
+ memory_forget: {
122
+ description: string;
123
+ args: {
124
+ id: import("zod").ZodString;
125
+ force: import("zod").ZodDefault<import("zod").ZodBoolean>;
126
+ scope: import("zod").ZodOptional<import("zod").ZodString>;
127
+ };
128
+ execute(args: {
129
+ id: string;
130
+ force: boolean;
131
+ scope?: string | undefined;
132
+ }, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
133
+ };
134
+ memory_citation: {
135
+ description: string;
136
+ args: {
137
+ id: import("zod").ZodString;
138
+ status: import("zod").ZodOptional<import("zod").ZodString>;
139
+ scope: import("zod").ZodOptional<import("zod").ZodString>;
140
+ };
141
+ execute(args: {
142
+ id: string;
143
+ status?: string | undefined;
144
+ scope?: string | undefined;
145
+ }, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
146
+ };
147
+ memory_validate_citation: {
148
+ description: string;
149
+ args: {
150
+ id: import("zod").ZodString;
151
+ scope: import("zod").ZodOptional<import("zod").ZodString>;
152
+ };
153
+ execute(args: {
154
+ id: string;
155
+ scope?: string | undefined;
156
+ }, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
157
+ };
158
+ memory_what_did_you_learn: {
159
+ description: string;
160
+ args: {
161
+ days: import("zod").ZodDefault<import("zod").ZodNumber>;
162
+ scope: import("zod").ZodOptional<import("zod").ZodString>;
163
+ };
164
+ execute(args: {
165
+ days: number;
166
+ scope?: string | undefined;
167
+ }, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
168
+ };
169
+ memory_why: {
170
+ description: string;
171
+ args: {
172
+ id: import("zod").ZodString;
173
+ scope: import("zod").ZodOptional<import("zod").ZodString>;
174
+ };
175
+ execute(args: {
176
+ id: string;
177
+ scope?: string | undefined;
178
+ }, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
179
+ };
180
+ memory_explain_recall: {
181
+ description: string;
182
+ args: {
183
+ scope: import("zod").ZodOptional<import("zod").ZodString>;
184
+ };
185
+ execute(args: {
186
+ scope?: string | undefined;
187
+ }, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
188
+ };
189
+ memory_scope_promote: {
190
+ description: string;
191
+ args: {
192
+ id: import("zod").ZodString;
193
+ confirm: import("zod").ZodDefault<import("zod").ZodBoolean>;
194
+ };
195
+ execute(args: {
196
+ id: string;
197
+ confirm: boolean;
198
+ }, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
199
+ };
200
+ memory_scope_demote: {
201
+ description: string;
202
+ args: {
203
+ id: import("zod").ZodString;
204
+ confirm: import("zod").ZodDefault<import("zod").ZodBoolean>;
205
+ scope: import("zod").ZodOptional<import("zod").ZodString>;
206
+ };
207
+ execute(args: {
208
+ id: string;
209
+ confirm: boolean;
210
+ scope?: string | undefined;
211
+ }, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
212
+ };
213
+ memory_global_list: {
214
+ description: string;
215
+ args: {
216
+ query: import("zod").ZodOptional<import("zod").ZodString>;
217
+ filter: import("zod").ZodOptional<import("zod").ZodString>;
218
+ limit: import("zod").ZodDefault<import("zod").ZodNumber>;
219
+ };
220
+ execute(args: {
221
+ limit: number;
222
+ query?: string | undefined;
223
+ filter?: string | undefined;
224
+ }, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
225
+ };
226
+ memory_consolidate: {
227
+ description: string;
228
+ args: {
229
+ scope: import("zod").ZodOptional<import("zod").ZodString>;
230
+ confirm: import("zod").ZodDefault<import("zod").ZodBoolean>;
231
+ };
232
+ execute(args: {
233
+ confirm: boolean;
234
+ scope?: string | undefined;
235
+ }, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
236
+ };
237
+ memory_consolidate_all: {
238
+ description: string;
239
+ args: {
240
+ confirm: import("zod").ZodDefault<import("zod").ZodBoolean>;
241
+ };
242
+ execute(args: {
243
+ confirm: boolean;
244
+ }, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
245
+ };
246
+ memory_port_plan: {
247
+ description: string;
248
+ args: {
249
+ project: import("zod").ZodOptional<import("zod").ZodString>;
250
+ services: import("zod").ZodArray<import("zod").ZodObject<{
251
+ name: import("zod").ZodString;
252
+ containerPort: import("zod").ZodNumber;
253
+ preferredHostPort: import("zod").ZodOptional<import("zod").ZodNumber>;
254
+ }, import("zod/v4/core").$strip>>;
255
+ rangeStart: import("zod").ZodDefault<import("zod").ZodNumber>;
256
+ rangeEnd: import("zod").ZodDefault<import("zod").ZodNumber>;
257
+ persist: import("zod").ZodDefault<import("zod").ZodBoolean>;
258
+ };
259
+ execute(args: {
260
+ services: {
261
+ name: string;
262
+ containerPort: number;
263
+ preferredHostPort?: number | undefined;
264
+ }[];
265
+ rangeStart: number;
266
+ rangeEnd: number;
267
+ persist: boolean;
268
+ project?: string | undefined;
269
+ }, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
270
+ };
271
+ memory_dashboard: {
272
+ description: string;
273
+ args: {
274
+ days: import("zod").ZodDefault<import("zod").ZodNumber>;
275
+ scope: import("zod").ZodOptional<import("zod").ZodString>;
276
+ };
277
+ execute(args: {
278
+ days: number;
279
+ scope?: string | undefined;
280
+ }, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
281
+ };
282
+ memory_kpi: {
283
+ description: string;
284
+ args: {
285
+ days: import("zod").ZodDefault<import("zod").ZodNumber>;
286
+ scope: import("zod").ZodOptional<import("zod").ZodString>;
287
+ };
288
+ execute(args: {
289
+ days: number;
290
+ scope?: string | undefined;
291
+ }, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
292
+ };
293
+ };