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(proximity): retain all tracked working-set paths

Huanyi Xie3989e50ab34d
diff --git a/scripts/lib/control-pane/proximity.js b/scripts/lib/control-pane/proximity.js
index 1db91c81e..e287ebee3 100644
--- a/scripts/lib/control-pane/proximity.js
+++ b/scripts/lib/control-pane/proximity.js
@@ -60,7 +60,12 @@ function runGitDiff(worktreePath, base, extraArgs) {
}
function untrackedFiles(worktreePath) {
- return runGit(worktreePath, ['ls-files', '--others', '--exclude-standard', '-z']).split('\0').filter(Boolean);
+ try {
+ return runGit(worktreePath, ['ls-files', '--others', '--exclude-standard', '-z']).split('\0').filter(Boolean);
+ } catch {
+ // Keep successful tracked-file diffs when this optional probe is unavailable.
+ return [];
+ }
}
/**
@@ -74,6 +79,10 @@ function defaultWorkingSetFor(session) {
const base = wt.base || 'HEAD';
try {
const ranges = parseDiffRanges(runGitDiff(wt.path, base, ['--unified=0']));
+ // Deletions, binary changes and quoted paths have no usable new-side hunks.
+ for (const file of runGitDiff(wt.path, base, ['--name-only', '-z']).split('\0').filter(Boolean)) {
+ if (!ranges.has(file)) ranges.set(file, []);
+ }
for (const file of untrackedFiles(wt.path)) ranges.set(file, []);
return [...ranges.entries()].map(([path, lines]) => (lines.length > 0 ? { path, lines } : { path }));
} catch {
diff --git a/tests/lib/control-pane-proximity.test.js b/tests/lib/control-pane-proximity.test.js
index 790959c39..042576eaf 100644
--- a/tests/lib/control-pane-proximity.test.js
+++ b/tests/lib/control-pane-proximity.test.js
@@ -103,6 +103,81 @@ test('real worktrees expose committed, staged, unstaged and untracked work befor
}
});
+test('real Git working sets retain tracked deletions and binary changes', () => {
+ const fs = require('fs');
+ const os = require('os');
+ const path = require('path');
+ const { execFileSync } = require('child_process');
+ const repo = fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-proximity-delete-'));
+ const git = (...args) => execFileSync('git', ['-C', repo, ...args], { stdio: 'pipe' });
+ try {
+ git('init', '-q', '-b', 'main');
+ git('config', 'user.name', 'proximity-test');
+ git('config', 'user.email', '[email protected]');
+ fs.writeFileSync(path.join(repo, 'deleted.js'), 'export const value = 1;\n');
+ fs.writeFileSync(path.join(repo, 'binary.bin'), Buffer.from([0, 1, 2]));
+ git('add', '.');
+ git('commit', '-qm', 'base');
+ fs.unlinkSync(path.join(repo, 'deleted.js'));
+ fs.writeFileSync(path.join(repo, 'binary.bin'), Buffer.from([0, 3, 4]));
+ const [agent] = sessionsToAgents([{ id: 'delete', worktree: { path: repo, base: 'main' } }]);
+ assert.ok(agent, 'an agent with only non-text tracked changes still participates');
+ assert.deepStrictEqual(agent.files.map(f => f.path).sort(), ['binary.bin', 'deleted.js']);
+ assert.ok(agent.files.every(f => f.lines === undefined));
+ } finally {
+ fs.rmSync(repo, { recursive: true, force: true });
+ }
+});
+
+test('quoted staged paths and untracked paths share identity, and untracked failures keep tracked edits', () => {
+ const fs = require('fs');
+ const os = require('os');
+ const path = require('path');
+ const childProcess = require('child_process');
+ const originalExec = childProcess.execFileSync;
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-proximity-quoted-'));
+ const repo = path.join(dir, 'repo');
+ const git = (cwd, ...args) => originalExec('git', ['-C', cwd, ...args], { stdio: 'pipe' });
+ const modulePath = require.resolve('../../scripts/lib/control-pane/proximity');
+ const cachedModule = require.cache[modulePath];
+ try {
+ fs.mkdirSync(repo);
+ git(repo, 'init', '-q', '-b', 'main');
+ git(repo, 'config', 'user.name', 'proximity-test');
+ git(repo, 'config', 'user.email', '[email protected]');
+ fs.writeFileSync(path.join(repo, 'README'), 'base\n');
+ git(repo, 'add', '.');
+ git(repo, 'commit', '-qm', 'base');
+ const file = 'café"résumé.js';
+ const worktrees = ['a', 'b'].map(name => {
+ const wt = path.join(dir, name);
+ git(repo, 'worktree', 'add', '-q', '-b', name, wt, 'main');
+ fs.writeFileSync(path.join(wt, file), `export const value = '${name}';\n`);
+ return { id: name, worktree: { path: wt, base: 'main' } };
+ });
+ git(worktrees[0].worktree.path, 'add', file);
+ const snapshot = buildProximitySnapshot(worktrees, { repoRoot: repo, graph: { adjacency: {} } });
+ assert.strictEqual(snapshot.counts.agents, 2);
+ assert.ok(snapshot.advisories.some(advisory => advisory.level === 'resolution'));
+ assert.ok(snapshot.agents.every(agent => agent.files.includes(file)));
+ for (const code of ['EACCES', 'ETIMEDOUT', 'ENOBUFS']) {
+ childProcess.execFileSync = (command, args, options) => {
+ if (args.includes('ls-files')) throw Object.assign(new Error('untracked probe unavailable'), { code });
+ return originalExec(command, args, options);
+ };
+ delete require.cache[modulePath];
+ const fresh = require(modulePath);
+ const [tracked] = fresh.sessionsToAgents([worktrees[0]]);
+ assert.ok(tracked, `${code}: tracked changes must survive`);
+ assert.deepStrictEqual(tracked.files.map(entry => entry.path), [file]);
+ }
+ } finally {
+ childProcess.execFileSync = originalExec;
+ require.cache[modulePath] = cachedModule;
+ fs.rmSync(dir, { recursive: true, force: true });
+ }
+});
+
test('sessionsToAgents: only worktree sessions with edits participate', () => {
const agents = sessionsToAgents(sessions, { changedFilesFor });
assert.deepStrictEqual(agents.map(a => a.agentId).sort(), ['docs-bot', 'lead-hermes', 'worker-kb']);