← 教程列表
coding

Task 4: Extract Update Check Logic

📅 2026/6/12 16:30:02⏱ 约 5 分钟阅读👁 9 阅读

**Files:** - Modify: `lib/skills-core.js` - Reference: `.codex/superpowers-codex` (lines 16-38) **Step 1: Add checkForUpdates function** Add at top after requires: ```javascript const { execSync } = require('child_process'); ``` Add before `module.exports`: ```javascript /** * Check if a git repository has updates available. * * @param {string} repoDir - Path to git repository * @returns {boolean} - True if updates are available */ function checkForUpdates(repoDir) { try { // Quick check with 3 second timeout to avoid delays if network is down const output = execSync('git fetch origin && git status --porcelain=v1 --branch', { cwd: repoDir, timeout: 3000, encoding: 'utf8', stdio: 'pipe' }); // Parse git status output to see if we're behind const statusLines = output.split('\n'); for (const line of statusLines) { if (line.startsWith('## ') && line.includes('[behind ')) { return true; // We're behind remote } } return false; // Up to date } catch (error) { // Network down, git error, timeout, etc. - don't block bootstrap return false; } } ``` **Step 2: Update module.exports** ```javascript module.exports = { extractFrontmatter, findSkillsInDir, resolveSkillPath, checkForUpdates }; ``` **Step 3: Verify syntax** Run: `node -c lib/skills-core.js` Expected: No output **Step 4: Commit** ```bash git add lib/skills-core.js git commit -m "feat: add git update checking to core module" ``` ---

← 返回教程列表 AI8899 · 内容仅供学习参考