#1 Persistent memory for AI coding agents based on real-world benchmarks
TypeScript agentmemoryagentsaiclaudeclaudecodecodexcopilotcursorgenaiharnesshermesmemoryompopenclawopencodepi
fix(tier1): install ERESOLVE + non-OpenAI base URL + bridge path (#649)
Rohit Ghumare66e099697f67
diff --git a/package.json b/package.jsonindex bc245a2f..bd92a70b 100644--- a/package.json+++ b/package.json@@ -59,7 +59,7 @@},"dependencies": {"@anthropic-ai/claude-agent-sdk": "^0.3.142",- "@anthropic-ai/sdk": "^0.39.0",+ "@anthropic-ai/sdk": "^0.93.0","@clack/prompts": "^1.2.0","dotenv": "^17.4.2","iii-sdk": "0.11.2",diff --git a/src/config.ts b/src/config.tsindex eed5725e..004e7d0f 100644--- a/src/config.ts+++ b/src/config.ts@@ -216,13 +216,19 @@ export function loadClaudeBridgeConfig(): ClaudeBridgeConfig {const lineBudget = safeParseInt(env["CLAUDE_MEMORY_LINE_BUDGET"], 200);let memoryFilePath = "";if (enabled && projectPath) {- const safePath = projectPath.replace(/[/\\]/g, "-").replace(/^-/, "");+ // #625: Claude Code stores MEMORY.md at+ // ~/.claude/projects/<slug>/MEMORY.md+ // where <slug> is the project path with `/` and `\` swapped for `-`.+ // The leading `-` from an absolute POSIX path is preserved (Claude+ // Code keeps it; stripping it produced a slug Claude never reads).+ // There's also no `memory/` subdirectory — the file sits directly+ // under the slug dir.+ const safePath = projectPath.replace(/[/\\]/g, "-");memoryFilePath = join(homedir(),".claude","projects",safePath,- "memory","MEMORY.md",);}diff --git a/src/providers/_openai-shared.ts b/src/providers/_openai-shared.tsindex b35cca99..09566b1a 100644--- a/src/providers/_openai-shared.ts+++ b/src/providers/_openai-shared.ts@@ -87,6 +87,34 @@ function v1AzureUrl(baseUrl: string, path: string): string {return url.toString();}+// Append an OpenAI-compatible route to the base URL without producing+// a doubled version segment. Three cases:+//+// 1. Empty path (just a hostname) — OpenAI default: prepend `/v1/`.+// https://api.openai.com → https://api.openai.com/v1/chat/completions+// 2. Path already ends with `/v1` — provider-documented base, treat+// it as the version anchor and append the route directly.+// https://api.deepseek.com/v1 → https://api.deepseek.com/v1/chat/completions+// (without this, we'd produce /v1/v1/chat/completions and 404. #628)+// 3. Path ends with any other versioned or path segment — provider+// uses a non-OpenAI version scheme (Zhipu /api/paas/v4, others) —+// append the route directly, no `/v1/` injected.+// https://open.bigmodel.cn/api/paas/v4 → .../v4/chat/completions (#646)+function appendOpenAIRoute(baseUrl: string, route: string): string {+ const trimmedBase = baseUrl.replace(/\/+$/, "");+ const cleanRoute = route.startsWith("/") ? route : `/${route}`;+ let pathname: string;+ try {+ pathname = new URL(trimmedBase).pathname.replace(/\/+$/, "");+ } catch {+ return `${trimmedBase}/v1${cleanRoute}`;+ }+ if (pathname === "" || pathname === "/") {+ return `${trimmedBase}/v1${cleanRoute}`;+ }+ return `${trimmedBase}${cleanRoute}`;+}+export function buildChatUrl(baseUrl: string,isAzure: boolean,@@ -97,7 +125,7 @@ export function buildChatUrl(? legacyAzureUrl(baseUrl, "/chat/completions", azureApiVersion): v1AzureUrl(baseUrl, "/chat/completions");}- return `${baseUrl}/v1/chat/completions`;+ return appendOpenAIRoute(baseUrl, "/chat/completions");}export function buildEmbeddingUrl(@@ -110,7 +138,7 @@ export function buildEmbeddingUrl(? legacyAzureUrl(baseUrl, "/embeddings", azureApiVersion): v1AzureUrl(baseUrl, "/embeddings");}- return `${baseUrl}/v1/embeddings`;+ return appendOpenAIRoute(baseUrl, "/embeddings");}// Azure key-auth uses `api-key: <KEY>`; standard OpenAI-compatiblediff --git a/test/claude-bridge-path.test.ts b/test/claude-bridge-path.test.tsnew file mode 100644index 00000000..c1e1f101--- /dev/null+++ b/test/claude-bridge-path.test.ts@@ -0,0 +1,58 @@+import { describe, it, expect, beforeEach, afterEach } from "vitest";+import { homedir } from "node:os";+import { join } from "node:path";+import { loadClaudeBridgeConfig } from "../src/config.js";++// #625: bridge path must match Claude Code's slug convention exactly:+// ~/.claude/projects/<slug>/MEMORY.md+// where <slug> replaces every / and \ with - and KEEPS any leading -.+// The previous code stripped the leading - and added a /memory/+// subdirectory; the bridge then wrote a file Claude Code never read.+describe("loadClaudeBridgeConfig path (#625)", () => {+ const ORIG_ENV = { ...process.env };+ beforeEach(() => {+ delete process.env["CLAUDE_MEMORY_BRIDGE"];+ delete process.env["CLAUDE_PROJECT_PATH"];+ delete process.env["CLAUDE_MEMORY_LINE_BUDGET"];+ });+ afterEach(() => {+ process.env = { ...ORIG_ENV };+ });++ it("preserves leading - on POSIX absolute paths", () => {+ process.env["CLAUDE_MEMORY_BRIDGE"] = "true";+ process.env["CLAUDE_PROJECT_PATH"] = "/home/user/repos/my-project";+ const cfg = loadClaudeBridgeConfig();+ expect(cfg.memoryFilePath).toBe(+ join(homedir(), ".claude", "projects", "-home-user-repos-my-project", "MEMORY.md"),+ );+ });++ it("writes MEMORY.md directly under the slug dir, no memory/ subdir", () => {+ process.env["CLAUDE_MEMORY_BRIDGE"] = "true";+ process.env["CLAUDE_PROJECT_PATH"] = "/Users/x/agentmemory";+ const cfg = loadClaudeBridgeConfig();+ expect(cfg.memoryFilePath).not.toMatch(/[/\\]memory[/\\]MEMORY\.md$/);+ expect(cfg.memoryFilePath).toMatch(/-Users-x-agentmemory[/\\]MEMORY\.md$/);+ });++ it("returns empty memoryFilePath when bridge disabled", () => {+ const cfg = loadClaudeBridgeConfig();+ expect(cfg.enabled).toBe(false);+ expect(cfg.memoryFilePath).toBe("");+ });++ it("returns empty memoryFilePath when project path unset", () => {+ process.env["CLAUDE_MEMORY_BRIDGE"] = "true";+ const cfg = loadClaudeBridgeConfig();+ expect(cfg.enabled).toBe(true);+ expect(cfg.memoryFilePath).toBe("");+ });++ it("handles Windows-style backslash paths by swapping to -", () => {+ process.env["CLAUDE_MEMORY_BRIDGE"] = "true";+ process.env["CLAUDE_PROJECT_PATH"] = "C:\\Users\\x\\project";+ const cfg = loadClaudeBridgeConfig();+ expect(cfg.memoryFilePath).toMatch(/C:-Users-x-project[/\\]MEMORY\.md$/);+ });+});diff --git a/test/openai-shared.test.ts b/test/openai-shared.test.tsindex 7240e10c..e3714c63 100644--- a/test/openai-shared.test.ts+++ b/test/openai-shared.test.ts@@ -150,6 +150,49 @@ describe("_openai-shared — buildEmbeddingUrl", () => {});});+describe("_openai-shared — non-OpenAI base URLs (#628, #646)", () => {+ it("does not double /v1 when base URL already ends with /v1 (DeepSeek shape, #628)", () => {+ expect(+ buildChatUrl("https://api.deepseek.com/v1", false, "2024-08-01-preview"),+ ).toBe("https://api.deepseek.com/v1/chat/completions");+ expect(+ buildEmbeddingUrl("https://api.deepseek.com/v1", false, "2024-08-01-preview"),+ ).toBe("https://api.deepseek.com/v1/embeddings");+ });++ it("does not inject /v1 when provider uses non-OpenAI version segment (Zhipu /api/paas/v4, #646)", () => {+ expect(+ buildChatUrl(+ "https://open.bigmodel.cn/api/paas/v4",+ false,+ "2024-08-01-preview",+ ),+ ).toBe("https://open.bigmodel.cn/api/paas/v4/chat/completions");+ expect(+ buildEmbeddingUrl(+ "https://open.bigmodel.cn/api/paas/v4",+ false,+ "2024-08-01-preview",+ ),+ ).toBe("https://open.bigmodel.cn/api/paas/v4/embeddings");+ });++ it("tolerates trailing slash on already-versioned base", () => {+ expect(+ buildChatUrl("https://api.deepseek.com/v1/", false, "2024-08-01-preview"),+ ).toBe("https://api.deepseek.com/v1/chat/completions");+ });++ it("handles localhost OpenAI-compatible servers with explicit /v1", () => {+ expect(+ buildChatUrl("http://localhost:11434/v1", false, "2024-08-01-preview"),+ ).toBe("http://localhost:11434/v1/chat/completions");+ expect(+ buildChatUrl("http://localhost:8000/v1", false, "2024-08-01-preview"),+ ).toBe("http://localhost:8000/v1/chat/completions");+ });+});+describe("_openai-shared — buildAuthHeaders", () => {it("emits Authorization: Bearer for standard OpenAI", () => {expect(buildAuthHeaders("sk-test", false)).toEqual({