@downcity/plugins 1.0.253 → 1.0.254

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 (67) hide show
  1. package/bin/memory/Action.d.ts +27 -36
  2. package/bin/memory/Action.d.ts.map +1 -1
  3. package/bin/memory/Action.js +71 -311
  4. package/bin/memory/Action.js.map +1 -1
  5. package/bin/memory/Index.d.ts +3 -1
  6. package/bin/memory/Index.d.ts.map +1 -1
  7. package/bin/memory/Index.js +3 -1
  8. package/bin/memory/Index.js.map +1 -1
  9. package/bin/memory/MemoryPlugin.d.ts +20 -37
  10. package/bin/memory/MemoryPlugin.d.ts.map +1 -1
  11. package/bin/memory/MemoryPlugin.js +231 -233
  12. package/bin/memory/MemoryPlugin.js.map +1 -1
  13. package/bin/memory/adapters/FileMemoryStorageAdapter.d.ts +43 -0
  14. package/bin/memory/adapters/FileMemoryStorageAdapter.d.ts.map +1 -0
  15. package/bin/memory/adapters/FileMemoryStorageAdapter.js +163 -0
  16. package/bin/memory/adapters/FileMemoryStorageAdapter.js.map +1 -0
  17. package/bin/memory/providers/BuiltinMemoryProvider.d.ts +63 -0
  18. package/bin/memory/providers/BuiltinMemoryProvider.d.ts.map +1 -0
  19. package/bin/memory/providers/BuiltinMemoryProvider.js +772 -0
  20. package/bin/memory/providers/BuiltinMemoryProvider.js.map +1 -0
  21. package/bin/memory/runtime/SystemProvider.d.ts +7 -12
  22. package/bin/memory/runtime/SystemProvider.d.ts.map +1 -1
  23. package/bin/memory/runtime/SystemProvider.js +30 -89
  24. package/bin/memory/runtime/SystemProvider.js.map +1 -1
  25. package/bin/memory/types/BuiltinMemoryProvider.d.ts +88 -0
  26. package/bin/memory/types/BuiltinMemoryProvider.d.ts.map +1 -0
  27. package/bin/memory/types/BuiltinMemoryProvider.js +9 -0
  28. package/bin/memory/types/BuiltinMemoryProvider.js.map +1 -0
  29. package/bin/memory/types/Memory.d.ts +249 -408
  30. package/bin/memory/types/Memory.d.ts.map +1 -1
  31. package/bin/memory/types/Memory.js +4 -4
  32. package/bin/memory/types/MemoryStorage.d.ts +35 -0
  33. package/bin/memory/types/MemoryStorage.d.ts.map +1 -0
  34. package/bin/memory/types/MemoryStorage.js +10 -0
  35. package/bin/memory/types/MemoryStorage.js.map +1 -0
  36. package/bin/memory.d.ts +6 -2
  37. package/bin/memory.d.ts.map +1 -1
  38. package/bin/memory.js +3 -1
  39. package/bin/memory.js.map +1 -1
  40. package/package.json +3 -2
  41. package/scripts/memory-plugin.test.mjs +227 -0
  42. package/scripts/plugin-subpaths.test.mjs +8 -0
  43. package/src/memory/Action.ts +106 -377
  44. package/src/memory/Index.ts +6 -1
  45. package/src/memory/MemoryPlugin.ts +254 -246
  46. package/src/memory/adapters/FileMemoryStorageAdapter.ts +197 -0
  47. package/src/memory/providers/BuiltinMemoryProvider.ts +905 -0
  48. package/src/memory/runtime/SystemProvider.ts +32 -95
  49. package/src/memory/types/BuiltinMemoryProvider.ts +121 -0
  50. package/src/memory/types/Memory.ts +322 -456
  51. package/src/memory/types/MemoryStorage.ts +44 -0
  52. package/src/memory.ts +48 -24
  53. package/bin/memory/runtime/Search.d.ts +0 -19
  54. package/bin/memory/runtime/Search.d.ts.map +0 -1
  55. package/bin/memory/runtime/Search.js +0 -262
  56. package/bin/memory/runtime/Search.js.map +0 -1
  57. package/bin/memory/runtime/Store.d.ts +0 -42
  58. package/bin/memory/runtime/Store.d.ts.map +0 -1
  59. package/bin/memory/runtime/Store.js +0 -94
  60. package/bin/memory/runtime/Store.js.map +0 -1
  61. package/bin/memory/runtime/Writer.d.ts +0 -61
  62. package/bin/memory/runtime/Writer.d.ts.map +0 -1
  63. package/bin/memory/runtime/Writer.js +0 -274
  64. package/bin/memory/runtime/Writer.js.map +0 -1
  65. package/src/memory/runtime/Search.ts +0 -327
  66. package/src/memory/runtime/Store.ts +0 -158
  67. package/src/memory/runtime/Writer.ts +0 -351
@@ -1 +1 @@
1
- {"version":3,"file":"MemoryPlugin.d.ts","sourceRoot":"","sources":["../../src/memory/MemoryPlugin.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAW7C,OAAO,EAEL,KAAK,kBAAkB,EACxB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAqD7D;;GAEG;AACH,qBAAa,YAAa,SAAQ,UAAU;IAc9B,OAAO,CAAC,QAAQ,CAAC,OAAO;IAbpC;;OAEG;IACH,QAAQ,CAAC,IAAI,YAAY;IAEzB;;OAEG;IACI,YAAY,EAAE,kBAAkB,GAAG,IAAI,CAAQ;IAEtD;;OAEG;gBAC0B,OAAO,GAAE,mBAAwB;IAI9D;;OAEG;IACG,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC;IAIrD;;OAEG;IACH,QAAQ,CAAC,SAAS;yBACO,aAAa,KAAG,OAAO,CAAC,IAAI,CAAC;oBAIpC,OAAO,CAAC,IAAI,CAAC;MAG7B;IAEF;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,aAAa,CA2R7B;IAEF;;OAEG;IACH,OAAO,CAAC,uBAAuB;CAMhC"}
1
+ {"version":3,"file":"MemoryPlugin.d.ts","sourceRoot":"","sources":["../../src/memory/MemoryPlugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAE,UAAU,EAAiB,MAAM,iBAAiB,CAAC;AAC5D,OAAO,KAAK,EAGV,aAAa,EACb,aAAa,EACd,MAAM,iBAAiB,CAAC;AAYzB,OAAO,KAAK,EACV,mBAAmB,EACnB,cAAc,EAEf,MAAM,0BAA0B,CAAC;AA+DlC,yBAAyB;AACzB,qBAAa,YAAa,SAAQ,UAAU;IAC1C,mBAAmB;IACnB,QAAQ,CAAC,IAAI,YAAY;IAEzB,uCAAuC;IACvC,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;gBAEtB,OAAO,EAAE,mBAAmB;IAQxC,4CAA4C;IACtC,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC;IAIrD,4CAA4C;IAC5C,QAAQ,CAAC,SAAS;yBACO,aAAa,KAAG,OAAO,CAAC,IAAI,CAAC;oBAKpC,OAAO,CAAC,IAAI,CAAC;MAG7B;IAEF,sCAAsC;IACtC,QAAQ,CAAC,OAAO,EAAE,aAAa,CAsS7B;CACH"}
@@ -1,395 +1,393 @@
1
1
  /**
2
- * MemoryPlugin:agent 的长期记忆 plugin
2
+ * MemoryPlugin:Agent 长期记忆的 provider-neutral facade
3
3
  *
4
- * 关键点(中文)
5
- * - 对外仍然是 MemoryPlugin,内部使用 LLM Wiki 方式组织知识。
6
- * - constructor 注入 digest/revise 能力,plugin 不绑定具体 LLM 服务。
7
- * - action 面向 agent 语义,而不是暴露底层文件写入细节。
4
+ * 职责说明(中文)
5
+ * - Agent 暴露稳定的 Memory actions 与 system 使用约束。
6
+ * - Agent/Session 上下文映射为结构化 Memory scope。
7
+ * - 将记忆形成、存储、召回、修订和删除委托给唯一 MemoryProvider。
8
+ *
9
+ * 边界说明(中文)
10
+ * - 不读取或拼接任何物理存储路径。
11
+ * - 不依赖 Workspace FileSystem,也不规定 Markdown、SQLite 或远程服务。
12
+ * - Provider 生命周期跟随当前 Plugin 实例,由 Agent 统一启动和释放。
8
13
  */
9
- import { BasePlugin } from "@downcity/agent";
10
- import { create_action } from "@downcity/agent";
14
+ import { BasePlugin, create_action } from "@downcity/agent";
11
15
  import { z } from "zod";
12
- import { digestMemoryAction, readMemoryAction, rememberMemoryAction, reviseMemoryAction, searchMemoryAction, statusMemoryAction, } from "./Action.js";
13
- import { createMemoryRuntimeState, } from "./runtime/Store.js";
14
- import { buildMemoryPluginSystemText } from "./runtime/SystemProvider.js";
15
- import { ensureMemoryDirectories } from "./runtime/Writer.js";
16
- function parsePositiveInteger(value) {
16
+ import { digest_memory_action, forget_memory_action, read_memory_action, remember_memory_action, revise_memory_action, search_memory_action, status_memory_action, } from "../memory/Action.js";
17
+ import { build_memory_plugin_system_text } from "../memory/runtime/SystemProvider.js";
18
+ const memory_type_schema = z.enum([
19
+ "fact",
20
+ "preference",
21
+ "decision",
22
+ "episode",
23
+ "procedure",
24
+ "document",
25
+ ]);
26
+ /** 解析正整数 CLI 参数。 */
27
+ function parse_positive_integer(value) {
17
28
  const text = String(value || "").trim();
18
- if (!/^\d+$/.test(text)) {
29
+ if (!/^\d+$/u.test(text))
19
30
  throw new Error(`Invalid positive integer: ${value}`);
20
- }
21
- const num = Number(text);
22
- if (!Number.isFinite(num) || num < 1) {
31
+ const number_value = Number(text);
32
+ if (!Number.isFinite(number_value) || number_value < 1) {
23
33
  throw new Error(`Invalid positive integer: ${value}`);
24
34
  }
25
- return num;
35
+ return number_value;
26
36
  }
27
- function parseNumber(value) {
28
- const text = String(value || "").trim();
29
- if (!text) {
30
- throw new Error("number is required");
31
- }
32
- const num = Number(text);
33
- if (!Number.isFinite(num)) {
37
+ /** 解析任意有限数值 CLI 参数。 */
38
+ function parse_number(value) {
39
+ const number_value = Number(String(value || "").trim());
40
+ if (!Number.isFinite(number_value))
34
41
  throw new Error(`Invalid number: ${value}`);
35
- }
36
- return num;
42
+ return number_value;
37
43
  }
38
- function readBodyObject(rawBody) {
39
- if (!rawBody || typeof rawBody !== "object" || Array.isArray(rawBody)) {
40
- return {};
41
- }
42
- return rawBody;
44
+ /** Action JSON 输入归一化为普通对象。 */
45
+ function read_body_object(raw_body) {
46
+ return raw_body && typeof raw_body === "object" && !Array.isArray(raw_body)
47
+ ? raw_body
48
+ : {};
43
49
  }
44
- function readString(body, key) {
45
- const value = body[key];
46
- return typeof value === "string" ? value : "";
50
+ /** 读取必填或可选字符串字段。 */
51
+ function read_string(body, key) {
52
+ return typeof body[key] === "string" ? String(body[key]) : "";
47
53
  }
48
- function readOptionalString(body, key) {
49
- const value = body[key];
50
- return typeof value === "string" ? value : undefined;
54
+ /** 读取可选字符串字段。 */
55
+ function read_optional_string(body, key) {
56
+ const value = read_string(body, key).trim();
57
+ return value || undefined;
51
58
  }
52
- function readOptionalNumber(body, key) {
53
- const value = body[key];
54
- return typeof value === "number" ? value : undefined;
59
+ /** 读取可选数值字段。 */
60
+ function read_optional_number(body, key) {
61
+ return typeof body[key] === "number" ? Number(body[key]) : undefined;
55
62
  }
56
- function readOptionalBoolean(body, key) {
57
- const value = body[key];
58
- return typeof value === "boolean" ? value : undefined;
63
+ /** 读取可选布尔字段。 */
64
+ function read_optional_boolean(body, key) {
65
+ return typeof body[key] === "boolean" ? Boolean(body[key]) : undefined;
59
66
  }
60
- /**
61
- * Memory plugin 类实现。
62
- */
67
+ /** 读取可选 MemoryType 字段。 */
68
+ function read_optional_memory_type(body) {
69
+ const result = memory_type_schema.safeParse(body.memory_type);
70
+ return result.success ? result.data : undefined;
71
+ }
72
+ /** Agent 长期记忆 Plugin。 */
63
73
  export class MemoryPlugin extends BasePlugin {
64
- options;
65
- /**
66
- * plugin 名称。
67
- */
74
+ /** Plugin 稳定名称。 */
68
75
  name = "memory";
69
- /**
70
- * 当前实例持有的 memory plugin state。
71
- */
72
- runtimeState = null;
73
- /**
74
- * 创建 MemoryPlugin。
75
- */
76
- constructor(options = {}) {
76
+ /** 当前 Plugin 唯一绑定的 Memory Provider。 */
77
+ provider;
78
+ constructor(options) {
77
79
  super();
78
- this.options = options;
80
+ if (!options?.provider)
81
+ throw new Error("MemoryPlugin requires provider");
82
+ const provider_name = String(options.provider.name || "").trim();
83
+ if (!provider_name)
84
+ throw new Error("MemoryPlugin provider requires name");
85
+ this.provider = options.provider;
79
86
  }
80
- /**
81
- * 当前 plugin 的 system 文本提供器。
82
- */
87
+ /** 构建 provider-neutral Memory system 内容。 */
83
88
  async system(context) {
84
- return await buildMemoryPluginSystemText(context);
89
+ return await build_memory_plugin_system_text(context, this.provider);
85
90
  }
86
- /**
87
- * 当前 plugin 生命周期。
88
- */
91
+ /** Provider 生命周期与当前 Agent Plugin 实例保持一致。 */
89
92
  lifecycle = {
90
93
  start: async (context) => {
91
- await ensureMemoryDirectories(context.workspace_path);
92
- this.getOrCreateRuntimeState(context);
94
+ await this.provider.initialize({
95
+ agent_id: context.agent_id,
96
+ });
93
97
  },
94
98
  stop: async () => {
95
- this.runtimeState = null;
99
+ await this.provider.dispose();
96
100
  },
97
101
  };
98
- /**
99
- * 当前 plugin action 定义表。
100
- */
102
+ /** Memory 对 Agent 暴露的稳定 Action 集合。 */
101
103
  actions = {
102
104
  status: create_action({
103
- description: "View memory wiki status (wiki/source/working).",
105
+ description: "Inspect the active Memory Provider and its capabilities.",
104
106
  input_schema: {
105
107
  zod: z.object({}).passthrough(),
106
- json_schema: { type: "object", properties: {} },
108
+ json_schema: { type: "object", additionalProperties: false, properties: {} },
107
109
  },
108
- examples: [{ title: "View status", payload: {} }],
110
+ examples: [{ title: "View Memory Provider status", payload: {} }],
109
111
  command: {
110
- description: "View memory wiki status (wiki/source/working).",
111
- map_input() {
112
- return {};
113
- },
114
- },
115
- execute: async (params) => {
116
- const state = this.getOrCreateRuntimeState(params.context);
117
- return await statusMemoryAction(params.context, state);
112
+ description: "Inspect the active Memory Provider.",
113
+ map_input: () => ({}),
118
114
  },
115
+ execute: async () => await status_memory_action(this.provider),
119
116
  }),
120
117
  search: create_action({
121
- description: "Search memory wiki, optionally extending into the source layer.",
118
+ description: "Recall scoped long-term memories for a focused query.",
122
119
  input_schema: {
123
120
  zod: z.object({
124
121
  query: z.string(),
125
- maxResults: z.number().optional(),
126
- minScore: z.number().optional(),
127
- includeSources: z.boolean().optional(),
122
+ max_results: z.number().optional(),
123
+ min_score: z.number().optional(),
124
+ include_evidence: z.boolean().optional(),
128
125
  }),
129
126
  json_schema: {
130
127
  type: "object",
128
+ additionalProperties: false,
131
129
  required: ["query"],
132
130
  properties: {
133
- query: { type: "string", description: "Search query." },
134
- maxResults: { type: "number", description: "Maximum number of results." },
135
- minScore: { type: "number", description: "Minimum relevance score." },
136
- includeSources: { type: "boolean", description: "Whether to include the source layer." },
131
+ query: { type: "string", description: "Focused recall query." },
132
+ max_results: { type: "number", description: "Maximum result count." },
133
+ min_score: { type: "number", minimum: 0, maximum: 1 },
134
+ include_evidence: { type: "boolean", description: "Include raw evidence records." },
137
135
  },
138
136
  },
139
137
  },
140
- examples: [
141
- { title: "Search memory", payload: { query: "user preferences" } },
142
- ],
138
+ examples: [{ title: "Recall preferences", payload: { query: "user preferences" } }],
143
139
  command: {
144
- description: "Search memory wiki.",
140
+ description: "Recall scoped long-term memories.",
145
141
  configure(command) {
146
142
  command
147
143
  .argument("<query>")
148
- .option("--max-results <number>", "Maximum number of results.", parsePositiveInteger)
149
- .option("--min-score <number>", "Minimum relevance score.", parseNumber)
150
- .option("--include-sources", "Also search the raw source layer.");
144
+ .option("--max-results <number>", "Maximum result count.", parse_positive_integer)
145
+ .option("--min-score <number>", "Minimum relevance score.", parse_number)
146
+ .option("--include-evidence", "Include raw evidence records.");
151
147
  },
152
148
  map_input({ args, opts }) {
153
- const payload = {
149
+ return {
154
150
  query: String(args[0] || ""),
151
+ ...(typeof opts.maxResults === "number" ? { max_results: opts.maxResults } : {}),
152
+ ...(typeof opts.minScore === "number" ? { min_score: opts.minScore } : {}),
153
+ ...(opts.includeEvidence === true ? { include_evidence: true } : {}),
155
154
  };
156
- if (typeof opts.maxResults === "number") {
157
- payload.maxResults = opts.maxResults;
158
- }
159
- if (typeof opts.minScore === "number") {
160
- payload.minScore = opts.minScore;
161
- }
162
- if (opts.includeSources === true) {
163
- payload.includeSources = true;
164
- }
165
- return payload;
166
155
  },
167
156
  },
168
- execute: async (params) => {
169
- const body = readBodyObject(params.input);
170
- const state = this.getOrCreateRuntimeState(params.context);
171
- return await searchMemoryAction(params.context, state, {
172
- query: readString(body, "query"),
173
- maxResults: readOptionalNumber(body, "maxResults"),
174
- minScore: readOptionalNumber(body, "minScore"),
175
- includeSources: readOptionalBoolean(body, "includeSources"),
157
+ execute: async ({ context, input }) => {
158
+ const body = read_body_object(input);
159
+ return await search_memory_action(context, this.provider, {
160
+ query: read_string(body, "query"),
161
+ max_results: read_optional_number(body, "max_results"),
162
+ min_score: read_optional_number(body, "min_score"),
163
+ include_evidence: read_optional_boolean(body, "include_evidence"),
176
164
  });
177
165
  },
178
166
  }),
179
167
  read: create_action({
180
- description: "Read a memory wiki/source file excerpt.",
168
+ description: "Read one exact memory by memory_id.",
181
169
  input_schema: {
182
170
  zod: z.object({
183
- path: z.string(),
184
- from: z.number().optional(),
185
- lines: z.number().optional(),
171
+ memory_id: z.string(),
172
+ from_line: z.number().optional(),
173
+ line_count: z.number().optional(),
186
174
  }),
187
175
  json_schema: {
188
176
  type: "object",
189
- required: ["path"],
177
+ additionalProperties: false,
178
+ required: ["memory_id"],
190
179
  properties: {
191
- path: { type: "string", description: "Memory file path relative to the project root." },
192
- from: { type: "number", description: "Starting line, 1-based." },
193
- lines: { type: "number", description: "Number of lines to read." },
180
+ memory_id: { type: "string", description: "Stable logical memory identifier." },
181
+ from_line: { type: "number", minimum: 1 },
182
+ line_count: { type: "number", minimum: 1 },
194
183
  },
195
184
  },
196
185
  },
197
- examples: [
198
- { title: "Read full page", payload: { path: ".downcity/memory/wiki/index.md" } },
199
- ],
186
+ examples: [{ title: "Read a memory", payload: { memory_id: "wiki/user-preferences" } }],
200
187
  command: {
201
- description: "Read a memory wiki/source file excerpt.",
188
+ description: "Read one exact memory.",
202
189
  configure(command) {
203
190
  command
204
- .argument("<memoryPath>", "Memory file path relative to the project root.")
205
- .option("--from <number>", "Starting line, 1-based.", parsePositiveInteger)
206
- .option("--lines <number>", "Number of lines to read.", parsePositiveInteger);
191
+ .argument("<memory_id>")
192
+ .option("--from-line <number>", "Starting line, 1-based.", parse_positive_integer)
193
+ .option("--line-count <number>", "Maximum line count.", parse_positive_integer);
207
194
  },
208
195
  map_input({ args, opts }) {
209
- const payload = {
210
- path: String(args[0] || ""),
196
+ return {
197
+ memory_id: String(args[0] || ""),
198
+ ...(typeof opts.fromLine === "number" ? { from_line: opts.fromLine } : {}),
199
+ ...(typeof opts.lineCount === "number" ? { line_count: opts.lineCount } : {}),
211
200
  };
212
- if (typeof opts.from === "number") {
213
- payload.from = opts.from;
214
- }
215
- if (typeof opts.lines === "number") {
216
- payload.lines = opts.lines;
217
- }
218
- return payload;
219
201
  },
220
202
  },
221
- execute: async (params) => {
222
- const body = readBodyObject(params.input);
223
- return await readMemoryAction(params.context, {
224
- path: readString(body, "path"),
225
- from: readOptionalNumber(body, "from"),
226
- lines: readOptionalNumber(body, "lines"),
203
+ execute: async ({ context, input }) => {
204
+ const body = read_body_object(input);
205
+ return await read_memory_action(context, this.provider, {
206
+ memory_id: read_string(body, "memory_id"),
207
+ from_line: read_optional_number(body, "from_line"),
208
+ line_count: read_optional_number(body, "line_count"),
227
209
  });
228
210
  },
229
211
  }),
230
212
  remember: create_action({
231
- description: "Record facts, preferences, or decisions into memory wiki.",
213
+ description: "Store a durable fact, preference, decision, episode, procedure, or document.",
232
214
  input_schema: {
233
215
  zod: z.object({
234
216
  content: z.string(),
235
217
  topic: z.string().optional(),
236
- path: z.string().optional(),
218
+ memory_type: memory_type_schema.optional(),
237
219
  source: z.string().optional(),
238
220
  }),
239
221
  json_schema: {
240
222
  type: "object",
223
+ additionalProperties: false,
241
224
  required: ["content"],
242
225
  properties: {
243
226
  content: { type: "string", description: "Content to remember." },
244
- topic: { type: "string", description: "Memory topic." },
245
- path: { type: "string", description: "Target wiki page path." },
246
- source: { type: "string", description: "Source note." },
227
+ topic: { type: "string", description: "Optional organization hint." },
228
+ memory_type: {
229
+ type: "string",
230
+ enum: ["fact", "preference", "decision", "episode", "procedure", "document"],
231
+ },
232
+ source: { type: "string", description: "Optional evidence label." },
247
233
  },
248
234
  },
249
235
  },
250
- examples: [
251
- { title: "Remember preference", payload: { content: "User prefers concise answers", topic: "user-prefs" } },
252
- ],
236
+ examples: [{
237
+ title: "Remember a preference",
238
+ payload: {
239
+ content: "User prefers concise answers.",
240
+ topic: "user-preferences",
241
+ memory_type: "preference",
242
+ },
243
+ }],
253
244
  command: {
254
- description: "Record facts, preferences, or decisions into memory wiki.",
245
+ description: "Store a durable memory.",
255
246
  configure(command) {
256
247
  command
257
248
  .requiredOption("--content <text>", "Content to remember.")
258
- .option("--topic <topic>", "Memory topic.")
259
- .option("--wiki-path <path>", "Target wiki page path.")
260
- .option("--source <source>", "Source note.");
249
+ .option("--topic <topic>", "Optional organization hint.")
250
+ .option("--memory-type <type>", "Memory type.")
251
+ .option("--source <source>", "Optional evidence label.");
261
252
  },
262
253
  map_input({ opts }) {
263
- const payload = {
254
+ return {
264
255
  content: String(opts.content || ""),
256
+ ...(typeof opts.topic === "string" ? { topic: opts.topic } : {}),
257
+ ...(typeof opts.memoryType === "string" ? { memory_type: opts.memoryType } : {}),
258
+ ...(typeof opts.source === "string" ? { source: opts.source } : {}),
265
259
  };
266
- if (typeof opts.topic === "string") {
267
- payload.topic = String(opts.topic).trim();
268
- }
269
- if (typeof opts.wikiPath === "string") {
270
- payload.path = String(opts.wikiPath).trim();
271
- }
272
- if (typeof opts.source === "string") {
273
- payload.source = String(opts.source).trim();
274
- }
275
- return payload;
276
260
  },
277
261
  },
278
- execute: async (params) => {
279
- const body = readBodyObject(params.input);
280
- return await rememberMemoryAction(params.context, this.options, {
281
- content: readString(body, "content"),
282
- topic: readOptionalString(body, "topic"),
283
- path: readOptionalString(body, "path"),
284
- source: readOptionalString(body, "source"),
262
+ execute: async ({ context, input }) => {
263
+ const body = read_body_object(input);
264
+ return await remember_memory_action(context, this.provider, {
265
+ content: read_string(body, "content"),
266
+ topic: read_optional_string(body, "topic"),
267
+ memory_type: read_optional_memory_type(body),
268
+ source: read_optional_string(body, "source"),
285
269
  });
286
270
  },
287
271
  }),
288
272
  digest: create_action({
289
- description: "Digest a session into memory wiki.",
273
+ description: "Digest a canonical Session transcript into long-term memory.",
290
274
  input_schema: {
291
275
  zod: z.object({
292
276
  session_id: z.string(),
293
- maxMessages: z.number().optional(),
277
+ max_messages: z.number().optional(),
294
278
  }),
295
279
  json_schema: {
296
280
  type: "object",
281
+ additionalProperties: false,
297
282
  required: ["session_id"],
298
283
  properties: {
299
- session_id: { type: "string", description: "Session ID." },
300
- maxMessages: { type: "number", description: "Message extraction window." },
284
+ session_id: { type: "string" },
285
+ max_messages: { type: "number", minimum: 1 },
301
286
  },
302
287
  },
303
288
  },
304
- examples: [
305
- { title: "Digest session", payload: { session_id: "sess-1" } },
306
- ],
289
+ examples: [{ title: "Digest a Session", payload: { session_id: "sess-1" } }],
307
290
  command: {
308
- description: "Digest a session into memory wiki.",
291
+ description: "Digest a canonical Session transcript.",
309
292
  configure(command) {
310
293
  command
311
- .requiredOption("--session-id <session_id>", "Session ID.")
312
- .option("--max-messages <number>", "Message extraction window.", parsePositiveInteger);
294
+ .requiredOption("--session-id <session_id>", "Session identifier.")
295
+ .option("--max-messages <number>", "Maximum message count.", parse_positive_integer);
313
296
  },
314
297
  map_input({ opts }) {
315
- const payload = {
316
- session_id: String(opts.session_id || ""),
298
+ return {
299
+ session_id: String(opts.sessionId || ""),
300
+ ...(typeof opts.maxMessages === "number" ? { max_messages: opts.maxMessages } : {}),
317
301
  };
318
- if (typeof opts.maxMessages === "number") {
319
- payload.maxMessages = opts.maxMessages;
320
- }
321
- return payload;
322
302
  },
323
303
  },
324
- execute: async (params) => {
325
- const body = readBodyObject(params.input);
326
- return await digestMemoryAction(params.context, this.options, {
327
- session_id: readString(body, "session_id"),
328
- maxMessages: readOptionalNumber(body, "maxMessages"),
304
+ execute: async ({ context, input }) => {
305
+ const body = read_body_object(input);
306
+ return await digest_memory_action(context, this.provider, {
307
+ session_id: read_string(body, "session_id"),
308
+ max_messages: read_optional_number(body, "max_messages"),
329
309
  });
330
310
  },
331
311
  }),
332
312
  revise: create_action({
333
- description: "Revise a memory wiki page based on new evidence.",
313
+ description: "Revise one memory using new evidence.",
334
314
  input_schema: {
335
315
  zod: z.object({
336
- path: z.string(),
316
+ memory_id: z.string(),
337
317
  instruction: z.string(),
338
318
  evidence: z.string().optional(),
339
319
  }),
340
320
  json_schema: {
341
321
  type: "object",
342
- required: ["path", "instruction"],
322
+ additionalProperties: false,
323
+ required: ["memory_id", "instruction"],
343
324
  properties: {
344
- path: { type: "string", description: "Target wiki page path." },
345
- instruction: { type: "string", description: "Revision instruction." },
346
- evidence: { type: "string", description: "New evidence." },
325
+ memory_id: { type: "string" },
326
+ instruction: { type: "string" },
327
+ evidence: { type: "string" },
347
328
  },
348
329
  },
349
330
  },
350
- examples: [
351
- {
352
- title: "Revise entry",
353
- payload: { path: "wiki/preferences.md", instruction: "Replace with latest preference." },
354
- },
355
- ],
331
+ examples: [{
332
+ title: "Revise a preference",
333
+ payload: {
334
+ memory_id: "wiki/user-preferences",
335
+ instruction: "Replace the old preference with the latest one.",
336
+ },
337
+ }],
356
338
  command: {
357
- description: "Revise a memory wiki page based on new evidence.",
339
+ description: "Revise one memory using new evidence.",
358
340
  configure(command) {
359
341
  command
360
- .argument("<memoryPath>", "Target wiki page path.")
342
+ .argument("<memory_id>")
361
343
  .requiredOption("--instruction <text>", "Revision instruction.")
362
344
  .option("--evidence <text>", "New evidence.");
363
345
  },
364
346
  map_input({ args, opts }) {
365
- const payload = {
366
- path: String(args[0] || ""),
347
+ return {
348
+ memory_id: String(args[0] || ""),
367
349
  instruction: String(opts.instruction || ""),
350
+ ...(typeof opts.evidence === "string" ? { evidence: opts.evidence } : {}),
368
351
  };
369
- if (typeof opts.evidence === "string") {
370
- payload.evidence = String(opts.evidence).trim();
371
- }
372
- return payload;
373
352
  },
374
353
  },
375
- execute: async (params) => {
376
- const body = readBodyObject(params.input);
377
- return await reviseMemoryAction(params.context, this.options, {
378
- path: readString(body, "path"),
379
- instruction: readString(body, "instruction"),
380
- evidence: readOptionalString(body, "evidence"),
354
+ execute: async ({ context, input }) => {
355
+ const body = read_body_object(input);
356
+ return await revise_memory_action(context, this.provider, {
357
+ memory_id: read_string(body, "memory_id"),
358
+ instruction: read_string(body, "instruction"),
359
+ evidence: read_optional_string(body, "evidence"),
360
+ });
361
+ },
362
+ }),
363
+ forget: create_action({
364
+ description: "Delete or invalidate one memory by memory_id.",
365
+ input_schema: {
366
+ zod: z.object({ memory_id: z.string() }),
367
+ json_schema: {
368
+ type: "object",
369
+ additionalProperties: false,
370
+ required: ["memory_id"],
371
+ properties: { memory_id: { type: "string" } },
372
+ },
373
+ },
374
+ examples: [{ title: "Forget a memory", payload: { memory_id: "wiki/obsolete" } }],
375
+ command: {
376
+ description: "Delete or invalidate one memory.",
377
+ configure(command) {
378
+ command.argument("<memory_id>");
379
+ },
380
+ map_input({ args }) {
381
+ return { memory_id: String(args[0] || "") };
382
+ },
383
+ },
384
+ execute: async ({ context, input }) => {
385
+ const body = read_body_object(input);
386
+ return await forget_memory_action(context, this.provider, {
387
+ memory_id: read_string(body, "memory_id"),
381
388
  });
382
389
  },
383
390
  }),
384
391
  };
385
- /**
386
- * 获取或创建当前实例绑定的 memory plugin state。
387
- */
388
- getOrCreateRuntimeState(context) {
389
- if (!this.runtimeState) {
390
- this.runtimeState = createMemoryRuntimeState(context);
391
- }
392
- return this.runtimeState;
393
- }
394
392
  }
395
393
  //# sourceMappingURL=MemoryPlugin.js.map