Rename /branch command to /fork

- RPC: branch -> fork, get_branch_messages -> get_fork_messages
- SDK: branch() -> fork(), getBranchMessages() -> getForkMessages()
- AgentSession: branch() -> fork(), getUserMessagesForBranching() -> getUserMessagesForForking()
- Extension events: session_before_branch -> session_before_fork, session_branch -> session_fork
- Settings: doubleEscapeAction 'branch' -> 'fork'

fixes #641
This commit is contained in:
Mario Zechner 2026-01-11 23:12:18 +01:00
parent e7352a50bf
commit df3f5f41c0
27 changed files with 162 additions and 156 deletions

View file

@ -20,7 +20,7 @@ cp permission-gate.ts ~/.pi/agent/extensions/
|-----------|-------------|
| `permission-gate.ts` | Prompts for confirmation before dangerous bash commands (rm -rf, sudo, etc.) |
| `protected-paths.ts` | Blocks writes to protected paths (.env, .git/, node_modules/) |
| `confirm-destructive.ts` | Confirms before destructive session actions (clear, switch, branch) |
| `confirm-destructive.ts` | Confirms before destructive session actions (clear, switch, fork) |
| `dirty-repo-guard.ts` | Prevents session changes with uncommitted git changes |
### Custom Tools
@ -53,7 +53,7 @@ cp permission-gate.ts ~/.pi/agent/extensions/
| Extension | Description |
|-----------|-------------|
| `git-checkpoint.ts` | Creates git stash checkpoints at each turn for code restoration on branch |
| `git-checkpoint.ts` | Creates git stash checkpoints at each turn for code restoration on fork |
| `auto-commit-on-exit.ts` | Auto-commits on exit using last assistant message for commit message |
### System Prompt & Compaction
@ -129,7 +129,7 @@ action: Type.Union([Type.Literal("list"), Type.Literal("add")])
**State persistence via details:**
```typescript
// Store state in tool result details for proper branching support
// Store state in tool result details for proper forking support
return {
content: [{ type: "text", text: "Done" }],
details: { todos: [...todos], nextId }, // Persisted in session

View file

@ -43,16 +43,16 @@ export default function (pi: ExtensionAPI) {
}
});
pi.on("session_before_branch", async (event, ctx) => {
pi.on("session_before_fork", async (event, ctx) => {
if (!ctx.hasUI) return;
const choice = await ctx.ui.select(`Branch from entry ${event.entryId.slice(0, 8)}?`, [
"Yes, create branch",
const choice = await ctx.ui.select(`Fork from entry ${event.entryId.slice(0, 8)}?`, [
"Yes, create fork",
"No, stay in current session",
]);
if (choice !== "Yes, create branch") {
ctx.ui.notify("Branch cancelled", "info");
if (choice !== "Yes, create fork") {
ctx.ui.notify("Fork cancelled", "info");
return { cancel: true };
}
});

View file

@ -50,7 +50,7 @@ export default function (pi: ExtensionAPI) {
return checkDirtyRepo(pi, ctx, action);
});
pi.on("session_before_branch", async (_event, ctx) => {
return checkDirtyRepo(pi, ctx, "branch");
pi.on("session_before_fork", async (_event, ctx) => {
return checkDirtyRepo(pi, ctx, "fork");
});
}

View file

@ -1,8 +1,8 @@
/**
* Git Checkpoint Extension
*
* Creates git stash checkpoints at each turn so /branch can restore code state.
* When branching, offers to restore code to that point in history.
* Creates git stash checkpoints at each turn so /fork can restore code state.
* When forking, offers to restore code to that point in history.
*/
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
@ -26,7 +26,7 @@ export default function (pi: ExtensionAPI) {
}
});
pi.on("session_before_branch", async (event, ctx) => {
pi.on("session_before_fork", async (event, ctx) => {
const ref = checkpoints.get(event.entryId);
if (!ref) return;

View file

@ -131,7 +131,7 @@ export default function (pi: ExtensionAPI) {
// Reconstruct state on session events
pi.on("session_start", async (_event, ctx) => reconstructState(ctx));
pi.on("session_switch", async (_event, ctx) => reconstructState(ctx));
pi.on("session_branch", async (_event, ctx) => reconstructState(ctx));
pi.on("session_fork", async (_event, ctx) => reconstructState(ctx));
pi.on("session_tree", async (_event, ctx) => reconstructState(ctx));
// Register the todo tool for the LLM

View file

@ -138,8 +138,8 @@ export default function toolsExtension(pi: ExtensionAPI) {
restoreFromBranch(ctx);
});
// Restore state after branching
pi.on("session_branch", async (_event, ctx) => {
// Restore state after forking
pi.on("session_fork", async (_event, ctx) => {
restoreFromBranch(ctx);
});
}