mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 21:03:19 +00:00
- Add setEditorText() and getEditorText() to HookUIContext for prompt generator pattern - custom() now accepts async factories for fire-and-forget work - Add CancellableLoader component to tui package - Add BorderedLoader component for hooks with cancel UI - Export HookAPI, HookContext, HookFactory from main package - Update all examples to import from packages instead of relative paths - Update hooks.md and custom-tools.md documentation fixes #350
48 lines
1.7 KiB
TypeScript
48 lines
1.7 KiB
TypeScript
/**
|
|
* Session Management
|
|
*
|
|
* Control session persistence: in-memory, new file, continue, or open specific.
|
|
*/
|
|
|
|
import { createAgentSession, SessionManager } from "@mariozechner/pi-coding-agent";
|
|
|
|
// In-memory (no persistence)
|
|
const { session: inMemory } = await createAgentSession({
|
|
sessionManager: SessionManager.inMemory(),
|
|
});
|
|
console.log("In-memory session:", inMemory.sessionFile ?? "(none)");
|
|
|
|
// New persistent session
|
|
const { session: newSession } = await createAgentSession({
|
|
sessionManager: SessionManager.create(process.cwd()),
|
|
});
|
|
console.log("New session file:", newSession.sessionFile);
|
|
|
|
// Continue most recent session (or create new if none)
|
|
const { session: continued, modelFallbackMessage } = await createAgentSession({
|
|
sessionManager: SessionManager.continueRecent(process.cwd()),
|
|
});
|
|
if (modelFallbackMessage) console.log("Note:", modelFallbackMessage);
|
|
console.log("Continued session:", continued.sessionFile);
|
|
|
|
// List and open specific session
|
|
const sessions = SessionManager.list(process.cwd());
|
|
console.log(`\nFound ${sessions.length} sessions:`);
|
|
for (const info of sessions.slice(0, 3)) {
|
|
console.log(` ${info.id.slice(0, 8)}... - "${info.firstMessage.slice(0, 30)}..."`);
|
|
}
|
|
|
|
if (sessions.length > 0) {
|
|
const { session: opened } = await createAgentSession({
|
|
sessionManager: SessionManager.open(sessions[0].path),
|
|
});
|
|
console.log(`\nOpened: ${opened.sessionId}`);
|
|
}
|
|
|
|
// Custom session directory (no cwd encoding)
|
|
// const customDir = "/path/to/my-sessions";
|
|
// const { session } = await createAgentSession({
|
|
// sessionManager: SessionManager.create(process.cwd(), customDir),
|
|
// });
|
|
// SessionManager.list(process.cwd(), customDir);
|
|
// SessionManager.continueRecent(process.cwd(), customDir);
|