mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 18:01:22 +00:00
Rename /clear to /new, update hook events to before_new/new
Closes #305 - took direct rename approach instead of alias system Thanks @mitsuhiko for the nudge!
This commit is contained in:
parent
0427445242
commit
454ea1d36a
11 changed files with 56 additions and 35 deletions
|
|
@ -186,7 +186,7 @@ interface ToolSessionEvent {
|
|||
entries: SessionEntry[]; // All session entries
|
||||
sessionFile: string | null; // Current session file
|
||||
previousSessionFile: string | null; // Previous session file
|
||||
reason: "start" | "switch" | "branch" | "clear";
|
||||
reason: "start" | "switch" | "branch" | "new";
|
||||
}
|
||||
```
|
||||
|
||||
|
|
@ -194,7 +194,7 @@ interface ToolSessionEvent {
|
|||
- `start`: Initial session load on startup
|
||||
- `switch`: User switched to a different session (`/resume`)
|
||||
- `branch`: User branched from a previous message (`/branch`)
|
||||
- `clear`: User cleared the session (`/clear`)
|
||||
- `new`: User started a new session (`/new`)
|
||||
|
||||
### State Management Pattern
|
||||
|
||||
|
|
@ -250,7 +250,7 @@ const factory: CustomToolFactory = (pi) => {
|
|||
This pattern ensures:
|
||||
- When user branches, state is correct for that point in history
|
||||
- When user switches sessions, state matches that session
|
||||
- When user clears, state resets
|
||||
- When user starts a new session, state resets
|
||||
|
||||
## Custom Rendering
|
||||
|
||||
|
|
|
|||
|
|
@ -125,10 +125,10 @@ user switches session (/resume)
|
|||
├─► session (reason: "before_switch", can cancel)
|
||||
└─► session (reason: "switch", AFTER switch)
|
||||
|
||||
user clears session (/clear)
|
||||
user starts new session (/new)
|
||||
│
|
||||
├─► session (reason: "before_clear", can cancel)
|
||||
└─► session (reason: "clear", AFTER clear)
|
||||
├─► session (reason: "before_new", can cancel)
|
||||
└─► session (reason: "new", AFTER new session starts)
|
||||
|
||||
context compaction (auto or /compact)
|
||||
│
|
||||
|
|
@ -151,12 +151,12 @@ pi.on("session", async (event, ctx) => {
|
|||
// event.entries: SessionEntry[] - all session entries
|
||||
// event.sessionFile: string | null - current session file (null with --no-session)
|
||||
// event.previousSessionFile: string | null - previous session file
|
||||
// event.reason: "start" | "before_switch" | "switch" | "before_clear" | "clear" |
|
||||
// event.reason: "start" | "before_switch" | "switch" | "before_new" | "new" |
|
||||
// "before_branch" | "branch" | "before_compact" | "compact" | "shutdown"
|
||||
// event.targetTurnIndex: number - only for "before_branch" and "branch"
|
||||
|
||||
// Cancel a before_* action:
|
||||
if (event.reason === "before_clear") {
|
||||
if (event.reason === "before_new") {
|
||||
return { cancel: true };
|
||||
}
|
||||
|
||||
|
|
@ -171,7 +171,7 @@ pi.on("session", async (event, ctx) => {
|
|||
**Reasons:**
|
||||
- `start`: Initial session load on startup
|
||||
- `before_switch` / `switch`: User switched sessions (`/resume`)
|
||||
- `before_clear` / `clear`: User cleared the session (`/clear`)
|
||||
- `before_new` / `new`: User started a new session (`/new`)
|
||||
- `before_branch` / `branch`: User branched the session (`/branch`)
|
||||
- `before_compact` / `compact`: Context compaction (auto or `/compact`)
|
||||
- `shutdown`: Process is exiting (double Ctrl+C, Ctrl+D, or SIGTERM)
|
||||
|
|
@ -848,9 +848,9 @@ Session switch:
|
|||
|
||||
Clear:
|
||||
-> AgentSession.reset()
|
||||
-> hookRunner.emit({ type: "session", reason: "before_clear", ... }) # can cancel
|
||||
-> [if not cancelled: clear happens]
|
||||
-> hookRunner.emit({ type: "session", reason: "clear", ... })
|
||||
-> hookRunner.emit({ type: "session", reason: "before_new", ... }) # can cancel
|
||||
-> [if not cancelled: new session starts]
|
||||
-> hookRunner.emit({ type: "session", reason: "new", ... })
|
||||
|
||||
Shutdown (interactive mode):
|
||||
-> handleCtrlC() or handleCtrlD()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue