quality-gate

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Quality Gate Skill (Bun-Only)

质量门禁技能(仅支持Bun)

Verify code quality before commits and deployments using Bun exclusively.
仅使用Bun在提交和部署前验证代码质量。

⚠️ CRITICAL: Bun-Only Approach (MANDATORY)

⚠️ 重要提示:仅使用Bun(强制要求)

ALL commands MUST use
bun
- NEVER use
pnpm
,
npm
, or
npx
.
Why:
  • pnpm run X
    spawns: pnpm (node) + command (node) = 2 processes
  • bun run X
    spawns: bun only = 1 process (6x lighter than node)
  • With
    --smol
    flag: 54MB vs 343MB memory footprint
bash
undefined
所有命令必须使用
bun
——绝对不能使用
pnpm
npm
npx
原因:
  • pnpm run X
    会启动:pnpm(node)+ 命令(node)= 2个进程
  • bun run X
    只会启动:bun = 1个进程(比node轻6倍)
  • 使用
    --smol
    标志:内存占用从343MB降至54MB
bash
undefined

❌ NEVER USE THESE

❌ 绝对不要使用这些

pnpm run typecheck # Spawns extra node process npm run test # Spawns extra node process npx tsc # Spawns node
pnpm run typecheck # 会启动额外的node进程 npm run test # 会启动额外的node进程 npx tsc # 会启动node

✅ ALWAYS USE THESE

✅ 务必使用这些

bun run typecheck # Direct bun execution bun test # Native bun test runner (17x faster) bun run lint # Single process

---
bun run typecheck # 直接通过bun执行 bun test # 原生bun测试运行器(快17倍) bun run lint # 单进程执行

---

⚠️ CRITICAL: Serialized Execution (MANDATORY)

⚠️ 重要提示:串行执行(强制要求)

Quality gates MUST run serially, never in parallel.
Multiple agents running quality gates simultaneously causes system crash:
  • 3 agents × 3 commands = resource exhaustion
  • Result: Load 500+, kernel_task spike, system freeze
Use flock to enforce serialization:
bash
LOCK_FILE="/tmp/rad-engineer-quality-gate.lock"

质量门禁必须串行运行,绝不能并行。
多个代理同时运行质量门禁会导致系统崩溃:
  • 3个代理 × 3条命令 = 资源耗尽
  • 结果:负载超过500,kernel_task飙升,系统冻结
使用flock强制串行执行:
bash
LOCK_FILE="/tmp/rad-engineer-quality-gate.lock"

⚠️ CRITICAL: JIT Resource Check (MANDATORY)

⚠️ 重要提示:实时资源检查(强制要求)

BEFORE running any quality gate, check system resources:
bash
undefined
在运行任何质量门禁之前,必须检查系统资源:
bash
undefined

Quick inline resource check (embedded in skill)

快速内联资源检查(嵌入在技能中)

check_resources() { local load kernel_cpu load=$(sysctl -n vm.loadavg | awk '{print $2}') kernel_cpu=$(ps -Ao %cpu,comm | grep kernel_task | head -1 | awk '{print $1}') kernel_cpu=${kernel_cpu:-0}
if (( $(echo "$load > 8.0" | bc -l) )); then
    echo "BLOCKED: Load too high ($load). Wait 30 seconds."
    return 1
fi
if (( $(echo "$kernel_cpu > 40" | bc -l) )); then
    echo "BLOCKED: kernel_task too high (${kernel_cpu}%). Wait 30 seconds."
    return 1
fi
return 0
}
check_resources() { local load kernel_cpu load=$(sysctl -n vm.loadavg | awk '{print $2}') kernel_cpu=$(ps -Ao %cpu,comm | grep kernel_task | head -1 | awk '{print $1}') kernel_cpu=${kernel_cpu:-0}
if (( $(echo "$load > 8.0" | bc -l) )); then
    echo "BLOCKED: 负载过高($load)。请等待30秒。"
    return 1
fi
if (( $(echo "$kernel_cpu > 40" | bc -l) )); then
    echo "BLOCKED: kernel_task占用过高(${kernel_cpu}%)。请等待30秒。"
    return 1
fi
return 0
}

Use before quality gates

在运行质量门禁前调用

check_resources || { sleep 30; check_resources; } || exit 1

**Full resource check script:** `.claude/hooks/check-system-resources.sh`

---
check_resources || { sleep 30; check_resources; } || exit 1

**完整资源检查脚本:** `.claude/hooks/check-system-resources.sh`

---

Quality Stages

质量检查阶段

Stage 1: Static Analysis

阶段1:静态分析

bash
LOCK="/tmp/rad-engineer-quality-gate.lock"
cd rad-engineer
bash
LOCK="/tmp/rad-engineer-quality-gate.lock"
cd rad-engineer

Check resources first

首先检查资源

