UNPKG

aios-core

Version:

Synkra AIOS: AI-Orchestrated System for Full Stack Development - Core Framework

74 lines (63 loc) 1.95 kB
#!/usr/bin/env node /** * Git Post-Commit Hook - AIOS ProjectStatusLoader Cache Invalidation * * Story ACT-3: Clears the project status cache after every commit * so that the next agent activation sees fresh data. * * Cross-platform: Uses Node.js for Windows/macOS/Linux compatibility. * * Installation: * Copy or symlink to .husky/post-commit, or add to your git hooks: * node .aios-core/infrastructure/scripts/git-hooks/post-commit.js */ const fs = require('fs'); const path = require('path'); /** * Find the project root by walking up from the current directory * looking for .aios-core directory. * * @returns {string|null} Project root or null */ function findProjectRoot() { let dir = process.cwd(); // Walk up looking for .aios-core for (let i = 0; i < 10; i++) { if (fs.existsSync(path.join(dir, '.aios-core'))) { return dir; } const parent = path.dirname(dir); if (parent === dir) break; // Reached filesystem root dir = parent; } return process.cwd(); // Fallback } /** * Clear all project-status cache files in the .aios directory. * Handles both standard cache and worktree-specific cache files. */ function clearProjectStatusCache() { const projectRoot = findProjectRoot(); const aiosDir = path.join(projectRoot, '.aios'); if (!fs.existsSync(aiosDir)) { return; // No .aios directory - nothing to clear } try { const files = fs.readdirSync(aiosDir); for (const file of files) { // Match project-status.yaml and project-status-{hash}.yaml if (file.startsWith('project-status') && file.endsWith('.yaml')) { const filePath = path.join(aiosDir, file); try { fs.unlinkSync(filePath); } catch (err) { // Ignore errors (file might be locked by another process) } } } } catch (err) { // Silently fail - this is a non-critical hook } } // Execute clearProjectStatusCache();