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: integrate contributor snapshot allocation revision

haelyra4e337f0a43e3
diff --cc scripts/lib/skill-evolution/versioning.js
index a57178ac3,d5043ae2e..9adcce14b
--- a/scripts/lib/skill-evolution/versioning.js
+++ b/scripts/lib/skill-evolution/versioning.js
@@@ -169,27 -158,20 +169,27 @@@ function getEvolutionLog(skillPath, log
return readJsonl(getEvolutionLogPath(skillPath, logType));
}
-function createVersion(skillPath, options = {}) {
- const skillFilePath = ensureSkillExists(skillPath);
- ensureSkillVersioning(skillPath);
-
+function allocateSnapshotVersion(skillPath) {
const versions = listVersions(skillPath);
+ const versionsDir = getVersionsDir(skillPath);
+ const occupiedPaths = new Set(fs.existsSync(versionsDir) ? fs.readdirSync(versionsDir) : []);
let nextVersion = versions.length === 0 ? 1 : versions[versions.length - 1].version + 1;
- let snapshotPath = path.join(getVersionsDir(skillPath), `v${nextVersion}.md`);
- while (Number.isSafeInteger(nextVersion) && fs.existsSync(snapshotPath)) {
+ // Listing excludes non-files, but their paths remain user-owned and occupied.
+ while (Number.isSafeInteger(nextVersion) && occupiedPaths.has(`v${nextVersion}.md`)) {
nextVersion += 1;
- snapshotPath = path.join(getVersionsDir(skillPath), `v${nextVersion}.md`);
}
if (!Number.isSafeInteger(nextVersion)) {
- throw new Error('Skill snapshot version range is exhausted; existing snapshots were preserved');
- throw new Error('Skill version exceeds the safe integer range');
++ throw new Error('Skill snapshot version range is exhausted; safe integer allocation is unavailable; existing snapshots were preserved');
}
+ return nextVersion;
+}
+
+function createVersion(skillPath, options = {}) {
+ const skillFilePath = ensureSkillExists(skillPath);
+ const nextVersion = allocateSnapshotVersion(skillPath);
+ const versionsDir = getVersionsDir(skillPath);
+ ensureSkillVersioning(skillPath);
+ const snapshotPath = path.join(versionsDir, `v${nextVersion}.md`);
const skillContent = fs.readFileSync(skillFilePath, 'utf8');
const createdAt = options.timestamp || new Date().toISOString();
diff --cc tests/lib/skill-evolution.test.js
index b23b65757,501a05155..1860de247
--- a/tests/lib/skill-evolution.test.js
+++ b/tests/lib/skill-evolution.test.js
@@@ -221,8 -221,24 +221,29 @@@ function runTests()
);
assert.strictEqual(versioning.getCurrentVersion(skillDir), 1);
assert.ok(fs.statSync(snapshotDirectory).isDirectory());
+ for (const version of [2, 3]) {
+ fs.mkdirSync(path.join(versioning.getVersionsDir(skillDir), `v${version}.md`));
+ }
+ assert.strictEqual(versioning.createVersion(skillDir).version, 4);
+ assert.deepStrictEqual(versioning.listVersions(skillDir).map(entry => entry.version), [1, 4]);
+ for (const version of [2, 3]) {
+ assert.ok(fs.statSync(path.join(versioning.getVersionsDir(skillDir), `v${version}.md`)).isDirectory());
+ }
assert.strictEqual(versioning.getCurrentVersion(path.join(fixtureRoot, 'missing-skill')), 0);
assert.throws(() => versioning.createVersion(snapshotDirectory), /Skill file not found/);
+ const oversizedSnapshot = path.join(versioning.getVersionsDir(skillDir), 'v9007199254740992.md');
+ fs.writeFileSync(oversizedSnapshot, 'Preserve this snapshot');
+ const overflow = spawnSync(process.execPath, [
- '-e', 'require("assert").throws(() => require(process.argv[1]).createVersion(process.argv[2]), /safe integer/)',
++ '-e', 'require("assert").strictEqual(require(process.argv[1]).createVersion(process.argv[2]).version, 5)',
+ require.resolve('../../scripts/lib/skill-evolution/versioning'), skillDir,
+ ], { encoding: 'utf8', timeout: 10000 });
+ assert.strictEqual(overflow.status, 0, overflow.error?.message || overflow.stderr);
+ assert.strictEqual(fs.readFileSync(oversizedSnapshot, 'utf8'), 'Preserve this snapshot');
++ // Unsafe names are excluded from listing, while the actual safe range boundary refuses allocation.
++ const exhaustedSnapshot = path.join(versioning.getVersionsDir(skillDir), `v${Number.MAX_SAFE_INTEGER}.md`);
++ fs.writeFileSync(exhaustedSnapshot, 'Preserve the range boundary');
++ assert.throws(() => versioning.createVersion(skillDir), /safe integer/);
++ assert.strictEqual(fs.readFileSync(exhaustedSnapshot, 'utf8'), 'Preserve the range boundary');
} finally {
cleanupTempDir(fixtureRoot);
}