Skip to content
Merged
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
12 changes: 6 additions & 6 deletions plugin/scripts/add-memory.cjs

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions plugin/scripts/context-hook.cjs

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions plugin/scripts/save-project-memory.cjs

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions plugin/scripts/search-memory.cjs

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions plugin/scripts/summary-hook.cjs

Large diffs are not rendered by default.

14 changes: 1 addition & 13 deletions src/lib/container-tag.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
const { execSync } = require('node:child_process');
const crypto = require('node:crypto');
const { loadProjectConfig } = require('./project-config');
const { getGitRoot } = require('./git-utils');

function sha256(input) {
return crypto.createHash('sha256').update(input).digest('hex').slice(0, 16);
}

function getGitRoot(cwd) {
try {
const gitRoot = execSync('git rev-parse --show-toplevel', {
cwd,
encoding: 'utf-8',
stdio: ['pipe', 'pipe', 'pipe'],
}).trim();
return gitRoot || null;
} catch {
return null;
}
}

function getGitRepoName(cwd) {
try {
const remoteUrl = execSync('git remote get-url origin', {
Comment on lines 2 to 12
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The use of basePath.split('/') in src/lib/container-tag.js is not cross-platform compatible and will fail to correctly parse directory names from paths on Windows systems.
Severity: MEDIUM

Suggested Fix

Import the path module in src/lib/container-tag.js and replace basePath.split('/').pop() with path.basename(basePath) to ensure cross-platform compatibility for path manipulation.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/lib/container-tag.js#L1-L12

Potential issue: In `src/lib/container-tag.js`, the repository name is determined using
`basePath.split('/').pop()` as a fallback. On Windows, where path separators are
backslashes (`\`), this method fails. For a path like `C:\Users\user\my-repo`,
`split('/')` returns the entire string, causing the full path to be used as the
repository name. This results in malformed container tags (e.g.,
`repo_c_users_user_my_repo`) for Windows users when a git remote is not configured,
leading to inconsistent tag generation across platforms and potential validation
failures.

Did we get this right? 👍 / 👎 to inform future reviews.

Expand Down
52 changes: 52 additions & 0 deletions src/lib/git-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const { execSync } = require('node:child_process');
const path = require('node:path');

function getGitRoot(cwd) {
const isolateWorktrees = process.env.SUPERMEMORY_ISOLATE_WORKTREES === 'true';

try {
if (isolateWorktrees) {
const gitRoot = execSync('git rev-parse --show-toplevel', {
cwd,
Comment on lines +1 to +10
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The default behavior for Git worktree handling in getGitRoot has changed, causing worktrees to share a root directory instead of being isolated. This is an undocumented breaking change.
Severity: MEDIUM

Suggested Fix

To maintain backward compatibility, the default behavior should be to isolate worktrees. The logic should be inverted so that worktree isolation is the default, and using --git-common-dir becomes the opt-in behavior, possibly controlled by a differently named environment variable.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/lib/git-utils.js#L1-L10

Potential issue: The refactored `getGitRoot` function in `src/lib/git-utils.js` changes
the default behavior for Git worktrees. Previously, each worktree was treated as an
isolated root. The new code defaults to using `--git-common-dir`, which resolves all
worktrees to the main repository's root. This undocumented breaking change means users
will have their worktree memories merged by default, losing the previous isolation. To
restore the old behavior, users must opt-in by setting the
`SUPERMEMORY_ISOLATE_WORKTREES` environment variable to 'true', which they would not
know to do.

Did we get this right? 👍 / 👎 to inform future reviews.

encoding: 'utf-8',
stdio: ['pipe', 'pipe', 'pipe'],
}).trim();
return gitRoot || null;
}

const gitCommonDir = execSync('git rev-parse --git-common-dir', {
cwd,
encoding: 'utf-8',
stdio: ['pipe', 'pipe', 'pipe'],
}).trim();

if (gitCommonDir === '.git') {
const gitRoot = execSync('git rev-parse --show-toplevel', {
cwd,
encoding: 'utf-8',
stdio: ['pipe', 'pipe', 'pipe'],
}).trim();
return gitRoot || null;
}

const resolved = path.resolve(cwd, gitCommonDir);

if (
path.basename(resolved) === '.git' &&
!resolved.includes(`${path.sep}.git${path.sep}`)
) {
return path.dirname(resolved);
}

const gitRoot = execSync('git rev-parse --show-toplevel', {
cwd,
encoding: 'utf-8',
stdio: ['pipe', 'pipe', 'pipe'],
}).trim();
return gitRoot || null;
} catch {
return null;
}
}

module.exports = { getGitRoot };
15 changes: 1 addition & 14 deletions src/lib/project-config.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
const fs = require('node:fs');
const path = require('node:path');
const { execSync } = require('node:child_process');
const { getGitRoot } = require('./git-utils');

const CONFIG_DIR = path.join('.claude', '.supermemory-claude');
const CONFIG_FILE = 'config.json';

function getGitRoot(cwd) {
try {
const gitRoot = execSync('git rev-parse --show-toplevel', {
cwd,
encoding: 'utf-8',
stdio: ['pipe', 'pipe', 'pipe'],
}).trim();
return gitRoot || null;
} catch {
return null;
}
}

function getConfigPath(cwd) {
const gitRoot = getGitRoot(cwd);
const basePath = gitRoot || cwd;
Expand Down