docs: add switchSession to ExtensionCommandContext in extensions.md
fixes #2735
This commit is contained in:
@@ -944,6 +944,38 @@ Options:
|
|||||||
- `replaceInstructions`: If true, `customInstructions` replaces the default prompt instead of being appended
|
- `replaceInstructions`: If true, `customInstructions` replaces the default prompt instead of being appended
|
||||||
- `label`: Label to attach to the branch summary entry (or target entry if not summarizing)
|
- `label`: Label to attach to the branch summary entry (or target entry if not summarizing)
|
||||||
|
|
||||||
|
### ctx.switchSession(sessionPath)
|
||||||
|
|
||||||
|
Switch to a different session file:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const result = await ctx.switchSession("/path/to/session.jsonl");
|
||||||
|
if (result.cancelled) {
|
||||||
|
// An extension cancelled the switch via session_before_switch
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
To discover available sessions, use the static `SessionManager.list()` or `SessionManager.listAll()` methods:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { SessionManager } from "@mariozechner/pi-coding-agent";
|
||||||
|
|
||||||
|
pi.registerCommand("switch", {
|
||||||
|
description: "Switch to another session",
|
||||||
|
handler: async (args, ctx) => {
|
||||||
|
const sessions = await SessionManager.list(ctx.cwd);
|
||||||
|
if (sessions.length === 0) return;
|
||||||
|
const choice = await ctx.ui.select(
|
||||||
|
"Pick session:",
|
||||||
|
sessions.map(s => s.file),
|
||||||
|
);
|
||||||
|
if (choice) {
|
||||||
|
await ctx.switchSession(choice);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
### ctx.reload()
|
### ctx.reload()
|
||||||
|
|
||||||
Run the same reload flow as `/reload`.
|
Run the same reload flow as `/reload`.
|
||||||
|
|||||||
Reference in New Issue
Block a user