dsh-memory-core 0.1.1 → 0.1.3
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/CHANGELOG.md +10 -0
- package/index.js +25 -13
- package/lib/schema.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.3
|
|
4
|
+
|
|
5
|
+
- 修复:路由与注入段直接访问 `ctx.agent`。Cordis 的 `ctx.<服务>` 在插件未声明 `inject` 时会抛 `cannot get property "agent" without inject`,被 webserver 兜底成 **400 空体**:`/api/memory-core/status`、`/manage`、`/entries` 全部打不开,`memory-core:snapshot` 注入同时失效,日志里也没有堆栈。改为 `agentOf(ctx)`,只经 `ctx.get(name, false)` 探测(取不到返回 undefined;lite 三轨不依赖 agent)。
|
|
6
|
+
- `_dryrun.mjs`:stub ctx 补 `get(name)`(模拟真实服务读取),并加 8d2 回归断言——`index.js` 里出现 `ctx.agent` 即失败。
|
|
7
|
+
|
|
8
|
+
## 0.1.2
|
|
9
|
+
|
|
10
|
+
- 修复:`lib/schema.js` 用 `z.enum(...)`(zod 的写法,`@deepseek-ai/schemastery` 没有这个方法),包一 import 就抛 `TypeError: z.enum is not a function`。内核 Loader 的 `_init()` 捕获 import 错误后不建 fiber,于是 preset 里这一行只显示「never started」,日志里不落错。改为 `z.union([z.const("lite"), z.const("full")])`。
|
|
11
|
+
- `_dryrun.mjs` 的依赖 stub 从「万能 Proxy」改为严格白名单:只认 schemastery 真实存在的构造器与实例方法,出现 `z.enum` 这类不存在的名字立即抛错。原先的万能 Proxy 把这类错误吞掉了,dryrun 63 项全过、真机却起不来。
|
|
12
|
+
|
|
3
13
|
## 0.1.1
|
|
4
14
|
|
|
5
15
|
- 文案修正:旧名「companion」统一改为 `dsh-memory-core`(README、package.json 的 description 与 keywords、源码注释、日志前缀)。
|
package/index.js
CHANGED
|
@@ -39,6 +39,17 @@ function sameOriginBlocked(req) {
|
|
|
39
39
|
return "";
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
/** 取当前会话的 agent。Cordis 的 ctx.<服务> 在未声明 inject 时会抛错,所以走 ctx.get(name, false) 探测;取不到返回 undefined。 */
|
|
43
|
+
function agentOf(ctx) {
|
|
44
|
+
for (const name of ["agent", "agents"]) {
|
|
45
|
+
try {
|
|
46
|
+
const a = ctx.get?.(name, false);
|
|
47
|
+
if (a?.session) return a;
|
|
48
|
+
} catch {}
|
|
49
|
+
}
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
|
|
42
53
|
function apply(ctx, config) {
|
|
43
54
|
const s = { ...DEFAULTS, ...(config ?? {}) };
|
|
44
55
|
const memoryDir = resolveMemoryDir(s);
|
|
@@ -138,7 +149,7 @@ function apply(ctx, config) {
|
|
|
138
149
|
ctx.systemPrompt.context({
|
|
139
150
|
name: "memory-core:snapshot",
|
|
140
151
|
order: s.snapshotOrder,
|
|
141
|
-
text: () => renderSnapshot(store, s, writeGap, { agent: ctx
|
|
152
|
+
text: () => renderSnapshot(store, s, writeGap, { agent: agentOf(ctx) }),
|
|
142
153
|
}),
|
|
143
154
|
`${name}: memory-core:snapshot inject`,
|
|
144
155
|
);
|
|
@@ -160,7 +171,8 @@ function apply(ctx, config) {
|
|
|
160
171
|
json(403, { ok: false, why: denied });
|
|
161
172
|
return;
|
|
162
173
|
}
|
|
163
|
-
|
|
174
|
+
const agent = agentOf(ctx);
|
|
175
|
+
const cwd = agent?.session?.header?.cwd;
|
|
164
176
|
|
|
165
177
|
// GET /manage —— 返回 manage.html 页面
|
|
166
178
|
if (req.method === "GET" && url.pathname === "/api/memory-core/manage") {
|
|
@@ -194,7 +206,7 @@ function apply(ctx, config) {
|
|
|
194
206
|
if (req.method === "GET" && url.pathname === "/api/memory-core/entries") {
|
|
195
207
|
const track = url.searchParams.get("track") || "memory";
|
|
196
208
|
try {
|
|
197
|
-
const entries = store.entriesOf(track,
|
|
209
|
+
const entries = store.entriesOf(track, agent);
|
|
198
210
|
const pendingItems = pending.read().filter((p) => p.target === track);
|
|
199
211
|
const archived = archive.entriesOf(track, cwd);
|
|
200
212
|
json(200, { ok: true, data: { track, entries, pending: pendingItems, archived, count: entries.length } });
|
|
@@ -221,29 +233,29 @@ function apply(ctx, config) {
|
|
|
221
233
|
if (t === "key" && s.writeGuard) {
|
|
222
234
|
pending.append({ target: t, content, at: new Date().toISOString() });
|
|
223
235
|
} else {
|
|
224
|
-
const r = store.add(t, content,
|
|
225
|
-
if (r?.ok !== false) markWrote(
|
|
236
|
+
const r = store.add(t, content, agent);
|
|
237
|
+
if (r?.ok !== false) markWrote(agent);
|
|
226
238
|
}
|
|
227
239
|
} else if (action === "replace" || action === "edit" || action === "saveEdit") {
|
|
228
|
-
const r = store.replace(t, match || entry, content,
|
|
229
|
-
if (r?.ok !== false) markWrote(
|
|
240
|
+
const r = store.replace(t, match || entry, content, agent);
|
|
241
|
+
if (r?.ok !== false) markWrote(agent);
|
|
230
242
|
} else if (action === "delete" || action === "remove") {
|
|
231
|
-
store.remove(t, match || entry,
|
|
243
|
+
store.remove(t, match || entry, agent);
|
|
232
244
|
} else if (action === "archive") {
|
|
233
245
|
// 先写归档、再删主轨(两步之间断掉也不丢内容)
|
|
234
246
|
archive.append(t, entry || match, cwd);
|
|
235
|
-
store.remove(t, match || entry,
|
|
247
|
+
store.remove(t, match || entry, agent);
|
|
236
248
|
} else if (action === "confirm") {
|
|
237
249
|
// 待确认 → 正式写入;按内容匹配,不用前端索引(前端列表是过滤后的)
|
|
238
250
|
const items = pending.read();
|
|
239
251
|
const want = String(entry ?? "").trim();
|
|
240
252
|
const idx = items.findIndex((p) => String(p.content ?? "").trim() === want);
|
|
241
253
|
if (idx >= 0) {
|
|
242
|
-
const r = store.add(items[idx].target, items[idx].content,
|
|
254
|
+
const r = store.add(items[idx].target, items[idx].content, agent);
|
|
243
255
|
if (r?.ok !== false) {
|
|
244
256
|
items.splice(idx, 1);
|
|
245
257
|
pending.write(items);
|
|
246
|
-
markWrote(
|
|
258
|
+
markWrote(agent);
|
|
247
259
|
}
|
|
248
260
|
}
|
|
249
261
|
} else if (action === "reject") {
|
|
@@ -259,10 +271,10 @@ function apply(ctx, config) {
|
|
|
259
271
|
}
|
|
260
272
|
} else if (action === "promote") {
|
|
261
273
|
// 归档 → 移回主轨:先写主轨,写成功才删归档
|
|
262
|
-
const r = store.add(t, entry,
|
|
274
|
+
const r = store.add(t, entry, agent);
|
|
263
275
|
if (r?.ok !== false) {
|
|
264
276
|
archive.removeExact(t, entry, cwd);
|
|
265
|
-
markWrote(
|
|
277
|
+
markWrote(agent);
|
|
266
278
|
}
|
|
267
279
|
} else if (action === "removeArchive") {
|
|
268
280
|
archive.removeExact(t, entry, cwd);
|
package/lib/schema.js
CHANGED
|
@@ -5,7 +5,7 @@ import z from "@deepseek-ai/schemastery";
|
|
|
5
5
|
import { DEFAULTS } from "./defaults.js";
|
|
6
6
|
|
|
7
7
|
export const Config = z.object({
|
|
8
|
-
memoryTracks: z.
|
|
8
|
+
memoryTracks: z.union([z.const("lite"), z.const("full")]).default(DEFAULTS.memoryTracks),
|
|
9
9
|
presetName: z.string().default(DEFAULTS.presetName),
|
|
10
10
|
memoryDir: z.string().default(DEFAULTS.memoryDir),
|
|
11
11
|
writeGuard: z.boolean().default(DEFAULTS.writeGuard),
|