Commit graph

1304 commits

Author SHA1 Message Date
Mario Zechner
32ec1fa883 fix(coding-agent): treat multiple roots as children of virtual branching root 2025-12-30 22:42:23 +01:00
Mario Zechner
7c103ddc55 refactor(coding-agent): simplify tree indentation
- At indent 0: stay flat unless parent branches
- At indent 1: children go to indent 2 (visual grouping)
- At indent 2+: stay flat for single-child chains
- Remove gutter/connector complexity for now
2025-12-30 22:42:23 +01:00
Mario Zechner
6fbc3a01ef refactor(coding-agent): cleaner tree gutter/indent logic
- Only indent when parent has siblings (branch point)
- gutterLevels array tracks which levels need │ vs spaces
- connector: none/branch/last for ├─/└─ display
2025-12-30 22:42:23 +01:00
Mario Zechner
1d90592df1 fix(coding-agent): always show error/aborted assistant messages in tree 2025-12-30 22:42:23 +01:00
Mario Zechner
e8debe78c6 fix(coding-agent): use visible leaf for tree display, preserve metadata on branch 2025-12-30 22:42:23 +01:00
Mario Zechner
5726770d1f fix(coding-agent): always show current leaf in tree selector even if aborted/error 2025-12-30 22:42:22 +01:00
Mario Zechner
2922020382 feat(coding-agent): improve tree selector tool display
- Tool results show formatted call info like [read: path:1-10], [bash: cmd]
- Skip assistant messages with stopReason error/aborted
- Skip assistant messages with only tool calls (no text)
- Format built-in tools like tool-execution.ts (read, write, edit, bash, grep, find, ls)
- Custom tools show truncated JSON args
2025-12-30 22:42:22 +01:00
Mario Zechner
b153b528e8 feat(coding-agent): show tool name instead of result content in tree selector 2025-12-30 22:42:22 +01:00
Mario Zechner
6b7ad0ed4b feat(coding-agent): reimplement tree selector features
- Label editing with 'l' key
- Ctrl+O cycles through filters: default -> user-only -> labeled-only -> all
- Preserve cursor position when toggling filters
- Labels shown at front of node
- Normalize tabs/newlines in content
- extractContent limited to 200 chars for performance
- truncateToWidth on all rendered lines
- Iterative flattenTree to avoid stack overflow
- Linear chain optimization (no indent for single-child chains)
2025-12-30 22:42:22 +01:00
Mario Zechner
544814875e Add global debug key (Shift+Ctrl+D), iterative tree sorting to avoid stack overflow 2025-12-30 22:42:22 +01:00
Mario Zechner
1f4594598b feat(coding-agent): add search to /tree selector
- Type to filter nodes by matching tokens in content
- Search field always visible above tree
- Backspace removes chars, Escape clears search
- Restructured layout: title, border, help+search, border, tree, border
2025-12-30 22:42:22 +01:00
Mario Zechner
4958271dd3 feat(coding-agent): implement /tree command for session tree navigation
- Add TreeSelectorComponent with ASCII tree visualization
- Add AgentSession.navigateTree() for switching branches
- Add session_before_tree/session_tree hook events
- Add SessionManager.resetLeaf() for navigating to root
- Change leafId from string to string|null for consistency with parentId
- Support optional branch summarization when switching
- Update buildSessionContext() to handle null leafId
- Add /tree to slash commands in interactive mode
2025-12-30 22:42:22 +01:00
Mario Zechner
256761e410 Clean-up 2025-12-30 22:42:22 +01:00
Mario Zechner
59ce62bffc Tree spec 2025-12-30 22:42:22 +01:00
Mario Zechner
d6283f99dc refactor(hooks): split session events into individual typed events
Major changes:
- Replace monolithic SessionEvent with reason discriminator with individual
  event types: session_start, session_before_switch, session_switch,
  session_before_new, session_new, session_before_branch, session_branch,
  session_before_compact, session_compact, session_shutdown
- Each event has dedicated result type (SessionBeforeSwitchResult, etc.)
- HookHandler type now allows bare return statements (void in return type)
- HookAPI.on() has proper overloads for each event with correct typing

Additional fixes:
- AgentSession now always subscribes to agent in constructor (was only
  subscribing when external subscribe() called, breaking internal handlers)
- Standardize on undefined over null throughout codebase
- HookUIContext methods return undefined instead of null
- SessionManager methods return undefined instead of null
- Simplify hook exports to 'export type * from types.js'
- Add detailed JSDoc for skipConversationRestore vs cancel
- Fix createBranchedSession to rebuild index in persist mode
- newSession() now returns the session file path

