mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-21 05:02:14 +00:00
Update hooks.md: clarify session_before_tree, document all sessionManager methods
This commit is contained in:
parent
57b066f135
commit
bab343b8bc
1 changed files with 21 additions and 19 deletions
|
|
@ -232,15 +232,16 @@ pi.on("session_compact", async (event, ctx) => {
|
||||||
|
|
||||||
#### session_before_tree / session_tree
|
#### session_before_tree / session_tree
|
||||||
|
|
||||||
Fired on `/tree` navigation. See [compaction.md](compaction.md) for details.
|
Fired on `/tree` navigation. Always fires regardless of user's summarization choice. See [compaction.md](compaction.md) for details.
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
pi.on("session_before_tree", async (event, ctx) => {
|
pi.on("session_before_tree", async (event, ctx) => {
|
||||||
const { preparation, signal } = event;
|
const { preparation, signal } = event;
|
||||||
// preparation.targetId, oldLeafId, commonAncestorId, entriesToSummarize, userWantsSummary
|
// preparation.targetId, oldLeafId, commonAncestorId, entriesToSummarize
|
||||||
|
// preparation.userWantsSummary - whether user chose to summarize
|
||||||
|
|
||||||
return { cancel: true };
|
return { cancel: true };
|
||||||
// OR (if userWantsSummary):
|
// OR provide custom summary (only used if userWantsSummary is true):
|
||||||
return { summary: { summary: "...", details: {} } };
|
return { summary: { summary: "...", details: {} } };
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -433,26 +434,27 @@ Current working directory.
|
||||||
|
|
||||||
### ctx.sessionManager
|
### ctx.sessionManager
|
||||||
|
|
||||||
Read-only access to session state:
|
Read-only access to session state. See `ReadonlySessionManager` in [`src/core/session-manager.ts`](../src/core/session-manager.ts).
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
// Get all entries (excludes header)
|
// Session info
|
||||||
const entries = ctx.sessionManager.getEntries();
|
ctx.sessionManager.getCwd() // Working directory
|
||||||
|
ctx.sessionManager.getSessionDir() // Session directory (~/.pi/agent/sessions)
|
||||||
|
ctx.sessionManager.getSessionId() // Current session ID
|
||||||
|
ctx.sessionManager.getSessionFile() // Session file path (undefined with --no-session)
|
||||||
|
|
||||||
// Get current branch (root to leaf)
|
// Entries
|
||||||
const branch = ctx.sessionManager.getBranch();
|
ctx.sessionManager.getEntries() // All entries (excludes header)
|
||||||
|
ctx.sessionManager.getHeader() // Session header entry
|
||||||
|
ctx.sessionManager.getEntry(id) // Specific entry by ID
|
||||||
|
ctx.sessionManager.getLabel(id) // Entry label (if any)
|
||||||
|
|
||||||
// Get specific entry by ID
|
// Tree navigation
|
||||||
const entry = ctx.sessionManager.getEntry(id);
|
ctx.sessionManager.getBranch() // Current branch (root to leaf)
|
||||||
|
ctx.sessionManager.getBranch(leafId) // Specific branch
|
||||||
// Get session file (undefined with --no-session)
|
ctx.sessionManager.getTree() // Full tree structure
|
||||||
const file = ctx.sessionManager.getSessionFile();
|
ctx.sessionManager.getLeafId() // Current leaf entry ID
|
||||||
|
ctx.sessionManager.getLeafEntry() // Current leaf entry
|
||||||
// Get tree structure
|
|
||||||
const tree = ctx.sessionManager.getTree();
|
|
||||||
|
|
||||||
// Get entry label
|
|
||||||
const label = ctx.sessionManager.getLabel(entryId);
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Use `pi.sendMessage()` or `pi.appendEntry()` for writes.
|
Use `pi.sendMessage()` or `pi.appendEntry()` for writes.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue