From e8419423771e71a36fcea3ecab73c23e6343cd3f Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Fri, 26 Dec 2025 21:34:48 +0100 Subject: [PATCH] Use CompactionResult type for hook compaction return value - Import CompactionResult in hooks/types.ts - Replace inline type with CompactionResult for SessionEventResult.compaction - Add labels feature to changelog --- packages/coding-agent/CHANGELOG.md | 3 ++- .../coding-agent/docs/session-tree-plan.md | 24 +++++++++++++++++++ packages/coding-agent/src/core/hooks/types.ts | 8 ++----- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.md index 987e4d5f..8441876d 100644 --- a/packages/coding-agent/CHANGELOG.md +++ b/packages/coding-agent/CHANGELOG.md @@ -30,7 +30,8 @@ - **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` -- **New entry types**: `BranchSummaryEntry` for branch context, `CustomEntry` for hook data +- **New entry types**: `BranchSummaryEntry` for branch context, `CustomEntry` for hook data, `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. ### Fixed diff --git a/packages/coding-agent/docs/session-tree-plan.md b/packages/coding-agent/docs/session-tree-plan.md index c862162b..fbc60e81 100644 --- a/packages/coding-agent/docs/session-tree-plan.md +++ b/packages/coding-agent/docs/session-tree-plan.md @@ -91,6 +91,30 @@ Questions to resolve: - [ ] Display labels in UI (tree view, path view) - deferred to UI phase - [ ] `/label` command - deferred to UI phase +### CustomMessageEntry + +Hooks can define their own custom message entry types and inject them into the session. + +```typescript +export interface CustomMessageEntry extends SessionEntryBase { + type: "custom_message"; + customType: string; // Hook identifier + content: (string | Attachment)[]; // Message content + details?: T; // Hook-specific data (like tool result details) + display: boolean; // Whether to display in TUI +} +``` + +Behavior: +- [ ] Participates in context and compaction as user messages (after messageTransformer) +- [ ] Not displayed as user messages in TUI +- [ ] Display options: + - `display: false` - hidden entirely + - `display: true` - baseline renderer (content with different bg/fg color) + - Custom renderer defined by the hook that contributes it +- [ ] Define injection mechanism for hooks to add CustomMessageEntry +- [ ] Hook registration for custom renderers + ### HTML Export - [ ] Add collapsible sidebar showing full tree structure diff --git a/packages/coding-agent/src/core/hooks/types.ts b/packages/coding-agent/src/core/hooks/types.ts index a51a93bf..82033e21 100644 --- a/packages/coding-agent/src/core/hooks/types.ts +++ b/packages/coding-agent/src/core/hooks/types.ts @@ -7,7 +7,7 @@ import type { AppMessage, Attachment } from "@mariozechner/pi-agent-core"; import type { ImageContent, Model, TextContent, ToolResultMessage } from "@mariozechner/pi-ai"; -import type { CutPointResult } from "../compaction.js"; +import type { CompactionResult, CutPointResult } from "../compaction.js"; import type { CompactionEntry, SessionEntry } from "../session-manager.js"; import type { BashToolDetails, @@ -354,11 +354,7 @@ export interface SessionEventResult { /** If true (for before_branch only), skip restoring conversation to branch point while still creating the branched session file */ skipConversationRestore?: boolean; /** Custom compaction result (for before_compact event) - SessionManager adds id/parentId */ - compaction?: { - summary: string; - firstKeptEntryId: string; - tokensBefore: number; - }; + compaction?: CompactionResult; } // ============================================================================