@astrosheep/keiyaku 0.1.76 → 0.1.78

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/README.md +88 -96
  2. package/build/.tsbuildinfo +1 -1
  3. package/build/config/apply-argument-descriptions.js +1 -1
  4. package/build/config/base-rules.js +14 -7
  5. package/build/config/dotenv.js +17 -11
  6. package/build/config/keiyaku-home.js +9 -0
  7. package/build/config/settings.js +41 -24
  8. package/build/config/term-presets/resolver.js +0 -3
  9. package/build/errno.js +3 -0
  10. package/build/flow-error.js +2 -0
  11. package/build/generated/version.js +1 -1
  12. package/build/git/diff/constants.js +1 -0
  13. package/build/git/diff/filter.js +3 -18
  14. package/build/git/diff/parsers.js +149 -61
  15. package/build/git/diff/preview.js +16 -2
  16. package/build/git/diff/read.js +32 -20
  17. package/build/git/snapshot.js +5 -24
  18. package/build/git/worktree.js +5 -4
  19. package/build/mcp/responses.js +3 -2
  20. package/build/mcp/server.js +61 -69
  21. package/build/protocol/draft-artifacts.js +2 -1
  22. package/build/protocol/file-guards.js +2 -1
  23. package/build/protocol/markdown/lex.js +52 -14
  24. package/build/protocol/markdown/normalization.js +3 -2
  25. package/build/protocol/markdown/parser.js +2 -2
  26. package/build/protocol/response-history.js +44 -5
  27. package/build/protocol/status-previews.js +20 -8
  28. package/build/protocol/summon-draft.js +3 -2
  29. package/build/protocol/summon-input.js +1 -0
  30. package/build/protocol/trace.js +1 -1
  31. package/build/tools/amend/index.js +11 -21
  32. package/build/tools/ask/index.js +11 -18
  33. package/build/tools/ask/persist.js +60 -37
  34. package/build/tools/ask/run.js +17 -7
  35. package/build/tools/create-handler.js +31 -0
  36. package/build/tools/drive/index.js +11 -24
  37. package/build/tools/drive/run.js +9 -5
  38. package/build/tools/petition/claim-gates.js +38 -9
  39. package/build/tools/petition/claim.js +20 -2
  40. package/build/tools/petition/forfeit.js +4 -1
  41. package/build/tools/petition/index.js +43 -58
  42. package/build/tools/petition/run.js +12 -0
  43. package/build/tools/round/head-guard.js +10 -0
  44. package/build/tools/round/incremental-diff.js +6 -2
  45. package/build/tools/round/report.js +24 -2
  46. package/build/tools/round/run.js +6 -0
  47. package/build/tools/round/worktree.js +6 -2
  48. package/build/tools/status/index.js +11 -24
  49. package/build/tools/status/read.js +6 -4
  50. package/build/tools/summon/index.js +17 -27
  51. package/build/tools/summon/run.js +21 -18
  52. package/package.json +6 -6
  53. package/build/git/diff/stat.js +0 -9
package/README.md CHANGED
@@ -1,148 +1,140 @@
1
1
  # Keiyaku
2
2
 
3
- Keiyaku is an MCP server that runs a contract-style workflow for AI-assisted coding in Git repos: isolate work on a dedicated `keiyaku/*` branch, iterate in rounds with review, then submit a final petition for judgment.
3
+ MCP serverAI 的代码改动跑在独立 branch 上,task 写进 repo,没你许可不准结束。
4
4
 
5
- This README is for users of the tool (MCP clients). It intentionally does not document repo maintenance workflows.
6
-
7
- ## Philosophy
5
+ ```bash
6
+ npm install -g @astrosheep/keiyaku
7
+ ```
8
8
 
9
- Keiyaku is opinionated on purpose:
9
+ ---
10
10
 
11
- - Isolation over “chat edits”: work happens on a dedicated `keiyaku/*` branch so your base branch stays clean.
12
- - Explicit contracts: the goal/rules/criteria live in `KEIYAKU.md` so “what are we doing?” is always answered by a file, not a scrolling chat.
13
- - Review-driven iteration: you drive the rounds; the tool optimizes for diffs and verification, not vibes.
14
- - Verdict-gated finish: the contract ends via `petition` (CLAIM/FORFEIT) so “done” is an explicit decision with gates (oath + scores).
11
+ ## 装之前
15
12
 
16
- ## When To Use Which Tool
13
+ 少一个都别来问为什么不能用:
17
14
 
