23f7624596
ADR-166 MCP Bridge Security Lock / Static-source security lock (push) Failing after 0s
ADR-166 MCP Bridge Security Lock / Compose default binds loopback + Mongo has auth (push) Failing after 2s
CodeQL Advanced / Analyze (rust) (push) Failing after 0s
ADR-166 MCP Bridge Security Lock / plugin-agent-federation bindHost default (push) Failing after 1s
ADR-166 MCP Bridge Security Lock / Runtime behavior — 401 + terminal gate + fail-closed (push) Failing after 4s
business-pods-smoke / smoke (push) Failing after 1s
all-plugins-smoke / smoke-all (push) Failing after 2s
CI/CD Pipeline / Security & Code Quality (push) Failing after 1s
CI/CD Pipeline / Test Suite (ubuntu-latest) (push) Failing after 1s
CI/CD Pipeline / Build & Package (macos-latest) (push) Has been skipped
CI/CD Pipeline / Build & Package (ubuntu-latest) (push) Has been skipped
CI/CD Pipeline / Build & Package (windows-latest) (push) Has been skipped
CI/CD Pipeline / Documentation & Examples (push) Failing after 1s
Clone Tracker (14-day rolling) / Snapshot clones for ruflo ecosystem (push) Failing after 1s
CodeQL Advanced / Analyze (actions) (push) Failing after 1s
CodeQL Advanced / Analyze (javascript-typescript) (push) Failing after 1s
federation-peer-rust / stable-noop (push) Failing after 1s
metaharness-ci / score (push) Failing after 1s
metaharness-ci / router-compat (push) Failing after 0s
metaharness-ci / similarity-tests (push) Failing after 0s
no-agentbbs-smoke / smoke-without-agentbbs (push) Failing after 1s
V3 CI/CD Pipeline / Build V3 (windows-latest) (push) Has been skipped
codex-integration-audit / Codex integration audit (push) Failing after 1s
helpers-manifest-guard / guard (push) Failing after 1s
🔗 Cross-Agent Integration Tests / 🤝 Agent Coordination Tests (push) Has been skipped
🔗 Cross-Agent Integration Tests / 🧠 Memory Sharing Integration (push) Has been skipped
🔗 Cross-Agent Integration Tests / 🛡️ Fault Tolerance Tests (push) Has been skipped
🔗 Cross-Agent Integration Tests / ⚡ Performance Integration Tests (push) Has been skipped
metaharness-ci / mcp-scan (push) Failing after 1s
metaharness-ci / eject-dryrun (push) Failing after 1s
metaharness-ci / metaharness-real-data (push) Failing after 0s
no-cli-optdep-bloat-2561 / guard (push) Failing after 1s
no-metaharness-smoke / smoke-without-metaharness (push) Failing after 1s
no-phantom-agentic-flow-subpath / guard (push) Failing after 1s
🔄 Automated Rollback Manager / 🚨 Failure Detection (push) Failing after 1s
V3 CI/CD Pipeline / Plugin hooks smoke / ubuntu-latest / Node 22 (push) Failing after 1s
V3 CI/CD Pipeline / ruflo-graph-intelligence build + test smoke (#2044, ADR-123) (push) Failing after 1s
CVE Audit Gate / Audit root (critical-blocking) (push) Failing after 2s
cost-tracker-smoke / smoke (push) Failing after 3s
oia-audit-weekly / audit (push) Failing after 2s
ruflo-agent-smoke / ruflo-agent structural smoke (push) Failing after 1s
📊 Status Badges Update / 📊 Update Status Badges (push) Failing after 1s
V3 CI/CD Pipeline / Static regression guards (#2267 YAML + (push) Failing after 1s
V3 CI/CD Pipeline / Test V3 Packages (push) Failing after 0s
V3 CI/CD Pipeline / agent_execute provider routing smoke (#2042) (push) Failing after 0s
CVE Audit Gate / Audit v3 (critical-blocking) (push) Failing after 1s
federation-peer-rust / stable-native (push) Failing after 2s
🔗 Cross-Agent Integration Tests / 🚀 Integration Test Setup (push) Failing after 2s
neural-trader-smoke / runtime-smoke (push) Failing after 1s
V3 CI/CD Pipeline / Build V3 (macos-latest) (push) Has been skipped
V3 CI/CD Pipeline / Build V3 (ubuntu-latest) (push) Has been skipped
V3 CI/CD Pipeline / Type Check V3 (push) Failing after 1s
V3 CI/CD Pipeline / Smoke (no better-sqlite3) / ubuntu-latest / Node 24 (push) Failing after 1s
V3 CI/CD Pipeline / Smoke (no better-sqlite3) / ubuntu-latest / Node 22 (push) Failing after 2s
V3 CI/CD Pipeline / browser rvf create flag smoke (#2015) (push) Failing after 0s
V3 CI/CD Pipeline / Dependency review (#2046) (push) Has been skipped
V3 CI/CD Pipeline / Supply-chain audit (#2046) (push) Failing after 0s
V3 CI/CD Pipeline / witness marker drift smoke (#2021) (push) Failing after 1s
V3 CI/CD Pipeline / neural-trader portfolio CG smoke (#2068, ADR-126 Phase 3) (push) Failing after 1s
V3 CI/CD Pipeline / neural-trader backtest signing smoke (#2068, ADR-126 Phase 4) (push) Failing after 1s
V3 CI/CD Pipeline / kg-extract type-import classification smoke (#2049) (push) Failing after 0s
V3 CI/CD Pipeline / witness verify precondition smoke (#1880) (push) Failing after 2s
V3 CI/CD Pipeline / neural-trader pipeline risk-gate smoke (#2068, ADR-126 Phase 5) (push) Failing after 0s
V3 CI/CD Pipeline / neural-trader feature attribution smoke (#2068, ADR-126 Phase 6) (push) Failing after 0s
V3 CI/CD Pipeline / plugin-registry signature verification smoke (#1922, CWE-347) (push) Failing after 4s
V3 CI/CD Pipeline / memory stats legacy-DB smoke (#2120) (push) Failing after 4s
V3 CI/CD Pipeline / github deprecated actions smoke (#2089, ADR-127 Phase 3) (push) Failing after 1s
V3 CI/CD Pipeline / graph query + pathfinder smoke (ADR-130 P2+P5) (push) Has been skipped
V3 CI/CD Pipeline / graph trajectory hooks smoke (ADR-130 P3) (push) Has been skipped
V3 CI/CD Pipeline / graph plugin adapter smoke (ADR-130 P4) (push) Has been skipped
V3 CI/CD Pipeline / graph benchmark (ADR-130 P6) (push) Has been skipped
V3 CI/CD Pipeline / statusline generator delegation smoke (#2195) (push) Failing after 1s
V3 CI/CD Pipeline / wizard init regression guard (#2206 (push) Failing after 1s
V3 CI/CD Pipeline / memory no-stray-db smoke (ADR-125 P7) (push) Failing after 1s
V3 CI/CD Pipeline / github-safe injection smoke (#2089, ADR-127 Phase 1) (push) Failing after 1s
V3 CI/CD Pipeline / github actions pin smoke (#2089, ADR-127 Phase 1) (push) Failing after 1s
V3 CI/CD Pipeline / github attribution opt-in smoke (#2089, ADR-127 Phase 4) (push) Failing after 1s
V3 CI/CD Pipeline / pre-bash hook safety smoke (#2017) (push) Failing after 1s
V3 CI/CD Pipeline / Memory import smoke / ubuntu-latest (push) Failing after 0s
V3 CI/CD Pipeline / MCP protocol smoke / ubuntu-latest (push) Failing after 2s
V3 CI/CD Pipeline / ruvllm WASM auto-init smoke (#2086) (push) Failing after 4s
V3 CI/CD Pipeline / MCP paired-tool round-trip smoke (#1889) (push) Failing after 1s
V3 CI/CD Pipeline / Plugin package install-safety (#1902/#1903/#1904) (push) Failing after 1s
V3 CI/CD Pipeline / Tool description discoverability (ADR-112) (push) Failing after 3s
V3 CI/CD Pipeline / CLI npx-install smoke (#1147 / (22) (push) Failing after 1s
V3 CI/CD Pipeline / CLI npx-install smoke (#1147 / (24) (push) Failing after 1s
V3 CI/CD Pipeline / Windows hook shim smoke (#2132) / ubuntu-latest (push) Failing after 2s
V3 CI/CD Pipeline / Windows hook execution smoke (#2132) / ubuntu-latest (push) Failing after 1s
V3 CI/CD Pipeline / Windows init hooks smoke (#2132) / ubuntu-latest (push) Failing after 1s
V3 CI/CD Pipeline / Vector-index dimension audit (#1947) (push) Failing after 0s
V3 CI/CD Pipeline / Hook-command install safety (#1921) (push) Failing after 1s
V3 CI/CD Pipeline / ToolOutputGuardrail smoke (ADR-131, (push) Failing after 1s
V3 CI/CD Pipeline / init-bundle invariants smoke (#2095, ADR-128 Phase 5) (push) Failing after 1s
V3 CI/CD Pipeline / wasm provider bridge smoke (ADR-129 P1) (push) Failing after 2s
V3 CI/CD Pipeline / wasm gallery CRUD smoke (ADR-129 P3) (push) Failing after 1s
V3 CI/CD Pipeline / wasm plugin bridge smoke (ADR-129 P4) (push) Failing after 0s
V3 CI/CD Pipeline / wasm compose smoke (ADR-129 P2) (push) Failing after 4s
V3 CI/CD Pipeline / graph schema smoke (ADR-130 P1) (push) Failing after 0s
Validate Marketplace / validate (push) Failing after 1s
🔍 Verification Pipeline / 🚀 Setup Verification (push) Failing after 1s
🔍 Verification Pipeline / 🛡️ Security Verification (push) Has been skipped
🔍 Verification Pipeline / 📝 Code Quality (push) Has been skipped
🔍 Verification Pipeline / 🧪 Test Verification (${{ matrix.os }}, Node ${{ matrix.node }}) (push) Has been skipped
🔍 Verification Pipeline / 🏗️ Build Verification (push) Has been skipped
🔍 Verification Pipeline / 📚 Documentation Verification (push) Has been skipped
CVE Audit Gate / High-severity report (warn only) (push) Has been cancelled
🔄 Automated Rollback Manager / 🔄 Execute Rollback (push) Has been cancelled
🔄 Automated Rollback Manager / ✅ Post-Rollback Verification (push) Has been cancelled
🔄 Automated Rollback Manager / 📊 Rollback Monitoring (push) Has been cancelled
V3 CI/CD Pipeline / Windows init hooks smoke (#2132) / windows-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook execution smoke (#2132) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook execution smoke (#2132) / windows-latest (push) Has been cancelled
🔄 Automated Rollback Manager / ⏳ Manual Rollback Approval (push) Has been cancelled
V3 CI/CD Pipeline / MCP protocol smoke / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Memory import smoke / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook shim smoke (#2132) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook shim smoke (#2132) / windows-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows init hooks smoke (#2132) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Witness verify (signed manifest) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Witness verify (signed manifest) / ubuntu-latest (push) Has been cancelled
V3 CI/CD Pipeline / Witness verify (signed manifest) / windows-latest (push) Has been cancelled
V3 CI/CD Pipeline / Publish to npm (alpha) (push) Has been cancelled
V3 CI/CD Pipeline / Smoke (no better-sqlite3) / macos-latest / Node 22 (push) Has been cancelled
V3 CI/CD Pipeline / Plugin hooks smoke / macos-latest / Node 22 (push) Has been cancelled
CI/CD Pipeline / Deploy & Release (push) Has been cancelled
CI/CD Pipeline / CI Status (push) Has been cancelled
🔗 Cross-Agent Integration Tests / 📊 Integration Test Report (push) Has been cancelled
🔄 Automated Rollback Manager / 🔍 Pre-Rollback Validation (push) Has been cancelled
🔍 Verification Pipeline / ⚡ Performance Verification (push) Has been cancelled
🔍 Verification Pipeline / 📊 Verification Report (push) Has been cancelled
230 lines
9.1 KiB
JavaScript
Executable File
230 lines
9.1 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
||
// cost-health — composition skill: runs all four CI-gate checks in parallel
|
||
// and surfaces a single combined health status with max exit code.
|
||
//
|
||
// Each underlying check answers a different question; together they form
|
||
// a complete spend health picture:
|
||
//
|
||
// budget-check (reactive) "have we crossed the budget?"
|
||
// burn (trend) "is daily burn accelerating?"
|
||
// anomaly (point) "is any specific session an outlier?"
|
||
// projection (predictive) "when will we hit the budget?"
|
||
//
|
||
// USAGE
|
||
// node scripts/health.mjs # default thresholds
|
||
// node scripts/health.mjs --alert-acceleration 50 # burn threshold
|
||
// node scripts/health.mjs --alert-outliers 1 # anomaly threshold
|
||
// node scripts/health.mjs --alert-days-to-exhaust 7 # projection threshold
|
||
// node scripts/health.mjs --format json
|
||
//
|
||
// Default thresholds are set to "would you want to know about this on Slack?":
|
||
// - burn: +100% (latest day spent 2× the prior weekly mean)
|
||
// - anomaly: ≥1 outlier (any single session > 3.5σ from median)
|
||
// - projection: <14d until 100% budget (only fires when budget is set)
|
||
// - budget: HARD_STOP at 100% (the budget-check default)
|
||
//
|
||
// EXIT CODE = max(component exits). If ANY subcheck failed, the gate fails.
|
||
//
|
||
// Env: HEALTH_QUIET=1, HEALTH_BUDGET_PERIOD=today|week|month|all,
|
||
// HEALTH_NAMESPACE=cost-tracking (forwarded to each subcheck).
|
||
|
||
import { spawn } from 'node:child_process';
|
||
import { dirname, join } from 'node:path';
|
||
import { fileURLToPath } from 'node:url';
|
||
|
||
const SCRIPTS_DIR = dirname(fileURLToPath(import.meta.url));
|
||
|
||
const ARGS = (() => {
|
||
const a = {
|
||
alertAcceleration: 100, // burn — +100% bucket vs prior mean
|
||
alertOutliers: 1, // anomaly — any outlier fails
|
||
alertDaysToExhaust: 14, // projection — < 14d to 100% budget
|
||
format: 'table',
|
||
skip: new Set(), // --skip burn,anomaly to disable subchecks
|
||
};
|
||
if (process.env.HEALTH_QUIET === '1') a.format = 'json';
|
||
for (let i = 2; i < process.argv.length; i++) {
|
||
const v = process.argv[i];
|
||
if (v === '--alert-acceleration') a.alertAcceleration = parseFloat(process.argv[++i]);
|
||
else if (v === '--alert-outliers') a.alertOutliers = parseInt(process.argv[++i], 10);
|
||
else if (v === '--alert-days-to-exhaust') a.alertDaysToExhaust = parseFloat(process.argv[++i]);
|
||
else if (v === '--format') a.format = process.argv[++i];
|
||
else if (v === '--skip') {
|
||
for (const s of (process.argv[++i] || '').split(',')) a.skip.add(s.trim());
|
||
}
|
||
}
|
||
return a;
|
||
})();
|
||
|
||
function runScript(name, scriptFile, scriptArgs, jsonViaEnv) {
|
||
// Most scripts take `--format json` as a flag. budget.mjs uses
|
||
// positional subcommands + BUDGET_QUIET=1 env to opt into JSON. The
|
||
// jsonViaEnv parameter lets the caller pick which mechanism to use.
|
||
const args = jsonViaEnv
|
||
? [scriptFile, ...scriptArgs]
|
||
: [scriptFile, ...scriptArgs, '--format', 'json'];
|
||
const env = jsonViaEnv
|
||
? { ...process.env, [jsonViaEnv]: '1' }
|
||
: process.env;
|
||
return new Promise((resolve) => {
|
||
const p = spawn('node', args, { stdio: ['ignore', 'pipe', 'pipe'], env });
|
||
let stdout = '';
|
||
let stderr = '';
|
||
p.stdout.on('data', (d) => { stdout += d.toString(); });
|
||
p.stderr.on('data', (d) => { stderr += d.toString(); });
|
||
p.on('close', (code) => {
|
||
let json = null;
|
||
const m = /\{[\s\S]*\}/.exec(stdout);
|
||
if (m) {
|
||
try { json = JSON.parse(m[0]); } catch { /* leave null */ }
|
||
}
|
||
resolve({ name, exitCode: code ?? 0, json, stderr: stderr.slice(0, 300) });
|
||
});
|
||
p.on('error', (err) => {
|
||
resolve({ name, exitCode: 127, json: null, stderr: err.message });
|
||
});
|
||
});
|
||
}
|
||
|
||
async function main() {
|
||
const budgetPeriod = process.env.HEALTH_BUDGET_PERIOD || 'all';
|
||
|
||
const tasks = [];
|
||
if (!ARGS.skip.has('budget')) {
|
||
tasks.push(runScript('budget', join(SCRIPTS_DIR, 'budget.mjs'), ['check'], 'BUDGET_QUIET'));
|
||
}
|
||
if (!ARGS.skip.has('burn')) {
|
||
tasks.push(runScript('burn', join(SCRIPTS_DIR, 'burn.mjs'), [
|
||
'--alert-on-acceleration-pct', String(ARGS.alertAcceleration),
|
||
]));
|
||
}
|
||
if (!ARGS.skip.has('anomaly')) {
|
||
tasks.push(runScript('anomaly', join(SCRIPTS_DIR, 'anomaly.mjs'), [
|
||
'--alert-on-outliers', String(ARGS.alertOutliers),
|
||
]));
|
||
}
|
||
if (!ARGS.skip.has('projection')) {
|
||
tasks.push(runScript('projection', join(SCRIPTS_DIR, 'projection.mjs'), []));
|
||
}
|
||
|
||
// Run in parallel — each spawns its own npx CLI shellout.
|
||
const results = await Promise.all(tasks);
|
||
|
||
// Projection has no built-in exit code, so derive a synthetic one from
|
||
// days-until-100%-budget-exhaustion.
|
||
const projectionResult = results.find((r) => r.name === 'projection');
|
||
let projectionExit = 0;
|
||
let projectionDays = null;
|
||
if (projectionResult?.json?.budget?.exhaustion) {
|
||
const hundred = projectionResult.json.budget.exhaustion.find((e) => e.thresholdPct === 100);
|
||
if (hundred?.daysUntilReached !== undefined && hundred.daysUntilReached !== null) {
|
||
projectionDays = hundred.daysUntilReached;
|
||
if (hundred.daysUntilReached < ARGS.alertDaysToExhaust) {
|
||
projectionExit = 1;
|
||
}
|
||
}
|
||
projectionResult.exitCode = projectionExit;
|
||
} else if (projectionResult) {
|
||
// No budget configured or no data — projection is "OK" by default.
|
||
projectionResult.exitCode = 0;
|
||
}
|
||
|
||
const maxExit = Math.max(...results.map((r) => r.exitCode));
|
||
|
||
const payload = {
|
||
config: {
|
||
alertAcceleration: ARGS.alertAcceleration,
|
||
alertOutliers: ARGS.alertOutliers,
|
||
alertDaysToExhaust: ARGS.alertDaysToExhaust,
|
||
budgetPeriod,
|
||
skipped: [...ARGS.skip],
|
||
},
|
||
checks: results.map((r) => ({
|
||
name: r.name,
|
||
exitCode: r.exitCode,
|
||
ok: r.exitCode === 0,
|
||
summary: summarize(r),
|
||
})),
|
||
overall: {
|
||
ok: maxExit === 0,
|
||
exitCode: maxExit,
|
||
},
|
||
generatedAt: new Date().toISOString(),
|
||
};
|
||
|
||
if (ARGS.format === 'json') {
|
||
console.log(JSON.stringify(payload, null, 2));
|
||
} else {
|
||
console.log(`# cost-health`);
|
||
console.log('');
|
||
const badge = maxExit === 0 ? '✓ HEALTHY' : '⚠ UNHEALTHY';
|
||
console.log(`**Overall**: ${badge} (max exit code ${maxExit})`);
|
||
console.log('');
|
||
console.log('| Check | Status | Detail |');
|
||
console.log('|---|:---:|---|');
|
||
for (const r of results) {
|
||
const status = r.exitCode === 0 ? '✓' : '⚠';
|
||
console.log(`| \`${r.name}\` | ${status} | ${summarize(r)} |`);
|
||
}
|
||
if (ARGS.skip.size > 0) {
|
||
console.log('');
|
||
console.log(`_Skipped: ${[...ARGS.skip].join(', ')}_`);
|
||
}
|
||
console.log('');
|
||
console.log(`_Run \`cost <check>\` for the full detail of any failing leg._`);
|
||
console.log('');
|
||
}
|
||
|
||
process.exit(maxExit);
|
||
}
|
||
|
||
function summarize(r) {
|
||
if (!r) return 'no result';
|
||
if (r.exitCode === 127 || !r.json) {
|
||
return `**error** (exit ${r.exitCode}${r.stderr ? `: ${r.stderr.slice(0, 80)}` : ''})`;
|
||
}
|
||
const j = r.json;
|
||
switch (r.name) {
|
||
case 'budget': {
|
||
// budget.mjs returns { error: 'no budget configured', totalSpend, recordCount }
|
||
// when no budget is set; otherwise { level, utilization_pct, budget_usd, spent_usd }.
|
||
if (j.error === 'no budget configured') {
|
||
const spend = typeof j.totalSpend === 'number' ? `$${j.totalSpend.toFixed(2)}` : '—';
|
||
return `no budget set (${spend} measured spend; run \`cost budget set <usd>\` to enable)`;
|
||
}
|
||
const level = j.level || 'OK';
|
||
const util = (typeof j.utilization_pct === 'number') ? `${j.utilization_pct.toFixed(1)}%` : '—';
|
||
const budget = (typeof j.budget_usd === 'number') ? `$${j.budget_usd.toFixed(2)}` : '—';
|
||
return `${level} — ${util} of ${budget} budget consumed`;
|
||
}
|
||
case 'burn': {
|
||
const d = j.delta?.deltaPct;
|
||
const triggered = j.alert?.triggered;
|
||
const reason = j.alert?.reason || '';
|
||
if (triggered) return `**ALERT** ${d?.toFixed(1)}% acceleration: ${reason.slice(0, 100)}`;
|
||
return `delta ${d === null ? 'n/a' : (d?.toFixed?.(1) ?? '0') + '%'} — within ±${ARGS.alertAcceleration}%`;
|
||
}
|
||
case 'anomaly': {
|
||
const n = j.outliers?.length ?? 0;
|
||
const triggered = j.alert?.triggered;
|
||
if (triggered) return `**ALERT** ${n} outlier session(s) detected (|z|>${j.filters?.threshold ?? 3.5})`;
|
||
if (!j.sufficient) return `insufficient data (${j.reason || 'n<3'})`;
|
||
return `${n} outlier(s) — under threshold ≥${ARGS.alertOutliers}`;
|
||
}
|
||
case 'projection': {
|
||
if (!j.budget) return 'no budget configured — skipping forward-look';
|
||
const hundred = j.budget.exhaustion?.find((e) => e.thresholdPct === 100);
|
||
if (!hundred || hundred.daysUntilReached === null || hundred.daysUntilReached === undefined) {
|
||
return 'no spend rate yet — cannot project';
|
||
}
|
||
const d = hundred.daysUntilReached;
|
||
if (d < ARGS.alertDaysToExhaust) return `**ALERT** ${d.toFixed(1)}d to 100% budget (threshold <${ARGS.alertDaysToExhaust}d)`;
|
||
return `${d.toFixed(1)}d to 100% budget — over ${ARGS.alertDaysToExhaust}d horizon`;
|
||
}
|
||
default:
|
||
return `exit ${r.exitCode}`;
|
||
}
|
||
}
|
||
|
||
main();
|