mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-18 15:03:02 +00:00
Change branch() to use entryId instead of entryIndex
- AgentSession.branch(entryId: string) now takes entry ID - SessionBeforeBranchEvent.entryId replaces entryIndex - getUserMessagesForBranching() returns entryId - Update RPC types and client - Update UserMessageSelectorComponent - Update hook examples and tests - Update docs (hooks.md, sdk.md)
This commit is contained in:
parent
027d39aa33
commit
8e1e99ca05
12 changed files with 64 additions and 50 deletions
|
|
@ -195,7 +195,7 @@ Fired when branching via `/branch`.
|
|||
|
||||
```typescript
|
||||
pi.on("session_before_branch", async (event, ctx) => {
|
||||
// event.entryIndex - entry index being branched from
|
||||
// event.entryId - ID of the entry being branched from
|
||||
|
||||
return { cancel: true }; // Cancel branch
|
||||
// OR
|
||||
|
|
@ -634,15 +634,23 @@ export default function (pi: HookAPI) {
|
|||
import type { HookAPI } from "@mariozechner/pi-coding-agent/hooks";
|
||||
|
||||
export default function (pi: HookAPI) {
|
||||
const checkpoints = new Map<number, string>();
|
||||
const checkpoints = new Map<string, string>();
|
||||
let currentEntryId: string | undefined;
|
||||
|
||||
pi.on("turn_start", async (event) => {
|
||||
pi.on("tool_result", async (_event, ctx) => {
|
||||
const leaf = ctx.sessionManager.getLeafEntry();
|
||||
if (leaf) currentEntryId = leaf.id;
|
||||
});
|
||||
|
||||
pi.on("turn_start", async () => {
|
||||
const { stdout } = await pi.exec("git", ["stash", "create"]);
|
||||
if (stdout.trim()) checkpoints.set(event.turnIndex, stdout.trim());
|
||||
if (stdout.trim() && currentEntryId) {
|
||||
checkpoints.set(currentEntryId, stdout.trim());
|
||||
}
|
||||
});
|
||||
|
||||
pi.on("session_before_branch", async (event, ctx) => {
|
||||
const ref = checkpoints.get(event.entryIndex);
|
||||
const ref = checkpoints.get(event.entryId);
|
||||
if (!ref || !ctx.hasUI) return;
|
||||
|
||||
const ok = await ctx.ui.confirm("Restore?", "Restore code to checkpoint?");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue