Squad 代码库规范
squad-conventions
Squad 代码库中使用的核心约定和模式。
- License 许可
- MIT
- 所属仓库
- spboyer/sensei
- 最近更新
- 2026-11-14
- Stars
- ★ 60
- Forks
- 8
01 前言 Front Matter
- name
- squad-conventions
- domain
- project-conventions
- source
- manual
- confidence
- high
- description
- Core conventions and patterns used in the Squad codebase
03 SKILL.md 正文
Context
These conventions apply to all work on the Squad CLI tool (create-squad). Squad is a zero-dependency Node.js package that adds AI agent teams to any project. Understanding these patterns is essential before modifying any Squad source code.
Patterns
Zero Dependencies
Squad has zero runtime dependencies. Everything uses Node.js built-ins (fs, path, os, child_process). Do not add packages to dependencies in package.json. This is a hard constraint, not a preference.
Node.js Built-in Test Runner
Tests use node:test and node:assert/strict — no test frameworks. Run with npm test. Test files live in test/. The test command is node --test test/.
Error Handling — fatal() Pattern
All user-facing errors use the fatal(msg) function which prints a red ✗ prefix and exits with code 1. Never throw unhandled exceptions or print raw stack traces. The global uncaughtException handler calls fatal() as a safety net.
ANSI Color Constants
Colors are defined as constants at the top of index.js: GREEN, RED, DIM, BOLD, RESET. Use these constants — do not inline ANSI escape codes.
File Structure
.ai-team/— Team state (user-owned, never overwritten by upgrades).ai-team-templates/— Template files copied fromtemplates/(Squad-owned, overwritten on upgrade).github/agents/squad.agent.md— Coordinator prompt (Squad-owned, overwritten on upgrade)templates/— Source templates shipped with the npm package.ai-team/skills/— Team skills in SKILL.md format (user-owned).ai-team/decisions/inbox/— Drop-box for parallel decision writes
Windows Compatibility
Always use path.join() for file paths — never hardcode / or \ separators. Squad must work on Windows, macOS, and Linux. All tests must pass on all platforms.
Init Idempotency
The init flow uses a skip-if-exists pattern: if a file or directory already exists, skip it and report "already exists." Never overwrite user state during init. The upgrade flow overwrites only Squad-owned files.
Copy Pattern
copyRecursive(src, target) handles both files and directories. It creates parent directories with { recursive: true } and uses fs.copyFileSync for files.
Examples
// Error handling
function fatal(msg) {
console.error(`${RED}✗${RESET} ${msg}`);
process.exit(1);
}
// File path construction (Windows-safe)
const agentDest = path.join(dest, '.github', 'agents', 'squad.agent.md');
// Skip-if-exists pattern
if (!fs.existsSync(ceremoniesDest)) {
fs.copyFileSync(ceremoniesSrc, ceremoniesDest);
console.log(`${GREEN}✓${RESET} .ai-team/ceremonies.md`);
} else {
console.log(`${DIM}ceremonies.md already exists — skipping${RESET}`);
}
Anti-Patterns
- Adding npm dependencies — Squad is zero-dep. Use Node.js built-ins only.
- Hardcoded path separators — Never use
/or\directly. Alwayspath.join(). - Overwriting user state on init — Init skips existing files. Only upgrade overwrites Squad-owned files.
- Raw stack traces — All errors go through
fatal(). Users see clean messages, not stack traces. - Inline ANSI codes — Use the color constants (
GREEN,RED,DIM,BOLD,RESET).
04 同仓库更多 Skills
文件处理示例技能
sample-skill
用于处理文件的实用工具
智能体技能改进与评估
sensei
**工作流技能** —— 通过可移植验证、主机配置(host profiles)、资源分析和行为证据来改进与评估智能体技能(Agent Skills)。适用场景:「run sensei」「sensei help」「improve skill」「fix frontmatter」「score skill」「analyze skill」「evaluate skill」。调用工具:Sensei CLI、测试运行器、git。单次操作:直接使用 Sensei CLI。
{技能名称}
{skill-name}
{本技能教给智能体的内容}