From 2ed904fd0031ba2ab1a2228944687078a4458649 Mon Sep 17 00:00:00 2001 From: autodev-bot Date: Sun, 30 Aug 2026 05:29:29 +0800 Subject: [PATCH 01/38] fix(llm): propagate opts.op through facade to providers (#2308) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `LlmClient.buildCallInput()` dropped `opts.op` when constructing the `ProviderCallInput` object handed to `provider.complete()` / `stream()`. Callers set `op` for every logical call site (e.g. `capture.summarize`, `retrieval.filter`, `skill.evolve`) but only the audit / metrics paths inside the facade saw the tag — providers never did. As a result any per-op provider behavior (request-body tweaks, routing overrides, reasoning kill-switches keyed on `opts.op === "capture.summarize"`) silently could never fire. The issue-reported symptom: OpenRouter DeepSeek reasoning models burn full token budget and double latency on `capture.summarize` because the recommended `thinking: { type: "disabled" }` switch is unreachable. Fix: - extend `ProviderCallInput` with optional `op?: string` - copy `opts?.op` in `buildCallInput()` Field stays optional so providers must not assume it is set. No public LlmClient surface change; consumers keep calling `complete` / `completeJson` / `stream` unchanged. Added 4 unit tests in `tests/unit/llm/client.test.ts` under an "op propagation (issue #2308)" describe block covering complete / completeJson / stream forwarding and the "no op supplied" case. --- apps/memos-local-plugin/core/llm/client.ts | 1 + apps/memos-local-plugin/core/llm/types.ts | 8 ++++ .../tests/unit/llm/client.test.ts | 45 +++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/apps/memos-local-plugin/core/llm/client.ts b/apps/memos-local-plugin/core/llm/client.ts index ee456ac12..a94d05556 100644 --- a/apps/memos-local-plugin/core/llm/client.ts +++ b/apps/memos-local-plugin/core/llm/client.ts @@ -282,6 +282,7 @@ export function createLlmClientWithProvider( maxTokens: opts?.maxTokens ?? config.maxTokens ?? DEFAULT_MAX_TOKENS, jsonMode, stop: opts?.stop, + op: opts?.op, }; } diff --git a/apps/memos-local-plugin/core/llm/types.ts b/apps/memos-local-plugin/core/llm/types.ts index 2dd761f32..ef61c439f 100644 --- a/apps/memos-local-plugin/core/llm/types.ts +++ b/apps/memos-local-plugin/core/llm/types.ts @@ -257,6 +257,14 @@ export interface ProviderCallInput { maxTokens: number; jsonMode: boolean; stop?: string[]; + /** + * Logical call site (e.g. `capture.summarize`, `retrieval.filter`, + * `skill.evolve`). Forwarded from `LlmCallOptions.op` so providers + * can apply per-op behavior (request-body tweaks, routing overrides, + * reasoning kill-switches, per-op budget caps). Optional — providers + * must not assume it is set. + */ + op?: string; } /** What providers return — pre-facade post-processing. */ diff --git a/apps/memos-local-plugin/tests/unit/llm/client.test.ts b/apps/memos-local-plugin/tests/unit/llm/client.test.ts index cd125ecd8..084ec5d6f 100644 --- a/apps/memos-local-plugin/tests/unit/llm/client.test.ts +++ b/apps/memos-local-plugin/tests/unit/llm/client.test.ts @@ -322,6 +322,51 @@ describe("llm/client", () => { ); }); + // ─── op propagation to providers (issue #2308) ──────────────────────── + // + // The facade must forward `opts.op` onto the `ProviderCallInput` handed to + // `provider.complete()` / `provider.stream()` so per-op provider behavior + // (e.g. request-body tweaks, routing overrides, reasoning kill-switches + // keyed on `capture.summarize`) can fire. Dropping it silently makes + // those switches unreachable. + describe("op propagation (issue #2308)", () => { + it("complete forwards opts.op onto the provider input", async () => { + const fake = new FakeProvider("openai_compatible", () => ({ text: "ok", durationMs: 1 })); + const client = createLlmClientWithProvider(cfg(), fake); + await client.complete("hi", { op: "capture.summarize" }); + expect(fake.lastInput?.op).toBe("capture.summarize"); + }); + + it("completeJson forwards opts.op onto the provider input", async () => { + const fake = new FakeProvider("openai_compatible", () => ({ + text: '{"a":1}', + durationMs: 1, + })); + const client = createLlmClientWithProvider(cfg(), fake); + await client.completeJson<{ a: number }>("score", { op: "retrieval.filter" }); + expect(fake.lastInput?.op).toBe("retrieval.filter"); + }); + + it("stream forwards opts.op onto the provider input (non-streaming provider)", async () => { + // FakeProvider has no stream(); the facade wraps complete() in a + // single-chunk iterable, which still exercises buildCallInput. + const fake = new FakeProvider("openai_compatible", () => ({ text: "one", durationMs: 1 })); + const client = createLlmClientWithProvider(cfg(), fake); + const parts: string[] = []; + for await (const c of client.stream("x", { op: "skill.evolve" })) { + if (!c.done) parts.push(c.delta); + } + expect(fake.lastInput?.op).toBe("skill.evolve"); + }); + + it("omits op field when caller supplies no op (contract stays optional)", async () => { + const fake = new FakeProvider("openai_compatible", () => ({ text: "ok", durationMs: 1 })); + const client = createLlmClientWithProvider(cfg(), fake); + await client.complete("hi"); + expect(fake.lastInput?.op).toBeUndefined(); + }); + }); + // ─── Circuit breaker (issue #1897) ────────────────────────────────────── describe("circuit breaker", () => { function statusSink(): { rows: LlmStatusDetail[]; push: (d: LlmStatusDetail) => void } { From 4fb4fa010d40ff1b98a86834e251d3f9ef09ff35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=81=E5=9C=A8=E5=90=B5=E7=9D=80=E5=90=83=E7=B3=96?= Date: Thu, 3 Sep 2026 20:30:06 +0800 Subject: [PATCH 02/38] test(plugin): cover native stream op propagation --- .../tests/unit/llm/client.test.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/apps/memos-local-plugin/tests/unit/llm/client.test.ts b/apps/memos-local-plugin/tests/unit/llm/client.test.ts index c5f663130..51051ab00 100644 --- a/apps/memos-local-plugin/tests/unit/llm/client.test.ts +++ b/apps/memos-local-plugin/tests/unit/llm/client.test.ts @@ -58,11 +58,17 @@ class FakeProvider implements LlmProvider { class StreamingProvider implements LlmProvider { readonly name: LlmProviderName = "openai_compatible"; + public lastInput: ProviderCallInput | null = null; + async complete(): Promise { return { text: "full", durationMs: 1 }; } // eslint-disable-next-line require-yield - async *stream(): AsyncGenerator { + async *stream( + _messages: LlmMessage[], + opts: ProviderCallInput, + ): AsyncGenerator { + this.lastInput = opts; yield { delta: "he", done: false }; yield { delta: "llo", done: false }; yield { @@ -372,7 +378,16 @@ describe("llm/client", () => { expect(fake.lastInput?.op).toBe("skill.evolve"); }); - it("omits op field when caller supplies no op (contract stays optional)", async () => { + it("stream forwards opts.op onto a native streaming provider", async () => { + const provider = new StreamingProvider(); + const client = createLlmClientWithProvider(cfg(), provider); + for await (const _chunk of client.stream("x", { op: "capture.summarize" })) { + // Consume the stream so the provider receives the cooked input. + } + expect(provider.lastInput?.op).toBe("capture.summarize"); + }); + + it("leaves op undefined when the caller supplies no op", async () => { const fake = new FakeProvider("openai_compatible", () => ({ text: "ok", durationMs: 1 })); const client = createLlmClientWithProvider(cfg(), fake); await client.complete("hi"); From 77c563cb0102ef95462c92771ac68802ea666981 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=81=E5=9C=A8=E5=90=B5=E7=9D=80=E5=90=83=E7=B3=96?= Date: Wed, 16 Sep 2026 14:59:33 +0800 Subject: [PATCH 03/38] fix(plugin): stop skill verification retry loops --- apps/memos-local-plugin/core/llm/client.ts | 38 +++++++++++++------ apps/memos-local-plugin/core/skill/skill.ts | 1 + .../core/skill/subscriber.ts | 17 ++++++++- .../core/skill/tool-names.ts | 15 +++++++- apps/memos-local-plugin/core/skill/types.ts | 1 + .../tests/unit/skill/events.test.ts | 14 +++++++ .../tests/unit/skill/verifier.test.ts | 16 ++++++++ 7 files changed, 88 insertions(+), 14 deletions(-) diff --git a/apps/memos-local-plugin/core/llm/client.ts b/apps/memos-local-plugin/core/llm/client.ts index a94d05556..7e19f25ca 100644 --- a/apps/memos-local-plugin/core/llm/client.ts +++ b/apps/memos-local-plugin/core/llm/client.ts @@ -356,24 +356,25 @@ export function createLlmClientWithProvider( notifyError: true, }); } catch (hostErr) { + const normalizedHostErr = normalizeError(hostErr, ERROR_CODES.LLM_UNAVAILABLE, "host fallback failed"); failures++; - const failAt = markFail(hostErr); + const failAt = markFail(normalizedHostErr); facadeLog.error("host.fallback_failed", { primary: summarizeErr(err), - host: summarizeErr(hostErr), + host: summarizeErr(normalizedHostErr), }); // Primary AND host bridge both failed. Trip on a terminal // primary error (the one the operator typically needs to fix // — host bridge failures are usually transient stdio issues). if (breakerIsTerminal(err)) breakerTrip(err); - notifyOnError(hostErr); + notifyOnError(normalizedHostErr); notifyStatus({ status: "error", provider: provider.name, model: config.model, - message: summarizeErrMessage(hostErr), - code: hostErr instanceof MemosError ? hostErr.code : undefined, - ...extractRetryDiagnostics(hostErr instanceof MemosError ? hostErr.details : undefined), + message: summarizeErrMessage(normalizedHostErr), + code: normalizedHostErr.code, + ...extractRetryDiagnostics(normalizedHostErr.details), at: failAt, durationMs: Date.now() - startedAt, fallbackProvider: "host", @@ -381,12 +382,7 @@ export function createLlmClientWithProvider( episodeId: opts?.episodeId, phase: opts?.phase, }); - throw hostErr instanceof MemosError - ? hostErr - : new MemosError( - ERROR_CODES.LLM_UNAVAILABLE, - `host fallback failed: ${(hostErr as Error).message ?? String(hostErr)}`, - ); + throw normalizedHostErr; } } failures++; @@ -841,3 +837,21 @@ function summarizeErrMessage(e: unknown): string { if (e instanceof Error) return e.message; return String(e); } + +function normalizeError( + err: unknown, + fallbackCode: (typeof ERROR_CODES)[keyof typeof ERROR_CODES], + prefix: string, +): MemosError { + if (err instanceof MemosError) return err; + if (err instanceof Error) return new MemosError(fallbackCode, `${prefix}: ${err.message}`); + if (typeof err === "object" && err !== null) { + const record = err as { code?: unknown; message?: unknown; data?: unknown }; + const code = typeof record.code === "string" ? record.code : fallbackCode; + const message = typeof record.message === "string" ? record.message : String(record.data ?? err); + return new MemosError(code as (typeof ERROR_CODES)[keyof typeof ERROR_CODES], `${prefix}: ${message}`, { + bridgeError: err as Record, + }); + } + return new MemosError(fallbackCode, `${prefix}: ${String(err)}`); +} diff --git a/apps/memos-local-plugin/core/skill/skill.ts b/apps/memos-local-plugin/core/skill/skill.ts index d0cdc48ae..be9c0aea2 100644 --- a/apps/memos-local-plugin/core/skill/skill.ts +++ b/apps/memos-local-plugin/core/skill/skill.ts @@ -174,6 +174,7 @@ export async function runSkill( kind: "skill.verification.failed", at: nowMs(), skillId: "sk_placeholder" as SkillId, + policyId: decision.policy.id, reason: verdict.reason ?? "verify-failed", }); continue; diff --git a/apps/memos-local-plugin/core/skill/subscriber.ts b/apps/memos-local-plugin/core/skill/subscriber.ts index 6b30d9d5e..eccfafa9b 100644 --- a/apps/memos-local-plugin/core/skill/subscriber.ts +++ b/apps/memos-local-plugin/core/skill/subscriber.ts @@ -79,6 +79,7 @@ export function attachSkillSubscriber( }; let inflight: Promise | null = null; + let lastRewardRunAt: number | null = null; let queued: { trigger: SkillTrigger; hint?: { policyId?: string; skillId?: SkillId } } | null = null; @@ -115,6 +116,20 @@ export function attachSkillSubscriber( inflight = promise; } + function triggerRewardRun(): void { + const cooldownMs = Math.max(0, deps.config.cooldownMs); + const at = nowMs(); + if (cooldownMs > 0 && lastRewardRunAt !== null && at - lastRewardRunAt < cooldownMs) { + log.debug("skill.run.cooldown", { + trigger: "reward.updated", + remainingMs: cooldownMs - (at - lastRewardRunAt), + }); + return; + } + lastRewardRunAt = at; + triggerRun("reward.updated"); + } + const offInduced = deps.l2Bus.on("l2.policy.induced", (evt: L2Event) => { if (evt.kind !== "l2.policy.induced") return; log.debug("trigger.l2.policy.induced", { policyId: evt.policyId }); @@ -134,7 +149,7 @@ export function attachSkillSubscriber( episodeId: evt.result.episodeId, }); resolveTrialsForReward(evt); - triggerRun("reward.updated"); + triggerRewardRun(); }); function dispose(): void { diff --git a/apps/memos-local-plugin/core/skill/tool-names.ts b/apps/memos-local-plugin/core/skill/tool-names.ts index 4dd903a75..34532f63e 100644 --- a/apps/memos-local-plugin/core/skill/tool-names.ts +++ b/apps/memos-local-plugin/core/skill/tool-names.ts @@ -21,7 +21,20 @@ export function extractToolNames(traces: readonly TraceRow[]): Set { if (name && !IGNORED_NAMES.has(name)) out.add(name); if (typeof tc.input === "string") { - const first = tc.input.trim().split(/\s+/)[0]?.toLowerCase(); + const raw = tc.input.trim(); + // JSON tool arguments are payload, not shell commands. Taking the + // first whitespace token from them produces entries such as `{"code":` + // and poisons the EVIDENCE_TOOLS whitelist. + let parsed: unknown; + try { + parsed = JSON.parse(raw); + } catch { + parsed = undefined; + } + if (parsed !== undefined) { + continue; + } + const first = raw.split(/\s+/)[0]?.toLowerCase(); if (first && first.length >= 2) out.add(first); } } diff --git a/apps/memos-local-plugin/core/skill/types.ts b/apps/memos-local-plugin/core/skill/types.ts index b04e3bc35..5c1dd89ef 100644 --- a/apps/memos-local-plugin/core/skill/types.ts +++ b/apps/memos-local-plugin/core/skill/types.ts @@ -214,6 +214,7 @@ export interface SkillVerificationPassedEvent export interface SkillVerificationFailedEvent extends SkillEventBase<"skill.verification.failed"> { skillId: SkillId; + policyId: string; reason: string; } diff --git a/apps/memos-local-plugin/tests/unit/skill/events.test.ts b/apps/memos-local-plugin/tests/unit/skill/events.test.ts index 2643cff16..8b1bf6425 100644 --- a/apps/memos-local-plugin/tests/unit/skill/events.test.ts +++ b/apps/memos-local-plugin/tests/unit/skill/events.test.ts @@ -48,4 +48,18 @@ describe("skill/events", () => { }); expect(called).toEqual(["second"]); }); + + it("preserves the policy that produced a verification failure", () => { + const bus = createSkillEventBus(); + const seen: SkillEvent[] = []; + bus.on("skill.verification.failed", (event) => seen.push(event)); + bus.emit({ + kind: "skill.verification.failed", + at: 1, + skillId: "sk_1" as SkillId, + policyId: "po_1", + reason: "resonance=0.00<0.5", + }); + expect(seen[0]).toMatchObject({ policyId: "po_1" }); + }); }); diff --git a/apps/memos-local-plugin/tests/unit/skill/verifier.test.ts b/apps/memos-local-plugin/tests/unit/skill/verifier.test.ts index d74ac9d09..930c95aff 100644 --- a/apps/memos-local-plugin/tests/unit/skill/verifier.test.ts +++ b/apps/memos-local-plugin/tests/unit/skill/verifier.test.ts @@ -119,6 +119,22 @@ describe("skill/verifier", () => { expect(r.coverage).toBe(1); }); + it("does not treat JSON string arguments as command names", () => { + const draft = makeDraft({ + summary: "Execute code safely", + tools: ["execute_code"], + steps: [{ title: "execute", body: "execute the supplied code" }], + }); + const evidence = [ + trace("tr_json", "run code", "execution completed", [ + { name: "execute_code", input: '{"code": "print(1)"}' }, + ]), + ]; + const r = verifyDraft({ draft, evidence }, { log }); + expect(r.coverage).toBe(1); + expect(r.unmappedTokens).toEqual([]); + }); + it("partial coverage below threshold fails", () => { const draft = makeDraft({ summary: "Use several tools", From dc61f2e17ef47d8378d2b6c55b4baccc5f569be3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=81=E5=9C=A8=E5=90=B5=E7=9D=80=E5=90=83=E7=B3=96?= Date: Wed, 16 Sep 2026 17:39:11 +0800 Subject: [PATCH 04/38] fix(plugin): bound L3 clusters and retry failures --- .../core/config/defaults.ts | 1 + apps/memos-local-plugin/core/config/schema.ts | 2 ++ .../core/memory/l3/cluster.ts | 20 ++++++++---- apps/memos-local-plugin/core/memory/l3/l3.ts | 22 +++++++++++++ .../core/memory/l3/types.ts | 3 ++ .../tests/unit/memory/l3/cluster.test.ts | 31 +++++++++++++++++++ 6 files changed, 73 insertions(+), 6 deletions(-) diff --git a/apps/memos-local-plugin/core/config/defaults.ts b/apps/memos-local-plugin/core/config/defaults.ts index 2575a8405..e5bd95c16 100644 --- a/apps/memos-local-plugin/core/config/defaults.ts +++ b/apps/memos-local-plugin/core/config/defaults.ts @@ -222,6 +222,7 @@ export const DEFAULT_CONFIG: ResolvedConfig = { // an early-life install can still cluster into a world model; // strict 0.6 starved L3 in real usage. clusterMinSimilarity: 0.3, + maxPoliciesPerCluster: 20, policyCharCap: 800, traceCharCap: 500, traceEvidencePerPolicy: 1, diff --git a/apps/memos-local-plugin/core/config/schema.ts b/apps/memos-local-plugin/core/config/schema.ts index 9cd79b612..5b7071061 100644 --- a/apps/memos-local-plugin/core/config/schema.ts +++ b/apps/memos-local-plugin/core/config/schema.ts @@ -326,6 +326,8 @@ const AlgorithmSchema = Type.Object({ * are ignored (policies too disparate to share a world model). */ clusterMinSimilarity: NumberInRange(0.6, 0, 1), + /** Maximum policies included in one L3 abstraction prompt. */ + maxPoliciesPerCluster: NumberInRange(20, 1, 100), /** Chars of L2 body handed to `l3.abstraction`. */ policyCharCap: NumberInRange(800, 200, 4_000), /** Chars of trace body handed per evidence trace. */ diff --git a/apps/memos-local-plugin/core/memory/l3/cluster.ts b/apps/memos-local-plugin/core/memory/l3/cluster.ts index ab20809e0..0b2ee1943 100644 --- a/apps/memos-local-plugin/core/memory/l3/cluster.ts +++ b/apps/memos-local-plugin/core/memory/l3/cluster.ts @@ -27,7 +27,7 @@ export interface ClusterInput { } export interface ClusterDeps { - config: Pick; + config: Pick; } // ─── Domain key extraction ───────────────────────────────────────────────── @@ -173,25 +173,33 @@ export function clusterPolicies( // here is only "strict subset" vs "whole bucket". let cohort: PolicyWithMeta[]; let admission: "strict" | "loose"; - if (strict.length >= config.minPolicies) { + const requiredPolicies = key === "_|_" + ? Math.max(2, config.minPolicies) + : config.minPolicies; + if (strict.length >= requiredPolicies) { cohort = strict; admission = "strict"; - } else if (members.length >= config.minPolicies) { + } else if (key !== "_|_" && members.length >= requiredPolicies) { cohort = members; admission = "loose"; } else { continue; } + const capped = cohort + .slice() + .sort((a, b) => String(a.policy.id).localeCompare(String(b.policy.id))) + .slice(0, Math.max(1, config.maxPoliciesPerCluster ?? 20)); + if (capped.length < requiredPolicies) continue; const tags = new Set(); - for (const m of cohort) for (const t of m.tags) tags.add(t); + for (const m of capped) for (const t of m.tags) tags.add(t); const avgGain = - cohort.reduce((s, m) => s + m.policy.gain, 0) / Math.max(1, cohort.length); + capped.reduce((s, m) => s + m.policy.gain, 0) / Math.max(1, capped.length); out.push({ key, - policies: cohort.map((m) => m.policy), + policies: capped.map((m) => m.policy), domainTags: Array.from(tags), centroidVec: center, avgGain, diff --git a/apps/memos-local-plugin/core/memory/l3/l3.ts b/apps/memos-local-plugin/core/memory/l3/l3.ts index 3a786b08d..3a57f8376 100644 --- a/apps/memos-local-plugin/core/memory/l3/l3.ts +++ b/apps/memos-local-plugin/core/memory/l3/l3.ts @@ -62,6 +62,8 @@ export interface RunL3Deps { } const KV_COOLDOWN_PREFIX = "l3.lastRun."; +const KV_RETRY_PREFIX = "l3.retry."; +const FAILURE_BACKOFF_MS = [5 * 60_000, 30 * 60_000, 2 * 60 * 60_000, 6 * 60 * 60_000]; // ─── Public entry ────────────────────────────────────────────────────────── @@ -102,6 +104,7 @@ export async function runL3( config: { clusterMinSimilarity: config.clusterMinSimilarity, minPolicies: config.minPolicies, + maxPoliciesPerCluster: config.maxPoliciesPerCluster ?? 20, }, }, ); @@ -150,6 +153,11 @@ export async function runL3( abstractions.push(skipped(cluster, "cooldown")); continue; } + const retry = repos.kv.get<{ nextRetryAt: number; failures: number } | null>(retryKey(cluster), null); + if (retry && retry.nextRetryAt > now) { + abstractions.push(skipped(cluster, "retry_cooldown")); + continue; + } const evidenceByPolicy = loadEvidence(cluster, repos, config.traceEvidencePerPolicy); const episodeIds = collectEpisodeIds(cluster.policies, evidenceByPolicy); @@ -170,6 +178,7 @@ export async function runL3( timings.abstract += Date.now() - t0; if (!draftRes.ok) { + recordFailure(cluster, repos.kv, now); abstractions.push(skipped(cluster, draftRes.reason, { episodeIds, policyIds: cluster.policies.map((p) => p.id) })); emit(bus, { kind: "l3.failed", @@ -314,6 +323,7 @@ export async function runL3( } markCooldown(cluster, repos.kv, now); + repos.kv.del(retryKey(cluster)); timings.persist += Date.now() - t1; } @@ -441,6 +451,18 @@ function cooldownKey(cluster: PolicyCluster): string { return `${KV_COOLDOWN_PREFIX}${primary}`; } +function retryKey(cluster: PolicyCluster): string { + const members = cluster.policies.map((p) => String(p.id)).sort().join(","); + return `${KV_RETRY_PREFIX}${cluster.key}:${members}`; +} + +function recordFailure(cluster: PolicyCluster, kv: Repos["kv"], now: number): void { + const previous = kv.get<{ nextRetryAt: number; failures: number } | null>(retryKey(cluster), null); + const failures = Math.min((previous?.failures ?? 0) + 1, FAILURE_BACKOFF_MS.length); + const delay = FAILURE_BACKOFF_MS[failures - 1] ?? FAILURE_BACKOFF_MS[FAILURE_BACKOFF_MS.length - 1]!; + kv.set(retryKey(cluster), { failures, nextRetryAt: now + delay }); +} + function isInCooldown( cluster: PolicyCluster, kv: Repos["kv"], diff --git a/apps/memos-local-plugin/core/memory/l3/types.ts b/apps/memos-local-plugin/core/memory/l3/types.ts index 69d0751a8..142a51a6a 100644 --- a/apps/memos-local-plugin/core/memory/l3/types.ts +++ b/apps/memos-local-plugin/core/memory/l3/types.ts @@ -39,6 +39,8 @@ export interface L3Config { minPolicySupport: number; /** Cosine floor for two L2s to share a cluster. */ clusterMinSimilarity: number; + /** Maximum policies admitted to one abstraction prompt. */ + maxPoliciesPerCluster?: number; /** Char cap for each L2 body section handed to the prompt. */ policyCharCap: number; /** Char cap for each L1 evidence trace handed to the prompt. */ @@ -152,6 +154,7 @@ export interface AbstractionResult { | "llm_failed" | "draft_invalid" | "cooldown" + | "retry_cooldown" | "no_centroid" | "duplicate_of"; /** When `skippedReason === "duplicate_of"`, the existing WM id. */ diff --git a/apps/memos-local-plugin/tests/unit/memory/l3/cluster.test.ts b/apps/memos-local-plugin/tests/unit/memory/l3/cluster.test.ts index 737b602d9..b67cf557b 100644 --- a/apps/memos-local-plugin/tests/unit/memory/l3/cluster.test.ts +++ b/apps/memos-local-plugin/tests/unit/memory/l3/cluster.test.ts @@ -61,6 +61,23 @@ describe("memory/l3/cluster", () => { expect(tags).toEqual([]); }); + it("does not create a cluster from an untagged bucket", () => { + const policies = [ + [1, 0, 0], + [0, 1, 0], + [0, 0, 1], + ].map((v, n) => mkPolicy({ + id: `po_u${n}` as PolicyId, + title: `中文策略 ${n}`, + vec: vec(v), + })); + const clusters = clusterPolicies( + { policies }, + { config: { clusterMinSimilarity: 0.6, minPolicies: 1, maxPoliciesPerCluster: 20 } }, + ); + expect(clusters).toHaveLength(0); + }); + it("groups network-related text under 'network'", () => { const p = mkPolicy({ id: "po_n" as PolicyId, @@ -108,6 +125,20 @@ describe("memory/l3/cluster", () => { ); }); + it("caps loose clusters before they reach the prompt", () => { + const policies = [1, 2, 3].map((n) => mkPolicy({ + id: `po_n${n}` as PolicyId, + title: `network retry ${n}`, + trigger: "proxy DNS failure", + vec: vec([1, 0, 0]), + })); + const clusters = clusterPolicies( + { policies }, + { config: { clusterMinSimilarity: 0.99, minPolicies: 1, maxPoliciesPerCluster: 2 } }, + ); + expect(clusters[0]!.policies).toHaveLength(2); + }); + it("skips a bucket that doesn't meet minPolicies", () => { const policies = [ mkPolicy({ From 8c47b6d61b82e0509eaafa50b6d7f7cc95ec808c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=81=E5=9C=A8=E5=90=B5=E7=9D=80=E5=90=83=E7=B3=96?= Date: Wed, 16 Sep 2026 18:39:03 +0800 Subject: [PATCH 05/38] fix(plugin): harden L3 clustering retries --- .../core/config/defaults.ts | 6 +- .../core/memory/l3/ALGORITHMS.md | 10 ++- .../core/memory/l3/README.md | 1 + .../core/memory/l3/cluster.ts | 53 ++++++++++++- apps/memos-local-plugin/core/memory/l3/l3.ts | 15 +++- apps/memos-local-plugin/core/skill/README.md | 2 +- .../tests/unit/memory/l3/cluster.test.ts | 41 +++++----- .../unit/memory/l3/l3.integration.test.ts | 78 +++++++++++++++++++ 8 files changed, 174 insertions(+), 32 deletions(-) diff --git a/apps/memos-local-plugin/core/config/defaults.ts b/apps/memos-local-plugin/core/config/defaults.ts index e5bd95c16..7a54fd270 100644 --- a/apps/memos-local-plugin/core/config/defaults.ts +++ b/apps/memos-local-plugin/core/config/defaults.ts @@ -250,9 +250,9 @@ export const DEFAULT_CONFIG: ResolvedConfig = { // real usage; 1 lets the candidate→active transition happen // immediately on first successful invocation. candidateTrials: 1, - // Lowered from 6 hours → 0: no cooldown, skills can re-evolve - // as soon as new evidence arrives. - cooldownMs: 0, + // Verification failures are retried after six hours by default; + // operators may set this to 0 when immediate re-evaluation is desired. + cooldownMs: 6 * 60 * 60 * 1000, traceCharCap: 500, evidenceLimit: 6, useLlm: true, diff --git a/apps/memos-local-plugin/core/memory/l3/ALGORITHMS.md b/apps/memos-local-plugin/core/memory/l3/ALGORITHMS.md index bdccc8290..f84766cde 100644 --- a/apps/memos-local-plugin/core/memory/l3/ALGORITHMS.md +++ b/apps/memos-local-plugin/core/memory/l3/ALGORITHMS.md @@ -250,9 +250,15 @@ if (now − kv.get(key)) < cooldownDays × 86_400_000: ## 9. Failure policy -* Storage error → propagate. Partial state remains; next run sees the - same eligible policies and re-drives. +* Storage error → warn for the affected cluster and retain retry state. + Other clusters continue; a later run re-drives the failed cluster. * LLM error → single-cluster skip, reason logged. No cooldown update. + +Failed LLM drafts use a persisted retry key scoped by cluster membership. The +retry delays are 5 minutes, 30 minutes, 2 hours, then 6 hours (capped), so a +repeated provider failure cannot consume one LLM call per episode. A successful +world-model insert/update clears the retry key and only then records the normal +cooldown. Storage failures keep the retry state and do not record success. Other clusters continue. * Invalid draft (missing `environment/inference/constraints`) → treated as LLM error. diff --git a/apps/memos-local-plugin/core/memory/l3/README.md b/apps/memos-local-plugin/core/memory/l3/README.md index 0d71f64de..b1a7341b0 100644 --- a/apps/memos-local-plugin/core/memory/l3/README.md +++ b/apps/memos-local-plugin/core/memory/l3/README.md @@ -146,6 +146,7 @@ See `algorithm.l3Abstraction` in | `traceEvidencePerPolicy` | `1` | Evidence traces per policy in the prompt. | | `useLlm` | `true` | Toggle the LLM abstractor off for tests. | | `cooldownDays` | `1` | Debounce per domain tag. | +| `maxPoliciesPerCluster` | `20` | Cap policies included in one abstraction prompt. | | `confidenceDelta` | `0.05` | Confidence step per merge / feedback. | | `minConfidenceForRetrieval` | `0.2` | Tier-3 hide threshold. | diff --git a/apps/memos-local-plugin/core/memory/l3/cluster.ts b/apps/memos-local-plugin/core/memory/l3/cluster.ts index 0b2ee1943..7db92ed7b 100644 --- a/apps/memos-local-plugin/core/memory/l3/cluster.ts +++ b/apps/memos-local-plugin/core/memory/l3/cluster.ts @@ -123,6 +123,11 @@ export function clusterPolicies( for (const [key, members] of byKey) { if (members.length < config.minPolicies) continue; + if (key === "_|_") { + out.push(...clusterUntagged(members, config)); + continue; + } + const vecs: Array = members.map((m) => m.policy.vec ?? null); const center = centroid(vecs); @@ -173,9 +178,7 @@ export function clusterPolicies( // here is only "strict subset" vs "whole bucket". let cohort: PolicyWithMeta[]; let admission: "strict" | "loose"; - const requiredPolicies = key === "_|_" - ? Math.max(2, config.minPolicies) - : config.minPolicies; + const requiredPolicies = config.minPolicies; if (strict.length >= requiredPolicies) { cohort = strict; admission = "strict"; @@ -219,3 +222,47 @@ export function clusterPolicies( }); return out; } + +function clusterUntagged( + members: readonly PolicyWithMeta[], + config: ClusterDeps["config"], +): PolicyCluster[] { + const requiredPolicies = Math.max(2, config.minPolicies); + const maxPolicies = Math.max(1, config.maxPoliciesPerCluster ?? 20); + const groups: PolicyWithMeta[][] = []; + + for (const member of members + .filter((m) => m.policy.vec) + .slice() + .sort((a, b) => String(a.policy.id).localeCompare(String(b.policy.id)))) { + let target: PolicyWithMeta[] | undefined; + for (const group of groups) { + if (group.length >= maxPolicies) continue; + const center = centroid(group.map((m) => m.policy.vec ?? null)); + if (center && member.policy.vec && cosine(center, member.policy.vec) >= config.clusterMinSimilarity) { + target = group; + break; + } + } + if (target) target.push(member); + else groups.push([member]); + } + + return groups + .filter((group) => group.length >= requiredPolicies) + .map((group) => { + const center = centroid(group.map((m) => m.policy.vec ?? null)); + const cohesion = center + ? group.reduce((sum, m) => sum + cosine(center, m.policy.vec!), 0) / group.length + : 0; + return { + key: `_|_:vec:${String(group[0]!.policy.id)}`, + policies: group.map((m) => m.policy), + domainTags: [], + centroidVec: center, + avgGain: group.reduce((sum, m) => sum + m.policy.gain, 0) / group.length, + cohesion, + admission: "strict" as const, + }; + }); +} diff --git a/apps/memos-local-plugin/core/memory/l3/l3.ts b/apps/memos-local-plugin/core/memory/l3/l3.ts index 3a57f8376..8610db895 100644 --- a/apps/memos-local-plugin/core/memory/l3/l3.ts +++ b/apps/memos-local-plugin/core/memory/l3/l3.ts @@ -178,7 +178,9 @@ export async function runL3( timings.abstract += Date.now() - t0; if (!draftRes.ok) { - recordFailure(cluster, repos.kv, now); + if (draftRes.reason === "llm_failed" || draftRes.reason === "draft_invalid") { + recordFailure(cluster, repos.kv, now); + } abstractions.push(skipped(cluster, draftRes.reason, { episodeIds, policyIds: cluster.policies.map((p) => p.id) })); emit(bus, { kind: "l3.failed", @@ -195,6 +197,7 @@ export async function runL3( lookup: repos.worldModel, config, }); + let persisted = false; if (decision.kind === "update") { const patch = mergeForUpdate({ @@ -268,6 +271,7 @@ export async function runL3( policyIds: patch.policyIds as PolicyId[], confidence: bumped, }); + persisted = true; } catch (err) { warnings.push(stageWarn("merge", err, { clusterKey: cluster.key })); } @@ -317,13 +321,18 @@ export async function runL3( policyIds: wm.policyIds, confidence: wm.confidence, }); + persisted = true; } catch (err) { warnings.push(stageWarn("insert", err, { clusterKey: cluster.key })); } } - markCooldown(cluster, repos.kv, now); - repos.kv.del(retryKey(cluster)); + if (persisted) { + markCooldown(cluster, repos.kv, now); + repos.kv.del(retryKey(cluster)); + } else { + recordFailure(cluster, repos.kv, now); + } timings.persist += Date.now() - t1; } diff --git a/apps/memos-local-plugin/core/skill/README.md b/apps/memos-local-plugin/core/skill/README.md index 04a2de8bf..1c89d9808 100644 --- a/apps/memos-local-plugin/core/skill/README.md +++ b/apps/memos-local-plugin/core/skill/README.md @@ -201,7 +201,7 @@ See `algorithm.skill` in | `minSupport` | `2` | Min distinct-episode support to crystallize. | | `minGain` | `0.02` | Min policy gain required (paired with the new shrinkage-anchored gain in `core/memory/l2/gain.ts`). | | `candidateTrials` | `3` | Trials required to transition out of `candidate`. NOTE: legacy docs called this `probationaryTrials`; the schema field is `candidateTrials`. | -| `cooldownMs` | `60000` | Debounce between runs triggered by the same policy. | +| `cooldownMs` | `21600000` | Debounce reward-triggered runs (6 hours; `0` disables). | | `traceCharCap` | `600` | Char cap per evidence trace in the crystallize prompt.| | `evidenceLimit` | `4` | Max evidence traces per crystallize call. | | `useLlm` | `true` | Toggle the LLM off (tests / degraded mode). | diff --git a/apps/memos-local-plugin/tests/unit/memory/l3/cluster.test.ts b/apps/memos-local-plugin/tests/unit/memory/l3/cluster.test.ts index b67cf557b..f5a708196 100644 --- a/apps/memos-local-plugin/tests/unit/memory/l3/cluster.test.ts +++ b/apps/memos-local-plugin/tests/unit/memory/l3/cluster.test.ts @@ -215,30 +215,25 @@ describe("memory/l3/cluster", () => { expect(keys.some((k) => k.includes("node") || k.includes("npm"))).toBe(true); }); - it("falls back to loose admission when strict subset is too small but bucket survives", () => { - // All three policies share the same domain key (`python|_`) but - // their vectors point in mutually-orthogonal directions, so the - // strict (cosine ≥ minSimilarity) subset would be empty. The - // bucket itself satisfies minPolicies, so `cluster.ts` should - // fall back to admitting the WHOLE bucket as a `loose` cluster. + it("does not cluster unrelated untagged policies", () => { const policies = [ mkPolicy({ id: "po_validate" as PolicyId, title: "validate python syntax", - trigger: "after writing python files", - procedure: "python -m py_compile ", + trigger: "after writing source files", + procedure: "run the syntax checker on the changed file", vec: vec([1, 0, 0]), }), mkPolicy({ id: "po_cli" as PolicyId, - title: "register python CLI subcommand", + title: "register a command line subcommand", trigger: "adding a new task verb", procedure: "register(subparsers) + handler() -> int", vec: vec([0, 1, 0]), }), mkPolicy({ id: "po_storage" as PolicyId, - title: "implement python storage backend", + title: "implement a storage backend", trigger: "new persistence format requested", procedure: "implement load/save with UTF-8", vec: vec([0, 0, 1]), @@ -248,16 +243,22 @@ describe("memory/l3/cluster", () => { { policies }, { config: { clusterMinSimilarity: 0.6, minPolicies: 2 } }, ); - expect(clusters.length).toBe(1); - const c = clusters[0]!; - expect(c.admission).toBe("loose"); - expect(c.policies.length).toBe(3); - // Centroid of three orthogonal unit vectors gives mean cosine - // 1/sqrt(3) ≈ 0.577 — strictly less than 0.6 (the strict floor), - // confirming we landed in the loose fallback for the right - // reason and not because of a bug elsewhere. - expect(c.cohesion).toBeLessThan(0.6); - expect(c.cohesion).toBeGreaterThan(0.49); + expect(clusters).toEqual([]); + }); + + it("clusters similar untagged policies and enforces the cap", () => { + const policies = [1, 2, 3].map((n) => mkPolicy({ + id: `po_uv${n}` as PolicyId, + title: `中文策略 ${n}`, + vec: vec([1, n * 0.01, 0]), + })); + const clusters = clusterPolicies( + { policies }, + { config: { clusterMinSimilarity: 0.6, minPolicies: 2, maxPoliciesPerCluster: 2 } }, + ); + expect(clusters).toHaveLength(1); + expect(clusters[0]!.policies).toHaveLength(2); + expect(clusters[0]!.admission).toBe("strict"); }); it("filters outliers below clusterMinSimilarity", () => { diff --git a/apps/memos-local-plugin/tests/unit/memory/l3/l3.integration.test.ts b/apps/memos-local-plugin/tests/unit/memory/l3/l3.integration.test.ts index 51ba5d4b8..0f0b6713e 100644 --- a/apps/memos-local-plugin/tests/unit/memory/l3/l3.integration.test.ts +++ b/apps/memos-local-plugin/tests/unit/memory/l3/l3.integration.test.ts @@ -38,6 +38,16 @@ import { const OP = `${L3_ABSTRACTION_PROMPT.id}.v${L3_ABSTRACTION_PROMPT.version}`; const log = rootLogger.child({ channel: "core.memory.l3" }); +const validDraft = { + title: "Alpine python dependency model", + domain_tags: ["docker", "alpine", "pip"], + environment: [{ label: "musl libc", description: "no glibc" }], + inference: [{ label: "binary wheels fail", description: "compile from source" }], + constraints: [], + body: "# summary", + confidence: 0.75, + supersedes_world_ids: [], +}; function cfg(overrides: Partial = {}): L3Config { return { @@ -237,6 +247,74 @@ describe("memory/l3/integration", () => { ); expect(res.abstractions.every((a) => a.skippedReason === "llm_disabled")).toBe(true); expect(handle.repos.worldModel.list().length).toBe(0); + expect(handle.repos.kv.all().filter((row) => row.key.startsWith("l3.retry."))).toEqual([]); + }); + + it("backs off a failed abstraction, retries after expiry, and clears retry state", async () => { + seedTriplet(); + let calls = 0; + const llm = fakeLlm({ + completeJson: { + [OP]: () => { + calls++; + if (calls === 1) throw new Error("temporary failure"); + return validDraft; + }, + }, + }); + const deps = { + repos: { + policies: handle.repos.policies, + traces: handle.repos.traces, + worldModel: handle.repos.worldModel, + kv: handle.repos.kv, + }, + llm, + log, + config: cfg(), + }; + + const failed = await runL3({ trigger: "manual", now: NOW }, deps); + expect(failed.abstractions[0]!.skippedReason).toBe("llm_failed"); + expect(calls).toBe(1); + expect(handle.repos.kv.all().some((row) => row.key.startsWith("l3.retry."))).toBe(true); + + const deferred = await runL3({ trigger: "manual", now: NOW + 299_999 }, deps); + expect(deferred.abstractions[0]!.skippedReason).toBe("retry_cooldown"); + expect(calls).toBe(1); + + const retried = await runL3({ trigger: "manual", now: NOW + 300_000 }, deps); + expect(retried.abstractions[0]!.skippedReason).toBeNull(); + expect(calls).toBe(2); + expect(handle.repos.kv.all().filter((row) => row.key.startsWith("l3.retry."))).toEqual([]); + }); + + it("records retry state instead of success cooldown when persistence fails", async () => { + seedTriplet(); + const worldModel = { + ...handle.repos.worldModel, + insert: () => { + throw new Error("disk full"); + }, + }; + const result = await runL3( + { trigger: "manual", now: NOW }, + { + repos: { + policies: handle.repos.policies, + traces: handle.repos.traces, + worldModel, + kv: handle.repos.kv, + }, + llm: fakeLlm({ completeJson: { [OP]: validDraft } }), + log, + config: cfg({ cooldownDays: 1 }), + }, + ); + + expect(result.warnings.some((warning) => warning.stage === "insert")).toBe(true); + expect(handle.repos.kv.all().some((row) => row.key.startsWith("l3.retry."))).toBe(true); + expect(handle.repos.kv.all().some((row) => row.key.startsWith("l3.lastRun."))).toBe(false); }); it("adjustConfidence clamps in [0,1] and emits an event", async () => { From be07f5a848f07ee2e0ac61c59efc377c5344a129 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=81=E5=9C=A8=E5=90=B5=E7=9D=80=E5=90=83=E7=B3=96?= Date: Fri, 18 Sep 2026 14:37:59 +0800 Subject: [PATCH 06/38] fix(plugin): harden memory evolution and Hermes install --- .../adapters/hermes/README.md | 30 ++ .../core/memory/l3/ALGORITHMS.md | 14 +- .../core/memory/l3/README.md | 11 +- .../core/memory/l3/cluster.ts | 15 +- apps/memos-local-plugin/core/memory/l3/l3.ts | 77 +++- .../core/skill/ALGORITHMS.md | 5 +- apps/memos-local-plugin/core/skill/README.md | 7 +- .../core/skill/subscriber.ts | 83 ++-- .../core/storage/repos/trace-policy-links.ts | 10 + apps/memos-local-plugin/install.sh | 372 +++++++++++++++--- .../python/test_hermes_install_environment.py | 169 ++++++++ .../unit/install/hermes-provider-link.test.ts | 34 +- .../tests/unit/memory/l3/cluster.test.ts | 8 +- .../unit/memory/l3/l3.integration.test.ts | 57 +++ .../tests/unit/skill/subscriber.test.ts | 150 +++++++ 15 files changed, 935 insertions(+), 107 deletions(-) create mode 100644 apps/memos-local-plugin/tests/python/test_hermes_install_environment.py diff --git a/apps/memos-local-plugin/adapters/hermes/README.md b/apps/memos-local-plugin/adapters/hermes/README.md index 9f05755c9..f1b20b896 100644 --- a/apps/memos-local-plugin/adapters/hermes/README.md +++ b/apps/memos-local-plugin/adapters/hermes/README.md @@ -25,6 +25,36 @@ keepalive, reconnect generation, and host callback dispatch. All algorithm logic (L1/L2/L3, skills, retrieval, feedback, decision repair) remains in the shared TypeScript core. +## Desktop and custom Unix installations + +Use the backend source directory and Python environment used by the desktop +app, which may differ from the CLI installation. The Unix installer validates +`hermes_cli` and `plugins.memory.load_memory_provider` before stopping Hermes +or deploying the plugin. It checks literal Python/Bash launchers and the default +backend's `venv` and `.venv` directories. + +If auto-detection fails, use the updated `install.sh` with explicit paths: + +```bash +HERMES_INSTALL_DIR="/actual/path/to/hermes-agent" \ +HERMES_PYTHON="/actual/path/to/hermes-agent/venv/bin/python" \ +bash install.sh --agent hermes +``` + +`HERMES_INSTALL_DIR` is the backend source directory containing `hermes_cli` +and `plugins/memory`, not simply the `.app` bundle. `HERMES_PYTHON` must be the +interpreter that runs that backend. Explicit paths fail with diagnostic output +instead of falling back to another installation. Paths containing spaces work +when quoted. For a non-default data/config directory, also set `HERMES_HOME`; +it defaults to `~/.hermes`. The MemOS package/data location remains +`~/.hermes/memos-plugin` for compatibility with existing installations. + +If the chosen interpreter cannot import the host's memory provider API, repair +or update that Hermes environment. Creating an empty `plugins/memory` directory +does not supply the missing API. Restart the desktop app after installation. +Desktop distributions with unrecognized layouts require explicit paths; these +options do not imply that every desktop release has been tested. + ## Protocol surface The adapter calls the following methods on the bridge: diff --git a/apps/memos-local-plugin/core/memory/l3/ALGORITHMS.md b/apps/memos-local-plugin/core/memory/l3/ALGORITHMS.md index f84766cde..aceeb5a98 100644 --- a/apps/memos-local-plugin/core/memory/l3/ALGORITHMS.md +++ b/apps/memos-local-plugin/core/memory/l3/ALGORITHMS.md @@ -126,7 +126,11 @@ strict, high-gain clusters surface first. ## 4. Evidence packing -Per cluster we assemble a prompt payload: +Per cluster we assemble one or more prompt payloads. Policies are sorted +deterministically and split into batches of at most +`maxPoliciesPerCluster`; the limit bounds prompt size and never discards +cluster members. Batch drafts are then unioned into one draft before the +single merge/create decision. ``` { @@ -134,8 +138,8 @@ Per cluster we assemble a prompt payload: domain_tags: string[], avg_gain: number, avg_support: number, - policies: PolicyPrompt[], // up to |cluster|, each capped - evidence: TracePrompt[] // at most traceEvidencePerPolicy × |cluster| + policies: PolicyPrompt[], // up to maxPoliciesPerCluster, each capped + evidence: TracePrompt[] // at most traceEvidencePerPolicy × batch size } ``` @@ -144,8 +148,8 @@ Per cluster we assemble a prompt payload: * For each policy we fetch the most recent non-redacted supporting trace (by `episodeId`) and include up to `traceCharCap` characters of `userText + reflection`. Evidence is **read-only**, never mutated. -* Total token budget is bounded by `policyCharCap × |cluster| + - traceCharCap × evidencePerPolicy × |cluster|`, which is deterministic +* Per-call token budget is bounded by `policyCharCap × batchSize + + traceCharCap × evidencePerPolicy × batchSize`, which is deterministic and easy to debug. --- diff --git a/apps/memos-local-plugin/core/memory/l3/README.md b/apps/memos-local-plugin/core/memory/l3/README.md index b1a7341b0..1c0f5c021 100644 --- a/apps/memos-local-plugin/core/memory/l3/README.md +++ b/apps/memos-local-plugin/core/memory/l3/README.md @@ -37,8 +37,8 @@ l2.policy.induced ── triggers ──▶ attachL3Subscriber 2. cluster by (domainKey, centroid cosine ≥ similarity) 3. cooldown check per primary domain tag 4. for each cluster: - a. pack policies + a small evidence trace slice - b. `l3.abstraction` prompt → draft + a. split policies into prompt-sized batches without dropping members + b. `l3.abstraction` prompt per batch → one combined draft c. gather candidate WMs via findByDomainTag d. chooseMergeTarget(cluster, candidates, draft) ├── update: mergeForUpdate + updateBody + bump confidence @@ -61,6 +61,11 @@ No single step blocks reward/L2. Any LLM failure is captured as a cosine, so policies in the same bucket that are still semantically far apart (different sub-environments) end up in separate clusters. +`maxPoliciesPerCluster` is a prompt-size bound, not a retention bound. +Clusters larger than that value are processed in deterministic policy-id +batches. Their drafts are merged before persistence, so all source policy +and episode ids remain attached to a single world model. + ### Merge vs create Whenever a cluster's centroid cosine-matches an existing WM that shares @@ -146,7 +151,7 @@ See `algorithm.l3Abstraction` in | `traceEvidencePerPolicy` | `1` | Evidence traces per policy in the prompt. | | `useLlm` | `true` | Toggle the LLM abstractor off for tests. | | `cooldownDays` | `1` | Debounce per domain tag. | -| `maxPoliciesPerCluster` | `20` | Cap policies included in one abstraction prompt. | +| `maxPoliciesPerCluster` | `20` | Batch size for one abstraction prompt; overflow is retained. | | `confidenceDelta` | `0.05` | Confidence step per merge / feedback. | | `minConfidenceForRetrieval` | `0.2` | Tier-3 hide threshold. | diff --git a/apps/memos-local-plugin/core/memory/l3/cluster.ts b/apps/memos-local-plugin/core/memory/l3/cluster.ts index 7db92ed7b..b754d1253 100644 --- a/apps/memos-local-plugin/core/memory/l3/cluster.ts +++ b/apps/memos-local-plugin/core/memory/l3/cluster.ts @@ -189,20 +189,19 @@ export function clusterPolicies( continue; } - const capped = cohort + const ordered = cohort .slice() - .sort((a, b) => String(a.policy.id).localeCompare(String(b.policy.id))) - .slice(0, Math.max(1, config.maxPoliciesPerCluster ?? 20)); - if (capped.length < requiredPolicies) continue; + .sort((a, b) => String(a.policy.id).localeCompare(String(b.policy.id))); + if (ordered.length < requiredPolicies) continue; const tags = new Set(); - for (const m of capped) for (const t of m.tags) tags.add(t); + for (const m of ordered) for (const t of m.tags) tags.add(t); const avgGain = - capped.reduce((s, m) => s + m.policy.gain, 0) / Math.max(1, capped.length); + ordered.reduce((s, m) => s + m.policy.gain, 0) / Math.max(1, ordered.length); out.push({ key, - policies: capped.map((m) => m.policy), + policies: ordered.map((m) => m.policy), domainTags: Array.from(tags), centroidVec: center, avgGain, @@ -228,7 +227,6 @@ function clusterUntagged( config: ClusterDeps["config"], ): PolicyCluster[] { const requiredPolicies = Math.max(2, config.minPolicies); - const maxPolicies = Math.max(1, config.maxPoliciesPerCluster ?? 20); const groups: PolicyWithMeta[][] = []; for (const member of members @@ -237,7 +235,6 @@ function clusterUntagged( .sort((a, b) => String(a.policy.id).localeCompare(String(b.policy.id)))) { let target: PolicyWithMeta[] | undefined; for (const group of groups) { - if (group.length >= maxPolicies) continue; const center = centroid(group.map((m) => m.policy.vec ?? null)); if (center && member.policy.vec && cosine(center, member.policy.vec) >= config.clusterMinSimilarity) { target = group; diff --git a/apps/memos-local-plugin/core/memory/l3/l3.ts b/apps/memos-local-plugin/core/memory/l3/l3.ts index 8610db895..1b24c87a7 100644 --- a/apps/memos-local-plugin/core/memory/l3/l3.ts +++ b/apps/memos-local-plugin/core/memory/l3/l3.ts @@ -43,6 +43,9 @@ import { } from "./merge.js"; import type { AbstractionResult, + L3AbstractionDraft, + L3AbstractionDraftEntry, + L3AbstractionDraftResult, L3Config, L3Event, L3EventBus, @@ -171,10 +174,30 @@ export async function runL3( const triggerEpisodeId = input.episodeId ?? episodeIds[0]; const t0 = Date.now(); - const draftRes = await abstractDraft( - { cluster, evidenceByPolicy, episodeId: triggerEpisodeId }, - { llm: deps.llm, log: abstractLog, config }, - ); + const batchSize = Math.max(1, config.maxPoliciesPerCluster ?? 20); + const drafts: Array<{ draft: L3AbstractionDraft; policyCount: number }> = []; + let draftRes: L3AbstractionDraftResult | null = null; + for (let offset = 0; offset < cluster.policies.length; offset += batchSize) { + const batchPolicies = cluster.policies.slice(offset, offset + batchSize); + const batchPolicyIds = new Set(batchPolicies.map((policy) => policy.id)); + const batchEvidence = new Map( + Array.from(evidenceByPolicy.entries()).filter(([policyId]) => batchPolicyIds.has(policyId)), + ); + const batchCluster: PolicyCluster = { + ...cluster, + policies: batchPolicies, + }; + const batchResult = await abstractDraft( + { cluster: batchCluster, evidenceByPolicy: batchEvidence, episodeId: triggerEpisodeId }, + { llm: deps.llm, log: abstractLog, config }, + ); + if (!batchResult.ok) { + draftRes = batchResult; + break; + } + drafts.push({ draft: batchResult.draft, policyCount: batchPolicies.length }); + } + draftRes ??= { ok: true, draft: combineBatchDrafts(drafts) }; timings.abstract += Date.now() - t0; if (!draftRes.ok) { @@ -391,6 +414,52 @@ function worldModelVectorText(title: string, body: string): string { return [title.trim(), body.trim()].filter(Boolean).join("\n\n") || "(empty)"; } +function combineBatchDrafts( + drafts: readonly { draft: L3AbstractionDraft; policyCount: number }[], +): L3AbstractionDraft { + const first = drafts[0]!; + const weightedPolicyCount = drafts.reduce((sum, item) => sum + item.policyCount, 0); + return { + title: first.draft.title, + domainTags: dedupeStrings(drafts.flatMap((item) => item.draft.domainTags)), + environment: combineDraftEntries(drafts.flatMap((item) => item.draft.environment)), + inference: combineDraftEntries(drafts.flatMap((item) => item.draft.inference)), + constraints: combineDraftEntries(drafts.flatMap((item) => item.draft.constraints)), + body: dedupeStrings(drafts.map((item) => item.draft.body).filter(Boolean)).join("\n\n---\n\n"), + confidence: + drafts.reduce( + (sum, item) => sum + item.draft.confidence * item.policyCount, + 0, + ) / weightedPolicyCount, + supersedesWorldIds: Array.from( + new Set(drafts.flatMap((item) => item.draft.supersedesWorldIds ?? [])), + ), + }; +} + +function combineDraftEntries( + entries: readonly L3AbstractionDraftEntry[], +): L3AbstractionDraftEntry[] { + const combined = new Map(); + for (const entry of entries) { + const key = `${entry.label.trim().toLowerCase()}\u0000${entry.description.trim().toLowerCase()}`; + const previous = combined.get(key); + if (!previous) { + combined.set(key, { ...entry, evidenceIds: dedupeStrings(entry.evidenceIds ?? []) }); + continue; + } + previous.evidenceIds = dedupeStrings([ + ...(previous.evidenceIds ?? []), + ...(entry.evidenceIds ?? []), + ]); + } + return Array.from(combined.values()); +} + +function dedupeStrings(values: readonly string[]): string[] { + return Array.from(new Set(values.map((value) => value.trim()).filter(Boolean))); +} + function skipped( cluster: PolicyCluster, reason: Exclude, diff --git a/apps/memos-local-plugin/core/skill/ALGORITHMS.md b/apps/memos-local-plugin/core/skill/ALGORITHMS.md index e1560d926..f0f783553 100644 --- a/apps/memos-local-plugin/core/skill/ALGORITHMS.md +++ b/apps/memos-local-plugin/core/skill/ALGORITHMS.md @@ -285,7 +285,10 @@ still under trial. `cooldownMs` debounces repeat runs for the same policy triggered by rapid-fire upstream events (e.g. a burst of `reward.updated`). The -subscriber holds a simple in-memory `{policyId → lastRunAt}` table. +subscriber holds an in-memory `{policyId → lastRunAt}` table plus a pending +policy set. A reward event received during cooldown is coalesced and drained +when that policy becomes eligible; it is not silently discarded. Different +policies have independent cooldowns and queue entries. If `cooldownMs === 0` (as in unit tests), every event triggers a run. diff --git a/apps/memos-local-plugin/core/skill/README.md b/apps/memos-local-plugin/core/skill/README.md index 1c89d9808..b061d5af9 100644 --- a/apps/memos-local-plugin/core/skill/README.md +++ b/apps/memos-local-plugin/core/skill/README.md @@ -53,6 +53,11 @@ event-driven and every triggered run is fully async. Listener errors are captured so a bad downstream consumer can never break the orchestrator. +For `reward.updated`, the subscriber resolves only policies linked to the +updated episode (falling back to `sourceEpisodeIds` for legacy rows). Each +resolved policy receives its own queue entry and cooldown, so unrelated +policies neither trigger a global scan nor block one another. + ## Key concepts ### Eligibility @@ -201,7 +206,7 @@ See `algorithm.skill` in | `minSupport` | `2` | Min distinct-episode support to crystallize. | | `minGain` | `0.02` | Min policy gain required (paired with the new shrinkage-anchored gain in `core/memory/l2/gain.ts`). | | `candidateTrials` | `3` | Trials required to transition out of `candidate`. NOTE: legacy docs called this `probationaryTrials`; the schema field is `candidateTrials`. | -| `cooldownMs` | `21600000` | Debounce reward-triggered runs (6 hours; `0` disables). | +| `cooldownMs` | `21600000` | Per-policy debounce for reward-triggered runs (6 hours; `0` disables). | | `traceCharCap` | `600` | Char cap per evidence trace in the crystallize prompt.| | `evidenceLimit` | `4` | Max evidence traces per crystallize call. | | `useLlm` | `true` | Toggle the LLM off (tests / degraded mode). | diff --git a/apps/memos-local-plugin/core/skill/subscriber.ts b/apps/memos-local-plugin/core/skill/subscriber.ts index eccfafa9b..c827a8dfc 100644 --- a/apps/memos-local-plugin/core/skill/subscriber.ts +++ b/apps/memos-local-plugin/core/skill/subscriber.ts @@ -7,10 +7,10 @@ * - `l2.policy.induced` → `runSkill({ trigger, policyId })` * - `l2.policy.status_changed` → `runSkill({ trigger, policyId })` when * the new status is `active` - * - `reward.updated` → `runSkill({ trigger: "reward.updated" })` - * — evaluates every policy referenced by - * the updated episode. Also drives the η - * drift adjustment on existing skills. + * - `reward.updated` → one scoped run per policy linked to the + * updated episode. Each policy has its own + * cooldown and pending queue entry. Also + * drives η adjustment on existing skills. * * The handle returns `runOnce` for manual runs (used by the CLI / viewer * rebuild button) and `applyFeedback` for explicit skill feedback. @@ -33,7 +33,7 @@ import type { SkillFeedbackKind, SkillTrigger, } from "./types.js"; -import type { SkillId } from "../types.js"; +import type { PolicyId, SkillId } from "../types.js"; import { now as nowMs } from "../time.js"; import { IDLE_ARCHIVE_BATCH_LIMIT } from "../storage/repos/skills.js"; @@ -79,14 +79,18 @@ export function attachSkillSubscriber( }; let inflight: Promise | null = null; - let lastRewardRunAt: number | null = null; - let queued: { trigger: SkillTrigger; hint?: { policyId?: string; skillId?: SkillId } } | null = - null; + let disposed = false; + let rewardTimer: ReturnType | null = null; + const lastRewardRunAt = new Map(); + const pendingRewardPolicies = new Set(); + const queued: Array<{ + trigger: SkillTrigger; + hint?: { policyId?: PolicyId; skillId?: SkillId }; + }> = []; async function drain(): Promise { - while (queued) { - const next = queued; - queued = null; + while (queued.length > 0) { + const next = queued.shift()!; try { await runSkill( { trigger: next.trigger, policyId: next.hint?.policyId, skillId: next.hint?.skillId }, @@ -103,9 +107,9 @@ export function attachSkillSubscriber( function triggerRun( trigger: SkillTrigger, - hint?: { policyId?: string; skillId?: SkillId }, + hint?: { policyId?: PolicyId; skillId?: SkillId }, ): void { - queued = { trigger, hint }; + queued.push({ trigger, hint }); if (inflight) { log.debug("skill.run.queued", { trigger }); return; @@ -116,18 +120,39 @@ export function attachSkillSubscriber( inflight = promise; } - function triggerRewardRun(): void { + function scheduleRewardRuns(): void { + if (disposed) return; + if (rewardTimer) { + clearTimeout(rewardTimer); + rewardTimer = null; + } const cooldownMs = Math.max(0, deps.config.cooldownMs); const at = nowMs(); - if (cooldownMs > 0 && lastRewardRunAt !== null && at - lastRewardRunAt < cooldownMs) { - log.debug("skill.run.cooldown", { - trigger: "reward.updated", - remainingMs: cooldownMs - (at - lastRewardRunAt), - }); - return; + let nextDelay: number | null = null; + for (const policyId of pendingRewardPolicies) { + const lastRunAt = lastRewardRunAt.get(policyId); + const remainingMs = lastRunAt === undefined ? 0 : cooldownMs - (at - lastRunAt); + if (remainingMs > 0) { + nextDelay = nextDelay === null ? remainingMs : Math.min(nextDelay, remainingMs); + log.debug("skill.run.cooldown", { + trigger: "reward.updated", + policyId, + remainingMs, + }); + continue; + } + pendingRewardPolicies.delete(policyId); + lastRewardRunAt.set(policyId, at); + triggerRun("reward.updated", { policyId }); } - lastRewardRunAt = at; - triggerRun("reward.updated"); + if (nextDelay !== null && pendingRewardPolicies.size > 0) { + rewardTimer = setTimeout(scheduleRewardRuns, nextDelay); + } + } + + function triggerRewardRuns(policyIds: readonly PolicyId[]): void { + for (const policyId of policyIds) pendingRewardPolicies.add(policyId); + scheduleRewardRuns(); } const offInduced = deps.l2Bus.on("l2.policy.induced", (evt: L2Event) => { @@ -149,10 +174,22 @@ export function attachSkillSubscriber( episodeId: evt.result.episodeId, }); resolveTrialsForReward(evt); - triggerRewardRun(); + const linkedPolicyIds = deps.repos.tracePolicyLinks.getLinkedPolicyIds(evt.result.episodeId); + const sourceEpisodePolicyIds = deps.repos.policies + .list({ status: "active", limit: 200 }) + .filter((policy) => policy.sourceEpisodeIds.includes(evt.result.episodeId)) + .map((policy) => policy.id); + const relatedPolicyIds = Array.from( + new Set([...linkedPolicyIds, ...sourceEpisodePolicyIds]), + ); + triggerRewardRuns(relatedPolicyIds); }); function dispose(): void { + disposed = true; + if (rewardTimer) clearTimeout(rewardTimer); + rewardTimer = null; + pendingRewardPolicies.clear(); offInduced(); offStatus(); offReward(); diff --git a/apps/memos-local-plugin/core/storage/repos/trace-policy-links.ts b/apps/memos-local-plugin/core/storage/repos/trace-policy-links.ts index a3c443a9c..6c20bdc86 100644 --- a/apps/memos-local-plugin/core/storage/repos/trace-policy-links.ts +++ b/apps/memos-local-plugin/core/storage/repos/trace-policy-links.ts @@ -24,6 +24,12 @@ export function makeTracePolicyLinksRepo(db: StorageDb) { WHERE policy_id=@policy_id ORDER BY episode_id`, ); + const selectPolicyIds = db.prepare<{ episode_id: EpisodeId }, { policy_id: PolicyId }>( + `SELECT DISTINCT policy_id + FROM trace_policy_links + WHERE episode_id=@episode_id + ORDER BY policy_id`, + ); return { link(args: { @@ -47,5 +53,9 @@ export function makeTracePolicyLinksRepo(db: StorageDb) { getLinkedEpisodeIds(policyId: PolicyId): EpisodeId[] { return selectEpisodeIds.all({ policy_id: policyId }).map((r) => r.episode_id); }, + + getLinkedPolicyIds(episodeId: EpisodeId): PolicyId[] { + return selectPolicyIds.all({ episode_id: episodeId }).map((r) => r.policy_id); + }, }; } diff --git a/apps/memos-local-plugin/install.sh b/apps/memos-local-plugin/install.sh index 4e96ba2e9..eb30bff68 100755 --- a/apps/memos-local-plugin/install.sh +++ b/apps/memos-local-plugin/install.sh @@ -135,6 +135,12 @@ Usage: "all" keeps its existing meaning: installed OpenClaw + Hermes targets. Select DSH explicitly with --agent dsh. +Hermes desktop/custom installs (environment variables): + HERMES_INSTALL_DIR Actual Hermes backend source directory + HERMES_PYTHON Python executable used by that Hermes installation + HERMES_HOME Hermes data/config directory (default: ~/.hermes) +Paths containing spaces are supported; quote environment variable values. + Each agent runs its viewer on a fixed port: openclaw → http://127.0.0.1:${OPENCLAW_PORT} hermes → http://127.0.0.1:${HERMES_PORT} @@ -229,7 +235,10 @@ HAS_OPENCLAW="false" HAS_HERMES="false" HAS_DSH="false" [[ -d "${HOME}/.openclaw" ]] && HAS_OPENCLAW="true" -[[ -d "${HOME}/.hermes" ]] && HAS_HERMES="true" +if [[ -d "${HERMES_HOME:-${HOME}/.hermes}" || -n "${HERMES_INSTALL_DIR:-}" || -n "${HERMES_PYTHON:-}" ]] \ + || command -v hermes >/dev/null 2>&1; then + HAS_HERMES="true" +fi find_openclaw_cli() { command -v openclaw 2>/dev/null && return 0 @@ -301,8 +310,15 @@ SOURCE_KIND="" # "path" for a local file, "npm" otherwise SOURCE_SPEC="" GATEWAY_RECOVERY_BIN="" GATEWAY_RECOVERY_STATE="inactive" +HERMES_STAGED_PREFIX="" +HERMES_PREFIX_BACKUP_ROOT="" +HERMES_LIVE_PREFIX="" +HERMES_PREFIX_SWAPPED="false" cleanup_install_state() { + if declare -F rollback_hermes_install >/dev/null 2>&1; then + rollback_hermes_install + fi if [[ "${GATEWAY_RECOVERY_STATE:-inactive}" == "needs_recovery" \ && -n "${GATEWAY_RECOVERY_BIN:-}" ]]; then local recovery_out="" @@ -744,15 +760,263 @@ NODE return 1 } +# Probe only: do not stop processes or write host files until this succeeds. +# The bootstrap Python uses only the standard library; each candidate is +# validated in its own interpreter, independently of the bootstrap environment. +resolve_hermes_environment() { + local bootstrap="${HERMES_PYTHON:-$(command -v python3 || true)}" + [[ -x "${bootstrap}" ]] || { printf '%s\n' "Cannot run Python: ${bootstrap}. Set HERMES_PYTHON to the Hermes interpreter." >&2; return 1; } + "${bootstrap}" - <<'PY' +import os +import shlex +import shutil +import subprocess +import sys +from pathlib import Path + + +def absolute(value): + return Path(os.path.abspath(os.path.expanduser(value))) + + +explicit_root = os.environ.get("HERMES_INSTALL_DIR", "") +explicit_python = os.environ.get("HERMES_PYTHON", "") +host_home = absolute(os.environ.get("HERMES_HOME") or str(Path.home() / ".hermes")) +roots = [] +candidates = [] + + +def add_root(root): + root = absolute(str(root)) + if root not in roots: + roots.append(root) + + +def add_python(python, root=None): + # Do not resolve the Python symlink: that would escape its virtualenv. + pair = (str(absolute(str(python))), str(root) if root else "") + if pair not in candidates: + candidates.append(pair) + + +if explicit_root: + add_root(explicit_root) +else: + launchers = [shutil.which("hermes"), str(Path.home() / ".local/bin/hermes")] + for launcher in launchers: + if not launcher or not Path(launcher).is_file(): + continue + entry = Path(launcher).resolve() + for parent in entry.parents: + if (parent / "hermes_cli").is_dir(): + add_root(parent) + break + try: + lines = entry.read_text().splitlines() + except (OSError, UnicodeError): + continue + for line in lines: + try: + words = shlex.split(line[2:] if line.startswith("#!") else line) + except ValueError: + continue + # Recognize literal Python shebangs and official `exec "...python"` + # launchers. Never source/eval a wrapper or expand shell expressions. + value = words[1] if len(words) > 1 and words[0] == "exec" else ( + words[0] if words and line.startswith("#!") else "" + ) + if not value.startswith("/") or not Path(value).name.startswith("python"): + continue + python = absolute(value) + root = next((p for p in python.parents if (p / "hermes_cli").is_dir()), None) + if root: + add_root(root) + if not explicit_python: + add_python(python, root) + add_root(host_home / "hermes-agent") + +if explicit_python: + candidates = [] + for root in roots: + add_python(explicit_python, root) + if not explicit_root: + add_python(explicit_python) +else: + for root in roots: + for venv in ("venv", ".venv"): + for name in ("python", "python3"): + add_python(root / venv / "bin" / name, root) + # A PATH interpreter is acceptable only if it really imports the host API. + # Do not combine a system interpreter with a guessed source checkout. + if not explicit_root: + for name in ("python3", "python"): + value = shutil.which(name) + if value: + add_python(value) + +probe = ''' +import sys +from pathlib import Path +if sys.argv[1]: + sys.path.insert(0, sys.argv[1]) +import hermes_cli +import plugins.memory as memory +from plugins.memory import load_memory_provider +if not callable(load_memory_provider): + raise ImportError("Hermes load_memory_provider is not callable") +directory = Path(memory.__file__).resolve().parent +if sys.argv[1] and directory != Path(sys.argv[1]).resolve() / "plugins" / "memory": + raise ImportError("Memory API resolved outside the selected Hermes source directory") +print(directory) +print(directory.parent.parent) +''' +child_env = {k: v for k, v in os.environ.items() if k not in ("PYTHONPATH", "PYTHONHOME")} +for python, root in candidates: + if not os.access(python, os.X_OK): + print("Not executable: " + python, file=sys.stderr) + continue + try: + result = subprocess.run( + [python, "-c", probe, root], env=child_env, cwd="/", + capture_output=True, text=True, timeout=15, + ) + except (OSError, subprocess.TimeoutExpired) as exc: + print("Cannot probe {}: {}".format(python, exc), file=sys.stderr) + continue + paths = result.stdout.strip().splitlines() + if result.returncode == 0 and len(paths) == 2 and Path(paths[0]).is_dir(): + print(python) + print("\n".join(paths)) + sys.exit(0) + print("Hermes import failed using {} (root: {}):\n{}".format( + python, root or "interpreter default", result.stderr.strip() or result.stdout.strip() + ), file=sys.stderr) +print("Cannot locate a compatible Hermes environment. Set HERMES_INSTALL_DIR to the actual " + "backend source directory and HERMES_PYTHON to its Python executable. " + "HERMES_HOME is the data/config directory, not the application bundle. " + "If imports still fail, repair/update that Hermes environment first.", file=sys.stderr) +sys.exit(1) +PY +} + # ─── Hermes install ─────────────────────────────────────────────────────── +HERMES_PROVIDER_BACKUP_DIR="" +HERMES_PROVIDER_BACKUP_TARGETS=() +HERMES_PROVIDER_BACKUP_PATHS=() + +rollback_hermes_install() { + if ((${#HERMES_PROVIDER_BACKUP_TARGETS[@]} > 0)); then + restore_hermes_provider_targets + fi + if [[ "${HERMES_PREFIX_SWAPPED}" == "true" \ + && "${HERMES_LIVE_PREFIX:-}" == "${HOME}/.hermes/memos-plugin" ]]; then + if [[ -d "${HERMES_LIVE_PREFIX}" ]]; then + rm -rf "${HERMES_LIVE_PREFIX}" + fi + if [[ -d "${HERMES_PREFIX_BACKUP_ROOT:-}" && -d "${HERMES_PREFIX_BACKUP_ROOT}/live" ]]; then + mv "${HERMES_PREFIX_BACKUP_ROOT}/live" "${HERMES_LIVE_PREFIX}" \ + || warn "Failed to restore the previous Hermes plugin prefix." + fi + fi + if [[ -n "${HERMES_STAGED_PREFIX:-}" && -d "${HERMES_STAGED_PREFIX}" ]]; then + rm -rf "${HERMES_STAGED_PREFIX}" + fi + if [[ -n "${HERMES_PREFIX_BACKUP_ROOT:-}" && -d "${HERMES_PREFIX_BACKUP_ROOT}" ]]; then + rm -rf "${HERMES_PREFIX_BACKUP_ROOT}" + fi + HERMES_STAGED_PREFIX="" + HERMES_PREFIX_BACKUP_ROOT="" + HERMES_LIVE_PREFIX="" + HERMES_PREFIX_SWAPPED="false" +} + +restore_hermes_provider_targets() { + local index target backup + for ((index=${#HERMES_PROVIDER_BACKUP_TARGETS[@]}-1; index>=0; index--)); do + target="${HERMES_PROVIDER_BACKUP_TARGETS[index]}" + backup="${HERMES_PROVIDER_BACKUP_PATHS[index]}" + if [[ -L "${target}" ]]; then + rm -f "${target}" + elif [[ -e "${target}" ]]; then + warn "Cannot restore Hermes provider target because it changed after installation: ${target}" + continue + fi + if [[ -e "${backup}" || -L "${backup}" ]]; then + mv "${backup}" "${target}" || warn "Failed to restore Hermes provider target: ${target}" + fi + done + if [[ -n "${HERMES_PROVIDER_BACKUP_DIR}" && -d "${HERMES_PROVIDER_BACKUP_DIR}" ]]; then + rm -rf "${HERMES_PROVIDER_BACKUP_DIR}" + fi + HERMES_PROVIDER_BACKUP_DIR="" + HERMES_PROVIDER_BACKUP_TARGETS=() + HERMES_PROVIDER_BACKUP_PATHS=() +} + +prepare_hermes_provider_targets() { + local backup_root="$1" + shift + HERMES_PROVIDER_BACKUP_DIR="$(mktemp -d "${TMPDIR:-/tmp}/memos-hermes-provider.XXXXXX")" \ + || die "Unable to create a Hermes provider rollback directory." + local index=0 target backup + for target in "$@"; do + backup="" + if [[ -e "${target}" || -L "${target}" ]]; then + backup="${HERMES_PROVIDER_BACKUP_DIR}/target-${index}" + mv "${target}" "${backup}" \ + || { restore_hermes_provider_targets; die "Unable to back up Hermes provider target: ${target}"; } + fi + HERMES_PROVIDER_BACKUP_TARGETS+=("${target}") + HERMES_PROVIDER_BACKUP_PATHS+=("${backup}") + ln -sfn "${backup_root}" "${target}" \ + || { restore_hermes_provider_targets; die "Unable to link Hermes memtensor provider: ${target}"; } + success "Symlinked → ${target}" + index=$((index + 1)) + done +} + install_hermes() { STEP_CURRENT=0 header "Hermes Install" + step "Locating and validating Hermes Python environment" + local resolved python_bin plugin_dir hermes_source + resolved="$(resolve_hermes_environment)" || die "Hermes preflight failed; host files and processes were not changed." + python_bin="$(printf '%s\n' "${resolved}" | sed -n '1p')" + plugin_dir="$(printf '%s\n' "${resolved}" | sed -n '2p')" + hermes_source="$(printf '%s\n' "${resolved}" | sed -n '3p')" + success "Python: ${python_bin}" + success "plugins/memory: ${plugin_dir}" + # Keep all subsequent Python operations in the validated host context. + local PYTHONPATH="${hermes_source}" PYTHONHOME="" + export PYTHONPATH PYTHONHOME + local hermes_host_home="${HERMES_HOME:-${HOME}/.hermes}" local prefix="${HOME}/.hermes/memos-plugin" + local config_file="${hermes_host_home}/config.yaml" + HERMES_LIVE_PREFIX="${prefix}" + mkdir -p "${HOME}/.hermes" + HERMES_STAGED_PREFIX="$(mktemp -d "${HOME}/.hermes/.memos-plugin-stage.XXXXXX")" \ + || die "Unable to create a staged Hermes plugin directory." + local staged_prefix="${HERMES_STAGED_PREFIX}" local home="${prefix}" - local config_file="${HOME}/.hermes/config.yaml" local adapter_dir="${prefix}/adapters/hermes" - mkdir -p "${HOME}/.hermes" + local staged_adapter_dir="${staged_prefix}/adapters/hermes" + deploy_tarball_to_prefix "${staged_prefix}" + + step "Preparing staged Hermes runtime" + ensure_runtime_home "hermes" "${staged_prefix}" "${staged_prefix}" + local staged_bridge_entry="${staged_prefix}/dist/bridge.cjs" + [[ -f "${staged_bridge_entry}" ]] || staged_bridge_entry="${staged_prefix}/bridge.cts" + echo "${prefix}/dist/bridge.cjs" > "${staged_adapter_dir}/bridge_path.txt" + [[ -f "${staged_adapter_dir}/plugin.yaml" ]] || die "Staged Hermes adapter manifest is missing." + local staged_version_sync="${staged_prefix}/scripts/sync-hermes-version.cjs" + if [[ -f "${staged_version_sync}" ]]; then + node "${staged_version_sync}" "${staged_prefix}" >/dev/null \ + || die "Failed to synchronize staged Hermes plugin version metadata." + else + warn "Hermes version sync helper missing; using packaged plugin.yaml as-is." + fi + cp "${staged_adapter_dir}/plugin.yaml" "${staged_adapter_dir}/memos_provider/plugin.yaml" 2>/dev/null \ + || die "Failed to prepare the staged memtensor provider." step "Stopping existing bridge daemon" local bridge_pids="" @@ -792,49 +1056,41 @@ install_hermes() { fi fi - deploy_tarball_to_prefix "${prefix}" - - step "Configuring runtime environment" - ensure_runtime_home "hermes" "${home}" "${prefix}" + # Copy user data only after the host processes are stopped. The old prefix + # remains intact until the staged prefix has been handed off successfully. + step "Handing off staged Hermes runtime" + local preserved_item + local preserved_items=(data logs skills daemon .migrations config.yaml .auth.json) + mkdir -p "${prefix%/*}" + for preserved_item in "${preserved_items[@]}"; do + if [[ -e "${prefix}/${preserved_item}" ]]; then + rm -rf "${staged_prefix:?}/${preserved_item}" + cp -a "${prefix}/${preserved_item}" "${staged_prefix}/${preserved_item}" \ + || die "Failed to stage Hermes runtime data: ${preserved_item}" + fi + done + HERMES_PREFIX_BACKUP_ROOT="$(mktemp -d "${HOME}/.hermes/.memos-plugin-backup.XXXXXX")" \ + || die "Unable to create a Hermes rollback directory." + if [[ -d "${prefix}" ]]; then + mv "${prefix}" "${HERMES_PREFIX_BACKUP_ROOT}/live" \ + || die "Unable to move the existing Hermes plugin prefix into rollback storage." + fi + HERMES_PREFIX_SWAPPED="true" + mv "${staged_prefix}" "${prefix}" \ + || { rollback_hermes_install; die "Unable to activate the staged Hermes plugin prefix."; } + HERMES_STAGED_PREFIX="" + adapter_dir="${prefix}/adapters/hermes" + home="${prefix}" + staged_bridge_entry="" + success "Staged Hermes runtime activated" local bridge_entry="${prefix}/dist/bridge.cjs" [[ -f "${bridge_entry}" ]] || bridge_entry="${prefix}/bridge.cts" echo "${bridge_entry}" > "${adapter_dir}/bridge_path.txt" success "Bridge path recorded" - step "Locating Hermes Python environment" - local python_bin="" - if command -v hermes >/dev/null 2>&1; then - local shebang; shebang="$(head -1 "$(command -v hermes)" 2>/dev/null || true)" - [[ "${shebang}" == "#!"*python* ]] && python_bin="$(echo "${shebang}" | sed 's/^#!\s*//')" - fi - if [[ -z "${python_bin}" || ! -x "${python_bin}" ]] \ - && [[ -x "${HOME}/.hermes/hermes-agent/venv/bin/python3" ]]; then - python_bin="${HOME}/.hermes/hermes-agent/venv/bin/python3" - fi - [[ -z "${python_bin}" || ! -x "${python_bin}" ]] && python_bin="$(command -v python3 || true)" - [[ -n "${python_bin}" && -x "${python_bin}" ]] || die "Cannot locate Python for Hermes." - success "Python: ${python_bin}" - - local plugin_dir="" - plugin_dir="$("${python_bin}" -c " -from pathlib import Path -try: - import plugins.memory as pm - print(Path(pm.__file__).parent) -except Exception: - pass -" 2>/dev/null || true)" - if [[ -z "${plugin_dir}" || ! -d "${plugin_dir}" ]]; then - for d in "${HOME}/.hermes/hermes-agent/plugins/memory"; do - [[ -d "${d}" && -f "${d}/__init__.py" ]] && { plugin_dir="${d}"; break; } - done - fi - [[ -n "${plugin_dir}" && -d "${plugin_dir}" ]] || die "plugins/memory not found" - success "plugins/memory: ${plugin_dir}" - step "Linking memtensor provider" - local user_plugin_dir="${HOME}/.hermes/plugins/memory" + local user_plugin_dir="${hermes_host_home}/plugins/memory" mkdir -p "${user_plugin_dir}" local version_sync="${prefix}/scripts/sync-hermes-version.cjs" if [[ -f "${version_sync}" ]]; then @@ -843,20 +1099,13 @@ except Exception: else warn "Hermes version sync helper missing; using packaged plugin.yaml as-is." fi - # Ensure the provider directory is fully populated before symlinking so - # the second symlink (user-level) already points at a complete tree. - cp "${adapter_dir}/plugin.yaml" "${adapter_dir}/memos_provider/plugin.yaml" 2>/dev/null || true + # The provider directory was populated while the package was staged, before + # any host link was changed. local provider_targets=( "${plugin_dir}/memtensor" "${user_plugin_dir}/memtensor" ) - local target - for target in "${provider_targets[@]}"; do - # Use `ln -sfn` for atomic, idempotent replace; matches install.hermes.sh. - if [[ -e "${target}" && ! -L "${target}" ]]; then rm -rf "${target}"; fi - ln -sfn "${adapter_dir}/memos_provider" "${target}" - success "Symlinked → ${target}" - done + prepare_hermes_provider_targets "${adapter_dir}/memos_provider" "${provider_targets[@]}" step "Verifying provider & patching config" local verify @@ -865,8 +1114,13 @@ from plugins.memory import load_memory_provider p = load_memory_provider('memtensor') print('OK' if p and p.name == 'memtensor' else 'FAIL') " 2>/dev/null || true)" - [[ "${verify}" == "OK" ]] && success "Provider verification passed" \ - || warn "Provider verification didn't return OK" + if [[ "${verify}" == "OK" ]]; then + success "Provider verification passed" + else + restore_hermes_provider_targets + rollback_hermes_install + die "Hermes memtensor provider verification failed. Existing provider targets and plugin prefix were restored." + fi step "Installing Hermes profile defaults hook" "${python_bin}" - <<'PYEOF' || warn "Hermes profile defaults hook install failed" @@ -1015,7 +1269,7 @@ PYEOF if [[ -f "${config_file}" ]]; then local patched_configs - patched_configs="$("${python_bin}" - "${HOME}/.hermes" 2>/dev/null <<'PYEOF' + patched_configs="$("${python_bin}" - "${hermes_host_home}" 2>/dev/null <<'PYEOF' import sys from pathlib import Path @@ -1133,6 +1387,20 @@ CFGEOF else printf " ${DIM}Next:${NC} ${BOLD}hermes chat${NC}\n" fi + # Keep rollback material until the daemon smoke test and all post-swap + # configuration work have completed successfully. + if [[ -n "${HERMES_PROVIDER_BACKUP_DIR}" ]]; then + rm -rf "${HERMES_PROVIDER_BACKUP_DIR}" + fi + if [[ -n "${HERMES_PREFIX_BACKUP_ROOT}" && -d "${HERMES_PREFIX_BACKUP_ROOT}" ]]; then + rm -rf "${HERMES_PREFIX_BACKUP_ROOT}" + fi + HERMES_PROVIDER_BACKUP_DIR="" + HERMES_PROVIDER_BACKUP_TARGETS=() + HERMES_PROVIDER_BACKUP_PATHS=() + HERMES_PREFIX_BACKUP_ROOT="" + HERMES_LIVE_PREFIX="" + HERMES_PREFIX_SWAPPED="false" return 0 } diff --git a/apps/memos-local-plugin/tests/python/test_hermes_install_environment.py b/apps/memos-local-plugin/tests/python/test_hermes_install_environment.py new file mode 100644 index 000000000..978c5677f --- /dev/null +++ b/apps/memos-local-plugin/tests/python/test_hermes_install_environment.py @@ -0,0 +1,169 @@ +"""Execute Unix installer preflight against isolated Hermes layouts.""" + +import os +import subprocess +import sys + +from pathlib import Path + + +INSTALLER = Path(__file__).resolve().parents[2] / "install.sh" + + +def fixture_host(root: Path, env_name: str = "venv") -> Path: + for module in ("hermes_cli", "plugins", "plugins/memory"): + directory = root / module + directory.mkdir(parents=True, exist_ok=True) + (directory / "__init__.py").write_text( + "def load_memory_provider(name): return None\n" if module == "plugins/memory" else "" + ) + python = root / env_name / "bin/python" + python.parent.mkdir(parents=True) + python.symlink_to(sys.executable) + return python + + +def probe(tmp_path: Path, **overrides: str) -> subprocess.CompletedProcess: + source = INSTALLER.read_text() + start = source.find("resolve_hermes_environment() {") + assert start >= 0, "installer needs a validated Hermes environment resolver" + end = source.index("# ─── Hermes install", start) + env = {k: v for k, v in os.environ.items() if not k.startswith("HERMES_")} + env.update(HOME=str(tmp_path), PATH="/usr/bin:/bin") + env.update(overrides) + script = source[start:end] + "\nresolve_hermes_environment\n" + return subprocess.run( + ["/bin/bash", "-c", script], + cwd=tmp_path, + env=env, + capture_output=True, + text=True, + check=False, + timeout=30, + ) + + +def test_default_layout(tmp_path: Path) -> None: + root = tmp_path / ".hermes/hermes-agent" + python = fixture_host(root) + result = probe(tmp_path) + assert result.returncode == 0, result.stderr + assert result.stdout.splitlines() == [str(python), str(root / "plugins/memory"), str(root)] + + +def test_explicit_desktop_root_with_spaces(tmp_path: Path) -> None: + root = tmp_path / "Library/Application Support/Desktop/backend" + python = fixture_host(root, ".venv") + result = probe(tmp_path, HERMES_INSTALL_DIR=str(root)) + assert result.returncode == 0, result.stderr + assert result.stdout.splitlines()[0] == str(python) + + +def test_bash_launcher_with_spaces(tmp_path: Path) -> None: + root = tmp_path / "Desktop backend" + python = fixture_host(root) + cli = tmp_path / ".local/bin/hermes" + cli.parent.mkdir(parents=True) + cli.write_text(f'#!/usr/bin/env bash\nexec "{python}" "{root}/hermes" "$@"\n') + cli.chmod(0o755) + result = probe(tmp_path) + assert result.returncode == 0, result.stderr + assert result.stdout.splitlines()[0] == str(python) + + +def test_custom_data_home(tmp_path: Path) -> None: + home = tmp_path / "custom home" + root = home / "hermes-agent" + fixture_host(root) + result = probe(tmp_path, HERMES_HOME=str(home)) + assert result.returncode == 0, result.stderr + assert result.stdout.splitlines()[2] == str(root) + + +def test_explicit_python_and_root(tmp_path: Path) -> None: + root = tmp_path / "desktop source" + fixture_host(root) + result = probe(tmp_path, HERMES_INSTALL_DIR=str(root), HERMES_PYTHON=sys.executable) + assert result.returncode == 0, result.stderr + assert result.stdout.splitlines()[0] == sys.executable + + +def test_invalid_override_does_not_fall_back(tmp_path: Path) -> None: + fixture_host(tmp_path / ".hermes/hermes-agent") + result = probe(tmp_path, HERMES_PYTHON=str(tmp_path / "missing-python")) + assert result.returncode != 0 + assert "missing-python" in result.stderr + assert "HERMES_PYTHON" in result.stderr + + +def test_missing_host_api_keeps_import_error(tmp_path: Path) -> None: + root = tmp_path / "old-hermes" + fixture_host(root) + (root / "plugins/memory/__init__.py").write_text( + "raise ImportError('missing host dependency')\n" + ) + result = probe(tmp_path, HERMES_INSTALL_DIR=str(root)) + assert result.returncode != 0 + assert "missing host dependency" in result.stderr + assert "HERMES_INSTALL_DIR" in result.stderr + + +def test_environment_is_checked_before_install_side_effects() -> None: + source = INSTALLER.read_text() + body = source[source.index("install_hermes() {") :] + assert body.index("resolve_hermes_environment") < body.index("Stopping existing bridge daemon") + assert body.index("resolve_hermes_environment") < body.index("deploy_tarball_to_prefix") + + +def test_incompatible_host_api_is_rejected(tmp_path: Path) -> None: + root = tmp_path / "old-hermes" + fixture_host(root) + (root / "plugins/memory/__init__.py").write_text("") + result = probe(tmp_path, HERMES_INSTALL_DIR=str(root)) + assert result.returncode != 0 + assert "load_memory_provider" in result.stderr + + +def test_python_shebang_launcher(tmp_path: Path) -> None: + root = tmp_path / "custom-host" + python = fixture_host(root) + cli = tmp_path / ".local/bin/hermes" + cli.parent.mkdir(parents=True) + cli.write_text(f"#!{python}\n") + cli.chmod(0o755) + result = probe(tmp_path) + assert result.returncode == 0, result.stderr + assert result.stdout.splitlines()[0] == str(python) + + +def test_failed_preflight_does_not_stop_or_deploy(tmp_path: Path) -> None: + source = INSTALLER.read_text() + start = source.index("resolve_hermes_environment() {") + end = source.index("# ─── Main", start) + script = ( + """ +header() { :; } +step() { :; } +die() { printf '%s\\n' "$*" >&2; exit 1; } +pgrep() { echo unexpected-process-probe >&2; exit 99; } +deploy_tarball_to_prefix() { echo unexpected-deployment >&2; exit 99; } +""" + + source[start:end] + + "\ninstall_hermes\n" + ) + result = subprocess.run( + ["/bin/bash", "-c", script], + env={ + "HOME": str(tmp_path), + "PATH": "/usr/bin:/bin", + "HERMES_PYTHON": str(tmp_path / "missing"), + }, + capture_output=True, + text=True, + check=False, + timeout=30, + ) + assert result.returncode != 0 + assert "preflight failed" in result.stderr + assert "unexpected-" not in result.stderr + assert not (tmp_path / ".hermes").exists() diff --git a/apps/memos-local-plugin/tests/unit/install/hermes-provider-link.test.ts b/apps/memos-local-plugin/tests/unit/install/hermes-provider-link.test.ts index 6943c4807..ffa33f0a0 100644 --- a/apps/memos-local-plugin/tests/unit/install/hermes-provider-link.test.ts +++ b/apps/memos-local-plugin/tests/unit/install/hermes-provider-link.test.ts @@ -8,11 +8,33 @@ describe("Hermes provider install links", () => { it("main Unix installer links both checkout-local and user-level provider paths", () => { const source = readFileSync(path.join(repoRoot, "install.sh"), "utf8"); - expect(source).toContain('${HOME}/.hermes/plugins/memory'); + expect(source).toContain('local hermes_host_home="${HERMES_HOME:-${HOME}/.hermes}"'); + expect(source).toContain('${hermes_host_home}/plugins/memory'); expect(source).toContain('"${plugin_dir}/memtensor"'); expect(source).toContain('"${user_plugin_dir}/memtensor"'); }); + it("fails closed and restores provider targets when live verification fails", () => { + const source = readFileSync(path.join(repoRoot, "install.sh"), "utf8"); + + expect(source).toContain("restore_hermes_provider_targets"); + expect(source).toContain('die "Hermes memtensor provider verification failed.'); + expect(source).not.toContain('if [[ -e "${target}" && ! -L "${target}" ]]; then rm -rf "${target}"; fi'); + }); + + it("stages the Hermes package before stopping the host and can roll back the prefix", () => { + const source = readFileSync(path.join(repoRoot, "install.sh"), "utf8"); + const hermesStart = source.indexOf("install_hermes() {"); + const hermesEnd = source.indexOf("# ─── DSH install", hermesStart); + const hermesSource = source.slice(hermesStart, hermesEnd); + + expect(hermesSource).toContain('deploy_tarball_to_prefix "${staged_prefix}"'); + expect(hermesSource).toContain("rollback_hermes_install"); + expect(hermesSource.indexOf('deploy_tarball_to_prefix "${staged_prefix}"')).toBeLessThan( + hermesSource.indexOf('step "Stopping existing bridge daemon"'), + ); + }); + it("adapter Unix installer keeps a user-level provider link", () => { const source = readFileSync( path.join(repoRoot, "adapters/hermes/install.hermes.sh"), @@ -142,12 +164,14 @@ describe("Hermes provider install links", () => { it("main Unix installer uses atomic ln -sfn and prepares provider dir first", () => { const source = readFileSync(path.join(repoRoot, "install.sh"), "utf8"); - // cp runs BEFORE the loop now so the provider dir is populated before - // the second symlink is created. - const cpPos = source.indexOf('cp "${adapter_dir}/plugin.yaml"'); + // The staged provider is populated before any host symlink is created. + const cpPos = source.indexOf('cp "${staged_adapter_dir}/plugin.yaml"'); const loopPos = source.indexOf("provider_targets=("); expect(cpPos).toBeGreaterThan(0); expect(loopPos).toBeGreaterThan(cpPos); - expect(source).toContain('ln -sfn "${adapter_dir}/memos_provider" "${target}"'); + expect(source).toContain('ln -sfn "${backup_root}" "${target}"'); + expect(source).toContain( + 'prepare_hermes_provider_targets "${adapter_dir}/memos_provider" "${provider_targets[@]}"', + ); }); }); diff --git a/apps/memos-local-plugin/tests/unit/memory/l3/cluster.test.ts b/apps/memos-local-plugin/tests/unit/memory/l3/cluster.test.ts index f5a708196..cc37340b7 100644 --- a/apps/memos-local-plugin/tests/unit/memory/l3/cluster.test.ts +++ b/apps/memos-local-plugin/tests/unit/memory/l3/cluster.test.ts @@ -125,7 +125,7 @@ describe("memory/l3/cluster", () => { ); }); - it("caps loose clusters before they reach the prompt", () => { + it("preserves every policy so prompt batching can process the full cluster", () => { const policies = [1, 2, 3].map((n) => mkPolicy({ id: `po_n${n}` as PolicyId, title: `network retry ${n}`, @@ -136,7 +136,7 @@ describe("memory/l3/cluster", () => { { policies }, { config: { clusterMinSimilarity: 0.99, minPolicies: 1, maxPoliciesPerCluster: 2 } }, ); - expect(clusters[0]!.policies).toHaveLength(2); + expect(clusters[0]!.policies).toHaveLength(3); }); it("skips a bucket that doesn't meet minPolicies", () => { @@ -246,7 +246,7 @@ describe("memory/l3/cluster", () => { expect(clusters).toEqual([]); }); - it("clusters similar untagged policies and enforces the cap", () => { + it("clusters similar untagged policies without dropping prompt overflow", () => { const policies = [1, 2, 3].map((n) => mkPolicy({ id: `po_uv${n}` as PolicyId, title: `中文策略 ${n}`, @@ -257,7 +257,7 @@ describe("memory/l3/cluster", () => { { config: { clusterMinSimilarity: 0.6, minPolicies: 2, maxPoliciesPerCluster: 2 } }, ); expect(clusters).toHaveLength(1); - expect(clusters[0]!.policies).toHaveLength(2); + expect(clusters[0]!.policies).toHaveLength(3); expect(clusters[0]!.admission).toBe("strict"); }); diff --git a/apps/memos-local-plugin/tests/unit/memory/l3/l3.integration.test.ts b/apps/memos-local-plugin/tests/unit/memory/l3/l3.integration.test.ts index 0f0b6713e..ec51e2213 100644 --- a/apps/memos-local-plugin/tests/unit/memory/l3/l3.integration.test.ts +++ b/apps/memos-local-plugin/tests/unit/memory/l3/l3.integration.test.ts @@ -165,6 +165,63 @@ describe("memory/l3/integration", () => { ); }); + it("batches a large cluster without dropping policies or creating duplicate world models", async () => { + for (let index = 1; index <= 5; index++) { + const episodeId = `ep_batch_${index}`; + seedPolicy(handle, { + id: `po_batch_${index}` as PolicyId, + title: `Alpine pip dependency ${index}`, + trigger: "pip install fails in Alpine container", + procedure: `apk add dependency-${index} then pip install`, + sourceEpisodeIds: [episodeId as EpisodeId], + vec: vec([1, index * 0.01, 0]), + }); + seedTrace(handle, { + id: `tr_batch_${index}`, + episodeId, + tags: ["docker", "alpine", "pip"], + }); + } + let calls = 0; + const llm = fakeLlm({ + completeJson: { + [OP]: () => { + calls += 1; + return { + ...validDraft, + environment: [{ label: `batch ${calls}`, description: "covered" }], + }; + }, + }, + }); + + const result = await runL3( + { trigger: "manual" }, + { + repos: { + policies: handle.repos.policies, + traces: handle.repos.traces, + worldModel: handle.repos.worldModel, + kv: handle.repos.kv, + }, + llm, + log, + config: cfg({ minPolicies: 1, maxPoliciesPerCluster: 2 }), + }, + ); + + expect(calls).toBe(3); + expect(result.abstractions).toHaveLength(1); + expect(handle.repos.worldModel.list()).toHaveLength(1); + expect(handle.repos.worldModel.list()[0]!.policyIds.map(String).sort()).toEqual([ + "po_batch_1", + "po_batch_2", + "po_batch_3", + "po_batch_4", + "po_batch_5", + ]); + }); + it("merges into an existing WM that covers the same domain", async () => { seedTriplet(); // Seed a prior WM that shares domain tags + vector, so merge kicks in. diff --git a/apps/memos-local-plugin/tests/unit/skill/subscriber.test.ts b/apps/memos-local-plugin/tests/unit/skill/subscriber.test.ts index a8c35468a..ba4463298 100644 --- a/apps/memos-local-plugin/tests/unit/skill/subscriber.test.ts +++ b/apps/memos-local-plugin/tests/unit/skill/subscriber.test.ts @@ -2,6 +2,7 @@ import { describe, it, expect, afterEach, vi } from "vitest"; import { createL2EventBus } from "../../../core/memory/l2/events.js"; import { createRewardEventBus } from "../../../core/reward/events.js"; +import type { RewardResult } from "../../../core/reward/types.js"; import { attachSkillSubscriber, createSkillEventBus, @@ -49,6 +50,33 @@ function seedTracesForPolicy(h: TmpDbHandle, id: PolicyId) { return { episodeId }; } +function minimalRewardResult(episodeId: EpisodeId): RewardResult { + return { + episodeId, + sessionId: "s_reward", + rHuman: 0.8, + humanScore: { + rHuman: 0.8, + axes: { goalAchievement: 1, processQuality: 1, userSatisfaction: 1 }, + reason: "test", + source: "heuristic", + model: null, + }, + feedbackCount: 0, + backprop: { + updates: [], + meanAbsValue: 0, + maxPriority: 0, + echoParams: { gamma: 0.9, decayHalfLifeDays: 30, now: Date.now() }, + }, + traceIds: [], + timings: { summary: 0, score: 0, backprop: 0, persist: 0, total: 0 }, + warnings: [], + startedAt: Date.now(), + completedAt: Date.now(), + }; +} + describe("skill/subscriber", () => { it("triggers runSkill on l2.policy.induced", async () => { handle = makeTmpDb(); @@ -156,6 +184,128 @@ describe("skill/subscriber", () => { sub.dispose(); }); + it("runs reward updates only for policies linked to that episode", async () => { + handle = makeTmpDb(); + const h = handle; + const episodeA = seedTracesForPolicy(h, "po_reward_a" as PolicyId).episodeId; + const episodeB = seedTracesForPolicy(h, "po_reward_b" as PolicyId).episodeId; + const policyA = seedPolicy(h, { id: "po_reward_a" as PolicyId, sourceEpisodeIds: [episodeA] }); + seedPolicy(h, { id: "po_reward_b" as PolicyId, sourceEpisodeIds: [episodeB] }); + const traceA = h.repos.traces.listAllForEpisode(episodeA)[0]!; + h.repos.tracePolicyLinks.link({ traceId: traceA.id, policyId: policyA.id, episodeId: episodeA }); + + const rewardBus = createRewardEventBus(); + let draftNumber = 0; + const sub = attachSkillSubscriber({ + l2Bus: createL2EventBus(), + rewardBus, + bus: createSkillEventBus(), + repos: h.repos, + embedder: null, + llm: fakeLlm({ + completeJson: { + "skill.crystallize": () => { + draftNumber += 1; + return makeDraft({ name: `reward_policy_${draftNumber}` }); + }, + }, + }), + log: rootLogger.child({ channel: "core.skill.subscriber" }), + config: makeSkillConfig({ cooldownMs: 6 * 60 * 60 * 1000 }), + }); + + rewardBus.emit({ + kind: "reward.updated", + result: minimalRewardResult(episodeA), + }); + await sub.flush(); + + expect(h.repos.skills.list().map((skill) => skill.sourcePolicyIds.flat()).flat()).toEqual([policyA.id]); + sub.dispose(); + }); + + it("does not let one policy cooldown block another policy reward update", async () => { + handle = makeTmpDb(); + const h = handle; + const episodeA = seedTracesForPolicy(h, "po_reward_c" as PolicyId).episodeId; + const episodeB = seedTracesForPolicy(h, "po_reward_d" as PolicyId).episodeId; + const policyA = seedPolicy(h, { id: "po_reward_c" as PolicyId, sourceEpisodeIds: [episodeA] }); + const policyB = seedPolicy(h, { id: "po_reward_d" as PolicyId, sourceEpisodeIds: [episodeB] }); + for (const [policy, episode] of [[policyA, episodeA], [policyB, episodeB]] as const) { + const trace = h.repos.traces.listAllForEpisode(episode)[0]!; + h.repos.tracePolicyLinks.link({ traceId: trace.id, policyId: policy.id, episodeId: episode }); + } + + const rewardBus = createRewardEventBus(); + let draftNumber = 0; + const sub = attachSkillSubscriber({ + l2Bus: createL2EventBus(), + rewardBus, + bus: createSkillEventBus(), + repos: h.repos, + embedder: null, + llm: fakeLlm({ + completeJson: { + "skill.crystallize": () => { + draftNumber += 1; + return makeDraft({ name: `reward_cooldown_${draftNumber}` }); + }, + }, + }), + log: rootLogger.child({ channel: "core.skill.subscriber" }), + config: makeSkillConfig({ cooldownMs: 6 * 60 * 60 * 1000 }), + }); + + rewardBus.emit({ kind: "reward.updated", result: minimalRewardResult(episodeA) }); + await sub.flush(); + rewardBus.emit({ kind: "reward.updated", result: minimalRewardResult(episodeB) }); + await sub.flush(); + + expect(h.repos.skills.list().flatMap((skill) => skill.sourcePolicyIds.map(String)).sort()).toEqual([ + String(policyA.id), + String(policyB.id), + ]); + sub.dispose(); + }); + + it("retains a same-policy reward event received during cooldown", async () => { + handle = makeTmpDb(); + const h = handle; + const episode = seedTracesForPolicy(h, "po_reward_pending" as PolicyId).episodeId; + const policy = seedPolicy(h, { + id: "po_reward_pending" as PolicyId, + sourceEpisodeIds: [episode], + }); + const trace = h.repos.traces.listAllForEpisode(episode)[0]!; + h.repos.tracePolicyLinks.link({ traceId: trace.id, policyId: policy.id, episodeId: episode }); + + const rewardBus = createRewardEventBus(); + const bus = createSkillEventBus(); + let eligibilityRuns = 0; + bus.on("skill.eligibility.checked", () => { + eligibilityRuns += 1; + }); + const sub = attachSkillSubscriber({ + l2Bus: createL2EventBus(), + rewardBus, + bus, + repos: h.repos, + embedder: null, + llm: fakeLlm({ completeJson: { "skill.crystallize": makeDraft() } }), + log: rootLogger.child({ channel: "core.skill.subscriber" }), + config: makeSkillConfig({ cooldownMs: 20 }), + }); + + rewardBus.emit({ kind: "reward.updated", result: minimalRewardResult(episode) }); + await sub.flush(); + rewardBus.emit({ kind: "reward.updated", result: minimalRewardResult(episode) }); + await new Promise((resolve) => setTimeout(resolve, 30)); + await sub.flush(); + + expect(eligibilityRuns).toBe(2); + sub.dispose(); + }); + it("archives each stale low-η active skill once without regressing candidate promotion", async () => { handle = makeTmpDb(); const h = handle; From 6a83d36807bedab8765502cfa6258dafb6167fe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=81=E5=9C=A8=E5=90=B5=E7=9D=80=E5=90=83=E7=B3=96?= Date: Mon, 21 Sep 2026 13:08:45 +0800 Subject: [PATCH 07/38] fix(plugin): harden multilingual L2 and L3 evolution --- .../core/config/defaults.ts | 1 + apps/memos-local-plugin/core/config/schema.ts | 2 + .../core/llm/prompts/index.ts | 20 +- .../core/memory/l2/induce.ts | 66 +++++ apps/memos-local-plugin/core/memory/l2/l2.ts | 2 + .../core/memory/l3/ALGORITHMS.md | 16 +- .../core/memory/l3/README.md | 10 +- .../core/memory/l3/abstract.ts | 29 +- .../core/memory/l3/cluster.ts | 44 +++ .../core/memory/l3/index.ts | 2 +- apps/memos-local-plugin/core/memory/l3/l3.ts | 118 +++++++- .../core/memory/l3/types.ts | 17 +- .../core/skill/crystallize.ts | 17 +- apps/memos-local-plugin/core/storage/index.ts | 1 + .../migrations/019-policy-metadata.sql | 4 + .../core/storage/migrator.ts | 33 ++- .../core/storage/policy-metadata-backfill.ts | 189 ++++++++++++ .../core/storage/repos/policies.ts | 29 +- apps/memos-local-plugin/core/types.ts | 11 + .../docs/CONFIG-ADVANCED.md | 2 + .../integration/skill-l3-full-chain.test.ts | 279 ++++++++++++++++++ .../tests/unit/llm/prompts.test.ts | 7 + .../tests/unit/memory/l2/induce.test.ts | 9 + .../unit/memory/l2/l2.integration.test.ts | 6 + .../tests/unit/memory/l3/abstract.test.ts | 15 +- .../tests/unit/memory/l3/cluster.test.ts | 41 +++ .../unit/memory/l3/l3.integration.test.ts | 36 +++ .../unit/skill/skill.integration.test.ts | 93 ++++++ .../tests/unit/storage/migrator.test.ts | 25 ++ .../storage/policy-metadata-backfill.test.ts | 51 ++++ 30 files changed, 1132 insertions(+), 43 deletions(-) create mode 100644 apps/memos-local-plugin/core/storage/migrations/019-policy-metadata.sql create mode 100644 apps/memos-local-plugin/core/storage/policy-metadata-backfill.ts create mode 100644 apps/memos-local-plugin/tests/integration/skill-l3-full-chain.test.ts create mode 100644 apps/memos-local-plugin/tests/unit/storage/policy-metadata-backfill.test.ts diff --git a/apps/memos-local-plugin/core/config/defaults.ts b/apps/memos-local-plugin/core/config/defaults.ts index 7a54fd270..b09307c2a 100644 --- a/apps/memos-local-plugin/core/config/defaults.ts +++ b/apps/memos-local-plugin/core/config/defaults.ts @@ -223,6 +223,7 @@ export const DEFAULT_CONFIG: ResolvedConfig = { // strict 0.6 starved L3 in real usage. clusterMinSimilarity: 0.3, maxPoliciesPerCluster: 20, + maxPromptChars: 32_000, policyCharCap: 800, traceCharCap: 500, traceEvidencePerPolicy: 1, diff --git a/apps/memos-local-plugin/core/config/schema.ts b/apps/memos-local-plugin/core/config/schema.ts index 5b7071061..a5d394b49 100644 --- a/apps/memos-local-plugin/core/config/schema.ts +++ b/apps/memos-local-plugin/core/config/schema.ts @@ -328,6 +328,8 @@ const AlgorithmSchema = Type.Object({ clusterMinSimilarity: NumberInRange(0.6, 0, 1), /** Maximum policies included in one L3 abstraction prompt. */ maxPoliciesPerCluster: NumberInRange(20, 1, 100), + /** Hard total character cap for one L3 abstraction prompt. */ + maxPromptChars: NumberInRange(32_000, 4_000, 128_000), /** Chars of L2 body handed to `l3.abstraction`. */ policyCharCap: NumberInRange(800, 200, 4_000), /** Chars of trace body handed per evidence trace. */ diff --git a/apps/memos-local-plugin/core/llm/prompts/index.ts b/apps/memos-local-plugin/core/llm/prompts/index.ts index 504398a92..ab5aa68ba 100644 --- a/apps/memos-local-plugin/core/llm/prompts/index.ts +++ b/apps/memos-local-plugin/core/llm/prompts/index.ts @@ -50,8 +50,13 @@ export function languageSteeringLine(lang: PromptLanguage): string { * Heuristic: * - Count CJK Unified Ideographs (U+4E00..U+9FFF) as `zh`. * - Count ASCII letters A-Z/a-z as `en`. - * - If CJK accounts for more than `zhRatioThreshold` of counted - * CJK+ASCII signal, pick `zh`. + * - Treat Japanese kana as an explicit non-Chinese signal. This keeps + * Japanese prompts from being mistaken for Chinese just because they + * contain a few shared Han characters. + * - CJK characters carry a small weight because technical identifiers + * (package names, commands, file paths) can contribute many ASCII + * characters inside an otherwise Chinese sentence. If weighted CJK + * accounts for more than `zhRatioThreshold` of the signal, pick `zh`. * - Otherwise pick `en`. * * This intentionally treats Japanese / Korean prompts with filenames, @@ -66,18 +71,25 @@ export function detectDominantLanguage( samples: ReadonlyArray, opts: { zhRatioThreshold?: number } = {}, ): PromptLanguage { - const zhRatioThreshold = opts.zhRatioThreshold ?? 0.7; + const zhRatioThreshold = opts.zhRatioThreshold ?? 0.6; let zh = 0; let en = 0; + let kana = 0; for (const s of samples) { if (!s) continue; for (let i = 0; i < s.length; i++) { const code = s.charCodeAt(i); if (code >= 0x4e00 && code <= 0x9fff) zh++; + else if ( + (code >= 0x3040 && code <= 0x30ff) || + (code >= 0x31f0 && code <= 0x31ff) + ) kana++; else if ((code >= 0x41 && code <= 0x5a) || (code >= 0x61 && code <= 0x7a)) en++; } } + if (kana > 0) return "en"; const total = zh + en; if (total === 0) return "en"; - return zh / total > zhRatioThreshold ? "zh" : "en"; + const weightedZh = zh * 4; + return weightedZh / (weightedZh + en) > zhRatioThreshold ? "zh" : "en"; } diff --git a/apps/memos-local-plugin/core/memory/l2/induce.ts b/apps/memos-local-plugin/core/memory/l2/induce.ts index 2ea750cd2..6d752f099 100644 --- a/apps/memos-local-plugin/core/memory/l2/induce.ts +++ b/apps/memos-local-plugin/core/memory/l2/induce.ts @@ -23,6 +23,7 @@ import type { EmbeddingVector, EpisodeId, PolicyId, + PolicyMetadata, PolicyRow, TraceId, TraceRow, @@ -156,6 +157,7 @@ export function buildPolicyRow(args: { inducedBy: string; // prompt id + version now?: number; id?: PolicyId; + sourceSignature?: string; }): PolicyRow { const now = args.now ?? Date.now(); const vec = centroid(args.evidenceTraces.map((t) => t.vecSummary ?? t.vecAction ?? null)); @@ -170,6 +172,7 @@ export function buildPolicyRow(args: { gain: 0, status: "candidate", sourceEpisodeIds: Array.from(new Set(args.episodeIds)), + sourceTraceIds: Array.from(new Set(args.evidenceTraces.map((trace) => trace.id))), inducedBy: args.inducedBy, // Fresh policy starts without learned guidance — populated by the // decision-repair pipeline as user feedback / failure bursts arrive. @@ -177,9 +180,72 @@ export function buildPolicyRow(args: { vec: vec as EmbeddingVector | null, createdAt: now, updatedAt: now, + metadata: derivePolicyMetadata(args.evidenceTraces, args.sourceSignature), }; } +function derivePolicyMetadata( + traces: readonly TraceRow[], + sourceSignature?: string, +): PolicyMetadata { + const domainTags = uniqueStrings(traces.flatMap((t) => t.tags ?? [])); + const toolNames = uniqueStrings( + traces.flatMap((t) => (t.toolCalls ?? []).map((c) => c.name ?? "")), + ); + const errorCodes = uniqueStrings( + traces.flatMap((t) => { + const text = [ + t.agentText, + t.reflection ?? "", + ...(t.toolCalls ?? []).map((c) => + typeof c.output === "string" ? c.output : "", + ), + ].join(" "); + return Array.from( + text.matchAll(/\b[A-Z][A-Z0-9]{2,}_[A-Z0-9_]+\b/g), + (m) => m[0], + ); + }), + ); + let zh = 0; + let en = 0; + for (const t of traces) { + for (const s of [t.userText, t.agentText, t.reflection ?? ""]) { + for (const ch of s) { + const code = ch.charCodeAt(0); + if (code >= 0x4e00 && code <= 0x9fff) zh++; + else if ( + (code >= 0x41 && code <= 0x5a) || + (code >= 0x61 && code <= 0x7a) + ) en++; + } + } + } + const total = zh + en; + const language = + total === 0 + ? "unknown" + : zh / total >= 0.7 + ? "zh" + : en / total >= 0.7 + ? "en" + : "mixed"; + return { + version: 1, + language, + domainTags, + toolNames, + errorCodes, + ...(sourceSignature ? { sourceSignature } : {}), + }; +} + +function uniqueStrings(values: readonly string[]): string[] { + return Array.from( + new Set(values.map((v) => v.trim().toLowerCase()).filter(Boolean)), + ).slice(0, 32); +} + // ─── helpers ──────────────────────────────────────────────────────────────── function packTraces( diff --git a/apps/memos-local-plugin/core/memory/l2/l2.ts b/apps/memos-local-plugin/core/memory/l2/l2.ts index 903502b32..b880df52d 100644 --- a/apps/memos-local-plugin/core/memory/l2/l2.ts +++ b/apps/memos-local-plugin/core/memory/l2/l2.ts @@ -253,6 +253,7 @@ export async function runL2( evidenceTraces: traces, inducedBy: `${L2_INDUCTION_PROMPT.id}.v${L2_INDUCTION_PROMPT.version}`, now: input.now ?? Date.now(), + sourceSignature: bucket.signature, }); const owner = ownerFromTraces(traces); policy.ownerAgentKind = owner.ownerAgentKind; @@ -632,6 +633,7 @@ function mergePolicyEvidence(existing: PolicyRow, incoming: PolicyRow, now: numb ...incoming.sourceEpisodeIds, ]), vec: existing.vec ?? incoming.vec, + metadata: existing.metadata ?? incoming.metadata, updatedAt: now as PolicyRow["updatedAt"], }; } diff --git a/apps/memos-local-plugin/core/memory/l3/ALGORITHMS.md b/apps/memos-local-plugin/core/memory/l3/ALGORITHMS.md index aceeb5a98..ae3594d51 100644 --- a/apps/memos-local-plugin/core/memory/l3/ALGORITHMS.md +++ b/apps/memos-local-plugin/core/memory/l3/ALGORITHMS.md @@ -50,13 +50,15 @@ rust|cargo|go|java|maven|gradle|typescript|javascript ``` Matches are ordered by the first-hit position so the sweep is -deterministic, then we pick the top two distinct tokens. We deliberately -**do not** embed free-form LLM tags here — domain keys must be cheap -and stable enough to hash. - -Policies with no recognised domain keyword fall into the bucket -`__generic|` and are still candidates for clustering by vector -similarity. +deterministic, then we pick the top two distinct tokens. Newly induced L2 +rows also persist trace-derived metadata (language, tags, tool names, error +codes, and the source signature); that structured metadata is preferred over +this legacy prose heuristic. We deliberately **do not** embed free-form LLM +tags here — domain keys must be cheap and stable enough to hash. + +Policies with no recognised domain keyword fall into the generic bucket and +are only clustered when at least two vector-bearing policies pass the cosine +gate. This prevents unrelated no-label policies from becoming an L3 prompt. --- diff --git a/apps/memos-local-plugin/core/memory/l3/README.md b/apps/memos-local-plugin/core/memory/l3/README.md index 1c0f5c021..7db55d3c8 100644 --- a/apps/memos-local-plugin/core/memory/l3/README.md +++ b/apps/memos-local-plugin/core/memory/l3/README.md @@ -56,7 +56,9 @@ No single step blocks reward/L2. Any LLM failure is captured as a `clusterPolicies` (see [`cluster.ts`](./cluster.ts) and [`ALGORITHMS.md`](./ALGORITHMS.md)) bucket-sorts policies by a compact -**domain key** derived from the policy's trigger/procedure text +**domain key** derived first from trace-derived policy metadata (language, +tags, tools, error codes, and source signature), with a legacy +trigger/procedure-text fallback for pre-migration rows (`docker|pip`, `node|npm`, …) and then splits each bucket by centroid cosine, so policies in the same bucket that are still semantically far apart (different sub-environments) end up in separate clusters. @@ -152,6 +154,7 @@ See `algorithm.l3Abstraction` in | `useLlm` | `true` | Toggle the LLM abstractor off for tests. | | `cooldownDays` | `1` | Debounce per domain tag. | | `maxPoliciesPerCluster` | `20` | Batch size for one abstraction prompt; overflow is retained. | +| `maxPromptChars` | `32000` | Hard total prompt cap; oversized legacy batches are skipped and quarantined. | | `confidenceDelta` | `0.05` | Confidence step per merge / feedback. | | `minConfidenceForRetrieval` | `0.2` | Tier-3 hide threshold. | @@ -166,6 +169,11 @@ All L3 work is logged on dedicated channels (see * `core.memory.l3.merge` — merge decisions. * `core.memory.l3.confidence` — confidence bumps. * `core.memory.l3.feedback` — human feedback-driven confidence changes. + +Failed legacy clusters use a bounded retry policy (5m/30m/2h/6h). After the +fourth deterministic failure they are quarantined rather than retried forever; +clear the `l3.retry.*` record through the L3 retry-state helper after fixing +the provider or prompt configuration. * `core.memory.l3.events` — listener dispatch errors. ## Tests diff --git a/apps/memos-local-plugin/core/memory/l3/abstract.ts b/apps/memos-local-plugin/core/memory/l3/abstract.ts index 0bde96fb3..e01c70734 100644 --- a/apps/memos-local-plugin/core/memory/l3/abstract.ts +++ b/apps/memos-local-plugin/core/memory/l3/abstract.ts @@ -49,7 +49,7 @@ export interface AbstractInput { export interface AbstractDeps { llm: LlmClient | null; log: Logger; - config: Pick; + config: Pick; /** Optional extra validation executed after the base validator. */ validate?: (d: L3AbstractionDraft) => void; } @@ -74,19 +74,38 @@ export async function abstractDraft( } const userPayload = packPrompt(input, config); + const maxPromptChars = Math.max(4_000, Math.floor(config.maxPromptChars ?? 32_000)); + if (userPayload.length > maxPromptChars) { + log.warn("l3.abstract.prompt_too_large", { + clusterKey: input.cluster.key, + promptChars: userPayload.length, + maxPromptChars, + policyCount: input.cluster.policies.length, + }); + return { + ok: false, + reason: "prompt_too_large", + detail: `prompt has ${userPayload.length} chars; limit is ${maxPromptChars}`, + }; + } // Pick the world-model's rendering language from the underlying // policies + trace evidence. A Chinese user generating "docker alpine // 依赖" policies should see the environment/inference/constraint bullets // written in Chinese; an English user should see them in English. - const langSamples: Array = []; + const policySamples: Array = []; for (const p of input.cluster.policies) { - langSamples.push(p.title, p.trigger, p.procedure, p.boundary, p.verification); + policySamples.push(p.title, p.trigger, p.procedure, p.boundary, p.verification); } + const evidenceSamples: Array = []; for (const traces of input.evidenceByPolicy.values()) { - for (const t of traces) langSamples.push(t.userText, t.agentText, t.reflection); + for (const t of traces) evidenceSamples.push(t.userText, t.agentText, t.reflection); } - const evidenceLang = detectDominantLanguage(langSamples); + // Evidence language wins over legacy policy prose: old English policies + // must not force a Chinese trace cluster back to English. + const evidenceLang = detectDominantLanguage( + evidenceSamples.some((sample) => sample?.trim()) ? evidenceSamples : policySamples, + ); try { const rsp = await llm.completeJson>( diff --git a/apps/memos-local-plugin/core/memory/l3/cluster.ts b/apps/memos-local-plugin/core/memory/l3/cluster.ts index b754d1253..4620b3d3a 100644 --- a/apps/memos-local-plugin/core/memory/l3/cluster.ts +++ b/apps/memos-local-plugin/core/memory/l3/cluster.ts @@ -60,6 +60,32 @@ const TOOL_REGEXES: Array<{ re: RegExp; tag: string }> = [ ]; export function domainKeyOf(policy: PolicyRow): { key: PolicyClusterKey; tags: string[] } { + // New policies carry structured provenance from their L1 traces. Prefer it + // over English-only regexes so Chinese/Japanese policies and tool-heavy + // traces do not collapse into the generic `_|_` bucket. + if (policy.metadata) { + const tags = uniqueLower([ + ...(policy.metadata.domainTags ?? []), + ...(policy.metadata.toolNames ?? []), + ...(policy.metadata.errorCodes ?? []), + ]); + const signature = policy.metadata.sourceSignature?.split("|") ?? []; + const primary = firstUseful( + policy.metadata.domainTags, + signature[0] && signature[0] !== "_" ? [signature[0]] : [], + ); + const tool = firstUseful( + policy.metadata.toolNames, + signature[2] && signature[2] !== "_" ? [signature[2]] : [], + ); + // Legacy backfill can only provide language (and an empty tag set) when + // traces were already compacted. Preserve the old text heuristics in that + // case instead of turning every such policy into the generic `_|_` bucket. + if (primary || tool || tags.length > 0) { + return { key: `${primary ?? "_"}|${tool ?? "_"}`, tags }; + } + } + const haystack = [policy.title, policy.trigger, policy.procedure, policy.boundary] .filter(Boolean) .join(" \n "); @@ -87,6 +113,24 @@ export function domainKeyOf(policy: PolicyRow): { key: PolicyClusterKey; tags: s }; } +function uniqueLower(values: readonly string[] | undefined): string[] { + return Array.from( + new Set( + (values ?? []) + .map((value) => value.trim().toLowerCase()) + .filter(Boolean), + ), + ).slice(0, 64); +} + +function firstUseful(...groups: Array): string | undefined { + for (const group of groups) { + const value = group?.find((item) => item.trim() && item.trim() !== "_"); + if (value) return value.trim().toLowerCase(); + } + return undefined; +} + // ─── Clustering ──────────────────────────────────────────────────────────── interface PolicyWithMeta { diff --git a/apps/memos-local-plugin/core/memory/l3/index.ts b/apps/memos-local-plugin/core/memory/l3/index.ts index 4443a023a..65cc789ee 100644 --- a/apps/memos-local-plugin/core/memory/l3/index.ts +++ b/apps/memos-local-plugin/core/memory/l3/index.ts @@ -13,7 +13,7 @@ export { abstractDraft, buildWorldModelRow } from "./abstract.js"; export { clusterPolicies, domainKeyOf } from "./cluster.js"; export { createL3EventBus } from "./events.js"; -export { adjustConfidence, runL3 } from "./l3.js"; +export { adjustConfidence, clearL3RetryState, runL3 } from "./l3.js"; export type { RunL3Deps } from "./l3.js"; export { chooseMergeTarget, diff --git a/apps/memos-local-plugin/core/memory/l3/l3.ts b/apps/memos-local-plugin/core/memory/l3/l3.ts index 1b24c87a7..bdc131e9c 100644 --- a/apps/memos-local-plugin/core/memory/l3/l3.ts +++ b/apps/memos-local-plugin/core/memory/l3/l3.ts @@ -52,6 +52,7 @@ import type { L3ProcessInput, L3ProcessResult, PolicyCluster, + PolicyClusterKey, } from "./types.js"; // ─── Deps ────────────────────────────────────────────────────────────────── @@ -67,6 +68,16 @@ export interface RunL3Deps { const KV_COOLDOWN_PREFIX = "l3.lastRun."; const KV_RETRY_PREFIX = "l3.retry."; const FAILURE_BACKOFF_MS = [5 * 60_000, 30 * 60_000, 2 * 60 * 60_000, 6 * 60 * 60_000]; +const RETRY_STATE_VERSION = 2; +const MAX_FAILURE_ATTEMPTS = FAILURE_BACKOFF_MS.length; + +interface L3RetryState { + version: number; + nextRetryAt: number; + failures: number; + quarantined: boolean; + reason?: string; +} // ─── Public entry ────────────────────────────────────────────────────────── @@ -145,6 +156,12 @@ export async function runL3( if (!cluster.centroidVec) { abstractions.push(skipped(cluster, "no_centroid")); + emit(bus, { + kind: "l3.abstraction.skipped", + clusterKey: cluster.key, + reason: "no_centroid", + policyIds: cluster.policies.map((p) => p.id), + }); continue; } @@ -156,7 +173,17 @@ export async function runL3( abstractions.push(skipped(cluster, "cooldown")); continue; } - const retry = repos.kv.get<{ nextRetryAt: number; failures: number } | null>(retryKey(cluster), null); + const retry = readRetryState(repos.kv.get(retryKey(cluster), null)); + if (retry?.quarantined) { + abstractions.push(skipped(cluster, "quarantined")); + emit(bus, { + kind: "l3.abstraction.skipped", + clusterKey: cluster.key, + reason: "quarantined", + policyIds: cluster.policies.map((p) => p.id), + }); + continue; + } if (retry && retry.nextRetryAt > now) { abstractions.push(skipped(cluster, "retry_cooldown")); continue; @@ -201,16 +228,31 @@ export async function runL3( timings.abstract += Date.now() - t0; if (!draftRes.ok) { - if (draftRes.reason === "llm_failed" || draftRes.reason === "draft_invalid") { - recordFailure(cluster, repos.kv, now); + if ( + draftRes.reason === "llm_failed" || + draftRes.reason === "draft_invalid" || + draftRes.reason === "prompt_too_large" + ) { + recordFailure(cluster, repos.kv, now, draftRes.reason, draftRes.reason === "prompt_too_large"); + } + const policyIds = cluster.policies.map((p) => p.id); + abstractions.push(skipped(cluster, draftRes.reason, { episodeIds, policyIds })); + if (draftRes.reason === "prompt_too_large") { + emit(bus, { + kind: "l3.abstraction.skipped", + clusterKey: cluster.key, + reason: draftRes.reason, + policyIds, + }); + } else { + emit(bus, { + kind: "l3.failed", + stage: "abstract", + error: { code: draftRes.reason, message: draftRes.detail ?? "" }, + clusterKey: cluster.key, + policyIds, + }); } - abstractions.push(skipped(cluster, draftRes.reason, { episodeIds, policyIds: cluster.policies.map((p) => p.id) })); - emit(bus, { - kind: "l3.failed", - stage: "abstract", - error: { code: draftRes.reason, message: draftRes.detail ?? "" }, - clusterKey: cluster.key, - }); continue; } @@ -530,15 +572,59 @@ function cooldownKey(cluster: PolicyCluster): string { } function retryKey(cluster: PolicyCluster): string { - const members = cluster.policies.map((p) => String(p.id)).sort().join(","); - return `${KV_RETRY_PREFIX}${cluster.key}:${members}`; + return retryKeyFor(cluster.key, cluster.policies.map((p) => p.id)); } -function recordFailure(cluster: PolicyCluster, kv: Repos["kv"], now: number): void { - const previous = kv.get<{ nextRetryAt: number; failures: number } | null>(retryKey(cluster), null); - const failures = Math.min((previous?.failures ?? 0) + 1, FAILURE_BACKOFF_MS.length); +function retryKeyFor(clusterKey: PolicyClusterKey, policyIds: readonly PolicyId[]): string { + const members = policyIds.map((id) => String(id)).sort().join(","); + return `${KV_RETRY_PREFIX}${clusterKey}:${members}`; +} + +/** Clear a retry/quarantine record after a config or prompt fix. */ +export function clearL3RetryState( + clusterKey: PolicyClusterKey, + policyIds: readonly PolicyId[], + kv: Repos["kv"], +): void { + kv.del(retryKeyFor(clusterKey, policyIds)); +} + +function recordFailure( + cluster: PolicyCluster, + kv: Repos["kv"], + now: number, + reason?: string, + quarantine = false, +): void { + const previous = readRetryState(kv.get(retryKey(cluster), null)); + const failures = Math.min((previous?.failures ?? 0) + 1, MAX_FAILURE_ATTEMPTS); const delay = FAILURE_BACKOFF_MS[failures - 1] ?? FAILURE_BACKOFF_MS[FAILURE_BACKOFF_MS.length - 1]!; - kv.set(retryKey(cluster), { failures, nextRetryAt: now + delay }); + kv.set(retryKey(cluster), { + version: RETRY_STATE_VERSION, + failures, + nextRetryAt: now + delay, + quarantined: quarantine || failures >= MAX_FAILURE_ATTEMPTS, + ...(reason ? { reason } : {}), + }); +} + +function readRetryState(raw: unknown): L3RetryState | null { + if (!raw || typeof raw !== "object") return null; + const row = raw as Record; + const failures = typeof row.failures === "number" && Number.isFinite(row.failures) + ? Math.max(0, Math.floor(row.failures)) + : 0; + const nextRetryAt = typeof row.nextRetryAt === "number" && Number.isFinite(row.nextRetryAt) + ? row.nextRetryAt + : 0; + if (failures <= 0 && nextRetryAt <= 0) return null; + return { + version: typeof row.version === "number" ? row.version : 1, + failures, + nextRetryAt, + quarantined: row.quarantined === true, + reason: typeof row.reason === "string" ? row.reason : undefined, + }; } function isInCooldown( diff --git a/apps/memos-local-plugin/core/memory/l3/types.ts b/apps/memos-local-plugin/core/memory/l3/types.ts index 142a51a6a..99f081f9f 100644 --- a/apps/memos-local-plugin/core/memory/l3/types.ts +++ b/apps/memos-local-plugin/core/memory/l3/types.ts @@ -41,6 +41,8 @@ export interface L3Config { clusterMinSimilarity: number; /** Maximum policies admitted to one abstraction prompt. */ maxPoliciesPerCluster?: number; + /** Hard total character cap for one abstraction prompt. */ + maxPromptChars?: number; /** Char cap for each L2 body section handed to the prompt. */ policyCharCap: number; /** Char cap for each L1 evidence trace handed to the prompt. */ @@ -132,7 +134,11 @@ export interface L3AbstractionDraft { export type L3AbstractionDraftResult = | { ok: true; draft: L3AbstractionDraft } - | { ok: false; reason: "llm_disabled" | "llm_failed" | "draft_invalid"; detail?: string }; + | { + ok: false; + reason: "llm_disabled" | "llm_failed" | "draft_invalid" | "prompt_too_large"; + detail?: string; + }; // ─── Abstraction outcomes ────────────────────────────────────────────────── @@ -153,6 +159,8 @@ export interface AbstractionResult { | "llm_disabled" | "llm_failed" | "draft_invalid" + | "prompt_too_large" + | "quarantined" | "cooldown" | "retry_cooldown" | "no_centroid" @@ -232,6 +240,13 @@ export type L3Event = stage: string; error: { code: string; message: string }; clusterKey?: PolicyClusterKey; + policyIds?: PolicyId[]; + } + | { + kind: "l3.abstraction.skipped"; + clusterKey: PolicyClusterKey; + reason: string; + policyIds: PolicyId[]; }; export type L3EventKind = L3Event["kind"]; diff --git a/apps/memos-local-plugin/core/skill/crystallize.ts b/apps/memos-local-plugin/core/skill/crystallize.ts index 04de81654..77505df40 100644 --- a/apps/memos-local-plugin/core/skill/crystallize.ts +++ b/apps/memos-local-plugin/core/skill/crystallize.ts @@ -146,12 +146,19 @@ export async function crystallizeDraft( // human-facing fields (display_title, summary, preconditions, steps, // examples) come out in the same language the user was using. The // `name` slug stays snake_case regardless — enforced by `sanitiseName`. - const evidenceLang = detectDominantLanguage([ - input.policy.title, - input.policy.trigger, - input.policy.procedure, - ...input.evidence.flatMap((t) => [t.userText, t.agentText, t.reflection]), + // Trace evidence is authoritative for rendering language. Including an + // old English policy here can force a Chinese episode back to English and + // recreate the verifier resonance failure during upgrades. + const evidenceSamples = input.evidence.flatMap((t) => [ + t.userText, + t.agentText, + t.reflection, ]); + const evidenceLang = detectDominantLanguage( + evidenceSamples.some((sample) => sample?.trim()) + ? evidenceSamples + : [input.policy.title, input.policy.trigger, input.policy.procedure], + ); try { const rsp = await llm.completeJson>( diff --git a/apps/memos-local-plugin/core/storage/index.ts b/apps/memos-local-plugin/core/storage/index.ts index 1cc7dc5e3..bb2f9baaf 100644 --- a/apps/memos-local-plugin/core/storage/index.ts +++ b/apps/memos-local-plugin/core/storage/index.ts @@ -20,6 +20,7 @@ export { type MigrationFile, type MigrationsResult, } from "./migrator.js"; +export { backfillLegacyPolicyMetadata } from "./policy-metadata-backfill.js"; export { withRetry, withSavepoint, diff --git a/apps/memos-local-plugin/core/storage/migrations/019-policy-metadata.sql b/apps/memos-local-plugin/core/storage/migrations/019-policy-metadata.sql new file mode 100644 index 000000000..b3e63e7e4 --- /dev/null +++ b/apps/memos-local-plugin/core/storage/migrations/019-policy-metadata.sql @@ -0,0 +1,4 @@ +-- Structured provenance for L2 policies. Nullable for backwards compatibility; +-- legacy rows continue to use the L3 text heuristic until re-induced. +ALTER TABLE policies ADD COLUMN metadata_json TEXT; +CREATE INDEX IF NOT EXISTS idx_policies_metadata ON policies(metadata_json); diff --git a/apps/memos-local-plugin/core/storage/migrator.ts b/apps/memos-local-plugin/core/storage/migrator.ts index b858f7aa3..85a5be3c8 100644 --- a/apps/memos-local-plugin/core/storage/migrator.ts +++ b/apps/memos-local-plugin/core/storage/migrator.ts @@ -18,6 +18,7 @@ import { fileURLToPath } from "node:url"; import { now } from "../time.js"; import { rootLogger } from "../logger/index.js"; import { markReady } from "./connection.js"; +import { backfillLegacyPolicyMetadata } from "./policy-metadata-backfill.js"; import type { StorageDb } from "./types.js"; const log = rootLogger.child({ channel: "storage.migration" }); @@ -34,6 +35,8 @@ export interface MigrationsResult { applied: Array<{ version: number; name: string; durationMs: number }>; skipped: number; total: number; + /** Number of legacy policy rows healed during this boot (bounded batch). */ + metadataBackfilled: number; } /** @@ -113,6 +116,19 @@ export function runMigrations(db: StorageDb, dir: string = defaultMigrationsDir( skipped++; continue; } + // Some recovery/compatibility tests (and a few hand-created legacy + // databases) contain only the migration bookkeeping tables. The policy + // metadata migration is additive and has nothing to do when the parent + // policies table is absent; record it as applied so boot can continue. + // Normal databases always have policies from 001-initial.sql, so this + // branch never bypasses the real ALTER TABLE upgrade. + if (file.version === 19 && !tableExists(db, "policies")) { + db.prepare( + `INSERT INTO schema_migrations (version, name, applied_at) VALUES (@version, @name, @applied_at)`, + ).run({ version: file.version, name: file.name, applied_at: now() }); + applied.push({ version: file.version, name: file.name, durationMs: 0 }); + continue; + } const t0 = now(); db.tx(() => { applyMigration(db, file); @@ -134,6 +150,10 @@ export function runMigrations(db: StorageDb, dir: string = defaultMigrationsDir( } ensureHubSharingSearchColumns(db); + const metadataBackfilled = backfillLegacyPolicyMetadata(db); + if (metadataBackfilled > 0) { + log.info("policy-metadata.backfilled", { count: metadataBackfilled }); + } markReady(db); log.info("migrations.summary", { @@ -142,7 +162,7 @@ export function runMigrations(db: StorageDb, dir: string = defaultMigrationsDir( skipped, }); - return { applied, skipped, total: allFiles.length }; + return { applied, skipped, total: allFiles.length, metadataBackfilled }; } /** @@ -210,6 +230,17 @@ function applyMigration(db: StorageDb, file: MigrationFile): void { } return; } + if (file.version === 19 && file.name === "policy-metadata") { + // 019 is intentionally idempotent beyond the schema_migrations marker: + // a process can crash after ALTER TABLE but before recording the marker. + // Re-running must detect the already-present column instead of failing + // with "duplicate column name". + if (tableExists(db, "policies")) { + ensureColumn(db, "policies", "metadata_json", "TEXT"); + db.exec(`CREATE INDEX IF NOT EXISTS idx_policies_metadata ON policies(metadata_json)`); + } + return; + } db.exec(fs.readFileSync(file.fullPath, "utf8")); } diff --git a/apps/memos-local-plugin/core/storage/policy-metadata-backfill.ts b/apps/memos-local-plugin/core/storage/policy-metadata-backfill.ts new file mode 100644 index 000000000..088c9212b --- /dev/null +++ b/apps/memos-local-plugin/core/storage/policy-metadata-backfill.ts @@ -0,0 +1,189 @@ +import type { PolicyMetadata } from "../types.js"; +import type { StorageDb } from "./types.js"; + +const DEFAULT_BATCH_SIZE = 100; + +interface LegacyPolicyRow { + id: string; + title: string; + trigger: string; + procedure: string; + verification: string; + boundary: string; + source_episodes_json: string | null; + source_trace_ids_json: string | null; +} + +interface LegacyTraceRow { + id: string; + episode_id: string; + user_text: string; + agent_text: string; + reflection: string | null; + tags_json: string | null; + tool_calls_json: string | null; +} + +/** + * Fill metadata for legacy policies without holding the migration transaction + * open. The query is deliberately bounded: a large 2.0.x database is healed + * over several normal boots instead of making the first upgrade block on a + * full-table rewrite. Rows are selected by `metadata_json IS NULL`, making the + * operation idempotent and safe to resume after an interrupted boot. + */ +export function backfillLegacyPolicyMetadata( + db: StorageDb, + options: { batchSize?: number } = {}, +): number { + if (!tableExists(db, "policies") || !hasColumn(db, "policies", "metadata_json")) return 0; + + const limit = Math.max(1, Math.min(500, Math.floor(options.batchSize ?? DEFAULT_BATCH_SIZE))); + const policies = db + .prepare<{ limit: number }, LegacyPolicyRow>( + `SELECT id, title, trigger, procedure, verification, boundary, + source_episodes_json, source_trace_ids_json + FROM policies + WHERE metadata_json IS NULL + ORDER BY updated_at ASC, id ASC + LIMIT @limit`, + ) + .all({ limit }); + if (policies.length === 0) return 0; + + const traceById = new Map(); + if (tableExists(db, "traces")) { + const traceIds = new Set(); + const episodeIds = new Set(); + for (const policy of policies) { + for (const id of parseStringArray(policy.source_trace_ids_json)) traceIds.add(id); + for (const id of parseStringArray(policy.source_episodes_json)) episodeIds.add(id); + } + if (traceIds.size > 0 || episodeIds.size > 0) { + const idPlaceholders = Array.from(traceIds, (_, i) => `@id${i}`); + const episodePlaceholders = Array.from(episodeIds, (_, i) => `@episode${i}`); + const predicates = []; + if (idPlaceholders.length > 0) predicates.push(`id IN (${idPlaceholders.join(",")})`); + if (episodePlaceholders.length > 0) predicates.push(`episode_id IN (${episodePlaceholders.join(",")})`); + const params = { + ...Object.fromEntries(Array.from(traceIds, (id, i) => [`id${i}`, id])), + ...Object.fromEntries(Array.from(episodeIds, (id, i) => [`episode${i}`, id])), + }; + const keyed = db + .prepare, LegacyTraceRow>( + `SELECT id, episode_id, user_text, agent_text, reflection, tags_json, tool_calls_json + FROM traces WHERE ${predicates.join(" OR ")}`, + ) + .all(params); + for (const row of keyed) traceById.set(row.id, row); + } + } + + const update = db.prepare<{ id: string; metadata_json: string }>( + `UPDATE policies SET metadata_json=@metadata_json WHERE id=@id AND metadata_json IS NULL`, + ); + return db.tx(() => { + let updated = 0; + for (const policy of policies) { + const traces = parseStringArray(policy.source_trace_ids_json) + .map((id) => traceById.get(id)) + .filter((trace): trace is LegacyTraceRow => trace !== undefined); + if (traces.length === 0) { + const episodes = new Set(parseStringArray(policy.source_episodes_json)); + for (const trace of traceById.values()) { + if (episodes.has(trace.episode_id)) traces.push(trace); + if (traces.length >= 8) break; + } + } + const metadata = deriveLegacyMetadata(policy, traces); + updated += update.run({ id: policy.id, metadata_json: JSON.stringify(metadata) }).changes; + } + return updated; + }); +} + +function deriveLegacyMetadata( + policy: LegacyPolicyRow, + traces: readonly LegacyTraceRow[], +): PolicyMetadata { + const domainTags = unique(traces.flatMap((trace) => parseStringArray(trace.tags_json))); + const toolNames = unique( + traces.flatMap((trace) => parseJsonArray(trace.tool_calls_json) + .map((call) => typeof call.name === "string" ? call.name : "") + .filter(Boolean)), + ); + const errorCodes = unique( + traces.flatMap((trace) => extractErrorCodes([ + trace.agent_text, + trace.reflection ?? "", + ...parseJsonArray(trace.tool_calls_json).map((call) => + typeof call.output === "string" ? call.output : "", + ), + ].join(" "))), + ); + const prose = traces.length > 0 + ? traces.flatMap((trace) => [trace.user_text, trace.agent_text, trace.reflection ?? ""]) + : [policy.title, policy.trigger, policy.procedure, policy.verification, policy.boundary]; + const language = detectLanguage(prose); + return { version: 1, language, domainTags, toolNames, errorCodes }; +} + +function detectLanguage(values: readonly string[]): PolicyMetadata["language"] { + let zh = 0; + let en = 0; + for (const value of values) { + for (const char of value) { + const code = char.charCodeAt(0); + if (code >= 0x4e00 && code <= 0x9fff) zh++; + else if ((code >= 0x41 && code <= 0x5a) || (code >= 0x61 && code <= 0x7a)) en++; + } + } + if (zh === 0 && en === 0) return "unknown"; + if (zh > 0 && en > 0) return zh / en >= 1.5 ? "zh" : en / zh >= 1.5 ? "en" : "mixed"; + return zh > 0 ? "zh" : "en"; +} + +function extractErrorCodes(text: string): string[] { + return Array.from(text.matchAll(/\b[A-Z][A-Z0-9]{2,}_[A-Z0-9_]+\b/g), (match) => match[0]!); +} + +function parseStringArray(raw: string | null): string[] { + if (!raw) return []; + try { + const value: unknown = JSON.parse(raw); + return Array.isArray(value) + ? value.filter((item): item is string => typeof item === "string" && item.trim().length > 0) + : []; + } catch { + return []; + } +} + +function parseJsonArray(raw: string | null): Array> { + if (!raw) return []; + try { + const value: unknown = JSON.parse(raw); + return Array.isArray(value) + ? value.filter((item): item is Record => + Boolean(item) && typeof item === "object" && !Array.isArray(item), + ) + : []; + } catch { + return []; + } +} + +function unique(values: readonly string[]): string[] { + return Array.from(new Set(values.map((value) => value.trim()).filter(Boolean))).slice(0, 32); +} + +function tableExists(db: StorageDb, table: string): boolean { + return Boolean(db.prepare<{ name: string }, { name: string }>( + `SELECT name FROM sqlite_master WHERE type='table' AND name=@name`, + ).get({ name: table })); +} + +function hasColumn(db: StorageDb, table: string, column: string): boolean { + return db.prepare(`PRAGMA table_info(${table})`) + .all() + .some((row) => row.name === column); +} diff --git a/apps/memos-local-plugin/core/storage/repos/policies.ts b/apps/memos-local-plugin/core/storage/repos/policies.ts index 29920f60a..cf769e2bc 100644 --- a/apps/memos-local-plugin/core/storage/repos/policies.ts +++ b/apps/memos-local-plugin/core/storage/repos/policies.ts @@ -1,4 +1,4 @@ -import type { EmbeddingVector, PolicyId, PolicyRow, ShareScope } from "../../types.js"; +import type { EmbeddingVector, PolicyId, PolicyMetadata, PolicyRow, ShareScope } from "../../types.js"; import type { PolicyListFilter, StorageDb } from "../types.js"; import { buildInsert, buildUpdate } from "../tx.js"; import { scanAndTopK, type VectorHit } from "../vector.js"; @@ -46,6 +46,7 @@ const COLUMNS = [ "share_target", "shared_at", "edited_at", + "metadata_json", ]; export interface PolicySearchMeta { @@ -420,6 +421,7 @@ interface RawPolicyRow { share_target: string | null; shared_at: number | null; edited_at: number | null; + metadata_json: string | null; } type RawPolicySearchRow = Pick< @@ -476,6 +478,7 @@ function rowToParams(row: PolicyRow): Record { share_target: row.share?.target ?? null, shared_at: row.share?.sharedAt ?? null, edited_at: row.editedAt ?? null, + metadata_json: row.metadata ? toJsonText(row.metadata) : null, }; } @@ -517,6 +520,30 @@ function mapRow(r: RawPolicyRow): PolicyRow { } : null, editedAt: r.edited_at, + metadata: parsePolicyMetadata(r.metadata_json), + }; +} + +function parsePolicyMetadata(raw: string | null | undefined): PolicyMetadata | undefined { + if (!raw) return undefined; + const value = fromJsonText | null>(raw, null); + if (!value || value.version !== 1) return undefined; + const language = value.language; + if (!['zh', 'en', 'other', 'mixed', 'unknown'].includes(String(language))) return undefined; + const list = (input: unknown): string[] => + Array.isArray(input) + ? Array.from(new Set(input.filter((v): v is string => typeof v === 'string' && !!v.trim()).map((v) => v.trim().slice(0, 64)))) + : []; + const sourceSignature = typeof value.sourceSignature === 'string' && value.sourceSignature.trim() + ? value.sourceSignature.trim().slice(0, 256) + : undefined; + return { + version: 1, + language: language as PolicyMetadata['language'], + domainTags: list(value.domainTags), + toolNames: list(value.toolNames), + errorCodes: list(value.errorCodes), + ...(sourceSignature ? { sourceSignature } : {}), }; } diff --git a/apps/memos-local-plugin/core/types.ts b/apps/memos-local-plugin/core/types.ts index 0e4f87f52..1256326a8 100644 --- a/apps/memos-local-plugin/core/types.ts +++ b/apps/memos-local-plugin/core/types.ts @@ -203,6 +203,17 @@ export interface PolicyRow extends OwnedRow { } | null; /** Last user edit through the viewer's edit modal (migration 009). */ editedAt?: EpochMs | null; + /** Structured provenance used by L3 clustering; optional for legacy rows. */ + metadata?: PolicyMetadata; +} + +export interface PolicyMetadata { + version: 1; + language: "zh" | "en" | "other" | "mixed" | "unknown"; + domainTags: string[]; + toolNames: string[]; + errorCodes: string[]; + sourceSignature?: string; } /** diff --git a/apps/memos-local-plugin/docs/CONFIG-ADVANCED.md b/apps/memos-local-plugin/docs/CONFIG-ADVANCED.md index 82e03230d..e25743e34 100644 --- a/apps/memos-local-plugin/docs/CONFIG-ADVANCED.md +++ b/apps/memos-local-plugin/docs/CONFIG-ADVANCED.md @@ -138,6 +138,8 @@ algorithm: minPolicyGain: 0.02 # eligible L2 gain floor (paired with shrinkage-anchored gain) minPolicySupport: 1 # eligible L2 support floor clusterMinSimilarity: 0.6 # cosine cutoff for cluster-and-merge decisions + maxPoliciesPerCluster: 20 # policies per abstraction batch; overflow is retained + maxPromptChars: 32000 # hard total prompt cap; oversized legacy batches are quarantined policyCharCap: 800 # chars per policy in the prompt traceCharCap: 500 # chars per evidence trace in the prompt traceEvidencePerPolicy: 1 # evidence traces per policy in the prompt diff --git a/apps/memos-local-plugin/tests/integration/skill-l3-full-chain.test.ts b/apps/memos-local-plugin/tests/integration/skill-l3-full-chain.test.ts new file mode 100644 index 000000000..f5c593bef --- /dev/null +++ b/apps/memos-local-plugin/tests/integration/skill-l3-full-chain.test.ts @@ -0,0 +1,279 @@ +/** + * Full local-memory verification for the repaired Skill → L3 path. + * + * This deliberately keeps the same Chinese, JSON-tool evidence that used to + * fail Skill verification, then feeds three compatible active L2 policies to + * L3. It proves the repaired boundaries in one deterministic SQLite run: + * language steering, tool-name extraction, Skill persistence, L3 creation, + * and idempotent L3 merge. + */ + +import { afterEach, describe, expect, it } from "vitest"; + +import { rootLogger } from "../../core/logger/index.js"; +import { + createL3EventBus, + runL3, + type L3Config, + type L3Event, +} from "../../core/memory/l3/index.js"; +import { L3_ABSTRACTION_PROMPT } from "../../core/llm/prompts/l3-abstraction.js"; +import { runL2, type L2Config } from "../../core/memory/l2/index.js"; +import { + createSkillEventBus, + runSkill, + type SkillEvent, +} from "../../core/skill/index.js"; +import type { EpisodeId } from "../../core/types.js"; +import { fakeLlm } from "../helpers/fake-llm.js"; +import { makeTmpDb, type TmpDbHandle } from "../helpers/tmp-db.js"; +import { + makeDraft, + makeSkillConfig, + seedSessionOnly, + seedTrace, +} from "../unit/skill/_helpers.js"; + +const L3_OP = `${L3_ABSTRACTION_PROMPT.id}.v${L3_ABSTRACTION_PROMPT.version}`; +const log = rootLogger.child({ channel: "integration.skill-l3" }); + +function l3Config(): L3Config { + return { + minPolicies: 3, + minPolicyGain: 0.1, + minPolicySupport: 2, + clusterMinSimilarity: 0.3, + maxPoliciesPerCluster: 20, + maxPromptChars: 32_000, + looseMinCohesion: 0.55, + policyCharCap: 800, + traceCharCap: 500, + traceEvidencePerPolicy: 1, + useLlm: true, + cooldownDays: 0, + confidenceDelta: 0.1, + minConfidenceForRetrieval: 0.2, + }; +} + +function l2Config(): L2Config { + return { + minSimilarity: 0.95, + candidateTtlDays: 30, + gamma: 0.9, + tauSoftmax: 0.4, + useLlm: true, + minTraceValue: 0.1, + minEpisodesForInduction: 2, + inductionTraceCharCap: 2_000, + gainEmaAlpha: 0.4, + }; +} + +describe("integration: Chinese Skill crystallization → L3 world model", () => { + let handle: TmpDbHandle | null = null; + + afterEach(() => { + handle?.cleanup(); + handle = null; + }); + + it("completes Skill verification and creates then merges one L3 model", async () => { + handle = makeTmpDb(); + const h = handle; + const groups = [ + { packageName: "cryptography", errorCode: "EXIT_1", vector: [1, 0, 0] }, + { packageName: "lxml", errorCode: "EXIT_2", vector: [0, 1, 0] }, + { packageName: "psycopg2", errorCode: "EXIT_3", vector: [0, 0, 1] }, + ] as const; + for (const [groupIndex, group] of groups.entries()) { + for (let repetition = 0; repetition < 2; repetition += 1) { + const episodeId = `ep_chain_${groupIndex + 1}_${repetition + 1}` as EpisodeId; + const sessionId = `s_chain_${groupIndex}_${repetition}`; + const toolCalls = [ + { + name: "pip", + input: JSON.stringify({ package: group.packageName }), + output: `Error: ${group.errorCode}`, + }, + { name: "execute_code", input: '{"code":"print(1)"}' }, + ]; + seedSessionOnly(h, sessionId); + seedTrace(h, { + episodeId, + sessionId, + userText: `在 Alpine 镜像中安装 ${group.packageName} 失败`, + agentText: `先执行 apk add ${group.packageName}-dev,再执行 pip install ${group.packageName}`, + reflection: "先安装系统库,再重试 pip 安装", + value: 0.9, + tags: ["alpine", "pip"], + vec: new Float32Array(group.vector), + toolCalls, + }); + } + } + + const skillEvents: SkillEvent[] = []; + const skillBus = createSkillEventBus(); + skillBus.onAny((event) => skillEvents.push(event)); + const skillPrompts: unknown[] = []; + let inductionCount = 0; + const llm = fakeLlm({ + completeJson: { + "l2.l2.induction.v2": () => { + const group = groups[inductionCount++] ?? groups[0]; + return { + title: `Alpine ${group.packageName} dependency repair`, + trigger: `pip install ${group.packageName} fails in Alpine`, + procedure: `apk add ${group.packageName}-dev then pip install ${group.packageName}`, + verification: `${group.packageName} installs successfully`, + boundary: "仅适用于 Alpine 镜像", + rationale: "多次观察到 Alpine 原生依赖缺失", + caveats: ["Alpine 使用 musl libc"], + confidence: 0.8, + }; + }, + "skill.crystallize": (input) => { + skillPrompts.push(input); + return makeDraft({ + name: "alpine_cryptography_fix", + displayTitle: "Alpine cryptography 安装修复", + summary: "在 Alpine 中先安装系统库,再重试 pip 安装 cryptography", + preconditions: ["当前环境是 Alpine 镜像"], + steps: [ + { title: "检查错误", body: "确认 pip install cryptography 安装失败" }, + { title: "安装系统库", body: "执行 apk add openssl-dev" }, + { title: "重新安装", body: "再次执行 pip install cryptography" }, + ], + tools: ["execute_code"], + tags: ["alpine", "pip"], + }); + }, + [L3_OP]: () => ({ + title: "Alpine Python dependency environment", + domain_tags: ["alpine", "python", "pip"], + environment: [ + { + label: "Alpine uses musl libc", + description: "Alpine images commonly lack glibc-linked build dependencies by default.", + }, + ], + inference: [ + { + label: "Native extensions need system headers", + description: "Python packages with native extensions fail to build when matching headers are absent.", + }, + ], + constraints: [], + body: "# Alpine Python dependency environment", + confidence: 0.75, + supersedes_world_ids: [], + }), + }, + }); + + const l2Runs = []; + const l2Deps = { + db: h.db, + repos: h.repos, + llm, + log, + config: l2Config(), + thresholds: { minSupport: 2, minGain: 0.1, archiveGain: -0.05 }, + }; + for (const group of groups) { + const traces = h.repos.traces + .list({ limit: 20 }) + .filter((trace) => trace.userText.includes(group.packageName)); + expect(traces).toHaveLength(2); + for (const trace of traces) { + l2Runs.push( + await runL2( + { + episodeId: trace.episodeId, + sessionId: trace.sessionId, + traces: [trace], + trigger: "reward.updated", + }, + l2Deps, + ), + ); + } + } + + const inducedPolicies = h.repos.policies.list({ status: "active" }); + expect(l2Runs.flatMap((run) => run.inductions).filter((induction) => induction.policyId)) + .toHaveLength(3); + expect(inducedPolicies).toHaveLength(3); + const p1 = inducedPolicies.find((policy) => policy.title.includes("cryptography")); + expect(p1).toBeDefined(); + expect(p1!.metadata?.domainTags).toEqual(["alpine", "pip"]); + expect(p1!.metadata?.toolNames).toEqual(["pip", "execute_code"]); + + const skillResult = await runSkill( + { trigger: "manual", policyId: p1!.id, episodeId: p1!.sourceEpisodeIds[0] }, + { + repos: h.repos, + embedder: null, + llm, + log, + bus: skillBus, + config: makeSkillConfig({ minSupport: 2, minGain: 0.1 }), + }, + ); + + expect(skillResult).toMatchObject({ evaluated: 1, crystallized: 1, rejected: 0 }); + expect(skillEvents).toContainEqual( + expect.objectContaining({ kind: "skill.crystallized", policyId: p1!.id }), + ); + expect(skillEvents.some((event) => event.kind === "skill.verification.failed")).toBe(false); + + const messages = skillPrompts[0] as Array<{ role: string; content: string }>; + expect(messages).toEqual( + expect.arrayContaining([ + expect.objectContaining({ role: "system", content: expect.stringContaining("简体中文") }), + ]), + ); + const payload = JSON.parse(messages.find((message) => message.role === "user")!.content) as { + evidence_tools: string[]; + }; + expect(payload.evidence_tools).toEqual(["pip", "execute_code"]); + expect(payload.evidence_tools).not.toContain('{"code":'); + + const storedSkill = h.repos.skills.list()[0]!; + expect(storedSkill.status).toBe("candidate"); + expect(storedSkill.sourcePolicyIds).toContain(p1!.id); + + const l3Events: L3Event[] = []; + const l3Bus = createL3EventBus(); + l3Bus.onAny((event) => l3Events.push(event)); + const l3Deps = { + repos: h.repos, + llm, + log, + bus: l3Bus, + config: l3Config(), + }; + + const created = await runL3( + { trigger: "l2.policy.induced", episodeId: p1!.sourceEpisodeIds[0] }, + l3Deps, + ); + expect(created.abstractions).toHaveLength(1); + expect(created.abstractions[0]).toMatchObject({ + clusterKey: "alpine|pip", + policyCount: 3, + createdNew: true, + skippedReason: null, + }); + expect(h.repos.worldModel.list()).toHaveLength(1); + expect(l3Events).toContainEqual(expect.objectContaining({ kind: "l3.world-model.created" })); + + const merged = await runL3({ trigger: "manual" }, l3Deps); + expect(merged.abstractions).toHaveLength(1); + expect(merged.abstractions[0]!.createdNew).toBe(false); + expect(merged.abstractions[0]!.mergedIntoWorldId).toBe(created.abstractions[0]!.worldModelId); + expect(h.repos.worldModel.list()).toHaveLength(1); + expect(l3Events).toContainEqual(expect.objectContaining({ kind: "l3.world-model.updated" })); + }); +}); diff --git a/apps/memos-local-plugin/tests/unit/llm/prompts.test.ts b/apps/memos-local-plugin/tests/unit/llm/prompts.test.ts index bee52730a..1e35b5e7f 100644 --- a/apps/memos-local-plugin/tests/unit/llm/prompts.test.ts +++ b/apps/memos-local-plugin/tests/unit/llm/prompts.test.ts @@ -43,6 +43,13 @@ describe("llm/prompts", () => { it("detectDominantLanguage only chooses Chinese when CJK dominates", () => { expect(detectDominantLanguage(["请修复这个问题,并解释原因"])).toBe("zh"); + expect( + detectDominantLanguage([ + "在 Alpine 镜像中安装 cryptography 失败", + "先执行 apk add openssl-dev,再执行 pip install cryptography", + "先安装系统库,再重试 pip 安装", + ]), + ).toBe("zh"); expect(detectDominantLanguage(["Excelファイルの欠落値を復元してください"])).toBe("en"); expect(detectDominantLanguage(["저는 GRPO를 사용하여 모델을 훈련시키고 있습니다"])).toBe("en"); expect(detectDominantLanguage(["GRPO / TRL / reward_fn.py"])).toBe("en"); diff --git a/apps/memos-local-plugin/tests/unit/memory/l2/induce.test.ts b/apps/memos-local-plugin/tests/unit/memory/l2/induce.test.ts index 06d61459f..52b3b3e73 100644 --- a/apps/memos-local-plugin/tests/unit/memory/l2/induce.test.ts +++ b/apps/memos-local-plugin/tests/unit/memory/l2/induce.test.ts @@ -182,6 +182,7 @@ describe("memory/l2/induce", () => { episodeIds: ["ep_1", "ep_2"] as EpisodeId[], evidenceTraces: [mkTrace("tr_a", "ep_1", vec([1, 0])), mkTrace("tr_b", "ep_2", vec([0, 1]))], inducedBy: "l2.l2.induction.v1", + sourceSignature: "docker|pip|pip.install|MODULE_NOT_FOUND", now: 42, }); expect(row.status).toBe("candidate"); @@ -191,5 +192,13 @@ describe("memory/l2/induce", () => { expect(row.vec).not.toBeNull(); expect(row.createdAt).toBe(42); expect(row.title).toBe("t"); + expect(row.metadata).toEqual(expect.objectContaining({ + version: 1, + language: "en", + domainTags: ["docker", "pip"], + toolNames: ["pip.install"], + errorCodes: ["module_not_found"], + sourceSignature: "docker|pip|pip.install|MODULE_NOT_FOUND", + })); }); }); diff --git a/apps/memos-local-plugin/tests/unit/memory/l2/l2.integration.test.ts b/apps/memos-local-plugin/tests/unit/memory/l2/l2.integration.test.ts index d9d062d1f..7cbd6b303 100644 --- a/apps/memos-local-plugin/tests/unit/memory/l2/l2.integration.test.ts +++ b/apps/memos-local-plugin/tests/unit/memory/l2/l2.integration.test.ts @@ -186,6 +186,12 @@ describe("memory/l2/integration", () => { const persisted = handle.repos.policies.getById(induced.policyId!)!; expect(persisted.status).toBe("candidate"); expect(persisted.sourceEpisodeIds.sort()).toEqual(["ep_A", "ep_B"]); + expect(persisted.metadata).toEqual(expect.objectContaining({ + version: 1, + domainTags: ["docker", "pip"], + toolNames: ["pip.install"], + sourceSignature: "docker|pip|pip.install|MODULE_NOT_FOUND", + })); // ── A third run with a trace that cosine-matches the new policy should // associate (not re-induce) and bump gain/support. diff --git a/apps/memos-local-plugin/tests/unit/memory/l3/abstract.test.ts b/apps/memos-local-plugin/tests/unit/memory/l3/abstract.test.ts index ff759b17f..2bbefa199 100644 --- a/apps/memos-local-plugin/tests/unit/memory/l3/abstract.test.ts +++ b/apps/memos-local-plugin/tests/unit/memory/l3/abstract.test.ts @@ -168,6 +168,20 @@ describe("memory/l3/abstract", () => { expect(res.reason).toBe("llm_disabled"); }); + it("skips oversized legacy batches before calling the LLM", async () => { + const llm = fakeLlm({ completeJson: { [OP]: {} } }); + const cluster = mkCluster(); + cluster.policies[0]!.procedure = "x".repeat(5_000); + const res = await abstractDraft( + { cluster, evidenceByPolicy: new Map() }, + { llm, log, config: cfg({ maxPromptChars: 4_000, policyCharCap: 4_000 }) }, + ); + expect(res.ok).toBe(false); + if (res.ok) return; + expect(res.reason).toBe("prompt_too_large"); + expect(llm.stats().requests).toBe(0); + }); + it("returns llm_failed when the LLM throws — never rethrows", async () => { const llm = throwingLlm(new Error("boom")); const res = await abstractDraft( @@ -227,4 +241,3 @@ describe("memory/l3/abstract", () => { expect(row.body).toContain("Environment"); }); }); - diff --git a/apps/memos-local-plugin/tests/unit/memory/l3/cluster.test.ts b/apps/memos-local-plugin/tests/unit/memory/l3/cluster.test.ts index cc37340b7..32e57684a 100644 --- a/apps/memos-local-plugin/tests/unit/memory/l3/cluster.test.ts +++ b/apps/memos-local-plugin/tests/unit/memory/l3/cluster.test.ts @@ -33,6 +33,7 @@ function mkPolicy(partial: Partial & { id: PolicyId }): PolicyRow { vec: partial.vec ?? vec([1, 0, 0]), createdAt: NOW, updatedAt: NOW, + metadata: partial.metadata, }; } @@ -61,6 +62,46 @@ describe("memory/l3/cluster", () => { expect(tags).toEqual([]); }); + it("prefers structured trace metadata over English-only policy prose", () => { + const p = mkPolicy({ + id: "po_zh" as PolicyId, + title: "处理依赖安装失败", + procedure: "执行包管理器并重试", + metadata: { + version: 1, + language: "zh", + domainTags: ["python", "alpine"], + toolNames: ["pip.install"], + errorCodes: ["module_not_found"], + sourceSignature: "python|alpine|pip.install|MODULE_NOT_FOUND", + }, + }); + expect(domainKeyOf(p)).toEqual({ + key: "python|pip.install", + tags: expect.arrayContaining(["python", "alpine", "pip.install", "module_not_found"]), + }); + }); + + it("keeps the legacy text fallback when backfilled metadata has no tags", () => { + const p = mkPolicy({ + id: "po_legacy" as PolicyId, + title: "修复 Docker 中的 pip 安装失败", + trigger: "pip install fails in Alpine container", + procedure: "apk add build tools before pip install", + metadata: { + version: 1, + language: "mixed", + domainTags: [], + toolNames: [], + errorCodes: [], + }, + }); + const { key, tags } = domainKeyOf(p); + expect(key).toContain("docker"); + expect(key).toContain("pip"); + expect(tags).toEqual(expect.arrayContaining(["docker", "alpine", "pip"])); + }); + it("does not create a cluster from an untagged bucket", () => { const policies = [ [1, 0, 0], diff --git a/apps/memos-local-plugin/tests/unit/memory/l3/l3.integration.test.ts b/apps/memos-local-plugin/tests/unit/memory/l3/l3.integration.test.ts index ec51e2213..7dc1cd811 100644 --- a/apps/memos-local-plugin/tests/unit/memory/l3/l3.integration.test.ts +++ b/apps/memos-local-plugin/tests/unit/memory/l3/l3.integration.test.ts @@ -346,6 +346,42 @@ describe("memory/l3/integration", () => { expect(handle.repos.kv.all().filter((row) => row.key.startsWith("l3.retry."))).toEqual([]); }); + it("quarantines a deterministically failing legacy cluster after bounded attempts", async () => { + seedTriplet(); + let calls = 0; + const llm = fakeLlm({ + completeJson: { + [OP]: () => { + calls++; + throw new Error("malformed legacy response"); + }, + }, + }); + const deps = { + repos: { + policies: handle.repos.policies, + traces: handle.repos.traces, + worldModel: handle.repos.worldModel, + kv: handle.repos.kv, + }, + llm, + log, + config: cfg(), + }; + + for (const at of [0, 300_000, 2_100_000, 9_300_000]) { + const result = await runL3({ trigger: "manual", now: NOW + at }, deps); + expect(result.abstractions[0]!.skippedReason).toBe("llm_failed"); + } + expect(calls).toBe(4); + + const quarantined = await runL3({ trigger: "manual", now: NOW + 100_000_000 }, deps); + expect(quarantined.abstractions[0]!.skippedReason).toBe("quarantined"); + expect(calls).toBe(4); + const state = handle.repos.kv.all().find((row) => row.key.startsWith("l3.retry.")); + expect(state?.value).toMatchObject({ version: 2, failures: 4, quarantined: true }); + }); + it("records retry state instead of success cooldown when persistence fails", async () => { seedTriplet(); const worldModel = { diff --git a/apps/memos-local-plugin/tests/unit/skill/skill.integration.test.ts b/apps/memos-local-plugin/tests/unit/skill/skill.integration.test.ts index 476134abc..6f1c22c80 100644 --- a/apps/memos-local-plugin/tests/unit/skill/skill.integration.test.ts +++ b/apps/memos-local-plugin/tests/unit/skill/skill.integration.test.ts @@ -14,6 +14,7 @@ import { createL2EventBus } from "../../../core/memory/l2/index.js"; import { fakeLlm } from "../../helpers/fake-llm.js"; import { makeTmpDb, type TmpDbHandle } from "../../helpers/tmp-db.js"; import type { EpisodeId, PolicyId, SkillId } from "../../../core/types.js"; +import type { ToolCallDTO } from "../../../agent-contract/dto.js"; import { makeDraft, makeSkillConfig, @@ -92,6 +93,98 @@ function seedFullCandidate(h: TmpDbHandle): { } describe("skill/runSkill (integration)", () => { + it("crystallizes a Chinese multi-episode tool workflow without resonance or tool coverage loss", async () => { + const h = open(); + const episodeIds = ["ep_cn_1", "ep_cn_2"] as EpisodeId[]; + const toolCall: ToolCallDTO = { + name: "execute_code", + input: '{"code":"print(1)"}', + }; + + for (const [index, episodeId] of episodeIds.entries()) { + const sessionId = `s_cn_${index}`; + seedSessionOnly(h, sessionId); + seedTrace(h, { + episodeId, + sessionId, + userText: "在 Alpine 镜像中安装 cryptography 失败", + agentText: "先执行 apk add openssl-dev,再执行 pip install cryptography", + reflection: "先安装系统库,再重试 pip 安装", + value: 0.9, + tags: ["alpine", "pip"], + toolCalls: [toolCall], + }); + } + + const policy = seedPolicy(h, { + id: "po_cn_workflow" as PolicyId, + title: "Alpine 中先安装系统库再重试 pip", + trigger: "Alpine 镜像中的 cryptography 安装失败", + procedure: "先执行 apk add openssl-dev,再执行 pip install cryptography", + verification: "cryptography 安装成功", + boundary: "仅适用于 Alpine 镜像", + support: 2, + gain: 0.3, + sourceEpisodeIds: episodeIds, + }); + + const prompts: unknown[] = []; + const { deps, events } = makeDeps(h, { + llm: fakeLlm({ + completeJson: { + "skill.crystallize": (input) => { + prompts.push(input); + return makeDraft({ + name: "alpine_cryptography_fix", + displayTitle: "Alpine cryptography 安装修复", + summary: "在 Alpine 中先安装系统库,再重试 pip 安装 cryptography", + preconditions: ["当前环境是 Alpine 镜像"], + steps: [ + { title: "检查错误", body: "确认 pip install cryptography 安装失败" }, + { title: "安装系统库", body: "执行 apk add openssl-dev" }, + { title: "重新安装", body: "再次执行 pip install cryptography" }, + ], + tools: ["execute_code"], + tags: ["alpine", "pip"], + }); + }, + }, + }), + config: makeSkillConfig({ minSupport: 2, minGain: 0.1 }), + }); + + const result = await runSkill({ trigger: "manual", policyId: policy.id }, deps); + + expect(result).toMatchObject({ evaluated: 1, crystallized: 1, rejected: 0 }); + expect(events).toContainEqual( + expect.objectContaining({ + kind: "skill.crystallized", + policyId: policy.id, + }), + ); + expect(events.some((event) => event.kind === "skill.verification.failed")).toBe(false); + + const messages = prompts[0] as Array<{ role: string; content: string }>; + expect(messages).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + role: "system", + content: expect.stringContaining("简体中文"), + }), + ]), + ); + const userMessage = messages.find((message) => message.role === "user"); + expect(userMessage).toBeDefined(); + const payload = JSON.parse(userMessage!.content) as { evidence_tools: string[] }; + expect(payload.evidence_tools).toEqual(["execute_code"]); + expect(payload.evidence_tools).not.toContain('{"code":'); + + const stored = h.repos.skills.list()[0]!; + expect(stored.status).toBe("candidate"); + expect(stored.sourcePolicyIds).toContain(policy.id); + expect(stored.procedureJson?.steps).toHaveLength(3); + }); + it("crystallizes a fresh skill for an eligible policy", async () => { const h = open(); const { policyId } = seedFullCandidate(h); diff --git a/apps/memos-local-plugin/tests/unit/storage/migrator.test.ts b/apps/memos-local-plugin/tests/unit/storage/migrator.test.ts index 933f59977..88e1af788 100644 --- a/apps/memos-local-plugin/tests/unit/storage/migrator.test.ts +++ b/apps/memos-local-plugin/tests/unit/storage/migrator.test.ts @@ -59,6 +59,31 @@ describe("storage/migrator", () => { } }); + it("replays the policy metadata migration after an interrupted marker write", () => { + const { dbPath, cleanup } = tmpDb(); + cleanups.push(cleanup); + const db = openDb({ filepath: dbPath, agent: "openclaw" }); + try { + runMigrations(db); + const metadataColumn = db + .prepare(`PRAGMA table_info(policies)`) + .all() + .find((row) => row.name === "metadata_json"); + expect(metadataColumn).toBeDefined(); + db.prepare<{ version: number }>(`DELETE FROM schema_migrations WHERE version=@version`) + .run({ version: 19 }); + + const replay = runMigrations(db); + expect(replay.applied.map((m) => m.version)).toContain(19); + expect(db + .prepare(`PRAGMA table_info(policies)`) + .all() + .filter((row) => row.name === "metadata_json")).toHaveLength(1); + } finally { + db.close(); + } + }); + it("rejects duplicate migration versions in a custom dir", () => { const dir = fs.mkdtempSync(path.join(os.tmpdir(), "memos-mig-dup-")); cleanups.push(() => fs.rmSync(dir, { recursive: true, force: true })); diff --git a/apps/memos-local-plugin/tests/unit/storage/policy-metadata-backfill.test.ts b/apps/memos-local-plugin/tests/unit/storage/policy-metadata-backfill.test.ts new file mode 100644 index 000000000..36dc03cb5 --- /dev/null +++ b/apps/memos-local-plugin/tests/unit/storage/policy-metadata-backfill.test.ts @@ -0,0 +1,51 @@ +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; + +import { afterEach, describe, expect, it } from "vitest"; + +import { backfillLegacyPolicyMetadata } from "../../../core/storage/policy-metadata-backfill.js"; +import { openDb, runMigrations } from "../../../core/storage/index.js"; + +describe("policy metadata backfill", () => { + const cleanups: Array<() => void> = []; + + afterEach(() => { + while (cleanups.length) cleanups.pop()!(); + }); + + it("backfills old rows in bounded, idempotent batches", () => { + const dir = fs.mkdtempSync(path.join(os.tmpdir(), "memos-meta-")); + const dbPath = path.join(dir, "m.db"); + cleanups.push(() => fs.rmSync(dir, { recursive: true, force: true })); + const db = openDb({ filepath: dbPath, agent: "openclaw" }); + try { + runMigrations(db); + db.exec(` + INSERT INTO sessions (id, agent, started_at, last_seen_at) VALUES ('s1', 'openclaw', 1, 1); + INSERT INTO episodes (id, session_id, started_at) VALUES ('e1', 's1', 1); + INSERT INTO traces (id, episode_id, session_id, ts, user_text, agent_text, reflection, tool_calls_json, tags_json, turn_id) + VALUES ('t1', 'e1', 's1', 1, '请修复部署', '部署失败 DEPLOY_TIMEOUT', '重试服务', + '[{"name":"kubectl","input":"{\\"code\\":1}"}]', '["k8s","部署"]', 1); + INSERT INTO policies (id, title, trigger, procedure, verification, boundary, source_trace_ids_json, created_at, updated_at) + VALUES ('p1', 'legacy policy', 'trigger', 'procedure', 'verify', 'boundary', '["t1"]', 1, 1); + `); + + const replay = runMigrations(db); + expect(replay.metadataBackfilled).toBe(1); + const row = db.prepare<{ id: string }, { metadata_json: string | null }>( + `SELECT metadata_json FROM policies WHERE id=@id`, + ).get({ id: "p1" }); + expect(JSON.parse(row!.metadata_json!)).toMatchObject({ + version: 1, + language: "mixed", + domainTags: ["k8s", "部署"], + toolNames: ["kubectl"], + errorCodes: ["DEPLOY_TIMEOUT"], + }); + expect(backfillLegacyPolicyMetadata(db, { batchSize: 1 })).toBe(0); + } finally { + db.close(); + } + }); +}); From 0f3265a5a6b9a800795855fbd7547df026fc61f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=81=E5=9C=A8=E5=90=B5=E7=9D=80=E5=90=83=E7=B3=96?= Date: Mon, 21 Sep 2026 17:48:50 +0800 Subject: [PATCH 08/38] fix(plugin): wire skill evolver model into evolution --- apps/memos-local-plugin/core/pipeline/deps.ts | 15 ++--- .../core/pipeline/memory-core.ts | 2 +- .../memos-local-plugin/core/pipeline/types.ts | 4 +- .../capture-reflect-llm-wiring.test.ts | 64 +++++++++++++++++++ 4 files changed, 74 insertions(+), 11 deletions(-) diff --git a/apps/memos-local-plugin/core/pipeline/deps.ts b/apps/memos-local-plugin/core/pipeline/deps.ts index 79714b35e..f3048fbbe 100644 --- a/apps/memos-local-plugin/core/pipeline/deps.ts +++ b/apps/memos-local-plugin/core/pipeline/deps.ts @@ -217,7 +217,7 @@ export function buildPipelineSubscribers( const log = deps.log ?? rootLogger.child({ channel: "core.pipeline" }); const bgLlmSemaphore = createSemaphore(algorithm.session.bgLlmConcurrency); const bgLlm = rateLimitLlmClient(deps.llm, bgLlmSemaphore, resources); - const bgReflectLlm = rateLimitLlmClient(deps.reflectLlm, bgLlmSemaphore, resources); + const bgEvolverLlm = rateLimitLlmClient(deps.reflectLlm ?? deps.llm, bgLlmSemaphore, resources); const bgL3Llm = rateLimitLlmClient(deps.l3Llm ?? deps.llm, bgLlmSemaphore, resources); const bgEmbedder = resources ? prioritizeEmbedder(deps.embedder, resources, "background") @@ -233,9 +233,8 @@ export function buildPipelineSubscribers( // Issue #2148: capture batch reflection emits JSON, so it must use // the main model rather than the potentially thinking-enabled // skill-evolver model. Keep the background wrapper so capture also - // participates in the shared concurrency limit. `bgReflectLlm` - // remains read-only evaluator metadata below; the original - // `deps.reflectLlm` is also exposed to the Overview health card. + // participates in the shared concurrency limit. The dedicated + // evolver client is used by L2 induction and skill crystallization. reflectLlm: bgLlm, bus: buses.capture, cfg: algorithm.capture, @@ -276,8 +275,8 @@ export function buildPipelineSubscribers( bus: buses.reward, cfg: algorithm.reward, evaluator: { - reflectionProvider: bgReflectLlm?.provider, - reflectionModel: bgReflectLlm?.model, + reflectionProvider: bgLlm?.provider, + reflectionModel: bgLlm?.model, scorerProvider: bgLlm?.provider, scorerModel: bgLlm?.model, }, @@ -311,7 +310,7 @@ export function buildPipelineSubscribers( repos: deps.repos, rewardBus: buses.reward, l2Bus: buses.l2, - llm: bgLlm, + llm: bgEvolverLlm, log: log.child({ channel: "core.memory.l2" }), config: algorithm.l2Induction, thresholds: { @@ -336,7 +335,7 @@ export function buildPipelineSubscribers( const skillHandle = attachSkillSubscriber({ repos: deps.repos, embedder: bgEmbedder, - llm: bgLlm, + llm: bgEvolverLlm, bus: buses.skill, l2Bus: buses.l2, rewardBus: buses.reward, diff --git a/apps/memos-local-plugin/core/pipeline/memory-core.ts b/apps/memos-local-plugin/core/pipeline/memory-core.ts index 660ea737c..c7b2782e4 100644 --- a/apps/memos-local-plugin/core/pipeline/memory-core.ts +++ b/apps/memos-local-plugin/core/pipeline/memory-core.ts @@ -426,7 +426,7 @@ export async function bootstrapMemoryCoreFull( llm = null; } - // Build a dedicated LLM for the reflection phase from skillEvolver + // Build a dedicated LLM for L2 induction and skills from skillEvolver // config when the user has configured a stronger model there. Falls // back to the main `llm` when skillEvolver.model is blank. let reflectLlm: ReturnType | null = null; diff --git a/apps/memos-local-plugin/core/pipeline/types.ts b/apps/memos-local-plugin/core/pipeline/types.ts index 4e20bfada..05c8c2d7b 100644 --- a/apps/memos-local-plugin/core/pipeline/types.ts +++ b/apps/memos-local-plugin/core/pipeline/types.ts @@ -144,7 +144,7 @@ export interface PipelineDeps { repos: Repos; llm: LlmClient | null; /** - * Dedicated LLM for the topic-end reflection + α scoring pass. + * Dedicated LLM for L2 induction and skill crystallization. * Built from `config.skillEvolver.*` when the user configures a * stronger model for skill evolution; falls back to `llm` when * absent. Summarization and per-turn lite capture still use `llm`. @@ -181,7 +181,7 @@ export interface PipelineHandle { readonly repos: Repos; readonly llm: LlmClient | null; /** - * Dedicated client for skill-evolution reflection. When the operator + * Dedicated client for L2 induction and skill crystallization. When the operator * leaves `skillEvolver.*` blank, this is the same instance as `llm` * (so call sites can blindly read whichever is non-null). When they * configure their own model it carries its own `stats()` so the diff --git a/apps/memos-local-plugin/tests/unit/pipeline/capture-reflect-llm-wiring.test.ts b/apps/memos-local-plugin/tests/unit/pipeline/capture-reflect-llm-wiring.test.ts index 3eede9e1c..20013e980 100644 --- a/apps/memos-local-plugin/tests/unit/pipeline/capture-reflect-llm-wiring.test.ts +++ b/apps/memos-local-plugin/tests/unit/pipeline/capture-reflect-llm-wiring.test.ts @@ -29,6 +29,46 @@ const captureRunnerCalls: Array<{ llm: LlmClient | null; reflectLlm: LlmClient | null; }> = []; +const evolutionSubscriberCalls: Array<{ + l2Llm: LlmClient | null; + skillLlm: LlmClient | null; +}> = []; + +vi.mock("../../../core/memory/l2/index.js", async () => { + const actual = await vi.importActual< + typeof import("../../../core/memory/l2/index.js") + >("../../../core/memory/l2/index.js"); + return { + ...actual, + attachL2Subscriber: (deps: { llm: LlmClient | null; [k: string]: unknown }) => { + evolutionSubscriberCalls.push({ + l2Llm: deps.llm, + skillLlm: null, + }); + return actual.attachL2Subscriber( + deps as Parameters[0], + ); + }, + }; +}); + +vi.mock("../../../core/skill/index.js", async () => { + const actual = await vi.importActual< + typeof import("../../../core/skill/index.js") + >("../../../core/skill/index.js"); + return { + ...actual, + attachSkillSubscriber: (deps: { llm: LlmClient | null; [k: string]: unknown }) => { + evolutionSubscriberCalls.push({ + l2Llm: null, + skillLlm: deps.llm, + }); + return actual.attachSkillSubscriber( + deps as Parameters[0], + ); + }, + }; +}); vi.mock("../../../core/capture/index.js", async () => { const actual = await vi.importActual< @@ -141,6 +181,7 @@ function buildDepsWithDistinctLlms( beforeEach(() => { dbHandle = makeTmpDb(); captureRunnerCalls.length = 0; + evolutionSubscriberCalls.length = 0; }); afterEach(() => { @@ -189,4 +230,27 @@ describe("pipeline/deps captureRunner wiring (issue #2148)", () => { expect(call.reflectLlm).toBe(call.llm); expect(call.reflectLlm?.model).toBe("main-llm"); }); + + it("passes the dedicated skill-evolver model to L2 induction and skill crystallization", () => { + const buses = buildPipelineBuses(); + const deps = buildDepsWithDistinctLlms(dbHandle!, false); + const algorithm = extractAlgorithmConfig(deps); + const session = buildPipelineSession(deps, buses.session); + buildPipelineSubscribers(deps, buses, algorithm, session); + + expect(evolutionSubscriberCalls[0].l2Llm?.model).toBe("skill-evolver-llm"); + expect(evolutionSubscriberCalls[1].skillLlm?.model).toBe("skill-evolver-llm"); + expect(evolutionSubscriberCalls[0].l2Llm).toBe(evolutionSubscriberCalls[1].skillLlm); + }); + + it("inherits the main model when no dedicated evolver client is available", () => { + const buses = buildPipelineBuses(); + const deps = buildDepsWithDistinctLlms(dbHandle!, false); + deps.reflectLlm = null; + buildPipelineSubscribers(deps, buses, extractAlgorithmConfig(deps)); + + expect(evolutionSubscriberCalls[0].l2Llm?.model).toBe("main-llm"); + expect(evolutionSubscriberCalls[1].skillLlm?.model).toBe("main-llm"); + }); + }); From a92484972d0191a0a1a144d5d863f9491354484e Mon Sep 17 00:00:00 2001 From: MLittleprince Date: Mon, 21 Sep 2026 20:11:28 +0800 Subject: [PATCH 09/38] ci: extend npm release visibility window --- .../scripts/prepare-memos-release.test.mjs | 2 +- .github/scripts/publish-local-plugin.sh | 4 +-- .github/scripts/publish-local-plugin.test.mjs | 6 ++-- .../wait-for-local-plugin-npm-release.mjs | 10 ++++-- ...wait-for-local-plugin-npm-release.test.mjs | 33 +++++++++++++++++++ .../workflows/memos-local-plugin-publish.yml | 4 +-- 6 files changed, 50 insertions(+), 9 deletions(-) diff --git a/.github/scripts/prepare-memos-release.test.mjs b/.github/scripts/prepare-memos-release.test.mjs index d88795930..fd10e75d4 100644 --- a/.github/scripts/prepare-memos-release.test.mjs +++ b/.github/scripts/prepare-memos-release.test.mjs @@ -842,7 +842,7 @@ test("legacy standalone local-plugin publisher requires an extra non-dry-run con assert.match(workflow, /ALLOW_STAGED_TAG_BEFORE_NPM/); assert.match(workflow, /audit-local-plugin-package\.mjs/); assert.match(workflow, /wait-for-local-plugin-npm-release\.test\.mjs/); - assert.match(workflow, /NPM_VISIBILITY_TIMEOUT_SECONDS: "150"/); + assert.match(workflow, /NPM_VISIBILITY_TIMEOUT_SECONDS: "360"/); assert.match(workflow, /FORCE_PACKAGE_ONLY_RELEASE: \$\{\{ inputs\.tag != 'latest' \|\| contains\(inputs\.version, '-'\) \}\}/); assert.match(workflow, /if \[ -n "\$\{DOCS_SYNC_MODE\}" \]; then/); assert.doesNotMatch(workflow, /EVENT_NAME: \$\{\{ github\.event_name \}\}/); diff --git a/.github/scripts/publish-local-plugin.sh b/.github/scripts/publish-local-plugin.sh index 034a00d8c..0344f125f 100755 --- a/.github/scripts/publish-local-plugin.sh +++ b/.github/scripts/publish-local-plugin.sh @@ -13,7 +13,7 @@ if [ ! -s "${RELEASE_TARBALL}" ]; then exit 2 fi -npm_visibility_timeout_seconds="${NPM_VISIBILITY_TIMEOUT_SECONDS:-150}" +npm_visibility_timeout_seconds="${NPM_VISIBILITY_TIMEOUT_SECONDS:-360}" npm_visibility_interval_seconds="${NPM_VISIBILITY_INTERVAL_SECONDS:-10}" npm_visibility_request_timeout_seconds="${NPM_VISIBILITY_REQUEST_TIMEOUT_SECONDS:-8}" npm_registry_url="https://registry.npmjs.org" @@ -336,7 +336,7 @@ if npm_version_exists; then published_version_visible=true published_version_preexisting=true if [ "${RECOVER_EXISTING_NPM_RELEASE:-false}" != "true" ]; then - echo "::error::${PACKAGE_NAME}@${RELEASE_VERSION} already exists. Normal releases require an unused version; enable recovery only after release-owner verification of a partial failure." + echo "::error::${PACKAGE_NAME}@${RELEASE_VERSION} already exists. Normal releases require an unused version; inspect npm first and use explicit recovery only after release-owner verification of a partial failure." exit 1 fi if remote_tag_exists "${RELEASE_TAG}"; then diff --git a/.github/scripts/publish-local-plugin.test.mjs b/.github/scripts/publish-local-plugin.test.mjs index 2e7864545..92474b1e2 100644 --- a/.github/scripts/publish-local-plugin.test.mjs +++ b/.github/scripts/publish-local-plugin.test.mjs @@ -121,7 +121,7 @@ if [[ "\${1:-}" == *"wait-for-local-plugin-npm-release.mjs" ]]; then printf '%s' "\${count}" > "\${increment_file}" case "\${NPM_MOCK_SCENARIO}" in always-missing|publish-fails) - echo "::error::npm release was not fully visible within 150s" + echo "::error::npm release was not fully visible within \${NPM_VISIBILITY_TIMEOUT_SECONDS:-360}s" exit 1 ;; integrity-mismatch) @@ -130,7 +130,7 @@ if [[ "\${1:-}" == *"wait-for-local-plugin-npm-release.mjs" ]]; then ;; *) if [ "\${NPM_MOCK_DIST_TAG_VERSION:-\${RELEASE_VERSION}}" != "\${RELEASE_VERSION}" ]; then - echo "::error::npm release was not fully visible within 150s: dist-tag \${NPM_DIST_TAG} did not point to \${RELEASE_VERSION}" + echo "::error::npm release was not fully visible within \${NPM_VISIBILITY_TIMEOUT_SECONDS:-360}s: dist-tag \${NPM_DIST_TAG} did not point to \${RELEASE_VERSION}" exit 1 fi echo '{"ok":true,"attempts":3}' @@ -330,6 +330,7 @@ test("stops before tag creation when publish succeeds but visibility remains del assert.equal(result.metadataWaitCount, 1); assert.equal(result.packCount, 0); assert.match(result.stdout + result.stderr, /Refusing to issue a second publish request/); + assert.match(result.stdout + result.stderr, /within 360s/); }); test("allows npm publish after a staged paired Draft Release only in npm-only phase", () => { @@ -461,4 +462,5 @@ test("rejects an already-used npm version outside explicit recovery", () => { assert.equal(result.publishCount, 0); assert.equal(result.packCount, 0); assert.match(result.stdout + result.stderr, /Normal releases require an unused version/); + assert.match(result.stdout + result.stderr, /inspect npm first/); }); diff --git a/.github/scripts/wait-for-local-plugin-npm-release.mjs b/.github/scripts/wait-for-local-plugin-npm-release.mjs index 2c00bb198..7a3629117 100644 --- a/.github/scripts/wait-for-local-plugin-npm-release.mjs +++ b/.github/scripts/wait-for-local-plugin-npm-release.mjs @@ -3,6 +3,7 @@ import { readFileSync } from "node:fs"; import { pathToFileURL } from "node:url"; const INTEGRITY_PATTERN = /^sha512-[A-Za-z0-9+/]+={0,2}$/; +export const DEFAULT_NPM_VISIBILITY_TIMEOUT_SECONDS = 360; function clean(value) { return String(value ?? "").trim(); @@ -103,7 +104,7 @@ export async function waitForNpmReleaseVisibility( distTag, expectedIntegrity, registryUrl = "https://registry.npmjs.org", - timeoutMs = 150_000, + timeoutMs = DEFAULT_NPM_VISIBILITY_TIMEOUT_SECONDS * 1000, intervalMs = 10_000, requestTimeoutMs = 8_000, } = {}, @@ -208,7 +209,12 @@ export async function run(env = process.env) { distTag: env.NPM_DIST_TAG, expectedIntegrity, registryUrl: env.NPM_CONFIG_REGISTRY || "https://registry.npmjs.org", - timeoutMs: positiveInteger(env.NPM_VISIBILITY_TIMEOUT_SECONDS, 150, "timeout") * 1000, + timeoutMs: + positiveInteger( + env.NPM_VISIBILITY_TIMEOUT_SECONDS, + DEFAULT_NPM_VISIBILITY_TIMEOUT_SECONDS, + "timeout", + ) * 1000, intervalMs: positiveInteger(env.NPM_VISIBILITY_INTERVAL_SECONDS, 10, "interval") * 1000, requestTimeoutMs: positiveInteger(env.NPM_VISIBILITY_REQUEST_TIMEOUT_SECONDS, 8, "request timeout") * 1000, diff --git a/.github/scripts/wait-for-local-plugin-npm-release.test.mjs b/.github/scripts/wait-for-local-plugin-npm-release.test.mjs index b3aabf84e..85ac37686 100644 --- a/.github/scripts/wait-for-local-plugin-npm-release.test.mjs +++ b/.github/scripts/wait-for-local-plugin-npm-release.test.mjs @@ -6,6 +6,7 @@ import { join } from "node:path"; import test from "node:test"; import { + DEFAULT_NPM_VISIBILITY_TIMEOUT_SECONDS, inspectNpmReleaseVisibility, npmPackumentUrl, tarballIntegrity, @@ -224,3 +225,35 @@ test("uses a hard deadline for an unavailable registry version", async () => { assert.equal(clock, 30_000); assert.equal(attempts, 3); }); + +test("uses the six-minute default visibility deadline", async () => { + let clock = 0; + let attempts = 0; + await assert.rejects( + waitForNpmReleaseVisibility( + { + packageName: "@memtensor/memos-local-plugin", + version: "2.0.14", + distTag: "latest", + expectedIntegrity: integrity, + intervalMs: 10_000, + requestTimeoutMs: 1_000, + }, + { + fetchImpl: async () => { + attempts += 1; + return response({}, 404); + }, + sleep: async (milliseconds) => { + clock += milliseconds; + }, + now: () => clock, + log: () => {}, + }, + ), + /not fully visible within 360s/, + ); + assert.equal(DEFAULT_NPM_VISIBILITY_TIMEOUT_SECONDS, 360); + assert.equal(clock, 360_000); + assert.equal(attempts, 36); +}); diff --git a/.github/workflows/memos-local-plugin-publish.yml b/.github/workflows/memos-local-plugin-publish.yml index 52d634384..dd39ac050 100644 --- a/.github/workflows/memos-local-plugin-publish.yml +++ b/.github/workflows/memos-local-plugin-publish.yml @@ -30,7 +30,7 @@ on: type: boolean default: true recover_existing_npm_release: - description: "Allow reconstructing a missing tag for an existing npm version. Keep false for normal releases." + description: "Recover a verified partial publish only; keep false for normal releases." required: true type: boolean default: false @@ -799,7 +799,7 @@ jobs: NPM_DIST_TAG: ${{ inputs.tag }} RECOVER_EXISTING_NPM_RELEASE: ${{ inputs.recover_existing_npm_release }} RELEASE_METADATA_STATE: ${{ steps.release_state.outputs.state }} - NPM_VISIBILITY_TIMEOUT_SECONDS: "150" + NPM_VISIBILITY_TIMEOUT_SECONDS: "360" NPM_VISIBILITY_INTERVAL_SECONDS: "10" NPM_VISIBILITY_REQUEST_TIMEOUT_SECONDS: "8" ALLOW_STAGED_TAG_BEFORE_NPM: ${{ (inputs.publish_phase || 'full') == 'publish_npm_only' && 'true' || 'false' }} From faf994e16290a4051fcfbe239d897c559d0c4aa8 Mon Sep 17 00:00:00 2001 From: MLittleprince Date: Mon, 21 Sep 2026 20:27:27 +0800 Subject: [PATCH 10/38] ci: extend npm release visibility window to ten minutes --- .github/scripts/prepare-memos-release.test.mjs | 2 +- .github/scripts/publish-local-plugin.sh | 2 +- .github/scripts/publish-local-plugin.test.mjs | 6 +++--- .github/scripts/wait-for-local-plugin-npm-release.mjs | 2 +- .../scripts/wait-for-local-plugin-npm-release.test.mjs | 10 +++++----- .github/workflows/memos-local-plugin-publish.yml | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/scripts/prepare-memos-release.test.mjs b/.github/scripts/prepare-memos-release.test.mjs index fd10e75d4..ffe51247e 100644 --- a/.github/scripts/prepare-memos-release.test.mjs +++ b/.github/scripts/prepare-memos-release.test.mjs @@ -842,7 +842,7 @@ test("legacy standalone local-plugin publisher requires an extra non-dry-run con assert.match(workflow, /ALLOW_STAGED_TAG_BEFORE_NPM/); assert.match(workflow, /audit-local-plugin-package\.mjs/); assert.match(workflow, /wait-for-local-plugin-npm-release\.test\.mjs/); - assert.match(workflow, /NPM_VISIBILITY_TIMEOUT_SECONDS: "360"/); + assert.match(workflow, /NPM_VISIBILITY_TIMEOUT_SECONDS: "600"/); assert.match(workflow, /FORCE_PACKAGE_ONLY_RELEASE: \$\{\{ inputs\.tag != 'latest' \|\| contains\(inputs\.version, '-'\) \}\}/); assert.match(workflow, /if \[ -n "\$\{DOCS_SYNC_MODE\}" \]; then/); assert.doesNotMatch(workflow, /EVENT_NAME: \$\{\{ github\.event_name \}\}/); diff --git a/.github/scripts/publish-local-plugin.sh b/.github/scripts/publish-local-plugin.sh index 0344f125f..399b8ad10 100755 --- a/.github/scripts/publish-local-plugin.sh +++ b/.github/scripts/publish-local-plugin.sh @@ -13,7 +13,7 @@ if [ ! -s "${RELEASE_TARBALL}" ]; then exit 2 fi -npm_visibility_timeout_seconds="${NPM_VISIBILITY_TIMEOUT_SECONDS:-360}" +npm_visibility_timeout_seconds="${NPM_VISIBILITY_TIMEOUT_SECONDS:-600}" npm_visibility_interval_seconds="${NPM_VISIBILITY_INTERVAL_SECONDS:-10}" npm_visibility_request_timeout_seconds="${NPM_VISIBILITY_REQUEST_TIMEOUT_SECONDS:-8}" npm_registry_url="https://registry.npmjs.org" diff --git a/.github/scripts/publish-local-plugin.test.mjs b/.github/scripts/publish-local-plugin.test.mjs index 92474b1e2..e661dfd1c 100644 --- a/.github/scripts/publish-local-plugin.test.mjs +++ b/.github/scripts/publish-local-plugin.test.mjs @@ -121,7 +121,7 @@ if [[ "\${1:-}" == *"wait-for-local-plugin-npm-release.mjs" ]]; then printf '%s' "\${count}" > "\${increment_file}" case "\${NPM_MOCK_SCENARIO}" in always-missing|publish-fails) - echo "::error::npm release was not fully visible within \${NPM_VISIBILITY_TIMEOUT_SECONDS:-360}s" + echo "::error::npm release was not fully visible within \${NPM_VISIBILITY_TIMEOUT_SECONDS:-600}s" exit 1 ;; integrity-mismatch) @@ -130,7 +130,7 @@ if [[ "\${1:-}" == *"wait-for-local-plugin-npm-release.mjs" ]]; then ;; *) if [ "\${NPM_MOCK_DIST_TAG_VERSION:-\${RELEASE_VERSION}}" != "\${RELEASE_VERSION}" ]; then - echo "::error::npm release was not fully visible within \${NPM_VISIBILITY_TIMEOUT_SECONDS:-360}s: dist-tag \${NPM_DIST_TAG} did not point to \${RELEASE_VERSION}" + echo "::error::npm release was not fully visible within \${NPM_VISIBILITY_TIMEOUT_SECONDS:-600}s: dist-tag \${NPM_DIST_TAG} did not point to \${RELEASE_VERSION}" exit 1 fi echo '{"ok":true,"attempts":3}' @@ -330,7 +330,7 @@ test("stops before tag creation when publish succeeds but visibility remains del assert.equal(result.metadataWaitCount, 1); assert.equal(result.packCount, 0); assert.match(result.stdout + result.stderr, /Refusing to issue a second publish request/); - assert.match(result.stdout + result.stderr, /within 360s/); + assert.match(result.stdout + result.stderr, /within 600s/); }); test("allows npm publish after a staged paired Draft Release only in npm-only phase", () => { diff --git a/.github/scripts/wait-for-local-plugin-npm-release.mjs b/.github/scripts/wait-for-local-plugin-npm-release.mjs index 7a3629117..fda985310 100644 --- a/.github/scripts/wait-for-local-plugin-npm-release.mjs +++ b/.github/scripts/wait-for-local-plugin-npm-release.mjs @@ -3,7 +3,7 @@ import { readFileSync } from "node:fs"; import { pathToFileURL } from "node:url"; const INTEGRITY_PATTERN = /^sha512-[A-Za-z0-9+/]+={0,2}$/; -export const DEFAULT_NPM_VISIBILITY_TIMEOUT_SECONDS = 360; +export const DEFAULT_NPM_VISIBILITY_TIMEOUT_SECONDS = 600; function clean(value) { return String(value ?? "").trim(); diff --git a/.github/scripts/wait-for-local-plugin-npm-release.test.mjs b/.github/scripts/wait-for-local-plugin-npm-release.test.mjs index 85ac37686..d9f9b4f2b 100644 --- a/.github/scripts/wait-for-local-plugin-npm-release.test.mjs +++ b/.github/scripts/wait-for-local-plugin-npm-release.test.mjs @@ -226,7 +226,7 @@ test("uses a hard deadline for an unavailable registry version", async () => { assert.equal(attempts, 3); }); -test("uses the six-minute default visibility deadline", async () => { +test("uses the ten-minute default visibility deadline", async () => { let clock = 0; let attempts = 0; await assert.rejects( @@ -251,9 +251,9 @@ test("uses the six-minute default visibility deadline", async () => { log: () => {}, }, ), - /not fully visible within 360s/, + /not fully visible within 600s/, ); - assert.equal(DEFAULT_NPM_VISIBILITY_TIMEOUT_SECONDS, 360); - assert.equal(clock, 360_000); - assert.equal(attempts, 36); + assert.equal(DEFAULT_NPM_VISIBILITY_TIMEOUT_SECONDS, 600); + assert.equal(clock, 600_000); + assert.equal(attempts, 60); }); diff --git a/.github/workflows/memos-local-plugin-publish.yml b/.github/workflows/memos-local-plugin-publish.yml index dd39ac050..60478c396 100644 --- a/.github/workflows/memos-local-plugin-publish.yml +++ b/.github/workflows/memos-local-plugin-publish.yml @@ -799,7 +799,7 @@ jobs: NPM_DIST_TAG: ${{ inputs.tag }} RECOVER_EXISTING_NPM_RELEASE: ${{ inputs.recover_existing_npm_release }} RELEASE_METADATA_STATE: ${{ steps.release_state.outputs.state }} - NPM_VISIBILITY_TIMEOUT_SECONDS: "360" + NPM_VISIBILITY_TIMEOUT_SECONDS: "600" NPM_VISIBILITY_INTERVAL_SECONDS: "10" NPM_VISIBILITY_REQUEST_TIMEOUT_SECONDS: "8" ALLOW_STAGED_TAG_BEFORE_NPM: ${{ (inputs.publish_phase || 'full') == 'publish_npm_only' && 'true' || 'false' }} From 1c0fb1d82eecadd4cce3910cc8ca144d4bb5f240 Mon Sep 17 00:00:00 2001 From: MLittleprince Date: Tue, 22 Sep 2026 01:19:37 +0800 Subject: [PATCH 11/38] ci: retrigger pull request review From a318a6eca029891602b87675902c7b14d2e1b7f6 Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 22 Sep 2026 16:09:09 +0800 Subject: [PATCH 12/38] docs: align Chinese contribution links with the English docs Co-authored-by: Cursor --- .../open_source/contribution/development_workflow.md | 2 +- docs/cn/open_source/contribution/overview.md | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/cn/open_source/contribution/development_workflow.md b/docs/cn/open_source/contribution/development_workflow.md index 088784fb8..0f8353998 100644 --- a/docs/cn/open_source/contribution/development_workflow.md +++ b/docs/cn/open_source/contribution/development_workflow.md @@ -48,7 +48,7 @@ git fetch upstream git rebase upstream/dev # 把你的 feat 分支基于最新 dev 重放 ``` -提交更改时请遵循项目的提交规范(参见 [提交规范](commit_guidelines.md))。 +提交更改时请遵循项目的提交规范(参见 [提交规范](./commit_guidelines.md))。 #### 推送到你的 Fork 仓库 diff --git a/docs/cn/open_source/contribution/overview.md b/docs/cn/open_source/contribution/overview.md index 83f58c4bc..61678a8ac 100644 --- a/docs/cn/open_source/contribution/overview.md +++ b/docs/cn/open_source/contribution/overview.md @@ -3,11 +3,11 @@ title: 参与 MemOS 开发 desc: 欢迎阅读 MemOS 贡献指南!了解如何配置开发环境、遵循我们的开发流程、撰写规范的提交信息、完善文档以及添加测试用例。 --- -- **首次贡献者:** 请先阅读 [环境配置指南](setting_up.md),以准备你的开发环境。 -- **准备开始编码了吗?** 请查看 [开发流程](development_workflow.md) 指南,了解我们提交更改的流程。 -- **撰写规范的提交信息:** 请参考我们的 [提交规范](commit_guidelines.md)。 -- **参与文档编写:** 如果你正在帮助我们改进文档,请阅读 [文档编写指南](writing_docs.md)。 -- **添加或完善测试用例:** 请参考 [测试编写指南](writing_tests.md)。 +- **首次贡献者:** 请先阅读 [环境配置指南](./setting_up.md),以准备你的开发环境。 +- **准备开始编码了吗?** 请查看 [开发流程](./development_workflow.md) 指南,了解我们提交更改的流程。 +- **撰写规范的提交信息:** 请参考我们的 [提交规范](./commit_guidelines.md)。 +- **参与文档编写:** 如果你正在帮助我们改进文档,请阅读 [文档编写指南](./writing_docs.md)。 +- **添加或完善测试用例:** 请参考 [测试编写指南](./writing_tests.md)。 你的贡献让这个项目更加优秀!✨ 如果有任何问题,欢迎提交 issue 或参与讨论,也可以扫描下方二维码加入我们的 Discord 或微信社群与我们联系。 From 568e9a1cfe007312732db88476629334c9cf9d9f Mon Sep 17 00:00:00 2001 From: Wang Daoji <75928131+Wang-Daoji@users.noreply.github.com> Date: Mon, 28 Sep 2026 20:09:33 -0700 Subject: [PATCH 13/38] fix: recall playground memories from every searched cube (#2436) Playground only kept the first cube in text_mem, so personal memories were dropped when a knowledge-base cube came first. Co-authored-by: Cursor --- src/memos/api/handlers/chat_handler.py | 24 ++++++++++++------------ tests/api/test_playground_cube_recall.py | 24 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 tests/api/test_playground_cube_recall.py diff --git a/src/memos/api/handlers/chat_handler.py b/src/memos/api/handlers/chat_handler.py index 58a96cd75..31acec6d0 100644 --- a/src/memos/api/handlers/chat_handler.py +++ b/src/memos/api/handlers/chat_handler.py @@ -482,12 +482,8 @@ def generate_chat_response() -> Generator[str, None, None]: yield f"data: {json.dumps({'type': 'status', 'data': '1'})}\n\n" - # Extract memories from search results (first search) - memories_list = [] - if search_response.data and search_response.data.get("text_mem"): - text_mem_results = search_response.data["text_mem"] - if text_mem_results and text_mem_results[0].get("memories"): - memories_list = text_mem_results[0]["memories"] + # Extract memories from every searched cube (first search) + memories_list = self._memories_from_cube_results(search_response.data) # Filter memories by threshold filtered_memories = self._filter_memories_by_threshold(memories_list)[:5] @@ -577,12 +573,8 @@ def generate_chat_response() -> Generator[str, None, None]: project_id=chat_req.project_id, ) - # Extract memories from search results (second search) - memories_list = [] - if search_response.data and search_response.data.get("text_mem"): - text_mem_results = search_response.data["text_mem"] - if text_mem_results and text_mem_results[0].get("memories"): - memories_list = text_mem_results[0]["memories"] + # Extract memories from every searched cube (second search) + memories_list = self._memories_from_cube_results(search_response.data) # Filter memories by threshold, min_num is the min number of memories for playground second_filtered_memories = self._filter_memories_by_threshold( @@ -1161,6 +1153,14 @@ def _format_mem_block( return "\n".join(lines_o), "\n".join(lines_p) + @staticmethod + def _memories_from_cube_results(search_data: dict[str, Any] | None) -> list[Any]: + """Collect textual memories from every cube in a search response.""" + memories_list: list[Any] = [] + for cube_result in (search_data or {}).get("text_mem") or []: + memories_list.extend(cube_result.get("memories") or []) + return memories_list + def _filter_memories_by_threshold( self, memories: list, diff --git a/tests/api/test_playground_cube_recall.py b/tests/api/test_playground_cube_recall.py new file mode 100644 index 000000000..4b1d8fd40 --- /dev/null +++ b/tests/api/test_playground_cube_recall.py @@ -0,0 +1,24 @@ +"""Playground recall must keep memories from every searched cube.""" + +from memos.api.handlers.chat_handler import ChatHandler + + +def test_playground_recall_keeps_memories_from_later_cubes(): + search_data = { + "text_mem": [ + {"cube_id": "knowledge-base", "memories": []}, + { + "cube_id": "personal", + "memories": [{"id": "mem-1", "memory": "use event_id as the idempotency key"}], + }, + ] + } + + memories = ChatHandler._memories_from_cube_results(search_data) + + assert [item["id"] for item in memories] == ["mem-1"] + + +def test_playground_recall_returns_empty_when_search_data_missing(): + assert ChatHandler._memories_from_cube_results(None) == [] + assert ChatHandler._memories_from_cube_results({}) == [] From aba1391324f5ed1db2da8fe9b74e22be0002c0dc Mon Sep 17 00:00:00 2001 From: Daoji Wang <627665797@qq.com> Date: Thu, 8 Oct 2026 16:30:32 +0800 Subject: [PATCH 14/38] fix: skip vision calls for non-sendable image URLs Relative markdown paths such as images/.jpg were forwarded to the vision API and rejected as invalid base64. Co-authored-by: Cursor --- .../read_multi_modal/image_parser.py | 19 +++++ tests/mem_reader/test_image_parser.py | 76 +++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 tests/mem_reader/test_image_parser.py diff --git a/src/memos/mem_reader/read_multi_modal/image_parser.py b/src/memos/mem_reader/read_multi_modal/image_parser.py index ec19ba304..40561c430 100644 --- a/src/memos/mem_reader/read_multi_modal/image_parser.py +++ b/src/memos/mem_reader/read_multi_modal/image_parser.py @@ -27,6 +27,18 @@ logger = get_logger(__name__) +def is_sendable_image_url(url: str) -> bool: + """Return whether a vision API can accept this image address. + + Accepted forms are http(s) URLs and ``data:image/...;base64,...`` payloads. + Relative paths such as ``images/.jpg`` are rejected. + """ + candidate = url.strip().lower() + if candidate.startswith(("http://", "https://")): + return True + return candidate.startswith("data:image/") and "base64," in candidate + + class ImageParser(BaseMessageParser): """Parser for image_url content parts.""" @@ -177,6 +189,13 @@ def parse_fine( logger.warning("[ImageParser] No image URL found in message") return [] + if not is_sendable_image_url(url): + logger.warning( + "[ImageParser] Skip image URL that cannot be sent to the vision model: %s", + url[:200], + ) + return [] + # Create source for this image source = self.create_source(message, info) diff --git a/tests/mem_reader/test_image_parser.py b/tests/mem_reader/test_image_parser.py new file mode 100644 index 000000000..374ac17e9 --- /dev/null +++ b/tests/mem_reader/test_image_parser.py @@ -0,0 +1,76 @@ +"""Tests for vision image URL validation in ImageParser.parse_fine.""" + +import json + +from unittest.mock import MagicMock + +import pytest + +from memos.mem_reader.read_multi_modal.image_parser import ImageParser + + +def _parser() -> tuple[ImageParser, MagicMock]: + llm = MagicMock() + llm.generate.return_value = json.dumps( + { + "memory list": [ + { + "key": "visible label", + "memory_type": "LongTermMemory", + "value": "A product label is visible.", + "tags": ["image"], + } + ], + "summary": "A labeled product.", + } + ) + embedder = MagicMock() + embedder.embed.return_value = [[0.1, 0.2]] + return ImageParser(embedder, llm), llm + + +def _image_message(url: str) -> dict: + return {"type": "image_url", "image_url": {"url": url, "detail": "auto"}} + + +INFO = {"user_id": "user-1", "session_id": "session-1"} + + +@pytest.mark.parametrize( + "url", + [ + "images/c502e59b213998cd695d7f57a6e33de73f5493f2d3fbab6c4e9635341aa7e7b7.jpg", + "image/photo.png", + "/tmp/photo.jpg", + "file:///tmp/photo.jpg", + "data:images/jpeg;base64,aaaa", + "data:image/jpeg,not-base64", + ], +) +def test_parse_fine_skips_non_sendable_image_url(url: str) -> None: + parser, llm = _parser() + + result = parser.parse_fine(_image_message(url), INFO) + + assert result == [] + llm.generate.assert_not_called() + + +@pytest.mark.parametrize( + "url", + [ + "https://example.com/device.jpg", + "http://example.com/images/device.jpg", + "data:image/jpeg;base64,aaaa", + "DATA:IMAGE/PNG;base64,bbbb", + ], +) +def test_parse_fine_sends_http_and_base64_image_urls(url: str) -> None: + parser, llm = _parser() + + result = parser.parse_fine(_image_message(url), INFO) + + assert len(result) == 1 + llm.generate.assert_called_once() + sent_url = llm.generate.call_args.args[0][0]["content"][1]["image_url"]["url"] + assert sent_url == url From 1729844a4eae03c562ac37804bb6ffd8095ca147 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=91=E5=B8=83=E6=9E=97?= <11641432+heiheiyouyou@user.noreply.gitee.com> Date: Sat, 10 Oct 2026 15:38:04 +0800 Subject: [PATCH 15/38] Decouple knowledge memories from graph-edge relationships Persist summary-material and raw-file neighbor relationships as node metadata so knowledge storage, retrieval deduplication, deletion, merging, and feedback locking remain functional on backends without graph edges. Raw file creation now follows file sources independently of prompt selection. Constraint: SUMMARY, MATERIAL, PRECEDING, and FOLLOWING edge operations are unavailable on the replacement graph backend. Rejected: Remove legacy edge helpers | retained unused compatibility code as requested. Confidence: high Scope-risk: moderate Directive: Keep knowledge_material_ids and knowledge_summary_ids bidirectional when adding, merging, or deleting knowledge nodes. Tested: 10 focused test functions executed directly; Ruff passed on all changed files. Not-tested: pytest runner crashes with exit 139 in the existing Anaconda environment; uv environment setup timed out fetching lxml. --- src/memos/mem_feedback/feedback.py | 23 +-- src/memos/mem_reader/multi_modal_struct.py | 70 ++++--- .../handlers/mem_read_handler.py | 2 +- src/memos/memories/textual/item.py | 8 + src/memos/memories/textual/tree.py | 171 +++++++++++++++- .../tree_text_memory/retrieve/searcher.py | 31 +-- src/memos/multi_mem_cube/single_cube.py | 27 ++- .../test_single_cube_knowledge_neighbors.py | 50 +++++ tests/mem_feedback/test_feedback.py | 20 ++ tests/mem_reader/test_multi_modal_rawfile.py | 89 +++++++++ .../textual/test_tree_knowledge_relations.py | 182 ++++++++++++++++++ tests/memories/textual/test_tree_searcher.py | 25 +++ 12 files changed, 622 insertions(+), 76 deletions(-) create mode 100644 tests/mem_cube/test_single_cube_knowledge_neighbors.py create mode 100644 tests/mem_reader/test_multi_modal_rawfile.py create mode 100644 tests/memories/textual/test_tree_knowledge_relations.py diff --git a/src/memos/mem_feedback/feedback.py b/src/memos/mem_feedback/feedback.py index 28f495afb..18ebb0b49 100644 --- a/src/memos/mem_feedback/feedback.py +++ b/src/memos/mem_feedback/feedback.py @@ -657,11 +657,6 @@ def _info_comparison(self, memory: TextualMemoryItem, _info: dict, include_keys: def _retrieve(self, query: str, info=None, top_k=20, user_name=None): """Retrieve memory items""" - def check_has_edges(mem_item: TextualMemoryItem) -> tuple[TextualMemoryItem, bool]: - """Check if a memory item has edges.""" - edges = self.searcher.graph_store.get_edges(mem_item.id, user_name=user_name) - return (mem_item, len(edges) == 0) - logger.info(f"[feedback _retrieve] query: {query}, user_name: {user_name}") text_mems = self.searcher.search( query=query, @@ -686,22 +681,16 @@ def check_has_edges(mem_item: TextualMemoryItem) -> tuple[TextualMemoryItem, boo pref_mems = [item[0] for item in pref_mems if float(item[1]) > 0.01] text_mems.extend(pref_mems) - # Memory with edges is not modified by feedback - retrieved_mems = [] - with ContextThreadPoolExecutor(max_workers=10) as executor: - futures = {executor.submit(check_has_edges, item): item for item in text_mems} - for future in concurrent.futures.as_completed(futures): - try: - mem_item, has_no_edges = future.result() - if has_no_edges: - retrieved_mems.append(mem_item) - except Exception as e: - logger.error(f"[0107 Feedback Core: _retrieve] Error checking edges: {e}") + retrieved_mems = [ + item + for item in text_mems + if not (getattr(item.metadata, "knowledge_material_ids", None) or []) + ] if len(retrieved_mems) < len(text_mems): logger.info( f"[0107 Feedback Core: _retrieve] {len(text_mems) - len(retrieved_mems)} " - f"text memories are not modified by feedback due to edges." + f"knowledge memories are not modified by feedback." ) return retrieved_mems diff --git a/src/memos/mem_reader/multi_modal_struct.py b/src/memos/mem_reader/multi_modal_struct.py index c46331f1d..eb226c27d 100644 --- a/src/memos/mem_reader/multi_modal_struct.py +++ b/src/memos/mem_reader/multi_modal_struct.py @@ -769,30 +769,52 @@ def _process_one_item( except Exception as e: logger.error(f"[MultiModalFine] parse error: {e}") - # save rawfile node - if self.save_rawfile and prompt_type == "doc" and len(fine_items) > 0: - rawfile_chunk = mem_str - file_info = fine_items[0].metadata.sources[0].file_info - source = self.multi_modal_parser.file_content_parser.create_source( - message={"file": file_info}, - info=info_per_item, - chunk_index=chunk_idx, - chunk_total=total_chunks, - chunk_content="", - ) - rawfile_node = self._make_memory_item( - value=rawfile_chunk, - info=info_per_item, - memory_type="RawFileMemory", - tags=[ - "mode:fine", - "multimodal:file", - f"chunk:{chunk_idx + 1}/{total_chunks}", - ], - sources=[source], - ) - rawfile_node.metadata.summary_ids = [mem_node.id for mem_node in fine_items] - fine_items.append(rawfile_node) + # Save the original file chunk independently from prompt selection. + file_source = next( + ( + source + for source in sources + if ( + source.get("type") + if isinstance(source, dict) + else getattr(source, "type", None) + ) + == "file" + ), + None, + ) + if self.save_rawfile and file_source is not None and fine_items: + if isinstance(file_source, dict): + file_info = file_source.get("file_info") or {} + file_content = file_source.get("content") + else: + file_info = file_source.file_info or {} + file_content = file_source.content + + rawfile_chunk = file_content or file_info.get("file_data", "") + if rawfile_chunk: + source = self.multi_modal_parser.file_content_parser.create_source( + message={"file": file_info}, + info=info_per_item, + chunk_index=chunk_idx, + chunk_total=total_chunks, + chunk_content=rawfile_chunk, + ) + rawfile_node = self._make_memory_item( + value=rawfile_chunk, + info=info_per_item, + memory_type="RawFileMemory", + tags=[ + "mode:fine", + "multimodal:file", + f"chunk:{chunk_idx + 1}/{total_chunks}", + ], + sources=[source], + ) + rawfile_node.metadata.summary_ids = [mem_node.id for mem_node in fine_items] + fine_items.append(rawfile_node) + else: + logger.warning("[RawFile] File source has no content; skipping raw-file node") enriched_items = trigger_hook( H.MEMORY_ITEMS_AFTER_FINE_EXTRACT, items=fine_items, diff --git a/src/memos/mem_scheduler/task_schedule_modules/handlers/mem_read_handler.py b/src/memos/mem_scheduler/task_schedule_modules/handlers/mem_read_handler.py index a954794b7..50031b7aa 100644 --- a/src/memos/mem_scheduler/task_schedule_modules/handlers/mem_read_handler.py +++ b/src/memos/mem_scheduler/task_schedule_modules/handlers/mem_read_handler.py @@ -209,7 +209,7 @@ def _process_memories_with_reader( for memory in flattened_memories if memory.metadata.memory_type == "RawFileMemory" ] - text_mem.add_rawfile_nodes_n_edges( + text_mem.add_rawfile_nodes( raw_file_mem_group, enhanced_mem_ids, user_id=user_id, diff --git a/src/memos/memories/textual/item.py b/src/memos/memories/textual/item.py index 23474cc20..1ba148d8a 100644 --- a/src/memos/memories/textual/item.py +++ b/src/memos/memories/textual/item.py @@ -212,6 +212,14 @@ class TreeNodeTextualMemoryMetadata(TextualMemoryMetadata): default_factory=list, description="The ids of the files associated with the memory.", ) + knowledge_material_ids: list[str] = Field( + default_factory=list, + description="RawFileMemory ids that support this knowledge summary.", + ) + knowledge_summary_ids: list[str] = Field( + default_factory=list, + description="Knowledge summary ids extracted from this raw file memory.", + ) @field_validator("sources", mode="before") @classmethod diff --git a/src/memos/memories/textual/tree.py b/src/memos/memories/textual/tree.py index 426a2359b..c9d74d43f 100644 --- a/src/memos/memories/textual/tree.py +++ b/src/memos/memories/textual/tree.py @@ -399,10 +399,13 @@ def get_all( ) return graph_output - def delete(self, memory_ids: list[str], user_name: str | None = None) -> None: + def delete(self, memory_ids: str | list[str], user_name: str | None = None) -> None: """Hard delete: permanently remove nodes and their edges from the graph.""" if not memory_ids: return + if isinstance(memory_ids, str): + memory_ids = [memory_ids] + self._unlink_knowledge_relations(memory_ids, user_name=user_name) for mid in memory_ids: try: self.graph_store.delete_node(mid, user_name=user_name) @@ -412,6 +415,7 @@ def delete(self, memory_ids: list[str], user_name: str | None = None) -> None: def delete_by_memory_ids(self, memory_ids: list[str]) -> None: """Delete memories by memory_ids.""" try: + self._unlink_knowledge_relations(memory_ids) self.graph_store.delete_node_by_prams(memory_ids=memory_ids) except Exception as e: logger.error(f"An error occurred while deleting memories by memory_ids: {e}") @@ -432,10 +436,71 @@ def delete_by_filter( filter: dict | None = None, ) -> None: """Delete memories by filter.""" + if file_ids: + user_names = writable_cube_ids or [None] + for user_name in user_names: + memory_ids: set[str] = set() + for file_id in file_ids: + memory_ids.update( + self.graph_store.get_by_metadata( + [{"field": "file_ids", "op": "contains", "value": file_id}], + user_name=user_name, + ) + ) + self._unlink_knowledge_relations(list(memory_ids), user_name=user_name) self.graph_store.delete_node_by_prams( writable_cube_ids=writable_cube_ids, file_ids=file_ids, filter=filter ) + @staticmethod + def _node_metadata(node: dict[str, Any] | TextualMemoryItem) -> dict[str, Any]: + if isinstance(node, TextualMemoryItem): + return node.metadata.model_dump() + return node.get("metadata") or {} + + def _get_node_map( + self, memory_ids: list[str] | set[str], user_name: str | None = None + ) -> dict[str, dict[str, Any] | TextualMemoryItem]: + if not memory_ids: + return {} + nodes = self.graph_store.get_nodes(ids=list(memory_ids), user_name=user_name) or [] + return { + node.id if isinstance(node, TextualMemoryItem) else node["id"]: node for node in nodes + } + + def _unlink_knowledge_relations( + self, memory_ids: list[str], user_name: str | None = None + ) -> None: + """Remove reverse knowledge ids before deleting or deactivating nodes.""" + deleting_ids = set(memory_ids) + deleting_nodes = self._get_node_map(deleting_ids, user_name=user_name) + removals: dict[str, dict[str, set[str]]] = {} + + for memory_id, node in deleting_nodes.items(): + metadata = self._node_metadata(node) + for material_id in metadata.get("knowledge_material_ids") or []: + if material_id not in deleting_ids: + removals.setdefault(material_id, {}).setdefault( + "knowledge_summary_ids", set() + ).add(memory_id) + for summary_id in metadata.get("knowledge_summary_ids") or []: + if summary_id not in deleting_ids: + removals.setdefault(summary_id, {}).setdefault( + "knowledge_material_ids", set() + ).add(memory_id) + + related_nodes = self._get_node_map(set(removals), user_name=user_name) + for related_id, fields in removals.items(): + node = related_nodes.get(related_id) + if node is None: + continue + metadata = self._node_metadata(node) + updates = { + field: [value for value in metadata.get(field) or [] if value not in removed_ids] + for field, removed_ids in fields.items() + } + self.graph_store.update_node(related_id, updates, user_name=user_name) + def load(self, dir: str, user_name: str | None = None) -> None: try: memory_file = os.path.join(dir, self.config.memory_filename) @@ -593,6 +658,109 @@ def add_rawfile_nodes_n_edges( f"[RawFile] Time taken to add edges: {end_time - start_time} seconds for {len(from_ids)} edges" ) + def add_rawfile_nodes( + self, + raw_file_mem_group: list[TextualMemoryItem], + mem_ids: list[str], + user_id: str | None = None, + user_name: str | None = None, + ) -> None: + """Persist raw-file nodes and their knowledge relationships without graph edges.""" + valid_summary_ids = set(mem_ids) + summary_to_material_ids: dict[str, list[str]] = {} + + for raw_file_mem in raw_file_mem_group: + summary_ids = list( + dict.fromkeys( + summary_id + for summary_id in getattr(raw_file_mem.metadata, "summary_ids", []) or [] + if summary_id in valid_summary_ids + ) + ) + raw_file_mem.metadata.knowledge_summary_ids = summary_ids + for summary_id in summary_ids: + summary_to_material_ids.setdefault(summary_id, []).append(raw_file_mem.id) + + self.add(raw_file_mem_group, user_name=user_name) + summary_nodes = self._get_node_map(set(summary_to_material_ids), user_name=user_name) + + merged_from_by_summary: dict[str, list[str]] = {} + old_summary_ids: set[str] = set() + for summary_id, node in summary_nodes.items(): + info = self._node_metadata(node).get("info") or {} + merged_from = info.get("merged_from") or [] + if isinstance(merged_from, str): + merged_from = [merged_from] + merged_from_by_summary[summary_id] = list(dict.fromkeys(merged_from)) + old_summary_ids.update(merged_from) + + old_summary_nodes = self._get_node_map(old_summary_ids, user_name=user_name) + material_relinks: dict[str, dict[str, Any]] = {} + + for summary_id, direct_material_ids in summary_to_material_ids.items(): + summary_node = summary_nodes.get(summary_id) + if summary_node is None: + logger.warning( + "Knowledge summary %s was not found after raw-file write", summary_id + ) + continue + + metadata = self._node_metadata(summary_node) + merged_from = merged_from_by_summary.get(summary_id, []) + inherited_material_ids: list[str] = [] + for old_summary_id in merged_from: + old_summary = old_summary_nodes.get(old_summary_id) + if old_summary is not None: + inherited_material_ids.extend( + self._node_metadata(old_summary).get("knowledge_material_ids") or [] + ) + + material_ids = list( + dict.fromkeys( + [ + *(metadata.get("knowledge_material_ids") or []), + *direct_material_ids, + *inherited_material_ids, + ] + ) + ) + self.graph_store.update_node( + summary_id, + {"knowledge_material_ids": material_ids}, + user_name=user_name, + ) + + for material_id in inherited_material_ids: + relink = material_relinks.setdefault(material_id, {"remove": set(), "add": []}) + relink["remove"].update(merged_from) + relink["add"].append(summary_id) + + material_nodes = self._get_node_map(set(material_relinks), user_name=user_name) + for material_id, relink in material_relinks.items(): + material_node = material_nodes.get(material_id) + if material_node is None: + continue + current_summary_ids = ( + self._node_metadata(material_node).get("knowledge_summary_ids") or [] + ) + updated_summary_ids = [ + summary_id + for summary_id in current_summary_ids + if summary_id not in relink["remove"] + ] + updated_summary_ids.extend(relink["add"]) + self.graph_store.update_node( + material_id, + {"knowledge_summary_ids": list(dict.fromkeys(updated_summary_ids))}, + user_name=user_name, + ) + + logger.info( + "[RawFile] Added %s chunks with ID mappings for user %s", + len(raw_file_mem_group), + user_id, + ) + def add_graph_edges( self, from_ids: list[str], to_ids: list[str], types: list[str], user_name: str | None = None ) -> None: @@ -624,6 +792,7 @@ def soft_delete( user_name: str, evolve_to_ids: list[str] | None = None, ) -> None: + self._unlink_knowledge_relations(memory_ids, user_name=user_name) # for ruff check... if not evolve_to_ids: update_fields = {"status": "deleted"} diff --git a/src/memos/memories/textual/tree_text_memory/retrieve/searcher.py b/src/memos/memories/textual/tree_text_memory/retrieve/searcher.py index 5c9cce78e..b44d28218 100644 --- a/src/memos/memories/textual/tree_text_memory/retrieve/searcher.py +++ b/src/memos/memories/textual/tree_text_memory/retrieve/searcher.py @@ -3,8 +3,6 @@ import re import traceback -from concurrent.futures import as_completed - from memos.context.context import ContextThreadPoolExecutor from memos.embedders.factory import OllamaEmbedder from memos.graph_dbs.factory import Neo4jGraphDB @@ -1282,7 +1280,7 @@ def _sort_and_trim( @timed def _deduplicate_rawfile_results(self, results, user_name: str | None = None): """ - Deduplicate rawfile related memories by edge + Deduplicate raw-file results using their persisted summary ids. """ if not results: return results @@ -1292,29 +1290,10 @@ def _deduplicate_rawfile_results(self, results, user_name: str | None = None): if not rawfile_items: return results - with ContextThreadPoolExecutor(max_workers=min(len(rawfile_items), 10)) as executor: - futures = [ - executor.submit( - self.graph_store.get_edges, - rawfile_item.id, - type="SUMMARY", - direction="OUTGOING", - user_name=user_name, - ) - for rawfile_item in rawfile_items - ] - for future in as_completed(futures): - try: - edges = future.result() - for edge in edges: - summary_target_id = edge.get("to") - if summary_target_id: - summary_ids_to_remove.add(summary_target_id) - logger.debug( - f"[DEDUP] Marking summary node {summary_target_id} for removal (pointed by RawFileMemory)" - ) - except Exception as e: - logger.warning(f"[DEDUP] Failed to get summary target ids: {e}") + for rawfile_item in rawfile_items: + summary_ids_to_remove.update( + getattr(rawfile_item.metadata, "knowledge_summary_ids", None) or [] + ) filtered_results = [] for item in results: diff --git a/src/memos/multi_mem_cube/single_cube.py b/src/memos/multi_mem_cube/single_cube.py index 27399259a..0b9829b7f 100644 --- a/src/memos/multi_mem_cube/single_cube.py +++ b/src/memos/multi_mem_cube/single_cube.py @@ -441,22 +441,35 @@ def extract_edge_info(edges_info: list[dict], neighbor_relativity: float): ) return edge_mems + def get_neighbor(chunk_target_id: str | None, neighbor_relativity: float): + if not chunk_target_id: + return None + item_neighbor = self.searcher.graph_store.get_node(chunk_target_id, user_name=user_name) + if not item_neighbor: + return None + item_neighbor_mem = TextualMemoryItem(**item_neighbor) + item_neighbor_mem.metadata.relativity = neighbor_relativity + self.logger.info("Add neighbor chunk by id: %s", chunk_target_id) + return item_neighbor_mem + final_items = [] if neighbor_discovery: for item in search_results: if item.metadata.memory_type == "RawFileMemory": neighbor_relativity = item.metadata.relativity * 0.8 - preceding_info = self.searcher.graph_store.get_edges( - item.id, type="PRECEDING", direction="OUTGOING", user_name=user_name + preceding = get_neighbor( + getattr(item.metadata, "preceding_id", None), neighbor_relativity ) - final_items.extend(extract_edge_info(preceding_info, neighbor_relativity)) + if preceding is not None: + final_items.append(preceding) final_items.append(item) - following_info = self.searcher.graph_store.get_edges( - item.id, type="FOLLOWING", direction="OUTGOING", user_name=user_name + following = get_neighbor( + getattr(item.metadata, "following_id", None), neighbor_relativity ) - final_items.extend(extract_edge_info(following_info, neighbor_relativity)) + if following is not None: + final_items.append(following) else: final_items.append(item) @@ -748,7 +761,7 @@ def _process_text_mem( for memory in flattened_local if memory.metadata.memory_type == "RawFileMemory" ] - self.naive_mem_cube.text_mem.add_rawfile_nodes_n_edges( + self.naive_mem_cube.text_mem.add_rawfile_nodes( raw_file_mem_group, mem_ids_local, user_id=add_req.user_id, diff --git a/tests/mem_cube/test_single_cube_knowledge_neighbors.py b/tests/mem_cube/test_single_cube_knowledge_neighbors.py new file mode 100644 index 000000000..5cb433d77 --- /dev/null +++ b/tests/mem_cube/test_single_cube_knowledge_neighbors.py @@ -0,0 +1,50 @@ +import uuid + +from unittest.mock import Mock + +from memos.memories.textual.item import TextualMemoryItem, TreeNodeTextualMemoryMetadata + + +def make_raw(item_id: str, relativity: float, **extra) -> TextualMemoryItem: + return TextualMemoryItem( + id=item_id, + memory=item_id, + metadata=TreeNodeTextualMemoryMetadata( + memory_type="RawFileMemory", + relativity=relativity, + **extra, + ), + ) + + +def test_postformat_discovers_rawfile_neighbors_by_id_without_edges(): + import memos.api.handlers # noqa: F401 - initialize package before known circular import + + from memos.multi_mem_cube.single_cube import SingleCubeView + + previous = make_raw(str(uuid.uuid4()), 0.1) + following = make_raw(str(uuid.uuid4()), 0.1) + current = make_raw(str(uuid.uuid4()), 1.0, preceding_id=previous.id, following_id=following.id) + searcher = Mock() + neighbors = { + previous.id: previous.model_dump(), + following.id: following.model_dump(), + } + searcher.graph_store.get_node.side_effect = lambda node_id, **_: neighbors.get(node_id) + view = SingleCubeView( + cube_id="cube-1", + naive_mem_cube=Mock(), + mem_reader=Mock(), + mem_scheduler=Mock(), + logger=Mock(), + searcher=searcher, + ) + + result = view._postformat_memories( + [current], "cube-1", include_embedding=False, neighbor_discovery=True + ) + + assert [item["id"] for item in result] == [previous.id, current.id, following.id] + assert result[0]["metadata"]["relativity"] == 0.8 + assert result[2]["metadata"]["relativity"] == 0.8 + searcher.graph_store.get_edges.assert_not_called() diff --git a/tests/mem_feedback/test_feedback.py b/tests/mem_feedback/test_feedback.py index bbf30ae94..3f86ac482 100644 --- a/tests/mem_feedback/test_feedback.py +++ b/tests/mem_feedback/test_feedback.py @@ -1,3 +1,5 @@ +import uuid + from unittest.mock import Mock from memos.mem_feedback.feedback import MemFeedback @@ -139,3 +141,21 @@ def test_update_judgement_prompt_omits_memory_text_from_response_schema(): assert '"reason"' in output_section assert '"text"' not in output_section assert '"old_memory"' not in output_section + + +def test_retrieve_locks_only_knowledge_summaries_without_edge_queries(): + feedback = MemFeedback.__new__(MemFeedback) + feedback.pref_feedback = False + feedback.searcher = Mock() + normal = TextualMemoryItem(id=str(uuid.uuid4()), memory="normal") + knowledge = TextualMemoryItem( + id=str(uuid.uuid4()), + memory="knowledge", + metadata={"knowledge_material_ids": [str(uuid.uuid4())]}, + ) + feedback.searcher.search.return_value = [(normal, 0.9), (knowledge, 0.8)] + + result = feedback._retrieve("query", user_name="cube-1") + + assert result == [normal] + feedback.searcher.graph_store.get_edges.assert_not_called() diff --git a/tests/mem_reader/test_multi_modal_rawfile.py b/tests/mem_reader/test_multi_modal_rawfile.py new file mode 100644 index 000000000..f583b7173 --- /dev/null +++ b/tests/mem_reader/test_multi_modal_rawfile.py @@ -0,0 +1,89 @@ +from unittest.mock import MagicMock, patch + +from memos.mem_reader.multi_modal_struct import MultiModalStructMemReader +from memos.memories.textual.item import ( + SourceMessage, + TextualMemoryItem, + TreeNodeTextualMemoryMetadata, +) + + +def test_mixed_file_source_creates_rawfile_without_changing_prompt_type(): + reader = MultiModalStructMemReader.__new__(MultiModalStructMemReader) + reader.save_rawfile = True + reader.memory_version_switch = "off" + reader.embedder = MagicMock() + reader.embedder.embed.return_value = [[0.1]] + reader.multi_modal_parser = MagicMock() + + file_info = { + "file_id": "file-1", + "filename": "knowledge.txt", + "file_data": "Complete file content", + } + file_source = SourceMessage( + type="file", + role=None, + content="Current file chunk", + file_info=file_info, + ) + fast_item = TextualMemoryItem( + memory="Please parse this file\nCurrent file chunk\nRecord it completely", + metadata=TreeNodeTextualMemoryMetadata( + user_id="user-1", + session_id="session-1", + memory_type="LongTermMemory", + sources=[ + SourceMessage(type="chat", role="user", content="Please parse this file"), + file_source, + SourceMessage(type="chat", role="user", content="Record it completely"), + ], + file_ids=[file_info["file_id"]], + ), + ) + reader.multi_modal_parser.file_content_parser.create_source.return_value = SourceMessage( + type="file", + content=file_source.content, + doc_path=file_info["filename"], + ) + + llm_response = { + "memory list": [ + { + "key": "Knowledge summary", + "memory_type": "LongTermMemory", + "value": "Summarized knowledge", + "tags": ["knowledge"], + } + ], + "summary": "Summary background", + } + + with ( + patch.object(reader, "_get_llm_response", return_value=llm_response) as get_llm_response, + patch.object( + reader, + "_get_maybe_merged_memory", + side_effect=lambda extracted_memory_dict, **kwargs: extracted_memory_dict, + ), + patch( + "memos.mem_reader.multi_modal_struct.trigger_hook", + side_effect=lambda _hook, **kwargs: kwargs["items"], + ), + ): + result = reader._process_string_fine( + [fast_item], + {"user_id": "user-1", "session_id": "session-1"}, + ) + + summaries = [item for item in result if item.metadata.memory_type != "RawFileMemory"] + rawfiles = [item for item in result if item.metadata.memory_type == "RawFileMemory"] + + assert get_llm_response.call_args.args[3] == "chat" + assert len(summaries) == 1 + assert len(rawfiles) == 1 + assert rawfiles[0].memory == file_source.content + assert rawfiles[0].metadata.summary_ids == [summaries[0].id] + assert reader.multi_modal_parser.file_content_parser.create_source.call_args.kwargs[ + "message" + ] == {"file": file_info} diff --git a/tests/memories/textual/test_tree_knowledge_relations.py b/tests/memories/textual/test_tree_knowledge_relations.py new file mode 100644 index 000000000..79bd80743 --- /dev/null +++ b/tests/memories/textual/test_tree_knowledge_relations.py @@ -0,0 +1,182 @@ +import uuid + +from unittest.mock import Mock + +from memos.memories.textual.item import TextualMemoryItem, TreeNodeTextualMemoryMetadata +from memos.memories.textual.tree import TreeTextMemory + + +class FakeGraphStore: + def __init__(self, items: list[TextualMemoryItem]) -> None: + self.nodes = {item.id: item.model_dump() for item in items} + self.edge_calls: list[tuple] = [] + self.deleted_by_params: list[dict] = [] + + def get_nodes(self, ids, user_name=None): + return [self.nodes[node_id] for node_id in ids if node_id in self.nodes] + + def update_node(self, id, fields, user_name=None): + self.nodes[id]["metadata"].update(fields) + + def delete_node(self, id, user_name=None): + self.nodes.pop(id, None) + + def delete_node_by_prams(self, **kwargs): + self.deleted_by_params.append(kwargs) + for node_id in kwargs.get("memory_ids") or []: + self.nodes.pop(node_id, None) + + def get_by_metadata(self, filters, user_name=None, status=None): + matched = [] + for node_id, node in self.nodes.items(): + metadata = node["metadata"] + if all( + ( + item["value"] in (metadata.get(item["field"]) or []) + if item.get("op") == "contains" + else metadata.get(item["field"]) == item["value"] + ) + for item in filters + ): + matched.append(node_id) + return matched + + def add_edge(self, *args, **kwargs): + self.edge_calls.append((args, kwargs)) + + def get_edges(self, *args, **kwargs): + self.edge_calls.append((args, kwargs)) + return [] + + +def _test_id(value: str) -> str: + try: + return str(uuid.UUID(value)) + except ValueError: + return str(uuid.uuid5(uuid.NAMESPACE_DNS, value)) + + +def make_item( + item_id: str, + memory_type: str, + *, + knowledge_material_ids: list[str] | None = None, + knowledge_summary_ids: list[str] | None = None, + info: dict | None = None, + file_ids: list[str] | None = None, + summary_ids: list[str] | None = None, +) -> TextualMemoryItem: + metadata = TreeNodeTextualMemoryMetadata( + memory_type=memory_type, + knowledge_material_ids=[_test_id(value) for value in knowledge_material_ids or []], + knowledge_summary_ids=[_test_id(value) for value in knowledge_summary_ids or []], + info=( + { + **info, + "merged_from": [_test_id(value) for value in info.get("merged_from", [])], + } + if info and "merged_from" in info + else info + ), + file_ids=file_ids or [], + ) + if summary_ids is not None: + metadata.summary_ids = [_test_id(value) for value in summary_ids] + return TextualMemoryItem(id=_test_id(item_id), memory=item_id, metadata=metadata) + + +def make_tree(items: list[TextualMemoryItem]) -> tuple[TreeTextMemory, FakeGraphStore]: + tree = TreeTextMemory.__new__(TreeTextMemory) + graph_store = FakeGraphStore(items) + tree.graph_store = graph_store + + def add(memories, user_name=None, **kwargs): + for memory in memories: + graph_store.nodes[memory.id] = memory.model_dump() + return [memory.id for memory in memories] + + tree.add = Mock(side_effect=add) + return tree, graph_store + + +def test_add_rawfile_nodes_persists_bidirectional_ids_without_edges(): + summary = make_item("summary-1", "LongTermMemory") + material = make_item("material-1", "RawFileMemory", summary_ids=[summary.id]) + tree, graph_store = make_tree([summary]) + + tree.add_rawfile_nodes([material], [summary.id], user_name="cube-1") + + assert graph_store.nodes[material.id]["metadata"]["knowledge_summary_ids"] == [summary.id] + assert graph_store.nodes[summary.id]["metadata"]["knowledge_material_ids"] == [material.id] + assert graph_store.edge_calls == [] + + +def test_add_rawfile_nodes_reconnects_materials_when_summary_is_merged(): + old_material = make_item("material-old", "RawFileMemory", knowledge_summary_ids=["summary-old"]) + old_summary = make_item( + "summary-old", "LongTermMemory", knowledge_material_ids=[old_material.id] + ) + new_summary = make_item("summary-new", "LongTermMemory", info={"merged_from": [old_summary.id]}) + new_material = make_item("material-new", "RawFileMemory", summary_ids=[new_summary.id]) + tree, graph_store = make_tree([old_material, old_summary, new_summary]) + + tree.add_rawfile_nodes([new_material], [new_summary.id], user_name="cube-1") + + assert graph_store.nodes[new_summary.id]["metadata"]["knowledge_material_ids"] == [ + new_material.id, + old_material.id, + ] + assert graph_store.nodes[old_material.id]["metadata"]["knowledge_summary_ids"] == [ + new_summary.id + ] + + +def test_delete_summary_unlinks_material_without_deleting_it(): + material = make_item("material-1", "RawFileMemory", knowledge_summary_ids=["summary-1"]) + summary = make_item("summary-1", "LongTermMemory", knowledge_material_ids=[material.id]) + tree, graph_store = make_tree([material, summary]) + + tree.delete_by_memory_ids([summary.id]) + + assert summary.id not in graph_store.nodes + assert graph_store.nodes[material.id]["metadata"]["knowledge_summary_ids"] == [] + + +def test_delete_material_unlinks_summary_without_deleting_it(): + material = make_item("material-1", "RawFileMemory", knowledge_summary_ids=["summary-1"]) + summary = make_item("summary-1", "LongTermMemory", knowledge_material_ids=[material.id]) + tree, graph_store = make_tree([material, summary]) + + tree.delete_by_memory_ids([material.id]) + + assert material.id not in graph_store.nodes + assert graph_store.nodes[summary.id]["metadata"]["knowledge_material_ids"] == [] + + +def test_file_delete_unlinks_knowledge_relations_before_bulk_delete(): + material = make_item( + "material-1", + "RawFileMemory", + knowledge_summary_ids=["summary-1"], + file_ids=["file-1"], + ) + summary = make_item("summary-1", "LongTermMemory", knowledge_material_ids=[material.id]) + tree, graph_store = make_tree([material, summary]) + + tree.delete_by_filter(writable_cube_ids=["cube-1"], file_ids=["file-1"]) + + assert graph_store.nodes[summary.id]["metadata"]["knowledge_material_ids"] == [] + assert graph_store.deleted_by_params == [ + {"writable_cube_ids": ["cube-1"], "file_ids": ["file-1"], "filter": None} + ] + + +def test_soft_delete_unlinks_summary_before_marking_it_deleted(): + material = make_item("material-1", "RawFileMemory", knowledge_summary_ids=["summary-1"]) + summary = make_item("summary-1", "LongTermMemory", knowledge_material_ids=[material.id]) + tree, graph_store = make_tree([material, summary]) + + tree.soft_delete([summary.id], user_name="cube-1") + + assert graph_store.nodes[material.id]["metadata"]["knowledge_summary_ids"] == [] + assert graph_store.nodes[summary.id]["metadata"]["status"] == "deleted" diff --git a/tests/memories/textual/test_tree_searcher.py b/tests/memories/textual/test_tree_searcher.py index b79958ca1..fe40cbb7d 100644 --- a/tests/memories/textual/test_tree_searcher.py +++ b/tests/memories/textual/test_tree_searcher.py @@ -1,3 +1,5 @@ +import uuid + from unittest.mock import MagicMock import pytest @@ -143,3 +145,26 @@ def test_searcher_respects_memory_type(mock_searcher): ) # WorkingMemory triggers only once path A assert mock_searcher.graph_retriever.retrieve.call_args[1]["memory_scope"] == "WorkingMemory" + + +def test_deduplicate_rawfile_results_uses_knowledge_summary_ids(mock_searcher): + summary_id = str(uuid.uuid4()) + material_id = str(uuid.uuid4()) + summary = TextualMemoryItem( + id=summary_id, + memory="summary", + metadata=TreeNodeTextualMemoryMetadata(memory_type="LongTermMemory"), + ) + raw_file = TextualMemoryItem( + id=material_id, + memory="material", + metadata=TreeNodeTextualMemoryMetadata( + memory_type="RawFileMemory", + knowledge_summary_ids=[summary.id], + ), + ) + + result = mock_searcher._deduplicate_rawfile_results([summary, raw_file], user_name="cube-1") + + assert result == [raw_file] + mock_searcher.graph_store.get_edges.assert_not_called() From 721416d2c49eb09dd1c55dcacb70a6217ec79c8a Mon Sep 17 00:00:00 2001 From: keeponlight Date: Sat, 17 Oct 2026 19:58:04 +0800 Subject: [PATCH 16/38] fix(scheduler): align enhanced_mem_ids with filtered mem_group in mem_read_handler --- .../handlers/mem_read_handler.py | 4 +- .../test_mem_read_handler_fast_cleanup.py | 147 +++++++++++++++++- 2 files changed, 143 insertions(+), 8 deletions(-) diff --git a/src/memos/mem_scheduler/task_schedule_modules/handlers/mem_read_handler.py b/src/memos/mem_scheduler/task_schedule_modules/handlers/mem_read_handler.py index 50031b7aa..5e663c99e 100644 --- a/src/memos/mem_scheduler/task_schedule_modules/handlers/mem_read_handler.py +++ b/src/memos/mem_scheduler/task_schedule_modules/handlers/mem_read_handler.py @@ -328,9 +328,7 @@ def _process_memories_with_reader( add_meta_legacy: list[dict] = [] update_content_legacy: list[dict] = [] update_meta_legacy: list[dict] = [] - for item_id, item in zip( - enhanced_mem_ids, flattened_memories, strict=False - ): + for item_id, item in zip(enhanced_mem_ids, mem_group, strict=False): key = getattr(item.metadata, "key", None) or transform_name_to_key( name=item.memory ) diff --git a/tests/mem_scheduler/test_mem_read_handler_fast_cleanup.py b/tests/mem_scheduler/test_mem_read_handler_fast_cleanup.py index c54b49de6..8cdb873ce 100644 --- a/tests/mem_scheduler/test_mem_read_handler_fast_cleanup.py +++ b/tests/mem_scheduler/test_mem_read_handler_fast_cleanup.py @@ -4,11 +4,18 @@ from unittest.mock import MagicMock -def _make_text_item(item_id: str, memory: str): +def _make_text_item( + item_id: str, + memory: str, + *, + memory_type: str = "LongTermMemory", + key: str | None = None, + info: dict | None = None, +): metadata = SimpleNamespace( - memory_type="LongTermMemory", - info={}, - key=None, + memory_type=memory_type, + info=info if info is not None else {}, + key=key, status="activated", confidence=0.9, tags=[], @@ -17,8 +24,10 @@ def _make_text_item(item_id: str, memory: str): class _FakeTextMem: - def __init__(self, items): + def __init__(self, items, added_ids: list[str] | None = None): self._items = {item.id: item for item in items} + self._added_ids = added_ids + self.add_calls: list = [] self.delete_calls: list = [] self.soft_delete_calls: list = [] self.memory_manager = SimpleNamespace( @@ -29,6 +38,13 @@ def __init__(self, items): def get(self, mem_id, user_name=None): return self._items[mem_id] + def add(self, memories, user_name=None): + mem_list = list(memories) + self.add_calls.append((mem_list, user_name)) + if self._added_ids is not None: + return list(self._added_ids) + return [item.id for item in mem_list] + def delete(self, ids, user_name=None): self.delete_calls.append((list(ids), user_name)) @@ -98,3 +114,124 @@ def test_fine_transfer_error_does_not_soft_delete_fast_memory_with_versions(): assert text_mem.delete_calls == [] assert text_mem.soft_delete_calls == [] + + +def test_playground_legacy_events_align_enhanced_ids_with_filtered_mem_group(monkeypatch): + import memos.mem_scheduler.task_schedule_modules.handlers.mem_read_handler as handler_module + + from memos.mem_scheduler.task_schedule_modules.handlers.mem_read_handler import ( + MemReadMessageHandler, + ) + + monkeypatch.setattr(handler_module, "is_playground_api", lambda: True) + + raw_chunk = _make_text_item("raw_1", "raw chunk") + raw_file_mem = _make_text_item( + "raw_file_1", + "raw file content", + memory_type="RawFileMemory", + key="raw-file-key", + ) + added_mem = _make_text_item( + "mem_add_1", + "user prefers dark mode", + memory_type="LongTermMemory", + key="theme-pref", + ) + updated_mem = _make_text_item( + "mem_upd_1", + "user lives in Shanghai", + memory_type="UserMemory", + key="city-pref", + info={"merged_from": ["old_mem_1"]}, + ) + + text_mem = _FakeTextMem( + [raw_chunk], + added_ids=["enhanced_id_add_1", "enhanced_id_upd_1"], + ) + mem_cube = SimpleNamespace(text_mem=text_mem) + + mem_reader = MagicMock() + mem_reader.fine_transfer_simple_mem.return_value = [[raw_file_mem, added_mem, updated_mem]] + mem_reader.memory_version_switch = "off" + mem_reader.graph_db = None + mem_reader.save_rawfile = False + + submitted_events: list = [] + services = SimpleNamespace( + create_event_log=lambda **kwargs: SimpleNamespace(**kwargs), + submit_web_logs=lambda events, **kwargs: submitted_events.extend(events), + map_memcube_name=lambda mem_cube_id: "UserMemCube", + submit_messages=lambda messages: None, + ) + scheduler_context = SimpleNamespace( + get_mem_cube=lambda: mem_cube, + get_mem_reader=lambda: mem_reader, + services=services, + ) + + handler = MemReadMessageHandler.__new__(MemReadMessageHandler) + handler.scheduler_context = scheduler_context + + handler._process_memories_with_reader( + mem_ids=["raw_1"], + user_id="user_1", + mem_cube_id="cube_1", + text_mem=text_mem, + user_name="cube_1", + task_id="task_1", + info={"trigger_source": "Messages"}, + ) + + assert len(text_mem.add_calls) == 1 + assert text_mem.add_calls[0] == ([added_mem, updated_mem], "cube_1") + + assert len(submitted_events) == 2 + add_event, update_event = submitted_events + + assert add_event.label == "addMemory" + assert add_event.task_id == "task_1" + assert add_event.memory_len == 1 + assert add_event.memcube_log_content == [ + { + "content": "theme-pref: user prefers dark mode", + "ref_id": "enhanced_id_add_1", + } + ] + assert add_event.metadata == [ + { + "ref_id": "enhanced_id_add_1", + "id": "enhanced_id_add_1", + "key": "theme-pref", + "memory": "user prefers dark mode", + "memory_type": "LongTermMemory", + "status": "activated", + "confidence": 0.9, + "tags": [], + "updated_at": None, + } + ] + + assert update_event.label == "updateMemory" + assert update_event.task_id == "task_1" + assert update_event.memory_len == 1 + assert update_event.memcube_log_content == [ + { + "content": "city-pref: user lives in Shanghai", + "ref_id": "enhanced_id_upd_1", + } + ] + assert update_event.metadata == [ + { + "ref_id": "enhanced_id_upd_1", + "id": "enhanced_id_upd_1", + "key": "city-pref", + "memory": "user lives in Shanghai", + "memory_type": "UserMemory", + "status": "activated", + "confidence": 0.9, + "tags": [], + "updated_at": None, + } + ] From 9b4fea36cf26102b10f07cec40e8389180e7e2ab Mon Sep 17 00:00:00 2001 From: keeponlight Date: Sat, 17 Oct 2026 19:54:09 +0800 Subject: [PATCH 17/38] fix(llm): prevent IndexError when reasoning items are absent in responses API --- src/memos/llms/openai_new.py | 4 +- tests/llms/test_openai_responses_llm.py | 104 ++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 tests/llms/test_openai_responses_llm.py diff --git a/src/memos/llms/openai_new.py b/src/memos/llms/openai_new.py index 766a17fda..50c87b78f 100644 --- a/src/memos/llms/openai_new.py +++ b/src/memos/llms/openai_new.py @@ -50,7 +50,7 @@ def generate(self, messages: MessageList, **kwargs) -> str: output_reasoning = [ item for item in response.output if isinstance(item, ResponseReasoningItem) ] - summary = output_reasoning[0].summary + summary = output_reasoning[0].summary if output_reasoning else None if self.config.remove_think_prefix: return remove_thinking_tags(output_text) @@ -138,7 +138,7 @@ def generate(self, messages: MessageList, **kwargs) -> str: output_reasoning = [ item for item in response.output if isinstance(item, ResponseReasoningItem) ] - summary = output_reasoning[0].summary + summary = output_reasoning[0].summary if output_reasoning else None if self.config.remove_think_prefix: return remove_thinking_tags(output_text) diff --git a/tests/llms/test_openai_responses_llm.py b/tests/llms/test_openai_responses_llm.py new file mode 100644 index 000000000..d6915b122 --- /dev/null +++ b/tests/llms/test_openai_responses_llm.py @@ -0,0 +1,104 @@ +"""Tests for OpenAIResponsesLLM and AzureResponsesLLM generate reasoning handling.""" + +from types import SimpleNamespace +from unittest.mock import MagicMock + +import pytest + +from openai.types.responses.response_reasoning_item import ResponseReasoningItem, Summary + +from memos.configs.llm import AzureLLMConfig, OpenAIResponsesLLMConfig +from memos.llms.openai_new import AzureResponsesLLM, OpenAIResponsesLLM + + +MESSAGES = [{"role": "user", "content": "Hello"}] + + +def _make_openai_llm( + *, enable_thinking: bool = False, remove_think_prefix: bool = False +) -> OpenAIResponsesLLM: + llm = OpenAIResponsesLLM.__new__(OpenAIResponsesLLM) + llm.config = OpenAIResponsesLLMConfig( + api_key="test-key", + model_name_or_path="gpt-4o", + enable_thinking=enable_thinking, + remove_think_prefix=remove_think_prefix, + ) + llm.client = MagicMock() + return llm + + +def _make_azure_llm( + *, enable_thinking: bool = False, remove_think_prefix: bool = False +) -> AzureResponsesLLM: + llm = AzureResponsesLLM.__new__(AzureResponsesLLM) + llm.config = AzureLLMConfig( + api_key="test-key", + model_name_or_path="gpt-4o", + enable_thinking=enable_thinking, + remove_think_prefix=remove_think_prefix, + ) + llm.client = MagicMock() + return llm + + +@pytest.mark.parametrize( + "make_llm", + [_make_openai_llm, _make_azure_llm], + ids=["openai", "azure"], +) +class TestResponsesLLMGenerate: + def test_generate_without_reasoning_item_returns_output_text(self, make_llm): + llm = make_llm(enable_thinking=False) + llm.client.responses.create.return_value = SimpleNamespace( + output=[SimpleNamespace(type="message")], + output_text="plain answer", + ) + + result = llm.generate(MESSAGES) + + assert result == "plain answer" + + def test_generate_with_empty_reasoning_summary_returns_output_text(self, make_llm): + llm = make_llm(enable_thinking=True) + reasoning_item = ResponseReasoningItem(id="rs_1", summary=[], type="reasoning") + llm.client.responses.create.return_value = SimpleNamespace( + output=[reasoning_item], + output_text="plain answer", + ) + + result = llm.generate(MESSAGES) + + assert result == "plain answer" + + def test_generate_with_reasoning_summary_prepends_think_tag(self, make_llm): + llm = make_llm(enable_thinking=True, remove_think_prefix=False) + reasoning_item = ResponseReasoningItem( + id="rs_1", + summary=[Summary(text="step by step", type="summary_text")], + type="reasoning", + ) + llm.client.responses.create.return_value = SimpleNamespace( + output=[reasoning_item], + output_text="final answer", + ) + + result = llm.generate(MESSAGES) + + assert result == "step by stepfinal answer" + + def test_generate_with_remove_think_prefix_strips_thinking(self, make_llm): + llm = make_llm(enable_thinking=True, remove_think_prefix=True) + reasoning_item = ResponseReasoningItem( + id="rs_1", + summary=[Summary(text="step by step", type="summary_text")], + type="reasoning", + ) + llm.client.responses.create.return_value = SimpleNamespace( + output=[reasoning_item], + output_text="inline thoughtfinal answer", + ) + + result = llm.generate(MESSAGES) + + assert result == "final answer" From fe70153bffac15f0e04503510b1cd0d82f90eca7 Mon Sep 17 00:00:00 2001 From: lils <310442317+linsheng-li@users.noreply.github.com> Date: Tue, 20 Oct 2026 11:43:32 +0800 Subject: [PATCH 18/38] fix(memory): decode JSON-encoded internal_info metadata --- src/memos/memories/textual/item.py | 10 ++++ tests/memories/textual/test_item.py | 91 +++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 tests/memories/textual/test_item.py diff --git a/src/memos/memories/textual/item.py b/src/memos/memories/textual/item.py index 23474cc20..9ad5369e7 100644 --- a/src/memos/memories/textual/item.py +++ b/src/memos/memories/textual/item.py @@ -159,6 +159,16 @@ class TextualMemoryMetadata(BaseModel): description="Internal algorithm metadata reserved for system use.", ) + @field_validator("internal_info", mode="before") + @classmethod + def _decode_internal_info(cls, value: Any) -> Any: + # Neo4j stores dictionaries as JSON strings; decode them before model validation. + if isinstance(value, str): + value = json.loads(value) + if not isinstance(value, dict): + raise ValueError("internal_info JSON must decode to an object") + return value + model_config = ConfigDict(extra="allow") covered_history: Any | None = Field( diff --git a/tests/memories/textual/test_item.py b/tests/memories/textual/test_item.py new file mode 100644 index 000000000..71c206742 --- /dev/null +++ b/tests/memories/textual/test_item.py @@ -0,0 +1,91 @@ +"""Regression tests for JSON-encoded internal metadata read from graph storage.""" + +import copy +import json +import uuid + +import pytest + +from pydantic import ValidationError + +from memos.memories.textual.item import ( + PreferenceTextualMemoryMetadata, + SearchedTreeNodeTextualMemoryMetadata, + TextualMemoryItem, + TextualMemoryMetadata, + TreeNodeTextualMemoryMetadata, +) + + +@pytest.mark.parametrize( + "metadata_cls", + [ + TextualMemoryMetadata, + TreeNodeTextualMemoryMetadata, + SearchedTreeNodeTextualMemoryMetadata, + PreferenceTextualMemoryMetadata, + ], +) +def test_internal_info_decodes_json_object(metadata_cls): + value = {"ingest_batch_id": "test-batch", "nested": {"chunk_index": 0, "values": [True, None]}} + + metadata = metadata_cls(internal_info=json.dumps(value)) + + assert metadata.internal_info == value + assert metadata.model_dump()["internal_info"] == value + + +@pytest.mark.parametrize("value", [None, {}, {"ingest_batch_id": "test-batch", "nested": [1, 2]}]) +def test_internal_info_preserves_existing_values(value): + original = copy.deepcopy(value) + + metadata = TextualMemoryMetadata(internal_info=value) + + assert metadata.internal_info == original + assert value == original + + +@pytest.mark.parametrize( + "value", + ["{", "not-json", "[]", "null", "1", "true", '"text"', json.dumps('{"batch": "test"}')], +) +def test_internal_info_rejects_malformed_json_and_encoded_non_objects(value): + with pytest.raises(ValidationError): + TextualMemoryMetadata(internal_info=value) + + +@pytest.mark.parametrize("value", [[], [["batch", "test"]], 1, False]) +def test_internal_info_preserves_rejection_of_invalid_types(value): + with pytest.raises(ValidationError): + TextualMemoryMetadata(internal_info=value) + + +def test_search_item_from_dict_decodes_internal_info_without_changing_other_fields(): + value = {"ingest_batch_id": "test-batch", "chunk_index": 0, "chunk_total": 2} + record = { + "id": str(uuid.uuid4()), + "memory": "Synthetic memory for a graph storage round trip.", + "metadata": { + "memory_type": "LongTermMemory", + "internal_info": json.dumps(value), + "relativity": 0.75, + "sources": [{"type": "chat", "role": "user", "content": "Synthetic source."}], + "session_id": "test-session", + }, + } + original = copy.deepcopy(record) + + item = TextualMemoryItem.from_dict(record) + + assert item.metadata.internal_info == value + assert item.id == record["id"] + assert item.memory == record["memory"] + assert item.metadata.sources[0].content == "Synthetic source." + assert item.metadata.session_id == "test-session" + assert item.metadata.relativity == 0.75 + assert record == original + + # Graph storage serializes dictionaries as JSON strings again on the next write. + stored = item.to_dict() + stored["metadata"]["internal_info"] = json.dumps(stored["metadata"]["internal_info"]) + assert TextualMemoryItem.from_dict(stored).to_dict() == item.to_dict() From ab57487c6b1d9c4f34b81ac6aa9692026eb00e5d Mon Sep 17 00:00:00 2001 From: Wenqiang Wei <46308778+endxxxx@users.noreply.github.com> Date: Tue, 20 Oct 2026 15:23:42 +0800 Subject: [PATCH 19/38] fix(plugin): use producer-owned sources for DSH V4 messages --- .../adapters/deepseek-harness/host-llm.ts | 4 ++-- .../adapters/deepseek-harness/index.ts | 17 ++++++++-------- .../deepseek-harness/message-source.ts | 20 +++++++++++++++++++ .../deepseek-harness-host-llm.test.ts | 2 +- .../adapters/deepseek-harness-runtime.test.ts | 10 ++++++++++ 5 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 apps/memos-local-plugin/adapters/deepseek-harness/message-source.ts diff --git a/apps/memos-local-plugin/adapters/deepseek-harness/host-llm.ts b/apps/memos-local-plugin/adapters/deepseek-harness/host-llm.ts index a755efb98..3334f9021 100644 --- a/apps/memos-local-plugin/adapters/deepseek-harness/host-llm.ts +++ b/apps/memos-local-plugin/adapters/deepseek-harness/host-llm.ts @@ -16,6 +16,7 @@ import { } from "@deepseek-ai/dsh-llm"; import { deadline, timeoutOf } from "@deepseek-ai/dsh-timeout"; import { AsyncLocalStorage } from "node:async_hooks"; +import { memosMessageSource } from "./message-source.js"; import { ERROR_CODES, MemosError } from "../../agent-contract/errors.js"; import type { @@ -27,7 +28,6 @@ import type { LlmMessage, LlmUsage } from "../../core/llm/types.js"; const HOST_LLM_BRIDGE_ID = "deepseek-harness.host.v1"; const HOST_LLM_TIMEOUT_CODE = "MEMOS_DSH_HOST_LLM_TIMEOUT"; -const HOST_LLM_MESSAGE_SOURCE = "memos-local-memory"; const NO_REASONING_EFFORT = ReasoningEffortId("off"); const UNSUPPORTED_REASONING_EFFORT = "UNSUPPORTED_REASONING_EFFORT"; const MODEL_CAPABILITY_TTL_MS = 10 * 60 * 1_000; @@ -366,7 +366,7 @@ function toDshMessage( if (message.role === "user") { return createUserMessage({ content, - source: { kind: "plugin", plugin: HOST_LLM_MESSAGE_SOURCE }, + source: memosMessageSource(), }); } return createAssistantMessage({ diff --git a/apps/memos-local-plugin/adapters/deepseek-harness/index.ts b/apps/memos-local-plugin/adapters/deepseek-harness/index.ts index bc63ba5d6..eec0cea5c 100644 --- a/apps/memos-local-plugin/adapters/deepseek-harness/index.ts +++ b/apps/memos-local-plugin/adapters/deepseek-harness/index.ts @@ -39,9 +39,17 @@ import { type DeepSeekHarnessHostLlmBridge, } from "./host-llm.js"; import { registerDeepSeekHarnessTools } from "./tools.js"; +import { memosMessageSource } from "./message-source.js"; export const name = DEEPSEEK_HARNESS_PLUGIN; export const inject = ["systemPrompt", "tools", "llm"]; + +export function createDeepSeekHarnessRecallMessage(text: string): ReturnType { + return createUserMessage({ + content: [{ type: "text", text }], + source: memosMessageSource("recall"), + }); +} export const DEEPSEEK_HARNESS_VIEWER_PORT = 18_801; export const DEEPSEEK_HARNESS_VIEWER_RETRY_DELAYS_MS = [ 250, @@ -384,14 +392,7 @@ export async function apply( recallTimeoutMs: foregroundSearchTimeoutMs, contextMaxChars: config.contextMaxChars, runWithLlmRoute: (route, operation) => routes.run(route, operation), - createRecallMessage: (text) => createUserMessage({ - content: [{ type: "text", text }], - source: { - kind: "plugin", - plugin: DEEPSEEK_HARNESS_PLUGIN, - form: "recall", - }, - }) as unknown as DshUserMessageLike, + createRecallMessage: (text) => createDeepSeekHarnessRecallMessage(text) as unknown as DshUserMessageLike, onWarn: (message, error) => { ctx.logger.warn(`memos-local-memory: ${message}`); if (error instanceof Error && error.stack) ctx.logger.warn(error.stack); diff --git a/apps/memos-local-plugin/adapters/deepseek-harness/message-source.ts b/apps/memos-local-plugin/adapters/deepseek-harness/message-source.ts new file mode 100644 index 000000000..58f345fc5 --- /dev/null +++ b/apps/memos-local-plugin/adapters/deepseek-harness/message-source.ts @@ -0,0 +1,20 @@ +/** Producer attribution accepted by both extensible V3 and native V4 sessions. */ +export interface MemOSMessageSource { + kind: "plugin:memos-local-memory"; + plugin: "memos-local-memory"; + form?: "recall"; +} + +declare module "@deepseek-ai/dsh-llm" { + interface MessageSourceMap { + "plugin:memos-local-memory": MemOSMessageSource; + } +} + +export function memosMessageSource(form?: "recall"): MemOSMessageSource { + return { + kind: "plugin:memos-local-memory", + plugin: "memos-local-memory", + ...(form ? { form } : {}), + }; +} diff --git a/apps/memos-local-plugin/tests/unit/adapters/deepseek-harness-host-llm.test.ts b/apps/memos-local-plugin/tests/unit/adapters/deepseek-harness-host-llm.test.ts index 493fba9e7..ea9b1854b 100644 --- a/apps/memos-local-plugin/tests/unit/adapters/deepseek-harness-host-llm.test.ts +++ b/apps/memos-local-plugin/tests/unit/adapters/deepseek-harness-host-llm.test.ts @@ -176,7 +176,7 @@ describe("DeepSeek Harness host LLM bridge", () => { { role: "user", content: [{ type: "text", text: "Question" }], - source: { kind: "plugin", plugin: "memos-local-memory" }, + source: { kind: "plugin:memos-local-memory", plugin: "memos-local-memory" }, }, { role: "assistant", diff --git a/apps/memos-local-plugin/tests/unit/adapters/deepseek-harness-runtime.test.ts b/apps/memos-local-plugin/tests/unit/adapters/deepseek-harness-runtime.test.ts index 7d6c515ef..b5e690888 100644 --- a/apps/memos-local-plugin/tests/unit/adapters/deepseek-harness-runtime.test.ts +++ b/apps/memos-local-plugin/tests/unit/adapters/deepseek-harness-runtime.test.ts @@ -5,6 +5,7 @@ import { describe, expect, it, vi } from "vitest"; import { configureDeepSeekHarnessHostLlm, + createDeepSeekHarnessRecallMessage, deepSeekHarnessAutoRecoveryEnabled, deepSeekHarnessMemoryGuidance, defaultDeepSeekHarnessHome, @@ -17,6 +18,15 @@ import type { import { DEFAULT_CONFIG } from "../../../core/config/index.js"; describe("DeepSeek Harness adapter runtime defaults", () => { + it("creates producer-owned recall messages admitted by DSH V4", () => { + const message = createDeepSeekHarnessRecallMessage("synthetic recall"); + expect(message).toMatchObject({ + role: "user", + content: [{ type: "text", text: "synthetic recall" }], + source: { kind: "plugin:memos-local-memory", plugin: "memos-local-memory", form: "recall" }, + }); + }); + it("injects the DSH LLM service and uses it for an otherwise unconfigured MemOS LLM", () => { expect(inject).toContain("llm"); From 5a12a4d445b3ea58dec33567022ff3ca52c42f46 Mon Sep 17 00:00:00 2001 From: Wenqiang Wei <46308778+endxxxx@users.noreply.github.com> Date: Tue, 20 Oct 2026 15:23:42 +0800 Subject: [PATCH 20/38] fix(plugin): validate imports and expose ownership previews --- .../agent-contract/import.ts | 40 ++ .../agent-contract/memory-core.ts | 9 +- .../core/pipeline/bundle-import.ts | 494 ++++++++++++++++++ .../core/pipeline/memory-core.ts | 305 +---------- .../server/routes/import-export.ts | 12 +- .../tests/unit/pipeline/import-bundle.test.ts | 182 +++++++ .../tests/unit/server/http.test.ts | 19 + 7 files changed, 752 insertions(+), 309 deletions(-) create mode 100644 apps/memos-local-plugin/agent-contract/import.ts create mode 100644 apps/memos-local-plugin/core/pipeline/bundle-import.ts create mode 100644 apps/memos-local-plugin/tests/unit/pipeline/import-bundle.test.ts diff --git a/apps/memos-local-plugin/agent-contract/import.ts b/apps/memos-local-plugin/agent-contract/import.ts new file mode 100644 index 000000000..20d1c271c --- /dev/null +++ b/apps/memos-local-plugin/agent-contract/import.ts @@ -0,0 +1,40 @@ +export interface MemoryImportBundle { + version?: number; + traces?: unknown[]; + policies?: unknown[]; + worldModels?: unknown[]; + skills?: unknown[]; +} + +export interface MemoryImportOptions { + /** Preserve source ownership unless the caller explicitly requests migration. */ + ownership?: "preserve" | "target"; + /** Target the active agent's named profile; omitted means its active profile. */ + targetProfileId?: string; + /** Validate and estimate visibility without writing any records. */ + dryRun?: boolean; +} + +export interface MemoryImportIssue { + kind: "trace" | "policy" | "worldModel" | "skill"; + /** Zero-based index in the corresponding bundle collection. */ + index: number; + field?: string; + code: string; + message: string; +} + +export interface MemoryImportResult { + imported: number; + /** Backwards-compatible total: duplicates + invalid + failed. */ + skipped: number; + duplicates: number; + invalid: number; + failed: number; + /** Successful (or preview candidate) rows visible to the active profile. */ + visible: number; + hidden: number; + dryRun: boolean; + /** At most 50 diagnostics; never includes row text or raw database errors. */ + issues: MemoryImportIssue[]; +} diff --git a/apps/memos-local-plugin/agent-contract/memory-core.ts b/apps/memos-local-plugin/agent-contract/memory-core.ts index be0e8563d..0bdd10d05 100644 --- a/apps/memos-local-plugin/agent-contract/memory-core.ts +++ b/apps/memos-local-plugin/agent-contract/memory-core.ts @@ -33,6 +33,7 @@ import type { } from "./dto.js"; import type { CoreEvent } from "./events.js"; import type { LogRecord } from "./log-record.js"; +import type { MemoryImportBundle, MemoryImportOptions, MemoryImportResult } from "./import.js"; // ─── Public lifecycle / status ──────────────────────────────────────────────── @@ -588,13 +589,7 @@ export interface MemoryCore { worldModels: WorldModelDTO[]; skills: SkillDTO[]; }>; - importBundle(bundle: { - version?: number; - traces?: unknown[]; - policies?: unknown[]; - worldModels?: unknown[]; - skills?: unknown[]; - }): Promise<{ imported: number; skipped: number }>; + importBundle(bundle: MemoryImportBundle, options?: MemoryImportOptions): Promise; // ── embedding maintenance ── embeddingMaintenanceStats(): Promise; diff --git a/apps/memos-local-plugin/core/pipeline/bundle-import.ts b/apps/memos-local-plugin/core/pipeline/bundle-import.ts new file mode 100644 index 000000000..38cd2529b --- /dev/null +++ b/apps/memos-local-plugin/core/pipeline/bundle-import.ts @@ -0,0 +1,494 @@ +import type { + MemoryImportBundle, + MemoryImportIssue, + MemoryImportOptions, + MemoryImportResult, +} from "../../agent-contract/import.js"; +import type { + PolicyDTO, + RuntimeNamespace, + SkillDTO, + TraceDTO, + WorldModelDTO, +} from "../../agent-contract/dto.js"; +import { MemosError } from "../../agent-contract/errors.js"; +import { + isVisibleTo, + normalizeNamespace, + ownerFromNamespace, +} from "../runtime/namespace.js"; +import { rootLogger } from "../logger/index.js"; +import type { Repos, StorageDb } from "../storage/index.js"; +import type { + EpisodeId, + SkillRow, + TraceId, + TraceRow, + WorldModelRow, +} from "../types.js"; + +type Kind = MemoryImportIssue["kind"]; +type RecordRow = Record; +type Owner = ReturnType; +const BATCH_SIZE = 100; + +function validationIssue( + kind: Kind, + value: unknown, +): Omit | undefined { + if (!value || typeof value !== "object" || Array.isArray(value)) { + return { code: "invalid_row", message: "Row must be an object." }; + } + const row = value as RecordRow; + const required = + kind === "trace" + ? ["id", "sessionId", "episodeId"] + : kind === "policy" + ? [ + "id", + "title", + "trigger", + "procedure", + "verification", + "boundary", + "status", + ] + : kind === "skill" + ? ["id", "name", "invocationGuide", "status"] + : ["id", "title", "body"]; + for (const field of required) { + if ( + typeof row[field] !== "string" || + (["id", "sessionId", "episodeId"].includes(field) && !row[field].trim()) + ) { + return { + field, + code: "invalid_field", + message: `${field} must be a string${field === "id" ? " with a nonempty id" : ""}.`, + }; + } + } + if ( + row.status != null && + !( + kind === "worldModel" + ? ["active", "archived"] + : ["candidate", "active", "archived"] + ).includes(String(row.status)) + ) { + return { + field: "status", + code: "invalid_field", + message: "status is not a supported lifecycle state.", + }; + } + for (const field of [ + "ts", + "turnId", + "createdAt", + "updatedAt", + "lastUsedAt", + "version", + ]) { + if (row[field] != null && !Number.isSafeInteger(row[field])) { + return { + field, + code: "invalid_integer", + message: `${field} must be a safe integer; timestamps use milliseconds.`, + }; + } + } + for (const field of [ + "userText", + "agentText", + "summary", + "reflection", + "agentThinking", + "ownerAgentKind", + "ownerProfileId", + "ownerWorkspaceId", + ]) { + if (row[field] != null && typeof row[field] !== "string") { + return { + field, + code: "invalid_field", + message: `${field} must be a string.`, + }; + } + } + for (const field of [ + "value", + "alpha", + "priority", + "rHuman", + "support", + "gain", + "eta", + "salience", + "confidence", + ]) { + if ( + row[field] != null && + (typeof row[field] !== "number" || !Number.isFinite(row[field])) + ) { + return { + field, + code: "invalid_field", + message: `${field} must be a finite number.`, + }; + } + } + for (const field of [ + "toolCalls", + "tags", + "preference", + "antiPattern", + "policyIds", + "sourceEpisodeIds", + "sourceFeedbackIds", + "sourceTraceIds", + "sourcePolicyIds", + "sourceWorldModelIds", + "evidenceAnchors", + ]) { + if (row[field] != null && !Array.isArray(row[field])) { + return { + field, + code: "invalid_field", + message: `${field} must be an array.`, + }; + } + if ( + field !== "toolCalls" && + Array.isArray(row[field]) && + row[field].some((value) => typeof value !== "string") + ) { + return { + field, + code: "invalid_field", + message: `${field} must contain strings.`, + }; + } + } + if (row.share != null) { + const share = row.share as RecordRow; + if ( + typeof share !== "object" || + Array.isArray(share) || + !["private", "local", "public", "hub"].includes(String(share.scope)) + ) { + return { + field: "share", + code: "invalid_field", + message: "share must specify a valid scope.", + }; + } + if (share.sharedAt != null && !Number.isSafeInteger(share.sharedAt)) { + return { + field: "share.sharedAt", + code: "invalid_integer", + message: "share.sharedAt must be an integer timestamp in milliseconds.", + }; + } + } + return undefined; +} + +function ownerFor( + row: RecordRow, + fallback: Owner, + options: MemoryImportOptions, +): Owner { + if (options.ownership === "target") return fallback; + return { + ownerAgentKind: (row.ownerAgentKind as string) ?? fallback.ownerAgentKind, + ownerProfileId: (row.ownerProfileId as string) ?? fallback.ownerProfileId, + ownerWorkspaceId: + (row.ownerWorkspaceId as string | null) ?? fallback.ownerWorkspaceId, + }; +} + +/** Import each row atomically; a rejected trace must not leave synthetic parents behind. */ +export async function importMemoryBundle( + bundle: MemoryImportBundle, + options: MemoryImportOptions, + context: { db: StorageDb; repos: Repos; namespace: RuntimeNamespace }, +): Promise { + if (!bundle || typeof bundle !== "object" || Array.isArray(bundle)) + throw new MemosError("invalid_argument", "bundle must be an object"); + if (bundle.version !== undefined && bundle.version !== 1) + throw new MemosError("unsupported", "unsupported bundle version"); + if ( + options.ownership !== undefined && + !["preserve", "target"].includes(options.ownership) + ) + throw new MemosError( + "invalid_argument", + "ownership must be preserve or target", + ); + if ( + options.targetProfileId !== undefined && + (options.ownership !== "target" || + typeof options.targetProfileId !== "string" || + !options.targetProfileId.trim()) + ) { + throw new MemosError( + "invalid_argument", + "targetProfileId requires target ownership and a nonempty profile id", + ); + } + if (options.dryRun !== undefined && typeof options.dryRun !== "boolean") + throw new MemosError("invalid_argument", "dryRun must be boolean"); + const collections = [ + ["trace", "traces"], + ["policy", "policies"], + ["skill", "skills"], + ["worldModel", "worldModels"], + ] as const; + for (const [, name] of collections) { + if (bundle[name] !== undefined && !Array.isArray(bundle[name])) + throw new MemosError("invalid_argument", `${name} must be an array`); + } + const { db, repos, namespace } = context; + const target = normalizeNamespace({ + ...namespace, + profileId: options.targetProfileId ?? namespace.profileId, + }); + const fallback = ownerFromNamespace( + options.ownership === "target" ? target : namespace, + ); + const result: MemoryImportResult = { + imported: 0, + skipped: 0, + duplicates: 0, + invalid: 0, + failed: 0, + visible: 0, + hidden: 0, + dryRun: options.dryRun === true, + issues: [], + }; + const issue = (value: MemoryImportIssue) => { + if (result.issues.length < 50) result.issues.push(value); + }; + + for (const [kind, name] of collections) { + const rows = bundle[name] ?? []; + const ids = new Set(); + for (let offset = 0; offset < rows.length; offset += BATCH_SIZE) { + const batch = rows.slice(offset, offset + BATCH_SIZE); + const existingTraces = + kind === "trace" + ? new Set( + repos.traces + .getManyByIds( + batch + .filter( + (row): row is RecordRow => + !!row && + typeof row === "object" && + typeof (row as RecordRow).id === "string", + ) + .map((row) => row.id as TraceId), + ) + .map((row) => row.id as string), + ) + : new Set(); + db.tx(() => { + for (let i = 0; i < batch.length; i++) { + const index = offset + i; + const invalid = validationIssue(kind, batch[i]); + if (invalid) { + result.invalid++; + result.skipped++; + issue({ kind, index, ...invalid }); + continue; + } + const raw = batch[i] as RecordRow; + const id = raw.id as string; + const exists = + ids.has(id) || + (kind === "trace" + ? existingTraces.has(id) + : kind === "policy" + ? !!repos.policies.getById(id) + : kind === "skill" + ? !!repos.skills.getById(id) + : !!repos.worldModel.getById(id)); + if (exists) { + result.duplicates++; + result.skipped++; + continue; + } + const owner = ownerFor(raw, fallback, options); + const row = { ...raw, ...owner }; + try { + if (!options.dryRun) db.tx(() => insertRow(kind, row, repos)); + ids.add(id); + result.imported++; + if (isVisibleTo(row, namespace)) result.visible++; + else result.hidden++; + } catch { + result.failed++; + result.skipped++; + issue({ + kind, + index, + code: "write_failed", + message: + "Database rejected this row; verify its fields and references.", + }); + } + } + }); + await new Promise((resolve) => setImmediate(resolve)); + } + } + if (!options.dryRun && (result.failed || result.invalid)) { + rootLogger.child({ channel: "core.import" }).warn("rows_rejected", { + invalid: result.invalid, + failed: result.failed, + issues: result.issues, + }); + } + return result; +} + +function insertRow(kind: Kind, raw: RecordRow & Owner, repos: Repos): void { + const owner: Owner = { + ownerAgentKind: raw.ownerAgentKind, + ownerProfileId: raw.ownerProfileId, + ownerWorkspaceId: raw.ownerWorkspaceId, + }; + const now = Date.now(); + if (kind === "trace") { + const dto = raw as unknown as TraceDTO; + const ts = dto.ts ?? now; + if (!repos.sessions.getById(dto.sessionId)) + repos.sessions.upsert({ + id: dto.sessionId, + agent: owner.ownerAgentKind, + ...owner, + startedAt: ts, + lastSeenAt: ts, + meta: { source: "import" }, + }); + const episode = repos.episodes.getById(dto.episodeId); + if (!episode) + repos.episodes.upsert({ + id: dto.episodeId, + sessionId: dto.sessionId, + ...owner, + share: dto.share ?? null, + startedAt: ts, + endedAt: ts, + traceIds: [], + rTask: null, + status: "closed", + meta: { source: "import" }, + }); + repos.traces.insert({ + ...owner, + id: dto.id, + episodeId: dto.episodeId, + sessionId: dto.sessionId, + ts, + userText: dto.userText ?? "", + agentText: dto.agentText ?? "", + summary: dto.summary ?? null, + share: dto.share ?? null, + toolCalls: dto.toolCalls ?? [], + agentThinking: dto.agentThinking ?? null, + reflection: dto.reflection ?? null, + value: dto.value ?? 0, + alpha: dto.alpha ?? 0, + rHuman: dto.rHuman ?? null, + priority: dto.priority ?? 0, + tags: dto.tags ?? [], + vecSummary: null, + vecAction: null, + turnId: dto.turnId ?? ts, + schemaVersion: 1, + } as TraceRow); + repos.episodes.appendTrace(dto.episodeId as EpisodeId, [ + ...new Set([...(episode?.traceIds ?? []), dto.id]), + ]); + } else if (kind === "policy") { + const dto = raw as unknown as PolicyDTO; + repos.policies.insert({ + ...owner, + id: dto.id, + title: dto.title, + trigger: dto.trigger, + procedure: dto.procedure, + verification: dto.verification, + boundary: dto.boundary, + support: dto.support ?? 0, + gain: dto.gain ?? 0, + status: dto.status, + experienceType: dto.experienceType ?? "success_pattern", + evidencePolarity: dto.evidencePolarity ?? "positive", + salience: dto.salience ?? 0, + confidence: dto.confidence ?? 0.5, + skillEligible: dto.skillEligible !== false, + sourceEpisodeIds: dto.sourceEpisodeIds ?? [], + sourceFeedbackIds: dto.sourceFeedbackIds ?? [], + sourceTraceIds: dto.sourceTraceIds ?? [], + inducedBy: "import", + decisionGuidance: { + preference: [...(dto.preference ?? [])], + antiPattern: [...(dto.antiPattern ?? [])], + }, + verifierMeta: dto.verifierMeta ?? null, + share: dto.share ?? null, + vec: null, + createdAt: dto.createdAt ?? now, + updatedAt: dto.updatedAt ?? now, + }); + } else if (kind === "skill") { + const dto = raw as unknown as SkillDTO; + repos.skills.insert({ + ...owner, + id: dto.id, + name: dto.name, + status: dto.status, + invocationGuide: dto.invocationGuide, + eta: dto.eta ?? 0, + support: dto.support ?? 0, + gain: dto.gain ?? 0, + trialsAttempted: 0, + trialsPassed: 0, + sourcePolicyIds: dto.sourcePolicyIds ?? [], + sourceWorldModelIds: dto.sourceWorldModelIds ?? [], + evidenceAnchors: dto.evidenceAnchors ?? [], + procedureJson: {}, + share: dto.share ?? null, + vec: null, + createdAt: dto.createdAt ?? now, + updatedAt: dto.updatedAt ?? now, + version: dto.version ?? 1, + usageCount: dto.usageCount ?? 0, + lastUsedAt: dto.lastUsedAt ?? null, + } as SkillRow); + } else { + const dto = raw as unknown as WorldModelDTO; + repos.worldModel.insert({ + ...owner, + id: dto.id, + title: dto.title, + body: dto.body, + structure: { environment: [], inference: [], constraints: [] }, + domainTags: [], + confidence: 0.5, + policyIds: dto.policyIds ?? [], + sourceEpisodeIds: [], + inducedBy: "import", + share: dto.share ?? null, + vec: null, + createdAt: dto.createdAt ?? now, + updatedAt: dto.updatedAt ?? now, + version: dto.version ?? 1, + status: dto.status ?? "active", + } as WorldModelRow); + } +} diff --git a/apps/memos-local-plugin/core/pipeline/memory-core.ts b/apps/memos-local-plugin/core/pipeline/memory-core.ts index c7b2782e4..852f846de 100644 --- a/apps/memos-local-plugin/core/pipeline/memory-core.ts +++ b/apps/memos-local-plugin/core/pipeline/memory-core.ts @@ -23,6 +23,8 @@ * minimal `{ agent, home?, config? }` input. Used by adapters. */ +import type { MemoryImportBundle, MemoryImportOptions, MemoryImportResult } from "../../agent-contract/import.js"; +import { importMemoryBundle } from "./bundle-import.js"; import { randomUUID } from "node:crypto"; import { MemosError } from "../../agent-contract/errors.js"; @@ -129,7 +131,6 @@ import type { UserFeedback } from "../reward/types.js"; const FINAL_HUB_LLM_FILTER_TIMEOUT_MS = 3_000; const DEADLINE_FILTER_SAFE_CUTOFF_MS = 2_000; -const IMPORT_WRITE_BATCH_SIZE = 500; type DedicatedLlmConfig = { provider?: string; @@ -4358,276 +4359,9 @@ export function createMemoryCore( }; } - async function importBundle(bundle: { - version?: number; - traces?: unknown[]; - policies?: unknown[]; - worldModels?: unknown[]; - skills?: unknown[]; - }): Promise<{ imported: number; skipped: number }> { + async function importBundle(bundle: MemoryImportBundle, options: MemoryImportOptions = {}): Promise { ensureLive(); - if (bundle.version && bundle.version !== 1) { - throw new MemosError("unsupported", `unsupported bundle version: ${bundle.version}`); - } - let imported = 0; - let skipped = 0; - - // Best-effort: only insert rows that don't collide with existing - // ids. We don't re-mint fresh ids on collision to keep the shape - // deterministic for the user — they opt in via a de-duplicating - // pre-pass if they want merging. - const traces = Array.isArray(bundle.traces) ? bundle.traces : []; - const defaultOwner = ownerFromNamespace(activeNamespace); - const seenSessions = new Set(); - const seenEpisodes = new Set(); - - for (const batch of chunkArray(traces, IMPORT_WRITE_BATCH_SIZE)) { - const result = handle.db.tx(() => { - let batchImported = 0; - let batchSkipped = 0; - const valid = batch - .map((raw) => raw as TraceDTO) - .filter((dto) => dto?.id && dto.episodeId && dto.sessionId); - batchSkipped += batch.length - valid.length; - - // Phase 0 — ensure every referenced (sessionId, episodeId) row - // exists before `traces.insert`, otherwise the FK constraint would - // bounce imported legacy/external rows. - for (const dto of valid) { - const owner = importOwnerFields(dto, defaultOwner); - const ts = Number.isFinite(dto.ts) ? dto.ts : Date.now(); - if (!seenSessions.has(dto.sessionId)) { - try { - if (!handle.repos.sessions.getById(dto.sessionId)) { - handle.repos.sessions.upsert({ - id: dto.sessionId, - agent: dto.ownerAgentKind ?? handle.agent, - ...owner, - startedAt: ts, - lastSeenAt: ts, - meta: { source: "import" }, - } as never); - } - } catch { - // If the synthetic session row is rejected, the FK insert - // below will fail and be counted as `skipped`. - } - seenSessions.add(dto.sessionId); - } - if (!seenEpisodes.has(dto.episodeId)) { - try { - if (!handle.repos.episodes.getById(dto.episodeId)) { - handle.repos.episodes.upsert({ - id: dto.episodeId, - sessionId: dto.sessionId, - ...owner, - share: dto.share ?? null, - startedAt: ts, - endedAt: ts, - traceIds: [], - rTask: null, - status: "closed", - meta: { source: "import" }, - } as never); - } - } catch { - /* see comment above */ - } - seenEpisodes.add(dto.episodeId); - } - } - - const existingIds = new Set( - handle.repos.traces - .getManyByIds(valid.map((dto) => dto.id as TraceId)) - .map((row) => row.id), - ); - const addedByEpisode = new Map(); - for (const dto of valid) { - try { - if (existingIds.has(dto.id)) { batchSkipped++; continue; } - const owner = importOwnerFields(dto, defaultOwner); - const ts = Number.isFinite(dto.ts) ? dto.ts : Date.now(); - const turnId = Number.isFinite(dto.turnId) ? dto.turnId : ts; - handle.repos.traces.insert({ - ...owner, - id: dto.id, - episodeId: dto.episodeId, - sessionId: dto.sessionId, - ts, - userText: dto.userText ?? "", - agentText: dto.agentText ?? "", - summary: dto.summary ?? null, - share: dto.share ?? null, - toolCalls: dto.toolCalls ?? [], - agentThinking: dto.agentThinking ?? null, - reflection: dto.reflection ?? null, - value: dto.value ?? 0, - alpha: dto.alpha ?? 0, - rHuman: dto.rHuman ?? null, - priority: dto.priority ?? 0, - tags: dto.tags ?? [], - vecSummary: null, - vecAction: null, - turnId, - schemaVersion: 1, - } as TraceRow); - existingIds.add(dto.id); - if (!addedByEpisode.has(dto.episodeId)) addedByEpisode.set(dto.episodeId, []); - addedByEpisode.get(dto.episodeId)!.push(dto.id as TraceId); - batchImported++; - } catch { - batchSkipped++; - } - } - for (const [episodeId, ids] of addedByEpisode) { - const episode = handle.repos.episodes.getById(episodeId); - if (!episode) continue; - handle.repos.episodes.appendTrace( - episodeId, - dedupeTraceIds([...episode.traceIds, ...ids]) as string[], - ); - } - return { imported: batchImported, skipped: batchSkipped }; - }); - imported += result.imported; - skipped += result.skipped; - await yieldToEventLoop(); - } - - // Policies / world models / skills use existing repo.insert shape. - for (const batch of chunkArray(bundle.policies ?? [], IMPORT_WRITE_BATCH_SIZE)) { - const result = handle.db.tx(() => { - let batchImported = 0; - let batchSkipped = 0; - for (const raw of batch) { - try { - const dto = raw as PolicyDTO; - if (!dto?.id || handle.repos.policies.getById(dto.id)) { batchSkipped++; continue; } - handle.repos.policies.insert({ - ...importOwnerFields(dto, defaultOwner), - id: dto.id, - title: dto.title, - trigger: dto.trigger, - procedure: dto.procedure, - verification: dto.verification, - boundary: dto.boundary, - support: dto.support ?? 0, - gain: dto.gain ?? 0, - status: dto.status, - experienceType: dto.experienceType ?? "success_pattern", - evidencePolarity: dto.evidencePolarity ?? "positive", - salience: dto.salience ?? 0, - confidence: dto.confidence ?? 0.5, - skillEligible: dto.skillEligible !== false, - sourceEpisodeIds: dto.sourceEpisodeIds ?? [], - sourceFeedbackIds: dto.sourceFeedbackIds ?? [], - sourceTraceIds: dto.sourceTraceIds ?? [], - inducedBy: "import", - decisionGuidance: { - preference: [...(dto.preference ?? [])], - antiPattern: [...(dto.antiPattern ?? [])], - }, - verifierMeta: dto.verifierMeta ?? null, - share: dto.share ?? null, - vec: null, - createdAt: dto.createdAt ?? Date.now(), - updatedAt: dto.updatedAt ?? Date.now(), - }); - batchImported++; - } catch { - batchSkipped++; - } - } - return { imported: batchImported, skipped: batchSkipped }; - }); - imported += result.imported; - skipped += result.skipped; - await yieldToEventLoop(); - } - - for (const batch of chunkArray(bundle.skills ?? [], IMPORT_WRITE_BATCH_SIZE)) { - const result = handle.db.tx(() => { - let batchImported = 0; - let batchSkipped = 0; - for (const raw of batch) { - try { - const dto = raw as SkillDTO; - if (!dto?.id || handle.repos.skills.getById(dto.id)) { batchSkipped++; continue; } - handle.repos.skills.insert({ - ...importOwnerFields(dto, defaultOwner), - id: dto.id, - name: dto.name, - status: dto.status, - invocationGuide: dto.invocationGuide, - eta: dto.eta ?? 0, - support: dto.support ?? 0, - gain: dto.gain ?? 0, - trialsAttempted: 0, - trialsPassed: 0, - sourcePolicyIds: dto.sourcePolicyIds ?? [], - sourceWorldModelIds: dto.sourceWorldModelIds ?? [], - evidenceAnchors: dto.evidenceAnchors ?? [], - procedureJson: {}, - share: dto.share ?? null, - vec: null, - createdAt: dto.createdAt ?? Date.now(), - updatedAt: dto.updatedAt ?? Date.now(), - version: dto.version ?? 1, - usageCount: dto.usageCount ?? 0, - lastUsedAt: dto.lastUsedAt ?? null, - } as SkillRow); - batchImported++; - } catch { - batchSkipped++; - } - } - return { imported: batchImported, skipped: batchSkipped }; - }); - imported += result.imported; - skipped += result.skipped; - await yieldToEventLoop(); - } - - for (const batch of chunkArray(bundle.worldModels ?? [], IMPORT_WRITE_BATCH_SIZE)) { - const result = handle.db.tx(() => { - let batchImported = 0; - let batchSkipped = 0; - for (const raw of batch) { - try { - const dto = raw as WorldModelDTO; - if (!dto?.id || handle.repos.worldModel.getById(dto.id)) { batchSkipped++; continue; } - handle.repos.worldModel.insert({ - ...importOwnerFields(dto, defaultOwner), - id: dto.id, - title: dto.title, - body: dto.body, - structure: { environment: [], inference: [], constraints: [] }, - domainTags: [], - confidence: 0.5, - policyIds: dto.policyIds ?? [], - sourceEpisodeIds: [], - inducedBy: "import", - share: dto.share ?? null, - vec: null, - createdAt: dto.createdAt ?? Date.now(), - updatedAt: dto.updatedAt ?? Date.now(), - version: dto.version ?? 1, - status: dto.status ?? "active", - } as WorldModelRow); - batchImported++; - } catch { - batchSkipped++; - } - } - return { imported: batchImported, skipped: batchSkipped }; - }); - imported += result.imported; - skipped += result.skipped; - await yieldToEventLoop(); - } - - return { imported, skipped }; + return importMemoryBundle(bundle, options, { db: handle.db, repos: handle.repos, namespace: activeNamespace }); } async function embeddingMaintenanceStats(): Promise { @@ -5579,25 +5313,6 @@ function compareTraceRowsForEpisodeOrder( return a.ts - b.ts; } -function importOwnerFields( - row: { - ownerAgentKind?: AgentKind; - ownerProfileId?: string; - ownerWorkspaceId?: string | null; - }, - fallback: ReturnType, -): { - ownerAgentKind: AgentKind; - ownerProfileId: string; - ownerWorkspaceId: string | null; -} { - return { - ownerAgentKind: row.ownerAgentKind ?? fallback.ownerAgentKind, - ownerProfileId: row.ownerProfileId ?? fallback.ownerProfileId, - ownerWorkspaceId: row.ownerWorkspaceId ?? fallback.ownerWorkspaceId ?? null, - }; -} - function dedupeTraceIds(ids: readonly TraceId[]): TraceId[] { const seen = new Set(); const out: TraceId[] = []; @@ -5609,18 +5324,6 @@ function dedupeTraceIds(ids: readonly TraceId[]): TraceId[] { return out; } -function chunkArray(items: readonly T[], size: number): T[][] { - const out: T[][] = []; - for (let i = 0; i < items.length; i += size) { - out.push(items.slice(i, i + size)); - } - return out; -} - -function yieldToEventLoop(): Promise { - return new Promise((resolve) => setTimeout(resolve, 0)); -} - // ─── Row → DTO mappers ─────────────────────────────────────────────────────── export function traceRowToDTO(row: TraceRow, episode?: EpisodeRow | null): TraceDTO { diff --git a/apps/memos-local-plugin/server/routes/import-export.ts b/apps/memos-local-plugin/server/routes/import-export.ts index 082aabe23..954349fbc 100644 --- a/apps/memos-local-plugin/server/routes/import-export.ts +++ b/apps/memos-local-plugin/server/routes/import-export.ts @@ -127,7 +127,17 @@ export function registerImportExportRoutes( writeError(ctx, 400, "invalid_argument", "bundle must be a JSON object"); return; } - return await deps.core.importBundle(bundle); + const ownership = ctx.url.searchParams.get("ownership") ?? "preserve"; + const dryRun = ctx.url.searchParams.get("dryRun") ?? "false"; + const targetProfileId = ctx.url.searchParams.get("targetProfileId") ?? undefined; + if (!["preserve", "target"].includes(ownership) || !["true", "false"].includes(dryRun) + || (targetProfileId !== undefined && (ownership !== "target" || !targetProfileId.trim()))) { + writeError(ctx, 400, "invalid_argument", "invalid import ownership, targetProfileId or dryRun option"); + return; + } + return await deps.core.importBundle(bundle, { + ownership: ownership as "preserve" | "target", dryRun: dryRun === "true", targetProfileId, + }); }); routes.set("GET /api/v1/import/hermes-native/scan", async () => { diff --git a/apps/memos-local-plugin/tests/unit/pipeline/import-bundle.test.ts b/apps/memos-local-plugin/tests/unit/pipeline/import-bundle.test.ts new file mode 100644 index 000000000..16602f655 --- /dev/null +++ b/apps/memos-local-plugin/tests/unit/pipeline/import-bundle.test.ts @@ -0,0 +1,182 @@ +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; + +import { afterEach, beforeEach, describe, expect, it } from "vitest"; + +import type { MemoryCore } from "../../../agent-contract/memory-core.js"; +import { DEFAULT_CONFIG, resolveHome } from "../../../core/config/index.js"; +import { bootstrapMemoryCore } from "../../../core/pipeline/memory-core.js"; +import { openDb } from "../../../core/storage/index.js"; + +let dir: string; +let core: MemoryCore; +const row = (id: string, extra: Record = {}) => ({ + id, + episodeId: `episode-${id}`, + sessionId: `session-${id}`, + ts: 1_700_000_000_000, + turnId: 1, + userText: "Synthetic import test", + agentText: "Synthetic answer", + ...extra, +}); + +describe("bundle import validation and ownership", () => { + beforeEach(async () => { + dir = fs.mkdtempSync(path.join(os.tmpdir(), "memos-import-test-")); + core = await bootstrapMemoryCore({ + agent: "deepseek-harness", + namespace: { agentKind: "deepseek-harness", profileId: "default" }, + home: resolveHome("deepseek-harness", dir), + config: structuredClone(DEFAULT_CONFIG), + autoRecovery: false, + }); + }); + + afterEach(async () => { + await core?.shutdown(); + fs.rmSync(dir, { recursive: true, force: true }); + }); + + it("distinguishes invalid integer fields from duplicates without leaking row content", async () => { + const valid = row("valid"); + const result = await core.importBundle({ + traces: [ + valid, + row("fractional-ts", { ts: 12.5 }), + row("fractional-turn", { turnId: 1.5 }), + row("unsafe", { ts: Number.MAX_SAFE_INTEGER + 1 }), + null, + valid, + ], + }); + expect(result).toMatchObject({ + imported: 1, + skipped: 5, + duplicates: 1, + invalid: 4, + failed: 0, + visible: 1, + hidden: 0, + }); + expect(result.issues).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + kind: "trace", + index: 1, + field: "ts", + code: "invalid_integer", + }), + expect.objectContaining({ + kind: "trace", + index: 2, + field: "turnId", + code: "invalid_integer", + }), + ]), + ); + expect(JSON.stringify(result)).not.toContain("Synthetic import test"); + expect((await core.exportBundle()).traces).toHaveLength(1); + }); + + it("reports database failures separately and rolls back synthetic parents", async () => { + const db = openDb({ + filepath: resolveHome("deepseek-harness", dir).dbFile, + agent: "deepseek-harness", + }); + try { + db.exec( + "CREATE TRIGGER reject_import BEFORE INSERT ON traces BEGIN SELECT RAISE(ABORT, 'sensitive database detail'); END", + ); + const result = await core.importBundle({ traces: [row("rejected")] }); + expect(result).toMatchObject({ + imported: 0, + skipped: 1, + failed: 1, + invalid: 0, + duplicates: 0, + }); + expect(result.issues).toContainEqual( + expect.objectContaining({ code: "write_failed", index: 0 }), + ); + expect(JSON.stringify(result)).not.toContain("sensitive database detail"); + expect(db.prepare("SELECT COUNT(*) AS n FROM sessions").get()).toEqual({ + n: 0, + }); + expect(db.prepare("SELECT COUNT(*) AS n FROM episodes").get()).toEqual({ + n: 0, + }); + } finally { + db.close(); + } + }); + + it("previews visibility without writes and explicitly migrates private rows to a target profile", async () => { + const seeded = row("seeded", { + ownerAgentKind: "deepseek-harness", + ownerProfileId: "seed", + }); + const preview = await core.importBundle( + { traces: [seeded] }, + { dryRun: true }, + ); + expect(preview).toMatchObject({ + imported: 1, + visible: 0, + hidden: 1, + dryRun: true, + }); + expect((await core.exportBundle()).traces).toHaveLength(0); + const movedPreview = await core.importBundle( + { traces: [seeded] }, + { dryRun: true, ownership: "target" }, + ); + expect(movedPreview).toMatchObject({ visible: 1, hidden: 0 }); + const result = await core.importBundle( + { traces: [seeded] }, + { ownership: "target" }, + ); + expect(result).toMatchObject({ imported: 1, visible: 1, hidden: 0 }); + expect(await core.getTrace("seeded")).toMatchObject({ + ownerProfileId: "default", + share: { scope: "private" }, + }); + }); + + it("preserves original ownership by default and supports an explicit target profile", async () => { + const seeded = row("preserved", { + ownerAgentKind: "deepseek-harness", + ownerProfileId: "seed", + }); + expect(await core.importBundle({ traces: [seeded] })).toMatchObject({ + hidden: 1, + }); + expect(await core.getTrace("preserved")).toBeNull(); + const result = await core.importBundle( + { traces: [row("target")] }, + { ownership: "target", targetProfileId: "work" }, + ); + expect(result).toMatchObject({ hidden: 1 }); + expect( + await core.getTrace("target", { + agentKind: "deepseek-harness", + profileId: "work", + }), + ).toMatchObject({ ownerProfileId: "work", share: { scope: "private" } }); + }); + + it("bounds detailed issues while retaining accurate totals", async () => { + const result = await core.importBundle({ + traces: Array.from({ length: 80 }, () => null), + }); + expect(result).toMatchObject({ imported: 0, invalid: 80, skipped: 80 }); + expect(result.issues).toHaveLength(50); + }); + + it("rejects malformed top-level collections instead of silently importing nothing", async () => { + await expect( + core.importBundle({ traces: {} as never }), + ).rejects.toMatchObject({ code: "invalid_argument" }); + }); +}); diff --git a/apps/memos-local-plugin/tests/unit/server/http.test.ts b/apps/memos-local-plugin/tests/unit/server/http.test.ts index 8291e01bd..c7072e7c3 100644 --- a/apps/memos-local-plugin/tests/unit/server/http.test.ts +++ b/apps/memos-local-plugin/tests/unit/server/http.test.ts @@ -668,6 +668,25 @@ describe("HTTP server — REST routes", () => { expect(body.imported).toBe(0); }); + it("forwards preview and explicit import ownership choices", async () => { + const r = await fetch(`${handle.url}/api/v1/import?dryRun=true&ownership=target&targetProfileId=work`, { + method: "POST", headers: { "content-type": "application/json" }, + body: JSON.stringify({ version: 1, traces: [] }), + }); + expect(r.status).toBe(200); + expect(core.importBundle).toHaveBeenCalledWith({ version: 1, traces: [] }, { + dryRun: true, ownership: "target", targetProfileId: "work", + }); + }); + + it("rejects invalid import options before calling the core", async () => { + const r = await fetch(`${handle.url}/api/v1/import?ownership=public`, { + method: "POST", headers: { "content-type": "application/json" }, body: "{}", + }); + expect(r.status).toBe(400); + expect(core.importBundle).not.toHaveBeenCalled(); + }); + it("GET /api/v1/embeddings/maintenance returns vector health", async () => { const r = await fetch(`${handle.url}/api/v1/embeddings/maintenance`); expect(r.status).toBe(200); From 79676eec60cac729d5dbdf605ef9b8a348b9abf6 Mon Sep 17 00:00:00 2001 From: Wenqiang Wei <46308778+endxxxx@users.noreply.github.com> Date: Tue, 20 Oct 2026 15:23:42 +0800 Subject: [PATCH 21/38] fix(plugin): configure and report local model loading --- .../core/config/defaults.ts | 1 + apps/memos-local-plugin/core/config/schema.ts | 7 + .../core/embedding/providers/local.ts | 200 ++++++++++++++--- .../core/embedding/types.ts | 7 + .../server/routes/models.ts | 13 +- .../tests/unit/embedding/local-abort.test.ts | 1 + .../tests/unit/embedding/local-config.test.ts | 207 ++++++++++++++++++ .../tests/unit/pipeline/memory-core.test.ts | 122 ++++++----- .../tests/unit/server/models.test.ts | 6 + 9 files changed, 477 insertions(+), 87 deletions(-) create mode 100644 apps/memos-local-plugin/tests/unit/embedding/local-config.test.ts diff --git a/apps/memos-local-plugin/core/config/defaults.ts b/apps/memos-local-plugin/core/config/defaults.ts index b09307c2a..093e06035 100644 --- a/apps/memos-local-plugin/core/config/defaults.ts +++ b/apps/memos-local-plugin/core/config/defaults.ts @@ -36,6 +36,7 @@ export const DEFAULT_CONFIG: ResolvedConfig = { provider: "local", endpoint: "", model: "Xenova/all-MiniLM-L6-v2", + local: { remoteHost: "", modelPath: "", cacheDir: "", offline: false, loadTimeoutMs: 120_000 }, apiKey: "", providerIgnore: [], providerOrder: [], diff --git a/apps/memos-local-plugin/core/config/schema.ts b/apps/memos-local-plugin/core/config/schema.ts index a5d394b49..49c6ad6e1 100644 --- a/apps/memos-local-plugin/core/config/schema.ts +++ b/apps/memos-local-plugin/core/config/schema.ts @@ -43,6 +43,13 @@ const EmbeddingSchema = Type.Object({ ], { default: "local" }), endpoint: StringWithDefault(""), model: StringWithDefault("Xenova/all-MiniLM-L6-v2"), + local: Type.Optional(Type.Object({ + remoteHost: StringWithDefault(""), + modelPath: StringWithDefault(""), + cacheDir: StringWithDefault(""), + offline: Bool(false), + loadTimeoutMs: NumberInRange(120_000, 1, 3_600_000), + }, { default: {} })), apiKey: StringWithDefault(""), /** OpenRouter provider routing — providers to skip. */ providerIgnore: Type.Optional(Type.Array(Type.String(), { default: [] })), diff --git a/apps/memos-local-plugin/core/embedding/providers/local.ts b/apps/memos-local-plugin/core/embedding/providers/local.ts index 01c00d7c3..2b8d31e03 100644 --- a/apps/memos-local-plugin/core/embedding/providers/local.ts +++ b/apps/memos-local-plugin/core/embedding/providers/local.ts @@ -10,7 +10,11 @@ * don't normalize again on top of that. */ +import { homedir } from "node:os"; +import { join, resolve } from "node:path"; +import { MemosError } from "../../../agent-contract/errors.js"; import type { + EmbeddingConfig, EmbedRole, EmbeddingProvider, EmbeddingProviderName, @@ -18,10 +22,16 @@ import type { } from "../types.js"; // eslint-disable-next-line @typescript-eslint/no-explicit-any -type Extractor = (text: string, options?: Record) => Promise; +type Extractor = ( + text: string, + options?: Record, +) => Promise; let extractorPromise: Promise | null = null; -let currentModel: string | null = null; +let currentKey: string | null = null; +// Transformers has a process-wide env. Keep our differently configured loads +// exclusive until pipeline creation has finished, including background warmup. +let loadQueue: Promise = Promise.resolve(); function abortReason(signal: AbortSignal): unknown { return signal.reason ?? new DOMException("Aborted", "AbortError"); @@ -36,7 +46,10 @@ function abortReason(signal: AbortSignal): unknown { * cache for the next request. Attaching both promise handlers also prevents a * late native failure from becoming an unhandled rejection. */ -function awaitWithAbort(promise: Promise, signal?: AbortSignal): Promise { +function awaitWithAbort( + promise: Promise, + signal?: AbortSignal, +): Promise { if (!signal) return promise; if (signal.aborted) return Promise.reject(abortReason(signal)); @@ -59,35 +72,159 @@ function awaitWithAbort(promise: Promise, signal?: AbortSignal): Promise { - if (extractorPromise && currentModel === model) return extractorPromise; - if (extractorPromise && currentModel && currentModel !== model) { - log.warn("model.swap", { from: currentModel, to: model }); - extractorPromise = null; +function localPath(value?: string): string | undefined { + if (!value?.trim()) return undefined; + const path = value.trim(); + return resolve( + path === "~" + ? homedir() + : path.startsWith("~/") + ? join(homedir(), path.slice(2)) + : path, + ); +} + +function localSettings(config: EmbeddingConfig) { + let remoteHost = + config.local?.remoteHost?.trim() || + process.env.HF_ENDPOINT?.trim() || + undefined; + if (remoteHost) { + try { + const url = new URL(remoteHost); + if ( + !["https:", "http:"].includes(url.protocol) || + url.username || + url.password || + url.search || + url.hash + ) + throw new Error(); + remoteHost = url.href.endsWith("/") ? url.href : `${url.href}/`; + } catch { + throw new MemosError( + "config_invalid", + "Local model remoteHost/HF_ENDPOINT must be an HTTP(S) base URL without credentials, query or fragment.", + ); + } } - log.info("loading", { model }); + return { + remoteHost, + modelPath: localPath(config.local?.modelPath), + cacheDir: + localPath(config.local?.cacheDir) ?? + join(homedir(), ".cache", "memos", "models"), + offline: config.local?.offline === true, + }; +} + +function ensureExtractor( + config: EmbeddingConfig, + log: ProviderCallCtx["log"], +): Promise { + const { model } = config; + const settings = localSettings(config); + const key = JSON.stringify([model, settings]); + if (extractorPromise && currentKey === key) return extractorPromise; + log.info("loading", { model, offline: settings.offline }); const t0 = Date.now(); - extractorPromise = (async () => { - // Dynamic import keeps the heavy dep out of the hot path for tests that - // don't need it. + const previous = loadQueue; + const pending = previous.then(async () => { const mod = await import("@huggingface/transformers"); const pipeline = (mod as unknown as { pipeline: PipelineFn }).pipeline; - const ext = (await pipeline("feature-extraction", model, { - dtype: "q8", - device: "cpu", - })) as unknown as Extractor; - log.info("ready", { model, durationMs: Date.now() - t0 }); - return ext; - })().catch((err) => { - extractorPromise = null; + const env = mod.env; + const saved = { + remoteHost: env.remoteHost, + localModelPath: env.localModelPath, + cacheDir: env.cacheDir, + allowRemoteModels: env.allowRemoteModels, + }; + if (settings.remoteHost) env.remoteHost = settings.remoteHost; + if (settings.modelPath) env.localModelPath = settings.modelPath; + if (settings.cacheDir) env.cacheDir = settings.cacheDir; + env.allowRemoteModels = !settings.offline; + const progressByFile = new Map(); + try { + const ext = (await pipeline("feature-extraction", model, { + dtype: "q8", + device: "cpu", + local_files_only: settings.offline, + progress_callback: (event: { + status?: string; + file?: string; + progress?: number; + }) => { + if ( + event.status !== "progress" || + typeof event.progress !== "number" || + !Number.isFinite(event.progress) + ) + return; + const file = event.file ?? "model"; + const progress = Math.max( + 0, + Math.min(100, Math.floor(event.progress)), + ); + if ( + progressByFile.get(file) === progress || + (progress < (progressByFile.get(file) ?? -10) + 10 && + progress !== 100) + ) + return; + progressByFile.set(file, progress); + log.info("download.progress", { model, file, progress }); + }, + })) as unknown as Extractor; + log.info("ready", { model, durationMs: Date.now() - t0 }); + return ext; + } finally { + Object.assign(env, saved); + } + }); + const observed = pending.catch((err) => { + if (extractorPromise === observed) { + extractorPromise = null; + currentKey = null; + } log.error("load_failed", { model, err: { name: (err as Error).name, message: (err as Error).message }, }); throw err; }); - currentModel = model; - return extractorPromise; + loadQueue = observed.then( + () => undefined, + () => undefined, + ); + currentKey = key; + extractorPromise = observed; + return observed; +} + +async function waitForModel( + load: Promise, + timeoutMs: number, +): Promise { + let timer: ReturnType | undefined; + try { + return await Promise.race([ + load, + new Promise((_, reject) => { + timer = setTimeout( + () => + reject( + new MemosError( + "embedding_unavailable", + `Local model loading exceeded ${timeoutMs} ms. Check download progress, configure a mirror or local model directory, then retry. Background loading may still complete.`, + ), + ), + timeoutMs, + ); + }), + ]); + } finally { + if (timer) clearTimeout(timer); + } } /** @@ -104,11 +241,21 @@ type PipelineFn = ( export class LocalEmbeddingProvider implements EmbeddingProvider { readonly name: EmbeddingProviderName = "local"; - async embed(texts: string[], _role: EmbedRole, ctx: ProviderCallCtx): Promise { + async embed( + texts: string[], + _role: EmbedRole, + ctx: ProviderCallCtx, + ): Promise { const { config, log } = ctx; // Avoid starting a costly lazy model load for an already-expired request. if (ctx.signal?.aborted) throw abortReason(ctx.signal); - const ext = await awaitWithAbort(ensureExtractor(config.model, log), ctx.signal); + const ext = await awaitWithAbort( + waitForModel( + ensureExtractor(config, log), + config.local?.loadTimeoutMs ?? 120_000, + ), + ctx.signal, + ); const out: number[][] = []; for (let i = 0; i < texts.length; i++) { if (ctx.signal?.aborted) throw abortReason(ctx.signal); @@ -128,12 +275,13 @@ export class LocalEmbeddingProvider implements EmbeddingProvider { async close(): Promise { // The transformers pipeline doesn't expose a .close(); GC handles it. extractorPromise = null; - currentModel = null; + currentKey = null; } } // Test hook — tests can reset the cached extractor without touching internals. export function __resetLocalExtractorForTests(): void { extractorPromise = null; - currentModel = null; + currentKey = null; + loadQueue = Promise.resolve(); } diff --git a/apps/memos-local-plugin/core/embedding/types.ts b/apps/memos-local-plugin/core/embedding/types.ts index 9e190ea58..c27b7b7f6 100644 --- a/apps/memos-local-plugin/core/embedding/types.ts +++ b/apps/memos-local-plugin/core/embedding/types.ts @@ -27,6 +27,13 @@ export interface EmbeddingConfig { provider: EmbeddingProviderName; endpoint?: string; model: string; + local?: { + remoteHost?: string; + modelPath?: string; + cacheDir?: string; + offline?: boolean; + loadTimeoutMs?: number; + }; dimensions: number; apiKey?: string; /** OpenRouter provider routing — providers to skip. */ diff --git a/apps/memos-local-plugin/server/routes/models.ts b/apps/memos-local-plugin/server/routes/models.ts index fb186bf1a..620fdc325 100644 --- a/apps/memos-local-plugin/server/routes/models.ts +++ b/apps/memos-local-plugin/server/routes/models.ts @@ -20,6 +20,7 @@ * The test runs with values from the request body only. */ import { createEmbedder, type Embedder } from "../../core/embedding/index.js"; +import type { EmbeddingConfig } from "../../core/embedding/types.js"; import type { ServerDeps } from "../types.js"; import { parseJson, writeError, type Routes } from "./registry.js"; @@ -29,6 +30,7 @@ interface TestRequest { endpoint?: string; model?: string; apiKey?: string; + local?: EmbeddingConfig["local"]; } export function registerModelsRoutes(routes: Routes, deps: ServerDeps): void { @@ -157,12 +159,13 @@ async function resolveSecrets( const DEFAULT_LOCAL_EMBEDDING_MODEL = "Xenova/all-MiniLM-L6-v2"; type LocalProbeEmbedder = Pick; -type LocalProbeEmbedderFactory = (model: string) => LocalProbeEmbedder; +type LocalProbeEmbedderFactory = (model: string, local?: EmbeddingConfig["local"]) => LocalProbeEmbedder; -function createLocalProbeEmbedder(model: string): LocalProbeEmbedder { +function createLocalProbeEmbedder(model: string, local?: EmbeddingConfig["local"]): LocalProbeEmbedder { return createEmbedder({ provider: "local", model, + local, dimensions: 384, openRouter: false, cache: { enabled: false, maxItems: 0 }, @@ -176,10 +179,12 @@ function createLocalProbeEmbedder(model: string): LocalProbeEmbedder { export async function probeLocalEmbedding( model: string, create: LocalProbeEmbedderFactory = createLocalProbeEmbedder, + local?: EmbeddingConfig["local"], ): Promise { const resolvedModel = model.trim() || DEFAULT_LOCAL_EMBEDDING_MODEL; try { - const vector = await create(resolvedModel).embedOne("ping"); + const embedder = local === undefined ? create(resolvedModel) : create(resolvedModel, local); + const vector = await embedder.embedOne("ping"); if (vector.length === 0) throw new Error("no embedding vector returned"); return vector.length; } catch (err) { @@ -281,7 +286,7 @@ async function probeEmbedding(req: TestRequest): Promise { return first.length; } case "local": - return probeLocalEmbedding(model); + return probeLocalEmbedding(model, undefined, req.local); default: throw new Error(`unsupported embedding provider: ${provider}`); } diff --git a/apps/memos-local-plugin/tests/unit/embedding/local-abort.test.ts b/apps/memos-local-plugin/tests/unit/embedding/local-abort.test.ts index ad9d90fba..ceeb45d14 100644 --- a/apps/memos-local-plugin/tests/unit/embedding/local-abort.test.ts +++ b/apps/memos-local-plugin/tests/unit/embedding/local-abort.test.ts @@ -6,6 +6,7 @@ const { pipelineMock } = vi.hoisted(() => ({ vi.mock("@huggingface/transformers", () => ({ pipeline: pipelineMock, + env: { remoteHost: "https://huggingface.co/", localModelPath: "/models", cacheDir: "/cache", allowRemoteModels: true }, })); import { diff --git a/apps/memos-local-plugin/tests/unit/embedding/local-config.test.ts b/apps/memos-local-plugin/tests/unit/embedding/local-config.test.ts new file mode 100644 index 000000000..23da461c2 --- /dev/null +++ b/apps/memos-local-plugin/tests/unit/embedding/local-config.test.ts @@ -0,0 +1,207 @@ +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import type { ProviderCallCtx } from "../../../core/embedding/types.js"; +import { homedir } from "node:os"; +import { join } from "node:path"; + +const { pipeline, env } = vi.hoisted(() => ({ + pipeline: vi.fn(), + env: { + remoteHost: "https://huggingface.co/", + localModelPath: "/original/models", + cacheDir: "/original/cache", + allowRemoteModels: true, + }, +})); +vi.mock("@huggingface/transformers", () => ({ pipeline, env })); +import { + LocalEmbeddingProvider, + __resetLocalExtractorForTests, +} from "../../../core/embedding/providers/local.js"; + +const extractor = async () => ({ data: new Float32Array([1, 0]) }); +function ctx(local: Record = {}): ProviderCallCtx { + return { + config: { + provider: "local", + model: "test/model", + dimensions: 2, + local, + openRouter: false, + cache: { enabled: false, maxItems: 0 }, + }, + log: { + trace: vi.fn(), + debug: vi.fn(), + info: vi.fn(), + warn: vi.fn(), + error: vi.fn(), + }, + }; +} + +describe("local model source and load status", () => { + beforeEach(() => { + __resetLocalExtractorForTests(); + pipeline.mockReset().mockResolvedValue(extractor); + Object.assign(env, { + remoteHost: "https://huggingface.co/", + localModelPath: "/original/models", + cacheDir: "/original/cache", + allowRemoteModels: true, + }); + vi.stubEnv("HF_ENDPOINT", ""); + }); + afterEach(() => { + vi.unstubAllEnvs(); + vi.useRealTimers(); + }); + + it("keeps the default model cache outside installed package files", async () => { + pipeline.mockImplementation(async () => { + expect(env.cacheDir).toBe(join(homedir(), ".cache", "memos", "models")); + return extractor; + }); + await new LocalEmbeddingProvider().embed(["test"], "query", ctx()); + }); + + it("uses HF_ENDPOINT but lets explicit local configuration take precedence", async () => { + vi.stubEnv("HF_ENDPOINT", "https://env-mirror.example/"); + const observed: string[] = []; + pipeline.mockImplementation(async () => { + observed.push(env.remoteHost); + return extractor; + }); + const provider = new LocalEmbeddingProvider(); + await provider.embed(["test"], "query", ctx()); + await provider.embed( + ["test"], + "query", + ctx({ remoteHost: "https://config-mirror.example" }), + ); + expect(observed).toEqual([ + "https://env-mirror.example/", + "https://config-mirror.example/", + ]); + expect(env.remoteHost).toBe("https://huggingface.co/"); + }); + + it("applies offline directories before loading and restores the shared environment", async () => { + pipeline.mockImplementation(async (_task, _model, options) => { + expect(env).toMatchObject({ + localModelPath: "/models", + cacheDir: "/cache", + allowRemoteModels: false, + }); + expect(options).toMatchObject({ local_files_only: true }); + return extractor; + }); + await new LocalEmbeddingProvider().embed( + ["test"], + "query", + ctx({ modelPath: "/models", cacheDir: "/cache", offline: true }), + ); + expect(env).toMatchObject({ + localModelPath: "/original/models", + cacheDir: "/original/cache", + allowRemoteModels: true, + }); + }); + + it("restores environment after a failure and permits a later retry", async () => { + pipeline + .mockRejectedValueOnce(new Error("synthetic failure")) + .mockResolvedValue(extractor); + const provider = new LocalEmbeddingProvider(); + await expect( + provider.embed( + ["test"], + "query", + ctx({ remoteHost: "https://mirror.example" }), + ), + ).rejects.toThrow("synthetic failure"); + expect(env.remoteHost).toBe("https://huggingface.co/"); + await expect( + provider.embed( + ["test"], + "query", + ctx({ remoteHost: "https://mirror.example" }), + ), + ).resolves.toEqual([[1, 0]]); + expect(pipeline).toHaveBeenCalledTimes(2); + }); + + it("serializes loads with different sources so their global settings do not overlap", async () => { + let finish!: (value: typeof extractor) => void; + const first = new Promise((resolve) => { + finish = resolve; + }); + const sources: string[] = []; + pipeline.mockImplementation(async () => { + sources.push(env.remoteHost); + return sources.length === 1 ? first : extractor; + }); + const provider = new LocalEmbeddingProvider(); + const a = provider.embed( + ["a"], + "query", + ctx({ remoteHost: "https://a.example/" }), + ); + await vi.waitFor(() => expect(pipeline).toHaveBeenCalledTimes(1)); + const b = provider.embed( + ["b"], + "query", + ctx({ remoteHost: "https://b.example/" }), + ); + await Promise.resolve(); + expect(pipeline).toHaveBeenCalledTimes(1); + finish(extractor); + await Promise.all([a, b]); + expect(sources).toEqual(["https://a.example/", "https://b.example/"]); + expect(env.remoteHost).toBe("https://huggingface.co/"); + }); + + it("reports file download progress", async () => { + const context = ctx(); + pipeline.mockImplementation(async (_task, _model, options) => { + options.progress_callback({ + status: "progress", + file: "onnx/model_quantized.onnx", + progress: 50, + }); + return extractor; + }); + await new LocalEmbeddingProvider().embed(["test"], "query", context); + expect(context.log.info).toHaveBeenCalledWith( + "download.progress", + expect.objectContaining({ + progress: 50, + file: "onnx/model_quantized.onnx", + }), + ); + }); + + it("bounds the initial wait while allowing a slow shared model load to warm up", async () => { + vi.useFakeTimers(); + let finish!: (value: typeof extractor) => void; + pipeline.mockReturnValue( + new Promise((resolve) => { + finish = resolve; + }), + ); + const provider = new LocalEmbeddingProvider(); + const pending = provider.embed( + ["test"], + "query", + ctx({ loadTimeoutMs: 50 }), + ); + const failure = expect(pending).rejects.toMatchObject({ + code: "embedding_unavailable", + }); + await vi.advanceTimersByTimeAsync(51); + await failure; + finish(extractor); + await expect( + provider.embed(["test"], "query", ctx({ loadTimeoutMs: 50 })), + ).resolves.toEqual([[1, 0]]); + }); +}); diff --git a/apps/memos-local-plugin/tests/unit/pipeline/memory-core.test.ts b/apps/memos-local-plugin/tests/unit/pipeline/memory-core.test.ts index 2759ae5bd..39241cf40 100644 --- a/apps/memos-local-plugin/tests/unit/pipeline/memory-core.test.ts +++ b/apps/memos-local-plugin/tests/unit/pipeline/memory-core.test.ts @@ -7,6 +7,7 @@ */ import net from "node:net"; +import * as embeddingModule from "../../../core/embedding/index.js"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; @@ -1622,64 +1623,71 @@ describe("bootstrapMemoryCore", () => { }); it("persists lightweight summarizer model status for Hermes overview", async () => { - home = await makeTmpHome({ - agent: "hermes", - configYaml: ` -llm: - provider: host - model: hermes-summary-test -algorithm: - lightweightMemory: - enabled: true -`, - }); - const bridge: HostLlmBridge = { - id: "test-host-llm", - async complete() { - return { - text: JSON.stringify({ summary: "Hermes remembered the overview status fact" }), - model: "hermes-summary-test", - durationMs: 1, - }; - }, - }; - core = await bootstrapMemoryCore({ - agent: "hermes", - home: home.home, - config: home.config, - pkgVersion: "bootstrap-test", - hostLlmBridge: bridge, - now: () => 1_700_000_000_000, - }); - await core.init(); + // This test verifies summarizer status, without downloading embedding models. + const embeddingFactory = vi.spyOn(embeddingModule, "createEmbedder") + .mockReturnValue(fakeEmbedder({ dimensions: TEST_EMBED_DIMENSIONS })); + try { + home = await makeTmpHome({ + agent: "hermes", + configYaml: ` + llm: + provider: host + model: hermes-summary-test + algorithm: + lightweightMemory: + enabled: true + `, + }); + const bridge: HostLlmBridge = { + id: "test-host-llm", + async complete() { + return { + text: JSON.stringify({ summary: "Hermes remembered the overview status fact" }), + model: "hermes-summary-test", + durationMs: 1, + }; + }, + }; + core = await bootstrapMemoryCore({ + agent: "hermes", + home: home.home, + config: home.config, + pkgVersion: "bootstrap-test", + hostLlmBridge: bridge, + now: () => 1_700_000_000_000, + }); + await core.init(); - const start = await core.onTurnStart({ - agent: "hermes", - sessionId: "hermes-lightweight-status", - userText: "请记住 Hermes 摘要模型状态应该显示已调用", - ts: 1_700_000_000_000, - }); - await core.onTurnEnd({ - agent: "hermes", - sessionId: "hermes-lightweight-status", - episodeId: start.query.episodeId!, - agentText: "已记住。", - toolCalls: [], - ts: 1_700_000_000_100, - }); - - const logs = await core.listApiLogs({ toolName: "system_model_status", limit: 10 }); - const llmRows = logs.logs - .map((row) => JSON.parse(row.outputJson) as { role?: string; status?: string; op?: string }) - .filter((row) => row.role === "llm"); - expect(llmRows).toEqual( - expect.arrayContaining([ - expect.objectContaining({ - status: "ok", - op: "capture.summarize", - }), - ]), - ); + const start = await core.onTurnStart({ + agent: "hermes", + sessionId: "hermes-lightweight-status", + userText: "请记住 Hermes 摘要模型状态应该显示已调用", + ts: 1_700_000_000_000, + }); + await core.onTurnEnd({ + agent: "hermes", + sessionId: "hermes-lightweight-status", + episodeId: start.query.episodeId!, + agentText: "已记住。", + toolCalls: [], + ts: 1_700_000_000_100, + }); + + const logs = await core.listApiLogs({ toolName: "system_model_status", limit: 10 }); + const llmRows = logs.logs + .map((row) => JSON.parse(row.outputJson) as { role?: string; status?: string; op?: string }) + .filter((row) => row.role === "llm"); + expect(llmRows).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + status: "ok", + op: "capture.summarize", + }), + ]), + ); + } finally { + embeddingFactory.mockRestore(); + } }); it("init() recovers orphaned open episodes left behind by a previous crash", async () => { diff --git a/apps/memos-local-plugin/tests/unit/server/models.test.ts b/apps/memos-local-plugin/tests/unit/server/models.test.ts index 43e292050..18cfef5cf 100644 --- a/apps/memos-local-plugin/tests/unit/server/models.test.ts +++ b/apps/memos-local-plugin/tests/unit/server/models.test.ts @@ -3,6 +3,12 @@ import { describe, expect, it, vi } from "vitest"; import { probeLocalEmbedding } from "../../../server/routes/models.js"; describe("local embedding model probe", () => { + it("tests unsaved local model source and offline settings", async () => { + const create = vi.fn(() => ({ embedOne: vi.fn(async () => Float32Array.from([1, 0])) })); + const local = { remoteHost: "https://mirror.example/", modelPath: "/models", offline: true }; + await expect(probeLocalEmbedding("test/model", create, local)).resolves.toBe(2); + expect(create).toHaveBeenCalledWith("test/model", local); + }); it("loads the default MiniLM model and verifies a real vector", async () => { const embedOne = vi.fn(async () => Float32Array.from([0.1, 0.2, 0.3])); const create = vi.fn(() => ({ embedOne })); From 559b62c19433edce17f9e7634fef782b14a4bcb1 Mon Sep 17 00:00:00 2001 From: Wenqiang Wei <46308778+endxxxx@users.noreply.github.com> Date: Tue, 20 Oct 2026 15:23:42 +0800 Subject: [PATCH 22/38] feat(plugin): expose import previews and local model settings --- apps/memos-local-plugin/README.md | 50 ++++++++++++++++ .../viewer/src/stores/i18n.ts | 36 +++++++++++- .../viewer/src/views/ImportView.tsx | 57 ++++++++++++++++--- .../viewer/src/views/SettingsView.tsx | 33 +++++++++-- 4 files changed, 162 insertions(+), 14 deletions(-) diff --git a/apps/memos-local-plugin/README.md b/apps/memos-local-plugin/README.md index 9b2939490..92f3317eb 100644 --- a/apps/memos-local-plugin/README.md +++ b/apps/memos-local-plugin/README.md @@ -261,6 +261,56 @@ The runtime/config location is resolved in the following priority order: 4. **`DSH_HOME`** (DSH only) — defaults the DSH memory root to `$DSH_HOME/memos-plugin/` 5. **Default path** — `~/.hermes/memos-plugin/`, `~/.openclaw/memos-plugin/`, or `~/.dsh/memos-plugin/` based on the agent +### Local embedding model sources + +For `embedding.provider: local`, the Viewer Settings page exposes the same +options as `config.yaml`: + +```yaml +embedding: + provider: local + model: Xenova/all-MiniLM-L6-v2 + local: + remoteHost: "" # Optional HTTP(S) mirror base URL + modelPath: "" # Optional local model root containing / files + cacheDir: "" # Empty: ~/.cache/memos/models, outside installed packages + offline: false # true: load local/cache files only, without downloads + loadTimeoutMs: 120000 +``` + +`local.remoteHost` takes precedence over `HF_ENDPOINT`; leaving both empty uses +Hugging Face. Use absolute directory paths (a leading `~/` is also supported). +For offline use, place the model's config, tokenizer and quantized ONNX files +under `//`, or point `cacheDir` to an existing Transformers.js +cache. Changing the model/source settings causes a fresh pipeline load. + +The Settings **Test** button uses the form's unsaved local settings and shows a +loading notice. Logs report `loading`, per-file `download.progress`, `ready`, +and `load_failed`. The load timeout bounds the caller's wait; Transformers +loading can continue in the background and warm the next request. + +### Bundle import preview and ownership + +Choosing a JSON bundle in the Viewer previews it without writing records. +Choose either preserving original ownership (default) or importing into the +active agent's current/named profile. Sharing scopes are preserved. Preview +shows how many candidate rows would be visible to the active profile. +Existing IDs are skipped, including on a target-profile import; this does not +change ownership of records already stored. + +`POST /api/v1/import` accepts the same JSON or multipart body as before, with +optional query parameters `dryRun=true`, `ownership=preserve|target` and +`targetProfileId` (only with `ownership=target`). The response retains +`imported` and `skipped`, adding `duplicates`, `invalid`, `failed`, `visible`, +`hidden`, `dryRun` and up to 50 row diagnostics (`kind`, zero-based `index`, +`field`, `code`, `message`). Timestamps and integer IDs such as `turnId` must +be safe integers; invalid values are rejected rather than rounded. + +Preview counts are estimates: database write failures can only be reported +on the real import. A rejected trace rolls back its synthetic session and +episode. Use **Repair embeddings** after import to enable semantic retrieval +for imported rows; JSON bundles do not contain embedding vectors. + ### Docker Deployment When running the daemon in a Docker container, you must explicitly specify the config location if it differs from the default path. There are three ways to do this: diff --git a/apps/memos-local-plugin/viewer/src/stores/i18n.ts b/apps/memos-local-plugin/viewer/src/stores/i18n.ts index 0833819c5..cf5564050 100644 --- a/apps/memos-local-plugin/viewer/src/stores/i18n.ts +++ b/apps/memos-local-plugin/viewer/src/stores/i18n.ts @@ -776,9 +776,25 @@ const en = { "import.export.desc": "Save every memory, experience, environment knowledge entry and skill to a portable JSON bundle. Safe to share with other local installs.", "import.export.btn": "Export JSON bundle", + "import.preview": "Preview import", + "import.confirm": "Import valid rows", + "import.ownership": "Memory ownership", + "import.ownership.preserve": "Preserve original ownership", + "import.ownership.target": "Move to a target profile", + "import.targetProfile": "Target profile", + "import.targetProfile.hint": "Leave empty to use the active profile", + "import.visibility.hint": "Preview makes no writes. Visibility is calculated for the active profile. Private memories remain private.", + "import.preview.done": "Preview: {imported} candidates; {duplicates} duplicates, {invalid} invalid, {failed} failed. Visible here: {visible}; hidden: {hidden}.", + "import.result.done": "Imported {imported}; duplicates {duplicates}, invalid {invalid}, failed {failed}. Visible here: {visible}; hidden: {hidden}.", + "settings.embedding.remoteHost": "Model mirror URL (empty uses HF_ENDPOINT)", + "settings.embedding.modelPath": "Local model directory", + "settings.embedding.cacheDir": "Model cache directory", + "settings.embedding.offline": "Use local files only", + "settings.embedding.loadTimeout": "Model loading timeout (seconds)", + "settings.embedding.loading": "Loading the local model. First use may download model files; progress is available in Logs. A request timeout can leave background warmup running.", "import.import.title": "Import a bundle", "import.import.desc": - "Restore memories, experiences, environment knowledge and skills from a JSON bundle. Your existing data is preserved; imported rows are added alongside with new ids.", + "Restore memories, experiences, environment knowledge and skills from a JSON bundle. Existing ids are preserved; duplicates are skipped. Preview ownership and visibility before importing.", "import.import.btn": "Choose JSON bundle…", "import.migrate.title": "Migrate from legacy plugin (memos-local-openclaw / memos-local-hermes)", "import.migrate.desc": @@ -1651,9 +1667,25 @@ const zh: Record = { "import.export.title": "导出当前数据库", "import.export.desc": "把记忆、经验、环境认知和技能全部导成 JSON 包,可分享给其他本机实例。", "import.export.btn": "导出 JSON 包", + "import.preview": "预览导入", + "import.confirm": "导入有效记录", + "import.ownership": "记忆归属", + "import.ownership.preserve": "保留原有归属", + "import.ownership.target": "迁移到目标 profile", + "import.targetProfile": "目标 profile", + "import.targetProfile.hint": "留空使用当前 profile", + "import.visibility.hint": "预览不会写入数据。可见性按当前运行的 profile 计算,私有记忆仍保持私有。", + "import.preview.done": "预览:预计可导入 {imported} 条;重复 {duplicates},无效 {invalid},失败 {failed}。当前可见 {visible},不可见 {hidden}。", + "import.result.done": "已导入 {imported} 条;重复 {duplicates},无效 {invalid},失败 {failed}。当前可见 {visible},不可见 {hidden}。", + "settings.embedding.remoteHost": "模型镜像地址(留空使用 HF_ENDPOINT)", + "settings.embedding.modelPath": "本地模型目录", + "settings.embedding.cacheDir": "模型缓存目录", + "settings.embedding.offline": "仅使用本地文件", + "settings.embedding.loadTimeout": "模型加载超时(秒)", + "settings.embedding.loading": "正在加载本地模型,首次使用可能需要下载文件;进度可在日志中查看。请求超时后,后台预热仍可能继续。", "import.import.title": "导入一个包", "import.import.desc": - "从 JSON 包中恢复记忆、经验、环境认知和技能。原有数据保留,导入内容以新 id 追加。", + "从 JSON 包中恢复记忆、经验、环境认知和技能。保留原有 id,跳过重复记录;导入前可预览归属和可见性。", "import.import.btn": "选择 JSON 文件…", "import.migrate.title": "从旧插件迁入(memos-local-openclaw / memos-local-hermes)", "import.migrate.desc": diff --git a/apps/memos-local-plugin/viewer/src/views/ImportView.tsx b/apps/memos-local-plugin/viewer/src/views/ImportView.tsx index 6cac347a9..51effd25e 100644 --- a/apps/memos-local-plugin/viewer/src/views/ImportView.tsx +++ b/apps/memos-local-plugin/viewer/src/views/ImportView.tsx @@ -4,7 +4,7 @@ * - Export: `GET /api/v1/export` returns a JSON bundle of every * trace/policy/world-model/skill. We trigger a browser download. * - Import: POST the file back to `/api/v1/import`. The server - * preserves existing data and assigns fresh ids to imported rows. + * preserves existing ids and skips duplicates. * - Migrate: `POST /api/v1/migrate/legacy/run` — scans the legacy * SQLite file for the **currently running agent** (openclaw or * hermes — the server picks the right path based on its own @@ -20,6 +20,7 @@ import { api } from "../api/client"; import { health } from "../stores/health"; import { t } from "../stores/i18n"; import { Icon } from "../components/Icon"; +import type { MemoryImportResult } from "../../../agent-contract/import"; type NativeImportKind = "hermes" | "openclaw"; @@ -160,24 +161,36 @@ function ExportCard() { function ImportCard() { const [busy, setBusy] = useState(false); + const [file, setFile] = useState(null); + const [ownership, setOwnership] = useState<"preserve" | "target">("preserve"); + const [targetProfileId, setTargetProfileId] = useState(""); + const [preview, setPreview] = useState(null); + const [result, setResult] = useState(null); const [status, setStatus] = useState<{ kind: "ok" | "error"; text: string; } | null>(null); - const run = async (file: File) => { + const resetPreview = () => { setPreview(null); setResult(null); setStatus(null); }; + const run = async (file: File, dryRun: boolean) => { setBusy(true); setStatus(null); try { const form = new FormData(); form.append("bundle", file); - const r = await api.postRaw<{ imported: number; skipped: number }>( - "/api/v1/import", + const query = new URLSearchParams({ ownership, dryRun: String(dryRun) }); + if (ownership === "target" && targetProfileId.trim()) query.set("targetProfileId", targetProfileId.trim()); + const r = await api.postRaw( + `/api/v1/import?${query}`, form, ); + if (dryRun) { setPreview(r); setResult(null); } else { setResult(r); setPreview(null); } setStatus({ - kind: "ok", - text: `Imported ${r.imported} / skipped ${r.skipped}`, + kind: r.invalid || r.failed ? "error" : "ok", + text: t(dryRun ? "import.preview.done" : "import.result.done", { + imported: r.imported, duplicates: r.duplicates, invalid: r.invalid, failed: r.failed, + visible: r.visible, hidden: r.hidden, + }), }); } catch (err) { setStatus({ kind: "error", text: (err as Error).message }); @@ -206,6 +219,22 @@ function ImportCard() { +
+ + {ownership === "target" && } +

{t("import.visibility.hint")}

+ {file &&
+ {file.name} + + +
} +
{status && (
)} - {status?.kind === "ok" && } + {(preview ?? result)?.issues?.length ?
    + {(preview ?? result)!.issues.map(issue =>
  • + {issue.kind}[{issue.index + 1}]{issue.field ? ` · ${issue.field}` : ""}: {issue.message} ({issue.code}) +
  • )} +
: null} + {result && result.imported > 0 && } ); } diff --git a/apps/memos-local-plugin/viewer/src/views/SettingsView.tsx b/apps/memos-local-plugin/viewer/src/views/SettingsView.tsx index d3e62fdd5..43d2efb1a 100644 --- a/apps/memos-local-plugin/viewer/src/views/SettingsView.tsx +++ b/apps/memos-local-plugin/viewer/src/views/SettingsView.tsx @@ -39,6 +39,13 @@ interface ProviderBlock { temperature?: number; maxInputTokens?: number; batchSize?: number; + local?: { + remoteHost?: string; + modelPath?: string; + cacheDir?: string; + offline?: boolean; + loadTimeoutMs?: number; + }; } interface AlgorithmBlock { @@ -408,6 +415,7 @@ function ModelCard({ provider: block.provider, endpoint: block.endpoint, model: block.model, + local: block.local, apiKey: sanitizeApiKey(block.apiKey), }); setResult(r); @@ -472,6 +480,7 @@ function ModelCard({ {localHint}
)} + {isLocal && testing &&
{t("settings.embedding.loading")}
}
onPatch({ model: (e.target as HTMLInputElement).value })} /> - + {!isLocal && onPatch({ endpoint: (e.target as HTMLInputElement).value })} /> - - + } + {!isLocal && onPatch({ apiKey: (e.target as HTMLInputElement).value })} /> - + } + {isLocal && ([ + ["remoteHost", "settings.embedding.remoteHost"], + ["modelPath", "settings.embedding.modelPath"], + ["cacheDir", "settings.embedding.cacheDir"], + ] as const).map(([key, label]) => + onPatch({ local: { ...block.local, [key]: (event.target as HTMLInputElement).value } })} /> + )} + {isLocal && + onPatch({ local: { ...block.local, offline: (event.target as HTMLInputElement).checked } })} /> + } + {isLocal && + onPatch({ local: { ...block.local, loadTimeoutMs: Math.min(3600, Math.max(1, Number((event.target as HTMLInputElement).value) || 120)) * 1000 } })} /> + } {type === "embedding" && ( Date: Tue, 20 Oct 2026 20:32:20 +0800 Subject: [PATCH 23/38] test(plugin): enforce DSH V4 message admission regressions --- .../adapters/deepseek-harness/README.md | 19 + apps/memos-local-plugin/package-lock.json | 196 +++++++++- apps/memos-local-plugin/package.json | 5 +- apps/memos-local-plugin/pnpm-lock.yaml | 339 ++++++++++++------ .../tests/helpers/deepseek-harness-v4.ts | 9 + .../adapters/deepseek-harness-bridge.test.ts | 42 ++- .../deepseek-harness-host-llm.test.ts | 9 + .../adapters/deepseek-harness-runtime.test.ts | 25 ++ 8 files changed, 500 insertions(+), 144 deletions(-) create mode 100644 apps/memos-local-plugin/tests/helpers/deepseek-harness-v4.ts diff --git a/apps/memos-local-plugin/adapters/deepseek-harness/README.md b/apps/memos-local-plugin/adapters/deepseek-harness/README.md index 5c18bc682..dddb5f4b9 100644 --- a/apps/memos-local-plugin/adapters/deepseek-harness/README.md +++ b/apps/memos-local-plugin/adapters/deepseek-harness/README.md @@ -567,6 +567,25 @@ errors and are not fail-open. as untrusted and potentially stale, especially when it contains copied tool output or repository text. +## V4 message-source regression tests + +From `apps/memos-local-plugin`, run: + +```sh +npm ci +npx vitest run tests/unit/adapters/deepseek-harness-{bridge,host-llm,runtime}.test.ts +``` + +These tests use the published `@deepseek-ai/dsh-session-format-v3-to-v4` +`0.2.0-rc.2` codec, without a DSH desktop installation, account, or network +calls during testing. They check real recall and host-LLM messages through +both `assertV4RowAdmission` and `encodeEvent`, including a pre-step inbox +batch and rejection of retired `kind: "plugin"` sources. The codec is a dev +dependency only. Its Cordis peer is satisfied by the development range; +existing DSH brand/protocol peers remain pinned to the older adapter test +stack. This validates V4 attribution, not general compatibility with every +DSH API in the codec's release line. + ## Known limitations 1. **Developer-preview compatibility.** The initial compatibility target is diff --git a/apps/memos-local-plugin/package-lock.json b/apps/memos-local-plugin/package-lock.json index fb4d188f0..dd76f4bdf 100644 --- a/apps/memos-local-plugin/package-lock.json +++ b/apps/memos-local-plugin/package-lock.json @@ -20,13 +20,16 @@ "yaml": "^2.6.0" }, "devDependencies": { - "@deepseek-ai/cordis": "^4.0.1", + "@deepseek-ai/cordis": "~4.0.4", "@deepseek-ai/dsh-agent": "0.1.0-rc.6", + "@deepseek-ai/dsh-brand": "0.1.0-rc.6", "@deepseek-ai/dsh-llm": "0.1.0-rc.6", "@deepseek-ai/dsh-session": "0.1.0-rc.6", + "@deepseek-ai/dsh-session-format-v3-to-v4": "0.2.0-rc.2", "@deepseek-ai/dsh-system-prompt": "0.1.0-rc.6", "@deepseek-ai/dsh-timeout": "0.1.0-rc.6", "@deepseek-ai/dsh-tools": "0.1.0-rc.6", + "@deepseek-ai/dsh-typert-protocol": "0.1.0-rc.6", "@deepseek-ai/schemastery": "^3.18.1", "@preact/preset-vite": "^2.10.5", "@types/better-sqlite3": "^7.6.12", @@ -107,6 +110,7 @@ "integrity": "sha512-CGOfOJqWjg2qW/Mb6zNsDm+u5vFQ8DxXfbM09z69p5Z6+mE1ikP2jUXw+j42Pf1XTYED2Rni5f95npYeuwMDQA==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@babel/code-frame": "^7.29.0", "@babel/generator": "^7.29.0", @@ -412,21 +416,22 @@ } }, "node_modules/@deepseek-ai/cordis": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/@deepseek-ai/cordis/-/cordis-4.0.1.tgz", - "integrity": "sha512-YBdskTU2Po1kru3GgcUWUbkTsPMA9LkSQDAY8rBkFJeajdgcQad3QPJZE26JyK99Xb6HaASvoXg2DSUTeN/0Nw==", + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/@deepseek-ai/cordis/-/cordis-4.0.5.tgz", + "integrity": "sha512-Sktq5axy0owk9PdnivBRNOJjHEVEibCt0+TDDZcv0+UH2KS1M910fX4kn5y45YFsrpZIi1mJf/1s5VzywMUnyg==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { - "@deepseek-ai/cosmokit": "^1.8.2", + "@deepseek-ai/cosmokit": "~1.8.6", "@standard-schema/spec": "^1.1.0" }, "bin": { "cordis": "bin.js" }, "peerDependencies": { - "@deepseek-ai/cordis-plugin-include": "^1.0.6", - "@deepseek-ai/cordis-plugin-loader": "^1.0.2" + "@deepseek-ai/cordis-plugin-include": "~1.0.10", + "@deepseek-ai/cordis-plugin-loader": "~1.0.6" }, "peerDependenciesMeta": { "@deepseek-ai/cordis-plugin-include": { @@ -438,9 +443,9 @@ } }, "node_modules/@deepseek-ai/cosmokit": { - "version": "1.8.2", - "resolved": "https://registry.npmjs.org/@deepseek-ai/cosmokit/-/cosmokit-1.8.2.tgz", - "integrity": "sha512-muBOKtSrUKU5m/xpq8ZXWL6hQ/jgd4PhU2PqH97bcxIiLEJfNwZOGQEx4t/aS/GgxRAR+ra9pMHPMtTHU4sqqA==", + "version": "1.8.6", + "resolved": "https://registry.npmjs.org/@deepseek-ai/cosmokit/-/cosmokit-1.8.6.tgz", + "integrity": "sha512-ZSD/fN52L498LBIOYwjIOlaLv5veY6ZEwI2yzvZUKQtctn0QAPqu8tKdJ+OF5+Tv6NBq1U+wJWH+QI6OGy5EvQ==", "dev": true, "license": "MIT" }, @@ -450,6 +455,7 @@ "integrity": "sha512-vtqq2pWTrzn0dKfj5kREZRpP82AwtGjGx9V1lYnKvF+Uc/a8zyWbSvjDE7V1d3YQAQJzs2cWO31hURWDekDXIA==", "dev": true, "license": "MIT", + "peer": true, "peerDependencies": { "@deepseek-ai/cordis": "^4.0.1", "@deepseek-ai/dsh-invariants": "^0.1.0-rc.6", @@ -517,6 +523,7 @@ "integrity": "sha512-kuFGC8bHlzGTwlRxQhXjf3CYWl8M4NzH+EYIkrW8rri4iMc9W53xrdvkil5No/DUlMm8g1u7GdeiWYFy0TMvtA==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@deepseek-ai/schemastery": "^3.18.1" }, @@ -546,6 +553,7 @@ "integrity": "sha512-8tu8I6VWC7050GAUXWhcEWQw4pakALQc8TlhKr52m7Y4+kIKeNt3FBgP86PaGPBtpK0p5zUPRQNkFpzZbBdxyw==", "dev": true, "license": "MIT", + "peer": true, "peerDependencies": { "@deepseek-ai/cordis": "^4.0.1", "@deepseek-ai/dsh-brand": "^0.1.0-rc.6", @@ -555,12 +563,137 @@ "@deepseek-ai/dsh-typert-protocol": "^0.1.0-rc.6" } }, + "node_modules/@deepseek-ai/dsh-session-format": { + "version": "0.2.0-rc.2", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-session-format/-/dsh-session-format-0.2.0-rc.2.tgz", + "integrity": "sha512-qdWtsJt1cLJbUAMCgzRBZ2LyW+XRJpetnle4N/0X/pkmJ9eOM6Y+QqwRQdcEcI4pWuEbPwuq7/HrnqoanVaiwg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@deepseek-ai/dsh-util-values": "0.2.0-rc.2" + }, + "peerDependencies": { + "@deepseek-ai/cordis": "~4.0.4" + } + }, + "node_modules/@deepseek-ai/dsh-session-format-v0-to-v1": { + "version": "0.2.0-rc.2", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-session-format-v0-to-v1/-/dsh-session-format-v0-to-v1-0.2.0-rc.2.tgz", + "integrity": "sha512-PPcfT7txn82/sZnFNxsuxEEUSSdEfBTkNTuOCaiu5ANDMmxUaxOOW6gXt+zBKndGJZRgCR/u9SoAdKv659FSZQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@deepseek-ai/dsh-session-format": "0.2.0-rc.2", + "@deepseek-ai/dsh-util-values": "0.2.0-rc.2" + }, + "peerDependencies": { + "@deepseek-ai/cordis": "~4.0.4" + } + }, + "node_modules/@deepseek-ai/dsh-session-format-v1-to-v2": { + "version": "0.2.0-rc.2", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-session-format-v1-to-v2/-/dsh-session-format-v1-to-v2-0.2.0-rc.2.tgz", + "integrity": "sha512-PBIsz4OBE0wNnapaD87lz6255em24Kn53BKV4K1AqiNH9OWf1+m29TLXs/ICtZ2xigk6TK5H9q6oOVBBmbZyVw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@deepseek-ai/dsh-llm": "0.2.0-rc.2", + "@deepseek-ai/dsh-session-format": "0.2.0-rc.2", + "@deepseek-ai/dsh-session-format-v0-to-v1": "0.2.0-rc.2", + "@deepseek-ai/dsh-util-values": "0.2.0-rc.2" + }, + "peerDependencies": { + "@deepseek-ai/cordis": "~4.0.4" + } + }, + "node_modules/@deepseek-ai/dsh-session-format-v1-to-v2/node_modules/@deepseek-ai/dsh-brand": { + "version": "0.2.0-rc.2", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-brand/-/dsh-brand-0.2.0-rc.2.tgz", + "integrity": "sha512-A5XlN4tIgP0qObkYFhcZ7Oz/tM2oESEZqLwS0Qq+sM1ivGx6o4AMPgJdfKQlwLzqk0cMLNtAaVBHfiYoElt4lw==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "@deepseek-ai/cordis": "~4.0.4" + } + }, + "node_modules/@deepseek-ai/dsh-session-format-v1-to-v2/node_modules/@deepseek-ai/dsh-llm": { + "version": "0.2.0-rc.2", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-llm/-/dsh-llm-0.2.0-rc.2.tgz", + "integrity": "sha512-6QFrQn/h0iNqCfPpgQidnHtLSpA99A7ZND/uYKaGSd/4BGP8KBhuRd0w63e9s4u+hfW8jc3j29WKcNLIOeUfcA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@deepseek-ai/dsh-brand": "0.2.0-rc.2", + "@deepseek-ai/dsh-timeout": "0.2.0-rc.2", + "@deepseek-ai/dsh-typert-protocol": "0.2.0-rc.2", + "@deepseek-ai/dsh-util-crypto": "0.2.0-rc.2", + "@deepseek-ai/dsh-util-values": "0.2.0-rc.2", + "@deepseek-ai/schemastery": "~3.18.4", + "zod": "^4.4.3" + }, + "peerDependencies": { + "@deepseek-ai/cordis": "~4.0.4" + } + }, + "node_modules/@deepseek-ai/dsh-session-format-v1-to-v2/node_modules/@deepseek-ai/dsh-timeout": { + "version": "0.2.0-rc.2", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-timeout/-/dsh-timeout-0.2.0-rc.2.tgz", + "integrity": "sha512-NDob8b8DJDB/sDPz3P7xhrkxOh1O9FbN1EZRKsxP4fuTfp4hrQU7aekYS5qZENFKoR8dBJMTh/zcEBw4m31glQ==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "@deepseek-ai/cordis": "~4.0.4" + } + }, + "node_modules/@deepseek-ai/dsh-session-format-v1-to-v2/node_modules/@deepseek-ai/dsh-typert-protocol": { + "version": "0.2.0-rc.2", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-typert-protocol/-/dsh-typert-protocol-0.2.0-rc.2.tgz", + "integrity": "sha512-95RvIDcVac2BWdv1IxN6yKlRV+8eEvkofqSxV+d0r8x1kx2EIWEsbdxz6C+coYIm+8e03MiN+rwOt8J7sLfe7Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "@deepseek-ai/dsh-brand": "0.2.0-rc.2" + }, + "peerDependencies": { + "@deepseek-ai/cordis": "~4.0.4" + } + }, + "node_modules/@deepseek-ai/dsh-session-format-v2-to-v3": { + "version": "0.2.0-rc.2", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-session-format-v2-to-v3/-/dsh-session-format-v2-to-v3-0.2.0-rc.2.tgz", + "integrity": "sha512-vrQQ1l3JgPIv/19mhm50FVD40hjro+tAkP3L1PNtGHrbBoYriNWXpR4QDOCQsHdPhg3vpnp9MmARMr8vZzl0Nw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@deepseek-ai/dsh-session-format": "0.2.0-rc.2", + "@deepseek-ai/dsh-session-format-v0-to-v1": "0.2.0-rc.2", + "@deepseek-ai/dsh-session-format-v1-to-v2": "0.2.0-rc.2" + }, + "peerDependencies": { + "@deepseek-ai/cordis": "~4.0.4" + } + }, + "node_modules/@deepseek-ai/dsh-session-format-v3-to-v4": { + "version": "0.2.0-rc.2", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-session-format-v3-to-v4/-/dsh-session-format-v3-to-v4-0.2.0-rc.2.tgz", + "integrity": "sha512-UkiNDdGS8cwJKqjvHs52BKi+3NuKhoziz/l0IrDoDYpSdgDfK8HrrXkvIxOi+QaBUgIxNTQzA6tsI+TAIMDsGQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@deepseek-ai/dsh-session-format": "0.2.0-rc.2", + "@deepseek-ai/dsh-session-format-v2-to-v3": "0.2.0-rc.2" + }, + "peerDependencies": { + "@deepseek-ai/cordis": "~4.0.4" + } + }, "node_modules/@deepseek-ai/dsh-system-prompt": { "version": "0.1.0-rc.6", "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-system-prompt/-/dsh-system-prompt-0.1.0-rc.6.tgz", "integrity": "sha512-E7g+XChh4q4/wX++v56z1pV4SA1Rtz42xkznLPPi9FlXrrzJxwHMOUzBZ9Rz3Y1kLhQ++HJG3ZatmNx3rjFilg==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@deepseek-ai/schemastery": "^3.18.1" }, @@ -577,6 +710,7 @@ "integrity": "sha512-CUean0fAnfsJVszFEip7PsU/S26W+JfDFfsza2dCtlw8n6xlkbHA9Gjxdk2aTwqDGCgXEPkRW7mYkdJ0n6FR7w==", "dev": true, "license": "MIT", + "peer": true, "peerDependencies": { "@deepseek-ai/cordis": "^4.0.1", "@deepseek-ai/dsh-invariants": "^0.1.0-rc.6" @@ -636,14 +770,34 @@ "@deepseek-ai/dsh-system-prompt": "^0.1.0-rc.6" } }, + "node_modules/@deepseek-ai/dsh-util-crypto": { + "version": "0.2.0-rc.2", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-util-crypto/-/dsh-util-crypto-0.2.0-rc.2.tgz", + "integrity": "sha512-5OvvmepY69uXTagUMlnoHqg7euI4ZMifLgfdV8xZO20OslWGGiRCkJbZRyDtcJG9GsXWz9UimfWmUu52zKXJ5w==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "@deepseek-ai/cordis": "~4.0.4" + } + }, + "node_modules/@deepseek-ai/dsh-util-values": { + "version": "0.2.0-rc.2", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-util-values/-/dsh-util-values-0.2.0-rc.2.tgz", + "integrity": "sha512-qgpsbgiZABuE9UvgNaVo9b2HiWwLeU93CTl9PFXqE0jN8ap1ALxzQsLGvr/q2MJuWDYqnFBg60XnqnY8ZxPWEg==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "@deepseek-ai/cordis": "~4.0.4" + } + }, "node_modules/@deepseek-ai/schemastery": { - "version": "3.18.1", - "resolved": "https://registry.npmjs.org/@deepseek-ai/schemastery/-/schemastery-3.18.1.tgz", - "integrity": "sha512-Qn0FCSwCQnpnj6SB31I6i2sIKgKWnkbJM8O0EU91Gv2UsYVvtZTl6IA0sCwk2e2MZf5S8w5hpq9QkeVvK9qwxg==", + "version": "3.18.5", + "resolved": "https://registry.npmjs.org/@deepseek-ai/schemastery/-/schemastery-3.18.5.tgz", + "integrity": "sha512-Mnobvqf9rHsZYv4g5edj5ddxS1oF1kIdSlz0DunUgnY3LWG5F26MqvH3YOOsSaodCgyzJ16OMN9O99/s5Crtdw==", "dev": true, "license": "MIT", "dependencies": { - "@deepseek-ai/cosmokit": "^1.8.2", + "@deepseek-ai/cosmokit": "~1.8.6", "@standard-schema/spec": "^1.1.0" } }, @@ -2467,6 +2621,7 @@ } ], "license": "MIT", + "peer": true, "dependencies": { "baseline-browser-mapping": "^2.10.12", "caniuse-lite": "^1.0.30001782", @@ -3415,6 +3570,7 @@ "resolved": "https://registry.npmjs.org/preact/-/preact-10.29.1.tgz", "integrity": "sha512-gQCLc/vWroE8lIpleXtdJhTFDogTdZG9AjMUpVkDf2iTCNwYNWA+u16dL41TqUDJO4gm2IgrcMv3uTpjd4Pwmg==", "license": "MIT", + "peer": true, "funding": { "type": "opencollective", "url": "https://opencollective.com/preact" @@ -3541,6 +3697,7 @@ "integrity": "sha512-VmtB2rFU/GroZ4oL8+ZqXgSA38O6GR8KSIvWmEFv63pQ0G6KaBH9s07PO8XTXP4vI+3UJUEypOfjkGfmSBBR0w==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@types/estree": "1.0.8" }, @@ -4011,6 +4168,7 @@ "integrity": "sha512-o5a9xKjbtuhY6Bi5S3+HvbRERmouabWbyUcpXXUA1u+GNUKoROi9byOJ8M0nHbHYHkYICiMlqxkg1KkYmm25Sw==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "esbuild": "^0.21.3", "postcss": "^8.4.43", @@ -4646,6 +4804,16 @@ "integrity": "sha512-B58NGBEoc8Y9MWWCQGl/gq9xBCe4IiKM0a2x7GZdQKOW5Exr8S1W24J6OgM1njK8xCRGvAJIL/MxXHf6SkmQKQ==", "dev": true, "license": "MIT" + }, + "node_modules/zod": { + "version": "4.6.7", + "resolved": "https://registry.npmjs.org/zod/-/zod-4.6.7.tgz", + "integrity": "sha512-g8W2D2kU6a8untc053fX1uVBKzM7yqAxW/3zwk83+6RyF2+SKOuV+c0wBDhUwzV1PaGapmZH+rmcUzPf+3CGwg==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } } } } diff --git a/apps/memos-local-plugin/package.json b/apps/memos-local-plugin/package.json index d9d5e3099..25c24b3d7 100644 --- a/apps/memos-local-plugin/package.json +++ b/apps/memos-local-plugin/package.json @@ -135,13 +135,16 @@ } }, "devDependencies": { - "@deepseek-ai/cordis": "^4.0.1", + "@deepseek-ai/cordis": "~4.0.4", "@deepseek-ai/dsh-agent": "0.1.0-rc.6", + "@deepseek-ai/dsh-brand": "0.1.0-rc.6", "@deepseek-ai/dsh-llm": "0.1.0-rc.6", "@deepseek-ai/dsh-session": "0.1.0-rc.6", + "@deepseek-ai/dsh-session-format-v3-to-v4": "0.2.0-rc.2", "@deepseek-ai/dsh-system-prompt": "0.1.0-rc.6", "@deepseek-ai/dsh-timeout": "0.1.0-rc.6", "@deepseek-ai/dsh-tools": "0.1.0-rc.6", + "@deepseek-ai/dsh-typert-protocol": "0.1.0-rc.6", "@deepseek-ai/schemastery": "^3.18.1", "@preact/preset-vite": "^2.10.5", "@types/better-sqlite3": "^7.6.12", diff --git a/apps/memos-local-plugin/pnpm-lock.yaml b/apps/memos-local-plugin/pnpm-lock.yaml index 6e94638a6..659e036df 100644 --- a/apps/memos-local-plugin/pnpm-lock.yaml +++ b/apps/memos-local-plugin/pnpm-lock.yaml @@ -34,26 +34,35 @@ importers: version: 2.8.3 devDependencies: '@deepseek-ai/cordis': - specifier: ^4.0.1 - version: 4.0.1 + specifier: ~4.0.4 + version: 4.0.5 '@deepseek-ai/dsh-agent': specifier: 0.1.0-rc.6 - version: 0.1.0-rc.6(b0514d7a320728b6d8f5a31eb3960e10) + version: 0.1.0-rc.6(6889e29676788162cc6455c880e3b4a2) + '@deepseek-ai/dsh-brand': + specifier: 0.1.0-rc.6 + version: 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) '@deepseek-ai/dsh-llm': specifier: 0.1.0-rc.6 - version: 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))) + version: 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))) '@deepseek-ai/dsh-session': specifier: 0.1.0-rc.6 - version: 0.1.0-rc.6(6fd26f59436a18b115f326d6060415e6) + version: 0.1.0-rc.6(f5e28831e96e72c33b5ea3a797f6fddf) + '@deepseek-ai/dsh-session-format-v3-to-v4': + specifier: 0.2.0-rc.2 + version: 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) '@deepseek-ai/dsh-system-prompt': specifier: 0.1.0-rc.6 - version: 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))(@deepseek-ai/dsh-llm@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))))(@deepseek-ai/dsh-scope@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))) + version: 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-llm@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))))(@deepseek-ai/dsh-scope@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))) '@deepseek-ai/dsh-timeout': specifier: 0.1.0-rc.6 - version: 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)) + version: 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) '@deepseek-ai/dsh-tools': specifier: 0.1.0-rc.6 - version: 0.1.0-rc.6(f8724372086ccc1457fc84e7becee2e0) + version: 0.1.0-rc.6(14b150c73c93dfea9f66b8be648ac0d7) + '@deepseek-ai/dsh-typert-protocol': + specifier: 0.1.0-rc.6 + version: 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) '@deepseek-ai/schemastery': specifier: ^3.18.1 version: 3.18.1 @@ -174,12 +183,12 @@ packages: resolution: {integrity: sha512-LwdZHpScM4Qz8Xw2iKSzS+cfglZzJGvofQICy7W7v4caru4EaAmyUuO6BGrbyQ2mYV11W0U8j5mBhd14dd3B0A==} engines: {node: '>=6.9.0'} - '@deepseek-ai/cordis@4.0.1': - resolution: {integrity: sha512-YBdskTU2Po1kru3GgcUWUbkTsPMA9LkSQDAY8rBkFJeajdgcQad3QPJZE26JyK99Xb6HaASvoXg2DSUTeN/0Nw==} + '@deepseek-ai/cordis@4.0.5': + resolution: {integrity: sha512-Sktq5axy0owk9PdnivBRNOJjHEVEibCt0+TDDZcv0+UH2KS1M910fX4kn5y45YFsrpZIi1mJf/1s5VzywMUnyg==} hasBin: true peerDependencies: - '@deepseek-ai/cordis-plugin-include': ^1.0.6 - '@deepseek-ai/cordis-plugin-loader': ^1.0.2 + '@deepseek-ai/cordis-plugin-include': ~1.0.10 + '@deepseek-ai/cordis-plugin-loader': ~1.0.6 peerDependenciesMeta: '@deepseek-ai/cordis-plugin-include': optional: true @@ -189,6 +198,9 @@ packages: '@deepseek-ai/cosmokit@1.8.2': resolution: {integrity: sha512-muBOKtSrUKU5m/xpq8ZXWL6hQ/jgd4PhU2PqH97bcxIiLEJfNwZOGQEx4t/aS/GgxRAR+ra9pMHPMtTHU4sqqA==} + '@deepseek-ai/cosmokit@1.8.6': + resolution: {integrity: sha512-ZSD/fN52L498LBIOYwjIOlaLv5veY6ZEwI2yzvZUKQtctn0QAPqu8tKdJ+OF5+Tv6NBq1U+wJWH+QI6OGy5EvQ==} + '@deepseek-ai/dsh-agent@0.1.0-rc.6': resolution: {integrity: sha512-vtqq2pWTrzn0dKfj5kREZRpP82AwtGjGx9V1lYnKvF+Uc/a8zyWbSvjDE7V1d3YQAQJzs2cWO31hURWDekDXIA==} peerDependencies: @@ -213,6 +225,11 @@ packages: '@deepseek-ai/cordis': ^4.0.1 '@deepseek-ai/dsh-invariants': ^0.1.0-rc.6 + '@deepseek-ai/dsh-brand@0.2.0-rc.2': + resolution: {integrity: sha512-A5XlN4tIgP0qObkYFhcZ7Oz/tM2oESEZqLwS0Qq+sM1ivGx6o4AMPgJdfKQlwLzqk0cMLNtAaVBHfiYoElt4lw==} + peerDependencies: + '@deepseek-ai/cordis': ~4.0.4 + '@deepseek-ai/dsh-code-runtime@0.1.0-rc.6': resolution: {integrity: sha512-aw8D4IOeMo11A3uxQeE4LFoW3bvaQnVkGFqqtS+lsINDARrOCJHXLUgecoKpys+Lc5erZZ4UQDnymJmL4OCcKA==} peerDependencies: @@ -233,12 +250,42 @@ packages: '@deepseek-ai/dsh-invariants': ^0.1.0-rc.6 '@deepseek-ai/dsh-timeout': ^0.1.0-rc.6 + '@deepseek-ai/dsh-llm@0.2.0-rc.2': + resolution: {integrity: sha512-6QFrQn/h0iNqCfPpgQidnHtLSpA99A7ZND/uYKaGSd/4BGP8KBhuRd0w63e9s4u+hfW8jc3j29WKcNLIOeUfcA==} + peerDependencies: + '@deepseek-ai/cordis': ~4.0.4 + '@deepseek-ai/dsh-scope@0.1.0-rc.6': resolution: {integrity: sha512-UlDLV4syLoJinNg9imhXrSAHrdaTa5Ff8gg46rzjFJGPUOhAk3DZff0hryT5OhrBi0A5Tj92qVpg2pRVvxnUzQ==} peerDependencies: '@deepseek-ai/cordis': ^4.0.1 '@deepseek-ai/dsh-invariants': ^0.1.0-rc.6 + '@deepseek-ai/dsh-session-format-v0-to-v1@0.2.0-rc.2': + resolution: {integrity: sha512-PPcfT7txn82/sZnFNxsuxEEUSSdEfBTkNTuOCaiu5ANDMmxUaxOOW6gXt+zBKndGJZRgCR/u9SoAdKv659FSZQ==} + peerDependencies: + '@deepseek-ai/cordis': ~4.0.4 + + '@deepseek-ai/dsh-session-format-v1-to-v2@0.2.0-rc.2': + resolution: {integrity: sha512-PBIsz4OBE0wNnapaD87lz6255em24Kn53BKV4K1AqiNH9OWf1+m29TLXs/ICtZ2xigk6TK5H9q6oOVBBmbZyVw==} + peerDependencies: + '@deepseek-ai/cordis': ~4.0.4 + + '@deepseek-ai/dsh-session-format-v2-to-v3@0.2.0-rc.2': + resolution: {integrity: sha512-vrQQ1l3JgPIv/19mhm50FVD40hjro+tAkP3L1PNtGHrbBoYriNWXpR4QDOCQsHdPhg3vpnp9MmARMr8vZzl0Nw==} + peerDependencies: + '@deepseek-ai/cordis': ~4.0.4 + + '@deepseek-ai/dsh-session-format-v3-to-v4@0.2.0-rc.2': + resolution: {integrity: sha512-UkiNDdGS8cwJKqjvHs52BKi+3NuKhoziz/l0IrDoDYpSdgDfK8HrrXkvIxOi+QaBUgIxNTQzA6tsI+TAIMDsGQ==} + peerDependencies: + '@deepseek-ai/cordis': ~4.0.4 + + '@deepseek-ai/dsh-session-format@0.2.0-rc.2': + resolution: {integrity: sha512-qdWtsJt1cLJbUAMCgzRBZ2LyW+XRJpetnle4N/0X/pkmJ9eOM6Y+QqwRQdcEcI4pWuEbPwuq7/HrnqoanVaiwg==} + peerDependencies: + '@deepseek-ai/cordis': ~4.0.4 + '@deepseek-ai/dsh-session@0.1.0-rc.6': resolution: {integrity: sha512-8tu8I6VWC7050GAUXWhcEWQw4pakALQc8TlhKr52m7Y4+kIKeNt3FBgP86PaGPBtpK0p5zUPRQNkFpzZbBdxyw==} peerDependencies: @@ -263,6 +310,11 @@ packages: '@deepseek-ai/cordis': ^4.0.1 '@deepseek-ai/dsh-invariants': ^0.1.0-rc.6 + '@deepseek-ai/dsh-timeout@0.2.0-rc.2': + resolution: {integrity: sha512-NDob8b8DJDB/sDPz3P7xhrkxOh1O9FbN1EZRKsxP4fuTfp4hrQU7aekYS5qZENFKoR8dBJMTh/zcEBw4m31glQ==} + peerDependencies: + '@deepseek-ai/cordis': ~4.0.4 + '@deepseek-ai/dsh-tools@0.1.0-rc.6': resolution: {integrity: sha512-Tu08EPK3JyK0iNjH4FGzu/1uADynNSS6SmwOLdfytUN0YNqwNuKFSt2OJUg19famNlTgy992DcHfDu0T+gLXFg==} peerDependencies: @@ -282,6 +334,11 @@ packages: '@deepseek-ai/cordis': ^4.0.1 '@deepseek-ai/dsh-invariants': ^0.1.0-rc.6 + '@deepseek-ai/dsh-typert-protocol@0.2.0-rc.2': + resolution: {integrity: sha512-95RvIDcVac2BWdv1IxN6yKlRV+8eEvkofqSxV+d0r8x1kx2EIWEsbdxz6C+coYIm+8e03MiN+rwOt8J7sLfe7Q==} + peerDependencies: + '@deepseek-ai/cordis': ~4.0.4 + '@deepseek-ai/dsh-user-approval@0.1.0-rc.6': resolution: {integrity: sha512-9rnkSDGOpu2XUeGwbPeTzVUTFWTND1PMPM5L/ZQPptV5yyZlQiNxM2rCC6OdL+ZVerwxEqrRhZIQn/KVtQfKag==} peerDependencies: @@ -294,9 +351,22 @@ packages: '@deepseek-ai/dsh-session': ^0.1.0-rc.6 '@deepseek-ai/dsh-system-prompt': ^0.1.0-rc.6 + '@deepseek-ai/dsh-util-crypto@0.2.0-rc.2': + resolution: {integrity: sha512-5OvvmepY69uXTagUMlnoHqg7euI4ZMifLgfdV8xZO20OslWGGiRCkJbZRyDtcJG9GsXWz9UimfWmUu52zKXJ5w==} + peerDependencies: + '@deepseek-ai/cordis': ~4.0.4 + + '@deepseek-ai/dsh-util-values@0.2.0-rc.2': + resolution: {integrity: sha512-qgpsbgiZABuE9UvgNaVo9b2HiWwLeU93CTl9PFXqE0jN8ap1ALxzQsLGvr/q2MJuWDYqnFBg60XnqnY8ZxPWEg==} + peerDependencies: + '@deepseek-ai/cordis': ~4.0.4 + '@deepseek-ai/schemastery@3.18.1': resolution: {integrity: sha512-Qn0FCSwCQnpnj6SB31I6i2sIKgKWnkbJM8O0EU91Gv2UsYVvtZTl6IA0sCwk2e2MZf5S8w5hpq9QkeVvK9qwxg==} + '@deepseek-ai/schemastery@3.18.5': + resolution: {integrity: sha512-Mnobvqf9rHsZYv4g5edj5ddxS1oF1kIdSlz0DunUgnY3LWG5F26MqvH3YOOsSaodCgyzJ16OMN9O99/s5Crtdw==} + '@emnapi/runtime@1.10.0': resolution: {integrity: sha512-ewvYlk86xUoGI0zQRNq/mC+16R1QeDlKQy21Ki3oSYXNgLb45GV1P6A0M+/s6nyCuNDqe5VpaY84BzXGwVbwFA==} @@ -634,105 +704,89 @@ packages: resolution: {integrity: sha512-excjX8DfsIcJ10x1Kzr4RcWe1edC9PquDRRPx3YVCvQv+U5p7Yin2s32ftzikXojb1PIFc/9Mt28/y+iRklkrw==} cpu: [arm64] os: [linux] - libc: [glibc] '@img/sharp-libvips-linux-arm@1.2.4': resolution: {integrity: sha512-bFI7xcKFELdiNCVov8e44Ia4u2byA+l3XtsAj+Q8tfCwO6BQ8iDojYdvoPMqsKDkuoOo+X6HZA0s0q11ANMQ8A==} cpu: [arm] os: [linux] - libc: [glibc] '@img/sharp-libvips-linux-ppc64@1.2.4': resolution: {integrity: sha512-FMuvGijLDYG6lW+b/UvyilUWu5Ayu+3r2d1S8notiGCIyYU/76eig1UfMmkZ7vwgOrzKzlQbFSuQfgm7GYUPpA==} cpu: [ppc64] os: [linux] - libc: [glibc] '@img/sharp-libvips-linux-riscv64@1.2.4': resolution: {integrity: sha512-oVDbcR4zUC0ce82teubSm+x6ETixtKZBh/qbREIOcI3cULzDyb18Sr/Wcyx7NRQeQzOiHTNbZFF1UwPS2scyGA==} cpu: [riscv64] os: [linux] - libc: [glibc] '@img/sharp-libvips-linux-s390x@1.2.4': resolution: {integrity: sha512-qmp9VrzgPgMoGZyPvrQHqk02uyjA0/QrTO26Tqk6l4ZV0MPWIW6LTkqOIov+J1yEu7MbFQaDpwdwJKhbJvuRxQ==} cpu: [s390x] os: [linux] - libc: [glibc] '@img/sharp-libvips-linux-x64@1.2.4': resolution: {integrity: sha512-tJxiiLsmHc9Ax1bz3oaOYBURTXGIRDODBqhveVHonrHJ9/+k89qbLl0bcJns+e4t4rvaNBxaEZsFtSfAdquPrw==} cpu: [x64] os: [linux] - libc: [glibc] '@img/sharp-libvips-linuxmusl-arm64@1.2.4': resolution: {integrity: sha512-FVQHuwx1IIuNow9QAbYUzJ+En8KcVm9Lk5+uGUQJHaZmMECZmOlix9HnH7n1TRkXMS0pGxIJokIVB9SuqZGGXw==} cpu: [arm64] os: [linux] - libc: [musl] '@img/sharp-libvips-linuxmusl-x64@1.2.4': resolution: {integrity: sha512-+LpyBk7L44ZIXwz/VYfglaX/okxezESc6UxDSoyo2Ks6Jxc4Y7sGjpgU9s4PMgqgjj1gZCylTieNamqA1MF7Dg==} cpu: [x64] os: [linux] - libc: [musl] '@img/sharp-linux-arm64@0.34.5': resolution: {integrity: sha512-bKQzaJRY/bkPOXyKx5EVup7qkaojECG6NLYswgktOZjaXecSAeCWiZwwiFf3/Y+O1HrauiE3FVsGxFg8c24rZg==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [arm64] os: [linux] - libc: [glibc] '@img/sharp-linux-arm@0.34.5': resolution: {integrity: sha512-9dLqsvwtg1uuXBGZKsxem9595+ujv0sJ6Vi8wcTANSFpwV/GONat5eCkzQo/1O6zRIkh0m/8+5BjrRr7jDUSZw==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [arm] os: [linux] - libc: [glibc] '@img/sharp-linux-ppc64@0.34.5': resolution: {integrity: sha512-7zznwNaqW6YtsfrGGDA6BRkISKAAE1Jo0QdpNYXNMHu2+0dTrPflTLNkpc8l7MUP5M16ZJcUvysVWWrMefZquA==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [ppc64] os: [linux] - libc: [glibc] '@img/sharp-linux-riscv64@0.34.5': resolution: {integrity: sha512-51gJuLPTKa7piYPaVs8GmByo7/U7/7TZOq+cnXJIHZKavIRHAP77e3N2HEl3dgiqdD/w0yUfiJnII77PuDDFdw==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [riscv64] os: [linux] - libc: [glibc] '@img/sharp-linux-s390x@0.34.5': resolution: {integrity: sha512-nQtCk0PdKfho3eC5MrbQoigJ2gd1CgddUMkabUj+rBevs8tZ2cULOx46E7oyX+04WGfABgIwmMC0VqieTiR4jg==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [s390x] os: [linux] - libc: [glibc] '@img/sharp-linux-x64@0.34.5': resolution: {integrity: sha512-MEzd8HPKxVxVenwAa+JRPwEC7QFjoPWuS5NZnBt6B3pu7EG2Ge0id1oLHZpPJdn3OQK+BQDiw9zStiHBTJQQQQ==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [x64] os: [linux] - libc: [glibc] '@img/sharp-linuxmusl-arm64@0.34.5': resolution: {integrity: sha512-fprJR6GtRsMt6Kyfq44IsChVZeGN97gTD331weR1ex1c1rypDEABN6Tm2xa1wE6lYb5DdEnk03NZPqA7Id21yg==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [arm64] os: [linux] - libc: [musl] '@img/sharp-linuxmusl-x64@0.34.5': resolution: {integrity: sha512-Jg8wNT1MUzIvhBFxViqrEhWDGzqymo3sV7z7ZsaWbZNDLXRJZoRGrjulp60YYtV4wfY8VIKcWidjojlLcWrd8Q==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [x64] os: [linux] - libc: [musl] '@img/sharp-wasm32@0.34.5': resolution: {integrity: sha512-OdWTEiVkY2PHwqkbBI8frFxQQFekHaSSkUIJkwzclWZe64O1X4UlUjqqqLaPbUpMOQk6FBu/HtlGXNblIs0huw==} @@ -881,79 +935,66 @@ packages: resolution: {integrity: sha512-2QxQrM+KQ7DAW4o22j+XZ6RKdxjLD7BOWTP0Bv0tmjdyhXSsr2Ul1oJDQqh9Zf5qOwTuTc7Ek83mOFaKnodPjg==} cpu: [arm] os: [linux] - libc: [glibc] '@rollup/rollup-linux-arm-musleabihf@4.60.2': resolution: {integrity: sha512-TbziEu2DVsTEOPif2mKWkMeDMLoYjx95oESa9fkQQK7r/Orta0gnkcDpzwufEcAO2BLBsD7mZkXGFqEdMRRwfw==} cpu: [arm] os: [linux] - libc: [musl] '@rollup/rollup-linux-arm64-gnu@4.60.2': resolution: {integrity: sha512-bO/rVDiDUuM2YfuCUwZ1t1cP+/yqjqz+Xf2VtkdppefuOFS2OSeAfgafaHNkFn0t02hEyXngZkxtGqXcXwO8Rg==} cpu: [arm64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-arm64-musl@4.60.2': resolution: {integrity: sha512-hr26p7e93Rl0Za+JwW7EAnwAvKkehh12BU1Llm9Ykiibg4uIr2rbpxG9WCf56GuvidlTG9KiiQT/TXT1yAWxTA==} cpu: [arm64] os: [linux] - libc: [musl] '@rollup/rollup-linux-loong64-gnu@4.60.2': resolution: {integrity: sha512-pOjB/uSIyDt+ow3k/RcLvUAOGpysT2phDn7TTUB3n75SlIgZzM6NKAqlErPhoFU+npgY3/n+2HYIQVbF70P9/A==} cpu: [loong64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-loong64-musl@4.60.2': resolution: {integrity: sha512-2/w+q8jszv9Ww1c+6uJT3OwqhdmGP2/4T17cu8WuwyUuuaCDDJ2ojdyYwZzCxx0GcsZBhzi3HmH+J5pZNXnd+Q==} cpu: [loong64] os: [linux] - libc: [musl] '@rollup/rollup-linux-ppc64-gnu@4.60.2': resolution: {integrity: sha512-11+aL5vKheYgczxtPVVRhdptAM2H7fcDR5Gw4/bTcteuZBlH4oP9f5s9zYO9aGZvoGeBpqXI/9TZZihZ609wKw==} cpu: [ppc64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-ppc64-musl@4.60.2': resolution: {integrity: sha512-i16fokAGK46IVZuV8LIIwMdtqhin9hfYkCh8pf8iC3QU3LpwL+1FSFGej+O7l3E/AoknL6Dclh2oTdnRMpTzFQ==} cpu: [ppc64] os: [linux] - libc: [musl] '@rollup/rollup-linux-riscv64-gnu@4.60.2': resolution: {integrity: sha512-49FkKS6RGQoriDSK/6E2GkAsAuU5kETFCh7pG4yD/ylj9rKhTmO3elsnmBvRD4PgJPds5W2PkhC82aVwmUcJ7A==} cpu: [riscv64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-riscv64-musl@4.60.2': resolution: {integrity: sha512-mjYNkHPfGpUR00DuM1ZZIgs64Hpf4bWcz9Z41+4Q+pgDx73UwWdAYyf6EG/lRFldmdHHzgrYyge5akFUW0D3mQ==} cpu: [riscv64] os: [linux] - libc: [musl] '@rollup/rollup-linux-s390x-gnu@4.60.2': resolution: {integrity: sha512-ALyvJz965BQk8E9Al/JDKKDLH2kfKFLTGMlgkAbbYtZuJt9LU8DW3ZoDMCtQpXAltZxwBHevXz5u+gf0yA0YoA==} cpu: [s390x] os: [linux] - libc: [glibc] '@rollup/rollup-linux-x64-gnu@4.60.2': resolution: {integrity: sha512-UQjrkIdWrKI626Du8lCQ6MJp/6V1LAo2bOK9OTu4mSn8GGXIkPXk/Vsp4bLHCd9Z9Iz2OTEaokUE90VweJgIYQ==} cpu: [x64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-x64-musl@4.60.2': resolution: {integrity: sha512-bTsRGj6VlSdn/XD4CGyzMnzaBs9bsRxy79eTqTCBsA8TMIEky7qg48aPkvJvFe1HyzQ5oMZdg7AnVlWQSKLTnw==} cpu: [x64] os: [linux] - libc: [musl] '@rollup/rollup-openbsd-x64@4.60.2': resolution: {integrity: sha512-6d4Z3534xitaA1FcMWP7mQPq5zGwBmGbhphh2DwaA1aNIXUu3KTOfwrWpbwI4/Gr0uANo7NTtaykFyO2hPuFLg==} @@ -1626,6 +1667,9 @@ packages: zimmerframe@1.1.4: resolution: {integrity: sha512-B58NGBEoc8Y9MWWCQGl/gq9xBCe4IiKM0a2x7GZdQKOW5Exr8S1W24J6OgM1njK8xCRGvAJIL/MxXHf6SkmQKQ==} + zod@4.6.7: + resolution: {integrity: sha512-g8W2D2kU6a8untc053fX1uVBKzM7yqAxW/3zwk83+6RyF2+SKOuV+c0wBDhUwzV1PaGapmZH+rmcUzPf+3CGwg==} + snapshots: '@babel/code-frame@7.29.0': @@ -1757,115 +1801,186 @@ snapshots: '@babel/helper-string-parser': 7.27.1 '@babel/helper-validator-identifier': 7.28.5 - '@deepseek-ai/cordis@4.0.1': + '@deepseek-ai/cordis@4.0.5': dependencies: - '@deepseek-ai/cosmokit': 1.8.2 + '@deepseek-ai/cosmokit': 1.8.6 '@standard-schema/spec': 1.1.0 '@deepseek-ai/cosmokit@1.8.2': {} - '@deepseek-ai/dsh-agent@0.1.0-rc.6(b0514d7a320728b6d8f5a31eb3960e10)': + '@deepseek-ai/cosmokit@1.8.6': {} + + '@deepseek-ai/dsh-agent@0.1.0-rc.6(6889e29676788162cc6455c880e3b4a2)': dependencies: - '@deepseek-ai/cordis': 4.0.1 - '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1) - '@deepseek-ai/dsh-llm': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))) - '@deepseek-ai/dsh-scope': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)) - '@deepseek-ai/dsh-session': 0.1.0-rc.6(6fd26f59436a18b115f326d6060415e6) - '@deepseek-ai/dsh-system-prompt': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))(@deepseek-ai/dsh-llm@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))))(@deepseek-ai/dsh-scope@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))) - '@deepseek-ai/dsh-typert-protocol': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)) + '@deepseek-ai/cordis': 4.0.5 + '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-llm': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))) + '@deepseek-ai/dsh-scope': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) + '@deepseek-ai/dsh-session': 0.1.0-rc.6(f5e28831e96e72c33b5ea3a797f6fddf) + '@deepseek-ai/dsh-system-prompt': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-llm@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))))(@deepseek-ai/dsh-scope@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))) + '@deepseek-ai/dsh-typert-protocol': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) - '@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))': + '@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))': dependencies: - '@deepseek-ai/cordis': 4.0.1 - '@deepseek-ai/dsh-brand': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)) - '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1) + '@deepseek-ai/cordis': 4.0.5 + '@deepseek-ai/dsh-brand': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) + '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5) - '@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))': + '@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))': dependencies: - '@deepseek-ai/cordis': 4.0.1 - '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1) + '@deepseek-ai/cordis': 4.0.5 + '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5) - '@deepseek-ai/dsh-code-runtime@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))': + '@deepseek-ai/dsh-brand@0.2.0-rc.2(@deepseek-ai/cordis@4.0.5)': dependencies: - '@deepseek-ai/cordis': 4.0.1 - '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1) + '@deepseek-ai/cordis': 4.0.5 - '@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)': + '@deepseek-ai/dsh-code-runtime@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))': dependencies: - '@deepseek-ai/cordis': 4.0.1 - '@deepseek-ai/schemastery': 3.18.1 + '@deepseek-ai/cordis': 4.0.5 + '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5) + + '@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)': + dependencies: + '@deepseek-ai/cordis': 4.0.5 + '@deepseek-ai/schemastery': 3.18.5 - '@deepseek-ai/dsh-llm@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))': + '@deepseek-ai/dsh-llm@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))': dependencies: - '@deepseek-ai/cordis': 4.0.1 - '@deepseek-ai/dsh-attachment': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)) - '@deepseek-ai/dsh-brand': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)) - '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1) - '@deepseek-ai/dsh-timeout': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)) + '@deepseek-ai/cordis': 4.0.5 + '@deepseek-ai/dsh-attachment': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) + '@deepseek-ai/dsh-brand': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) + '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-timeout': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) '@deepseek-ai/schemastery': 3.18.1 - '@deepseek-ai/dsh-scope@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))': + '@deepseek-ai/dsh-llm@0.2.0-rc.2(@deepseek-ai/cordis@4.0.5)': dependencies: - '@deepseek-ai/cordis': 4.0.1 - '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1) + '@deepseek-ai/cordis': 4.0.5 + '@deepseek-ai/dsh-brand': 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-timeout': 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-typert-protocol': 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-util-crypto': 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-util-values': 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/schemastery': 3.18.5 + zod: 4.6.7 - '@deepseek-ai/dsh-session@0.1.0-rc.6(6fd26f59436a18b115f326d6060415e6)': + '@deepseek-ai/dsh-scope@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))': dependencies: - '@deepseek-ai/cordis': 4.0.1 - '@deepseek-ai/dsh-brand': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)) - '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1) - '@deepseek-ai/dsh-llm': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))) - '@deepseek-ai/dsh-scope': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)) - '@deepseek-ai/dsh-typert-protocol': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)) + '@deepseek-ai/cordis': 4.0.5 + '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5) - '@deepseek-ai/dsh-system-prompt@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))(@deepseek-ai/dsh-llm@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))))(@deepseek-ai/dsh-scope@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))': + '@deepseek-ai/dsh-session-format-v0-to-v1@0.2.0-rc.2(@deepseek-ai/cordis@4.0.5)': dependencies: - '@deepseek-ai/cordis': 4.0.1 - '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1) - '@deepseek-ai/dsh-llm': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))) - '@deepseek-ai/dsh-scope': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)) - '@deepseek-ai/schemastery': 3.18.1 + '@deepseek-ai/cordis': 4.0.5 + '@deepseek-ai/dsh-session-format': 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-util-values': 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) + + '@deepseek-ai/dsh-session-format-v1-to-v2@0.2.0-rc.2(@deepseek-ai/cordis@4.0.5)': + dependencies: + '@deepseek-ai/cordis': 4.0.5 + '@deepseek-ai/dsh-llm': 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-session-format': 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-session-format-v0-to-v1': 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-util-values': 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) + + '@deepseek-ai/dsh-session-format-v2-to-v3@0.2.0-rc.2(@deepseek-ai/cordis@4.0.5)': + dependencies: + '@deepseek-ai/cordis': 4.0.5 + '@deepseek-ai/dsh-session-format': 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-session-format-v0-to-v1': 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-session-format-v1-to-v2': 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) + + '@deepseek-ai/dsh-session-format-v3-to-v4@0.2.0-rc.2(@deepseek-ai/cordis@4.0.5)': + dependencies: + '@deepseek-ai/cordis': 4.0.5 + '@deepseek-ai/dsh-session-format': 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-session-format-v2-to-v3': 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) - '@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))': + '@deepseek-ai/dsh-session-format@0.2.0-rc.2(@deepseek-ai/cordis@4.0.5)': dependencies: - '@deepseek-ai/cordis': 4.0.1 - '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1) + '@deepseek-ai/cordis': 4.0.5 + '@deepseek-ai/dsh-util-values': 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) - '@deepseek-ai/dsh-tools@0.1.0-rc.6(f8724372086ccc1457fc84e7becee2e0)': + '@deepseek-ai/dsh-session@0.1.0-rc.6(f5e28831e96e72c33b5ea3a797f6fddf)': dependencies: - '@deepseek-ai/cordis': 4.0.1 - '@deepseek-ai/dsh-agent': 0.1.0-rc.6(b0514d7a320728b6d8f5a31eb3960e10) - '@deepseek-ai/dsh-code-runtime': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)) - '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1) - '@deepseek-ai/dsh-llm': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))) - '@deepseek-ai/dsh-scope': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)) - '@deepseek-ai/dsh-session': 0.1.0-rc.6(6fd26f59436a18b115f326d6060415e6) - '@deepseek-ai/dsh-system-prompt': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))(@deepseek-ai/dsh-llm@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))))(@deepseek-ai/dsh-scope@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))) - '@deepseek-ai/dsh-user-approval': 0.1.0-rc.6(dbdaba06c174c5e30e3a58edf3cc27a9) + '@deepseek-ai/cordis': 4.0.5 + '@deepseek-ai/dsh-brand': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) + '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-llm': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))) + '@deepseek-ai/dsh-scope': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) + '@deepseek-ai/dsh-typert-protocol': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) + + '@deepseek-ai/dsh-system-prompt@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-llm@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))))(@deepseek-ai/dsh-scope@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))': + dependencies: + '@deepseek-ai/cordis': 4.0.5 + '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-llm': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))) + '@deepseek-ai/dsh-scope': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) '@deepseek-ai/schemastery': 3.18.1 - '@deepseek-ai/dsh-typert-protocol@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))': + '@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))': + dependencies: + '@deepseek-ai/cordis': 4.0.5 + '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5) + + '@deepseek-ai/dsh-timeout@0.2.0-rc.2(@deepseek-ai/cordis@4.0.5)': dependencies: - '@deepseek-ai/cordis': 4.0.1 - '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1) + '@deepseek-ai/cordis': 4.0.5 - '@deepseek-ai/dsh-user-approval@0.1.0-rc.6(dbdaba06c174c5e30e3a58edf3cc27a9)': + '@deepseek-ai/dsh-tools@0.1.0-rc.6(14b150c73c93dfea9f66b8be648ac0d7)': dependencies: - '@deepseek-ai/cordis': 4.0.1 - '@deepseek-ai/dsh-agent': 0.1.0-rc.6(b0514d7a320728b6d8f5a31eb3960e10) - '@deepseek-ai/dsh-brand': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)) - '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1) - '@deepseek-ai/dsh-llm': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))) - '@deepseek-ai/dsh-scope': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)) - '@deepseek-ai/dsh-session': 0.1.0-rc.6(6fd26f59436a18b115f326d6060415e6) - '@deepseek-ai/dsh-system-prompt': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))(@deepseek-ai/dsh-llm@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))))(@deepseek-ai/dsh-scope@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.1))) + '@deepseek-ai/cordis': 4.0.5 + '@deepseek-ai/dsh-agent': 0.1.0-rc.6(6889e29676788162cc6455c880e3b4a2) + '@deepseek-ai/dsh-code-runtime': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) + '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-llm': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))) + '@deepseek-ai/dsh-scope': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) + '@deepseek-ai/dsh-session': 0.1.0-rc.6(f5e28831e96e72c33b5ea3a797f6fddf) + '@deepseek-ai/dsh-system-prompt': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-llm@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))))(@deepseek-ai/dsh-scope@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))) + '@deepseek-ai/dsh-user-approval': 0.1.0-rc.6(731c4b6587473c7b25a7e36b8e78ec80) '@deepseek-ai/schemastery': 3.18.1 + '@deepseek-ai/dsh-typert-protocol@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))': + dependencies: + '@deepseek-ai/cordis': 4.0.5 + '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5) + + '@deepseek-ai/dsh-typert-protocol@0.2.0-rc.2(@deepseek-ai/cordis@4.0.5)': + dependencies: + '@deepseek-ai/cordis': 4.0.5 + '@deepseek-ai/dsh-brand': 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) + + '@deepseek-ai/dsh-user-approval@0.1.0-rc.6(731c4b6587473c7b25a7e36b8e78ec80)': + dependencies: + '@deepseek-ai/cordis': 4.0.5 + '@deepseek-ai/dsh-agent': 0.1.0-rc.6(6889e29676788162cc6455c880e3b4a2) + '@deepseek-ai/dsh-brand': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) + '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-llm': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))) + '@deepseek-ai/dsh-scope': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) + '@deepseek-ai/dsh-session': 0.1.0-rc.6(f5e28831e96e72c33b5ea3a797f6fddf) + '@deepseek-ai/dsh-system-prompt': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-llm@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))))(@deepseek-ai/dsh-scope@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))) + '@deepseek-ai/schemastery': 3.18.5 + + '@deepseek-ai/dsh-util-crypto@0.2.0-rc.2(@deepseek-ai/cordis@4.0.5)': + dependencies: + '@deepseek-ai/cordis': 4.0.5 + + '@deepseek-ai/dsh-util-values@0.2.0-rc.2(@deepseek-ai/cordis@4.0.5)': + dependencies: + '@deepseek-ai/cordis': 4.0.5 + '@deepseek-ai/schemastery@3.18.1': dependencies: '@deepseek-ai/cosmokit': 1.8.2 '@standard-schema/spec': 1.1.0 + '@deepseek-ai/schemastery@3.18.5': + dependencies: + '@deepseek-ai/cosmokit': 1.8.6 + '@standard-schema/spec': 1.1.0 + '@emnapi/runtime@1.10.0': dependencies: tslib: 2.8.1 @@ -3010,3 +3125,5 @@ snapshots: yaml@2.8.3: {} zimmerframe@1.1.4: {} + + zod@4.6.7: {} diff --git a/apps/memos-local-plugin/tests/helpers/deepseek-harness-v4.ts b/apps/memos-local-plugin/tests/helpers/deepseek-harness-v4.ts new file mode 100644 index 000000000..2005b1e39 --- /dev/null +++ b/apps/memos-local-plugin/tests/helpers/deepseek-harness-v4.ts @@ -0,0 +1,9 @@ +import { releasedV4SessionFormatCodec } from "@deepseek-ai/dsh-session-format-v3-to-v4"; + +/** Use the same JSON boundary as durable DSH events, without a desktop install. */ +export function dshV4Event( + type: string, + data: unknown, +): Parameters[0] { + return JSON.parse(JSON.stringify({ type, seq: 1, time: 1, data })); +} diff --git a/apps/memos-local-plugin/tests/unit/adapters/deepseek-harness-bridge.test.ts b/apps/memos-local-plugin/tests/unit/adapters/deepseek-harness-bridge.test.ts index 4c5404365..d83147f11 100644 --- a/apps/memos-local-plugin/tests/unit/adapters/deepseek-harness-bridge.test.ts +++ b/apps/memos-local-plugin/tests/unit/adapters/deepseek-harness-bridge.test.ts @@ -1,5 +1,7 @@ +import { assertV4RowAdmission, releasedV4SessionFormatCodec } from "@deepseek-ai/dsh-session-format-v3-to-v4"; import { describe, expect, it, vi } from "vitest"; +import { dshV4Event } from "../../helpers/deepseek-harness-v4.js"; import type { MemoryCore } from "../../../agent-contract/memory-core.js"; import { createDeepSeekHarnessBridge, @@ -7,6 +9,7 @@ import { type DshSessionLike, type DshUserMessageLike, } from "../../../adapters/deepseek-harness/bridge.js"; +import { createDeepSeekHarnessRecallMessage } from "../../../adapters/deepseek-harness/index.js"; import { DeepSeekHarnessLlmRouteContext } from "../../../adapters/deepseek-harness/host-llm.js"; function userMessage(text: string): DshUserMessageLike { @@ -19,16 +22,7 @@ function userMessage(text: string): DshUserMessageLike { } function recallMessage(text: string): DshUserMessageLike { - return { - id: `recall-${text.length}`, - role: "user", - content: [{ type: "text", text }], - source: { - kind: "plugin", - plugin: "memos-local-memory", - form: "recall", - }, - }; + return createDeepSeekHarnessRecallMessage(text) as unknown as DshUserMessageLike; } function makeCore(overrides: Partial = {}): MemoryCore { @@ -539,7 +533,7 @@ describe("DeepSeek Harness bridge", () => { expect(first.messages[1]).toMatchObject({ role: "user", source: { - kind: "plugin", + kind: "plugin:memos-local-memory", plugin: "memos-local-memory", form: "recall", }, @@ -548,12 +542,24 @@ describe("DeepSeek Harness bridge", () => { text: expect.stringContaining("The user prefers concise technical answers."), }], }); + // Pre-step persists the original query and recall together. Both must pass V4. + const batch = dshV4Event("agent/inbox/spliced", { + removedCount: 1, + inserted: first.messages, + }); + expect(() => assertV4RowAdmission(batch)).not.toThrow(); + expect(() => releasedV4SessionFormatCodec.encodeEvent(batch)).not.toThrow(); + for (const message of first.messages) { + const event = dshV4Event("user/message", message); + expect(() => assertV4RowAdmission(event)).not.toThrow(); + expect(() => releasedV4SessionFormatCodec.encodeEvent(event)).not.toThrow(); + } expect(replayedFirstStep).toEqual({ kind: "enter", messages: [prompt] }); expect(second).toEqual({ kind: "enter", messages: [] }); expect(followUp).toMatchObject({ kind: "enter", messages: [followUpPrompt, expect.objectContaining({ - source: expect.objectContaining({ plugin: "memos-local-memory" }), + source: expect.objectContaining({ kind: "plugin:memos-local-memory" }), })], }); }); @@ -590,7 +596,7 @@ describe("DeepSeek Harness bridge", () => { expect(result).toMatchObject({ kind: "enter", messages: [prompt, expect.objectContaining({ - source: expect.objectContaining({ plugin: "memos-local-memory" }), + source: expect.objectContaining({ kind: "plugin:memos-local-memory" }), })], }); expect(core.searchMemory).toHaveBeenCalledTimes(1); @@ -637,7 +643,7 @@ describe("DeepSeek Harness bridge", () => { expect(result).toMatchObject({ kind: "enter", messages: [prompt, expect.objectContaining({ - source: expect.objectContaining({ plugin: "memos-local-memory" }), + source: expect.objectContaining({ kind: "plugin:memos-local-memory" }), })], }); }); @@ -682,7 +688,7 @@ describe("DeepSeek Harness bridge", () => { expect(result).toMatchObject({ kind: "enter", messages: [prompt, expect.objectContaining({ - source: expect.objectContaining({ plugin: "memos-local-memory" }), + source: expect.objectContaining({ kind: "plugin:memos-local-memory" }), })], }); expect(core.searchMemory).toHaveBeenCalledTimes(1); @@ -836,7 +842,7 @@ describe("DeepSeek Harness bridge", () => { expect(result).toMatchObject({ kind: "enter", messages: [retry, expect.objectContaining({ - source: expect.objectContaining({ plugin: "memos-local-memory" }), + source: expect.objectContaining({ kind: "plugin:memos-local-memory" }), })], }); @@ -959,7 +965,7 @@ describe("DeepSeek Harness bridge", () => { await expect(nextStep).resolves.toMatchObject({ kind: "enter", messages: [secondPrompt, expect.objectContaining({ - source: expect.objectContaining({ plugin: "memos-local-memory" }), + source: expect.objectContaining({ kind: "plugin:memos-local-memory" }), })], }); expect(core.searchMemory).toHaveBeenCalledTimes(2); @@ -1037,7 +1043,7 @@ describe("DeepSeek Harness bridge", () => { await expect(nextStep).resolves.toMatchObject({ kind: "enter", messages: [secondPrompt, expect.objectContaining({ - source: expect.objectContaining({ plugin: "memos-local-memory" }), + source: expect.objectContaining({ kind: "plugin:memos-local-memory" }), })], }); expect(core.searchMemory).toHaveBeenCalledTimes(2); diff --git a/apps/memos-local-plugin/tests/unit/adapters/deepseek-harness-host-llm.test.ts b/apps/memos-local-plugin/tests/unit/adapters/deepseek-harness-host-llm.test.ts index ea9b1854b..4f91e310c 100644 --- a/apps/memos-local-plugin/tests/unit/adapters/deepseek-harness-host-llm.test.ts +++ b/apps/memos-local-plugin/tests/unit/adapters/deepseek-harness-host-llm.test.ts @@ -1,3 +1,4 @@ +import { assertV4RowAdmission, releasedV4SessionFormatCodec } from "@deepseek-ai/dsh-session-format-v3-to-v4"; import { Context } from "@deepseek-ai/cordis"; import LlmRuntime, { LlmAdapter, @@ -12,6 +13,7 @@ import LlmRuntime, { } from "@deepseek-ai/dsh-llm"; import { describe, expect, it, vi } from "vitest"; +import { dshV4Event } from "../../helpers/deepseek-harness-v4.js"; import { createDeepSeekHarnessHostLlmBridge, DeepSeekHarnessLlmRouteContext, @@ -165,6 +167,13 @@ describe("DeepSeek Harness host LLM bridge", () => { timeoutMs: 2_000, })); + // Exercise the actual host bridge output; auxiliary messages need no form. + const message = request!.messages[0]!; + expect(message.source).not.toHaveProperty("form"); + const event = dshV4Event("user/message", message); + expect(() => assertV4RowAdmission(event)).not.toThrow(); + expect(() => releasedV4SessionFormatCodec.encodeEvent(event)).not.toThrow(); + expect(request).toMatchObject({ provider: "deepseek", model: "deepseek-chat", diff --git a/apps/memos-local-plugin/tests/unit/adapters/deepseek-harness-runtime.test.ts b/apps/memos-local-plugin/tests/unit/adapters/deepseek-harness-runtime.test.ts index b5e690888..01ddeb8f8 100644 --- a/apps/memos-local-plugin/tests/unit/adapters/deepseek-harness-runtime.test.ts +++ b/apps/memos-local-plugin/tests/unit/adapters/deepseek-harness-runtime.test.ts @@ -1,4 +1,5 @@ import { join } from "node:path"; +import { assertV4RowAdmission, releasedV4SessionFormatCodec } from "@deepseek-ai/dsh-session-format-v3-to-v4"; import type { Context } from "@deepseek-ai/cordis"; import { describe, expect, it, vi } from "vitest"; @@ -15,11 +16,15 @@ import { import type { DeepSeekHarnessHostLlmBridge, } from "../../../adapters/deepseek-harness/host-llm.js"; +import { dshV4Event } from "../../helpers/deepseek-harness-v4.js"; import { DEFAULT_CONFIG } from "../../../core/config/index.js"; describe("DeepSeek Harness adapter runtime defaults", () => { it("creates producer-owned recall messages admitted by DSH V4", () => { const message = createDeepSeekHarnessRecallMessage("synthetic recall"); + const event = dshV4Event("user/message", message); + expect(() => assertV4RowAdmission(event)).not.toThrow(); + expect(() => releasedV4SessionFormatCodec.encodeEvent(event)).not.toThrow(); expect(message).toMatchObject({ role: "user", content: [{ type: "text", text: "synthetic recall" }], @@ -27,6 +32,26 @@ describe("DeepSeek Harness adapter runtime defaults", () => { }); }); + it.each([ + { kind: "plugin", plugin: "memos-local-memory", form: "recall" }, + { kind: "plugin", plugin: "memos-local-memory" }, + ])("rejects retired plugin sources at both V4 gates: %j", (source) => { + const message = { ...createDeepSeekHarnessRecallMessage("synthetic recall"), source }; + const user = { ...message, source: { kind: "user" } }; + const events = [ + dshV4Event("user/message", message), + dshV4Event("agent/inbox/spliced", { removedCount: 1, inserted: [user, message] }), + ]; + for (const event of events) { + expect(() => assertV4RowAdmission(event)).toThrow( + "format v4 message requires a producer-owned source kind", + ); + expect(() => releasedV4SessionFormatCodec.encodeEvent(event)).toThrow( + "format v4 message requires a producer-owned source kind", + ); + } + }); + it("injects the DSH LLM service and uses it for an otherwise unconfigured MemOS LLM", () => { expect(inject).toContain("llm"); From c8aed140ddedef45f10e9aac1e79b741c3366d09 Mon Sep 17 00:00:00 2001 From: Zyntrael <2650876010@qq.com> Date: Wed, 21 Oct 2026 21:26:47 +0800 Subject: [PATCH 24/38] feat: align PostgreSQL graph storage with current v2.0.36 APIs (#2531) * feat: align PostgreSQL graph storage with current v2.0.36 APIs Store the existing graph interface on MD5 tenant shards so this branch can run on PostgreSQL without attribute-tree tables. Co-authored-by: Cursor * style: format PostgreSQL graph files for Ruff The upstream check stops on ruff format before the tests run. Co-authored-by: Cursor * ci: retrigger pull request checks The Windows Python 3.11 dependency install failed once and needs another run. Co-authored-by: Cursor --------- Co-authored-by: Cursor --- src/memos/api/config.py | 6 +- src/memos/configs/graph_db.py | 33 +- src/memos/graph_dbs/postgres.py | 2154 ++++++++++++++++--- tests/graph_dbs/test_postgres_400_compat.py | 391 ++++ tests/graph_dbs/test_postgres_pgvector.py | 461 ++++ 5 files changed, 2712 insertions(+), 333 deletions(-) create mode 100644 tests/graph_dbs/test_postgres_400_compat.py create mode 100644 tests/graph_dbs/test_postgres_pgvector.py diff --git a/src/memos/api/config.py b/src/memos/api/config.py index 0247dfa42..f09e51335 100644 --- a/src/memos/api/config.py +++ b/src/memos/api/config.py @@ -906,8 +906,8 @@ def get_polardb_config(user_id: str | None = None) -> dict[str, Any]: def get_postgres_config(user_id: str | None = None) -> dict[str, Any]: """Get PostgreSQL + pgvector configuration for MemOS graph storage. - Uses standard PostgreSQL with pgvector extension. - Schema: memos.memories, memos.edges + Uses standard PostgreSQL with pgvector. Shard count, index, and + full-text configuration keep the backend defaults unless overridden. """ user_name = os.getenv("MEMOS_USER_NAME", "default") if user_id: @@ -922,7 +922,7 @@ def get_postgres_config(user_id: str | None = None) -> dict[str, Any]: "schema_name": os.getenv("MEMOS_SCHEMA", "memos"), "user_name": user_name, "use_multi_db": False, - "embedding_dimension": int(os.getenv("EMBEDDING_DIMENSION", "384")), + "embedding_dimension": int(os.getenv("EMBEDDING_DIMENSION", "1024")), "maxconn": int(os.getenv("POSTGRES_MAX_CONN", "20")), } diff --git a/src/memos/configs/graph_db.py b/src/memos/configs/graph_db.py index 98de09812..984c95060 100644 --- a/src/memos/configs/graph_db.py +++ b/src/memos/configs/graph_db.py @@ -1,4 +1,4 @@ -from typing import Any, ClassVar +from typing import Any, ClassVar, Literal from pydantic import BaseModel, Field, field_validator, model_validator @@ -195,8 +195,7 @@ class PostgresGraphDBConfig(BaseConfig): Does NOT require Apache AGE or other graph extensions. Schema: - - memos_memories: Main table for memory nodes (id, memory, properties JSONB, embedding vector) - - memos_edges: Edge table for relationships (source_id, target_id, type) + - {schema}_graph_{n}."Memory" and "Edges", one physical shard per tenant Example: --- @@ -223,13 +222,33 @@ class PostgresGraphDBConfig(BaseConfig): default=False, description="If False: use single database with logical isolation by user_name", ) - embedding_dimension: int = Field( - default=768, description="Dimension of vector embedding (768 for all-mpnet-base-v2)" + embedding_dimension: int = Field(default=1024, description="Dimension of vector embedding") + shard_count: int = Field( + default=400, + ge=1, + le=4096, + description="Number of MD5 tenant shards", ) maxconn: int = Field( default=20, description="Maximum number of connections in the connection pool", ) + minconn: int = Field( + default=8, + ge=1, + description="Warm connections kept in the pool", + ) + vector_index_type: Literal["hnsw", "ivfflat"] = Field( + default="hnsw", + description="pgvector approximate index type", + ) + hnsw_m: int = Field(default=16, ge=2, le=100) + hnsw_ef_construction: int = Field(default=64, ge=4, le=1000) + ivfflat_lists: int = Field(default=100, ge=1) + fulltext_config: str = Field( + default="jiebacfg", + description="PostgreSQL text search configuration used to build search_vector", + ) @model_validator(mode="after") def validate_config(self): @@ -238,6 +257,10 @@ def validate_config(self): raise ValueError("`db_name` must be provided") if not self.use_multi_db and not self.user_name: raise ValueError("In single-database mode, `user_name` must be provided") + if self.minconn > self.maxconn: + raise ValueError(f"`minconn` ({self.minconn}) must be <= `maxconn` ({self.maxconn})") + if not self.fulltext_config.replace(".", "_").isidentifier(): + raise ValueError("`fulltext_config` must be a valid PostgreSQL configuration name") return self diff --git a/src/memos/graph_dbs/postgres.py b/src/memos/graph_dbs/postgres.py index 594f7e695..2820a8b54 100644 --- a/src/memos/graph_dbs/postgres.py +++ b/src/memos/graph_dbs/postgres.py @@ -5,16 +5,18 @@ No Apache AGE or other graph extensions required. Tables: -- {schema}.memories: Memory nodes with JSONB properties and vector embeddings -- {schema}.edges: Relationships between memory nodes +- {schema}_graph_{n}."Memory": one tenant shard of memory nodes +- {schema}_graph_{n}."Edges": relationships for that same shard """ +import hashlib import json +import random import re import time from contextlib import suppress -from datetime import datetime +from datetime import datetime, timezone from typing import Any, Literal from memos.configs.graph_db import PostgresGraphDBConfig @@ -28,7 +30,7 @@ def _prepare_node_metadata(metadata: dict[str, Any]) -> dict[str, Any]: """Ensure metadata has proper datetime fields and normalized types.""" - now = datetime.utcnow().isoformat() + now = datetime.now(timezone.utc).isoformat() metadata.setdefault("created_at", now) metadata.setdefault("updated_at", now) @@ -43,6 +45,9 @@ def _prepare_node_metadata(metadata: dict[str, Any]) -> dict[str, Any]: class PostgresGraphDB(BaseGraphDB): """PostgreSQL + pgvector implementation of a graph memory store.""" + supports_lightweight_vector_search = True + prefer_lightweight_vector_search = True + @require_python_package( import_name="psycopg2", install_command="pip install psycopg2-binary", @@ -50,26 +55,29 @@ class PostgresGraphDB(BaseGraphDB): ) def __init__(self, config: PostgresGraphDBConfig): """Initialize PostgreSQL connection pool.""" - import psycopg2 import psycopg2.pool self.config = config + if not self._is_safe_field_name(config.schema_name): + raise ValueError(f"Invalid PostgreSQL schema name: {config.schema_name}") self.schema = config.schema_name + self.db_name = config.db_name self.user_name = config.user_name self._pool_closed = False + self._partition_remainders: dict[str, int] = {} logger.info(f"Connecting to PostgreSQL: {config.host}:{config.port}/{config.db_name}") # Create connection pool self.pool = psycopg2.pool.ThreadedConnectionPool( - minconn=2, + minconn=config.minconn, maxconn=config.maxconn, host=config.host, port=config.port, user=config.user, password=config.password, dbname=config.db_name, - connect_timeout=30, + connect_timeout=10, keepalives_idle=30, keepalives_interval=10, keepalives_count=5, @@ -78,8 +86,39 @@ def __init__(self, config: PostgresGraphDBConfig): # Initialize schema and tables self._init_schema() + def warm_up_search_connections_by_full(self, user_name: str | None = None) -> None: + """Warm one pooled PostgreSQL connection; tenant routing needs no fan-out.""" + conn = self._get_conn() + self._put_conn(conn) + + def get_memory_graph_table_name(self, user_name: str | None) -> str: + """Return the one partition table for this tenant, matching PolarDB shard routing.""" + target = user_name or self.user_name + return self._physical_table("memories", target) + + def create_extension(self) -> None: + self._init_schema() + + def create_graph(self) -> None: + self._init_schema() + + def create_edge(self) -> None: + self._init_schema() + + def create_index( + self, + label: str = "Memory", + vector_property: str = "embedding", + dimensions: int = 1024, + index_name: str = "memory_vector_index", + ) -> None: + self._init_schema() + + def format_param_value(self, value: str | None) -> str: + return "null" if value is None else json.dumps(value, ensure_ascii=False) + def _get_conn(self): - """Get connection from pool with health check.""" + """Get a pooled connection without an extra round trip.""" if self._pool_closed: raise RuntimeError("Connection pool is closed") @@ -91,9 +130,6 @@ def _get_conn(self): self.pool.putconn(conn, close=True) continue conn.autocommit = True - # Health check - with conn.cursor() as cur: - cur.execute("SELECT 1") return conn except Exception as e: if conn: @@ -114,66 +150,145 @@ def _put_conn(self, conn): conn.close() def _init_schema(self): - """Create schema and tables if they don't exist.""" + """Create PolarDB-style MD5 shards with a halfvec Memory table in each.""" + fulltext_config = getattr(self.config, "fulltext_config", "simple") + if not re.match(r"^[A-Za-z_][A-Za-z0-9_.]*$", fulltext_config): + raise ValueError(f"Invalid PostgreSQL text search config: {fulltext_config}") + vector_index_type = getattr(self.config, "vector_index_type", "hnsw") + shard_count = int(getattr(self.config, "shard_count", 400)) + if shard_count < 1 or shard_count > 4096: + raise ValueError("PostgreSQL shard_count must be between 1 and 4096") + conn = self._get_conn() try: with conn.cursor() as cur: - # Create schema cur.execute(f"CREATE SCHEMA IF NOT EXISTS {self.schema}") - - # Enable pgvector cur.execute("CREATE EXTENSION IF NOT EXISTS vector") - # Create memories table - dim = self.config.embedding_dimension - cur.execute(f""" - CREATE TABLE IF NOT EXISTS {self.schema}.memories ( - id TEXT PRIMARY KEY, - memory TEXT NOT NULL DEFAULT '', - properties JSONB NOT NULL DEFAULT '{{}}', - embedding vector({dim}), - user_name TEXT, - created_at TIMESTAMPTZ DEFAULT NOW(), - updated_at TIMESTAMPTZ DEFAULT NOW() - ) - """) - - # Create edges table - cur.execute(f""" - CREATE TABLE IF NOT EXISTS {self.schema}.edges ( - id SERIAL PRIMARY KEY, - source_id TEXT NOT NULL, - target_id TEXT NOT NULL, - edge_type TEXT NOT NULL, - created_at TIMESTAMPTZ DEFAULT NOW(), - UNIQUE(source_id, target_id, edge_type) + cur.execute( + """ + SELECT c.relname, c.relkind + FROM pg_class AS c + JOIN pg_namespace AS n ON n.oid = c.relnamespace + WHERE n.nspname = %s + AND c.relname = ANY(%s) + """, + ( + self.schema, + ["memories", "edges"], + ), + ) + legacy_rows = cur.fetchall() + if isinstance(legacy_rows, list) and legacy_rows: + raise RuntimeError( + f"{self.schema} still has the old memories layout; " + "configure a new MEMOS_SCHEMA for the MD5 shard layout " + "or migrate the existing data" ) - """) - - # Create indexes - cur.execute(f""" - CREATE INDEX IF NOT EXISTS idx_memories_user - ON {self.schema}.memories(user_name) - """) - cur.execute(f""" - CREATE INDEX IF NOT EXISTS idx_memories_props - ON {self.schema}.memories USING GIN(properties) - """) - cur.execute(f""" - CREATE INDEX IF NOT EXISTS idx_memories_embedding - ON {self.schema}.memories USING ivfflat(embedding vector_cosine_ops) - WITH (lists = 100) - """) - cur.execute(f""" - CREATE INDEX IF NOT EXISTS idx_edges_source - ON {self.schema}.edges(source_id) - """) - cur.execute(f""" - CREATE INDEX IF NOT EXISTS idx_edges_target - ON {self.schema}.edges(target_id) - """) - - logger.info(f"Schema {self.schema} initialized successfully") + + dim = int(self.config.embedding_dimension) + cur.execute( + """ + SELECT COUNT(*) + FROM pg_class AS c + JOIN pg_namespace AS n ON n.oid = c.relnamespace + WHERE c.relname = 'Memory' + AND c.relkind = 'r' + AND n.nspname ~ %s + """, + (rf"^{re.escape(self.schema)}_graph_[0-9]+$",), + ) + count_row = cur.fetchone() + memory_tables = count_row[0] if count_row and isinstance(count_row[0], int) else -1 + if memory_tables != shard_count: + hnsw_m = int(getattr(self.config, "hnsw_m", 16)) + ef_construction = int(getattr(self.config, "hnsw_ef_construction", 64)) + lists = int(getattr(self.config, "ivfflat_lists", 100)) + statements: list[str] = [] + for remainder in range(shard_count): + shard_schema = f"{self.schema}_graph_{remainder}" + memory = f'"{shard_schema}"."Memory"' + edges = f'"{shard_schema}"."Edges"' + if vector_index_type == "ivfflat": + vector_index = ( + f"CREATE INDEX IF NOT EXISTS idx_memory_embedding_halfvec " + f"ON {memory} USING ivfflat (embedding halfvec_cosine_ops) " + f"WITH (lists = {lists})" + ) + else: + vector_index = ( + f"CREATE INDEX IF NOT EXISTS idx_memory_embedding_halfvec " + f"ON {memory} USING hnsw (embedding halfvec_cosine_ops) " + f"WITH (m = {hnsw_m}, ef_construction = {ef_construction})" + ) + statements.extend( + [ + f'CREATE SCHEMA IF NOT EXISTS "{shard_schema}"', + f""" + CREATE TABLE IF NOT EXISTS {memory} ( + id TEXT NOT NULL, + memory TEXT NOT NULL DEFAULT '', + properties JSONB NOT NULL DEFAULT '{{}}', + embedding halfvec({dim}), + user_name TEXT NOT NULL, + search_vector tsvector GENERATED ALWAYS AS ( + to_tsvector( + '{fulltext_config}', + coalesce(memory, '') || ' ' || coalesce(properties::text, '') + ) + ) STORED, + deleted_at TIMESTAMPTZ, + created_at TIMESTAMPTZ DEFAULT NOW(), + updated_at TIMESTAMPTZ DEFAULT NOW(), + PRIMARY KEY (user_name, id) + ) + """, + f""" + CREATE TABLE IF NOT EXISTS {edges} ( + id BIGSERIAL NOT NULL, + user_name TEXT NOT NULL, + source_id TEXT NOT NULL, + target_id TEXT NOT NULL, + edge_type TEXT NOT NULL, + created_at TIMESTAMPTZ DEFAULT NOW(), + PRIMARY KEY (user_name, id), + UNIQUE(user_name, source_id, target_id, edge_type) + ) + """, + ( + f"CREATE INDEX IF NOT EXISTS idx_memory_user " + f"ON {memory}(user_name)" + ), + ( + f"CREATE INDEX IF NOT EXISTS idx_memory_props " + f"ON {memory} USING GIN(properties)" + ), + ( + f"CREATE INDEX IF NOT EXISTS idx_memory_search_vector " + f"ON {memory} USING GIN(search_vector)" + ), + vector_index, + ( + f"CREATE INDEX IF NOT EXISTS idx_edges_source " + f"ON {edges}(user_name, source_id)" + ), + ( + f"CREATE INDEX IF NOT EXISTS idx_edges_target " + f"ON {edges}(user_name, target_id)" + ), + ( + "CREATE UNIQUE INDEX IF NOT EXISTS idx_edges_tenant_unique " + f"ON {edges}(user_name, source_id, target_id, edge_type)" + ), + ] + ) + cur.execute(";\n".join(statements)) + + logger.info( + "Schema %s initialized successfully with %d MD5 shards", + self.schema, + shard_count, + ) except Exception as e: logger.error(f"Failed to init schema: {e}") raise @@ -197,6 +312,8 @@ def remove_oldest_memory( """ user_name = user_name or self.user_name keep_latest = int(keep_latest) + memories = self._physical_table("memories", user_name) + edges = self._physical_table("edges", user_name) conn = self._get_conn() try: @@ -206,7 +323,7 @@ def remove_oldest_memory( f""" WITH ranked AS ( SELECT id, ROW_NUMBER() OVER (ORDER BY updated_at DESC) as rn - FROM {self.schema}.memories + FROM {memories} WHERE user_name = %s AND properties->>'memory_type' = %s ) @@ -221,101 +338,140 @@ def remove_oldest_memory( # Delete edges first cur.execute( f""" - DELETE FROM {self.schema}.edges - WHERE source_id = ANY(%s) OR target_id = ANY(%s) + DELETE FROM {edges} + WHERE user_name = %s + AND (source_id = ANY(%s) OR target_id = ANY(%s)) """, - (ids_to_delete, ids_to_delete), + (user_name, ids_to_delete, ids_to_delete), ) # Delete nodes cur.execute( f""" - DELETE FROM {self.schema}.memories - WHERE id = ANY(%s) + DELETE FROM {memories} + WHERE id = ANY(%s) AND user_name = %s """, - (ids_to_delete,), + (ids_to_delete, user_name), ) logger.info( - f"Removed {len(ids_to_delete)} oldest {memory_type} memories for user {user_name}" + "Removed %d oldest %s memories for user %s", + len(ids_to_delete), + memory_type, + user_name, ) finally: self._put_conn(conn) - def add_node( - self, id: str, memory: str, metadata: dict[str, Any], user_name: str | None = None - ) -> None: - """Add a memory node.""" - user_name = user_name or self.user_name - metadata = _prepare_node_metadata(metadata.copy()) - - # Extract embedding - embedding = metadata.pop("embedding", None) - created_at = metadata.pop("created_at", datetime.utcnow().isoformat()) - updated_at = metadata.pop("updated_at", datetime.utcnow().isoformat()) + def _prepare_node_for_insert( + self, + node_id: str, + memory: str, + metadata: dict[str, Any] | None, + user_name: str, + ) -> tuple[Any, ...]: + """Build one write row with the same property shape PolarDB stores.""" + fields = _prepare_node_metadata(dict(metadata or {})) + fields["user_name"] = user_name + fields.setdefault("delete_time", "") + fields.setdefault("delete_record_id", "") + now = datetime.now(timezone.utc).isoformat() + created_at = fields.pop("created_at", now) + updated_at = fields.pop("updated_at", now) + for field_name in ("sources", "usage"): + value = fields.get(field_name) + if isinstance(value, list): + fields[field_name] = [ + item if isinstance(item, str) else json.dumps(item) for item in value + ] + embedding = fields.pop("embedding", None) + if not isinstance(embedding, list) or not embedding: + embedding = [round(random.uniform(-0.2, 0.2), 6) for _ in range(self._vector_dim())] + else: + embedding = [float(item) for item in embedding] + properties = { + "id": node_id, + "memory": memory, + "created_at": created_at, + "updated_at": updated_at, + "delete_time": fields.get("delete_time", ""), + "delete_record_id": fields.get("delete_record_id", ""), + **fields, + } + return ( + node_id, + memory, + json.dumps(properties, ensure_ascii=False), + embedding, + user_name, + created_at, + updated_at, + ) - # Serialize sources if present - if metadata.get("sources"): - metadata["sources"] = [ - json.dumps(s) if not isinstance(s, str) else s for s in metadata["sources"] - ] + def add_node(self, id: str, memory: str, metadata: dict[str, Any], user_name: str) -> None: + """Add a memory node.""" + if not user_name: + raise ValueError("add_node requires user_name") + self.add_nodes_batch( + [{"id": id, "memory": memory, "metadata": metadata}], + user_name, + ) + def add_nodes_batch(self, nodes: list[dict[str, Any]], user_name: str) -> None: + """Insert every node for one tenant in a single statement.""" + if not nodes: + return + if not user_name: + raise ValueError("add_nodes_batch requires user_name") + rows: list[tuple[Any, ...]] = [] + for node in nodes: + try: + rows.append( + self._prepare_node_for_insert( + node["id"], + node["memory"], + node.get("metadata", {}), + user_name, + ) + ) + except Exception: + logger.error( + "add_nodes_batch failed to prepare node %s", + node.get("id", "unknown"), + exc_info=True, + ) + if not rows: + return + memories = self._physical_table("memories", user_name) + dim = self._vector_dim() + values_sql = ",".join([f"(%s, %s, %s, %s::halfvec({dim}), %s, %s, %s)"] * len(rows)) + params: list[Any] = [value for row in rows for value in row] conn = self._get_conn() try: with conn.cursor() as cur: - if embedding: - cur.execute( - f""" - INSERT INTO {self.schema}.memories - (id, memory, properties, embedding, user_name, created_at, updated_at) - VALUES (%s, %s, %s, %s::vector, %s, %s, %s) - ON CONFLICT (id) DO UPDATE SET - memory = EXCLUDED.memory, - properties = EXCLUDED.properties, - embedding = EXCLUDED.embedding, - updated_at = EXCLUDED.updated_at - """, - ( - id, - memory, - json.dumps(metadata), - embedding, - user_name, - created_at, - updated_at, - ), - ) - else: - cur.execute( - f""" - INSERT INTO {self.schema}.memories - (id, memory, properties, user_name, created_at, updated_at) - VALUES (%s, %s, %s, %s, %s, %s) - ON CONFLICT (id) DO UPDATE SET - memory = EXCLUDED.memory, - properties = EXCLUDED.properties, - updated_at = EXCLUDED.updated_at + cur.execute( + f""" + INSERT INTO {memories} + (id, memory, properties, embedding, user_name, created_at, updated_at) + VALUES {values_sql} + ON CONFLICT (user_name, id) DO UPDATE SET + memory = EXCLUDED.memory, + properties = EXCLUDED.properties, + embedding = EXCLUDED.embedding, + updated_at = EXCLUDED.updated_at + WHERE "Memory".user_name = EXCLUDED.user_name """, - (id, memory, json.dumps(metadata), user_name, created_at, updated_at), - ) + params, + ) finally: self._put_conn(conn) - def add_nodes_batch(self, nodes: list[dict[str, Any]], user_name: str | None = None) -> None: - """Batch add memory nodes.""" - for node in nodes: - self.add_node( - id=node["id"], - memory=node["memory"], - metadata=node.get("metadata", {}), - user_name=user_name, - ) - def update_node(self, id: str, fields: dict[str, Any], user_name: str | None = None) -> None: """Update node fields.""" user_name = user_name or self.user_name if not fields: return + fields = fields.copy() # Get current node current = self.get_node(id, user_name=user_name) @@ -327,7 +483,8 @@ def update_node(self, id: str, fields: dict[str, Any], user_name: str | None = N embedding = fields.pop("embedding", None) memory = fields.pop("memory", current.get("memory", "")) props.update(fields) - props["updated_at"] = datetime.utcnow().isoformat() + props["updated_at"] = datetime.now(timezone.utc).isoformat() + memories = self._physical_table("memories", user_name) conn = self._get_conn() try: @@ -335,8 +492,8 @@ def update_node(self, id: str, fields: dict[str, Any], user_name: str | None = N if embedding: cur.execute( f""" - UPDATE {self.schema}.memories - SET memory = %s, properties = %s, embedding = %s::vector, updated_at = NOW() + UPDATE {memories} + SET memory = %s, properties = %s, embedding = %s::halfvec({self._vector_dim()}), updated_at = NOW() WHERE id = %s AND user_name = %s """, (memory, json.dumps(props), embedding, id, user_name), @@ -344,7 +501,7 @@ def update_node(self, id: str, fields: dict[str, Any], user_name: str | None = N else: cur.execute( f""" - UPDATE {self.schema}.memories + UPDATE {memories} SET memory = %s, properties = %s, updated_at = NOW() WHERE id = %s AND user_name = %s """, @@ -356,21 +513,23 @@ def update_node(self, id: str, fields: dict[str, Any], user_name: str | None = N def delete_node(self, id: str, user_name: str | None = None) -> None: """Delete a node and its edges.""" user_name = user_name or self.user_name + memories = self._physical_table("memories", user_name) + edges = self._physical_table("edges", user_name) conn = self._get_conn() try: with conn.cursor() as cur: # Delete edges cur.execute( f""" - DELETE FROM {self.schema}.edges - WHERE source_id = %s OR target_id = %s + DELETE FROM {edges} + WHERE user_name = %s AND (source_id = %s OR target_id = %s) """, - (id, id), + (user_name, id, id), ) # Delete node cur.execute( f""" - DELETE FROM {self.schema}.memories + DELETE FROM {memories} WHERE id = %s AND user_name = %s """, (id, user_name), @@ -378,22 +537,34 @@ def delete_node(self, id: str, user_name: str | None = None) -> None: finally: self._put_conn(conn) - def get_node(self, id: str, include_embedding: bool = False, **kwargs) -> dict[str, Any] | None: + def get_node( + self, id: str, include_embedding: bool = False, user_name: str | None = None + ) -> dict[str, Any] | None: """Get a single node by ID.""" - user_name = kwargs.get("user_name") or self.user_name + relation = self._tenant_relation("memories", [user_name] if user_name else []) conn = self._get_conn() try: with conn.cursor() as cur: cols = "id, memory, properties, created_at, updated_at" if include_embedding: cols += ", embedding" - cur.execute( - f""" - SELECT {cols} FROM {self.schema}.memories - WHERE id = %s AND user_name = %s - """, - (id, user_name), - ) + cols += ", user_name" + if user_name: + cur.execute( + f""" + SELECT {cols} FROM {relation} + WHERE id = %s AND user_name = %s + """, + (id, user_name), + ) + else: + cur.execute( + f""" + SELECT {cols} FROM {relation} + WHERE id = %s + """, + (id,), + ) row = cur.fetchone() if not row: return None @@ -402,32 +573,77 @@ def get_node(self, id: str, include_embedding: bool = False, **kwargs) -> dict[s self._put_conn(conn) def get_nodes( - self, ids: list, include_embedding: bool = False, **kwargs + self, ids: list[str], user_name: str | None = None, **kwargs ) -> list[dict[str, Any]]: """Get multiple nodes by IDs.""" if not ids: return [] - user_name = kwargs.get("user_name") or self.user_name + include_embedding = bool(kwargs.get("include_embedding", False)) + relation = self._tenant_relation("memories", [user_name] if user_name else []) conn = self._get_conn() try: with conn.cursor() as cur: cols = "id, memory, properties, created_at, updated_at" if include_embedding: cols += ", embedding" - cur.execute( - f""" - SELECT {cols} FROM {self.schema}.memories - WHERE id = ANY(%s) AND user_name = %s - """, - (ids, user_name), - ) + cols += ", user_name" + if user_name: + cur.execute( + f""" + SELECT {cols} FROM {relation} + WHERE id = ANY(%s) AND user_name = %s + AND COALESCE(properties->>'status', 'activated') <> 'archived' + """, + (ids, user_name), + ) + else: + cur.execute( + f""" + SELECT {cols} FROM {relation} + WHERE id = ANY(%s) + AND COALESCE(properties->>'status', 'activated') <> 'archived' + """, + (ids,), + ) return [self._parse_row(row, include_embedding) for row in cur.fetchall()] finally: self._put_conn(conn) + @staticmethod + def _normalize_node_properties( + raw_properties: dict[str, Any], user_name: str | None = None + ) -> dict[str, Any]: + """Restore the logical PolarDB metadata shape from relational storage.""" + properties = dict(raw_properties) + if user_name: + properties["user_name"] = user_name + + sources = properties.get("sources") + if isinstance(sources, list): + normalized_sources: list[Any] = [] + for source in sources: + if isinstance(source, str): + try: + parsed_source = json.loads(source) + except (json.JSONDecodeError, TypeError): + parsed_source = {"type": "doc", "content": source} + normalized_sources.append(parsed_source) + elif isinstance(source, dict): + normalized_sources.append(source) + else: + normalized_sources.append({"type": "doc", "content": str(source)}) + properties["sources"] = normalized_sources + + return properties + def _parse_row(self, row, include_embedding: bool = False) -> dict[str, Any]: """Parse database row to node dict.""" - props = row[2] if isinstance(row[2], dict) else json.loads(row[2] or "{}") + raw_props = row[2] if isinstance(row[2], dict) else json.loads(row[2] or "{}") + user_name_index = 6 if include_embedding else 5 + user_name = row[user_name_index] if len(row) > user_name_index else None + props = self._normalize_node_properties(raw_props, user_name=user_name) + props["id"] = row[0] + props["memory"] = row[1] or "" props["created_at"] = row[3].isoformat() if row[3] else None props["updated_at"] = row[4].isoformat() if row[4] else None result = { @@ -436,9 +652,21 @@ def _parse_row(self, row, include_embedding: bool = False) -> dict[str, Any]: "metadata": props, } if include_embedding and len(row) > 5: - result["metadata"]["embedding"] = row[5] + result["metadata"]["embedding"] = self._coerce_embedding(row[5]) return result + @staticmethod + def _coerce_embedding(value: Any) -> list[float]: + """Normalize pgvector values returned as lists, tuples, or text.""" + if value is None: + return [] + if isinstance(value, str): + value = value.strip().strip("[]") + if not value: + return [] + return [float(item) for item in value.split(",")] + return [float(item) for item in value] + @staticmethod def _is_safe_field_name(field: str) -> bool: """Validate field names used in dynamic SQL fragments.""" @@ -486,31 +714,40 @@ def _build_single_filter_condition( op_map = {"gt": ">", "lt": "<", "gte": ">=", "lte": "<="} sql_op = op_map[op] if raw_key in timestamp_fields or raw_key.endswith("_at"): - parts.append(f"({text_expr})::timestamptz {sql_op} %s::timestamptz") + parts.append(f"({text_expr})::timestamp {sql_op} %s::timestamp") params.append(op_value) else: parts.append(f"NULLIF({text_expr}, '')::numeric {sql_op} %s") params.append(op_value) elif op == "contains": - if raw_key in array_fields: - parts.append(f"{json_expr} @> %s::jsonb") - params.append(json.dumps([op_value])) - else: - parts.append(f"{text_expr} ILIKE %s") - params.append(f"%{op_value}%") + values = op_value if isinstance(op_value, list) else [op_value] + or_parts = [] + for item in values: + or_parts.append(f"{json_expr} @> %s::jsonb") + params.append(json.dumps([item], ensure_ascii=False)) + parts.append("(" + " OR ".join(or_parts) + ")") elif op == "in": if not isinstance(op_value, list): raise ValueError( - f"in operator expects list for '{key}', got {type(op_value).__name__}" + f"in operator expects list for '{key}', " + f"got {type(op_value).__name__}" ) - if raw_key in array_fields: - parts.append(f"{json_expr} ?| %s") - params.append([str(v) for v in op_value]) + if len(op_value) == 0: + parts.append("FALSE") + elif raw_key in array_fields or raw_key == "related_id": + or_parts = [] + for item in op_value: + or_parts.append(f"{json_expr} @> %s::jsonb") + params.append(json.dumps([str(item)], ensure_ascii=False)) + parts.append("(" + " OR ".join(or_parts) + ")") else: parts.append(f"{text_expr} = ANY(%s)") params.append([str(v) for v in op_value]) elif op == "like": - parts.append(f"{text_expr} ILIKE %s") + parts.append(f"{text_expr} LIKE %s") + params.append(f"%{op_value}%") + elif op == "nolike": + parts.append(f"{text_expr} NOT LIKE %s") params.append(f"%{op_value}%") else: raise ValueError(f"Unsupported filter operator: {op}") @@ -532,6 +769,7 @@ def _build_single_filter_condition( def _build_filter_where_clause(self, filter_dict: dict[str, Any], params: list[Any]) -> str: """Build SQL WHERE fragment from filter dict.""" + filter_dict = self.parse_filter(filter_dict) if not filter_dict: return "" @@ -542,7 +780,7 @@ def _build_filter_where_clause(self, filter_dict: dict[str, Any], params: list[A parts: list[str] = [] for cond in and_conditions: if isinstance(cond, dict): - cond_sql = self._build_single_filter_condition(cond, params) + cond_sql = self._build_filter_where_clause(cond, params) if cond_sql: parts.append(f"({cond_sql})") return " AND ".join(parts) @@ -554,7 +792,7 @@ def _build_filter_where_clause(self, filter_dict: dict[str, Any], params: list[A parts: list[str] = [] for cond in or_conditions: if isinstance(cond, dict): - cond_sql = self._build_single_filter_condition(cond, params) + cond_sql = self._build_filter_where_clause(cond, params) if cond_sql: parts.append(f"({cond_sql})") return f"({' OR '.join(parts)})" if parts else "" @@ -562,6 +800,55 @@ def _build_filter_where_clause(self, filter_dict: dict[str, Any], params: list[A cond_sql = self._build_single_filter_condition(filter_dict, params) return cond_sql or "" + def parse_filter(self, filter_dict: dict | None = None): + """Apply the same implicit info.* field routing as the PolarDB backend.""" + if filter_dict is None: + return None + full_fields = { + "id", + "key", + "tags", + "type", + "usage", + "memory", + "status", + "sources", + "user_id", + "graph_id", + "user_name", + "background", + "confidence", + "created_at", + "session_id", + "updated_at", + "memory_type", + "node_type", + "info", + "source", + "file_ids", + "project_id", + "manager_user_id", + "delete_time", + "related_id", + "message_ids", + } + + def normalize(condition: Any) -> Any: + if not isinstance(condition, dict): + return condition + normalized: dict[str, Any] = {} + for key, value in condition.items(): + if key.lower() in {"and", "or"} and isinstance(value, list): + normalized[key] = [normalize(item) for item in value] + continue + normalized_key = ( + key if key in full_fields or key.startswith("info.") else f"info.{key}" + ) + normalized[normalized_key] = value + return normalized + + return normalize(filter_dict) + def delete_node_by_prams( self, writable_cube_ids: list[str] | None = None, @@ -571,7 +858,8 @@ def delete_node_by_prams( ) -> int: """Delete nodes by memory_ids, file_ids, or filter.""" logger.info( - "[delete_node_by_prams] memory_ids: %s, file_ids: %s, filter: %s, writable_cube_ids: %s", + "[delete_node_by_prams] memory_ids: %s, file_ids: %s, " + "filter: %s, writable_cube_ids: %s", memory_ids, file_ids, filter, @@ -600,7 +888,8 @@ def delete_node_by_prams( if not where_conditions: logger.warning( - "[delete_node_by_prams] No nodes to delete (no memory_ids, file_ids, or filter provided)" + "[delete_node_by_prams] No nodes to delete " + "(no memory_ids, file_ids, or filter provided)" ) return 0 @@ -609,32 +898,148 @@ def delete_node_by_prams( params.append(writable_cube_ids) where_clause = " AND ".join(where_conditions) + memory_tables = self._physical_tables("memories", writable_cube_ids) + edge_tables = self._physical_tables("edges", writable_cube_ids) conn = self._get_conn() try: with conn.cursor() as cur: - query = f""" - WITH to_delete AS ( - SELECT id - FROM {self.schema}.memories - WHERE {where_clause} - ), - deleted_edges AS ( - DELETE FROM {self.schema}.edges e + deleted_count = 0 + for memories, edges in zip(memory_tables, edge_tables, strict=True): + query = f""" + WITH to_delete AS ( + SELECT id, user_name + FROM {memories} + WHERE {where_clause} + ), + deleted_edges AS ( + DELETE FROM {edges} e + USING to_delete d + WHERE e.user_name = d.user_name + AND (e.source_id = d.id OR e.target_id = d.id) + ) + DELETE FROM {memories} m USING to_delete d - WHERE e.source_id = d.id OR e.target_id = d.id - ) - DELETE FROM {self.schema}.memories m - USING to_delete d - WHERE m.id = d.id - """ - cur.execute(query, params) - deleted_count = cur.rowcount if cur.rowcount is not None else 0 + WHERE m.id = d.id + """ + cur.execute(query, params) + deleted_count += cur.rowcount if cur.rowcount is not None else 0 logger.info("[delete_node_by_prams] Deleted %s nodes", deleted_count) return deleted_count finally: self._put_conn(conn) + @staticmethod + def _normalize_cube_memory_groups( + cube_memory_groups: list[dict[str, Any]], + ) -> list[tuple[str, str]]: + """Normalize and de-duplicate (tenant, memory-id) requests.""" + pairs: list[tuple[str, str]] = [] + seen: set[tuple[str, str]] = set() + for group in cube_memory_groups: + cube_id = str(group.get("cube_id") or "").strip() + if not cube_id: + continue + for raw_memory_id in group.get("memory_ids") or []: + memory_id = str(raw_memory_id).strip() + pair = (cube_id, memory_id) + if memory_id and pair not in seen: + seen.add(pair) + pairs.append(pair) + return pairs + + def delete_node_by_cube_memory_groups(self, cube_memory_groups: list[dict[str, Any]]) -> int: + """Delete exactly the requested (cube, memory-id) pairs. + + PolarDB locates these pairs in one of 400 schemas. PostgreSQL keeps the + same isolation rule in a shared table by joining both user_name and id. + """ + pairs = self._normalize_cube_memory_groups(cube_memory_groups) + if not pairs: + return 0 + user_names = [pair[0] for pair in pairs] + memory_ids = [pair[1] for pair in pairs] + tenant_names = list(dict.fromkeys(user_names)) + memory_tables = self._physical_tables("memories", tenant_names) + edge_tables = self._physical_tables("edges", tenant_names) + + conn = self._get_conn() + try: + with conn.cursor() as cur: + deleted_count = 0 + for memories, edges in zip(memory_tables, edge_tables, strict=True): + cur.execute( + f""" + WITH requested(user_name, memory_id) AS ( + SELECT * FROM unnest(%s::text[], %s::text[]) + ), to_delete AS ( + SELECT m.id, m.user_name + FROM {memories} m + JOIN requested + ON requested.user_name = m.user_name + AND requested.memory_id = m.id + ), deleted_edges AS ( + DELETE FROM {edges} e + USING to_delete d + WHERE e.user_name = d.user_name + AND (e.source_id = d.id OR e.target_id = d.id) + ), deleted AS ( + DELETE FROM {memories} m + USING to_delete d + WHERE m.id = d.id AND m.user_name = d.user_name + RETURNING 1 + ) + SELECT COUNT(*) FROM deleted + """, + (user_names, memory_ids), + ) + row = cur.fetchone() + deleted_count += int(row[0]) if row and row[0] is not None else 0 + return deleted_count + finally: + self._put_conn(conn) + + def get_user_names_by_cube_memory_groups( + self, cube_memory_groups: list[dict[str, Any]] + ) -> dict[str, str | None]: + """Resolve memory ownership without scanning unrelated tenants.""" + raw_ids = [ + str(memory_id).strip() + for group in cube_memory_groups + for memory_id in (group.get("memory_ids") or []) + if str(memory_id).strip() + ] + result: dict[str, str | None] = dict.fromkeys(raw_ids) + pairs = self._normalize_cube_memory_groups(cube_memory_groups) + if not pairs: + return result + + user_names = [pair[0] for pair in pairs] + memory_ids = [pair[1] for pair in pairs] + memories = self._tenant_relation("memories", list(dict.fromkeys(user_names)), alias="m") + conn = self._get_conn() + try: + with conn.cursor() as cur: + cur.execute( + f""" + WITH requested(user_name, memory_id) AS ( + SELECT * FROM unnest(%s::text[], %s::text[]) + ) + SELECT requested.memory_id, m.user_name + FROM requested + LEFT JOIN {memories} + ON m.id = requested.memory_id + AND m.user_name = requested.user_name + """, + (user_names, memory_ids), + ) + for memory_id, owner in cur.fetchall(): + if owner: + result[str(memory_id)] = str(owner) + return result + finally: + self._put_conn(conn) + # ========================================================================= # Edge Management # ========================================================================= @@ -643,16 +1048,36 @@ def add_edge( self, source_id: str, target_id: str, type: str, user_name: str | None = None ) -> None: """Create an edge between nodes.""" + user_name = user_name or self.user_name + memories = self._physical_table("memories", user_name) + edges = self._physical_table("edges", user_name) conn = self._get_conn() try: with conn.cursor() as cur: cur.execute( f""" - INSERT INTO {self.schema}.edges (source_id, target_id, edge_type) - VALUES (%s, %s, %s) - ON CONFLICT (source_id, target_id, edge_type) DO NOTHING + INSERT INTO {edges} + (user_name, source_id, target_id, edge_type) + SELECT %s, %s, %s, %s + WHERE EXISTS ( + SELECT 1 FROM {memories} + WHERE id = %s AND user_name = %s + ) AND EXISTS ( + SELECT 1 FROM {memories} + WHERE id = %s AND user_name = %s + ) + ON CONFLICT (user_name, source_id, target_id, edge_type) DO NOTHING """, - (source_id, target_id, type), + ( + user_name, + source_id, + target_id, + type, + source_id, + user_name, + target_id, + user_name, + ), ) finally: self._put_conn(conn) @@ -661,31 +1086,62 @@ def delete_edge( self, source_id: str, target_id: str, type: str, user_name: str | None = None ) -> None: """Delete an edge.""" + user_name = user_name or self.user_name + edges = self._physical_table("edges", user_name) conn = self._get_conn() try: with conn.cursor() as cur: cur.execute( f""" - DELETE FROM {self.schema}.edges - WHERE source_id = %s AND target_id = %s AND edge_type = %s + DELETE FROM {edges} + WHERE user_name = %s + AND source_id = %s AND target_id = %s AND edge_type = %s """, - (source_id, target_id, type), + (user_name, source_id, target_id, type), ) finally: self._put_conn(conn) - def edge_exists(self, source_id: str, target_id: str, type: str) -> bool: + def edge_exists( + self, + source_id: str, + target_id: str, + type: str = "ANY", + direction: str = "OUTGOING", + user_name: str | None = None, + ) -> bool: """Check if edge exists.""" + user_name = user_name or self.user_name + direction = direction.upper() + if direction not in {"OUTGOING", "INCOMING", "ANY"}: + raise ValueError("direction must be OUTGOING, INCOMING, or ANY") + if direction == "INCOMING": + source_id, target_id = target_id, source_id + + direction_sql = "source_id = %s AND target_id = %s" + params: list[Any] = [user_name, source_id, target_id] + if direction == "ANY": + direction_sql = ( + "((source_id = %s AND target_id = %s) OR (source_id = %s AND target_id = %s))" + ) + params = [user_name, source_id, target_id, target_id, source_id] + + type_sql = "" + if type != "ANY": + type_sql = " AND edge_type = %s" + params.append(type) + + edges = self._physical_table("edges", user_name) conn = self._get_conn() try: with conn.cursor() as cur: cur.execute( f""" - SELECT 1 FROM {self.schema}.edges - WHERE source_id = %s AND target_id = %s AND edge_type = %s + SELECT 1 FROM {edges} + WHERE user_name = %s AND {direction_sql}{type_sql} LIMIT 1 """, - (source_id, target_id, type), + params, ) return cur.fetchone() is not None finally: @@ -696,43 +1152,132 @@ def edge_exists(self, source_id: str, target_id: str, type: str) -> bool: # ========================================================================= def get_neighbors( - self, id: str, type: str, direction: Literal["in", "out", "both"] = "out" + self, + id: str, + type: str, + direction: Literal["in", "out", "both"] = "out", ) -> list[str]: """Get neighboring node IDs.""" + user_name = self.user_name + edges = self._physical_table("edges", user_name) conn = self._get_conn() try: with conn.cursor() as cur: if direction == "out": cur.execute( f""" - SELECT target_id FROM {self.schema}.edges - WHERE source_id = %s AND edge_type = %s + SELECT target_id FROM {edges} + WHERE user_name = %s AND source_id = %s AND edge_type = %s """, - (id, type), + (user_name, id, type), ) elif direction == "in": cur.execute( f""" - SELECT source_id FROM {self.schema}.edges - WHERE target_id = %s AND edge_type = %s + SELECT source_id FROM {edges} + WHERE user_name = %s AND target_id = %s AND edge_type = %s """, - (id, type), + (user_name, id, type), ) else: # both cur.execute( f""" - SELECT target_id FROM {self.schema}.edges WHERE source_id = %s AND edge_type = %s + SELECT target_id FROM {edges} + WHERE user_name = %s AND source_id = %s AND edge_type = %s UNION - SELECT source_id FROM {self.schema}.edges WHERE target_id = %s AND edge_type = %s + SELECT source_id FROM {edges} + WHERE user_name = %s AND target_id = %s AND edge_type = %s """, - (id, type, id, type), + (user_name, id, type, user_name, id, type), ) return [row[0] for row in cur.fetchall()] finally: self._put_conn(conn) + def get_children_with_embeddings( + self, id: str, user_name: str | None = None + ) -> list[dict[str, Any]]: + """Return PARENT-edge children with vectors for structure optimization.""" + user_name = user_name or self.user_name + memories = self._physical_table("memories", user_name) + edges = self._physical_table("edges", user_name) + conn = self._get_conn() + try: + with conn.cursor() as cur: + cur.execute( + f""" + SELECT child.id, child.embedding, child.memory + FROM {edges} e + JOIN {memories} child + ON child.id = e.target_id AND child.user_name = e.user_name + WHERE e.user_name = %s + AND e.source_id = %s + AND e.edge_type = 'PARENT' + AND child.deleted_at IS NULL + ORDER BY e.id + """, + (user_name, id), + ) + return [ + { + "id": row[0], + "embedding": self._coerce_embedding(row[1]), + "memory": row[2] or "", + } + for row in cur.fetchall() + ] + finally: + self._put_conn(conn) + + def get_edges( + self, + id: str, + type: str = "ANY", + direction: str = "ANY", + user_name: str | None = None, + ) -> list[dict[str, str]]: + """Return tenant-scoped edges connected to a node.""" + user_name = user_name or self.user_name + direction = direction.upper() + if direction not in {"OUTGOING", "INCOMING", "ANY"}: + raise ValueError("direction must be OUTGOING, INCOMING, or ANY") + + conditions = ["user_name = %s"] + params: list[Any] = [user_name] + if direction == "OUTGOING": + conditions.append("source_id = %s") + params.append(id) + elif direction == "INCOMING": + conditions.append("target_id = %s") + params.append(id) + else: + conditions.append("(source_id = %s OR target_id = %s)") + params.extend([id, id]) + if type != "ANY": + conditions.append("edge_type = %s") + params.append(type) + + edges = self._physical_table("edges", user_name) + conn = self._get_conn() + try: + with conn.cursor() as cur: + cur.execute( + f""" + SELECT source_id, target_id, edge_type + FROM {edges} + WHERE {" AND ".join(conditions)} + ORDER BY id + """, + params, + ) + return [{"from": row[0], "to": row[1], "type": row[2]} for row in cur.fetchall()] + finally: + self._put_conn(conn) + def get_path(self, source_id: str, target_id: str, max_depth: int = 3) -> list[str]: """Get path between nodes using recursive CTE.""" + user_name = self.user_name + edges = self._physical_table("edges", user_name) conn = self._get_conn() try: with conn.cursor() as cur: @@ -740,13 +1285,14 @@ def get_path(self, source_id: str, target_id: str, max_depth: int = 3) -> list[s f""" WITH RECURSIVE path AS ( SELECT source_id, target_id, ARRAY[source_id] as nodes, 1 as depth - FROM {self.schema}.edges - WHERE source_id = %s + FROM {edges} + WHERE user_name = %s AND source_id = %s UNION ALL SELECT e.source_id, e.target_id, p.nodes || e.source_id, p.depth + 1 - FROM {self.schema}.edges e + FROM {edges} e JOIN path p ON e.source_id = p.target_id - WHERE p.depth < %s AND NOT e.source_id = ANY(p.nodes) + WHERE e.user_name = %s + AND p.depth < %s AND NOT e.source_id = ANY(p.nodes) ) SELECT nodes || target_id as full_path FROM path @@ -754,34 +1300,95 @@ def get_path(self, source_id: str, target_id: str, max_depth: int = 3) -> list[s ORDER BY depth LIMIT 1 """, - (source_id, max_depth, target_id), + (user_name, source_id, user_name, max_depth, target_id), ) row = cur.fetchone() return row[0] if row else [] finally: self._put_conn(conn) - def get_subgraph(self, center_id: str, depth: int = 2) -> list[str]: - """Get subgraph around center node.""" + def get_subgraph( + self, + center_id: str, + depth: int = 2, + center_status: str = "activated", + user_name: str | None = None, + ) -> dict[str, Any]: + """Return the PolarDB-compatible local subgraph structure.""" + if not 1 <= depth <= 5: + raise ValueError("depth must be 1-5") + center_id = center_id.strip('"') + user_name = user_name or self.user_name + core_node = self.get_node(center_id, user_name=user_name) + if core_node is None: + return {"core_node": None, "neighbors": [], "edges": []} + actual_status = core_node.get("metadata", {}).get("status", "activated") + if center_status and actual_status != center_status: + return {"core_node": None, "neighbors": [], "edges": []} + + edges_table = self._physical_table("edges", user_name) conn = self._get_conn() try: with conn.cursor() as cur: cur.execute( f""" - WITH RECURSIVE subgraph AS ( - SELECT %s::text as node_id, 0 as level - UNION - SELECT CASE WHEN e.source_id = s.node_id THEN e.target_id ELSE e.source_id END, - s.level + 1 - FROM {self.schema}.edges e + WITH RECURSIVE subgraph(node_id, level, path) AS ( + SELECT %s::text, 0, ARRAY[%s::text] + UNION ALL + SELECT + CASE + WHEN e.source_id = s.node_id THEN e.target_id + ELSE e.source_id + END, + s.level + 1, + s.path || CASE + WHEN e.source_id = s.node_id THEN e.target_id + ELSE e.source_id + END + FROM {edges_table} e JOIN subgraph s ON (e.source_id = s.node_id OR e.target_id = s.node_id) - WHERE s.level < %s + WHERE e.user_name = %s + AND s.level < %s + AND NOT ( + CASE + WHEN e.source_id = s.node_id THEN e.target_id + ELSE e.source_id + END + ) = ANY(s.path) ) - SELECT DISTINCT node_id FROM subgraph - """, - (center_id, depth), + SELECT DISTINCT node_id FROM subgraph ORDER BY node_id + """, + (center_id, center_id, user_name, depth), ) - return [row[0] for row in cur.fetchall()] + node_ids = [str(row[0]) for row in cur.fetchall()] + neighbor_ids = [node_id for node_id in node_ids if node_id != center_id] + neighbors = ( + self.get_nodes(neighbor_ids, user_name=user_name) if neighbor_ids else [] + ) + + if node_ids: + cur.execute( + f""" + SELECT source_id, target_id, edge_type + FROM {edges_table} + WHERE user_name = %s + AND source_id = ANY(%s) + AND target_id = ANY(%s) + ORDER BY id + """, + (user_name, node_ids, node_ids), + ) + edges = [ + {"source": row[0], "target": row[1], "type": row[2]} + for row in cur.fetchall() + ] + else: + edges = [] + return { + "core_node": core_node, + "neighbors": neighbors, + "edges": edges, + } finally: self._put_conn(conn) @@ -789,95 +1396,638 @@ def get_context_chain(self, id: str, type: str = "FOLLOWS") -> list[str]: """Get ordered chain following relationship type.""" return self.get_neighbors(id, type, "out") + def get_neighbors_by_tag( + self, + tags: list[str], + exclude_ids: list[str], + top_k: int = 5, + min_overlap: int = 1, + include_embedding: bool = False, + user_name: str | None = None, + ) -> list[dict[str, Any]]: + """Find active tenant memories ranked by tag overlap.""" + if not tags or top_k <= 0: + return [] + user_name = user_name or self.user_name + params: list[Any] = [user_name] + exclude_sql = "" + if exclude_ids: + exclude_sql = "AND id <> ALL(%s)" + params.append(exclude_ids) + + cols = "id, memory, properties, created_at, updated_at" + if include_embedding: + cols += ", embedding" + cols += ", user_name" + memories = self._physical_table("memories", user_name) + conn = self._get_conn() + try: + with conn.cursor() as cur: + cur.execute( + f""" + SELECT {cols} + FROM {memories} + WHERE user_name = %s + AND COALESCE(properties->>'status', 'activated') = 'activated' + AND COALESCE(properties->>'node_type', '') <> 'reasoning' + AND COALESCE(properties->>'memory_type', '') <> 'WorkingMemory' + {exclude_sql} + """, + params, + ) + ranked: list[tuple[int, dict[str, Any]]] = [] + requested_tags = set(tags) + for row in cur.fetchall(): + node = self._parse_row(row, include_embedding) + node_tags = node.get("metadata", {}).get("tags", []) + if isinstance(node_tags, str): + try: + node_tags = json.loads(node_tags) + except (TypeError, json.JSONDecodeError): + node_tags = [] + overlap = len(requested_tags.intersection(node_tags or [])) + if overlap >= min_overlap: + ranked.append((overlap, node)) + ranked.sort(key=lambda item: item[0], reverse=True) + return [node for _, node in ranked[:top_k]] + finally: + self._put_conn(conn) + # ========================================================================= # Search Operations # ========================================================================= - def search_by_embedding( + def _effective_user_names( self, - vector: list[float], - top_k: int = 5, - scope: str | None = None, - status: str | None = None, - threshold: float | None = None, - search_filter: dict | None = None, user_name: str | None = None, - filter: dict | None = None, knowledgebase_ids: list[str] | None = None, - **kwargs, - ) -> list[dict]: - """Search nodes by vector similarity using pgvector.""" - user_name = user_name or self.user_name + ) -> list[str]: + """Resolve the memory cubes that a query is allowed to read.""" + names: list[str] = [] + primary = user_name or self.user_name + if primary: + names.append(primary) + for knowledgebase_id in knowledgebase_ids or []: + if knowledgebase_id and knowledgebase_id not in names: + names.append(knowledgebase_id) + return names + + def _shard_count(self) -> int: + return int(getattr(self.config, "shard_count", 400)) + + def _remainder_cache(self) -> dict[str, int]: + cache = getattr(self, "_partition_remainders", None) + if cache is None: + cache = {} + self._partition_remainders = cache + return cache + + def _partition_remainder(self, user_name: str, conn=None) -> int: + """Return the PolarDB MD5 shard number for one tenant.""" + del conn + cache = self._remainder_cache() + cached = cache.get(user_name) + if cached is not None: + return cached + remainder = ( + int(hashlib.md5(user_name.encode("utf-8")).hexdigest(), 16) % self._shard_count() + ) + cache[user_name] = remainder + return remainder - # Build WHERE clause - conditions = ["embedding IS NOT NULL"] - params = [] + def _qualified_partition(self, table: str, remainder: int) -> str: + physical_names = { + "memories": "Memory", + "edges": "Edges", + } + physical = physical_names.get(table) + if physical is None: + raise ValueError(f"Invalid partitioned table: {table}") + schema = f"{self.schema}_graph_{remainder}" + if not self._is_safe_field_name(schema): + raise ValueError(f"Invalid partition schema: {schema}") + return f'"{schema}"."{physical}"' + + def _all_partitions_relation(self, table: str, alias: str | None = None) -> str: + """Read every hash partition explicitly, as PolarDB unions every shard.""" + branches = " UNION ALL ".join( + f"SELECT * FROM {self._qualified_partition(table, remainder)}" + for remainder in range(self._shard_count()) + ) + return f"({branches}) {alias or table}" - if user_name: + def _tenant_relation( + self, + table: str, + user_names: list[str] | None, + alias: str | None = None, + conn=None, + ) -> str: + """Return one child table, or a union of only the touched partitions.""" + names = [name for name in (user_names or []) if name] + if not names: + return self._all_partitions_relation(table, alias) + remainders = sorted({self._partition_remainder(name, conn) for name in names}) + if len(remainders) == 1: + relation = self._qualified_partition(table, remainders[0]) + else: + branches = " UNION ALL ".join( + f"SELECT * FROM {self._qualified_partition(table, remainder)}" + for remainder in remainders + ) + relation = f"({branches})" + if alias is None: + alias = table + return f"{relation} {alias}" if alias else relation + + def _physical_tables(self, table: str, user_names: list[str] | None, conn=None) -> list[str]: + """Real tables a write can target. A union subquery cannot be updated.""" + names = [name for name in (user_names or []) if name] + if not names: + return [ + self._qualified_partition(table, remainder) + for remainder in range(self._shard_count()) + ] + remainders = sorted({self._partition_remainder(name, conn) for name in names}) + return [self._qualified_partition(table, remainder) for remainder in remainders] + + def _physical_table(self, table: str, user_name: str | None, conn=None) -> str: + """Return the one partition table PolarDB would address for this tenant.""" + if not user_name: + return f"{self.schema}.{table}" + return self._qualified_partition(table, self._partition_remainder(user_name, conn)) + + def _vector_dim(self) -> int: + dim = int(getattr(self.config, "embedding_dimension", 1024)) + if dim < 1 or dim > 4096: + raise ValueError(f"Invalid embedding dimension: {dim}") + return dim + + def _ensure_hnsw_search_settings(self, conn) -> None: + """Match PolarDB's HNSW session settings once for each pooled connection.""" + ready = getattr(self, "_hnsw_ready_ids", None) + if ready is None: + ready = set() + self._hnsw_ready_ids = ready + marker = id(conn) + if marker in ready: + return + with conn.cursor() as cur: + cur.execute( + """ + SELECT set_config('hnsw.ef_search', '100', false), + set_config('hnsw.iterative_scan', 'relaxed_order', false) + """ + ) + ready.add(marker) + + def _projected_field_exprs(self, return_fields: list[str] | None) -> list[tuple[str, str]]: + projected: list[tuple[str, str]] = [] + for field in self._validate_return_fields(return_fields): + if field in {"id", "memory", "score", "user_name", "created_at", "updated_at"}: + continue + if field == "embedding": + projected.append((field, "embedding")) + else: + projected.append((field, f"properties->'{field}'")) + return projected + + @staticmethod + def _decode_projected_value(value: Any) -> Any: + if isinstance(value, str): + try: + return json.loads(value) + except (json.JSONDecodeError, TypeError): + return value + return value + + def _build_projected_search_result( + self, row: tuple[Any, ...], extra_fields: list[str] + ) -> dict[str, Any]: + created_at, updated_at = row[3], row[4] + result: dict[str, Any] = { + "id": row[0], + "score": float(row[1]), + "memory": row[2] or "", + "user_name": row[5], + } + if created_at is not None: + result["created_at"] = ( + created_at.isoformat() if hasattr(created_at, "isoformat") else created_at + ) + if updated_at is not None: + result["updated_at"] = ( + updated_at.isoformat() if hasattr(updated_at, "isoformat") else updated_at + ) + for offset, field in enumerate(extra_fields): + result[field] = self._decode_projected_value(row[6 + offset]) + return result + + def _append_user_name_condition( + self, conditions: list[str], params: list[Any], user_names: list[str] + ) -> None: + if len(user_names) == 1: conditions.append("user_name = %s") - params.append(user_name) + params.append(user_names[0]) + elif user_names: + conditions.append("user_name = ANY(%s)") + params.append(user_names) + def _build_search_conditions( + self, + params: list[Any], + *, + user_name: str | None = None, + knowledgebase_ids: list[str] | None = None, + scope: str | None = None, + status: str | None = None, + search_filter: dict | None = None, + filter: dict | None = None, + default_activated: bool = True, + ) -> list[str]: + conditions: list[str] = [] + user_names = self._effective_user_names(user_name, knowledgebase_ids) + self._append_user_name_condition(conditions, params, user_names) if scope: conditions.append("properties->>'memory_type' = %s") params.append(scope) - if status: conditions.append("properties->>'status' = %s") params.append(status) - else: - conditions.append( - "(properties->>'status' = 'activated' OR properties->>'status' IS NULL)" - ) + elif default_activated: + conditions.append("properties->>'status' = 'activated'") + + for filter_dict in (search_filter, filter): + if filter_dict: + filter_sql = self._build_filter_where_clause(filter_dict, params) + if filter_sql: + conditions.append(f"({filter_sql})") + return conditions + + def _build_search_result( + self, row: tuple[Any, ...], return_fields: list[str] | None + ) -> dict[str, Any]: + result: dict[str, Any] = {"id": row[0], "score": float(row[1])} + fields = self._validate_return_fields(return_fields) + if not fields: + return result + + memory = row[2] or "" + created_at, updated_at, user_name = row[4], row[5], row[6] + raw_properties = row[3] if isinstance(row[3], dict) else json.loads(row[3] or "{}") + properties = dict(raw_properties) + properties["user_name"] = user_name + properties.update( + { + "id": row[0], + "memory": memory, + "created_at": created_at.isoformat() if created_at else None, + "updated_at": updated_at.isoformat() if updated_at else None, + "user_name": user_name, + } + ) + for field in fields: + if field != "id" and field in properties: + result[field] = properties[field] + return result - if search_filter: - for k, v in search_filter.items(): - conditions.append(f"properties->>'{k}' = %s") - params.append(str(v)) + def _build_keyword_result( + self, row: tuple[Any, ...], return_fields: list[str] | None + ) -> dict[str, Any]: + result: dict[str, Any] = {"id": row[0]} + fields = self._validate_return_fields(return_fields) + if not fields: + return result + + raw_properties = row[2] if isinstance(row[2], dict) else json.loads(row[2] or "{}") + properties = dict(raw_properties) + properties["user_name"] = row[5] + properties.update( + { + "id": row[0], + "memory": row[1] or "", + "created_at": row[3].isoformat() if row[3] else None, + "updated_at": row[4].isoformat() if row[4] else None, + "user_name": row[5], + } + ) + for field in fields: + if field != "id" and field in properties: + result[field] = properties[field] + return result + def search_by_embedding( + self, + vector: list[float], + user_name: str, + top_k: int = 5, + scope: str | None = None, + status: str | None = None, + threshold: float | None = None, + search_filter: dict | None = None, + filter: dict | None = None, + knowledgebase_ids: list[str] | None = None, + return_fields: list[str] | None = None, + light_weight_mode: bool = False, + **kwargs, + ) -> list[dict]: + """Search nodes by vector similarity using pgvector.""" + if light_weight_mode and not return_fields: + return_fields = [ + "memory", + "memory_type", + "user_name", + "status", + "key", + "tags", + "confidence", + "source", + ] + params: list[Any] = [] + conditions = ["embedding IS NOT NULL"] + conditions.extend( + self._build_search_conditions( + params, + user_name=user_name, + knowledgebase_ids=knowledgebase_ids, + scope=scope, + status=status, + search_filter=search_filter, + filter=filter, + ) + ) where_clause = " AND ".join(conditions) + relation = self._tenant_relation( + "memories", + self._effective_user_names(user_name, knowledgebase_ids), + ) - # pgvector cosine distance: 1 - (a <=> b) gives similarity score + # Match PolarDB: one distance, index-ordered LIMIT, then drop rows at or past 0.9. + dim = self._vector_dim() + distance_sql = "embedding <=> (SELECT query_vector FROM q)" conn = self._get_conn() try: + self._ensure_hnsw_search_settings(conn) with conn.cursor() as cur: + projected = self._projected_field_exprs(return_fields) if light_weight_mode else [] + if light_weight_mode: + inner_columns = "memory, created_at, updated_at, user_name" + extra_inner = "".join( + f', {expression} AS "{field}"' for field, expression in projected + ) + extra_outer = "".join(f', "{field}"' for field, _ in projected) + else: + inner_columns = "memory, properties, created_at, updated_at, user_name" + extra_inner = "" + extra_outer = "" cur.execute( f""" - SELECT id, 1 - (embedding <=> %s::vector) as score - FROM {self.schema}.memories - WHERE {where_clause} - ORDER BY embedding <=> %s::vector - LIMIT %s - """, - (vector, *params, vector, top_k), + WITH q AS ( + SELECT %s::halfvec({dim}) AS query_vector + ), + t AS MATERIALIZED ( + SELECT COALESCE(properties->>'id', id) AS id, + ({distance_sql}) AS scope_distance, + {inner_columns} + {extra_inner} + FROM {relation} + WHERE {where_clause} + ORDER BY {distance_sql} + LIMIT %s + ) + SELECT id, + ((1 - scope_distance) + 1) / 2.0 AS score, + {inner_columns} + {extra_outer} + FROM t + WHERE scope_distance < 0.9 + """, + (vector, *params, top_k), ) results = [] for row in cur.fetchall(): score = float(row[1]) if threshold is None or score >= threshold: - results.append({"id": row[0], "score": score}) + if light_weight_mode: + results.append( + self._build_projected_search_result( + row, [field for field, _ in projected] + ) + ) + else: + results.append(self._build_search_result(row, return_fields)) return results finally: self._put_conn(conn) - def get_by_metadata( + def search_by_fulltext( self, - filters: list[dict[str, Any]], + query_words: list[str], + top_k: int = 10, + scope: str | None = None, + status: str | None = None, + threshold: float | None = None, + search_filter: dict | None = None, + user_name: str | None = None, + filter: dict | None = None, + knowledgebase_ids: list[str] | None = None, + tsvector_field: str = "properties_tsvector_zh", + tsquery_config: str = "jiebacfg", + return_fields: list[str] | None = None, + **kwargs, + ) -> list[dict]: + """Search with PolarDB's AND tsquery on one tenant partition.""" + terms = [str(word).strip() for word in query_words if str(word).strip()] + if not terms: + return [] + + query_config = tsquery_config or getattr(self.config, "fulltext_config", "simple") + if not re.match(r"^[A-Za-z_][A-Za-z0-9_]*$", query_config): + raise ValueError(f"Invalid PostgreSQL text search config: {query_config}") + quoted_terms = [] + for term in terms: + if len(term) >= 2 and term[0] == term[-1] and term[0] in {"'", '"'}: + term = term[1:-1] + quoted_terms.append("'" + term.replace("'", "''") + "'") + params: list[Any] = [" & ".join(quoted_terms)] + conditions = self._build_search_conditions( + params, + user_name=user_name, + knowledgebase_ids=knowledgebase_ids, + scope=scope, + status=status, + search_filter=search_filter, + filter=filter, + ) + where_clause = " AND ".join(conditions) if conditions else "TRUE" + relation = self._tenant_relation( + "memories", + self._effective_user_names(user_name, knowledgebase_ids), + ) + + conn = self._get_conn() + try: + with conn.cursor() as cur: + cur.execute( + f""" + WITH q AS ( + SELECT to_tsquery('{query_config}', %s) AS query + ) + SELECT COALESCE(properties->>'id', id) AS id, + ts_rank(search_vector, q.query) AS score, + memory, properties, created_at, updated_at, user_name + FROM {relation} + CROSS JOIN q + WHERE {where_clause} + AND search_vector @@ q.query + ORDER BY score DESC, updated_at DESC + LIMIT %s + """, + (*params, top_k), + ) + output = [] + for row in cur.fetchall(): + result = self._build_search_result(row, return_fields) + if threshold is None or result["score"] >= threshold: + output.append(result) + return output + finally: + self._put_conn(conn) + + def search_by_keywords_tfidf( + self, + query_words: list[str], + scope: str | None = None, status: str | None = None, + search_filter: dict | None = None, user_name: str | None = None, filter: dict | None = None, knowledgebase_ids: list[str] | None = None, + tsvector_field: str = "properties_tsvector_zh", + tsquery_config: str = "jiebaqry", + return_fields: list[str] | None = None, + **kwargs, + ) -> list[dict]: + """Return keyword matches with PolarDB's OR tsquery and no score.""" + if not user_name: + return [] + terms = [str(word).strip() for word in query_words if str(word).strip()] + if not terms: + return [] + + query_config = tsquery_config or getattr(self.config, "fulltext_config", "simple") + if not re.match(r"^[A-Za-z_][A-Za-z0-9_]*$", query_config): + raise ValueError(f"Invalid PostgreSQL text search config: {query_config}") + quoted_terms = [] + for term in terms: + if len(term) >= 2 and term[0] == term[-1] and term[0] in {"'", '"'}: + term = term[1:-1] + quoted_terms.append("'" + term.replace("'", "''") + "'") + params: list[Any] = [" | ".join(quoted_terms)] + conditions = self._build_search_conditions( + params, + user_name=user_name, + knowledgebase_ids=knowledgebase_ids, + scope=scope, + status=status, + search_filter=search_filter, + filter=filter, + ) + where_clause = " AND ".join(conditions) if conditions else "TRUE" + relation = self._tenant_relation( + "memories", + self._effective_user_names(user_name, knowledgebase_ids), + ) + + conn = self._get_conn() + try: + with conn.cursor() as cur: + cur.execute( + f""" + WITH q AS ( + SELECT to_tsquery('{query_config}', %s) AS query + ) + SELECT COALESCE(properties->>'id', id) AS id, memory, properties, created_at, updated_at, user_name + FROM {relation} + CROSS JOIN q + WHERE {where_clause} + AND search_vector @@ q.query + """, + (*params,), + ) + return [self._build_keyword_result(row, return_fields) for row in cur.fetchall()] + finally: + self._put_conn(conn) + + def search_by_keywords_like( + self, + query_word: str, + scope: str | None = None, + status: str | None = None, + search_filter: dict | None = None, + user_name: str | None = None, + filter: dict | None = None, + knowledgebase_ids: list[str] | None = None, + return_fields: list[str] | None = None, + **kwargs, + ) -> list[dict]: + """Fallback substring search compatible with the PolarDB adapter.""" + if not user_name: + return [] + pattern = f"%{query_word}%" + params: list[Any] = [] + conditions = self._build_search_conditions( + params, + user_name=user_name, + knowledgebase_ids=knowledgebase_ids, + search_filter=search_filter, + filter=filter, + status=status, + scope=scope, + ) + conditions.append("COALESCE(properties->>'memory', '') LIKE %s") + params.append(pattern) + relation = self._tenant_relation( + "memories", + self._effective_user_names(user_name, knowledgebase_ids), + ) + + conn = self._get_conn() + try: + with conn.cursor() as cur: + cur.execute( + f""" + SELECT COALESCE(properties->>'id', id) AS id, memory, properties, created_at, updated_at, user_name + FROM {relation} + WHERE {" AND ".join(conditions)} + """, + params, + ) + return [self._build_keyword_result(row, return_fields) for row in cur.fetchall()] + finally: + self._put_conn(conn) + + def get_by_metadata( + self, + filters: list[dict[str, Any]], + user_name: str | None = None, + filter: dict | None = None, + knowledgebase_ids: list | None = None, user_name_flag: bool = True, + status: str | None = None, + **kwargs, ) -> list[str]: """Get node IDs matching metadata filters.""" - user_name = user_name or self.user_name + if not user_name: + raise ValueError("get_by_metadata requires user_name") + conditions: list[str] = [] + params: list[Any] = [] + user_names: list[str] = [] - conditions = [] - params = [] - - if user_name_flag and user_name: - conditions.append("user_name = %s") - params.append(user_name) + if user_name_flag: + user_names = self._effective_user_names(user_name, knowledgebase_ids) + self._append_user_name_condition(conditions, params, user_names) if status: conditions.append("properties->>'status' = %s") @@ -887,29 +2037,52 @@ def get_by_metadata( field = f["field"] op = f.get("op", "=") value = f["value"] + text_expr, json_expr = self._field_expr(field) if op == "=": - conditions.append(f"properties->>'{field}' = %s") + conditions.append(f"{text_expr} = %s") params.append(str(value)) elif op == "in": - placeholders = ",".join(["%s"] * len(value)) - conditions.append(f"properties->>'{field}' IN ({placeholders})") - params.extend([str(v) for v in value]) + if not isinstance(value, list): + raise ValueError("in operator expects a list") + conditions.append(f"{text_expr} = ANY(%s)") + params.append([str(item) for item in value]) elif op in (">", ">=", "<", "<="): - conditions.append(f"(properties->>'{field}')::numeric {op} %s") + conditions.append(f"NULLIF({text_expr}, '')::numeric {op} %s") params.append(value) elif op == "contains": - conditions.append(f"properties->'{field}' @> %s::jsonb") - params.append(json.dumps([value])) + values = value if isinstance(value, list) else [value] + or_parts = [] + for item in values: + or_parts.append(f"{json_expr} @> %s::jsonb") + params.append(json.dumps([item], ensure_ascii=False)) + conditions.append("(" + " OR ".join(or_parts) + ")") + elif op == "like": + conditions.append(f"{text_expr} LIKE %s") + params.append(f"%{value}%") + elif op == "starts_with": + conditions.append(f"{text_expr} LIKE %s") + params.append(f"{value}%") + elif op == "ends_with": + conditions.append(f"{text_expr} LIKE %s") + params.append(f"%{value}") + else: + raise ValueError(f"Unsupported operator: {op}") + + if filter: + filter_sql = self._build_filter_where_clause(filter, params) + if filter_sql: + conditions.append(f"({filter_sql})") where_clause = " AND ".join(conditions) if conditions else "TRUE" + relation = self._tenant_relation("memories", user_names) conn = self._get_conn() try: with conn.cursor() as cur: cur.execute( f""" - SELECT id FROM {self.schema}.memories + SELECT id FROM {relation} WHERE {where_clause} """, params, @@ -921,23 +2094,34 @@ def get_by_metadata( def get_all_memory_items( self, scope: str, + user_name: str | None = None, include_embedding: bool = False, - status: str | None = None, filter: dict | None = None, - knowledgebase_ids: list[str] | None = None, - **kwargs, + knowledgebase_ids: list | None = None, + status: str | None = None, ) -> list[dict]: """Get all memory items of a specific type.""" - user_name = kwargs.get("user_name") or self.user_name - - conditions = ["properties->>'memory_type' = %s", "user_name = %s"] - params = [scope, user_name] + if not user_name: + return [] + if scope not in {"WorkingMemory", "LongTermMemory", "UserMemory", "OuterMemory"}: + raise ValueError(f"Unsupported memory type scope: {scope}") - if status: - conditions.append("properties->>'status' = %s") - params.append(status) + params: list[Any] = [] + conditions = self._build_search_conditions( + params, + user_name=user_name, + knowledgebase_ids=knowledgebase_ids, + scope=scope, + status=status, + filter=filter, + default_activated=False, + ) - where_clause = " AND ".join(conditions) + where_clause = " AND ".join(conditions) if conditions else "TRUE" + relation = self._tenant_relation( + "memories", + self._effective_user_names(user_name, knowledgebase_ids), + ) conn = self._get_conn() try: @@ -945,10 +2129,12 @@ def get_all_memory_items( cols = "id, memory, properties, created_at, updated_at" if include_embedding: cols += ", embedding" + cols += ", user_name" cur.execute( f""" - SELECT {cols} FROM {self.schema}.memories + SELECT {cols} FROM {relation} WHERE {where_clause} + LIMIT 100 """, params, ) @@ -957,29 +2143,44 @@ def get_all_memory_items( self._put_conn(conn) def get_structure_optimization_candidates( - self, scope: str, include_embedding: bool = False + self, + scope: str, + include_embedding: bool = False, + user_name: str | None = None, ) -> list[dict]: """Find isolated nodes (no edges).""" - user_name = self.user_name + if not user_name: + raise ValueError("get_structure_optimization_candidates requires user_name") + memories = self._tenant_relation("memories", [user_name]) + edges = self._tenant_relation("edges", [user_name]) conn = self._get_conn() try: with conn.cursor() as cur: cols = "m.id, m.memory, m.properties, m.created_at, m.updated_at" + if include_embedding: + cols += ", m.embedding" + cols += ", m.user_name" cur.execute( f""" SELECT {cols} - FROM {self.schema}.memories m - LEFT JOIN {self.schema}.edges e1 ON m.id = e1.source_id - LEFT JOIN {self.schema}.edges e2 ON m.id = e2.target_id + FROM {memories} m + LEFT JOIN {edges} e1 + ON m.id = e1.source_id + AND e1.user_name = m.user_name + AND e1.edge_type = 'PARENT' + LEFT JOIN {edges} e2 + ON m.id = e2.target_id + AND e2.user_name = m.user_name + AND e2.edge_type = 'PARENT' WHERE m.properties->>'memory_type' = %s AND m.user_name = %s AND m.properties->>'status' = 'activated' AND e1.id IS NULL AND e2.id IS NULL - """, + """, (scope, user_name), ) - return [self._parse_row(row, False) for row in cur.fetchall()] + return [self._parse_row(row, include_embedding) for row in cur.fetchall()] finally: self._put_conn(conn) @@ -987,6 +2188,190 @@ def get_structure_optimization_candidates( # Maintenance # ========================================================================= + def get_memory_count(self, memory_type: str, user_name: str | None = None) -> int: + """Count active memories of one type for a tenant.""" + user_name = user_name or self.user_name + relation = self._tenant_relation("memories", [user_name] if user_name else []) + conn = self._get_conn() + try: + with conn.cursor() as cur: + cur.execute( + f""" + SELECT COUNT(*) + FROM {relation} + WHERE user_name = %s + AND properties->>'memory_type' = %s + AND COALESCE(properties->>'status', 'activated') = 'activated' + """, + (user_name, memory_type), + ) + row = cur.fetchone() + return int(row[0]) if row else 0 + finally: + self._put_conn(conn) + + def node_not_exist(self, scope: str, user_name: str | None = None) -> int: + """Return 1 when no active node exists for the requested scope.""" + return int(self.get_memory_count(scope, user_name=user_name) == 0) + + def count_nodes(self, scope: str, user_name: str | None = None) -> int: + """Compatibility alias for memory counts.""" + return self.get_memory_count(scope, user_name=user_name) + + def get_user_names_by_memory_ids(self, memory_ids: list[str]) -> dict[str, str | None]: + normalized_ids = list( + dict.fromkeys( + str(memory_id).strip() for memory_id in memory_ids if str(memory_id).strip() + ) + ) + if not normalized_ids: + return {} + result: dict[str, str | None] = dict.fromkeys(normalized_ids) + memories = self._all_partitions_relation("memories") + conn = self._get_conn() + try: + with conn.cursor() as cur: + cur.execute( + f""" + SELECT id, user_name + FROM {memories} + WHERE id = ANY(%s) + """, + (normalized_ids,), + ) + result.update({str(row[0]): row[1] for row in cur.fetchall()}) + return result + finally: + self._put_conn(conn) + + def exist_user_name(self, user_name: str) -> dict[str, bool]: + memories = self._physical_table("memories", user_name) + conn = self._get_conn() + try: + with conn.cursor() as cur: + cur.execute( + f"SELECT EXISTS(SELECT 1 FROM {memories} WHERE user_name = %s)", + (user_name,), + ) + row = cur.fetchone() + return {user_name: bool(row and row[0])} + finally: + self._put_conn(conn) + + def delete_node_by_mem_cube_id( + self, + mem_cube_id: str, + delete_record_id: str, + hard_delete: bool = False, + ) -> int: + """Soft-delete a tenant's memories, or purge a previously deleted batch.""" + if not mem_cube_id: + raise ValueError("delete_node_by_mem_cube_id mem_cube_id is required") + if not delete_record_id: + raise ValueError("delete_node_by_mem_cube_id delete_record_id is required") + + memories = self._physical_table("memories", mem_cube_id) + edges = self._physical_table("edges", mem_cube_id) + conn = self._get_conn() + try: + with conn.cursor() as cur: + if hard_delete: + cur.execute( + f""" + WITH deleted AS ( + DELETE FROM {memories} + WHERE user_name = %s + AND properties->>'delete_record_id' = %s + RETURNING id + ), deleted_edges AS ( + DELETE FROM {edges} e + USING deleted d + WHERE e.user_name = %s + AND (e.source_id = d.id OR e.target_id = d.id) + RETURNING e.id + ) + SELECT COUNT(*) FROM deleted + """, + (mem_cube_id, delete_record_id, mem_cube_id), + ) + row = cur.fetchone() + return int(row[0]) if row else 0 + else: + deleted_at = datetime.now(timezone.utc).isoformat() + cur.execute( + f""" + UPDATE {memories} + SET properties = properties || %s::jsonb, + deleted_at = %s::timestamptz, + updated_at = NOW() + WHERE user_name = %s + AND COALESCE(properties->>'status', 'activated') <> 'deleted' + """, + ( + json.dumps( + { + "status": "deleted", + "delete_time": deleted_at, + "delete_record_id": delete_record_id, + } + ), + deleted_at, + mem_cube_id, + ), + ) + return max(int(cur.rowcount or 0), 0) + finally: + self._put_conn(conn) + + def recover_memory_by_mem_cube_id( + self, + mem_cube_id: str, + delete_record_id: str, + ) -> int: + """Recover one tenant soft-delete batch.""" + if not mem_cube_id: + raise ValueError("recover_memory_by_mem_cube_id mem_cube_id is required") + if not delete_record_id: + raise ValueError("recover_memory_by_mem_cube_id delete_record_id is required") + + memories = self._physical_table("memories", mem_cube_id) + conn = self._get_conn() + try: + with conn.cursor() as cur: + cur.execute( + f""" + UPDATE {memories} + SET properties = properties || %s::jsonb, + deleted_at = NULL, + updated_at = NOW() + WHERE user_name = %s + AND properties->>'delete_record_id' = %s + AND properties->>'status' = 'deleted' + """, + ( + json.dumps( + { + "status": "activated", + "delete_time": "", + "delete_record_id": "", + } + ), + mem_cube_id, + delete_record_id, + ), + ) + return max(int(cur.rowcount or 0), 0) + finally: + self._put_conn(conn) + + def drop_database(self) -> None: + """Compatibility operation: clear only the configured tenant. + + The standard PostgreSQL backend is shared, so dropping the physical + database or schema would delete other tenants. + """ + self.clear(user_name=self.user_name) + def deduplicate_nodes(self) -> None: """Not implemented - handled at application level.""" @@ -1012,6 +2397,8 @@ def get_grouped_counts( user_name = user_name or self.user_name if not group_fields: raise ValueError("group_fields cannot be empty") + if any(not self._is_safe_field_name(field) for field in group_fields): + raise ValueError("group_fields contains an invalid field name") # Build SELECT and GROUP BY clauses # Fields come from JSONB properties column @@ -1033,10 +2420,11 @@ def get_grouped_counts( query_params.extend(params.values()) where_sql = " AND ".join(conditions) + memories = self._physical_table("memories", user_name) query = f""" SELECT {select_fields}, COUNT(*) AS count - FROM {self.schema}.memories + FROM {memories} WHERE {where_sql} GROUP BY {group_by} """ @@ -1067,13 +2455,15 @@ def merge_nodes(self, id1: str, id2: str) -> str: def clear(self, user_name: str | None = None) -> None: """Clear all data for user.""" user_name = user_name or self.user_name + memories = self._physical_table("memories", user_name) + edges = self._physical_table("edges", user_name) conn = self._get_conn() try: with conn.cursor() as cur: # Get all node IDs for user cur.execute( f""" - SELECT id FROM {self.schema}.memories WHERE user_name = %s + SELECT id FROM {memories} WHERE user_name = %s """, (user_name,), ) @@ -1083,16 +2473,17 @@ def clear(self, user_name: str | None = None) -> None: # Delete edges cur.execute( f""" - DELETE FROM {self.schema}.edges - WHERE source_id = ANY(%s) OR target_id = ANY(%s) + DELETE FROM {edges} + WHERE user_name = %s + AND (source_id = ANY(%s) OR target_id = ANY(%s)) """, - (ids, ids), + (user_name, ids, ids), ) # Delete nodes cur.execute( f""" - DELETE FROM {self.schema}.memories WHERE user_name = %s + DELETE FROM {memories} WHERE user_name = %s """, (user_name,), ) @@ -1100,36 +2491,148 @@ def clear(self, user_name: str | None = None) -> None: finally: self._put_conn(conn) - def export_graph(self, include_embedding: bool = False, **kwargs) -> dict[str, Any]: - """Export all data.""" - user_name = kwargs.get("user_name") or self.user_name + def export_graph( + self, + user_name: str | None = None, + include_embedding: bool = False, + user_id: str | None = None, + page: int | None = None, + page_size: int | None = None, + filter: dict | None = None, + memory_type: list[str] | None = None, + status: list[str] | None = None, + **kwargs, + ) -> dict[str, Any]: + """Export memories with the same filters and pagination as PolarDB.""" + + extracted_object_type: str | None = None + extracted_mem_cube_id: str | None = None + + def extract_special_values(value: Any) -> Any: + nonlocal extracted_object_type, extracted_mem_cube_id + if not isinstance(value, dict): + return value + cleaned: dict[str, Any] = {} + for key, item in value.items(): + if key in {"and", "or"} and isinstance(item, list): + children = [extract_special_values(child) for child in item] + children = [child for child in children if child not in (None, {}, [])] + if children: + cleaned[key] = children + elif key == "object_type" and isinstance(item, str): + extracted_object_type = extracted_object_type or item + elif key == "mem_cube_id" and isinstance(item, str): + extracted_mem_cube_id = extracted_mem_cube_id or item + else: + cleaned[key] = item + return cleaned or None + + filter_for_sql = extract_special_values(filter) + conditions: list[str] = [] + params: list[Any] = [] + has_object_filter = bool(extracted_object_type and extracted_mem_cube_id) + object_type = (extracted_object_type or "").strip().lower() + + if has_object_filter: + if object_type == "user": + conditions.append("user_name <> %s") + params.append(extracted_mem_cube_id) + elif object_type == "public": + conditions.append("user_name = %s") + params.append(extracted_mem_cube_id) + elif user_name: + conditions.append("user_name = %s") + params.append(user_name) + + effective_user_id = user_id or getattr(self.config, "user_id", None) + if effective_user_id: + conditions.append("properties->>'user_id' = %s") + params.append(effective_user_id) + if memory_type: + conditions.append("properties->>'memory_type' = ANY(%s)") + params.append([str(item) for item in memory_type]) + if status: + conditions.append("properties->>'status' = ANY(%s)") + params.append([str(item) for item in status]) + else: + conditions.append("COALESCE(properties->>'status', 'activated') <> 'deleted'") + conditions.append("deleted_at IS NULL") + if filter_for_sql: + filter_sql = self._build_filter_where_clause(filter_for_sql, params) + if filter_sql: + conditions.append(f"({filter_sql})") + + where_clause = " AND ".join(conditions) if conditions else "TRUE" + target_user = user_name + if has_object_filter and object_type == "public": + target_user = extracted_mem_cube_id + elif has_object_filter and object_type == "user": + target_user = None + memories = self._physical_table("memories", target_user) + use_pagination = page is not None and page_size is not None + if use_pagination: + page = max(int(page), 1) + page_size = max(int(page_size), 1) + offset = (page - 1) * page_size + conn = self._get_conn() try: with conn.cursor() as cur: - # Get nodes + cur.execute( + f"SELECT COUNT(*) FROM {memories} WHERE {where_clause}", + params, + ) + count_row = cur.fetchone() + total_nodes = int(count_row[0]) if count_row else 0 + cols = "id, memory, properties, created_at, updated_at" if include_embedding: cols += ", embedding" + cols += ", user_name" + pagination_sql = "" + data_params = list(params) + if use_pagination: + pagination_sql = "LIMIT %s OFFSET %s" + data_params.extend([page_size, offset]) cur.execute( f""" - SELECT {cols} FROM {self.schema}.memories - WHERE user_name = %s - ORDER BY created_at DESC - """, - (user_name,), + SELECT {cols} + FROM {memories} + WHERE {where_clause} + ORDER BY created_at DESC NULLS LAST, id DESC + {pagination_sql} + """, + data_params, ) nodes = [self._parse_row(row, include_embedding) for row in cur.fetchall()] - # Get edges node_ids = [n["id"] for n in nodes] - if node_ids: + node_user_names = [ + n.get("metadata", {}).get("user_name") or user_name for n in nodes + ] + if node_ids and all(node_user_names): + edges_table = self._tenant_relation( + "edges", + list(dict.fromkeys(str(name) for name in node_user_names if name)), + alias="e", + conn=conn, + ) cur.execute( f""" - SELECT source_id, target_id, edge_type - FROM {self.schema}.edges - WHERE source_id = ANY(%s) OR target_id = ANY(%s) - """, - (node_ids, node_ids), + WITH selected_nodes(user_name, node_id) AS ( + SELECT * FROM unnest(%s::text[], %s::text[]) + ) + SELECT e.source_id, e.target_id, e.edge_type + FROM {edges_table} + JOIN selected_nodes AS source_node + ON source_node.user_name = e.user_name + AND source_node.node_id = e.source_id + JOIN selected_nodes AS target_node + ON target_node.user_name = e.user_name + AND target_node.node_id = e.target_id + ORDER BY e.id + """, + (node_user_names, node_ids), ) edges = [ {"source": row[0], "target": row[1], "type": row[2]} @@ -1141,7 +2644,7 @@ def export_graph(self, include_embedding: bool = False, **kwargs) -> dict[str, A return { "nodes": nodes, "edges": edges, - "total_nodes": len(nodes), + "total_nodes": total_nodes, "total_edges": len(edges), } finally: @@ -1164,6 +2667,7 @@ def import_graph(self, data: dict[str, Any], user_name: str | None = None) -> No source_id=edge["source"], target_id=edge["target"], type=edge["type"], + user_name=user_name, ) def close(self): diff --git a/tests/graph_dbs/test_postgres_400_compat.py b/tests/graph_dbs/test_postgres_400_compat.py new file mode 100644 index 000000000..bd23fd8ff --- /dev/null +++ b/tests/graph_dbs/test_postgres_400_compat.py @@ -0,0 +1,391 @@ +import json + +from datetime import datetime, timezone +from types import SimpleNamespace +from unittest.mock import MagicMock + +import pytest + +from memos.graph_dbs.postgres import PostgresGraphDB + + +@pytest.fixture +def postgres_db(): + db = PostgresGraphDB.__new__(PostgresGraphDB) + db.schema = "memos" + db.db_name = "memos" + db.user_name = "tenant-a" + db._pool_closed = False + db.config = SimpleNamespace( + embedding_dimension=3, + fulltext_config="simple", + vector_index_type="hnsw", + hnsw_m=16, + hnsw_ef_construction=64, + ivfflat_lists=100, + shard_count=400, + ) + + cursor = MagicMock() + connection = MagicMock() + connection.cursor.return_value.__enter__.return_value = cursor + db._get_conn = MagicMock(return_value=connection) + db._put_conn = MagicMock() + db._partition_remainders = { + "tenant-a": 17, + "tenant-b": 17, + "kb-1": 17, + } + return db, cursor + + +def _executed_sql(cursor: MagicMock) -> str: + return "\n".join(str(call.args[0]) for call in cursor.execute.call_args_list) + + +def test_schema_does_not_create_profile_storage(postgres_db): + db, cursor = postgres_db + + db._init_schema() + + sql = _executed_sql(cursor) + assert "profile_templates" not in sql + assert "profile_instances" not in sql + + +def test_schema_creates_400_md5_memory_shards(postgres_db): + db, cursor = postgres_db + + db._init_schema() + + sql = _executed_sql(cursor) + assert "PARTITION BY HASH" not in sql + assert '"Memory"' in sql + assert "embedding halfvec(" in sql + assert "memos_graph_0" in sql + assert "memos_graph_399" in sql + assert "MODULUS" not in sql + assert sql.count("CREATE SCHEMA IF NOT EXISTS") == 401 + assert "PRIMARY KEY (user_name, id)" in sql + + +def test_schema_rejects_legacy_nonpartitioned_parent(postgres_db): + db, cursor = postgres_db + cursor.fetchall.return_value = [("memories", "r")] + + with pytest.raises(RuntimeError, match="configure a new MEMOS_SCHEMA"): + db._init_schema() + + +def test_schema_skips_partition_ddl_when_layout_is_complete(postgres_db): + db, cursor = postgres_db + cursor.fetchone.return_value = (400,) + + db._init_schema() + + sql = _executed_sql(cursor) + assert sql.count("CREATE SCHEMA IF NOT EXISTS") == 1 + assert "memos_graph_0" not in sql + + +def test_node_upsert_targets_composite_partition_key(postgres_db): + db, cursor = postgres_db + + db.add_node( + "memory-1", + "memory", + {"embedding": [1.0, 0.0, 0.0]}, + user_name="tenant-a", + ) + + assert "ON CONFLICT (user_name, id)" in _executed_sql(cursor) + + +def test_batch_insert_uses_one_statement_and_polardb_properties(postgres_db): + db, cursor = postgres_db + + db.add_nodes_batch( + [ + {"id": "m1", "memory": "one", "metadata": {"embedding": [1.0, 0.0, 0.0]}}, + {"id": "m2", "memory": "two", "metadata": {"embedding": [0.0, 1.0, 0.0]}}, + ], + user_name="tenant-a", + ) + + assert cursor.execute.call_count == 1 + query, params = cursor.execute.call_args.args + assert query.count("::halfvec(") == 2 + assert "ON CONFLICT (user_name, id)" in query + first_properties = json.loads(params[2]) + second_properties = json.loads(params[9]) + assert first_properties["id"] == "m1" + assert first_properties["memory"] == "one" + assert second_properties["id"] == "m2" + assert second_properties["memory"] == "two" + assert "embedding" not in first_properties + + +def test_node_upsert_persists_tenant_in_metadata(postgres_db): + db, cursor = postgres_db + + db.add_node( + "memory-1", + "memory", + {"embedding": [1.0, 0.0, 0.0]}, + user_name="tenant-a", + ) + + _, params = cursor.execute.call_args.args + properties = json.loads(params[2]) + assert properties["user_name"] == "tenant-a" + assert properties["delete_time"] == "" + assert properties["delete_record_id"] == "" + + +def test_batch_node_metadata_matches_polardb_shape(postgres_db): + db, _ = postgres_db + now = datetime.now(timezone.utc) + + node = db._parse_row( + ( + "memory-1", + "service HTTP comparison memory", + {"status": "activated"}, + now, + now, + ) + ) + + assert node["metadata"]["id"] == "memory-1" + assert node["metadata"]["memory"] == "service HTTP comparison memory" + + +def test_parse_row_restores_tenant_and_deserializes_sources(postgres_db): + db, _ = postgres_db + now = datetime.now(timezone.utc) + source = {"type": "chat", "role": "user", "content": "hello"} + + node = db._parse_row( + ( + "memory-1", + "memory", + {"sources": [json.dumps(source)]}, + now, + now, + "tenant-a", + ) + ) + + assert node["metadata"]["user_name"] == "tenant-a" + assert node["metadata"]["sources"] == [source] + + +def test_new_polardb_business_methods_are_available(): + required_methods = { + "delete_node_by_cube_memory_groups", + "get_user_names_by_cube_memory_groups", + "get_children_with_embeddings", + "get_neighbors_by_tag", + } + + missing = sorted(name for name in required_methods if not hasattr(PostgresGraphDB, name)) + assert missing == [] + + +def test_get_subgraph_matches_polardb_return_shape(postgres_db): + db, cursor = postgres_db + core = { + "id": "core", + "memory": "core memory", + "metadata": {"status": "activated"}, + } + neighbor = { + "id": "neighbor", + "memory": "neighbor memory", + "metadata": {"status": "activated"}, + } + db.get_node = MagicMock(return_value=core) + db.get_nodes = MagicMock(return_value=[neighbor]) + cursor.fetchall.side_effect = [ + [("core",), ("neighbor",)], + [("core", "neighbor", "RELATE_TO")], + ] + + result = db.get_subgraph( + "core", + depth=2, + center_status="activated", + user_name="tenant-a", + ) + + assert result == { + "core_node": core, + "neighbors": [neighbor], + "edges": [{"source": "core", "target": "neighbor", "type": "RELATE_TO"}], + } + assert "user_name = %s" in _executed_sql(cursor) + db.get_node.assert_called_once_with("core", user_name="tenant-a") + db.get_nodes.assert_called_once_with(["neighbor"], user_name="tenant-a") + + +def test_cube_group_delete_pairs_ids_with_tenants(postgres_db): + db, cursor = postgres_db + cursor.fetchone.return_value = (2,) + + deleted = db.delete_node_by_cube_memory_groups( + [ + {"cube_id": "tenant-a", "memory_ids": ["m1"]}, + {"cube_id": "tenant-b", "memory_ids": ["m2"]}, + ] + ) + + query, params = cursor.execute.call_args.args + assert deleted == 2 + assert "unnest" in query.lower() + assert "requested.user_name" in query + assert params == (["tenant-a", "tenant-b"], ["m1", "m2"]) + + +def test_memory_owner_lookup_preserves_missing_ids(postgres_db): + db, cursor = postgres_db + cursor.fetchall.return_value = [("m1", "tenant-a")] + + owners = db.get_user_names_by_memory_ids(["m1", "missing"]) + + assert owners == {"m1": "tenant-a", "missing": None} + + +def test_export_graph_supports_latest_filters_and_pagination(postgres_db): + db, cursor = postgres_db + now = datetime.now(timezone.utc) + cursor.fetchone.return_value = (3,) + cursor.fetchall.side_effect = [ + [ + ( + "m1", + "memory", + {"memory_type": "LongTermMemory", "status": "activated"}, + now, + now, + ) + ], + [("m1", "m2", "RELATE_TO")], + ] + + result = db.export_graph( + user_name="tenant-a", + page=2, + page_size=1, + filter={"agent_id": "agent-1"}, + memory_type=["LongTermMemory"], + status=["activated"], + ) + + sql = _executed_sql(cursor) + assert result["total_nodes"] == 3 + assert result["nodes"][0]["id"] == "m1" + assert "properties->'info'->>'agent_id'" in sql + assert "LIMIT %s OFFSET %s" in sql + assert "properties->>'memory_type' = ANY(%s)" in sql + assert "JOIN selected_nodes AS source_node" in sql + assert "source_node.user_name = e.user_name" in sql + + +def test_keyword_like_matches_polardb_filters_and_parameter_name(postgres_db): + db, cursor = postgres_db + now = datetime.now(timezone.utc) + cursor.fetchall.return_value = [ + ( + "memory-1", + "needle memory", + {"source": "conversation"}, + now, + now, + "tenant-a", + ) + ] + + result = db.search_by_keywords_like( + query_word="needle", + scope="LongTermMemory", + status="activated", + search_filter={"source": "conversation"}, + user_name="tenant-a", + knowledgebase_ids=["kb-1"], + return_fields=["memory", "source"], + ) + + query, params = cursor.execute.call_args.args + assert result == [{"id": "memory-1", "memory": "needle memory", "source": "conversation"}] + assert "user_name = ANY(%s)" in query + assert ["tenant-a", "kb-1"] in params + assert "properties->>'source'" in query + assert "properties->>'memory', '') LIKE %s" in query + + +def test_keyword_tfidf_matches_polardb_result_shape(postgres_db): + db, cursor = postgres_db + now = datetime.now(timezone.utc) + cursor.fetchall.return_value = [ + ( + "memory-1", + "needle memory", + {"source": "conversation"}, + now, + now, + "tenant-a", + ) + ] + + result = db.search_by_keywords_tfidf( + ["needle", "memory"], + scope="LongTermMemory", + user_name="tenant-a", + return_fields=["memory", "source"], + ) + + assert result == [{"id": "memory-1", "memory": "needle memory", "source": "conversation"}] + query, params = cursor.execute.call_args.args + assert params[0] == "'needle' | 'memory'" + assert "to_tsquery('jiebaqry'" in query + assert "ILIKE" not in query + + +def test_keyword_searches_require_explicit_user_name(postgres_db): + db, cursor = postgres_db + + assert db.search_by_keywords_like("needle") == [] + assert db.search_by_keywords_tfidf(["needle"]) == [] + cursor.execute.assert_not_called() + + +def test_get_all_memory_items_matches_polardb_defaults(postgres_db): + db, cursor = postgres_db + + assert db.get_all_memory_items("LongTermMemory") == [] + cursor.execute.assert_not_called() + + with pytest.raises(ValueError, match="Unsupported memory type scope"): + db.get_all_memory_items("Context", user_name="tenant-a") + + cursor.fetchall.return_value = [] + db.get_all_memory_items("LongTermMemory", user_name="tenant-a") + query, _ = cursor.execute.call_args.args + assert "properties->>'status'" not in query + + +def test_metadata_contains_list_uses_json_array_overlap(postgres_db): + db, cursor = postgres_db + cursor.fetchall.return_value = [("m1",)] + + result = db.get_by_metadata( + [{"field": "tags", "op": "contains", "value": ["blue", "green"]}], + user_name="tenant-a", + ) + + query, params = cursor.execute.call_args.args + assert result == ["m1"] + assert "properties->'tags' @> %s::jsonb" in query + assert " OR " in query + assert json.dumps(["blue"], ensure_ascii=False) in params + assert json.dumps(["green"], ensure_ascii=False) in params diff --git a/tests/graph_dbs/test_postgres_pgvector.py b/tests/graph_dbs/test_postgres_pgvector.py new file mode 100644 index 000000000..d404cf230 --- /dev/null +++ b/tests/graph_dbs/test_postgres_pgvector.py @@ -0,0 +1,461 @@ +import hashlib +import json + +from datetime import datetime, timezone +from types import SimpleNamespace +from unittest.mock import MagicMock + +import pytest + +from memos.configs.graph_db import PostgresGraphDBConfig +from memos.graph_dbs.postgres import PostgresGraphDB + + +@pytest.fixture +def postgres_db(): + db = PostgresGraphDB.__new__(PostgresGraphDB) + db.schema = "memos" + db.db_name = "memos" + db.user_name = "tenant-a" + db._pool_closed = False + db.config = SimpleNamespace( + embedding_dimension=3, + fulltext_config="simple", + vector_index_type="hnsw", + hnsw_m=16, + hnsw_ef_construction=64, + ivfflat_lists=100, + shard_count=400, + ) + db._partition_remainders = { + "tenant-a": 17, + "tenant-b": 17, + "kb-1": 17, + } + + cursor = MagicMock() + connection = MagicMock() + connection.cursor.return_value.__enter__.return_value = cursor + db._get_conn = MagicMock(return_value=connection) + db._put_conn = MagicMock() + return db, cursor + + +def _executed_sql(cursor: MagicMock) -> str: + return "\n".join(str(call.args[0]) for call in cursor.execute.call_args_list) + + +def test_postgres_pool_keeps_eight_warm_connections(): + config = PostgresGraphDBConfig( + host="postgres", + user="postgres", + password="secret", + db_name="memos", + user_name="tenant-a", + ) + assert config.minconn == 8 + assert config.maxconn == 20 + + +def test_get_conn_does_not_ping_before_the_query(): + db = PostgresGraphDB.__new__(PostgresGraphDB) + db._pool_closed = False + cursor = MagicMock() + connection = MagicMock() + connection.closed = 0 + connection.cursor.return_value.__enter__.return_value = cursor + db.pool = MagicMock() + db.pool.getconn.return_value = connection + + assert db._get_conn() is connection + cursor.execute.assert_not_called() + + +def test_postgres_config_defaults_to_current_embedding_dimension(): + config = PostgresGraphDBConfig( + host="postgres", + user="memos", + password="secret", + db_name="memos", + user_name="tenant-a", + ) + + assert config.embedding_dimension == 1024 + assert config.shard_count == 400 + + +def test_init_schema_creates_tenant_edges_fulltext_and_hnsw(postgres_db): + db, cursor = postgres_db + + db._init_schema() + + sql = _executed_sql(cursor) + assert "user_name TEXT NOT NULL" in sql + assert "UNIQUE(user_name, source_id, target_id, edge_type)" in sql + assert "search_vector tsvector" in sql + assert "properties::text" in sql + assert "USING GIN(search_vector)" in sql + assert "halfvec_cosine_ops" in sql + assert "idx_memory_embedding_halfvec" in sql + assert "embedding halfvec(" in sql + assert '"Memory"' in sql + assert "USING ivfflat" not in sql + + +def test_edge_operations_are_tenant_scoped_and_support_any_direction(postgres_db): + db, cursor = postgres_db + cursor.fetchone.return_value = (1,) + cursor.fetchall.return_value = [("source", "target", "RELATE_TO")] + + db.add_edge("source", "target", "RELATE_TO", user_name="tenant-a") + assert db.edge_exists( + "source", + "target", + "RELATE_TO", + direction="ANY", + user_name="tenant-a", + ) + edges = db.get_edges("source", type="ANY", direction="ANY", user_name="tenant-a") + + sql = _executed_sql(cursor) + assert "user_name" in sql + assert edges == [{"from": "source", "to": "target", "type": "RELATE_TO"}] + assert any( + "tenant-a" in call.args[1] for call in cursor.execute.call_args_list if len(call.args) > 1 + ) + + db.edge_exists("source", "target", type="ANY", user_name="tenant-a") + query, params = cursor.execute.call_args.args + assert "edge_type = %s" not in query + assert params == ["tenant-a", "source", "target"] + + +def test_vector_search_applies_filters_kb_ids_and_return_fields(postgres_db): + db, cursor = postgres_db + now = datetime.now(timezone.utc) + cursor.fetchall.return_value = [ + ( + "node-1", + 0.95, + "remember this", + {"status": "activated", "source": "conversation"}, + now, + now, + "tenant-a", + ) + ] + + results = db.search_by_embedding( + vector=[0.1, 0.2, 0.3], + top_k=5, + scope="LongTermMemory", + status="activated", + user_name="tenant-a", + knowledgebase_ids=["kb-1"], + filter={"and": [{"info.agent_id": "agent-1"}, {"tags": {"contains": "blue"}}]}, + return_fields=["memory", "source", "created_at"], + ) + + query, params = cursor.execute.call_args.args + assert "user_name = ANY(%s)" in query + assert "COALESCE(properties->>'id', id)" in query + assert "properties->'info'->>'agent_id'" in query + assert "properties->'tags' @> %s::jsonb" in query + assert ["tenant-a", "kb-1"] in params + assert results[0]["memory"] == "remember this" + assert results[0]["source"] == "conversation" + assert results[0]["created_at"] == now.isoformat() + + +def test_lightweight_vector_search_returns_memory_without_extra_lookup(postgres_db): + db, cursor = postgres_db + now = datetime.now(timezone.utc) + cursor.fetchall.return_value = [ + ( + "node-1", + 0.95, + "remember this", + now, + now, + "tenant-a", + '"LongTermMemory"', + '"activated"', + None, + None, + None, + None, + ) + ] + + results = db.search_by_embedding( + vector=[0.1, 0.2, 0.3], + top_k=5, + scope="LongTermMemory", + user_name="tenant-a", + light_weight_mode=True, + ) + + assert results[0]["memory"] == "remember this" + assert results[0]["memory_type"] == "LongTermMemory" + assert PostgresGraphDB.supports_lightweight_vector_search is True + assert PostgresGraphDB.prefer_lightweight_vector_search is True + + +def test_search_result_does_not_add_postgres_only_property_aliases(postgres_db): + db, _ = postgres_db + now = datetime.now(timezone.utc) + row = ( + "node-1", + 0.95, + "remember this", + {"status": "activated"}, + now, + now, + "tenant-a", + ) + + result = db._build_search_result(row, ["metadata", "properties"]) + + assert result == {"id": "node-1", "score": 0.95} + + +def test_search_result_keeps_polardb_serialized_source_shape(postgres_db): + db, _ = postgres_db + now = datetime.now(timezone.utc) + source = json.dumps({"type": "chat", "role": "user", "content": "hello"}) + row = ( + "node-1", + 0.95, + "remember this", + {"sources": [source]}, + now, + now, + "tenant-a", + ) + + result = db._build_search_result(row, ["sources"]) + + assert result["sources"] == [source] + + +def test_fulltext_search_uses_polardb_and_tsquery(postgres_db): + db, cursor = postgres_db + now = datetime.now(timezone.utc) + cursor.fetchall.return_value = [ + ( + "node-1", + 0.8, + "中文记忆内容", + {"status": "activated"}, + now, + now, + "tenant-a", + ) + ] + + results = db.search_by_fulltext( + query_words=["中文", "记忆"], + top_k=10, + scope="LongTermMemory", + user_name="tenant-a", + filter={"info.agent_id": "agent-1"}, + return_fields=["memory"], + ) + + query, params = cursor.execute.call_args.args + assert "to_tsquery('jiebacfg'" in query + assert "search_vector @@" in query + assert "ILIKE" not in query + assert "properties->'info'->>'agent_id'" in query + assert params[0] == "'中文' & '记忆'" + assert results == [{"id": "node-1", "score": 0.8, "memory": "中文记忆内容"}] + + +def test_get_node_without_tenant_searches_all_partitions(postgres_db): + db, cursor = postgres_db + now = datetime.now(timezone.utc) + cursor.fetchone.return_value = ( + "node-1", + "remember this", + {"status": "activated", "user_name": "tenant-b"}, + now, + now, + ) + + result = db.get_node("node-1") + + query, params = cursor.execute.call_args.args + assert "WHERE id = %s" in query + assert "user_name = %s" not in query + assert '"memos_graph_0"."Memory"' in query + assert '"memos_graph_399"."Memory"' in query + assert "FROM memos.memories" not in query + assert params == ("node-1",) + assert result["id"] == "node-1" + + +def test_get_node_with_tenant_remains_tenant_scoped(postgres_db): + db, cursor = postgres_db + cursor.fetchone.return_value = None + + assert db.get_node("node-1", user_name="tenant-b") is None + + query, params = cursor.execute.call_args.args + assert "WHERE id = %s AND user_name = %s" in query + assert params == ("node-1", "tenant-b") + + +def test_get_nodes_without_tenant_searches_all_partitions(postgres_db): + db, cursor = postgres_db + cursor.fetchall.return_value = [] + + assert db.get_nodes(["node-1", "node-2"]) == [] + + query, params = cursor.execute.call_args.args + assert "WHERE id = ANY(%s)" in query + assert "user_name = %s" not in query + assert '"memos_graph_0"."Memory"' in query + assert '"memos_graph_399"."Memory"' in query + assert "FROM memos.memories" not in query + assert params == (["node-1", "node-2"],) + + +def test_cube_soft_delete_recover_and_counts_are_available(postgres_db): + db, cursor = postgres_db + cursor.rowcount = 3 + cursor.fetchone.side_effect = [(3,), (0,)] + + assert db.delete_node_by_mem_cube_id("tenant-a", "delete-1") == 3 + assert db.recover_memory_by_mem_cube_id("tenant-a", "delete-1") == 3 + assert db.get_memory_count("LongTermMemory", user_name="tenant-a") == 3 + assert db.node_not_exist("UserMemory", user_name="tenant-a") == 1 + + sql = _executed_sql(cursor) + assert "delete_record_id" in sql + assert "status" in sql + assert "user_name = %s" in sql + + +def test_drop_database_is_scoped_to_current_tenant(postgres_db): + db, _cursor = postgres_db + db.clear = MagicMock() + + db.drop_database() + + db.clear.assert_called_once_with(user_name="tenant-a") + + +def test_structure_candidates_accept_tenant_and_optional_embedding(postgres_db): + db, cursor = postgres_db + now = datetime.now(timezone.utc) + cursor.fetchall.return_value = [ + ( + "node-1", + "remember this", + {"status": "activated", "memory_type": "LongTermMemory"}, + now, + now, + [0.1, 0.2, 0.3], + ) + ] + + results = db.get_structure_optimization_candidates( + "LongTermMemory", + include_embedding=True, + user_name="tenant-b", + ) + + query, params = cursor.execute.call_args.args + assert "m.embedding" in query + assert params == ("LongTermMemory", "tenant-b") + assert results[0]["metadata"]["embedding"] == [0.1, 0.2, 0.3] + + +def test_structure_candidates_only_exclude_parent_edges(postgres_db): + db, cursor = postgres_db + cursor.fetchall.return_value = [] + + db.get_structure_optimization_candidates( + "LongTermMemory", + user_name="tenant-a", + ) + + query, _ = cursor.execute.call_args.args + assert "e1.edge_type = 'PARENT'" in query + assert "e2.edge_type = 'PARENT'" in query + + +def test_time_filter_uses_timestamp_comparison(postgres_db): + db, cursor = postgres_db + cursor.fetchall.return_value = [] + + db.search_by_embedding( + [0.1, 0.2, 0.3], + user_name="tenant-a", + top_k=5, + filter={"created_at": {"gt": "2026-01-01T00:00:00"}}, + ) + + query, _params = cursor.execute.call_args.args + assert "::timestamp >" in query + assert "timestamptz" not in query + + +def test_single_tenant_vector_search_reads_one_hash_partition(postgres_db): + db, cursor = postgres_db + db._partition_remainders = {"tenant-a": 17} + cursor.fetchall.return_value = [] + + db.search_by_embedding([0.1, 0.2, 0.3], user_name="tenant-a", top_k=5) + + query, params = cursor.execute.call_args.args + assert 'FROM "memos_graph_17"."Memory"' in query + assert "FROM memos.memories" not in query + assert query.count("%s::halfvec(3)") == 1 + assert "AS MATERIALIZED" in query + assert "ORDER BY embedding <=> (SELECT query_vector FROM q)" in query + materialized_and_score, outer_filter = query.split("FROM t", 1) + materialized_body = materialized_and_score.split("AS MATERIALIZED", 1)[1] + assert "< 0.9" not in materialized_body + assert "scope_distance < 0.9" in outer_filter + assert "((1 - scope_distance) + 1) / 2.0" in materialized_and_score + assert "embedding::halfvec" not in query + assert "user_name = %s" in query + assert "user_name = ANY(%s)" not in query + assert params[0] == [0.1, 0.2, 0.3] + assert params[1] == "tenant-a" + assert params[-1] == 5 + assert any("hnsw.iterative_scan" in str(call.args[0]) for call in cursor.execute.call_args_list) + + +def test_cross_shard_vector_search_reads_only_those_partitions(postgres_db): + db, cursor = postgres_db + db._partition_remainders = {"tenant-a": 17, "kb-1": 19} + cursor.fetchall.return_value = [] + + db.search_by_embedding( + [0.1, 0.2, 0.3], + user_name="tenant-a", + knowledgebase_ids=["kb-1"], + top_k=5, + ) + + query, _params = cursor.execute.call_args.args + assert '"memos_graph_17"."Memory"' in query + assert '"memos_graph_19"."Memory"' in query + assert "UNION ALL" in query + assert "FROM memos.memories" not in query + + +def test_partition_remainder_uses_polardb_md5(postgres_db): + db, cursor = postgres_db + db._partition_remainders = {} + cursor.fetchall.return_value = [] + shard = int(hashlib.md5(b"tenant-a").hexdigest(), 16) % 400 + + db.search_by_embedding([0.1, 0.2, 0.3], user_name="tenant-a", top_k=5) + + query = cursor.execute.call_args.args[0] + assert f'"memos_graph_{shard}"."Memory"' in query + assert "satisfies_hash_partition" not in _executed_sql(cursor) + assert db._partition_remainder("tenant-a") == shard From 9b35357f1d5957886cb23562e6c07e289be45758 Mon Sep 17 00:00:00 2001 From: lils <310442317+linsheng-li@users.noreply.github.com> Date: Wed, 21 Oct 2026 22:54:22 +0800 Subject: [PATCH 25/38] fix(scheduler): initialize RabbitMQ IO thread before shutdown --- .../webservice_modules/rabbitmq_service.py | 2 +- tests/mem_scheduler/test_rabbitmq_shutdown.py | 110 ++++++++++++++++++ 2 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 tests/mem_scheduler/test_rabbitmq_shutdown.py diff --git a/src/memos/mem_scheduler/webservice_modules/rabbitmq_service.py b/src/memos/mem_scheduler/webservice_modules/rabbitmq_service.py index 3123bfdee..e39f4bbd9 100644 --- a/src/memos/mem_scheduler/webservice_modules/rabbitmq_service.py +++ b/src/memos/mem_scheduler/webservice_modules/rabbitmq_service.py @@ -61,7 +61,7 @@ def __init__(self): self.rabbitmq_conn_sleep_seconds = 1 # Thread management - self._rabbitmq_io_loop_thread = None # For IOLoop execution + self._io_loop_thread = None # For IOLoop execution self._rabbitmq_stop_flag = False # Graceful shutdown flag # Use RLock because publishing may trigger initialization, which also grabs the lock. self._rabbitmq_lock = threading.RLock() diff --git a/tests/mem_scheduler/test_rabbitmq_shutdown.py b/tests/mem_scheduler/test_rabbitmq_shutdown.py new file mode 100644 index 000000000..5cb594c43 --- /dev/null +++ b/tests/mem_scheduler/test_rabbitmq_shutdown.py @@ -0,0 +1,110 @@ +"""Native scheduler cleanup only; no models, broker or business data.""" + +import threading +import time + +from types import SimpleNamespace +from unittest.mock import Mock + +import pytest + +from memos.api import lifecycle +from memos.configs.mem_scheduler import GeneralSchedulerConfig +from memos.mem_scheduler.optimized_scheduler import OptimizedScheduler +from memos.mem_scheduler.webservice_modules.rabbitmq_service import RabbitMQSchedulerModule + + +def test_close_without_rabbitmq_initialization_is_safe_and_repeatable(): + scheduler = RabbitMQSchedulerModule() + scheduler.rabbitmq_close() + scheduler.rabbitmq_close() + assert scheduler._io_loop_thread is None + assert scheduler._rabbitmq_stop_flag is True + + +def test_early_initialization_skip_still_closes(monkeypatch): + monkeypatch.setenv("CI", "true") + monkeypatch.delenv("MEMOS_ENABLE_RABBITMQ", raising=False) + scheduler = RabbitMQSchedulerModule() + scheduler.initialize_rabbitmq() + assert scheduler._rabbitmq_initializing is False + scheduler.rabbitmq_close() + assert scheduler._io_loop_thread is None + + +def test_real_io_thread_and_connection_cleanup_still_execute(): + scheduler = RabbitMQSchedulerModule() + stopped = threading.Event() + calls = [] + scheduler.rabbitmq_channel = SimpleNamespace( + is_open=True, close=lambda: calls.append("channel") + ) + scheduler.rabbitmq_connection = SimpleNamespace( + is_open=True, + close=lambda: calls.append("connection"), + ioloop=SimpleNamespace(stop=lambda: (calls.append("ioloop"), stopped.set())), + ) + worker = threading.Thread(target=stopped.wait, daemon=True) + scheduler._io_loop_thread = worker + worker.start() + try: + scheduler.rabbitmq_close() + assert not worker.is_alive() + assert calls == ["channel", "connection", "ioloop"] + assert scheduler._rabbitmq_stop_flag is True + finally: + stopped.set() + worker.join(timeout=1) + + +def test_actual_optimized_scheduler_lifecycle_joins_threads_and_shuts_executor(monkeypatch): + scheduler = OptimizedScheduler(GeneralSchedulerConfig(use_redis_queue=False)) + scheduler._running = True + + def native_running_loop(): + while scheduler._running: + time.sleep(0.005) + + consumer = threading.Thread(target=native_running_loop, daemon=True) + monitor = threading.Thread(target=native_running_loop, daemon=True) + scheduler._consumer_thread = consumer + scheduler._monitor_thread = monitor + consumer.start() + monitor.start() + task = scheduler.dispatcher.dispatcher_executor.submit(lambda: 42) + assert task.result(timeout=2) == 42 + shutdown = Mock(wraps=scheduler.dispatcher.shutdown) + monkeypatch.setattr(scheduler.dispatcher, "shutdown", shutdown) + error = Mock() + monkeypatch.setattr(lifecycle.logger, "exception", error) + try: + lifecycle.shutdown_components({"mem_scheduler": scheduler}) + assert not consumer.is_alive() and not monitor.is_alive() + assert scheduler._running is False + assert task.done() and scheduler.dispatcher.dispatcher_executor._shutdown is True + deadline = time.monotonic() + 2 + while ( + any(t.is_alive() for t in scheduler.dispatcher.dispatcher_executor._threads) + and time.monotonic() < deadline + ): + time.sleep(0.005) + assert not any(t.is_alive() for t in scheduler.dispatcher.dispatcher_executor._threads) + shutdown.assert_called_once() + assert scheduler._rabbitmq_stop_flag is True + error.assert_not_called() + finally: + scheduler._running = False + consumer.join(timeout=1) + monitor.join(timeout=1) + scheduler.dispatcher.shutdown() + + +def test_unexpected_join_error_is_not_hidden(): + scheduler = RabbitMQSchedulerModule() + + def fail_join(**kwargs): + raise RuntimeError("fixture join failed") + + scheduler._io_loop_thread = SimpleNamespace(is_alive=lambda: True, join=fail_join) + with pytest.raises(RuntimeError, match="fixture join failed"): + scheduler.rabbitmq_close() From f6266bef7fd1ff51019c95f5f1c911ce0d52efeb Mon Sep 17 00:00:00 2001 From: Chengzhen Jia Date: Fri, 23 Oct 2026 19:58:44 +0800 Subject: [PATCH 26/38] fix: pin certifi 2026.10.19 to drop compromised eMudhra roots (#2536) The Docker requirements and lockfiles still shipped CA bundles from before the October 2026 distrust. Co-authored-by: jiachengzhen Co-authored-by: Cursor --- docker/requirements-full.txt | 2 +- docker/requirements.txt | 2 +- poetry.lock | 6 +++--- uv.lock | 12 ++++++------ 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/docker/requirements-full.txt b/docker/requirements-full.txt index b148d43d6..4e800d98c 100644 --- a/docker/requirements-full.txt +++ b/docker/requirements-full.txt @@ -8,7 +8,7 @@ attrs==25.3.0 authlib==1.6.0 beautifulsoup4==4.13.4 cachetools==6.2.1 -certifi==2025.7.14 +certifi==2026.10.19 cffi==1.17.1 charset-normalizer==3.4.2 chonkie==1.1.1 diff --git a/docker/requirements.txt b/docker/requirements.txt index 988e64b83..15b5685f7 100644 --- a/docker/requirements.txt +++ b/docker/requirements.txt @@ -4,7 +4,7 @@ attrs==25.4.0 Authlib==1.6.5 beartype==0.22.5 cachetools==6.2.2 -certifi==2025.11.12 +certifi==2026.10.19 cffi==2.0.0 charset-normalizer==3.4.4 chonkie==1.1.0 diff --git a/poetry.lock b/poetry.lock index 915204888..3aa5c9268 100644 --- a/poetry.lock +++ b/poetry.lock @@ -184,14 +184,14 @@ files = [ [[package]] name = "certifi" -version = "2025.7.14" +version = "2026.10.19" description = "Python package for providing Mozilla's CA Bundle." optional = false python-versions = ">=3.7" groups = ["main", "eval"] files = [ - {file = "certifi-2025.7.14-py3-none-any.whl", hash = "sha256:6b31f564a415d79ee77df69d757bb49a5bb53bd9f756cbbe24394ffd6fc1f4b2"}, - {file = "certifi-2025.7.14.tar.gz", hash = "sha256:8ea99dbdfaaf2ba2f9bac77b9249ef62ec5218e7c2b2e903378ed5fccf765995"}, + {file = "certifi-2026.10.19-py3-none-any.whl", hash = "sha256:42d35340cc5b9ba78e818ddbff0c5b1c2b779de448a340fd1b989f5fa8670e1b"}, + {file = "certifi-2026.10.19.tar.gz", hash = "sha256:035c1e85572b141bf1c3a3eff0e33a8eb74917522f2559075ff8d2fea780a1ae"}, ] [[package]] diff --git a/uv.lock b/uv.lock index 385ef4382..d081fa9d5 100644 --- a/uv.lock +++ b/uv.lock @@ -132,11 +132,11 @@ wheels = [ [[package]] name = "certifi" -version = "2026.2.25" +version = "2026.10.19" source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/af/2d/7bf41579a8986e348fa033a31cdd0e4121114f6bce2457e8876010b092dd/certifi-2026.2.25.tar.gz", hash = "sha256:e887ab5cee78ea814d3472169153c2d12cd43b14bd03329a39a9c6e2e80bfba7", size = 155029, upload-time = "2026-02-25T02:54:17.342Z" } +sdist = { url = "https://files.pythonhosted.org/packages/a6/bd/1436c50cc46699de0230fbaacc1d1de7bfec413176099949e9d5112e88f2/certifi-2026.10.19.tar.gz", hash = "sha256:035c1e85572b141bf1c3a3eff0e33a8eb74917522f2559075ff8d2fea780a1ae", size = 137598, upload-time = "2026-10-20T02:24:16.604Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/9a/3c/c17fb3ca2d9c3acff52e30b309f538586f9f5b9c9cf454f3845fc9af4881/certifi-2026.2.25-py3-none-any.whl", hash = "sha256:027692e4402ad994f1c42e52a4997a9763c646b73e4096e4d5d6db8af1d6f0fa", size = 153684, upload-time = "2026-02-25T02:54:15.766Z" }, + { url = "https://files.pythonhosted.org/packages/c4/51/29046e48f693c54e5b7412216d447a1d8362c9653148d98c02cdf65fa733/certifi-2026.10.19-py3-none-any.whl", hash = "sha256:42d35340cc5b9ba78e818ddbff0c5b1c2b779de448a340fd1b989f5fa8670e1b", size = 136464, upload-time = "2026-10-20T02:24:15.072Z" }, ] [[package]] @@ -2069,9 +2069,10 @@ wheels = [ [[package]] name = "memoryos" -version = "2.0.14" +version = "2.0.33" source = { editable = "." } dependencies = [ + { name = "cachetools" }, { name = "concurrent-log-handler" }, { name = "fastapi", extra = ["all"] }, { name = "fastmcp" }, @@ -2090,7 +2091,6 @@ dependencies = [ [package.optional-dependencies] all = [ { name = "alibabacloud-oss-v2" }, - { name = "cachetools" }, { name = "chonkie" }, { name = "datasketch" }, { name = "jieba" }, @@ -2142,7 +2142,7 @@ tree-mem = [ requires-dist = [ { name = "alibabacloud-oss-v2", marker = "extra == 'all'", specifier = ">=1.2.2,<1.2.3" }, { name = "alibabacloud-oss-v2", marker = "extra == 'skill-mem'", specifier = ">=1.2.2,<1.2.3" }, - { name = "cachetools", marker = "extra == 'all'", specifier = ">=6.0.0" }, + { name = "cachetools", specifier = ">=6.0.0" }, { name = "chonkie", marker = "extra == 'all'", specifier = ">=1.0.7,<2.0.0" }, { name = "chonkie", marker = "extra == 'mem-reader'", specifier = ">=1.0.7,<2.0.0" }, { name = "concurrent-log-handler", specifier = ">=0.9.28,<1.0.0" }, From 27a0143966fa7d5218aee0224835c2e7d1ecad75 Mon Sep 17 00:00:00 2001 From: jiachengzhen Date: Fri, 23 Oct 2026 16:51:48 +0800 Subject: [PATCH 27/38] fix: pin certifi 2026.10.19 to drop compromised eMudhra roots The Docker requirements and lockfiles still shipped CA bundles from before the October 2026 distrust. Co-authored-by: Cursor --- docker/requirements-full.txt | 2 +- docker/requirements.txt | 2 +- poetry.lock | 6 +++--- uv.lock | 12 ++++++------ 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/docker/requirements-full.txt b/docker/requirements-full.txt index b148d43d6..4e800d98c 100644 --- a/docker/requirements-full.txt +++ b/docker/requirements-full.txt @@ -8,7 +8,7 @@ attrs==25.3.0 authlib==1.6.0 beautifulsoup4==4.13.4 cachetools==6.2.1 -certifi==2025.7.14 +certifi==2026.10.19 cffi==1.17.1 charset-normalizer==3.4.2 chonkie==1.1.1 diff --git a/docker/requirements.txt b/docker/requirements.txt index 988e64b83..15b5685f7 100644 --- a/docker/requirements.txt +++ b/docker/requirements.txt @@ -4,7 +4,7 @@ attrs==25.4.0 Authlib==1.6.5 beartype==0.22.5 cachetools==6.2.2 -certifi==2025.11.12 +certifi==2026.10.19 cffi==2.0.0 charset-normalizer==3.4.4 chonkie==1.1.0 diff --git a/poetry.lock b/poetry.lock index 915204888..3aa5c9268 100644 --- a/poetry.lock +++ b/poetry.lock @@ -184,14 +184,14 @@ files = [ [[package]] name = "certifi" -version = "2025.7.14" +version = "2026.10.19" description = "Python package for providing Mozilla's CA Bundle." optional = false python-versions = ">=3.7" groups = ["main", "eval"] files = [ - {file = "certifi-2025.7.14-py3-none-any.whl", hash = "sha256:6b31f564a415d79ee77df69d757bb49a5bb53bd9f756cbbe24394ffd6fc1f4b2"}, - {file = "certifi-2025.7.14.tar.gz", hash = "sha256:8ea99dbdfaaf2ba2f9bac77b9249ef62ec5218e7c2b2e903378ed5fccf765995"}, + {file = "certifi-2026.10.19-py3-none-any.whl", hash = "sha256:42d35340cc5b9ba78e818ddbff0c5b1c2b779de448a340fd1b989f5fa8670e1b"}, + {file = "certifi-2026.10.19.tar.gz", hash = "sha256:035c1e85572b141bf1c3a3eff0e33a8eb74917522f2559075ff8d2fea780a1ae"}, ] [[package]] diff --git a/uv.lock b/uv.lock index 385ef4382..d081fa9d5 100644 --- a/uv.lock +++ b/uv.lock @@ -132,11 +132,11 @@ wheels = [ [[package]] name = "certifi" -version = "2026.2.25" +version = "2026.10.19" source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/af/2d/7bf41579a8986e348fa033a31cdd0e4121114f6bce2457e8876010b092dd/certifi-2026.2.25.tar.gz", hash = "sha256:e887ab5cee78ea814d3472169153c2d12cd43b14bd03329a39a9c6e2e80bfba7", size = 155029, upload-time = "2026-02-25T02:54:17.342Z" } +sdist = { url = "https://files.pythonhosted.org/packages/a6/bd/1436c50cc46699de0230fbaacc1d1de7bfec413176099949e9d5112e88f2/certifi-2026.10.19.tar.gz", hash = "sha256:035c1e85572b141bf1c3a3eff0e33a8eb74917522f2559075ff8d2fea780a1ae", size = 137598, upload-time = "2026-10-20T02:24:16.604Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/9a/3c/c17fb3ca2d9c3acff52e30b309f538586f9f5b9c9cf454f3845fc9af4881/certifi-2026.2.25-py3-none-any.whl", hash = "sha256:027692e4402ad994f1c42e52a4997a9763c646b73e4096e4d5d6db8af1d6f0fa", size = 153684, upload-time = "2026-02-25T02:54:15.766Z" }, + { url = "https://files.pythonhosted.org/packages/c4/51/29046e48f693c54e5b7412216d447a1d8362c9653148d98c02cdf65fa733/certifi-2026.10.19-py3-none-any.whl", hash = "sha256:42d35340cc5b9ba78e818ddbff0c5b1c2b779de448a340fd1b989f5fa8670e1b", size = 136464, upload-time = "2026-10-20T02:24:15.072Z" }, ] [[package]] @@ -2069,9 +2069,10 @@ wheels = [ [[package]] name = "memoryos" -version = "2.0.14" +version = "2.0.33" source = { editable = "." } dependencies = [ + { name = "cachetools" }, { name = "concurrent-log-handler" }, { name = "fastapi", extra = ["all"] }, { name = "fastmcp" }, @@ -2090,7 +2091,6 @@ dependencies = [ [package.optional-dependencies] all = [ { name = "alibabacloud-oss-v2" }, - { name = "cachetools" }, { name = "chonkie" }, { name = "datasketch" }, { name = "jieba" }, @@ -2142,7 +2142,7 @@ tree-mem = [ requires-dist = [ { name = "alibabacloud-oss-v2", marker = "extra == 'all'", specifier = ">=1.2.2,<1.2.3" }, { name = "alibabacloud-oss-v2", marker = "extra == 'skill-mem'", specifier = ">=1.2.2,<1.2.3" }, - { name = "cachetools", marker = "extra == 'all'", specifier = ">=6.0.0" }, + { name = "cachetools", specifier = ">=6.0.0" }, { name = "chonkie", marker = "extra == 'all'", specifier = ">=1.0.7,<2.0.0" }, { name = "chonkie", marker = "extra == 'mem-reader'", specifier = ">=1.0.7,<2.0.0" }, { name = "concurrent-log-handler", specifier = ">=0.9.28,<1.0.0" }, From 629bf7f805bb7595f92309d73e63aec7d6baac6c Mon Sep 17 00:00:00 2001 From: Wenqiang Wei <46308778+endxxxx@users.noreply.github.com> Date: Mon, 26 Oct 2026 22:41:31 +0800 Subject: [PATCH 28/38] fix(plugin): isolate Windows local embedding native libraries --- apps/memos-local-plugin/README.md | 50 ++++ .../providers/local-process-entry.ts | 70 +++++ .../providers/local-process-protocol.ts | 22 ++ .../core/embedding/providers/local-process.ts | 214 +++++++++++++++ .../core/embedding/providers/local.ts | 35 ++- .../scripts/verify-windows-dll-isolation.mjs | 123 +++++++++ .../unit/embedding/local-process.test.ts | 246 ++++++++++++++++++ 7 files changed, 758 insertions(+), 2 deletions(-) create mode 100644 apps/memos-local-plugin/core/embedding/providers/local-process-entry.ts create mode 100644 apps/memos-local-plugin/core/embedding/providers/local-process-protocol.ts create mode 100644 apps/memos-local-plugin/core/embedding/providers/local-process.ts create mode 100644 apps/memos-local-plugin/scripts/verify-windows-dll-isolation.mjs create mode 100644 apps/memos-local-plugin/tests/unit/embedding/local-process.test.ts diff --git a/apps/memos-local-plugin/README.md b/apps/memos-local-plugin/README.md index 92f3317eb..2694bf04a 100644 --- a/apps/memos-local-plugin/README.md +++ b/apps/memos-local-plugin/README.md @@ -289,6 +289,56 @@ loading notice. Logs report `loading`, per-file `download.progress`, `ready`, and `load_failed`. The load timeout bounds the caller's wait; Transformers loading can continue in the background and warm the next request. +### Windows native-library isolation + +On Windows, local embedding inference runs in a separate Node process so the +plugin's Transformers/Sharp/libvips libraries cannot occupy DLL names in the +host process. The model process is shared, starts lazily, and stops when its +last provider closes or after five minutes without requests. Cancelling one +request does not cancel other callers. A crashed child is restarted on the +next request; failures are reported as `embedding_unavailable`, without +falling back to loading these libraries inside the host. macOS/Linux keep +the existing in-process embedding path. + +Electron hosts must support `ELECTRON_RUN_AS_NODE`/`child_process.fork`. +The child reuses the host executable, clears inherited `NODE_OPTIONS` and +`NODE_PATH` preloads, and sends only model settings/text/vectors and model +logs over IPC. No DLL replacement or host Sharp version pin is required. + +To verify the native collision fix on Windows, build this branch and run +`scripts/verify-windows-dll-isolation.mjs` against the **host's** Sharp package. +For a DSH installation whose JavaScript is inside `app.asar`, use its Electron +executable so ASAR paths remain readable (replace the example install paths): + +```powershell +npm ci +npm run build:package +$DshExe = "C:\path\to\DeepSeek Harness.exe" +$HostSharp = "C:\path\to\resources\app.asar\dsh\node_modules\sharp" +$ModelCache = "$env:USERPROFILE\.cache\memos\models" +$PreviousRunAsNode = $env:ELECTRON_RUN_AS_NODE +$env:ELECTRON_RUN_AS_NODE = "1" +try { + & $DshExe .\scripts\verify-windows-dll-isolation.mjs --host-sharp $HostSharp --cache-dir $ModelCache --offline +} finally { + $env:ELECTRON_RUN_AS_NODE = $PreviousRunAsNode +} +``` + +Use an existing Transformers model cache with `--offline`; omit that flag to +allow downloading (including through `HF_ENDPOINT`). Each of the two load +orders runs in a fresh process: plugin model before host Sharp, and host +Sharp before plugin model. Both must return a 384-dimensional vector and +successfully encode a PNG with host Sharp; model inference must add no +Sharp/libvips/ONNX libraries to the parent process. The script reports the +separate host/worker PIDs and host library versions. + +Then restart DSH completely, enable this plugin build and the local model, +and verify both a new conversation and a long conversation that previously +failed, including any image processing path. Windows DLL behavior requires +this native check; passing the cross-platform IPC tests alone does not prove +that the original Windows failure is resolved. + ### Bundle import preview and ownership Choosing a JSON bundle in the Viewer previews it without writing records. diff --git a/apps/memos-local-plugin/core/embedding/providers/local-process-entry.ts b/apps/memos-local-plugin/core/embedding/providers/local-process-entry.ts new file mode 100644 index 000000000..23e32a4dc --- /dev/null +++ b/apps/memos-local-plugin/core/embedding/providers/local-process-entry.ts @@ -0,0 +1,70 @@ +/** Child-only entry point. Never import this module from a host adapter. */ +import { InProcessLocalEmbeddingProvider } from "./local.js"; +import type { ProviderLogger } from "../types.js"; +import type { + LocalProcessRequest, + LocalProcessResponse, +} from "./local-process-protocol.js"; + +const provider = new InProcessLocalEmbeddingProvider(); +const controllers = new Map(); +function send(message: LocalProcessResponse): void { + if (!process.connected) return; + try { + process.send?.(message, () => {}); + } catch { + /* Parent disconnected. */ + } +} +async function handle(message: LocalProcessRequest): Promise { + if (message.type === "cancel") { + controllers.get(message.id)?.abort(); + return; + } + const controller = new AbortController(); + controllers.set(message.id, controller); + const log = Object.fromEntries( + ["trace", "debug", "info", "warn", "error"].map((level) => [ + level, + (text: string, data?: Record) => + send({ + type: "log", + id: message.id, + level: level as keyof ProviderLogger, + message: text, + data, + }), + ]), + ) as unknown as ProviderLogger; + try { + const vectors = await provider.embed(message.texts, "query", { + config: { + provider: "local", + model: message.model, + local: message.local, + dimensions: 384, + openRouter: false, + cache: { enabled: false, maxItems: 0 }, + }, + log, + signal: controller.signal, + }); + send({ type: "result", id: message.id, vectors }); + } catch (error) { + send({ + type: "error", + id: message.id, + message: + error instanceof Error + ? error.message + : "Local model loading or inference failed.", + }); + } finally { + controllers.delete(message.id); + } +} +process.on("message", (message: LocalProcessRequest) => { + void handle(message); +}); +// No orphan model process after a host crash, restart or normal exit. +process.on("disconnect", () => process.exit(0)); diff --git a/apps/memos-local-plugin/core/embedding/providers/local-process-protocol.ts b/apps/memos-local-plugin/core/embedding/providers/local-process-protocol.ts new file mode 100644 index 000000000..f71a700af --- /dev/null +++ b/apps/memos-local-plugin/core/embedding/providers/local-process-protocol.ts @@ -0,0 +1,22 @@ +import type { EmbeddingConfig, ProviderLogger } from "../types.js"; + +/** Only model settings cross IPC: never forward API keys or the full runtime config. */ +export type LocalProcessRequest = + | { + type: "embed"; + id: number; + texts: string[]; + model: string; + local?: EmbeddingConfig["local"]; + } + | { type: "cancel"; id: number }; +export type LocalProcessResponse = + | { type: "result"; id: number; vectors: number[][] } + | { type: "error"; id: number; message: string } + | { + type: "log"; + id: number; + level: keyof ProviderLogger; + message: string; + data?: Record; + }; diff --git a/apps/memos-local-plugin/core/embedding/providers/local-process.ts b/apps/memos-local-plugin/core/embedding/providers/local-process.ts new file mode 100644 index 000000000..6be6d5bf0 --- /dev/null +++ b/apps/memos-local-plugin/core/embedding/providers/local-process.ts @@ -0,0 +1,214 @@ +/** Windows DLL isolation. A thread would still share the host's native DLLs. */ +import { fork, type ChildProcess, type ForkOptions } from "node:child_process"; +import { existsSync } from "node:fs"; +import { createRequire } from "node:module"; +import { fileURLToPath, pathToFileURL } from "node:url"; +import { MemosError } from "../../../agent-contract/errors.js"; +import type { ProviderCallCtx } from "../types.js"; +import type { + LocalProcessRequest, + LocalProcessResponse, +} from "./local-process-protocol.js"; + +interface PendingCall { + resolve(vectors: number[][]): void; + reject(error: unknown): void; + ctx: ProviderCallCtx; + count: number; + cleanup(): void; +} +const IDLE_MS = 5 * 60_000; + +class LocalEmbeddingProcess { + private child?: ChildProcess; + private pending = new Map(); + private nextId = 0; + private idleTimer?: ReturnType; + private lastLog?: ProviderCallCtx["log"]; + + private start(): ChildProcess { + if (this.child) return this.child; + let entry = new URL("./local-process-entry.js", import.meta.url); + let execArgv: string[] = []; + if (!existsSync(entry)) { + // Source checkouts use the declared tsx runtime; published packages use JS. + entry = new URL("./local-process-entry.ts", import.meta.url); + execArgv = [ + "--import", + pathToFileURL(createRequire(import.meta.url).resolve("tsx")).href, + ]; + } + const env: NodeJS.ProcessEnv = { + ...process.env, + ELECTRON_RUN_AS_NODE: "1", + }; + // Do not re-run a host's preloads or resolver hooks in the isolated process. + delete env.NODE_OPTIONS; + delete env.NODE_PATH; + const options: ForkOptions & { windowsHide: boolean } = { + execArgv, + env, + windowsHide: true, + stdio: ["ignore", "ignore", "ignore", "ipc"], + }; + const child = fork(fileURLToPath(entry), [], options); + this.child = child; + child.on("message", (message) => + this.receive(child, message as LocalProcessResponse), + ); + child.on("error", () => + this.fail( + child, + "Local embedding process failed to start or communicate.", + ), + ); + child.on("exit", () => + this.fail( + child, + "Local embedding process exited; the next request will restart it.", + ), + ); + return child; + } + + private fail(child: ChildProcess, message: string): void { + if (this.child !== child) return; + this.child = undefined; + clearTimeout(this.idleTimer); + for (const call of this.pending.values()) { + call.cleanup(); + call.reject(new MemosError("embedding_unavailable", message)); + } + this.pending.clear(); + child.kill(); + } + + private send(child: ChildProcess, message: LocalProcessRequest): void { + try { + child.send(message, (error) => { + if (error) this.fail(child, "Local embedding process IPC failed."); + }); + } catch { + this.fail(child, "Local embedding process IPC failed."); + } + } + + private receive(child: ChildProcess, message: LocalProcessResponse): void { + if (this.child !== child || !message || typeof message !== "object") return; + const call = this.pending.get(message.id); + if (message.type === "log") { + const log = call?.ctx.log ?? this.lastLog; + if (["trace", "debug", "info", "warn", "error"].includes(message.level)) + log?.[message.level](message.message, message.data); + return; + } + if (!call || !["result", "error"].includes(message.type)) return; + this.pending.delete(message.id); + call.cleanup(); + if (message.type === "error") { + call.reject(new MemosError("embedding_unavailable", message.message)); + } else if (message.type === "result") { + const vectors = message.vectors; + if ( + !Array.isArray(vectors) || + vectors.length !== call.count || + vectors.some( + (vector) => + !Array.isArray(vector) || + !vector.length || + vector.some((n) => typeof n !== "number" || !Number.isFinite(n)), + ) + ) { + call.reject( + new MemosError( + "embedding_unavailable", + "Local embedding process returned invalid vectors.", + ), + ); + } else call.resolve(vectors); + } + this.updateLiveness(); + } + + private updateLiveness(): void { + clearTimeout(this.idleTimer); + if (this.pending.size) { + this.child?.ref(); + this.child?.channel?.ref(); + } else { + // Keep a warm model without preventing the host from exiting. Idle cleanup + // also bounds resources used by throwaway Settings model probes. + this.child?.unref(); + this.child?.channel?.unref(); + this.idleTimer = setTimeout(() => this.close(), IDLE_MS); + this.idleTimer.unref(); + } + } + + embed(texts: string[], ctx: ProviderCallCtx): Promise { + if (ctx.signal?.aborted) return Promise.reject(ctx.signal.reason); + let child: ChildProcess; + try { + child = this.start(); + } catch { + return Promise.reject( + new MemosError( + "embedding_unavailable", + "Cannot start the isolated local embedding process.", + ), + ); + } + const id = ++this.nextId; + this.lastLog = ctx.log; + ctx.log.debug("process.request", { pid: child.pid, requestId: id }); + return new Promise((resolve, reject) => { + const onAbort = () => { + if (!this.pending.delete(id)) return; + ctx.signal?.removeEventListener("abort", onAbort); + reject(ctx.signal?.reason ?? new DOMException("Aborted", "AbortError")); + this.send(child, { type: "cancel", id }); + this.updateLiveness(); + }; + this.pending.set(id, { + resolve, + reject, + ctx, + count: texts.length, + cleanup: () => ctx.signal?.removeEventListener("abort", onAbort), + }); + ctx.signal?.addEventListener("abort", onAbort, { once: true }); + this.updateLiveness(); + this.send(child, { + type: "embed", + id, + texts, + model: ctx.config.model, + local: ctx.config.local, + }); + }); + } + + close(): void { + if (this.child) this.fail(this.child, "Local embedding process closed."); + clearTimeout(this.idleTimer); + this.lastLog = undefined; + } +} + +// Share a warm process across cores and Settings probes; closing one provider +// must not interrupt another provider's pending inference. +let shared: { client: LocalEmbeddingProcess; users: number } | undefined; +export function acquireLocalEmbeddingProcess(): LocalEmbeddingProcess { + shared ??= { client: new LocalEmbeddingProcess(), users: 0 }; + shared.users++; + return shared.client; +} +export function releaseLocalEmbeddingProcess( + client: LocalEmbeddingProcess, +): void { + if (!shared || shared.client !== client) return; + if (--shared.users === 0) { + shared = undefined; + client.close(); + } +} diff --git a/apps/memos-local-plugin/core/embedding/providers/local.ts b/apps/memos-local-plugin/core/embedding/providers/local.ts index 2b8d31e03..50ac037c6 100644 --- a/apps/memos-local-plugin/core/embedding/providers/local.ts +++ b/apps/memos-local-plugin/core/embedding/providers/local.ts @@ -10,7 +10,11 @@ * don't normalize again on top of that. */ -import { homedir } from "node:os"; +import { homedir, platform } from "node:os"; +import { + acquireLocalEmbeddingProcess, + releaseLocalEmbeddingProcess, +} from "./local-process.js"; import { join, resolve } from "node:path"; import { MemosError } from "../../../agent-contract/errors.js"; import type { @@ -238,7 +242,7 @@ type PipelineFn = ( options?: Record, ) => Promise; -export class LocalEmbeddingProvider implements EmbeddingProvider { +export class InProcessLocalEmbeddingProvider implements EmbeddingProvider { readonly name: EmbeddingProviderName = "local"; async embed( @@ -279,6 +283,33 @@ export class LocalEmbeddingProvider implements EmbeddingProvider { } } +/** Windows native DLLs must remain outside the host process. */ +export class LocalEmbeddingProvider implements EmbeddingProvider { + readonly name: EmbeddingProviderName = "local"; + private inProcess = new InProcessLocalEmbeddingProvider(); + private isolated?: ReturnType; + + embed( + texts: string[], + role: EmbedRole, + ctx: ProviderCallCtx, + ): Promise { + if (ctx.signal?.aborted) return Promise.reject(abortReason(ctx.signal)); + if (platform() !== "win32") return this.inProcess.embed(texts, role, ctx); + this.isolated ??= acquireLocalEmbeddingProcess(); + return this.isolated.embed(texts, ctx); + } + + async close(): Promise { + if (this.isolated) { + releaseLocalEmbeddingProcess(this.isolated); + this.isolated = undefined; + } else { + await this.inProcess.close(); + } + } +} + // Test hook — tests can reset the cached extractor without touching internals. export function __resetLocalExtractorForTests(): void { extractorPromise = null; diff --git a/apps/memos-local-plugin/scripts/verify-windows-dll-isolation.mjs b/apps/memos-local-plugin/scripts/verify-windows-dll-isolation.mjs new file mode 100644 index 000000000..a46c6f294 --- /dev/null +++ b/apps/memos-local-plugin/scripts/verify-windows-dll-isolation.mjs @@ -0,0 +1,123 @@ +#!/usr/bin/env node +/** Run against the host's real Sharp; each load order starts in a fresh process. */ +import assert from "node:assert/strict"; +import { execFile } from "node:child_process"; +import { createRequire } from "node:module"; +import { fileURLToPath } from "node:url"; +import { resolve } from "node:path"; +import { promisify } from "node:util"; + +const args = process.argv.slice(2); +const option = (name) => { + const i = args.indexOf(name); + return i < 0 ? undefined : args[i + 1]; +}; +if (process.platform !== "win32") { + console.log("SKIP: native DLL collision verification requires Windows."); + process.exit(0); +} +const hostSharp = option("--host-sharp"); +if (!hostSharp) + throw new Error( + "Pass --host-sharp . Run npm run build first.", + ); +const order = option("--order"); +if (!order) { + const env = { ...process.env, ELECTRON_RUN_AS_NODE: "1" }; + delete env.NODE_OPTIONS; + delete env.NODE_PATH; + for (const sequence of ["plugin-first", "host-first"]) { + const result = await promisify(execFile)( + process.execPath, + [fileURLToPath(import.meta.url), ...args, "--order", sequence], + { env, windowsHide: true, timeout: 180_000 }, + ); + process.stdout.write(result.stdout); + process.stderr.write(result.stderr); + } + process.exit(0); +} +assert.ok(["plugin-first", "host-first"].includes(order)); +const { LocalEmbeddingProvider } = await import( + "../dist/core/embedding/providers/local.js" +); +const provider = new LocalEmbeddingProvider(); +let hostVersion; +let workerPid; +async function hostImage() { + const sharp = createRequire(import.meta.url)(resolve(hostSharp)); + const image = await sharp({ + create: { width: 1, height: 1, channels: 3, background: "#ffffff" }, + }) + .png() + .toBuffer(); + assert.ok(image.length > 0); + hostVersion = sharp.versions; +} +async function embed() { + const before = new Set(process.report.getReport().sharedObjects); + const log = Object.fromEntries( + ["trace", "debug", "info", "warn", "error"].map((level) => [ + level, + (message, data) => { + if (message === "process.request") workerPid = data.pid; + }, + ]), + ); + const vectors = await provider.embed( + ["Synthetic Windows DLL isolation verification."], + "query", + { + config: { + provider: "local", + model: option("--model") ?? "Xenova/all-MiniLM-L6-v2", + dimensions: 384, + local: { + cacheDir: option("--cache-dir"), + offline: args.includes("--offline"), + loadTimeoutMs: 120_000, + }, + openRouter: false, + cache: { enabled: false, maxItems: 0 }, + }, + log, + signal: AbortSignal.timeout(150_000), + }, + ); + assert.equal(vectors.length, 1); + assert.equal(vectors[0].length, 384); + assert.ok(vectors[0].every(Number.isFinite)); + assert.ok( + Number.isInteger(workerPid) && workerPid !== process.pid, + "Local model must run in a separate process", + ); + const added = process.report + .getReport() + .sharedObjects.filter( + (path) => !before.has(path) && /sharp|vips|onnxruntime/i.test(path), + ); + assert.deepEqual( + added, + [], + "Local embeddings must not load native model/image libraries into the host", + ); +} +try { + if (order === "host-first") await hostImage(); + await embed(); + // Exercise the real host image path after model initialization in both orders. + await hostImage(); + console.log( + JSON.stringify({ + order, + passed: true, + hostPid: process.pid, + workerPid, + dimensions: 384, + hostSharp: hostVersion.sharp, + hostVips: hostVersion.vips, + }), + ); +} finally { + await provider.close(); +} diff --git a/apps/memos-local-plugin/tests/unit/embedding/local-process.test.ts b/apps/memos-local-plugin/tests/unit/embedding/local-process.test.ts new file mode 100644 index 000000000..5e2297286 --- /dev/null +++ b/apps/memos-local-plugin/tests/unit/embedding/local-process.test.ts @@ -0,0 +1,246 @@ +import { EventEmitter } from "node:events"; +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import type { ProviderCallCtx } from "../../../core/embedding/types.js"; + +const { fork, pipeline, osPlatform } = vi.hoisted(() => ({ + fork: vi.fn(), + pipeline: vi.fn(), + osPlatform: vi.fn(() => "win32"), +})); +vi.mock("node:child_process", () => ({ fork })); +vi.mock("node:os", async (original) => ({ + ...(await original()), + platform: osPlatform, +})); +vi.mock("@huggingface/transformers", () => ({ pipeline })); +import { LocalEmbeddingProvider } from "../../../core/embedding/providers/local.js"; + +class FakeChild extends EventEmitter { + connected = true; + channel = { ref: vi.fn(), unref: vi.fn() }; + ref = vi.fn(); + unref = vi.fn(); + send = vi.fn( + (_message: unknown, callback?: (error: Error | null) => void) => { + callback?.(null); + return true; + }, + ); + kill = vi.fn(() => { + this.connected = false; + this.emit("exit", 0, null); + return true; + }); +} +let children: FakeChild[]; +let providers: LocalEmbeddingProvider[]; +function provider() { + const p = new LocalEmbeddingProvider(); + providers.push(p); + return p; +} +function ctx(signal?: AbortSignal): ProviderCallCtx { + return { + config: { + provider: "local", + model: "synthetic/model", + dimensions: 2, + local: { offline: true }, + openRouter: false, + cache: { enabled: false, maxItems: 0 }, + }, + signal, + log: { + trace: vi.fn(), + debug: vi.fn(), + info: vi.fn(), + warn: vi.fn(), + error: vi.fn(), + }, + }; +} +function request(child = children[0]!) { + return child.send.mock.calls + .map(([m]) => m as any) + .find((m) => m.type === "embed"); +} +function success(child = children[0]!, vectors = [[1, 0]]) { + child.emit("message", { type: "result", id: request(child).id, vectors }); +} + +beforeEach(() => { + children = []; + providers = []; + pipeline.mockReset(); + fork.mockReset(); + fork.mockImplementation(() => { + const child = new FakeChild(); + children.push(child); + return child; + }); +}); +afterEach(async () => { + await Promise.all(providers.map((p) => p.close())); + vi.unstubAllEnvs(); +}); + +describe("Windows local embedding process isolation", () => { + it("loads embeddings in a child without importing Transformers into the host", async () => { + vi.stubEnv("NODE_OPTIONS", "--require host-preload.cjs"); + vi.stubEnv("NODE_PATH", "host-modules"); + const pending = provider().embed(["synthetic"], "query", ctx()); + await vi.waitFor(() => expect(fork).toHaveBeenCalledTimes(1)); + const [entry, args, options] = fork.mock.calls[0]!; + expect(String(entry)).toMatch(/local-process-entry\.(js|ts)$/); + expect(args).toEqual([]); + expect(options).toMatchObject({ + windowsHide: true, + env: { ELECTRON_RUN_AS_NODE: "1" }, + stdio: ["ignore", "ignore", "ignore", "ipc"], + }); + expect(options.env.NODE_OPTIONS).toBeUndefined(); + expect(options.env.NODE_PATH).toBeUndefined(); + expect(pipeline).not.toHaveBeenCalled(); + success(); + await expect(pending).resolves.toEqual([[1, 0]]); + }); + + it("routes concurrent results and progress to the matching caller", async () => { + const p = provider(); + const a = ctx(); + const b = ctx(); + const first = p.embed(["first"], "query", a); + const second = p.embed(["second"], "query", b); + await vi.waitFor(() => expect(children[0]?.send).toHaveBeenCalledTimes(2)); + const messages = children[0]!.send.mock.calls.map(([m]) => m as any); + children[0]!.emit("message", { + type: "log", + id: messages[1].id, + level: "info", + message: "download.progress", + data: { progress: 50 }, + }); + expect(b.log.info).toHaveBeenCalledWith("download.progress", { + progress: 50, + }); + children[0]!.emit("message", { + type: "result", + id: messages[1].id, + vectors: [[0, 1]], + }); + children[0]!.emit("message", { + type: "result", + id: messages[0].id, + vectors: [[1, 0]], + }); + await expect(first).resolves.toEqual([[1, 0]]); + await expect(second).resolves.toEqual([[0, 1]]); + }); + + it("does not spawn for an aborted request, and cancels only the matching pending call", async () => { + const p = provider(); + const controller = new AbortController(); + controller.abort(new Error("expired")); + await expect( + p.embed(["skip"], "query", ctx(controller.signal)), + ).rejects.toThrow("expired"); + expect(fork).not.toHaveBeenCalled(); + const active = new AbortController(); + const pending = p.embed(["slow"], "query", ctx(active.signal)); + const rejected = expect(pending).rejects.toThrow("cancelled"); + await vi.waitFor(() => expect(fork).toHaveBeenCalledTimes(1)); + active.abort(new Error("cancelled")); + await rejected; + expect(children[0]!.send).toHaveBeenCalledWith( + { type: "cancel", id: request().id }, + expect.any(Function), + ); + success(); // Late completion must be harmless. + }); + + it("rejects crashed work and starts a fresh process for the next request", async () => { + const p = provider(); + const pending = p.embed(["first"], "query", ctx()); + const rejected = expect(pending).rejects.toMatchObject({ + code: "embedding_unavailable", + }); + await vi.waitFor(() => expect(fork).toHaveBeenCalledTimes(1)); + children[0]!.emit("exit", 1, null); + await rejected; + const next = p.embed(["retry"], "query", ctx()); + await vi.waitFor(() => expect(fork).toHaveBeenCalledTimes(2)); + success(children[1]); + await expect(next).resolves.toEqual([[1, 0]]); + }); + + it("propagates load failures and validates worker vectors", async () => { + const p = provider(); + const pending = p.embed(["first"], "query", ctx()); + const failed = expect(pending).rejects.toMatchObject({ + code: "embedding_unavailable", + message: "offline model missing", + }); + await vi.waitFor(() => expect(fork).toHaveBeenCalledTimes(1)); + children[0]!.emit("message", { + type: "error", + id: request().id, + message: "offline model missing", + }); + await failed; + const invalid = p.embed(["invalid"], "query", ctx()); + const rejected = expect(invalid).rejects.toMatchObject({ + code: "embedding_unavailable", + }); + const messages = children[0]!.send.mock.calls + .map(([m]) => m as any) + .filter((m) => m.type === "embed"); + children[0]!.emit("message", { + type: "result", + id: messages.at(-1).id, + vectors: [[NaN]], + }); + await rejected; + }); + + it("rejects startup and IPC errors without loading native code in the host", async () => { + const p = provider(); + fork.mockImplementationOnce(() => { + throw new Error("spawn denied"); + }); + await expect(p.embed(["start"], "query", ctx())).rejects.toMatchObject({ + code: "embedding_unavailable", + }); + fork.mockImplementationOnce(() => { + const child = new FakeChild(); + children.push(child); + child.send.mockImplementation((_m, callback) => { + callback?.(new Error("closed IPC")); + return false; + }); + return child; + }); + await expect(p.embed(["IPC"], "query", ctx())).rejects.toMatchObject({ + code: "embedding_unavailable", + }); + expect(pipeline).not.toHaveBeenCalled(); + }); + + it("shares a process and releases it only after the last provider closes", async () => { + const a = provider(); + const b = provider(); + const first = a.embed(["a"], "query", ctx()); + const second = b.embed(["b"], "query", ctx()); + await vi.waitFor(() => expect(children[0]?.send).toHaveBeenCalledTimes(2)); + for (const [m] of children[0]!.send.mock.calls) + children[0]!.emit("message", { + type: "result", + id: (m as any).id, + vectors: [[1, 0]], + }); + await Promise.all([first, second]); + await a.close(); + expect(children[0]!.kill).not.toHaveBeenCalled(); + await b.close(); + expect(children[0]!.kill).toHaveBeenCalledOnce(); + }); +}); From 1e3d57548842ed3529b8eb8d80c635a939b43b42 Mon Sep 17 00:00:00 2001 From: Wenqiang Wei <46308778+endxxxx@users.noreply.github.com> Date: Tue, 27 Oct 2026 15:59:36 +0800 Subject: [PATCH 29/38] fix(plugin): preserve world structures and validate trace parents --- apps/memos-local-plugin/README.md | 7 + .../core/pipeline/bundle-import.ts | 111 +++++++++- .../tests/unit/pipeline/import-bundle.test.ts | 195 ++++++++++++++++++ 3 files changed, 311 insertions(+), 2 deletions(-) diff --git a/apps/memos-local-plugin/README.md b/apps/memos-local-plugin/README.md index 2694bf04a..a5507db90 100644 --- a/apps/memos-local-plugin/README.md +++ b/apps/memos-local-plugin/README.md @@ -360,6 +360,13 @@ Preview counts are estimates: database write failures can only be reported on the real import. A rejected trace rolls back its synthetic session and episode. Use **Repair embeddings** after import to enable semantic retrieval for imported rows; JSON bundles do not contain embedding vectors. +API callers should use `POST /api/v1/embeddings/rebuild` with +`{"mode":"repair","limit":100}` and repeat batches until `done` is true; +`Repair embeddings` is the Viewer button label, not an `/embeddings/repair` route. + +DSH memory ownership follows the configured `profileId`, independently of +agent presets. See [legacy preset ownership repair](adapters/deepseek-harness/README.md#legacy-preset-ownership) +for explicitly migrating older `standard`/other preset partitions after backup. ### Docker Deployment diff --git a/apps/memos-local-plugin/core/pipeline/bundle-import.ts b/apps/memos-local-plugin/core/pipeline/bundle-import.ts index 38cd2529b..2cc48d996 100644 --- a/apps/memos-local-plugin/core/pipeline/bundle-import.ts +++ b/apps/memos-local-plugin/core/pipeline/bundle-import.ts @@ -170,6 +170,45 @@ function validationIssue( }; } } + if (kind === "worldModel" && row.structure != null) { + const structure = row.structure as RecordRow; + if (typeof structure !== "object" || Array.isArray(structure)) { + return { + field: "structure", + code: "invalid_field", + message: "structure must be an object.", + }; + } + for (const facet of ["environment", "inference", "constraints"]) { + const entries = structure[facet]; + if (entries === undefined) continue; + if ( + !Array.isArray(entries) || + entries.some((entry) => { + // Earlier exports used plain strings. Preserve those as well as the + // current labelled entries rather than silently discarding evidence. + if (typeof entry === "string") return false; + if (!entry || typeof entry !== "object" || Array.isArray(entry)) + return true; + return ( + typeof entry.label !== "string" || + typeof entry.description !== "string" || + (entry.evidenceIds !== undefined && + (!Array.isArray(entry.evidenceIds) || + entry.evidenceIds.some( + (id: unknown) => typeof id !== "string", + ))) + ); + }) + ) { + return { + field: `structure.${facet}`, + code: "invalid_field", + message: `structure.${facet} must contain strings or labelled entries with optional string evidenceIds.`, + }; + } + } + } if (row.share != null) { const share = row.share as RecordRow; if ( @@ -208,6 +247,50 @@ function ownerFor( }; } +type ParentState = { + sessions: Map; + episodes: Map; +}; + +function conflictingParent( + row: RecordRow & Owner, + repos: Repos, + planned: ParentState, +): Omit | undefined { + const sessionId = row.sessionId as string; + const episodeId = row.episodeId as string; + const episode = + planned.episodes.get(episodeId) ?? + repos.episodes.getById(episodeId as EpisodeId); + if (episode && episode.sessionId !== sessionId) { + return { + field: "sessionId", + code: "conflicting_parent", + message: "sessionId does not match the existing episode's session.", + }; + } + const session = + planned.sessions.get(sessionId) ?? + repos.sessions.getById(sessionId as TraceDTO["sessionId"]); + for (const [field, parent] of [ + ["sessionId", session], + ["episodeId", episode], + ] as const) { + if ( + parent && + ((parent.ownerAgentKind ?? "unknown") !== row.ownerAgentKind || + (parent.ownerProfileId ?? "default") !== row.ownerProfileId) + ) { + return { + field, + code: "conflicting_parent", + message: `${field} belongs to another memory owner.`, + }; + } + } + return undefined; +} + /** Import each row atomically; a rejected trace must not leave synthetic parents behind. */ export async function importMemoryBundle( bundle: MemoryImportBundle, @@ -268,6 +351,7 @@ export async function importMemoryBundle( dryRun: options.dryRun === true, issues: [], }; + const planned: ParentState = { sessions: new Map(), episodes: new Map() }; const issue = (value: MemoryImportIssue) => { if (result.issues.length < 50) result.issues.push(value); }; @@ -321,10 +405,29 @@ export async function importMemoryBundle( continue; } const owner = ownerFor(raw, fallback, options); - const row = { ...raw, ...owner }; + const row: RecordRow & Owner = { ...raw, ...owner }; + const conflict = + kind === "trace" + ? conflictingParent(row, repos, planned) + : undefined; + if (conflict) { + result.invalid++; + result.skipped++; + issue({ kind, index, ...conflict }); + continue; + } try { if (!options.dryRun) db.tx(() => insertRow(kind, row, repos)); ids.add(id); + if (kind === "trace") { + // Preview must resolve later rows against the same accepted + // parents as a real import, including across batch boundaries. + planned.sessions.set(row.sessionId as string, owner); + planned.episodes.set(row.episodeId as string, { + ...owner, + sessionId: row.sessionId as string, + }); + } result.imported++; if (isVisibleTo(row, namespace)) result.visible++; else result.hidden++; @@ -477,7 +580,11 @@ function insertRow(kind: Kind, raw: RecordRow & Owner, repos: Repos): void { id: dto.id, title: dto.title, body: dto.body, - structure: { environment: [], inference: [], constraints: [] }, + structure: { + environment: dto.structure?.environment ?? [], + inference: dto.structure?.inference ?? [], + constraints: dto.structure?.constraints ?? [], + }, domainTags: [], confidence: 0.5, policyIds: dto.policyIds ?? [], diff --git a/apps/memos-local-plugin/tests/unit/pipeline/import-bundle.test.ts b/apps/memos-local-plugin/tests/unit/pipeline/import-bundle.test.ts index 16602f655..01fc8fe30 100644 --- a/apps/memos-local-plugin/tests/unit/pipeline/import-bundle.test.ts +++ b/apps/memos-local-plugin/tests/unit/pipeline/import-bundle.test.ts @@ -8,6 +8,7 @@ import type { MemoryCore } from "../../../agent-contract/memory-core.js"; import { DEFAULT_CONFIG, resolveHome } from "../../../core/config/index.js"; import { bootstrapMemoryCore } from "../../../core/pipeline/memory-core.js"; import { openDb } from "../../../core/storage/index.js"; +import { deepSeekHarnessNamespace } from "../../../adapters/deepseek-harness/namespace.js"; let dir: string; let core: MemoryCore; @@ -166,6 +167,200 @@ describe("bundle import validation and ownership", () => { ).toMatchObject({ ownerProfileId: "work", share: { scope: "private" } }); }); + it("round-trips world model structure and evidence without losing legacy string entries", async () => { + const structure = { + environment: [ + { + label: "cloud", + description: "synthetic cloud", + evidenceIds: ["trace-evidence"], + }, + ], + inference: [{ label: "region", description: "synthetic-region" }], + constraints: [ + { + label: "boundary", + description: "synthetic constraint", + evidenceIds: [], + }, + ], + }; + await core.importBundle({ + worldModels: [ + { + id: "world-source", + title: "Synthetic", + body: "Synthetic body", + structure, + version: 3, + status: "active", + }, + ], + }); + const exported = (await core.exportBundle()).worldModels[0]!; + expect(exported.structure).toEqual(structure); + await core.importBundle({ + worldModels: [{ ...exported, id: "world-copy" }], + }); + expect( + (await core.exportBundle()).worldModels.find( + (row) => row.id === "world-copy", + ), + ).toMatchObject({ structure, version: 3 }); + const legacy = { + environment: ["aws"], + inference: ["region=synthetic"], + constraints: ["synthetic-limit"], + }; + await core.importBundle({ + worldModels: [ + { + id: "world-legacy", + title: "Legacy", + body: "Synthetic body", + structure: legacy, + }, + ], + }); + expect( + (await core.exportBundle()).worldModels.find( + (row) => row.id === "world-legacy", + )!.structure, + ).toEqual(legacy); + }); + + it.each([[], { environment: "not-an-array" }, { constraints: [123] }])( + "rejects malformed world model structure in preview and actual import: %j", + async (structure) => { + for (const dryRun of [true, false]) { + const result = await core.importBundle( + { + worldModels: [ + { + id: "invalid-structure", + title: "Synthetic", + body: "Synthetic body", + structure, + }, + ], + }, + { dryRun }, + ); + expect(result).toMatchObject({ imported: 0, invalid: 1, failed: 0 }); + expect(result.issues[0]).toMatchObject({ + code: "invalid_field", + field: expect.stringContaining("structure"), + }); + } + }, + ); + + it("rejects an existing episode's conflicting session in preview and write without synthetic parents", async () => { + const parent = row("parent"); + await core.importBundle({ traces: [parent] }); + const conflict = row("conflict", { episodeId: parent.episodeId }); + for (const dryRun of [true, false]) { + const result = await core.importBundle( + { traces: [conflict] }, + { dryRun }, + ); + expect(result).toMatchObject({ + imported: 0, + invalid: 1, + failed: 0, + skipped: 1, + }); + expect(result.issues[0]).toMatchObject({ + code: "conflicting_parent", + field: "sessionId", + }); + } + const db = openDb({ + filepath: resolveHome("deepseek-harness", dir).dbFile, + agent: "deepseek-harness", + }); + try { + expect(db.prepare("SELECT COUNT(*) AS n FROM sessions").get()).toEqual({ + n: 1, + }); + expect(db.prepare("SELECT trace_ids_json FROM episodes").get()).toEqual({ + trace_ids_json: JSON.stringify([parent.id]), + }); + } finally { + db.close(); + } + }); + + it("detects parent conflicts created earlier in the bundle, including across preview batches", async () => { + const parent = row("batch-parent"); + const traces = [ + parent, + ...Array.from({ length: 100 }, (_, i) => row(`independent-${i}`)), + row("batch-conflict", { episodeId: parent.episodeId }), + ]; + for (const dryRun of [true, false]) { + const result = await core.importBundle({ traces }, { dryRun }); + expect(result).toMatchObject({ imported: 101, invalid: 1, failed: 0 }); + expect(result.issues[0]).toMatchObject({ + index: 101, + code: "conflicting_parent", + }); + if (dryRun) expect((await core.exportBundle()).traces).toHaveLength(0); + } + }); + + it("refuses to attach rows to another profile's session or episode", async () => { + const parent = row("foreign-parent", { + ownerAgentKind: "deepseek-harness", + ownerProfileId: "foreign", + }); + await core.importBundle({ traces: [parent] }); + for (const dryRun of [true, false]) { + const result = await core.importBundle( + { + traces: [ + row("foreign-session", { sessionId: parent.sessionId }), + row("foreign-episode", { + sessionId: parent.sessionId, + episodeId: parent.episodeId, + }), + ], + }, + { dryRun }, + ); + expect(result).toMatchObject({ imported: 0, invalid: 2, failed: 0 }); + expect( + result.issues.every((issue) => issue.code === "conflicting_parent"), + ).toBe(true); + } + }); + + it("makes UI presets and headless share configured-profile records without exposing other profiles", async () => { + const ui = deepSeekHarnessNamespace( + { id: "ui", header: { agentPreset: "standard" } }, + "default", + ); + const headless = deepSeekHarnessNamespace({ id: "headless" }, "default"); + await core.importBundle({ + traces: [ + row("ui-memory", { + ownerAgentKind: ui.agentKind, + ownerProfileId: ui.profileId, + }), + ], + }); + expect(await core.getTrace("ui-memory", headless)).not.toBeNull(); + expect( + await core.getTrace( + "ui-memory", + deepSeekHarnessNamespace( + { id: "other", header: { agentPreset: "standard" } }, + "work", + ), + ), + ).toBeNull(); + }); + it("bounds detailed issues while retaining accurate totals", async () => { const result = await core.importBundle({ traces: Array.from({ length: 80 }, () => null), From f232c4f950858eca14a5786aa977240b870cc941 Mon Sep 17 00:00:00 2001 From: Wenqiang Wei <46308778+endxxxx@users.noreply.github.com> Date: Tue, 27 Oct 2026 15:59:36 +0800 Subject: [PATCH 30/38] fix(plugin): keep DSH memory ownership independent of presets --- .../adapters/deepseek-harness/README.md | 50 ++++-- .../adapters/deepseek-harness/bridge.ts | 13 +- .../adapters/deepseek-harness/namespace.ts | 16 ++ .../adapters/deepseek-harness/tools.ts | 13 +- apps/memos-local-plugin/package.json | 1 + .../scripts/migrate-dsh-preset-profile.mjs | 150 ++++++++++++++++++ .../adapters/deepseek-harness-bridge.test.ts | 55 +++++++ .../adapters/deepseek-harness-tools.test.ts | 6 +- .../migrate-dsh-preset-profile.test.ts | 135 ++++++++++++++++ 9 files changed, 405 insertions(+), 34 deletions(-) create mode 100644 apps/memos-local-plugin/adapters/deepseek-harness/namespace.ts create mode 100644 apps/memos-local-plugin/scripts/migrate-dsh-preset-profile.mjs create mode 100644 apps/memos-local-plugin/tests/unit/scripts/migrate-dsh-preset-profile.test.ts diff --git a/apps/memos-local-plugin/adapters/deepseek-harness/README.md b/apps/memos-local-plugin/adapters/deepseek-harness/README.md index dddb5f4b9..693a03be4 100644 --- a/apps/memos-local-plugin/adapters/deepseek-harness/README.md +++ b/apps/memos-local-plugin/adapters/deepseek-harness/README.md @@ -320,7 +320,7 @@ deep-merging keys, so keep every field when overriding one. | Field | Default | Meaning | | --- | --- | --- | | `enabled` | `true` | Mount or disable the adapter. | -| `profileId` | `default` | Fallback namespace; a non-empty session `agentPreset` overrides it consistently for recall, capture, and tools. | +| `profileId` | `default` | Stable memory namespace for recall, capture, tools and Viewer; independent of session `agentPreset`. | | `home` | `''` | Empty means `$DSH_HOME/memos-plugin` (default `~/.dsh/memos-plugin`); otherwise an absolute or `~`-relative runtime root. | | `recallEnabled` | `true` | Run one automatic recall for every accepted, non-empty direct-user turn. Re-entry within the same logical turn is de-duplicated; there is no greeting or restored-session exception. | | `captureEnabled` | `true` | Capture completed DSH turns and tool outcomes. | @@ -487,14 +487,46 @@ rephrased, or explicitly scoped follow-up lookup. Automatic recall and `memos_search` use the same absolute deadline (`min(recallTimeoutMs, 3000)` ms) and DSH-specific no-malformed-retry filter policy. When tools are disabled, the system-prompt guidance omits the tool suggestion. Automatic -recall, capture, and all explicit tools use the same `agentPreset`-aware -namespace resolver. - -The default runtime home is shared across DSH profiles and the fallback -`profileId` is `default`. If multiple profiles point at that same home and a -session has no distinct `agentPreset`, they intentionally share a namespace. -Set a unique `profileId` per profile (or a separate `home`) when that sharing is -not desired. +recall, capture, and all explicit tools use the configured `profileId` through +the same namespace resolver. Changing `agentPreset` changes agent behavior, +not memory ownership, so Web UI and headless sessions can recall each other's +memories when configured with the same memory profile. + +The default runtime home is shared across DSH profiles and the default memory +`profileId` is `default`. Profiles using the same home and memory profile ID +intentionally share memories. Set a unique `profileId` per profile (or a +separate `home`) when that sharing is not desired. + +### Legacy preset ownership + +Earlier versions treated the session's `agentPreset` (e.g. `standard`) as the +memory profile. Those records remain in their original namespace after this +fix; they are not automatically shared or moved. If that namespace was meant +to be separate, keep it separate by configuring its explicit `profileId`. + +To reunite accidental preset partitions, stop DSH and **all** other writers to +the same database, then run the packaged repair tool from the plugin directory: + +```sh +# Read-only counts for exactly one source profile; no changes or backup yet. +node scripts/migrate-dsh-preset-profile.mjs --db /path/to/memos.db --from standard --to default +# Apply only after checking the source/target. The backup path must not exist. +node scripts/migrate-dsh-preset-profile.mjs --db /path/to/memos.db --from standard --to default --apply --backup /path/to/memos-before-preset-repair.db +``` + +Use the actual configured memory profile as `--to`; do not blindly merge every +profile into `default`. The tool changes only DSH-owned records from the named +source profile. It uses SQLite backup (including committed WAL data), then one +transaction across ownership tables, preserving IDs, vectors, sharing scopes +and references. Routing metadata in sessions/episodes is updated too. Any +constraint conflict, such as an existing skill name, rolls back all changes +and leaves the backup intact. Historical audit payload text is not rewritten. + +Use a runtime compatible with the installed `better-sqlite3` binary. For a +DSH install compiled for Electron, run the script with DSH's executable and +`ELECTRON_RUN_AS_NODE=1`, as shown in the package README's Windows validation +example. Restart DSH after a successful repair. To revert, stop all writers +and restore the backup as the database; do not mix it with newer WAL/SHM files. ## Failure behavior diff --git a/apps/memos-local-plugin/adapters/deepseek-harness/bridge.ts b/apps/memos-local-plugin/adapters/deepseek-harness/bridge.ts index a2ea43b38..270d18145 100644 --- a/apps/memos-local-plugin/adapters/deepseek-harness/bridge.ts +++ b/apps/memos-local-plugin/adapters/deepseek-harness/bridge.ts @@ -15,6 +15,7 @@ import type { } from "../../agent-contract/dto.js"; import type { MemoryCore } from "../../agent-contract/memory-core.js"; import type { DeepSeekHarnessLlmRoute } from "./host-llm.js"; +import { deepSeekHarnessNamespace } from "./namespace.js"; import { waitForDeepSeekHarnessDeadline } from "./deadline.js"; export const DEEPSEEK_HARNESS_AGENT = "deepseek-harness"; @@ -386,17 +387,7 @@ export class DeepSeekHarnessBridge { } namespaceFor(session: DshSessionLike): RuntimeNamespace { - const preset = session.header?.["agentPreset"]; - const profileId = typeof preset === "string" && preset.trim() - ? preset.trim() - : this.profileId; - return { - agentKind: DEEPSEEK_HARNESS_AGENT, - profileId, - profileLabel: profileId, - workspacePath: session.header?.cwd, - sessionKey: session.id, - }; + return deepSeekHarnessNamespace(session, this.profileId); } async flush(sessionId?: string): Promise { diff --git a/apps/memos-local-plugin/adapters/deepseek-harness/namespace.ts b/apps/memos-local-plugin/adapters/deepseek-harness/namespace.ts new file mode 100644 index 000000000..ad1bd7cfe --- /dev/null +++ b/apps/memos-local-plugin/adapters/deepseek-harness/namespace.ts @@ -0,0 +1,16 @@ +import type { RuntimeNamespace } from "../../agent-contract/dto.js"; +import type { DshSessionLike } from "./bridge.js"; + +/** Agent presets choose behavior, not memory ownership or visibility. */ +export function deepSeekHarnessNamespace( + session: DshSessionLike | undefined, + profileId: string, +): RuntimeNamespace { + return { + agentKind: "deepseek-harness", + profileId, + profileLabel: profileId, + workspacePath: session?.header?.cwd, + sessionKey: session?.id, + }; +} diff --git a/apps/memos-local-plugin/adapters/deepseek-harness/tools.ts b/apps/memos-local-plugin/adapters/deepseek-harness/tools.ts index 20f2fd518..f45fdefbd 100644 --- a/apps/memos-local-plugin/adapters/deepseek-harness/tools.ts +++ b/apps/memos-local-plugin/adapters/deepseek-harness/tools.ts @@ -19,6 +19,7 @@ import { type DshAgentLike, type DshSessionLike, } from "./bridge.js"; +import { deepSeekHarnessNamespace } from "./namespace.js"; import type { DeepSeekHarnessLlmRoute } from "./host-llm.js"; import { isDeepSeekHarnessTimeout, @@ -451,17 +452,7 @@ function namespaceFor( session: DshSessionLike | undefined, profileId: string, ): RuntimeNamespace { - const preset = session?.header?.["agentPreset"]; - const resolvedProfileId = typeof preset === "string" && preset.trim() - ? preset.trim() - : profileId; - return { - agentKind: DEEPSEEK_HARNESS_AGENT, - profileId: resolvedProfileId, - profileLabel: resolvedProfileId, - workspacePath: session?.header?.cwd, - sessionKey: session?.id, - }; + return deepSeekHarnessNamespace(session, profileId); } function requireText(value: unknown, field: string): string { diff --git a/apps/memos-local-plugin/package.json b/apps/memos-local-plugin/package.json index 25c24b3d7..144451d62 100644 --- a/apps/memos-local-plugin/package.json +++ b/apps/memos-local-plugin/package.json @@ -39,6 +39,7 @@ "templates/README.user.md", "viewer/dist", "scripts/postinstall.cjs", + "scripts/migrate-dsh-preset-profile.mjs", "scripts/sync-hermes-version.cjs", "install.sh", "install.ps1", diff --git a/apps/memos-local-plugin/scripts/migrate-dsh-preset-profile.mjs b/apps/memos-local-plugin/scripts/migrate-dsh-preset-profile.mjs new file mode 100644 index 000000000..48246f9b3 --- /dev/null +++ b/apps/memos-local-plugin/scripts/migrate-dsh-preset-profile.mjs @@ -0,0 +1,150 @@ +#!/usr/bin/env node +/** Explicit data repair only; never run automatically when the plugin starts. */ +import Database from "better-sqlite3"; +import { closeSync, openSync } from "node:fs"; +import { resolve } from "node:path"; +import { pathToFileURL } from "node:url"; +import { parseArgs } from "node:util"; + +const AGENT = "deepseek-harness"; +const quote = (name) => `"${name.replaceAll('"', '""')}"`; + +/** + * Move only the selected DSH profile. IDs, vectors, sharing and references stay + * intact. Stop every writer to this database before applying the repair. + * @param {{dbPath:string, from:string, to:string, apply?:boolean, backupPath?:string}} options + */ +export async function migrateDshPresetProfile(options) { + const { from, to } = options; + if ( + ![from, to].every( + (id) => typeof id === "string" && /^[a-z0-9][a-z0-9_-]*$/.test(id), + ) || + from === to + ) { + throw new Error( + "Specify two distinct canonical profile IDs using lowercase letters, digits, hyphens or underscores.", + ); + } + const dbPath = resolve(options.dbPath); + const apply = options.apply === true; + if ( + apply && + (!options.backupPath || resolve(options.backupPath) === dbPath) + ) { + throw new Error( + "Applying migration requires --backup with a new path distinct from the database.", + ); + } + const db = new Database(dbPath, { readonly: !apply, fileMustExist: true }); + try { + db.pragma("busy_timeout = 5000"); + const tables = db + .prepare( + "SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' ORDER BY name", + ) + .all() + .filter(({ name }) => { + const columns = new Set( + db + .prepare(`PRAGMA table_info(${quote(name)})`) + .all() + .map((column) => column.name), + ); + return ( + columns.has("owner_agent_kind") && columns.has("owner_profile_id") + ); + }); + const counts = Object.fromEntries( + tables.map(({ name }) => [ + name, + db + .prepare( + `SELECT COUNT(*) AS n FROM ${quote(name)} WHERE owner_agent_kind=? AND owner_profile_id=?`, + ) + .get(AGENT, from).n, + ]), + ); + if (!apply) return { from, to, dryRun: true, counts }; + + const backupPath = resolve(options.backupPath); + // Reserve without clobbering an existing backup. SQLite's backup API includes + // committed WAL data, unlike copying only the main .db file. + closeSync(openSync(backupPath, "wx", 0o600)); + await db.backup(backupPath); + db.transaction(() => { + for (const { name } of tables) { + if (name === "sessions" || name === "episodes") { + const rows = db + .prepare( + `SELECT id,meta_json FROM ${quote(name)} WHERE owner_agent_kind=? AND owner_profile_id=?`, + ) + .all(AGENT, from); + const updateMeta = db.prepare( + `UPDATE ${quote(name)} SET meta_json=? WHERE id=?`, + ); + for (const row of rows) { + const meta = JSON.parse(row.meta_json); + if (meta && typeof meta === "object" && !Array.isArray(meta)) { + if ( + meta.namespace?.agentKind === AGENT && + meta.namespace.profileId === from + ) { + meta.namespace.profileId = to; + if (meta.namespace.profileLabel === from) + meta.namespace.profileLabel = to; + } + if (meta.ownerProfileId === from) meta.ownerProfileId = to; + updateMeta.run(JSON.stringify(meta), row.id); + } + } + } + // Uniqueness conflicts (e.g. skill names) abort the entire transaction; + // never overwrite the target profile's data to make a merge succeed. + db.prepare( + `UPDATE ${quote(name)} SET owner_profile_id=? WHERE owner_agent_kind=? AND owner_profile_id=?`, + ).run(to, AGENT, from); + } + })(); + return { from, to, dryRun: false, counts, backupPath }; + } finally { + db.close(); + } +} + +if ( + process.argv[1] && + import.meta.url === pathToFileURL(resolve(process.argv[1])).href +) { + try { + const { values } = parseArgs({ + options: { + db: { type: "string" }, + from: { type: "string" }, + to: { type: "string" }, + backup: { type: "string" }, + apply: { type: "boolean", default: false }, + }, + }); + if (!values.db || !values.from || !values.to) + throw new Error( + "Usage: node scripts/migrate-dsh-preset-profile.mjs --db --from --to [--apply --backup ]", + ); + console.log( + JSON.stringify( + await migrateDshPresetProfile({ + dbPath: values.db, + from: values.from, + to: values.to, + apply: values.apply, + backupPath: values.backup, + }), + null, + 2, + ), + ); + } catch (error) { + console.error(error instanceof Error ? error.message : String(error)); + process.exitCode = 1; + } +} diff --git a/apps/memos-local-plugin/tests/unit/adapters/deepseek-harness-bridge.test.ts b/apps/memos-local-plugin/tests/unit/adapters/deepseek-harness-bridge.test.ts index d83147f11..fea695ec6 100644 --- a/apps/memos-local-plugin/tests/unit/adapters/deepseek-harness-bridge.test.ts +++ b/apps/memos-local-plugin/tests/unit/adapters/deepseek-harness-bridge.test.ts @@ -110,6 +110,61 @@ const session: DshSessionLike = { }; describe("DeepSeek Harness bridge", () => { + it.each([undefined, "standard", "research"])( + "uses the configured memory profile for recall and capture with preset %s", + async (preset) => { + const core = makeCore(); + const bridge = makeBridge(core); + const current = { + id: `preset-${preset ?? "headless"}`, + header: { + cwd: "/workspace/project", + ...(preset ? { agentPreset: preset } : {}), + }, + }; + bridge.onSessionEvent(current, { + type: "turn/start", + seq: 0, + time: 100, + data: { turn: 1 }, + }); + const prompt = userMessage("Synthetic memory lookup"); + await bridge.beforeStep( + { + agent: { id: current.id, session: current }, + messages: [prompt], + turn: 1, + step: 1, + signal: new AbortController().signal, + }, + async () => ({ kind: "enter", messages: [prompt] }), + ); + bridge.onSessionEvent(current, { + type: "assistant/message", + seq: 1, + time: 110, + data: { + turn: 1, + message: { content: [{ type: "text", text: "Synthetic answer" }] }, + }, + }); + bridge.onSessionEvent(current, { + type: "turn/end", + seq: 2, + time: 120, + data: { turn: 1, reason: { kind: "completed" } }, + }); + await bridge.flush(current.id); + const scoped = expect.objectContaining({ + namespace: expect.objectContaining({ profileId: "web" }), + }); + expect(core.searchMemory).toHaveBeenCalledWith(scoped, expect.anything()); + expect(core.prepareTurn).toHaveBeenCalledWith(scoped); + expect(core.onTurnEnd).toHaveBeenCalledWith(scoped); + await bridge.closeSession(current); + }, + ); + it("prefers the persisted request route and falls back to agent defaults", () => { const routedSession: DshSessionLike = { id: "route-session", diff --git a/apps/memos-local-plugin/tests/unit/adapters/deepseek-harness-tools.test.ts b/apps/memos-local-plugin/tests/unit/adapters/deepseek-harness-tools.test.ts index 192d9b4fb..0ae4222ee 100644 --- a/apps/memos-local-plugin/tests/unit/adapters/deepseek-harness-tools.test.ts +++ b/apps/memos-local-plugin/tests/unit/adapters/deepseek-harness-tools.test.ts @@ -118,8 +118,8 @@ describe("DeepSeek Harness memory tools", () => { agent: "deepseek-harness", namespace: { agentKind: "deepseek-harness", - profileId: "standard", - profileLabel: "standard", + profileId: "web", + profileLabel: "web", workspacePath: "/workspace/project", sessionKey: "dsh-session-a", }, @@ -207,7 +207,7 @@ describe("DeepSeek Harness memory tools", () => { sessionId: "dsh-session-a", episodeId: "episode-1", toolCallId: "tool-call-1", - namespace: expect.objectContaining({ profileId: "standard" }), + namespace: expect.objectContaining({ profileId: "web" }), })); expect(result).toMatchObject({ found: true, diff --git a/apps/memos-local-plugin/tests/unit/scripts/migrate-dsh-preset-profile.test.ts b/apps/memos-local-plugin/tests/unit/scripts/migrate-dsh-preset-profile.test.ts new file mode 100644 index 000000000..1cfed23b1 --- /dev/null +++ b/apps/memos-local-plugin/tests/unit/scripts/migrate-dsh-preset-profile.test.ts @@ -0,0 +1,135 @@ +import fs from "node:fs"; +import path from "node:path"; +import Database from "better-sqlite3"; +import { afterEach, beforeEach, describe, expect, it } from "vitest"; +import { makeTmpDb, type TmpDbHandle } from "../../helpers/tmp-db.js"; +import { migrateDshPresetProfile } from "../../../scripts/migrate-dsh-preset-profile.mjs"; + +let handle: TmpDbHandle; +beforeEach(() => { + handle = makeTmpDb({ agent: "deepseek-harness" }); + const meta = JSON.stringify({ + namespace: { + agentKind: "deepseek-harness", + profileId: "standard", + profileLabel: "standard", + }, + ownerProfileId: "standard", + }); + handle.db + .prepare( + "INSERT INTO sessions(id,agent,owner_agent_kind,owner_profile_id,started_at,last_seen_at,meta_json) VALUES('s','deepseek-harness','deepseek-harness','standard',1,1,?)", + ) + .run(meta); + handle.db.exec( + "INSERT INTO episodes(id,session_id,owner_agent_kind,owner_profile_id,started_at) VALUES('e','s','deepseek-harness','standard',1)", + ); + handle.db.exec( + "INSERT INTO traces(id,session_id,episode_id,owner_agent_kind,owner_profile_id,ts,user_text,agent_text,turn_id,vec_summary) VALUES('t','s','e','deepseek-harness','standard',1,'Synthetic migration','Synthetic answer',1,X'0000803F')", + ); + handle.db.exec( + "INSERT INTO sessions(id,agent,owner_agent_kind,owner_profile_id,started_at,last_seen_at) VALUES('other','deepseek-harness','deepseek-harness','work',1,1),('other-agent','hermes','hermes','standard',1,1)", + ); +}); +afterEach(() => handle.cleanup()); +const options = () => ({ + dbPath: handle.filepath, + from: "standard", + to: "default", +}); + +describe("explicit migration of legacy DSH preset ownership", () => { + it("defaults to a read-only preview and never merges other profiles", async () => { + const result = await migrateDshPresetProfile(options()); + expect(result).toMatchObject({ + dryRun: true, + counts: { traces: 1, sessions: 1, episodes: 1 }, + }); + expect( + handle.db.prepare("SELECT owner_profile_id FROM traces").get(), + ).toEqual({ owner_profile_id: "standard" }); + }); + + it("backs up first and atomically preserves IDs, vectors, sharing and namespace metadata", async () => { + const backupPath = path.join(handle.dir, "before.db"); + const result = await migrateDshPresetProfile({ + ...options(), + apply: true, + backupPath, + }); + expect(result).toMatchObject({ dryRun: false, backupPath }); + const saved = new Database(backupPath, { readonly: true }); + try { + expect( + saved.prepare("SELECT owner_profile_id FROM traces").get(), + ).toEqual({ owner_profile_id: "standard" }); + } finally { + saved.close(); + } + expect( + handle.db + .prepare( + "SELECT id,owner_profile_id,hex(vec_summary) AS vec,share_scope FROM traces", + ) + .get(), + ).toEqual({ + id: "t", + owner_profile_id: "default", + vec: "0000803F", + share_scope: "private", + }); + const session = handle.db + .prepare("SELECT meta_json FROM sessions WHERE id='s'") + .get() as { meta_json: string }; + expect(JSON.parse(session.meta_json)).toMatchObject({ + ownerProfileId: "default", + namespace: { profileId: "default" }, + }); + expect( + handle.db + .prepare("SELECT owner_profile_id FROM sessions WHERE id='other'") + .get(), + ).toEqual({ owner_profile_id: "work" }); + expect( + handle.db + .prepare("SELECT owner_profile_id FROM sessions WHERE id='other-agent'") + .get(), + ).toEqual({ owner_profile_id: "standard" }); + }); + + it("rolls back all ownership updates on a conflicting skill name", async () => { + handle.db.exec( + "INSERT INTO skills(id,owner_agent_kind,owner_profile_id,name,invocation_guide,created_at,updated_at) VALUES('a','deepseek-harness','standard','synthetic','guide',1,1),('b','deepseek-harness','default','synthetic','guide',1,1)", + ); + const backupPath = path.join(handle.dir, "before.db"); + await expect( + migrateDshPresetProfile({ ...options(), apply: true, backupPath }), + ).rejects.toThrow(); + expect( + handle.db.prepare("SELECT owner_profile_id FROM episodes").get(), + ).toEqual({ owner_profile_id: "standard" }); + expect( + handle.db.prepare("SELECT owner_profile_id FROM traces").get(), + ).toEqual({ owner_profile_id: "standard" }); + expect(fs.existsSync(backupPath)).toBe(true); + }); + + it("requires a new backup path before applying changes", async () => { + await expect( + migrateDshPresetProfile({ ...options(), apply: true }), + ).rejects.toThrow(/backup/i); + const backupPath = path.join(handle.dir, "protected.db"); + fs.writeFileSync(backupPath, "keep"); + await expect( + migrateDshPresetProfile({ ...options(), apply: true, backupPath }), + ).rejects.toThrow(); + expect(fs.readFileSync(backupPath, "utf8")).toBe("keep"); + await expect( + migrateDshPresetProfile({ + ...options(), + apply: true, + backupPath: handle.filepath, + }), + ).rejects.toThrow(); + }); +}); From af0108d04c25ce197ddfe0ffa65f9e555f4df489 Mon Sep 17 00:00:00 2001 From: RerankerGuo Date: Tue, 13 Oct 2026 16:54:31 +0800 Subject: [PATCH 31/38] fix(api): strip Bearer scheme so keyed requests reach per-key rate-limit bucket (#2428) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit _get_client_key in src/memos/api/middleware/rate_limit.py tested whether request.headers['Authorization'] started with 'krlk_', but real clients send 'Authorization: Bearer krlk_' per RFC 6750. The prefix check never matched and every request — including ones carrying a valid API key — fell through to IP-based limiting. Behind a shared egress IP all keyed clients shared one bucket, so the per-key rate-limit was dead. The fix strips the 'Bearer ' scheme (case-insensitive, per RFC 7235) before the prefix check, so 'Bearer krlk_' correctly maps to 'ratelimit:key:'. Backwards compatibility is preserved: a bare 'krlk_' header still matches. - New tests/api/test_rate_limit_bearer.py with 7 cases covering Bearer prefix, lowercase bearer, non-key Bearer tokens, missing header, X-Forwarded-For preference, and the bare-krlk_ backwards-compat path. - No new imports, no new dependencies, no public API change. Fixes #2428. --- src/memos/api/middleware/rate_limit.py | 7 ++- tests/api/test_rate_limit_bearer.py | 78 ++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 tests/api/test_rate_limit_bearer.py diff --git a/src/memos/api/middleware/rate_limit.py b/src/memos/api/middleware/rate_limit.py index c547378ca..72808a13d 100644 --- a/src/memos/api/middleware/rate_limit.py +++ b/src/memos/api/middleware/rate_limit.py @@ -57,8 +57,13 @@ def _get_client_key(request: Request) -> str: Uses API key if available, otherwise falls back to IP. """ - # Try to get API key from header + # Try to get API key from header. Real clients send a Bearer scheme + # per RFC 6750 (``Authorization: Bearer krlk_``); we strip the + # scheme before the prefix check so keyed requests actually land on + # a per-key bucket (issue #2428). auth_header = request.headers.get("Authorization", "") + if auth_header.lower().startswith("bearer "): + auth_header = auth_header[len("bearer ") :].lstrip() if auth_header.startswith("krlk_"): # Use first 20 chars of key as identifier return f"ratelimit:key:{auth_header[:20]}" diff --git a/tests/api/test_rate_limit_bearer.py b/tests/api/test_rate_limit_bearer.py new file mode 100644 index 000000000..710346cf0 --- /dev/null +++ b/tests/api/test_rate_limit_bearer.py @@ -0,0 +1,78 @@ +"""Regression tests for issue #2428. + +``_get_client_key`` in ``src/memos/api/middleware/rate_limit.py`` checked +whether ``request.headers['Authorization']`` started with ``krlk_`` — but +real clients send ``Authorization: Bearer krlk_`` per RFC 6750, so +the prefix check never matched and every request fell through to IP-based +limiting. Behind a shared egress IP all keyed clients shared one bucket +and the per-key rate-limit was dead code. + +The fix strips the ``Bearer `` scheme before testing the key prefix, so +``Bearer krlk_`` correctly maps to ``ratelimit:key:``. +""" + +from __future__ import annotations + +from types import SimpleNamespace + +from memos.api.middleware.rate_limit import _get_client_key + + +def _fake_request(authorization: str | None, *, client_host: str = "10.0.0.1"): + headers: dict[str, str] = {} + if authorization is not None: + headers["Authorization"] = authorization + return SimpleNamespace( + headers=headers, + client=SimpleNamespace(host=client_host), + ) + + +class TestGetClientKey: + def test_bearer_krlk_key_uses_per_key_bucket(self): + body = "krlk_" + "a" * 64 + request = _fake_request("Bearer " + body) + key = _get_client_key(request) + assert key == "ratelimit:key:" + body[:20] + assert "10.0.0.1" not in key + + def test_bearer_krlk_key_first_twenty_chars_of_actual_key(self): + body = "krlk_" + "f" * 64 + request = _fake_request("Bearer " + body) + key = _get_client_key(request) + assert key == "ratelimit:key:" + body[:20] + + def test_lowercase_bearer_scheme(self): + # RFC 7235: the scheme name is case-insensitive. We normalise to + # lowercase before the prefix check. + body = "krlk_" + "b" * 64 + request = _fake_request("bearer " + body) + key = _get_client_key(request) + assert key == "ratelimit:key:" + body[:20] + + def test_bearer_with_non_key_token_falls_back_to_ip(self): + request = _fake_request("Bearer some-jwt-token") + key = _get_client_key(request) + assert key.startswith("ratelimit:ip:") + assert "10.0.0.1" in key + + def test_missing_authorization_header_falls_back_to_ip(self): + request = _fake_request(None) + key = _get_client_key(request) + assert key.startswith("ratelimit:ip:") + assert "10.0.0.1" in key + + def test_x_forwarded_for_header_preferred_over_ip(self): + request = _fake_request(None, client_host="203.0.113.1") + request.headers["X-Forwarded-For"] = "198.51.100.1, 10.0.0.1" + key = _get_client_key(request) + assert key == "ratelimit:ip:198.51.100.1" + + def test_krlk_prefix_without_bearer_scheme_still_matches(self): + # Backwards compatibility: clients that sent a bare krlk_ header + # (before the Bearer scheme was added) must still match. + body = "krlk_" + "c" * 64 + request = _fake_request(body) + key = _get_client_key(request) + assert key == "ratelimit:key:" + body[:20] From 981130cc640b7543bc9b351fb4f55cf0cb3de627 Mon Sep 17 00:00:00 2001 From: RerankerGuo Date: Tue, 13 Oct 2026 16:59:01 +0800 Subject: [PATCH 32/38] fix(api): enforce canonical hex format on validate_key_format (#2427) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit validate_key_format exists as a separate copy in two modules — src/memos/api/utils/api_keys.py (canonical home, used by the key-creation utilities) and src/memos/api/middleware/auth.py (the middleware that gates every authenticated request). Both used `int(hex_part, 16)` to verify the 64-char hex tail, which silently passes for: - a leading `+` or `-` sign (`int("+a..a", 16)` == ...), - a `0x` / `0X` prefix (`int("0xa..", 16)` == ...), - `_` separators (PEP 515: `int("a_a", 16)`), - surrounding whitespace. So the documented format `krlk_<64-lowercase-hex>` was not actually enforced — keys like `krlk_+a..a`, `krlk_0x..`, or `krlk_a_a` were accepted by the middleware, hashed verbatim, and looked up against the database, bypassing the canonical form that `generate_api_key()` produces. This commit: - Replaces the `int(hex_part, 16)` check in the canonical api_keys.py implementation with an anchored regex (`[0-9a-f]{64}`) so only the exact lowercase 64-hex form is valid. - Imports the fixed implementation into auth.py and keeps the public `validate_key_format` name as a thin re-export, so the middleware shares the same logic as the canonical utils copy. This prevents the two copies from drifting again — the original bug class. New tests/api/test_validate_key_format.py covers 21 cases: - canonical format and `generate_api_key()` output always pass - 15 non-canonical variants are rejected (signs, 0x prefix, underscore, uppercase, whitespace, wrong length, missing prefix, empty) - both copies (utils and middleware) enforce the same contract Fixes #2427. --- src/memos/api/middleware/auth.py | 28 +++++--- src/memos/api/utils/api_keys.py | 20 +++--- tests/api/test_validate_key_format.py | 99 +++++++++++++++++++++++++++ 3 files changed, 127 insertions(+), 20 deletions(-) create mode 100644 tests/api/test_validate_key_format.py diff --git a/src/memos/api/middleware/auth.py b/src/memos/api/middleware/auth.py index 15b217651..6d812337b 100644 --- a/src/memos/api/middleware/auth.py +++ b/src/memos/api/middleware/auth.py @@ -17,6 +17,13 @@ import memos.log +# Canonical format check; re-exported here so the middleware shares the +# same logic as ``src/memos/api/utils/api_keys.py``. Keeping one source of +# truth is what fixes issue #2427 (previously the middleware copy and the +# utils copy could drift independently). +from memos.api.utils.api_keys import validate_key_format as validate_key_format_canonical + + logger = memos.log.get_logger(__name__) # API key header configuration @@ -63,17 +70,16 @@ def hash_api_key(key: str) -> str: def validate_key_format(key: str) -> bool: - """Validate API key format: krlk_<64-hex>.""" - if not key or not key.startswith("krlk_"): - return False - hex_part = key[5:] # Remove 'krlk_' prefix - if len(hex_part) != 64: - return False - try: - int(hex_part, 16) - return True - except ValueError: - return False + """Validate API key format: krlk_<64-hex>. + + Re-exported from ``memos.api.utils.api_keys.validate_key_format`` for + backwards compatibility with callers that imported this symbol from + the middleware path. Issue #2427: the previous copy used ``int(...)`` + which accepted non-canonical hex (leading signs, ``0x`` prefix, ``_`` + separators, whitespace) — see the canonical implementation for the + fix. + """ + return validate_key_format_canonical(key) def get_key_prefix(key: str) -> str: diff --git a/src/memos/api/utils/api_keys.py b/src/memos/api/utils/api_keys.py index 29b493fd0..123420513 100644 --- a/src/memos/api/utils/api_keys.py +++ b/src/memos/api/utils/api_keys.py @@ -5,6 +5,7 @@ """ import hashlib +import re import secrets from dataclasses import dataclass @@ -45,11 +46,19 @@ def hash_key(key: str) -> str: return hashlib.sha256(key.encode()).hexdigest() +# Match the only form ``generate_api_key()`` produces: ``krlk_`` followed by +# exactly 64 lowercase hex characters. Using ``int(hex_part, 16)`` would also +# accept leading signs, ``0x`` prefixes, ``_`` separators, and surrounding +# whitespace, none of which a real key ever carries (issue #2427). +_KEY_FORMAT_HEX_RE = re.compile(r"[0-9a-f]{64}") + + def validate_key_format(key: str) -> bool: """ Validate API key format. - Valid format: krlk_<64-hex-chars> + Valid format: ``krlk_<64-hex-chars>`` where the hex part is exactly 64 + characters from ``[0-9a-f]`` — the only form ``generate_api_key()`` produces. """ if not key or not isinstance(key, str): return False @@ -58,14 +67,7 @@ def validate_key_format(key: str) -> bool: return False hex_part = key[5:] - if len(hex_part) != 64: - return False - - try: - int(hex_part, 16) - return True - except ValueError: - return False + return _KEY_FORMAT_HEX_RE.fullmatch(hex_part) is not None def generate_master_key() -> tuple[str, str]: diff --git a/tests/api/test_validate_key_format.py b/tests/api/test_validate_key_format.py new file mode 100644 index 000000000..757d2519a --- /dev/null +++ b/tests/api/test_validate_key_format.py @@ -0,0 +1,99 @@ +"""Regression tests for issue #2427. + +``validate_key_format`` exists in two copies — ``src/memos/api/utils/api_keys.py`` +(the canonical home) and ``src/memos/api/middleware/auth.py`` (the +middleware gating every authenticated request). Both check the hex part +with ``int(hex_part, 16)``, which accepts non-canonical forms a generated +key can never have: + +- leading ``+`` / ``-`` (sign) +- ``0x`` / ``0X`` prefix +- ``_`` separators (PEP 515) +- surrounding whitespace + +So the documented format ``krlk_<64-hex-chars>`` is not actually enforced: +keys with embedded underscores, signs, or ``0x`` prefixes pass the format +gate and are hashed/looked up as-is, bypassing the canonical form that +``generate_api_key()`` produces. + +These tests pin the new contract on both validator copies: + +- the hex part must match ``[0-9a-f]{64}`` exactly +- the only valid form is the canonical lowercase hex string +""" + +from __future__ import annotations + +import pytest + +from memos.api.middleware.auth import validate_key_format as validate_in_auth +from memos.api.utils.api_keys import generate_api_key, validate_key_format + + +CANONICAL = "krlk_" + "0123456789abcdef" * 4 # 64 hex chars, lowercase + + +class TestValidateKeyFormatUtils: + def test_canonical_key_passes(self): + assert validate_key_format(CANONICAL) is True + + def test_generated_key_always_passes(self): + # The validator must accept every key that generate_api_key() + # produces, since that is the documented format. + for _ in range(20): + assert validate_key_format(generate_api_key().key) is True + + @pytest.mark.parametrize( + "bad_key", + [ + # Leading sign + "krlk_" + "+" + "a" * 63, + "krlk_" + "-" + "a" * 63, + # 0x prefix + "krlk_" + "0x" + "a" * 62, + "krlk_" + "0X" + "a" * 62, + # Underscore separator (PEP 515) + "krlk_" + "a" * 32 + "_" + "b" * 31, + # Uppercase hex (the generator emits lowercase only) + "krlk_" + "A" * 64, + # Surrounding whitespace + " krlk_" + "a" * 64, + "krlk_" + "a" * 64 + " ", + # Wrong total length + "krlk_" + "a" * 63, + "krlk_" + "a" * 65, + # Empty hex part + "krlk_", + # Missing prefix + "0123456789abcdef" * 4, + "Bearer " + CANONICAL, + # Non-string + "", + ], + ) + def test_non_canonical_keys_rejected(self, bad_key): + assert validate_key_format(bad_key) is False, ( + f"validate_key_format({bad_key!r}) should return False" + ) + + +class TestAuthMiddlewareValidator: + """The middleware copy must enforce the same contract as the canonical + one — issue #2427 documents both copies accepting non-canonical hex.""" + + def test_canonical_key_passes(self): + assert validate_in_auth(CANONICAL) is True + + def test_signed_hex_rejected(self): + # The most surprising bit: ``int("+a..", 16)`` succeeds, so a signed + # hex passes the middleware's validator today. + assert validate_in_auth("krlk_" + "+" + "a" * 63) is False + + def test_underscore_rejected(self): + assert validate_in_auth("krlk_" + "a" * 32 + "_" + "b" * 31) is False + + def test_uppercase_rejected(self): + assert validate_in_auth("krlk_" + "A" * 64) is False + + def test_0x_prefix_rejected(self): + assert validate_in_auth("krlk_" + "0x" + "a" * 62) is False From 04bfa63dd25ff3bb765759571dcbe52d33ed9946 Mon Sep 17 00:00:00 2001 From: Wenqiang Wei <46308778+endxxxx@users.noreply.github.com> Date: Thu, 29 Oct 2026 10:10:01 +0800 Subject: [PATCH 33/38] fix(plugin)!: adopt SQLite 13 prebuilds and require Node 22 --- .../memos-local-plugin-install-contract.yml | 55 ++ .../workflows/memos-local-plugin-publish.yml | 26 +- apps/memos-local-plugin/.npmrc | 2 + apps/memos-local-plugin/README.md | 64 ++ .../adapters/deepseek-harness/README.md | 45 +- .../adapters/hermes/install.hermes.sh | 2 +- .../core/pipeline/memory-core.ts | 4 + apps/memos-local-plugin/install.ps1 | 21 +- apps/memos-local-plugin/install.sh | 184 +++--- apps/memos-local-plugin/package-lock.json | 451 +------------ apps/memos-local-plugin/package.json | 25 +- apps/memos-local-plugin/pnpm-lock.yaml | 604 ++++++------------ apps/memos-local-plugin/pnpm-workspace.yaml | 10 + .../scripts/normalize-sqlite-lock.cjs | 24 + .../scripts/verify-native-runtime.cjs | 19 + .../scripts/verify-script-policy.cjs | 35 + .../unit/install/hermes-provider-link.test.ts | 2 +- .../unit/install/hermes-version-sync.test.ts | 2 +- .../tests/unit/install/install-sh.test.ts | 111 +--- .../install/sqlite-install-contract.test.ts | 95 +++ 20 files changed, 675 insertions(+), 1106 deletions(-) create mode 100644 .github/workflows/memos-local-plugin-install-contract.yml create mode 100644 apps/memos-local-plugin/.npmrc create mode 100644 apps/memos-local-plugin/pnpm-workspace.yaml create mode 100644 apps/memos-local-plugin/scripts/normalize-sqlite-lock.cjs create mode 100644 apps/memos-local-plugin/scripts/verify-native-runtime.cjs create mode 100644 apps/memos-local-plugin/scripts/verify-script-policy.cjs create mode 100644 apps/memos-local-plugin/tests/unit/install/sqlite-install-contract.test.ts diff --git a/.github/workflows/memos-local-plugin-install-contract.yml b/.github/workflows/memos-local-plugin-install-contract.yml new file mode 100644 index 000000000..a198c336c --- /dev/null +++ b/.github/workflows/memos-local-plugin-install-contract.yml @@ -0,0 +1,55 @@ +name: Local plugin installation contract + +on: + pull_request: + paths: + - 'apps/memos-local-plugin/**' + - '.github/workflows/memos-local-plugin-install-contract.yml' + workflow_dispatch: + +permissions: + contents: read + +jobs: + clean-install: + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + node: ['22', '24'] + manager: [npm, pnpm] + runs-on: ${{ matrix.os }} + defaults: + run: + shell: bash + working-directory: apps/memos-local-plugin + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node }} + - name: Pin installation tools + run: | + npm install --global npm@11.17.0 pnpm@11.7.0 --ignore-scripts --no-audit --no-fund + test "$(npm --version)" = 11.17.0 + test "$(pnpm --version)" = 11.7.0 + - name: Verify reviewed lock metadata + run: | + npm run lock:check + npm run verify:script-policy + - name: Clean npm installation + if: matrix.manager == 'npm' + run: npm ci --no-audit --no-fund + - name: Frozen pnpm installation + if: matrix.manager == 'pnpm' + run: pnpm install --frozen-lockfile + - name: SQLite and CPU ONNX runtime smoke + run: node scripts/verify-native-runtime.cjs + - name: Type check and build package + run: | + npm run lint + npm run build:package + - name: Check runtime and lock contracts + run: | + npm exec -- vitest run tests/unit/install/sqlite-install-contract.test.ts + git diff --exit-code -- package.json package-lock.json pnpm-lock.yaml diff --git a/.github/workflows/memos-local-plugin-publish.yml b/.github/workflows/memos-local-plugin-publish.yml index 60478c396..bd65c52eb 100644 --- a/.github/workflows/memos-local-plugin-publish.yml +++ b/.github/workflows/memos-local-plugin-publish.yml @@ -388,19 +388,17 @@ jobs: - name: Install dependencies shell: bash - run: bash ../../.github/scripts/retry.sh --label "npm ci" -- npm ci - - - name: Rebuild for x64 under Rosetta (darwin-x64 only) - if: matrix.platform == 'darwin-x64' - shell: bash - run: bash ../../.github/scripts/retry.sh --label "npm rebuild better-sqlite3 under Rosetta" -- arch -x86_64 npm rebuild better-sqlite3 + run: | + npm install --global npm@11.17.0 --ignore-scripts --no-audit --no-fund + npm run lock:check + bash ../../.github/scripts/retry.sh --label "npm ci" -- npm ci - name: Collect prebuild shell: bash run: | bash ../../.github/scripts/retry.sh --label "collect ${{ matrix.platform }} prebuild" -- bash -euo pipefail -c ' mkdir -p prebuilds/${{ matrix.platform }} - cp node_modules/better-sqlite3/build/Release/better_sqlite3.node prebuilds/${{ matrix.platform }}/ + cp node_modules/better-sqlite3/prebuilds/${{ matrix.platform }}.node prebuilds/${{ matrix.platform }}/better_sqlite3.node ' - name: Upload prebuild artifact @@ -492,16 +490,12 @@ jobs: find . -name "*.node" -exec ls -lh {} \; ' - - name: Install dependencies (skip native build) - run: bash ../../.github/scripts/retry.sh --label "npm ci --ignore-scripts" -- npm ci --ignore-scripts - - - name: Install Linux sqlite binding for validation + - name: Install dependencies with reviewed scripts run: | - bash ../../.github/scripts/retry.sh --label "install linux sqlite binding for validation" -- bash -euo pipefail -c ' - test -s prebuilds/linux-x64/better_sqlite3.node - mkdir -p node_modules/better-sqlite3/build/Release - cp prebuilds/linux-x64/better_sqlite3.node node_modules/better-sqlite3/build/Release/better_sqlite3.node - ' + npm install --global npm@11.17.0 --ignore-scripts --no-audit --no-fund + npm run lock:check + bash ../../.github/scripts/retry.sh --label "npm ci" -- npm ci + npm run verify:native - name: Generate telemetry credentials for a real publish if: ${{ inputs.dry_run != true && (inputs.publish_phase || 'full') != 'stage_release' }} diff --git a/apps/memos-local-plugin/.npmrc b/apps/memos-local-plugin/.npmrc new file mode 100644 index 000000000..3cefa3035 --- /dev/null +++ b/apps/memos-local-plugin/.npmrc @@ -0,0 +1,2 @@ +engine-strict=true +strict-allow-scripts=true diff --git a/apps/memos-local-plugin/README.md b/apps/memos-local-plugin/README.md index a5507db90..2a35d5a74 100644 --- a/apps/memos-local-plugin/README.md +++ b/apps/memos-local-plugin/README.md @@ -1,5 +1,69 @@ # @memtensor/memos-local-plugin +> **Runtime compatibility change:** this development version requires Node.js +> **22 or newer in the actual host process**, including Electron's embedded Node. +> It pins `better-sqlite3` to `13.0.3`, using packaged Node-API prebuilds instead +> of per-Node/Electron ABI rebuilds. Node 20 users must keep their previously +> installed compatible release until upgrading the host; this version rejects +> Node 20 before opening storage. This is a breaking runtime requirement and +> must be called out in the release version/notes; no database schema migration +> is introduced by this dependency change. + +### Reproducible dependency maintenance + +Use npm **11.17.0** and pnpm **11.7.0** with a supported Node runtime. These are +our installation-policy validation versions; installing a different package +manager version must not silently regenerate the release locks. + +From `apps/memos-local-plugin`, after a reviewed dependency edit: + +```sh +npm install --package-lock-only --ignore-scripts +npm run lock:normalize +pnpm import +npm run lock:check +``` + +`--ignore-scripts` is only for lock generation, not the release installation. +`lock:normalize` repairs npm's SQLite install-metadata inference only for the +reviewed 13.0.3 tarball URL and integrity. It refuses unknown artifacts and is +never invoked during end-user installation. Commit both lockfiles together. +`pnpm import` can change peer layouts; inspect every version change rather than +assuming a one-to-one conversion. The release validation command checks the +SQLite lock metadata, and the installation contract tests compare both locks. + +Validate `npm ci` and `pnpm install --frozen-lockfile` in separate clean checkouts +with independent `node_modules`. Both must load SQLite, create a table, write, +query and close under the actual Node/Electron runtime. Repeat lock generation +and normalization to check that it leaves the committed locks unchanged. +Runtime tarballs installed by DSH use the profile owner's dependency graph; +the source checkout locks alone do not establish the packed-install result. + +### Dependency install-script policy + +npm policy lives in this package's `allowScripts`; `.npmrc` enables engine and +script strictness for source/CI installs. pnpm 11 uses the separate +`pnpm-workspace.yaml#allowBuilds` policy. Reviewed esbuild and Sharp versions +may run scripts; SQLite 13.0.3, protobufjs, optional fsevents, and the ONNX CUDA +downloader are denied. CPU ONNX and SQLite prebuilds must pass runtime smoke +checks even when these scripts are denied. New versions require review. + +These policies belong to the installing root, not arbitrary transitive +packages. For DSH, prepare the equivalent policy in the selected profile before +the first add. Do not overwrite another plugin's settings or an explicit script +denial. The installer rejects unknown pending builds instead of approving them. +Direct host-managed installs must configure the host's policy as well. +Do not bypass this with `--dangerously-allow-all-scripts`, blanket approval or +`--ignore-scripts`. Older npm versions have different policy behavior and are +not the release installation validation path. + +A failed prebuilt probe is an installation failure, not permission to invoke +node-gyp automatically. Preserve the old deployment and diagnose the actual +host/runtime and binary resolution. Standard installs do not require MSVC, +Python or Electron headers. Windows Desktop must be revalidated with the final +package; isolated dependency-smoke results do not replace integration tests. + + > Reflect2Evolve memory plugin for AI agents. > One algorithm core, with adapters for OpenClaw, Hermes Agent, and DeepSeek > Harness. diff --git a/apps/memos-local-plugin/adapters/deepseek-harness/README.md b/apps/memos-local-plugin/adapters/deepseek-harness/README.md index 693a03be4..e8241ee5a 100644 --- a/apps/memos-local-plugin/adapters/deepseek-harness/README.md +++ b/apps/memos-local-plugin/adapters/deepseek-harness/README.md @@ -117,7 +117,7 @@ Prerequisites: - A Node.js version accepted by the DSH release. DSH `0.1.0-rc.5` requires Node.js `^22.19.0 || >=24.0.0`; this stricter host requirement takes - precedence over the MemOS package's standalone `>=20` engine. + precedence over the MemOS package's standalone `>=22` engine. - A working DSH installation. The recommended one-command installer prepares an isolated `pnpm@11.7.0` for the install when pnpm is absent. Lower-level direct `dsh plugin` commands still require pnpm on `PATH`. @@ -206,34 +206,35 @@ approve only the dependencies you trust. `dsh plugin` forwards this command to dsh plugin --profile web approve-builds ``` -For the tested `2.0.16-beta.1` package, pnpm reported `better-sqlite3`, -`esbuild`, `onnxruntime-node`, `protobufjs`, `sharp`, and the MemOS package's -own postinstall hint. Review found that the -required set was `better-sqlite3`, `esbuild`, `onnxruntime-node`, and `sharp`; -`protobufjs` and the package's own postinstall hint were not needed. The -equivalent reviewed profile policy was: +This candidate requires Node **22+** in the host, pins SQLite to **13.0.3**, +and uses its packaged Node-API prebuild. Do not carry over the previous +`better-sqlite3: true` rebuild policy. For the current locked dependencies the +reviewed profile policy is: ```yaml -# $DSH_HOME/profiles/web/pnpm-workspace.yaml +# $DSH_HOME/profiles//pnpm-workspace.yaml +strictDepBuilds: true allowBuilds: '@memtensor/memos-local-plugin': false - better-sqlite3: true - esbuild: true - onnxruntime-node: true + better-sqlite3: false + esbuild@0.27.7: true + esbuild@0.21.5: true + sharp@0.34.5: true + onnxruntime-node: false protobufjs: false - sharp: true ``` -Dependency sets can change by package version and platform, so use pnpm's -current output as the source of truth; do not use `approve-builds --all` or -copy this allowlist blindly. Install scripts execute with the current user's -permissions, outside the agent tool sandbox. After approval, rerun the same -`dsh plugin --profile web add ...` command so DSH can finish installation and -reconcile the bundle layer. - -The one-command installer automates this exact reviewed policy only when the -pending set contains no other package. Direct `dsh plugin add` users retain the -manual review flow above. +Prepare policy before the first installation. The ONNX CPU backend is bundled; +the optional CUDA download is not needed for local CPU embeddings. A clean +profile must still pass the CPU runtime smoke check. Preserve unrelated policy +entries and stop for review when an existing denial conflicts with a required +script or a new version requires approval. Do not approve all scripts. + +The one-command installer merges this reviewed policy before calling DSH. +Unknown pending scripts stop installation. A SQLite smoke failure is reported +without attempting source compilation. Profile package-manager policy is +separate from npm's source-checkout `allowScripts`; see the package README for +both lockfile maintenance and the fixed npm/pnpm validation versions. This branch pins Transformers.js to `4.2.0`; the tested lock and DSH profile resolve Transformers.js 4.2.0 with `onnxruntime-node` 1.24.3. The earlier diff --git a/apps/memos-local-plugin/adapters/hermes/install.hermes.sh b/apps/memos-local-plugin/adapters/hermes/install.hermes.sh index a010c68d0..b8d3c7cb4 100755 --- a/apps/memos-local-plugin/adapters/hermes/install.hermes.sh +++ b/apps/memos-local-plugin/adapters/hermes/install.hermes.sh @@ -48,7 +48,7 @@ if command -v npm >/dev/null 2>&1; then npm install --no-audit --no-fund --prefer-offline fi else - warn "npm not found on PATH; the bridge runtime requires Node.js ≥ 20." + warn "npm not found on PATH; the bridge runtime requires Node.js ≥ 22." fi # ── 2. viewer bundle ────────────────────────────────────────────────────────── diff --git a/apps/memos-local-plugin/core/pipeline/memory-core.ts b/apps/memos-local-plugin/core/pipeline/memory-core.ts index 852f846de..4f9ad2c01 100644 --- a/apps/memos-local-plugin/core/pipeline/memory-core.ts +++ b/apps/memos-local-plugin/core/pipeline/memory-core.ts @@ -225,6 +225,10 @@ export async function bootstrapMemoryCore( export async function bootstrapMemoryCoreFull( options: BootstrapOptions, ): Promise { + const nodeMajor = Number(process.versions.node.split(".")[0]); + if (!Number.isInteger(nodeMajor) || nodeMajor < 22) { + throw new MemosError("config_invalid", `MemOS requires Node.js >=22 in the actual host runtime (received ${process.versions.node}). Upgrade the host before installing this version.`); + } const home = options.home ?? resolveHome(options.agent); const configResult = options.config ? { config: options.config, fromDisk: true, warnings: [], source: home.configFile } diff --git a/apps/memos-local-plugin/install.ps1 b/apps/memos-local-plugin/install.ps1 index 184997b30..6d8f29c4b 100644 --- a/apps/memos-local-plugin/install.ps1 +++ b/apps/memos-local-plugin/install.ps1 @@ -175,6 +175,9 @@ Write-Host "" try { $NodeVersionStr = (node -v 2>$null) if (-not $NodeVersionStr) { Stop-Die "Node.js is not installed or not in PATH." } + if ([int]($NodeVersionStr.TrimStart('v').Split('.')[0]) -lt 22) { + Stop-Die "Node.js >=22 is required. Upgrade the actual host runtime before replacing the existing plugin." + } Write-Success "Node.js $NodeVersionStr" } catch { Stop-Die "Node.js is not installed or not in PATH." @@ -341,6 +344,9 @@ function Prepare-StagedPackage { Remove-Item -Recurse -Force $StagedPrefix -ErrorAction SilentlyContinue throw "Node.js executable not found for staged install" } + & $NodeForBridge -e 'if (Number(process.versions.node.split(".")[0]) < 22) { console.error("MemOS requires Node.js >=22 in the bridge runtime"); process.exit(1); }' + if ($LASTEXITCODE -ne 0) { Remove-Item -Recurse -Force $StagedPrefix; throw "Bridge Node.js runtime is unsupported; existing installation is unchanged." } + $NpmCommand = (Get-Command "npm.cmd" -ErrorAction SilentlyContinue).Source if (-not $NpmCommand) { $NpmCommand = (Get-Command "npm" -ErrorAction SilentlyContinue).Source } if (-not $NpmCommand) { @@ -364,7 +370,7 @@ function Prepare-StagedPackage { # npm 11 still resolves omitted DSH development peer trees unless # legacy peer resolution is requested for the packed runtime. Invoke-NativeChecked -Command $NpmCommand -Arguments @( - "install", "--omit=dev", "--legacy-peer-deps", "--no-fund", "--no-audit", "--loglevel=error" + "install", "--omit=dev", "--legacy-peer-deps", "--strict-allow-scripts", "--engine-strict", "--no-fund", "--no-audit", "--loglevel=error" ) -FailureMessage "npm install failed" } finally { if ($null -eq $PreviousSkipSetup) { @@ -376,18 +382,7 @@ function Prepare-StagedPackage { } if (-not (Test-BetterSqlite3 -NodeBin $NodeForBridge -Prefix $StagedPrefix)) { - Write-Info "Rebuilding better-sqlite3 in staging..." - Push-Location $StagedPrefix - try { - Invoke-NativeChecked -Command $NpmCommand -Arguments @( - "rebuild", "better-sqlite3", "--loglevel=error" - ) -FailureMessage "better-sqlite3 rebuild failed" - } finally { - Pop-Location - } - if (-not (Test-BetterSqlite3 -NodeBin $NodeForBridge -Prefix $StagedPrefix)) { - throw "better-sqlite3 is not loadable after rebuild" - } + throw "better-sqlite3 is not loadable: SQLite prebuilt failed its staging smoke test. No source rebuild was attempted; existing installation is unchanged." } Set-Content -Path (Join-Path $StagedPrefix ".memos-node-bin") -Value $NodeForBridge -Encoding UTF8 diff --git a/apps/memos-local-plugin/install.sh b/apps/memos-local-plugin/install.sh index eb30bff68..0c114eb76 100755 --- a/apps/memos-local-plugin/install.sh +++ b/apps/memos-local-plugin/install.sh @@ -88,7 +88,7 @@ OPENCLAW_PORT="18799" HERMES_PORT="18800" DSH_PORT="18801" DSH_PNPM_VERSION="11.7.0" -REQUIRED_NODE_MAJOR=20 +REQUIRED_NODE_MAJOR=22 OPENCLAW_RUNTIME_ENTRY="./dist/adapters/openclaw/index.js" # Older plugin IDs disabled on install so they don't fight for the # memory slot. We never touch the old plugin's data. @@ -211,22 +211,9 @@ install_node_linux() { ensure_node() { local current; current="$(node_major)" if ! [[ "${current}" =~ ^[0-9]+$ ]] || (( current < REQUIRED_NODE_MAJOR )); then - warn "Node.js >= ${REQUIRED_NODE_MAJOR} required (have ${current}). Auto-installing..." - case "${OS_NAME}" in - Darwin) install_node_mac ;; - Linux) install_node_linux ;; - esac - current="$(node_major)" - [[ "${current}" =~ ^[0-9]+$ ]] && (( current >= REQUIRED_NODE_MAJOR )) \ - || die "Node.js install failed. Install ≥ ${REQUIRED_NODE_MAJOR} and re-run." + die "Node.js >= ${REQUIRED_NODE_MAJOR} is required. Upgrade the actual host runtime before installing; the existing plugin has not been replaced." fi - # Node 25+ has no better-sqlite3 prebuilts → must compile. Warn the - # user (but don't block; the rebuild step below tries regardless). - if (( current >= 25 )); then - warn "Node $(node -v) — no better-sqlite3 prebuild available, will compile from source." - printf " ${DIM}Tip: switch to Node LTS for prebuilt binaries: nvm install 22${NC}\n" >&2 - fi success "Node.js $(node -v)" } @@ -382,13 +369,37 @@ resolve_tarball() { # the user's memory DB on every re-install. # # We mitigate that by preserving a well-known allowlist of user-data -# artefacts across the rm/extract cycle. node_modules is preserved too -# so npm install stays fast on re-install. +# artefacts across replacement. Dependencies are staged afresh and verified +# before any existing deployment is changed. deploy_tarball_to_prefix() { local prefix="$1" + local staged_prefix + staged_prefix="$(mktemp -d)" + tar xzf "${BUILT_TARBALL}" -C "${staged_prefix}" --strip-components=1 \ + || { rm -rf "${staged_prefix}"; die "Package extraction failed; existing installation is unchanged."; } + [[ -f "${staged_prefix}/package.json" ]] \ + || { rm -rf "${staged_prefix}"; die "Staged package.json missing; existing installation is unchanged."; } + step "Installing npm dependencies" + local node_bin node_dir node_version + node_bin="$(command -v node || true)" + [[ -n "${node_bin}" && -x "${node_bin}" ]] || die "Node.js not found after bootstrap." + node_dir="$(dirname "${node_bin}")" + node_version="$("${node_bin}" -v 2>/dev/null || echo "unknown")" + printf "%s\n" "${node_bin}" > "${staged_prefix}/.memos-node-bin" + # npm 11 still resolves omitted devDependency peer trees unless legacy peer + # resolution is requested. DSH peers are intentionally absent from the + # standalone OpenClaw/Hermes runtime. + ( cd "${staged_prefix}" && PATH="${node_dir}:${PATH}" MEMOS_SKIP_SETUP=1 npm install --omit=dev --legacy-peer-deps --strict-allow-scripts --engine-strict --no-fund --no-audit --loglevel=error ) || { rm -rf "${staged_prefix}"; die "Dependency staging failed; existing installation is unchanged."; } + [[ -d "${staged_prefix}/node_modules" ]] || die "npm install failed in ${staged_prefix}" + + step "Verifying SQLite prebuilt runtime" + ( cd "${staged_prefix}" && "${node_bin}" -e 'const Database = require("better-sqlite3"); const db = new Database(":memory:"); try { db.exec("CREATE TABLE probe (value TEXT)"); db.prepare("INSERT INTO probe VALUES (?)").run("ok"); if (db.prepare("SELECT value FROM probe").get().value !== "ok") throw new Error("SQLite probe failed"); } finally { db.close(); }' ) \ + || { rm -rf "${staged_prefix}"; die "SQLite prebuilt cannot load in ${node_bin}. Existing installation is unchanged; no source rebuild was attempted."; } + success "better-sqlite3 native module OK" + success "Dependencies ready" step "Deploying to ${prefix}" local saved_dir="" - local preserve=(node_modules data logs skills daemon .migrations config.yaml .auth.json .memos-node-bin) + local preserve=(data logs skills daemon .migrations config.yaml .auth.json) if [[ -d "${prefix}" ]]; then saved_dir="$(mktemp -d)" local item @@ -400,7 +411,7 @@ deploy_tarball_to_prefix() { done rm -rf "${prefix}" mkdir -p "${prefix}" - tar xzf "${BUILT_TARBALL}" -C "${prefix}" --strip-components=1 + cp -R "${staged_prefix}/." "${prefix}/" for item in "${preserve[@]}"; do if [[ -e "${saved_dir}/${item}" ]]; then rm -rf "${prefix}/${item}" @@ -410,37 +421,12 @@ deploy_tarball_to_prefix() { rm -rf "${saved_dir}" else mkdir -p "${prefix}" - tar xzf "${BUILT_TARBALL}" -C "${prefix}" --strip-components=1 + cp -R "${staged_prefix}/." "${prefix}/" fi [[ -f "${prefix}/package.json" ]] || die "Extraction failed: ${prefix}/package.json missing" - success "Package extracted" + rm -rf "${staged_prefix}" + success "Verified package deployed" - step "Installing npm dependencies" - local node_bin node_dir node_version - node_bin="$(command -v node || true)" - [[ -n "${node_bin}" && -x "${node_bin}" ]] || die "Node.js not found after bootstrap." - node_dir="$(dirname "${node_bin}")" - node_version="$("${node_bin}" -v 2>/dev/null || echo "unknown")" - printf "%s\n" "${node_bin}" > "${prefix}/.memos-node-bin" - # npm 11 still resolves omitted devDependency peer trees unless legacy peer - # resolution is requested. DSH peers are intentionally absent from the - # standalone OpenClaw/Hermes runtime. - ( cd "${prefix}" && PATH="${node_dir}:${PATH}" MEMOS_SKIP_SETUP=1 npm install --omit=dev --legacy-peer-deps --no-fund --no-audit --loglevel=error >/dev/null 2>&1 ) - [[ -d "${prefix}/node_modules" ]] || die "npm install failed in ${prefix}" - - if [[ -d "${prefix}/node_modules/better-sqlite3" ]]; then - step "Rebuilding better-sqlite3 for Node ${node_version}" - ( cd "${prefix}" && PATH="${node_dir}:${PATH}" npm rebuild better-sqlite3 --loglevel=error >/dev/null 2>&1 ) \ - || ( cd "${prefix}" && PATH="${node_dir}:${PATH}" npm rebuild better-sqlite3 --build-from-source --loglevel=error >/dev/null 2>&1 ) \ - || warn "better-sqlite3 rebuild did not complete cleanly." - if ( cd "${prefix}" && "${node_bin}" -e "require('better-sqlite3')" >/dev/null 2>&1 ); then - success "better-sqlite3 native module OK" - else - warn "better-sqlite3 not loadable — plugin will fail at startup." - printf " ${DIM}Fix: cd ${prefix} && PATH=${node_dir}:\$PATH npm rebuild better-sqlite3${NC}\n" >&2 - fi - fi - success "Dependencies ready" warn "Local MiniLM model weights are not bundled." printf " ${DIM}If embedding.provider is local, the first Viewer test or use downloads about 23 MB from Hugging Face.${NC}\n" } @@ -1407,11 +1393,9 @@ CFGEOF # ─── DeepSeek Harness install ───────────────────────────────────────────── # DSH owns its profile dependency graph and bundle reconciliation. We never # unpack into the profile or edit package.json/cordis.patch.yml ourselves. -# pnpm 11 deliberately blocks unreviewed lifecycle scripts. On that one -# expected failure we approve only the exact dependency names reviewed for -# this package, deny unnecessary scripts (including ONNX Runtime's optional -# Linux CUDA download), and repeat the same add so DSH can reconcile the -# bundle after pnpm exits successfully. +# Preseed the reviewed pnpm 11 build policy before the first add. Unknown +# scripts and conflicting explicit denials stop installation for review; +# no pending package is approved automatically after a failed install. read_pending_dsh_builds() { local workspace="$1" [[ -f "${workspace}" ]] || return 0 @@ -1470,10 +1454,45 @@ resolve_dsh_home_for_installer() { node -e 'const path = require("node:path"); const os = require("node:os"); const MEMOS_DSH_HOME = true; const configured = process.env.DSH_HOME; const selected = configured !== undefined && configured.trim().length > 0 ? configured : path.join(os.homedir(), ".dsh"); const expanded = selected === "~" ? os.homedir() : selected.startsWith("~/") || selected.startsWith("~\\") ? path.join(os.homedir(), selected.slice(2)) : selected; process.stdout.write(path.resolve(expanded));' } -deny_existing_dsh_onnx_build() { +prepare_dsh_build_policy() { local workspace="$1" - [[ -f "${workspace}" ]] || return 0 - node -e 'const fs = require("node:fs"); const MEMOS_DSH_POLICY = true; const file = process.argv[1]; const raw = fs.readFileSync(file, "utf8"); const eol = raw.includes("\r\n") ? "\r\n" : "\n"; const hadFinalEol = raw.endsWith(eol); const lines = raw.split(/\r?\n/); if (hadFinalEol) lines.pop(); let inAllowBuilds = false; let changed = false; const key = /^(\s+)(["\x27]?)onnxruntime-node\2:\s*(?:true|false|set this to true or false)(\s*(?:#.*)?)$/; for (let i = 0; i < lines.length; i += 1) { if (/^allowBuilds:\s*(?:#.*)?$/.test(lines[i])) { inAllowBuilds = true; continue; } if (inAllowBuilds && /^[^\s#]/.test(lines[i])) break; if (!inAllowBuilds) continue; const match = key.exec(lines[i]); if (!match) continue; const replacement = `${match[1]}${match[2]}onnxruntime-node${match[2]}: false${match[3]}`; if (replacement !== lines[i]) { lines[i] = replacement; changed = true; } break; } if (changed) fs.writeFileSync(file, `${lines.join(eol)}${hadFinalEol ? eol : ""}`, "utf8");' "${workspace}" + node -e 'const fs = require("node:fs"); +const path = require("node:path"); +const MEMOS_DSH_POLICY = true; +const file = process.argv[1]; +let raw = fs.existsSync(file) ? fs.readFileSync(file, "utf8") : ""; +const eol = raw.includes("\r\n") ? "\r\n" : "\n"; +const lines = raw.split(/\r?\n/); +const policy = {"better-sqlite3": false, "esbuild@0.27.7": true, "esbuild@0.21.5": true, "sharp@0.34.5": true, "onnxruntime-node": false, "protobufjs": false, "@memtensor/memos-local-plugin": false}; +let block = -1, end = -1; +const seen = new Set(); +for (let i = 0; i < lines.length; i++) { + if (/^strictDepBuilds:/.test(lines[i]) && !/^strictDepBuilds:\s*true\s*(#.*)?$/.test(lines[i])) throw new Error("Preserve existing strictDepBuilds policy; review it before installing"); + if (/^allowBuilds:/.test(lines[i])) { + if (block >= 0 || !/^allowBuilds:\s*(#.*)?$/.test(lines[i])) throw new Error("Unsupported allowBuilds YAML; review before installing"); + block = i; end = i + 1; + while (end < lines.length && (!/^[^\s#]/.test(lines[end]) || !lines[end].trim())) end++; + for (let j = i + 1; j < end; j++) { + if (!lines[j].trim() || /^\s*#/.test(lines[j])) continue; + const match = lines[j].match(/^\s+(["\x27]?)(.+?)\1:\s*(true|false|set this to true or false)\s*(#.*)?$/); + if (!match || seen.has(match[2])) throw new Error("Unsupported/duplicate allowBuilds entry"); + const key = match[2]; seen.add(key); + if (match[3] === "false" && key.includes("*")) throw new Error("Existing wildcard script denial requires explicit review"); + if ((key === "esbuild" || key.startsWith("esbuild@") || key === "sharp" || key.startsWith("sharp@")) && match[3] === "false") throw new Error("Existing script denial for " + key + "; explicit review required"); + if (key in policy) { + if (policy[key] === true && match[3] === "false") throw new Error("Existing script denial for " + key); + lines[j] = " " + JSON.stringify(key) + ": " + policy[key]; + delete policy[key]; + } + } + } +} +const additions = Object.entries(policy).map(([k,v]) => " " + JSON.stringify(k) + ": " + v); +if (block < 0) lines.push("allowBuilds:", ...additions); +else lines.splice(end, 0, ...additions); +if (!/^strictDepBuilds:/m.test(raw)) lines.push("strictDepBuilds: true"); +fs.mkdirSync(path.dirname(file), {recursive: true}); +fs.writeFileSync(file, lines.join(eol).replace(/(?:\r?\n)*$/, eol));' "${workspace}" } run_dsh_plugin_without_onnx_cuda() { @@ -1484,7 +1503,7 @@ verify_dsh_better_sqlite3() { local profile_dir="$1" ( cd "${profile_dir}" - node -e 'const Database = require("better-sqlite3"); const db = new Database(":memory:"); try { db.prepare("SELECT 1").get(); } finally { db.close(); }' + node -e 'const { createRequire } = require("node:module"); const fromPlugin = createRequire(require.resolve("@memtensor/memos-local-plugin/dist/adapters/deepseek-harness/index.js")); const Database = fromPlugin("better-sqlite3"); const db = new Database(":memory:"); try { db.exec("CREATE TABLE probe (v TEXT)"); db.prepare("INSERT INTO probe VALUES (?)").run("ok"); if (db.prepare("SELECT v FROM probe").get().v !== "ok") throw new Error("SQLite probe failed"); } finally { db.close(); }' ) } @@ -1492,7 +1511,7 @@ verify_dsh_onnx_cpu() { local profile_dir="$1" ( cd "${profile_dir}" - node -e 'const ort = require("onnxruntime-node"); const cpu = ort.listSupportedBackends().find((backend) => backend.name === "cpu"); if (!cpu || cpu.bundled !== true) throw new Error("onnxruntime-node CPU backend is unavailable");' + node -e 'const { createRequire } = require("node:module"); const fromPlugin = createRequire(require.resolve("@memtensor/memos-local-plugin/dist/adapters/deepseek-harness/index.js")); const fromTransformers = createRequire(fromPlugin.resolve("@huggingface/transformers")); const ort = fromTransformers("onnxruntime-node"); const cpu = ort.listSupportedBackends().find((backend) => backend.name === "cpu"); if (!cpu || cpu.bundled !== true) throw new Error("onnxruntime-node CPU backend is unavailable");' ) } @@ -1525,8 +1544,8 @@ install_dsh() { profile_dir="${dsh_home}/profiles/${DSH_PROFILE}" profile_workspace="${profile_dir}/pnpm-workspace.yaml" - if ! deny_existing_dsh_onnx_build "${profile_workspace}"; then - error "Unable to disable the unnecessary onnxruntime-node CUDA installer in ${profile_workspace}." + if ! prepare_dsh_build_policy "${profile_workspace}"; then + error "Unable to prepare the reviewed dependency script policy in ${profile_workspace}." return 1 fi @@ -1566,34 +1585,14 @@ install_dsh() { return 1 fi - local -a approval_args=() - for package in better-sqlite3 esbuild sharp; do - if grep -Fxq "${package}" <<< "${pending}"; then approval_args+=("${package}"); fi - done - for package in onnxruntime-node protobufjs "${NPM_PACKAGE}"; do - if grep -Fxq "${package}" <<< "${pending}"; then approval_args+=("!${package}"); fi - done - - info "pnpm requested build-script review for this fresh DSH profile." - info "Allowing reviewed native installers: better-sqlite3, esbuild, sharp" - info "Denying unnecessary scripts: onnxruntime-node CUDA download, protobufjs, ${NPM_PACKAGE}" - if ! run_dsh_plugin_without_onnx_cuda "${dsh_bin}" plugin --profile "${DSH_PROFILE}" approve-builds "${approval_args[@]}"; then - rm -f "${add_log}" - error "DSH dependency build approval failed." - return 1 - fi - - step "Completing DSH bundle activation" - if ! run_dsh_plugin_without_onnx_cuda "${dsh_bin}" plugin --profile "${DSH_PROFILE}" add "${spec}"; then - rm -f "${add_log}" - error "DSH plugin installation still failed after reviewed build approval." - return 1 - fi + rm -f "${add_log}" + error "DSH reported pending scripts after policy preparation. Review the package versions before changing the allowlist." + return 1 fi rm -f "${add_log}" - if ! deny_existing_dsh_onnx_build "${profile_workspace}"; then - error "Unable to persist the onnxruntime-node CUDA build denial in ${profile_workspace}." + if ! prepare_dsh_build_policy "${profile_workspace}"; then + error "Unable to persist the reviewed dependency script policy in ${profile_workspace}." return 1 fi @@ -1616,20 +1615,11 @@ install_dsh() { return 1 fi - if verify_dsh_better_sqlite3 "${profile_dir}"; then - success "better-sqlite3 native binding OK" - else - warn "better-sqlite3 native binding is not loadable; rebuilding it in the DSH profile." - if ! (cd "${profile_dir}" && pnpm rebuild better-sqlite3); then - error "better-sqlite3 rebuild failed in ${profile_dir}." - return 1 - fi - if ! verify_dsh_better_sqlite3 "${profile_dir}"; then - error "better-sqlite3 native binding is not loadable after rebuild." - return 1 - fi - success "better-sqlite3 native binding repaired" + if ! verify_dsh_better_sqlite3 "${profile_dir}"; then + error "better-sqlite3 native binding is not loadable in the selected runtime; no source rebuild was attempted." + return 1 fi + success "better-sqlite3 native binding OK" if ! verify_dsh_onnx_cpu "${profile_dir}"; then error "onnxruntime-node CPU binding is not loadable." diff --git a/apps/memos-local-plugin/package-lock.json b/apps/memos-local-plugin/package-lock.json index dd76f4bdf..5902e431a 100644 --- a/apps/memos-local-plugin/package-lock.json +++ b/apps/memos-local-plugin/package-lock.json @@ -13,7 +13,7 @@ "@huggingface/transformers": "4.2.0", "@preact/signals": "^2.9.0", "@sinclair/typebox": "^0.34.48", - "better-sqlite3": "^12.10.0", + "better-sqlite3": "13.0.3", "preact": "^10.29.1", "tsx": "^4.21.0", "uuid": "^10.0.0", @@ -40,7 +40,7 @@ "vitest": "^2.1.9" }, "engines": { - "node": ">=20.0.0" + "node": ">=22.0.0" }, "peerDependencies": { "@deepseek-ai/cordis": "^4.0.1", @@ -110,7 +110,6 @@ "integrity": "sha512-CGOfOJqWjg2qW/Mb6zNsDm+u5vFQ8DxXfbM09z69p5Z6+mE1ikP2jUXw+j42Pf1XTYED2Rni5f95npYeuwMDQA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@babel/code-frame": "^7.29.0", "@babel/generator": "^7.29.0", @@ -421,7 +420,6 @@ "integrity": "sha512-Sktq5axy0owk9PdnivBRNOJjHEVEibCt0+TDDZcv0+UH2KS1M910fX4kn5y45YFsrpZIi1mJf/1s5VzywMUnyg==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@deepseek-ai/cosmokit": "~1.8.6", "@standard-schema/spec": "^1.1.0" @@ -455,7 +453,6 @@ "integrity": "sha512-vtqq2pWTrzn0dKfj5kREZRpP82AwtGjGx9V1lYnKvF+Uc/a8zyWbSvjDE7V1d3YQAQJzs2cWO31hURWDekDXIA==", "dev": true, "license": "MIT", - "peer": true, "peerDependencies": { "@deepseek-ai/cordis": "^4.0.1", "@deepseek-ai/dsh-invariants": "^0.1.0-rc.6", @@ -485,7 +482,6 @@ "integrity": "sha512-E8j9Nby24qP4rfrdcfc7bpt1CHpGT3tYmycOJJkEOH4ptIdT1m2ro9nmnSd5CWYukTr64A77vjm2WGqHRI92UA==", "dev": true, "license": "MIT", - "peer": true, "peerDependencies": { "@deepseek-ai/cordis": "^4.0.1", "@deepseek-ai/dsh-invariants": "^0.1.0-rc.6" @@ -523,7 +519,6 @@ "integrity": "sha512-kuFGC8bHlzGTwlRxQhXjf3CYWl8M4NzH+EYIkrW8rri4iMc9W53xrdvkil5No/DUlMm8g1u7GdeiWYFy0TMvtA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@deepseek-ai/schemastery": "^3.18.1" }, @@ -553,7 +548,6 @@ "integrity": "sha512-8tu8I6VWC7050GAUXWhcEWQw4pakALQc8TlhKr52m7Y4+kIKeNt3FBgP86PaGPBtpK0p5zUPRQNkFpzZbBdxyw==", "dev": true, "license": "MIT", - "peer": true, "peerDependencies": { "@deepseek-ai/cordis": "^4.0.1", "@deepseek-ai/dsh-brand": "^0.1.0-rc.6", @@ -693,7 +687,6 @@ "integrity": "sha512-E7g+XChh4q4/wX++v56z1pV4SA1Rtz42xkznLPPi9FlXrrzJxwHMOUzBZ9Rz3Y1kLhQ++HJG3ZatmNx3rjFilg==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@deepseek-ai/schemastery": "^3.18.1" }, @@ -710,7 +703,6 @@ "integrity": "sha512-CUean0fAnfsJVszFEip7PsU/S26W+JfDFfsza2dCtlw8n6xlkbHA9Gjxdk2aTwqDGCgXEPkRW7mYkdJ0n6FR7w==", "dev": true, "license": "MIT", - "peer": true, "peerDependencies": { "@deepseek-ai/cordis": "^4.0.1", "@deepseek-ai/dsh-invariants": "^0.1.0-rc.6" @@ -743,7 +735,6 @@ "integrity": "sha512-weWzN8r01YCkoDCAM7BsKw2YhRrD4zL8N2SAZu9hovYtXSq8xHXsP4Zh8RLYIlYcuotjyff/6hic+0TJPd14YA==", "dev": true, "license": "MIT", - "peer": true, "peerDependencies": { "@deepseek-ai/cordis": "^4.0.1", "@deepseek-ai/dsh-invariants": "^0.1.0-rc.6" @@ -2520,26 +2511,6 @@ "@babel/core": "^7.12.10" } }, - "node_modules/base64-js": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", - "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "license": "MIT" - }, "node_modules/baseline-browser-mapping": { "version": "2.10.19", "resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.10.19.tgz", @@ -2554,38 +2525,18 @@ } }, "node_modules/better-sqlite3": { - "version": "12.10.0", - "resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-12.10.0.tgz", - "integrity": "sha512-CyzaZRQKyHkB2ZInfTTl2nvT33EbDpjkLEbE8/Zck3Ll6O0qqvuGdrJ45HgtH+HykRg88ITY3AdreBGN70aBSQ==", - "hasInstallScript": true, + "version": "13.0.3", + "resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-13.0.3.tgz", + "integrity": "sha512-RbOBxmLBG8uvFUc15X9+9SFemKcQ0WBuISBVkpuiaUB2qblC8UWlHEjdWVoZ8AdhSwmoEgsiXKfopX0CQxaACQ==", "license": "MIT", "dependencies": { - "bindings": "^1.5.0", - "prebuild-install": "^7.1.1" + "node-addon-api": "^8.0.0" }, "engines": { - "node": "20.x || 22.x || 23.x || 24.x || 25.x || 26.x" - } - }, - "node_modules/bindings": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", - "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", - "license": "MIT", - "dependencies": { - "file-uri-to-path": "1.0.0" - } - }, - "node_modules/bl": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz", - "integrity": "sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==", - "license": "MIT", - "dependencies": { - "buffer": "^5.5.0", - "inherits": "^2.0.4", - "readable-stream": "^3.4.0" - } + "node": ">=22" + }, + "gypfile": false, + "hasInstallScript": false }, "node_modules/boolbase": { "version": "1.0.0", @@ -2621,7 +2572,6 @@ } ], "license": "MIT", - "peer": true, "dependencies": { "baseline-browser-mapping": "^2.10.12", "caniuse-lite": "^1.0.30001782", @@ -2636,30 +2586,6 @@ "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" } }, - "node_modules/buffer": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", - "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "license": "MIT", - "dependencies": { - "base64-js": "^1.3.1", - "ieee754": "^1.1.13" - } - }, "node_modules/cac": { "version": "6.7.14", "resolved": "https://registry.npmjs.org/cac/-/cac-6.7.14.tgz", @@ -2773,21 +2699,6 @@ } } }, - "node_modules/decompress-response": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-6.0.0.tgz", - "integrity": "sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ==", - "license": "MIT", - "dependencies": { - "mimic-response": "^3.1.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/deep-eql": { "version": "5.0.2", "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-5.0.2.tgz", @@ -2798,15 +2709,6 @@ "node": ">=6" } }, - "node_modules/deep-extend": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz", - "integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==", - "license": "MIT", - "engines": { - "node": ">=4.0.0" - } - }, "node_modules/define-data-property": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz", @@ -2922,15 +2824,6 @@ "dev": true, "license": "ISC" }, - "node_modules/end-of-stream": { - "version": "1.4.5", - "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.5.tgz", - "integrity": "sha512-ooEGc6HP26xXq/N+GCGOT0JKCLDGrq2bQUZrQ7gyrJiZANJ/8YDTxTpQBXGMn+WbIQXNVpyWymm7KYVICQnyOg==", - "license": "MIT", - "dependencies": { - "once": "^1.4.0" - } - }, "node_modules/entities": { "version": "4.5.0", "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz", @@ -3048,15 +2941,6 @@ "@types/estree": "^1.0.0" } }, - "node_modules/expand-template": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/expand-template/-/expand-template-2.0.3.tgz", - "integrity": "sha512-XYfuKMvj4O35f/pOXLObndIRvyQ+/+6AhODh+OKWj9S9498pHHn/IMszH+gt0fBCRWMNfk1ZSp5x3AifmnI2vg==", - "license": "(MIT OR WTFPL)", - "engines": { - "node": ">=6" - } - }, "node_modules/expect-type": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/expect-type/-/expect-type-1.3.0.tgz", @@ -3067,24 +2951,12 @@ "node": ">=12.0.0" } }, - "node_modules/file-uri-to-path": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", - "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==", - "license": "MIT" - }, "node_modules/flatbuffers": { "version": "25.9.23", "resolved": "https://registry.npmjs.org/flatbuffers/-/flatbuffers-25.9.23.tgz", "integrity": "sha512-MI1qs7Lo4Syw0EOzUl0xjs2lsoeqFku44KpngfIduHBYvzm8h2+7K8YMQh1JtVVVrUvhLpNwqVi4DERegUJhPQ==", "license": "Apache-2.0" }, - "node_modules/fs-constants": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz", - "integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==", - "license": "MIT" - }, "node_modules/fsevents": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", @@ -3121,12 +2993,6 @@ "url": "https://github.com/privatenumber/get-tsconfig?sponsor=1" } }, - "node_modules/github-from-package": { - "version": "0.0.0", - "resolved": "https://registry.npmjs.org/github-from-package/-/github-from-package-0.0.0.tgz", - "integrity": "sha512-SyHy3T1v2NUXn29OsWdxmK6RwHD+vkj3v8en8AOBZ1wBQ/hCAQ5bAQTD02kW4W9tUp/3Qh6J8r9EvntiyCmOOw==", - "license": "MIT" - }, "node_modules/global-agent": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/global-agent/-/global-agent-3.0.0.tgz", @@ -3200,38 +3066,6 @@ "he": "bin/he" } }, - "node_modules/ieee754": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", - "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "license": "BSD-3-Clause" - }, - "node_modules/inherits": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", - "license": "ISC" - }, - "node_modules/ini": { - "version": "1.3.8", - "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz", - "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==", - "license": "ISC" - }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -3330,33 +3164,6 @@ "node": ">=10" } }, - "node_modules/mimic-response": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-3.1.0.tgz", - "integrity": "sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ==", - "license": "MIT", - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/minimist": { - "version": "1.2.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", - "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", - "license": "MIT", - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/mkdirp-classic": { - "version": "0.5.3", - "resolved": "https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz", - "integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==", - "license": "MIT" - }, "node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", @@ -3383,22 +3190,13 @@ "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" } }, - "node_modules/napi-build-utils": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/napi-build-utils/-/napi-build-utils-2.0.0.tgz", - "integrity": "sha512-GEbrYkbfF7MoNaoh2iGG84Mnf/WZfB0GdGEsM8wz7Expx/LlWf5U8t9nvJKXSp3qr5IsEbK04cBGhol/KwOsWA==", - "license": "MIT" - }, - "node_modules/node-abi": { - "version": "3.89.0", - "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.89.0.tgz", - "integrity": "sha512-6u9UwL0HlAl21+agMN3YAMXcKByMqwGx+pq+P76vii5f7hTPtKDp08/H9py6DY+cfDw7kQNTGEj/rly3IgbNQA==", + "node_modules/node-addon-api": { + "version": "8.9.2", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-8.9.2.tgz", + "integrity": "sha512-VijLXbi3UACN69I0JVXJsX4tjACjNoQDgv2gTF6sx2wWEi8tkSg2eX8p5gSIFi8z2+DL3oHmY6OyKce38SDolg==", "license": "MIT", - "dependencies": { - "semver": "^7.3.5" - }, "engines": { - "node": ">=10" + "node": "^18 || ^20 || >= 21" } }, "node_modules/node-html-parser": { @@ -3441,15 +3239,6 @@ "node": ">= 0.4" } }, - "node_modules/once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", - "license": "ISC", - "dependencies": { - "wrappy": "1" - } - }, "node_modules/onnxruntime-common": { "version": "1.24.3", "resolved": "https://registry.npmjs.org/onnxruntime-common/-/onnxruntime-common-1.24.3.tgz", @@ -3570,39 +3359,11 @@ "resolved": "https://registry.npmjs.org/preact/-/preact-10.29.1.tgz", "integrity": "sha512-gQCLc/vWroE8lIpleXtdJhTFDogTdZG9AjMUpVkDf2iTCNwYNWA+u16dL41TqUDJO4gm2IgrcMv3uTpjd4Pwmg==", "license": "MIT", - "peer": true, "funding": { "type": "opencollective", "url": "https://opencollective.com/preact" } }, - "node_modules/prebuild-install": { - "version": "7.1.3", - "resolved": "https://registry.npmjs.org/prebuild-install/-/prebuild-install-7.1.3.tgz", - "integrity": "sha512-8Mf2cbV7x1cXPUILADGI3wuhfqWvtiLA1iclTDbFRZkgRQS0NqsPZphna9V+HyTEadheuPmjaJMsbzKQFOzLug==", - "deprecated": "No longer maintained. Please contact the author of the relevant native addon; alternatives are available.", - "license": "MIT", - "dependencies": { - "detect-libc": "^2.0.0", - "expand-template": "^2.0.3", - "github-from-package": "0.0.0", - "minimist": "^1.2.3", - "mkdirp-classic": "^0.5.3", - "napi-build-utils": "^2.0.0", - "node-abi": "^3.3.0", - "pump": "^3.0.0", - "rc": "^1.2.7", - "simple-get": "^4.0.0", - "tar-fs": "^2.0.0", - "tunnel-agent": "^0.6.0" - }, - "bin": { - "prebuild-install": "bin.js" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/protobufjs": { "version": "7.6.5", "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-7.6.5.tgz", @@ -3626,45 +3387,6 @@ "node": ">=12.0.0" } }, - "node_modules/pump": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.4.tgz", - "integrity": "sha512-VS7sjc6KR7e1ukRFhQSY5LM2uBWAUPiOPa/A3mkKmiMwSmRFUITt0xuj+/lesgnCv+dPIEYlkzrcyXgquIHMcA==", - "license": "MIT", - "dependencies": { - "end-of-stream": "^1.1.0", - "once": "^1.3.1" - } - }, - "node_modules/rc": { - "version": "1.2.8", - "resolved": "https://registry.npmjs.org/rc/-/rc-1.2.8.tgz", - "integrity": "sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==", - "license": "(BSD-2-Clause OR MIT OR Apache-2.0)", - "dependencies": { - "deep-extend": "^0.6.0", - "ini": "~1.3.0", - "minimist": "^1.2.0", - "strip-json-comments": "~2.0.1" - }, - "bin": { - "rc": "cli.js" - } - }, - "node_modules/readable-stream": { - "version": "3.6.2", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", - "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", - "license": "MIT", - "dependencies": { - "inherits": "^2.0.3", - "string_decoder": "^1.1.1", - "util-deprecate": "^1.0.1" - }, - "engines": { - "node": ">= 6" - } - }, "node_modules/resolve-pkg-maps": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz", @@ -3697,7 +3419,6 @@ "integrity": "sha512-VmtB2rFU/GroZ4oL8+ZqXgSA38O6GR8KSIvWmEFv63pQ0G6KaBH9s07PO8XTXP4vI+3UJUEypOfjkGfmSBBR0w==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@types/estree": "1.0.8" }, @@ -3737,26 +3458,6 @@ "fsevents": "~2.3.2" } }, - "node_modules/safe-buffer": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", - "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "license": "MIT" - }, "node_modules/semver": { "version": "7.7.4", "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.4.tgz", @@ -3851,51 +3552,6 @@ "kolorist": "^1.6.0" } }, - "node_modules/simple-concat": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.1.tgz", - "integrity": "sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "license": "MIT" - }, - "node_modules/simple-get": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/simple-get/-/simple-get-4.0.1.tgz", - "integrity": "sha512-brv7p5WgH0jmQJr1ZDDfKDOSeWWg+OVypG99A/5vYGPqJ6pxiaHLy8nxtFjBA7oMa01ebA9gfh1uMCFqOuXxvA==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "license": "MIT", - "dependencies": { - "decompress-response": "^6.0.0", - "once": "^1.3.1", - "simple-concat": "^1.0.0" - } - }, "node_modules/source-map": { "version": "0.7.6", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.6.tgz", @@ -3946,58 +3602,6 @@ "dev": true, "license": "MIT" }, - "node_modules/string_decoder": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", - "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", - "license": "MIT", - "dependencies": { - "safe-buffer": "~5.2.0" - } - }, - "node_modules/strip-json-comments": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", - "integrity": "sha512-4gB8na07fecVVkOI6Rs4e7T6NOTki5EmL7TUduTs6bu3EdnSycntVJ4re8kgZA+wx9IueI2Y11bfbgwtzuE0KQ==", - "license": "MIT", - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/tar-fs": { - "version": "2.1.4", - "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.4.tgz", - "integrity": "sha512-mDAjwmZdh7LTT6pNleZ05Yt65HC3E+NiQzl672vQG38jIrehtJk/J3mNwIg+vShQPcLF/LV7CMnDW6vjj6sfYQ==", - "license": "MIT", - "dependencies": { - "chownr": "^1.1.1", - "mkdirp-classic": "^0.5.2", - "pump": "^3.0.0", - "tar-stream": "^2.1.4" - } - }, - "node_modules/tar-fs/node_modules/chownr": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.4.tgz", - "integrity": "sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg==", - "license": "ISC" - }, - "node_modules/tar-stream": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.2.0.tgz", - "integrity": "sha512-ujeqbceABgwMZxEJnk2HDY2DlnUZ+9oEcb1KzTVfYHio0UE6dG71n60d8D2I4qNvleWrrXpmjpt7vZeF1LnMZQ==", - "license": "MIT", - "dependencies": { - "bl": "^4.0.3", - "end-of-stream": "^1.4.1", - "fs-constants": "^1.0.0", - "inherits": "^2.0.3", - "readable-stream": "^3.1.1" - }, - "engines": { - "node": ">=6" - } - }, "node_modules/tinybench": { "version": "2.9.0", "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-2.9.0.tgz", @@ -4068,18 +3672,6 @@ "fsevents": "~2.3.3" } }, - "node_modules/tunnel-agent": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", - "integrity": "sha512-McnNiV1l8RYeY8tBgEpuodCC1mLUdbSN+CYBL7kJsJNInOP8UjDDEwdk6Mw60vdLLrr5NHKZhMAOSrR2NZuQ+w==", - "license": "Apache-2.0", - "dependencies": { - "safe-buffer": "^5.0.1" - }, - "engines": { - "node": "*" - } - }, "node_modules/type-fest": { "version": "0.13.1", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.13.1.tgz", @@ -4143,12 +3735,6 @@ "browserslist": ">= 4.21.0" } }, - "node_modules/util-deprecate": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", - "license": "MIT" - }, "node_modules/uuid": { "version": "10.0.0", "resolved": "https://registry.npmjs.org/uuid/-/uuid-10.0.0.tgz", @@ -4168,7 +3754,6 @@ "integrity": "sha512-o5a9xKjbtuhY6Bi5S3+HvbRERmouabWbyUcpXXUA1u+GNUKoROi9byOJ8M0nHbHYHkYICiMlqxkg1KkYmm25Sw==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "esbuild": "^0.21.3", "postcss": "^8.4.43", @@ -4777,12 +4362,6 @@ "node": ">=8" } }, - "node_modules/wrappy": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", - "license": "ISC" - }, "node_modules/yaml": { "version": "2.8.3", "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.8.3.tgz", diff --git a/apps/memos-local-plugin/package.json b/apps/memos-local-plugin/package.json index 144451d62..7e6366228 100644 --- a/apps/memos-local-plugin/package.json +++ b/apps/memos-local-plugin/package.json @@ -52,7 +52,9 @@ "!**/.gitkeep", "!**/*.map", "!dist/tests", - "!dist/tests/**" + "!dist/tests/**", + "scripts/normalize-sqlite-lock.cjs", + "scripts/verify-native-runtime.cjs" ], "scripts": { "build": "tsc -p tsconfig.build.json && node scripts/copy-runtime-assets.cjs", @@ -61,7 +63,7 @@ "prepack": "npm run check:hermes-version && npm run build:package", "sync:hermes-version": "node scripts/sync-hermes-version.cjs", "check:hermes-version": "node scripts/sync-hermes-version.cjs --check", - "release:validate": "npm run check:hermes-version && npm run lint && npm test", + "release:validate": "npm run lock:check && npm run verify:script-policy && npm run check:hermes-version && npm run lint && npm test", "dev": "tsc -p tsconfig.json --watch", "viewer:dev": "vite --config vite.config.ts", "bridge": "tsx bridge.cts", @@ -72,7 +74,11 @@ "test:integration": "vitest run tests/integration", "test:e2e": "vitest run tests/e2e", "lint": "tsc -p tsconfig.json --noEmit", - "postinstall": "node scripts/postinstall.cjs" + "postinstall": "node scripts/postinstall.cjs", + "lock:normalize": "node scripts/normalize-sqlite-lock.cjs", + "lock:check": "node scripts/normalize-sqlite-lock.cjs --check", + "verify:native": "node scripts/verify-native-runtime.cjs", + "verify:script-policy": "node scripts/verify-script-policy.cjs" }, "keywords": [ "memory", @@ -87,13 +93,13 @@ ], "license": "MIT", "engines": { - "node": ">=20.0.0" + "node": ">=22.0.0" }, "dependencies": { "@huggingface/transformers": "4.2.0", "@preact/signals": "^2.9.0", "@sinclair/typebox": "^0.34.48", - "better-sqlite3": "^12.10.0", + "better-sqlite3": "13.0.3", "preact": "^10.29.1", "tsx": "^4.21.0", "uuid": "^10.0.0", @@ -154,5 +160,14 @@ "typescript": "^5.7.0", "vite": "^5.4.10", "vitest": "^2.1.9" + }, + "allowScripts": { + "better-sqlite3": false, + "esbuild@0.27.7": true, + "esbuild@0.21.5": true, + "sharp@0.34.5": true, + "onnxruntime-node": false, + "protobufjs": false, + "fsevents": false } } diff --git a/apps/memos-local-plugin/pnpm-lock.yaml b/apps/memos-local-plugin/pnpm-lock.yaml index 659e036df..5116f3c47 100644 --- a/apps/memos-local-plugin/pnpm-lock.yaml +++ b/apps/memos-local-plugin/pnpm-lock.yaml @@ -18,8 +18,8 @@ importers: specifier: ^0.34.48 version: 0.34.49 better-sqlite3: - specifier: ^12.10.0 - version: 12.11.1 + specifier: 13.0.3 + version: 13.0.3 preact: specifier: ^10.29.1 version: 10.29.1 @@ -65,10 +65,10 @@ importers: version: 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) '@deepseek-ai/schemastery': specifier: ^3.18.1 - version: 3.18.1 + version: 3.18.5 '@preact/preset-vite': specifier: ^2.10.5 - version: 2.10.5(@babel/core@7.29.0)(preact@10.29.1)(rollup@4.60.2)(vite@5.4.21(@types/node@22.19.17)) + version: 2.10.5(@babel/core@7.29.0)(preact@10.29.1)(rollup@4.60.1)(vite@5.4.21(@types/node@22.19.17)) '@types/better-sqlite3': specifier: ^7.6.12 version: 7.6.13 @@ -195,9 +195,6 @@ packages: '@deepseek-ai/cordis-plugin-loader': optional: true - '@deepseek-ai/cosmokit@1.8.2': - resolution: {integrity: sha512-muBOKtSrUKU5m/xpq8ZXWL6hQ/jgd4PhU2PqH97bcxIiLEJfNwZOGQEx4t/aS/GgxRAR+ra9pMHPMtTHU4sqqA==} - '@deepseek-ai/cosmokit@1.8.6': resolution: {integrity: sha512-ZSD/fN52L498LBIOYwjIOlaLv5veY6ZEwI2yzvZUKQtctn0QAPqu8tKdJ+OF5+Tv6NBq1U+wJWH+QI6OGy5EvQ==} @@ -361,9 +358,6 @@ packages: peerDependencies: '@deepseek-ai/cordis': ~4.0.4 - '@deepseek-ai/schemastery@3.18.1': - resolution: {integrity: sha512-Qn0FCSwCQnpnj6SB31I6i2sIKgKWnkbJM8O0EU91Gv2UsYVvtZTl6IA0sCwk2e2MZf5S8w5hpq9QkeVvK9qwxg==} - '@deepseek-ai/schemastery@3.18.5': resolution: {integrity: sha512-Mnobvqf9rHsZYv4g5edj5ddxS1oF1kIdSlz0DunUgnY3LWG5F26MqvH3YOOsSaodCgyzJ16OMN9O99/s5Crtdw==} @@ -704,89 +698,105 @@ packages: resolution: {integrity: sha512-excjX8DfsIcJ10x1Kzr4RcWe1edC9PquDRRPx3YVCvQv+U5p7Yin2s32ftzikXojb1PIFc/9Mt28/y+iRklkrw==} cpu: [arm64] os: [linux] + libc: [glibc] '@img/sharp-libvips-linux-arm@1.2.4': resolution: {integrity: sha512-bFI7xcKFELdiNCVov8e44Ia4u2byA+l3XtsAj+Q8tfCwO6BQ8iDojYdvoPMqsKDkuoOo+X6HZA0s0q11ANMQ8A==} cpu: [arm] os: [linux] + libc: [glibc] '@img/sharp-libvips-linux-ppc64@1.2.4': resolution: {integrity: sha512-FMuvGijLDYG6lW+b/UvyilUWu5Ayu+3r2d1S8notiGCIyYU/76eig1UfMmkZ7vwgOrzKzlQbFSuQfgm7GYUPpA==} cpu: [ppc64] os: [linux] + libc: [glibc] '@img/sharp-libvips-linux-riscv64@1.2.4': resolution: {integrity: sha512-oVDbcR4zUC0ce82teubSm+x6ETixtKZBh/qbREIOcI3cULzDyb18Sr/Wcyx7NRQeQzOiHTNbZFF1UwPS2scyGA==} cpu: [riscv64] os: [linux] + libc: [glibc] '@img/sharp-libvips-linux-s390x@1.2.4': resolution: {integrity: sha512-qmp9VrzgPgMoGZyPvrQHqk02uyjA0/QrTO26Tqk6l4ZV0MPWIW6LTkqOIov+J1yEu7MbFQaDpwdwJKhbJvuRxQ==} cpu: [s390x] os: [linux] + libc: [glibc] '@img/sharp-libvips-linux-x64@1.2.4': resolution: {integrity: sha512-tJxiiLsmHc9Ax1bz3oaOYBURTXGIRDODBqhveVHonrHJ9/+k89qbLl0bcJns+e4t4rvaNBxaEZsFtSfAdquPrw==} cpu: [x64] os: [linux] + libc: [glibc] '@img/sharp-libvips-linuxmusl-arm64@1.2.4': resolution: {integrity: sha512-FVQHuwx1IIuNow9QAbYUzJ+En8KcVm9Lk5+uGUQJHaZmMECZmOlix9HnH7n1TRkXMS0pGxIJokIVB9SuqZGGXw==} cpu: [arm64] os: [linux] + libc: [musl] '@img/sharp-libvips-linuxmusl-x64@1.2.4': resolution: {integrity: sha512-+LpyBk7L44ZIXwz/VYfglaX/okxezESc6UxDSoyo2Ks6Jxc4Y7sGjpgU9s4PMgqgjj1gZCylTieNamqA1MF7Dg==} cpu: [x64] os: [linux] + libc: [musl] '@img/sharp-linux-arm64@0.34.5': resolution: {integrity: sha512-bKQzaJRY/bkPOXyKx5EVup7qkaojECG6NLYswgktOZjaXecSAeCWiZwwiFf3/Y+O1HrauiE3FVsGxFg8c24rZg==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [arm64] os: [linux] + libc: [glibc] '@img/sharp-linux-arm@0.34.5': resolution: {integrity: sha512-9dLqsvwtg1uuXBGZKsxem9595+ujv0sJ6Vi8wcTANSFpwV/GONat5eCkzQo/1O6zRIkh0m/8+5BjrRr7jDUSZw==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [arm] os: [linux] + libc: [glibc] '@img/sharp-linux-ppc64@0.34.5': resolution: {integrity: sha512-7zznwNaqW6YtsfrGGDA6BRkISKAAE1Jo0QdpNYXNMHu2+0dTrPflTLNkpc8l7MUP5M16ZJcUvysVWWrMefZquA==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [ppc64] os: [linux] + libc: [glibc] '@img/sharp-linux-riscv64@0.34.5': resolution: {integrity: sha512-51gJuLPTKa7piYPaVs8GmByo7/U7/7TZOq+cnXJIHZKavIRHAP77e3N2HEl3dgiqdD/w0yUfiJnII77PuDDFdw==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [riscv64] os: [linux] + libc: [glibc] '@img/sharp-linux-s390x@0.34.5': resolution: {integrity: sha512-nQtCk0PdKfho3eC5MrbQoigJ2gd1CgddUMkabUj+rBevs8tZ2cULOx46E7oyX+04WGfABgIwmMC0VqieTiR4jg==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [s390x] os: [linux] + libc: [glibc] '@img/sharp-linux-x64@0.34.5': resolution: {integrity: sha512-MEzd8HPKxVxVenwAa+JRPwEC7QFjoPWuS5NZnBt6B3pu7EG2Ge0id1oLHZpPJdn3OQK+BQDiw9zStiHBTJQQQQ==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [x64] os: [linux] + libc: [glibc] '@img/sharp-linuxmusl-arm64@0.34.5': resolution: {integrity: sha512-fprJR6GtRsMt6Kyfq44IsChVZeGN97gTD331weR1ex1c1rypDEABN6Tm2xa1wE6lYb5DdEnk03NZPqA7Id21yg==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [arm64] os: [linux] + libc: [musl] '@img/sharp-linuxmusl-x64@0.34.5': resolution: {integrity: sha512-Jg8wNT1MUzIvhBFxViqrEhWDGzqymo3sV7z7ZsaWbZNDLXRJZoRGrjulp60YYtV4wfY8VIKcWidjojlLcWrd8Q==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [x64] os: [linux] + libc: [musl] '@img/sharp-wasm32@0.34.5': resolution: {integrity: sha512-OdWTEiVkY2PHwqkbBI8frFxQQFekHaSSkUIJkwzclWZe64O1X4UlUjqqqLaPbUpMOQk6FBu/HtlGXNblIs0huw==} @@ -864,29 +874,26 @@ packages: '@protobufjs/base64@1.1.2': resolution: {integrity: sha512-AZkcAA5vnN/v4PDqKyMR5lx7hZttPDgClv83E//FMNhR2TMcLUhfRUBHCmSl0oi9zMgDDqRUJkSxO3wm85+XLg==} - '@protobufjs/codegen@2.0.4': - resolution: {integrity: sha512-YyFaikqM5sH0ziFZCN3xDC7zeGaB/d0IUb9CATugHWbd1FRFwWwt4ld4OYMPWu5a3Xe01mGAULCdqhMlPl29Jg==} + '@protobufjs/codegen@2.0.5': + resolution: {integrity: sha512-zgXFLzW3Ap33e6d0Wlj4MGIm6Ce8O89n/apUaGNB/jx+hw+ruWEp7EwGUshdLKVRCxZW12fp9r40E1mQrf/34g==} - '@protobufjs/eventemitter@1.1.0': - resolution: {integrity: sha512-j9ednRT81vYJ9OfVuXG6ERSTdEL1xVsNgqpkxMsbIabzSo3goCjDIveeGv5d03om39ML71RdmrGNjG5SReBP/Q==} + '@protobufjs/eventemitter@1.1.1': + resolution: {integrity: sha512-vW1GmwMZNnL+gMRaovlh9yZX74kc+TTU3FObkkurpMaRtBfLP3ldjS9KQWlwZgraRE0+dheEEoAxdzcJQ8eXZg==} - '@protobufjs/fetch@1.1.0': - resolution: {integrity: sha512-lljVXpqXebpsijW71PZaCYeIcE5on1w5DlQy5WH6GLbFryLUrBD4932W/E2BSpfRJWseIL4v/KPgBFxDOIdKpQ==} + '@protobufjs/fetch@1.1.1': + resolution: {integrity: sha512-GpptLrs57adMSuHi3VNj0mAF8dwh36LMaYF6XyJ6JMWlVsc+t42tm1HSEDmOs3A8fC9yyeisgLhsTVQokOZ0zw==} '@protobufjs/float@1.0.2': resolution: {integrity: sha512-Ddb+kVXlXst9d+R9PfTIxh1EdNkgoRe5tOX6t01f1lYWOvJnSPDBlG241QLzcyPdoNTsblLUdujGSE4RzrTZGQ==} - '@protobufjs/inquire@1.1.0': - resolution: {integrity: sha512-kdSefcPdruJiFMVSbn801t4vFK7KB/5gd2fYvrxhuJYg8ILrmn9SKSX2tZdV6V+ksulWqS7aXjBcRXl3wHoD9Q==} - '@protobufjs/path@1.1.2': resolution: {integrity: sha512-6JOcJ5Tm08dOHAbdR3GrvP+yUUfkjG5ePsHYczMFLq3ZmMkAD98cDgcT2iA1lJ9NVwFd4tH/iSSoe44YWkltEA==} '@protobufjs/pool@1.1.0': resolution: {integrity: sha512-0kELaGSIDBKvcgS4zkjz1PeddatrjYcmMWOlAuAPwAeccUrPHdUqo/J6LiymHHEiJT5NrF1UVwxY14f+fy4WQw==} - '@protobufjs/utf8@1.1.0': - resolution: {integrity: sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==} + '@protobufjs/utf8@1.1.2': + resolution: {integrity: sha512-b1UQwcEZ4yCnMCD8DAL1VlbvBJE9/IX4FTIp7BG1xYpf29SLazLSrqUkj4w7Y5y7cCVP6E5tcqqcI0xemPkHug==} '@rollup/pluginutils@4.2.1': resolution: {integrity: sha512-iKnFXr7NkdZAIHiIWE+BX5ULi/ucVFYWD6TbAV+rZctiRTY2PL6tsIKhoIOaoskiWAkgu+VsbXgUVDNLHf+InQ==} @@ -901,128 +908,141 @@ packages: rollup: optional: true - '@rollup/rollup-android-arm-eabi@4.60.2': - resolution: {integrity: sha512-dnlp69efPPg6Uaw2dVqzWRfAWRnYVb1XJ8CyyhIbZeaq4CA5/mLeZ1IEt9QqQxmbdvagjLIm2ZL8BxXv5lH4Yw==} + '@rollup/rollup-android-arm-eabi@4.60.1': + resolution: {integrity: sha512-d6FinEBLdIiK+1uACUttJKfgZREXrF0Qc2SmLII7W2AD8FfiZ9Wjd+rD/iRuf5s5dWrr1GgwXCvPqOuDquOowA==} cpu: [arm] os: [android] - '@rollup/rollup-android-arm64@4.60.2': - resolution: {integrity: sha512-OqZTwDRDchGRHHm/hwLOL7uVPB9aUvI0am/eQuWMNyFHf5PSEQmyEeYYheA0EPPKUO/l0uigCp+iaTjoLjVoHg==} + '@rollup/rollup-android-arm64@4.60.1': + resolution: {integrity: sha512-YjG/EwIDvvYI1YvYbHvDz/BYHtkY4ygUIXHnTdLhG+hKIQFBiosfWiACWortsKPKU/+dUwQQCKQM3qrDe8c9BA==} cpu: [arm64] os: [android] - '@rollup/rollup-darwin-arm64@4.60.2': - resolution: {integrity: sha512-UwRE7CGpvSVEQS8gUMBe1uADWjNnVgP3Iusyda1nSRwNDCsRjnGc7w6El6WLQsXmZTbLZx9cecegumcitNfpmA==} + '@rollup/rollup-darwin-arm64@4.60.1': + resolution: {integrity: sha512-mjCpF7GmkRtSJwon+Rq1N8+pI+8l7w5g9Z3vWj4T7abguC4Czwi3Yu/pFaLvA3TTeMVjnu3ctigusqWUfjZzvw==} cpu: [arm64] os: [darwin] - '@rollup/rollup-darwin-x64@4.60.2': - resolution: {integrity: sha512-gjEtURKLCC5VXm1I+2i1u9OhxFsKAQJKTVB8WvDAHF+oZlq0GTVFOlTlO1q3AlCTE/DF32c16ESvfgqR7343/g==} + '@rollup/rollup-darwin-x64@4.60.1': + resolution: {integrity: sha512-haZ7hJ1JT4e9hqkoT9R/19XW2QKqjfJVv+i5AGg57S+nLk9lQnJ1F/eZloRO3o9Scy9CM3wQ9l+dkXtcBgN5Ew==} cpu: [x64] os: [darwin] - '@rollup/rollup-freebsd-arm64@4.60.2': - resolution: {integrity: sha512-Bcl6CYDeAgE70cqZaMojOi/eK63h5Me97ZqAQoh77VPjMysA/4ORQBRGo3rRy45x4MzVlU9uZxs8Uwy7ZaKnBw==} + '@rollup/rollup-freebsd-arm64@4.60.1': + resolution: {integrity: sha512-czw90wpQq3ZsAVBlinZjAYTKduOjTywlG7fEeWKUA7oCmpA8xdTkxZZlwNJKWqILlq0wehoZcJYfBvOyhPTQ6w==} cpu: [arm64] os: [freebsd] - '@rollup/rollup-freebsd-x64@4.60.2': - resolution: {integrity: sha512-LU+TPda3mAE2QB0/Hp5VyeKJivpC6+tlOXd1VMoXV/YFMvk/MNk5iXeBfB4MQGRWyOYVJ01625vjkr0Az98OJQ==} + '@rollup/rollup-freebsd-x64@4.60.1': + resolution: {integrity: sha512-KVB2rqsxTHuBtfOeySEyzEOB7ltlB/ux38iu2rBQzkjbwRVlkhAGIEDiiYnO2kFOkJp+Z7pUXKyrRRFuFUKt+g==} cpu: [x64] os: [freebsd] - '@rollup/rollup-linux-arm-gnueabihf@4.60.2': - resolution: {integrity: sha512-2QxQrM+KQ7DAW4o22j+XZ6RKdxjLD7BOWTP0Bv0tmjdyhXSsr2Ul1oJDQqh9Zf5qOwTuTc7Ek83mOFaKnodPjg==} + '@rollup/rollup-linux-arm-gnueabihf@4.60.1': + resolution: {integrity: sha512-L+34Qqil+v5uC0zEubW7uByo78WOCIrBvci69E7sFASRl0X7b/MB6Cqd1lky/CtcSVTydWa2WZwFuWexjS5o6g==} cpu: [arm] os: [linux] + libc: [glibc] - '@rollup/rollup-linux-arm-musleabihf@4.60.2': - resolution: {integrity: sha512-TbziEu2DVsTEOPif2mKWkMeDMLoYjx95oESa9fkQQK7r/Orta0gnkcDpzwufEcAO2BLBsD7mZkXGFqEdMRRwfw==} + '@rollup/rollup-linux-arm-musleabihf@4.60.1': + resolution: {integrity: sha512-n83O8rt4v34hgFzlkb1ycniJh7IR5RCIqt6mz1VRJD6pmhRi0CXdmfnLu9dIUS6buzh60IvACM842Ffb3xd6Gg==} cpu: [arm] os: [linux] + libc: [musl] - '@rollup/rollup-linux-arm64-gnu@4.60.2': - resolution: {integrity: sha512-bO/rVDiDUuM2YfuCUwZ1t1cP+/yqjqz+Xf2VtkdppefuOFS2OSeAfgafaHNkFn0t02hEyXngZkxtGqXcXwO8Rg==} + '@rollup/rollup-linux-arm64-gnu@4.60.1': + resolution: {integrity: sha512-Nql7sTeAzhTAja3QXeAI48+/+GjBJ+QmAH13snn0AJSNL50JsDqotyudHyMbO2RbJkskbMbFJfIJKWA6R1LCJQ==} cpu: [arm64] os: [linux] + libc: [glibc] - '@rollup/rollup-linux-arm64-musl@4.60.2': - resolution: {integrity: sha512-hr26p7e93Rl0Za+JwW7EAnwAvKkehh12BU1Llm9Ykiibg4uIr2rbpxG9WCf56GuvidlTG9KiiQT/TXT1yAWxTA==} + '@rollup/rollup-linux-arm64-musl@4.60.1': + resolution: {integrity: sha512-+pUymDhd0ys9GcKZPPWlFiZ67sTWV5UU6zOJat02M1+PiuSGDziyRuI/pPue3hoUwm2uGfxdL+trT6Z9rxnlMA==} cpu: [arm64] os: [linux] + libc: [musl] - '@rollup/rollup-linux-loong64-gnu@4.60.2': - resolution: {integrity: sha512-pOjB/uSIyDt+ow3k/RcLvUAOGpysT2phDn7TTUB3n75SlIgZzM6NKAqlErPhoFU+npgY3/n+2HYIQVbF70P9/A==} + '@rollup/rollup-linux-loong64-gnu@4.60.1': + resolution: {integrity: sha512-VSvgvQeIcsEvY4bKDHEDWcpW4Yw7BtlKG1GUT4FzBUlEKQK0rWHYBqQt6Fm2taXS+1bXvJT6kICu5ZwqKCnvlQ==} cpu: [loong64] os: [linux] + libc: [glibc] - '@rollup/rollup-linux-loong64-musl@4.60.2': - resolution: {integrity: sha512-2/w+q8jszv9Ww1c+6uJT3OwqhdmGP2/4T17cu8WuwyUuuaCDDJ2ojdyYwZzCxx0GcsZBhzi3HmH+J5pZNXnd+Q==} + '@rollup/rollup-linux-loong64-musl@4.60.1': + resolution: {integrity: sha512-4LqhUomJqwe641gsPp6xLfhqWMbQV04KtPp7/dIp0nzPxAkNY1AbwL5W0MQpcalLYk07vaW9Kp1PBhdpZYYcEw==} cpu: [loong64] os: [linux] + libc: [musl] - '@rollup/rollup-linux-ppc64-gnu@4.60.2': - resolution: {integrity: sha512-11+aL5vKheYgczxtPVVRhdptAM2H7fcDR5Gw4/bTcteuZBlH4oP9f5s9zYO9aGZvoGeBpqXI/9TZZihZ609wKw==} + '@rollup/rollup-linux-ppc64-gnu@4.60.1': + resolution: {integrity: sha512-tLQQ9aPvkBxOc/EUT6j3pyeMD6Hb8QF2BTBnCQWP/uu1lhc9AIrIjKnLYMEroIz/JvtGYgI9dF3AxHZNaEH0rw==} cpu: [ppc64] os: [linux] + libc: [glibc] - '@rollup/rollup-linux-ppc64-musl@4.60.2': - resolution: {integrity: sha512-i16fokAGK46IVZuV8LIIwMdtqhin9hfYkCh8pf8iC3QU3LpwL+1FSFGej+O7l3E/AoknL6Dclh2oTdnRMpTzFQ==} + '@rollup/rollup-linux-ppc64-musl@4.60.1': + resolution: {integrity: sha512-RMxFhJwc9fSXP6PqmAz4cbv3kAyvD1etJFjTx4ONqFP9DkTkXsAMU4v3Vyc5BgzC+anz7nS/9tp4obsKfqkDHg==} cpu: [ppc64] os: [linux] + libc: [musl] - '@rollup/rollup-linux-riscv64-gnu@4.60.2': - resolution: {integrity: sha512-49FkKS6RGQoriDSK/6E2GkAsAuU5kETFCh7pG4yD/ylj9rKhTmO3elsnmBvRD4PgJPds5W2PkhC82aVwmUcJ7A==} + '@rollup/rollup-linux-riscv64-gnu@4.60.1': + resolution: {integrity: sha512-QKgFl+Yc1eEk6MmOBfRHYF6lTxiiiV3/z/BRrbSiW2I7AFTXoBFvdMEyglohPj//2mZS4hDOqeB0H1ACh3sBbg==} cpu: [riscv64] os: [linux] + libc: [glibc] - '@rollup/rollup-linux-riscv64-musl@4.60.2': - resolution: {integrity: sha512-mjYNkHPfGpUR00DuM1ZZIgs64Hpf4bWcz9Z41+4Q+pgDx73UwWdAYyf6EG/lRFldmdHHzgrYyge5akFUW0D3mQ==} + '@rollup/rollup-linux-riscv64-musl@4.60.1': + resolution: {integrity: sha512-RAjXjP/8c6ZtzatZcA1RaQr6O1TRhzC+adn8YZDnChliZHviqIjmvFwHcxi4JKPSDAt6Uhf/7vqcBzQJy0PDJg==} cpu: [riscv64] os: [linux] + libc: [musl] - '@rollup/rollup-linux-s390x-gnu@4.60.2': - resolution: {integrity: sha512-ALyvJz965BQk8E9Al/JDKKDLH2kfKFLTGMlgkAbbYtZuJt9LU8DW3ZoDMCtQpXAltZxwBHevXz5u+gf0yA0YoA==} + '@rollup/rollup-linux-s390x-gnu@4.60.1': + resolution: {integrity: sha512-wcuocpaOlaL1COBYiA89O6yfjlp3RwKDeTIA0hM7OpmhR1Bjo9j31G1uQVpDlTvwxGn2nQs65fBFL5UFd76FcQ==} cpu: [s390x] os: [linux] + libc: [glibc] - '@rollup/rollup-linux-x64-gnu@4.60.2': - resolution: {integrity: sha512-UQjrkIdWrKI626Du8lCQ6MJp/6V1LAo2bOK9OTu4mSn8GGXIkPXk/Vsp4bLHCd9Z9Iz2OTEaokUE90VweJgIYQ==} + '@rollup/rollup-linux-x64-gnu@4.60.1': + resolution: {integrity: sha512-77PpsFQUCOiZR9+LQEFg9GClyfkNXj1MP6wRnzYs0EeWbPcHs02AXu4xuUbM1zhwn3wqaizle3AEYg5aeoohhg==} cpu: [x64] os: [linux] + libc: [glibc] - '@rollup/rollup-linux-x64-musl@4.60.2': - resolution: {integrity: sha512-bTsRGj6VlSdn/XD4CGyzMnzaBs9bsRxy79eTqTCBsA8TMIEky7qg48aPkvJvFe1HyzQ5oMZdg7AnVlWQSKLTnw==} + '@rollup/rollup-linux-x64-musl@4.60.1': + resolution: {integrity: sha512-5cIATbk5vynAjqqmyBjlciMJl1+R/CwX9oLk/EyiFXDWd95KpHdrOJT//rnUl4cUcskrd0jCCw3wpZnhIHdD9w==} cpu: [x64] os: [linux] + libc: [musl] - '@rollup/rollup-openbsd-x64@4.60.2': - resolution: {integrity: sha512-6d4Z3534xitaA1FcMWP7mQPq5zGwBmGbhphh2DwaA1aNIXUu3KTOfwrWpbwI4/Gr0uANo7NTtaykFyO2hPuFLg==} + '@rollup/rollup-openbsd-x64@4.60.1': + resolution: {integrity: sha512-cl0w09WsCi17mcmWqqglez9Gk8isgeWvoUZ3WiJFYSR3zjBQc2J5/ihSjpl+VLjPqjQ/1hJRcqBfLjssREQILw==} cpu: [x64] os: [openbsd] - '@rollup/rollup-openharmony-arm64@4.60.2': - resolution: {integrity: sha512-NetAg5iO2uN7eB8zE5qrZ3CSil+7IJt4WDFLcC75Ymywq1VZVD6qJ6EvNLjZ3rEm6gB7XW5JdT60c6MN35Z85Q==} + '@rollup/rollup-openharmony-arm64@4.60.1': + resolution: {integrity: sha512-4Cv23ZrONRbNtbZa37mLSueXUCtN7MXccChtKpUnQNgF010rjrjfHx3QxkS2PI7LqGT5xXyYs1a7LbzAwT0iCA==} cpu: [arm64] os: [openharmony] - '@rollup/rollup-win32-arm64-msvc@4.60.2': - resolution: {integrity: sha512-NCYhOotpgWZ5kdxCZsv6Iudx0wX8980Q/oW4pNFNihpBKsDbEA1zpkfxJGC0yugsUuyDZ7gL37dbzwhR0VI7pQ==} + '@rollup/rollup-win32-arm64-msvc@4.60.1': + resolution: {integrity: sha512-i1okWYkA4FJICtr7KpYzFpRTHgy5jdDbZiWfvny21iIKky5YExiDXP+zbXzm3dUcFpkEeYNHgQ5fuG236JPq0g==} cpu: [arm64] os: [win32] - '@rollup/rollup-win32-ia32-msvc@4.60.2': - resolution: {integrity: sha512-RXsaOqXxfoUBQoOgvmmijVxJnW2IGB0eoMO7F8FAjaj0UTywUO/luSqimWBJn04WNgUkeNhh7fs7pESXajWmkg==} + '@rollup/rollup-win32-ia32-msvc@4.60.1': + resolution: {integrity: sha512-u09m3CuwLzShA0EYKMNiFgcjjzwqtUMLmuCJLeZWjjOYA3IT2Di09KaxGBTP9xVztWyIWjVdsB2E9goMjZvTQg==} cpu: [ia32] os: [win32] - '@rollup/rollup-win32-x64-gnu@4.60.2': - resolution: {integrity: sha512-qdAzEULD+/hzObedtmV6iBpdL5TIbKVztGiK7O3/KYSf+HIzU257+MX1EXJcyIiDbMAqmbwaufcYPvyRryeZtA==} + '@rollup/rollup-win32-x64-gnu@4.60.1': + resolution: {integrity: sha512-k+600V9Zl1CM7eZxJgMyTUzmrmhB/0XZnF4pRypKAlAgxmedUA+1v9R+XOFv56W4SlHEzfeMtzujLJD22Uz5zg==} cpu: [x64] os: [win32] - '@rollup/rollup-win32-x64-msvc@4.60.2': - resolution: {integrity: sha512-Nd/SgG27WoA9e+/TdK74KnHz852TLa94ovOYySo/yMPuTmpckK/jIF2jSwS3g7ELSKXK13/cVdmg1Z/DaCWKxA==} + '@rollup/rollup-win32-x64-msvc@4.60.1': + resolution: {integrity: sha512-lWMnixq/QzxyhTV6NjQJ4SFo1J6PvOX8vUx5Wb4bBPsEb+8xZ89Bz6kOXpfXj9ak9AHTQVQzlgzBEc1SyM27xQ==} cpu: [x64] os: [win32] @@ -1086,23 +1106,14 @@ packages: peerDependencies: '@babel/core': ^7.12.10 - base64-js@1.5.1: - resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==} - - baseline-browser-mapping@2.10.20: - resolution: {integrity: sha512-1AaXxEPfXT+GvTBJFuy4yXVHWJBXa4OdbIebGN/wX5DlsIkU0+wzGnd2lOzokSk51d5LUmqjgBLRLlypLUqInQ==} + baseline-browser-mapping@2.10.19: + resolution: {integrity: sha512-qCkNLi2sfBOn8XhZQ0FXsT1Ki/Yo5P90hrkRamVFRS7/KV9hpfA4HkoWNU152+8w0zPjnxo5psx5NL3PSGgv5g==} engines: {node: '>=6.0.0'} hasBin: true - better-sqlite3@12.11.1: - resolution: {integrity: sha512-dq9AtApgg5PGFtBzPFSBl3HZQjHok5gaQCM6zh2Yk0aSmDCs1CbnVI8/HgASQkNKsWFpseIO9beg5xxpYhbIfA==} - engines: {node: 20.x || 22.x || 23.x || 24.x || 25.x || 26.x} - - bindings@1.5.0: - resolution: {integrity: sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==} - - bl@4.1.0: - resolution: {integrity: sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==} + better-sqlite3@13.0.3: + resolution: {integrity: sha512-RbOBxmLBG8uvFUc15X9+9SFemKcQ0WBuISBVkpuiaUB2qblC8UWlHEjdWVoZ8AdhSwmoEgsiXKfopX0CQxaACQ==} + engines: {node: '>=22'} boolbase@1.0.0: resolution: {integrity: sha512-JZOSA7Mo9sNGB8+UjSgzdLtokWAky1zbztM3WRLCbZ70/3cTANmQmOdR7y2g+J0e2WXywy1yS468tY+IruqEww==} @@ -1116,9 +1127,6 @@ packages: engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7} hasBin: true - buffer@5.7.1: - resolution: {integrity: sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==} - cac@6.7.14: resolution: {integrity: sha512-b6Ilus+c3RrdDk+JhLKUAQfzzgLEPy6wcXqS7f/xe1EETvsDP6GORG7SFuOs6cID5YkqchW/LXZbX5bc8j7ZcQ==} engines: {node: '>=8'} @@ -1134,9 +1142,6 @@ packages: resolution: {integrity: sha512-PAJdDJusoxnwm1VwW07VWwUN1sl7smmC3OKggvndJFadxxDRyFJBX/ggnu/KE4kQAB7a3Dp8f/YXC1FlUprWmA==} engines: {node: '>= 16'} - chownr@1.1.4: - resolution: {integrity: sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg==} - convert-source-map@2.0.0: resolution: {integrity: sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==} @@ -1156,18 +1161,10 @@ packages: supports-color: optional: true - decompress-response@6.0.0: - resolution: {integrity: sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ==} - engines: {node: '>=10'} - deep-eql@5.0.2: resolution: {integrity: sha512-h5k/5U50IJJFpzfL6nO9jaaumfjO/f2NjK/oYB2Djzm4p9L+3T9qWpZqZ2hAbLPuuYq9wrU08WQyBTL5GbPk5Q==} engines: {node: '>=6'} - deep-extend@0.6.0: - resolution: {integrity: sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==} - engines: {node: '>=4.0.0'} - define-data-property@1.1.4: resolution: {integrity: sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==} engines: {node: '>= 0.4'} @@ -1196,11 +1193,8 @@ packages: domutils@3.2.2: resolution: {integrity: sha512-6kZKyUajlDuqlHKVX1w7gyslj9MPIXzIFiz/rGu35uC1wMi+kMhQwGhl4lt9unC9Vb9INnY9Z3/ZA3+FhASLaw==} - electron-to-chromium@1.5.343: - resolution: {integrity: sha512-YHnQ3MXI08icvL9ZKnEBy05F2EQ8ob01UaMOuMbM8l+4UcAq6MPPbBTJBbsBUg3H8JeZNt+O4fjsoWth3p6IFg==} - - end-of-stream@1.4.5: - resolution: {integrity: sha512-ooEGc6HP26xXq/N+GCGOT0JKCLDGrq2bQUZrQ7gyrJiZANJ/8YDTxTpQBXGMn+WbIQXNVpyWymm7KYVICQnyOg==} + electron-to-chromium@1.5.340: + resolution: {integrity: sha512-908qahOGocRMinT2nM3ajCEM99H4iPdv84eagPP3FfZy/1ZGeOy2CZYzjhms81ckOPCXPlW7LkY4XpxD8r1DrA==} entities@4.5.0: resolution: {integrity: sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==} @@ -1244,23 +1238,13 @@ packages: estree-walker@3.0.3: resolution: {integrity: sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==} - expand-template@2.0.3: - resolution: {integrity: sha512-XYfuKMvj4O35f/pOXLObndIRvyQ+/+6AhODh+OKWj9S9498pHHn/IMszH+gt0fBCRWMNfk1ZSp5x3AifmnI2vg==} - engines: {node: '>=6'} - expect-type@1.3.0: resolution: {integrity: sha512-knvyeauYhqjOYvQ66MznSMs83wmHrCycNEN6Ao+2AeYEfxUIkuiVxdEa1qlGEPK+We3n0THiDciYSsCcgW/DoA==} engines: {node: '>=12.0.0'} - file-uri-to-path@1.0.0: - resolution: {integrity: sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==} - flatbuffers@25.9.23: resolution: {integrity: sha512-MI1qs7Lo4Syw0EOzUl0xjs2lsoeqFku44KpngfIduHBYvzm8h2+7K8YMQh1JtVVVrUvhLpNwqVi4DERegUJhPQ==} - fs-constants@1.0.0: - resolution: {integrity: sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==} - fsevents@2.3.3: resolution: {integrity: sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==} engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} @@ -1273,9 +1257,6 @@ packages: get-tsconfig@4.14.0: resolution: {integrity: sha512-yTb+8DXzDREzgvYmh6s9vHsSVCHeC0G3PI5bEXNBHtmshPnO+S5O7qgLEOn0I5QvMy6kpZN8K1NKGyilLb93wA==} - github-from-package@0.0.0: - resolution: {integrity: sha512-SyHy3T1v2NUXn29OsWdxmK6RwHD+vkj3v8en8AOBZ1wBQ/hCAQ5bAQTD02kW4W9tUp/3Qh6J8r9EvntiyCmOOw==} - global-agent@3.0.0: resolution: {integrity: sha512-PT6XReJ+D07JvGoxQMkT6qji/jVNfX/h364XHZOWeRzy64sSFr+xJ5OX7LI3b4MPQzdL4H8Y8M0xzPpsVMwA8Q==} engines: {node: '>=10.0'} @@ -1298,15 +1279,6 @@ packages: resolution: {integrity: sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==} hasBin: true - ieee754@1.2.1: - resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==} - - inherits@2.0.4: - resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==} - - ini@1.3.8: - resolution: {integrity: sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==} - js-tokens@4.0.0: resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==} @@ -1342,16 +1314,6 @@ packages: resolution: {integrity: sha512-OkeDaAZ/bQCxeFAozM55PKcKU0yJMPGifLwV4Qgjitu+5MoAfSQN4lsLJeXZ1b8w0x+/Emda6MZgXS1jvsapng==} engines: {node: '>=10'} - mimic-response@3.1.0: - resolution: {integrity: sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ==} - engines: {node: '>=10'} - - minimist@1.2.8: - resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==} - - mkdirp-classic@0.5.3: - resolution: {integrity: sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==} - ms@2.1.3: resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==} @@ -1360,18 +1322,15 @@ packages: engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} hasBin: true - napi-build-utils@2.0.0: - resolution: {integrity: sha512-GEbrYkbfF7MoNaoh2iGG84Mnf/WZfB0GdGEsM8wz7Expx/LlWf5U8t9nvJKXSp3qr5IsEbK04cBGhol/KwOsWA==} - - node-abi@3.89.0: - resolution: {integrity: sha512-6u9UwL0HlAl21+agMN3YAMXcKByMqwGx+pq+P76vii5f7hTPtKDp08/H9py6DY+cfDw7kQNTGEj/rly3IgbNQA==} - engines: {node: '>=10'} + node-addon-api@8.9.2: + resolution: {integrity: sha512-VijLXbi3UACN69I0JVXJsX4tjACjNoQDgv2gTF6sx2wWEi8tkSg2eX8p5gSIFi8z2+DL3oHmY6OyKce38SDolg==} + engines: {node: ^18 || ^20 || >= 21} node-html-parser@6.1.13: resolution: {integrity: sha512-qIsTMOY4C/dAa5Q5vsobRpOOvPfC4pB61UVW2uSwZNUp0QU/jCekTal1vMmbO0DgdHeLUJpv/ARmDqErVxA3Sg==} - node-releases@2.0.38: - resolution: {integrity: sha512-3qT/88Y3FbH/Kx4szpQQ4HzUbVrHPKTLVpVocKiLfoYvw9XSGOX2FmD2d6DrXbVYyAQTF2HeF6My8jmzx7/CRw==} + node-releases@2.0.37: + resolution: {integrity: sha512-1h5gKZCF+pO/o3Iqt5Jp7wc9rH3eJJ0+nh/CIoiRwjRxde/hAHyLPXYN4V3CqKAbiZPSeJFSWHmJsbkicta0Eg==} nth-check@2.1.1: resolution: {integrity: sha512-lqjrjmaOoAnWfMmBPL+XNnynZh2+swxiX3WUE0s4yEHI6m+AwrK2UZOimIRl3X/4QctVqS8AiZjFqyOGrMXb/w==} @@ -1380,9 +1339,6 @@ packages: resolution: {integrity: sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==} engines: {node: '>= 0.4'} - once@1.4.0: - resolution: {integrity: sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==} - onnxruntime-common@1.24.0-dev.20251116-b39e144322: resolution: {integrity: sha512-BOoomdHYmNRL5r4iQ4bMvsl2t0/hzVQ3OM3PHD0gxeXu1PmggqBv3puZicEUVOA3AtHHYmqZtjMj9FOfGrATTw==} @@ -1424,27 +1380,10 @@ packages: preact@10.29.1: resolution: {integrity: sha512-gQCLc/vWroE8lIpleXtdJhTFDogTdZG9AjMUpVkDf2iTCNwYNWA+u16dL41TqUDJO4gm2IgrcMv3uTpjd4Pwmg==} - prebuild-install@7.1.3: - resolution: {integrity: sha512-8Mf2cbV7x1cXPUILADGI3wuhfqWvtiLA1iclTDbFRZkgRQS0NqsPZphna9V+HyTEadheuPmjaJMsbzKQFOzLug==} - engines: {node: '>=10'} - deprecated: No longer maintained. Please contact the author of the relevant native addon; alternatives are available. - hasBin: true - - protobufjs@7.5.5: - resolution: {integrity: sha512-3wY1AxV+VBNW8Yypfd1yQY9pXnqTAN+KwQxL8iYm3/BjKYMNg4i0owhEe26PWDOMaIrzeeF98Lqd5NGz4omiIg==} + protobufjs@7.6.5: + resolution: {integrity: sha512-/FPD0nUc9jH6rfFjji9IBqOz4pcSE3CsT1m7Ep6Mdb0LxSUMj8hgl6GomOvZzpNpAqqGaXA0P3VSrZLFzIhQrw==} engines: {node: '>=12.0.0'} - pump@3.0.4: - resolution: {integrity: sha512-VS7sjc6KR7e1ukRFhQSY5LM2uBWAUPiOPa/A3mkKmiMwSmRFUITt0xuj+/lesgnCv+dPIEYlkzrcyXgquIHMcA==} - - rc@1.2.8: - resolution: {integrity: sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==} - hasBin: true - - readable-stream@3.6.2: - resolution: {integrity: sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==} - engines: {node: '>= 6'} - resolve-pkg-maps@1.0.0: resolution: {integrity: sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==} @@ -1452,14 +1391,11 @@ packages: resolution: {integrity: sha512-CHhPh+UNHD2GTXNYhPWLnU8ONHdI+5DI+4EYIAOaiD63rHeYlZvyh8P+in5999TTSFgUYuKUAjzRI4mdh/p+2A==} engines: {node: '>=8.0'} - rollup@4.60.2: - resolution: {integrity: sha512-J9qZyW++QK/09NyN/zeO0dG/1GdGfyp9lV8ajHnRVLfo/uFsbji5mHnDgn/qYdUHyCkM2N+8VyspgZclfAh0eQ==} + rollup@4.60.1: + resolution: {integrity: sha512-VmtB2rFU/GroZ4oL8+ZqXgSA38O6GR8KSIvWmEFv63pQ0G6KaBH9s07PO8XTXP4vI+3UJUEypOfjkGfmSBBR0w==} engines: {node: '>=18.0.0', npm: '>=8.0.0'} hasBin: true - safe-buffer@5.2.1: - resolution: {integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==} - semver-compare@1.0.0: resolution: {integrity: sha512-YM3/ITh2MJ5MtzaM429anh+x2jiLVjqILF4m4oyQB18W7Ggea7BfqdH/wGMK7dDiMghv/6WG7znWMwUDzJiXow==} @@ -1486,12 +1422,6 @@ packages: simple-code-frame@1.3.0: resolution: {integrity: sha512-MB4pQmETUBlNs62BBeRjIFGeuy/x6gGKh7+eRUemn1rCFhqo7K+4slPqsyizCbcbYLnaYqaoZ2FWsZ/jN06D8w==} - simple-concat@1.0.1: - resolution: {integrity: sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q==} - - simple-get@4.0.1: - resolution: {integrity: sha512-brv7p5WgH0jmQJr1ZDDfKDOSeWWg+OVypG99A/5vYGPqJ6pxiaHLy8nxtFjBA7oMa01ebA9gfh1uMCFqOuXxvA==} - source-map-js@1.2.1: resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==} engines: {node: '>=0.10.0'} @@ -1513,20 +1443,6 @@ packages: std-env@3.10.0: resolution: {integrity: sha512-5GS12FdOZNliM5mAOxFRg7Ir0pWz8MdpYm6AY6VPkGpbA7ZzmbzNcBJQ0GPvvyWgcY7QAhCgf9Uy89I03faLkg==} - string_decoder@1.3.0: - resolution: {integrity: sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==} - - strip-json-comments@2.0.1: - resolution: {integrity: sha512-4gB8na07fecVVkOI6Rs4e7T6NOTki5EmL7TUduTs6bu3EdnSycntVJ4re8kgZA+wx9IueI2Y11bfbgwtzuE0KQ==} - engines: {node: '>=0.10.0'} - - tar-fs@2.1.4: - resolution: {integrity: sha512-mDAjwmZdh7LTT6pNleZ05Yt65HC3E+NiQzl672vQG38jIrehtJk/J3mNwIg+vShQPcLF/LV7CMnDW6vjj6sfYQ==} - - tar-stream@2.2.0: - resolution: {integrity: sha512-ujeqbceABgwMZxEJnk2HDY2DlnUZ+9oEcb1KzTVfYHio0UE6dG71n60d8D2I4qNvleWrrXpmjpt7vZeF1LnMZQ==} - engines: {node: '>=6'} - tinybench@2.9.0: resolution: {integrity: sha512-0+DUvqWMValLmha6lr4kD8iAMK1HzV0/aKnCtWb9v9641TnP/MFb7Pc2bxoxQjTXAErryXVgUOfv2YqNllqGeg==} @@ -1553,9 +1469,6 @@ packages: engines: {node: '>=18.0.0'} hasBin: true - tunnel-agent@0.6.0: - resolution: {integrity: sha512-McnNiV1l8RYeY8tBgEpuodCC1mLUdbSN+CYBL7kJsJNInOP8UjDDEwdk6Mw60vdLLrr5NHKZhMAOSrR2NZuQ+w==} - type-fest@0.13.1: resolution: {integrity: sha512-34R7HTnG0XIJcBSn5XhDd7nNFPRcXYRZrBB2O2jdKqYODldSzBAqzsWoZYYvduky73toYS/ESqxPvkDf/F0XMg==} engines: {node: '>=10'} @@ -1574,9 +1487,6 @@ packages: peerDependencies: browserslist: '>= 4.21.0' - util-deprecate@1.0.2: - resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==} - uuid@10.0.0: resolution: {integrity: sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==} deprecated: uuid@10 and below is no longer supported. For ESM codebases, update to uuid@latest. For CommonJS codebases, use uuid@11 (but be aware this version will likely be deprecated in 2028). @@ -1653,9 +1563,6 @@ packages: engines: {node: '>=8'} hasBin: true - wrappy@1.0.2: - resolution: {integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==} - yallist@3.1.1: resolution: {integrity: sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==} @@ -1806,8 +1713,6 @@ snapshots: '@deepseek-ai/cosmokit': 1.8.6 '@standard-schema/spec': 1.1.0 - '@deepseek-ai/cosmokit@1.8.2': {} - '@deepseek-ai/cosmokit@1.8.6': {} '@deepseek-ai/dsh-agent@0.1.0-rc.6(6889e29676788162cc6455c880e3b4a2)': @@ -1852,7 +1757,7 @@ snapshots: '@deepseek-ai/dsh-brand': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5) '@deepseek-ai/dsh-timeout': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) - '@deepseek-ai/schemastery': 3.18.1 + '@deepseek-ai/schemastery': 3.18.5 '@deepseek-ai/dsh-llm@0.2.0-rc.2(@deepseek-ai/cordis@4.0.5)': dependencies: @@ -1917,7 +1822,7 @@ snapshots: '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5) '@deepseek-ai/dsh-llm': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))) '@deepseek-ai/dsh-scope': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) - '@deepseek-ai/schemastery': 3.18.1 + '@deepseek-ai/schemastery': 3.18.5 '@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))': dependencies: @@ -1939,7 +1844,7 @@ snapshots: '@deepseek-ai/dsh-session': 0.1.0-rc.6(f5e28831e96e72c33b5ea3a797f6fddf) '@deepseek-ai/dsh-system-prompt': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-llm@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))))(@deepseek-ai/dsh-scope@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))) '@deepseek-ai/dsh-user-approval': 0.1.0-rc.6(731c4b6587473c7b25a7e36b8e78ec80) - '@deepseek-ai/schemastery': 3.18.1 + '@deepseek-ai/schemastery': 3.18.5 '@deepseek-ai/dsh-typert-protocol@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))': dependencies: @@ -1971,11 +1876,6 @@ snapshots: dependencies: '@deepseek-ai/cordis': 4.0.5 - '@deepseek-ai/schemastery@3.18.1': - dependencies: - '@deepseek-ai/cosmokit': 1.8.2 - '@standard-schema/spec': 1.1.0 - '@deepseek-ai/schemastery@3.18.5': dependencies: '@deepseek-ai/cosmokit': 1.8.6 @@ -2260,13 +2160,13 @@ snapshots: '@jridgewell/resolve-uri': 3.1.2 '@jridgewell/sourcemap-codec': 1.5.5 - '@preact/preset-vite@2.10.5(@babel/core@7.29.0)(preact@10.29.1)(rollup@4.60.2)(vite@5.4.21(@types/node@22.19.17))': + '@preact/preset-vite@2.10.5(@babel/core@7.29.0)(preact@10.29.1)(rollup@4.60.1)(vite@5.4.21(@types/node@22.19.17))': dependencies: '@babel/core': 7.29.0 '@babel/plugin-transform-react-jsx': 7.28.6(@babel/core@7.29.0) '@babel/plugin-transform-react-jsx-development': 7.27.1(@babel/core@7.29.0) '@prefresh/vite': 2.4.12(preact@10.29.1)(vite@5.4.21(@types/node@22.19.17)) - '@rollup/pluginutils': 5.3.0(rollup@4.60.2) + '@rollup/pluginutils': 5.3.0(rollup@4.60.1) babel-plugin-transform-hook-names: 1.0.2(@babel/core@7.29.0) debug: 4.4.3 magic-string: 0.30.21 @@ -2310,111 +2210,108 @@ snapshots: '@protobufjs/base64@1.1.2': {} - '@protobufjs/codegen@2.0.4': {} + '@protobufjs/codegen@2.0.5': {} - '@protobufjs/eventemitter@1.1.0': {} + '@protobufjs/eventemitter@1.1.1': {} - '@protobufjs/fetch@1.1.0': + '@protobufjs/fetch@1.1.1': dependencies: '@protobufjs/aspromise': 1.1.2 - '@protobufjs/inquire': 1.1.0 '@protobufjs/float@1.0.2': {} - '@protobufjs/inquire@1.1.0': {} - '@protobufjs/path@1.1.2': {} '@protobufjs/pool@1.1.0': {} - '@protobufjs/utf8@1.1.0': {} + '@protobufjs/utf8@1.1.2': {} '@rollup/pluginutils@4.2.1': dependencies: estree-walker: 2.0.2 picomatch: 2.3.2 - '@rollup/pluginutils@5.3.0(rollup@4.60.2)': + '@rollup/pluginutils@5.3.0(rollup@4.60.1)': dependencies: '@types/estree': 1.0.8 estree-walker: 2.0.2 picomatch: 4.0.4 optionalDependencies: - rollup: 4.60.2 + rollup: 4.60.1 - '@rollup/rollup-android-arm-eabi@4.60.2': + '@rollup/rollup-android-arm-eabi@4.60.1': optional: true - '@rollup/rollup-android-arm64@4.60.2': + '@rollup/rollup-android-arm64@4.60.1': optional: true - '@rollup/rollup-darwin-arm64@4.60.2': + '@rollup/rollup-darwin-arm64@4.60.1': optional: true - '@rollup/rollup-darwin-x64@4.60.2': + '@rollup/rollup-darwin-x64@4.60.1': optional: true - '@rollup/rollup-freebsd-arm64@4.60.2': + '@rollup/rollup-freebsd-arm64@4.60.1': optional: true - '@rollup/rollup-freebsd-x64@4.60.2': + '@rollup/rollup-freebsd-x64@4.60.1': optional: true - '@rollup/rollup-linux-arm-gnueabihf@4.60.2': + '@rollup/rollup-linux-arm-gnueabihf@4.60.1': optional: true - '@rollup/rollup-linux-arm-musleabihf@4.60.2': + '@rollup/rollup-linux-arm-musleabihf@4.60.1': optional: true - '@rollup/rollup-linux-arm64-gnu@4.60.2': + '@rollup/rollup-linux-arm64-gnu@4.60.1': optional: true - '@rollup/rollup-linux-arm64-musl@4.60.2': + '@rollup/rollup-linux-arm64-musl@4.60.1': optional: true - '@rollup/rollup-linux-loong64-gnu@4.60.2': + '@rollup/rollup-linux-loong64-gnu@4.60.1': optional: true - '@rollup/rollup-linux-loong64-musl@4.60.2': + '@rollup/rollup-linux-loong64-musl@4.60.1': optional: true - '@rollup/rollup-linux-ppc64-gnu@4.60.2': + '@rollup/rollup-linux-ppc64-gnu@4.60.1': optional: true - '@rollup/rollup-linux-ppc64-musl@4.60.2': + '@rollup/rollup-linux-ppc64-musl@4.60.1': optional: true - '@rollup/rollup-linux-riscv64-gnu@4.60.2': + '@rollup/rollup-linux-riscv64-gnu@4.60.1': optional: true - '@rollup/rollup-linux-riscv64-musl@4.60.2': + '@rollup/rollup-linux-riscv64-musl@4.60.1': optional: true - '@rollup/rollup-linux-s390x-gnu@4.60.2': + '@rollup/rollup-linux-s390x-gnu@4.60.1': optional: true - '@rollup/rollup-linux-x64-gnu@4.60.2': + '@rollup/rollup-linux-x64-gnu@4.60.1': optional: true - '@rollup/rollup-linux-x64-musl@4.60.2': + '@rollup/rollup-linux-x64-musl@4.60.1': optional: true - '@rollup/rollup-openbsd-x64@4.60.2': + '@rollup/rollup-openbsd-x64@4.60.1': optional: true - '@rollup/rollup-openharmony-arm64@4.60.2': + '@rollup/rollup-openharmony-arm64@4.60.1': optional: true - '@rollup/rollup-win32-arm64-msvc@4.60.2': + '@rollup/rollup-win32-arm64-msvc@4.60.1': optional: true - '@rollup/rollup-win32-ia32-msvc@4.60.2': + '@rollup/rollup-win32-ia32-msvc@4.60.1': optional: true - '@rollup/rollup-win32-x64-gnu@4.60.2': + '@rollup/rollup-win32-x64-gnu@4.60.1': optional: true - '@rollup/rollup-win32-x64-msvc@4.60.2': + '@rollup/rollup-win32-x64-msvc@4.60.1': optional: true '@sinclair/typebox@0.34.49': {} @@ -2481,24 +2378,11 @@ snapshots: dependencies: '@babel/core': 7.29.0 - base64-js@1.5.1: {} - - baseline-browser-mapping@2.10.20: {} - - better-sqlite3@12.11.1: - dependencies: - bindings: 1.5.0 - prebuild-install: 7.1.3 - - bindings@1.5.0: - dependencies: - file-uri-to-path: 1.0.0 + baseline-browser-mapping@2.10.19: {} - bl@4.1.0: + better-sqlite3@13.0.3: dependencies: - buffer: 5.7.1 - inherits: 2.0.4 - readable-stream: 3.6.2 + node-addon-api: 8.9.2 boolbase@1.0.0: {} @@ -2506,17 +2390,12 @@ snapshots: browserslist@4.28.2: dependencies: - baseline-browser-mapping: 2.10.20 + baseline-browser-mapping: 2.10.19 caniuse-lite: 1.0.30001788 - electron-to-chromium: 1.5.343 - node-releases: 2.0.38 + electron-to-chromium: 1.5.340 + node-releases: 2.0.37 update-browserslist-db: 1.2.3(browserslist@4.28.2) - buffer@5.7.1: - dependencies: - base64-js: 1.5.1 - ieee754: 1.2.1 - cac@6.7.14: {} caniuse-lite@1.0.30001788: {} @@ -2531,8 +2410,6 @@ snapshots: check-error@2.1.3: {} - chownr@1.1.4: {} - convert-source-map@2.0.0: {} css-select@5.2.2: @@ -2549,14 +2426,8 @@ snapshots: dependencies: ms: 2.1.3 - decompress-response@6.0.0: - dependencies: - mimic-response: 3.1.0 - deep-eql@5.0.2: {} - deep-extend@0.6.0: {} - define-data-property@1.1.4: dependencies: es-define-property: 1.0.1 @@ -2591,11 +2462,7 @@ snapshots: domelementtype: 2.3.0 domhandler: 5.0.3 - electron-to-chromium@1.5.343: {} - - end-of-stream@1.4.5: - dependencies: - once: 1.4.0 + electron-to-chromium@1.5.340: {} entities@4.5.0: {} @@ -2672,16 +2539,10 @@ snapshots: dependencies: '@types/estree': 1.0.8 - expand-template@2.0.3: {} - expect-type@1.3.0: {} - file-uri-to-path@1.0.0: {} - flatbuffers@25.9.23: {} - fs-constants@1.0.0: {} - fsevents@2.3.3: optional: true @@ -2691,8 +2552,6 @@ snapshots: dependencies: resolve-pkg-maps: 1.0.0 - github-from-package@0.0.0: {} - global-agent@3.0.0: dependencies: boolean: 3.2.0 @@ -2717,12 +2576,6 @@ snapshots: he@1.2.0: {} - ieee754@1.2.1: {} - - inherits@2.0.4: {} - - ini@1.3.8: {} - js-tokens@4.0.0: {} jsesc@3.1.0: {} @@ -2749,28 +2602,18 @@ snapshots: dependencies: escape-string-regexp: 4.0.0 - mimic-response@3.1.0: {} - - minimist@1.2.8: {} - - mkdirp-classic@0.5.3: {} - ms@2.1.3: {} nanoid@3.3.11: {} - napi-build-utils@2.0.0: {} - - node-abi@3.89.0: - dependencies: - semver: 7.7.4 + node-addon-api@8.9.2: {} node-html-parser@6.1.13: dependencies: css-select: 5.2.2 he: 1.2.0 - node-releases@2.0.38: {} + node-releases@2.0.37: {} nth-check@2.1.1: dependencies: @@ -2778,10 +2621,6 @@ snapshots: object-keys@1.1.1: {} - once@1.4.0: - dependencies: - wrappy: 1.0.2 - onnxruntime-common@1.24.0-dev.20251116-b39e144322: {} onnxruntime-common@1.24.3: {} @@ -2799,7 +2638,7 @@ snapshots: long: 5.3.2 onnxruntime-common: 1.24.0-dev.20251116-b39e144322 platform: 1.3.6 - protobufjs: 7.5.5 + protobufjs: 7.6.5 pathe@1.1.2: {} @@ -2821,54 +2660,20 @@ snapshots: preact@10.29.1: {} - prebuild-install@7.1.3: - dependencies: - detect-libc: 2.1.2 - expand-template: 2.0.3 - github-from-package: 0.0.0 - minimist: 1.2.8 - mkdirp-classic: 0.5.3 - napi-build-utils: 2.0.0 - node-abi: 3.89.0 - pump: 3.0.4 - rc: 1.2.8 - simple-get: 4.0.1 - tar-fs: 2.1.4 - tunnel-agent: 0.6.0 - - protobufjs@7.5.5: + protobufjs@7.6.5: dependencies: '@protobufjs/aspromise': 1.1.2 '@protobufjs/base64': 1.1.2 - '@protobufjs/codegen': 2.0.4 - '@protobufjs/eventemitter': 1.1.0 - '@protobufjs/fetch': 1.1.0 + '@protobufjs/codegen': 2.0.5 + '@protobufjs/eventemitter': 1.1.1 + '@protobufjs/fetch': 1.1.1 '@protobufjs/float': 1.0.2 - '@protobufjs/inquire': 1.1.0 '@protobufjs/path': 1.1.2 '@protobufjs/pool': 1.1.0 - '@protobufjs/utf8': 1.1.0 + '@protobufjs/utf8': 1.1.2 '@types/node': 22.19.17 long: 5.3.2 - pump@3.0.4: - dependencies: - end-of-stream: 1.4.5 - once: 1.4.0 - - rc@1.2.8: - dependencies: - deep-extend: 0.6.0 - ini: 1.3.8 - minimist: 1.2.8 - strip-json-comments: 2.0.1 - - readable-stream@3.6.2: - dependencies: - inherits: 2.0.4 - string_decoder: 1.3.0 - util-deprecate: 1.0.2 - resolve-pkg-maps@1.0.0: {} roarr@2.15.4: @@ -2880,39 +2685,37 @@ snapshots: semver-compare: 1.0.0 sprintf-js: 1.1.3 - rollup@4.60.2: + rollup@4.60.1: dependencies: '@types/estree': 1.0.8 optionalDependencies: - '@rollup/rollup-android-arm-eabi': 4.60.2 - '@rollup/rollup-android-arm64': 4.60.2 - '@rollup/rollup-darwin-arm64': 4.60.2 - '@rollup/rollup-darwin-x64': 4.60.2 - '@rollup/rollup-freebsd-arm64': 4.60.2 - '@rollup/rollup-freebsd-x64': 4.60.2 - '@rollup/rollup-linux-arm-gnueabihf': 4.60.2 - '@rollup/rollup-linux-arm-musleabihf': 4.60.2 - '@rollup/rollup-linux-arm64-gnu': 4.60.2 - '@rollup/rollup-linux-arm64-musl': 4.60.2 - '@rollup/rollup-linux-loong64-gnu': 4.60.2 - '@rollup/rollup-linux-loong64-musl': 4.60.2 - '@rollup/rollup-linux-ppc64-gnu': 4.60.2 - '@rollup/rollup-linux-ppc64-musl': 4.60.2 - '@rollup/rollup-linux-riscv64-gnu': 4.60.2 - '@rollup/rollup-linux-riscv64-musl': 4.60.2 - '@rollup/rollup-linux-s390x-gnu': 4.60.2 - '@rollup/rollup-linux-x64-gnu': 4.60.2 - '@rollup/rollup-linux-x64-musl': 4.60.2 - '@rollup/rollup-openbsd-x64': 4.60.2 - '@rollup/rollup-openharmony-arm64': 4.60.2 - '@rollup/rollup-win32-arm64-msvc': 4.60.2 - '@rollup/rollup-win32-ia32-msvc': 4.60.2 - '@rollup/rollup-win32-x64-gnu': 4.60.2 - '@rollup/rollup-win32-x64-msvc': 4.60.2 + '@rollup/rollup-android-arm-eabi': 4.60.1 + '@rollup/rollup-android-arm64': 4.60.1 + '@rollup/rollup-darwin-arm64': 4.60.1 + '@rollup/rollup-darwin-x64': 4.60.1 + '@rollup/rollup-freebsd-arm64': 4.60.1 + '@rollup/rollup-freebsd-x64': 4.60.1 + '@rollup/rollup-linux-arm-gnueabihf': 4.60.1 + '@rollup/rollup-linux-arm-musleabihf': 4.60.1 + '@rollup/rollup-linux-arm64-gnu': 4.60.1 + '@rollup/rollup-linux-arm64-musl': 4.60.1 + '@rollup/rollup-linux-loong64-gnu': 4.60.1 + '@rollup/rollup-linux-loong64-musl': 4.60.1 + '@rollup/rollup-linux-ppc64-gnu': 4.60.1 + '@rollup/rollup-linux-ppc64-musl': 4.60.1 + '@rollup/rollup-linux-riscv64-gnu': 4.60.1 + '@rollup/rollup-linux-riscv64-musl': 4.60.1 + '@rollup/rollup-linux-s390x-gnu': 4.60.1 + '@rollup/rollup-linux-x64-gnu': 4.60.1 + '@rollup/rollup-linux-x64-musl': 4.60.1 + '@rollup/rollup-openbsd-x64': 4.60.1 + '@rollup/rollup-openharmony-arm64': 4.60.1 + '@rollup/rollup-win32-arm64-msvc': 4.60.1 + '@rollup/rollup-win32-ia32-msvc': 4.60.1 + '@rollup/rollup-win32-x64-gnu': 4.60.1 + '@rollup/rollup-win32-x64-msvc': 4.60.1 fsevents: 2.3.3 - safe-buffer@5.2.1: {} - semver-compare@1.0.0: {} semver@6.3.1: {} @@ -2960,14 +2763,6 @@ snapshots: dependencies: kolorist: 1.8.0 - simple-concat@1.0.1: {} - - simple-get@4.0.1: - dependencies: - decompress-response: 6.0.0 - once: 1.4.0 - simple-concat: 1.0.1 - source-map-js@1.2.1: {} source-map@0.7.6: {} @@ -2980,27 +2775,6 @@ snapshots: std-env@3.10.0: {} - string_decoder@1.3.0: - dependencies: - safe-buffer: 5.2.1 - - strip-json-comments@2.0.1: {} - - tar-fs@2.1.4: - dependencies: - chownr: 1.1.4 - mkdirp-classic: 0.5.3 - pump: 3.0.4 - tar-stream: 2.2.0 - - tar-stream@2.2.0: - dependencies: - bl: 4.1.0 - end-of-stream: 1.4.5 - fs-constants: 1.0.0 - inherits: 2.0.4 - readable-stream: 3.6.2 - tinybench@2.9.0: {} tinyexec@0.3.2: {} @@ -3021,10 +2795,6 @@ snapshots: optionalDependencies: fsevents: 2.3.3 - tunnel-agent@0.6.0: - dependencies: - safe-buffer: 5.2.1 - type-fest@0.13.1: {} typescript@5.9.3: {} @@ -3037,8 +2807,6 @@ snapshots: escalade: 3.2.0 picocolors: 1.1.1 - util-deprecate@1.0.2: {} - uuid@10.0.0: {} vite-node@2.1.9(@types/node@22.19.17): @@ -3073,7 +2841,7 @@ snapshots: dependencies: esbuild: 0.21.5 postcss: 8.5.10 - rollup: 4.60.2 + rollup: 4.60.1 optionalDependencies: '@types/node': 22.19.17 fsevents: 2.3.3 @@ -3118,8 +2886,6 @@ snapshots: siginfo: 2.0.0 stackback: 0.0.2 - wrappy@1.0.2: {} - yallist@3.1.1: {} yaml@2.8.3: {} diff --git a/apps/memos-local-plugin/pnpm-workspace.yaml b/apps/memos-local-plugin/pnpm-workspace.yaml new file mode 100644 index 000000000..6ee7f50e9 --- /dev/null +++ b/apps/memos-local-plugin/pnpm-workspace.yaml @@ -0,0 +1,10 @@ +# pnpm 11.7.0; npm's independent policy is package.json#allowScripts. +strictDepBuilds: true +allowBuilds: + better-sqlite3: false + esbuild@0.27.7: true + esbuild@0.21.5: true + sharp@0.34.5: true + onnxruntime-node: false + protobufjs: false + fsevents: false diff --git a/apps/memos-local-plugin/scripts/normalize-sqlite-lock.cjs b/apps/memos-local-plugin/scripts/normalize-sqlite-lock.cjs new file mode 100644 index 000000000..e8c11d5f3 --- /dev/null +++ b/apps/memos-local-plugin/scripts/normalize-sqlite-lock.cjs @@ -0,0 +1,24 @@ +#!/usr/bin/env node +// npm 11 can drop gypfile:false while serializing a lock, then infer a rebuild. +// Never generalize this repair to unreviewed artifacts or run it during install. +"use strict"; +const fs = require("node:fs"); +const path = require("node:path"); +const args = process.argv.slice(2); +const file = args.find(arg => !arg.startsWith("--")) || path.join(__dirname, "../package-lock.json"); +const lock = JSON.parse(fs.readFileSync(file, "utf8")); +const entry = lock.packages?.["node_modules/better-sqlite3"]; +const expectedIntegrity = "sha512-RbOBxmLBG8uvFUc15X9+9SFemKcQ0WBuISBVkpuiaUB2qblC8UWlHEjdWVoZ8AdhSwmoEgsiXKfopX0CQxaACQ=="; +if (lock.packages?.[""]?.dependencies?.["better-sqlite3"] !== "13.0.3" || + entry?.version !== "13.0.3" || entry?.integrity !== expectedIntegrity || + entry?.resolved !== "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-13.0.3.tgz") { + throw new Error("Unreviewed better-sqlite3 lock entry: verify version, URL and integrity before changing the normalizer."); +} +const changed = entry.gypfile !== false || entry.hasInstallScript !== false; +if (changed && args.includes("--check")) throw new Error("SQLite lock metadata drift; run npm run lock:normalize before committing."); +if (changed) { + entry.gypfile = false; + entry.hasInstallScript = false; + fs.writeFileSync(file, JSON.stringify(lock, null, 2) + "\n"); +} +console.log("SQLite 13.0.3 lock metadata verified"); diff --git a/apps/memos-local-plugin/scripts/verify-native-runtime.cjs b/apps/memos-local-plugin/scripts/verify-native-runtime.cjs new file mode 100644 index 000000000..f32ad8864 --- /dev/null +++ b/apps/memos-local-plugin/scripts/verify-native-runtime.cjs @@ -0,0 +1,19 @@ +#!/usr/bin/env node +"use strict"; +const assert = require("node:assert/strict"); +const { createRequire } = require("node:module"); +if (Number(process.versions.node.split(".")[0]) < 22) { + throw new Error("MemOS requires Node.js >=22 in the actual host runtime"); +} +const Database = require("better-sqlite3"); +const db = new Database(":memory:"); +try { + db.exec("CREATE TABLE probe (v TEXT)"); + db.prepare("INSERT INTO probe VALUES (?)").run("ok"); + assert.equal(db.prepare("SELECT v FROM probe").get().v, "ok"); +} finally { db.close(); } +const fromTransformers = createRequire(require.resolve("@huggingface/transformers")); +const ort = fromTransformers("onnxruntime-node"); +assert.ok(ort.listSupportedBackends().some(backend => backend.name === "cpu" && backend.bundled)); +console.log(JSON.stringify({ node: process.versions.node, electron: process.versions.electron ?? null, + sqlite: require("better-sqlite3/package.json").version, cpuOnnx: true })); diff --git a/apps/memos-local-plugin/scripts/verify-script-policy.cjs b/apps/memos-local-plugin/scripts/verify-script-policy.cjs new file mode 100644 index 000000000..2a513cbb9 --- /dev/null +++ b/apps/memos-local-plugin/scripts/verify-script-policy.cjs @@ -0,0 +1,35 @@ +#!/usr/bin/env node +// Negative control: a previously unseen dependency must not execute its script. +"use strict"; +const fs = require("node:fs"); +const os = require("node:os"); +const path = require("node:path"); +const { spawnSync } = require("node:child_process"); +const assert = require("node:assert/strict"); +const npmCli = process.env.npm_execpath; +assert.ok(npmCli, "Run through npm run verify:script-policy with npm 11.17.0"); +const temp = fs.mkdtempSync(path.join(os.tmpdir(), "memos-script-policy-")); +const dep = path.join(temp, "dependency"), project = path.join(temp, "project"); +fs.mkdirSync(dep); fs.mkdirSync(project); +const marker = path.join(temp, "unexpected-script-ran"); +const run = (cwd, args) => spawnSync(process.execPath, [npmCli, ...args], { + cwd, encoding: "utf8", timeout: 30_000, + env: { ...process.env, MEMOS_POLICY_MARKER: marker }, +}); +try { + fs.writeFileSync(path.join(dep, "package.json"), JSON.stringify({name: "memos-unreviewed-policy-probe", version: "1.0.0", scripts: {postinstall: "node postinstall.cjs"}})); + fs.writeFileSync(path.join(dep, "postinstall.cjs"), 'require("node:fs").writeFileSync(process.env.MEMOS_POLICY_MARKER, "unexpected");'); + const pack = run(dep, ["pack", "--ignore-scripts", "--json"]); + assert.equal(pack.status, 0, pack.stderr); + const tar = JSON.parse(pack.stdout)[0].filename; + fs.writeFileSync(path.join(project, "package.json"), JSON.stringify({name: "memos-policy-root", version: "1.0.0", private: true, + dependencies: {"memos-unreviewed-policy-probe": `file:../dependency/${tar}`}, allowScripts: {}})); + fs.writeFileSync(path.join(project, ".npmrc"), "strict-allow-scripts=true\n"); + const lock = run(project, ["install", "--package-lock-only", "--ignore-scripts", "--no-audit", "--no-fund"]); + assert.equal(lock.status, 0, lock.stderr); + const install = run(project, ["ci", "--no-audit", "--no-fund"]); + assert.notEqual(install.status, 0, "Unreviewed install script did not fail installation"); + assert.match(install.stdout + install.stderr, /memos-unreviewed-policy-probe/); + assert.equal(fs.existsSync(marker), false, "Unreviewed script executed"); + console.log("PASS: strict npm policy rejected the unknown script without executing it"); +} finally { fs.rmSync(temp, { recursive: true, force: true }); } diff --git a/apps/memos-local-plugin/tests/unit/install/hermes-provider-link.test.ts b/apps/memos-local-plugin/tests/unit/install/hermes-provider-link.test.ts index ffa33f0a0..0a5885684 100644 --- a/apps/memos-local-plugin/tests/unit/install/hermes-provider-link.test.ts +++ b/apps/memos-local-plugin/tests/unit/install/hermes-provider-link.test.ts @@ -125,7 +125,7 @@ describe("Hermes provider install links", () => { expect(unixSource).toContain("npm install --omit=dev --legacy-peer-deps"); expect(windowsSource).toMatch( - /"install", "--omit=dev", "--legacy-peer-deps", "--no-fund"/, + /"install", "--omit=dev", "--legacy-peer-deps", "--strict-allow-scripts", "--engine-strict", "--no-fund"/, ); }); diff --git a/apps/memos-local-plugin/tests/unit/install/hermes-version-sync.test.ts b/apps/memos-local-plugin/tests/unit/install/hermes-version-sync.test.ts index 6f2ce6993..e471d0a48 100644 --- a/apps/memos-local-plugin/tests/unit/install/hermes-version-sync.test.ts +++ b/apps/memos-local-plugin/tests/unit/install/hermes-version-sync.test.ts @@ -115,7 +115,7 @@ describe("Hermes version synchronization", () => { expect(syncPosition).toBeGreaterThan(bumpPosition); expect(validationPosition).toBeGreaterThan(syncPosition); expect(packageJson.scripts["release:validate"]).toBe( - "npm run check:hermes-version && npm run lint && npm test", + "npm run lock:check && npm run verify:script-policy && npm run check:hermes-version && npm run lint && npm test", ); expect(workflow).toContain("npm pack --json --silent --pack-destination"); expect(workflow).toContain("raw.match(/^\\[/m)"); diff --git a/apps/memos-local-plugin/tests/unit/install/install-sh.test.ts b/apps/memos-local-plugin/tests/unit/install/install-sh.test.ts index 943345fdd..a436b74c0 100644 --- a/apps/memos-local-plugin/tests/unit/install/install-sh.test.ts +++ b/apps/memos-local-plugin/tests/unit/install/install-sh.test.ts @@ -232,7 +232,7 @@ exit 64 `, ); - const firstAdd = options.firstAdd ?? "ignored-builds"; + const firstAdd = options.firstAdd ?? "success"; const approval = options.approval ?? "success"; const secondAdd = options.secondAdd ?? "success"; const dump = options.dump ?? "success"; @@ -374,8 +374,6 @@ describe("install.sh — CLI surface", () => { expect(r.code).toBe(0); const calls = readFileSync(fixture.log, "utf8").trim().split("\n"); expect(calls).toEqual([ - `plugin --profile web add ${tarball}`, - "plugin --profile web approve-builds better-sqlite3 esbuild sharp !onnxruntime-node !protobufjs !@memtensor/memos-local-plugin", `plugin --profile web add ${tarball}`, "--profile web --dump-config", ]); @@ -385,11 +383,9 @@ describe("install.sh — CLI surface", () => { ]); expect(readFileSync(fixture.dshEnvLog, "utf8").trim().split("\n")).toEqual([ "skip", - "skip", - "skip", ]); expect(readFileSync(fixture.profileWorkspace, "utf8")).toContain( - "onnxruntime-node: false", + '"onnxruntime-node": false', ); expect(r.stdout).toContain("DeepSeek Harness install complete"); expect(r.stdout).toContain("http://127.0.0.1:18801"); @@ -446,7 +442,7 @@ exit 90 expect(calls).toHaveLength(2); expect(readFileSync(fixture.dshEnvLog, "utf8").trim()).toBe("skip"); expect(readFileSync(fixture.profileWorkspace, "utf8")).toContain( - "onnxruntime-node: false", + '"onnxruntime-node": false', ); } finally { rmSync(fixture.root, { recursive: true, force: true }); @@ -520,101 +516,26 @@ exit 90 } }); - it("does not retry installation when reviewed build approval fails", () => { - const fixture = makeDshFixture({ approval: "error" }); + it("does not auto-approve unexpected pending builds", () => { + const fixture = makeDshFixture({ firstAdd: "ignored-builds" }); try { - const tarball = path.join(fixture.root, "memos-local-plugin.tgz"); - writeFileSync(tarball, "fixture", "utf8"); - const r = run(["--agent", "dsh", "--version", tarball], fixture.env); - + const r = run(["--agent", "dsh", "--version", "2.0.16-beta.1"], fixture.env); expect(r.code).not.toBe(0); - const calls = readFileSync(fixture.log, "utf8").trim().split("\n"); - expect(calls).toHaveLength(2); - expect(calls[1]).toContain("approve-builds"); - } finally { - rmSync(fixture.root, { recursive: true, force: true }); - } + expect(readFileSync(fixture.log, "utf8")).not.toContain("approve-builds"); + expect(`${r.stdout}\n${r.stderr}`).toContain("Review the package versions"); + } finally { rmSync(fixture.root, { recursive: true, force: true }); } }); - it("repairs a missing DSH better-sqlite3 binding before reporting success", () => { - const fixture = makeDshFixture({ - firstAdd: "success", - sqliteProbe: "repairable", - }); + it.each(["repairable", "error"] as const)("fails without rebuilding a %s SQLite prebuilt", (sqliteProbe) => { + const fixture = makeDshFixture({ firstAdd: "success", sqliteProbe }); try { - const tarball = path.join(fixture.root, "memos-local-plugin.tgz"); - writeFileSync(tarball, "fixture", "utf8"); - - const r = run(["--agent", "dsh", "--version", tarball], fixture.env); - - expect(r.code).toBe(0); - expect(readFileSync(fixture.pnpmActionLog, "utf8").trim()).toBe( - "rebuild better-sqlite3", - ); - expect(readFileSync(fixture.nativeProbeLog, "utf8").trim().split("\n")).toEqual([ - "better-sqlite3", - "better-sqlite3", - "onnxruntime-node", - ]); - expect(r.stdout).toContain("better-sqlite3 native binding repaired"); - expect(r.stdout).toContain("DeepSeek Harness install complete"); - } finally { - rmSync(fixture.root, { recursive: true, force: true }); - } - }); - - it("fails DSH installation when the targeted better-sqlite3 rebuild fails", () => { - const fixture = makeDshFixture({ - firstAdd: "success", - sqliteProbe: "repairable", - rebuild: "error", - }); - try { - const tarball = path.join(fixture.root, "memos-local-plugin.tgz"); - writeFileSync(tarball, "fixture", "utf8"); - - const r = run(["--agent", "dsh", "--version", tarball], fixture.env); - + const r = run(["--agent", "dsh", "--version", "2.0.16-beta.1"], fixture.env); expect(r.code).not.toBe(0); - expect(readFileSync(fixture.pnpmActionLog, "utf8").trim()).toBe( - "rebuild better-sqlite3", - ); - expect(`${r.stdout}\n${r.stderr}`).toContain( - "better-sqlite3 rebuild failed", - ); + expect(existsSync(fixture.pnpmActionLog)).toBe(false); + expect(readFileSync(fixture.nativeProbeLog, "utf8").trim()).toBe("better-sqlite3"); + expect(`${r.stdout}\n${r.stderr}`).toContain("no source rebuild was attempted"); expect(r.stdout).not.toContain("DeepSeek Harness install complete"); - expect(r.stdout).not.toContain("MemOS Local installed successfully"); - } finally { - rmSync(fixture.root, { recursive: true, force: true }); - } - }); - - it("fails DSH installation when better-sqlite3 remains unusable after rebuild", () => { - const fixture = makeDshFixture({ - firstAdd: "success", - sqliteProbe: "error", - }); - try { - const tarball = path.join(fixture.root, "memos-local-plugin.tgz"); - writeFileSync(tarball, "fixture", "utf8"); - - const r = run(["--agent", "dsh", "--version", tarball], fixture.env); - - expect(r.code).not.toBe(0); - expect(readFileSync(fixture.pnpmActionLog, "utf8").trim()).toBe( - "rebuild better-sqlite3", - ); - expect(readFileSync(fixture.nativeProbeLog, "utf8").trim().split("\n")).toEqual([ - "better-sqlite3", - "better-sqlite3", - ]); - expect(`${r.stdout}\n${r.stderr}`).toContain( - "better-sqlite3 native binding is not loadable", - ); - expect(r.stdout).not.toContain("DeepSeek Harness install complete"); - } finally { - rmSync(fixture.root, { recursive: true, force: true }); - } + } finally { rmSync(fixture.root, { recursive: true, force: true }); } }); it("fails DSH installation when the bundled ONNX CPU backend cannot load", () => { diff --git a/apps/memos-local-plugin/tests/unit/install/sqlite-install-contract.test.ts b/apps/memos-local-plugin/tests/unit/install/sqlite-install-contract.test.ts new file mode 100644 index 000000000..fbc96d250 --- /dev/null +++ b/apps/memos-local-plugin/tests/unit/install/sqlite-install-contract.test.ts @@ -0,0 +1,95 @@ +import { mkdtempSync, readFileSync, writeFileSync, rmSync } from "node:fs"; +import { tmpdir } from "node:os"; +import path from "node:path"; +import { spawnSync } from "node:child_process"; +import { describe, expect, it } from "vitest"; +import { bootstrapMemoryCoreFull } from "../../../core/pipeline/memory-core.js"; +const root = path.resolve(__dirname, "../../.."); +const normalizer = path.join(root, "scripts/normalize-sqlite-lock.cjs"); +describe("SQLite prebuilt installation contract", () => { + it("rejects an old actual host runtime before opening storage", async () => { + const descriptor = Object.getOwnPropertyDescriptor(process.versions, "node")!; + Object.defineProperty(process.versions, "node", { value: "20.19.0", configurable: true }); + try { + await expect(bootstrapMemoryCoreFull({ agent: "deepseek-harness", get home(): never { throw new Error("storage must not be resolved"); } })).rejects.toThrow(/Node.js >=22/); + } finally { Object.defineProperty(process.versions, "node", descriptor); } + }); + it("keeps runtime declarations, both lockfiles and build policy consistent", () => { + const pkg = JSON.parse(readFileSync(path.join(root, "package.json"), "utf8")); + const lock = JSON.parse(readFileSync(path.join(root, "package-lock.json"), "utf8")); + expect(pkg.engines.node).toBe(">=22.0.0"); + expect(pkg.dependencies["better-sqlite3"]).toBe("13.0.3"); + expect(lock.packages[""].dependencies["better-sqlite3"]).toBe("13.0.3"); + expect(lock.packages["node_modules/better-sqlite3"]).toMatchObject({version: "13.0.3", gypfile: false, hasInstallScript: false}); + expect(pkg.allowScripts["better-sqlite3"]).toBe(false); + expect(readFileSync(path.join(root, "pnpm-lock.yaml"), "utf8")).toMatch(/better-sqlite3:\s+specifier: 13\.0\.3\s+version: 13\.0\.3/); + }); + it("normalizes only reviewed SQLite metadata and detects later drift", () => { + const dir = mkdtempSync(path.join(tmpdir(), "sqlite-lock-test-")); + const file = path.join(dir, "package-lock.json"); + const actual = JSON.parse(readFileSync(path.join(root, "package-lock.json"), "utf8")); + delete actual.packages["node_modules/better-sqlite3"].gypfile; + delete actual.packages["node_modules/better-sqlite3"].hasInstallScript; + writeFileSync(file, JSON.stringify(actual)); + const run = (...args: string[]) => spawnSync(process.execPath, [normalizer, file, ...args], { encoding: "utf8" }); + try { + expect(run("--check").status).not.toBe(0); + expect(run().status).toBe(0); + expect(run("--check").status).toBe(0); + const repaired = JSON.parse(readFileSync(file, "utf8")); + expect(repaired.packages["node_modules/better-sqlite3"]).toMatchObject({gypfile: false, hasInstallScript: false}); + repaired.packages["node_modules/better-sqlite3"].integrity = "unreviewed"; + writeFileSync(file, JSON.stringify(repaired)); + expect(run().status).not.toBe(0); + expect(JSON.parse(readFileSync(file, "utf8")).packages["node_modules/better-sqlite3"].integrity).toBe("unreviewed"); + } finally { rmSync(dir, { recursive: true, force: true }); } + }); + it("preseeds DSH policy, preserves unrelated settings and refuses an explicit denial", () => { + const source = readFileSync(path.join(root, "install.sh"), "utf8"); + const fn = source.slice(source.indexOf("prepare_dsh_build_policy() {"), source.indexOf("\nrun_dsh_plugin_without_onnx_cuda()")); + const dir = mkdtempSync(path.join(tmpdir(), "dsh-policy-test-")); + const file = path.join(dir, "pnpm-workspace.yaml"); + const run = () => spawnSync("bash", ["-c", `${fn}\nprepare_dsh_build_policy "$1"`, "bash", file], { encoding: "utf8" }); + try { + writeFileSync(file, "packages:\n - .\nallowBuilds:\n other: false\n"); + expect(run().status).toBe(0); + const once = readFileSync(file, "utf8"); + expect(once).toContain('"better-sqlite3": false'); + expect(once).toContain("other: false"); + expect(run().status).toBe(0); + expect(readFileSync(file, "utf8")).toBe(once); + writeFileSync(file, "allowBuilds:\n esbuild: false\n"); + expect(run().status).not.toBe(0); + expect(readFileSync(file, "utf8")).toBe("allowBuilds:\n esbuild: false\n"); + } finally { rmSync(dir, { recursive: true, force: true }); } + }); + it("refuses Node 20 before attempting a deployment", () => { + const source = readFileSync(path.join(root, "install.sh"), "utf8"); + const fn = source.slice(source.indexOf("ensure_node() {"), source.indexOf("\n}", source.indexOf("ensure_node() {")) + 2); + const run = spawnSync("bash", ["-c", `REQUIRED_NODE_MAJOR=22; node_major() { echo 20; }; die() { echo "$*"; exit 1; }; ${fn}\nensure_node`], { encoding: "utf8" }); + expect(run.status).not.toBe(0); + expect(run.stdout).toContain("existing plugin has not been replaced"); + }); + + it.skipIf(process.platform === "win32")("leaves an existing deployment untouched when dependency staging fails", () => { + const source = readFileSync(path.join(root, "install.sh"), "utf8"); + const start = source.indexOf("deploy_tarball_to_prefix() {"); + const fn = source.slice(start, source.indexOf("\n# ─── Generate runtime", start)); + const dir = mkdtempSync(path.join(tmpdir(), "sqlite-stage-test-")); + const prefix = path.join(dir, "existing"); + const unpacked = path.join(dir, "package"); + // Use a real tarball but a failing npm boundary; no user host is involved. + spawnSync("mkdir", ["-p", prefix, unpacked]); + writeFileSync(path.join(prefix, "package.json"), "old-install"); + writeFileSync(path.join(unpacked, "package.json"), "{}"); + const tarball = path.join(dir, "candidate.tgz"); + expect(spawnSync("tar", ["czf", tarball, "-C", dir, "package"]).status).toBe(0); + try { + const result = spawnSync("bash", ["-c", `step() { :; }; success() { :; }; warn() { :; }; die() { echo "$*"; exit 1; }; npm() { return 66; }; BUILT_TARBALL="$2"; ${fn}\ndeploy_tarball_to_prefix "$1"`, "bash", prefix, tarball], { encoding: "utf8" }); + expect(result.status).not.toBe(0); + expect(result.stdout).toContain("existing installation is unchanged"); + expect(readFileSync(path.join(prefix, "package.json"), "utf8")).toBe("old-install"); + } finally { rmSync(dir, { recursive: true, force: true }); } + }); + +}); From 78706b0b19f65b37267743e2d7fa63bc63ed1779 Mon Sep 17 00:00:00 2001 From: Wenqiang Wei <46308778+endxxxx@users.noreply.github.com> Date: Thu, 29 Oct 2026 17:56:59 +0800 Subject: [PATCH 34/38] fix(plugin): support validated DSH 0.2 preview APIs --- apps/memos-local-plugin/CHANGELOG.md | 9 + .../deepseek-harness/COMPATIBILITY.md | 74 +++ .../adapters/deepseek-harness/README.md | 79 ++- .../adapters/deepseek-harness/tools.ts | 8 +- apps/memos-local-plugin/package-lock.json | 464 +++++++++------- apps/memos-local-plugin/package.json | 38 +- apps/memos-local-plugin/pnpm-lock.yaml | 504 +++++++++--------- .../scripts/check-dsh-compatibility.mjs | 102 ++++ .../adapters/deepseek-harness-package.test.ts | 41 ++ .../adapters/deepseek-harness-runtime.test.ts | 11 + 10 files changed, 836 insertions(+), 494 deletions(-) create mode 100644 apps/memos-local-plugin/adapters/deepseek-harness/COMPATIBILITY.md create mode 100644 apps/memos-local-plugin/scripts/check-dsh-compatibility.mjs diff --git a/apps/memos-local-plugin/CHANGELOG.md b/apps/memos-local-plugin/CHANGELOG.md index 7700dd6f5..996768a3e 100644 --- a/apps/memos-local-plugin/CHANGELOG.md +++ b/apps/memos-local-plugin/CHANGELOG.md @@ -5,6 +5,15 @@ for the full per-commit history use `git log` or the GitHub releases page. ## Index +- Unreleased — Admit DSH `0.1.7-rc.2`, `0.2.0-rc.2`, and `0.2.1-rc.2/rc.3` + through explicit, bounded optional peer ranges; retain the `2.0.21` V4 + producer-owned message sources. Stop importing the moved `JsonValue` type + from `dsh-tools`, align the development host stack to `0.2.1-rc.3`, and + synchronize both package-manager lockfiles. Add an isolated compile/build/ + adapter-test matrix with an installable `0.1.0-rc.6` legacy baseline; the + unavailable `0.1.0-rc.5` core packages are no longer advertised. npm `2.0.21` + still has the old startup version restriction until a new release ships. + Reinstall released packages instead of carrying hand-edited `dist/` patches. - `2.0.16` (unreleased) — Add the out-of-tree DeepSeek Harness Cordis bundle with capture, six memory tools, DSH profile-aware storage, and one automatic recall for every accepted, non-empty direct-user turn. Same-turn diff --git a/apps/memos-local-plugin/adapters/deepseek-harness/COMPATIBILITY.md b/apps/memos-local-plugin/adapters/deepseek-harness/COMPATIBILITY.md new file mode 100644 index 000000000..6f92acd37 --- /dev/null +++ b/apps/memos-local-plugin/adapters/deepseek-harness/COMPATIBILITY.md @@ -0,0 +1,74 @@ +# DSH compatibility diagnosis and validation + +Validated on 2026-10-29, macOS arm64, Node.js 25.1.0, npm 11.6.2, +pnpm 10.21.0. Scope: the local plugin; the Cloud plugin is separate. +Related: MemOS issue #2520 and PR #2541. + +## Diagnosis + +The local plugin's six optional host-service peers excluded DSH 0.2.x. +DSH 0.2.1 actively skips an incompatible bundle before mounting any plugin +row. `failOnStartupError: false` cannot help because this check precedes +the adapter's `apply()` function. The V4 message-source fix in 2.0.21 does +not change this version gate. + +An independent compile against 0.2.1-rc.3 also failed with: + +```text +tools.ts(4,27): error TS2614: Module '"@deepseek-ai/dsh-tools"' has no exported member 'JsonValue'. +``` + +The fix adds bounded prerelease comparator sets, replaces that moved type +with the equivalent local JSON shape, and aligns the entire development +stack and both lockfiles. The V4 source implementation is unchanged. +The old rc.5 API baseline is no longer declared because its core packages +cannot be retrieved from npm; rc.6 is the installable legacy baseline. + +## Regression evidence + +Before the manifest change, the package regression suite failed for all +four newly targeted previews: 0.1.7-rc.2, 0.2.0-rc.2, 0.2.1-rc.2/rc.3. +After the change, each of the five API stacks in `npm run test:dsh-compat` +passed type checking, a TypeScript production build, and 71 adapter tests. +The matrix installs the complete matching host peer graph, without borrowing +DSH packages from the checkout. The native session admission/snapshot tests +preserve the producer-owned recall source on the legacy and modern stacks. + +Official DSH 0.2.1-rc.3 CLI smoke test: install the published CLI with +`--ignore-scripts` in a temporary directory; create an isolated `DSH_HOME`, +initialize a `compat` profile from `web`, and register a staged local bundle +in `dsh.profile.bundles`. Run `--profile compat --dump-config` with the old +and new peer declarations, holding all other bundle files constant: + +| Declaration | Incompatible warning | MemOS row in composed tree | +| --- | --- | --- | +| Old `>=0.1.0-rc.5 <0.2.0` | Yes; exact-version exemption inactive | Absent | +| New bounded ranges | No | Present | + +Both commands exit 0: exit status alone cannot detect a skipped bundle. +No version exemption, live profile, credential, or customer session was used. +The installed Desktop 0.2.0-rc.2 loader accepted both declarations, so it +cannot reproduce the newer 0.2.1 startup gate. + +Other real command results: + +```text +make format: All checks passed! / 630 files left unchanged +npm test: Test Files 191 passed (191) + Tests 1655 passed | 3 skipped (1658) +npm run lint: passed +npm run build:package: passed (TypeScript and Viewer) +npm ci --ignore-scripts --no-audit --no-fund: added 211 packages +npm ls --all: exit 0, no invalid peers +pnpm install --lockfile-only --frozen-lockfile --strict-peer-dependencies --ignore-scripts: passed +npm run lock:check: SQLite 13.0.3 lock metadata verified +``` + +The first sandboxed full run failed when HTTP tests could not bind localhost +(`listen EPERM`). The full result above comes from a rerun with local port +access. Package installation scripts were disabled; the unchanged SQLite +13.0.3 native build was reused for testing. + +These checks do not constitute a fresh authenticated model conversation on +every Desktop/Web/CLI platform. The compatibility change is unreleased; +installing npm 2.0.21 still has the old startup restriction. diff --git a/apps/memos-local-plugin/adapters/deepseek-harness/README.md b/apps/memos-local-plugin/adapters/deepseek-harness/README.md index e8241ee5a..0c44a47bb 100644 --- a/apps/memos-local-plugin/adapters/deepseek-harness/README.md +++ b/apps/memos-local-plugin/adapters/deepseek-harness/README.md @@ -7,11 +7,11 @@ background capture, and on-demand memory tools to a DSH profile without modifying the DSH repository. > [!IMPORTANT] -> DeepSeek Harness is currently a developer preview. The initial compatibility -> target for this adapter is DSH `0.1.0-rc.5`; record the exact DSH version in -> every release's validation because later preview releases may require adapter -> changes. Unit compilation and contract tests currently use the published DSH -> `0.1.0-rc.6` packages; the end-to-end host below is the rc.5 source checkout. +> DeepSeek Harness is currently a developer preview. The development API stack +> is pinned to `0.2.1-rc.3`. The compatibility matrix compiles, builds, and tests +> this adapter against the published `0.1.0-rc.6`, `0.1.7-rc.2`, `0.2.0-rc.2`, +> `0.2.1-rc.2`, and `0.2.1-rc.3` packages. These are API/contract checks, not a +> substitute for validating each packaged Desktop/Web/CLI release. ## How it works @@ -115,9 +115,8 @@ the MemOS JSON-RPC bridge or a sidecar daemon. Prerequisites: -- A Node.js version accepted by the DSH release. DSH `0.1.0-rc.5` requires - Node.js `^22.19.0 || >=24.0.0`; this stricter host requirement takes - precedence over the MemOS package's standalone `>=22` engine. +- Node.js `>=22` in the actual host runtime, also satisfying the selected DSH + release's engine constraint. Desktop uses its bundled Node/Electron runtime. - A working DSH installation. The recommended one-command installer prepares an isolated `pnpm@11.7.0` for the install when pnpm is absent. Lower-level direct `dsh plugin` commands still require pnpm on `PATH`. @@ -610,22 +609,66 @@ npx vitest run tests/unit/adapters/deepseek-harness-{bridge,host-llm,runtime}.te ``` These tests use the published `@deepseek-ai/dsh-session-format-v3-to-v4` -`0.2.0-rc.2` codec, without a DSH desktop installation, account, or network +`0.2.1-rc.3` codec, without a DSH desktop installation, account, or network calls during testing. They check real recall and host-LLM messages through both `assertV4RowAdmission` and `encodeEvent`, including a pre-step inbox batch and rejection of retired `kind: "plugin"` sources. The codec is a dev -dependency only. Its Cordis peer is satisfied by the development range; -existing DSH brand/protocol peers remain pinned to the older adapter test -stack. This validates V4 attribution, not general compatibility with every -DSH API in the codec's release line. +dependency only. All DSH development packages, including brand/protocol peers, +use the same `0.2.1-rc.3` stack and Cordis `~4.0.5`. + +For the compatibility matrix, run: + +```sh +npm run test:dsh-compat +# Or select a specific published API stack: +npm run test:dsh-compat -- 0.2.1-rc.3 +``` + +The script needs npm registry access. It installs each real host peer graph in +its own temporary directory, then type-checks and builds the plugin and runs +the adapter tests. Non-host test/build dependencies reuse the checkout's +installation. It retains fixtures for inspection and does not touch DSH +profiles, credentials, sessions, or the checkout's dependency installation. +The native session boundary tests also check that the producer-owned source +survives the old host's admission and snapshot paths. + +## Version compatibility and upgrades + +The six optional DSH service peers intentionally declare separate prerelease +lines: + +```text +>=0.1.0-rc.6 <0.2.0 || >=0.1.7-rc.2 <0.1.8 || >=0.2.0-rc.2 <0.2.1 || >=0.2.1-rc.2 <0.2.2 +``` + +npm semver only admits a prerelease when a comparator explicitly names its +`major.minor.patch` tuple. Simply changing `<0.2.0` to `<0.3.0` would still +exclude `0.2.1-rc.3`. Unvalidated `0.2.2` and `0.3.x` remain excluded. +The former `0.1.0-rc.5` API baseline is no longer advertised: its core packages +are unavailable from npm, so it cannot be revalidated by this matrix. + +There are two independent checks to distinguish: + +- **Startup: bundle skipped as incompatible.** Plugin `2.0.20` and `2.0.21` + declare peers below `0.2.0`; neither version's manifest admits DSH 0.2.x. + This change updates that declaration together with the adapter's moved JSON + type and synchronized npm/pnpm locks. It does not change the Cloud plugin. +- **Runtime: V4 rejects `source.kind: "plugin"`.** Fixed in `2.0.21`; this + adapter retains that producer-owned source implementation and codec tests. + +After a release containing these compatibility changes is published, update +the plugin in each DSH profile that uses it and fully restart that host. If +you patched `dist/` by hand, reinstall the released package: a profile install +can overwrite those patches. A successful `allow-version` exemption alone +does not verify runtime compatibility. Until this change is released, +installing npm `2.0.21` still leaves the startup version restriction in place. ## Known limitations -1. **Developer-preview compatibility.** The initial compatibility target is - DSH `0.1.0-rc.5`; verify the packaged artifact against that exact host - before publishing results. Its optional DSH peer range is - `>=0.1.0-rc.5 <0.2.0`, but that range is not a guarantee across preview - breaking changes. +1. **Developer-preview compatibility.** The supported prerelease lines and + repeatable API matrix are listed above. New DSH lines need explicit + validation before the peer range is expanded. Automated adapter tests do + not validate every platform's native dependencies or Desktop packaging. 2. **Eventual consistency and abrupt-crash replay gap.** Per-turn foreground recall never waits for prior capture, relation, or intent work. A completed background result is visible to later automatic recalls and explicit tool diff --git a/apps/memos-local-plugin/adapters/deepseek-harness/tools.ts b/apps/memos-local-plugin/adapters/deepseek-harness/tools.ts index f45fdefbd..a31a6843e 100644 --- a/apps/memos-local-plugin/adapters/deepseek-harness/tools.ts +++ b/apps/memos-local-plugin/adapters/deepseek-harness/tools.ts @@ -1,7 +1,7 @@ /** Read-oriented MemOS tools exposed through DeepSeek Harness. */ import type { Context } from "@deepseek-ai/cordis"; -import { defineTool, type JsonValue } from "@deepseek-ai/dsh-tools"; +import { defineTool } from "@deepseek-ai/dsh-tools"; import type { RetrievalQueryDTO, @@ -26,6 +26,12 @@ import { waitForDeepSeekHarnessDeadline, } from "./deadline.js"; +// DSH 0.2 moved JsonValue out of dsh-tools. Keep this structural output +// boundary local so the adapter compiles with both the 0.1 and 0.2 APIs. +type JsonValue = null | boolean | number | string | JsonValue[] | { + [key: string]: JsonValue; +}; + export interface DeepSeekHarnessToolsOptions { core: MemoryCore; profileId: string; diff --git a/apps/memos-local-plugin/package-lock.json b/apps/memos-local-plugin/package-lock.json index 5902e431a..7cc00eeac 100644 --- a/apps/memos-local-plugin/package-lock.json +++ b/apps/memos-local-plugin/package-lock.json @@ -20,21 +20,22 @@ "yaml": "^2.6.0" }, "devDependencies": { - "@deepseek-ai/cordis": "~4.0.4", - "@deepseek-ai/dsh-agent": "0.1.0-rc.6", - "@deepseek-ai/dsh-brand": "0.1.0-rc.6", - "@deepseek-ai/dsh-llm": "0.1.0-rc.6", - "@deepseek-ai/dsh-session": "0.1.0-rc.6", - "@deepseek-ai/dsh-session-format-v3-to-v4": "0.2.0-rc.2", - "@deepseek-ai/dsh-system-prompt": "0.1.0-rc.6", - "@deepseek-ai/dsh-timeout": "0.1.0-rc.6", - "@deepseek-ai/dsh-tools": "0.1.0-rc.6", - "@deepseek-ai/dsh-typert-protocol": "0.1.0-rc.6", + "@deepseek-ai/cordis": "~4.0.5", + "@deepseek-ai/dsh-agent": "0.2.1-rc.3", + "@deepseek-ai/dsh-brand": "0.2.1-rc.3", + "@deepseek-ai/dsh-llm": "0.2.1-rc.3", + "@deepseek-ai/dsh-session": "0.2.1-rc.3", + "@deepseek-ai/dsh-session-format-v3-to-v4": "0.2.1-rc.3", + "@deepseek-ai/dsh-system-prompt": "0.2.1-rc.3", + "@deepseek-ai/dsh-timeout": "0.2.1-rc.3", + "@deepseek-ai/dsh-tools": "0.2.1-rc.3", + "@deepseek-ai/dsh-typert-protocol": "0.2.1-rc.3", "@deepseek-ai/schemastery": "^3.18.1", "@preact/preset-vite": "^2.10.5", "@types/better-sqlite3": "^7.6.12", "@types/node": "^22.10.0", "@types/uuid": "^10.0.0", + "semver": "7.7.4", "typescript": "^5.7.0", "vite": "^5.4.10", "vitest": "^2.1.9" @@ -44,12 +45,12 @@ }, "peerDependencies": { "@deepseek-ai/cordis": "^4.0.1", - "@deepseek-ai/dsh-agent": ">=0.1.0-rc.5 <0.2.0", - "@deepseek-ai/dsh-llm": ">=0.1.0-rc.5 <0.2.0", - "@deepseek-ai/dsh-session": ">=0.1.0-rc.5 <0.2.0", - "@deepseek-ai/dsh-system-prompt": ">=0.1.0-rc.5 <0.2.0", - "@deepseek-ai/dsh-timeout": ">=0.1.0-rc.5 <0.2.0", - "@deepseek-ai/dsh-tools": ">=0.1.0-rc.5 <0.2.0", + "@deepseek-ai/dsh-agent": ">=0.1.0-rc.6 <0.2.0 || >=0.1.7-rc.2 <0.1.8 || >=0.2.0-rc.2 <0.2.1 || >=0.2.1-rc.2 <0.2.2", + "@deepseek-ai/dsh-llm": ">=0.1.0-rc.6 <0.2.0 || >=0.1.7-rc.2 <0.1.8 || >=0.2.0-rc.2 <0.2.1 || >=0.2.1-rc.2 <0.2.2", + "@deepseek-ai/dsh-session": ">=0.1.0-rc.6 <0.2.0 || >=0.1.7-rc.2 <0.1.8 || >=0.2.0-rc.2 <0.2.1 || >=0.2.1-rc.2 <0.2.2", + "@deepseek-ai/dsh-system-prompt": ">=0.1.0-rc.6 <0.2.0 || >=0.1.7-rc.2 <0.1.8 || >=0.2.0-rc.2 <0.2.1 || >=0.2.1-rc.2 <0.2.2", + "@deepseek-ai/dsh-timeout": ">=0.1.0-rc.6 <0.2.0 || >=0.1.7-rc.2 <0.1.8 || >=0.2.0-rc.2 <0.2.1 || >=0.2.1-rc.2 <0.2.2", + "@deepseek-ai/dsh-tools": ">=0.1.0-rc.6 <0.2.0 || >=0.1.7-rc.2 <0.1.8 || >=0.2.0-rc.2 <0.2.1 || >=0.2.1-rc.2 <0.2.2", "@deepseek-ai/schemastery": "^3.18.1" }, "peerDependenciesMeta": { @@ -110,6 +111,7 @@ "integrity": "sha512-CGOfOJqWjg2qW/Mb6zNsDm+u5vFQ8DxXfbM09z69p5Z6+mE1ikP2jUXw+j42Pf1XTYED2Rni5f95npYeuwMDQA==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@babel/code-frame": "^7.29.0", "@babel/generator": "^7.29.0", @@ -420,6 +422,7 @@ "integrity": "sha512-Sktq5axy0owk9PdnivBRNOJjHEVEibCt0+TDDZcv0+UH2KS1M910fX4kn5y45YFsrpZIi1mJf/1s5VzywMUnyg==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@deepseek-ai/cosmokit": "~1.8.6", "@standard-schema/spec": "^1.1.0" @@ -448,337 +451,392 @@ "license": "MIT" }, "node_modules/@deepseek-ai/dsh-agent": { - "version": "0.1.0-rc.6", - "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-agent/-/dsh-agent-0.1.0-rc.6.tgz", - "integrity": "sha512-vtqq2pWTrzn0dKfj5kREZRpP82AwtGjGx9V1lYnKvF+Uc/a8zyWbSvjDE7V1d3YQAQJzs2cWO31hURWDekDXIA==", + "version": "0.2.1-rc.3", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-agent/-/dsh-agent-0.2.1-rc.3.tgz", + "integrity": "sha512-S6x/deneAsd+pOgecRLM1PC1No9O472kHjS9pS57nuTXi2Vtdo9l7qF+q7PfiHRezL5dxv5gUBQMORPmIYDNvQ==", "dev": true, "license": "MIT", + "peer": true, "peerDependencies": { - "@deepseek-ai/cordis": "^4.0.1", - "@deepseek-ai/dsh-invariants": "^0.1.0-rc.6", - "@deepseek-ai/dsh-llm": "^0.1.0-rc.6", - "@deepseek-ai/dsh-scope": "^0.1.0-rc.6", - "@deepseek-ai/dsh-session": "^0.1.0-rc.6", - "@deepseek-ai/dsh-system-prompt": "^0.1.0-rc.6", - "@deepseek-ai/dsh-typert-protocol": "^0.1.0-rc.6" + "@deepseek-ai/cordis": "~4.0.5", + "@deepseek-ai/dsh-llm": "0.2.1-rc.3", + "@deepseek-ai/dsh-scope": "0.2.1-rc.3", + "@deepseek-ai/dsh-session": "0.2.1-rc.3", + "@deepseek-ai/dsh-session-projection": "0.2.1-rc.3", + "@deepseek-ai/dsh-system-prompt": "0.2.1-rc.3", + "@deepseek-ai/dsh-typert-protocol": "0.2.1-rc.3", + "@deepseek-ai/dsh-util-values": "0.2.1-rc.3", + "@deepseek-ai/dsh-workspace": "0.2.1-rc.3" + }, + "peerDependenciesMeta": { + "@deepseek-ai/dsh-workspace": { + "optional": true + } } }, - "node_modules/@deepseek-ai/dsh-attachment": { - "version": "0.1.0-rc.6", - "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-attachment/-/dsh-attachment-0.1.0-rc.6.tgz", - "integrity": "sha512-3P6N17NQ8jqSQGzeCs+svCIqArU8oq0YmgEAo+axN9aVuUDferWU4DLRSX59UGpmyldX4LQn81toA+c+DqMcHg==", + "node_modules/@deepseek-ai/dsh-brand": { + "version": "0.2.1-rc.3", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-brand/-/dsh-brand-0.2.1-rc.3.tgz", + "integrity": "sha512-bPpKuu05gZj7gdW15z6PL2dz4+A4MDEafgWOrhexFO7f08g1NeI4fhE4YNOxd8N2ua+tZJjsKCMAIobFMAaGOw==", "dev": true, "license": "MIT", "peer": true, "peerDependencies": { - "@deepseek-ai/cordis": "^4.0.1", - "@deepseek-ai/dsh-brand": "^0.1.0-rc.6", - "@deepseek-ai/dsh-invariants": "^0.1.0-rc.6" + "@deepseek-ai/cordis": "~4.0.5" } }, - "node_modules/@deepseek-ai/dsh-brand": { - "version": "0.1.0-rc.6", - "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-brand/-/dsh-brand-0.1.0-rc.6.tgz", - "integrity": "sha512-E8j9Nby24qP4rfrdcfc7bpt1CHpGT3tYmycOJJkEOH4ptIdT1m2ro9nmnSd5CWYukTr64A77vjm2WGqHRI92UA==", + "node_modules/@deepseek-ai/dsh-fs": { + "version": "0.2.1-rc.3", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-fs/-/dsh-fs-0.2.1-rc.3.tgz", + "integrity": "sha512-tENLWe471WlAXMc13J4cns8xU6lFyu1smwpkSKR85vhGr6FyWZhTlpVohZYm66LbwKTmSWiDhd9Urk7VxN9B9w==", "dev": true, "license": "MIT", + "peer": true, "peerDependencies": { - "@deepseek-ai/cordis": "^4.0.1", - "@deepseek-ai/dsh-invariants": "^0.1.0-rc.6" + "@deepseek-ai/cordis": "~4.0.5", + "@deepseek-ai/dsh-brand": "0.2.1-rc.3", + "@deepseek-ai/dsh-llm": "0.2.1-rc.3", + "@deepseek-ai/dsh-sandbox": "0.2.1-rc.3" } }, - "node_modules/@deepseek-ai/dsh-code-runtime": { - "version": "0.1.0-rc.6", - "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-code-runtime/-/dsh-code-runtime-0.1.0-rc.6.tgz", - "integrity": "sha512-aw8D4IOeMo11A3uxQeE4LFoW3bvaQnVkGFqqtS+lsINDARrOCJHXLUgecoKpys+Lc5erZZ4UQDnymJmL4OCcKA==", + "node_modules/@deepseek-ai/dsh-llm": { + "version": "0.2.1-rc.3", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-llm/-/dsh-llm-0.2.1-rc.3.tgz", + "integrity": "sha512-7Fq7zS3yQb1J1PsaNmahQ1gHDdsb338UhTkmZCexlNecmc5I44c/PbkHcT5pJ5SO4hnLplJOdDhiIMFpvvyAaw==", "dev": true, "license": "MIT", "peer": true, + "dependencies": { + "@deepseek-ai/dsh-brand": "0.2.1-rc.3", + "@deepseek-ai/dsh-timeout": "0.2.1-rc.3", + "@deepseek-ai/dsh-typert-protocol": "0.2.1-rc.3", + "@deepseek-ai/dsh-util-crypto": "0.2.1-rc.3", + "@deepseek-ai/dsh-util-values": "0.2.1-rc.3", + "@deepseek-ai/schemastery": "~3.18.5", + "zod": "4.4.3" + }, "peerDependencies": { - "@deepseek-ai/cordis": "^4.0.1", - "@deepseek-ai/dsh-invariants": "^0.1.0-rc.6" + "@deepseek-ai/cordis": "~4.0.5" + } + }, + "node_modules/@deepseek-ai/dsh-llm/node_modules/zod": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/zod/-/zod-4.4.3.tgz", + "integrity": "sha512-ytENFjIJFl2UwYglde2jchW2Hwm4GJFLDiSXWdTrJQBIN9Fcyp7n4DhxJEiWNAJMV1/BqWfW/kkg71UDcHJyTQ==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/colinhacks" } }, - "node_modules/@deepseek-ai/dsh-invariants": { - "version": "0.1.0-rc.6", - "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-invariants/-/dsh-invariants-0.1.0-rc.6.tgz", - "integrity": "sha512-WfEfOi99a4cpOugRAHTBSTnesLieu3ist1q9PXDXFBHX++K1rAl9+sB7YrdnbB8LH0UOY532gS9xJUYU6w0SLw==", + "node_modules/@deepseek-ai/dsh-ptc-runtime": { + "version": "0.2.1-rc.3", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-ptc-runtime/-/dsh-ptc-runtime-0.2.1-rc.3.tgz", + "integrity": "sha512-nFUzb1abLvCQfUsrp/fMKQMCYU+O+ttiwqUFMa+uO4rFE6Nd+xNjus3V5aaqyy78jdciyBzzNysblZeryJAcXQ==", + "dev": true, + "license": "MIT", + "peer": true, + "peerDependencies": { + "@deepseek-ai/cordis": "~4.0.5", + "@deepseek-ai/dsh-sandbox": "0.2.1-rc.3" + } + }, + "node_modules/@deepseek-ai/dsh-sandbox": { + "version": "0.2.1-rc.3", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-sandbox/-/dsh-sandbox-0.2.1-rc.3.tgz", + "integrity": "sha512-7JXzEw2FBNAD3hNhiMzpxCjm8Zedc6DpFfsJfvh1Uh4HuIzX2BFEtzjvEUSwXGSWA+pCZOEvaYD9v0sZoMx3fQ==", "dev": true, "license": "MIT", "peer": true, "dependencies": { - "@deepseek-ai/schemastery": "^3.18.1" + "@deepseek-ai/dsh-util-values": "0.2.1-rc.3" }, "peerDependencies": { - "@deepseek-ai/cordis": "^4.0.1" + "@deepseek-ai/cordis": "~4.0.5", + "@deepseek-ai/dsh-llm": "0.2.1-rc.3", + "@deepseek-ai/dsh-session": "0.2.1-rc.3" } }, - "node_modules/@deepseek-ai/dsh-llm": { - "version": "0.1.0-rc.6", - "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-llm/-/dsh-llm-0.1.0-rc.6.tgz", - "integrity": "sha512-kuFGC8bHlzGTwlRxQhXjf3CYWl8M4NzH+EYIkrW8rri4iMc9W53xrdvkil5No/DUlMm8g1u7GdeiWYFy0TMvtA==", + "node_modules/@deepseek-ai/dsh-sandbox-policy": { + "version": "0.2.1-rc.3", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-sandbox-policy/-/dsh-sandbox-policy-0.2.1-rc.3.tgz", + "integrity": "sha512-/PlQEx/F6pwjjC/eOEBCHWG9InCu+aSEIC1k9V32noS43B/KS/FRSgP+SZ0YkbjMfk6iyS27sgglJDIY7RG1zQ==", "dev": true, "license": "MIT", "dependencies": { - "@deepseek-ai/schemastery": "^3.18.1" + "@deepseek-ai/schemastery": "~3.18.5", + "zod": "4.4.3" }, "peerDependencies": { - "@deepseek-ai/cordis": "^4.0.1", - "@deepseek-ai/dsh-attachment": "^0.1.0-rc.6", - "@deepseek-ai/dsh-brand": "^0.1.0-rc.6", - "@deepseek-ai/dsh-invariants": "^0.1.0-rc.6", - "@deepseek-ai/dsh-timeout": "^0.1.0-rc.6" + "@deepseek-ai/cordis": "~4.0.5", + "@deepseek-ai/dsh-agent": "0.2.1-rc.3", + "@deepseek-ai/dsh-sandbox": "0.2.1-rc.3", + "@deepseek-ai/dsh-session": "0.2.1-rc.3", + "@deepseek-ai/dsh-session-projection": "0.2.1-rc.3", + "@deepseek-ai/dsh-system-prompt": "0.2.1-rc.3" + } + }, + "node_modules/@deepseek-ai/dsh-sandbox-policy/node_modules/zod": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/zod/-/zod-4.4.3.tgz", + "integrity": "sha512-ytENFjIJFl2UwYglde2jchW2Hwm4GJFLDiSXWdTrJQBIN9Fcyp7n4DhxJEiWNAJMV1/BqWfW/kkg71UDcHJyTQ==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/colinhacks" } }, "node_modules/@deepseek-ai/dsh-scope": { - "version": "0.1.0-rc.6", - "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-scope/-/dsh-scope-0.1.0-rc.6.tgz", - "integrity": "sha512-UlDLV4syLoJinNg9imhXrSAHrdaTa5Ff8gg46rzjFJGPUOhAk3DZff0hryT5OhrBi0A5Tj92qVpg2pRVvxnUzQ==", + "version": "0.2.1-rc.3", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-scope/-/dsh-scope-0.2.1-rc.3.tgz", + "integrity": "sha512-3oCu1zZhbJTzV9TtYXjVUyxc9yOaQOYzxSGQvMuZ/q/O7/1Y1ofIS2j2GETfc79mCoiQIoQAjr2gu/ncXSgALw==", "dev": true, "license": "MIT", "peer": true, "peerDependencies": { - "@deepseek-ai/cordis": "^4.0.1", - "@deepseek-ai/dsh-invariants": "^0.1.0-rc.6" + "@deepseek-ai/cordis": "~4.0.5" } }, "node_modules/@deepseek-ai/dsh-session": { - "version": "0.1.0-rc.6", - "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-session/-/dsh-session-0.1.0-rc.6.tgz", - "integrity": "sha512-8tu8I6VWC7050GAUXWhcEWQw4pakALQc8TlhKr52m7Y4+kIKeNt3FBgP86PaGPBtpK0p5zUPRQNkFpzZbBdxyw==", + "version": "0.2.1-rc.3", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-session/-/dsh-session-0.2.1-rc.3.tgz", + "integrity": "sha512-z1Dfn6yB2YMm9iNThPHaIYCx0Y/mKjm+fMrWFtnPZmX0fJXVmTIr4RAfLF7ZFJk6qd52SUl8d2uX+uNbrPJESg==", "dev": true, "license": "MIT", + "peer": true, + "dependencies": { + "@deepseek-ai/dsh-brand": "0.2.1-rc.3", + "@deepseek-ai/dsh-llm": "0.2.1-rc.3", + "@deepseek-ai/dsh-util-values": "0.2.1-rc.3" + }, "peerDependencies": { - "@deepseek-ai/cordis": "^4.0.1", - "@deepseek-ai/dsh-brand": "^0.1.0-rc.6", - "@deepseek-ai/dsh-invariants": "^0.1.0-rc.6", - "@deepseek-ai/dsh-llm": "^0.1.0-rc.6", - "@deepseek-ai/dsh-scope": "^0.1.0-rc.6", - "@deepseek-ai/dsh-typert-protocol": "^0.1.0-rc.6" + "@deepseek-ai/cordis": "~4.0.5", + "@deepseek-ai/dsh-scope": "0.2.1-rc.3" } }, "node_modules/@deepseek-ai/dsh-session-format": { - "version": "0.2.0-rc.2", - "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-session-format/-/dsh-session-format-0.2.0-rc.2.tgz", - "integrity": "sha512-qdWtsJt1cLJbUAMCgzRBZ2LyW+XRJpetnle4N/0X/pkmJ9eOM6Y+QqwRQdcEcI4pWuEbPwuq7/HrnqoanVaiwg==", + "version": "0.2.1-rc.3", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-session-format/-/dsh-session-format-0.2.1-rc.3.tgz", + "integrity": "sha512-NXd8/YrrZIWKZXMEipscBl7CIM2fvMrkH7TxsSycCUPmtq2lVx/fAulN9VOUPHxvCvh1WyppXBbbeTcLwfTbIA==", "dev": true, "license": "MIT", "dependencies": { - "@deepseek-ai/dsh-util-values": "0.2.0-rc.2" + "@deepseek-ai/dsh-util-values": "0.2.1-rc.3" }, "peerDependencies": { - "@deepseek-ai/cordis": "~4.0.4" + "@deepseek-ai/cordis": "~4.0.5" } }, "node_modules/@deepseek-ai/dsh-session-format-v0-to-v1": { - "version": "0.2.0-rc.2", - "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-session-format-v0-to-v1/-/dsh-session-format-v0-to-v1-0.2.0-rc.2.tgz", - "integrity": "sha512-PPcfT7txn82/sZnFNxsuxEEUSSdEfBTkNTuOCaiu5ANDMmxUaxOOW6gXt+zBKndGJZRgCR/u9SoAdKv659FSZQ==", + "version": "0.2.1-rc.3", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-session-format-v0-to-v1/-/dsh-session-format-v0-to-v1-0.2.1-rc.3.tgz", + "integrity": "sha512-0bEZthwUO4e4PBRqHfvwkvrSE8qKztA7ga8C9tYvK8JBiu2GgT4z+ez6qUsvDJ+clLZeCPIPg1+VjN9lM8JfjA==", "dev": true, "license": "MIT", "dependencies": { - "@deepseek-ai/dsh-session-format": "0.2.0-rc.2", - "@deepseek-ai/dsh-util-values": "0.2.0-rc.2" + "@deepseek-ai/dsh-session-format": "0.2.1-rc.3", + "@deepseek-ai/dsh-util-values": "0.2.1-rc.3" }, "peerDependencies": { - "@deepseek-ai/cordis": "~4.0.4" + "@deepseek-ai/cordis": "~4.0.5" } }, "node_modules/@deepseek-ai/dsh-session-format-v1-to-v2": { - "version": "0.2.0-rc.2", - "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-session-format-v1-to-v2/-/dsh-session-format-v1-to-v2-0.2.0-rc.2.tgz", - "integrity": "sha512-PBIsz4OBE0wNnapaD87lz6255em24Kn53BKV4K1AqiNH9OWf1+m29TLXs/ICtZ2xigk6TK5H9q6oOVBBmbZyVw==", + "version": "0.2.1-rc.3", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-session-format-v1-to-v2/-/dsh-session-format-v1-to-v2-0.2.1-rc.3.tgz", + "integrity": "sha512-j3/QzReV7nnFqxdPFaeM4qGKFPAyT2lMZA6ApU6OrIQOy2e8r3APd6KuMOEcqf7s1WnQD8Qmy+MSqatuW7iQgA==", "dev": true, "license": "MIT", "dependencies": { - "@deepseek-ai/dsh-llm": "0.2.0-rc.2", - "@deepseek-ai/dsh-session-format": "0.2.0-rc.2", - "@deepseek-ai/dsh-session-format-v0-to-v1": "0.2.0-rc.2", - "@deepseek-ai/dsh-util-values": "0.2.0-rc.2" + "@deepseek-ai/dsh-llm": "0.2.1-rc.3", + "@deepseek-ai/dsh-session-format": "0.2.1-rc.3", + "@deepseek-ai/dsh-session-format-v0-to-v1": "0.2.1-rc.3", + "@deepseek-ai/dsh-util-values": "0.2.1-rc.3" }, "peerDependencies": { - "@deepseek-ai/cordis": "~4.0.4" + "@deepseek-ai/cordis": "~4.0.5" } }, - "node_modules/@deepseek-ai/dsh-session-format-v1-to-v2/node_modules/@deepseek-ai/dsh-brand": { - "version": "0.2.0-rc.2", - "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-brand/-/dsh-brand-0.2.0-rc.2.tgz", - "integrity": "sha512-A5XlN4tIgP0qObkYFhcZ7Oz/tM2oESEZqLwS0Qq+sM1ivGx6o4AMPgJdfKQlwLzqk0cMLNtAaVBHfiYoElt4lw==", - "dev": true, - "license": "MIT", - "peerDependencies": { - "@deepseek-ai/cordis": "~4.0.4" - } - }, - "node_modules/@deepseek-ai/dsh-session-format-v1-to-v2/node_modules/@deepseek-ai/dsh-llm": { - "version": "0.2.0-rc.2", - "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-llm/-/dsh-llm-0.2.0-rc.2.tgz", - "integrity": "sha512-6QFrQn/h0iNqCfPpgQidnHtLSpA99A7ZND/uYKaGSd/4BGP8KBhuRd0w63e9s4u+hfW8jc3j29WKcNLIOeUfcA==", + "node_modules/@deepseek-ai/dsh-session-format-v2-to-v3": { + "version": "0.2.1-rc.3", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-session-format-v2-to-v3/-/dsh-session-format-v2-to-v3-0.2.1-rc.3.tgz", + "integrity": "sha512-bXieiYETRov5pIiHR5TCJzgd7B/vCmme+i0Zh2+ZPBBZNnhltEfK2+Hg4qzd3Has9GHaMHc2wYOzuw328P1/7Q==", "dev": true, "license": "MIT", "dependencies": { - "@deepseek-ai/dsh-brand": "0.2.0-rc.2", - "@deepseek-ai/dsh-timeout": "0.2.0-rc.2", - "@deepseek-ai/dsh-typert-protocol": "0.2.0-rc.2", - "@deepseek-ai/dsh-util-crypto": "0.2.0-rc.2", - "@deepseek-ai/dsh-util-values": "0.2.0-rc.2", - "@deepseek-ai/schemastery": "~3.18.4", - "zod": "^4.4.3" + "@deepseek-ai/dsh-session-format": "0.2.1-rc.3", + "@deepseek-ai/dsh-session-format-v0-to-v1": "0.2.1-rc.3", + "@deepseek-ai/dsh-session-format-v1-to-v2": "0.2.1-rc.3" }, "peerDependencies": { - "@deepseek-ai/cordis": "~4.0.4" - } - }, - "node_modules/@deepseek-ai/dsh-session-format-v1-to-v2/node_modules/@deepseek-ai/dsh-timeout": { - "version": "0.2.0-rc.2", - "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-timeout/-/dsh-timeout-0.2.0-rc.2.tgz", - "integrity": "sha512-NDob8b8DJDB/sDPz3P7xhrkxOh1O9FbN1EZRKsxP4fuTfp4hrQU7aekYS5qZENFKoR8dBJMTh/zcEBw4m31glQ==", - "dev": true, - "license": "MIT", - "peerDependencies": { - "@deepseek-ai/cordis": "~4.0.4" + "@deepseek-ai/cordis": "~4.0.5" } }, - "node_modules/@deepseek-ai/dsh-session-format-v1-to-v2/node_modules/@deepseek-ai/dsh-typert-protocol": { - "version": "0.2.0-rc.2", - "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-typert-protocol/-/dsh-typert-protocol-0.2.0-rc.2.tgz", - "integrity": "sha512-95RvIDcVac2BWdv1IxN6yKlRV+8eEvkofqSxV+d0r8x1kx2EIWEsbdxz6C+coYIm+8e03MiN+rwOt8J7sLfe7Q==", + "node_modules/@deepseek-ai/dsh-session-format-v3-to-v4": { + "version": "0.2.1-rc.3", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-session-format-v3-to-v4/-/dsh-session-format-v3-to-v4-0.2.1-rc.3.tgz", + "integrity": "sha512-F7+GRMgW8TsA615jI5Lk4ZMTTTSidY0N+Ga+xyoH+520JyRpWtyalojIWVP1fopHXDLUjqBPODMWGTk7qV/N+g==", "dev": true, "license": "MIT", "dependencies": { - "@deepseek-ai/dsh-brand": "0.2.0-rc.2" + "@deepseek-ai/dsh-session-format": "0.2.1-rc.3", + "@deepseek-ai/dsh-session-format-v2-to-v3": "0.2.1-rc.3" }, "peerDependencies": { - "@deepseek-ai/cordis": "~4.0.4" + "@deepseek-ai/cordis": "~4.0.5" } }, - "node_modules/@deepseek-ai/dsh-session-format-v2-to-v3": { - "version": "0.2.0-rc.2", - "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-session-format-v2-to-v3/-/dsh-session-format-v2-to-v3-0.2.0-rc.2.tgz", - "integrity": "sha512-vrQQ1l3JgPIv/19mhm50FVD40hjro+tAkP3L1PNtGHrbBoYriNWXpR4QDOCQsHdPhg3vpnp9MmARMr8vZzl0Nw==", + "node_modules/@deepseek-ai/dsh-session-projection": { + "version": "0.2.1-rc.3", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-session-projection/-/dsh-session-projection-0.2.1-rc.3.tgz", + "integrity": "sha512-kyDxXb0avo0m4ZmAb8P+X6T/963NOZCvH/MgrWl3AUs5fHkXA6NfeVnalj488o5RpkRtZdqI7KtCEFNkyKAEsA==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { - "@deepseek-ai/dsh-session-format": "0.2.0-rc.2", - "@deepseek-ai/dsh-session-format-v0-to-v1": "0.2.0-rc.2", - "@deepseek-ai/dsh-session-format-v1-to-v2": "0.2.0-rc.2" + "zod": "4.4.3" }, "peerDependencies": { - "@deepseek-ai/cordis": "~4.0.4" + "@deepseek-ai/cordis": "~4.0.5", + "@deepseek-ai/dsh-session": "0.2.1-rc.3" } }, - "node_modules/@deepseek-ai/dsh-session-format-v3-to-v4": { - "version": "0.2.0-rc.2", - "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-session-format-v3-to-v4/-/dsh-session-format-v3-to-v4-0.2.0-rc.2.tgz", - "integrity": "sha512-UkiNDdGS8cwJKqjvHs52BKi+3NuKhoziz/l0IrDoDYpSdgDfK8HrrXkvIxOi+QaBUgIxNTQzA6tsI+TAIMDsGQ==", + "node_modules/@deepseek-ai/dsh-session-projection/node_modules/zod": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/zod/-/zod-4.4.3.tgz", + "integrity": "sha512-ytENFjIJFl2UwYglde2jchW2Hwm4GJFLDiSXWdTrJQBIN9Fcyp7n4DhxJEiWNAJMV1/BqWfW/kkg71UDcHJyTQ==", "dev": true, "license": "MIT", - "dependencies": { - "@deepseek-ai/dsh-session-format": "0.2.0-rc.2", - "@deepseek-ai/dsh-session-format-v2-to-v3": "0.2.0-rc.2" - }, - "peerDependencies": { - "@deepseek-ai/cordis": "~4.0.4" + "funding": { + "url": "https://github.com/sponsors/colinhacks" } }, "node_modules/@deepseek-ai/dsh-system-prompt": { - "version": "0.1.0-rc.6", - "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-system-prompt/-/dsh-system-prompt-0.1.0-rc.6.tgz", - "integrity": "sha512-E7g+XChh4q4/wX++v56z1pV4SA1Rtz42xkznLPPi9FlXrrzJxwHMOUzBZ9Rz3Y1kLhQ++HJG3ZatmNx3rjFilg==", + "version": "0.2.1-rc.3", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-system-prompt/-/dsh-system-prompt-0.2.1-rc.3.tgz", + "integrity": "sha512-2CXnigUF0N2Ps0AG/lOvvY9qeEhvo5uUCGCqvoGrH9IWbhoh/tfvzo9KTa5svyZIBW6mLMAyLyHOdi7f1T9tfg==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { - "@deepseek-ai/schemastery": "^3.18.1" + "@deepseek-ai/schemastery": "~3.18.5" }, "peerDependencies": { - "@deepseek-ai/cordis": "^4.0.1", - "@deepseek-ai/dsh-invariants": "^0.1.0-rc.6", - "@deepseek-ai/dsh-llm": "^0.1.0-rc.6", - "@deepseek-ai/dsh-scope": "^0.1.0-rc.6" + "@deepseek-ai/cordis": "~4.0.5", + "@deepseek-ai/dsh-llm": "0.2.1-rc.3", + "@deepseek-ai/dsh-scope": "0.2.1-rc.3" } }, "node_modules/@deepseek-ai/dsh-timeout": { - "version": "0.1.0-rc.6", - "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-timeout/-/dsh-timeout-0.1.0-rc.6.tgz", - "integrity": "sha512-CUean0fAnfsJVszFEip7PsU/S26W+JfDFfsza2dCtlw8n6xlkbHA9Gjxdk2aTwqDGCgXEPkRW7mYkdJ0n6FR7w==", + "version": "0.2.1-rc.3", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-timeout/-/dsh-timeout-0.2.1-rc.3.tgz", + "integrity": "sha512-DOuGjmY5dMlXqXqhuXlHNgEVajTLTYuj/EabS5b8IIBC5VN36YDOtyPgaT8aq1+LI7XoReDMUYQRUHCI3SOXqw==", "dev": true, "license": "MIT", "peerDependencies": { - "@deepseek-ai/cordis": "^4.0.1", - "@deepseek-ai/dsh-invariants": "^0.1.0-rc.6" + "@deepseek-ai/cordis": "~4.0.5" } }, "node_modules/@deepseek-ai/dsh-tools": { - "version": "0.1.0-rc.6", - "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-tools/-/dsh-tools-0.1.0-rc.6.tgz", - "integrity": "sha512-Tu08EPK3JyK0iNjH4FGzu/1uADynNSS6SmwOLdfytUN0YNqwNuKFSt2OJUg19famNlTgy992DcHfDu0T+gLXFg==", + "version": "0.2.1-rc.3", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-tools/-/dsh-tools-0.2.1-rc.3.tgz", + "integrity": "sha512-fHmhIFaztPt9+uvOlk3p4wXMU62F+TRe0ozVPasV3seIsFcxpca74QGSK5dFHICDhKIY1T9MUh0F3itMTdMi3A==", "dev": true, "license": "MIT", "dependencies": { - "@deepseek-ai/schemastery": "^3.18.1" + "@deepseek-ai/dsh-brand": "0.2.1-rc.3", + "@deepseek-ai/dsh-util-values": "0.2.1-rc.3", + "@deepseek-ai/schemastery": "~3.18.5" }, "peerDependencies": { - "@deepseek-ai/cordis": "^4.0.1", - "@deepseek-ai/dsh-agent": "^0.1.0-rc.6", - "@deepseek-ai/dsh-code-runtime": "^0.1.0-rc.6", - "@deepseek-ai/dsh-invariants": "^0.1.0-rc.6", - "@deepseek-ai/dsh-llm": "^0.1.0-rc.6", - "@deepseek-ai/dsh-scope": "^0.1.0-rc.6", - "@deepseek-ai/dsh-session": "^0.1.0-rc.6", - "@deepseek-ai/dsh-system-prompt": "^0.1.0-rc.6", - "@deepseek-ai/dsh-user-approval": "^0.1.0-rc.6" + "@deepseek-ai/cordis": "~4.0.5", + "@deepseek-ai/dsh-agent": "0.2.1-rc.3", + "@deepseek-ai/dsh-llm": "0.2.1-rc.3", + "@deepseek-ai/dsh-ptc-runtime": "0.2.1-rc.3", + "@deepseek-ai/dsh-sandbox": "0.2.1-rc.3", + "@deepseek-ai/dsh-sandbox-policy": "0.2.1-rc.3", + "@deepseek-ai/dsh-scope": "0.2.1-rc.3", + "@deepseek-ai/dsh-session": "0.2.1-rc.3", + "@deepseek-ai/dsh-system-prompt": "0.2.1-rc.3", + "@deepseek-ai/dsh-user-approval": "0.2.1-rc.3", + "@deepseek-ai/dsh-working-directory": "0.2.1-rc.3" } }, "node_modules/@deepseek-ai/dsh-typert-protocol": { - "version": "0.1.0-rc.6", - "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-typert-protocol/-/dsh-typert-protocol-0.1.0-rc.6.tgz", - "integrity": "sha512-weWzN8r01YCkoDCAM7BsKw2YhRrD4zL8N2SAZu9hovYtXSq8xHXsP4Zh8RLYIlYcuotjyff/6hic+0TJPd14YA==", + "version": "0.2.1-rc.3", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-typert-protocol/-/dsh-typert-protocol-0.2.1-rc.3.tgz", + "integrity": "sha512-ycKq2jF0h/iE/gwQFXn7Fx/pdKsVnPe6rkaA8F0SIZ8QfbAK8KcYmpG1Kn9zjwZAWPyb6pLMhD2GI/gXlM7f0Q==", "dev": true, "license": "MIT", + "peer": true, + "dependencies": { + "@deepseek-ai/dsh-brand": "0.2.1-rc.3", + "zod": "^4.4.3" + }, "peerDependencies": { - "@deepseek-ai/cordis": "^4.0.1", - "@deepseek-ai/dsh-invariants": "^0.1.0-rc.6" + "@deepseek-ai/cordis": "~4.0.5" } }, "node_modules/@deepseek-ai/dsh-user-approval": { - "version": "0.1.0-rc.6", - "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-user-approval/-/dsh-user-approval-0.1.0-rc.6.tgz", - "integrity": "sha512-9rnkSDGOpu2XUeGwbPeTzVUTFWTND1PMPM5L/ZQPptV5yyZlQiNxM2rCC6OdL+ZVerwxEqrRhZIQn/KVtQfKag==", + "version": "0.2.1-rc.3", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-user-approval/-/dsh-user-approval-0.2.1-rc.3.tgz", + "integrity": "sha512-n2AG2Oh3/32UNStxdkoTOYwheOjSjrJWPj9pPvgISw6vBURPUYrquoVD0AmvmV8TeWpxaCKIGsFNO08yrP9ODw==", "dev": true, "license": "MIT", "peer": true, "dependencies": { - "@deepseek-ai/schemastery": "^3.18.1" + "@deepseek-ai/schemastery": "~3.18.5" }, "peerDependencies": { - "@deepseek-ai/cordis": "^4.0.1", - "@deepseek-ai/dsh-agent": "^0.1.0-rc.6", - "@deepseek-ai/dsh-brand": "^0.1.0-rc.6", - "@deepseek-ai/dsh-invariants": "^0.1.0-rc.6", - "@deepseek-ai/dsh-llm": "^0.1.0-rc.6", - "@deepseek-ai/dsh-scope": "^0.1.0-rc.6", - "@deepseek-ai/dsh-session": "^0.1.0-rc.6", - "@deepseek-ai/dsh-system-prompt": "^0.1.0-rc.6" + "@deepseek-ai/cordis": "~4.0.5", + "@deepseek-ai/dsh-agent": "0.2.1-rc.3", + "@deepseek-ai/dsh-brand": "0.2.1-rc.3", + "@deepseek-ai/dsh-llm": "0.2.1-rc.3", + "@deepseek-ai/dsh-scope": "0.2.1-rc.3", + "@deepseek-ai/dsh-session": "0.2.1-rc.3", + "@deepseek-ai/dsh-system-prompt": "0.2.1-rc.3" } }, "node_modules/@deepseek-ai/dsh-util-crypto": { - "version": "0.2.0-rc.2", - "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-util-crypto/-/dsh-util-crypto-0.2.0-rc.2.tgz", - "integrity": "sha512-5OvvmepY69uXTagUMlnoHqg7euI4ZMifLgfdV8xZO20OslWGGiRCkJbZRyDtcJG9GsXWz9UimfWmUu52zKXJ5w==", + "version": "0.2.1-rc.3", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-util-crypto/-/dsh-util-crypto-0.2.1-rc.3.tgz", + "integrity": "sha512-AKznKjQmc2JHDQO+DV2Z68zwGrr3+0qAkxNqZE3SnuBTpO7TeTaS7v2cOzQi81EhZUlYFArmKEbmjcsCrsQvvw==", "dev": true, "license": "MIT", "peerDependencies": { - "@deepseek-ai/cordis": "~4.0.4" + "@deepseek-ai/cordis": "~4.0.5" } }, "node_modules/@deepseek-ai/dsh-util-values": { - "version": "0.2.0-rc.2", - "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-util-values/-/dsh-util-values-0.2.0-rc.2.tgz", - "integrity": "sha512-qgpsbgiZABuE9UvgNaVo9b2HiWwLeU93CTl9PFXqE0jN8ap1ALxzQsLGvr/q2MJuWDYqnFBg60XnqnY8ZxPWEg==", + "version": "0.2.1-rc.3", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-util-values/-/dsh-util-values-0.2.1-rc.3.tgz", + "integrity": "sha512-YyHu30xQBdp7sIr4ZNUliNxm2S9yRNOwdUPiBvfQZ+KaRtekI2j+T8+TFy7qgyBiGM7YYiG0xzJVibS894WIrg==", "dev": true, "license": "MIT", + "peer": true, "peerDependencies": { - "@deepseek-ai/cordis": "~4.0.4" + "@deepseek-ai/cordis": "~4.0.5" + } + }, + "node_modules/@deepseek-ai/dsh-working-directory": { + "version": "0.2.1-rc.3", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-working-directory/-/dsh-working-directory-0.2.1-rc.3.tgz", + "integrity": "sha512-Ec/MG+j4jWu/4+ym9UieB2zHt22mwSFfS2s2xZfnoCQIrxkIH5ayVcY1SNttrmHFYDwsyZEG4YY2dzYRtcuIfw==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "@deepseek-ai/schemastery": "~3.18.5", + "zod": "^4.4.3" + }, + "peerDependencies": { + "@deepseek-ai/cordis": "~4.0.5", + "@deepseek-ai/dsh-agent": "0.2.1-rc.3", + "@deepseek-ai/dsh-fs": "0.2.1-rc.3", + "@deepseek-ai/dsh-llm": "0.2.1-rc.3", + "@deepseek-ai/dsh-session": "0.2.1-rc.3", + "@deepseek-ai/dsh-session-projection": "0.2.1-rc.3", + "@deepseek-ai/dsh-system-prompt": "0.2.1-rc.3" } }, "node_modules/@deepseek-ai/schemastery": { @@ -2572,6 +2630,7 @@ } ], "license": "MIT", + "peer": true, "dependencies": { "baseline-browser-mapping": "^2.10.12", "caniuse-lite": "^1.0.30001782", @@ -3359,6 +3418,7 @@ "resolved": "https://registry.npmjs.org/preact/-/preact-10.29.1.tgz", "integrity": "sha512-gQCLc/vWroE8lIpleXtdJhTFDogTdZG9AjMUpVkDf2iTCNwYNWA+u16dL41TqUDJO4gm2IgrcMv3uTpjd4Pwmg==", "license": "MIT", + "peer": true, "funding": { "type": "opencollective", "url": "https://opencollective.com/preact" @@ -3419,6 +3479,7 @@ "integrity": "sha512-VmtB2rFU/GroZ4oL8+ZqXgSA38O6GR8KSIvWmEFv63pQ0G6KaBH9s07PO8XTXP4vI+3UJUEypOfjkGfmSBBR0w==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@types/estree": "1.0.8" }, @@ -3754,6 +3815,7 @@ "integrity": "sha512-o5a9xKjbtuhY6Bi5S3+HvbRERmouabWbyUcpXXUA1u+GNUKoROi9byOJ8M0nHbHYHkYICiMlqxkg1KkYmm25Sw==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "esbuild": "^0.21.3", "postcss": "^8.4.43", diff --git a/apps/memos-local-plugin/package.json b/apps/memos-local-plugin/package.json index 7e6366228..b0d879531 100644 --- a/apps/memos-local-plugin/package.json +++ b/apps/memos-local-plugin/package.json @@ -78,7 +78,8 @@ "lock:normalize": "node scripts/normalize-sqlite-lock.cjs", "lock:check": "node scripts/normalize-sqlite-lock.cjs --check", "verify:native": "node scripts/verify-native-runtime.cjs", - "verify:script-policy": "node scripts/verify-script-policy.cjs" + "verify:script-policy": "node scripts/verify-script-policy.cjs", + "test:dsh-compat": "node scripts/check-dsh-compatibility.mjs" }, "keywords": [ "memory", @@ -107,12 +108,12 @@ }, "peerDependencies": { "@deepseek-ai/cordis": "^4.0.1", - "@deepseek-ai/dsh-agent": ">=0.1.0-rc.5 <0.2.0", - "@deepseek-ai/dsh-llm": ">=0.1.0-rc.5 <0.2.0", - "@deepseek-ai/dsh-session": ">=0.1.0-rc.5 <0.2.0", - "@deepseek-ai/dsh-system-prompt": ">=0.1.0-rc.5 <0.2.0", - "@deepseek-ai/dsh-timeout": ">=0.1.0-rc.5 <0.2.0", - "@deepseek-ai/dsh-tools": ">=0.1.0-rc.5 <0.2.0", + "@deepseek-ai/dsh-agent": ">=0.1.0-rc.6 <0.2.0 || >=0.1.7-rc.2 <0.1.8 || >=0.2.0-rc.2 <0.2.1 || >=0.2.1-rc.2 <0.2.2", + "@deepseek-ai/dsh-llm": ">=0.1.0-rc.6 <0.2.0 || >=0.1.7-rc.2 <0.1.8 || >=0.2.0-rc.2 <0.2.1 || >=0.2.1-rc.2 <0.2.2", + "@deepseek-ai/dsh-session": ">=0.1.0-rc.6 <0.2.0 || >=0.1.7-rc.2 <0.1.8 || >=0.2.0-rc.2 <0.2.1 || >=0.2.1-rc.2 <0.2.2", + "@deepseek-ai/dsh-system-prompt": ">=0.1.0-rc.6 <0.2.0 || >=0.1.7-rc.2 <0.1.8 || >=0.2.0-rc.2 <0.2.1 || >=0.2.1-rc.2 <0.2.2", + "@deepseek-ai/dsh-timeout": ">=0.1.0-rc.6 <0.2.0 || >=0.1.7-rc.2 <0.1.8 || >=0.2.0-rc.2 <0.2.1 || >=0.2.1-rc.2 <0.2.2", + "@deepseek-ai/dsh-tools": ">=0.1.0-rc.6 <0.2.0 || >=0.1.7-rc.2 <0.1.8 || >=0.2.0-rc.2 <0.2.1 || >=0.2.1-rc.2 <0.2.2", "@deepseek-ai/schemastery": "^3.18.1" }, "peerDependenciesMeta": { @@ -142,16 +143,16 @@ } }, "devDependencies": { - "@deepseek-ai/cordis": "~4.0.4", - "@deepseek-ai/dsh-agent": "0.1.0-rc.6", - "@deepseek-ai/dsh-brand": "0.1.0-rc.6", - "@deepseek-ai/dsh-llm": "0.1.0-rc.6", - "@deepseek-ai/dsh-session": "0.1.0-rc.6", - "@deepseek-ai/dsh-session-format-v3-to-v4": "0.2.0-rc.2", - "@deepseek-ai/dsh-system-prompt": "0.1.0-rc.6", - "@deepseek-ai/dsh-timeout": "0.1.0-rc.6", - "@deepseek-ai/dsh-tools": "0.1.0-rc.6", - "@deepseek-ai/dsh-typert-protocol": "0.1.0-rc.6", + "@deepseek-ai/cordis": "~4.0.5", + "@deepseek-ai/dsh-agent": "0.2.1-rc.3", + "@deepseek-ai/dsh-brand": "0.2.1-rc.3", + "@deepseek-ai/dsh-llm": "0.2.1-rc.3", + "@deepseek-ai/dsh-session": "0.2.1-rc.3", + "@deepseek-ai/dsh-session-format-v3-to-v4": "0.2.1-rc.3", + "@deepseek-ai/dsh-system-prompt": "0.2.1-rc.3", + "@deepseek-ai/dsh-timeout": "0.2.1-rc.3", + "@deepseek-ai/dsh-tools": "0.2.1-rc.3", + "@deepseek-ai/dsh-typert-protocol": "0.2.1-rc.3", "@deepseek-ai/schemastery": "^3.18.1", "@preact/preset-vite": "^2.10.5", "@types/better-sqlite3": "^7.6.12", @@ -159,7 +160,8 @@ "@types/uuid": "^10.0.0", "typescript": "^5.7.0", "vite": "^5.4.10", - "vitest": "^2.1.9" + "vitest": "^2.1.9", + "semver": "7.7.4" }, "allowScripts": { "better-sqlite3": false, diff --git a/apps/memos-local-plugin/pnpm-lock.yaml b/apps/memos-local-plugin/pnpm-lock.yaml index 5116f3c47..31affb09c 100644 --- a/apps/memos-local-plugin/pnpm-lock.yaml +++ b/apps/memos-local-plugin/pnpm-lock.yaml @@ -34,35 +34,35 @@ importers: version: 2.8.3 devDependencies: '@deepseek-ai/cordis': - specifier: ~4.0.4 + specifier: ~4.0.5 version: 4.0.5 '@deepseek-ai/dsh-agent': - specifier: 0.1.0-rc.6 - version: 0.1.0-rc.6(6889e29676788162cc6455c880e3b4a2) + specifier: 0.2.1-rc.3 + version: 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-llm@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-session-projection@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-session@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))))(@deepseek-ai/dsh-session@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-system-prompt@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-llm@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-typert-protocol@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-util-values@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)) '@deepseek-ai/dsh-brand': - specifier: 0.1.0-rc.6 - version: 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) + specifier: 0.2.1-rc.3 + version: 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) '@deepseek-ai/dsh-llm': - specifier: 0.1.0-rc.6 - version: 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))) + specifier: 0.2.1-rc.3 + version: 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) '@deepseek-ai/dsh-session': - specifier: 0.1.0-rc.6 - version: 0.1.0-rc.6(f5e28831e96e72c33b5ea3a797f6fddf) + specifier: 0.2.1-rc.3 + version: 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)) '@deepseek-ai/dsh-session-format-v3-to-v4': - specifier: 0.2.0-rc.2 - version: 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) + specifier: 0.2.1-rc.3 + version: 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) '@deepseek-ai/dsh-system-prompt': - specifier: 0.1.0-rc.6 - version: 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-llm@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))))(@deepseek-ai/dsh-scope@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))) + specifier: 0.2.1-rc.3 + version: 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-llm@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)) '@deepseek-ai/dsh-timeout': - specifier: 0.1.0-rc.6 - version: 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) + specifier: 0.2.1-rc.3 + version: 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) '@deepseek-ai/dsh-tools': - specifier: 0.1.0-rc.6 - version: 0.1.0-rc.6(14b150c73c93dfea9f66b8be648ac0d7) + specifier: 0.2.1-rc.3 + version: 0.2.1-rc.3(1f5d0a9b849aaa1244bc4f2e453f609a) '@deepseek-ai/dsh-typert-protocol': - specifier: 0.1.0-rc.6 - version: 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) + specifier: 0.2.1-rc.3 + version: 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) '@deepseek-ai/schemastery': specifier: ^3.18.1 version: 3.18.5 @@ -78,6 +78,9 @@ importers: '@types/uuid': specifier: ^10.0.0 version: 10.0.0 + semver: + specifier: 7.7.4 + version: 7.7.4 typescript: specifier: ^5.7.0 version: 5.9.3 @@ -198,165 +201,168 @@ packages: '@deepseek-ai/cosmokit@1.8.6': resolution: {integrity: sha512-ZSD/fN52L498LBIOYwjIOlaLv5veY6ZEwI2yzvZUKQtctn0QAPqu8tKdJ+OF5+Tv6NBq1U+wJWH+QI6OGy5EvQ==} - '@deepseek-ai/dsh-agent@0.1.0-rc.6': - resolution: {integrity: sha512-vtqq2pWTrzn0dKfj5kREZRpP82AwtGjGx9V1lYnKvF+Uc/a8zyWbSvjDE7V1d3YQAQJzs2cWO31hURWDekDXIA==} + '@deepseek-ai/dsh-agent@0.2.1-rc.3': + resolution: {integrity: sha512-S6x/deneAsd+pOgecRLM1PC1No9O472kHjS9pS57nuTXi2Vtdo9l7qF+q7PfiHRezL5dxv5gUBQMORPmIYDNvQ==} peerDependencies: - '@deepseek-ai/cordis': ^4.0.1 - '@deepseek-ai/dsh-invariants': ^0.1.0-rc.6 - '@deepseek-ai/dsh-llm': ^0.1.0-rc.6 - '@deepseek-ai/dsh-scope': ^0.1.0-rc.6 - '@deepseek-ai/dsh-session': ^0.1.0-rc.6 - '@deepseek-ai/dsh-system-prompt': ^0.1.0-rc.6 - '@deepseek-ai/dsh-typert-protocol': ^0.1.0-rc.6 - - '@deepseek-ai/dsh-attachment@0.1.0-rc.6': - resolution: {integrity: sha512-3P6N17NQ8jqSQGzeCs+svCIqArU8oq0YmgEAo+axN9aVuUDferWU4DLRSX59UGpmyldX4LQn81toA+c+DqMcHg==} - peerDependencies: - '@deepseek-ai/cordis': ^4.0.1 - '@deepseek-ai/dsh-brand': ^0.1.0-rc.6 - '@deepseek-ai/dsh-invariants': ^0.1.0-rc.6 + '@deepseek-ai/cordis': ~4.0.5 + '@deepseek-ai/dsh-llm': 0.2.1-rc.3 + '@deepseek-ai/dsh-scope': 0.2.1-rc.3 + '@deepseek-ai/dsh-session': 0.2.1-rc.3 + '@deepseek-ai/dsh-session-projection': 0.2.1-rc.3 + '@deepseek-ai/dsh-system-prompt': 0.2.1-rc.3 + '@deepseek-ai/dsh-typert-protocol': 0.2.1-rc.3 + '@deepseek-ai/dsh-util-values': 0.2.1-rc.3 + '@deepseek-ai/dsh-workspace': 0.2.1-rc.3 + peerDependenciesMeta: + '@deepseek-ai/dsh-workspace': + optional: true - '@deepseek-ai/dsh-brand@0.1.0-rc.6': - resolution: {integrity: sha512-E8j9Nby24qP4rfrdcfc7bpt1CHpGT3tYmycOJJkEOH4ptIdT1m2ro9nmnSd5CWYukTr64A77vjm2WGqHRI92UA==} + '@deepseek-ai/dsh-brand@0.2.1-rc.3': + resolution: {integrity: sha512-bPpKuu05gZj7gdW15z6PL2dz4+A4MDEafgWOrhexFO7f08g1NeI4fhE4YNOxd8N2ua+tZJjsKCMAIobFMAaGOw==} peerDependencies: - '@deepseek-ai/cordis': ^4.0.1 - '@deepseek-ai/dsh-invariants': ^0.1.0-rc.6 + '@deepseek-ai/cordis': ~4.0.5 - '@deepseek-ai/dsh-brand@0.2.0-rc.2': - resolution: {integrity: sha512-A5XlN4tIgP0qObkYFhcZ7Oz/tM2oESEZqLwS0Qq+sM1ivGx6o4AMPgJdfKQlwLzqk0cMLNtAaVBHfiYoElt4lw==} + '@deepseek-ai/dsh-fs@0.2.1-rc.3': + resolution: {integrity: sha512-tENLWe471WlAXMc13J4cns8xU6lFyu1smwpkSKR85vhGr6FyWZhTlpVohZYm66LbwKTmSWiDhd9Urk7VxN9B9w==} peerDependencies: - '@deepseek-ai/cordis': ~4.0.4 + '@deepseek-ai/cordis': ~4.0.5 + '@deepseek-ai/dsh-brand': 0.2.1-rc.3 + '@deepseek-ai/dsh-llm': 0.2.1-rc.3 + '@deepseek-ai/dsh-sandbox': 0.2.1-rc.3 - '@deepseek-ai/dsh-code-runtime@0.1.0-rc.6': - resolution: {integrity: sha512-aw8D4IOeMo11A3uxQeE4LFoW3bvaQnVkGFqqtS+lsINDARrOCJHXLUgecoKpys+Lc5erZZ4UQDnymJmL4OCcKA==} + '@deepseek-ai/dsh-llm@0.2.1-rc.3': + resolution: {integrity: sha512-7Fq7zS3yQb1J1PsaNmahQ1gHDdsb338UhTkmZCexlNecmc5I44c/PbkHcT5pJ5SO4hnLplJOdDhiIMFpvvyAaw==} peerDependencies: - '@deepseek-ai/cordis': ^4.0.1 - '@deepseek-ai/dsh-invariants': ^0.1.0-rc.6 + '@deepseek-ai/cordis': ~4.0.5 - '@deepseek-ai/dsh-invariants@0.1.0-rc.6': - resolution: {integrity: sha512-WfEfOi99a4cpOugRAHTBSTnesLieu3ist1q9PXDXFBHX++K1rAl9+sB7YrdnbB8LH0UOY532gS9xJUYU6w0SLw==} + '@deepseek-ai/dsh-ptc-runtime@0.2.1-rc.3': + resolution: {integrity: sha512-nFUzb1abLvCQfUsrp/fMKQMCYU+O+ttiwqUFMa+uO4rFE6Nd+xNjus3V5aaqyy78jdciyBzzNysblZeryJAcXQ==} peerDependencies: - '@deepseek-ai/cordis': ^4.0.1 + '@deepseek-ai/cordis': ~4.0.5 + '@deepseek-ai/dsh-sandbox': 0.2.1-rc.3 - '@deepseek-ai/dsh-llm@0.1.0-rc.6': - resolution: {integrity: sha512-kuFGC8bHlzGTwlRxQhXjf3CYWl8M4NzH+EYIkrW8rri4iMc9W53xrdvkil5No/DUlMm8g1u7GdeiWYFy0TMvtA==} + '@deepseek-ai/dsh-sandbox-policy@0.2.1-rc.3': + resolution: {integrity: sha512-/PlQEx/F6pwjjC/eOEBCHWG9InCu+aSEIC1k9V32noS43B/KS/FRSgP+SZ0YkbjMfk6iyS27sgglJDIY7RG1zQ==} peerDependencies: - '@deepseek-ai/cordis': ^4.0.1 - '@deepseek-ai/dsh-attachment': ^0.1.0-rc.6 - '@deepseek-ai/dsh-brand': ^0.1.0-rc.6 - '@deepseek-ai/dsh-invariants': ^0.1.0-rc.6 - '@deepseek-ai/dsh-timeout': ^0.1.0-rc.6 - - '@deepseek-ai/dsh-llm@0.2.0-rc.2': - resolution: {integrity: sha512-6QFrQn/h0iNqCfPpgQidnHtLSpA99A7ZND/uYKaGSd/4BGP8KBhuRd0w63e9s4u+hfW8jc3j29WKcNLIOeUfcA==} + '@deepseek-ai/cordis': ~4.0.5 + '@deepseek-ai/dsh-agent': 0.2.1-rc.3 + '@deepseek-ai/dsh-sandbox': 0.2.1-rc.3 + '@deepseek-ai/dsh-session': 0.2.1-rc.3 + '@deepseek-ai/dsh-session-projection': 0.2.1-rc.3 + '@deepseek-ai/dsh-system-prompt': 0.2.1-rc.3 + + '@deepseek-ai/dsh-sandbox@0.2.1-rc.3': + resolution: {integrity: sha512-7JXzEw2FBNAD3hNhiMzpxCjm8Zedc6DpFfsJfvh1Uh4HuIzX2BFEtzjvEUSwXGSWA+pCZOEvaYD9v0sZoMx3fQ==} peerDependencies: - '@deepseek-ai/cordis': ~4.0.4 + '@deepseek-ai/cordis': ~4.0.5 + '@deepseek-ai/dsh-llm': 0.2.1-rc.3 + '@deepseek-ai/dsh-session': 0.2.1-rc.3 - '@deepseek-ai/dsh-scope@0.1.0-rc.6': - resolution: {integrity: sha512-UlDLV4syLoJinNg9imhXrSAHrdaTa5Ff8gg46rzjFJGPUOhAk3DZff0hryT5OhrBi0A5Tj92qVpg2pRVvxnUzQ==} + '@deepseek-ai/dsh-scope@0.2.1-rc.3': + resolution: {integrity: sha512-3oCu1zZhbJTzV9TtYXjVUyxc9yOaQOYzxSGQvMuZ/q/O7/1Y1ofIS2j2GETfc79mCoiQIoQAjr2gu/ncXSgALw==} peerDependencies: - '@deepseek-ai/cordis': ^4.0.1 - '@deepseek-ai/dsh-invariants': ^0.1.0-rc.6 + '@deepseek-ai/cordis': ~4.0.5 - '@deepseek-ai/dsh-session-format-v0-to-v1@0.2.0-rc.2': - resolution: {integrity: sha512-PPcfT7txn82/sZnFNxsuxEEUSSdEfBTkNTuOCaiu5ANDMmxUaxOOW6gXt+zBKndGJZRgCR/u9SoAdKv659FSZQ==} + '@deepseek-ai/dsh-session-format-v0-to-v1@0.2.1-rc.3': + resolution: {integrity: sha512-0bEZthwUO4e4PBRqHfvwkvrSE8qKztA7ga8C9tYvK8JBiu2GgT4z+ez6qUsvDJ+clLZeCPIPg1+VjN9lM8JfjA==} peerDependencies: - '@deepseek-ai/cordis': ~4.0.4 + '@deepseek-ai/cordis': ~4.0.5 - '@deepseek-ai/dsh-session-format-v1-to-v2@0.2.0-rc.2': - resolution: {integrity: sha512-PBIsz4OBE0wNnapaD87lz6255em24Kn53BKV4K1AqiNH9OWf1+m29TLXs/ICtZ2xigk6TK5H9q6oOVBBmbZyVw==} + '@deepseek-ai/dsh-session-format-v1-to-v2@0.2.1-rc.3': + resolution: {integrity: sha512-j3/QzReV7nnFqxdPFaeM4qGKFPAyT2lMZA6ApU6OrIQOy2e8r3APd6KuMOEcqf7s1WnQD8Qmy+MSqatuW7iQgA==} peerDependencies: - '@deepseek-ai/cordis': ~4.0.4 + '@deepseek-ai/cordis': ~4.0.5 - '@deepseek-ai/dsh-session-format-v2-to-v3@0.2.0-rc.2': - resolution: {integrity: sha512-vrQQ1l3JgPIv/19mhm50FVD40hjro+tAkP3L1PNtGHrbBoYriNWXpR4QDOCQsHdPhg3vpnp9MmARMr8vZzl0Nw==} + '@deepseek-ai/dsh-session-format-v2-to-v3@0.2.1-rc.3': + resolution: {integrity: sha512-bXieiYETRov5pIiHR5TCJzgd7B/vCmme+i0Zh2+ZPBBZNnhltEfK2+Hg4qzd3Has9GHaMHc2wYOzuw328P1/7Q==} peerDependencies: - '@deepseek-ai/cordis': ~4.0.4 + '@deepseek-ai/cordis': ~4.0.5 - '@deepseek-ai/dsh-session-format-v3-to-v4@0.2.0-rc.2': - resolution: {integrity: sha512-UkiNDdGS8cwJKqjvHs52BKi+3NuKhoziz/l0IrDoDYpSdgDfK8HrrXkvIxOi+QaBUgIxNTQzA6tsI+TAIMDsGQ==} + '@deepseek-ai/dsh-session-format-v3-to-v4@0.2.1-rc.3': + resolution: {integrity: sha512-F7+GRMgW8TsA615jI5Lk4ZMTTTSidY0N+Ga+xyoH+520JyRpWtyalojIWVP1fopHXDLUjqBPODMWGTk7qV/N+g==} peerDependencies: - '@deepseek-ai/cordis': ~4.0.4 + '@deepseek-ai/cordis': ~4.0.5 - '@deepseek-ai/dsh-session-format@0.2.0-rc.2': - resolution: {integrity: sha512-qdWtsJt1cLJbUAMCgzRBZ2LyW+XRJpetnle4N/0X/pkmJ9eOM6Y+QqwRQdcEcI4pWuEbPwuq7/HrnqoanVaiwg==} + '@deepseek-ai/dsh-session-format@0.2.1-rc.3': + resolution: {integrity: sha512-NXd8/YrrZIWKZXMEipscBl7CIM2fvMrkH7TxsSycCUPmtq2lVx/fAulN9VOUPHxvCvh1WyppXBbbeTcLwfTbIA==} peerDependencies: - '@deepseek-ai/cordis': ~4.0.4 + '@deepseek-ai/cordis': ~4.0.5 - '@deepseek-ai/dsh-session@0.1.0-rc.6': - resolution: {integrity: sha512-8tu8I6VWC7050GAUXWhcEWQw4pakALQc8TlhKr52m7Y4+kIKeNt3FBgP86PaGPBtpK0p5zUPRQNkFpzZbBdxyw==} + '@deepseek-ai/dsh-session-projection@0.2.1-rc.3': + resolution: {integrity: sha512-kyDxXb0avo0m4ZmAb8P+X6T/963NOZCvH/MgrWl3AUs5fHkXA6NfeVnalj488o5RpkRtZdqI7KtCEFNkyKAEsA==} peerDependencies: - '@deepseek-ai/cordis': ^4.0.1 - '@deepseek-ai/dsh-brand': ^0.1.0-rc.6 - '@deepseek-ai/dsh-invariants': ^0.1.0-rc.6 - '@deepseek-ai/dsh-llm': ^0.1.0-rc.6 - '@deepseek-ai/dsh-scope': ^0.1.0-rc.6 - '@deepseek-ai/dsh-typert-protocol': ^0.1.0-rc.6 - - '@deepseek-ai/dsh-system-prompt@0.1.0-rc.6': - resolution: {integrity: sha512-E7g+XChh4q4/wX++v56z1pV4SA1Rtz42xkznLPPi9FlXrrzJxwHMOUzBZ9Rz3Y1kLhQ++HJG3ZatmNx3rjFilg==} + '@deepseek-ai/cordis': ~4.0.5 + '@deepseek-ai/dsh-session': 0.2.1-rc.3 + + '@deepseek-ai/dsh-session@0.2.1-rc.3': + resolution: {integrity: sha512-z1Dfn6yB2YMm9iNThPHaIYCx0Y/mKjm+fMrWFtnPZmX0fJXVmTIr4RAfLF7ZFJk6qd52SUl8d2uX+uNbrPJESg==} peerDependencies: - '@deepseek-ai/cordis': ^4.0.1 - '@deepseek-ai/dsh-invariants': ^0.1.0-rc.6 - '@deepseek-ai/dsh-llm': ^0.1.0-rc.6 - '@deepseek-ai/dsh-scope': ^0.1.0-rc.6 + '@deepseek-ai/cordis': ~4.0.5 + '@deepseek-ai/dsh-scope': 0.2.1-rc.3 - '@deepseek-ai/dsh-timeout@0.1.0-rc.6': - resolution: {integrity: sha512-CUean0fAnfsJVszFEip7PsU/S26W+JfDFfsza2dCtlw8n6xlkbHA9Gjxdk2aTwqDGCgXEPkRW7mYkdJ0n6FR7w==} + '@deepseek-ai/dsh-system-prompt@0.2.1-rc.3': + resolution: {integrity: sha512-2CXnigUF0N2Ps0AG/lOvvY9qeEhvo5uUCGCqvoGrH9IWbhoh/tfvzo9KTa5svyZIBW6mLMAyLyHOdi7f1T9tfg==} peerDependencies: - '@deepseek-ai/cordis': ^4.0.1 - '@deepseek-ai/dsh-invariants': ^0.1.0-rc.6 + '@deepseek-ai/cordis': ~4.0.5 + '@deepseek-ai/dsh-llm': 0.2.1-rc.3 + '@deepseek-ai/dsh-scope': 0.2.1-rc.3 - '@deepseek-ai/dsh-timeout@0.2.0-rc.2': - resolution: {integrity: sha512-NDob8b8DJDB/sDPz3P7xhrkxOh1O9FbN1EZRKsxP4fuTfp4hrQU7aekYS5qZENFKoR8dBJMTh/zcEBw4m31glQ==} + '@deepseek-ai/dsh-timeout@0.2.1-rc.3': + resolution: {integrity: sha512-DOuGjmY5dMlXqXqhuXlHNgEVajTLTYuj/EabS5b8IIBC5VN36YDOtyPgaT8aq1+LI7XoReDMUYQRUHCI3SOXqw==} peerDependencies: - '@deepseek-ai/cordis': ~4.0.4 + '@deepseek-ai/cordis': ~4.0.5 - '@deepseek-ai/dsh-tools@0.1.0-rc.6': - resolution: {integrity: sha512-Tu08EPK3JyK0iNjH4FGzu/1uADynNSS6SmwOLdfytUN0YNqwNuKFSt2OJUg19famNlTgy992DcHfDu0T+gLXFg==} + '@deepseek-ai/dsh-tools@0.2.1-rc.3': + resolution: {integrity: sha512-fHmhIFaztPt9+uvOlk3p4wXMU62F+TRe0ozVPasV3seIsFcxpca74QGSK5dFHICDhKIY1T9MUh0F3itMTdMi3A==} peerDependencies: - '@deepseek-ai/cordis': ^4.0.1 - '@deepseek-ai/dsh-agent': ^0.1.0-rc.6 - '@deepseek-ai/dsh-code-runtime': ^0.1.0-rc.6 - '@deepseek-ai/dsh-invariants': ^0.1.0-rc.6 - '@deepseek-ai/dsh-llm': ^0.1.0-rc.6 - '@deepseek-ai/dsh-scope': ^0.1.0-rc.6 - '@deepseek-ai/dsh-session': ^0.1.0-rc.6 - '@deepseek-ai/dsh-system-prompt': ^0.1.0-rc.6 - '@deepseek-ai/dsh-user-approval': ^0.1.0-rc.6 - - '@deepseek-ai/dsh-typert-protocol@0.1.0-rc.6': - resolution: {integrity: sha512-weWzN8r01YCkoDCAM7BsKw2YhRrD4zL8N2SAZu9hovYtXSq8xHXsP4Zh8RLYIlYcuotjyff/6hic+0TJPd14YA==} + '@deepseek-ai/cordis': ~4.0.5 + '@deepseek-ai/dsh-agent': 0.2.1-rc.3 + '@deepseek-ai/dsh-llm': 0.2.1-rc.3 + '@deepseek-ai/dsh-ptc-runtime': 0.2.1-rc.3 + '@deepseek-ai/dsh-sandbox': 0.2.1-rc.3 + '@deepseek-ai/dsh-sandbox-policy': 0.2.1-rc.3 + '@deepseek-ai/dsh-scope': 0.2.1-rc.3 + '@deepseek-ai/dsh-session': 0.2.1-rc.3 + '@deepseek-ai/dsh-system-prompt': 0.2.1-rc.3 + '@deepseek-ai/dsh-user-approval': 0.2.1-rc.3 + '@deepseek-ai/dsh-working-directory': 0.2.1-rc.3 + + '@deepseek-ai/dsh-typert-protocol@0.2.1-rc.3': + resolution: {integrity: sha512-ycKq2jF0h/iE/gwQFXn7Fx/pdKsVnPe6rkaA8F0SIZ8QfbAK8KcYmpG1Kn9zjwZAWPyb6pLMhD2GI/gXlM7f0Q==} peerDependencies: - '@deepseek-ai/cordis': ^4.0.1 - '@deepseek-ai/dsh-invariants': ^0.1.0-rc.6 + '@deepseek-ai/cordis': ~4.0.5 - '@deepseek-ai/dsh-typert-protocol@0.2.0-rc.2': - resolution: {integrity: sha512-95RvIDcVac2BWdv1IxN6yKlRV+8eEvkofqSxV+d0r8x1kx2EIWEsbdxz6C+coYIm+8e03MiN+rwOt8J7sLfe7Q==} + '@deepseek-ai/dsh-user-approval@0.2.1-rc.3': + resolution: {integrity: sha512-n2AG2Oh3/32UNStxdkoTOYwheOjSjrJWPj9pPvgISw6vBURPUYrquoVD0AmvmV8TeWpxaCKIGsFNO08yrP9ODw==} peerDependencies: - '@deepseek-ai/cordis': ~4.0.4 - - '@deepseek-ai/dsh-user-approval@0.1.0-rc.6': - resolution: {integrity: sha512-9rnkSDGOpu2XUeGwbPeTzVUTFWTND1PMPM5L/ZQPptV5yyZlQiNxM2rCC6OdL+ZVerwxEqrRhZIQn/KVtQfKag==} + '@deepseek-ai/cordis': ~4.0.5 + '@deepseek-ai/dsh-agent': 0.2.1-rc.3 + '@deepseek-ai/dsh-brand': 0.2.1-rc.3 + '@deepseek-ai/dsh-llm': 0.2.1-rc.3 + '@deepseek-ai/dsh-scope': 0.2.1-rc.3 + '@deepseek-ai/dsh-session': 0.2.1-rc.3 + '@deepseek-ai/dsh-system-prompt': 0.2.1-rc.3 + + '@deepseek-ai/dsh-util-crypto@0.2.1-rc.3': + resolution: {integrity: sha512-AKznKjQmc2JHDQO+DV2Z68zwGrr3+0qAkxNqZE3SnuBTpO7TeTaS7v2cOzQi81EhZUlYFArmKEbmjcsCrsQvvw==} peerDependencies: - '@deepseek-ai/cordis': ^4.0.1 - '@deepseek-ai/dsh-agent': ^0.1.0-rc.6 - '@deepseek-ai/dsh-brand': ^0.1.0-rc.6 - '@deepseek-ai/dsh-invariants': ^0.1.0-rc.6 - '@deepseek-ai/dsh-llm': ^0.1.0-rc.6 - '@deepseek-ai/dsh-scope': ^0.1.0-rc.6 - '@deepseek-ai/dsh-session': ^0.1.0-rc.6 - '@deepseek-ai/dsh-system-prompt': ^0.1.0-rc.6 - - '@deepseek-ai/dsh-util-crypto@0.2.0-rc.2': - resolution: {integrity: sha512-5OvvmepY69uXTagUMlnoHqg7euI4ZMifLgfdV8xZO20OslWGGiRCkJbZRyDtcJG9GsXWz9UimfWmUu52zKXJ5w==} + '@deepseek-ai/cordis': ~4.0.5 + + '@deepseek-ai/dsh-util-values@0.2.1-rc.3': + resolution: {integrity: sha512-YyHu30xQBdp7sIr4ZNUliNxm2S9yRNOwdUPiBvfQZ+KaRtekI2j+T8+TFy7qgyBiGM7YYiG0xzJVibS894WIrg==} peerDependencies: - '@deepseek-ai/cordis': ~4.0.4 + '@deepseek-ai/cordis': ~4.0.5 - '@deepseek-ai/dsh-util-values@0.2.0-rc.2': - resolution: {integrity: sha512-qgpsbgiZABuE9UvgNaVo9b2HiWwLeU93CTl9PFXqE0jN8ap1ALxzQsLGvr/q2MJuWDYqnFBg60XnqnY8ZxPWEg==} + '@deepseek-ai/dsh-working-directory@0.2.1-rc.3': + resolution: {integrity: sha512-Ec/MG+j4jWu/4+ym9UieB2zHt22mwSFfS2s2xZfnoCQIrxkIH5ayVcY1SNttrmHFYDwsyZEG4YY2dzYRtcuIfw==} peerDependencies: - '@deepseek-ai/cordis': ~4.0.4 + '@deepseek-ai/cordis': ~4.0.5 + '@deepseek-ai/dsh-agent': 0.2.1-rc.3 + '@deepseek-ai/dsh-fs': 0.2.1-rc.3 + '@deepseek-ai/dsh-llm': 0.2.1-rc.3 + '@deepseek-ai/dsh-session': 0.2.1-rc.3 + '@deepseek-ai/dsh-session-projection': 0.2.1-rc.3 + '@deepseek-ai/dsh-system-prompt': 0.2.1-rc.3 '@deepseek-ai/schemastery@3.18.5': resolution: {integrity: sha512-Mnobvqf9rHsZYv4g5edj5ddxS1oF1kIdSlz0DunUgnY3LWG5F26MqvH3YOOsSaodCgyzJ16OMN9O99/s5Crtdw==} @@ -698,105 +704,89 @@ packages: resolution: {integrity: sha512-excjX8DfsIcJ10x1Kzr4RcWe1edC9PquDRRPx3YVCvQv+U5p7Yin2s32ftzikXojb1PIFc/9Mt28/y+iRklkrw==} cpu: [arm64] os: [linux] - libc: [glibc] '@img/sharp-libvips-linux-arm@1.2.4': resolution: {integrity: sha512-bFI7xcKFELdiNCVov8e44Ia4u2byA+l3XtsAj+Q8tfCwO6BQ8iDojYdvoPMqsKDkuoOo+X6HZA0s0q11ANMQ8A==} cpu: [arm] os: [linux] - libc: [glibc] '@img/sharp-libvips-linux-ppc64@1.2.4': resolution: {integrity: sha512-FMuvGijLDYG6lW+b/UvyilUWu5Ayu+3r2d1S8notiGCIyYU/76eig1UfMmkZ7vwgOrzKzlQbFSuQfgm7GYUPpA==} cpu: [ppc64] os: [linux] - libc: [glibc] '@img/sharp-libvips-linux-riscv64@1.2.4': resolution: {integrity: sha512-oVDbcR4zUC0ce82teubSm+x6ETixtKZBh/qbREIOcI3cULzDyb18Sr/Wcyx7NRQeQzOiHTNbZFF1UwPS2scyGA==} cpu: [riscv64] os: [linux] - libc: [glibc] '@img/sharp-libvips-linux-s390x@1.2.4': resolution: {integrity: sha512-qmp9VrzgPgMoGZyPvrQHqk02uyjA0/QrTO26Tqk6l4ZV0MPWIW6LTkqOIov+J1yEu7MbFQaDpwdwJKhbJvuRxQ==} cpu: [s390x] os: [linux] - libc: [glibc] '@img/sharp-libvips-linux-x64@1.2.4': resolution: {integrity: sha512-tJxiiLsmHc9Ax1bz3oaOYBURTXGIRDODBqhveVHonrHJ9/+k89qbLl0bcJns+e4t4rvaNBxaEZsFtSfAdquPrw==} cpu: [x64] os: [linux] - libc: [glibc] '@img/sharp-libvips-linuxmusl-arm64@1.2.4': resolution: {integrity: sha512-FVQHuwx1IIuNow9QAbYUzJ+En8KcVm9Lk5+uGUQJHaZmMECZmOlix9HnH7n1TRkXMS0pGxIJokIVB9SuqZGGXw==} cpu: [arm64] os: [linux] - libc: [musl] '@img/sharp-libvips-linuxmusl-x64@1.2.4': resolution: {integrity: sha512-+LpyBk7L44ZIXwz/VYfglaX/okxezESc6UxDSoyo2Ks6Jxc4Y7sGjpgU9s4PMgqgjj1gZCylTieNamqA1MF7Dg==} cpu: [x64] os: [linux] - libc: [musl] '@img/sharp-linux-arm64@0.34.5': resolution: {integrity: sha512-bKQzaJRY/bkPOXyKx5EVup7qkaojECG6NLYswgktOZjaXecSAeCWiZwwiFf3/Y+O1HrauiE3FVsGxFg8c24rZg==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [arm64] os: [linux] - libc: [glibc] '@img/sharp-linux-arm@0.34.5': resolution: {integrity: sha512-9dLqsvwtg1uuXBGZKsxem9595+ujv0sJ6Vi8wcTANSFpwV/GONat5eCkzQo/1O6zRIkh0m/8+5BjrRr7jDUSZw==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [arm] os: [linux] - libc: [glibc] '@img/sharp-linux-ppc64@0.34.5': resolution: {integrity: sha512-7zznwNaqW6YtsfrGGDA6BRkISKAAE1Jo0QdpNYXNMHu2+0dTrPflTLNkpc8l7MUP5M16ZJcUvysVWWrMefZquA==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [ppc64] os: [linux] - libc: [glibc] '@img/sharp-linux-riscv64@0.34.5': resolution: {integrity: sha512-51gJuLPTKa7piYPaVs8GmByo7/U7/7TZOq+cnXJIHZKavIRHAP77e3N2HEl3dgiqdD/w0yUfiJnII77PuDDFdw==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [riscv64] os: [linux] - libc: [glibc] '@img/sharp-linux-s390x@0.34.5': resolution: {integrity: sha512-nQtCk0PdKfho3eC5MrbQoigJ2gd1CgddUMkabUj+rBevs8tZ2cULOx46E7oyX+04WGfABgIwmMC0VqieTiR4jg==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [s390x] os: [linux] - libc: [glibc] '@img/sharp-linux-x64@0.34.5': resolution: {integrity: sha512-MEzd8HPKxVxVenwAa+JRPwEC7QFjoPWuS5NZnBt6B3pu7EG2Ge0id1oLHZpPJdn3OQK+BQDiw9zStiHBTJQQQQ==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [x64] os: [linux] - libc: [glibc] '@img/sharp-linuxmusl-arm64@0.34.5': resolution: {integrity: sha512-fprJR6GtRsMt6Kyfq44IsChVZeGN97gTD331weR1ex1c1rypDEABN6Tm2xa1wE6lYb5DdEnk03NZPqA7Id21yg==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [arm64] os: [linux] - libc: [musl] '@img/sharp-linuxmusl-x64@0.34.5': resolution: {integrity: sha512-Jg8wNT1MUzIvhBFxViqrEhWDGzqymo3sV7z7ZsaWbZNDLXRJZoRGrjulp60YYtV4wfY8VIKcWidjojlLcWrd8Q==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [x64] os: [linux] - libc: [musl] '@img/sharp-wasm32@0.34.5': resolution: {integrity: sha512-OdWTEiVkY2PHwqkbBI8frFxQQFekHaSSkUIJkwzclWZe64O1X4UlUjqqqLaPbUpMOQk6FBu/HtlGXNblIs0huw==} @@ -942,79 +932,66 @@ packages: resolution: {integrity: sha512-L+34Qqil+v5uC0zEubW7uByo78WOCIrBvci69E7sFASRl0X7b/MB6Cqd1lky/CtcSVTydWa2WZwFuWexjS5o6g==} cpu: [arm] os: [linux] - libc: [glibc] '@rollup/rollup-linux-arm-musleabihf@4.60.1': resolution: {integrity: sha512-n83O8rt4v34hgFzlkb1ycniJh7IR5RCIqt6mz1VRJD6pmhRi0CXdmfnLu9dIUS6buzh60IvACM842Ffb3xd6Gg==} cpu: [arm] os: [linux] - libc: [musl] '@rollup/rollup-linux-arm64-gnu@4.60.1': resolution: {integrity: sha512-Nql7sTeAzhTAja3QXeAI48+/+GjBJ+QmAH13snn0AJSNL50JsDqotyudHyMbO2RbJkskbMbFJfIJKWA6R1LCJQ==} cpu: [arm64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-arm64-musl@4.60.1': resolution: {integrity: sha512-+pUymDhd0ys9GcKZPPWlFiZ67sTWV5UU6zOJat02M1+PiuSGDziyRuI/pPue3hoUwm2uGfxdL+trT6Z9rxnlMA==} cpu: [arm64] os: [linux] - libc: [musl] '@rollup/rollup-linux-loong64-gnu@4.60.1': resolution: {integrity: sha512-VSvgvQeIcsEvY4bKDHEDWcpW4Yw7BtlKG1GUT4FzBUlEKQK0rWHYBqQt6Fm2taXS+1bXvJT6kICu5ZwqKCnvlQ==} cpu: [loong64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-loong64-musl@4.60.1': resolution: {integrity: sha512-4LqhUomJqwe641gsPp6xLfhqWMbQV04KtPp7/dIp0nzPxAkNY1AbwL5W0MQpcalLYk07vaW9Kp1PBhdpZYYcEw==} cpu: [loong64] os: [linux] - libc: [musl] '@rollup/rollup-linux-ppc64-gnu@4.60.1': resolution: {integrity: sha512-tLQQ9aPvkBxOc/EUT6j3pyeMD6Hb8QF2BTBnCQWP/uu1lhc9AIrIjKnLYMEroIz/JvtGYgI9dF3AxHZNaEH0rw==} cpu: [ppc64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-ppc64-musl@4.60.1': resolution: {integrity: sha512-RMxFhJwc9fSXP6PqmAz4cbv3kAyvD1etJFjTx4ONqFP9DkTkXsAMU4v3Vyc5BgzC+anz7nS/9tp4obsKfqkDHg==} cpu: [ppc64] os: [linux] - libc: [musl] '@rollup/rollup-linux-riscv64-gnu@4.60.1': resolution: {integrity: sha512-QKgFl+Yc1eEk6MmOBfRHYF6lTxiiiV3/z/BRrbSiW2I7AFTXoBFvdMEyglohPj//2mZS4hDOqeB0H1ACh3sBbg==} cpu: [riscv64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-riscv64-musl@4.60.1': resolution: {integrity: sha512-RAjXjP/8c6ZtzatZcA1RaQr6O1TRhzC+adn8YZDnChliZHviqIjmvFwHcxi4JKPSDAt6Uhf/7vqcBzQJy0PDJg==} cpu: [riscv64] os: [linux] - libc: [musl] '@rollup/rollup-linux-s390x-gnu@4.60.1': resolution: {integrity: sha512-wcuocpaOlaL1COBYiA89O6yfjlp3RwKDeTIA0hM7OpmhR1Bjo9j31G1uQVpDlTvwxGn2nQs65fBFL5UFd76FcQ==} cpu: [s390x] os: [linux] - libc: [glibc] '@rollup/rollup-linux-x64-gnu@4.60.1': resolution: {integrity: sha512-77PpsFQUCOiZR9+LQEFg9GClyfkNXj1MP6wRnzYs0EeWbPcHs02AXu4xuUbM1zhwn3wqaizle3AEYg5aeoohhg==} cpu: [x64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-x64-musl@4.60.1': resolution: {integrity: sha512-5cIATbk5vynAjqqmyBjlciMJl1+R/CwX9oLk/EyiFXDWd95KpHdrOJT//rnUl4cUcskrd0jCCw3wpZnhIHdD9w==} cpu: [x64] os: [linux] - libc: [musl] '@rollup/rollup-openbsd-x64@4.60.1': resolution: {integrity: sha512-cl0w09WsCi17mcmWqqglez9Gk8isgeWvoUZ3WiJFYSR3zjBQc2J5/ihSjpl+VLjPqjQ/1hJRcqBfLjssREQILw==} @@ -1574,6 +1551,9 @@ packages: zimmerframe@1.1.4: resolution: {integrity: sha512-B58NGBEoc8Y9MWWCQGl/gq9xBCe4IiKM0a2x7GZdQKOW5Exr8S1W24J6OgM1njK8xCRGvAJIL/MxXHf6SkmQKQ==} + zod@4.4.3: + resolution: {integrity: sha512-ytENFjIJFl2UwYglde2jchW2Hwm4GJFLDiSXWdTrJQBIN9Fcyp7n4DhxJEiWNAJMV1/BqWfW/kkg71UDcHJyTQ==} + zod@4.6.7: resolution: {integrity: sha512-g8W2D2kU6a8untc053fX1uVBKzM7yqAxW/3zwk83+6RyF2+SKOuV+c0wBDhUwzV1PaGapmZH+rmcUzPf+3CGwg==} @@ -1715,166 +1695,176 @@ snapshots: '@deepseek-ai/cosmokit@1.8.6': {} - '@deepseek-ai/dsh-agent@0.1.0-rc.6(6889e29676788162cc6455c880e3b4a2)': + '@deepseek-ai/dsh-agent@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-llm@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-session-projection@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-session@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))))(@deepseek-ai/dsh-session@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-system-prompt@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-llm@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-typert-protocol@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-util-values@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))': dependencies: '@deepseek-ai/cordis': 4.0.5 - '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5) - '@deepseek-ai/dsh-llm': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))) - '@deepseek-ai/dsh-scope': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) - '@deepseek-ai/dsh-session': 0.1.0-rc.6(f5e28831e96e72c33b5ea3a797f6fddf) - '@deepseek-ai/dsh-system-prompt': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-llm@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))))(@deepseek-ai/dsh-scope@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))) - '@deepseek-ai/dsh-typert-protocol': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) + '@deepseek-ai/dsh-llm': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-scope': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-session': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)) + '@deepseek-ai/dsh-session-projection': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-session@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))) + '@deepseek-ai/dsh-system-prompt': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-llm@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)) + '@deepseek-ai/dsh-typert-protocol': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-util-values': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) - '@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))': + '@deepseek-ai/dsh-brand@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)': dependencies: '@deepseek-ai/cordis': 4.0.5 - '@deepseek-ai/dsh-brand': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) - '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5) - '@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))': + '@deepseek-ai/dsh-fs@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-brand@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-llm@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-sandbox@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-llm@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-session@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))))': dependencies: '@deepseek-ai/cordis': 4.0.5 - '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-brand': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-llm': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-sandbox': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-llm@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-session@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))) - '@deepseek-ai/dsh-brand@0.2.0-rc.2(@deepseek-ai/cordis@4.0.5)': + '@deepseek-ai/dsh-llm@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)': dependencies: '@deepseek-ai/cordis': 4.0.5 + '@deepseek-ai/dsh-brand': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-timeout': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-typert-protocol': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-util-crypto': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-util-values': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/schemastery': 3.18.5 + zod: 4.4.3 - '@deepseek-ai/dsh-code-runtime@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))': + '@deepseek-ai/dsh-ptc-runtime@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-sandbox@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-llm@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-session@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))))': dependencies: '@deepseek-ai/cordis': 4.0.5 - '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-sandbox': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-llm@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-session@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))) - '@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)': + '@deepseek-ai/dsh-sandbox-policy@0.2.1-rc.3(1809d3b5f9b8552c21c008788fe3c75e)': dependencies: '@deepseek-ai/cordis': 4.0.5 + '@deepseek-ai/dsh-agent': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-llm@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-session-projection@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-session@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))))(@deepseek-ai/dsh-session@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-system-prompt@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-llm@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-typert-protocol@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-util-values@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)) + '@deepseek-ai/dsh-sandbox': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-llm@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-session@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))) + '@deepseek-ai/dsh-session': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)) + '@deepseek-ai/dsh-session-projection': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-session@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))) + '@deepseek-ai/dsh-system-prompt': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-llm@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)) '@deepseek-ai/schemastery': 3.18.5 + zod: 4.4.3 - '@deepseek-ai/dsh-llm@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))': + '@deepseek-ai/dsh-sandbox@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-llm@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-session@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)))': dependencies: '@deepseek-ai/cordis': 4.0.5 - '@deepseek-ai/dsh-attachment': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) - '@deepseek-ai/dsh-brand': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) - '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5) - '@deepseek-ai/dsh-timeout': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) - '@deepseek-ai/schemastery': 3.18.5 + '@deepseek-ai/dsh-llm': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-session': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)) + '@deepseek-ai/dsh-util-values': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) - '@deepseek-ai/dsh-llm@0.2.0-rc.2(@deepseek-ai/cordis@4.0.5)': + '@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)': dependencies: '@deepseek-ai/cordis': 4.0.5 - '@deepseek-ai/dsh-brand': 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) - '@deepseek-ai/dsh-timeout': 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) - '@deepseek-ai/dsh-typert-protocol': 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) - '@deepseek-ai/dsh-util-crypto': 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) - '@deepseek-ai/dsh-util-values': 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) - '@deepseek-ai/schemastery': 3.18.5 - zod: 4.6.7 - '@deepseek-ai/dsh-scope@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))': + '@deepseek-ai/dsh-session-format-v0-to-v1@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)': dependencies: '@deepseek-ai/cordis': 4.0.5 - '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-session-format': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-util-values': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) - '@deepseek-ai/dsh-session-format-v0-to-v1@0.2.0-rc.2(@deepseek-ai/cordis@4.0.5)': + '@deepseek-ai/dsh-session-format-v1-to-v2@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)': dependencies: '@deepseek-ai/cordis': 4.0.5 - '@deepseek-ai/dsh-session-format': 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) - '@deepseek-ai/dsh-util-values': 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-llm': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-session-format': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-session-format-v0-to-v1': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-util-values': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) - '@deepseek-ai/dsh-session-format-v1-to-v2@0.2.0-rc.2(@deepseek-ai/cordis@4.0.5)': + '@deepseek-ai/dsh-session-format-v2-to-v3@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)': dependencies: '@deepseek-ai/cordis': 4.0.5 - '@deepseek-ai/dsh-llm': 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) - '@deepseek-ai/dsh-session-format': 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) - '@deepseek-ai/dsh-session-format-v0-to-v1': 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) - '@deepseek-ai/dsh-util-values': 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-session-format': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-session-format-v0-to-v1': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-session-format-v1-to-v2': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) - '@deepseek-ai/dsh-session-format-v2-to-v3@0.2.0-rc.2(@deepseek-ai/cordis@4.0.5)': + '@deepseek-ai/dsh-session-format-v3-to-v4@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)': dependencies: '@deepseek-ai/cordis': 4.0.5 - '@deepseek-ai/dsh-session-format': 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) - '@deepseek-ai/dsh-session-format-v0-to-v1': 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) - '@deepseek-ai/dsh-session-format-v1-to-v2': 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-session-format': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-session-format-v2-to-v3': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) - '@deepseek-ai/dsh-session-format-v3-to-v4@0.2.0-rc.2(@deepseek-ai/cordis@4.0.5)': + '@deepseek-ai/dsh-session-format@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)': dependencies: '@deepseek-ai/cordis': 4.0.5 - '@deepseek-ai/dsh-session-format': 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) - '@deepseek-ai/dsh-session-format-v2-to-v3': 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-util-values': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) - '@deepseek-ai/dsh-session-format@0.2.0-rc.2(@deepseek-ai/cordis@4.0.5)': + '@deepseek-ai/dsh-session-projection@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-session@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)))': dependencies: '@deepseek-ai/cordis': 4.0.5 - '@deepseek-ai/dsh-util-values': 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-session': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)) + zod: 4.4.3 - '@deepseek-ai/dsh-session@0.1.0-rc.6(f5e28831e96e72c33b5ea3a797f6fddf)': + '@deepseek-ai/dsh-session@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))': dependencies: '@deepseek-ai/cordis': 4.0.5 - '@deepseek-ai/dsh-brand': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) - '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5) - '@deepseek-ai/dsh-llm': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))) - '@deepseek-ai/dsh-scope': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) - '@deepseek-ai/dsh-typert-protocol': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) + '@deepseek-ai/dsh-brand': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-llm': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-scope': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-util-values': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) - '@deepseek-ai/dsh-system-prompt@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-llm@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))))(@deepseek-ai/dsh-scope@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))': + '@deepseek-ai/dsh-system-prompt@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-llm@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))': dependencies: '@deepseek-ai/cordis': 4.0.5 - '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5) - '@deepseek-ai/dsh-llm': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))) - '@deepseek-ai/dsh-scope': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) + '@deepseek-ai/dsh-llm': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-scope': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) '@deepseek-ai/schemastery': 3.18.5 - '@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))': + '@deepseek-ai/dsh-timeout@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)': dependencies: '@deepseek-ai/cordis': 4.0.5 - '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5) - '@deepseek-ai/dsh-timeout@0.2.0-rc.2(@deepseek-ai/cordis@4.0.5)': + '@deepseek-ai/dsh-tools@0.2.1-rc.3(1f5d0a9b849aaa1244bc4f2e453f609a)': dependencies: '@deepseek-ai/cordis': 4.0.5 - - '@deepseek-ai/dsh-tools@0.1.0-rc.6(14b150c73c93dfea9f66b8be648ac0d7)': - dependencies: - '@deepseek-ai/cordis': 4.0.5 - '@deepseek-ai/dsh-agent': 0.1.0-rc.6(6889e29676788162cc6455c880e3b4a2) - '@deepseek-ai/dsh-code-runtime': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) - '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5) - '@deepseek-ai/dsh-llm': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))) - '@deepseek-ai/dsh-scope': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) - '@deepseek-ai/dsh-session': 0.1.0-rc.6(f5e28831e96e72c33b5ea3a797f6fddf) - '@deepseek-ai/dsh-system-prompt': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-llm@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))))(@deepseek-ai/dsh-scope@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))) - '@deepseek-ai/dsh-user-approval': 0.1.0-rc.6(731c4b6587473c7b25a7e36b8e78ec80) + '@deepseek-ai/dsh-agent': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-llm@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-session-projection@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-session@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))))(@deepseek-ai/dsh-session@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-system-prompt@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-llm@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-typert-protocol@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-util-values@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)) + '@deepseek-ai/dsh-brand': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-llm': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-ptc-runtime': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-sandbox@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-llm@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-session@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)))) + '@deepseek-ai/dsh-sandbox': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-llm@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-session@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))) + '@deepseek-ai/dsh-sandbox-policy': 0.2.1-rc.3(1809d3b5f9b8552c21c008788fe3c75e) + '@deepseek-ai/dsh-scope': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-session': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)) + '@deepseek-ai/dsh-system-prompt': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-llm@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)) + '@deepseek-ai/dsh-user-approval': 0.2.1-rc.3(f3a61cdc614c420235807a61121b4b4a) + '@deepseek-ai/dsh-util-values': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-working-directory': 0.2.1-rc.3(b3db524bc35e44edbf239e3bbf3fca0a) '@deepseek-ai/schemastery': 3.18.5 - '@deepseek-ai/dsh-typert-protocol@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))': + '@deepseek-ai/dsh-typert-protocol@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)': dependencies: '@deepseek-ai/cordis': 4.0.5 - '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-brand': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) + zod: 4.6.7 - '@deepseek-ai/dsh-typert-protocol@0.2.0-rc.2(@deepseek-ai/cordis@4.0.5)': + '@deepseek-ai/dsh-user-approval@0.2.1-rc.3(f3a61cdc614c420235807a61121b4b4a)': dependencies: '@deepseek-ai/cordis': 4.0.5 - '@deepseek-ai/dsh-brand': 0.2.0-rc.2(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-agent': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-llm@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-session-projection@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-session@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))))(@deepseek-ai/dsh-session@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-system-prompt@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-llm@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-typert-protocol@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-util-values@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)) + '@deepseek-ai/dsh-brand': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-llm': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-scope': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-session': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)) + '@deepseek-ai/dsh-system-prompt': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-llm@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)) + '@deepseek-ai/schemastery': 3.18.5 - '@deepseek-ai/dsh-user-approval@0.1.0-rc.6(731c4b6587473c7b25a7e36b8e78ec80)': + '@deepseek-ai/dsh-util-crypto@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)': dependencies: '@deepseek-ai/cordis': 4.0.5 - '@deepseek-ai/dsh-agent': 0.1.0-rc.6(6889e29676788162cc6455c880e3b4a2) - '@deepseek-ai/dsh-brand': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) - '@deepseek-ai/dsh-invariants': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5) - '@deepseek-ai/dsh-llm': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))) - '@deepseek-ai/dsh-scope': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)) - '@deepseek-ai/dsh-session': 0.1.0-rc.6(f5e28831e96e72c33b5ea3a797f6fddf) - '@deepseek-ai/dsh-system-prompt': 0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-llm@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-attachment@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-brand@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-timeout@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))))(@deepseek-ai/dsh-scope@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-invariants@0.1.0-rc.6(@deepseek-ai/cordis@4.0.5))) - '@deepseek-ai/schemastery': 3.18.5 - '@deepseek-ai/dsh-util-crypto@0.2.0-rc.2(@deepseek-ai/cordis@4.0.5)': + '@deepseek-ai/dsh-util-values@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)': dependencies: '@deepseek-ai/cordis': 4.0.5 - '@deepseek-ai/dsh-util-values@0.2.0-rc.2(@deepseek-ai/cordis@4.0.5)': + '@deepseek-ai/dsh-working-directory@0.2.1-rc.3(b3db524bc35e44edbf239e3bbf3fca0a)': dependencies: '@deepseek-ai/cordis': 4.0.5 + '@deepseek-ai/dsh-agent': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-llm@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-session-projection@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-session@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))))(@deepseek-ai/dsh-session@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-system-prompt@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-llm@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)))(@deepseek-ai/dsh-typert-protocol@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-util-values@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)) + '@deepseek-ai/dsh-fs': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-brand@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-llm@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-sandbox@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-llm@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-session@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)))) + '@deepseek-ai/dsh-llm': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5) + '@deepseek-ai/dsh-session': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)) + '@deepseek-ai/dsh-session-projection': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-session@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))) + '@deepseek-ai/dsh-system-prompt': 0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)(@deepseek-ai/dsh-llm@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5))(@deepseek-ai/dsh-scope@0.2.1-rc.3(@deepseek-ai/cordis@4.0.5)) + '@deepseek-ai/schemastery': 3.18.5 + zod: 4.6.7 '@deepseek-ai/schemastery@3.18.5': dependencies: @@ -2892,4 +2882,6 @@ snapshots: zimmerframe@1.1.4: {} + zod@4.4.3: {} + zod@4.6.7: {} diff --git a/apps/memos-local-plugin/scripts/check-dsh-compatibility.mjs b/apps/memos-local-plugin/scripts/check-dsh-compatibility.mjs new file mode 100644 index 000000000..34bfd00d1 --- /dev/null +++ b/apps/memos-local-plugin/scripts/check-dsh-compatibility.mjs @@ -0,0 +1,102 @@ +import { cp, mkdir, mkdtemp, readdir, readFile, symlink, writeFile } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import { dirname, join, resolve } from "node:path"; +import { fileURLToPath } from "node:url"; +import { spawnSync } from "node:child_process"; + +// Install each real host API in isolation; never rewrite the checkout's dependencies +// or use a customer's DSH profile, credentials, or session data. +const root = resolve(dirname(fileURLToPath(import.meta.url)), ".."); +const manifest = JSON.parse(await readFile(join(root, "package.json"), "utf8")); +const versions = process.argv.slice(2); +if (!versions.length) versions.push( + "0.1.0-rc.6", "0.1.7-rc.2", + "0.2.0-rc.2", "0.2.1-rc.2", "0.2.1-rc.3", +); +if (versions.some((version) => !/^\d+\.\d+\.\d+(?:-rc\.\d+)?$/.test(version))) { + throw new Error("Expected explicit DSH versions, e.g. 0.2.1-rc.3"); +} +const matrix = await mkdtemp(join(tmpdir(), "memos-dsh-matrix-")); +console.log(`DSH compatibility fixtures: ${matrix}`); + +function run(command, args, cwd) { + const result = spawnSync(command, args, { cwd, stdio: "inherit", shell: false }); + if (result.error) throw result.error; + if (result.status !== 0) throw new Error(`${command} exited ${result.status} in ${cwd}`); +} + +for (const version of versions) { + const fixture = join(matrix, version); + await mkdir(fixture); + const devDependencies = Object.fromEntries( + Object.entries(manifest.devDependencies) + .filter(([name]) => name.startsWith("@deepseek-ai/")) + .map(([name, value]) => [name, + name.startsWith("@deepseek-ai/dsh-") && name !== "@deepseek-ai/dsh-session-format-v3-to-v4" + ? version : value]), + ); + // Early DSH previews used caret peers. Letting npm choose their latest + // prerelease mixes rc.6 and rc.8, so pin the entire host peer closure. + const inspected = new Set(); + let pending = Object.keys(devDependencies).filter((name) => name.startsWith("@deepseek-ai/dsh-") + && name !== "@deepseek-ai/dsh-session-format-v3-to-v4"); + while (pending.length) { + const metadata = await Promise.all(pending.map(async (name) => { + inspected.add(name); + const response = await fetch(`https://registry.npmjs.org/${encodeURIComponent(name)}/${version}`); + if (!response.ok) throw new Error(`Cannot resolve ${name}@${version}: ${response.status}`); + return response.json(); + })); + const next = new Set(); + for (const pkg of metadata) { + for (const name of Object.keys({ ...pkg.dependencies, ...pkg.peerDependencies })) { + if (!name.startsWith("@deepseek-ai/dsh-") || name === "@deepseek-ai/dsh-session-format-v3-to-v4") continue; + devDependencies[name] = version; + if (!inspected.has(name)) next.add(name); + } + } + pending = [...next]; + } + await writeFile(join(fixture, "package.json"), JSON.stringify({ + name: "memos-dsh-compatibility-fixture", private: true, type: "module", devDependencies, + }, null, 2)); + const installArgs = ["install", "--ignore-scripts", "--no-audit", "--no-fund"]; + if (process.env.npm_execpath) { + run(process.execPath, [process.env.npm_execpath, ...installArgs], fixture); + } else { + run("npm", installArgs, fixture); + } + + // Reuse the installed non-host test/build tools and native bindings. DSH and + // all its transitive peers above remain local to the fixture. + for (const entry of await readdir(join(root, "node_modules"), { withFileTypes: true })) { + if (entry.name === ".bin" || entry.name.startsWith(".")) continue; + const source = join(root, "node_modules", entry.name); + const target = join(fixture, "node_modules", entry.name); + if (entry.name.startsWith("@")) { + await mkdir(target, { recursive: true }); + for (const child of await readdir(source)) { + if (entry.name === "@deepseek-ai" && (child.startsWith("dsh-") || child === "cordis")) continue; + try { await symlink(join(source, child), join(target, child), "junction"); } + catch (error) { if (error.code !== "EEXIST") throw error; } + } + } else { + try { await symlink(source, target, "junction"); } + catch (error) { if (error.code !== "EEXIST") throw error; } + } + } + for (const path of [ + "adapters", "agent-contract", "bridge", "core", "server", "tests", "scripts", + "bridge.cts", "bridge.mts", "tsconfig.json", "tsconfig.build.json", "vitest.config.ts", + ]) await cp(join(root, path), join(fixture, path), { recursive: true }); + + console.log(`\n=== DSH ${version}: compile, build, and adapter contracts ===`); + run(process.execPath, [join(root, "node_modules/typescript/bin/tsc"), "-p", "tsconfig.json", "--noEmit"], fixture); + run(process.execPath, [join(root, "node_modules/typescript/bin/tsc"), "-p", "tsconfig.build.json"], fixture); + const tests = (await readdir(join(fixture, "tests/unit/adapters"))) + .filter((name) => name.startsWith("deepseek-harness-") && name.endsWith(".test.ts") && name !== "deepseek-harness-package.test.ts") + .map((name) => `tests/unit/adapters/${name}`); + run(process.execPath, [join(root, "node_modules/vitest/vitest.mjs"), "run", ...tests], fixture); + console.log(`PASS DSH ${version}`); +} +console.log(`PASS all ${versions.length} DSH versions. Fixtures retained at ${matrix}`); diff --git a/apps/memos-local-plugin/tests/unit/adapters/deepseek-harness-package.test.ts b/apps/memos-local-plugin/tests/unit/adapters/deepseek-harness-package.test.ts index 0fe1a2201..dd1f08dd6 100644 --- a/apps/memos-local-plugin/tests/unit/adapters/deepseek-harness-package.test.ts +++ b/apps/memos-local-plugin/tests/unit/adapters/deepseek-harness-package.test.ts @@ -1,12 +1,53 @@ import { readFile } from "node:fs/promises"; import { resolve } from "node:path"; +import { createRequire } from "node:module"; import { parse } from "yaml"; import { describe, expect, it } from "vitest"; const root = resolve(import.meta.dirname, "../../.."); +const { satisfies } = createRequire(import.meta.url)("semver") as { + satisfies(version: string, range: string): boolean; +}; +const hostServices = ["agent", "llm", "session", "system-prompt", "timeout", "tools"]; describe("DeepSeek Harness bundle package", () => { + it.each(["0.1.0-rc.6", "0.1.7-rc.2", "0.2.0-rc.2", "0.2.1-rc.2", "0.2.1-rc.3"])( + "admits the supported host %s without a version exemption", + async (version) => { + const pkg = JSON.parse(await readFile(resolve(root, "package.json"), "utf8")); + for (const service of hostServices) { + const name = `@deepseek-ai/dsh-${service}`; + expect(satisfies(version, pkg.peerDependencies[name]), name).toBe(true); + expect(pkg.peerDependenciesMeta[name]?.optional, name).toBe(true); + } + }, + ); + + it.each(["0.1.0-rc.5", "0.2.2-rc.1", "0.2.2", "0.3.0-rc.1", "0.3.0"])( + "does not admit the unvalidated host %s", + async (version) => { + const pkg = JSON.parse(await readFile(resolve(root, "package.json"), "utf8")); + for (const service of hostServices) { + expect(satisfies(version, pkg.peerDependencies[`@deepseek-ai/dsh-${service}`])).toBe(false); + } + }, + ); + + it("keeps both lockfile importers aligned with the manifest", async () => { + const pkg = JSON.parse(await readFile(resolve(root, "package.json"), "utf8")); + const npm = JSON.parse(await readFile(resolve(root, "package-lock.json"), "utf8")); + const pnpm = parse(await readFile(resolve(root, "pnpm-lock.yaml"), "utf8")); + for (const group of ["dependencies", "devDependencies", "peerDependencies"]) { + expect(npm.packages[""][group]).toEqual(pkg[group]); + } + for (const group of ["dependencies", "devDependencies"]) { + for (const [name, version] of Object.entries(pkg[group])) { + expect(pnpm.importers["."][group][name].specifier, name).toBe(version); + } + } + }); + it("declares a DSH bundle patch and mounts the compiled adapter", async () => { const packageJson = JSON.parse( await readFile(resolve(root, "package.json"), "utf8"), diff --git a/apps/memos-local-plugin/tests/unit/adapters/deepseek-harness-runtime.test.ts b/apps/memos-local-plugin/tests/unit/adapters/deepseek-harness-runtime.test.ts index 01ddeb8f8..04a7726c7 100644 --- a/apps/memos-local-plugin/tests/unit/adapters/deepseek-harness-runtime.test.ts +++ b/apps/memos-local-plugin/tests/unit/adapters/deepseek-harness-runtime.test.ts @@ -1,5 +1,6 @@ import { join } from "node:path"; import { assertV4RowAdmission, releasedV4SessionFormatCodec } from "@deepseek-ai/dsh-session-format-v3-to-v4"; +import { adoptSessionEvent, snapshotSessionEvent } from "@deepseek-ai/dsh-session"; import type { Context } from "@deepseek-ai/cordis"; import { describe, expect, it, vi } from "vitest"; @@ -20,6 +21,16 @@ import { dshV4Event } from "../../helpers/deepseek-harness-v4.js"; import { DEFAULT_CONFIG } from "../../../core/config/index.js"; describe("DeepSeek Harness adapter runtime defaults", () => { + it("preserves recall attribution across the installed host's session boundary", () => { + const message = createDeepSeekHarnessRecallMessage("synthetic recall"); + const event = { ...dshV4Event("user/message", message), surfaceOp: "append" }; + expect(adoptSessionEvent(event as never)).toEqual(event); + expect(snapshotSessionEvent(event as never)).toEqual(event); + expect(event.data).toMatchObject({ source: { + kind: "plugin:memos-local-memory", plugin: "memos-local-memory", form: "recall", + } }); + }); + it("creates producer-owned recall messages admitted by DSH V4", () => { const message = createDeepSeekHarnessRecallMessage("synthetic recall"); const event = dshV4Event("user/message", message); From faec48d7695ed5992cee81492ad72044fe1949d9 Mon Sep 17 00:00:00 2001 From: Wenqiang Wei <46308778+endxxxx@users.noreply.github.com> Date: Thu, 29 Oct 2026 18:33:55 +0800 Subject: [PATCH 35/38] fix: preserve identifier types in PolarDB lightweight recall --- src/memos/graph_dbs/polardb.py | 25 +++++++- tests/graph_dbs/test_search_return_fields.py | 67 ++++++++++++++++++++ 2 files changed, 90 insertions(+), 2 deletions(-) diff --git a/src/memos/graph_dbs/polardb.py b/src/memos/graph_dbs/polardb.py index bf74fbb8b..e7a8c4306 100644 --- a/src/memos/graph_dbs/polardb.py +++ b/src/memos/graph_dbs/polardb.py @@ -33,9 +33,30 @@ def _build_lightweight_return_columns(return_fields: list[str]) -> str: return "".join(f",\n {column}" for column in columns) -def _decode_lightweight_return_value(value: Any) -> Any: +def _decode_lightweight_return_value(value: Any, field: str | None = None) -> Any: if hasattr(value, "value"): value = value.value + # Drivers may return agtype identifiers as already-decoded scalar strings. + # Parsing a numeric ID again would change its type. + identifier_fields = { + "user_id", + "user_name", + "session_id", + "mem_cube_id", + "dialog_id", + "working_binding", + "project_id", + "manager_user_id", + } + if field in identifier_fields: + if isinstance(value, str): + try: + decoded = json.loads(value) + except (json.JSONDecodeError, TypeError): + return value + return decoded if decoded is None or isinstance(decoded, str) else value + if isinstance(value, int) and not isinstance(value, bool): + return str(value) if isinstance(value, str): try: return json.loads(value) @@ -1990,7 +2011,7 @@ def search_by_embedding( item = {"id": id_val, "score": score_val} if light_weight_mode: for offset, field in enumerate(validated_return_fields, start=5): - item[field] = _decode_lightweight_return_value(row[offset]) + item[field] = _decode_lightweight_return_value(row[offset], field=field) elif validated_return_fields: properties = row[1] # properties column item.update( diff --git a/tests/graph_dbs/test_search_return_fields.py b/tests/graph_dbs/test_search_return_fields.py index 1ed0f6173..a23374e5a 100644 --- a/tests/graph_dbs/test_search_return_fields.py +++ b/tests/graph_dbs/test_search_return_fields.py @@ -264,6 +264,73 @@ def fake_connection(): def test_polardb_declares_lightweight_vector_search_support(self, polardb_instance): assert polardb_instance.supports_lightweight_vector_search is True + @pytest.mark.parametrize( + "stored_user_id,expected_user_id", + [ + ("1234567890123456789", "1234567890123456789"), + (1234567890123456789, "1234567890123456789"), + ('"1234567890123456789"', "1234567890123456789"), + ("00123", "00123"), + (None, None), + ("null", None), + ], + ) + def test_lightweight_numeric_user_id_can_be_recalled( + self, polardb_instance, stored_user_id, expected_user_id + ): + from memos.memories.textual.tree_text_memory.retrieve.recall import GraphMemoryRetriever + + polardb_instance.db_name = "test_db" + polardb_instance.config = {"user_name": "default_user"} + polardb_instance._build_user_name_and_kb_ids_conditions_sql = MagicMock(return_value=[]) + polardb_instance._build_filter_conditions_sql = MagicMock(return_value=[]) + cursor = MagicMock() + cursor.fetchall.return_value = [ + ( + 1, + None, + None, + '"00000000-0000-4000-8000-000000000001"', + 0.2, + '"synthetic knowledge"', + '"LongTermMemory"', + stored_user_id, + '["synthetic"]', + '{"test":true}', + "0.9", + "true", + 0.8, + ) + ] + connection = MagicMock() + connection.cursor.return_value.__enter__.return_value = cursor + + @contextmanager + def fake_connection(): + yield connection + + polardb_instance._get_connection = fake_connection + hits = polardb_instance.search_by_embedding( + vector=[0.1] * 1024, + user_name="knowledge-cube", + light_weight_mode=True, + return_fields=[ + "memory", + "memory_type", + "user_id", + "tags", + "info", + "confidence", + "is_fast", + ], + ) + memory = GraphMemoryRetriever._memory_item_from_vector_hit(hits[0]) + assert memory.metadata.user_id == expected_user_id + assert memory.metadata.tags == ["synthetic"] + assert memory.metadata.info == {"test": True} + assert memory.metadata.confidence == 0.9 + assert memory.metadata.is_fast is True + class TestFieldNameValidation: """Tests for _validate_return_fields injection prevention.""" From b1a7d5fee60c06923933550c9c9c0755c54e383c Mon Sep 17 00:00:00 2001 From: Wenqiang Wei <46308778+endxxxx@users.noreply.github.com> Date: Thu, 29 Oct 2026 18:40:53 +0800 Subject: [PATCH 36/38] refactor: reuse lightweight identifier field set --- src/memos/graph_dbs/polardb.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/memos/graph_dbs/polardb.py b/src/memos/graph_dbs/polardb.py index e7a8c4306..8bd9fe76d 100644 --- a/src/memos/graph_dbs/polardb.py +++ b/src/memos/graph_dbs/polardb.py @@ -20,6 +20,19 @@ logger = get_logger(__name__) +_LIGHTWEIGHT_IDENTIFIER_FIELDS = frozenset( + { + "user_id", + "user_name", + "session_id", + "mem_cube_id", + "dialog_id", + "working_binding", + "project_id", + "manager_user_id", + } +) + def _build_lightweight_return_columns(return_fields: list[str]) -> str: columns = [] @@ -38,17 +51,7 @@ def _decode_lightweight_return_value(value: Any, field: str | None = None) -> An value = value.value # Drivers may return agtype identifiers as already-decoded scalar strings. # Parsing a numeric ID again would change its type. - identifier_fields = { - "user_id", - "user_name", - "session_id", - "mem_cube_id", - "dialog_id", - "working_binding", - "project_id", - "manager_user_id", - } - if field in identifier_fields: + if field in _LIGHTWEIGHT_IDENTIFIER_FIELDS: if isinstance(value, str): try: decoded = json.loads(value) From 7f64e49d9af3e2e970104237751e96401792b615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=8D=A3=20ArchieTeriyaki?= Date: Mon, 2 Nov 2026 21:25:19 +0800 Subject: [PATCH 37/38] Update README.md - GitHub Trending Badge --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 9c85150d0..9c1d8c910 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,10 @@ Give your Agent persistent memory and the ability to grow.

+

+MemTensor%2FMemOS | Trendshift +

+

English | 中文

From 755e8eb2e08380dd2ba37835aeec8f0169139c80 Mon Sep 17 00:00:00 2001 From: Wenqiang Wei <46308778+endxxxx@users.noreply.github.com> Date: Mon, 9 Nov 2026 19:45:34 +0800 Subject: [PATCH 38/38] chore: change version number to v2.0.36 --- pyproject.toml | 2 +- src/memos/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 314fce3d5..134d380ee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ ############################################################################## name = "MemoryOS" -version = "2.0.33" +version = "2.0.36" description = "Intelligence Begins with Memory" license = {text = "Apache-2.0"} readme = "README.md" diff --git a/src/memos/__init__.py b/src/memos/__init__.py index 339107e75..d7df9f7d0 100644 --- a/src/memos/__init__.py +++ b/src/memos/__init__.py @@ -1,4 +1,4 @@ -__version__ = "2.0.33" +__version__ = "2.0.36" from memos.configs.mem_cube import GeneralMemCubeConfig from memos.configs.mem_os import MOSConfig