Skip to content

Commit 3d87d79

Browse files
committed
feat: use git remote URL for cross-machine project memory sync
Resolves #38 Problem: - Project memories use directory path hash as identifier - Different machines have different paths for the same project - Result: project memories don't sync across machines - Setting projectContainerTag affects ALL projects (memory pollution) Solution: - Use git remote origin URL as primary project identifier - Same git remote = same project tag across all machines - Fallback to directory hash if no git remote Benefits: - Transparent: works without user configuration - Automatic sync for same repository across machines - Automatic isolation for different repositories - Backward compatible: falls back to existing behavior
1 parent 3aa09ef commit 3d87d79

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

src/services/tags.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@ export function getGitEmail(): string | null {
1515
}
1616
}
1717

18+
/**
19+
* Get the git remote URL for the given directory.
20+
* This provides a stable, cross-machine identifier for projects.
21+
* Returns null if not in a git repo or no remote configured.
22+
*/
23+
export function getGitRemoteUrl(directory: string): string | null {
24+
try {
25+
const remoteUrl = execSync("git config --get remote.origin.url", {
26+
cwd: directory,
27+
encoding: "utf-8",
28+
stdio: ["pipe", "pipe", "pipe"],
29+
}).trim();
30+
return remoteUrl || null;
31+
} catch {
32+
return null;
33+
}
34+
}
35+
1836
export function getUserTag(): string {
1937
// If userContainerTag is explicitly set, use it
2038
if (CONFIG.userContainerTag) {
@@ -36,7 +54,14 @@ export function getProjectTag(directory: string): string {
3654
return CONFIG.projectContainerTag;
3755
}
3856

39-
// Otherwise, auto-generate based on containerTagPrefix
57+
// Try to use git remote URL as a stable cross-machine project identifier
58+
// This allows the same project on different machines to share memories
59+
const remoteUrl = getGitRemoteUrl(directory);
60+
if (remoteUrl) {
61+
return `${CONFIG.containerTagPrefix}_project_${sha256(remoteUrl)}`;
62+
}
63+
64+
// Fall back to directory path hash (machine-specific)
4065
return `${CONFIG.containerTagPrefix}_project_${sha256(directory)}`;
4166
}
4267

@@ -45,4 +70,4 @@ export function getTags(directory: string): { user: string; project: string } {
4570
user: getUserTag(),
4671
project: getProjectTag(directory),
4772
};
48-
}
73+
}

0 commit comments

Comments
 (0)