Updated all example hooks, tests, and emission sites to use new event types.
2025-12-30 22:42:22 +01:00
Mario Zechner
38d65dfe59 Add ReadonlySessionManager type for hooks
Hooks now receive ReadonlySessionManager in contexts, which only
exposes read methods. Writes must go through pi.sendMessage() or
pi.appendEntry().
2025-12-30 22:42:22 +01:00
Mario Zechner
26e1c9d91c Fix nested background issue in HookMessageComponent
When custom renderer returns a component with its own background,
don't wrap it in another background box. The nested bg resets
were causing padding to lose its background color.
2025-12-30 22:42:22 +01:00
Mario Zechner
41af99cccf Support multiple messages in agent.prompt() and agentLoop
- agentLoop now accepts AgentMessage[] instead of single message
- agent.prompt() accepts AgentMessage | AgentMessage[]
- Emits message_start/end for each message in the array
- AgentSession.prompt() builds array with hook message + user message
- TUI now receives events for before_agent_start injected messages
2025-12-30 22:42:22 +01:00
Mario Zechner
575c875475 Remove allowDuringStreaming flag - commands always run immediately
Hook commands now always execute immediately, even during streaming.
If a command needs to interact with the LLM, it uses pi.sendMessage()
which handles queueing automatically.

This simplifies the API and eliminates the issue of queued slash
commands being sent to the LLM instead of executing.
2025-12-30 22:42:22 +01:00
Mario Zechner
f8352bb7d7 Rename immediate -> allowDuringStreaming for hook commands 2025-12-30 22:42:22 +01:00
Mario Zechner
454dd919be Fix test hook: add triggerTurn to start agent run 2025-12-30 22:42:22 +01:00
Mario Zechner
0d558813e4 Fix test hook: use valid theme colors, proper type import 2025-12-30 22:42:22 +01:00
Mario Zechner
f43969b31a Update plan: mark before_agent_start as complete 2025-12-30 22:42:22 +01:00
Mario Zechner
57146de202 Implement before_agent_start hook event
- Add BeforeAgentStartEvent and BeforeAgentStartEventResult types
- Add emitBeforeAgentStart to HookRunner
- Call in AgentSession.prompt() before agent.prompt()
- Hook can return a message to inject into context (persisted + visible)
- Add test hook demonstrating custom message rendering and before_agent_start
2025-12-30 22:42:22 +01:00
Mario Zechner
bbdc350394 Add reference to #330 (Dynamic Context Pruning) in plan
Documents why context event was added and notes the type
inconsistency between ContextEvent (AgentMessage[]) and
ContextEventResult (Message[])
2025-12-30 22:42:22 +01:00
Mario Zechner
ae614f93e3 Add investigation item for context event vs before_agent_start
Reference: #324

Documents:
- Current context event behavior (AgentMessage[], transient)
- Proposed before_agent_start event (persistent, TUI visible)
- Key differences table
- Open design questions
- Need to verify AgentMessage vs Message abstraction level
2025-12-30 22:42:22 +01:00
Mario Zechner
1721bb8398 Mark Hook API Changes as complete in plan 2025-12-30 22:42:21 +01:00
Mario Zechner
4ff5f61ffc Add BranchSummaryMessageComponent, unify styling with hook messages
- CompactionSummaryMessageComponent now extends Box, uses customMessageBg
- New BranchSummaryMessageComponent for branch summaries
- Both use same background color as HookMessageComponent for consistency
- Added Spacer before compaction/branch components in chat
2025-12-30 22:42:21 +01:00
Mario Zechner
b921298af7 Use exhaustive switch on message.role throughout coding-agent
- addMessageToChat: exhaustive switch for all AgentMessage roles
- renderSessionContext: delegates to addMessageToChat, special handling for assistant tool calls and tool results
- export-html formatMessage: exhaustive switch for all AgentMessage roles
- Removed isHookMessage, isBashExecutionMessage type guards in favor of role checks
- Fixed imports and removed unused getLatestCompactionEntry
2025-12-30 22:42:21 +01:00
Mario Zechner
ecef601d19 Fix hook message duplication in TUI
Two bugs:
1. createCustomMessage was returning role: 'user' instead of preserving
   the hook message structure (role: 'hookMessage', customType, etc.)
