Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,20 @@ The repository hash comes from the normalized Git `origin` remote, so Claude Cod
Codex, Cursor, and OpenCode use the same container for the same repository.
Repositories with the same name but different remotes remain isolated. Without an
origin remote, OpenCode falls back to the repository's real filesystem path.
Relative local Git origins are resolved against the repository directory, not
the directory where OpenCode was launched.

If a relative local origin previously produced a launch-directory-dependent tag,
its corrected tag will differ. Memories in that old container are not automatically
read or migrated: unrelated repositories may have shared the incorrect tag. To
keep a known existing container, explicitly configure `projectContainerTag` only
after verifying that the container belongs to this project.

OpenCode also reads previous `user_project_*`, `repo_<project-name>`,
`claudecode_project_*`, `codex_user_*`, `codex_project_*`, `opencode_user_*`,
`opencode_project_*`, `cursor_user_*`, and `cursor_project_*` containers, so upgrading
does not require a migration.
`opencode_project_*`, `cursor_user_*`, and `cursor_project_*` containers. Those
legacy containers remain readable without migration; this does not include the
incorrect relative-origin containers described above.

## Configuration

Expand Down
61 changes: 60 additions & 1 deletion src/services/tags.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { describe, expect, test } from "bun:test";
import { normalizeGitRemote, sanitizeRepoName } from "./tags.js";
import { execFileSync } from "node:child_process";
import { mkdtempSync, mkdirSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import {
getGeneratedProjectTag,
getProjectIdentity,
normalizeGitRemote,
sanitizeRepoName,
} from "./tags.js";

describe("repository identity", () => {
test("normalizes equivalent HTTPS and SSH remotes", () => {
Expand All @@ -17,3 +26,53 @@ describe("repository identity", () => {
);
});
});

describe("local Git origin identity", () => {
function repository(path: string, origin: string): void {
mkdirSync(path, { recursive: true });
execFileSync("git", ["init", "--quiet", path]);
execFileSync("git", ["-C", path, "remote", "add", "origin", origin]);
// Git itself must resolve the configured origin successfully.
execFileSync("git", ["-C", path, "ls-remote", "origin"]);
}

test("relative and absolute origins for the same repository share identity", () => {
const root = mkdtempSync(join(tmpdir(), "supermemory-local-origin-"));
try {
const upstream = join(root, "upstream.git");
execFileSync("git", ["init", "--bare", "--quiet", upstream]);
const relative = join(root, "relative");
const absolute = join(root, "absolute");
repository(relative, "../upstream.git");
repository(absolute, upstream);
expect(getProjectIdentity(relative)).toBe(getProjectIdentity(absolute));
expect(getGeneratedProjectTag(relative)).toBe(
getGeneratedProjectTag(absolute),
);
} finally {
rmSync(root, { recursive: true, force: true });
}
});

test("identical relative origin strings in different roots stay isolated", () => {
const root = mkdtempSync(join(tmpdir(), "supermemory-local-origin-"));
try {
const projects = ["first", "second"].map((name) => {
const parent = join(root, name);
mkdirSync(parent);
execFileSync("git", ["init", "--bare", "--quiet", join(parent, "upstream.git")]);
const project = join(parent, "project");
repository(project, "../upstream.git");
return project;
});
expect(getProjectIdentity(projects[0]!)).not.toBe(
getProjectIdentity(projects[1]!),
);
expect(getGeneratedProjectTag(projects[0]!)).not.toBe(
getGeneratedProjectTag(projects[1]!),
);
} finally {
rmSync(root, { recursive: true, force: true });
}
});
});
9 changes: 6 additions & 3 deletions src/services/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ function getGitEmail(directory: string): string | null {
}
}

export function normalizeGitRemote(remoteUrl: string): string | null {
export function normalizeGitRemote(
remoteUrl: string,
directory: string = process.cwd(),
): string | null {
const raw = remoteUrl.trim();
if (!raw) return null;

Expand All @@ -102,7 +105,7 @@ export function normalizeGitRemote(remoteUrl: string): string | null {
normalized =
scpStyle?.[1] && scpStyle[2]
? `${scpStyle[1].toLowerCase()}/${scpStyle[2]}`
: `file:${resolve(raw)}`;
: `file:${resolve(directory, raw)}`;
}

return normalized
Expand All @@ -127,7 +130,7 @@ function getGitRepoInfo(directory: string): {
stdio: ["pipe", "pipe", "pipe"],
windowsHide: true,
}).trim();
const normalizedRemote = normalizeGitRemote(remoteUrl);
const normalizedRemote = normalizeGitRemote(remoteUrl, directory);
const displayRemote = remoteUrl.replace(/\/+$/, "").replace(/\.git$/i, "");
const separator = Math.max(
displayRemote.lastIndexOf("/"),
Expand Down