Skip to content

#1 Persistent memory for AI coding agents based on real-world benchmarks

fix(runtime): make dist actually start — drop getContext, externalize onnx, restore KV.state

Rohit Ghumarea12767bac77b
diff --git a/package-lock.json b/package-lock.json
index 887b5fb1..3628c79d 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -13,7 +13,7 @@
"@anthropic-ai/sdk": "^0.39.0",
"@clack/prompts": "^1.2.0",
"dotenv": "^16.4.7",
- "iii-sdk": "^0.11.0",
+ "iii-sdk": "^0.11.2",
"zod": "^4.0.0"
},
"bin": {
@@ -3082,9 +3082,9 @@
"optional": true
},
"node_modules/iii-sdk": {
- "version": "0.11.0",
- "resolved": "https://registry.npmjs.org/iii-sdk/-/iii-sdk-0.11.0.tgz",
- "integrity": "sha512-/eY0Fo5HA9fLSD8PrGMNVgRYNk0TRuqKMFD8sdOsySp5+z6Sd3xh33BjuvlzEJUlwp3+jClxr02wL/Tfr+QscQ==",
+ "version": "0.11.2",
+ "resolved": "https://registry.npmjs.org/iii-sdk/-/iii-sdk-0.11.2.tgz",
+ "integrity": "sha512-S8/o53j1z+IOU6Mp1f3GbivJ59hEgWhtT6hNutVpfwhJK5Q9zS2rV2LUX1Ko6+xF/Zr3Y6xodNRmBRng0qiZZA==",
"license": "Apache-2.0",
"dependencies": {
"@opentelemetry/api": "^1.9.0",
diff --git a/package.json b/package.json
index 2dd41fc6..dedb13ed 100644
--- a/package.json
+++ b/package.json
@@ -58,7 +58,7 @@
"@anthropic-ai/sdk": "^0.39.0",
"@clack/prompts": "^1.2.0",
"dotenv": "^16.4.7",
- "iii-sdk": "^0.11.0",
+ "iii-sdk": "^0.11.2",
"zod": "^4.0.0"
},
"optionalDependencies": {
diff --git a/src/functions/compress.ts b/src/functions/compress.ts
index 19a144cd..ed1de787 100644
--- a/src/functions/compress.ts
+++ b/src/functions/compress.ts
@@ -1,4 +1,4 @@
-import { TriggerAction, type ISdk, getContext } from "iii-sdk";
+import { TriggerAction, type ISdk } from "iii-sdk";
import { readFileSync } from "node:fs";
import { isManagedImagePath } from "../utils/image-store.js";
import type {
diff --git a/src/functions/disk-size-manager.ts b/src/functions/disk-size-manager.ts
index 957866dd..a3329dba 100644
--- a/src/functions/disk-size-manager.ts
+++ b/src/functions/disk-size-manager.ts
@@ -1,21 +1,16 @@
import type { ISdk } from "iii-sdk";
-import { getContext } from "iii-sdk";
import { KV } from "../state/schema.js";
import { StateKV } from "../state/kv.js";
import { getMaxBytes } from "../utils/image-store.js";
import { withKeyedLock } from "../state/keyed-mutex.js";
+import { logger } from "../logger.js";
const DISK_SIZE_KEY = "system:currentDiskSize";
export function registerDiskSizeManager(sdk: ISdk, kv: StateKV): void {
sdk.registerFunction(
- {
- id: "mem::disk-size-delta",
- description: "Sequential single-writer manager for disk size tracking",
- },
+ "mem::disk-size-delta",
async (data: { deltaBytes: number }) => {
- const ctx = getContext();
-
if (typeof data?.deltaBytes !== "number" || !isFinite(data.deltaBytes)) {
return { success: false, error: "deltaBytes must be a finite number" };
}
@@ -30,7 +25,7 @@ export function registerDiskSizeManager(sdk: ISdk, kv: StateKV): void {
if (data.deltaBytes > 0 && newTotal > getMaxBytes()) {
sdk.triggerVoid("mem::image-quota-cleanup", {});
- ctx.logger.info("[agentmemory] Disk quota exceeded, cleanup triggered", {
+ logger.info("Disk quota exceeded, cleanup triggered", {
currentBytes: newTotal,
maxBytes: getMaxBytes(),
});
diff --git a/src/functions/image-quota-cleanup.ts b/src/functions/image-quota-cleanup.ts
index 545208ea..1a2e39a4 100644
--- a/src/functions/image-quota-cleanup.ts
+++ b/src/functions/image-quota-cleanup.ts
@@ -1,5 +1,4 @@
import type { ISdk } from "iii-sdk";
-import { getContext } from "iii-sdk";
import { KV } from "../state/schema.js";
import { StateKV } from "../state/kv.js";
import { readdir, stat } from "node:fs/promises";
@@ -7,17 +6,14 @@ import { join } from "node:path";
import { IMAGES_DIR, getMaxBytes, deleteImage } from "../utils/image-store.js";
import { getImageRefCount } from "./image-refs.js";
import { withKeyedLock } from "../state/keyed-mutex.js";
+import { logger } from "../logger.js";
const GRACE_PERIOD_MS = 30_000;
export function registerImageQuotaCleanup(sdk: ISdk, kv: StateKV): void {
sdk.registerFunction(
- {
- id: "mem::image-quota-cleanup",
- description: "Background LRU cleanup of image store when disk quota is exceeded",
- },
+ "mem::image-quota-cleanup",
async () => {
- const ctx = getContext();
const now = Date.now();
return withKeyedLock("system:cleanupLock", async () => {
@@ -62,7 +58,7 @@ export function registerImageQuotaCleanup(sdk: ISdk, kv: StateKV): void {
try {
refCount = await getImageRefCount(kv, f.filePath);
} catch (err) {
- ctx.logger.error(`[agentmemory] Failed to read refCount for ${f.filePath}:`, err);
+ logger.error("Failed to read refCount", { filePath: f.filePath, error: err instanceof Error ? err.message : String(err) });
}
if (refCount > 0) {
@@ -81,7 +77,7 @@ export function registerImageQuotaCleanup(sdk: ISdk, kv: StateKV): void {
if (evicted > 0) {
const freedMb = (freedBytes / (1024 * 1024)).toFixed(1);
- ctx.logger.info("[agentmemory] Image quota cleanup complete", { evicted, freedMb });
+ logger.info("Image quota cleanup complete", { evicted, freedMb });
}
return { success: true, evicted, freedBytes };
diff --git a/src/state/schema.ts b/src/state/schema.ts
index 33d2ccfe..27f1958d 100644
--- a/src/state/schema.ts
+++ b/src/state/schema.ts
@@ -45,6 +45,7 @@ export const KV = {
imageEmbeddings: "mem:image-embeddings",
slots: "mem:slots",
globalSlots: "mem:slots:global",
+ state: "mem:state",
} as const;
export const STREAM = {
diff --git a/test/multimodal.test.ts b/test/multimodal.test.ts
index de694636..ffadd120 100644
--- a/test/multimodal.test.ts
+++ b/test/multimodal.test.ts
@@ -173,8 +173,8 @@ describe("Disk Size Manager", () => {
let managerCallback: any = null;
const sdkMocker = {
...localSdk,
- registerFunction: vi.fn((config: any, cb: any) => {
- if (config.id === "mem::disk-size-delta") managerCallback = cb;
+ registerFunction: vi.fn((id: string, cb: any) => {
+ if (id === "mem::disk-size-delta") managerCallback = cb;
}),
};
@@ -206,8 +206,8 @@ describe("Disk Size Manager", () => {
let managerCallback: any = null;
const sdkMocker = {
...localSdk,
- registerFunction: vi.fn((config: any, cb: any) => {
- if (config.id === "mem::disk-size-delta") managerCallback = cb;
+ registerFunction: vi.fn((id: string, cb: any) => {
+ if (id === "mem::disk-size-delta") managerCallback = cb;
}),
};
@@ -235,8 +235,8 @@ describe("Disk Size Manager", () => {
let managerCallback: any = null;
const sdkMocker = {
...localSdk,
- registerFunction: vi.fn((config: any, cb: any) => {
- if (config.id === "mem::disk-size-delta") managerCallback = cb;
+ registerFunction: vi.fn((id: string, cb: any) => {
+ if (id === "mem::disk-size-delta") managerCallback = cb;
}),
};
@@ -254,8 +254,8 @@ describe("Disk Size Manager", () => {
let managerCallback: any = null;
const sdkMocker = {
...localSdk,
- registerFunction: vi.fn((config: any, cb: any) => {
- if (config.id === "mem::disk-size-delta") managerCallback = cb;
+ registerFunction: vi.fn((id: string, cb: any) => {
+ if (id === "mem::disk-size-delta") managerCallback = cb;
}),
};
diff --git a/tsdown.config.ts b/tsdown.config.ts
index 9ffa3c5c..0e7f97e1 100644
--- a/tsdown.config.ts
+++ b/tsdown.config.ts
@@ -19,6 +19,16 @@ const shared = {
format: ["esm"] as const,
target: "node20" as const,
inlineOnly: false as const,
+ // Keep as node_modules imports. Bundling inlines relative paths like
+ // `../bin/napi-v3/darwin/arm64/onnxruntime_binding.node` that no longer
+ // resolve from dist/. CLIP + local embeddings lazy-load these anyway.
+ external: [
+ "@xenova/transformers",
+ "onnxruntime-node",
+ "onnxruntime-web",
+ "@anthropic-ai/claude-agent-sdk",
+ "@anthropic-ai/sdk",
+ ] as const,
};
export default defineConfig([