Repository navigation
fix(cli): scope squad cost to the shell's Squad session #4831
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Squad Heartbeat (Ralph) | ||
|
Check warning on line 1 in .github/workflows/squad-heartbeat.yml
|
||
| # Canonical source: .squad-templates/workflows/squad-heartbeat.yml. | ||
| # Run node scripts/sync-templates.mjs --sync for root, CLI and SDK mirrors; | ||
| # update the active .github/workflows copy while preserving repo-specific steps. | ||
| # | ||
| # CI Hardening: Cron schedule audit (item 8, refs diberry/squad#120) | ||
| # ───────────────────────────────────────────────────────────────── | ||
| # Audit finding: No cron schedule is configured here, which is INTENTIONAL. | ||
| # Ralph should only run reactively (on issue/PR events) or manually. | ||
| # A cron schedule would waste Actions minutes (~20 min/week) for minimal | ||
| # benefit since Ralph's triage logic is event-driven. | ||
| # If scheduled runs appear in Actions history, they are event-triggered | ||
| # (issue close/label), not cron-triggered. Do NOT add a schedule trigger. | ||
| on: | ||
| # React to completed work or new squad work | ||
| issues: | ||
| types: [closed, labeled] | ||
| # pull_request_target (not pull_request): GITHUB_TOKEN is forced read-only | ||
| # for `pull_request` events triggered by a fork, so write steps below | ||
| # (addLabels/createComment) 403 on fork PR closes (#2080-class bug). | ||
| # Safe here because the checkout step below has no `ref:` override, so it | ||
| # always checks out the BASE ref — no fork code or fork-controlled input | ||
| # is ever read or executed by this job. | ||
| pull_request_target: | ||
| types: [closed] | ||
| # Manual trigger | ||
| workflow_dispatch: | ||
| permissions: | ||
| issues: write | ||
| contents: read | ||
| pull-requests: read | ||
| actions: write | ||
| # CI Hardening Phase 3 item A1: Prevent parallel runs from competing for resources | ||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.event.issue.number || github.ref }} | ||
| cancel-in-progress: true | ||
| jobs: | ||
| heartbeat: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 #v7 | ||
| # CI Hardening: GitHub API rate limit monitoring (item 9) | ||
| # Ralph makes multiple API calls (list issues, add labels, create comments). | ||
| # Check rate limit early to avoid silent failures mid-workflow. | ||
| - name: "📊 Check GitHub API rate limit" | ||
| uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 #v9 | ||
| with: | ||
| script: | | ||
| const { data: rateLimit } = await github.rest.rateLimit.get(); | ||
| const { remaining, limit, reset } = rateLimit.rate; | ||
| // Security: mask numeric values to prevent fingerprinting via CI logs | ||
| core.setSecret(String(remaining)); | ||
| core.setSecret(String(limit)); | ||
| const resetDate = new Date(reset * 1000).toISOString(); | ||
| if (remaining < 10) { | ||
| core.setFailed(`❌ Rate limit: CRITICAL — below minimum threshold. Aborting to prevent silent failures.`); | ||
| } else if (remaining < 100) { | ||
| core.warning(`⚠️ Rate limit: WARNING — below safe threshold (resets ${resetDate})`); | ||
| } else { | ||
| core.info(`✅ Rate limit: OK — above safe threshold (resets ${resetDate})`); | ||
| } | ||
| - name: Ralph — Repair orphaned squad labels | ||
| uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 #v9 | ||
| with: | ||
| script: | | ||
| // Find issues with squad:{member} labels but missing parent "squad" label | ||
| const { data: openIssues } = await github.rest.issues.listForRepo({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| state: 'open', | ||
| per_page: 100 | ||
| }); | ||
| let repaired = 0; | ||
| for (const issue of openIssues) { | ||
| const labels = issue.labels.map(l => l.name); | ||
| const hasSquadMember = labels.some(l => l.startsWith('squad:')); | ||
| const hasSquadParent = labels.includes('squad'); | ||
| if (hasSquadMember && !hasSquadParent) { | ||
| await github.rest.issues.addLabels({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issue.number, | ||
| labels: ['squad'] | ||
| }); | ||
| core.info(`Repaired orphaned label on #${issue.number} — added parent "squad" label`); | ||
| repaired++; | ||
| } | ||
| } | ||
| if (repaired > 0) { | ||
| core.info(`🔧 Ralph repaired ${repaired} orphaned squad label(s)`); | ||
| } | ||
| - name: Check triage script | ||
| id: check-script | ||
| run: | | ||
| if [ -f "templates/ralph-triage.js" ]; then | ||
| echo "has_script=true" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "has_script=false" >> "$GITHUB_OUTPUT" | ||
| echo "⚠️ product-owned ralph-triage.js not found" | ||
| fi | ||
| - name: Ralph — Smart triage | ||
| if: steps.check-script.outputs.has_script == 'true' | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| node templates/ralph-triage.js \ | ||
| --squad-dir .squad \ | ||
| --output triage-results.json | ||
| - name: Ralph — Apply triage decisions | ||
| if: steps.check-script.outputs.has_script == 'true' && hashFiles('triage-results.json') != '' | ||
| uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 #v9 | ||
| with: | ||
| script: | | ||
| const fs = require('fs'); | ||
| const path = 'triage-results.json'; | ||
| if (!fs.existsSync(path)) { | ||
| core.info('No triage results — board is clear'); | ||
| return; | ||
| } | ||
| const results = JSON.parse(fs.readFileSync(path, 'utf8')); | ||
| if (results.length === 0) { | ||
| core.info('📋 Board is clear — Ralph found no untriaged issues'); | ||
| return; | ||
| } | ||
| const autoAssign = /<!--\s*copilot-auto-assign:\s*true\s*-->/i | ||
| .test(fs.readFileSync('.squad/team.md', 'utf8')); | ||
| for (const decision of results) { | ||
| try { | ||
| await github.rest.issues.addLabels({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: decision.issueNumber, | ||
| labels: [decision.label] | ||
| }); | ||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: decision.issueNumber, | ||
| body: [ | ||
| '### 🔄 Ralph — Auto-Triage', | ||
| '', | ||
| `**Assigned to:** ${decision.assignTo}`, | ||
| `**Reason:** ${decision.reason}`, | ||
| `**Source:** ${decision.source}`, | ||
| '', | ||
| '> Ralph auto-triaged this issue using routing rules.', | ||
| '> To reassign, swap the `squad:*` label.' | ||
| ].join('\n') | ||
| }); | ||
| if (decision.label === 'squad:copilot' && autoAssign) { | ||
| await github.rest.actions.createWorkflowDispatch({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| workflow_id: 'squad-issue-assign.yml', | ||
| ref: context.payload.repository.default_branch, | ||
| inputs: { issue_number: String(decision.issueNumber) } | ||
| }); | ||
| core.info(`Dispatched squad-issue-assign.yml for auto-assigned issue #${decision.issueNumber}`); | ||
| } | ||
| core.info(`Triaged #${decision.issueNumber} → ${decision.assignTo} (${decision.source})`); | ||
| } catch (e) { | ||
| core.warning(`Failed to triage #${decision.issueNumber}: ${e.message}`); | ||
| if (decision.label === 'squad:copilot' && autoAssign) { | ||
| core.setFailed(`Failed to dispatch Copilot assignment for #${decision.issueNumber}: ${e.message}`); | ||
| } | ||
| } | ||
| } | ||
| core.info(`🔄 Ralph triaged ${results.length} issue(s)`); | ||
| # Copilot assignment belongs exclusively to squad-issue-assign.yml. | ||