Skip to content

Commit 413133e

Browse files
committed
fix: isOwnedByAgent阻斷derived被main fallback錯誤繼承(#448); move _initialized to end of register(); use embedPassage in import-markdown
1 parent fdcea58 commit 413133e

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ export function registerMemoryCLI(program: Command, context: CLIContext): void {
11371137
}
11381138

11391139
try {
1140-
const vector = await context.embedder!.embedQuery(text);
1140+
const vector = await context.embedder!.embedPassage(text);
11411141
await context.store.store({
11421142
text,
11431143
vector,

index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1629,7 +1629,6 @@ const memoryLanceDBProPlugin = {
16291629
api.logger.debug("memory-lancedb-pro: register() called again — skipping re-init (idempotent)");
16301630
return;
16311631
}
1632-
_initialized = true;
16331632

16341633
// Parse and validate configuration
16351634
const config = parsePluginConfig(api.pluginConfig);
@@ -3730,6 +3729,7 @@ const memoryLanceDBProPlugin = {
37303729
// Run initial backup after a short delay, then schedule daily
37313730
setTimeout(() => void runBackup(), 60_000); // 1 min after start
37323731
backupTimer = setInterval(() => void runBackup(), BACKUP_INTERVAL_MS);
3732+
_initialized = true;
37333733
},
37343734
stop: async () => {
37353735
if (backupTimer) {

src/reflection-store.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,20 @@ function isReflectionMetadataType(type: unknown): boolean {
428428

429429
function isOwnedByAgent(metadata: Record<string, unknown>, agentId: string): boolean {
430430
const owner = typeof metadata.agentId === "string" ? metadata.agentId.trim() : "";
431+
432+
// itemKind 只存在於 memory-reflection-item 類型
433+
// legacy (memory-reflection) 和 mapped (memory-reflection-mapped) 都沒有 itemKind
434+
// 因此 undefined !== "derived",會走原本的 main fallback(維持相容)
435+
const itemKind = metadata.itemKind;
436+
437+
// 如果是 derived 項目(memory-reflection-item):不做 main fallback,
438+
// 且 derived 不允許空白 owner(空白 owner 的 derived 應完全不可見,防止洩漏)
439+
if (itemKind === "derived") {
440+
if (!owner) return false;
441+
return owner === agentId;
442+
}
443+
444+
// invariant / legacy / mapped:允許空白 owner 可見,維持原本的 main fallback
431445
if (!owner) return true;
432446
return owner === agentId || owner === "main";
433447
}

0 commit comments

Comments
 (0)