Merge reviewed PR #3874

# Conflicts:
#	manifests/context-packs/skill-triggers@1.json
This commit is contained in:
haelyra committed 2026-11-05 23:11:12 -05:00
commit f6e68a186f
2 files changed
+52 -11

No files matched your search

+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);