18
- - Use `ask` for investigation: summarize, locate relevant code, run tests/scripts, debug a failure. No branch required.
19
- - Use `summon`/`drive` for non-trivial code changes that should be isolated and iterated.
20
- - Use `petition` only when you believe the criteria are met (CLAIM) or when you want to discard the contract (FORFEIT).
15
+ - **Git repo**,worktree 干净的。脏的不给用。
16
+ - **MCP client**。Claude Desktop、Claude Code、随便什么 stdio 的。
17
+ - **Subagent CLI**。[`claude`](https://docs.anthropic.com/en/docs/claude-code) [`gemini`](https://github.com/google-gemini/gemini-cli),装好,登录好。Keiyaku 自己不跑代码,全丢给 subprocess。没装 = 什么都不会发生。
21
18
 
22
- ## How It Works
19
+ ---
23
20
 
24
- Keiyaku formalizes a task into:
21
+ ## 配置
25
22
 
26
- - A signed contract (`KEIYAKU.md`) that defines goal, rules, and verification criteria
27
- - A round trace (`KEIYAKU_TRACE.md`) that records iterations
28
- - A final petition (`petition`) that requests a CLAIM or FORFEIT verdict
23
+ Claude Desktop (`~/Library/Application Support/Claude/claude_desktop_config.json`):
29
24
 
30
- Default workflow:
25
+ ```json
26
+ {
27
+ "mcpServers": {
28
+ "keiyaku": {
29
+ "command": "npx",
30
+ "args": ["-y", "@astrosheep/keiyaku"]
31
+ }
32
+ }
33
+ }
34
+ ```
31
35
 
32
- `ask` (anytime) | `summon` -> [`drive` | `ask`]* -> `petition`
36
+ 重启 client。打开 git repo。跑 `status`。完了。
33
37
 
34
- Typical loop:
38
+ ---
35
39
 
36
- 1. `summon`: provide `title`, `goal`, `criteria` (plus any rules/context). Repo must be clean.
37
- 2. Review the round output and repo diff.
38
- 3. `drive`: issue the next directive (fixes, refinements, tests, cleanup).
39
- 4. `ask`: optionally verify independently (tests, static checks, targeted inspection).
40
- 5. `petition`:
41
- - `CLAIM` to request acceptance (requires oath + 0-10 scores).
42
- - `FORFEIT` to abandon and discard the contract.
40
+ ## 流程
43
41
 
44
- ## Tools (Default Preset)
42
+ ```
43
+ ask (随时) | summon → [drive | ask]* → petition
44
+ ```
45
45
 
46
- Keiyaku registers the following MCP tools:
46
+ ---
47
47
 
48
- - `summon`: start a contract, create/enter a `keiyaku/*` branch, and write the initial protocol files
49
- - `drive`: run the next round (mutates the repo)
50
- - `ask`: stateless delegation (analysis, running tests/scripts, debugging). No keiyaku branch required.
51
- - `petition`: submit `CLAIM` or `FORFEIT` to close the contract (verdict-gated)
52
- - `status`: read-only contract/protocol status and readiness hints
53
- - `help`: usage guide and protocol notes
48
+ ## 工具
54
49
 
55
- Term presets: currently only `default` is supported (`KEIYAKU_TERM_PRESET=default`).
50
+ **`ask`** 问东西用的。不开 branch,不建 contract,随便用。
56
51
 
57
- ## Install / Run
52
+ ```
53
+ retry 逻辑在哪?跑一下那个文件的 unit test。
54
+ ```
58
55
 
59
- Global install:
56
+ ---
60
57
 
61
- ```bash
62
- npm install -g @astrosheep/keiyaku
63
- keiyaku --version
64
- ```
58
+ **`summon`** — 开 branch,写 contract。repo 必须干净。
65
59
 
66
- Via npx:
60
+ criteria 写多具体,结果就有多具体。写 "make it better" 就别怪 AI 自由发挥。
67
61
 
68
- ```bash
69
- npx -y @astrosheep/keiyaku --version
62
+ ```
63
+ summon:
64
+ title: "Retry logic for HTTP client"
65
+ goal: "5xx failures retry up to 3 times with exponential backoff"
66
+ criteria:
67
+ - Retry unit tests pass
68
+ - Public API unchanged
69
+ - Existing tests still pass
70
70
  ```
71
71
 
72
- ## MCP Setup
72
+ ---
73
73
 
74
- ### Claude Desktop (stdio)
74
+ **`drive`** 下一轮。看完 diff,说哪里不对,再跑一轮。
75
75
 
76
- ```json
77
- {
78
- "mcpServers": {
79
- "keiyaku": {
80
- "command": "npx",
81
- "args": ["-y", "@astrosheep/keiyaku"]
82
- }
83
- }
84
- }
85
76
  ```
86
-
87
- ### Streamable HTTP
88
-
89
- ```bash
90
- KEIYAKU_MCP_TRANSPORT=streamable-http \
91
- KEIYAKU_MCP_HTTP_HOST=127.0.0.1 \
92
- KEIYAKU_MCP_HTTP_PORT=3000 \
93
- npx -y @astrosheep/keiyaku
77
+ Backoff 是 1.5x,应该 2x。改掉,test 也更新。
94
78
  ```
95
79
 
96
- Endpoint: `http://127.0.0.1:3000/mcp`
80
+ ---
97
81
 
98
- ## What Gets Written To Your Repo
82
+ **`petition`** 结束 task。
99
83
 
100
- Keiyaku writes protocol artifacts into the target repository:
84
+ `CLAIM` = 我验证过了,criteria 全过了。`FORFEIT` = 不要了,全部丢掉。
101
85
 
102
- - `KEIYAKU.md`: the active contract (goal/rules/criteria)
103
- - `KEIYAKU_TRACE.md`: round-by-round trace
104
- - `KEIYAKU.draft.md`: optional recovery draft when start fails
105
- - `.keiyaku/response/*.md`: persisted responses for `summon`, `drive`, and `ask`
106
- - `.keiyaku/draft/*`: internal drafts (used for recovery and workflow safety)
86
+ 要打分 (0–10),要宣誓。gate 是真的会拒绝你的。没检查就别来。
107
87
 
108
- If you do not want these tracked, add:
88
+ ---
109
89
 
110
- - `.keiyaku/draft/`
111
- - `.keiyaku/response/`
90
+ **`status`** — 现在什么状态,什么在挡路。
112
91
 
113
- to `.gitignore`.
92
+ **`help`** — 完整参考。
114
93
 
115
- ## Key Environment Variables
94
+ ---
116
95
 
117
- Server / transport:
96
+ ## 写进 repo 的东西
118
97
 
119
- - `KEIYAKU_MCP_TRANSPORT`: `stdio` (default) or `streamable-http`
120
- - `KEIYAKU_MCP_HTTP_HOST`: default `127.0.0.1`
121
- - `KEIYAKU_MCP_HTTP_PORT`: default `3000`
98
+ | 文件 | |
99
+ |------|--|
100
+ | `KEIYAKU.md` | 当前 contract |
101
+ | `KEIYAKU_TRACE.md` | 每轮记录 |
102
+ | `KEIYAKU.draft.md` | summon 失败时的恢复用 draft |
103
+ | `.keiyaku/response/*.md` | 每轮输出 |
122
104
 
123
- Preset / naming:
105
+ 不想 track 就加 `.gitignore`:
124
106
 
125
- - `KEIYAKU_TERM_PRESET`: only `default` is supported
126
- - `KEIYAKU_SUBAGENT_NAME_OVERRIDE`: overrides the default subagent display name
107
+ ```gitignore
108
+ .keiyaku/draft/
109
+ .keiyaku/response/
110
+ ```
127
111
 
128
- Subagent execution:
112
+ ---
129
113
 
130
- - `KEIYAKU_DISABLE_SUBAGENT_SPAWN`: when `1`, blocks Keiyaku MCP server startup
131
- - `KEIYAKU_FAKE_SUBAGENT`: `0` | `1` | `abort-wait` (stub subagent execution)
132
- - `KEIYAKU_SUBAGENT_EXEC_TIMEOUT_MS`: total execution timeout for all providers
133
- - `KEIYAKU_SUBAGENT_EXEC_IDLE_TIMEOUT_MS`: idle timeout for all providers, reset by subprocess output or streamed SDK events
114
+ ## 进阶
134
115
 
135
- Workflow:
116
+ ```bash
117
+ keiyaku dump-env
118
+ ```
136
119
 
137
- - `KEIYAKU_INCREMENTAL_DIFF_MODE`: `targeted` (default) | `stat` | `unified`
138
- - `KEIYAKU_CLOSE_OATH`: overrides the required petition oath template
120
+ | 变量 | 默认值 | |
121
+ |------|--------|--|
122
+ | `KEIYAKU_MCP_TRANSPORT` | `stdio` | `stdio` 或 `streamable-http` |
123
+ | `KEIYAKU_MCP_HTTP_PORT` | `3000` | HTTP 端口 |
124
+ | `KEIYAKU_SUBAGENT_EXEC_TIMEOUT_MS` | — | 执行超时 |
125
+ | `KEIYAKU_SUBAGENT_EXEC_IDLE_TIMEOUT_MS` | — | 空闲超时 |
126
+ | `KEIYAKU_INCREMENTAL_DIFF_MODE` | `targeted` | `targeted` \| `stat` \| `unified` |
127
+ | `KEIYAKU_FAKE_SUBAGENT` | `0` | `1` = 测试用 stub |
139
128
 
140
- Print the full env template with defaults:
129
+ HTTP transport:
141
130
 
142
131
  ```bash
143
- keiyaku dump-env
132
+ KEIYAKU_MCP_TRANSPORT=streamable-http \
133
+ KEIYAKU_MCP_HTTP_HOST=127.0.0.1 \
134
+ KEIYAKU_MCP_HTTP_PORT=3000 \
135
+ npx -y @astrosheep/keiyaku
144
136
  ```
145
137
 
146
- ## License
138
+ ---
147
139
 
148
140
  MIT