fix(skill-stocktake): compare quick scans with per-skill mtimes

A later batch save advances evaluated_at past edits to previously evaluated skills. Compare each saved evaluation mtime to the current inventory, including timestamps that move backward, and retain the legacy global timestamp fallback.
This commit is contained in:
wellkilo committed 2026-11-04 18:32:37 -08:00
1 parent b38be6a7f6
commit 3d8a6a1401
3 files changed
+53 -12

No files matched your search

@@ -10,7 +10,7 @@
"id": "hand-seeded",
"source": "manual-curation-pending-regeneration"
},
"registryDigest": "6f213dc845937b4093bc018d041b25b538d88d78451b9d799ad614989b360ee4",
"registryDigest": "1a3b98a420e7c275f255b7803ef5bd98b7fd9be558b8cbf3aaeda28e314c0c64",
"schemaVersion": 1,
"triggers": {
"skill:agent-runtime-gateway-smoke-test": [
+13 -11
View File
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
# quick-diff.sh — compare skill file mtimes against results.json evaluated_at
# quick-diff.sh — compare skill file mtimes against their saved evaluations
# Usage: quick-diff.sh RESULTS_JSON [CWD_SKILLS_DIR]
# Output: JSON array of changed/new files to stdout (empty [] if no changes)
#
@@ -88,16 +88,18 @@ process_dir() {
mtime=$(date -u -r "$file" +%Y-%m-%dT%H:%M:%SZ)
dp="${file/#$HOME/~}"
# Keep path comparison structured so literal newlines remain part of one
# JSON string instead of becoming ambiguous line-delimited records.
if jq -e --arg path "$dp" '.skills | any(.path == $path)' "$RESULTS_JSON" >/dev/null 2>&1; then
is_new="false"
# Known file: only emit if mtime changed (ISO 8601 string comparison is safe)
[[ "$mtime" > "$evaluated_at" ]] || continue
else
is_new="true"
# New file: always emit regardless of mtime
fi
# Compare against the version actually evaluated for this skill. The global
# completion time can be later than edits to an earlier evaluation batch.
# Older caches without per-skill mtimes retain the completion-time fallback.
is_new=$(jq -r --arg path "$dp" --arg mtime "$mtime" '
(first(.skills[] | select(.path == $path)) // null) as $cached |
if $cached == null then true
elif $cached.mtime != null then
if $cached.mtime != $mtime then false else empty end
elif $mtime > .evaluated_at then false
else empty end
' "$RESULTS_JSON")
[[ -n "$is_new" ]] || continue
jq -n \
--arg path "$dp" \
@@ -353,6 +353,45 @@ if (process.platform !== 'win32') {
}
}
if (process.platform !== 'win32') {
test('quick diff uses each saved evaluation mtime across cache shapes and timestamp changes', () => {
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-stocktake-quick-mtime-'));
try {
const skills = path.join(tempRoot, '.claude', 'skills');
writeSkill(path.join(skills, 'live'), 'live');
const skillPath = path.join(skills, 'live', 'SKILL.md');
const resultsPath = path.join(tempRoot, 'results.json');
const env = {
SKILL_STOCKTAKE_GLOBAL_DIR: path.join(tempRoot, 'missing'),
SKILL_STOCKTAKE_PROJECT_DIR: skills,
};
const evaluatedAt = '2025-01-10T00:00:00Z';
for (const shape of ['array', 'path-keyed', 'name-keyed']) {
for (const scenario of [
{ name: 'changed during batch', saved: '2025-01-01T00:00:00Z', live: '2025-01-02T00:00:00Z', changed: true },
{ name: 'restored older timestamp', saved: '2025-01-02T00:00:00Z', live: '2025-01-01T00:00:00Z', changed: true },
{ name: 'matching future timestamp', saved: '2025-02-01T00:00:00Z', live: '2025-02-01T00:00:00Z', changed: false },
{ name: 'null mtime unchanged', saved: null, live: '2025-01-01T00:00:00Z', changed: false },
{ name: 'null mtime changed', saved: null, live: '2025-02-01T00:00:00Z', changed: true },
{ name: 'legacy unchanged', live: '2025-01-01T00:00:00Z', changed: false },
{ name: 'legacy changed', live: '2025-02-01T00:00:00Z', changed: true },
]) {
const entry = { path: skillPath, ...(Object.hasOwn(scenario, 'saved') ? { mtime: scenario.saved } : {}) };
const cache = shape === 'array' ? [entry] : { [shape === 'path-keyed' ? skillPath : 'live']: entry };
fs.writeFileSync(resultsPath, JSON.stringify({ evaluated_at: evaluatedAt, skills: cache }));
fs.utimesSync(skillPath, new Date(scenario.live), new Date(scenario.live));
const result = runBash(quickDiffScript, [resultsPath], env);
assert.strictEqual(result.status, 0, result.stderr);
assert.deepStrictEqual(JSON.parse(result.stdout), scenario.changed
? [{ path: skillPath, mtime: scenario.live, is_new: false }] : [], `${shape}: ${scenario.name}`);
}
}
} finally {
fs.rmSync(tempRoot, { recursive: true, force: true });
}
});
}
console.log(`\nPassed: ${passed}`);
console.log(`Failed: ${failed}`);
process.exit(failed > 0 ? 1 : 0);