Skip to content

Commit 81c14f1

Browse files
authored
refactor: replace MCP tools with session CLI transport (#60)
1 parent 7b09fb4 commit 81c14f1

13 files changed

Lines changed: 658 additions & 958 deletions

File tree

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ Then load it in Pi with:
122122
/skill:hunk-review
123123
```
124124

125-
The skill explains what Hunk is and how to use Hunk's MCP tools for live code review.
125+
The skill explains what Hunk is and how to use `hunk session ...` for live code review.
126126

127127
## Config
128128

@@ -144,13 +144,14 @@ agent_notes = false
144144
## Advanced workflows
145145

146146
- `hunk diff --agent-context <file>` loads inline agent rationale from a JSON sidecar
147-
- `hunk mcp serve` runs the local MCP daemon for agent-to-diff communication
147+
- `hunk mcp serve` runs the local Hunk session daemon and websocket broker
148+
- normal Hunk sessions auto-start/register with it when MCP is enabled
148149
- Hunk keeps the daemon loopback-only by default
149150
- if you intentionally need remote access, set `HUNK_MCP_UNSAFE_ALLOW_REMOTE=1` and choose a non-loopback `HUNK_MCP_HOST`
150151

151152
### Live session control CLI
152153

153-
`hunk session ...` is the human/script interface to the same local daemon that MCP uses for live review sessions.
154+
`hunk session ...` is the user-facing and agent-facing interface to Hunk's local live review session daemon.
154155

155156
Use explicit session targeting with either a live `<session-id>` or `--repo <path>` when exactly one live session matches that repo root.
156157

bun.lock

Lines changed: 0 additions & 183 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
"typescript": "^5.9.3"
6464
},
6565
"dependencies": {
66-
"@modelcontextprotocol/sdk": "^1.27.1",
6766
"@opentui/core": "^0.1.88",
6867
"@opentui/react": "^0.1.88",
6968
"@pierre/diffs": "^1.1.0",

skills/hunk-review/SKILL.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
22
name: hunk-review
3-
description: Use when the task involves Hunk or Hunk MCP review sessions. Helps Pi briefly explain what Hunk is, prefer live Hunk MCP inspection over shell parsing, inspect current review focus, navigate hunks, and leave inline review comments.
3+
description: Use when the task involves Hunk review sessions. Helps Pi briefly explain what Hunk is, prefer live Hunk session CLI inspection over shell parsing, inspect current review focus, navigate hunks, and leave inline review comments.
44
compatibility: Requires Hunk from this repo or the published hunkdiff package. Works best with a real TTY for interactive review.
55
---
66

77
# Hunk Review
88

99
Use this skill when working with Hunk itself or when the user wants a code-review workflow centered on Hunk.
1010

11-
When this skill activates, start by briefly explaining what Hunk is in plain language before jumping into MCP details.
11+
When this skill activates, start by briefly explaining what Hunk is in plain language before jumping into session-control details.
1212

1313
## What Hunk is
1414

@@ -21,42 +21,42 @@ Keep these product rules in mind:
2121
- `[` and `]` navigate hunks across the full review stream
2222
- agent notes belong beside the code they explain
2323

24-
## Default rule: prefer live MCP review
24+
## Default rule: prefer live session CLI review
2525

26-
If a live Hunk session already exists, prefer Hunk's MCP tools over launching new shell commands or scraping terminal output.
26+
If a live Hunk session already exists, prefer `hunk session ...` over launching new shell commands that scrape terminal output.
2727

28-
The MCP daemon is local-only and brokers commands to one or more live Hunk sessions.
28+
The local Hunk daemon is loopback-only by default and brokers commands to one or more live Hunk sessions.
2929

3030
Important behavior:
3131
- normal Hunk sessions auto-start and register with the daemon when MCP is enabled
32-
- `hunk mcp serve` exists for manual startup or debugging
33-
- `HUNK_MCP_DISABLE=1` disables MCP registration for a session
32+
- `hunk mcp serve` exists for manual startup or debugging, but it is not the default review path
33+
- `HUNK_MCP_DISABLE=1` disables daemon registration for a session
3434
- one daemon can serve many Hunk sessions
3535

36-
## Recommended MCP review loop
36+
## Recommended review loop
3737

3838
Use this flow by default:
39-
1. `list_sessions`
40-
2. `get_selected_context`
41-
3. `navigate_to_hunk` only if the current focus is wrong
42-
4. `comment`
39+
1. `hunk session list`
40+
2. `hunk session context`
41+
3. `hunk session navigate` only if the current focus is wrong
42+
4. `hunk session comment add`
4343

44-
Use `get_session` only when you need broader session metadata.
44+
Use `hunk session get` only when you need broader session metadata.
4545

4646
Guidelines:
4747
- if multiple sessions are live, pass `sessionId` explicitly
48-
- prefer `get_selected_context` before navigating blindly
49-
- use `navigate_to_hunk` for hunk-level movement; do not invent extra remote-control behavior
50-
- use `comment` for concise inline review notes tied to real diff lines
51-
- prefer `reveal: true` unless the user wants a quieter action
48+
- prefer `hunk session context` before navigating blindly
49+
- use `hunk session navigate` for hunk-level movement; do not invent extra remote-control behavior
50+
- use `hunk session comment add` for concise inline review notes tied to real diff lines
51+
- prefer visible, review-oriented actions over shell parsing of rendered terminal output
5252

53-
For concrete MCP tool behavior and examples, read [references/mcp-review.md](references/mcp-review.md).
53+
For concrete review flow examples, read [references/mcp-review.md](references/mcp-review.md).
5454

5555
## Start Hunk only when needed
5656

57-
If no live Hunk session exists and the user wants an interactive review UI, launch Hunk itself with a minimal command and let it auto-start/register with the MCP daemon.
57+
If no live Hunk session exists and the user wants an interactive review UI, launch Hunk itself with a minimal command and let it auto-start/register with the daemon.
5858

59-
After launching Hunk, go back to `list_sessions` rather than suggesting manual daemon management.
59+
After launching Hunk, go back to `hunk session list` rather than suggesting manual daemon management.
6060

6161
Inside the Hunk repo, prefer the source entrypoint:
6262

@@ -87,7 +87,7 @@ When using Hunk for agent changes:
8787
Prefer a skill over a prompt dump:
8888
- keep always-loaded context small
8989
- load the full Hunk workflow only when the task is actually about review
90-
- use Hunk's existing MCP tools rather than ad hoc shell parsing
90+
- use Hunk's session CLI rather than a separate agent-facing MCP tool surface
9191

9292
Prefer review-oriented actions:
9393
- inspect the current live diff session

skills/hunk-review/references/commands.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Source repo vs installed CLI
44

5-
Launching Hunk normally should auto-start/register the MCP daemon when MCP is enabled, so Pi usually does not need to run `hunk mcp serve` first.
5+
Launching Hunk normally should auto-start/register the local session daemon when MCP is enabled, so Pi usually does not need to run `hunk mcp serve` first.
66

77
If Pi is operating inside the Hunk source repo, prefer the source entrypoint so review and validation target the current checkout:
88

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Hunk MCP review flow
1+
# Hunk live review flow
22

3-
Hunk MCP is a local-only loopback daemon that brokers commands to one or more live Hunk review sessions.
3+
Hunk uses one local-only loopback daemon to broker commands to one or more live Hunk review sessions.
44

55
## Daemon model
66

@@ -11,34 +11,37 @@ Hunk MCP is a local-only loopback daemon that brokers commands to one or more li
1111
hunk mcp serve
1212
```
1313

14-
- Disable MCP registration for one Hunk session with:
14+
- Disable daemon registration for one Hunk session with:
1515

1616
```bash
1717
HUNK_MCP_DISABLE=1 hunk diff
1818
```
1919

20-
## Current tool surface
20+
## User and agent interface
2121

22-
The review-oriented MCP tools are:
23-
- `list_sessions`
24-
- `get_session`
25-
- `get_selected_context`
26-
- `navigate_to_hunk`
27-
- `comment`
22+
The review-oriented interface is `hunk session ...`:
23+
- `hunk session list`
24+
- `hunk session get`
25+
- `hunk session context`
26+
- `hunk session navigate`
27+
- `hunk session comment add`
28+
- `hunk session comment list`
29+
- `hunk session comment rm`
30+
- `hunk session comment clear --yes`
2831

29-
## Recommended agent flow
32+
## Recommended review flow
3033

3134
### 1. Discover the target session
3235

33-
Call `list_sessions` first.
36+
Run `hunk session list` first.
3437

35-
If no session exists but the user wants interactive review, launch Hunk (`hunk diff`, `hunk show`, or the source entrypoint in this repo), then come back and call `list_sessions` again.
38+
If no session exists but the user wants interactive review, launch Hunk (`hunk diff`, `hunk show`, or the source entrypoint in this repo), then come back and run `hunk session list` again.
3639

37-
Use `sessionId` explicitly whenever more than one live session exists.
40+
Use explicit `sessionId` or `--repo <path>` whenever more than one live session exists.
3841

3942
### 2. Inspect current focus
4043

41-
Call `get_selected_context` to see:
44+
Run `hunk session context` to see:
4245
- current file
4346
- current hunk index
4447
- selected hunk old/new ranges
@@ -49,30 +52,28 @@ This is the best way to respect what the human reviewer is already looking at.
4952

5053
### 3. Move only when needed
5154

52-
If the current focus is wrong, call `navigate_to_hunk` with either:
53-
- `hunkIndex`, or
54-
- `side` + `line`
55+
If the current focus is wrong, run `hunk session navigate` with either:
56+
- `--hunk <n>`, or
57+
- `--old-line <n>` / `--new-line <n>`
5558

5659
Prefer hunk-level movement over adding broader remote-control actions.
5760

5861
### 4. Leave inline review notes
5962

60-
Call `comment` with:
61-
- `sessionId`
62-
- `filePath`
63-
- `side`
64-
- `line`
65-
- `summary`
66-
- optional `rationale`
67-
- optional `author`
68-
- usually `reveal: true`
63+
Run `hunk session comment add` with:
64+
- `<session-id>` or `--repo <path>`
65+
- `--file`
66+
- `--old-line` or `--new-line`
67+
- `--summary`
68+
- optional `--rationale`
69+
- optional `--author`
6970

7071
Use concise review comments tied to actual diff lines.
7172

7273
## Practical guidance for Pi
7374

74-
- Prefer MCP tools over scraping terminal text when a live Hunk session already exists.
75-
- Use `get_session` when you need broad session metadata; use `get_selected_context` for fast focus-aware checks.
75+
- Prefer `hunk session ...` over scraping terminal text when a live Hunk session already exists.
76+
- Use `hunk session get` when you need broad session metadata; use `hunk session context` for fast focus-aware checks.
7677
- In multi-session setups, never assume the sole-session fallback is still safe after new windows open.
7778
- Keep comments review-oriented rather than conversational.
7879
- If the user wants silent inspection rather than visible interaction, avoid unnecessary navigation and only comment when asked.

src/core/cli.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ function renderCliHelp() {
127127
" hunk pager general Git pager wrapper with diff detection",
128128
" hunk difftool <left> <right> [path] review Git difftool file pairs",
129129
" hunk session <subcommand> inspect or control a live Hunk session",
130-
" hunk mcp serve run the local Hunk MCP daemon",
130+
" hunk mcp serve run the local Hunk session daemon",
131131
"",
132132
"Options:",
133133
" -h, --help show help",
@@ -691,7 +691,7 @@ async function parseMcpCommand(tokens: string[]): Promise<ParsedCliInput> {
691691
text: [
692692
"Usage: hunk mcp serve",
693693
"",
694-
"Run the local Hunk MCP daemon and websocket session broker.",
694+
"Run the local Hunk session daemon and websocket session broker.",
695695
"",
696696
"Environment:",
697697
" HUNK_MCP_HOST bind host (default 127.0.0.1; loopback only unless explicitly overridden)",
@@ -711,7 +711,7 @@ async function parseMcpCommand(tokens: string[]): Promise<ParsedCliInput> {
711711
text: [
712712
"Usage: hunk mcp serve",
713713
"",
714-
"Run the local Hunk MCP daemon and websocket session broker.",
714+
"Run the local Hunk session daemon and websocket session broker.",
715715
].join("\n") + "\n",
716716
};
717717
}

0 commit comments

Comments
 (0)