2. rebuildChatFromMessages wasn't clearing the container before rebuilding
2025-12-30 22:42:21 +01:00
Mario Zechner
01c4e879a1 Clean-up 2025-12-30 22:42:21 +01:00
Mario Zechner
78aa417ef1 Update Changelog and Releasing sections in AGENTS.md 2025-12-30 22:42:21 +01:00
Mario Zechner
c05e7fafdd Simplify Publishing section in README.md 2025-12-30 22:42:21 +01:00
Mario Zechner
0f98decf65 Remove proxy package
The proxy functionality is now handled by web-ui's createStreamFn
with external proxy servers.
2025-12-30 22:42:21 +01:00
Mario Zechner
6bbe3147d8 Add release script
Usage: npm run release:patch|minor|major

Automates:
- Check for uncommitted changes
- Bump version
- Update CHANGELOGs: [Unreleased] -> [version] - date
- Commit and tag
- Publish to npm
- Add new [Unreleased] sections
- Push
2025-12-30 22:42:21 +01:00
Mario Zechner
262ba5487c Use queueMessage for notifications in example 2025-12-30 22:42:21 +01:00
Mario Zechner
b73a9169cc Add CHANGELOG.md for web-ui package 2025-12-30 22:42:21 +01:00
Mario Zechner
4d1936d3df AgentInterface sets default streamFn and getApiKey
- Make Agent.streamFn and Agent.getApiKey public
- AgentInterface sets defaults if not already set
- Example no longer needs to configure these
2025-12-30 22:42:21 +01:00
Mario Zechner
92898f486b Allow async streamFn for dynamic proxy settings
- StreamFn type now allows returning Promise
- agent-loop awaits streamFn result
- createStreamFn takes getProxyUrl callback, reads settings on each call
2025-12-30 22:42:21 +01:00
Mario Zechner
e0be2e650d Add createStreamFn for CORS proxy support
- createStreamFn(proxyUrl?) returns a sync streamFn that applies proxy
- Example reads proxy settings once when creating Agent
- Matches old ProviderTransport behavior
2025-12-30 22:42:21 +01:00
Mario Zechner
e49e787322 Set isStreaming=false on agent_end event, before emitting to listeners
Was only setting in finally block, after event was emitted.
2025-12-30 22:42:21 +01:00
Mario Zechner
6972ce4e87 Clear streaming container on agent_end 2025-12-30 22:42:21 +01:00
Mario Zechner
347d4cf729 Fix AgentInterface to requestUpdate on all message lifecycle events
Was only handling message_update, now also handles message_start,
message_end, turn_start, turn_end, agent_start, agent_end.
2025-12-30 22:42:21 +01:00
Mario Zechner
977e4ea6ef Add getApiKey to web-ui example Agent config
Provides API keys from the provider keys store, matching old ProviderTransport behavior.
2025-12-30 22:42:21 +01:00
Mario Zechner
3bf168615a Use dynamic import for http module in OAuth files
Prevents browser bundles from failing on import.
The http module is only loaded when login functions are actually called.
2025-12-30 22:42:21 +01:00
Mario Zechner
481bc79f83 Fix Buffer usage in github-copilot.ts - use atob() 2025-12-30 22:42:21 +01:00
Mario Zechner
c10fc1e081 Use Web Crypto API for OAuth PKCE, remove Node.js crypto dependency
- Add pkce.ts with generatePKCE() using Web Crypto API
- Update anthropic.ts, google-gemini-cli.ts, google-antigravity.ts
- Replace Buffer.from() with atob() for base64 decoding
- Works in both Node.js 20+ and browsers

The OAuth modules still use Node.js http.createServer for callbacks,
so they only work in CLI environments, but they no longer crash on
import in browser bundles.
2025-12-30 22:42:21 +01:00
Mario Zechner
6a6d1a59f4 Rename customMessageTransformer to customConvertToLlm 2025-12-30 22:42:20 +01:00
Mario Zechner
13a1991ec2 Add defaultConvertToLlm to web-ui, simplify example
- web-ui exports: defaultConvertToLlm, convertAttachments, isUserMessageWithAttachments, isArtifactMessage
- defaultConvertToLlm handles UserMessageWithAttachments and filters ArtifactMessage
- Example's customMessageTransformer now extends defaultConvertToLlm
- Removes duplicated attachment conversion logic from example
2025-12-30 22:42:20 +01:00
Mario Zechner
7a39f9eb11 Fix web-ui and example for new agent API
- AgentInterface composes UserMessageWithAttachments for attachments
- Updated example to use convertToLlm instead of transport/messageTransformer
- Fixed declaration merging: target pi-agent-core, add path to example tsconfig
- Fixed typo in CustomAgentMessages key (user-with-attachment -> user-with-attachments)
- customMessageTransformer properly converts UserMessageWithAttachments to content blocks
2025-12-30 22:42:20 +01:00