.claude/hooks/check-system-resources.sh || { sleep 30; .claude/hooks/check-system-resources.sh; } || exit 1
.claude/hooks/check-system-resources.sh || { sleep 30; .claude/hooks/check-system-resources.sh; } || exit 1

TypeScript check - MUST pass with 0 errors (SERIALIZED)

TypeScript检查 - 必须0错误(串行执行)

flock -w 300 "$LOCK" bun run typecheck
flock -w 300 "$LOCK" bun run typecheck

Lint check - MUST pass (SERIALIZED)

代码检查 - 必须通过(串行执行)

flock -w 300 "$LOCK" bun run lint

**Failure Actions:**

- List all TypeScript errors with file:line
- Separate lint errors into auto-fixable vs manual
flock -w 300 "$LOCK" bun run lint

**失败处理动作:**

- 列出所有TypeScript错误,包含文件:行号
- 将代码检查错误分为可自动修复和需手动修复两类

Stage 2: Tests

阶段2:测试

bash
LOCK="/tmp/rad-engineer-quality-gate.lock"
cd rad-engineer
bash
LOCK="/tmp/rad-engineer-quality-gate.lock"
cd rad-engineer

Check resources first

首先检查资源

.claude/hooks/check-system-resources.sh || { sleep 30; .claude/hooks/check-system-resources.sh; } || exit 1
.claude/hooks/check-system-resources.sh || { sleep 30; .claude/hooks/check-system-resources.sh; } || exit 1

Run all tests (SERIALIZED) - uses --smol from bunfig.toml

运行所有测试(串行执行)- 使用bunfig.toml中的--smol配置

flock -w 300 "$LOCK" bun test
flock -w 300 "$LOCK" bun test

Coverage (run separately when needed - NOT by default)

覆盖率检查(按需单独运行 - 非默认执行)

flock -w 300 "$LOCK" bun test --coverage

flock -w 300 "$LOCK" bun test --coverage


**Requirements:**

- All tests must pass
- Coverage ≥ 80% (when explicitly checked)

**要求:**

- 所有测试必须通过
- 覆盖率≥80%(当显式检查时)

Stage 3: Build (if applicable)

阶段3:构建(如适用)

bash
LOCK="/tmp/rad-engineer-quality-gate.lock"
cd rad-engineer
bash
LOCK="/tmp/rad-engineer-quality-gate.lock"
cd rad-engineer

Verify build succeeds (SERIALIZED)

验证构建成功(串行执行)

flock -w 300 "$LOCK" bun run build

---
flock -w 300 "$LOCK" bun run build

---

One-Liner for All Quality Gates

一键运行所有质量门禁

Use this single command that runs all gates serially with resource check:
bash
cd rad-engineer && \
LOCK="/tmp/rad-engineer-quality-gate.lock" && \
( ../.claude/hooks/check-system-resources.sh || { sleep 30; ../.claude/hooks/check-system-resources.sh; } ) && \
flock -w 300 "$LOCK" sh -c 'bun run typecheck && bun run lint && bun test'
This ensures:
  1. Resources are checked BEFORE spawning processes
  2. Only one quality gate runs at a time across ALL agents
  3. Typecheck → Lint → Test run sequentially
  4. Early exit on first failure
  5. All processes use Bun (no node overhead)

使用以下单个命令,串行运行所有门禁并包含资源检查:
bash
cd rad-engineer && \
LOCK="/tmp/rad-engineer-quality-gate.lock" && \
( ../.claude/hooks/check-system-resources.sh || { sleep 30; ../.claude/hooks/check-system-resources.sh; } ) && \
flock -w 300 "$LOCK" sh -c 'bun run typecheck && bun run lint && bun test'
该命令确保:
  1. 在启动进程前先检查资源
  2. 所有代理同时只能运行一个质量门禁
  3. 按顺序执行类型检查 → 代码检查 → 测试
  4. 首次失败时立即退出
  5. 所有进程均使用Bun(无node开销)

Bun Configuration (bunfig.toml)

Bun配置(bunfig.toml)

The project is configured with memory optimization:
toml
[test]
smol = true              # Reduces memory from 343MB to 54MB
coverage = false         # Disabled by default (run explicitly when needed)
timeout = 300000         # 5 min timeout for integration tests
coverageSkipTestFiles = true

项目已配置内存优化:
toml
[test]
smol = true              # 将内存占用从343MB降至54MB
coverage = false         # 默认禁用(按需显式运行)
timeout = 300000         # 集成测试超时时间为5分钟
coverageSkipTestFiles = true

Output Format

输出格式

All Passing

全部通过

✓ TypeScript: 0 errors
✓ Lint: Clean
✓ Tests: XX passed
✓ Coverage: XX% (if explicitly run)
✓ Build: Success
━━━━━━━━━━━━━━━━━━━━━━
Ready to commit!
✓ TypeScript: 0个错误
✓ 代码检查:无问题
✓ 测试:XX个通过
✓ 覆盖率:XX%(若显式运行)
✓ 构建:成功
━━━━━━━━━━━━━━━━━━━━━━
可提交!

