Skip to content

armgit / ECC

Public Imported from GitHub
0

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

fix(scripts): require legacy ownership manifest for auto fallback

Santhi Prakash56dafcc5e36a
diff --git a/scripts/lib/codex-legacy-sync.js b/scripts/lib/codex-legacy-sync.js
index e12a69aec..2afa26b00 100644
--- a/scripts/lib/codex-legacy-sync.js
+++ b/scripts/lib/codex-legacy-sync.js
@@ -489,8 +489,17 @@ function hasMarkerBlock(codexHome) {
return false;
}
+function resolveCodexHome(codexHome) {
+ return path.resolve(codexHome || process.env.CODEX_HOME || path.join(process.env.HOME || os.homedir(), '.codex'));
+}
+
+function legacyCodexSyncStateExists(codexHome) {
+ const resolvedCodexHome = resolveCodexHome(codexHome);
+ return readStateIfPresent(getStatePath(resolvedCodexHome)) !== null;
+}
+
function detectLegacyCodexSync(codexHome) {
- const resolvedCodexHome = path.resolve(codexHome || process.env.CODEX_HOME || path.join(process.env.HOME || os.homedir(), '.codex'));
+ const resolvedCodexHome = resolveCodexHome(codexHome);
if (readStateIfPresent(getStatePath(resolvedCodexHome))) return true;
return hasMarkerBlock(resolvedCodexHome);
}
@@ -514,7 +523,10 @@ function uninstallLegacyCodexSync(options = {}) {
const stripped = stripMarkerBlock(content);
if (stripped !== content) {
plannedRemovals.push(`${agentsPath}#ecc-marker-block`);
- if (!dryRun) replaceOpenedRegularFile(openedAgents, stripped, openedAgents.stat.mode & 0o777);
+ if (!dryRun) {
+ replaceOpenedRegularFile(openedAgents, stripped, openedAgents.stat.mode & 0o777);
+ removedPaths.push(agentsPath);
+ }
}
}
} catch (_error) {
@@ -621,6 +633,7 @@ module.exports = {
detectLegacyCodexSync,
finalizeLegacySyncState,
getStatePath,
+ legacyCodexSyncStateExists,
recordLegacySyncPath,
rollbackLegacyCodexSync,
stripMarkerBlock,
diff --git a/scripts/uninstall.js b/scripts/uninstall.js
index eaba93c68..49df98d61 100644
--- a/scripts/uninstall.js
+++ b/scripts/uninstall.js
@@ -6,7 +6,7 @@ const { uninstallInstalledStates } = require('./lib/install-lifecycle');
const { SUPPORTED_INSTALL_TARGETS } = require('./lib/install-manifests');
const { exitFeedbackLines } = require('./lib/feedback-links');
const {
- detectLegacyCodexSync,
+ legacyCodexSyncStateExists,
uninstallLegacyCodexSync,
} = require('./lib/codex-legacy-sync');
@@ -16,8 +16,9 @@ Usage: node scripts/uninstall.js [--target <${SUPPORTED_INSTALL_TARGETS.join('|'
Remove ECC-managed files recorded in install-state for the current context.
When no install-state is found, the uninstaller also detects and removes
-artifacts left by the older scripts/sync-ecc-to-codex.sh installer.
-Use --legacy-codex-sync to force the legacy path explicitly.
+legacy sync-ecc-to-codex.sh artifacts, but only when a legacy ownership
+manifest is present. Use --legacy-codex-sync to force the legacy path
+explicitly, including marker-only AGENTS.md cleanup.
`);
process.exit(exitCode);
}
@@ -93,8 +94,8 @@ function printHuman(result) {
}
}
-function legacyCodexSyncDetected(codexHome) {
- return detectLegacyCodexSync(codexHome);
+function legacyCodexSyncStateDetected(codexHome) {
+ return legacyCodexSyncStateExists(codexHome);
}
function printLegacy(result, dryRun) {
@@ -148,7 +149,7 @@ async function main() {
if (
result.results.length === 0
&& includesCodexTarget(options.targets)
- && legacyCodexSyncDetected(codexHomePath())
+ && legacyCodexSyncStateDetected(codexHomePath())
) {
result = uninstallLegacyCodexSync({
codexHome: codexHomePath(),
diff --git a/tests/scripts/uninstall.test.js b/tests/scripts/uninstall.test.js
index b42c6c2f2..1a1687f00 100644
--- a/tests/scripts/uninstall.test.js
+++ b/tests/scripts/uninstall.test.js
@@ -44,15 +44,9 @@ function writeState(filePath, options) {
}
function run(args = [], options = {}) {
- const env = {
- ...process.env,
- HOME: options.homeDir || process.env.HOME,
- };
- if (options.homeDir) {
- env.CODEX_HOME = path.join(options.homeDir, '.codex');
- } else {
- delete env.CODEX_HOME;
- }
+ const env = options.homeDir
+ ? { ...process.env, HOME: options.homeDir, CODEX_HOME: path.join(options.homeDir, '.codex') }
+ : Object.fromEntries(Object.entries(process.env).filter(([key]) => key !== 'CODEX_HOME'))
try {
const stdout = execFileSync('node', [SCRIPT, ...args], {
@@ -468,6 +462,63 @@ function runTests() {
}
})) passed++; else failed++;
+ if (test('does not auto-fallback to a marker-only AGENTS.md without a legacy ownership manifest', () => {
+ const homeDir = createTempDir('uninstall-marker-only-codex-home-');
+ const projectRoot = createTempDir('uninstall-marker-only-codex-project-');
+
+ try {
+ const codexHome = path.join(homeDir, '.codex');
+ const configPath = path.join(codexHome, 'config.toml');
+ const agentsPath = path.join(codexHome, 'AGENTS.md');
+ const conversationPath = path.join(codexHome, 'conversations', 'keep-me.md');
+
+ fs.mkdirSync(codexHome, { recursive: true });
+ fs.writeFileSync(configPath, 'model = "user"\n');
+ fs.writeFileSync(
+ agentsPath,
+ '# User instructions\n\n<!-- BEGIN ECC -->\n# ECC managed\n<!-- END ECC -->\n'
+ );
+ fs.mkdirSync(path.dirname(conversationPath), { recursive: true });
+ fs.writeFileSync(conversationPath, 'conversation history');
+
+ const uninstallResult = run([], { cwd: projectRoot, homeDir });
+ assert.strictEqual(uninstallResult.code, 0, uninstallResult.stderr);
+ assert.ok(uninstallResult.stdout.includes('No ECC install-state files found'), uninstallResult.stdout);
+ assert.ok(!uninstallResult.stdout.includes('Legacy Codex sync cleanup summary'), uninstallResult.stdout);
+ assert.strictEqual(fs.readFileSync(agentsPath, 'utf8'), '# User instructions\n\n<!-- BEGIN ECC -->\n# ECC managed\n<!-- END ECC -->\n');
+ assert.strictEqual(fs.readFileSync(configPath, 'utf8'), 'model = "user"\n');
+ assert.strictEqual(fs.readFileSync(conversationPath, 'utf8'), 'conversation history');
+ } finally {
+ cleanup(homeDir);
+ cleanup(projectRoot);
+ }
+ })) passed++; else failed++;
+
+ if (test('explicit --legacy-codex-sync removes a marker-only AGENTS.md block', () => {
+ const homeDir = createTempDir('uninstall-explicit-marker-codex-home-');
+ const projectRoot = createTempDir('uninstall-explicit-marker-codex-project-');
+
+ try {
+ const codexHome = path.join(homeDir, '.codex');
+ const agentsPath = path.join(codexHome, 'AGENTS.md');
+
+ fs.mkdirSync(codexHome, { recursive: true });
+ fs.writeFileSync(
+ agentsPath,
+ '# User instructions\n\n<!-- BEGIN ECC -->\n# ECC managed\n<!-- END ECC -->\n'
+ );
+
+ const uninstallResult = run(['--legacy-codex-sync'], { cwd: projectRoot, homeDir });
+ assert.strictEqual(uninstallResult.code, 0, uninstallResult.stderr);
+ assert.ok(uninstallResult.stdout.includes('Legacy Codex sync cleanup summary'), uninstallResult.stdout);
+ assert.ok(uninstallResult.stdout.includes('Status: UNINSTALLED'), uninstallResult.stdout);
+ assert.strictEqual(fs.readFileSync(agentsPath, 'utf8'), '# User instructions\n\n');
+ } finally {
+ cleanup(homeDir);
+ cleanup(projectRoot);
+ }
+ })) passed++; else failed++;
+
console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);
process.exit(failed > 0 ? 1 : 0);
}