Files
wehub-resource-sync 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
chore: import upstream snapshot with attribution
2026-07-13 12:02:19 +08:00

273 lines
11 KiB
JavaScript

#!/usr/bin/env node
/**
* Phase 1 micro-benchmarks for the @claude-flow/guidance optimization
* work (horizon: guidance-sota-2026-05, milestone M1).
*
* Three hot paths identified by the deep-researcher report
* (/tmp/guidance-optimization-plan.md):
*
* 1. analyzer.ts:831-917 extractMetrics — 10+ linear passes over `lines`
* 2. compiler.ts:294-326 parseRule — 4 new RegExp per call
* 3. retriever.ts:449-460 cosineSimilarity — recomputes norms (vectors are unit-normalised)
*
* Run BEFORE the fix to capture baseline, run AFTER to measure uplift.
* Output: docs/benchmarks/guidance-baseline.json or .../guidance-phase-1.json
*
* Usage:
* node v3/@claude-flow/cli ... build first
* node v3/@claude-flow/guidance/scripts/bench-phase-1.mjs --tag=baseline
* node v3/@claude-flow/guidance/scripts/bench-phase-1.mjs --tag=phase-1
*
* Standalone — does NOT require the test runner, just node ≥20 + ts files compiled
* to dist or invoked through tsx. We import the dist artifact when available,
* else fall back to ts-node-via-tsx (best-effort).
*/
import { performance } from 'node:perf_hooks';
import { mkdirSync, writeFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { dirname, resolve } from 'node:path';
const __dirname = dirname(fileURLToPath(import.meta.url));
const PKG_ROOT = resolve(__dirname, '..');
const REPO_ROOT = resolve(__dirname, '../../../..');
const OUT_DIR = resolve(REPO_ROOT, 'docs', 'benchmarks');
const args = Object.fromEntries(
process.argv.slice(2).map((a) => {
const [k, v] = a.replace(/^--/, '').split('=');
return [k, v ?? true];
}),
);
const TAG = args.tag || 'untagged';
const ITERS = parseInt(args.iters || '5000', 10);
function bench(name, fn, iters = ITERS) {
// Multi-trial median to reduce per-run variance — single trials at
// these iteration counts vary 5-15% between runs from background
// process load, GC, JIT recompile, etc. The median of 5 trials is
// stable to within ~2%, which is below the optimization signals we
// care about.
const TRIALS = 5;
// Warmup is critical for V8's JIT — do enough work to trigger
// optimization tier-up before the first measured run.
const warm = Math.min(2000, Math.floor(iters / 5));
for (let i = 0; i < warm; i++) fn();
const opsList = [];
for (let t = 0; t < TRIALS; t++) {
const start = performance.now();
for (let i = 0; i < iters; i++) fn();
const totalMs = performance.now() - start;
opsList.push(iters / (totalMs / 1000));
}
opsList.sort((a, b) => a - b);
const median = opsList[Math.floor(TRIALS / 2)];
const min = opsList[0];
const max = opsList[TRIALS - 1];
return {
name,
iters,
trials: TRIALS,
opsPerSec: Math.round(median),
avgMicros: Math.round((1 / median) * 1e6 * 1000) / 1000,
opsMin: Math.round(min),
opsMax: Math.round(max),
variance: Math.round(((max - min) / median) * 1000) / 1000,
};
}
// ─────────────────────────────────────────────────────────────────────────────
// Inputs (deterministic — same across runs so before/after are comparable)
// ─────────────────────────────────────────────────────────────────────────────
const CLAUDE_MD_FIXTURE = `# Project Constitution
## Behavioral Rules
- NEVER commit secrets or .env files
- ALWAYS read a file before editing it
- MUST run tests after code changes
- Prefer editing existing files over creating new ones
- Use npm scripts: \`npm run build\`, \`npm test\`, \`npm run lint\`
- No console.log in production code
- Keep files under 500 lines
## Security
- Validate input at system boundaries
- NEVER hardcode credentials
- DO NOT bypass auth checks
## Architecture
- Follow Domain-Driven Design
- Each bounded context owns its data
- Repository pattern for persistence
- Event sourcing for state changes
## Build & Test
- \`npm run build\` compiles TypeScript via tsc
- \`npm test\` runs vitest suite
- \`cargo test\` for Rust crate
## Tools
- npm, pnpm, docker, git, make, cargo
## Extra Section A
` + Array.from({ length: 80 }, (_, i) => `- Domain rule ${i}: enforce invariant ${i}`).join('\n') + `
## Extra Section B
` + Array.from({ length: 40 }, (_, i) => `Some prose content about pattern ${i}.`).join('\n') + `
`;
const RULE_TEXT_FIXTURE = `
RULE: enforce-secret-scan
TOOLS: <bash><write><edit>
INTENTS: <commit><push><release>
DOMAINS: <security><auth>
SCOPE: <**/*.env> <**/secrets/**> <**/.git/**>
When tool is <bash> or <write> AND intent matches <commit|push|release>,
scan the diff for credential patterns. Block if hit.
`;
function makeVec(seed, dim = 384) {
// Mulberry32-seeded deterministic Float32Array, normalised
let s = seed >>> 0 || 1;
const v = new Float32Array(dim);
let norm = 0;
for (let i = 0; i < dim; i++) {
s = (s * 9301 + 49297) % 233280;
v[i] = s / 233280 - 0.5;
norm += v[i] * v[i];
}
norm = Math.sqrt(norm);
for (let i = 0; i < dim; i++) v[i] /= norm;
return v;
}
// ─────────────────────────────────────────────────────────────────────────────
// Load the live code under test (dist if built, else src via tsx-shim path)
// ─────────────────────────────────────────────────────────────────────────────
let analyzerMod, compilerMod, retrieverMod;
async function loadMods() {
// Prefer dist
const distAnalyzer = resolve(PKG_ROOT, 'dist/analyzer.js');
const distCompiler = resolve(PKG_ROOT, 'dist/compiler.js');
const distRetriever = resolve(PKG_ROOT, 'dist/retriever.js');
try {
analyzerMod = await import(distAnalyzer);
} catch {
throw new Error(`Build the guidance package first: cd ${PKG_ROOT} && npm run build`);
}
compilerMod = await import(distCompiler);
retrieverMod = await import(distRetriever);
}
await loadMods();
// ─────────────────────────────────────────────────────────────────────────────
// Bench 1 — analyzer.extractMetrics via the exported `analyzeClaudeMd`
// ─────────────────────────────────────────────────────────────────────────────
const analyzeFn = analyzerMod.analyze || analyzerMod.analyzeClaudeMd || analyzerMod.default?.analyze;
if (typeof analyzeFn !== 'function') {
console.error('analyzer module has no analyzeClaudeMd/analyze export — exports:', Object.keys(analyzerMod).slice(0, 20));
process.exit(2);
}
const r1 = bench('analyzer.analyze(CLAUDE.md ~150 lines)', () => {
analyzeFn(CLAUDE_MD_FIXTURE);
});
// ─────────────────────────────────────────────────────────────────────────────
// Bench 2 — compiler.parseRule via the exported compile entry
// ─────────────────────────────────────────────────────────────────────────────
const CompilerCls =
compilerMod.Compiler ||
compilerMod.GuidanceCompiler ||
compilerMod.RuleCompiler ||
compilerMod.default;
let r2 = null;
if (typeof CompilerCls === 'function') {
const c = new CompilerCls();
// The compiler's hot path is `compile(claudeMdContent)` which does the full
// file walk + parseRule per discovered rule. We bench the full compile so
// the regex-construction-in-loop overhead in parseRule shows up.
r2 = bench('compiler.compile(CLAUDE.md ~150 lines, multiple rules)', () => {
c.compile(CLAUDE_MD_FIXTURE);
}, Math.max(1000, Math.floor(ITERS / 5)));
} else {
console.warn('compiler module — exports:', Object.keys(compilerMod).slice(0, 20));
}
// ─────────────────────────────────────────────────────────────────────────────
// Bench 3 — retriever.cosineSimilarity
// ─────────────────────────────────────────────────────────────────────────────
// cosineSimilarity is `private` inside ShardRetriever — we benchmark the
// same algorithmic shape via a free function. The phase-1 fix lives in
// the source file; the bench measures whether the math the retriever
// would do per shard comparison gets faster.
const a = makeVec(1);
const b = makeVec(2);
function cosineNaive(a, b) {
let dot = 0, na = 0, nb = 0;
for (let i = 0; i < a.length; i++) {
dot += a[i] * b[i];
na += a[i] * a[i];
nb += b[i] * b[i];
}
const d = Math.sqrt(na) * Math.sqrt(nb);
return d > 0 ? Math.max(0, Math.min(1, dot / d)) : 0;
}
function cosineDotOnly(a, b) {
// Optimised path — vectors are unit-normalised in HashEmbeddingProvider
// and ONNX providers, so we can skip both norm computations and the
// sqrt-div + clamp. Single multiply-add per dim.
let dot = 0;
for (let i = 0; i < a.length; i++) dot += a[i] * b[i];
return dot < 0 ? 0 : dot > 1 ? 1 : dot;
}
const r3 = bench('retriever.cosine(384-d, naive 3-accumulator)', () => {
cosineNaive(a, b);
}, 100000);
const r3b = bench('retriever.cosine(384-d, unit-norm dot-only)', () => {
cosineDotOnly(a, b);
}, 100000);
// ─────────────────────────────────────────────────────────────────────────────
// Emit result
// ─────────────────────────────────────────────────────────────────────────────
const results = [r1, r2, r3, r3b].filter(Boolean);
const out = {
tag: TAG,
iters: ITERS,
node: process.version,
platform: `${process.platform}-${process.arch}`,
capturedAt: new Date().toISOString(),
results,
};
mkdirSync(OUT_DIR, { recursive: true });
const outPath = resolve(OUT_DIR, `guidance-${TAG}.json`);
writeFileSync(outPath, JSON.stringify(out, null, 2));
console.log(`\nWrote ${outPath}\n`);
console.log('| Benchmark | Ops/sec | Avg µs |');
console.log('|------------------------------------------------------|-------------|----------|');
for (const r of results) {
const name = r.name.padEnd(52).slice(0, 52);
const ops = String(r.opsPerSec).padStart(11);
const us = String(r.avgMicros).padStart(8);
console.log(`| ${name} | ${ops} | ${us} |`);
}