Failures

存在失败项

✗ TypeScript: X errors
  - src/file.ts:42 - Error message

✗ Tests: X failed
  - test/file.test.ts - Test name
    Expected: X
    Received: Y

━━━━━━━━━━━━━━━━━━━━━━
BLOCKED: Fix issues before commit

✗ TypeScript: X个错误
  - src/file.ts:42 - 错误信息

✗ 测试:X个失败
  - test/file.test.ts - 测试名称
    预期值:X
    实际值:Y

━━━━━━━━━━━━━━━━━━━━━━
BLOCKED:修复问题后再提交

Quality Standards

质量标准

MetricMinimumTarget
TypeScript Errors00
Lint Errors00
Test Pass Rate100%100%
Coverage80%90%
BuildPassPass

指标最低要求目标值
TypeScript 错误数00
代码检查错误数00
测试通过率100%100%
代码覆盖率80%90%
构建结果通过通过

Why Bun-Only Matters

为何仅使用Bun至关重要

Process comparison per quality gate run:
CommandProcesses SpawnedMemory
pnpm run typecheck
pnpm + tsc = 2~200MB
bun run typecheck
bun only = 1~54MB
pnpm run test
pnpm + bun = 2~400MB
bun test
bun only = 1~54MB
With 3 agents running quality gates:
ApproachTotal ProcessesTotal Memory
pnpm (old)3 × 6 = 18~1.8GB
bun (new)3 × 3 = 9~162MB
Result: 90% memory reduction, 50% fewer processes

每次质量门禁运行的进程对比:
命令启动的进程数内存占用
pnpm run typecheck
pnpm + tsc = 2~200MB
bun run typecheck
bun 仅1个~54MB
pnpm run test
pnpm + bun = 2~400MB
bun test
bun 仅1个~54MB
3个代理同时运行质量门禁时:
方案总进程数总内存占用
pnpm(旧)3×6=18~1.8GB
bun(新)3×3=9~162MB
结果:内存占用减少90%,进程数减少50%

Why Serialization Matters

为何串行执行至关重要

Without flock (BROKEN):
Agent 1: bun run typecheck  → runs immediately
Agent 2: bun run typecheck  → runs in PARALLEL!
Agent 3: bun run lint       → runs in PARALLEL!
Result: 3+ heavy processes, potential overload
With flock (CORRECT):
Agent 1: flock ... bun run typecheck  → runs, holds lock
Agent 2: flock ... bun run typecheck  → WAITS for lock
Agent 3: flock ... bun run lint       → WAITS for lock
Result: Only 1 quality gate at a time

不使用flock(错误方式):
代理1:bun run typecheck → 立即运行
代理2:bun run typecheck → 并行运行!
代理3:bun run lint → 并行运行!
结果:3个及以上高负载进程,可能导致系统过载
使用flock(正确方式):
代理1:flock ... bun run typecheck → 运行并持有锁
代理2:flock ... bun run typecheck → 等待锁释放
代理3:flock ... bun run lint → 等待锁释放
结果:同一时间仅运行一个质量门禁

Quick Reference Card

速查卡片

undefined
undefined

ALWAYS CHECK RESOURCES FIRST

务必先检查资源

.claude/hooks/check-system-resources.sh || sleep 30
.claude/hooks/check-system-resources.sh || sleep 30

ALWAYS USE FLOCK

务必使用flock

LOCK="/tmp/rad-engineer-quality-gate.lock"
LOCK="/tmp/rad-engineer-quality-gate.lock"

ALWAYS USE BUN

务必使用Bun

flock -w 300 "$LOCK" bun run typecheck # NOT pnpm flock -w 300 "$LOCK" bun run lint # NOT npm flock -w 300 "$LOCK" bun test # NOT npx
flock -w 300 "$LOCK" bun run typecheck # 不要用pnpm flock -w 300 "$LOCK" bun run lint # 不要用npm flock -w 300 "$LOCK" bun test # 不要用npx

ONE-LINER (copy-paste ready)

一键命令(可直接复制粘贴)

cd rad-engineer && LOCK="/tmp/rad-engineer-quality-gate.lock" && flock -w 300 "$LOCK" sh -c 'bun run typecheck && bun run lint && bun test'

---

**Version**: 3.0.0 (Bun-Only + JIT Resource Check)
**Last Updated**: 2026-01-13
cd rad-engineer && LOCK="/tmp/rad-engineer-quality-gate.lock" && flock -w 300 "$LOCK" sh -c 'bun run typecheck && bun run lint && bun test'

---

**版本**:3.0.0(仅支持Bun + 实时资源检查)
**最后更新**:2026-01-13