agentsope/agentsop-repo-state-gating
>- A 5-minute gate the coder runs at project kickoff (and again whenever the repo shape changes). Classifies the workspace into Greenfield / Brownfield-large / Mid-size-familiar / Library-SDK, then maps the state to an agent strategy (autonomy, context primitive, tool choice). Use BEFORE picking Cursor vs Claude Code vs Aider, BEFORE turning on repo-map, BEFORE writing the first prompt. Skip only if the same repo was gated within the last day codebase, project setup strategy, legacy codebase agent, where to start a coding agent.
npx skills add https://github.com/agentsope/SkillAlchemy --skill agentsop-repo-state-gating
> 一句话:agent strategy = f(repo-state)。先判定 repo 状态,再选工具/上下文原语/自治程度。
> 跳过这一步 = 用错工具,浪费一个小时的上下文。
只在以下时刻跑一次(≤5 分钟):
cd 切到新目录、git clone 后第一次启动 agent)不要激活:
npx create-next-app 的仓库") → 仍写下结论,但 30 秒搞定> 不同 repo 状态,agent 的最佳武器不同。同一个 prompt 在 greenfield 里能跑通,在 brownfield 里会胡编路径;同一个 Aider 在 brownfield 里发光,在 greenfield 里失去 70% 价值。
状态 | 关键约束 | 最大杠杆 | 风险
----------------------+-------------------+---------------------+-------------------
Greenfield | 没有现成符号 | LM 自治 + scaffolder| 过度设计、目录漂移
Brownfield-large | 上下文炸 + 风格僵 | repo-map + 严格 /add| 修错文件、违反约定
Mid-size-familiar | 你脑里有图 | 最小上下文 + /ask | 多加文件稀释信号
Library / SDK | 你的代码即 API | 约定 + test-fix 环 | 破坏向后兼容
四个杠杆(按优先级递减):
| 假设错 | 症状 | 损失 |
|---|---|---|
| 把 brownfield 当 greenfield | LM 编造路径、违反隐含约定、改错文件 | 1–3 小时回滚 + 信任度 |
| 把 greenfield 当 brownfield | 等不到 repo-map 帮忙(图是空的)、纠结要不要 /add | 启动成本 + 错失 scaffolder |
| 把 library 当一般 brownfield | 改了公共 API 没改 changelog、破坏外部用户 | 隐性 bug,回归测试才能发现 |
| 把 mid-size-familiar 当 brownfield-large | 过度加载文件 / 反复扫 repo-map / token 爆 | 浪费的不是错误,而是 *慢* |
> 引用:Aider 自己声明,"For 'build me a new project from scratch' the repo-map is empty and the safety guarantees provide no marginal value." [aider-sop-skill/references/R4-anti-patterns.md §1]
> 引用:The General Partnership (2026):"legacy code doesn't come in neat, modular pieces… AI agent must learn the project's established patterns and not break things." [thegeneralpartnership.substack.com/p/a-practical-guide-to-brownfield-ai]
git log --oneline | wc -l # 提交数
git ls-files | wc -l # 跟踪文件数
ls -la # 顶层结构(package.json? pyproject? README? src/?)
可选第四个:git log --since='90 days ago' --oneline | wc -l(活跃度)
| Q | 选 A | 选 B |
|---|---|---|
| 1. git ls-files \| wc -l | < 20 → A | ≥ 20 → B |
| 2. 仓库里有公开/发布 API(PyPI、npm、SDK)? | 否 → A | 是 → B |
| 3. 你能不打开文件就说出主要模块名? | 否 → A | 是 → B |
| 4. 一次完整改动通常跨几个文件? | 1–3 → A | 4+ → B |
| 5. 风格约定写在哪?(CONVENTIONS.md / lint / package.json) | 没写过 → A | 有 → B |
Q1=A 且 Q5=A → Greenfield
Q2=B(公共 API 存在) → Library / SDK
Q1=B 且 Q3=A(不熟) → Brownfield-large
Q1=B 且 Q3=B(熟)且 Q4=A → Mid-size-familiar
其他 → Brownfield-large 兜底(最保守)
[repo-state: brownfield-large] tool=Aider, primitive=repo-map, autonomy=approve-each,
add-budget=2-5 files (<25k tok), convention=CONVENTIONS.md required.
> 这一行让 *下一次会话* 也能秒接,省去重新 gate。
op-1 gate-classify
trigger: 新会话进入仓库
rule: 跑 §3 Step 1 三命令 + §3 Step 2 五题 → 输出四态之一
op-2 greenfield-strategy
trigger: state=greenfield
rule:
- 工具: Claude Code / Cursor / 纯 LLM 对话;不要 Aider(repo-map 空)
- 原语: scaffolder 优先(create-next-app, cargo new, uv init, cookiecutter)
- 自治: 中-高;让 LM 一次产出多文件骨架
- 范围: 不限;但每生成 ~10 文件就 commit 一次
op-3 brownfield-large-strategy
trigger: state=brownfield-large
rule:
- 工具: Aider(repo-map 是核心杠杆) / Claude Code(长上下文兜底)
- 原语: 符号索引 / repo-map / ctags / tree-sitter;先 /ask 再 /code
- 自治: 低;每个 tool-call / 编辑都 approve
- 范围: /add 严格控制在 2–5 文件 + <25k tokens [aider edit-errors troubleshooting]
- 必读: CONVENTIONS.md(不存在就先建)
op-4 mid-size-familiar-strategy
trigger: state=mid-size-familiar
rule:
- 工具: Aider --architect 或 Claude Code(你脑里有图,工具只是杠杆)
- 原语: 你给定文件 + /read 约定文件;不浪费 repo-map 预算
- 自治: 中;/ask 先讨论方案,/code 再动手
- 范围: 1–3 文件,单次 commit
op-5 library-sdk-strategy
trigger: state=library-sdk
rule:
- 工具: Aider --auto-test 或 Claude Code with test runner
- 原语: test-fix 闭环最高价值;docstring 自动生成;semver 检查
- 自治: 低;改公共 API 必须人工确认
- 范围: 不只看本仓 — 同时看 CHANGELOG / migration guide
- 必备: 写 CONVENTIONS.md(API 命名风格、错误模式、deprecation 节奏)
op-6 state-reclassify
trigger: 跑了一周后仓库形态明显变了;或工具一直选错
rule: 重跑 op-1;如状态升级(greenfield→brownfield)则把第一行结论改写
op-7 cross-repo-multi-state
trigger: monorepo / 多包仓库
rule:
- 不跑整仓 gate,跑子目录 gate(cd packages/foo && 跑 op-1)
- 不同子目录可以有不同状态;agent 进入子目录时切策略
- Aider 用 --subtree-only;Claude Code 用 cwd 限定
op-8 state-mismatch-rescue
trigger: 已经开干,发现状态判错
rule:
- 立刻 /clear 或新会话,按对的状态重启
- 不要"将就着用"——错状态下省的 5 分钟 < 错工具浪费的 1 小时
完整操作目录见 intermediate/operation_candidates.json。
触发:项目从零,没 git history,团队主推 Aider。
5 题门禁:Q1=A(0 文件)、Q5=A(没写过)、Q3=A(无可言说)→ Greenfield。
结论:先用 npx create-next-app / cargo new / uv init 把骨架打出来,commit 一次。
然后才进 Aider,此时已经有了基础符号 + 约定 + tests,repo-map 才有内容可摸。
反模式:直接 aider --message "建个 Next.js + Postgres + Auth 项目" —— Aider 的 repo-map 是空的,git 安全保障建立在 *增量编辑* 上,对 *无中生有* 没价值。Paul Gauthier 自己也这么说。[aider-sop-skill/R4 §1]
教训:工具偏好 < 状态匹配。Aider 是好工具,但不是 *起步* 工具。
5 题门禁:Q1=B(800 文件)、Q3=A(不熟)、Q5=B(有 pylintrc + 历史约定)→ Brownfield-large。
结论:
/ask which files implement current auth?反模式 A:用 Cursor "全仓索引" 一把梭 —— 索引会过期,向量检索精度不如符号图,且无法 *选择性* 编辑写集合。
反模式 B:把 50 个相关文件都 /add 进来 —— token 直接破 25k,模型蒸馏度断崖。
5 题门禁:Q2=B(已 pip install 过)→ Library / SDK。
结论:
--auto-test:每次编辑后自动跑 pytest,新方法没测试会立刻暴露。DeprecationWarning + 双路径。反模式:当成普通 brownfield 处理,跳过 semver 检查 / 不更新 docs → 下次用户升级炸了,且 bug 不显式(只是 import 路径变了)。
5 题门禁:复杂——Dify 本体是 brownfield-large,但你的 *自定义节点* 是 greenfield。
结论:多状态共存,跑 op-7。
dify-plugins/my-plugin/ 子目录里:greenfield,按 op-2 走。底线:Dify 提供 code escape hatch 正是给这种场景 —— 但 escape 出去后那段代码是新写的、独立的,不要把 Dify 编排习惯(visual canvas)带进来。 [dify-sop-skill §A6 escape-hatch]
git init 就配 Aider + repo-map + CONVENTIONS.md —— scaffolder 一行命令的事,何必?d-repo-map-skill(brownfield 大杀器)、aider-sop-skill(具体命令)、scaffolder 工具集(greenfield)。| 状态 | Claude Code | Cline | Cursor | Aider |
|---|---|---|---|---|
| Greenfield | 强;1M 上下文承载多文件骨架生成 | 中;每个 file-write 要 approve,慢 | 强(officially 推荐 greenfield)[scrimba 2026] | 弱;repo-map 空,价值缺失 [aider R4 §1] |
| Brownfield-large | 强;long-context 兜底 + agent loop | 强;逐步 approve 适合不熟仓 | 中;index 易过期,符号精度 < tree-sitter | 最强;repo-map + /add 写集合是为此而生 |
| Mid-size-familiar | 强;你脑里有图,可以放手让它跑 | 中;approve 摩擦在熟仓里反而是噪声 | 强;ghost-text + composer 顺手 | 强;--architect 模式 + /ask /code 极简 |
| Library / SDK | 强;写 docstring + test 的 loop 很顺 | 中;适合人工把关 API 变更 | 中;缺 test-fix 内建闭环 | 强;--auto-test + per-edit commit 是 SDK 维护的甜区 |
> 决策行:选工具不要看 "哪个最强",要看 你的状态下哪个强。Aider 在 brownfield 是首选,在 greenfield 是反模式 —— 同一个工具。
Take agentsope/agentsop-repo-state-gating from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.
The instructions reference pip, npx.
Without those the skill loads but fails at the first command.