gsd-2-agent-framework

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

GSD 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-pi
Requires 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 work
Iron 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 goals

project/
├── .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
— 核心自主模式

Run the full automation loop. Reads
.gsd/STATE.md
, dispatches each unit in a fresh session, handles recovery, and advances through the entire milestone without intervention.
bash
/gsd auto
运行完整自动化循环。读取
.gsd/STATE.md
,在全新会话中调度每个单元,处理恢复操作,无需干预即可推进整个里程碑。
bash
/gsd auto

or 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
— 初始化项目

Scaffold the
.gsd/
directory from a
ROADMAP.md
and optional
PROJECT.md
.
bash
/gsd init
Creates initial
STATE.md
, registers milestones and slices from your roadmap, sets up the cost ledger.
ROADMAP.md
和可选的
PROJECT.md
搭建
.gsd/
目录。
bash
/gsd init
创建初始的
STATE.md
,从路线图中注册里程碑和切片,设置成本台账。

/gsd status
— Dashboard

/gsd status
— 仪表盘

Shows current position, per-slice costs, token usage, and what's queued next.
bash
/gsd status
Output 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
— 单个单元调度

Execute 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
— 从v1版本迁移

Import old
.planning/
directories from the original Get Shit Done.
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
— 成本报告

Detailed 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.csv

Project Setup

项目设置

1. Write
ROADMAP.md

1. 编写
ROADMAP.md

markdown
undefined
markdown
undefined

My 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
...
undefined

2. Write
PROJECT.md

2. 编写
PROJECT.md

markdown
undefined
markdown
undefined

My 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
    { data, error }
    envelope
  • Database migrations in
    db/migrations/
  • Feature modules in
    src/features/<name>/
undefined
  • 所有端点返回
    { data, error }
    格式
  • 数据库迁移文件存于
    db/migrations/
  • 功能模块存于
    src/features/<name>/
undefined

3. Initialize

3. 初始化

bash
/gsd init
bash
/gsd init

4. Run

4. 运行

bash
/gsd auto

bash
/gsd auto

The Auto-Mode State Machine

自动模式状态机

Research → Plan → Execute (per task) → Complete → Reassess → Next Slice
Each phase runs in a fresh session with context pre-inlined into the dispatch prompt:
PhaseWhat the LLM receivesWhat it produces
ResearchPROJECT.md, ROADMAP.md, slice description, codebase indexRESEARCH.md with findings, gotchas, relevant files
PlanResearch output, slice description, must-havesPLAN.md with task breakdown, verification steps
Execute (task N)Task plan, prior task summaries, dependency summaries, DECISIONS.mdWorking code committed to git
CompleteAll task summaries, slice planSUMMARY.md, UAT script, updated ROADMAP.md
ReassessCompleted slice summary, full ROADMAP.mdUpdated 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
undefined

Must-Haves

必备项

  • npm test -- --testPathPattern=auth
    passes with 0 failures
  • File
    src/features/auth/jwt.ts
    exists and exports
    signToken
    ,
    verifyToken
  • curl -X POST http://localhost:3000/auth/login
    returns 200 with
    { data: { token } }
  • No TypeScript errors:
    npx tsc --noEmit
    exits 0

The execute phase ends only when the LLM can check off every must-have.

---
  • npm test -- --testPathPattern=auth
    执行通过,无失败
  • 文件
    src/features/auth/jwt.ts
    存在并导出
    signToken
    verifyToken
  • curl -X POST http://localhost:3000/auth/login
    返回200状态码及
    { data: { token } }
  • 无TypeScript错误:
    npx tsc --noEmit
    退出码为0

只有当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
.gsd/LOCK
when a unit starts and removes it on clean completion. If the process dies:
bash
undefined
GSD在单元启动时会在
.gsd/LOCK
写入锁文件,正常完成后删除该文件。如果进程意外终止:
bash
undefined

