Improve CustomEntry docs and make it generic

- Add detailed doc comment explaining purpose (hook state persistence)
- Make CustomEntry<T = unknown> generic
- Clarify difference from CustomMessageEntry in plan
- Update changelog
This commit is contained in:
Mario Zechner 2025-12-26 21:40:09 +01:00
parent e841942377
commit efb1036d8e
3 changed files with 17 additions and 6 deletions

View file

@ -30,7 +30,7 @@
- **Entry IDs**: Session entries now use short 8-character hex IDs instead of full UUIDs - **Entry IDs**: Session entries now use short 8-character hex IDs instead of full UUIDs
- **API key priority**: `ANTHROPIC_OAUTH_TOKEN` now takes precedence over `ANTHROPIC_API_KEY` - **API key priority**: `ANTHROPIC_OAUTH_TOKEN` now takes precedence over `ANTHROPIC_API_KEY`
- **New entry types**: `BranchSummaryEntry` for branch context, `CustomEntry` for hook data, `LabelEntry` for user-defined bookmarks - **New entry types**: `BranchSummaryEntry` for branch context, `CustomEntry<T>` for hook state persistence, `LabelEntry` for user-defined bookmarks
- **Entry labels**: New `getLabel(id)` and `appendLabelChange(targetId, label)` methods for labeling entries. Labels are included in `SessionTreeNode` for UI/export. - **Entry labels**: New `getLabel(id)` and `appendLabelChange(targetId, label)` methods for labeling entries. Labels are included in `SessionTreeNode` for UI/export.
### Fixed ### Fixed

View file

@ -93,14 +93,14 @@ Questions to resolve:
### CustomMessageEntry<T> ### CustomMessageEntry<T>
Hooks can define their own custom message entry types and inject them into the session. Hook-injected messages that participate in LLM context. Unlike `CustomEntry<T>` (for hook state only), these are sent to the model.
```typescript ```typescript
export interface CustomMessageEntry<T = unknown> extends SessionEntryBase { export interface CustomMessageEntry<T = unknown> extends SessionEntryBase {
type: "custom_message"; type: "custom_message";
customType: string; // Hook identifier customType: string; // Hook identifier
content: (string | Attachment)[]; // Message content content: (string | Attachment)[]; // Message content
details?: T; // Hook-specific data (like tool result details) details?: T; // Hook-specific data for state reconstruction on reload
display: boolean; // Whether to display in TUI display: boolean; // Whether to display in TUI
} }
``` ```
@ -115,6 +115,8 @@ Behavior:
- [ ] Define injection mechanism for hooks to add CustomMessageEntry - [ ] Define injection mechanism for hooks to add CustomMessageEntry
- [ ] Hook registration for custom renderers - [ ] Hook registration for custom renderers
See also: `CustomEntry<T>` for storing hook state that does NOT participate in context.
### HTML Export ### HTML Export
- [ ] Add collapsible sidebar showing full tree structure - [ ] Add collapsible sidebar showing full tree structure

View file

@ -61,11 +61,20 @@ export interface BranchSummaryEntry extends SessionEntryBase {
summary: string; summary: string;
} }
/** Custom entry for hooks. Use customType to identify your hook's entries. */ /**
export interface CustomEntry extends SessionEntryBase { * Custom entry for hooks to store hook-specific data in the session.
* Use customType to identify your hook's entries.
*
* Purpose: Persist hook state across session reloads. On reload, hooks can
* scan entries for their customType and reconstruct internal state.
*
* Does NOT participate in LLM context (ignored by buildSessionContext).
* For injecting content into context, see CustomMessageEntry.
*/
export interface CustomEntry<T = unknown> extends SessionEntryBase {
type: "custom"; type: "custom";
customType: string; customType: string;
data?: unknown; data?: T;
} }
/** Label entry for user-defined bookmarks/markers on entries. */ /** Label entry for user-defined bookmarks/markers on entries. */