gsd-2-agent-framework
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGSD 2 — Autonomous Spec-Driven Agent Framework
GSD 2 — 自主规范驱动Agent框架
Skill by ara.so — Daily 2026 Skills collection
GSD 2 is a standalone CLI that turns a structured spec into running software autonomously. It controls the agent harness directly — managing fresh context windows per task, git worktree isolation, crash recovery, cost tracking, and stuck detection — rather than relying on LLM self-loops. One command, walk away, come back to a built project with clean git history.
由ara.so提供的Skill — 2026每日Skill合集
GSD 2是一款独立CLI工具,可将结构化规范自动转换为可运行的软件。它直接控制Agent管理机制——为每个任务管理全新的上下文窗口、git工作树隔离、崩溃恢复、成本追踪以及停滞检测——而非依赖LLM自循环。只需一条命令,无需干预,返回时即可获得带有清晰git历史的已构建项目。
Installation
安装
bash
npm install -g gsd-piRequires Node.js 18+. Works with Claude (Anthropic) as the underlying model via the Pi SDK.
bash
npm install -g gsd-pi需要Node.js 18+版本。通过Pi SDK,可搭配Claude(Anthropic)作为底层模型使用。
Core Concepts
核心概念
Work Hierarchy
工作层级
Milestone → a shippable version (4–10 slices)
Slice → one demoable vertical capability (1–7 tasks)
Task → one context-window-sized unit of workIron rule: A task must fit in one context window. If it can't, split it into two tasks.
Milestone(里程碑) → 可交付版本(包含4-10个Slice)
Slice(切片) → 可演示的垂直功能模块(包含1-7个Task)
Task(任务) → 单个上下文窗口可容纳的工作单元铁则:单个任务必须能放入一个上下文窗口。如果无法容纳,就拆分为两个任务。
Directory Layout
目录结构
project/
├── .gsd/
│ ├── STATE.md # current auto-mode position
│ ├── DECISIONS.md # architecture decisions register
│ ├── LOCK # crash recovery lock file
│ ├── milestones/
│ │ └── M1/
│ │ ├── slices/
│ │ │ └── S1/
│ │ │ ├── PLAN.md # task breakdown with must-haves
│ │ │ ├── RESEARCH.md # codebase/doc scouting output
│ │ │ ├── SUMMARY.md # completion summary
│ │ │ └── tasks/
│ │ │ └── T1/
│ │ │ ├── PLAN.md
│ │ │ └── SUMMARY.md
│ └── costs/
│ └── ledger.json # per-unit token/cost tracking
├── ROADMAP.md # milestone/slice structure
└── PROJECT.md # project description and goalsproject/
├── .gsd/
│ ├── STATE.md # 当前自动模式位置
│ ├── DECISIONS.md # 架构决策记录
│ ├── LOCK # 崩溃恢复锁文件
│ ├── milestones/
│ │ └── M1/
│ │ ├── slices/
│ │ │ └── S1/
│ │ │ ├── PLAN.md # 包含必备项的任务分解
│ │ │ ├── RESEARCH.md # 代码库/文档调研输出
│ │ │ ├── SUMMARY.md # 完成总结
│ │ │ └── tasks/
│ │ │ └── T1/
│ │ │ ├── PLAN.md
│ │ │ └── SUMMARY.md
│ └── costs/
│ └── ledger.json # 按单元统计的Token/成本记录
├── ROADMAP.md # 里程碑/切片结构
└── PROJECT.md # 项目描述与目标Commands
命令
/gsd auto
— Primary Autonomous Mode
/gsd auto/gsd auto
— 核心自主模式
/gsd autoRun the full automation loop. Reads , dispatches each unit in a fresh session, handles recovery, and advances through the entire milestone without intervention.
.gsd/STATE.mdbash
/gsd auto运行完整自动化循环。读取,在全新会话中调度每个单元,处理恢复操作,无需干预即可推进整个里程碑。
.gsd/STATE.mdbash
/gsd autoor with options:
或带参数运行:
/gsd auto --budget 5.00 # pause if cost exceeds $5
/gsd auto --milestone M1 # run only milestone 1
/gsd auto --dry-run # show dispatch plan without executing
undefined/gsd auto --budget 5.00 # 若成本超过5美元则暂停
/gsd auto --milestone M1 # 仅运行里程碑1
/gsd auto --dry-run # 显示调度计划但不执行
undefined/gsd init
— Initialize a Project
/gsd init/gsd init
— 初始化项目
/gsd initScaffold the directory from a and optional .
.gsd/ROADMAP.mdPROJECT.mdbash
/gsd initCreates initial , registers milestones and slices from your roadmap, sets up the cost ledger.
STATE.md从和可选的搭建目录。
ROADMAP.mdPROJECT.md.gsd/bash
/gsd init创建初始的,从路线图中注册里程碑和切片,设置成本台账。
STATE.md/gsd status
— Dashboard
/gsd status/gsd status
— 仪表盘
/gsd statusShows current position, per-slice costs, token usage, and what's queued next.
bash
/gsd statusOutput example:
Milestone 1: Auth System [3/5 slices complete]
✓ S1: User model + migrations
✓ S2: Password auth endpoints
✓ S3: JWT session management
→ S4: OAuth integration [PLANNING]
S5: Role-based access control
Cost: $1.84 / $5.00 budget
Tokens: 142k input, 38k output显示当前进度、各切片成本、Token使用量以及待处理任务。
bash
/gsd status输出示例:
Milestone 1: 认证系统 [5个切片已完成3个]
✓ S1: 用户模型 + 迁移
✓ S2: 密码认证端点
✓ S3: JWT会话管理
→ S4: OAuth集成 [规划中]
S5: 基于角色的访问控制
成本:1.84美元 / 预算5.00美元
Token:输入142k,输出38k/gsd run
— Single Unit Dispatch
/gsd run/gsd run
— 单个单元调度
/gsd runExecute one specific unit manually instead of running the full loop.
bash
/gsd run --slice M1/S4 # run research + plan + execute for a slice
/gsd run --task M1/S4/T2 # run a single task
/gsd run --phase research M1/S4 # run just the research phase
/gsd run --phase plan M1/S4 # run just the planning phase手动执行特定单元,而非运行完整循环。
bash
/gsd run --slice M1/S4 # 运行切片的调研+规划+执行流程
/gsd run --task M1/S4/T2 # 运行单个任务
/gsd run --phase research M1/S4 # 仅运行调研阶段
/gsd run --phase plan M1/S4 # 仅运行规划阶段/gsd migrate
— Migrate from v1
/gsd migrate/gsd migrate
— 从v1版本迁移
/gsd migrateImport old directories from the original Get Shit Done.
.planning/bash
/gsd migrate # migrate current directory
/gsd migrate ~/projects/old-project # migrate specific path从初代Get Shit Done导入旧的目录。
.planning/bash
/gsd migrate # 迁移当前目录
/gsd migrate ~/projects/old-project # 迁移指定路径/gsd costs
— Cost Report
/gsd costs/gsd costs
— 成本报告
/gsd costsDetailed cost breakdown with projections.
bash
/gsd costs
/gsd costs --by-phase
/gsd costs --by-slice
/gsd costs --export costs.csv包含预测的详细成本 breakdown。
bash
/gsd costs
/gsd costs --by-phase
/gsd costs --by-slice
/gsd costs --export costs.csvProject Setup
项目设置
1. Write ROADMAP.md
ROADMAP.md1. 编写ROADMAP.md
ROADMAP.mdmarkdown
undefinedmarkdown
undefinedMy Project Roadmap
我的项目路线图
Milestone 1: Core API
Milestone 1: 核心API
S1: Database schema and migrations
S1: 数据库 schema 与迁移
Set up Postgres schema for users, posts, and comments.
为用户、文章和评论设置Postgres schema。
S2: REST endpoints
S2: REST端点
CRUD endpoints for all resources with validation.
为所有资源提供带验证的CRUD端点。
S3: Authentication
S3: 认证
JWT-based auth with refresh tokens.
基于JWT的认证,支持刷新令牌。
Milestone 2: Frontend
Milestone 2: 前端
S1: React app scaffold
S1: React应用脚手架
...
undefined...
undefined2. Write PROJECT.md
PROJECT.md2. 编写PROJECT.md
PROJECT.mdmarkdown
undefinedmarkdown
undefinedMy Project
我的项目
A REST API for a blogging platform built with Express + TypeScript + Postgres.
基于Express + TypeScript + Postgres构建的博客平台REST API。
Tech Stack
技术栈
- Node.js 20, TypeScript 5
- Express 4
- PostgreSQL 15 via pg + kysely
- Jest for tests
- Node.js 20, TypeScript 5
- Express 4
- PostgreSQL 15(通过pg + kysely)
- Jest用于测试
Conventions
约定
- All endpoints return envelope
{ data, error } - Database migrations in
db/migrations/ - Feature modules in
src/features/<name>/
undefined- 所有端点返回格式
{ data, error } - 数据库迁移文件存于
db/migrations/ - 功能模块存于
src/features/<name>/
undefined3. Initialize
3. 初始化
bash
/gsd initbash
/gsd init4. Run
4. 运行
bash
/gsd autobash
/gsd autoThe Auto-Mode State Machine
自动模式状态机
Research → Plan → Execute (per task) → Complete → Reassess → Next SliceEach phase runs in a fresh session with context pre-inlined into the dispatch prompt:
| Phase | What the LLM receives | What it produces |
|---|---|---|
| Research | PROJECT.md, ROADMAP.md, slice description, codebase index | RESEARCH.md with findings, gotchas, relevant files |
| Plan | Research output, slice description, must-haves | PLAN.md with task breakdown, verification steps |
| Execute (task N) | Task plan, prior task summaries, dependency summaries, DECISIONS.md | Working code committed to git |
| Complete | All task summaries, slice plan | SUMMARY.md, UAT script, updated ROADMAP.md |
| Reassess | Completed slice summary, full ROADMAP.md | Updated roadmap with any corrections |
调研 → 规划 → 执行(按任务) → 完成 → 重新评估 → 下一切片每个阶段都在全新会话中运行,上下文预先内联到调度提示词中:
| 阶段 | LLM接收内容 | LLM产出内容 |
|---|---|---|
| 调研 | PROJECT.md、ROADMAP.md、切片描述、代码库索引 | 包含调研结果、注意事项、相关文件的RESEARCH.md |
| 规划 | 调研输出、切片描述、必备项 | 包含任务分解、验证步骤的PLAN.md |
| 执行(任务N) | 任务规划、之前的任务总结、依赖总结、DECISIONS.md | 已提交到git的可运行代码 |
| 完成 | 所有任务总结、切片规划 | SUMMARY.md、用户验收测试脚本、更新后的ROADMAP.md |
| 重新评估 | 已完成切片总结、完整ROADMAP.md | 包含修正内容的更新后路线图 |
Must-Haves: Mechanically Verifiable Outcomes
必备项:可机械验证的结果
Every task plan includes must-haves — explicit, checkable criteria the LLM uses to confirm completion. Write them as shell commands or file existence checks:
markdown
undefined每个任务规划都包含必备项——LLM用于确认完成情况的明确、可检查标准。以shell命令或文件存在性检查的形式编写:
markdown
undefinedMust-Haves
必备项
- passes with 0 failures
npm test -- --testPathPattern=auth - File exists and exports
src/features/auth/jwt.ts,signTokenverifyToken - returns 200 with
curl -X POST http://localhost:3000/auth/login{ data: { token } } - No TypeScript errors: exits 0
npx tsc --noEmit
The execute phase ends only when the LLM can check off every must-have.
---- 执行通过,无失败
npm test -- --testPathPattern=auth - 文件存在并导出
src/features/auth/jwt.ts、signTokenverifyToken - 返回200状态码及
curl -X POST http://localhost:3000/auth/login{ data: { token } } - 无TypeScript错误:退出码为0
npx tsc --noEmit
只有当LLM能勾选所有必备项时,执行阶段才会结束。
---Git Strategy
Git策略
GSD manages git automatically in auto mode:
main
└── milestone/M1 ← worktree branch created at start
├── commit: [M1/S1/T1] implement user model
├── commit: [M1/S1/T2] add migrations
├── commit: [M1/S1] slice complete
├── commit: [M1/S2/T1] POST /users endpoint
└── ...
After milestone complete:
main ← squash merge of milestone/M1 as "[M1] Auth system"Each task commits with a structured message. Each slice commits a summary commit. The milestone squash-merges to main as one clean entry.
GSD在自动模式下自动管理git:
main
└── milestone/M1 ← 开始时创建的工作树分支
├── commit: [M1/S1/T1] 实现用户模型
├── commit: [M1/S1/T2] 添加迁移
├── commit: [M1/S1] 切片完成
├── commit: [M1/S2/T1] POST /users端点
└── ...
里程碑完成后:
main ← 将milestone/M1合并为一个干净的提交:"[M1] 认证系统"每个任务都以结构化信息提交。每个切片都有一个总结提交。里程碑以一个干净的条目合并到main分支。
Crash Recovery
崩溃恢复
GSD writes a lock file at when a unit starts and removes it on clean completion. If the process dies:
.gsd/LOCKbash
undefinedGSD在单元启动时会在写入锁文件,正常完成后删除该文件。如果进程意外终止:
.gsd/LOCKbash
undefinedNext run detects the lock and auto-recovers:
下次运行时会检测到锁文件并自动恢复:
/gsd auto
/gsd auto
Output:
输出:
⚠ Lock file found: M1/S3/T2 was interrupted
⚠ 检测到锁文件:M1/S3/T2被中断
Synthesizing recovery briefing from session artifacts...
正在从会话工件中生成恢复简报...
Resuming with full context
恢复完整上下文后继续运行
The recovery briefing is synthesized from every tool call that reached disk — file writes, shell output, partial completions — so the resumed session has context continuity.
---
恢复简报会从所有已写入磁盘的工具调用中合成——包括文件写入、shell输出、部分完成内容——因此恢复后的会话具有上下文连续性。
---Cost Controls
成本控制
Set a budget ceiling to pause auto mode before overspending:
bash
/gsd auto --budget 10.00The cost ledger at :
.gsd/costs/ledger.jsonjson
{
"units": [
{
"id": "M1/S1/research",
"model": "claude-opus-4",
"inputTokens": 12400,
"outputTokens": 3200,
"costUsd": 0.21,
"completedAt": "2025-01-15T10:23:44Z"
}
],
"totalCostUsd": 1.84,
"budgetUsd": 10.00
}设置预算上限,防止超支时自动模式继续运行:
bash
/gsd auto --budget 10.00成本台账位于:
.gsd/costs/ledger.jsonjson
{
"units": [
{
"id": "M1/S1/research",
"model": "claude-opus-4",
"inputTokens": 12400,
"outputTokens": 3200,
"costUsd": 0.21,
"completedAt": "2025-01-15T10:23:44Z"
}
],
"totalCostUsd": 1.84,
"budgetUsd": 10.00
}Decisions Register
决策记录
.gsd/DECISIONS.mdmarkdown
undefined.gsd/DECISIONS.mdmarkdown
undefinedDecisions Register
决策记录
D1: Use kysely not prisma
D1: 使用kysely而非prisma
Date: 2025-01-14
Reason: Better TypeScript inference, no code generation step needed.
Impact: All DB queries use kysely QueryBuilder syntax.
日期: 2025-01-14
原因: 更好的TypeScript类型推断,无需代码生成步骤。
影响: 所有数据库查询使用kysely QueryBuilder语法。
D2: JWT in httpOnly cookie, not Authorization header
D2: JWT存储在httpOnly cookie中,而非Authorization头
Date: 2025-01-14
Reason: Better XSS protection for the web client. Impact: Auth middleware reads.
Reason: Better XSS protection for the web client. Impact: Auth middleware reads
req.cookies.token
---日期: 2025-01-14
原因: 为Web客户端提供更好的XSS防护。 影响: 认证中间件读取。
原因: 为Web客户端提供更好的XSS防护。 影响: 认证中间件读取
req.cookies.token
---Stuck Detection
停滞检测
If the same unit dispatches twice without producing its expected artifact, GSD:
- Retries once with a deep diagnostic prompt that includes what was expected vs. what exists on disk
- If the second attempt fails, stops auto mode and reports:
✗ Stuck on M1/S3/T1 after 2 attempts
Expected: src/features/auth/jwt.ts (not found)
Last session: .gsd/sessions/M1-S3-T1-attempt2.log
Run `/gsd run --task M1/S3/T1` to retry manually如果同一单元调度两次仍未生成预期工件,GSD会:
- 重试一次,使用深度诊断提示词,包含预期内容与磁盘实际存在内容的对比
- 如果第二次尝试失败,停止自动模式并报告:
✗ M1/S3/T1尝试2次后停滞
预期:src/features/auth/jwt.ts(未找到)
上次会话:.gsd/sessions/M1-S3-T1-attempt2.log
运行`/gsd run --task M1/S3/T1`手动重试Skills Integration
Skill集成
GSD supports auto-detecting and installing relevant skills during the research phase. Create in your project:
SKILLS.mdmarkdown
undefinedGSD支持在调研阶段自动检测并安装相关Skill。在项目中创建:
SKILLS.mdmarkdown
undefinedProject Skills
项目Skills
- name: postgres-kysely
- name: express-typescript
- name: jest-testing
Skills are injected into the research and plan dispatch prompts, giving the LLM curated knowledge about your exact stack without burning context on irrelevant docs.
---- name: postgres-kysely
- name: express-typescript
- name: jest-testing
Skills会被注入到调研和规划调度提示词中,为LLM提供与你的技术栈完全匹配的精选知识,无需在无关文档上消耗上下文。
---Timeout Supervision
超时监控
Three timeout tiers prevent runaway sessions:
| Timeout | Default | Behavior |
|---|---|---|
| Soft | 8 min | Sends "please wrap up" steering message |
| Idle | 3 min no tool calls | Sends "are you stuck?" recovery prompt |
| Hard | 15 min | Pauses auto mode, preserves all disk state |
Configure in :
.gsd/config.jsonjson
{
"timeouts": {
"softMinutes": 8,
"idleMinutes": 3,
"hardMinutes": 15
},
"defaultModel": "claude-opus-4",
"researchModel": "claude-sonnet-4"
}三级超时机制防止会话失控:
| 超时类型 | 默认值 | 行为 |
|---|---|---|
| 软超时 | 8分钟 | 发送“请尽快完成”的引导消息 |
| 空闲超时 | 3分钟无工具调用 | 发送“是否停滞?”的恢复提示词 |
| 硬超时 | 15分钟 | 暂停自动模式,保留所有磁盘状态 |
可在中配置:
.gsd/config.jsonjson
{
"timeouts": {
"softMinutes": 8,
"idleMinutes": 3,
"hardMinutes": 15
},
"defaultModel": "claude-opus-4",
"researchModel": "claude-sonnet-4"
}TypeScript Integration (Pi SDK)
TypeScript集成(Pi SDK)
GSD is built on the Pi SDK. You can extend it programmatically:
typescript
import { GSDProject, AutoRunner } from 'gsd-pi';
const project = await GSDProject.load('/path/to/project');
// Check current state
const state = await project.getState();
console.log(state.currentMilestone, state.currentSlice);
// Run a single slice programmatically
const runner = new AutoRunner(project, {
budget: 5.00,
onUnitComplete: (unit, cost) => {
console.log(`Completed ${unit.id}, cost: $${cost.toFixed(3)}`);
},
onStuck: (unit, attempts) => {
console.error(`Stuck on ${unit.id} after ${attempts} attempts`);
process.exit(1);
}
});
await runner.runSlice('M1/S4');GSD基于Pi SDK构建。你可以通过编程方式扩展它:
typescript
import { GSDProject, AutoRunner } from 'gsd-pi';
const project = await GSDProject.load('/path/to/project');
// 检查当前状态
const state = await project.getState();
console.log(state.currentMilestone, state.currentSlice);
// 以编程方式运行单个切片
const runner = new AutoRunner(project, {
budget: 5.00,
onUnitComplete: (unit, cost) => {
console.log(`已完成 ${unit.id},成本:$${cost.toFixed(3)}`);
},
onStuck: (unit, attempts) => {
console.error(`${unit.id}尝试${attempts}次后停滞`);
process.exit(1);
}
});
await runner.runSlice('M1/S4');Custom Dispatch Hooks
自定义调度钩子
Inject custom context into any dispatch prompt:
typescript
// .gsd/hooks.ts
import type { DispatchHook } from 'gsd-pi';
export const beforeTaskDispatch: DispatchHook = async (ctx) => {
// Append custom context to every task dispatch
return {
...ctx,
extraContext: `将自定义上下文注入任何调度提示词:
typescript
// .gsd/hooks.ts
import type { DispatchHook } from 'gsd-pi';
export const beforeTaskDispatch: DispatchHook = async (ctx) => {
// 为每个任务调度追加自定义上下文
return {
...ctx,
extraContext: `Live API Docs
实时API文档
${await fetchInternalAPIDocs()}
`
};
};
Register in `.gsd/config.json`:
```json
{
"hooks": "./hooks.ts"
}${await fetchInternalAPIDocs()}
`
};
};
在`.gsd/config.json`中注册:
```json
{
"hooks": "./hooks.ts"
}Roadmap Reassessment
路线图重新评估
After each slice completes, GSD runs a reassessment pass that may:
- Re-order upcoming slices based on discovered dependencies
- Split a slice that turned out larger than expected
- Mark a slice as no longer needed
- Add a new slice for discovered work
The LLM edits in place. You can review diffs with:
ROADMAP.mdbash
git diff ROADMAP.mdTo disable reassessment:
json
{
"reassessment": false
}每个切片完成后,GSD会运行重新评估流程,可能会:
- 根据发现的依赖关系重新排序后续切片
- 拆分实际规模超出预期的切片
- 标记不再需要的切片
- 为新发现的工作添加新切片
LLM会直接编辑。你可以通过以下命令查看差异:
ROADMAP.mdbash
git diff ROADMAP.md要禁用重新评估:
json
{
"reassessment": false
}Troubleshooting
故障排除
Auto mode stops immediately with "no pending slices"
自动模式立即停止,提示“无待处理切片”
All slices in are marked . Reset a slice: remove from its entry and delete .
ROADMAP.md[x][x].gsd/milestones/M1/slices/S3/SUMMARY.mdROADMAP.md[x][x].gsd/milestones/M1/slices/S3/SUMMARY.mdLLM keeps failing must-haves
LLM始终无法完成必备项
Check for the last session log. Common causes: must-have references wrong file path, or test command needs environment variable. Adjust must-haves in the task's and re-run with .
.gsd/sessions/PLAN.md/gsd run --task M1/S3/T2查看中的最后会话日志。常见原因:必备项引用了错误的文件路径,或测试命令需要环境变量。调整任务中的必备项,然后运行重新执行。
.gsd/sessions/PLAN.md/gsd run --task M1/S3/T2Cost ceiling hit unexpectedly
意外触发成本上限
The research phase on large codebases can be expensive. Set to a cheaper model in config, or reduce codebase index depth.
researchModel大型代码库的调研阶段成本可能较高。在配置中将设置为更便宜的模型,或减少代码库索引深度。
researchModelLock file left after clean exit
正常退出后仍残留锁文件
bash
rm .gsd/LOCK
/gsd autobash
rm .gsd/LOCK
/gsd autoGit worktree conflicts
Git工作树冲突
bash
git worktree list # see active worktrees
git worktree remove .gsd/worktrees/M1 --force
/gsd auto # recreates cleanlybash
git worktree list # 查看活跃工作树
git worktree remove .gsd/worktrees/M1 --force
/gsd auto # 重新创建干净的工作树Session file too large for recovery
会话文件过大导致恢复失败
If grows large, GSD compresses sessions older than 24h automatically. Manual cleanup:
.gsd/sessions/bash
/gsd cleanup --sessions --older-than 7d如果过大,GSD会自动压缩24小时以上的旧会话。手动清理:
.gsd/sessions/bash
/gsd cleanup --sessions --older-than 7d