Next 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.00
The cost ledger at
.gsd/costs/ledger.json
:
json
{
  "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.json
json
{
  "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.md
is auto-injected into every task dispatch. Record architectural decisions here and the LLM will respect them across all future sessions:
markdown
undefined
.gsd/DECISIONS.md
会自动注入到每个任务调度中。在此记录架构决策,LLM会在所有后续会话中遵循这些决策:
markdown
undefined

Decisions 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
req.cookies.token
.

---
日期: 2025-01-14
原因: 为Web客户端提供更好的XSS防护。 影响: 认证中间件读取
req.cookies.token

---

Stuck Detection

停滞检测

If the same unit dispatches twice without producing its expected artifact, GSD:
  1. Retries once with a deep diagnostic prompt that includes what was expected vs. what exists on disk
  2. 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会:
  1. 重试一次,使用深度诊断提示词,包含预期内容与磁盘实际存在内容的对比
  2. 如果第二次尝试失败,停止自动模式并报告:
✗ 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
SKILLS.md
in your project:
markdown
undefined
GSD支持在调研阶段自动检测并安装相关Skill。在项目中创建
SKILLS.md
markdown
undefined

Project 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:
TimeoutDefaultBehavior
Soft8 minSends "please wrap up" steering message
Idle3 min no tool callsSends "are you stuck?" recovery prompt
Hard15 minPauses auto mode, preserves all disk state
Configure in
.gsd/config.json
:
json
{
  "timeouts": {
    "softMinutes": 8,
    "idleMinutes": 3,
    "hardMinutes": 15
  },
  "defaultModel": "claude-opus-4",
  "researchModel": "claude-sonnet-4"
}

三级超时机制防止会话失控:
超时类型默认值行为
软超时8分钟发送“请尽快完成”的引导消息
空闲超时3分钟无工具调用发送“是否停滞?”的恢复提示词
硬超时15分钟暂停自动模式,保留所有磁盘状态
可在
.gsd/config.json
中配置:
json
{
  "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
ROADMAP.md
in place. You can review diffs with:
bash
git diff ROADMAP.md
To disable reassessment:
json
{
  "reassessment": false
}

每个切片完成后,GSD会运行重新评估流程,可能会:
  • 根据发现的依赖关系重新排序后续切片
  • 拆分实际规模超出预期的切片
  • 标记不再需要的切片
  • 为新发现的工作添加新切片
LLM会直接编辑
ROADMAP.md
。你可以通过以下命令查看差异:
bash
git diff ROADMAP.md
要禁用重新评估:
json
{
  "reassessment": false
}

Troubleshooting

故障排除

Auto mode stops immediately with "no pending slices"

自动模式立即停止,提示“无待处理切片”

All slices in
ROADMAP.md
are marked
[x]
. Reset a slice: remove
[x]
from its entry and delete
.gsd/milestones/M1/slices/S3/SUMMARY.md
.
ROADMAP.md
中的所有切片都已标记为
[x]
。重置切片:从条目中移除
[x]
并删除
.gsd/milestones/M1/slices/S3/SUMMARY.md

LLM keeps failing must-haves

LLM始终无法完成必备项

Check
.gsd/sessions/
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
PLAN.md
and re-run with
/gsd run --task M1/S3/T2
.
查看
.gsd/sessions/
中的最后会话日志。常见原因:必备项引用了错误的文件路径,或测试命令需要环境变量。调整任务
PLAN.md
中的必备项,然后运行
/gsd run --task M1/S3/T2
重新执行。

Cost ceiling hit unexpectedly

意外触发成本上限

The research phase on large codebases can be expensive. Set
researchModel
to a cheaper model in config, or reduce codebase index depth.
大型代码库的调研阶段成本可能较高。在配置中将
researchModel
设置为更便宜的模型,或减少代码库索引深度。

Lock file left after clean exit

正常退出后仍残留锁文件

bash
rm .gsd/LOCK
/gsd auto
bash
rm .gsd/LOCK
/gsd auto

Git worktree conflicts

Git工作树冲突

bash
git worktree list          # see active worktrees
git worktree remove .gsd/worktrees/M1 --force
/gsd auto                  # recreates cleanly
bash
git worktree list          # 查看活跃工作树
git worktree remove .gsd/worktrees/M1 --force
/gsd auto                  # 重新创建干净的工作树

Session file too large for recovery

会话文件过大导致恢复失败

If
.gsd/sessions/
grows large, GSD compresses sessions older than 24h automatically. Manual cleanup:
bash
/gsd cleanup --sessions --older-than 7d

如果
.gsd/sessions/
过大,GSD会自动压缩24小时以上的旧会话。手动清理:
bash
/gsd cleanup --sessions --older-than 7d

Links

链接