diff --git a/manifests/context-packs/skill-triggers@1.json b/manifests/context-packs/skill-triggers@1.json index 48081c3fb..422a258dd 100644 --- a/manifests/context-packs/skill-triggers@1.json +++ b/manifests/context-packs/skill-triggers@1.json @@ -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": [ diff --git a/skills/skill-stocktake/scripts/quick-diff.sh b/skills/skill-stocktake/scripts/quick-diff.sh index da36fa0f1..3e7984d5f 100755 --- a/skills/skill-stocktake/scripts/quick-diff.sh +++ b/skills/skill-stocktake/scripts/quick-diff.sh @@ -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" \ diff --git a/tests/scripts/skill-stocktake-discovery.test.js b/tests/scripts/skill-stocktake-discovery.test.js index 270c88547..6af6be496 100644 --- a/tests/scripts/skill-stocktake-discovery.test.js +++ b/tests/scripts/skill-stocktake-discovery.test.js @@ -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);