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
27 changes: 27 additions & 0 deletions plugin/scripts/codex-hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,37 @@ function stablePluginRootForStrayCopy(root) {
return null;
}

function cleanupStrayPluginCopy(root) {
if (!isReflexioStrayPluginCopy(root)) return;
const rootReal = realDir(root);
if (!rootReal) return;
try {
fs.rmSync(rootReal, { recursive: true, force: true });
appendLog("backend.log", `[claude-smart] removed stray plugin copy under ~/.reflexio (${rootReal})`);
} catch (err) {
appendLog("backend.log", `[claude-smart] failed to remove stray plugin copy ${rootReal}: ${err && err.message ? err.message : err}`);
return;
}

// Remove now-empty host-created wrapper folders (for example
// ~/.reflexio/CUsersAliceRepo/) without touching real Reflexio state dirs.
let parent = path.dirname(rootReal);
const reflexioReal = realDir(REFLEXIO_DIR);
while (reflexioReal && isInsideDir(reflexioReal, parent)) {
try {
fs.rmdirSync(parent);
} catch {
break;
}
parent = path.dirname(parent);
}
}

function stablePluginRoot(root) {
const stable = stablePluginRootForStrayCopy(root);
if (stable) {
appendLog("backend.log", `[claude-smart] redirecting stray plugin copy under ~/.reflexio (${root}) to stable root ${stable}`);
cleanupStrayPluginCopy(root);
return stable;
}
return root;
Expand Down
3 changes: 2 additions & 1 deletion tests/test_install_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2579,7 +2579,8 @@ def test_codex_hook_redirects_reflexio_stray_copy_to_stable_root(
assert (reflexio / "plugin-root").resolve() == stable_root
assert json.loads(result.stdout) == {"continue": True}
assert not (reflexio / "plugin-root").resolve() == stray_root
assert "redirecting stray plugin copy" in (
assert not stray_root.exists()
assert "removed stray plugin copy" in (
tmp_path / ".claude-smart" / "backend.log"
).read_text()

Expand Down
Loading